xerus
a general purpose tensor library
tensorNode.cpp
Go to the documentation of this file.
1 // Xerus - A General Purpose Tensor Library
2 // Copyright (C) 2014-2017 Benjamin Huber and Sebastian Wolf.
3 //
4 // Xerus is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as published
6 // by the Free Software Foundation, either version 3 of the License,
7 // or (at your option) any later version.
8 //
9 // Xerus is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
13 //
14 // You should have received a copy of the GNU Affero General Public License
15 // along with Xerus. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // For further information on Xerus visit https://libXerus.org
18 // or contact us at contact@libXerus.org.
19 
25 #include <xerus/tensorNetwork.h>
26 #include <xerus/tensor.h>
27 
28 namespace xerus {
29 
31 
33 
34  TensorNetwork::TensorNode::TensorNode( std::unique_ptr<Tensor>&& _tensorObject) : tensorObject(std::move(_tensorObject)), neighbors(), erased(false) {}
35 
36  TensorNetwork::TensorNode::TensorNode(std::unique_ptr<Tensor>&& _tensorObject, std::vector<Link> _neighbors) : tensorObject(std::move(_tensorObject)), neighbors(std::move(_neighbors)), erased(false) {}
37 
39 
41  if(_other.tensorObject) {
42  if(tensorObject) {
43  *tensorObject = *_other.tensorObject;
44  } else {
45  tensorObject.reset( new Tensor(*_other.tensorObject));
46  }
47  } else {
48  tensorObject.reset();
49  }
50  neighbors = _other.neighbors;
51  erased = _other.erased;
52  return *this;
53  }
54 
56  tensorObject = std::move(_other.tensorObject);
57  neighbors = std::move(_other.neighbors);
58  erased = _other.erased;
59  return *this;
60  }
61 
63  return TensorNetwork::TensorNode(std::unique_ptr<Tensor>(), neighbors);
64  }
65 
66  size_t TensorNetwork::TensorNode::size() const noexcept {
67  size_t s = 1;
68  for (const Link &l : neighbors) {
69  s *= l.dimension;
70  }
71  return s;
72  }
73 
74  size_t TensorNetwork::TensorNode::degree() const noexcept {
75  return neighbors.size();
76  }
77 
79  erased = true;
80  neighbors.clear();
81  tensorObject.reset();
82  }
83 } // namespace xerus
The TensorNode class is used by the class TensorNetwork to store the componentent tensors defining th...
Definition: tensorNetwork.h:85
The main namespace of xerus.
Definition: basic.h:37
Class that handles simple (non-decomposed) tensors in a dense or sparse representation.
Definition: tensor.h:70
STL namespace.
TensorNode strippped_copy() const
Definition: tensorNode.cpp:62
size_t size() const noexcept
Definition: tensorNode.cpp:66
Header file for the Tensor class.
size_t degree() const noexcept
Definition: tensorNode.cpp:74
TensorNode & operator=(const TensorNode &_other)
Definition: tensorNode.cpp:40
std::unique_ptr< Tensor > tensorObject
Save slot for the tensorObject associated with this node.
Definition: tensorNetwork.h:88
std::vector< Link > neighbors
Vector of links defining the connection of this node to the network.
Definition: tensorNetwork.h:91
Header file for the TensorNetwork class.