add possibility to iterate over SparseVector data at runtime (#143)

This commit is contained in:
kritz
2020-08-09 09:44:49 +02:00
committed by GitHub
parent e714a28c83
commit f981cea2ae
2 changed files with 21 additions and 1 deletions
+10
View File
@@ -31,6 +31,16 @@ TEST(sparseVectorTest, initialisationFromVector) {
EXPECT_FLOAT_EQ(a.at<2>(), vec(2));
}
TEST(sparseVectorTest, accessDataWithCompressedIndices) {
const Vector3f vec(1.f, 2.f, 3.f);
SparseVectorf<3, 0, 2> a(vec);
for (size_t i = 0; i < a.non_zeros(); i++) {
a.atCompressedIndex(i) = static_cast<float>(i);
}
EXPECT_FLOAT_EQ(a.at<0>(), a.atCompressedIndex(0));
EXPECT_FLOAT_EQ(a.at<2>(), a.atCompressedIndex(1));
}
TEST(sparseVectorTest, setZero) {
const float data[3] = {1.f, 2.f, 3.f};
SparseVectorf<24, 4, 6, 22> a(data);