mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-02-17 18:09:55 +08:00
Removed Column and Row in favor of Block
This commit is contained in:
parent
6da4d9d256
commit
35bce20954
@ -22,8 +22,6 @@ namespace Eigen {
|
||||
#include "src/Core/CwiseBinaryOp.h"
|
||||
#include "src/Core/CwiseUnaryOp.h"
|
||||
#include "src/Core/Product.h"
|
||||
#include "src/Core/Row.h"
|
||||
#include "src/Core/Column.h"
|
||||
#include "src/Core/Block.h"
|
||||
#include "src/Core/Minor.h"
|
||||
#include "src/Core/Transpose.h"
|
||||
|
@ -79,6 +79,24 @@ template<typename MatrixType, int BlockRows, int BlockCols> class Block
|
||||
|
||||
typedef typename MatrixType::AsArg MatRef;
|
||||
|
||||
/** Column or Row constructor
|
||||
*/
|
||||
Block(const MatRef& matrix, int i)
|
||||
: m_matrix(matrix),
|
||||
// It is a row if and only if BlockRows==1 and BlockCols==MatrixType::ColsAtCompileTime,
|
||||
// and it is a column if and only if BlockRows==MatrixType::RowsAtCompileTime and BlockCols==1,
|
||||
// all other cases are invalid.
|
||||
// The case a 1x1 matrix looks ambibuous, but the result is the same anyway.
|
||||
m_startRow( (BlockRows==1) && (BlockCols==MatrixType::ColsAtCompileTime) ? i : 0),
|
||||
m_startCol( (BlockRows==MatrixType::RowsAtCompileTime) && (BlockCols==1) ? i : 0),
|
||||
m_blockRows(matrix.rows()), // if it is a row, then m_blockRows has a fixed-size of 1, so no pb to try to overwrite it
|
||||
m_blockCols(matrix.cols()) // same for m_blockCols
|
||||
{
|
||||
assert( (i>=0) && (
|
||||
((BlockRows==1) && (BlockCols==MatrixType::ColsAtCompileTime) && i<matrix.rows())
|
||||
||((BlockRows==MatrixType::RowsAtCompileTime) && (BlockCols==1) && i<matrix.cols())));
|
||||
}
|
||||
|
||||
/** Fixed-size constructor
|
||||
*/
|
||||
Block(const MatRef& matrix, int startRow, int startCol)
|
||||
@ -354,4 +372,46 @@ const Block<Derived, BlockRows, BlockCols> MatrixBase<Derived>
|
||||
return Block<Derived, BlockRows, BlockCols>(asArg(), startRow, startCol);
|
||||
}
|
||||
|
||||
/** \returns an expression of the \a i-th column of *this. Note that the numbering starts at 0.
|
||||
*
|
||||
* Example: \include MatrixBase_col.cpp
|
||||
* Output: \verbinclude MatrixBase_col.out
|
||||
*
|
||||
* \sa row(), class Block */
|
||||
template<typename Derived>
|
||||
Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1>
|
||||
MatrixBase<Derived>::col(int i)
|
||||
{
|
||||
return Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1>(asArg(), i);
|
||||
}
|
||||
|
||||
/** This is the const version of col(). */
|
||||
template<typename Derived>
|
||||
const Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1>
|
||||
MatrixBase<Derived>::col(int i) const
|
||||
{
|
||||
return Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1>(asArg(), i);
|
||||
}
|
||||
|
||||
/** \returns an expression of the \a i-th row of *this. Note that the numbering starts at 0.
|
||||
*
|
||||
* Example: \include MatrixBase_row.cpp
|
||||
* Output: \verbinclude MatrixBase_row.out
|
||||
*
|
||||
* \sa col(), class Block */
|
||||
template<typename Derived>
|
||||
Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime>
|
||||
MatrixBase<Derived>::row(int i)
|
||||
{
|
||||
return Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime>(asArg(), i);
|
||||
}
|
||||
|
||||
/** This is the const version of row(). */
|
||||
template<typename Derived>
|
||||
const Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime>
|
||||
MatrixBase<Derived>::row(int i) const
|
||||
{
|
||||
return Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime>(asArg(), i);
|
||||
}
|
||||
|
||||
#endif // EIGEN_BLOCK_H
|
||||
|
@ -1,119 +0,0 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra. Eigen itself is part of the KDE project.
|
||||
//
|
||||
// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.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/>.
|
||||
|
||||
#ifndef EIGEN_COLUMN_H
|
||||
#define EIGEN_COLUMN_H
|
||||
|
||||
/** \class Column
|
||||
*
|
||||
* \brief Expression of a column
|
||||
*
|
||||
* \param MatrixType the type of the object in which we are taking a column
|
||||
*
|
||||
* This class represents an expression of a column. It is the return
|
||||
* type of MatrixBase::col() and most of the time this is the only way it
|
||||
* is used.
|
||||
*
|
||||
* However, if you want to directly maniputate column expressions,
|
||||
* for instance if you want to write a function returning such an expression, you
|
||||
* will need to use this class.
|
||||
*
|
||||
* Here is an example illustrating this:
|
||||
* \include class_Column.cpp
|
||||
* Output: \verbinclude class_Column.out
|
||||
*
|
||||
* \sa MatrixBase::col()
|
||||
*/
|
||||
template<typename MatrixType>
|
||||
struct ei_traits<Column<MatrixType> >
|
||||
{
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
enum {
|
||||
RowsAtCompileTime = MatrixType::RowsAtCompileTime,
|
||||
ColsAtCompileTime = 1,
|
||||
MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
|
||||
MaxColsAtCompileTime = 1
|
||||
};
|
||||
};
|
||||
|
||||
template<typename MatrixType> class Column
|
||||
: public MatrixBase<Column<MatrixType> >
|
||||
{
|
||||
public:
|
||||
|
||||
EIGEN_BASIC_PUBLIC_INTERFACE(Column)
|
||||
|
||||
typedef typename MatrixType::AsArg MatRef;
|
||||
|
||||
Column(const MatRef& matrix, int col)
|
||||
: m_matrix(matrix), m_col(col)
|
||||
{
|
||||
assert(col >= 0 && col < matrix.cols());
|
||||
}
|
||||
|
||||
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Column)
|
||||
|
||||
private:
|
||||
|
||||
const Column& _asArg() const { return *this; }
|
||||
int _rows() const { return m_matrix.rows(); }
|
||||
int _cols() const { return 1; }
|
||||
|
||||
Scalar& _coeffRef(int row, int)
|
||||
{
|
||||
return m_matrix.coeffRef(row, m_col);
|
||||
}
|
||||
|
||||
Scalar _coeff(int row, int) const
|
||||
{
|
||||
return m_matrix.coeff(row, m_col);
|
||||
}
|
||||
|
||||
protected:
|
||||
MatRef m_matrix;
|
||||
const int m_col;
|
||||
};
|
||||
|
||||
/** \returns an expression of the \a i-th column of *this. Note that the numbering starts at 0.
|
||||
*
|
||||
* Example: \include MatrixBase_col.cpp
|
||||
* Output: \verbinclude MatrixBase_col.out
|
||||
*
|
||||
* \sa row(), class Column */
|
||||
template<typename Derived>
|
||||
Column<Derived>
|
||||
MatrixBase<Derived>::col(int i)
|
||||
{
|
||||
return Column<Derived>(asArg(), i);
|
||||
}
|
||||
|
||||
/** This is the const version of col(). */
|
||||
template<typename Derived>
|
||||
const Column<Derived>
|
||||
MatrixBase<Derived>::col(int i) const
|
||||
{
|
||||
return Column<Derived>(asArg(), i);
|
||||
}
|
||||
|
||||
#endif // EIGEN_COLUMN_H
|
@ -52,8 +52,11 @@ struct MatrixBase<Derived>::CommaInitializer
|
||||
m_row+=m_currentBlockRows;
|
||||
m_col = 0;
|
||||
m_currentBlockRows = 1;
|
||||
assert(m_row<m_matrix.rows()
|
||||
&& "Too many rows passed to MatrixBase::operator<<");
|
||||
}
|
||||
assert(m_col<m_matrix.cols() && "Too many coefficients passed to Matrix::operator<<");
|
||||
assert(m_col<m_matrix.cols()
|
||||
&& "Too many coefficients passed to MatrixBase::operator<<");
|
||||
assert(m_currentBlockRows==1);
|
||||
m_matrix.coeffRef(m_row, m_col++) = s;
|
||||
return *this;
|
||||
@ -67,10 +70,17 @@ struct MatrixBase<Derived>::CommaInitializer
|
||||
m_row+=m_currentBlockRows;
|
||||
m_col = 0;
|
||||
m_currentBlockRows = other.rows();
|
||||
assert(m_row+m_currentBlockRows<=m_matrix.rows()
|
||||
&& "Too many rows passed to MatrixBase::operator<<");
|
||||
}
|
||||
assert(m_col<m_matrix.cols() && "Too many coefficients passed to Matrix::operator<<");
|
||||
assert(m_col<m_matrix.cols()
|
||||
&& "Too many coefficients passed to MatrixBase::operator<<");
|
||||
assert(m_currentBlockRows==other.rows());
|
||||
m_matrix.block(m_row, m_col, other.rows(), other.cols()) = other;
|
||||
if (OtherDerived::RowsAtCompileTime>0 && OtherDerived::ColsAtCompileTime>0)
|
||||
m_matrix.block< (OtherDerived::RowsAtCompileTime>0?OtherDerived::RowsAtCompileTime:1) ,
|
||||
(OtherDerived::ColsAtCompileTime>0?OtherDerived::ColsAtCompileTime:1) >(m_row, m_col) = other;
|
||||
else
|
||||
m_matrix.block(m_row, m_col, other.rows(), other.cols()) = other;
|
||||
m_col += other.cols();
|
||||
return *this;
|
||||
}
|
||||
|
@ -29,8 +29,6 @@ template<typename T> struct ei_traits;
|
||||
|
||||
template<typename _Scalar, int _Rows, int _Cols, int _StorageOrder, int _MaxRows, int _MaxCols> class Matrix;
|
||||
template<typename MatrixType> class MatrixRef;
|
||||
template<typename MatrixType> class Row;
|
||||
template<typename MatrixType> class Column;
|
||||
template<typename MatrixType> class Minor;
|
||||
template<typename MatrixType, int BlockRows=Dynamic, int BlockCols=Dynamic> class Block;
|
||||
template<typename MatrixType> class Transpose;
|
||||
|
@ -193,11 +193,11 @@ template<typename Derived> class MatrixBase
|
||||
|
||||
/// \name sub-matrices
|
||||
//@{
|
||||
Row<Derived> row(int i);
|
||||
const Row<Derived> row(int i) const;
|
||||
Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime> row(int i);
|
||||
const Block<Derived, 1, ei_traits<Derived>::ColsAtCompileTime> row(int i) const;
|
||||
|
||||
Column<Derived> col(int i);
|
||||
const Column<Derived> col(int i) const;
|
||||
Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1> col(int i);
|
||||
const Block<Derived, ei_traits<Derived>::RowsAtCompileTime, 1> col(int i) const;
|
||||
|
||||
Minor<Derived> minor(int row, int col);
|
||||
const Minor<Derived> minor(int row, int col) const;
|
||||
|
@ -1,120 +0,0 @@
|
||||
// This file is part of Eigen, a lightweight C++ template library
|
||||
// for linear algebra. Eigen itself is part of the KDE project.
|
||||
//
|
||||
// Copyright (C) 2006-2008 Benoit Jacob <jacob@math.jussieu.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/>.
|
||||
|
||||
#ifndef EIGEN_ROW_H
|
||||
#define EIGEN_ROW_H
|
||||
|
||||
/** \class Row
|
||||
*
|
||||
* \brief Expression of a row
|
||||
*
|
||||
* \param MatrixType the type of the object in which we are taking a row
|
||||
*
|
||||
* This class represents an expression of a row. It is the return
|
||||
* type of MatrixBase::row() and most of the time this is the only way it
|
||||
* is used.
|
||||
*
|
||||
* However, if you want to directly maniputate row expressions,
|
||||
* for instance if you want to write a function returning such an expression, you
|
||||
* will need to use this class.
|
||||
*
|
||||
* Here is an example illustrating this:
|
||||
* \include class_Row.cpp
|
||||
* Output: \verbinclude class_Row.out
|
||||
*
|
||||
* \sa MatrixBase::row()
|
||||
*/
|
||||
template<typename MatrixType>
|
||||
struct ei_traits<Row<MatrixType> >
|
||||
{
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
enum {
|
||||
RowsAtCompileTime = 1,
|
||||
ColsAtCompileTime = MatrixType::ColsAtCompileTime,
|
||||
MaxRowsAtCompileTime = 1,
|
||||
MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
|
||||
};
|
||||
};
|
||||
|
||||
template<typename MatrixType> class Row
|
||||
: public MatrixBase<Row<MatrixType> >
|
||||
{
|
||||
public:
|
||||
|
||||
EIGEN_BASIC_PUBLIC_INTERFACE(Row)
|
||||
|
||||
typedef typename MatrixType::AsArg MatRef;
|
||||
|
||||
Row(const MatRef& matrix, int row)
|
||||
: m_matrix(matrix), m_row(row)
|
||||
{
|
||||
assert(row >= 0 && row < matrix.rows());
|
||||
}
|
||||
|
||||
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Row)
|
||||
|
||||
private:
|
||||
|
||||
const Row& _asArg() const { return *this; }
|
||||
|
||||
int _rows() const { return 1; }
|
||||
int _cols() const { return m_matrix.cols(); }
|
||||
|
||||
Scalar& _coeffRef(int, int col)
|
||||
{
|
||||
return m_matrix.coeffRef(m_row, col);
|
||||
}
|
||||
|
||||
Scalar _coeff(int, int col) const
|
||||
{
|
||||
return m_matrix.coeff(m_row, col);
|
||||
}
|
||||
|
||||
protected:
|
||||
MatRef m_matrix;
|
||||
const int m_row;
|
||||
};
|
||||
|
||||
/** \returns an expression of the \a i-th row of *this. Note that the numbering starts at 0.
|
||||
*
|
||||
* Example: \include MatrixBase_row.cpp
|
||||
* Output: \verbinclude MatrixBase_row.out
|
||||
*
|
||||
* \sa col(), class Row */
|
||||
template<typename Derived>
|
||||
Row<Derived>
|
||||
MatrixBase<Derived>::row(int i)
|
||||
{
|
||||
return Row<Derived>(asArg(), i);
|
||||
}
|
||||
|
||||
/** This is the const version of row(). */
|
||||
template<typename Derived>
|
||||
const Row<Derived>
|
||||
MatrixBase<Derived>::row(int i) const
|
||||
{
|
||||
return Row<Derived>(asArg(), i);
|
||||
}
|
||||
|
||||
#endif // EIGEN_ROW_H
|
@ -1,12 +1,21 @@
|
||||
#!/bin/bash
|
||||
|
||||
CLIST[((g++))]="g++-4.1 -O3 -DNDEBUG"
|
||||
# CLIST[((g++))]="g++-3.4 -O3 -DNDEBUG"
|
||||
# CLIST[((g++))]="g++-3.4 -O3 -DNDEBUG -finline-limit=20000"
|
||||
|
||||
# CLIST[((g++))]="g++-4.1 -O3 -DNDEBUG"
|
||||
CLIST[((g++))]="g++-4.1 -O3 -DNDEBUG -finline-limit=20000"
|
||||
|
||||
CLIST[((g++))]="g++-4.2 -O3 -DNDEBUG"
|
||||
# CLIST[((g++))]="g++-4.2 -O3 -DNDEBUG"
|
||||
CLIST[((g++))]="g++-4.2 -O3 -DNDEBUG -finline-limit=20000"
|
||||
# CLIST[((g++))]="g++-4.2 -O3 -DNDEBUG -finline-limit=20000 -fprofile-generate"
|
||||
# CLIST[((g++))]="g++-4.2 -O3 -DNDEBUG -finline-limit=20000 -fprofile-use"
|
||||
|
||||
CLIST[((g++))]="g++-4.3 -O3 -DNDEBUG"
|
||||
# CLIST[((g++))]="g++-4.3 -O3 -DNDEBUG"
|
||||
CLIST[((g++))]="g++-4.3 -O3 -DNDEBUG -finline-limit=20000"
|
||||
# CLIST[((g++))]="g++-4.3 -O3 -DNDEBUG -finline-limit=20000 -fprofile-generate"
|
||||
# CLIST[((g++))]="g++-4.3 -O3 -DNDEBUG -finline-limit=20000 -fprofile-use"
|
||||
|
||||
CLIST[((g++))]="icpc -fast -DNDEBUG -fno-exceptions -no-inline-max-size"
|
||||
# CLIST[((g++))]="icpc -fast -DNDEBUG -fno-exceptions -no-inline-max-size"
|
||||
# CLIST[((g++))]="icpc -fast -DNDEBUG -fno-exceptions -no-inline-max-size -prof-genx"
|
||||
# CLIST[((g++))]="icpc -fast -DNDEBUG -fno-exceptions -no-inline-max-size -prof-use"
|
@ -17,7 +17,7 @@ for (( i=0 ; i<g ; ++i )) ; do
|
||||
if [ -e `which $compiler` ]; then
|
||||
echo "${CLIST[$i]}"
|
||||
# echo "${CLIST[$i]} $benchfile -I.. -o bench~"
|
||||
if [ -e ./.bench ] ; then rm .bench; fi
|
||||
# if [ -e ./.bench ] ; then rm .bench; fi
|
||||
${CLIST[$i]} $benchfile -I.. -o .bench && ./.bench 2> /dev/null
|
||||
echo ""
|
||||
else
|
||||
|
@ -3,17 +3,17 @@ USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace std;
|
||||
|
||||
template<typename Derived>
|
||||
Eigen::Column<Derived>
|
||||
Eigen::Block<Derived,Derived::RowsAtCompileTime,1>
|
||||
firstColumn(MatrixBase<Derived>& m)
|
||||
{
|
||||
return Eigen::Column<Derived>(m.asArg(), 0);
|
||||
return typename Eigen::Block<Derived,Derived::RowsAtCompileTime,1>(m.asArg(), 0);
|
||||
}
|
||||
|
||||
template<typename Derived>
|
||||
const Eigen::Column<Derived>
|
||||
const Eigen::Block<Derived,Derived::RowsAtCompileTime,1>
|
||||
firstColumn(const MatrixBase<Derived>& m)
|
||||
{
|
||||
return Eigen::Column<Derived>(m.asArg(), 0);
|
||||
return typename Eigen::Block<Derived,Derived::RowsAtCompileTime,1>(m.asArg(), 0);
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
|
@ -3,17 +3,17 @@ USING_PART_OF_NAMESPACE_EIGEN
|
||||
using namespace std;
|
||||
|
||||
template<typename Derived>
|
||||
Eigen::Row<Derived>
|
||||
Eigen::Block<Derived,1,Derived::ColsAtCompileTime>
|
||||
firstRow(MatrixBase<Derived>& m)
|
||||
{
|
||||
return Eigen::Row<Derived>(m.asArg(), 0);
|
||||
return Eigen::Block<Derived,1,Derived::ColsAtCompileTime>(m.asArg(), 0);
|
||||
}
|
||||
|
||||
template<typename Derived>
|
||||
const Eigen::Row<Derived>
|
||||
const Eigen::Block<Derived,1,Derived::ColsAtCompileTime>
|
||||
firstRow(const MatrixBase<Derived>& m)
|
||||
{
|
||||
return Eigen::Row<Derived>(m.asArg(), 0);
|
||||
return Eigen::Block<Derived,1,Derived::ColsAtCompileTime>(m.asArg(), 0);
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
|
@ -1,7 +1,7 @@
|
||||
typedef Matrix3i MyMatrixType;
|
||||
MyMatrixType m = MyMatrixType::random(3, 3);
|
||||
cout << "Here's the matrix m:" << endl << m << endl;
|
||||
typedef Eigen::Eval<Eigen::Row<MyMatrixType> >::MatrixType MyRowType;
|
||||
typedef Eigen::Eval<Eigen::Block<MyMatrixType,1,MyMatrixType::ColsAtCompileTime> >::MatrixType MyRowType;
|
||||
// now MyRowType is just the same typedef as RowVector3i
|
||||
MyRowType r = m.row(0);
|
||||
cout << "Here's r:" << endl << r << endl;
|
||||
|
@ -5,12 +5,12 @@
|
||||
//
|
||||
// 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
|
||||
// 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
|
||||
// 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
|
||||
@ -18,7 +18,7 @@
|
||||
// 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
|
||||
// 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/>.
|
||||
|
||||
@ -27,13 +27,13 @@
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
|
||||
bool has_set_repeat = false;
|
||||
bool has_set_seed = false;
|
||||
bool need_help = false;
|
||||
unsigned int seed;
|
||||
int repeat;
|
||||
|
||||
|
||||
QStringList args = QCoreApplication::instance()->arguments();
|
||||
args.takeFirst(); // throw away the first argument (path to executable)
|
||||
foreach(QString arg, args)
|
||||
@ -74,7 +74,7 @@ int main(int argc, char *argv[])
|
||||
need_help = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(need_help)
|
||||
{
|
||||
qDebug() << "This test application takes the following optional arguments:";
|
||||
@ -82,10 +82,10 @@ int main(int argc, char *argv[])
|
||||
qDebug() << " sN Use N as seed for random numbers (default: based on current time)";
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if(!has_set_seed) seed = (unsigned int) time(NULL);
|
||||
if(!has_set_repeat) repeat = DEFAULT_REPEAT;
|
||||
|
||||
|
||||
qDebug() << "Initializing random number generator with seed" << seed;
|
||||
srand(seed);
|
||||
qDebug() << "Repeating each test" << repeat << "times";
|
||||
|
19
test/main.h
19
test/main.h
@ -29,6 +29,7 @@
|
||||
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
|
||||
#define DEFAULT_REPEAT 50
|
||||
|
||||
@ -36,9 +37,14 @@
|
||||
|
||||
namespace Eigen
|
||||
{
|
||||
struct ei_assert_exception
|
||||
{};
|
||||
static const bool should_raise_an_assert = false;
|
||||
|
||||
// Used to avoid to raise two exceptions at the time in which
|
||||
// case the exception is not properly catched.
|
||||
// This may happen when a second exceptions is raise in a destructor.
|
||||
static bool no_more_assert = false;
|
||||
|
||||
struct ei_assert_exception {};
|
||||
}
|
||||
|
||||
#define EI_PP_MAKE_STRING2(S) #S
|
||||
@ -64,7 +70,7 @@
|
||||
}
|
||||
|
||||
#define assert(a) if (!(a)) { throw Eigen::ei_assert_exception();} \
|
||||
else if (Eigen::ei_push_assert) {ei_assert_list.push_back( std::string(EI_PP_MAKE_STRING(__FILE__)) + " (" + EI_PP_MAKE_STRING(__LINE__) + ") : " + #a );}
|
||||
else if (Eigen::ei_push_assert) {ei_assert_list.push_back( std::string(EI_PP_MAKE_STRING(__FILE__)" ("EI_PP_MAKE_STRING(__LINE__)") : "#a) );}
|
||||
|
||||
#define VERIFY_RAISES_ASSERT(a) {\
|
||||
try { \
|
||||
@ -80,10 +86,13 @@
|
||||
|
||||
#else // EIGEN_DEBUG_ASSERTS
|
||||
|
||||
#define assert(a) if (!(a)) { throw Eigen::ei_assert_exception();}
|
||||
#define assert(a) if( (!(a)) && (!no_more_assert) ) { \
|
||||
Eigen::no_more_assert = true; \
|
||||
throw Eigen::ei_assert_exception(); \
|
||||
}
|
||||
|
||||
#define VERIFY_RAISES_ASSERT(a) {\
|
||||
try {a; QVERIFY(Eigen::should_raise_an_assert && # a); } \
|
||||
try { a; QVERIFY(Eigen::should_raise_an_assert && # a); } \
|
||||
catch (Eigen::ei_assert_exception e) { QVERIFY(true);} }
|
||||
|
||||
#endif // EIGEN_DEBUG_ASSERTS
|
||||
|
Loading…
Reference in New Issue
Block a user