Skip to content

Commit

Permalink
explicitly use floats, get rid of compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fm94 committed Jun 2, 2024
1 parent dbfcc01 commit b5fb456
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions tests/test_dense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ using namespace Layer;
TEST(DenseLayerTest, ForwardPass)
{
Dense dense(3, 2);
dense.set_learning_rate(0.01);
dense.set_learning_rate(0.01f);

Eigen::MatrixXf input(1, 3);
input << 1.0, 2.0, 3.0;
input << 1.0f, 2.0f, 3.0f;
Eigen::MatrixXf output(1, 2);

dense.forward(input, output);
Expand All @@ -24,16 +24,16 @@ TEST(DenseLayerTest, ForwardPass)
TEST(DenseLayerTest, BackwardPass)
{
Dense dense(3, 2);
dense.set_learning_rate(0.01);
dense.set_learning_rate(0.01f);

Eigen::MatrixXf input(1, 3);
input << 1.0, 2.0, 3.0;
input << 1.0f, 2.0f, 3.0f;
Eigen::MatrixXf output(1, 2);

dense.forward(input, output);

Eigen::MatrixXf dout(1, 2);
dout << 0.1, 0.2;
dout << 0.1f, 0.2f;
Eigen::MatrixXf din(1, 3);
dense.backward(dout, din);

Expand Down
10 changes: 5 additions & 5 deletions tests/test_relu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ TEST(ReLULayerTest, ForwardPass)
{
ReLU relu;
Eigen::MatrixXf input(1, 3);
input << 1.0, -2.0, 3.0;
input << 1.0f, -2.0f, 3.0f;
Eigen::MatrixXf output(1, 3);

relu.forward(input, output);

Eigen::MatrixXf expected_output(1, 3);
expected_output << 1.0, 0.0, 3.0;
expected_output << 1.0f, 0.0f, 3.0f;
expectEigenMatrixNear(output, expected_output);
}

TEST(ReLULayerTest, BackwardPass)
{
ReLU relu;
Eigen::MatrixXf input(1, 3);
input << 1.0, -2.0, 3.0;
input << 1.0f, -2.0f, 3.0f;
Eigen::MatrixXf output(1, 3);

relu.forward(input, output);

Eigen::MatrixXf dout(1, 3);
dout << 0.1, 0.2, 0.3;
dout << 0.1f, 0.2f, 0.3f;
Eigen::MatrixXf din(1, 3);
relu.backward(dout, din);

Eigen::MatrixXf expected_din(1, 3);
expected_din << 0.1, 0.0, 0.3;
expected_din << 0.1f, 0.0f, 0.3f;
expectEigenMatrixNear(din, expected_din);
}
10 changes: 5 additions & 5 deletions tests/test_softmax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ TEST(SoftmaxLayerTest, ForwardPass)
{
Softmax softmax;
Eigen::MatrixXf input(2, 2);
input << 1.0, 2.0, 3.0, 4.0;
input << 1.0f, 2.0f, 3.0f, 4.0f;

Eigen::MatrixXf output;
softmax.forward(input, output);

Eigen::MatrixXf expected_output(2, 2);
expected_output << 0.268941, 0.731059, 0.268941, 0.731059;
expected_output << 0.268941f, 0.731059f, 0.268941f, 0.731059f;

expectEigenMatrixNear(output, expected_output, 1e-5);
}
Expand All @@ -24,20 +24,20 @@ TEST(SoftmaxLayerTest, BackwardPass)
{
Softmax softmax;
Eigen::MatrixXf input(2, 2);
input << 1.0, 2.0, 3.0, 4.0;
input << 1.0f, 2.0f, 3.0f, 4.0f;

Eigen::MatrixXf output;
softmax.forward(input, output);

Eigen::MatrixXf out_grad(2, 2);
out_grad << 0.1, -0.1, 0.1, -0.1;
out_grad << 0.1f, -0.1f, 0.1f, -0.1f;

Eigen::MatrixXf in_grad;
softmax.backward(out_grad, in_grad);

// manually calculated
Eigen::MatrixXf expected_in_grad(2, 2);
expected_in_grad << 0.0393, -0.0393, 0.0393, -0.0393;
expected_in_grad << 0.0393f, -0.0393f, 0.0393f, -0.0393f;

expectEigenMatrixNear(in_grad, expected_in_grad, 1e-3);
}

0 comments on commit b5fb456

Please sign in to comment.