Cytnx v0.9.1
Loading...
Searching...
No Matches
search_tree.hpp
Go to the documentation of this file.
1#ifndef _H_search_tree_
2#define _H_search_tree_
3
4#include "Type.hpp"
5#include "UniTensor.hpp"
6#include "cytnx_error.hpp"
7#include "utils/utils.hpp"
8#include <vector>
9#include <map>
10#include <string>
11
12namespace cytnx {
14 class PsudoUniTensor {
15 public:
16 // UniTensor utensor; //don't worry about copy, because everything are references in cytnx!
17 std::vector<std::string> labels;
18 std::vector<cytnx_uint64> shape;
19 bool is_assigned;
20 PsudoUniTensor *left;
21 PsudoUniTensor *right;
22 PsudoUniTensor *root;
23 cytnx_float cost;
24 cytnx_uint64 ID;
25
26 std::string accu_str;
27
28 PsudoUniTensor()
29 : is_assigned(false), left(nullptr), right(nullptr), root(nullptr), cost(0), ID(0){};
30 PsudoUniTensor(const PsudoUniTensor &rhs) {
31 this->left = rhs.left;
32 this->right = rhs.right;
33 this->root = rhs.root;
34 this->labels = rhs.labels;
35 this->shape = rhs.shape;
36 this->is_assigned = rhs.is_assigned;
37 this->cost = rhs.cost;
38 this->accu_str = rhs.accu_str;
39 this->ID = rhs.ID;
40 }
41 PsudoUniTensor &operator==(const PsudoUniTensor &rhs) {
42 this->left = rhs.left;
43 this->right = rhs.right;
44 this->root = rhs.root;
45 this->labels = rhs.labels;
46 this->shape = rhs.shape;
47 this->is_assigned = rhs.is_assigned;
48 this->cost = rhs.cost;
49 this->accu_str = rhs.accu_str;
50 this->ID = rhs.ID;
51 return *this;
52 }
53 void from_utensor(const UniTensor &in_uten) {
54 this->labels = in_uten.labels();
55 this->shape = in_uten.shape();
56 this->is_assigned = true;
57 }
58 void clear_utensor() {
59 this->is_assigned = false;
60 this->labels.clear();
61 this->shape.clear();
62 this->ID = 0;
63 this->cost = 0;
64 this->accu_str = "";
65 }
66 void set_ID(const cytnx_int64 &ID) { this->ID = ID; }
67 };
68
69 class SearchTree {
70 public:
71 std::vector<std::vector<PsudoUniTensor>> nodes_container;
72 // std::vector<PsudoUniTensor> nodes_container; // this contains intermediate layer.
73 std::vector<PsudoUniTensor> base_nodes; // this is the button layer.
74
75 SearchTree(){};
76 SearchTree(const SearchTree &rhs) {
77 this->nodes_container = rhs.nodes_container;
78 this->base_nodes = rhs.base_nodes;
79 }
80 SearchTree &operator==(const SearchTree &rhs) {
81 this->nodes_container = rhs.nodes_container;
82 this->base_nodes = rhs.base_nodes;
83 return *this;
84 }
85
86 // clear all the elements in the whole tree.
87 void clear() {
88 nodes_container.clear();
89 base_nodes.clear();
90 // nodes_container.reserve(1024);
91 }
92 // clear all the intermediate layer, leave all the base_nodes intact.
93 // and reset the root pointer on the base ondes
94 void reset_search_order() { nodes_container.clear(); }
95 void search_order();
96 };
98} // namespace cytnx
99#endif
Definition Accessor.hpp:12
float cytnx_float
Definition Type.hpp:44
Tensor operator==(const Tensor &Lt, const Tensor &Rt)
The comparison operator for Tensor.
uint64_t cytnx_uint64
Definition Type.hpp:45