aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/basicstuff.cpp
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2009-05-20 15:41:23 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2009-05-20 15:41:23 +0200
commitdd45c4805ced4ad8ead743875f42259e9b6a2795 (patch)
tree22ba6d80c2f8d60721e38adf579ffb6bba23d0f5 /test/basicstuff.cpp
parent6ecd02d7ec85f07e02559cb311d4dd07e844a72d (diff)
* add a writable generic coeff wise expression (CwiseUnaryView)
* add writable .real() and .imag() functions
Diffstat (limited to 'test/basicstuff.cpp')
-rw-r--r--test/basicstuff.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/basicstuff.cpp b/test/basicstuff.cpp
index 9bc1b7459..7b22cfb79 100644
--- a/test/basicstuff.cpp
+++ b/test/basicstuff.cpp
@@ -107,6 +107,40 @@ template<typename MatrixType> void basicStuff(const MatrixType& m)
{
VERIFY_IS_NOT_APPROX(m3, m1);
}
+
+ m3.real() = m1.real();
+ VERIFY_IS_APPROX(static_cast<const MatrixType&>(m3).real(), static_cast<const MatrixType&>(m1).real());
+ VERIFY_IS_APPROX(static_cast<const MatrixType&>(m3).real(), m1.real());
+}
+
+template<typename MatrixType> void basicStuffComplex(const MatrixType& m)
+{
+ typedef typename MatrixType::Scalar Scalar;
+ typedef typename NumTraits<Scalar>::Real RealScalar;
+ typedef Matrix<RealScalar, MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTime> RealMatrixType;
+
+ int rows = m.rows();
+ int cols = m.cols();
+
+ Scalar s1 = ei_random<Scalar>(),
+ s2 = ei_random<Scalar>();
+
+ VERIFY(ei_real(s1)==ei_real_ref(s1));
+ VERIFY(ei_imag(s1)==ei_imag_ref(s1));
+ ei_real_ref(s1) = ei_real(s2);
+ ei_imag_ref(s1) = ei_imag(s2);
+ VERIFY(s1==s2);
+
+ RealMatrixType rm1 = RealMatrixType::Random(rows,cols),
+ rm2 = RealMatrixType::Random(rows,cols);
+ MatrixType cm(rows,cols);
+ cm.real() = rm1;
+ cm.imag() = rm2;
+ VERIFY_IS_APPROX(static_cast<const MatrixType&>(cm).real(), rm1);
+ VERIFY_IS_APPROX(static_cast<const MatrixType&>(cm).imag(), rm2);
+ cm.real().setZero();
+ VERIFY(static_cast<const MatrixType&>(cm).real().isZero());
+ VERIFY(!static_cast<const MatrixType&>(cm).imag().isZero());
}
void casting()
@@ -128,6 +162,9 @@ void test_basicstuff()
CALL_SUBTEST( basicStuff(MatrixXcd(20, 20)) );
CALL_SUBTEST( basicStuff(Matrix<float, 100, 100>()) );
CALL_SUBTEST( basicStuff(Matrix<long double,Dynamic,Dynamic>(10,10)) );
+
+ CALL_SUBTEST( basicStuffComplex(MatrixXcf(21, 17)) );
+ CALL_SUBTEST( basicStuffComplex(MatrixXcd(2, 3)) );
}
CALL_SUBTEST(casting());