10 #define EIGEN_NO_STATIC_ASSERT // otherwise we fail at compile time on unused paths 13 template<
typename MatrixType,
typename Index,
typename Scalar>
20 VERIFY_IS_APPROX(m1.block(r1,c1,r2-r1+1,c2-c1+1).cwiseMin(s1), m1.cwiseMin(s1).block(r1,c1,r2-r1+1,c2-c1+1));
21 VERIFY_IS_APPROX(m1.block(r1,c1,r2-r1+1,c2-c1+1).cwiseMax(s1), m1.cwiseMax(s1).block(r1,c1,r2-r1+1,c2-c1+1));
26 template<
typename MatrixType,
typename Index,
typename Scalar>
47 m2 = MatrixType::Random(rows, cols),
49 ones = MatrixType::Ones(rows, cols);
50 VectorType
v1 = VectorType::Random(rows);
52 Scalar s1 = internal::random<Scalar>();
54 Index r1 = internal::random<Index>(0,rows-1);
55 Index r2 = internal::random<Index>(
r1,rows-1);
56 Index c1 = internal::random<Index>(0,cols-1);
57 Index c2 = internal::random<Index>(
c1,cols-1);
65 m1.row(r1) += s1 * m1_copy.row(r2);
68 m1.row(r1).row(0) += s1 * m1_copy.row(r2);
71 m1.col(c1) += s1 * m1_copy.col(c2);
73 m1.col(c1).col(0) += s1 * m1_copy.col(c2);
80 RowVectorType br1(m1.block(r1,0,1,cols));
81 VectorType bc1(m1.block(0,c1,rows,1));
86 m1.block(r1,c1,r2-r1+1,c2-c1+1) = s1 * m2.block(0, 0, r2-r1+1,c2-c1+1);
87 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);
93 if (rows>=5 && cols>=8)
96 m1.template block<BlockRows,BlockCols>(1,1) *= s1;
98 m1.template block<BlockRows,BlockCols>(1,1)(0, 3) = m1.template block<2,5>(1,1)(1,2);
104 m1.template block<BlockRows,Dynamic>(1,1,BlockRows,BlockCols) *= s1;
105 m1.template block<BlockRows,Dynamic>(1,1,BlockRows,BlockCols)(0,3) = m1.template block<2,5>(1,1)(1,2);
122 i = internal::random<Index>(0,rows-2);
144 VERIFY_IS_EQUAL( (m1.block(r1,c1,rows-r1,cols-c1).block(r2-r1,c2-c1,rows-r2,cols-c2)) , (m1.block(r2,c2,rows-r2,cols-c2)) );
145 VERIFY_IS_EQUAL( (m1.block(r1,c1,r2-r1+1,c2-c1+1).row(0)) , (m1.row(r1).segment(c1,c2-c1+1)) );
146 VERIFY_IS_EQUAL( (m1.block(r1,c1,r2-r1+1,c2-c1+1).col(0)) , (m1.col(c1).segment(r1,r2-r1+1)) );
147 VERIFY_IS_EQUAL( (m1.block(r1,c1,r2-r1+1,c2-c1+1).transpose().col(0)) , (m1.row(r1).segment(c1,c2-c1+1)).transpose() );
148 VERIFY_IS_EQUAL( (m1.transpose().block(c1,r1,c2-c1+1,r2-r1+1).col(0)) , (m1.row(r1).segment(c1,c2-c1+1)).transpose() );
151 VERIFY_IS_APPROX( ((m1+m2).
block(r1,c1,rows-r1,cols-c1).
block(r2-r1,c2-c1,rows-r2,cols-c2)) , ((m1+m2).
block(r2,c2,rows-r2,cols-c2)) );
165 DynamicMatrixType dm;
166 DynamicVectorType dv;
168 dm = m1.block(r1,c1,rows-r1,cols-c1).block(r2-r1,c2-c1,rows-r2,cols-c2);
172 dm = m1.block(r1,c1,r2-r1+1,c2-c1+1).row(0).transpose();
173 dv = m1.row(r1).segment(c1,c2-c1+1);
177 dm = m1.col(c1).segment(r1,r2-r1+1);
178 dv = m1.block(r1,c1,r2-r1+1,c2-c1+1).col(0);
182 dm = m1.block(r1,c1,r2-r1+1,c2-c1+1).transpose().col(0);
183 dv = m1.row(r1).segment(c1,c2-c1+1);
187 dm = m1.row(r1).segment(c1,c2-c1+1).transpose();
188 dv = m1.transpose().block(c1,r1,c2-c1+1,r2-r1+1).col(0);
191 VERIFY_IS_EQUAL( (m1.template block<Dynamic,1>(1,0,0,1)), m1.block(1,0,0,1));
192 VERIFY_IS_EQUAL( (m1.template block<1,Dynamic>(0,1,1,0)), m1.block(0,1,1,0));
193 VERIFY_IS_EQUAL( ((m1*1).
template block<Dynamic,1>(1,0,0,1)), m1.block(1,0,0,1));
194 VERIFY_IS_EQUAL( ((m1*1).
template block<1,Dynamic>(0,1,1,0)), m1.block(0,1,1,0));
196 if (rows>=2 && cols>=2)
206 template<
typename MatrixType>
212 Index innerStride = m.innerStride();
213 Index outerStride = m.outerStride();
214 Index rowStride = m.rowStride();
215 Index colStride = m.colStride();
220 VERIFY(m.coeff(
i,
j) == data[
i*rowStride +
j*colStride]);
222 if(!MatrixType::IsVectorAtCompileTime)
227 ?
i*outerStride +
j*innerStride
228 :
j*outerStride +
i*innerStride]);
231 if(MatrixType::IsVectorAtCompileTime)
233 VERIFY(innerStride ==
int((&m.coeff(1))-(&m.coeff(0))));
235 VERIFY(m.coeff(
i) == data[
i*innerStride]);
239 template<
typename MatrixType>
245 Index r1 = internal::random<Index>(0,rows-1);
246 Index r2 = internal::random<Index>(
r1,rows-1);
247 Index c1 = internal::random<Index>(0,cols-1);
248 Index c2 = internal::random<Index>(
c1,cols-1);
263 CALL_SUBTEST_2(
block(Matrix4d()) );
264 CALL_SUBTEST_3(
block(MatrixXcf(3, 3)) );
265 CALL_SUBTEST_4(
block(MatrixXi(8, 12)) );
266 CALL_SUBTEST_5(
block(MatrixXcd(20, 20)) );
267 CALL_SUBTEST_6(
block(MatrixXf(20, 20)) );
271 #ifndef EIGEN_DEFAULT_TO_ROW_MAJOR
#define VERIFY_RAISES_ASSERT(a)
EIGEN_DEVICE_FUNC ColsBlockXpr middleCols(Index startCol, Index numCols)
This is the const version of middleCols(Index,Index).
EIGEN_DEVICE_FUNC SegmentReturnType segment(Index start, Index n)
This is the const version of segment(Index,Index).
EIGEN_DEVICE_FUNC RowsBlockXpr topRows(Index n)
This is the const version of topRows(Index).
const unsigned int RowMajorBit
#define VERIFY_IS_APPROX(a, b)
EIGEN_DEVICE_FUNC ColsBlockXpr leftCols(Index n)
This is the const version of leftCols(Index).
#define VERIFY_IS_EQUAL(a, b)
void data_and_stride(const MatrixType &m)
EIGEN_DEVICE_FUNC RowsBlockXpr middleRows(Index startRow, Index n)
This is the const version of middleRows(Index,Index).
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
NumTraits< Scalar >::Real RealScalar
void compare_using_data_and_stride(const MatrixType &m)
const mpreal random(unsigned int seed=0)
The matrix class, also used for vectors and row-vectors.
void block(const MatrixType &m)
Eigen::internal::enable_if<!NumTraits< typename MatrixType::Scalar >::IsComplex, typename MatrixType::Scalar >::type block_real_only(const MatrixType &m1, Index r1, Index r2, Index c1, Index c2, const Scalar &s1)