*patch by Daniel Gomez:

- bugfix in SparseMatrix
 - add a sparse unit test
* renamed Transform::affine => linear
This commit is contained in:
Gael Guennebaud
2008-08-21 17:02:47 +00:00
parent 082e309d2a
commit 60804c306d
6 changed files with 101 additions and 30 deletions

View File

@@ -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)

View File

@@ -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() );
}

65
test/sparse.cpp Normal file
View File

@@ -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) );
}
}
}