Skip to content

Commit

Permalink
#365: add more tests and properly deal with size 0 arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
nmm0 committed Sep 25, 2024
1 parent 0e97e75 commit b785ba0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/checkpoint/container/array_serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace checkpoint {

template <typename Serializer, typename T, size_t N>
void serialize(Serializer& s, std::array<T, N>& array) {
dispatch::serializeArray(s, &array[0], array.size());
dispatch::serializeArray(s, array.data(), array.size());
}

} /* end namespace checkpoint */
Expand Down
2 changes: 1 addition & 1 deletion src/checkpoint/container/kokkos_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void serialize(Serializer& s, Kokkos::Array<T, N, Proxy>& array) {
#else
template <typename Serializer, typename T, size_t N>
void serialize(Serializer& s, Kokkos::Array<T, N>& array) {
dispatch::serializeArray(s, &array[0], array.size());
dispatch::serializeArray(s, array.data(), array.size());
}
#endif

Expand Down
14 changes: 13 additions & 1 deletion tests/unit/test_kokkos_serialize_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,20 @@ static void test_kokkos_array(Kokkos::Array<T, N>& refArray) {
TEST_F(KokkosArrayTest, test_kokkos_array) {
using namespace ::checkpoint;

auto arr1 = Kokkos::Array{ 1, 2, 3, 4, 5 };
auto arr1 = Kokkos::Array< int, 5 >{ 1, 2, 3, 4, 5 };
test_kokkos_array(arr1);

auto arr2 = Kokkos::Array< float, 3 >{ 3.14f, 2.71f, 365.242f };
test_kokkos_array(arr2);

auto arr3 = Kokkos::Array< double, 2 >{ 3.14, 2.71 };
test_kokkos_array(arr3);

auto arr4 = Kokkos::Array< int, 1 >{ 3 };
test_kokkos_array(arr4);

auto empty_arr = Kokkos::Array< double, 0 >{};
test_kokkos_array(empty_arr);
}

}}} // namespace checkpoint::tests::unit
Expand Down

0 comments on commit b785ba0

Please sign in to comment.