Skip to content

Commit

Permalink
Add cmake configuration for the location of the test data
Browse files Browse the repository at this point in the history
tests/CMakeLists.txt: add CYTNX_TEST_DATA_DIR variable for the location of the test data root directory

Update all tests that reference the test data directory to load data from CYTNX_TEST_DATA_DIR
  • Loading branch information
ianmccul committed Nov 21, 2024
1 parent fa4596e commit e6a1611
Show file tree
Hide file tree
Showing 17 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion tests/BlockUniTensor_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using namespace cytnx;
using namespace TestTools;
class BlockUniTensorTest : public ::testing::Test {
public:
std::string data_dir = "../../tests/test_data_base/common/BlockUniTensor/";
std::string data_dir = CYTNX_TEST_DATA_DIR "/common/BlockUniTensor/";

Bond B1 = Bond(BD_IN, {Qs(0) >> 1, Qs(1) >> 2});
Bond B2 = Bond(BD_IN, {Qs(0), Qs(1)}, {3, 4});
Expand Down
6 changes: 6 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
if(BACKEND_TORCH)
else()

# Define the path to the test data directory
set(CYTNX_TEST_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/test_data_base")

add_executable(
test_main
test_tools.cpp
Expand Down Expand Up @@ -36,6 +39,9 @@ add_executable(
algo_test/Vstack_test.cpp
)

# Add the preprocessor definition for CYTNX_TEST_DATA_DIR
target_compile_definitions(test_main PUBLIC CYTNX_TEST_DATA_DIR="${CYTNX_TEST_DATA_DIR}")

if(USE_CUDA)
add_subdirectory(gpu)
endif()
Expand Down
2 changes: 1 addition & 1 deletion tests/DenseUniTensor_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace std;
using namespace TestTools;
class DenseUniTensorTest : public ::testing::Test {
public:
std::string data_dir = "../../tests/test_data_base/common/DenseUniTensor/";
std::string data_dir = CYTNX_TEST_DATA_DIR "/common/DenseUniTensor/";

UniTensor ut_uninit;
UniTensor utzero345;
Expand Down
2 changes: 1 addition & 1 deletion tests/Tensor_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using namespace cytnx;
using namespace std;
class TensorTest : public ::testing::Test {
public:
std::string data_dir = "../../tests/test_data_base/common/Tensor/";
std::string data_dir = CYTNX_TEST_DATA_DIR "/common/Tensor/";

Tensor tzero345;
Tensor tone345;
Expand Down
2 changes: 1 addition & 1 deletion tests/common_data_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using namespace TestTools;

namespace CommonDataGen {

std::string dataRoot = "../../tests/test_data_base/common/";
std::string dataRoot = CYTNX_TEST_DATA_DIR "/common/";
static std::vector<unsigned int> dtype_list1 = {
Type.ComplexDouble,
Type.Double,
Expand Down
2 changes: 1 addition & 1 deletion tests/gpu/BlockUniTensor_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace TestTools;

class BlockUniTensorTest : public ::testing::Test {
public:
std::string data_dir = "../../../tests/test_data_base/common/BlockUniTensor/";
std::string data_dir = CYTNX_TEST_DATA_DIR "/common/BlockUniTensor/";

Bond B1 = Bond(BD_IN, {Qs(0) >> 1, Qs(1) >> 2});
Bond B2 = Bond(BD_IN, {Qs(0), Qs(1)}, {3, 4});
Expand Down
2 changes: 1 addition & 1 deletion tests/gpu/DenseUniTensor_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace std;
using namespace TestTools;
class DenseUniTensorTest : public ::testing::Test {
public:
std::string data_dir = "../../../tests/test_data_base/common/DenseUniTensor/";
std::string data_dir = CYTNX_TEST_DATA_DIR "/common/DenseUniTensor/";

UniTensor utzero345;
UniTensor utone345;
Expand Down
2 changes: 1 addition & 1 deletion tests/gpu/Tensor_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using namespace cytnx;
using namespace std;
class TensorTest : public ::testing::Test {
public:
std::string data_dir = "../../../tests/test_data_base/common/Tensor/";
std::string data_dir = CYTNX_TEST_DATA_DIR "/common/Tensor/";

Tensor tzero345;
Tensor tone345;
Expand Down
2 changes: 1 addition & 1 deletion tests/gpu/common_data_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using namespace TestTools;

namespace CommonDataGen {

std::string dataRoot = "../../tests/test_data_base/common/";
std::string dataRoot = CYTNX_TEST_DATA_DIR "/common/";
static std::vector<unsigned int> dtype_list1 = {
Type.ComplexDouble,
Type.Double,
Expand Down
5 changes: 2 additions & 3 deletions tests/gpu/linalg_test/GeSvd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ namespace GesvdTest {
bool ReComposeCheck(const UniTensor& Tin, const std::vector<UniTensor>& Tout);
bool CheckLabels(const UniTensor& Tin, const std::vector<UniTensor>& Tout);
bool SingularValsCorrect(const UniTensor& res, const UniTensor& ans);
std::string data_root = "../../../tests/test_data_base/";
std::string src_data_root = data_root + "common/";
std::string ans_data_root = data_root + "linalg/Gesvd/";
std::string src_data_root = CYTNX_TEST_DATA_DIR "common/";
std::string ans_data_root = CYTNX_TEST_DATA_DIR "linalg/Gesvd/";
// normal test

/*=====test info=====
Expand Down
6 changes: 3 additions & 3 deletions tests/gpu/linalg_test/Lanczos_Gnd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class MyOp2 : public LinOp {
public:
UniTensor H;
MyOp2(int dim) : LinOp("mv", dim) {
Tensor A = Tensor::Load("../../../tests/test_data_base/linalg/Lanczos_Gnd/lan_block_A.cytn")
Tensor A = Tensor::Load(CYTNX_TEST_DATA_DIR "/linalg/Lanczos_Gnd/lan_block_A.cytn")
.to(cytnx::Device.cuda);
Tensor B = Tensor::Load("../../../tests/test_data_base/linalg/Lanczos_Gnd/lan_block_B.cytn")
Tensor B = Tensor::Load(CYTNX_TEST_DATA_DIR "/linalg/Lanczos_Gnd/lan_block_B.cytn")
.to(cytnx::Device.cuda);
Tensor C = Tensor::Load("../../../tests/test_data_base/linalg/Lanczos_Gnd/lan_block_C.cytn")
Tensor C = Tensor::Load(CYTNX_TEST_DATA_DIR "/linalg/Lanczos_Gnd/lan_block_C.cytn")
.to(cytnx::Device.cuda);
Bond lan_I = Bond(BD_IN, {Qs(-1), Qs(0), Qs(1)}, {9, 9, 9});
Bond lan_J = Bond(BD_OUT, {Qs(-1), Qs(0), Qs(1)}, {9, 9, 9});
Expand Down
5 changes: 2 additions & 3 deletions tests/gpu/linalg_test/Svd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ namespace SvdTest {
bool ReComposeCheck(const UniTensor& Tin, const std::vector<UniTensor>& Tout);
bool CheckLabels(const UniTensor& Tin, const std::vector<UniTensor>& Tout);
bool SingularValsCorrect(const UniTensor& res, const UniTensor& ans);
std::string data_root = "../../../tests/test_data_base/";
std::string src_data_root = data_root + "common/";
std::string ans_data_root = data_root + "linalg/Svd/";
std::string src_data_root = CYTNX_TEST_DATA_DIR "common/";
std::string ans_data_root = CYTNX_TEST_DATA_DIR "linalg/Svd/";
// normal test

/*=====test info=====
Expand Down
2 changes: 1 addition & 1 deletion tests/gpu/linalg_test/linalg_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class linalg_Test : public ::testing::Test {
Tensor eye3x3cd = eye(3, Type.ComplexDouble).to(cytnx::Device.cuda);
Tensor zeros3x3cd = zeros(9, Type.ComplexDouble).reshape(3, 3).to(cytnx::Device.cuda);

std::string data_dir = "../../../tests/test_data_base/linalg/";
std::string data_dir = CYTNX_TEST_DATA_DIR "/linalg/";
// ==================== svd_truncate ===================
Bond svd_I = Bond(BD_OUT, {Qs(1), Qs(-1)}, {1, 1});
Bond svd_J =
Expand Down
5 changes: 2 additions & 3 deletions tests/linalg_test/GeSvd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ namespace GesvdTest {
bool ReComposeCheck(const UniTensor& Tin, const std::vector<UniTensor>& Tout);
bool CheckLabels(const UniTensor& Tin, const std::vector<UniTensor>& Tout);
bool SingularValsCorrect(const UniTensor& res, const UniTensor& ans);
std::string data_root = "../../tests/test_data_base/";
std::string src_data_root = data_root + "common/";
std::string ans_data_root = data_root + "linalg/Gesvd/";
std::string src_data_root = CYTNX_TEST_DATA_DIR "common/";
std::string ans_data_root = CYTNX_TEST_DATA_DIR "linalg/Gesvd/";
// normal test

/*=====test info=====
Expand Down
6 changes: 3 additions & 3 deletions tests/linalg_test/Lanczos_Gnd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class MyOp2 : public LinOp {
public:
UniTensor H;
MyOp2(int dim) : LinOp("mv", dim) {
Tensor A = Tensor::Load("../../tests/test_data_base/linalg/Lanczos_Gnd/lan_block_A.cytn");
Tensor B = Tensor::Load("../../tests/test_data_base/linalg/Lanczos_Gnd/lan_block_B.cytn");
Tensor C = Tensor::Load("../../tests/test_data_base/linalg/Lanczos_Gnd/lan_block_C.cytn");
Tensor A = Tensor::Load(CYTNX_TEST_DATA_DIR "/linalg/Lanczos_Gnd/lan_block_A.cytn");
Tensor B = Tensor::Load(CYTNX_TEST_DATA_DIR "/tests/test_data_base/linalg/Lanczos_Gnd/lan_block_B.cytn");
Tensor C = Tensor::Load(CYTNX_TEST_DATA_DIR "/tests/test_data_base/linalg/Lanczos_Gnd/lan_block_C.cytn");
Bond lan_I = Bond(BD_IN, {Qs(-1), Qs(0), Qs(1)}, {9, 9, 9});
Bond lan_J = Bond(BD_OUT, {Qs(-1), Qs(0), Qs(1)}, {9, 9, 9});
H = UniTensor({lan_I, lan_J});
Expand Down
5 changes: 2 additions & 3 deletions tests/linalg_test/Svd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ namespace SvdTest {
bool ReComposeCheck(const UniTensor& Tin, const std::vector<UniTensor>& Tout);
bool CheckLabels(const UniTensor& Tin, const std::vector<UniTensor>& Tout);
bool SingularValsCorrect(const UniTensor& res, const UniTensor& ans);
std::string data_root = "../../tests/test_data_base/";
std::string src_data_root = data_root + "common/";
std::string ans_data_root = data_root + "linalg/Svd/";
std::string src_data_root = CYTNX_TEST_DATA_DIR "common/";
std::string ans_data_root = CYTNX_TEST_DATA_DIR "linalg/Svd/";
// normal test

/*=====test info=====
Expand Down
2 changes: 1 addition & 1 deletion tests/linalg_test/linalg_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class linalg_Test : public ::testing::Test {
UniTensor ones3x3cd_ut = UniTensor(ones3x3cd, false, -1);
UniTensor invertable3x3cd_ut = UniTensor(invertable3x3cd, false, -1);

std::string data_dir = "../../tests/test_data_base/linalg/";
std::string data_dir = CYTNX_TEST_DATA_DIR "/linalg/";
// ==================== svd_truncate ===================
Bond svd_I = Bond(BD_OUT, {Qs(1), Qs(-1)}, {1, 1});
Bond svd_J =
Expand Down

0 comments on commit e6a1611

Please sign in to comment.