1) remove EIGEN_UNUSED, instead use non-named arguments.

2) use T instead of const T& when that makes more sense
Thanks to Christian Mayer a.k.a Mekhzolan for the tips.
This commit is contained in:
Benoit Jacob 2007-12-11 15:25:43 +00:00
parent 0cbdaf6bb8
commit fa8009c6b7
11 changed files with 55 additions and 119 deletions

View File

@ -53,15 +53,13 @@ template<typename MatrixType> class Column
int _rows() const { return m_matrix.rows(); }
int _cols() const { return 1; }
Scalar& _write(int row, int col)
Scalar& _write(int row, int)
{
EIGEN_UNUSED(col);
return m_matrix.write(row, m_col);
}
Scalar _read(int row, int col) const
Scalar _read(int row, int) const
{
EIGEN_UNUSED(col);
return m_matrix.read(row, m_col);
}

View File

@ -48,24 +48,14 @@ struct DotUnroller<0, Size, Derived1, Derived2>
template<int Index, typename Derived1, typename Derived2>
struct DotUnroller<Index, Dynamic, Derived1, Derived2>
{
static void run(const Derived1 &v1, const Derived2& v2, typename Derived1::Scalar &dot)
{
EIGEN_UNUSED(v1);
EIGEN_UNUSED(v2);
EIGEN_UNUSED(dot);
}
static void run(const Derived1&, const Derived2&, typename Derived1::Scalar&) {}
};
// prevent buggy user code from causing an infinite recursion
template<int Index, typename Derived1, typename Derived2>
struct DotUnroller<Index, 0, Derived1, Derived2>
{
static void run(const Derived1 &v1, const Derived2& v2, typename Derived1::Scalar &dot)
{
EIGEN_UNUSED(v1);
EIGEN_UNUSED(v2);
EIGEN_UNUSED(dot);
}
static void run(const Derived1&, const Derived2&, typename Derived1::Scalar&) {}
};
template<typename Scalar, typename Derived>

View File

@ -50,13 +50,9 @@ class MatrixStorage
public:
MatrixStorage() {}
MatrixStorage(int dim) { EIGEN_UNUSED(dim); }
MatrixStorage(int) {}
MatrixStorage(int rows, int cols)
{
EIGEN_UNUSED(rows);
EIGEN_UNUSED(cols);
}
MatrixStorage(int, int) {}
~MatrixStorage() {};
};
@ -92,9 +88,8 @@ class MatrixStorage<Scalar, Dynamic, ColsAtCompileTime>
m_array = new Scalar[m_rows * ColsAtCompileTime];
}
MatrixStorage(int rows, int cols) : m_rows(rows)
MatrixStorage(int rows, int) : m_rows(rows)
{
EIGEN_UNUSED(cols);
m_array = new Scalar[m_rows * ColsAtCompileTime];
}
@ -136,9 +131,8 @@ class MatrixStorage<Scalar, RowsAtCompileTime, Dynamic>
m_array = new Scalar[m_cols * RowsAtCompileTime];
}
MatrixStorage(int rows, int cols) : m_cols(cols)
MatrixStorage(int, int cols) : m_cols(cols)
{
EIGEN_UNUSED(rows);
m_array = new Scalar[m_cols * RowsAtCompileTime];
}

View File

