27 template<
typename SparseMatrixType>
void sparse_block(
const SparseMatrixType&
ref)
31 const Index inner = ref.innerSize();
32 const Index outer = ref.outerSize();
36 typedef typename SparseMatrixType::StorageIndex StorageIndex;
44 Scalar s1 = internal::random<Scalar>();
46 SparseMatrixType
m(rows, cols);
47 DenseMatrix refMat = DenseMatrix::Zero(rows, cols);
48 initSparse<Scalar>(density, refMat,
m);
53 for (
int t=0;
t<10; ++
t)
55 Index j = internal::random<Index>(0,cols-2);
56 Index i = internal::random<Index>(0,rows-2);
57 Index w = internal::random<Index>(1,cols-
j);
58 Index h = internal::random<Index>(1,rows-
i);
66 VERIFY_IS_APPROX(m.block(i,j,h,w).col(
c).coeff(r), refMat.block(i,j,h,w).col(
c).coeff(r));
75 VERIFY_IS_APPROX(m.block(i,j,h,w).row(r).coeff(
c), refMat.block(i,j,h,w).row(r).coeff(
c));
93 if(m.middleCols(j,w).coeff(r,
c) !=
Scalar(0))
97 if(m.middleRows(i,h).coeff(r,
c) !=
Scalar(0))
125 DenseMatrix refMat2 = DenseMatrix::Zero(rows, cols);
126 SparseMatrixType
m2(rows, cols);
127 initSparse<Scalar>(density, refMat2,
m2);
128 Index j0 = internal::random<Index>(0,outer-1);
129 Index j1 = internal::random<Index>(0,outer-1);
130 Index r0 = internal::random<Index>(0,rows-1);
131 Index c0 = internal::random<Index>(0,cols-1);
136 m2.innerVector(j0) *=
Scalar(2);
141 refMat2.row(r0) *=
Scalar(3);
145 refMat2.col(c0) *=
Scalar(4);
149 refMat2.row(r0) /=
Scalar(3);
153 refMat2.col(c0) /=
Scalar(4);
160 SparseMatrixType m3(rows,cols);
161 m3.reserve(VectorXi::Constant(outer,
int(inner/2)));
164 m3.insertByOuterInner(
j,k) = internal::convert_index<StorageIndex>(k+1);
179 VERIFY(m3.innerVector(j0).nonZeros() == m3.transpose().innerVector(j0).nonZeros());
188 DenseMatrix refMat2 = DenseMatrix::Zero(rows, cols);
189 SparseMatrixType
m2(rows, cols);
190 initSparse<Scalar>(density, refMat2,
m2);
191 if(internal::random<float>(0,1)>0.5f) m2.makeCompressed();
192 Index j0 = internal::random<Index>(0,outer-2);
193 Index j1 = internal::random<Index>(0,outer-2);
194 Index n0 = internal::random<Index>(1,outer-(
std::max)(j0,j1));
195 if(SparseMatrixType::IsRowMajor)
199 if(SparseMatrixType::IsRowMajor)
201 refMat2.middleRows(j0,n0)+refMat2.middleRows(j1,n0));
204 refMat2.block(0,j0,rows,n0)+refMat2.block(0,j1,rows,n0));
208 VERIFY(m2.innerVectors(j0,n0).nonZeros() == m2.transpose().innerVectors(j0,n0).nonZeros());
210 m2.innerVectors(j0,n0) = m2.innerVectors(j0,n0) + m2.innerVectors(j1,n0);
211 if(SparseMatrixType::IsRowMajor)
212 refMat2.middleRows(j0,n0) = (refMat2.middleRows(j0,n0) + refMat2.middleRows(j1,n0)).
eval();
214 refMat2.middleCols(j0,n0) = (refMat2.middleCols(j0,n0) + refMat2.middleCols(j1,n0)).
eval();
221 DenseMatrix refMat2 = DenseMatrix::Zero(rows, cols);
222 SparseMatrixType
m2(rows, cols);
223 initSparse<Scalar>(density, refMat2,
m2);
224 Index j0 = internal::random<Index>(0,outer-2);
225 Index j1 = internal::random<Index>(0,outer-2);
226 Index n0 = internal::random<Index>(1,outer-(
std::max)(j0,j1));
227 if(SparseMatrixType::IsRowMajor)
232 if(SparseMatrixType::IsRowMajor)
234 refMat2.block(j0,0,n0,cols)+refMat2.block(j1,0,n0,cols));
237 refMat2.block(0,j0,rows,n0)+refMat2.block(0,j1,rows,n0));
239 Index i = internal::random<Index>(0,m2.outerSize()-1);
240 if(SparseMatrixType::IsRowMajor) {
241 m2.innerVector(i) = m2.innerVector(i) * s1;
242 refMat2.row(i) = refMat2.row(i) * s1;
245 m2.innerVector(i) = m2.innerVector(i) * s1;
246 refMat2.col(i) = refMat2.col(i) * s1;
250 Index r0 = internal::random<Index>(0,rows-2);
251 Index c0 = internal::random<Index>(0,cols-2);
252 Index r1 = internal::random<Index>(1,rows-r0);
253 Index c1 = internal::random<Index>(1,cols-c0);
267 SparseMatrixType m3(rows, cols);
268 DenseMatrix refMat3(rows, cols); refMat3.setZero();
269 Index n = internal::random<Index>(1,10);
272 Index o1 = internal::random<Index>(0,outer-1);
273 Index o2 = internal::random<Index>(0,outer-1);
274 if(SparseMatrixType::IsRowMajor)
276 m3.innerVector(o1) = m2.row(o2);
277 refMat3.row(o1) = refMat2.row(o2);
281 m3.innerVector(o1) = m2.col(o2);
282 refMat3.col(o1) = refMat2.col(o2);
284 if(internal::random<bool>())
296 int r = Eigen::internal::random<int>(1,200),
c = Eigen::internal::random<int>(1,200);
297 if(Eigen::internal::random<int>(0,4) == 0) {
310 r = Eigen::internal::random<int>(1,100);
311 c = Eigen::internal::random<int>(1,100);
312 if(Eigen::internal::random<int>(0,4) == 0) {
318 #ifndef EIGEN_TEST_ANNOYING_SCALAR_DONT_THROW
const StorageIndex & col() const
Matrix< Scalar, Dynamic, Dynamic > DenseMatrix
#define CALL_SUBTEST_4(FUNC)
m m block(1, 0, 2, 2)<< 4
EIGEN_DECLARE_TEST(sparse_block)
#define CALL_SUBTEST_3(FUNC)
const StorageIndex & row() const
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Matrix< Scalar, Dynamic, 1 > DenseVector
#define VERIFY_IS_APPROX(a, b)
#define CALL_SUBTEST_1(FUNC)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
NumTraits< Scalar >::Real RealScalar
Reference counting helper.
#define CALL_SUBTEST_5(FUNC)
Eigen::internal::enable_if<(T::Flags &RowMajorBit)==RowMajorBit, typename T::RowXpr >::type innervec(T &A, Index i)
#define CALL_SUBTEST_2(FUNC)
internal::nested_eval< T, 1 >::type eval(const T &xpr)
The matrix class, also used for vectors and row-vectors.
void sparse_block(const SparseMatrixType &ref)
#define EIGEN_UNUSED_VARIABLE(var)