aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2007-09-26 14:06:32 +0000
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2007-09-26 14:06:32 +0000
commit8a024825d26aee76431e4c7dab98f114bf51dff2 (patch)
tree51e9a02462b558012b5d487e9066c6b7500b8dd7
parenta2dd9dd6f9a9b6f45e79082e4d8a3577dd4246b6 (diff)
fix bugs caused by default copy constructors being called. valgrind,
you saved my life.
-rw-r--r--doc/tutorial.cpp4
-rw-r--r--src/internal/Matrix.h23
-rw-r--r--test/matrixops.cpp5
-rw-r--r--test/vectorops.cpp4
4 files changed, 17 insertions, 19 deletions
diff --git a/doc/tutorial.cpp b/doc/tutorial.cpp
index 2d881cda2..efadc9bfa 100644
--- a/doc/tutorial.cpp
+++ b/doc/tutorial.cpp
@@ -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;
diff --git a/src/internal/Matrix.h b/src/internal/Matrix.h
index a4018c29d..15042beed 100644
--- a/src/internal/Matrix.h
+++ b/src/internal/Matrix.h
@@ -73,29 +73,30 @@ 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);
}
-
- template<typename OtherDerived>
- Matrix& operator+=(const EigenBase<Scalar, OtherDerived> &other)
- {
- return Base::operator+=(other);
- }
- template<typename OtherDerived>
- Matrix& operator-=(const EigenBase<Scalar, OtherDerived> &other)
+ Matrix& operator=(const Matrix& other)
{
- return Base::operator-=(other);
+ resize(other.rows(), other.cols());
+ 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>
Matrix(const EigenBase<Scalar, OtherDerived>& other) : Storage(other.rows(), other.cols())
{
*this = other;
}
+ Matrix(const Matrix& other) : Storage(other.rows(), other.cols())
+ {
+ *this = other;
+ }
~Matrix() {}
};
diff --git a/test/matrixops.cpp b/test/matrixops.cpp
index 8acf43277..1369a72a0 100644
--- a/test/matrixops.cpp
+++ b/test/matrixops.cpp
@@ -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));
}
diff --git a/test/vectorops.cpp b/test/vectorops.cpp
index 38beb19c2..b1bbfdbbb 100644
--- a/test/vectorops.cpp
+++ b/test/vectorops.cpp
@@ -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));
}