aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2008-03-06 11:36:27 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2008-03-06 11:36:27 +0000
commit138aad0ed03cb9045b1f74ce52f0e47ce02966c8 (patch)
treeb1e6ec6111cc8452177ea8d166e94124d387f331 /doc
parent8e0d548039f260db2eacb1e54e62e1acdbd4dd09 (diff)
* coefficient wise operators are more generic, with controllable result type.
- compatible with current STL's functors as well as with the extention proposal (TR1) * thanks to the above, Cast and ScalarMultiple have been removed * benchmark_suite is more flexible (compiler and matrix size)
Diffstat (limited to 'doc')
-rwxr-xr-xdoc/bench_unrolling11
-rw-r--r--doc/benchmark.cpp37
-rw-r--r--doc/benchmarkX.cpp2
-rwxr-xr-xdoc/benchmark_suite17
-rw-r--r--doc/examples/class_Cast.cpp9
-rw-r--r--doc/examples/class_CwiseBinaryOp.cpp11
-rw-r--r--doc/examples/class_CwiseUnaryOp.cpp17
7 files changed, 68 insertions, 36 deletions
diff --git a/doc/bench_unrolling b/doc/bench_unrolling
new file mode 100755
index 000000000..4af791412
--- /dev/null
+++ b/doc/bench_unrolling
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+# gcc : CXX="g++ -finline-limit=10000 -ftemplate-depth-2000 --param max-inline-recursive-depth=2000"
+# icc : CXX="icpc -fast -no-inline-max-size -fno-exceptions"
+
+for ((i=1; i<16; ++i)); do
+ echo "Matrix size: $i x $i :"
+ $CXX -O3 -I.. -DNDEBUG benchmark.cpp -DMATSIZE=$i -DEIGEN_UNROLLING_LIMIT_OPEQUAL=1024 -DEIGEN_UNROLLING_LIMIT_PRODUCT=25 -o benchmark && time ./benchmark >/dev/null
+ $CXX -O3 -I.. -DNDEBUG -finline-limit=10000 benchmark.cpp -DMATSIZE=$i -DEIGEN_DONT_USE_UNROLLED_LOOPS=1 -o benchmark && time ./benchmark >/dev/null
+ echo " "
+done
diff --git a/doc/benchmark.cpp b/doc/benchmark.cpp
index ad515e04e..0d95a5043 100644
--- a/doc/benchmark.cpp
+++ b/doc/benchmark.cpp
@@ -1,24 +1,31 @@
-// g++ -O3 -DNDEBUG benchmark.cpp -o benchmark && time ./benchmark
+// g++ -O3 -DNDEBUG -DMATSIZE=<x> benchmark.cpp -o benchmark && time ./benchmark
#include <cstdlib>
#include <cmath>
#include <Eigen/Core>
-//using namespace std;
+#ifndef MATSIZE
+#define MATSIZE 3
+#endif
+
+using namespace std;
USING_PART_OF_NAMESPACE_EIGEN
int main(int argc, char *argv[])
{
- Matrix3d I;
- Matrix3d m;
- for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++)
- {
- I(i,j) = (i==j);
- m(i,j) = (i+3*j);
- }
- for(int a = 0; a < 400000000; a++)
- {
- m = I + 0.00005 * (m + m*m);
- }
- std::cout << m << std::endl;
- return 0;
+ Matrix<double,MATSIZE,MATSIZE> I;
+ Matrix<double,MATSIZE,MATSIZE> m;
+ for(int i = 0; i < MATSIZE; i++)
+ for(int j = 0; j < MATSIZE; j++)
+ {
+ I(i,j) = (i==j);
+ m(i,j) = (i+MATSIZE*j);
+ }
+ asm("#begin");
+ for(int a = 0; a < 40000000; a++)
+ {
+ m = I + 0.00005 * (m + m*m);
+ }
+ asm("#end");
+ cout << m << endl;
+ return 0;
}
diff --git a/doc/benchmarkX.cpp b/doc/benchmarkX.cpp
index 1670341e9..1c8b6b803 100644
--- a/doc/benchmarkX.cpp
+++ b/doc/benchmarkX.cpp
@@ -7,7 +7,7 @@ USING_PART_OF_NAMESPACE_EIGEN
int main(int argc, char *argv[])
{
- MatrixXd I = MatrixXd::identity(20);
+ MatrixXd I = MatrixXd::identity(20,20);
MatrixXd m(20,20);
for(int i = 0; i < 20; i++) for(int j = 0; j < 20; j++)
{
diff --git a/doc/benchmark_suite b/doc/benchmark_suite
index e0969d0eb..9ddfccbf6 100755
--- a/doc/benchmark_suite
+++ b/doc/benchmark_suite
@@ -1,16 +1,17 @@
+#!/bin/bash
echo "Fixed size 3x3, ColumnMajor, -DNDEBUG"
-g++ -O3 -I .. -DNDEBUG benchmark.cpp -o benchmark && time ./benchmark >/dev/null
+$CXX -O3 -I .. -DNDEBUG benchmark.cpp -o benchmark && time ./benchmark >/dev/null
echo "Fixed size 3x3, ColumnMajor, with asserts"
-g++ -O3 -I .. benchmark.cpp -o benchmark && time ./benchmark >/dev/null
+$CXX -O3 -I .. benchmark.cpp -o benchmark && time ./benchmark >/dev/null
echo "Fixed size 3x3, RowMajor, -DNDEBUG"
-g++ -O3 -I .. -DEIGEN_DEFAULT_TO_ROW_MAJOR -DNDEBUG benchmark.cpp -o benchmark && time ./benchmark >/dev/null
+$CXX -O3 -I .. -DEIGEN_DEFAULT_TO_ROW_MAJOR -DNDEBUG benchmark.cpp -o benchmark && time ./benchmark >/dev/null
echo "Fixed size 3x3, RowMajor, with asserts"
-g++ -O3 -I .. -DEIGEN_DEFAULT_TO_ROW_MAJOR benchmark.cpp -o benchmark && time ./benchmark >/dev/null
+$CXX -O3 -I .. -DEIGEN_DEFAULT_TO_ROW_MAJOR benchmark.cpp -o benchmark && time ./benchmark >/dev/null
echo "Dynamic size 20x20, ColumnMajor, -DNDEBUG"
-g++ -O3 -I .. -DNDEBUG benchmarkX.cpp -o benchmarkX && time ./benchmarkX >/dev/null
+$CXX -O3 -I .. -DNDEBUG benchmarkX.cpp -o benchmarkX && time ./benchmarkX >/dev/null
echo "Dynamic size 20x20, ColumnMajor, with asserts"
-g++ -O3 -I .. benchmarkX.cpp -o benchmarkX && time ./benchmarkX >/dev/null
+$CXX -O3 -I .. benchmarkX.cpp -o benchmarkX && time ./benchmarkX >/dev/null
echo "Dynamic size 20x20, RowMajor, -DNDEBUG"
-g++ -O3 -I .. -DEIGEN_DEFAULT_TO_ROW_MAJOR -DNDEBUG benchmarkX.cpp -o benchmarkX && time ./benchmarkX >/dev/null
+$CXX -O3 -I .. -DEIGEN_DEFAULT_TO_ROW_MAJOR -DNDEBUG benchmarkX.cpp -o benchmarkX && time ./benchmarkX >/dev/null
echo "Dynamic size 20x20, RowMajor, with asserts"
-g++ -O3 -I .. -DEIGEN_DEFAULT_TO_ROW_MAJOR benchmarkX.cpp -o benchmarkX && time ./benchmarkX >/dev/null
+$CXX -O3 -I .. -DEIGEN_DEFAULT_TO_ROW_MAJOR benchmarkX.cpp -o benchmarkX && time ./benchmarkX >/dev/null
diff --git a/doc/examples/class_Cast.cpp b/doc/examples/class_Cast.cpp
index 9751b05c1..88549732f 100644
--- a/doc/examples/class_Cast.cpp
+++ b/doc/examples/class_Cast.cpp
@@ -3,16 +3,13 @@ USING_PART_OF_NAMESPACE_EIGEN
using namespace std;
template<typename Scalar, typename Derived>
-const Eigen::Cast<
- typename Eigen::NumTraits<Scalar>::FloatingPoint,
+const Eigen::CwiseUnaryOp<
+ Eigen::ScalarCastOp<typename Eigen::NumTraits<Scalar>::FloatingPoint>,
Derived
>
castToFloatingPoint(const MatrixBase<Scalar, Derived>& m)
{
- return Eigen::Cast<
- typename Eigen::NumTraits<Scalar>::FloatingPoint,
- Derived
- >(m.asArg());
+ return m.template cast<typename Eigen::NumTraits<Scalar>::FloatingPoint>();
}
int main(int, char**)
diff --git a/doc/examples/class_CwiseBinaryOp.cpp b/doc/examples/class_CwiseBinaryOp.cpp
index 9bb10cdcb..f5439a434 100644
--- a/doc/examples/class_CwiseBinaryOp.cpp
+++ b/doc/examples/class_CwiseBinaryOp.cpp
@@ -3,9 +3,9 @@ USING_PART_OF_NAMESPACE_EIGEN
using namespace std;
// define a custom template binary functor
-struct CwiseMinOp {
+struct CwiseMinOp EIGEN_EMPTY_STRUCT {
template<typename Scalar>
- static Scalar op(const Scalar& a, const Scalar& b) { return std::min(a,b); }
+ Scalar operator()(const Scalar& a, const Scalar& b) const { return std::min(a,b); }
};
// define a custom binary operator between two matrices
@@ -14,14 +14,13 @@ const Eigen::CwiseBinaryOp<CwiseMinOp, Derived1, Derived2>
cwiseMin(const MatrixBase<Scalar, Derived1> &mat1, const MatrixBase<Scalar, Derived2> &mat2)
{
return Eigen::CwiseBinaryOp<CwiseMinOp, Derived1, Derived2>(mat1.asArg(), mat2.asArg());
- // Note that the above is equivalent to:
- // return mat1.template cwise<CwiseMinOp>(mat2);
}
int main(int, char**)
{
Matrix4d m1 = Matrix4d::random(), m2 = Matrix4d::random();
- cout << cwiseMin(m1,m2) << endl; // use our new global operator
- cout << m1.cwise<CwiseMinOp>(m2) << endl; // directly use the generic expression member
+ cout << cwiseMin(m1,m2) << endl; // use our new global operator
+ cout << m1.cwise<CwiseMinOp>(m2) << endl; // directly use the generic expression member
+ cout << m1.cwise(m2, CwiseMinOp()) << endl; // directly use the generic expression member (variant)
return 0;
}
diff --git a/doc/examples/class_CwiseUnaryOp.cpp b/doc/examples/class_CwiseUnaryOp.cpp
new file mode 100644
index 000000000..e10037352
--- /dev/null
+++ b/doc/examples/class_CwiseUnaryOp.cpp
@@ -0,0 +1,17 @@
+#include <Eigen/Core>
+USING_PART_OF_NAMESPACE_EIGEN
+using namespace std;
+
+// define a custom template binary functor
+template<typename Scalar>
+struct CwiseClampOp EIGEN_EMPTY_STRUCT {
+ CwiseClampOp(const Scalar& inf, const Scalar& sup) : m_inf(inf), m_sup(sup) {}
+ Scalar operator()(const Scalar& x) const { return x<m_inf ? m_inf : (x>m_sup : m_sup : x); }
+};
+
+int main(int, char**)
+{
+ Matrix4d m1 = Matrix4d::random(), m2 = Matrix4d::random();
+ cout << m1.cwise(m2, CwiseClampOp<Matrix4d::Scalar>(-0.5,0.5)) << endl;
+ return 0;
+}