aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/examples
diff options
context:
space:
mode:
Diffstat (limited to 'doc/examples')
-rw-r--r--doc/examples/DenseBase_middleCols_int.cpp15
-rw-r--r--doc/examples/DenseBase_middleRows_int.cpp15
-rw-r--r--doc/examples/DenseBase_template_int_middleCols.cpp15
-rw-r--r--doc/examples/DenseBase_template_int_middleRows.cpp15
-rw-r--r--doc/examples/Tutorial_ArrayClass_accessors.cpp8
-rw-r--r--doc/examples/Tutorial_ArrayClass_addition.cpp9
-rw-r--r--doc/examples/Tutorial_ArrayClass_addition_scalar.cpp17
-rw-r--r--doc/examples/Tutorial_ArrayClass_cwise_other.cpp19
-rw-r--r--doc/examples/Tutorial_ArrayClass_interop.cpp20
-rw-r--r--doc/examples/Tutorial_ArrayClass_interop_array.cpp34
-rw-r--r--doc/examples/Tutorial_ArrayClass_interop_matrix.cpp25
-rw-r--r--doc/examples/Tutorial_ArrayClass_mult.cpp6
-rw-r--r--doc/examples/Tutorial_BlockOperations_block_assignment.cpp23
-rw-r--r--doc/examples/Tutorial_BlockOperations_colrow.cpp11
-rw-r--r--doc/examples/Tutorial_BlockOperations_corner.cpp20
-rw-r--r--doc/examples/Tutorial_BlockOperations_print_block.cpp20
-rw-r--r--doc/examples/Tutorial_BlockOperations_vector.cpp20
-rw-r--r--doc/examples/Tutorial_ReductionsVisitorsBroadcasting_maxnorm.cpp5
-rw-r--r--doc/examples/tut_matrix_coefficient_accessors.cpp1
19 files changed, 131 insertions, 167 deletions
diff --git a/doc/examples/DenseBase_middleCols_int.cpp b/doc/examples/DenseBase_middleCols_int.cpp
new file mode 100644
index 000000000..0ebd955ec
--- /dev/null
+++ b/doc/examples/DenseBase_middleCols_int.cpp
@@ -0,0 +1,15 @@
+#include <Eigen/Core>
+#include <iostream>
+
+using namespace Eigen;
+using namespace std;
+
+int main(void)
+{
+ int const N = 5;
+ MatrixXi A(N,N);
+ A.setRandom();
+ cout << "A =\n" << A << '\n' << endl;
+ cout << "A(1..3,:) =\n" << A.middleCols(1,3) << endl;
+ return 0;
+}
diff --git a/doc/examples/DenseBase_middleRows_int.cpp b/doc/examples/DenseBase_middleRows_int.cpp
new file mode 100644
index 000000000..a6fe9e844
--- /dev/null
+++ b/doc/examples/DenseBase_middleRows_int.cpp
@@ -0,0 +1,15 @@
+#include <Eigen/Core>
+#include <iostream>
+
+using namespace Eigen;
+using namespace std;
+
+int main(void)
+{
+ int const N = 5;
+ MatrixXi A(N,N);
+ A.setRandom();
+ cout << "A =\n" << A << '\n' << endl;
+ cout << "A(2..3,:) =\n" << A.middleRows(2,2) << endl;
+ return 0;
+}
diff --git a/doc/examples/DenseBase_template_int_middleCols.cpp b/doc/examples/DenseBase_template_int_middleCols.cpp
new file mode 100644
index 000000000..6191d79c8
--- /dev/null
+++ b/doc/examples/DenseBase_template_int_middleCols.cpp
@@ -0,0 +1,15 @@
+#include <Eigen/Core>
+#include <iostream>
+
+using namespace Eigen;
+using namespace std;
+
+int main(void)
+{
+ int const N = 5;
+ MatrixXi A(N,N);
+ A.setRandom();
+ cout << "A =\n" << A << '\n' << endl;
+ cout << "A(:,1..3) =\n" << A.middleCols<3>(1) << endl;
+ return 0;
+}
diff --git a/doc/examples/DenseBase_template_int_middleRows.cpp b/doc/examples/DenseBase_template_int_middleRows.cpp
new file mode 100644
index 000000000..7e8b6573f
--- /dev/null
+++ b/doc/examples/DenseBase_template_int_middleRows.cpp
@@ -0,0 +1,15 @@
+#include <Eigen/Core>
+#include <iostream>
+
+using namespace Eigen;
+using namespace std;
+
+int main(void)
+{
+ int const N = 5;
+ MatrixXi A(N,N);
+ A.setRandom();
+ cout << "A =\n" << A << '\n' << endl;
+ cout << "A(1..3,:) =\n" << A.middleRows<3>(1) << endl;
+ return 0;
+}
diff --git a/doc/examples/Tutorial_ArrayClass_accessors.cpp b/doc/examples/Tutorial_ArrayClass_accessors.cpp
index 812ba61a4..dc720ff58 100644
--- a/doc/examples/Tutorial_ArrayClass_accessors.cpp
+++ b/doc/examples/Tutorial_ArrayClass_accessors.cpp
@@ -8,17 +8,17 @@ int main()
{
ArrayXXf m(2,2);
- //assign some values coefficient by coefficient
+ // assign some values coefficient by coefficient
m(0,0) = 1.0; m(0,1) = 2.0;
- m(1,0) = 3.0; m(1,1) = 4.0;
+ m(1,0) = 3.0; m(1,1) = m(0,1) + m(1,0);
- //print values to standard output
+ // print values to standard output
cout << m << endl << endl;
// using the comma-initializer is also allowed
m << 1.0,2.0,
3.0,4.0;
- //print values to standard output
+ // print values to standard output
cout << m << endl;
}
diff --git a/doc/examples/Tutorial_ArrayClass_addition.cpp b/doc/examples/Tutorial_ArrayClass_addition.cpp
index eae1957bd..480ffb00f 100644
--- a/doc/examples/Tutorial_ArrayClass_addition.cpp
+++ b/doc/examples/Tutorial_ArrayClass_addition.cpp
@@ -8,15 +8,16 @@ int main()
{
ArrayXXf a(3,3);
ArrayXXf b(3,3);
-
a << 1,2,3,
4,5,6,
7,8,9;
-
b << 1,2,3,
1,2,3,
1,2,3;
- cout << "a + b = " << endl
- << a + b << endl;
+ // Adding two arrays
+ cout << "a + b = " << endl << a + b << endl << endl;
+
+ // Subtracting a scalar from an array
+ cout << "a - 2 = " << endl << a - 2 << endl;
}
diff --git a/doc/examples/Tutorial_ArrayClass_addition_scalar.cpp b/doc/examples/Tutorial_ArrayClass_addition_scalar.cpp
deleted file mode 100644
index 1c2665287..000000000
--- a/doc/examples/Tutorial_ArrayClass_addition_scalar.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-#include <Eigen/Dense>
-#include <iostream>
-
-using namespace Eigen;
-using namespace std;
-
-int main()
-{
- ArrayXXf a(3,3);
-
- a << 1,2,3,
- 4,5,6,
- 7,8,9;
-
- cout << "a + 2 = " << endl
- << a + 2 << endl;
-}
diff --git a/doc/examples/Tutorial_ArrayClass_cwise_other.cpp b/doc/examples/Tutorial_ArrayClass_cwise_other.cpp
new file mode 100644
index 000000000..d9046c63d
--- /dev/null
+++ b/doc/examples/Tutorial_ArrayClass_cwise_other.cpp
@@ -0,0 +1,19 @@
+#include <Eigen/Dense>
+#include <iostream>
+
+using namespace Eigen;
+using namespace std;
+
+int main()
+{
+ ArrayXf a = ArrayXf::Random(5);
+ a *= 2;
+ cout << "a =" << endl
+ << a << endl;
+ cout << "a.abs() =" << endl
+ << a.abs() << endl;
+ cout << "a.abs().sqrt() =" << endl
+ << a.abs().sqrt() << endl;
+ cout << "a.min(a.abs().sqrt()) =" << endl
+ << a.min(a.abs().sqrt()) << endl;
+}
diff --git a/doc/examples/Tutorial_ArrayClass_interop.cpp b/doc/examples/Tutorial_ArrayClass_interop.cpp
index 72ac5d307..371f07068 100644
--- a/doc/examples/Tutorial_ArrayClass_interop.cpp
+++ b/doc/examples/Tutorial_ArrayClass_interop.cpp
@@ -8,31 +8,15 @@ int main()
{
MatrixXf m(2,2);
MatrixXf n(2,2);
-
MatrixXf result(2,2);
- //initialize matrices
m << 1,2,
3,4;
-
n << 5,6,
7,8;
- // mix of array and matrix operations
- // first coefficient-wise addition
- // then the result is used with matrix multiplication
result = (m.array() + 4).matrix() * m;
-
- cout << "-- Combination 1: --" << endl
- << result << endl << endl;
-
-
- // mix of array and matrix operations
- // first coefficient-wise multiplication
- // then the result is used with matrix multiplication
+ cout << "-- Combination 1: --" << endl << result << endl << endl;
result = (m.array() * n.array()).matrix() * m;
-
- cout << "-- Combination 2: --" << endl
- << result << endl << endl;
-
+ cout << "-- Combination 2: --" << endl << result << endl << endl;
}
diff --git a/doc/examples/Tutorial_ArrayClass_interop_array.cpp b/doc/examples/Tutorial_ArrayClass_interop_array.cpp
deleted file mode 100644
index c2cb6bf3f..000000000
--- a/doc/examples/Tutorial_ArrayClass_interop_array.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-#include <Eigen/Dense>
-#include <iostream>
-
-using namespace Eigen;
-using namespace std;
-
-int main()
-{
- ArrayXXf m(2,2);
- ArrayXXf n(2,2);
-
- ArrayXXf result(2,2);
-
- //initialize arrays
- m << 1,2,
- 3,4;
-
- n << 5,6,
- 7,8;
-
-
- // --> array multiplication
- result = m * n;
-
- cout << "-- Array m*n: --" << endl
- << result << endl << endl;
-
-
- // --> Matrix multiplication
- result = m.matrix() * n.matrix();
-
- cout << "-- Matrix m*n: --" << endl
- << result << endl << endl;
-}
diff --git a/doc/examples/Tutorial_ArrayClass_interop_matrix.cpp b/doc/examples/Tutorial_ArrayClass_interop_matrix.cpp
index b3d48b6ae..101427511 100644
--- a/doc/examples/Tutorial_ArrayClass_interop_matrix.cpp
+++ b/doc/examples/Tutorial_ArrayClass_interop_matrix.cpp
@@ -8,34 +8,19 @@ int main()
{
MatrixXf m(2,2);
MatrixXf n(2,2);
-
MatrixXf result(2,2);
- //initialize matrices
m << 1,2,
3,4;
-
n << 5,6,
7,8;
-
- // --> matrix multiplication
result = m * n;
-
- cout << "-- Matrix m*n: --" << endl
- << result << endl << endl;
-
-
- // --> coeff-wise multiplication
+ cout << "-- Matrix m*n: --" << endl << result << endl << endl;
result = m.array() * n.array();
-
- cout << "-- Array m*n: --" << endl
- << result << endl << endl;
-
-
- // ->> coeff-wise addition of a scalar
+ cout << "-- Array m*n: --" << endl << result << endl << endl;
+ result = m.cwiseProduct(n);
+ cout << "-- With cwiseProduct: --" << endl << result << endl << endl;
result = m.array() + 4;
-
- cout << "-- Array m + 4: --" << endl
- << result << endl << endl;
+ cout << "-- Array m + 4: --" << endl << result << endl << endl;
}
diff --git a/doc/examples/Tutorial_ArrayClass_mult.cpp b/doc/examples/Tutorial_ArrayClass_mult.cpp
index 27c83e040..6cb439ff7 100644
--- a/doc/examples/Tutorial_ArrayClass_mult.cpp
+++ b/doc/examples/Tutorial_ArrayClass_mult.cpp
@@ -8,13 +8,9 @@ int main()
{
ArrayXXf a(2,2);
ArrayXXf b(2,2);
-
a << 1,2,
3,4;
-
b << 5,6,
7,8;
-
- cout << "a * b = " << endl
- << a * b << endl;
+ cout << "a * b = " << endl << a * b << endl;
}
diff --git a/doc/examples/Tutorial_BlockOperations_block_assignment.cpp b/doc/examples/Tutorial_BlockOperations_block_assignment.cpp
index 0419a500f..56ca69a6e 100644
--- a/doc/examples/Tutorial_BlockOperations_block_assignment.cpp
+++ b/doc/examples/Tutorial_BlockOperations_block_assignment.cpp
@@ -6,26 +6,13 @@ using namespace Eigen;
int main()
{
- MatrixXf m(3,3), n(2,2);
-
+ Array33f m;
m << 1,2,3,
4,5,6,
7,8,9;
-
- // assignment through a block operation,
- // block as rvalue
- n = m.block(0,0,2,2);
-
- //print n
+ Array<float,5,5> n = Array<float,5,5>::Constant(0.6);
+ n.block(1,1,3,3) = m;
cout << "n = " << endl << n << endl << endl;
-
-
- n << 1,1,
- 1,1;
-
- // block as lvalue
- m.block(0,0,2,2) = n;
-
- //print m
- cout << "m = " << endl << m << endl;
+ Array33f res = n.block(0,0,3,3) * m;
+ cout << "res =" << endl << res << endl;
}
diff --git a/doc/examples/Tutorial_BlockOperations_colrow.cpp b/doc/examples/Tutorial_BlockOperations_colrow.cpp
index e639324b2..e98263057 100644
--- a/doc/examples/Tutorial_BlockOperations_colrow.cpp
+++ b/doc/examples/Tutorial_BlockOperations_colrow.cpp
@@ -1,15 +1,14 @@
#include <Eigen/Dense>
#include <iostream>
-using namespace Eigen;
int main()
{
- MatrixXf m(3,3);
-
+ Eigen::MatrixXf m(3,3);
m << 1,2,3,
4,5,6,
7,8,9;
-
- std::cout << "2nd Row: "
- << m.row(1) << std::endl;
+ std::cout << "2nd Row: " << m.row(1) << std::endl;
+ m.col(0) += m.col(2);
+ std::cout << "m after adding third column to first:\n";
+ std::cout << m << std::endl;
}
diff --git a/doc/examples/Tutorial_BlockOperations_corner.cpp b/doc/examples/Tutorial_BlockOperations_corner.cpp
index 96c6df62b..3a31507aa 100644
--- a/doc/examples/Tutorial_BlockOperations_corner.cpp
+++ b/doc/examples/Tutorial_BlockOperations_corner.cpp
@@ -2,26 +2,16 @@
#include <iostream>
using namespace std;
-using namespace Eigen;
int main()
{
- MatrixXf m(4,4);
-
+ Eigen::Matrix4f m;
m << 1, 2, 3, 4,
5, 6, 7, 8,
9, 10,11,12,
13,14,15,16;
-
- //print first two columns
- cout << "-- leftCols(2) --" << endl
- << m.leftCols(2) << endl << endl;
-
- //print last two rows
- cout << "-- bottomRows(2) --" << endl
- << m.bottomRows(2) << endl << endl;
-
- //print top-left 2x3 corner
- cout << "-- topLeftCorner(2,3) --" << endl
- << m.topLeftCorner(2,3) << endl;
+ cout << "m.leftCols(2) =" << endl << m.leftCols(2) << endl << endl;
+ cout << "m.bottomRows<2>() =" << endl << m.bottomRows<2>() << endl << endl;
+ m.topLeftCorner(1,3) = m.bottomRightCorner(3,1).transpose();
+ cout << "After assignment, m = " << endl << m << endl;
}
diff --git a/doc/examples/Tutorial_BlockOperations_print_block.cpp b/doc/examples/Tutorial_BlockOperations_print_block.cpp
index a2d0db864..0fdefecdf 100644
--- a/doc/examples/Tutorial_BlockOperations_print_block.cpp
+++ b/doc/examples/Tutorial_BlockOperations_print_block.cpp
@@ -1,14 +1,18 @@
#include <Eigen/Dense>
#include <iostream>
-using namespace Eigen;
int main()
{
- MatrixXf m(3,3);
-
- m << 1,2,3,
- 4,5,6,
- 7,8,9;
-
- std::cout << m.block(0,0,2,2) << std::endl;
+ Eigen::MatrixXf m(4,4);
+ m << 1, 2, 3, 4,
+ 5, 6, 7, 8,
+ 9,10,11,12,
+ 13,14,15,16;
+ std::cout << "Block in the middle" << std::endl;
+ std::cout << m.block<2,2>(1,1) << std::endl << std::endl;
+ for (int i = 1; i < 4; ++i)
+ {
+ std::cout << "Block of size " << i << std::endl;
+ std::cout << m.block(0,0,i,i) << std::endl << std::endl;
+ }
}
diff --git a/doc/examples/Tutorial_BlockOperations_vector.cpp b/doc/examples/Tutorial_BlockOperations_vector.cpp
index 211b55472..4a0b02342 100644
--- a/doc/examples/Tutorial_BlockOperations_vector.cpp
+++ b/doc/examples/Tutorial_BlockOperations_vector.cpp
@@ -2,23 +2,13 @@
#include <iostream>
using namespace std;
-using namespace Eigen;
int main()
{
- VectorXf v(6);
-
+ Eigen::ArrayXf v(6);
v << 1, 2, 3, 4, 5, 6;
-
- //print first three elements
- cout << "-- head(3) --" << endl
- << v.head(3) << endl << endl;
-
- //print last three elements
- cout << "-- tail(3) --" << endl
- << v.tail(3) << endl << endl;
-
- //print between 2nd and 5th elem. inclusive
- cout << "-- segment(1,4) --" << endl
- << v.segment(1,4) << endl;
+ cout << "v.head(3) =" << endl << v.head(3) << endl << endl;
+ cout << "v.tail<3>() = " << endl << v.tail<3>() << endl << endl;
+ v.segment(1,4) *= 2;
+ cout << "after 'v.segment(1,4) *= 2', v =" << endl << v << endl;
}
diff --git a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_maxnorm.cpp b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_maxnorm.cpp
index cb46887b6..049c747b0 100644
--- a/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_maxnorm.cpp
+++ b/doc/examples/Tutorial_ReductionsVisitorsBroadcasting_maxnorm.cpp
@@ -2,13 +2,14 @@
#include <Eigen/Dense>
using namespace std;
+using namespace Eigen;
int main()
{
- Eigen::MatrixXf mat(2,4);
+ MatrixXf mat(2,4);
mat << 1, 2, 6, 9,
3, 1, 7, 2;
- int maxIndex;
+ MatrixXf::Index maxIndex;
float maxNorm = mat.colwise().sum().maxCoeff(&maxIndex);
std::cout << "Maximum sum at position " << maxIndex << std::endl;
diff --git a/doc/examples/tut_matrix_coefficient_accessors.cpp b/doc/examples/tut_matrix_coefficient_accessors.cpp
index 6d982b6e1..c2da17158 100644
--- a/doc/examples/tut_matrix_coefficient_accessors.cpp
+++ b/doc/examples/tut_matrix_coefficient_accessors.cpp
@@ -15,5 +15,4 @@ int main()
v(0) = 4;
v(1) = v(0) - 1;
std::cout << "Here is the vector v:\n" << v << std::endl;
-
}