mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-01 01:32:00 +08:00
Big rework of the Traits system, unittests updated.
This commit is contained in:
parent
ca438b2c12
commit
71268227d4
@ -101,12 +101,12 @@
|
|||||||
|
|
||||||
2004-11-04 19:12 opetzold
|
2004-11-04 19:12 opetzold
|
||||||
|
|
||||||
* testsuite/: TestNumericTraits.h, TestNumericTraitsComplex.h: conj
|
* testsuite/: TestTraits.h, TestTraitsComplex.h: conj
|
||||||
tests updated for signed and unsigned types.
|
tests updated for signed and unsigned types.
|
||||||
|
|
||||||
2004-11-04 19:10 opetzold
|
2004-11-04 19:10 opetzold
|
||||||
|
|
||||||
* include/tvmet/NumericTraits.h: conj for all unsigned types
|
* include/tvmet/Traits.h: conj for all unsigned types
|
||||||
disabled. An unary minus operator applied to unsigned type will
|
disabled. An unary minus operator applied to unsigned type will
|
||||||
result unsigned.
|
result unsigned.
|
||||||
|
|
||||||
@ -125,7 +125,7 @@
|
|||||||
|
|
||||||
2004-11-04 17:25 opetzold
|
2004-11-04 17:25 opetzold
|
||||||
|
|
||||||
* include/tvmet/NumericTraits.h: bug removed: displaced semicolon
|
* include/tvmet/Traits.h: bug removed: displaced semicolon
|
||||||
removed - was wrong statement termination.
|
removed - was wrong statement termination.
|
||||||
|
|
||||||
2004-11-04 17:21 opetzold
|
2004-11-04 17:21 opetzold
|
||||||
@ -149,7 +149,7 @@
|
|||||||
|
|
||||||
2004-10-31 10:51 opetzold
|
2004-10-31 10:51 opetzold
|
||||||
|
|
||||||
* include/tvmet/NumericTraits.h: doxygen notes added for unsigned
|
* include/tvmet/Traits.h: doxygen notes added for unsigned
|
||||||
types and conj - it's useless.
|
types and conj - it's useless.
|
||||||
|
|
||||||
2004-10-31 10:50 opetzold
|
2004-10-31 10:50 opetzold
|
||||||
@ -233,8 +233,8 @@
|
|||||||
|
|
||||||
2004-09-15 09:51 opetzold
|
2004-09-15 09:51 opetzold
|
||||||
|
|
||||||
* testsuite/: TestNumericTraits.cc, TestNumericTraits.h,
|
* testsuite/: TestTraits.cc, TestTraits.h,
|
||||||
TestNumericTraitsComplex.cc, TestNumericTraitsComplex.h: added new
|
TestTraitsComplex.cc, TestTraitsComplex.h: added new
|
||||||
tests for tvmet's traits.
|
tests for tvmet's traits.
|
||||||
|
|
||||||
2004-07-06 11:45 opetzold
|
2004-07-06 11:45 opetzold
|
||||||
@ -421,7 +421,7 @@
|
|||||||
|
|
||||||
2004-06-08 18:16 opetzold
|
2004-06-08 18:16 opetzold
|
||||||
|
|
||||||
* include/tvmet/NumericTraits.h: extended member to simplify
|
* include/tvmet/Traits.h: extended member to simplify
|
||||||
complex calcs; not used yet.
|
complex calcs; not used yet.
|
||||||
|
|
||||||
2004-06-08 14:11 opetzold
|
2004-06-08 14:11 opetzold
|
||||||
@ -914,7 +914,7 @@
|
|||||||
|
|
||||||
2003-12-13 21:20 opetzold
|
2003-12-13 21:20 opetzold
|
||||||
|
|
||||||
* include/tvmet/NumericTraits.h: infos about complex type added.
|
* include/tvmet/Traits.h: infos about complex type added.
|
||||||
|
|
||||||
2003-12-09 19:38 opetzold
|
2003-12-09 19:38 opetzold
|
||||||
|
|
||||||
@ -1191,7 +1191,7 @@
|
|||||||
include/tvmet/MatrixEval.h, include/tvmet/MatrixFunctions.h,
|
include/tvmet/MatrixEval.h, include/tvmet/MatrixFunctions.h,
|
||||||
include/tvmet/MatrixImpl.h, include/tvmet/MatrixOperators.h,
|
include/tvmet/MatrixImpl.h, include/tvmet/MatrixOperators.h,
|
||||||
include/tvmet/MatrixUnaryFunctions.h,
|
include/tvmet/MatrixUnaryFunctions.h,
|
||||||
include/tvmet/NumericTraits.h, include/tvmet/RunTimeError.h,
|
include/tvmet/Traits.h, include/tvmet/RunTimeError.h,
|
||||||
include/tvmet/TvmetBase.h, include/tvmet/TypePromotion.h,
|
include/tvmet/TvmetBase.h, include/tvmet/TypePromotion.h,
|
||||||
include/tvmet/UnaryFunctionals.h, include/tvmet/Vector.h,
|
include/tvmet/UnaryFunctionals.h, include/tvmet/Vector.h,
|
||||||
include/tvmet/VectorBinaryFunctions.h, include/tvmet/VectorEval.h,
|
include/tvmet/VectorBinaryFunctions.h, include/tvmet/VectorEval.h,
|
||||||
@ -1500,7 +1500,7 @@
|
|||||||
|
|
||||||
2003-10-21 20:48 opetzold
|
2003-10-21 20:48 opetzold
|
||||||
|
|
||||||
* include/tvmet/NumericTraits.h: complexity for numeric types
|
* include/tvmet/Traits.h: complexity for numeric types
|
||||||
added.
|
added.
|
||||||
|
|
||||||
2003-10-21 20:39 opetzold
|
2003-10-21 20:39 opetzold
|
||||||
@ -1777,7 +1777,7 @@
|
|||||||
CompileTimeError.h, Extremum.h, Functional.h, Matrix.h,
|
CompileTimeError.h, Extremum.h, Functional.h, Matrix.h,
|
||||||
MatrixBinaryFunctions.h, MatrixEval.h, MatrixFunctions.h,
|
MatrixBinaryFunctions.h, MatrixEval.h, MatrixFunctions.h,
|
||||||
MatrixImpl.h, MatrixOperators.h, MatrixUnaryFunctions.h,
|
MatrixImpl.h, MatrixOperators.h, MatrixUnaryFunctions.h,
|
||||||
NumericTraits.h, RunTimeError.h, TvmetBase.h, TypePromotion.h,
|
Traits.h, RunTimeError.h, TvmetBase.h, TypePromotion.h,
|
||||||
UnaryFunctionals.h, Vector.h, VectorBinaryFunctions.h,
|
UnaryFunctionals.h, Vector.h, VectorBinaryFunctions.h,
|
||||||
VectorEval.h, VectorFunctions.h, VectorImpl.h, VectorOperators.h,
|
VectorEval.h, VectorFunctions.h, VectorImpl.h, VectorOperators.h,
|
||||||
VectorUnaryFunctions.h, tvmet.h, meta/Gemm.h, meta/Gemmt.h,
|
VectorUnaryFunctions.h, tvmet.h, meta/Gemm.h, meta/Gemmt.h,
|
||||||
@ -3811,7 +3811,7 @@
|
|||||||
include/tvmet/Extremum.h, include/tvmet/Functional.h,
|
include/tvmet/Extremum.h, include/tvmet/Functional.h,
|
||||||
include/tvmet/Matrix.h, include/tvmet/MatrixEval.h,
|
include/tvmet/Matrix.h, include/tvmet/MatrixEval.h,
|
||||||
include/tvmet/MatrixFunctions.h, include/tvmet/MatrixImpl.h,
|
include/tvmet/MatrixFunctions.h, include/tvmet/MatrixImpl.h,
|
||||||
include/tvmet/MatrixOperators.h, include/tvmet/NumericTraits.h,
|
include/tvmet/MatrixOperators.h, include/tvmet/Traits.h,
|
||||||
include/tvmet/RunTimeError.h, include/tvmet/TvmetBase.h,
|
include/tvmet/RunTimeError.h, include/tvmet/TvmetBase.h,
|
||||||
include/tvmet/TypePromotion.h, include/tvmet/UnaryFunctionals.h,
|
include/tvmet/TypePromotion.h, include/tvmet/UnaryFunctionals.h,
|
||||||
include/tvmet/Vector.h, include/tvmet/VectorEval.h,
|
include/tvmet/Vector.h, include/tvmet/VectorEval.h,
|
||||||
@ -3935,7 +3935,7 @@
|
|||||||
include/tvmet/Extremum.h, include/tvmet/Functional.h,
|
include/tvmet/Extremum.h, include/tvmet/Functional.h,
|
||||||
include/tvmet/Matrix.h, include/tvmet/MatrixEval.h,
|
include/tvmet/Matrix.h, include/tvmet/MatrixEval.h,
|
||||||
include/tvmet/MatrixFunctions.h, include/tvmet/MatrixImpl.h,
|
include/tvmet/MatrixFunctions.h, include/tvmet/MatrixImpl.h,
|
||||||
include/tvmet/MatrixOperators.h, include/tvmet/NumericTraits.h,
|
include/tvmet/MatrixOperators.h, include/tvmet/Traits.h,
|
||||||
include/tvmet/RunTimeError.h, include/tvmet/TvmetBase.h,
|
include/tvmet/RunTimeError.h, include/tvmet/TvmetBase.h,
|
||||||
include/tvmet/TypePromotion.h, include/tvmet/UnaryFunctionals.h,
|
include/tvmet/TypePromotion.h, include/tvmet/UnaryFunctionals.h,
|
||||||
include/tvmet/Vector.h, include/tvmet/VectorEval.h,
|
include/tvmet/Vector.h, include/tvmet/VectorEval.h,
|
||||||
@ -4003,7 +4003,7 @@
|
|||||||
include/tvmet/Makefile.am, include/tvmet/Makefile.in,
|
include/tvmet/Makefile.am, include/tvmet/Makefile.in,
|
||||||
include/tvmet/Matrix.h, include/tvmet/MatrixEval.h,
|
include/tvmet/Matrix.h, include/tvmet/MatrixEval.h,
|
||||||
include/tvmet/MatrixFunctions.h, include/tvmet/MatrixImpl.h,
|
include/tvmet/MatrixFunctions.h, include/tvmet/MatrixImpl.h,
|
||||||
include/tvmet/MatrixOperators.h, include/tvmet/NumericTraits.h,
|
include/tvmet/MatrixOperators.h, include/tvmet/Traits.h,
|
||||||
include/tvmet/RunTimeError.h, include/tvmet/TvmetBase.h,
|
include/tvmet/RunTimeError.h, include/tvmet/TvmetBase.h,
|
||||||
include/tvmet/TypePromotion.h, include/tvmet/UnaryFunctionals.h,
|
include/tvmet/TypePromotion.h, include/tvmet/UnaryFunctionals.h,
|
||||||
include/tvmet/Vector.h, include/tvmet/VectorEval.h,
|
include/tvmet/Vector.h, include/tvmet/VectorEval.h,
|
||||||
@ -4078,7 +4078,7 @@
|
|||||||
include/tvmet/Makefile.am, include/tvmet/Makefile.in,
|
include/tvmet/Makefile.am, include/tvmet/Makefile.in,
|
||||||
include/tvmet/Matrix.h, include/tvmet/MatrixEval.h,
|
include/tvmet/Matrix.h, include/tvmet/MatrixEval.h,
|
||||||
include/tvmet/MatrixFunctions.h, include/tvmet/MatrixImpl.h,
|
include/tvmet/MatrixFunctions.h, include/tvmet/MatrixImpl.h,
|
||||||
include/tvmet/MatrixOperators.h, include/tvmet/NumericTraits.h,
|
include/tvmet/MatrixOperators.h, include/tvmet/Traits.h,
|
||||||
include/tvmet/RunTimeError.h, include/tvmet/TvmetBase.h,
|
include/tvmet/RunTimeError.h, include/tvmet/TvmetBase.h,
|
||||||
include/tvmet/TypePromotion.h, include/tvmet/UnaryFunctionals.h,
|
include/tvmet/TypePromotion.h, include/tvmet/UnaryFunctionals.h,
|
||||||
include/tvmet/Vector.h, include/tvmet/VectorEval.h,
|
include/tvmet/Vector.h, include/tvmet/VectorEval.h,
|
||||||
|
@ -313,7 +313,7 @@
|
|||||||
* regression/TestMathOps.h: Test for normalize(Vector<>) added.
|
* regression/TestMathOps.h: Test for normalize(Vector<>) added.
|
||||||
|
|
||||||
* include/tvmet/{Matrix,Vector}Operators.h: Matrix/Vector<T, Sz> and POD's
|
* include/tvmet/{Matrix,Vector}Operators.h: Matrix/Vector<T, Sz> and POD's
|
||||||
extended with long long int to handle long long from NumericTraits
|
extended with long long int to handle long long from Traits
|
||||||
too.
|
too.
|
||||||
|
|
||||||
2002-10-29 opetzold <opetzold@wit.regiocom.net>
|
2002-10-29 opetzold <opetzold@wit.regiocom.net>
|
||||||
@ -339,7 +339,7 @@
|
|||||||
|
|
||||||
* doc/Doxygen.in: PREDEFINED targets use the forgotten TVMET prefix too.
|
* doc/Doxygen.in: PREDEFINED targets use the forgotten TVMET prefix too.
|
||||||
|
|
||||||
* include/tvmet/{Binary|UnaryFunctionals.h, NumericTraits.h,
|
* include/tvmet/{Binary|UnaryFunctionals.h, Traits.h,
|
||||||
TypePromotion.h TvmetBase.h}: macros
|
TypePromotion.h TvmetBase.h}: macros
|
||||||
generated operators, functions and functionals doc added for
|
generated operators, functions and functionals doc added for
|
||||||
doxygen include path.
|
doxygen include path.
|
||||||
@ -443,7 +443,7 @@
|
|||||||
|
|
||||||
* version 0.4.0 released
|
* version 0.4.0 released
|
||||||
|
|
||||||
* include/tvmet/NumericTraits.h: rewritten to avoid macro and ifdef garbage.
|
* include/tvmet/Traits.h: rewritten to avoid macro and ifdef garbage.
|
||||||
|
|
||||||
* include/tvmet/*: member rename to be conform to m_xxx
|
* include/tvmet/*: member rename to be conform to m_xxx
|
||||||
|
|
||||||
@ -475,7 +475,7 @@
|
|||||||
and complex types as well. Change ranking breaks compatibility
|
and complex types as well. Change ranking breaks compatibility
|
||||||
with prior releases.
|
with prior releases.
|
||||||
|
|
||||||
* include/tvmet/NumericTraits.h: support for long long. Specialized version for
|
* include/tvmet/Traits.h: support for long long. Specialized version for
|
||||||
long double and long long self removed - there isn't a way to guarantee
|
long double and long long self removed - there isn't a way to guarantee
|
||||||
the precision than.
|
the precision than.
|
||||||
|
|
||||||
@ -556,10 +556,10 @@
|
|||||||
* include/tvmet/TypePromotion.h: std::complex<int> added, therfore the priorities
|
* include/tvmet/TypePromotion.h: std::complex<int> added, therfore the priorities
|
||||||
for all complex types have changed!
|
for all complex types have changed!
|
||||||
|
|
||||||
* include/tvmet/NumericTraits.h: depends on HAVE_LONG_DOUBLE, sum_type of double
|
* include/tvmet/Traits.h: depends on HAVE_LONG_DOUBLE, sum_type of double
|
||||||
is long double or double.
|
is long double or double.
|
||||||
|
|
||||||
* include/tvmet/{MatrixEval.h, MatrixFunctions.h, MatrixOperators.h, NumericTraits.h,
|
* include/tvmet/{MatrixEval.h, MatrixFunctions.h, MatrixOperators.h, Traits.h,
|
||||||
TypePromotion.h, UnaryFunctionals.h, VectorEval.h, VectorFunctions.h,
|
TypePromotion.h, UnaryFunctionals.h, VectorEval.h, VectorFunctions.h,
|
||||||
VectorOperators.h, XprFunctions.h, XprOperators.h} HAVE_LONG_DOUBLE
|
VectorOperators.h, XprFunctions.h, XprOperators.h} HAVE_LONG_DOUBLE
|
||||||
encapsulated.
|
encapsulated.
|
||||||
@ -577,7 +577,7 @@
|
|||||||
|
|
||||||
* examples/Makefile.am (examples): bug corrected.
|
* examples/Makefile.am (examples): bug corrected.
|
||||||
|
|
||||||
* include/tvmet/NumericTraits.h: complex<int> numeric traits added.
|
* include/tvmet/Traits.h: complex<int> numeric traits added.
|
||||||
|
|
||||||
* include/tvmet/MatrixOperators.h: operator*() is in namespace element_wise left
|
* include/tvmet/MatrixOperators.h: operator*() is in namespace element_wise left
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ frob_norm(const tvmet::Matrix<T, Rows, Cols>& M) {
|
|||||||
|
|
||||||
namespace tvmet {
|
namespace tvmet {
|
||||||
template<class T, int Rows, int Cols>
|
template<class T, int Rows, int Cols>
|
||||||
typename NumericTraits<T>::float_type
|
typename Traits<T>::float_type
|
||||||
norm(const Matrix<T, Rows, Cols>& M) {
|
norm(const Matrix<T, Rows, Cols>& M) {
|
||||||
return std::sqrt( sum( diag( MtM_prod(M,M) ) ) );
|
return std::sqrt( sum( diag( MtM_prod(M,M) ) ) );
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ _Z9frob_normIdLj3ELj3EEdRKN5tvmet6MatrixIT_XT0_EXT1_EEE:
|
|||||||
/*
|
/*
|
||||||
gcc 3.3 produce the norm function using tvmet 1.3.0:
|
gcc 3.3 produce the norm function using tvmet 1.3.0:
|
||||||
|
|
||||||
_ZN5tvmet4normIdLj3ELj3EEENS_13NumericTraitsIT_E10float_typeERKNS_6MatrixIS2_XT0_EXT1_EEE:
|
_ZN5tvmet4normIdLj3ELj3EEENS_13TraitsIT_E10float_typeERKNS_6MatrixIS2_XT0_EXT1_EEE:
|
||||||
.LFB3252:
|
.LFB3252:
|
||||||
.L194:
|
.L194:
|
||||||
.L198:
|
.L198:
|
||||||
|
@ -337,7 +337,7 @@ trans(const Matrix<T, Rows, Cols>& rhs) _tvmet_always_inline;
|
|||||||
|
|
||||||
|
|
||||||
template<class T, int Sz>
|
template<class T, int Sz>
|
||||||
typename NumericTraits<T>::sum_type
|
typename Traits<T>::sum_type
|
||||||
trace(const Matrix<T, Sz, Sz>& m) _tvmet_always_inline;
|
trace(const Matrix<T, Sz, Sz>& m) _tvmet_always_inline;
|
||||||
|
|
||||||
|
|
||||||
@ -972,7 +972,7 @@ trans(const Matrix<T, Rows, Cols>& rhs) {
|
|||||||
*/
|
*/
|
||||||
template<class T, int Sz>
|
template<class T, int Sz>
|
||||||
inline
|
inline
|
||||||
typename NumericTraits<T>::sum_type
|
typename Traits<T>::sum_type
|
||||||
trace(const Matrix<T, Sz, Sz>& m) {
|
trace(const Matrix<T, Sz, Sz>& m) {
|
||||||
return meta::Matrix<Sz, Sz, 0, 0>::trace(m);
|
return meta::Matrix<Sz, Sz, 0, 0>::trace(m);
|
||||||
}
|
}
|
||||||
|
@ -51,12 +51,12 @@ std::ostream& Matrix<T, NRows, NCols>::print_xpr(std::ostream& os, int l) const
|
|||||||
template<class T, int NRows, int NCols>
|
template<class T, int NRows, int NCols>
|
||||||
std::ostream& Matrix<T, NRows, NCols>::print_on(std::ostream& os) const
|
std::ostream& Matrix<T, NRows, NCols>::print_on(std::ostream& os) const
|
||||||
{
|
{
|
||||||
enum {
|
std::streamsize w;
|
||||||
complex_type = NumericTraits<value_type>::is_complex
|
if(Traits<value_type>::isComplex())
|
||||||
};
|
w = IoPrintHelper<Matrix>::width(dispatch<true>(), *this);
|
||||||
|
else
|
||||||
std::streamsize w = IoPrintHelper<Matrix>::width(dispatch<complex_type>(), *this);
|
w = IoPrintHelper<Matrix>::width(dispatch<false>(), *this);
|
||||||
|
|
||||||
os << std::setw(0) << "[\n";
|
os << std::setw(0) << "[\n";
|
||||||
for(int i = 0; i < Rows; ++i) {
|
for(int i = 0; i < Rows; ++i) {
|
||||||
os << " [";
|
os << " [";
|
||||||
|
@ -1,323 +0,0 @@
|
|||||||
/*
|
|
||||||
* Tiny Vector Matrix Library
|
|
||||||
* Dense Vector Matrix Libary of Tiny size using Expression Templates
|
|
||||||
*
|
|
||||||
* Copyright (C) 2001 - 2003 Olaf Petzold <opetzold@users.sourceforge.net>
|
|
||||||
*
|
|
||||||
* This library 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 2.1 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library 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 for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
* $Id: NumericTraits.h,v 1.11 2004/11/04 18:10:35 opetzold Exp $
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TVMET_NUMERIC_TRAITS_H
|
|
||||||
#define TVMET_NUMERIC_TRAITS_H
|
|
||||||
|
|
||||||
#if defined(EIGEN_USE_COMPLEX)
|
|
||||||
# include <complex>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <limits>
|
|
||||||
|
|
||||||
#include <tvmet/CompileTimeError.h>
|
|
||||||
#include <tvmet/util/Random.h>
|
|
||||||
|
|
||||||
namespace tvmet {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \class NumericTraits NumericTraits.h "tvmet/NumericTraits.h"
|
|
||||||
* \brief Traits for integral types for operations.
|
|
||||||
*
|
|
||||||
* For each type we have to specialize this traits.
|
|
||||||
*/
|
|
||||||
template<class T>
|
|
||||||
struct NumericTraits {
|
|
||||||
typedef T real_type;
|
|
||||||
typedef T value_type;
|
|
||||||
typedef T float_type;
|
|
||||||
typedef const T & argument_type;
|
|
||||||
|
|
||||||
static inline
|
|
||||||
real_type real(argument_type x);
|
|
||||||
|
|
||||||
static inline
|
|
||||||
real_type imag(argument_type x);
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type conj(argument_type x);
|
|
||||||
|
|
||||||
static inline
|
|
||||||
real_type abs(argument_type x);
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type sqrt(argument_type x);
|
|
||||||
|
|
||||||
enum{ is_complex = false };
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* numeric traits for built-in types
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \class NumericTraits<int> NumericTraits.h "tvmet/NumericTraits.h"
|
|
||||||
* \brief Traits specialized for int.
|
|
||||||
*/
|
|
||||||
template<>
|
|
||||||
struct NumericTraits<int> {
|
|
||||||
typedef int value_type;
|
|
||||||
typedef value_type real_type;
|
|
||||||
typedef double float_type;
|
|
||||||
typedef value_type argument_type;
|
|
||||||
|
|
||||||
static inline
|
|
||||||
real_type real(argument_type x) { return x; }
|
|
||||||
|
|
||||||
static inline
|
|
||||||
real_type imag(argument_type x) { TVMET_UNUSED(x); return 0; }
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type conj(argument_type x) { return x; }
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type sqrt(argument_type x) {
|
|
||||||
return static_cast<value_type>(std::sqrt(static_cast<float_type>(x)));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type abs(argument_type x) {
|
|
||||||
return std::abs(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum { is_complex = false };
|
|
||||||
|
|
||||||
/** Complexity on operations. */
|
|
||||||
enum {
|
|
||||||
ops_plus = 1, /**< Complexity on plus/minus ops. */
|
|
||||||
ops_muls = 1 /**< Complexity on multiplications. */
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \class NumericTraits<float> NumericTraits.h "tvmet/NumericTraits.h"
|
|
||||||
* \brief Traits specialized for float.
|
|
||||||
*/
|
|
||||||
template<>
|
|
||||||
struct NumericTraits<float> {
|
|
||||||
typedef float value_type;
|
|
||||||
typedef value_type real_type;
|
|
||||||
typedef value_type float_type;
|
|
||||||
typedef value_type argument_type;
|
|
||||||
|
|
||||||
static inline
|
|
||||||
real_type real(argument_type x) { return x; }
|
|
||||||
|
|
||||||
static inline
|
|
||||||
real_type imag(argument_type x) { TVMET_UNUSED(x); return 0; }
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type conj(argument_type x) { return x; }
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type sqrt(argument_type x) {
|
|
||||||
return std::sqrt(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type abs(argument_type x) {
|
|
||||||
return std::abs(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum { is_complex = false };
|
|
||||||
|
|
||||||
/** Complexity on operations. */
|
|
||||||
enum {
|
|
||||||
ops_plus = 1, /**< Complexity on plus/minus ops. */
|
|
||||||
ops_muls = 1 /**< Complexity on multiplications. */
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \class NumericTraits<double> NumericTraits.h "tvmet/NumericTraits.h"
|
|
||||||
* \brief Traits specialized for double.
|
|
||||||
*/
|
|
||||||
template<>
|
|
||||||
struct NumericTraits<double> {
|
|
||||||
typedef double value_type;
|
|
||||||
typedef value_type real_type;
|
|
||||||
typedef value_type float_type;
|
|
||||||
typedef value_type argument_type;
|
|
||||||
|
|
||||||
static inline
|
|
||||||
real_type real(argument_type x) { return x; }
|
|
||||||
|
|
||||||
static inline
|
|
||||||
real_type imag(argument_type x) { TVMET_UNUSED(x); return 0; }
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type conj(argument_type x) { return x; }
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type sqrt(argument_type x) {
|
|
||||||
return std::sqrt(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type abs(argument_type x) {
|
|
||||||
return std::abs(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum { is_complex = false };
|
|
||||||
|
|
||||||
/** Complexity on operations. */
|
|
||||||
enum {
|
|
||||||
ops_plus = 1, /**< Complexity on plus/minus ops. */
|
|
||||||
ops_muls = 1 /**< Complexity on multiplications. */
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* numeric traits for complex types
|
|
||||||
*/
|
|
||||||
#if defined(EIGEN_USE_COMPLEX)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \class NumericTraits< std::complex<int> > NumericTraits.h "tvmet/NumericTraits.h"
|
|
||||||
* \brief Traits specialized for std::complex<int>.
|
|
||||||
*/
|
|
||||||
template<>
|
|
||||||
struct NumericTraits< std::complex<int> > {
|
|
||||||
typedef std::complex<int> value_type;
|
|
||||||
typedef int real_type;
|
|
||||||
typedef std::complex<float> float_type;
|
|
||||||
typedef const value_type& argument_type;
|
|
||||||
|
|
||||||
static inline
|
|
||||||
real_type real(argument_type z) { return std::real(z); }
|
|
||||||
|
|
||||||
static inline
|
|
||||||
real_type imag(argument_type z) { return std::imag(z); }
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type conj(argument_type z) { return std::conj(z); }
|
|
||||||
|
|
||||||
static inline
|
|
||||||
real_type abs(argument_type z) {
|
|
||||||
// the use of ceil() guarantees e.g. that abs(real(x)) <= abs(x),
|
|
||||||
// and that abs(x)==0 if and only if x==0.
|
|
||||||
return static_cast<value_type>(std::ceil(std::abs(static_cast<float_type>(x))));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type sqrt(argument_type x) {
|
|
||||||
return static_cast<value_type>(std::sqrt(static_cast<float_type>(x)));
|
|
||||||
}
|
|
||||||
|
|
||||||
enum { is_complex = true };
|
|
||||||
|
|
||||||
/** Complexity on operations. */
|
|
||||||
enum {
|
|
||||||
ops_plus = 2, /**< Complexity on plus/minus ops. */
|
|
||||||
ops_muls = 6 /**< Complexity on multiplications. */
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \class NumericTraits< std::complex<float> > NumericTraits.h "tvmet/NumericTraits.h"
|
|
||||||
* \brief Traits specialized for std::complex<float>.
|
|
||||||
*/
|
|
||||||
template<>
|
|
||||||
struct NumericTraits< std::complex<float> > {
|
|
||||||
typedef std::complex<float> value_type;
|
|
||||||
typedef float real_type;
|
|
||||||
typedef value_type float_type;
|
|
||||||
typedef const value_type& argument_type;
|
|
||||||
|
|
||||||
static inline
|
|
||||||
real_type real(argument_type z) { return std::real(z); }
|
|
||||||
|
|
||||||
static inline
|
|
||||||
real_type imag(argument_type z) { return std::imag(z); }
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type conj(argument_type z) { return std::conj(z); }
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type sqrt(argument_type x) {
|
|
||||||
return std::sqrt(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type abs(argument_type x) {
|
|
||||||
return std::abs(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum { is_complex = true };
|
|
||||||
|
|
||||||
/** Complexity on operations. */
|
|
||||||
enum {
|
|
||||||
ops_plus = 2, /**< Complexity on plus/minus ops. */
|
|
||||||
ops_muls = 6 /**< Complexity on multiplications. */
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \class NumericTraits< std::complex<double> > NumericTraits.h "tvmet/NumericTraits.h"
|
|
||||||
* \brief Traits specialized for std::complex<double>.
|
|
||||||
*/
|
|
||||||
template<>
|
|
||||||
struct NumericTraits< std::complex<double> > {
|
|
||||||
typedef std::complex<double> value_type;
|
|
||||||
typedef double real_type;
|
|
||||||
typedef value_type float_type;
|
|
||||||
typedef const value_type& argument_type;
|
|
||||||
|
|
||||||
static inline
|
|
||||||
real_type real(argument_type z) { return std::real(z); }
|
|
||||||
|
|
||||||
static inline
|
|
||||||
real_type imag(argument_type z) { return std::imag(z); }
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type conj(argument_type z) { return std::conj(z); }
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type sqrt(argument_type x) {
|
|
||||||
return std::sqrt(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline
|
|
||||||
value_type abs(argument_type x) {
|
|
||||||
return std::abs(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum { is_complex = true };
|
|
||||||
|
|
||||||
/** Complexity on operations. */
|
|
||||||
enum {
|
|
||||||
ops_plus = 2, /**< Complexity on plus/minus ops. */
|
|
||||||
ops_muls = 6 /**< Complexity on multiplications. */
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // defined(EIGEN_USE_COMPLEX)
|
|
||||||
|
|
||||||
} // namespace tvmet
|
|
||||||
|
|
||||||
#endif // TVMET_NUMERIC_TRAITS_H
|
|
122
tvmet-1.7.1/include/tvmet/Traits.h
Normal file
122
tvmet-1.7.1/include/tvmet/Traits.h
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
/* This file is part of Eigen, a C++ template library for linear algebra
|
||||||
|
* Copyright (C) 2007 Benoit Jacob <jacob@math.jussieu.fr>
|
||||||
|
*
|
||||||
|
* Based on Tvmet source code, http://tvmet.sourceforge.net,
|
||||||
|
* Copyright (C) 2001 - 2003 Olaf Petzold <opetzold@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* This library 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 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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 for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* $Id: Traits.h,v 1.11 2004/11/04 18:10:35 opetzold Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TVMET_NUMERIC_TRAITS_H
|
||||||
|
#define TVMET_NUMERIC_TRAITS_H
|
||||||
|
|
||||||
|
#if defined(EIGEN_USE_COMPLEX)
|
||||||
|
# include <complex>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#include <tvmet/TraitsBase.h>
|
||||||
|
|
||||||
|
namespace tvmet {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \class Traits Traits.h "tvmet/Traits.h"
|
||||||
|
* \brief Traits for standard types.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
struct Traits : public TraitsBase<T>
|
||||||
|
{
|
||||||
|
typedef TraitsBase<T> Base;
|
||||||
|
typedef typename Base::value_type value_type;
|
||||||
|
typedef typename Base::real_type real_type;
|
||||||
|
typedef typename Base::float_type float_type;
|
||||||
|
typedef typename Base::argument_type argument_type;
|
||||||
|
|
||||||
|
using Base::isFloat;
|
||||||
|
using Base::isComplex;
|
||||||
|
using Base::epsilon;
|
||||||
|
using Base::abs;
|
||||||
|
using Base::real;
|
||||||
|
using Base::imag;
|
||||||
|
using Base::conj;
|
||||||
|
using Base::sqrt;
|
||||||
|
|
||||||
|
static value_type random()
|
||||||
|
{
|
||||||
|
value_type x;
|
||||||
|
pickRandom(x);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Short version: returns true if the absolute value of \a a is much smaller
|
||||||
|
* than that of \a b.
|
||||||
|
*
|
||||||
|
* Full story: returns(abs(a) <= abs(b) * epsilon());
|
||||||
|
*/
|
||||||
|
static bool isNegligible(argument_type a, argument_type b)
|
||||||
|
{
|
||||||
|
if(isFloat())
|
||||||
|
return(abs(a) <= abs(b) * epsilon());
|
||||||
|
else
|
||||||
|
return(a==0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short version: returns true if \a a is approximately zero.
|
||||||
|
*
|
||||||
|
* Full story: returns isNegligible( a, static_cast<T>(1) );
|
||||||
|
*/
|
||||||
|
static bool isZero(argument_type a)
|
||||||
|
{
|
||||||
|
return isNegligible(a, static_cast<value_type>(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short version: returns true if a is very close to b, false otherwise.
|
||||||
|
*
|
||||||
|
* Full story: returns abs( a - b ) <= min( abs(a), abs(b) ) * epsilon<T>.
|
||||||
|
*/
|
||||||
|
static bool isApprox(argument_type a, argument_type b)
|
||||||
|
{
|
||||||
|
if(isFloat())
|
||||||
|
return(abs( a - b ) <= std::min(abs(a), abs(b)) * epsilon());
|
||||||
|
else
|
||||||
|
return(a==b);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short version: returns true if a is smaller or approximately equalt to b, false otherwise.
|
||||||
|
*
|
||||||
|
* Full story: returns a <= b || isApprox(a, b);
|
||||||
|
*/
|
||||||
|
static bool isLessThan( argument_type a, argument_type b )
|
||||||
|
{
|
||||||
|
assert(!isComplex());
|
||||||
|
if(isFloat())
|
||||||
|
return(a <= b || isApprox(a, b));
|
||||||
|
else
|
||||||
|
return(a<=b);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace tvmet
|
||||||
|
|
||||||
|
#endif // TVMET_NUMERIC_TRAITS_H
|
@ -187,12 +187,12 @@ TVMET_DECLARE_MACRO(div)
|
|||||||
|
|
||||||
|
|
||||||
template<class T, int Sz>
|
template<class T, int Sz>
|
||||||
typename NumericTraits<T>::sum_type
|
typename Traits<T>::sum_type
|
||||||
sum(const Vector<T, Sz>& v) _tvmet_always_inline;
|
sum(const Vector<T, Sz>& v) _tvmet_always_inline;
|
||||||
|
|
||||||
|
|
||||||
template<class T, int Sz>
|
template<class T, int Sz>
|
||||||
typename NumericTraits<T>::sum_type
|
typename Traits<T>::sum_type
|
||||||
product(const Vector<T, Sz>& v) _tvmet_always_inline;
|
product(const Vector<T, Sz>& v) _tvmet_always_inline;
|
||||||
|
|
||||||
|
|
||||||
@ -209,12 +209,12 @@ cross(const Vector<T1, 3>& lhs,
|
|||||||
|
|
||||||
|
|
||||||
template<class T, int Sz>
|
template<class T, int Sz>
|
||||||
typename NumericTraits<T>::sum_type
|
typename Traits<T>::sum_type
|
||||||
norm1(const Vector<T, Sz>& v) _tvmet_always_inline;
|
norm1(const Vector<T, Sz>& v) _tvmet_always_inline;
|
||||||
|
|
||||||
|
|
||||||
template<class T, int Sz>
|
template<class T, int Sz>
|
||||||
typename NumericTraits<T>::sum_type
|
typename Traits<T>::sum_type
|
||||||
norm2(const Vector<T, Sz>& v) _tvmet_always_inline;
|
norm2(const Vector<T, Sz>& v) _tvmet_always_inline;
|
||||||
|
|
||||||
|
|
||||||
@ -505,7 +505,7 @@ TVMET_IMPLEMENT_MACRO(div)
|
|||||||
*/
|
*/
|
||||||
template<class T, int Sz>
|
template<class T, int Sz>
|
||||||
inline
|
inline
|
||||||
typename NumericTraits<T>::sum_type
|
typename Traits<T>::sum_type
|
||||||
sum(const Vector<T, Sz>& v) {
|
sum(const Vector<T, Sz>& v) {
|
||||||
return meta::Vector<Sz>::sum(v);
|
return meta::Vector<Sz>::sum(v);
|
||||||
}
|
}
|
||||||
@ -523,7 +523,7 @@ sum(const Vector<T, Sz>& v) {
|
|||||||
*/
|
*/
|
||||||
template<class T, int Sz>
|
template<class T, int Sz>
|
||||||
inline
|
inline
|
||||||
typename NumericTraits<T>::sum_type
|
typename Traits<T>::sum_type
|
||||||
product(const Vector<T, Sz>& v) {
|
product(const Vector<T, Sz>& v) {
|
||||||
return meta::Vector<Sz>::product(v);
|
return meta::Vector<Sz>::product(v);
|
||||||
}
|
}
|
||||||
@ -580,7 +580,7 @@ cross(const Vector<T1, 3>& lhs, const Vector<T2, 3>& rhs) {
|
|||||||
*/
|
*/
|
||||||
template<class T, int Sz>
|
template<class T, int Sz>
|
||||||
inline
|
inline
|
||||||
typename NumericTraits<T>::sum_type
|
typename Traits<T>::sum_type
|
||||||
norm1(const Vector<T, Sz>& v) {
|
norm1(const Vector<T, Sz>& v) {
|
||||||
return sum(abs(v));
|
return sum(abs(v));
|
||||||
}
|
}
|
||||||
@ -601,9 +601,9 @@ norm1(const Vector<T, Sz>& v) {
|
|||||||
*/
|
*/
|
||||||
template<class T, int Sz>
|
template<class T, int Sz>
|
||||||
inline
|
inline
|
||||||
typename NumericTraits<T>::sum_type
|
typename Traits<T>::sum_type
|
||||||
norm2(const Vector<T, Sz>& v) {
|
norm2(const Vector<T, Sz>& v) {
|
||||||
return static_cast<T>( std::sqrt(static_cast<typename NumericTraits<T>::float_type>(dot(v, v))) );
|
return static_cast<T>( std::sqrt(static_cast<typename Traits<T>::float_type>(dot(v, v))) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,12 +51,12 @@ std::ostream& Vector<T, Sz>::print_xpr(std::ostream& os, int l) const
|
|||||||
template<class T, int Sz>
|
template<class T, int Sz>
|
||||||
std::ostream& Vector<T, Sz>::print_on(std::ostream& os) const
|
std::ostream& Vector<T, Sz>::print_on(std::ostream& os) const
|
||||||
{
|
{
|
||||||
enum {
|
std::streamsize w;
|
||||||
complex_type = NumericTraits<value_type>::is_complex
|
if(Traits<value_type>::isComplex())
|
||||||
};
|
w = IoPrintHelper<Vector>::width(dispatch<true>(), *this);
|
||||||
|
else
|
||||||
std::streamsize w = IoPrintHelper<Vector>::width(dispatch<complex_type>(), *this);
|
w = IoPrintHelper<Vector>::width(dispatch<false>(), *this);
|
||||||
|
|
||||||
os << std::setw(0) << "[\n ";
|
os << std::setw(0) << "[\n ";
|
||||||
for(int i = 0; i < (Size - 1); ++i) {
|
for(int i = 0; i < (Size - 1); ++i) {
|
||||||
os << std::setw(w) << m_data[i] << ", ";
|
os << std::setw(w) << m_data[i] << ", ";
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#ifndef TVMET_META_MATRIX_H
|
#ifndef TVMET_META_MATRIX_H
|
||||||
#define TVMET_META_MATRIX_H
|
#define TVMET_META_MATRIX_H
|
||||||
|
|
||||||
#include <tvmet/NumericTraits.h>
|
#include <tvmet/Traits.h>
|
||||||
#include <tvmet/xpr/Null.h>
|
#include <tvmet/xpr/Null.h>
|
||||||
|
|
||||||
namespace tvmet {
|
namespace tvmet {
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#ifndef TVMET_META_VECTOR_H
|
#ifndef TVMET_META_VECTOR_H
|
||||||
#define TVMET_META_VECTOR_H
|
#define TVMET_META_VECTOR_H
|
||||||
|
|
||||||
#include <tvmet/NumericTraits.h>
|
#include <tvmet/Traits.h>
|
||||||
#include <tvmet/xpr/Null.h>
|
#include <tvmet/xpr/Null.h>
|
||||||
|
|
||||||
namespace tvmet {
|
namespace tvmet {
|
||||||
@ -72,7 +72,7 @@ public:
|
|||||||
/** build the product of the vector. */
|
/** build the product of the vector. */
|
||||||
template<class E>
|
template<class E>
|
||||||
static inline
|
static inline
|
||||||
typename NumericTraits<
|
typename Traits<
|
||||||
typename E::value_type
|
typename E::value_type
|
||||||
>::sum_type
|
>::sum_type
|
||||||
product(const E& e) {
|
product(const E& e) {
|
||||||
|
@ -1,88 +0,0 @@
|
|||||||
/* This file is part of Eigen, a C++ template library for linear algebra
|
|
||||||
* Copyright (C) 2006-2007 Benoit Jacob <jacob@math.jussieu.fr>
|
|
||||||
*
|
|
||||||
* This library 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 2.1 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library 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 for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
* $Id: SelfTest.cc,v 1.1 2004/04/24 11:55:15 opetzold Exp $
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef TVMET_UTIL_RANDOM_H
|
|
||||||
#define TVMET_UTIL_RANDOM_H
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
# if __GNUC__>=4
|
|
||||||
# define EIGEN_WITH_GCC_4_OR_LATER
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
#ifdef EIGEN_USE_COMPLEX
|
|
||||||
#include <complex>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace tvmet {
|
|
||||||
|
|
||||||
namespace util {
|
|
||||||
|
|
||||||
/** Stores in x a random int between -RAND_MAX/2 and RAND_MAX/2 */
|
|
||||||
inline void pickRandom( int & x )
|
|
||||||
{
|
|
||||||
x = rand() - RAND_MAX / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/** Stores in x a random float between -1.0 and 1.0 */
|
|
||||||
inline void pickRandom( float & x )
|
|
||||||
{
|
|
||||||
x = 2.0f * rand() / RAND_MAX - 1.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Stores in x a random double between -1.0 and 1.0 */
|
|
||||||
inline void pickRandom( double & x )
|
|
||||||
{
|
|
||||||
x = 2.0 * rand() / RAND_MAX - 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef EIGEN_USE_COMPLEX
|
|
||||||
/** Stores in the real and imaginary parts of x
|
|
||||||
* random values between -1.0 and 1.0 */
|
|
||||||
template<typename T> void pickRandom( std::complex<T> & x )
|
|
||||||
{
|
|
||||||
#ifdef EIGEN_WITH_GCC_4_OR_LATER
|
|
||||||
pickRandom( x.real() );
|
|
||||||
pickRandom( x.imag() );
|
|
||||||
#else // workaround by David Faure for MacOS 10.3 and GCC 3.3, commit 630812
|
|
||||||
T r = x.real();
|
|
||||||
T i = x.imag();
|
|
||||||
pickRandom( r );
|
|
||||||
pickRandom( i );
|
|
||||||
x = std::complex<T>(r,i);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif // EIGEN_USE_COMPLEX
|
|
||||||
|
|
||||||
template<typename T> T someRandom()
|
|
||||||
{
|
|
||||||
T t;
|
|
||||||
pickRandom(t);
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace util
|
|
||||||
|
|
||||||
} // namespace tvmet
|
|
||||||
|
|
||||||
#endif // TVMET_UTIL_RANDOM_H
|
|
@ -63,8 +63,8 @@ public:
|
|||||||
ops_rhs = E2::ops,
|
ops_rhs = E2::ops,
|
||||||
M = Rows1 * Cols1 * Cols2,
|
M = Rows1 * Cols1 * Cols2,
|
||||||
N = Rows1 * (Cols1 - 1) * Cols2,
|
N = Rows1 * (Cols1 - 1) * Cols2,
|
||||||
ops_plus = M * NumericTraits<value_type>::ops_plus,
|
ops_plus = M * Traits<value_type>::ops_plus,
|
||||||
ops_muls = N * NumericTraits<value_type>::ops_muls,
|
ops_muls = N * Traits<value_type>::ops_muls,
|
||||||
ops = ops_plus + ops_muls,
|
ops = ops_plus + ops_muls,
|
||||||
use_meta = Rows1*Cols2 < TVMET_COMPLEXITY_MM_TRIGGER ? true : false
|
use_meta = Rows1*Cols2 < TVMET_COMPLEXITY_MM_TRIGGER ? true : false
|
||||||
};
|
};
|
||||||
|
@ -64,8 +64,8 @@ public:
|
|||||||
ops_rhs = E2::ops,
|
ops_rhs = E2::ops,
|
||||||
M = Rows1 * Cols1 * Cols2,
|
M = Rows1 * Cols1 * Cols2,
|
||||||
N = Rows1 * (Cols1-1) * Cols2,
|
N = Rows1 * (Cols1-1) * Cols2,
|
||||||
ops_plus = M * NumericTraits<value_type>::ops_plus,
|
ops_plus = M * Traits<value_type>::ops_plus,
|
||||||
ops_muls = N * NumericTraits<value_type>::ops_muls,
|
ops_muls = N * Traits<value_type>::ops_muls,
|
||||||
ops = ops_plus + ops_muls,
|
ops = ops_plus + ops_muls,
|
||||||
use_meta = Cols2*Rows1 < TVMET_COMPLEXITY_MM_TRIGGER ? true : false
|
use_meta = Cols2*Rows1 < TVMET_COMPLEXITY_MM_TRIGGER ? true : false
|
||||||
};
|
};
|
||||||
|
@ -65,8 +65,8 @@ public:
|
|||||||
Rows2 = Cols1,
|
Rows2 = Cols1,
|
||||||
M = Rows1 * Cols1 * Rows1,
|
M = Rows1 * Cols1 * Rows1,
|
||||||
N = Rows1 * (Cols1 - 1) * Rows2,
|
N = Rows1 * (Cols1 - 1) * Rows2,
|
||||||
ops_plus = M * NumericTraits<value_type>::ops_plus,
|
ops_plus = M * Traits<value_type>::ops_plus,
|
||||||
ops_muls = N * NumericTraits<value_type>::ops_muls,
|
ops_muls = N * Traits<value_type>::ops_muls,
|
||||||
ops = ops_plus + ops_muls,
|
ops = ops_plus + ops_muls,
|
||||||
use_meta = Rows1*Rows2 < TVMET_COMPLEXITY_MM_TRIGGER ? true : false
|
use_meta = Rows1*Rows2 < TVMET_COMPLEXITY_MM_TRIGGER ? true : false
|
||||||
};
|
};
|
||||||
|
@ -61,8 +61,8 @@ public:
|
|||||||
ops_rhs = E2::ops,
|
ops_rhs = E2::ops,
|
||||||
M = Rows * Cols,
|
M = Rows * Cols,
|
||||||
N = Rows * (Cols - 1),
|
N = Rows * (Cols - 1),
|
||||||
ops_plus = M * NumericTraits<value_type>::ops_plus,
|
ops_plus = M * Traits<value_type>::ops_plus,
|
||||||
ops_muls = N * NumericTraits<value_type>::ops_muls,
|
ops_muls = N * Traits<value_type>::ops_muls,
|
||||||
ops = ops_plus + ops_muls,
|
ops = ops_plus + ops_muls,
|
||||||
use_meta = Rows*Cols < TVMET_COMPLEXITY_MV_TRIGGER ? true : false
|
use_meta = Rows*Cols < TVMET_COMPLEXITY_MV_TRIGGER ? true : false
|
||||||
};
|
};
|
||||||
|
@ -255,7 +255,7 @@ trans(const XprMatrix<E, Rows, Cols>& rhs) _tvmet_always_inline;
|
|||||||
|
|
||||||
#if 0 // XXX needs declaration of meta::Matrix<Sz, Sz, 0, 0>::trace
|
#if 0 // XXX needs declaration of meta::Matrix<Sz, Sz, 0, 0>::trace
|
||||||
template<class E, int Sz>
|
template<class E, int Sz>
|
||||||
typename NumericTraits<typename E::value_type>::sum_type
|
typename Traits<typename E::value_type>::sum_type
|
||||||
trace(const XprMatrix<E, Sz, Sz>& m)_tvmet_always_inline;
|
trace(const XprMatrix<E, Sz, Sz>& m)_tvmet_always_inline;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -649,7 +649,7 @@ trans(const XprMatrix<E, Rows, Cols>& rhs) {
|
|||||||
*/
|
*/
|
||||||
template<class E, int Sz>
|
template<class E, int Sz>
|
||||||
inline
|
inline
|
||||||
typename NumericTraits<typename E::value_type>::sum_type
|
typename Traits<typename E::value_type>::sum_type
|
||||||
trace(const XprMatrix<E, Sz, Sz>& m) {
|
trace(const XprMatrix<E, Sz, Sz>& m) {
|
||||||
return meta::Matrix<Sz, Sz, 0, 0>::trace(m);
|
return meta::Matrix<Sz, Sz, 0, 0>::trace(m);
|
||||||
}
|
}
|
||||||
|
@ -65,8 +65,8 @@ public:
|
|||||||
ops_rhs = E2::ops,
|
ops_rhs = E2::ops,
|
||||||
M = Rows1 * Cols1 * Cols2,
|
M = Rows1 * Cols1 * Cols2,
|
||||||
N = (Rows1-1) * Cols1 * Cols2,
|
N = (Rows1-1) * Cols1 * Cols2,
|
||||||
ops_plus = M * NumericTraits<value_type>::ops_plus,
|
ops_plus = M * Traits<value_type>::ops_plus,
|
||||||
ops_muls = N * NumericTraits<value_type>::ops_muls,
|
ops_muls = N * Traits<value_type>::ops_muls,
|
||||||
ops = ops_plus + ops_muls,
|
ops = ops_plus + ops_muls,
|
||||||
use_meta = Cols1*Cols2 < TVMET_COMPLEXITY_MM_TRIGGER ? true : false
|
use_meta = Cols1*Cols2 < TVMET_COMPLEXITY_MM_TRIGGER ? true : false
|
||||||
};
|
};
|
||||||
|
@ -61,8 +61,8 @@ public:
|
|||||||
ops_rhs = E2::ops,
|
ops_rhs = E2::ops,
|
||||||
M = Cols * Rows,
|
M = Cols * Rows,
|
||||||
N = Cols * (Rows - 1),
|
N = Cols * (Rows - 1),
|
||||||
ops_plus = M * NumericTraits<value_type>::ops_plus,
|
ops_plus = M * Traits<value_type>::ops_plus,
|
||||||
ops_muls = N * NumericTraits<value_type>::ops_muls,
|
ops_muls = N * Traits<value_type>::ops_muls,
|
||||||
ops = ops_plus + ops_muls,
|
ops = ops_plus + ops_muls,
|
||||||
use_meta = Rows*Cols < TVMET_COMPLEXITY_MV_TRIGGER ? true : false
|
use_meta = Rows*Cols < TVMET_COMPLEXITY_MV_TRIGGER ? true : false
|
||||||
};
|
};
|
||||||
|
@ -163,12 +163,12 @@ TVMET_DECLARE_MACRO(div)
|
|||||||
|
|
||||||
|
|
||||||
template<class E, int Sz>
|
template<class E, int Sz>
|
||||||
typename NumericTraits<typename E::value_type>::sum_type
|
typename Traits<typename E::value_type>::sum_type
|
||||||
sum(const XprVector<E, Sz>& v) _tvmet_always_inline;
|
sum(const XprVector<E, Sz>& v) _tvmet_always_inline;
|
||||||
|
|
||||||
|
|
||||||
template<class E, int Sz>
|
template<class E, int Sz>
|
||||||
typename NumericTraits<typename E::value_type>::sum_type
|
typename Traits<typename E::value_type>::sum_type
|
||||||
product(const XprVector<E, Sz>& v) _tvmet_always_inline;
|
product(const XprVector<E, Sz>& v) _tvmet_always_inline;
|
||||||
|
|
||||||
|
|
||||||
@ -220,12 +220,12 @@ cross(const XprVector<E, 3>& lhs,
|
|||||||
|
|
||||||
|
|
||||||
template<class E, int Sz>
|
template<class E, int Sz>
|
||||||
typename NumericTraits<typename E::value_type>::sum_type
|
typename Traits<typename E::value_type>::sum_type
|
||||||
norm1(const XprVector<E, Sz>& v) _tvmet_always_inline;
|
norm1(const XprVector<E, Sz>& v) _tvmet_always_inline;
|
||||||
|
|
||||||
|
|
||||||
template<class E, int Sz>
|
template<class E, int Sz>
|
||||||
typename NumericTraits<typename E::value_type>::sum_type
|
typename Traits<typename E::value_type>::sum_type
|
||||||
norm2(const XprVector<E, Sz>& v) _tvmet_always_inline;
|
norm2(const XprVector<E, Sz>& v) _tvmet_always_inline;
|
||||||
|
|
||||||
|
|
||||||
@ -418,7 +418,7 @@ TVMET_IMPLEMENT_MACRO(div)
|
|||||||
*/
|
*/
|
||||||
template<class E, int Sz>
|
template<class E, int Sz>
|
||||||
inline
|
inline
|
||||||
typename NumericTraits<typename E::value_type>::sum_type
|
typename Traits<typename E::value_type>::sum_type
|
||||||
sum(const XprVector<E, Sz>& v) {
|
sum(const XprVector<E, Sz>& v) {
|
||||||
return meta::Vector<Sz>::sum(v);
|
return meta::Vector<Sz>::sum(v);
|
||||||
}
|
}
|
||||||
@ -436,7 +436,7 @@ sum(const XprVector<E, Sz>& v) {
|
|||||||
*/
|
*/
|
||||||
template<class E, int Sz>
|
template<class E, int Sz>
|
||||||
inline
|
inline
|
||||||
typename NumericTraits<typename E::value_type>::sum_type
|
typename Traits<typename E::value_type>::sum_type
|
||||||
product(const XprVector<E, Sz>& v) {
|
product(const XprVector<E, Sz>& v) {
|
||||||
return meta::Vector<Sz>::product(v);
|
return meta::Vector<Sz>::product(v);
|
||||||
}
|
}
|
||||||
@ -585,7 +585,7 @@ cross(const Vector<T1, 3>& lhs, const XprVector<E2, 3>& rhs) {
|
|||||||
*/
|
*/
|
||||||
template<class E, int Sz>
|
template<class E, int Sz>
|
||||||
inline
|
inline
|
||||||
typename NumericTraits<typename E::value_type>::sum_type
|
typename Traits<typename E::value_type>::sum_type
|
||||||
norm1(const XprVector<E, Sz>& v) {
|
norm1(const XprVector<E, Sz>& v) {
|
||||||
return sum(abs(v));
|
return sum(abs(v));
|
||||||
}
|
}
|
||||||
@ -606,7 +606,7 @@ norm1(const XprVector<E, Sz>& v) {
|
|||||||
*/
|
*/
|
||||||
template<class E, int Sz>
|
template<class E, int Sz>
|
||||||
inline
|
inline
|
||||||
typename NumericTraits<typename E::value_type>::sum_type
|
typename Traits<typename E::value_type>::sum_type
|
||||||
norm2(const XprVector<E, Sz>& v) {
|
norm2(const XprVector<E, Sz>& v) {
|
||||||
typedef typename E::value_type value_type;
|
typedef typename E::value_type value_type;
|
||||||
return static_cast<value_type>( std::sqrt(static_cast<value_type>(dot(v, v))) );
|
return static_cast<value_type>( std::sqrt(static_cast<value_type>(dot(v, v))) );
|
||||||
|
@ -11,9 +11,9 @@ INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR} )
|
|||||||
SET(testsuite_SOURCES
|
SET(testsuite_SOURCES
|
||||||
main.cpp
|
main.cpp
|
||||||
selftest.cpp
|
selftest.cpp
|
||||||
testnumerictraits.cpp
|
testtraits.cpp
|
||||||
# TestNumericTraits.h TestNumericTraits.cc
|
# TestTraits.h TestTraits.cc
|
||||||
# TestNumericTraitsComplex.h TestNumericTraitsComplex.cc
|
# TestTraitsComplex.h TestTraitsComplex.cc
|
||||||
# TestConstruction.h TestConstruction.cc
|
# TestConstruction.h TestConstruction.cc
|
||||||
# TestComplexMatrix.h TestComplexMatrix.cc
|
# TestComplexMatrix.h TestComplexMatrix.cc
|
||||||
# TestComplexVector.h TestComplexVector.cc
|
# TestComplexVector.h TestComplexVector.cc
|
||||||
|
@ -18,13 +18,13 @@
|
|||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*
|
*
|
||||||
* $Id: TestNumericTraits.cc,v 1.1 2004/09/15 07:51:43 opetzold Exp $
|
* $Id: TestTraits.cc,v 1.1 2004/09/15 07:51:43 opetzold Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <complex>
|
#include <complex>
|
||||||
|
|
||||||
#include <TestNumericTraits.h>
|
#include <TestTraits.h>
|
||||||
#include <cppunit/extensions/HelperMacros.h>
|
#include <cppunit/extensions/HelperMacros.h>
|
||||||
|
|
||||||
|
|
||||||
@ -32,17 +32,17 @@
|
|||||||
* instance
|
* instance
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( TestNumericTraits<char> );
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestTraits<char> );
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( TestNumericTraits<unsigned char> );
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestTraits<unsigned char> );
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( TestNumericTraits<short int> );
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestTraits<short int> );
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( TestNumericTraits<unsigned short int> );
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestTraits<unsigned short int> );
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( TestNumericTraits<int> );
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestTraits<int> );
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( TestNumericTraits<unsigned int> );
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestTraits<unsigned int> );
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( TestNumericTraits<long> );
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestTraits<long> );
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( TestNumericTraits<unsigned long> );
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestTraits<unsigned long> );
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( TestNumericTraits<float> );
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestTraits<float> );
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( TestNumericTraits<double> );
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestTraits<double> );
|
||||||
#if defined(TVMET_HAVE_LONG_DOUBLE)
|
#if defined(TVMET_HAVE_LONG_DOUBLE)
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( TestNumericTraits<long double> );
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestTraits<long double> );
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*
|
*
|
||||||
* $Id: TestNumericTraits.h,v 1.2 2004/11/04 18:12:40 opetzold Exp $
|
* $Id: TestTraits.h,v 1.2 2004/11/04 18:12:40 opetzold Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TVMET_TEST_NUMERIC_TRAITS_H
|
#ifndef TVMET_TEST_NUMERIC_TRAITS_H
|
||||||
@ -34,9 +34,9 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class TestNumericTraits : public CppUnit::TestFixture
|
class TestTraits : public CppUnit::TestFixture
|
||||||
{
|
{
|
||||||
CPPUNIT_TEST_SUITE( TestNumericTraits );
|
CPPUNIT_TEST_SUITE( TestTraits );
|
||||||
CPPUNIT_TEST( Real );
|
CPPUNIT_TEST( Real );
|
||||||
CPPUNIT_TEST( Imag );
|
CPPUNIT_TEST( Imag );
|
||||||
CPPUNIT_TEST( Conj );
|
CPPUNIT_TEST( Conj );
|
||||||
@ -53,7 +53,7 @@ private:
|
|||||||
typedef tvmet::Matrix<T, 3, 3> matrix_type;
|
typedef tvmet::Matrix<T, 3, 3> matrix_type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TestNumericTraits()
|
TestTraits()
|
||||||
: m_real(4), m_imag(9),
|
: m_real(4), m_imag(9),
|
||||||
m_conj(16),
|
m_conj(16),
|
||||||
m_abs_Q1(7), m_abs_Q2(-m_abs_Q1)
|
m_abs_Q1(7), m_abs_Q2(-m_abs_Q1)
|
||||||
@ -95,10 +95,10 @@ private:
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void TestNumericTraits<T>::setUp () { }
|
void TestTraits<T>::setUp () { }
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void TestNumericTraits<T>::tearDown() { }
|
void TestTraits<T>::tearDown() { }
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Implementation Part II
|
* Implementation Part II
|
||||||
@ -106,11 +106,11 @@ void TestNumericTraits<T>::tearDown() { }
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraits<T>::Real()
|
TestTraits<T>::Real()
|
||||||
{
|
{
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type real_type;
|
typedef typename tvmet::Traits<T>::base_type real_type;
|
||||||
|
|
||||||
real_type r = tvmet::NumericTraits<T>::real(m_real);
|
real_type r = tvmet::Traits<T>::real(m_real);
|
||||||
|
|
||||||
CPPUNIT_ASSERT( r == m_real );
|
CPPUNIT_ASSERT( r == m_real );
|
||||||
}
|
}
|
||||||
@ -118,29 +118,29 @@ TestNumericTraits<T>::Real()
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraits<T>::Imag()
|
TestTraits<T>::Imag()
|
||||||
{
|
{
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type imag_type;
|
typedef typename tvmet::Traits<T>::base_type imag_type;
|
||||||
|
|
||||||
imag_type r = tvmet::NumericTraits<T>::imag(m_imag);
|
imag_type r = tvmet::Traits<T>::imag(m_imag);
|
||||||
|
|
||||||
CPPUNIT_ASSERT( r == 0 );
|
CPPUNIT_ASSERT( r == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// conj only for signed types !!
|
// conj only for signed types !!
|
||||||
template <> void TestNumericTraits<unsigned char>::Conj() { }
|
template <> void TestTraits<unsigned char>::Conj() { }
|
||||||
template <> void TestNumericTraits<unsigned short int>::Conj() { }
|
template <> void TestTraits<unsigned short int>::Conj() { }
|
||||||
template <> void TestNumericTraits<unsigned int>::Conj() { }
|
template <> void TestTraits<unsigned int>::Conj() { }
|
||||||
template <> void TestNumericTraits<unsigned long>::Conj() { }
|
template <> void TestTraits<unsigned long>::Conj() { }
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraits<T>::Conj()
|
TestTraits<T>::Conj()
|
||||||
{
|
{
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type conj_type;
|
typedef typename tvmet::Traits<T>::base_type conj_type;
|
||||||
|
|
||||||
conj_type r = tvmet::NumericTraits<T>::conj(m_conj);
|
conj_type r = tvmet::Traits<T>::conj(m_conj);
|
||||||
|
|
||||||
CPPUNIT_ASSERT( r == m_conj );
|
CPPUNIT_ASSERT( r == m_conj );
|
||||||
}
|
}
|
||||||
@ -148,16 +148,16 @@ TestNumericTraits<T>::Conj()
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraits<T>::Abs()
|
TestTraits<T>::Abs()
|
||||||
{
|
{
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type value_type;
|
typedef typename tvmet::Traits<T>::base_type value_type;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
is_signed = std::numeric_limits<value_type>::is_signed
|
is_signed = std::numeric_limits<value_type>::is_signed
|
||||||
};
|
};
|
||||||
|
|
||||||
value_type r1 = tvmet::NumericTraits<T>::abs(m_abs_Q1);
|
value_type r1 = tvmet::Traits<T>::abs(m_abs_Q1);
|
||||||
value_type r2 = tvmet::NumericTraits<T>::abs(m_abs_Q2);
|
value_type r2 = tvmet::Traits<T>::abs(m_abs_Q2);
|
||||||
|
|
||||||
CPPUNIT_ASSERT( r1 == m_abs_Q1 );
|
CPPUNIT_ASSERT( r1 == m_abs_Q1 );
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ TestNumericTraits<T>::Abs()
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraits<T>::AbsHelper(tvmet::dispatch<true>, const T& r)
|
TestTraits<T>::AbsHelper(tvmet::dispatch<true>, const T& r)
|
||||||
{
|
{
|
||||||
// signed type
|
// signed type
|
||||||
CPPUNIT_ASSERT( r == (m_abs_Q1) );
|
CPPUNIT_ASSERT( r == (m_abs_Q1) );
|
||||||
@ -177,7 +177,7 @@ TestNumericTraits<T>::AbsHelper(tvmet::dispatch<true>, const T& r)
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraits<T>::AbsHelper(tvmet::dispatch<false>, const T& r)
|
TestTraits<T>::AbsHelper(tvmet::dispatch<false>, const T& r)
|
||||||
{
|
{
|
||||||
// unsigned type
|
// unsigned type
|
||||||
CPPUNIT_ASSERT( r == T(-m_abs_Q1) );
|
CPPUNIT_ASSERT( r == T(-m_abs_Q1) );
|
||||||
@ -186,12 +186,12 @@ TestNumericTraits<T>::AbsHelper(tvmet::dispatch<false>, const T& r)
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraits<T>::Sqrt()
|
TestTraits<T>::Sqrt()
|
||||||
{
|
{
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type value_type;
|
typedef typename tvmet::Traits<T>::base_type value_type;
|
||||||
|
|
||||||
value_type r1 = tvmet::NumericTraits<T>::sqrt(m_real);
|
value_type r1 = tvmet::Traits<T>::sqrt(m_real);
|
||||||
value_type r2 = tvmet::NumericTraits<T>::sqrt(m_imag);
|
value_type r2 = tvmet::Traits<T>::sqrt(m_imag);
|
||||||
|
|
||||||
CPPUNIT_ASSERT( r1 == 2 );
|
CPPUNIT_ASSERT( r1 == 2 );
|
||||||
CPPUNIT_ASSERT( r2 == 3 );
|
CPPUNIT_ASSERT( r2 == 3 );
|
||||||
@ -200,56 +200,56 @@ TestNumericTraits<T>::Sqrt()
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraits<T>::Norm_1()
|
TestTraits<T>::Norm_1()
|
||||||
{
|
{
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type value_type;
|
typedef typename tvmet::Traits<T>::base_type value_type;
|
||||||
|
|
||||||
value_type r = tvmet::NumericTraits<T>::norm_1(m_real);
|
value_type r = tvmet::Traits<T>::norm_1(m_real);
|
||||||
|
|
||||||
CPPUNIT_ASSERT( r == tvmet::NumericTraits<T>::abs(m_real) );
|
CPPUNIT_ASSERT( r == tvmet::Traits<T>::abs(m_real) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraits<T>::Norm_2()
|
TestTraits<T>::Norm_2()
|
||||||
{
|
{
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type value_type;
|
typedef typename tvmet::Traits<T>::base_type value_type;
|
||||||
|
|
||||||
value_type r = tvmet::NumericTraits<T>::norm_2(m_real);
|
value_type r = tvmet::Traits<T>::norm_2(m_real);
|
||||||
|
|
||||||
CPPUNIT_ASSERT( r == tvmet::NumericTraits<T>::abs(m_real) );
|
CPPUNIT_ASSERT( r == tvmet::Traits<T>::abs(m_real) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraits<T>::Norm_Inf()
|
TestTraits<T>::Norm_Inf()
|
||||||
{
|
{
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type value_type;
|
typedef typename tvmet::Traits<T>::base_type value_type;
|
||||||
|
|
||||||
value_type r = tvmet::NumericTraits<T>::norm_inf(m_real);
|
value_type r = tvmet::Traits<T>::norm_inf(m_real);
|
||||||
|
|
||||||
CPPUNIT_ASSERT( r == tvmet::NumericTraits<T>::abs(m_real) );
|
CPPUNIT_ASSERT( r == tvmet::Traits<T>::abs(m_real) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraits<T>::Equals()
|
TestTraits<T>::Equals()
|
||||||
{
|
{
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type value_type;
|
typedef typename tvmet::Traits<T>::base_type value_type;
|
||||||
|
|
||||||
value_type lhs, rhs;
|
value_type lhs, rhs;
|
||||||
|
|
||||||
lhs = rhs = 47;
|
lhs = rhs = 47;
|
||||||
|
|
||||||
CPPUNIT_ASSERT( true == tvmet::NumericTraits<T>::equals(lhs,rhs) );
|
CPPUNIT_ASSERT( true == tvmet::Traits<T>::equals(lhs,rhs) );
|
||||||
|
|
||||||
// a not very intelligent test
|
// a not very intelligent test
|
||||||
rhs += 1;
|
rhs += 1;
|
||||||
|
|
||||||
CPPUNIT_ASSERT( false == tvmet::NumericTraits<T>::equals(lhs,rhs) );
|
CPPUNIT_ASSERT( false == tvmet::Traits<T>::equals(lhs,rhs) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,13 +18,13 @@
|
|||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*
|
*
|
||||||
* $Id: TestNumericTraitsComplex.cc,v 1.1 2004/09/15 07:51:44 opetzold Exp $
|
* $Id: TestTraitsComplex.cc,v 1.1 2004/09/15 07:51:44 opetzold Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <complex>
|
#include <complex>
|
||||||
|
|
||||||
#include <TestNumericTraitsComplex.h>
|
#include <TestTraitsComplex.h>
|
||||||
#include <cppunit/extensions/HelperMacros.h>
|
#include <cppunit/extensions/HelperMacros.h>
|
||||||
|
|
||||||
|
|
||||||
@ -33,13 +33,13 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if defined(EIGEN_USE_COMPLEX)
|
#if defined(EIGEN_USE_COMPLEX)
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( TestNumericTraitsComplex< std::complex<int> > );
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestTraitsComplex< std::complex<int> > );
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( TestNumericTraitsComplex< std::complex<unsigned int> > );
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestTraitsComplex< std::complex<unsigned int> > );
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( TestNumericTraitsComplex< std::complex<long> > );
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestTraitsComplex< std::complex<long> > );
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( TestNumericTraitsComplex< std::complex<unsigned long> > );
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestTraitsComplex< std::complex<unsigned long> > );
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( TestNumericTraitsComplex< std::complex<float> > );
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestTraitsComplex< std::complex<float> > );
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( TestNumericTraitsComplex< std::complex<double> > );
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestTraitsComplex< std::complex<double> > );
|
||||||
# if defined(TVMET_HAVE_LONG_DOUBLE)
|
# if defined(TVMET_HAVE_LONG_DOUBLE)
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( TestNumericTraitsComplex< std::complex<long double> > );
|
CPPUNIT_TEST_SUITE_REGISTRATION( TestTraitsComplex< std::complex<long double> > );
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*
|
*
|
||||||
* $Id: TestNumericTraitsComplex.h,v 1.2 2004/11/04 18:12:40 opetzold Exp $
|
* $Id: TestTraitsComplex.h,v 1.2 2004/11/04 18:12:40 opetzold Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TVMET_TEST_NUMERIC_TRAITS_H
|
#ifndef TVMET_TEST_NUMERIC_TRAITS_H
|
||||||
@ -34,9 +34,9 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class TestNumericTraitsComplex : public CppUnit::TestFixture
|
class TestTraitsComplex : public CppUnit::TestFixture
|
||||||
{
|
{
|
||||||
CPPUNIT_TEST_SUITE( TestNumericTraitsComplex );
|
CPPUNIT_TEST_SUITE( TestTraitsComplex );
|
||||||
CPPUNIT_TEST( Real );
|
CPPUNIT_TEST( Real );
|
||||||
CPPUNIT_TEST( Imag );
|
CPPUNIT_TEST( Imag );
|
||||||
CPPUNIT_TEST( Conj );
|
CPPUNIT_TEST( Conj );
|
||||||
@ -53,7 +53,7 @@ private:
|
|||||||
typedef tvmet::Matrix<T, 3, 3> matrix_type;
|
typedef tvmet::Matrix<T, 3, 3> matrix_type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TestNumericTraitsComplex()
|
TestTraitsComplex()
|
||||||
: m_p_real( 3), m_p_imag( 4),
|
: m_p_real( 3), m_p_imag( 4),
|
||||||
m_n_real(-3), m_n_imag(-4),
|
m_n_real(-3), m_n_imag(-4),
|
||||||
m_z1(m_p_real, m_p_imag),
|
m_z1(m_p_real, m_p_imag),
|
||||||
@ -83,19 +83,19 @@ protected:
|
|||||||
private:
|
private:
|
||||||
// Helper
|
// Helper
|
||||||
void AbsHelper(tvmet::dispatch<true>,
|
void AbsHelper(tvmet::dispatch<true>,
|
||||||
typename tvmet::NumericTraits<T>::base_type);
|
typename tvmet::Traits<T>::base_type);
|
||||||
void AbsHelper(tvmet::dispatch<false>,
|
void AbsHelper(tvmet::dispatch<false>,
|
||||||
typename tvmet::NumericTraits<T>::base_type);
|
typename tvmet::Traits<T>::base_type);
|
||||||
void SqrtHelper(tvmet::dispatch<true>);
|
void SqrtHelper(tvmet::dispatch<true>);
|
||||||
void SqrtHelper(tvmet::dispatch<false>);
|
void SqrtHelper(tvmet::dispatch<false>);
|
||||||
void NormHelper(tvmet::dispatch<true>,
|
void NormHelper(tvmet::dispatch<true>,
|
||||||
typename tvmet::NumericTraits<T>::base_type);
|
typename tvmet::Traits<T>::base_type);
|
||||||
void NormHelper(tvmet::dispatch<false>,
|
void NormHelper(tvmet::dispatch<false>,
|
||||||
typename tvmet::NumericTraits<T>::base_type);
|
typename tvmet::Traits<T>::base_type);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type base_type;
|
typedef typename tvmet::Traits<T>::base_type base_type;
|
||||||
typedef T value_type;
|
typedef T value_type;
|
||||||
|
|
||||||
const base_type m_p_real;
|
const base_type m_p_real;
|
||||||
@ -115,10 +115,10 @@ private:
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void TestNumericTraitsComplex<T>::setUp () { }
|
void TestTraitsComplex<T>::setUp () { }
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void TestNumericTraitsComplex<T>::tearDown() { }
|
void TestTraitsComplex<T>::tearDown() { }
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Implementation Part II
|
* Implementation Part II
|
||||||
@ -126,14 +126,14 @@ void TestNumericTraitsComplex<T>::tearDown() { }
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraitsComplex<T>::Real()
|
TestTraitsComplex<T>::Real()
|
||||||
{
|
{
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type base_type;
|
typedef typename tvmet::Traits<T>::base_type base_type;
|
||||||
|
|
||||||
base_type r1 = tvmet::NumericTraits<T>::real(m_z1);
|
base_type r1 = tvmet::Traits<T>::real(m_z1);
|
||||||
base_type r2 = tvmet::NumericTraits<T>::real(m_z2);
|
base_type r2 = tvmet::Traits<T>::real(m_z2);
|
||||||
base_type r3 = tvmet::NumericTraits<T>::real(m_z3);
|
base_type r3 = tvmet::Traits<T>::real(m_z3);
|
||||||
base_type r4 = tvmet::NumericTraits<T>::real(m_z4);
|
base_type r4 = tvmet::Traits<T>::real(m_z4);
|
||||||
|
|
||||||
CPPUNIT_ASSERT( r1 == m_p_real );
|
CPPUNIT_ASSERT( r1 == m_p_real );
|
||||||
CPPUNIT_ASSERT( r2 == m_n_real );
|
CPPUNIT_ASSERT( r2 == m_n_real );
|
||||||
@ -144,14 +144,14 @@ TestNumericTraitsComplex<T>::Real()
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraitsComplex<T>::Imag()
|
TestTraitsComplex<T>::Imag()
|
||||||
{
|
{
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type base_type;
|
typedef typename tvmet::Traits<T>::base_type base_type;
|
||||||
|
|
||||||
base_type i1 = tvmet::NumericTraits<T>::imag(m_z1);
|
base_type i1 = tvmet::Traits<T>::imag(m_z1);
|
||||||
base_type i2 = tvmet::NumericTraits<T>::imag(m_z2);
|
base_type i2 = tvmet::Traits<T>::imag(m_z2);
|
||||||
base_type i3 = tvmet::NumericTraits<T>::imag(m_z3);
|
base_type i3 = tvmet::Traits<T>::imag(m_z3);
|
||||||
base_type i4 = tvmet::NumericTraits<T>::imag(m_z4);
|
base_type i4 = tvmet::Traits<T>::imag(m_z4);
|
||||||
|
|
||||||
CPPUNIT_ASSERT( i1 == m_p_imag );
|
CPPUNIT_ASSERT( i1 == m_p_imag );
|
||||||
CPPUNIT_ASSERT( i2 == m_p_imag );
|
CPPUNIT_ASSERT( i2 == m_p_imag );
|
||||||
@ -161,69 +161,69 @@ TestNumericTraitsComplex<T>::Imag()
|
|||||||
|
|
||||||
|
|
||||||
// conj only for signed types !!
|
// conj only for signed types !!
|
||||||
template <> void TestNumericTraitsComplex<std::complex<unsigned char> >::Conj() { }
|
template <> void TestTraitsComplex<std::complex<unsigned char> >::Conj() { }
|
||||||
template <> void TestNumericTraitsComplex<std::complex<unsigned short int> >::Conj() { }
|
template <> void TestTraitsComplex<std::complex<unsigned short int> >::Conj() { }
|
||||||
template <> void TestNumericTraitsComplex<std::complex<unsigned int> >::Conj() { }
|
template <> void TestTraitsComplex<std::complex<unsigned int> >::Conj() { }
|
||||||
template <> void TestNumericTraitsComplex<std::complex<unsigned long> >::Conj() { }
|
template <> void TestTraitsComplex<std::complex<unsigned long> >::Conj() { }
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraitsComplex<T>::Conj()
|
TestTraitsComplex<T>::Conj()
|
||||||
{
|
{
|
||||||
typedef typename tvmet::NumericTraits<T>::value_type value_type;
|
typedef typename tvmet::Traits<T>::value_type value_type;
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type base_type;
|
typedef typename tvmet::Traits<T>::base_type base_type;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
is_signed = std::numeric_limits<base_type>::is_signed
|
is_signed = std::numeric_limits<base_type>::is_signed
|
||||||
};
|
};
|
||||||
|
|
||||||
// conjugate
|
// conjugate
|
||||||
value_type conj_z1 = tvmet::NumericTraits<T>::conj(m_z1);
|
value_type conj_z1 = tvmet::Traits<T>::conj(m_z1);
|
||||||
value_type conj_z2 = tvmet::NumericTraits<T>::conj(m_z2);
|
value_type conj_z2 = tvmet::Traits<T>::conj(m_z2);
|
||||||
value_type conj_z3 = tvmet::NumericTraits<T>::conj(m_z3);
|
value_type conj_z3 = tvmet::Traits<T>::conj(m_z3);
|
||||||
value_type conj_z4 = tvmet::NumericTraits<T>::conj(m_z4);
|
value_type conj_z4 = tvmet::Traits<T>::conj(m_z4);
|
||||||
|
|
||||||
// real part
|
// real part
|
||||||
base_type r1 = tvmet::NumericTraits<T>::real(conj_z1);
|
base_type r1 = tvmet::Traits<T>::real(conj_z1);
|
||||||
base_type r2 = tvmet::NumericTraits<T>::real(conj_z2);
|
base_type r2 = tvmet::Traits<T>::real(conj_z2);
|
||||||
base_type r3 = tvmet::NumericTraits<T>::real(conj_z3);
|
base_type r3 = tvmet::Traits<T>::real(conj_z3);
|
||||||
base_type r4 = tvmet::NumericTraits<T>::real(conj_z4);
|
base_type r4 = tvmet::Traits<T>::real(conj_z4);
|
||||||
|
|
||||||
// imag part
|
// imag part
|
||||||
base_type i1 = tvmet::NumericTraits<T>::imag(conj_z1);
|
base_type i1 = tvmet::Traits<T>::imag(conj_z1);
|
||||||
base_type i2 = tvmet::NumericTraits<T>::imag(conj_z2);
|
base_type i2 = tvmet::Traits<T>::imag(conj_z2);
|
||||||
base_type i3 = tvmet::NumericTraits<T>::imag(conj_z3);
|
base_type i3 = tvmet::Traits<T>::imag(conj_z3);
|
||||||
base_type i4 = tvmet::NumericTraits<T>::imag(conj_z4);
|
base_type i4 = tvmet::Traits<T>::imag(conj_z4);
|
||||||
|
|
||||||
// check on real part; real is tested before
|
// check on real part; real is tested before
|
||||||
CPPUNIT_ASSERT( r1 == tvmet::NumericTraits<T>::real(m_z1) );
|
CPPUNIT_ASSERT( r1 == tvmet::Traits<T>::real(m_z1) );
|
||||||
CPPUNIT_ASSERT( r2 == tvmet::NumericTraits<T>::real(m_z2) );
|
CPPUNIT_ASSERT( r2 == tvmet::Traits<T>::real(m_z2) );
|
||||||
CPPUNIT_ASSERT( r3 == tvmet::NumericTraits<T>::real(m_z3) );
|
CPPUNIT_ASSERT( r3 == tvmet::Traits<T>::real(m_z3) );
|
||||||
CPPUNIT_ASSERT( r4 == tvmet::NumericTraits<T>::real(m_z4) );
|
CPPUNIT_ASSERT( r4 == tvmet::Traits<T>::real(m_z4) );
|
||||||
|
|
||||||
// check on imag part
|
// check on imag part
|
||||||
CPPUNIT_ASSERT( i1 == -tvmet::NumericTraits<T>::imag(m_z1) );
|
CPPUNIT_ASSERT( i1 == -tvmet::Traits<T>::imag(m_z1) );
|
||||||
CPPUNIT_ASSERT( i2 == -tvmet::NumericTraits<T>::imag(m_z2) );
|
CPPUNIT_ASSERT( i2 == -tvmet::Traits<T>::imag(m_z2) );
|
||||||
CPPUNIT_ASSERT( i3 == -tvmet::NumericTraits<T>::imag(m_z3) );
|
CPPUNIT_ASSERT( i3 == -tvmet::Traits<T>::imag(m_z3) );
|
||||||
CPPUNIT_ASSERT( i4 == -tvmet::NumericTraits<T>::imag(m_z4) );
|
CPPUNIT_ASSERT( i4 == -tvmet::Traits<T>::imag(m_z4) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraitsComplex<T>::Abs()
|
TestTraitsComplex<T>::Abs()
|
||||||
{
|
{
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type base_type;
|
typedef typename tvmet::Traits<T>::base_type base_type;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
is_signed = std::numeric_limits<base_type>::is_signed
|
is_signed = std::numeric_limits<base_type>::is_signed
|
||||||
};
|
};
|
||||||
|
|
||||||
base_type a1 = tvmet::NumericTraits<T>::abs(m_z1);
|
base_type a1 = tvmet::Traits<T>::abs(m_z1);
|
||||||
base_type a2 = tvmet::NumericTraits<T>::abs(m_z2);
|
base_type a2 = tvmet::Traits<T>::abs(m_z2);
|
||||||
base_type a3 = tvmet::NumericTraits<T>::abs(m_z3);
|
base_type a3 = tvmet::Traits<T>::abs(m_z3);
|
||||||
base_type a4 = tvmet::NumericTraits<T>::abs(m_z4);
|
base_type a4 = tvmet::Traits<T>::abs(m_z4);
|
||||||
|
|
||||||
// result depends on signed type
|
// result depends on signed type
|
||||||
AbsHelper(tvmet::dispatch<is_signed>(), a1);
|
AbsHelper(tvmet::dispatch<is_signed>(), a1);
|
||||||
@ -235,8 +235,8 @@ TestNumericTraitsComplex<T>::Abs()
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraitsComplex<T>::AbsHelper(tvmet::dispatch<true>,
|
TestTraitsComplex<T>::AbsHelper(tvmet::dispatch<true>,
|
||||||
typename tvmet::NumericTraits<T>::base_type r)
|
typename tvmet::Traits<T>::base_type r)
|
||||||
{
|
{
|
||||||
// signed type
|
// signed type
|
||||||
CPPUNIT_ASSERT( r == 5 );
|
CPPUNIT_ASSERT( r == 5 );
|
||||||
@ -245,26 +245,26 @@ TestNumericTraitsComplex<T>::AbsHelper(tvmet::dispatch<true>,
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraitsComplex<T>::AbsHelper(tvmet::dispatch<false>,
|
TestTraitsComplex<T>::AbsHelper(tvmet::dispatch<false>,
|
||||||
typename tvmet::NumericTraits<T>::base_type r)
|
typename tvmet::Traits<T>::base_type r)
|
||||||
{
|
{
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type base_type;
|
typedef typename tvmet::Traits<T>::base_type base_type;
|
||||||
|
|
||||||
base_type x = m_z1.real(); // sign doesn't matter on abs()
|
base_type x = m_z1.real(); // sign doesn't matter on abs()
|
||||||
base_type y = m_z1.imag(); // sign doesn't matter on abs()
|
base_type y = m_z1.imag(); // sign doesn't matter on abs()
|
||||||
|
|
||||||
// unsigned type
|
// unsigned type
|
||||||
CPPUNIT_ASSERT( r == static_cast<base_type>(
|
CPPUNIT_ASSERT( r == static_cast<base_type>(
|
||||||
tvmet::NumericTraits<base_type>::sqrt(x * x + y * y))
|
tvmet::Traits<base_type>::sqrt(x * x + y * y))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraitsComplex<T>::Sqrt()
|
TestTraitsComplex<T>::Sqrt()
|
||||||
{
|
{
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type base_type;
|
typedef typename tvmet::Traits<T>::base_type base_type;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
is_signed = std::numeric_limits<base_type>::is_signed
|
is_signed = std::numeric_limits<base_type>::is_signed
|
||||||
@ -277,16 +277,16 @@ TestNumericTraitsComplex<T>::Sqrt()
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraitsComplex<T>::SqrtHelper(tvmet::dispatch<true>)
|
TestTraitsComplex<T>::SqrtHelper(tvmet::dispatch<true>)
|
||||||
{
|
{
|
||||||
// signed type
|
// signed type
|
||||||
typedef typename tvmet::NumericTraits<T>::value_type value_type;
|
typedef typename tvmet::Traits<T>::value_type value_type;
|
||||||
|
|
||||||
// sqrt
|
// sqrt
|
||||||
value_type z1 = tvmet::NumericTraits<T>::sqrt(m_z1);
|
value_type z1 = tvmet::Traits<T>::sqrt(m_z1);
|
||||||
value_type z2 = tvmet::NumericTraits<T>::sqrt(m_z2);
|
value_type z2 = tvmet::Traits<T>::sqrt(m_z2);
|
||||||
value_type z3 = tvmet::NumericTraits<T>::sqrt(m_z3);
|
value_type z3 = tvmet::Traits<T>::sqrt(m_z3);
|
||||||
value_type z4 = tvmet::NumericTraits<T>::sqrt(m_z4);
|
value_type z4 = tvmet::Traits<T>::sqrt(m_z4);
|
||||||
|
|
||||||
CPPUNIT_ASSERT( z1 == value_type(2,1) );
|
CPPUNIT_ASSERT( z1 == value_type(2,1) );
|
||||||
CPPUNIT_ASSERT( z2 == value_type(1,2) );
|
CPPUNIT_ASSERT( z2 == value_type(1,2) );
|
||||||
@ -298,7 +298,7 @@ TestNumericTraitsComplex<T>::SqrtHelper(tvmet::dispatch<true>)
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraitsComplex<T>::SqrtHelper(tvmet::dispatch<false>)
|
TestTraitsComplex<T>::SqrtHelper(tvmet::dispatch<false>)
|
||||||
{
|
{
|
||||||
// unsigned type
|
// unsigned type
|
||||||
|
|
||||||
@ -306,11 +306,11 @@ TestNumericTraitsComplex<T>::SqrtHelper(tvmet::dispatch<false>)
|
|||||||
* very dirty - we assume we calculate right
|
* very dirty - we assume we calculate right
|
||||||
* on "negative" complex types */
|
* on "negative" complex types */
|
||||||
|
|
||||||
typedef typename tvmet::NumericTraits<T>::value_type value_type;
|
typedef typename tvmet::Traits<T>::value_type value_type;
|
||||||
|
|
||||||
// sqrt
|
// sqrt
|
||||||
value_type z1 = tvmet::NumericTraits<T>::sqrt(m_z1);
|
value_type z1 = tvmet::Traits<T>::sqrt(m_z1);
|
||||||
value_type z2 = tvmet::NumericTraits<T>::sqrt(m_z2);
|
value_type z2 = tvmet::Traits<T>::sqrt(m_z2);
|
||||||
|
|
||||||
CPPUNIT_ASSERT( z1 == value_type(2,1) );
|
CPPUNIT_ASSERT( z1 == value_type(2,1) );
|
||||||
CPPUNIT_ASSERT( z2 == value_type(1,2) );
|
CPPUNIT_ASSERT( z2 == value_type(1,2) );
|
||||||
@ -319,19 +319,19 @@ TestNumericTraitsComplex<T>::SqrtHelper(tvmet::dispatch<false>)
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraitsComplex<T>::Norm_1()
|
TestTraitsComplex<T>::Norm_1()
|
||||||
{
|
{
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type base_type;
|
typedef typename tvmet::Traits<T>::base_type base_type;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
is_signed = std::numeric_limits<base_type>::is_signed
|
is_signed = std::numeric_limits<base_type>::is_signed
|
||||||
};
|
};
|
||||||
|
|
||||||
// norm_1
|
// norm_1
|
||||||
base_type n1 = tvmet::NumericTraits<T>::norm_1(m_z1);
|
base_type n1 = tvmet::Traits<T>::norm_1(m_z1);
|
||||||
base_type n2 = tvmet::NumericTraits<T>::norm_1(m_z2);
|
base_type n2 = tvmet::Traits<T>::norm_1(m_z2);
|
||||||
base_type n3 = tvmet::NumericTraits<T>::norm_1(m_z3);
|
base_type n3 = tvmet::Traits<T>::norm_1(m_z3);
|
||||||
base_type n4 = tvmet::NumericTraits<T>::norm_1(m_z4);
|
base_type n4 = tvmet::Traits<T>::norm_1(m_z4);
|
||||||
|
|
||||||
// result depends on signed type
|
// result depends on signed type
|
||||||
NormHelper(tvmet::dispatch<is_signed>(), n1);
|
NormHelper(tvmet::dispatch<is_signed>(), n1);
|
||||||
@ -343,19 +343,19 @@ TestNumericTraitsComplex<T>::Norm_1()
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraitsComplex<T>::Norm_2()
|
TestTraitsComplex<T>::Norm_2()
|
||||||
{
|
{
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type base_type;
|
typedef typename tvmet::Traits<T>::base_type base_type;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
is_signed = std::numeric_limits<base_type>::is_signed
|
is_signed = std::numeric_limits<base_type>::is_signed
|
||||||
};
|
};
|
||||||
|
|
||||||
// norm_2
|
// norm_2
|
||||||
base_type n1 = tvmet::NumericTraits<T>::norm_2(m_z1);
|
base_type n1 = tvmet::Traits<T>::norm_2(m_z1);
|
||||||
base_type n2 = tvmet::NumericTraits<T>::norm_2(m_z2);
|
base_type n2 = tvmet::Traits<T>::norm_2(m_z2);
|
||||||
base_type n3 = tvmet::NumericTraits<T>::norm_2(m_z3);
|
base_type n3 = tvmet::Traits<T>::norm_2(m_z3);
|
||||||
base_type n4 = tvmet::NumericTraits<T>::norm_2(m_z4);
|
base_type n4 = tvmet::Traits<T>::norm_2(m_z4);
|
||||||
|
|
||||||
// result depends on signed type
|
// result depends on signed type
|
||||||
NormHelper(tvmet::dispatch<is_signed>(), n1);
|
NormHelper(tvmet::dispatch<is_signed>(), n1);
|
||||||
@ -367,19 +367,19 @@ TestNumericTraitsComplex<T>::Norm_2()
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraitsComplex<T>::Norm_Inf()
|
TestTraitsComplex<T>::Norm_Inf()
|
||||||
{
|
{
|
||||||
typedef typename tvmet::NumericTraits<T>::base_type base_type;
|
typedef typename tvmet::Traits<T>::base_type base_type;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
is_signed = std::numeric_limits<base_type>::is_signed
|
is_signed = std::numeric_limits<base_type>::is_signed
|
||||||
};
|
};
|
||||||
|
|
||||||
// norm_inf
|
// norm_inf
|
||||||
base_type n1 = tvmet::NumericTraits<T>::norm_inf(m_z1);
|
base_type n1 = tvmet::Traits<T>::norm_inf(m_z1);
|
||||||
base_type n2 = tvmet::NumericTraits<T>::norm_inf(m_z2);
|
base_type n2 = tvmet::Traits<T>::norm_inf(m_z2);
|
||||||
base_type n3 = tvmet::NumericTraits<T>::norm_inf(m_z3);
|
base_type n3 = tvmet::Traits<T>::norm_inf(m_z3);
|
||||||
base_type n4 = tvmet::NumericTraits<T>::norm_inf(m_z4);
|
base_type n4 = tvmet::Traits<T>::norm_inf(m_z4);
|
||||||
|
|
||||||
// result depends on signed type
|
// result depends on signed type
|
||||||
NormHelper(tvmet::dispatch<is_signed>(), n1);
|
NormHelper(tvmet::dispatch<is_signed>(), n1);
|
||||||
@ -390,8 +390,8 @@ TestNumericTraitsComplex<T>::Norm_Inf()
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraitsComplex<T>::NormHelper(tvmet::dispatch<true>,
|
TestTraitsComplex<T>::NormHelper(tvmet::dispatch<true>,
|
||||||
typename tvmet::NumericTraits<T>::base_type)
|
typename tvmet::Traits<T>::base_type)
|
||||||
{
|
{
|
||||||
// XXX To be implement
|
// XXX To be implement
|
||||||
}
|
}
|
||||||
@ -399,8 +399,8 @@ TestNumericTraitsComplex<T>::NormHelper(tvmet::dispatch<true>,
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraitsComplex<T>::NormHelper(tvmet::dispatch<false>,
|
TestTraitsComplex<T>::NormHelper(tvmet::dispatch<false>,
|
||||||
typename tvmet::NumericTraits<T>::base_type)
|
typename tvmet::Traits<T>::base_type)
|
||||||
{
|
{
|
||||||
// XXX To be implement
|
// XXX To be implement
|
||||||
}
|
}
|
||||||
@ -408,49 +408,49 @@ TestNumericTraitsComplex<T>::NormHelper(tvmet::dispatch<false>,
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void
|
void
|
||||||
TestNumericTraitsComplex<T>::Equals()
|
TestTraitsComplex<T>::Equals()
|
||||||
{
|
{
|
||||||
// XXX this test is to simple
|
// XXX this test is to simple
|
||||||
|
|
||||||
typedef typename tvmet::NumericTraits<T>::value_type value_type;
|
typedef typename tvmet::Traits<T>::value_type value_type;
|
||||||
|
|
||||||
value_type lhs, rhs;
|
value_type lhs, rhs;
|
||||||
|
|
||||||
{
|
{
|
||||||
lhs = rhs = m_z1;
|
lhs = rhs = m_z1;
|
||||||
|
|
||||||
CPPUNIT_ASSERT( true == tvmet::NumericTraits<T>::equals(lhs,rhs) );
|
CPPUNIT_ASSERT( true == tvmet::Traits<T>::equals(lhs,rhs) );
|
||||||
|
|
||||||
rhs += m_z1;
|
rhs += m_z1;
|
||||||
|
|
||||||
CPPUNIT_ASSERT( false == tvmet::NumericTraits<T>::equals(lhs,rhs) );
|
CPPUNIT_ASSERT( false == tvmet::Traits<T>::equals(lhs,rhs) );
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
lhs = rhs = m_z2;
|
lhs = rhs = m_z2;
|
||||||
|
|
||||||
CPPUNIT_ASSERT( true == tvmet::NumericTraits<T>::equals(lhs,rhs) );
|
CPPUNIT_ASSERT( true == tvmet::Traits<T>::equals(lhs,rhs) );
|
||||||
|
|
||||||
rhs += m_z2;
|
rhs += m_z2;
|
||||||
|
|
||||||
CPPUNIT_ASSERT( false == tvmet::NumericTraits<T>::equals(lhs,rhs) );
|
CPPUNIT_ASSERT( false == tvmet::Traits<T>::equals(lhs,rhs) );
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
lhs = rhs = m_z3;
|
lhs = rhs = m_z3;
|
||||||
|
|
||||||
CPPUNIT_ASSERT( true == tvmet::NumericTraits<T>::equals(lhs,rhs) );
|
CPPUNIT_ASSERT( true == tvmet::Traits<T>::equals(lhs,rhs) );
|
||||||
|
|
||||||
rhs += m_z3;
|
rhs += m_z3;
|
||||||
|
|
||||||
CPPUNIT_ASSERT( false == tvmet::NumericTraits<T>::equals(lhs,rhs) );
|
CPPUNIT_ASSERT( false == tvmet::Traits<T>::equals(lhs,rhs) );
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
lhs = rhs = m_z4;
|
lhs = rhs = m_z4;
|
||||||
|
|
||||||
CPPUNIT_ASSERT( true == tvmet::NumericTraits<T>::equals(lhs,rhs) );
|
CPPUNIT_ASSERT( true == tvmet::Traits<T>::equals(lhs,rhs) );
|
||||||
|
|
||||||
rhs += m_z4;
|
rhs += m_z4;
|
||||||
|
|
||||||
CPPUNIT_ASSERT( false == tvmet::NumericTraits<T>::equals(lhs,rhs) );
|
CPPUNIT_ASSERT( false == tvmet::Traits<T>::equals(lhs,rhs) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,9 +434,9 @@ TestVectorFunctions<T>::fn_norm() {
|
|||||||
|
|
||||||
CPPUNIT_ASSERT( t1 == sum(v1) );
|
CPPUNIT_ASSERT( t1 == sum(v1) );
|
||||||
CPPUNIT_ASSERT( t2 == sum(v1) );
|
CPPUNIT_ASSERT( t2 == sum(v1) );
|
||||||
CPPUNIT_ASSERT( std::abs(t3 - std::sqrt(static_cast<typename tvmet::NumericTraits<T>::float_type>(14)))
|
CPPUNIT_ASSERT( std::abs(t3 - std::sqrt(static_cast<typename tvmet::Traits<T>::float_type>(14)))
|
||||||
< std::numeric_limits<T>::epsilon() );
|
< std::numeric_limits<T>::epsilon() );
|
||||||
CPPUNIT_ASSERT( std::abs(t4 - std::sqrt(static_cast<typename tvmet::NumericTraits<T>::float_type>(14)))
|
CPPUNIT_ASSERT( std::abs(t4 - std::sqrt(static_cast<typename tvmet::Traits<T>::float_type>(14)))
|
||||||
< std::numeric_limits<T>::epsilon() );
|
< std::numeric_limits<T>::epsilon() );
|
||||||
|
|
||||||
r = v1/norm2(v1); // norm2 is checked before
|
r = v1/norm2(v1); // norm2 is checked before
|
||||||
|
@ -285,9 +285,9 @@ TestXprVectorFunctions<T>::fn_norm() {
|
|||||||
|
|
||||||
CPPUNIT_ASSERT( t1 == sum(v1) );
|
CPPUNIT_ASSERT( t1 == sum(v1) );
|
||||||
CPPUNIT_ASSERT( t2 == sum(v1) );
|
CPPUNIT_ASSERT( t2 == sum(v1) );
|
||||||
CPPUNIT_ASSERT( std::abs(t3 - std::sqrt(static_cast<typename tvmet::NumericTraits<T>::float_type>(14)))
|
CPPUNIT_ASSERT( std::abs(t3 - std::sqrt(static_cast<typename tvmet::Traits<T>::float_type>(14)))
|
||||||
< std::numeric_limits<T>::epsilon() );
|
< std::numeric_limits<T>::epsilon() );
|
||||||
CPPUNIT_ASSERT( std::abs(t4 - std::sqrt(static_cast<typename tvmet::NumericTraits<T>::float_type>(14)))
|
CPPUNIT_ASSERT( std::abs(t4 - std::sqrt(static_cast<typename tvmet::Traits<T>::float_type>(14)))
|
||||||
< std::numeric_limits<T>::epsilon() );
|
< std::numeric_limits<T>::epsilon() );
|
||||||
|
|
||||||
r = v1/norm2(v1); // norm2 is checked before
|
r = v1/norm2(v1); // norm2 is checked before
|
||||||
|
@ -30,12 +30,9 @@
|
|||||||
#include <tvmet/Vector.h>
|
#include <tvmet/Vector.h>
|
||||||
#include <tvmet/Matrix.h>
|
#include <tvmet/Matrix.h>
|
||||||
|
|
||||||
#include <tvmet/util/Random.h>
|
|
||||||
|
|
||||||
#include "compare.h"
|
#include "compare.h"
|
||||||
|
|
||||||
using namespace tvmet;
|
using namespace tvmet;
|
||||||
using namespace util;
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class TvmetTestSuite : public QObject
|
class TvmetTestSuite : public QObject
|
||||||
@ -47,7 +44,7 @@ class TvmetTestSuite : public QObject
|
|||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void selfTest();
|
void selfTest();
|
||||||
void testNumericTraits();
|
void testTraits();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // EIGEN_TESTSUITE_MAIN_H
|
#endif // EIGEN_TESTSUITE_MAIN_H
|
||||||
|
@ -1,86 +0,0 @@
|
|||||||
/* This file is part of Eigen, a C++ template library for linear algebra
|
|
||||||
* Copyright (C) 2007 Benoit Jacob <jacob@math.jussieu.fr>
|
|
||||||
*
|
|
||||||
* Based on Tvmet source code, http://tvmet.sourceforge.net,
|
|
||||||
* Copyright (C) 2001 - 2003 Olaf Petzold <opetzold@users.sourceforge.net>
|
|
||||||
*
|
|
||||||
* This library 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 2.1 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library 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 for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
|
||||||
* License along with this library; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
* $Id: SelfTest.cc,v 1.1 2004/04/24 11:55:15 opetzold Exp $
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "main.h"
|
|
||||||
|
|
||||||
template<typename T> struct TestNumericTraits
|
|
||||||
{
|
|
||||||
void real()
|
|
||||||
{
|
|
||||||
T x = someRandom<T>();
|
|
||||||
typedef typename NumericTraits<T>::real_type real_type;
|
|
||||||
real_type r = NumericTraits<T>::real(x);
|
|
||||||
TEST_APPROX(r, x);
|
|
||||||
}
|
|
||||||
|
|
||||||
void imag()
|
|
||||||
{
|
|
||||||
T x = someRandom<T>();
|
|
||||||
typedef typename NumericTraits<T>::real_type real_type;
|
|
||||||
real_type r = NumericTraits<T>::imag(x);
|
|
||||||
TEST_ZERO(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
void conj()
|
|
||||||
{
|
|
||||||
T x = someRandom<T>();
|
|
||||||
typedef typename NumericTraits<T>::real_type conj_type;
|
|
||||||
conj_type r = NumericTraits<T>::conj(x);
|
|
||||||
TEST_APPROX(r, x);
|
|
||||||
}
|
|
||||||
|
|
||||||
void abs()
|
|
||||||
{
|
|
||||||
T x = someRandom<T>();
|
|
||||||
typedef typename NumericTraits<T>::real_type value_type;
|
|
||||||
value_type r1 = NumericTraits<T>::abs(x);
|
|
||||||
value_type r2 = NumericTraits<T>::abs(-x);
|
|
||||||
TEST_APPROX(r1, r2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void sqrt()
|
|
||||||
{
|
|
||||||
T x = someRandom<T>();
|
|
||||||
T a = NumericTraits<T>::abs(x);
|
|
||||||
T b = NumericTraits<T>::sqrt(a);
|
|
||||||
// T could be an integer type, so b*b=a is not necessarily true
|
|
||||||
TEST_LESSTHAN(b*b, a);
|
|
||||||
TEST_LESSTHAN(a, (b+1)*(b+1));
|
|
||||||
}
|
|
||||||
|
|
||||||
TestNumericTraits()
|
|
||||||
{
|
|
||||||
real();
|
|
||||||
imag();
|
|
||||||
conj();
|
|
||||||
abs();
|
|
||||||
sqrt();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void TvmetTestSuite::testNumericTraits()
|
|
||||||
{
|
|
||||||
TestNumericTraits<int>();
|
|
||||||
TestNumericTraits<float>();
|
|
||||||
TestNumericTraits<double>();
|
|
||||||
}
|
|
126
tvmet-1.7.1/testsuite/testtraits.cpp
Normal file
126
tvmet-1.7.1/testsuite/testtraits.cpp
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
/* This file is part of Eigen, a C++ template library for linear algebra
|
||||||
|
* Copyright (C) 2007 Benoit Jacob <jacob@math.jussieu.fr>
|
||||||
|
*
|
||||||
|
* Based on Tvmet source code, http://tvmet.sourceforge.net,
|
||||||
|
* Copyright (C) 2001 - 2003 Olaf Petzold <opetzold@users.sourceforge.net>
|
||||||
|
*
|
||||||
|
* This library 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 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library 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 for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* $Id: SelfTest.cc,v 1.1 2004/04/24 11:55:15 opetzold Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
template<typename T> struct TestTraits
|
||||||
|
{
|
||||||
|
void real()
|
||||||
|
{
|
||||||
|
T x = Traits<T>::random();
|
||||||
|
typedef typename Traits<T>::real_type real_type;
|
||||||
|
real_type r = Traits<T>::real(x);
|
||||||
|
TEST_APPROX(r, x);
|
||||||
|
}
|
||||||
|
|
||||||
|
void imag()
|
||||||
|
{
|
||||||
|
T x = Traits<T>::random();
|
||||||
|
typedef typename Traits<T>::real_type real_type;
|
||||||
|
real_type r = Traits<T>::imag(x);
|
||||||
|
TEST_ZERO(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
void conj()
|
||||||
|
{
|
||||||
|
T x = Traits<T>::random();
|
||||||
|
typedef typename Traits<T>::real_type conj_type;
|
||||||
|
conj_type r = Traits<T>::conj(x);
|
||||||
|
TEST_APPROX(r, x);
|
||||||
|
}
|
||||||
|
|
||||||
|
void abs()
|
||||||
|
{
|
||||||
|
T x = Traits<T>::random();
|
||||||
|
typedef typename Traits<T>::real_type value_type;
|
||||||
|
value_type r1 = Traits<T>::abs(x);
|
||||||
|
value_type r2 = Traits<T>::abs(-x);
|
||||||
|
TEST_APPROX(r1, r2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sqrt()
|
||||||
|
{
|
||||||
|
T x = Traits<T>::random();
|
||||||
|
T a = Traits<T>::abs(x);
|
||||||
|
T b = Traits<T>::sqrt(a);
|
||||||
|
// T could be an integer type, so b*b=a is not necessarily true
|
||||||
|
TEST_LESSTHAN(b*b, a);
|
||||||
|
TEST_LESSTHAN(a, (b+1)*(b+1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void isApprox()
|
||||||
|
{
|
||||||
|
T x = Traits<T>::random();
|
||||||
|
TEST(Traits<T>::isApprox(x,x));
|
||||||
|
TEST(Traits<T>::isApprox(x,x+Traits<T>::epsilon()/10));
|
||||||
|
TEST(!Traits<T>::isApprox(x,x+1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void isNegligible()
|
||||||
|
{
|
||||||
|
T zero(0), one(1), x = Traits<T>::random();
|
||||||
|
TEST(Traits<T>::isNegligible(zero, zero));
|
||||||
|
TEST(Traits<T>::isNegligible(zero, one));
|
||||||
|
TEST(!Traits<T>::isNegligible(one, one));
|
||||||
|
if(x != zero) {
|
||||||
|
TEST(Traits<T>::isNegligible(zero, x));
|
||||||
|
}
|
||||||
|
TEST(!Traits<T>::isNegligible(one, x));
|
||||||
|
}
|
||||||
|
|
||||||
|
void isZero()
|
||||||
|
{
|
||||||
|
T zero(0), one(1), x = Traits<T>::random(), y = Traits<T>::random();
|
||||||
|
TEST(Traits<T>::isZero(zero));
|
||||||
|
TEST(!Traits<T>::isZero(one));
|
||||||
|
TEST(Traits<T>::isZero((x+y)*(x+y)-x*x-y*y-x*y-y*x));
|
||||||
|
}
|
||||||
|
|
||||||
|
void isLessThan()
|
||||||
|
{
|
||||||
|
T one(1), x = Traits<T>::random();
|
||||||
|
TEST(Traits<T>::isLessThan(x, x+one));
|
||||||
|
TEST(!Traits<T>::isLessThan(x+one, x));
|
||||||
|
TEST(Traits<T>::isLessThan(x, x+Traits<T>::epsilon()/10));
|
||||||
|
}
|
||||||
|
|
||||||
|
TestTraits()
|
||||||
|
{
|
||||||
|
real();
|
||||||
|
imag();
|
||||||
|
conj();
|
||||||
|
abs();
|
||||||
|
sqrt();
|
||||||
|
isApprox();
|
||||||
|
isNegligible();
|
||||||
|
isZero();
|
||||||
|
isLessThan();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void TvmetTestSuite::testTraits()
|
||||||
|
{
|
||||||
|
TestTraits<int>();
|
||||||
|
TestTraits<float>();
|
||||||
|
TestTraits<double>();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user