Lines 429-444
template<typename SparseMatrixType> void
Link Here
|
429 |
m1.insert(0, m1.cols()-1) = refMat1(0, refMat1.cols()-1) = 1; |
429 |
m1.insert(0, m1.cols()-1) = refMat1(0, refMat1.cols()-1) = 1; |
430 |
|
430 |
|
431 |
VERIFY_IS_APPROX(m1, refMat1); |
431 |
VERIFY_IS_APPROX(m1, refMat1); |
432 |
|
432 |
|
433 |
|
433 |
|
434 |
} |
434 |
} |
435 |
} |
435 |
} |
436 |
|
436 |
|
|
|
437 |
// test filterOuter |
438 |
{ |
439 |
DenseMatrix ref = DenseMatrix::Zero(rows, cols); |
440 |
SparseMatrixType m1(rows, cols); |
441 |
for(int k=0; k<std::max(rows*cols/4, Index(1000)); ++k) |
442 |
{ |
443 |
Index i = internal::random<Index>(0,rows-1); |
444 |
Index j = internal::random<Index>(0,cols-1); |
445 |
Scalar v = internal::random<Scalar>(); |
446 |
m1.coeffRef(i,j) = v; |
447 |
ref.coeffRef(i,j) = v; |
448 |
} |
449 |
if(internal::random<Index>(0,10)<5) { |
450 |
m1.makeCompressed(); |
451 |
} |
452 |
std::vector<bool> filter(m1.outerSize()); |
453 |
Index retained = 0; |
454 |
for (int fx=0; fx < m1.outerSize(); ++fx) { |
455 |
bool inc = internal::random<bool>(); |
456 |
filter[fx] = inc; |
457 |
retained += inc; |
458 |
} |
459 |
m1.filterOuter(filter); |
460 |
VERIFY(m1.outerSize() == retained); |
461 |
if (retained == (Index) filter.size()) { |
462 |
VERIFY_IS_APPROX(m1, ref); |
463 |
} else { |
464 |
if (retained == m1.cols()) { |
465 |
for (int fx=0, dx=0; fx < ref.cols(); ++fx) { |
466 |
if (!filter[fx]) continue; |
467 |
VERIFY_IS_APPROX(m1.col(dx), ref.col(fx)); |
468 |
dx++; |
469 |
} |
470 |
} else { |
471 |
for (int fx=0, dx=0; fx < ref.rows(); ++fx) { |
472 |
if (!filter[fx]) continue; |
473 |
VERIFY_IS_APPROX(m1.row(dx), ref.row(fx)); |
474 |
dx++; |
475 |
} |
476 |
} |
477 |
} |
478 |
} |
479 |
|
437 |
// test Identity matrix |
480 |
// test Identity matrix |
438 |
{ |
481 |
{ |
439 |
DenseMatrix refMat1 = DenseMatrix::Identity(rows, rows); |
482 |
DenseMatrix refMat1 = DenseMatrix::Identity(rows, rows); |
440 |
SparseMatrixType m1(rows, rows); |
483 |
SparseMatrixType m1(rows, rows); |
441 |
m1.setIdentity(); |
484 |
m1.setIdentity(); |
442 |
VERIFY_IS_APPROX(m1, refMat1); |
485 |
VERIFY_IS_APPROX(m1, refMat1); |
443 |
for(int k=0; k<rows*rows/4; ++k) |
486 |
for(int k=0; k<rows*rows/4; ++k) |
444 |
{ |
487 |
{ |