Skip to content

Commit 4997f23

Browse files
authored
Fix bug in Eye matrix (#71)
1 parent cb51d84 commit 4997f23

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

ElementStorage.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Ones : public MatrixBase<Ones<Rows, Cols, DType>, Rows, Cols, DType>
7373
};
7474

7575
template <int Rows, int Cols = 1, typename DType = float>
76-
class Eye : public MatrixBase<Ones<Rows, Cols, DType>, Rows, Cols, DType>
76+
class Eye : public MatrixBase<Eye<Rows, Cols, DType>, Rows, Cols, DType>
7777
{
7878
public:
7979
DType operator()(int i, int j = 0) const { return i == j; }

test/test_arithmetic.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ TEST(Arithmetic, OnesTest)
5050
}
5151
}
5252

53+
TEST(Arithmetic, EyeTest)
54+
{
55+
auto I = BLA::Eye<2, 2>();
56+
auto Z = BLA::Zeros<2, 2>();
57+
auto R = I + Z;
58+
59+
for (int i = 0; i < 2; ++i)
60+
{
61+
for (int j = 0; j < 2; ++j)
62+
{
63+
EXPECT_FLOAT_EQ(I(i, j), i == j ? 1.0f : 0.0f);
64+
EXPECT_FLOAT_EQ(Z(i, j), 0.0f);
65+
EXPECT_FLOAT_EQ(R(i, j), i == j ? 1.0f : 0.0f);
66+
}
67+
}
68+
}
69+
5370
TEST(Arithmetic, AdditionSubtraction)
5471
{
5572
Matrix<3, 3> A = {3.25, 5.67, 8.67, 4.55, 7.23, 9.00, 2.35, 5.73, 10.56};

0 commit comments

Comments
 (0)