big addons:

* add Homogeneous expression for vector and set of vectors (aka matrix)
  => the next step will be to overload operator*
* add homogeneous normalization (again for vector and set of vectors)
* add a Replicate expression (with uni-directional replication
  facilities)
=> for all of them I'll add examples once we agree on the API
* fix gcc-4.4 warnings
* rename reverse.cpp array_reverse.cpp
This commit is contained in:
Gael Guennebaud
2009-03-05 10:25:22 +00:00
parent d710ccd41e
commit 0be89a4796
20 changed files with 623 additions and 75 deletions

View File

@@ -105,6 +105,8 @@ ei_add_test(commainitializer)
ei_add_test(smallvectors)
ei_add_test(map)
ei_add_test(array)
ei_add_test(array_replicate)
ei_add_test(array_reverse)
ei_add_test(triangular)
ei_add_test(cholesky " " "${GSL_LIBRARIES}")
ei_add_test(lu ${EI_OFLAG})
@@ -114,6 +116,7 @@ ei_add_test(qr)
ei_add_test(eigensolver " " "${GSL_LIBRARIES}")
ei_add_test(svd)
ei_add_test(geo_orthomethods)
ei_add_test(geo_homogeneous)
ei_add_test(geo_quaternion)
ei_add_test(geo_transformations)
ei_add_test(geo_eulerangles)
@@ -135,7 +138,6 @@ ei_add_test(sparse_vector)
ei_add_test(sparse_basic)
ei_add_test(sparse_product)
ei_add_test(sparse_solvers " " "${SPARSE_LIBS}")
ei_add_test(reverse)
ei_add_property(EIGEN_TESTING_SUMMARY "CXX: ${CMAKE_CXX_COMPILER}\n")

86
test/array_replicate.cpp Normal file
View File

@@ -0,0 +1,86 @@
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra. Eigen itself is part of the KDE project.
//
// Copyright (C) 2009 Gael Guennebaud <g.gael@free.fr>
//
// 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/Array>
template<typename MatrixType> void replicate(const MatrixType& m)
{
/* this test covers the following files:
Replicate.cpp
*/
typedef typename MatrixType::Scalar Scalar;
typedef typename NumTraits<Scalar>::Real RealScalar;
typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, 1> VectorType;
typedef Matrix<Scalar, Dynamic, Dynamic> MatrixX;
typedef Matrix<Scalar, Dynamic, 1> VectorX;
int rows = m.rows();
int cols = m.cols();
MatrixType m1 = MatrixType::Random(rows, cols),
m2 = MatrixType::Random(rows, cols);
VectorType v1 = VectorType::Random(rows);
MatrixX x1, x2;
VectorX vx1;
int f1 = ei_random<int>(1,10),
f2 = ei_random<int>(1,10);
x1.resize(rows*f1,cols*f2);
for(int j=0; j<f2; j++)
for(int i=0; i<f1; i++)
x1.block(i*rows,j*cols,rows,cols) = m1;
VERIFY_IS_APPROX(x1, m1.replicate(f1,f2));
x2.resize(2*rows,3*cols);
x2 << m2, m2, m2,
m2, m2, m2;
VERIFY_IS_APPROX(x2, (m2.template replicate<2,3>()));
x2.resize(rows,f1);
for (int j=0; j<f1; ++j)
x2.col(j) = v1;
VERIFY_IS_APPROX(x2, v1.rowwise().replicate(f1));
vx1.resize(rows*f2);
for (int j=0; j<f2; ++j)
vx1.segment(j*rows,rows) = v1;
VERIFY_IS_APPROX(vx1, v1.colwise().replicate(f2));
}
void test_array_replicate()
{
for(int i = 0; i < g_repeat; i++) {
CALL_SUBTEST( replicate(Matrix<float, 1, 1>()) );
CALL_SUBTEST( replicate(Vector2f()) );
CALL_SUBTEST( replicate(Vector3d()) );
CALL_SUBTEST( replicate(Vector4f()) );
CALL_SUBTEST( replicate(VectorXf(16)) );
CALL_SUBTEST( replicate(VectorXcd(10)) );
}
}

View File

@@ -160,7 +160,7 @@ template<typename MatrixType> void reverse(const MatrixType& m)
*/
}
void test_reverse()
void test_array_reverse()
{
for(int i = 0; i < g_repeat; i++) {
CALL_SUBTEST( reverse(Matrix<float, 1, 1>()) );

79
test/geo_homogeneous.cpp Normal file
View File

@@ -0,0 +1,79 @@
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra. Eigen itself is part of the KDE project.
//
// Copyright (C) 2009 Gael Guennebaud <g.gael@free.fr>
//
// 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/Geometry>
template<typename Scalar,int Size> void homogeneous(void)
{
/* this test covers the following files:
Homogeneous.h
*/
typedef Matrix<Scalar,Size,Size> MatrixType;
typedef Matrix<Scalar,Size,1> VectorType;
typedef Matrix<Scalar,Size+1,Size> HMatrixType;
typedef Matrix<Scalar,Size+1,1> HVectorType;
Scalar largeEps = test_precision<Scalar>();
if (ei_is_same_type<Scalar,float>::ret)
largeEps = 1e-3f;
Scalar eps = ei_random<Scalar>() * 1e-2;
VectorType v0 = VectorType::Random(),
v1 = VectorType::Random(),
ones = VectorType::Ones();
HVectorType hv0 = HVectorType::Random(),
hv1 = HVectorType::Random();
MatrixType m0 = MatrixType::Random(),
m1 = MatrixType::Random();
HMatrixType hm0 = HMatrixType::Random(),
hm1 = HMatrixType::Random();
hv0 << v0, 1;
VERIFY_IS_APPROX(v0.homogeneous(), hv0);
VERIFY_IS_APPROX(v0, hv0.hnormalized());
hm0 << m0, ones.transpose();
VERIFY_IS_APPROX(m0.colwise().homogeneous(), hm0);
VERIFY_IS_APPROX(m0, hm0.colwise().hnormalized());
hm0.row(Size-1).setRandom();
for(int j=0; j<Size; ++j)
m0.col(j) = hm0.col(j).start(Size) / hm0(Size,j);
VERIFY_IS_APPROX(m0, hm0.colwise().hnormalized());
}
void test_geo_homogeneous()
{
for(int i = 0; i < g_repeat; i++) {
CALL_SUBTEST(( homogeneous<float,1>() ));
CALL_SUBTEST(( homogeneous<double,3>() ));
CALL_SUBTEST(( homogeneous<double,8>() ));
}
}

View File

@@ -137,8 +137,8 @@ template<typename Scalar> void packetmath()
ref[0] = data1[0];
for (int i=0; i<PacketSize; ++i)
ref[0] = std::min(ref[0],data1[i]);
VERIFY(ei_isApprox(ref[0], ei_predux_min(ei_pload(data1))) && "ei_predux_max");
ref[0] = std::max(ref[0],data1[i]);
VERIFY(ei_isApprox(ref[0], ei_predux_max(ei_pload(data1))) && "ei_predux_max");
for (int j=0; j<PacketSize; ++j)
{