aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2008-08-21 17:02:47 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2008-08-21 17:02:47 +0000
commit60804c306dd9ad42e82402f25d31587cf749f3bb (patch)
treeaba825cbe3977922fe0e05c230bb03e4b2768935 /test
parent082e309d2a2c7da1e63586c5d115eceec8ccbf5e (diff)
*patch by Daniel Gomez:
- bugfix in SparseMatrix - add a sparse unit test * renamed Transform::affine => linear
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt1
-rw-r--r--test/geometry.cpp12
-rw-r--r--test/sparse.cpp65
3 files changed, 72 insertions, 6 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index e0f6f2664..8d217d421 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -111,5 +111,6 @@ EI_ADD_TEST(geometry)
EI_ADD_TEST(regression)
EI_ADD_TEST(svd)
EI_ADD_TEST(ioformat)
+EI_ADD_TEST(sparse)
ENDIF(BUILD_TESTS)
diff --git a/test/geometry.cpp b/test/geometry.cpp
index a41a26c23..2aad9dda3 100644
--- a/test/geometry.cpp
+++ b/test/geometry.cpp
@@ -117,9 +117,9 @@ template<typename Scalar> void geometry(void)
q1 = AngleAxis(a, v0.normalized());
Transform3 t0, t1, t2;
t0.setIdentity();
- t0.affine() = q1.toRotationMatrix();
+ t0.linear() = q1.toRotationMatrix();
t1.setIdentity();
- t1.affine() = q1.toRotationMatrix();
+ t1.linear() = q1.toRotationMatrix();
v0 << 50, 2, 1;//= Vector3::Random().cwiseProduct(Vector3(10,2,0.5));
t0.scale(v0);
@@ -131,10 +131,10 @@ template<typename Scalar> void geometry(void)
t0.setIdentity();
t1.setIdentity();
v1 << 1, 2, 3;
- t0.affine() = q1.toRotationMatrix();
+ t0.linear() = q1.toRotationMatrix();
t0.pretranslate(v0);
t0.scale(v1);
- t1.affine() = q1.conjugate().toRotationMatrix();
+ t1.linear() = q1.conjugate().toRotationMatrix();
t1.prescale(v1.cwise().inverse());
t1.translate(-v0);
@@ -148,12 +148,12 @@ template<typename Scalar> void geometry(void)
Vector2 v20 = Vector2::Random();
Vector2 v21 = Vector2::Random();
t21.setIdentity();
- t21.affine() = Rotation2D<Scalar>(a).toRotationMatrix();
+ t21.linear() = Rotation2D<Scalar>(a).toRotationMatrix();
VERIFY_IS_APPROX(t20.fromPositionOrientationScale(v20,a,v21).matrix(),
t21.pretranslate(v20).scale(v21).matrix());
t21.setIdentity();
- t21.affine() = Rotation2D<Scalar>(-a).toRotationMatrix();
+ t21.linear() = Rotation2D<Scalar>(-a).toRotationMatrix();
VERIFY( (t20.fromPositionOrientationScale(v20,a,v21) * (t21.prescale(v21.cwise().inverse()).translate(-v20))).isIdentity() );
}
diff --git a/test/sparse.cpp b/test/sparse.cpp
new file mode 100644
index 000000000..c86697712
--- /dev/null
+++ b/test/sparse.cpp
@@ -0,0 +1,65 @@
+// This file is part of Eigen, a lightweight C++ template library
+// for linear algebra. Eigen itself is part of the KDE project.
+//
+// Copyright (C) 2008 Daniel Gomez Ferro <dgomezferro@gmail.com>
+//
+// Eigen is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 3 of the License, or (at your option) any later version.
+//
+// Alternatively, you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License and a copy of the GNU General Public License along with
+// Eigen. If not, see <http://www.gnu.org/licenses/>.
+
+#include "main.h"
+#include <Eigen/Sparse>
+
+void test_sparse()
+{
+ int rows = 4, cols = 4;
+ SparseMatrix<double> m(rows, cols);
+
+ m.startFill(rows);
+ m.fill(0, 2) = 2;
+ m.fill(1, 2) = 1;
+ m.fill(0, 3) = 5;
+ m.endFill();
+
+ m.coeffRef(0, 2) = 3;
+ VERIFY_RAISES_ASSERT( m.coeffRef(0, 0) = 5 );
+ VERIFY_IS_MUCH_SMALLER_THAN( m.coeff(0, 0), 0.000001 );
+ VERIFY_IS_MUCH_SMALLER_THAN( m.coeff(0, 1), 0.000001 );
+ VERIFY_IS_MUCH_SMALLER_THAN( m.coeff(2, 1), 0.000001 );
+ VERIFY_IS_APPROX( m.coeff(0, 2), 3.0 );
+ VERIFY_IS_APPROX( m.coeff(1, 2), 1.0 );
+ VERIFY_IS_APPROX( m.coeff(0, 3), 5.0 );
+
+ Matrix4d dm;
+ double r;
+ m.startFill(rows*cols);
+ for(int i=0; i<cols; i++) {
+ for(int j=0; j<rows; j++) {
+ r = rand();
+ m.fill(j, i) = r;
+ dm(j, i) = r;
+ }
+ }
+ m.endFill();
+
+ for(int i=0; i<cols; i++) {
+ for(int j=0; j<rows; j++) {
+ VERIFY_IS_APPROX( m.coeff(j, i), dm(j, i) );
+ }
+ }
+}