diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 3612fb72..a6beed66 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -20,6 +20,7 @@ ### Improvements +* Use camel case for type aliases [(#17)](https://github.com/XanaduAI/jet/pull/17) * Exceptions are now favoured in place of `std::terminate` with `Exception` being the new base type for all exceptions thrown by Jet. [(#3)](https://github.com/XanaduAI/jet/pull/3) * `TaskBasedCpuContractor` now stores `Tensor` results. [(#8)](https://github.com/XanaduAI/jet/pull/8) diff --git a/README.rst b/README.rst index 2dd3d8d5..41e63e25 100644 --- a/README.rst +++ b/README.rst @@ -61,11 +61,11 @@ include path and OpenBLAS is installed on your system, you can compile the #include int main(){ - using tensor_t = Jet::Tensor>; + using Tensor = Jet::Tensor>; - std::array tensors; - tensors[0] = tensor_t({"i", "j", "k"}, {2, 2, 2}); - tensors[1] = tensor_t({"j", "k", "l"}, {2, 2, 2}); + std::array tensors; + tensors[0] = Tensor({"i", "j", "k"}, {2, 2, 2}); + tensors[1] = Tensor({"j", "k", "l"}, {2, 2, 2}); tensors[0].FillRandom(); tensors[1].FillRandom(); diff --git a/include/jet/PathInfo.hpp b/include/jet/PathInfo.hpp index 9b96057c..89d48ca1 100644 --- a/include/jet/PathInfo.hpp +++ b/include/jet/PathInfo.hpp @@ -51,16 +51,16 @@ struct PathStepInfo { class PathInfo { public: /// Type of a node ID. - using node_id_t = size_t; + using NodeID_t = size_t; /// Type of a contraction path. - using path_t = std::vector>; + using Path = std::vector>; /// Type of the index-to-size map. - using index_to_size_map_t = std::unordered_map; + using IndexToSizeMap = std::unordered_map; /// Type of a `PathStepInfo` sequence. - using steps_t = std::vector; + using Steps = std::vector; /** * @brief Constructs an empty path. @@ -78,7 +78,7 @@ class PathInfo { * @param path Pairs of node IDs representing a raw contraction path. */ template - PathInfo(const TensorNetwork &tn, const path_t &path) : path_(path) + PathInfo(const TensorNetwork &tn, const Path &path) : path_(path) { const auto &nodes = tn.GetNodes(); num_leaves_ = nodes.size(); @@ -117,7 +117,7 @@ class PathInfo { * * @return Map which associates each index with a dimension size. */ - const index_to_size_map_t &GetIndexSizes() const noexcept + const IndexToSizeMap &GetIndexSizes() const noexcept { return index_to_size_map_; } @@ -134,14 +134,14 @@ class PathInfo { * * @return Pairs of node IDs representing the contraction path. */ - const path_t &GetPath() const noexcept { return path_; } + const Path &GetPath() const noexcept { return path_; } /** * @brief Returns the steps of this path. * * @return Collection of path steps. */ - const steps_t &GetSteps() const noexcept { return steps_; } + const Steps &GetSteps() const noexcept { return steps_; } /** * @brief Computes the number of floating-point operations needed to execute @@ -240,10 +240,10 @@ class PathInfo { private: /// Contraction path through the tensor network associated with this path. - path_t path_; + Path path_; /// Contraction metadata of the tensor network associated with this path. - steps_t steps_; + Steps steps_; /// Number of leaf nodes in the tensor network associated with this path. size_t num_leaves_; @@ -251,7 +251,7 @@ class PathInfo { /// Map that associates each index with its corresponding dimension size. /// This information is used to estimate memory requirements and floating- /// point operation counts. - index_to_size_map_t index_to_size_map_; + IndexToSizeMap index_to_size_map_; /** * @brief Contracts two path steps. diff --git a/include/jet/TaskBasedCpuContractor.hpp b/include/jet/TaskBasedCpuContractor.hpp index def35298..b8e1a50a 100644 --- a/include/jet/TaskBasedCpuContractor.hpp +++ b/include/jet/TaskBasedCpuContractor.hpp @@ -29,18 +29,18 @@ namespace Jet { template class TaskBasedCpuContractor { public: /// Type of the name-to-task map. - using name_to_task_map_t = std::unordered_map; + using NameToTaskMap = std::unordered_map; /// Type of the name-to-tensor map. - using name_to_tensor_map_t = + using NameToTensorMap = std::unordered_map>; /// Type of the name-to-parents map. - using name_to_parents_map_t = + using NameToParentsMap = std::unordered_map>; /// Type of the task dependency graph. - using taskflow_t = tf::Taskflow; + using TaskFlow = tf::Taskflow; /** * @brief Constructs a new `%TaskBasedCpuContractor` object. @@ -52,7 +52,7 @@ template class TaskBasedCpuContractor { * * @return Map which associates names to tasks. */ - const name_to_task_map_t &GetNameToTaskMap() const noexcept + const NameToTaskMap &GetNameToTaskMap() const noexcept { return name_to_task_map_; } @@ -62,7 +62,7 @@ template class TaskBasedCpuContractor { * * @return Map which associates names to tensors. */ - const name_to_tensor_map_t &GetNameToTensorMap() const noexcept + const NameToTensorMap &GetNameToTensorMap() const noexcept { return name_to_tensor_map_; } @@ -72,7 +72,7 @@ template class TaskBasedCpuContractor { * * @return Map which associates names to a vector of parent node IDs. */ - const name_to_parents_map_t &GetNameToParentsMap() const noexcept + const NameToParentsMap &GetNameToParentsMap() const noexcept { return name_to_parents_map_; } @@ -112,7 +112,7 @@ template class TaskBasedCpuContractor { * * @return Taskflow instance representing the task dependency graph. */ - const taskflow_t &GetTaskflow() const noexcept { return taskflow_; } + const TaskFlow &GetTaskflow() const noexcept { return taskflow_; } /** * @brief Returns the number of floating-point operations needed to perform @@ -304,17 +304,17 @@ template class TaskBasedCpuContractor { private: /// Task graph to be executed during a contraction. - taskflow_t taskflow_; + TaskFlow taskflow_; /// Map that associates a task name with its corresponding task. - name_to_task_map_t name_to_task_map_; + NameToTaskMap name_to_task_map_; /// Map that associates a task name with its result tensor. - name_to_tensor_map_t name_to_tensor_map_; + NameToTensorMap name_to_tensor_map_; /// Map that associates a task name with a list of parent task names. /// Task `A` is a parent of task `B` if `A` immediately succeeds `B`. - name_to_parents_map_t name_to_parents_map_; + NameToParentsMap name_to_parents_map_; /// Tasks that store the results of a contraction in `results_`. std::vector result_tasks_; diff --git a/include/jet/TensorNetwork.hpp b/include/jet/TensorNetwork.hpp index d9cd0c01..0136f994 100644 --- a/include/jet/TensorNetwork.hpp +++ b/include/jet/TensorNetwork.hpp @@ -38,14 +38,14 @@ namespace Jet { template class TensorNetwork { public: /// Type of a node ID. - using node_id_t = size_t; + using NodeID_t = size_t; /** * @brief `%Node` is a POD which wraps tensors in a `TensorNetwork`. */ struct Node { /// Unique ID for this node. - node_id_t id; + NodeID_t id; /// Name of this node. std::string name; @@ -71,7 +71,7 @@ template class TensorNetwork { size_t dim; /// IDs of the nodes connected by this edge. - std::vector node_ids; + std::vector node_ids; /** * @brief Reports whether two edges are the same. @@ -92,31 +92,30 @@ template class TensorNetwork { }; /// Type of a `Node` collection. - using nodes_t = std::vector; + using Nodes = std::vector; /// Type of the index-to-edge map. - using index_to_edge_map_t = std::unordered_map; + using IndexToEdgeMap = std::unordered_map; /// Type of the tag-to-node-IDs map. - using tag_to_node_ids_map_t = - std::unordered_multimap; + using TagToNodeIdsMap = std::unordered_multimap; /// Type of a contraction path. - using path_t = std::vector>; + using Path = std::vector>; /** * @brief Returns the nodes in this `%TensorNetwork`. * * @return Collection of nodes. */ - const nodes_t &GetNodes() const noexcept { return nodes_; } + const Nodes &GetNodes() const noexcept { return nodes_; } /** * @brief Returns the index-to-edge map of this `%TensorNetwork`. * * @return Map which associates indices with edges. */ - const index_to_edge_map_t &GetIndexToEdgeMap() const noexcept + const IndexToEdgeMap &GetIndexToEdgeMap() const noexcept { return index_to_edge_map_; } @@ -126,7 +125,7 @@ template class TensorNetwork { * * @return Map which associates tags with node IDs. */ - const tag_to_node_ids_map_t &GetTagToNodesMap() const noexcept + const TagToNodeIdsMap &GetTagToNodesMap() const noexcept { return tag_to_nodes_map_; } @@ -138,7 +137,7 @@ template class TensorNetwork { * * @return Pairs of node IDs representing the contraction path. */ - const path_t &GetPath() noexcept { return path_; } + const Path &GetPath() noexcept { return path_; } /** * @brief Returns the number of indices in this `%TensorNetwork`. @@ -165,10 +164,10 @@ template class TensorNetwork { * * @return Node ID assigned to the tensor. */ - node_id_t AddTensor(const Tensor &tensor, - const std::vector &tags) noexcept + NodeID_t AddTensor(const Tensor &tensor, + const std::vector &tags) noexcept { - node_id_t id = nodes_.size(); + NodeID_t id = nodes_.size(); nodes_.emplace_back(Node{ id, // id DeriveNodeName_(tensor.GetIndices()), // name @@ -295,7 +294,7 @@ template class TensorNetwork { * @param path Contraction path specified as a list of node ID pairs. * @return Tensor associated with the result of the final contraction. */ - const Tensor &Contract(const path_t &path = {}) + const Tensor &Contract(const Path &path = {}) { JET_ABORT_IF(nodes_.empty(), "An empty tensor network cannot be contracted."); @@ -326,15 +325,15 @@ template class TensorNetwork { private: /// Nodes inside this tensor network. - nodes_t nodes_; + Nodes nodes_; /// Map that associates each index with its corresponding edge. /// Not used when a contraction path is specified. - index_to_edge_map_t index_to_edge_map_; + IndexToEdgeMap index_to_edge_map_; /// Map that associates each tag with a list of nodes that contain that tag. /// Not used when a contraction path is specified. - tag_to_node_ids_map_t tag_to_nodes_map_; + TagToNodeIdsMap tag_to_nodes_map_; /// Contraction path representing pairs of nodes to be contracted. std::vector> path_; diff --git a/python/src/PathInfo.hpp b/python/src/PathInfo.hpp index eec62160..751fe14b 100644 --- a/python/src/PathInfo.hpp +++ b/python/src/PathInfo.hpp @@ -12,8 +12,8 @@ template void bind_constructors(py::class_ &c) { c.def(py::init> &, - const Jet::PathInfo::path_t &>(), - py::arg("tn"), py::arg("path") = Jet::PathInfo::path_t(), R"( + const Jet::PathInfo::Path &>(), + py::arg("tn"), py::arg("path") = Jet::PathInfo::Path(), R"( Constructs a populated PathInfo for the given path through a tensor network diff --git a/python/src/Tensor.hpp b/python/src/Tensor.hpp index 5a735740..af1f179f 100644 --- a/python/src/Tensor.hpp +++ b/python/src/Tensor.hpp @@ -367,4 +367,4 @@ template void AddBindingsForTensor(py::module_ &m) Returns: Transposed tensor object. )"); -} \ No newline at end of file +} diff --git a/python/src/TensorNetwork.hpp b/python/src/TensorNetwork.hpp index a0a8b650..2e11a94b 100644 --- a/python/src/TensorNetwork.hpp +++ b/python/src/TensorNetwork.hpp @@ -23,7 +23,7 @@ namespace py = pybind11; template void AddBindingsForTensorNetwork(py::module_ &m) { using TensorNetwork = Jet::TensorNetwork>; - using node_id_t = typename Jet::TensorNetwork>::node_id_t; + using NodeID_t = typename Jet::TensorNetwork>::NodeID_t; using Node = typename Jet::TensorNetwork>::Node; using Edge = typename Jet::TensorNetwork>::Edge; @@ -68,7 +68,7 @@ template void AddBindingsForTensorNetwork(py::module_ &m) .def_property_readonly( "tag_to_node_id_map", [](const TensorNetwork &tn) { - std::unordered_map> map; + std::unordered_map> map; for (const auto &[tag, node_id] : tn.GetTagToNodesMap()) { map[tag].emplace_back(node_id); diff --git a/python/src/TensorNetworkIO.hpp b/python/src/TensorNetworkIO.hpp index d34fd966..32d1e5c4 100644 --- a/python/src/TensorNetworkIO.hpp +++ b/python/src/TensorNetworkIO.hpp @@ -193,4 +193,4 @@ template void AddBindingsForTensorNetworkIO(py::module_ &m) { AddBindingsForTensorNetworkFile(m); AddBindingsForTensorNetworkSerializer(m); -} \ No newline at end of file +} diff --git a/test/Test_PathInfo.cpp b/test/Test_PathInfo.cpp index 7a26c949..ef25f9b8 100644 --- a/test/Test_PathInfo.cpp +++ b/test/Test_PathInfo.cpp @@ -10,17 +10,16 @@ using namespace Jet; -using complex_t = std::complex; -using tensor_t = Tensor; +using TestTensor = Tensor>; -using index_to_size_map_t = PathInfo::index_to_size_map_t; -using path_t = PathInfo::path_t; -using steps_t = PathInfo::steps_t; +using IndexToSizeMap = PathInfo::IndexToSizeMap; +using Path = PathInfo::Path; +using Steps = PathInfo::Steps; -using children_t = std::pair; -using indices_t = std::vector; -using shape_t = std::vector; -using tags_t = std::vector; +using Children = std::pair; +using Indices = std::vector; +using Shape = std::vector; +using Tags = std::vector; namespace { /** @@ -31,9 +30,10 @@ namespace { * @return Tensor with the given indices and shape. Each element in the tensor * is populated with the value of its linear index. */ -tensor_t MakeTensor(const indices_t &indices, const shape_t &shape) +Tensor> MakeTensor(const Indices &indices, + const Shape &shape) { - tensor_t tensor(indices, shape); + Tensor> tensor(indices, shape); if (!shape.empty()) { for (size_t i = 0; i < tensor.GetSize(); i++) { const auto index = Jet::Utilities::UnravelIndex(i, shape); @@ -52,21 +52,21 @@ TEST_CASE("PathInfo::PathInfo()", "[PathInfo]") const size_t want_leaves = 0; CHECK(have_leaves == want_leaves); - const path_t have_path = path_info.GetPath(); - const path_t want_path = {}; + const Path have_path = path_info.GetPath(); + const Path want_path = {}; CHECK(have_path == want_path); - const index_to_size_map_t have_index_sizes = path_info.GetIndexSizes(); - const index_to_size_map_t want_index_sizes = {}; + const IndexToSizeMap have_index_sizes = path_info.GetIndexSizes(); + const IndexToSizeMap want_index_sizes = {}; CHECK(have_index_sizes == want_index_sizes); - const steps_t have_steps = path_info.GetSteps(); + const Steps have_steps = path_info.GetSteps(); CHECK(have_steps.empty()); } -TEST_CASE("PathInfo::PathInfo(TensorNetwork, path_t)", "[PathInfo]") +TEST_CASE("PathInfo::PathInfo(TensorNetwork, Path)", "[PathInfo]") { - TensorNetwork tn; + TensorNetwork tn; SECTION("Tensor network is empty") { @@ -76,15 +76,15 @@ TEST_CASE("PathInfo::PathInfo(TensorNetwork, path_t)", "[PathInfo]") const size_t want_leaves = 0; CHECK(have_leaves == want_leaves); - const path_t have_path = path_info.GetPath(); - const path_t want_path = {}; + const Path have_path = path_info.GetPath(); + const Path want_path = {}; CHECK(have_path == want_path); - const index_to_size_map_t have_index_sizes = path_info.GetIndexSizes(); - const index_to_size_map_t want_index_sizes = {}; + const IndexToSizeMap have_index_sizes = path_info.GetIndexSizes(); + const IndexToSizeMap want_index_sizes = {}; CHECK(have_index_sizes == want_index_sizes); - const steps_t have_steps = path_info.GetSteps(); + const Steps have_steps = path_info.GetSteps(); CHECK(have_steps.empty()); } @@ -99,26 +99,26 @@ TEST_CASE("PathInfo::PathInfo(TensorNetwork, path_t)", "[PathInfo]") const size_t want_leaves = 1; CHECK(have_leaves == want_leaves); - const path_t have_path = path_info.GetPath(); - const path_t want_path = {}; + const Path have_path = path_info.GetPath(); + const Path want_path = {}; CHECK(have_path == want_path); - const index_to_size_map_t have_index_sizes = path_info.GetIndexSizes(); - const index_to_size_map_t want_index_sizes = {{"A0", 3}}; + const IndexToSizeMap have_index_sizes = path_info.GetIndexSizes(); + const IndexToSizeMap want_index_sizes = {{"A0", 3}}; CHECK(have_index_sizes == want_index_sizes); - const steps_t steps = path_info.GetSteps(); + const Steps steps = path_info.GetSteps(); REQUIRE(steps.size() == 1); { const auto &step = steps[0]; CHECK(step.id == 0); CHECK(step.parent == -1UL); - CHECK(step.children == children_t{-1, -1}); - CHECK(step.node_indices == indices_t{"A0"}); - CHECK(step.tensor_indices == indices_t{"A0"}); - CHECK(step.contracted_indices == indices_t{}); - CHECK(step.tags == tags_t{}); + CHECK(step.children == Children{-1, -1}); + CHECK(step.node_indices == Indices{"A0"}); + CHECK(step.tensor_indices == Indices{"A0"}); + CHECK(step.contracted_indices == Indices{}); + CHECK(step.tags == Tags{}); } } @@ -138,64 +138,64 @@ TEST_CASE("PathInfo::PathInfo(TensorNetwork, path_t)", "[PathInfo]") const size_t want_leaves = 3; CHECK(have_leaves == want_leaves); - const path_t have_path = path_info.GetPath(); - const path_t want_path = {{0, 1}}; + const Path have_path = path_info.GetPath(); + const Path want_path = {{0, 1}}; CHECK(have_path == want_path); - const index_to_size_map_t have_index_sizes = path_info.GetIndexSizes(); - const index_to_size_map_t want_index_sizes = { + const IndexToSizeMap have_index_sizes = path_info.GetIndexSizes(); + const IndexToSizeMap want_index_sizes = { {"A0", 3}, {"B1", 2}, {"C2", 4}, {"D3", 5}}; CHECK(have_index_sizes == want_index_sizes); - const steps_t steps = path_info.GetSteps(); + const Steps steps = path_info.GetSteps(); REQUIRE(steps.size() == 4); { const auto &step = steps[0]; CHECK(step.id == 0); CHECK(step.parent == 3); - CHECK(step.children == children_t{-1, -1}); - CHECK(step.node_indices == indices_t{"A0", "B1"}); - CHECK(step.tensor_indices == indices_t{"A0", "B1"}); - CHECK(step.contracted_indices == indices_t{}); - CHECK(step.tags == tags_t{"apple"}); + CHECK(step.children == Children{-1, -1}); + CHECK(step.node_indices == Indices{"A0", "B1"}); + CHECK(step.tensor_indices == Indices{"A0", "B1"}); + CHECK(step.contracted_indices == Indices{}); + CHECK(step.tags == Tags{"apple"}); } { const auto &step = steps[1]; CHECK(step.id == 1); CHECK(step.parent == 3); - CHECK(step.children == children_t{-1, -1}); - CHECK(step.node_indices == indices_t{"B1", "C2"}); - CHECK(step.tensor_indices == indices_t{"B1", "C2"}); - CHECK(step.contracted_indices == indices_t{}); - CHECK(step.tags == tags_t{"banana"}); + CHECK(step.children == Children{-1, -1}); + CHECK(step.node_indices == Indices{"B1", "C2"}); + CHECK(step.tensor_indices == Indices{"B1", "C2"}); + CHECK(step.contracted_indices == Indices{}); + CHECK(step.tags == Tags{"banana"}); } { const auto &step = steps[2]; CHECK(step.id == 2); CHECK(step.parent == -1ULL); - CHECK(step.children == children_t{-1, -1}); - CHECK(step.node_indices == indices_t{"D3"}); - CHECK(step.tensor_indices == indices_t{"D3"}); - CHECK(step.contracted_indices == indices_t{}); - CHECK(step.tags == tags_t{"cherry"}); + CHECK(step.children == Children{-1, -1}); + CHECK(step.node_indices == Indices{"D3"}); + CHECK(step.tensor_indices == Indices{"D3"}); + CHECK(step.contracted_indices == Indices{}); + CHECK(step.tags == Tags{"cherry"}); } { const auto &step = steps[3]; CHECK(step.id == 3); CHECK(step.parent == -1UL); - CHECK(step.children == children_t{0, 1}); - CHECK(step.node_indices == indices_t{"A0", "C2"}); - CHECK(step.tensor_indices == indices_t{"A0", "C2"}); - CHECK(step.contracted_indices == indices_t{"B1"}); - CHECK(step.tags == tags_t{"apple", "banana"}); + CHECK(step.children == Children{0, 1}); + CHECK(step.node_indices == Indices{"A0", "C2"}); + CHECK(step.tensor_indices == Indices{"A0", "C2"}); + CHECK(step.contracted_indices == Indices{"B1"}); + CHECK(step.tags == Tags{"apple", "banana"}); } } } TEST_CASE("PathInfo::GetPathStepFlops()", "[PathInfo]") { - TensorNetwork tn; + TensorNetwork tn; SECTION("Path step is a leaf") { @@ -287,7 +287,7 @@ TEST_CASE("PathInfo::GetPathStepFlops()", "[PathInfo]") TEST_CASE("PathInfo::GetTotalFlops()", "[PathInfo]") { - TensorNetwork tn; + TensorNetwork tn; SECTION("Path is empty") { @@ -356,11 +356,11 @@ TEST_CASE("PathInfo::GetTotalFlops()", "[PathInfo]") TEST_CASE("PathInfo::GetPathStepMemory()", "[PathInfo]") { - TensorNetwork tn; + TensorNetwork tn; SECTION("Tensor is a scalar") { - const auto tensor = MakeTensor(indices_t{}, {}); + const auto tensor = MakeTensor(Indices{}, {}); tn.AddTensor(tensor, {}); const PathInfo path_info(tn, {}); @@ -423,7 +423,7 @@ TEST_CASE("PathInfo::GetPathStepMemory()", "[PathInfo]") TEST_CASE("PathInfo::GetTotalMemory()", "[PathInfo]") { - TensorNetwork tn; + TensorNetwork tn; SECTION("Path is empty") { @@ -462,4 +462,4 @@ TEST_CASE("PathInfo::GetTotalMemory()", "[PathInfo]") const double want_memory = (3 * 2) + (2 * 4) + (5) + (3 * 4); CHECK(have_memory == want_memory); } -} \ No newline at end of file +} diff --git a/test/Test_TaskBasedCpuContractor.cpp b/test/Test_TaskBasedCpuContractor.cpp index 5607cd18..d41c9f1d 100644 --- a/test/Test_TaskBasedCpuContractor.cpp +++ b/test/Test_TaskBasedCpuContractor.cpp @@ -17,11 +17,11 @@ using namespace Jet; using complex_t = std::complex; using tensor_t = Tensor; -using indices_t = std::vector; -using shape_t = std::vector; -using task_map_t = std::unordered_map; -using tensor_map_t = std::unordered_map>; -using parents_map_t = +using Indices = std::vector; +using Shape = std::vector; +using TaskMap = std::unordered_map; +using TensorMap = std::unordered_map>; +using ParentsMap = std::unordered_map>; namespace { @@ -33,9 +33,10 @@ namespace { * @return Tensor with the given indices and shape. Each element in the tensor * is populated with the value of its linear index. */ -tensor_t MakeTensor(const indices_t &indices, const shape_t &shape) +Tensor> MakeTensor(const Indices &indices, + const Shape &shape) { - tensor_t tensor(indices, shape); + Tensor> tensor(indices, shape); if (!shape.empty()) { for (size_t i = 0; i < tensor.GetSize(); i++) { const auto index = Jet::Utilities::UnravelIndex(i, shape); @@ -51,9 +52,9 @@ tensor_t MakeTensor(const indices_t &indices, const shape_t &shape) * @param tbcc Task-based CPU contractor holding the name-to-task map. * @return Modified name-to-task map with a defined `==` operator. */ -task_map_t GetTaskMap(const TaskBasedCpuContractor &tbcc) +TaskMap GetTaskMap(const TaskBasedCpuContractor &tbcc) { - task_map_t task_map; + TaskMap task_map; for (const auto &[name, task] : tbcc.GetNameToTaskMap()) { task_map[name] = task.name(); } @@ -66,9 +67,9 @@ task_map_t GetTaskMap(const TaskBasedCpuContractor &tbcc) * @param tbcc Task-based CPU contractor holding the name-to-tensor map. * @return Modified name-to-tensor map with a defined `==` operator. */ -tensor_map_t GetTensorMap(const TaskBasedCpuContractor &tbcc) +TensorMap GetTensorMap(const TaskBasedCpuContractor &tbcc) { - tensor_map_t tensor_map; + TensorMap tensor_map; for (const auto &[name, tensor_ptr] : tbcc.GetNameToTensorMap()) { std::vector tensor_data; if (tensor_ptr.get() != nullptr) { @@ -104,16 +105,16 @@ TEST_CASE("TaskBasedCpuContractor::AddContractionTasks()", const double want_memory = 0; CHECK(have_memory == want_memory); - const task_map_t have_task_map = GetTaskMap(tbcc); - const task_map_t want_task_map = {}; + const TaskMap have_task_map = GetTaskMap(tbcc); + const TaskMap want_task_map = {}; CHECK(have_task_map == want_task_map); - const tensor_map_t have_tensor_map = GetTensorMap(tbcc); - const tensor_map_t want_tensor_map = {}; + const TensorMap have_tensor_map = GetTensorMap(tbcc); + const TensorMap want_tensor_map = {}; CHECK(have_tensor_map == want_tensor_map); - const parents_map_t have_parents_map = tbcc.GetNameToParentsMap(); - const parents_map_t want_parents_map = {}; + const ParentsMap have_parents_map = tbcc.GetNameToParentsMap(); + const ParentsMap want_parents_map = {}; CHECK(have_parents_map == want_parents_map); } @@ -142,16 +143,16 @@ TEST_CASE("TaskBasedCpuContractor::AddContractionTasks()", const double want_memory = 0; CHECK(have_memory == want_memory); - const task_map_t have_task_map = GetTaskMap(tbcc); - const task_map_t want_task_map = {}; + const TaskMap have_task_map = GetTaskMap(tbcc); + const TaskMap want_task_map = {}; CHECK(have_task_map == want_task_map); - const tensor_map_t have_tensor_map = GetTensorMap(tbcc); - const tensor_map_t want_tensor_map = {}; + const TensorMap have_tensor_map = GetTensorMap(tbcc); + const TensorMap want_tensor_map = {}; CHECK(have_tensor_map == want_tensor_map); - const parents_map_t have_parents_map = tbcc.GetNameToParentsMap(); - const parents_map_t want_parents_map = {}; + const ParentsMap have_parents_map = tbcc.GetNameToParentsMap(); + const ParentsMap want_parents_map = {}; CHECK(have_parents_map == want_parents_map); } @@ -182,15 +183,15 @@ TEST_CASE("TaskBasedCpuContractor::AddContractionTasks()", const double want_memory = (3 * 4) + (2 * 4) + (2 * 3); CHECK(have_memory == want_memory); - const task_map_t have_task_map = GetTaskMap(tbcc); - const task_map_t want_task_map = { + const TaskMap have_task_map = GetTaskMap(tbcc); + const TaskMap want_task_map = { {"3:C2B1", "3:C2B1"}, {"4:A0C2", "4:A0C2"}, {"5:B1A0:results[0]", "5:B1A0:results[0]"}}; CHECK(have_task_map == want_task_map); - const tensor_map_t have_tensor_map = GetTensorMap(tbcc); - const tensor_map_t want_tensor_map = { + const TensorMap have_tensor_map = GetTensorMap(tbcc); + const TensorMap want_tensor_map = { {"0:A0C2", {0, 1, 2, 3, 4, 5, 6, 7}}, {"1:A0B1", {0, 1, 2, 3, 4, 5}}, {"2:B1C2", {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}}, @@ -200,8 +201,8 @@ TEST_CASE("TaskBasedCpuContractor::AddContractionTasks()", }; CHECK(have_tensor_map == want_tensor_map); - const parents_map_t have_parents_map = tbcc.GetNameToParentsMap(); - const parents_map_t want_parents_map = { + const ParentsMap have_parents_map = tbcc.GetNameToParentsMap(); + const ParentsMap want_parents_map = { {"0:A0C2", {"3:C2B1"}}, {"1:A0B1", {"3:C2B1", "4:A0C2"}}, {"2:B1C2", {"4:A0C2"}}, @@ -243,14 +244,14 @@ TEST_CASE("TaskBasedCpuContractor::AddContractionTasks()", const double want_memory = 3 + 2 * 1; CHECK(have_memory == want_memory); - const task_map_t have_task_map = GetTaskMap(tbcc); - const task_map_t want_task_map = {{"3:B1", "3:B1"}, - {"4:_:results[0]", "4:_:results[0]"}, - {"4:_:results[1]", "4:_:results[1]"}}; + const TaskMap have_task_map = GetTaskMap(tbcc); + const TaskMap want_task_map = {{"3:B1", "3:B1"}, + {"4:_:results[0]", "4:_:results[0]"}, + {"4:_:results[1]", "4:_:results[1]"}}; CHECK(have_task_map == want_task_map); - const tensor_map_t have_tensor_map = GetTensorMap(tbcc); - const tensor_map_t want_tensor_map = { + const TensorMap have_tensor_map = GetTensorMap(tbcc); + const TensorMap want_tensor_map = { {"0:A0B1", {0, 1, 2, 3, 4, 5}}, {"1:A0", {0, 1}}, {"2:B1", {0, 1, 2}}, @@ -260,8 +261,8 @@ TEST_CASE("TaskBasedCpuContractor::AddContractionTasks()", }; CHECK(have_tensor_map == want_tensor_map); - const parents_map_t have_parents_map = tbcc.GetNameToParentsMap(); - const parents_map_t want_parents_map = { + const ParentsMap have_parents_map = tbcc.GetNameToParentsMap(); + const ParentsMap want_parents_map = { {"0:A0B1", {"3:B1"}}, {"1:A0", {"3:B1"}}, {"2:B1", {"4:_:results[0]", "4:_:results[1]"}}, @@ -390,8 +391,8 @@ TEST_CASE("TaskBasedCpuContractor::AddDeletionTasks()", tbcc.Contract().wait(); - const tensor_map_t have_tensor_map = GetTensorMap(tbcc); - const tensor_map_t want_tensor_map = { + const TensorMap have_tensor_map = GetTensorMap(tbcc); + const TensorMap want_tensor_map = { {"0:A0", {}}, {"1:A0", {}}, {"2:_:results[0]", {5}}, @@ -421,8 +422,8 @@ TEST_CASE("TaskBasedCpuContractor::AddDeletionTasks()", tbcc.Contract().wait(); - const tensor_map_t have_tensor_map = GetTensorMap(tbcc); - const tensor_map_t want_tensor_map = { + const TensorMap have_tensor_map = GetTensorMap(tbcc); + const TensorMap want_tensor_map = { {"0:A0B1", {}}, {"1:A0", {}}, {"2:B1", {}}, {"3:B1", {}}, {"4:_:results[0]", {14}}, }; @@ -533,4 +534,4 @@ TEST_CASE("TaskBasedCpuContractor::AddReductionTask()", const tensor_t want_result = tensor_t({}, {}, {5}); CHECK(have_result == want_result); } -} \ No newline at end of file +} diff --git a/test/Test_Tensor.cpp b/test/Test_Tensor.cpp index 69215783..7aab5843 100644 --- a/test/Test_Tensor.cpp +++ b/test/Test_Tensor.cpp @@ -12,7 +12,7 @@ using c128_t = std::complex; using c64_t = std::complex; -using data_t = std::vector; +using Data = std::vector; using namespace Jet; diff --git a/test/Test_TensorNetwork.cpp b/test/Test_TensorNetwork.cpp index 57e98497..279f84ed 100644 --- a/test/Test_TensorNetwork.cpp +++ b/test/Test_TensorNetwork.cpp @@ -10,17 +10,16 @@ using namespace Jet; -using complex_t = std::complex; -using tensor_t = Tensor; - -using data_t = std::vector; -using indices_t = std::vector; -using index_to_edge_map_t = TensorNetwork::index_to_edge_map_t; -using path_t = TensorNetwork::path_t; -using shape_t = std::vector; -using tag_to_node_ids_map_t = - std::unordered_map>; -using tags_t = std::vector; +using Complex = std::complex; +using TestTensor = Tensor; + +using Data = std::vector; +using Indices = std::vector; +using IndexToEdgeMap = TensorNetwork::IndexToEdgeMap; +using Path = TensorNetwork::Path; +using Shape = std::vector; +using TagToNodeIDsMap = std::unordered_map>; +using Tags = std::vector; namespace { /** @@ -31,14 +30,15 @@ namespace { * @return Tensor with the given indices and shape. Each element in the tensor * is populated with the value of its linear index. */ -tensor_t MakeTensor(const indices_t &indices, const shape_t &shape) +Tensor> MakeTensor(const Indices &indices, + const Shape &shape) { - tensor_t tensor(indices, shape); + Tensor> tensor(indices, shape); if (!shape.empty()) { for (size_t i = 0; i < tensor.GetSize(); i++) { const auto index = Jet::Utilities::UnravelIndex(i, shape); - tensor.SetValue(index, complex_t{static_cast(i), - static_cast(2 * i)}); + tensor.SetValue(index, Complex{static_cast(i), + static_cast(2 * i)}); } } return tensor; @@ -50,9 +50,9 @@ tensor_t MakeTensor(const indices_t &indices, const shape_t &shape) * @param tn Tensor network holding the tag-to-nodes map. * @return Modified tag-to-nodes map with a defined `==` operator. */ -tag_to_node_ids_map_t GetTagToNodeIDsMap(const TensorNetwork &tn) +TagToNodeIDsMap GetTagToNodeIDsMap(const TensorNetwork &tn) { - tag_to_node_ids_map_t tag_map; + TagToNodeIDsMap tag_map; for (const auto &[tag, node_id] : tn.GetTagToNodesMap()) { tag_map[tag].emplace_back(node_id); } @@ -66,7 +66,7 @@ tag_to_node_ids_map_t GetTagToNodeIDsMap(const TensorNetwork &tn) TEST_CASE("TensorNetwork::NumIndices", "[TensorNetwork]") { - TensorNetwork tn; + TensorNetwork tn; CHECK(tn.NumIndices() == 0); const auto tensor_AB = MakeTensor({"A0", "B1"}, {2, 3}); @@ -80,10 +80,10 @@ TEST_CASE("TensorNetwork::NumIndices", "[TensorNetwork]") TEST_CASE("TensorNetwork::NumTensors", "[TensorNetwork]") { - TensorNetwork tn; + TensorNetwork tn; CHECK(tn.NumTensors() == 0); - const tensor_t tensor; + const Tensor tensor; tn.AddTensor(tensor, {}); CHECK(tn.NumTensors() == 1); @@ -94,7 +94,7 @@ TEST_CASE("TensorNetwork::NumTensors", "[TensorNetwork]") TEST_CASE("TensorNetwork::AddTensor", "[TensorNetwork]") { - TensorNetwork tn; + TensorNetwork tn; SECTION("Single tensor with no indices or tags") { @@ -106,8 +106,8 @@ TEST_CASE("TensorNetwork::AddTensor", "[TensorNetwork]") const auto &node = tn.GetNodes().front(); CHECK(node.id == 0); CHECK(node.name == "_"); - CHECK(node.indices == indices_t{}); - CHECK(node.tags == tags_t{}); + CHECK(node.indices == Indices{}); + CHECK(node.tags == Tags{}); CHECK(node.contracted == false); CHECK(tn.GetIndexToEdgeMap().empty()); @@ -124,18 +124,18 @@ TEST_CASE("TensorNetwork::AddTensor", "[TensorNetwork]") const auto &node = tn.GetNodes().front(); CHECK(node.id == 0); CHECK(node.name == "A0B1"); - CHECK(node.indices == indices_t{"A0", "B1"}); - CHECK(node.tags == tags_t{"chaotic", "neutral"}); + CHECK(node.indices == Indices{"A0", "B1"}); + CHECK(node.tags == Tags{"chaotic", "neutral"}); CHECK(node.contracted == false); - const index_to_edge_map_t have_edge_map = tn.GetIndexToEdgeMap(); - const index_to_edge_map_t want_edge_map = {{"A0", {2, {0}}}, - {"B1", {3, {0}}}}; + const IndexToEdgeMap have_edge_map = tn.GetIndexToEdgeMap(); + const IndexToEdgeMap want_edge_map = {{"A0", {2, {0}}}, + {"B1", {3, {0}}}}; CHECK(have_edge_map == want_edge_map); - const tag_to_node_ids_map_t have_tag_map = GetTagToNodeIDsMap(tn); - const tag_to_node_ids_map_t want_tag_map = {{"chaotic", {0}}, - {"neutral", {0}}}; + const TagToNodeIDsMap have_tag_map = GetTagToNodeIDsMap(tn); + const TagToNodeIDsMap want_tag_map = {{"chaotic", {0}}, + {"neutral", {0}}}; CHECK(have_tag_map == want_tag_map); } @@ -152,26 +152,26 @@ TEST_CASE("TensorNetwork::AddTensor", "[TensorNetwork]") const auto &node = tn.GetNodes()[0]; CHECK(node.id == 0); CHECK(node.name == "C2D3"); - CHECK(node.indices == indices_t{"C2", "D3"}); - CHECK(node.tags == tags_t{"bot", "mid"}); + CHECK(node.indices == Indices{"C2", "D3"}); + CHECK(node.tags == Tags{"bot", "mid"}); CHECK(node.contracted == false); } { const auto &node = tn.GetNodes()[1]; CHECK(node.id == 1); CHECK(node.name == "D3E4"); - CHECK(node.indices == indices_t{"D3", "E4"}); - CHECK(node.tags == tags_t{"mid", "top"}); + CHECK(node.indices == Indices{"D3", "E4"}); + CHECK(node.tags == Tags{"mid", "top"}); CHECK(node.contracted == false); } - const index_to_edge_map_t have_edge_map = tn.GetIndexToEdgeMap(); - const index_to_edge_map_t want_edge_map = {{"D3", {4, {0, 1}}}, - {"E4", {2, {1}}}}; + const IndexToEdgeMap have_edge_map = tn.GetIndexToEdgeMap(); + const IndexToEdgeMap want_edge_map = {{"D3", {4, {0, 1}}}, + {"E4", {2, {1}}}}; CHECK(have_edge_map == want_edge_map); - const tag_to_node_ids_map_t have_tag_map = GetTagToNodeIDsMap(tn); - const tag_to_node_ids_map_t want_tag_map = { + const TagToNodeIDsMap have_tag_map = GetTagToNodeIDsMap(tn); + const TagToNodeIDsMap want_tag_map = { {"bot", {0}}, {"mid", {0, 1}}, {"top", {1}}}; CHECK(have_tag_map == want_tag_map); } @@ -180,7 +180,7 @@ TEST_CASE("TensorNetwork::AddTensor", "[TensorNetwork]") TEST_CASE("TensorNetwork::SliceIndices", "[TensorNetwork]") { using namespace Catch::Matchers; - TensorNetwork tn; + TensorNetwork tn; const auto tensor_1 = MakeTensor({"A0", "B1", "C2"}, {2, 3, 4}); const auto tensor_2 = MakeTensor({"D3"}, {2}); @@ -197,20 +197,20 @@ TEST_CASE("TensorNetwork::SliceIndices", "[TensorNetwork]") const std::string want_name = "A0B1C2"; CHECK(have_name == want_name); - const indices_t have_node_indices = node.indices; - const indices_t want_node_indices = {"A0", "B1", "C2"}; + const Indices have_node_indices = node.indices; + const Indices want_node_indices = {"A0", "B1", "C2"}; CHECK(have_node_indices == want_node_indices); - const indices_t have_tensor_indices = node.tensor.GetIndices(); - const indices_t want_tensor_indices = {"A0", "B1", "C2"}; + const Indices have_tensor_indices = node.tensor.GetIndices(); + const Indices want_tensor_indices = {"A0", "B1", "C2"}; CHECK(have_tensor_indices == want_tensor_indices); - const shape_t have_tensor_shape = node.tensor.GetShape(); - const shape_t want_tensor_shape = {2, 3, 4}; + const Shape have_tensor_shape = node.tensor.GetShape(); + const Shape want_tensor_shape = {2, 3, 4}; CHECK(have_tensor_shape == want_tensor_shape); - const data_t have_tensor_data = node.tensor.GetData(); - const data_t want_tensor_data = { + const Data have_tensor_data = node.tensor.GetData(); + const Data want_tensor_data = { {0, 0}, {1, 2}, {2, 4}, {3, 6}, {4, 8}, {5, 10}, {6, 12}, {7, 14}, {8, 16}, {9, 18}, {10, 20}, {11, 22}, {12, 24}, {13, 26}, {14, 28}, {15, 30}, {16, 32}, {17, 34}, @@ -227,22 +227,22 @@ TEST_CASE("TensorNetwork::SliceIndices", "[TensorNetwork]") const std::string want_name = "A0(0)B1C2"; CHECK(have_name == want_name); - const indices_t have_node_indices = node.indices; - const indices_t want_node_indices = {"A0(0)", "B1", "C2"}; + const Indices have_node_indices = node.indices; + const Indices want_node_indices = {"A0(0)", "B1", "C2"}; CHECK(have_node_indices == want_node_indices); - const indices_t have_tensor_indices = node.tensor.GetIndices(); - const indices_t want_tensor_indices = {"B1", "C2"}; + const Indices have_tensor_indices = node.tensor.GetIndices(); + const Indices want_tensor_indices = {"B1", "C2"}; CHECK(have_tensor_indices == want_tensor_indices); - const shape_t have_tensor_shape = node.tensor.GetShape(); - const shape_t want_tensor_shape = {3, 4}; + const Shape have_tensor_shape = node.tensor.GetShape(); + const Shape want_tensor_shape = {3, 4}; CHECK(have_tensor_shape == want_tensor_shape); - const data_t have_tensor_data = node.tensor.GetData(); - const data_t want_tensor_data = {{0, 0}, {1, 2}, {2, 4}, {3, 6}, - {4, 8}, {5, 10}, {6, 12}, {7, 14}, - {8, 16}, {9, 18}, {10, 20}, {11, 22}}; + const Data have_tensor_data = node.tensor.GetData(); + const Data want_tensor_data = {{0, 0}, {1, 2}, {2, 4}, {3, 6}, + {4, 8}, {5, 10}, {6, 12}, {7, 14}, + {8, 16}, {9, 18}, {10, 20}, {11, 22}}; CHECK(have_tensor_data == want_tensor_data); } @@ -255,22 +255,22 @@ TEST_CASE("TensorNetwork::SliceIndices", "[TensorNetwork]") const std::string want_name = "A0(1)B1C2"; CHECK(have_name == want_name); - const indices_t have_node_indices = node.indices; - const indices_t want_node_indices = {"A0(1)", "B1", "C2"}; + const Indices have_node_indices = node.indices; + const Indices want_node_indices = {"A0(1)", "B1", "C2"}; CHECK(have_node_indices == want_node_indices); - const indices_t have_tensor_indices = node.tensor.GetIndices(); - const indices_t want_tensor_indices = {"B1", "C2"}; + const Indices have_tensor_indices = node.tensor.GetIndices(); + const Indices want_tensor_indices = {"B1", "C2"}; CHECK(have_tensor_indices == want_tensor_indices); - const shape_t have_tensor_shape = node.tensor.GetShape(); - const shape_t want_tensor_shape = {3, 4}; + const Shape have_tensor_shape = node.tensor.GetShape(); + const Shape want_tensor_shape = {3, 4}; CHECK(have_tensor_shape == want_tensor_shape); - const data_t have_tensor_data = node.tensor.GetData(); - const data_t want_tensor_data = { - {12, 24}, {13, 26}, {14, 28}, {15, 30}, {16, 32}, {17, 34}, - {18, 36}, {19, 38}, {20, 40}, {21, 42}, {22, 44}, {23, 46}}; + const Data have_tensor_data = node.tensor.GetData(); + const Data want_tensor_data = {{12, 24}, {13, 26}, {14, 28}, {15, 30}, + {16, 32}, {17, 34}, {18, 36}, {19, 38}, + {20, 40}, {21, 42}, {22, 44}, {23, 46}}; CHECK(have_tensor_data == want_tensor_data); } @@ -283,20 +283,20 @@ TEST_CASE("TensorNetwork::SliceIndices", "[TensorNetwork]") const std::string want_name = "A0(1)B1C2(2)"; CHECK(have_name == want_name); - const indices_t have_node_indices = node.indices; - const indices_t want_node_indices = {"A0(1)", "B1", "C2(2)"}; + const Indices have_node_indices = node.indices; + const Indices want_node_indices = {"A0(1)", "B1", "C2(2)"}; CHECK(have_node_indices == want_node_indices); - const indices_t have_tensor_indices = node.tensor.GetIndices(); - const indices_t want_tensor_indices = {"B1"}; + const Indices have_tensor_indices = node.tensor.GetIndices(); + const Indices want_tensor_indices = {"B1"}; CHECK(have_tensor_indices == want_tensor_indices); - const shape_t have_tensor_shape = node.tensor.GetShape(); - const shape_t want_tensor_shape = {3}; + const Shape have_tensor_shape = node.tensor.GetShape(); + const Shape want_tensor_shape = {3}; CHECK(have_tensor_shape == want_tensor_shape); - const data_t have_tensor_data = node.tensor.GetData(); - const data_t want_tensor_data = {{14, 28}, {18, 36}, {22, 44}}; + const Data have_tensor_data = node.tensor.GetData(); + const Data want_tensor_data = {{14, 28}, {18, 36}, {22, 44}}; CHECK(have_tensor_data == want_tensor_data); } @@ -309,20 +309,20 @@ TEST_CASE("TensorNetwork::SliceIndices", "[TensorNetwork]") const std::string want_name = "A0(1)B1(2)C2(3)"; CHECK(have_name == want_name); - const indices_t have_node_indices = node.indices; - const indices_t want_node_indices = {"A0(1)", "B1(2)", "C2(3)"}; + const Indices have_node_indices = node.indices; + const Indices want_node_indices = {"A0(1)", "B1(2)", "C2(3)"}; CHECK(have_node_indices == want_node_indices); - const indices_t have_tensor_indices = node.tensor.GetIndices(); - const indices_t want_tensor_indices = {}; + const Indices have_tensor_indices = node.tensor.GetIndices(); + const Indices want_tensor_indices = {}; CHECK(have_tensor_indices == want_tensor_indices); - const shape_t have_tensor_shape = node.tensor.GetShape(); - const shape_t want_tensor_shape = {}; + const Shape have_tensor_shape = node.tensor.GetShape(); + const Shape want_tensor_shape = {}; CHECK(have_tensor_shape == want_tensor_shape); - const data_t have_tensor_data = node.tensor.GetData(); - const data_t want_tensor_data = {{23, 46}}; + const Data have_tensor_data = node.tensor.GetData(); + const Data want_tensor_data = {{23, 46}}; CHECK(have_tensor_data == want_tensor_data); } SECTION("Slice non-existent index") @@ -335,7 +335,7 @@ TEST_CASE("TensorNetwork::SliceIndices", "[TensorNetwork]") TEST_CASE("TensorNetwork::Contract", "[TensorNetwork]") { using namespace Catch::Matchers; - TensorNetwork tn; + TensorNetwork tn; SECTION("Implicit contraction of network [2]") { @@ -344,12 +344,12 @@ TEST_CASE("TensorNetwork::Contract", "[TensorNetwork]") const auto result = tn.Contract(); - const path_t have_path = tn.GetPath(); - const path_t want_path = {}; + const Path have_path = tn.GetPath(); + const Path want_path = {}; CHECK(have_path == want_path); - const data_t have_tensor_data = result.GetData(); - const data_t want_tensor_data = {{0, 0}, {1, 2}}; + const Data have_tensor_data = result.GetData(); + const Data want_tensor_data = {{0, 0}, {1, 2}}; CHECK(have_tensor_data == want_tensor_data); const auto &nodes = tn.GetNodes(); @@ -358,8 +358,8 @@ TEST_CASE("TensorNetwork::Contract", "[TensorNetwork]") CHECK(nodes[0].contracted == false); } - const index_to_edge_map_t have_map = tn.GetIndexToEdgeMap(); - const index_to_edge_map_t want_map = {{"A0", {2, {0}}}}; + const IndexToEdgeMap have_map = tn.GetIndexToEdgeMap(); + const IndexToEdgeMap want_map = {{"A0", {2, {0}}}}; CHECK(have_map == want_map); } @@ -373,12 +373,12 @@ TEST_CASE("TensorNetwork::Contract", "[TensorNetwork]") const auto result = tn.Contract(); - const path_t have_path = tn.GetPath(); - const path_t want_path = {{0, 1}}; + const Path have_path = tn.GetPath(); + const Path want_path = {{0, 1}}; CHECK(have_path == want_path); - const data_t have_tensor_data = {result.GetValue({})}; - const data_t want_tensor_data = {{-15, 20}}; + const Data have_tensor_data = {result.GetValue({})}; + const Data want_tensor_data = {{-15, 20}}; CHECK(have_tensor_data == want_tensor_data); const auto &nodes = tn.GetNodes(); @@ -391,12 +391,12 @@ TEST_CASE("TensorNetwork::Contract", "[TensorNetwork]") const auto &node = nodes[2]; CHECK(node.id == 2); CHECK(node.name == "_"); - CHECK(node.indices == indices_t{}); + CHECK(node.indices == Indices{}); CHECK(node.contracted == false); } - const index_to_edge_map_t have_map = tn.GetIndexToEdgeMap(); - const index_to_edge_map_t want_map = {}; + const IndexToEdgeMap have_map = tn.GetIndexToEdgeMap(); + const IndexToEdgeMap want_map = {}; CHECK(have_map == want_map); } @@ -410,12 +410,12 @@ TEST_CASE("TensorNetwork::Contract", "[TensorNetwork]") const auto result = tn.Contract(); - const path_t have_path = tn.GetPath(); - const path_t want_path = {{0, 1}}; + const Path have_path = tn.GetPath(); + const Path want_path = {{0, 1}}; CHECK(have_path == want_path); - const data_t have_tensor_data = result.GetData(); - const data_t want_tensor_data = {{-30, 40}, {-39, 52}}; + const Data have_tensor_data = result.GetData(); + const Data want_tensor_data = {{-30, 40}, {-39, 52}}; CHECK(have_tensor_data == want_tensor_data); const auto &nodes = tn.GetNodes(); @@ -428,12 +428,12 @@ TEST_CASE("TensorNetwork::Contract", "[TensorNetwork]") const auto &node = nodes[2]; CHECK(node.id == 2); CHECK(node.name == "B1"); - CHECK(node.indices == indices_t{"B1"}); + CHECK(node.indices == Indices{"B1"}); CHECK(node.contracted == false); } - const index_to_edge_map_t have_map = tn.GetIndexToEdgeMap(); - const index_to_edge_map_t want_map = {{"B1", {2, {2}}}}; + const IndexToEdgeMap have_map = tn.GetIndexToEdgeMap(); + const IndexToEdgeMap want_map = {{"B1", {2, {2}}}}; CHECK(have_map == want_map); } @@ -447,12 +447,12 @@ TEST_CASE("TensorNetwork::Contract", "[TensorNetwork]") const auto result = tn.Contract(); - const path_t have_path = tn.GetPath(); - const path_t want_path = {{0, 1}}; + const Path have_path = tn.GetPath(); + const Path want_path = {{0, 1}}; CHECK(have_path == want_path); - const data_t have_tensor_data = {result.GetValue({})}; - const data_t want_tensor_data = {{-165, 220}}; + const Data have_tensor_data = {result.GetValue({})}; + const Data want_tensor_data = {{-165, 220}}; CHECK(have_tensor_data == want_tensor_data); const auto &nodes = tn.GetNodes(); @@ -465,12 +465,12 @@ TEST_CASE("TensorNetwork::Contract", "[TensorNetwork]") const auto &node = nodes[2]; CHECK(node.id == 2); CHECK(node.name == "_"); - CHECK(node.indices == indices_t{}); + CHECK(node.indices == Indices{}); CHECK(node.contracted == false); } - const index_to_edge_map_t have_map = tn.GetIndexToEdgeMap(); - const index_to_edge_map_t want_map = {}; + const IndexToEdgeMap have_map = tn.GetIndexToEdgeMap(); + const IndexToEdgeMap want_map = {}; CHECK(have_map == want_map); } @@ -484,17 +484,17 @@ TEST_CASE("TensorNetwork::Contract", "[TensorNetwork]") const auto result = tn.Contract(); - const path_t have_path = tn.GetPath(); - const path_t want_path = {{0, 1}}; + const Path have_path = tn.GetPath(); + const Path want_path = {{0, 1}}; CHECK(have_path == want_path); - const shape_t have_tensor_shape = result.GetShape(); - const shape_t want_tensor_shape = {2, 3}; + const Shape have_tensor_shape = result.GetShape(); + const Shape want_tensor_shape = {2, 3}; REQUIRE(have_tensor_shape == want_tensor_shape); - const data_t have_tensor_data = result.GetData(); - const data_t want_tensor_data = {{-15, 20}, {-42, 56}, {-69, 92}, - {-42, 56}, {-150, 200}, {-258, 344}}; + const Data have_tensor_data = result.GetData(); + const Data want_tensor_data = {{-15, 20}, {-42, 56}, {-69, 92}, + {-42, 56}, {-150, 200}, {-258, 344}}; CHECK(have_tensor_data == want_tensor_data); const auto &nodes = tn.GetNodes(); @@ -507,13 +507,12 @@ TEST_CASE("TensorNetwork::Contract", "[TensorNetwork]") const auto &node = nodes[2]; CHECK(node.id == 2); CHECK(node.name == "A0C2"); - CHECK(node.indices == indices_t{"A0", "C2"}); + CHECK(node.indices == Indices{"A0", "C2"}); CHECK(node.contracted == false); } - const index_to_edge_map_t have_map = tn.GetIndexToEdgeMap(); - const index_to_edge_map_t want_map = {{"A0", {2, {2}}}, - {"C2", {3, {2}}}}; + const IndexToEdgeMap have_map = tn.GetIndexToEdgeMap(); + const IndexToEdgeMap want_map = {{"A0", {2, {2}}}, {"C2", {3, {2}}}}; CHECK(have_map == want_map); } @@ -529,16 +528,16 @@ TEST_CASE("TensorNetwork::Contract", "[TensorNetwork]") const auto result = tn.Contract({{1, 2}, {0, 3}}); - const path_t have_path = tn.GetPath(); - const path_t want_path = {{1, 2}, {0, 3}}; + const Path have_path = tn.GetPath(); + const Path want_path = {{1, 2}, {0, 3}}; CHECK(have_path == want_path); - const shape_t have_tensor_shape = result.GetShape(); - const shape_t want_tensor_shape = {2, 2}; + const Shape have_tensor_shape = result.GetShape(); + const Shape want_tensor_shape = {2, 2}; REQUIRE(have_tensor_shape == want_tensor_shape); - const data_t have_tensor_data = result.GetData(); - const data_t want_tensor_data = { + const Data have_tensor_data = result.GetData(); + const Data want_tensor_data = { {-308, -56}, {-517, -94}, {-1100, -200}, {-1804, -328}}; CHECK(have_tensor_data == want_tensor_data); @@ -553,20 +552,19 @@ TEST_CASE("TensorNetwork::Contract", "[TensorNetwork]") const auto &node = nodes[3]; CHECK(node.id == 3); CHECK(node.name == "B1D3"); - CHECK(node.indices == indices_t{"B1", "D3"}); + CHECK(node.indices == Indices{"B1", "D3"}); CHECK(node.contracted == true); } { const auto &node = nodes[4]; CHECK(node.id == 4); CHECK(node.name == "A0D3"); - CHECK(node.indices == indices_t{"A0", "D3"}); + CHECK(node.indices == Indices{"A0", "D3"}); CHECK(node.contracted == false); } - const index_to_edge_map_t have_map = tn.GetIndexToEdgeMap(); - const index_to_edge_map_t want_map = {{"D3", {2, {4}}}, - {"A0", {2, {4}}}}; + const IndexToEdgeMap have_map = tn.GetIndexToEdgeMap(); + const IndexToEdgeMap want_map = {{"D3", {2, {4}}}, {"A0", {2, {4}}}}; CHECK(have_map == want_map); } diff --git a/test/Test_TensorNetworkIO.cpp b/test/Test_TensorNetworkIO.cpp index d4ddf20b..be2bb4dc 100644 --- a/test/Test_TensorNetworkIO.cpp +++ b/test/Test_TensorNetworkIO.cpp @@ -16,7 +16,7 @@ TEMPLATE_TEST_CASE("TensorNetworkSerializer::operator()", using namespace Jet; - using path_t = std::vector>; + using Path = std::vector>; using tensor_t = Tensor; SECTION("empty string") @@ -94,7 +94,7 @@ TEMPLATE_TEST_CASE("TensorNetworkSerializer::operator()", REQUIRE(tn_f.path.has_value() == true); - CHECK(tn_f.path.value().GetPath() == path_t({{0, 1}, {1, 2}})); + CHECK(tn_f.path.value().GetPath() == Path({{0, 1}, {1, 2}})); auto tn = tn_f.tensors;