Skip to content

Commit

Permalink
Add test for loss function
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhutchings committed Oct 18, 2023
1 parent 951e5d8 commit 336cdbe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/core/math/test_losses.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "catch2/catch_test_macros.hpp"
#include <jml/math/loss_functions.hpp>
#include <jml/math/vector.hpp>

SCENARIO("Loss can be calculated from two vectors") {
GIVEN("Two vectors of the same size") {
jml::Vector vec1(3), vec2(3);
vec1.set_entry(0, 1.0);
vec1.set_entry(1, 2.0);
vec1.set_entry(2, 3.0);
vec2.set_entry(0, 4.0);
vec2.set_entry(1, 2.0);
vec2.set_entry(2,-2.0);
auto loss = jml::l2lf(vec1, vec2);
REQUIRE(loss == 5.0);
}
}
1 change: 1 addition & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ core_test_sources = [
'core/math/test_matrix.cpp',
'core/math/test_vector.cpp',
'core/math/test_activation_functions.cpp',
'core/math/test_losses.cpp',
'core/test_model.cpp',
]

Expand Down

0 comments on commit 336cdbe

Please sign in to comment.