Skip to content

Commit f17b986

Browse files
committed
Fixes #1416
1 parent 6ec94ac commit f17b986

File tree

3 files changed

+2356
-3
lines changed

3 files changed

+2356
-3
lines changed

src/Core/Datatypes/SparseRowMatrix.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,13 @@ namespace Datatypes {
9696
index_type column = columnCounter[j];
9797
if (column >= ncols)
9898
THROW_INVALID_ARGUMENT("Invalid sparse row matrix array: column index out of bounds.");
99-
triplets.push_back(Triplet(i, columnCounter[j], 0));
99+
triplets.push_back(Triplet(i, columnCounter[j], data[j]));
100100
j++;
101101
}
102102
i++;
103103
}
104104
this->setFromTriplets(triplets.begin(), triplets.end());
105105
this->reserve(nnz);
106-
std::copy(data, data + nnz, this->valuePtr());
107106
this->makeCompressed();
108107
}
109108

src/Core/Datatypes/Tests/SparseRowMatrixTests.cc

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <Core/Datatypes/MatrixIO.h>
3535
#include <Core/Datatypes/MatrixComparison.h>
3636
#include <Testing/Utils/MatrixTestUtilities.h>
37+
#include <Core/Datatypes/MatrixTypeConversions.h>
3738

3839
using namespace SCIRun;
3940
using namespace SCIRun::Core::Datatypes;
@@ -562,7 +563,7 @@ TEST(SparseRowMatrixTest, TestLegacyConstructor)
562563
EXPECT_EQ(nnz, m.nonZeros());
563564
}
564565

565-
TEST(SparseRowMatrixTest, TestLegacyConstructorWithValues)
566+
TEST(SparseRowMatrixTest, TestLegacyConstructorWithValuesCrappySetOfAssertions)
566567
{
567568
int nnz = 35;
568569
int nrows = 7, ncols = 7;
@@ -578,6 +579,77 @@ TEST(SparseRowMatrixTest, TestLegacyConstructorWithValues)
578579
EXPECT_EQ(-1, *std::min_element(m.valuePtr(), m.valuePtr() + m.nonZeros()));
579580
}
580581

