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