OLD | NEW |
1 // This file is part of Eigen, a lightweight C++ template library | 1 // This file is part of Eigen, a lightweight C++ template library |
2 // for linear algebra. Eigen itself is part of the KDE project. | 2 // for linear algebra. Eigen itself is part of the KDE project. |
3 // | 3 // |
4 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> | 4 // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> |
5 // | 5 // |
6 // Eigen is free software; you can redistribute it and/or | 6 // Eigen is free software; you can redistribute it and/or |
7 // modify it under the terms of the GNU Lesser General Public | 7 // modify it under the terms of the GNU Lesser General Public |
8 // License as published by the Free Software Foundation; either | 8 // License as published by the Free Software Foundation; either |
9 // version 3 of the License, or (at your option) any later version. | 9 // version 3 of the License, or (at your option) any later version. |
10 // | 10 // |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 m1.block(r1,c1,r2-r1+1,c2-c1+1) = s1 * m2.block(0, 0, r2-r1+1,c2-c1+1); | 102 m1.block(r1,c1,r2-r1+1,c2-c1+1) = s1 * m2.block(0, 0, r2-r1+1,c2-c1+1); |
103 m1.block(r1,c1,r2-r1+1,c2-c1+1)(r2-r1,c2-c1) = m2.block(0, 0, r2-r1+1,c2-c1+1)
(0,0); | 103 m1.block(r1,c1,r2-r1+1,c2-c1+1)(r2-r1,c2-c1) = m2.block(0, 0, r2-r1+1,c2-c1+1)
(0,0); |
104 | 104 |
105 //check minor() | 105 //check minor() |
106 CheckMinor<Scalar, MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTim
e> checkminor(m1,r1,c1); | 106 CheckMinor<Scalar, MatrixType::RowsAtCompileTime, MatrixType::ColsAtCompileTim
e> checkminor(m1,r1,c1); |
107 | 107 |
108 //check diagonal() | 108 //check diagonal() |
109 VERIFY_IS_APPROX(m1.diagonal(), m1.transpose().diagonal()); | 109 VERIFY_IS_APPROX(m1.diagonal(), m1.transpose().diagonal()); |
110 m2.diagonal() = 2 * m1.diagonal(); | 110 m2.diagonal() = 2 * m1.diagonal(); |
111 m2.diagonal()[0] *= 3; | 111 m2.diagonal()[0] *= 3; |
112 VERIFY_IS_APPROX(m2.diagonal()[0], static_cast<Scalar>(6) * m1.diagonal()[0]); | |
113 | 112 |
114 const int BlockRows = EIGEN_ENUM_MIN(MatrixType::RowsAtCompileTime,2); | 113 const int BlockRows = EIGEN_ENUM_MIN(MatrixType::RowsAtCompileTime,2); |
115 const int BlockCols = EIGEN_ENUM_MIN(MatrixType::ColsAtCompileTime,5); | 114 const int BlockCols = EIGEN_ENUM_MIN(MatrixType::ColsAtCompileTime,5); |
116 if (rows>=5 && cols>=8) | 115 if (rows>=5 && cols>=8) |
117 { | 116 { |
118 // test fixed block() as lvalue | 117 // test fixed block() as lvalue |
119 m1.template block<BlockRows,BlockCols>(1,1) *= s1; | 118 m1.template block<BlockRows,BlockCols>(1,1) *= s1; |
120 // test operator() on fixed block() both as constant and non-constant | 119 // test operator() on fixed block() both as constant and non-constant |
121 m1.template block<BlockRows,BlockCols>(1,1)(0, 3) = m1.template block<2,5>(1
,1)(1,2); | 120 m1.template block<BlockRows,BlockCols>(1,1)(0, 3) = m1.template block<2,5>(1
,1)(1,2); |
122 // check that fixed block() and block() agree | 121 // check that fixed block() and block() agree |
(...skipping 15 matching lines...) Expand all Loading... |
138 VERIFY_IS_APPROX(v1.template end<2>(), v1.template segment<2>(i)); | 137 VERIFY_IS_APPROX(v1.template end<2>(), v1.template segment<2>(i)); |
139 i = ei_random(0,rows-2); | 138 i = ei_random(0,rows-2); |
140 VERIFY_IS_APPROX(v1.segment(i,2), v1.template segment<2>(i)); | 139 VERIFY_IS_APPROX(v1.segment(i,2), v1.template segment<2>(i)); |
141 | 140 |
142 enum { | 141 enum { |
143 N1 = MatrixType::RowsAtCompileTime>1 ? 1 : 0, | 142 N1 = MatrixType::RowsAtCompileTime>1 ? 1 : 0, |
144 N2 = MatrixType::RowsAtCompileTime>2 ? -2 : 0 | 143 N2 = MatrixType::RowsAtCompileTime>2 ? -2 : 0 |
145 }; | 144 }; |
146 | 145 |
147 // check sub/super diagonal | 146 // check sub/super diagonal |
148 m2.template diagonal<N1>() = 2 * m1.template diagonal<N1>(); | 147 m2.template band<N1>() = 2 * m1.template band<N1>(); |
149 m2.template diagonal<N1>()[0] *= 3; | 148 m2.template band<N1>()[0] *= 3; |
150 VERIFY_IS_APPROX(m2.template diagonal<N1>()[0], static_cast<Scalar>(6) * m1.
template diagonal<N1>()[0]); | 149 VERIFY_IS_APPROX(m2.template band<N1>()[0], static_cast<Scalar>(6) * m1.temp
late band<N1>()[0]); |
151 | 150 |
152 m2.template diagonal<N2>() = 2 * m1.template diagonal<N2>(); | 151 m2.template band<N2>() = 2 * m1.template band<N2>(); |
153 m2.template diagonal<N2>()[0] *= 3; | 152 m2.template band<N2>()[0] *= 3; |
154 VERIFY_IS_APPROX(m2.template diagonal<N2>()[0], static_cast<Scalar>(6) * m1.
template diagonal<N2>()[0]); | 153 VERIFY_IS_APPROX(m2.template band<N2>()[0], static_cast<Scalar>(6) * m1.temp
late band<N2>()[0]); |
| 154 |
| 155 m2.band(N1) = 2 * m1.band(N1); |
| 156 m2.band(N1)[0] *= 3; |
| 157 VERIFY_IS_APPROX(m2.band(N1)[0], static_cast<Scalar>(6) * m1.band(N1)[0]); |
| 158 |
| 159 m2.band(N2) = 2 * m1.band(N2); |
| 160 m2.band(N2)[0] *= 3; |
| 161 VERIFY_IS_APPROX(m2.band(N2)[0], static_cast<Scalar>(6) * m1.band(N2)[0]); |
155 } | 162 } |
156 | 163 |
157 // stress some basic stuffs with block matrices | 164 // stress some basic stuffs with block matrices |
158 VERIFY(ei_real(ones.col(c1).sum()) == RealScalar(rows)); | 165 VERIFY(ei_real(ones.col(c1).sum()) == RealScalar(rows)); |
159 VERIFY(ei_real(ones.row(r1).sum()) == RealScalar(cols)); | 166 VERIFY(ei_real(ones.row(r1).sum()) == RealScalar(cols)); |
160 | 167 |
161 VERIFY(ei_real(ones.col(c1).dot(ones.col(c2))) == RealScalar(rows)); | 168 VERIFY(ei_real(ones.col(c1).dot(ones.col(c2))) == RealScalar(rows)); |
162 VERIFY(ei_real(ones.row(r1).dot(ones.row(r2))) == RealScalar(cols)); | 169 VERIFY(ei_real(ones.row(r1).dot(ones.row(r2))) == RealScalar(cols)); |
163 } | 170 } |
164 | 171 |
165 void test_submatrices() | 172 void test_submatrices() |
166 { | 173 { |
167 for(int i = 0; i < g_repeat; i++) { | 174 for(int i = 0; i < g_repeat; i++) { |
168 CALL_SUBTEST( submatrices(Matrix<float, 1, 1>()) ); | 175 CALL_SUBTEST( submatrices(Matrix<float, 1, 1>()) ); |
169 CALL_SUBTEST( submatrices(Matrix4d()) ); | 176 CALL_SUBTEST( submatrices(Matrix4d()) ); |
170 CALL_SUBTEST( submatrices(MatrixXcf(3, 3)) ); | 177 CALL_SUBTEST( submatrices(MatrixXcf(3, 3)) ); |
171 CALL_SUBTEST( submatrices(MatrixXi(8, 12)) ); | 178 CALL_SUBTEST( submatrices(MatrixXi(8, 12)) ); |
172 CALL_SUBTEST( submatrices(MatrixXcd(20, 20)) ); | 179 CALL_SUBTEST( submatrices(MatrixXcd(20, 20)) ); |
173 CALL_SUBTEST( submatrices(MatrixXf(20, 20)) ); | 180 CALL_SUBTEST( submatrices(MatrixXf(20, 20)) ); |
174 } | 181 } |
175 } | 182 } |
OLD | NEW |