582+
TEST(SparseRowMatrixTest, TestLegacyConstructorWithValuesFixesBugWithBuildMappingMatrix)
583+
{
584+
int nnz = 162;
585+
int nrows = 54, ncols = 6;
586+
index_type rows[] = { 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99, 102, 105, 108, 111, 114, 117, 120, 123, 126, 129, 132, 135, 138, 141, 144, 147, 150, 153, 156, 159, 162 };
587+
index_type cols[] = { 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 1, 0, 3, 1, 0, 3, 1, 0, 3, 1, 0, 3, 0, 1, 2, 0, 1, 2, 0, 1, 2, 1, 0, 3, 1, 0, 3, 0, 2, 4, 0, 2, 4, 0, 2, 4, 3, 0, 4, 3, 0, 4, 0, 2, 4, 0, 2, 4, 3, 0, 4, 0, 1, 2, 0, 1, 2, 0, 1, 2, 1, 0, 3, 1, 0, 3, 0, 1, 2, 1, 0, 3, 0, 2, 4, 3, 0, 4, 0, 2, 4, 0, 2, 4, 3, 0, 4, 1, 5, 2, 1, 5, 2, 1, 5, 2, 1, 3, 5, 1, 3, 5, 2, 5, 4, 1, 3, 5, 2, 5, 4, 3, 4, 5, 2, 5, 4, 2, 5, 4, 3, 4, 5, 1, 5, 2, 1, 5, 2, 1, 3, 5, 1, 5, 2, 1, 5, 2, 1, 3, 5, 2, 5, 4, 2, 5, 4, 3, 4, 5 };
588+
double vals[] = { 0.444444444444445, 0.277777777777778, 0.277777777777778, 0.277777777777778, 0.444444444444444, 0.277777777777778, 0.277777777777778, 0.277777777777778, 0.444444444444444, 0.666666666666667, 0.333333333333333, 0, 0.666666666666667, 0.333333333333333, 0, 0.277777777777778, 0.444444444444444, 0.277777777777778, 0.444444444444445, 0.277777777777778, 0.277777777777778, 0.277777777777778, 0.277777777777778, 0.444444444444444, 0.666666666666667, 0, 0.333333333333333, 0.333333333333333, 0, 0.666666666666667, 1, 3.70074341541719e-017, 3.70074341541719e-017, -1.11022302462516e-016, 0.666666666666667, 0.333333333333333, 0, 0.333333333333333, 0.666666666666667, 0.444444444444445, 0.277777777777778, 0.277777777777778, 0.277777777777778, 0.444444444444444, 0.277777777777778, 0.666666666666667, 0, 0.333333333333333, 0.277777777777778, 0.444444444444444, 0.277777777777778, 0.444444444444445, 0.277777777777778, 0.277777777777778, 0.277777777777778, 0.277777777777778, 0.444444444444444, 0.333333333333333, 5.55111512312578e-017, 0.666666666666667, 0.277777777777778, 0.277777777777778, 0.444444444444444, -5.55111512312578e-017, 0.666666666666667, 0.333333333333333, 0, 0.333333333333333, 0.666666666666667, 0, 1, 0, 0.666666666666667, 0, 0.333333333333333, 0.333333333333333, 5.55111512312578e-017, 0.666666666666667, 0, 0, 1, 0, 5.55111512312578e-017, 1, -1.11022302462516e-016, 0.666666666666667, 0.333333333333333, 0.666666666666667, 1.11022302462516e-016, 0.333333333333333, 0, 0.333333333333333, 0.666666666666667, 0, 5.55111512312578e-017, 1, 0.333333333333333, 5.55111512312578e-017, 0.666666666666667, 0.444444444444445, 0.277777777777778, 0.277777777777778, 0.277777777777778, 0.277777777777778, 0.444444444444444, 0.666666666666667, 0.333333333333333, 0, 0.444444444444445, 0.277777777777778, 0.277777777777778, 0.277777777777778, 0.444444444444444, 0.277777777777778, 0.666666666666667, 0.333333333333333, 0, 0, 0.666666666666667, 0.333333333333333, 0.444444444444445, 0.277777777777778, 0.277777777777778, 0.444444444444445, 0.277777777777778, 0.277777777777778, 0.277777777777778, 0.277777777777778, 0.444444444444444, -2.22044604925031e-016, 0.333333333333333, 0.666666666666667, 0.277777777777778, 0.444444444444444, 0.277777777777778, 0.277777777777778, 0.444444444444444, 0.277777777777778, 0.333333333333333, 0.666666666666667, 0, 0.277777777777778, 0.277777777777778, 0.444444444444444, 0, 0.666666666666667, 0.333333333333333, 0, 1, 0, -2.22044604925031e-016, 0.333333333333333, 0.666666666666667, 0.277777777777778, 0.444444444444444, 0.277777777777778, 0, 0.666666666666667, 0.333333333333333, 0.277777777777778, 0.277777777777778, 0.444444444444444};
589+
590+
auto m = boost::make_shared<SparseRowMatrix>(nrows, ncols, rows, cols, vals, nnz);
591+
592+
DenseMatrix expected(nrows, ncols);
593+
expected << 0.444444444444445, 0.277777777777778, 0.277777777777778, 0, 0, 0,
594+
0.277777777777778, 0.444444444444444, 0.277777777777778, 0, 0, 0,
595+
0.277777777777778, 0.277777777777778, 0.444444444444444, 0, 0, 0,
596+
0.666666666666667, 0.333333333333333, 0, 0, 0, 0,
597+
0.333333333333333, 0.666666666666667, 0, 0, 0, 0,
598+
0.444444444444444, 0.277777777777778, 0, 0.277777777777778, 0, 0,
599+
0.277777777777778, 0.444444444444445, 0, 0.277777777777778, 0, 0,
600+
0.277777777777778, 0.277777777777778, 0, 0.444444444444444, 0, 0,
601+
0.666666666666667, 0, 0.333333333333333, 0, 0, 0,
602+
0.333333333333333, 0, 0.666666666666667, 0, 0, 0,
603+
1, 3.70074341541719e-017, 3.70074341541719e-017, 0, 0, 0,
604+
0.666666666666667, -1.11022302462516e-016, 0, 0.333333333333333, 0, 0,
605+
0.333333333333333, 0, 0, 0.666666666666667, 0, 0,
606+
0.444444444444445, 0, 0.277777777777778, 0, 0.277777777777778, 0,
607+
0.277777777777778, 0, 0.444444444444444, 0, 0.277777777777778, 0,
608+
0.666666666666667, 0, 0, 0, 0.333333333333333, 0,
609+
0.444444444444444, 0, 0, 0.277777777777778, 0.277777777777778, 0,
610+
0.277777777777778, 0, 0, 0.444444444444445, 0.277777777777778, 0,
611+
0.277777777777778, 0, 0.277777777777778, 0, 0.444444444444444, 0,
612+
0.333333333333333, 0, 5.55111512312578e-017, 0, 0.666666666666667, 0,
613+
0.277777777777778, 0, 0, 0.277777777777778, 0.444444444444444, 0,
614+
-5.55111512312578e-017, 0.666666666666667, 0.333333333333333, 0, 0, 0,
615+
0, 0.333333333333333, 0.666666666666667, 0, 0, 0,
616+
0, 1, 0, 0, 0, 0,
617+
0, 0.666666666666667, 0, 0.333333333333333, 0, 0,
618+
5.55111512312578e-017, 0.333333333333333, 0, 0.666666666666667, 0, 0,
619+
0, 0, 1, 0, 0, 0,
620+
5.55111512312578e-017, 0, 0, 1, 0, 0,
621+
-1.11022302462516e-016, 0, 0.666666666666667, 0, 0.333333333333333, 0,
622+
1.11022302462516e-016, 0, 0, 0.666666666666667, 0.333333333333333, 0,
623+
0, 0, 0.333333333333333, 0, 0.666666666666667, 0,
624+
0, 0, 5.55111512312578e-017, 0, 1, 0,
625+
5.55111512312578e-017, 0, 0, 0.333333333333333, 0.666666666666667, 0,
626+
0, 0.444444444444445, 0.277777777777778, 0, 0, 0.277777777777778,
627+
0, 0.277777777777778, 0.444444444444444, 0, 0, 0.277777777777778,
628+
0, 0.666666666666667, 0, 0, 0, 0.333333333333333,
629+
0, 0.444444444444445, 0, 0.277777777777778, 0, 0.277777777777778,
630+
0, 0.277777777777778, 0, 0.444444444444444, 0, 0.277777777777778,
631+
0, 0, 0.666666666666667, 0, 0, 0.333333333333333,
632+
0, 0, 0, 0.666666666666667, 0, 0.333333333333333,
633+
0, 0, 0.444444444444445, 0, 0.277777777777778, 0.277777777777778,
634+
0, 0, 0, 0.444444444444445, 0.277777777777778, 0.277777777777778,
635+
0, 0, 0.277777777777778, 0, 0.444444444444444, 0.277777777777778,
636+
0, 0, -2.22044604925031e-016, 0, 0.666666666666667, 0.333333333333333,
637+
0, 0, 0, 0.277777777777778, 0.444444444444444, 0.277777777777778,
638+
0, 0.277777777777778, 0.277777777777778, 0, 0, 0.444444444444444,
639+
0, 0.333333333333333, 0, 0, 0, 0.666666666666667,
640+
0, 0.277777777777778, 0, 0.277777777777778, 0, 0.444444444444444,
641+
0, 0, 0.333333333333333, 0, 0, 0.666666666666667,
642+
0, 0, 0, 0, 0, 1,
643+
0, -2.22044604925031e-016, 0, 0.333333333333333, 0, 0.666666666666667,
644+
0, 0, 0.277777777777778, 0, 0.277777777777778, 0.444444444444444,
645+
0, 0, 0, 0, 0.333333333333333, 0.666666666666667,
646+
0, 0, 0, 0.277777777777778, 0.277777777777778, 0.444444444444444;
647+
EXPECT_EQ(nrows, m->nrows());
648+
EXPECT_EQ(ncols, m->ncols());
649+
EXPECT_EQ(nnz, m->nonZeros());
650+
EXPECT_MATRIX_EQ_TOLERANCE(expected, *convertMatrix::toDense(m), 1e-15);
651+
}
652+
581653
TEST(SparseRowMatrixTest, CopyBlock)
582654
{
583655
auto m = MAKE_SPARSE_MATRIX_HANDLE(

0 commit comments

Comments
 (0)