mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-10 18:59:01 +08:00
fix bugs caused by default copy constructors being called. valgrind,
you saved my life.
This commit is contained in:
parent
a2dd9dd6f9
commit
8a024825d2
@ -17,13 +17,11 @@ int main(int, char **)
|
||||
|
||||
cout << "Here is a 2x2 matrix m:" << endl << m << endl;
|
||||
cout << "Let us now build a 4x4 matrix m2 by assembling together four 2x2 blocks." << endl;
|
||||
Matrix<double,4,4> m2; // dynamic matrix with initial size 4x4 and uninitialized entries
|
||||
MatrixXd m2(4,4); // dynamic matrix with initial size 4x4 and uninitialized entries
|
||||
// notice how we are mixing fixed-size and dynamic-size types.
|
||||
|
||||
cout << "In the top-left block, we put the matrix m shown above." << endl;
|
||||
m2.block(0,1,0,1) = m;
|
||||
cout << "m2 is now " << endl << m2 << endl;
|
||||
cout << "m2.block(0,1,0,1) has " << m2.block(0,1,0,1).rows() << " rows" << endl;
|
||||
cout << "In the bottom-left block, we put the matrix m*m, which is:" << endl << m*m << endl;
|
||||
m2.block(2,3,0,1) = m * m;
|
||||
cout << "In the top-right block, we put the matrix m+m, which is:" << endl << m+m << endl;
|
||||
|
@ -73,22 +73,19 @@ class Matrix : public EigenBase<_Scalar, Matrix<_Scalar, _Rows, _Cols> >,
|
||||
|
||||
public:
|
||||
template<typename OtherDerived>
|
||||
Matrix& operator=(const EigenBase<Scalar, OtherDerived> &other)
|
||||
Matrix& operator=(const EigenBase<Scalar, OtherDerived>& other)
|
||||
{
|
||||
resize(other.rows(), other.cols());
|
||||
return Base::operator=(other);
|
||||
}
|
||||
Matrix& operator=(const Matrix& other)
|
||||
{
|
||||
resize(other.rows(), other.cols());
|
||||
return Base::operator=(other);
|
||||
}
|
||||
|
||||
template<typename OtherDerived>
|
||||
Matrix& operator+=(const EigenBase<Scalar, OtherDerived> &other)
|
||||
{
|
||||
return Base::operator+=(other);
|
||||
}
|
||||
template<typename OtherDerived>
|
||||
Matrix& operator-=(const EigenBase<Scalar, OtherDerived> &other)
|
||||
{
|
||||
return Base::operator-=(other);
|
||||
}
|
||||
INHERIT_ASSIGNMENT_OPERATOR(Matrix, +=)
|
||||
INHERIT_ASSIGNMENT_OPERATOR(Matrix, -=)
|
||||
|
||||
explicit Matrix(int rows = 1, int cols = 1) : Storage(rows, cols) {}
|
||||
template<typename OtherDerived>
|
||||
@ -96,6 +93,10 @@ class Matrix : public EigenBase<_Scalar, Matrix<_Scalar, _Rows, _Cols> >,
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
Matrix(const Matrix& other) : Storage(other.rows(), other.cols())
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
~Matrix() {}
|
||||
};
|
||||
|
||||
|
@ -45,7 +45,6 @@ template<typename MatrixType1,
|
||||
a = b + c;
|
||||
a = s * (b - c);
|
||||
a = eval(a + b);
|
||||
|
||||
a += b;
|
||||
a -= b + b;
|
||||
|
||||
@ -60,10 +59,10 @@ void EigenTest::testMatrixOps()
|
||||
matrixOps(Matrix<int, 2, 3>(), Matrix<int, 3, 1>());
|
||||
matrixOps(Matrix<double, 3, 3>(), Matrix<double, 3, 3>());
|
||||
matrixOps(Matrix<complex<float>, 4,3>(), Matrix<complex<float>, 3,4>());
|
||||
/*matrixOps(MatrixXf(1, 1), MatrixXf(1, 3));
|
||||
matrixOps(MatrixXf(1, 1), MatrixXf(1, 3));
|
||||
matrixOps(MatrixXi(2, 2), MatrixXi(2, 2));
|
||||
matrixOps(MatrixXd(3, 5), MatrixXd(5, 1));
|
||||
matrixOps(MatrixXcf(4, 4), MatrixXcf(4, 4));
|
||||
matrixOps(MatrixXd(3, 5), Matrix<double, 5, 1>());
|
||||
matrixOps(Matrix4cf(), MatrixXcf(4, 4));*/
|
||||
matrixOps(Matrix4cf(), MatrixXcf(4, 4));
|
||||
}
|
||||
|
@ -54,8 +54,8 @@ void EigenTest::testVectorOps()
|
||||
vectorOps(Vector2i());
|
||||
vectorOps(Vector3d());
|
||||
vectorOps(Vector4cf());
|
||||
/*vectorOps(VectorXf(1));
|
||||
vectorOps(VectorXf(1));
|
||||
vectorOps(VectorXi(2));
|
||||
vectorOps(VectorXd(3));
|
||||
vectorOps(VectorXcf(4));*/
|
||||
vectorOps(VectorXcf(4));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user