Add explicit operator= and copy c'tors. (#9133)

Co-authored-by: David Cosgrove <david@cozchemix.co.uk>
This commit is contained in:
David Cosgrove
2026-03-01 06:18:20 +00:00
committed by GitHub
parent 8e76c27784
commit 73682f3700
4 changed files with 56 additions and 9 deletions

View File

@@ -71,9 +71,17 @@ class Matrix {
d_dataSize * sizeof(TYPE));
d_data.reset(data);
}
Matrix(Matrix<TYPE> &&other) = default;
virtual ~Matrix() {}
Matrix<TYPE> &operator=(const Matrix<TYPE> &other) {
if (this == &other) {
return *this;
}
return assign(other);
}
Matrix<TYPE> &operator=(Matrix<TYPE> &&other) = default;
//! returns the number of rows
inline unsigned int numRows() const { return d_nRows; }
@@ -159,7 +167,7 @@ class Matrix {
}
//! Matrix addition.
/*! Perform a element by element addition of other Matrix to this Matrix
/*! Perform an element by element addition of other Matrix to this Matrix
*/
virtual Matrix<TYPE> &operator+=(const Matrix<TYPE> &other) {
PRECONDITION(d_nRows == other.numRows(),
@@ -246,9 +254,6 @@ class Matrix {
unsigned int d_nCols{0};
unsigned int d_dataSize{0};
DATA_SPTR d_data;
private:
Matrix<TYPE> &operator=(const Matrix<TYPE> &other);
};
//! Matrix multiplication
@@ -276,7 +281,7 @@ Matrix<TYPE> &multiply(const Matrix<TYPE> &A, const Matrix<TYPE> &B,
CHECK_INVARIANT(aRows == cRows, "Size mismatch during multiplication");
CHECK_INVARIANT(bCols == cCols, "Size mismatch during multiplication");
// we have the sizes check do do the multiplication
// we have the sizes check so do the multiplication
TYPE *cData = C.getData();
const TYPE *bData = B.getData();
const TYPE *aData = A.getData();

View File

@@ -27,9 +27,11 @@ class SquareMatrix : public Matrix<TYPE> {
SquareMatrix(unsigned int N, typename Matrix<TYPE>::DATA_SPTR data)
: Matrix<TYPE>(N, N, data) {}
// inline unsigned int size() const {
// return d_nRows;
// }
SquareMatrix(const SquareMatrix &B) = default;
SquareMatrix(SquareMatrix<TYPE> &&B) = default;
SquareMatrix &operator=(const SquareMatrix<TYPE> &B) = default;
SquareMatrix &operator=(SquareMatrix<TYPE> &&B) = default;
~SquareMatrix() = default;
SquareMatrix<TYPE> &operator*=(TYPE scale) override {
Matrix<TYPE>::operator*=(scale);