More Index related stuff.

This commit is contained in:
Hauke Heibel 2010-06-21 11:36:00 +02:00
parent 5f65a89f49
commit dc6ad5e25b
12 changed files with 36 additions and 30 deletions

View File

@ -77,6 +77,7 @@ template<typename PlainObjectType, int MapOptions, typename StrideType>
struct ei_traits<Map<PlainObjectType, MapOptions, StrideType> >
: public ei_traits<PlainObjectType>
{
typedef typename PlainObjectType::Index Index;
typedef typename PlainObjectType::Scalar Scalar;
enum {
InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0

View File

@ -55,7 +55,7 @@ template<int _OuterStrideAtCompileTime, int _InnerStrideAtCompileTime>
class Stride
{
public:
typedef DenseIndex Index;
enum {
InnerStrideAtCompileTime = _InnerStrideAtCompileTime,
OuterStrideAtCompileTime = _OuterStrideAtCompileTime
@ -69,7 +69,7 @@ class Stride
}
/** Constructor allowing to pass the strides at runtime */
Stride(int outerStride, int innerStride)
Stride(Index outerStride, Index innerStride)
: m_outer(outerStride), m_inner(innerStride)
{
ei_assert(innerStride>=0 && outerStride>=0);
@ -81,13 +81,13 @@ class Stride
{}
/** \returns the outer stride */
inline int outer() const { return m_outer.value(); }
inline Index outer() const { return m_outer.value(); }
/** \returns the inner stride */
inline int inner() const { return m_inner.value(); }
inline Index inner() const { return m_inner.value(); }
protected:
ei_variable_if_dynamic<int, OuterStrideAtCompileTime> m_outer;
ei_variable_if_dynamic<int, InnerStrideAtCompileTime> m_inner;
ei_variable_if_dynamic<Index, OuterStrideAtCompileTime> m_outer;
ei_variable_if_dynamic<Index, InnerStrideAtCompileTime> m_inner;
};
/** \brief Convenience specialization of Stride to specify only an inner stride */
@ -96,8 +96,9 @@ class InnerStride : public Stride<0, Value>
{
typedef Stride<0, Value> Base;
public:
typedef DenseIndex Index;
InnerStride() : Base() {}
InnerStride(int v) : Base(0, v) {}
InnerStride(Index v) : Base(0, v) {}
};
/** \brief Convenience specialization of Stride to specify only an outer stride */
@ -106,8 +107,9 @@ class OuterStride : public Stride<Value, 0>
{
typedef Stride<Value, 0> Base;
public:
typedef DenseIndex Index;
OuterStride() : Base() {}
OuterStride(int v) : Base(v,0) {}
OuterStride(Index v) : Base(v,0) {}
};
#endif // EIGEN_STRIDE_H

View File

@ -50,8 +50,8 @@ template<typename MatrixType> void basicStuff(const MatrixType& m)
Scalar x = ei_random<Scalar>();
int r = ei_random<int>(0, rows-1),
c = ei_random<int>(0, cols-1);
Index r = ei_random<Index>(0, rows-1),
c = ei_random<Index>(0, cols-1);
m1.coeffRef(r,c) = x;
VERIFY_IS_APPROX(x, m1.coeff(r,c));

View File

@ -60,8 +60,8 @@ template<typename MatrixType> void cwiseops(const MatrixType& m)
vones = VectorType::Ones(rows),
v3(rows);
int r = ei_random<int>(0, rows-1),
c = ei_random<int>(0, cols-1);
Index r = ei_random<Index>(0, rows-1),
c = ei_random<Index>(0, cols-1);
Scalar s1 = ei_random<Scalar>();

View File

@ -31,7 +31,8 @@ template<typename MatrixType> void determinant(const MatrixType& m)
/* this test covers the following files:
Determinant.h
*/
int size = m.rows();
typedef typename MatrixType::Index Index;
Index size = m.rows();
MatrixType m1(size, size), m2(size, size);
m1.setRandom();
@ -41,10 +42,10 @@ template<typename MatrixType> void determinant(const MatrixType& m)
VERIFY_IS_APPROX(MatrixType::Identity(size, size).determinant(), Scalar(1));
VERIFY_IS_APPROX((m1*m2).eval().determinant(), m1.determinant() * m2.determinant());
if(size==1) return;
int i = ei_random<int>(0, size-1);
int j;
Index i = ei_random<Index>(0, size-1);
Index j;
do {
j = ei_random<int>(0, size-1);
j = ei_random<Index>(0, size-1);
} while(j==i);
m2 = m1;
m2.row(i).swap(m2.row(j));

View File

@ -66,8 +66,8 @@ template<typename MatrixType> void diagonalmatrices(const MatrixType& m)
sq_m1.transpose() = ldm1;
VERIFY_IS_APPROX(sq_m1, ldm1.toDenseMatrix());
int i = ei_random<int>(0, rows-1);
int j = ei_random<int>(0, cols-1);
Index i = ei_random<Index>(0, rows-1);
Index j = ei_random<Index>(0, cols-1);
VERIFY_IS_APPROX( ((ldm1 * m1)(i,j)) , ldm1.diagonal()(i) * m1(i,j) );
VERIFY_IS_APPROX( ((ldm1 * (m1+m2))(i,j)) , ldm1.diagonal()(i) * (m1+m2)(i,j) );

View File

@ -35,8 +35,8 @@ template<typename BoxType> void alignedbox(const BoxType& _box)
/* this test covers the following files:
AlignedBox.h
*/
const int dim = _box.dim();
typedef typename BoxType::Index Index;
const Index dim = _box.dim();
typedef typename BoxType::Scalar Scalar;
typedef typename NumTraits<Scalar>::Real RealScalar;
typedef Matrix<Scalar, BoxType::AmbientDimAtCompileTime, 1> VectorType;

View File

@ -33,8 +33,8 @@ template<typename HyperplaneType> void hyperplane(const HyperplaneType& _plane)
/* this test covers the following files:
Hyperplane.h
*/
const int dim = _plane.dim();
typedef typename HyperplaneType::Index Index;
const Index dim = _plane.dim();
typedef typename HyperplaneType::Scalar Scalar;
typedef typename NumTraits<Scalar>::Real RealScalar;
typedef Matrix<Scalar, HyperplaneType::AmbientDimAtCompileTime, 1> VectorType;

View File

@ -33,8 +33,8 @@ template<typename LineType> void parametrizedline(const LineType& _line)
/* this test covers the following files:
ParametrizedLine.h
*/
const int dim = _line.dim();
typedef typename LineType::Index Index;
const Index dim = _line.dim();
typedef typename LineType::Scalar Scalar;
typedef typename NumTraits<Scalar>::Real RealScalar;
typedef Matrix<Scalar, LineType::AmbientDimAtCompileTime, 1> VectorType;

View File

@ -45,8 +45,8 @@ template<typename MatrixType> void linearStructure(const MatrixType& m)
Scalar s1 = ei_random<Scalar>();
while (ei_abs(s1)<1e-3) s1 = ei_random<Scalar>();
int r = ei_random<int>(0, rows-1),
c = ei_random<int>(0, cols-1);
Index r = ei_random<Index>(0, rows-1),
c = ei_random<Index>(0, cols-1);
VERIFY_IS_APPROX(-(-m1), m1);
VERIFY_IS_APPROX(m1+m1, 2*m1);

View File

@ -82,9 +82,10 @@ template<typename MatrixType> void map_class_matrix(const MatrixType& m)
template<typename VectorType> void map_static_methods(const VectorType& m)
{
typedef typename VectorType::Index Index;
typedef typename VectorType::Scalar Scalar;
int size = m.size();
Index size = m.size();
// test Map.h
Scalar* array1 = ei_aligned_new<Scalar>(size);

View File

@ -26,13 +26,14 @@
template<typename VectorType> void map_class_vector(const VectorType& m)
{
typedef typename VectorType::Index Index;
typedef typename VectorType::Scalar Scalar;
int size = m.size();
Index size = m.size();
VectorType v = VectorType::Random(size);
int arraysize = 3*size;
Index arraysize = 3*size;
Scalar* array = ei_aligned_new<Scalar>(arraysize);
@ -68,7 +69,7 @@ template<typename MatrixType> void map_class_matrix(const MatrixType& _m)
MatrixType m = MatrixType::Random(rows,cols);
int arraysize = 2*(rows+4)*(cols+4);
Index arraysize = 2*(rows+4)*(cols+4);
Scalar* array = ei_aligned_new<Scalar>(arraysize);