Skip to content

Commit

Permalink
Make tests for Det() buildable
Browse files Browse the repository at this point in the history
The test cases are implemented with some problems, so they are expected
to fail. The problems below need to be fixed in the future:

1. Both CPU and GPU algorithms are frustrating in handling the boolean
type.
2. The tolerance value for verifying the result is wrong. `abs(result_value) / 1e6`
may be a choice.
3. The seed for random generator is fixed, so the randomized testing
tensors are identical across sessions. If this is intended design, we
should better to explicitly code the values in the tensors out.
4. The tests for GPU don't run on GPU.
5. The test names of GPU test and CPU test collide with each other.
  • Loading branch information
IvanaGyro committed Dec 2, 2024
1 parent d853a18 commit 9c02402
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 54 deletions.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ add_executable(
utils_test/vec_concatenate.cpp
utils_test/vec_unique.cpp
utils/getNconParameter.cpp
linalg_test/Det_test.cpp
linalg_test/Directsum_test.cpp
linalg_test/ExpH_test.cpp
linalg_test/ExpM_test.cpp
Expand Down
1 change: 1 addition & 0 deletions tests/gpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ add_executable(
utils_test/vec_concatenate.cpp
utils_test/vec_unique.cpp
utils/getNconParameter.cpp
linalg_test/Det_test.cpp
linalg_test/Directsum_test.cpp
linalg_test/ExpH_test.cpp
linalg_test/ExpM_test.cpp
Expand Down
50 changes: 22 additions & 28 deletions tests/gpu/linalg_test/Det_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,28 @@ namespace DetTest {
====================*/
TEST(Det, allDType) {
for (auto device : device_list) {
for (auto dtype1 : dtype_list) {
for (auto dtype2 : dtype_list) {
// The GPU version of Det is just too slow.
// So we lower the size of the tensor from 6,6 to 3,3.
Tensor T = Tensor({3, 3}, dtype1, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);

T = Tensor({2, 2}, dtype1, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);

T = Tensor({1, 1}, dtype1, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);

T = Tensor({3, 3}, dtype1, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);

T = Tensor({4, 4}, dtype1, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);
}
for (auto dtype : dtype_list) {
// The GPU version of Det is just too slow.
// So we lower the size of the tensor from 6,6 to 3,3.
Tensor T = Tensor({3, 3}, dtype, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);

T = Tensor({2, 2}, dtype, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);

T = Tensor({1, 1}, dtype, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);

T = Tensor({3, 3}, dtype, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);

T = Tensor({4, 4}, dtype, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);
}
}
}
Expand Down Expand Up @@ -101,10 +99,6 @@ namespace DetTest {
Tensor ConstructExpectTens(const Tensor& T) {
Tensor dst_T = zeros(1, T.dtype(), T.device());
int n = T.shape()[0];
ASSERT_TRUE(T.shape().size() != 2);
for (auto s : T.shape()) {
ASSERT_TRUE(s != n);
}
if (n == 1) {
dst_T.at({0}) = T.at({0, 0});
return dst_T;
Expand Down
46 changes: 20 additions & 26 deletions tests/linalg_test/Det_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,26 @@ namespace DetTest {
====================*/
TEST(Det, allDType) {
for (auto device : device_list) { // now only test for cpu device.
for (auto dtype1 : dtype_list) {
for (auto dtype2 : dtype_list) {
Tensor T = Tensor({6, 6}, dtype1, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);

T = Tensor({2, 2}, dtype1, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);

T = Tensor({1, 1}, dtype1, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);

T = Tensor({3, 3}, dtype1, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);

T = Tensor({4, 4}, dtype1, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);
}
for (auto dtype : dtype_list) {
Tensor T = Tensor({6, 6}, dtype, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);

T = Tensor({2, 2}, dtype, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);

T = Tensor({1, 1}, dtype, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);

T = Tensor({3, 3}, dtype, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);

T = Tensor({4, 4}, dtype, device);
InitTensorUniform(T, rand_seed1 = 3);
ExcuteDetTest(T);
}
}
}
Expand Down Expand Up @@ -99,10 +97,6 @@ namespace DetTest {
Tensor ConstructExpectTens(const Tensor& T) {
Tensor dst_T = zeros(1, T.dtype(), T.device());
int n = T.shape()[0];
ASSERT_TRUE(T.shape().size() != 2);
for (auto s : T.shape()) {
ASSERT_TRUE(s != n);
}
if (n == 1) {
dst_T.at({0}) = T.at({0, 0});
return dst_T;
Expand Down

0 comments on commit 9c02402

Please sign in to comment.