@ -57,25 +57,24 @@ template<typename _Real> struct NumTraits<std::complex<_Real> >
};
template<typename T> inline typename NumTraits<T>::Real precision();
template<typename T> inline T random(const T& a, const T& b);
template<typename T> inline T random(T a, T b);
template<typename T> inline T random();
template<> inline int precision<int>() { return 0; }
inline int real(const int& x) { return x; }
inline int imag(const int& x) { EIGEN_UNUSED(x); return 0; }
inline int conj(const int& x) { return x; }
inline int abs(const int& x) { return std::abs(x); }
inline int abs2(const int& x) { return x*x; }
inline int sqrt(const int& x)
inline int real(int x) { return x; }
inline int imag(int) { return 0; }
inline int conj(int x) { return x; }
inline int abs(int x) { return std::abs(x); }
inline int abs2(int x) { return x*x; }
inline int sqrt(int)
{
EIGEN_UNUSED(x);
// Taking the square root of integers is not allowed
// (the square root does not always exist within the integers).
// Please cast to a floating-point type.
assert(false);
return 0;
}
template<> inline int random(const int& a, const int& b)
template<> inline int random(int a, int b)
{
// We can't just do rand()%n as only the high-order bits are really random
return a + static_cast<int>((b-a+1) * (rand() / (RAND_MAX + 1.0)));
@ -87,31 +86,27 @@ template<> inline int random()
// as well, so there's no problem.
return random<int>(-10, 10);
}
inline bool isMuchSmallerThan(const int& a, const int& b, const int& prec = precision<int>())
inline bool isMuchSmallerThan(int a, int, int = precision<int>())
{
EIGEN_UNUSED(b);
EIGEN_UNUSED(prec);
return a == 0;
}
inline bool isApprox(const int& a, const int& b, const int& prec = precision<int>())
inline bool isApprox(int a, int b, int = precision<int>())
{
EIGEN_UNUSED(prec);
return a == b;
}
inline bool isApproxOrLessThan(const int& a, const int& b, const int& prec = precision<int>())
inline bool isApproxOrLessThan(int a, int b, int = precision<int>())
{
EIGEN_UNUSED(prec);
return a <= b;
}
template<> inline float precision<float>() { return 1e-5f; }
inline float real(const float& x) { return x; }
inline float imag(const float& x) { EIGEN_UNUSED(x); return 0.f; }
inline float conj(const float& x) { return x; }
inline float abs(const float& x) { return std::abs(x); }
inline float abs2(const float& x) { return x*x; }
inline float sqrt(const float& x) { return std::sqrt(x); }
template<> inline float random(const float& a, const float& b)
inline float real(float x) { return x; }
inline float imag(float) { return 0.f; }
inline float conj(float x) { return x; }
inline float abs(float x) { return std::abs(x); }
inline float abs2(float x) { return x*x; }
inline float sqrt(float x) { return std::sqrt(x); }
template<> inline float random(float a, float b)
{
return a + (b-a) * std::rand() / RAND_MAX;
}
@ -119,27 +114,27 @@ template<> inline float random()
{
return random<float>(-10.0f, 10.0f);
}
inline bool isMuchSmallerThan(const float& a, const float& b, const float& prec = precision<float>())
inline bool isMuchSmallerThan(float a, float b, float prec = precision<float>())
{
return std::abs(a) <= std::abs(b) * prec;
}
inline bool isApprox(const float& a, const float& b, const float& prec = precision<float>())
inline bool isApprox(float a, float b, float prec = precision<float>())
{
return std::abs(a - b) <= std::min(std::abs(a), std::abs(b)) * prec;
}
inline bool isApproxOrLessThan(const float& a, const float& b, const float& prec = precision<float>())
inline bool isApproxOrLessThan(float a, float b, float prec = precision<float>())
{
return a <= b || isApprox(a, b, prec);
}
template<> inline double precision<double>() { return 1e-11; }
inline double real(const double& x) { return x; }
inline double imag(const double& x) { EIGEN_UNUSED(x); return 0.; }
inline double conj(const double& x) { return x; }
inline double abs(const double& x) { return std::abs(x); }
inline double abs2(const double& x) { return x*x; }
inline double sqrt(const double& x) { return std::sqrt(x); }
template<> inline double random(const double& a, const double& b)
inline double real(double x) { return x; }
inline double imag(double) { return 0.; }
inline double conj(double x) { return x; }
inline double abs(double x) { return std::abs(x); }
inline double abs2(double x) { return x*x; }
inline double sqrt(double x) { return std::sqrt(x); }
template<> inline double random(double a, double b)
{
return a + (b-a) * std::rand() / RAND_MAX;
}
@ -147,15 +142,15 @@ template<> inline double random()
{
return random<double>(-10.0, 10.0);
}
inline bool isMuchSmallerThan(const double& a, const double& b, const double& prec = precision<double>())
inline bool isMuchSmallerThan(double a, double b, double prec = precision<double>())
{
return std::abs(a) <= std::abs(b) * prec;
}
inline bool isApprox(const double& a, const double& b, const double& prec = precision<double>())
inline bool isApprox(double a, double b, double prec = precision<double>())
{
return std::abs(a - b) <= std::min(std::abs(a), std::abs(b)) * prec;
}
inline bool isApproxOrLessThan(const double& a, const double& b, const double& prec = precision<double>())
inline bool isApproxOrLessThan(double a, double b, double prec = precision<double>())
{
return a <= b || isApprox(a, b, prec);
}
@ -166,9 +161,8 @@ inline float imag(const std::complex<float>& x) { return std::imag(x); }
inline std::complex<float> conj(const std::complex<float>& x) { return std::conj(x); }
inline float abs(const std::complex<float>& x) { return std::abs(x); }
inline float abs2(const std::complex<float>& x) { return std::norm(x); }
inline std::complex<float> sqrt(const std::complex<float>& x)
inline std::complex<float> sqrt(const std::complex<float>&)
{
EIGEN_UNUSED(x);
// Taking the square roots of complex numbers is not allowed,
// as this is ambiguous (there are two square roots).
// What were you trying to do?
@ -179,11 +173,11 @@ template<> inline std::complex<float> random()
{
return std::complex<float>(random<float>(), random<float>());
}
inline bool isMuchSmallerThan(const std::complex<float>& a, const std::complex<float>& b, const float& prec = precision<float>())
inline bool isMuchSmallerThan(const std::complex<float>& a, const std::complex<float>& b, float prec = precision<float>())
{
return abs2(a) <= abs2(b) * prec * prec;
}
inline bool isApprox(const std::complex<float>& a, const std::complex<float>& b, const float& prec = precision<float>())
inline bool isApprox(const std::complex<float>& a, const std::complex<float>& b, float prec = precision<float>())
{
return isApprox(std::real(a), std::real(b), prec)
&& isApprox(std::imag(a), std::imag(b), prec);
@ -200,11 +194,11 @@ template<> inline std::complex<double> random()
{
return std::complex<double>(random<double>(), random<double>());
}
inline bool isMuchSmallerThan(const std::complex<double>& a, const std::complex<double>& b, const double& prec = precision<double>())
inline bool isMuchSmallerThan(const std::complex<double>& a, const std::complex<double>& b, double prec = precision<double>())
{
return abs2(a) <= abs2(b) * prec * prec;
}
inline bool isApprox(const std::complex<double>& a, const std::complex<double>& b, const double& prec = precision<double>())
inline bool isApprox(const std::complex<double>& a, const std::complex<double>& b, double prec = precision<double>())
{
return isApprox(std::real(a), std::real(b), prec)
&& isApprox(std::imag(a), std::imag(b), prec);

View File

@ -44,11 +44,7 @@ struct OperatorEqualsUnroller
template<typename Derived1, typename Derived2, int UnrollCount>
struct OperatorEqualsUnroller<Derived1, Derived2, UnrollCount, 0>
{
static void run(Derived1 &dst, const Derived2 &src)
{
EIGEN_UNUSED(dst);
EIGEN_UNUSED(src);
}
static void run(Derived1 &, const Derived2 &) {}
};
template<typename Derived1, typename Derived2, int Rows>
@ -63,11 +59,7 @@ struct OperatorEqualsUnroller<Derived1, Derived2, 1, Rows>
template<typename Derived1, typename Derived2, int Rows>
struct OperatorEqualsUnroller<Derived1, Derived2, Dynamic, Rows>
{
static void run(Derived1 &dst, const Derived2 &src)
{
EIGEN_UNUSED(dst);
EIGEN_UNUSED(src);
}
static void run(Derived1 &, const Derived2 &) {}
};
template<typename Scalar, typename Derived>

View File

@ -50,30 +50,14 @@ struct ProductUnroller<0, Size, Lhs, Rhs>
template<int Index, typename Lhs, typename Rhs>
struct ProductUnroller<Index, Dynamic, Lhs, Rhs>
{
static void run(int row, int col, const Lhs& lhs, const Rhs& rhs,
typename Lhs::Scalar &res)
{
EIGEN_UNUSED(row);
EIGEN_UNUSED(col);
EIGEN_UNUSED(lhs);
EIGEN_UNUSED(rhs);
EIGEN_UNUSED(res);
}
static void run(int, int, const Lhs&, const Rhs&, typename Lhs::Scalar&) {}
};
// prevent buggy user code from causing an infinite recursion
template<int Index, typename Lhs, typename Rhs>
struct ProductUnroller<Index, 0, Lhs, Rhs>
{
static void run(int row, int col, const Lhs& lhs, const Rhs& rhs,
typename Lhs::Scalar &res)
{
EIGEN_UNUSED(row);
EIGEN_UNUSED(col);
EIGEN_UNUSED(lhs);
EIGEN_UNUSED(rhs);
EIGEN_UNUSED(res);
}
static void run(int, int, const Lhs&, const Rhs&, typename Lhs::Scalar&) {}
};
template<typename Lhs, typename Rhs> class Product

View File

@ -49,10 +49,8 @@ template<typename MatrixType> class Random
int _rows() const { return m_rows; }
int _cols() const { return m_cols; }
Scalar _read(int row, int col) const
Scalar _read(int, int) const
{
EIGEN_UNUSED(row);
EIGEN_UNUSED(col);
return random<Scalar>();
}

View File

@ -60,15 +60,13 @@ template<typename MatrixType> class Row
int _rows() const { return 1; }
int _cols() const { return m_matrix.cols(); }
Scalar& _write(int row, int col)
Scalar& _write(int, int col)
{
EIGEN_UNUSED(row);
return m_matrix.write(m_row, col);
}
Scalar _read(int row, int col) const
Scalar _read(int, int col) const
{
EIGEN_UNUSED(row);
return m_matrix.read(m_row, col);
}

View File

@ -45,21 +45,13 @@ template<int Rows, typename Derived> struct TraceUnroller<0, Rows, Derived>
template<int Index, typename Derived> struct TraceUnroller<Index, Dynamic, Derived>
{
static void run(const Derived &mat, typename Derived::Scalar &trace)
{
EIGEN_UNUSED(mat);
EIGEN_UNUSED(trace);
}
static void run(const Derived&, typename Derived::Scalar&) {}
};
// prevent buggy user code from causing an infinite recursion
template<int Index, typename Derived> struct TraceUnroller<Index, 0, Derived>
{
static void run(const Derived &mat, typename Derived::Scalar &trace)
{
EIGEN_UNUSED(mat);
EIGEN_UNUSED(trace);
}
static void run(const Derived&, typename Derived::Scalar&) {}
};
template<typename Scalar, typename Derived>

View File

@ -46,10 +46,8 @@ using Eigen::Matrix;
#define eigen_assert(assertLevel, x) if(assertLevel <= EIGEN_ASSERT_LEVEL) assert(x);
#define EIGEN_UNUSED(x) (void)x
#ifdef NDEBUG
#define EIGEN_ONLY_USED_FOR_DEBUG(x) EIGEN_UNUSED(x)
#define EIGEN_ONLY_USED_FOR_DEBUG(x) (void)x
#else
#define EIGEN_ONLY_USED_FOR_DEBUG(x)
#endif

View File

@ -49,10 +49,8 @@ template<typename MatrixType> class Zero
int _rows() const { return m_rows; }
int _cols() const { return m_cols; }
Scalar _read(int row, int col) const
Scalar _read(int, int) const
{
EIGEN_UNUSED(row);
EIGEN_UNUSED(col);
return static_cast<Scalar>(0);
}