From e6a16118a2a1de6da4ef4958a36fcc6245e25725 Mon Sep 17 00:00:00 2001 From: Ian McCulloch Date: Thu, 21 Nov 2024 21:21:59 +0800 Subject: [PATCH] Add cmake configuration for the location of the test data 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 --- tests/BlockUniTensor_test.h | 2 +- tests/CMakeLists.txt | 6 ++++++ tests/DenseUniTensor_test.h | 2 +- tests/Tensor_test.h | 2 +- tests/common_data_generator.cpp | 2 +- tests/gpu/BlockUniTensor_test.h | 2 +- tests/gpu/DenseUniTensor_test.h | 2 +- tests/gpu/Tensor_test.h | 2 +- tests/gpu/common_data_generator.cpp | 2 +- tests/gpu/linalg_test/GeSvd_test.cpp | 5 ++--- tests/gpu/linalg_test/Lanczos_Gnd_test.cpp | 6 +++--- tests/gpu/linalg_test/Svd_test.cpp | 5 ++--- tests/gpu/linalg_test/linalg_test.h | 2 +- tests/linalg_test/GeSvd_test.cpp | 5 ++--- tests/linalg_test/Lanczos_Gnd_test.cpp | 6 +++--- tests/linalg_test/Svd_test.cpp | 5 ++--- tests/linalg_test/linalg_test.h | 2 +- 17 files changed, 30 insertions(+), 28 deletions(-) diff --git a/tests/BlockUniTensor_test.h b/tests/BlockUniTensor_test.h index 75c874f99..f4b975a1b 100644 --- a/tests/BlockUniTensor_test.h +++ b/tests/BlockUniTensor_test.h @@ -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}); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 94e198dd4..2e82b50a3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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 @@ -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() diff --git a/tests/DenseUniTensor_test.h b/tests/DenseUniTensor_test.h index cab2ff0a9..f859a588e 100644 --- a/tests/DenseUniTensor_test.h +++ b/tests/DenseUniTensor_test.h @@ -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; diff --git a/tests/Tensor_test.h b/tests/Tensor_test.h index 8a91068d4..3388f159b 100644 --- a/tests/Tensor_test.h +++ b/tests/Tensor_test.h @@ -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; diff --git a/tests/common_data_generator.cpp b/tests/common_data_generator.cpp index e8991ef57..ac95dee31 100644 --- a/tests/common_data_generator.cpp +++ b/tests/common_data_generator.cpp @@ -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 dtype_list1 = { Type.ComplexDouble, Type.Double, diff --git a/tests/gpu/BlockUniTensor_test.h b/tests/gpu/BlockUniTensor_test.h index e558330f5..8a6335142 100644 --- a/tests/gpu/BlockUniTensor_test.h +++ b/tests/gpu/BlockUniTensor_test.h @@ -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}); diff --git a/tests/gpu/DenseUniTensor_test.h b/tests/gpu/DenseUniTensor_test.h index 269707113..388e664ba 100644 --- a/tests/gpu/DenseUniTensor_test.h +++ b/tests/gpu/DenseUniTensor_test.h @@ -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; diff --git a/tests/gpu/Tensor_test.h b/tests/gpu/Tensor_test.h index 09805f99e..36c61b9b4 100644 --- a/tests/gpu/Tensor_test.h +++ b/tests/gpu/Tensor_test.h @@ -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; diff --git a/tests/gpu/common_data_generator.cpp b/tests/gpu/common_data_generator.cpp index e8991ef57..ac95dee31 100644 --- a/tests/gpu/common_data_generator.cpp +++ b/tests/gpu/common_data_generator.cpp @@ -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 dtype_list1 = { Type.ComplexDouble, Type.Double, diff --git a/tests/gpu/linalg_test/GeSvd_test.cpp b/tests/gpu/linalg_test/GeSvd_test.cpp index 385b9aab5..405322d56 100644 --- a/tests/gpu/linalg_test/GeSvd_test.cpp +++ b/tests/gpu/linalg_test/GeSvd_test.cpp @@ -14,9 +14,8 @@ namespace GesvdTest { bool ReComposeCheck(const UniTensor& Tin, const std::vector& Tout); bool CheckLabels(const UniTensor& Tin, const std::vector& 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===== diff --git a/tests/gpu/linalg_test/Lanczos_Gnd_test.cpp b/tests/gpu/linalg_test/Lanczos_Gnd_test.cpp index a922b63bc..f58c241c2 100644 --- a/tests/gpu/linalg_test/Lanczos_Gnd_test.cpp +++ b/tests/gpu/linalg_test/Lanczos_Gnd_test.cpp @@ -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}); diff --git a/tests/gpu/linalg_test/Svd_test.cpp b/tests/gpu/linalg_test/Svd_test.cpp index ed7848b87..81f5e9be5 100644 --- a/tests/gpu/linalg_test/Svd_test.cpp +++ b/tests/gpu/linalg_test/Svd_test.cpp @@ -14,9 +14,8 @@ namespace SvdTest { bool ReComposeCheck(const UniTensor& Tin, const std::vector& Tout); bool CheckLabels(const UniTensor& Tin, const std::vector& 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===== diff --git a/tests/gpu/linalg_test/linalg_test.h b/tests/gpu/linalg_test/linalg_test.h index f2fe0976f..183cc1800 100644 --- a/tests/gpu/linalg_test/linalg_test.h +++ b/tests/gpu/linalg_test/linalg_test.h @@ -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 = diff --git a/tests/linalg_test/GeSvd_test.cpp b/tests/linalg_test/GeSvd_test.cpp index c72ed186b..2b967ab13 100644 --- a/tests/linalg_test/GeSvd_test.cpp +++ b/tests/linalg_test/GeSvd_test.cpp @@ -14,9 +14,8 @@ namespace GesvdTest { bool ReComposeCheck(const UniTensor& Tin, const std::vector& Tout); bool CheckLabels(const UniTensor& Tin, const std::vector& 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===== diff --git a/tests/linalg_test/Lanczos_Gnd_test.cpp b/tests/linalg_test/Lanczos_Gnd_test.cpp index 4e602bcba..52cd1b69c 100644 --- a/tests/linalg_test/Lanczos_Gnd_test.cpp +++ b/tests/linalg_test/Lanczos_Gnd_test.cpp @@ -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}); diff --git a/tests/linalg_test/Svd_test.cpp b/tests/linalg_test/Svd_test.cpp index 8addd4fc8..74be6b89a 100644 --- a/tests/linalg_test/Svd_test.cpp +++ b/tests/linalg_test/Svd_test.cpp @@ -14,9 +14,8 @@ namespace SvdTest { bool ReComposeCheck(const UniTensor& Tin, const std::vector& Tout); bool CheckLabels(const UniTensor& Tin, const std::vector& 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===== diff --git a/tests/linalg_test/linalg_test.h b/tests/linalg_test/linalg_test.h index 773c84fee..e45b0da31 100644 --- a/tests/linalg_test/linalg_test.h +++ b/tests/linalg_test/linalg_test.h @@ -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 =