64 Link() noexcept = default;
65 Link(const
Link& ) noexcept = default;
68 Link(const
size_t _other, const
size_t _indexPos, const
size_t _dim, const
bool _external) noexcept;
70 Link& operator=(const
Link& ) noexcept = default;
71 Link& operator=(
Link&&) noexcept = default;
78 bool links(const
size_t _other) const noexcept;
101 explicit TensorNode( std::unique_ptr<Tensor>&& _tensorObject);
103 explicit TensorNode(std::unique_ptr<Tensor>&& _tensorObject, std::vector<Link> _neighbors);
114 size_t size() const noexcept;
116 size_t degree() const noexcept;
118 void erase() noexcept;
232 std::pair<size_t, size_t>
find_common_edge(
const size_t _nodeA,
const size_t _nodeB)
const;
258 explicit operator Tensor()
const;
305 template<
typename... args>
316 template<
typename... args>
439 virtual void round_edge(
const size_t _nodeA,
const size_t _nodeB,
const size_t _maxRank,
const double _eps,
const double _softThreshold);
449 virtual void transfer_core(
const size_t _from,
const size_t _to,
const bool _allowRankReduction =
true);
464 virtual void fix_mode(
const size_t _mode,
const size_t _slatePosition);
469 virtual void remove_slate(
const size_t _mode,
const size_t _slatePosition);
479 virtual void resize_mode(
const size_t _mode,
const size_t _newDim,
const size_t _cutPos=~0ul);
487 void contract(
const size_t _nodeId1,
const size_t _nodeId2);
496 double contraction_cost(
const size_t _nodeId1,
const size_t _nodeId2)
const;
505 size_t contract(
const std::set<size_t>& _ids);
520 void draw(
const std::string& _filename)
const;
static void add_network_to_network(internal::IndexedTensorWritable< TensorNetwork > &&_base, internal::IndexedTensorReadOnly< TensorNetwork > &&_toInsert)
Inserts all nodes from _toInsert into _base, creating links where demanded by the indices...
void contract(const size_t _nodeId1, const size_t _nodeId2)
Contracts the nodes with indices _nodeId1 and _nodeId2.
TensorNetwork stripped_subnet(const std::function< bool(size_t)> &_idF=[](size_t){ return true;}) const
Creates a dataless copy of a subnet.
void draw(const std::string &_filename) const
Draws a graph representation of the TensorNetwork.
static void link_traces_and_fix(internal::IndexedTensorWritable< TensorNetwork > &&_base)
Finds traces defined by the indices and internally links the corresponding indices. Also applys all fixed indices.
Link & operator=(const Link &) noexcept=default
Internal representation of an read and write and moveable indexed Tensor or TensorNetwork.
void sanitize()
Removes all erased nodes from the TensorNetwork.
virtual void remove_slate(const size_t _mode, const size_t _slatePosition)
removes the given _slatePosition from the _mode. this reduces the given dimension by one ...
ZeroNode
Internal indicator to prevent the creation of an degree zero node in TensorNetwork constructor...
virtual TensorNetwork * get_copy() const
Returns a new copy of the network.
size_t dimension
Dimension of the link, always equals to other->tensorObject->dimensions[indexPosition].
std::pair< size_t, size_t > find_common_edge(const size_t _nodeA, const size_t _nodeB) const
Finds the position of a single common edge between two nodes.
bool erased
Internal Flag.
virtual void contract_unconnected_subnetworks()
Contracts all nodes that are not connected to any external links.
Very general class used to represent arbitary tensor networks.
Internal representation of an readable indexed Tensor or TensorNetwork.
size_t datasize() const
Calculates the storage requirement of the current representation.
The TensorNode class is used by the class TensorNetwork to store the componentent tensors defining th...
The main namespace of xerus.
Class that handles simple (non-decomposed) tensors in a dense or sparse representation.
bool links(const size_t _other) const noexcept
Checks whether this link links to a particular node.
Header file for templates to store and restore objects from / to files / streams. ...
Tensor operator*(const value_t _factor, Tensor _tensor)
Calculates the entrywise multiplication of the Tensor _tensor with the constant _factor.
internal::IndexedTensorReadOnly< TensorNetwork > operator()(args... _args) const
Indexes the TensorNetwork for read only use.
void perform_traces(const size_t _nodeId)
Performs all traces in the given node.
Class representing a link from a TensorNode to another node or an external index. ...
std::ostream & operator<<(std::ostream &_out, const xerus::Index &_idx)
Allows to pretty print indices, giving the valueId and span.
void reduce_representation()
Contracts all nodes that are joined by a full-rank edge.
size_t degree() const
Gets the degree of the TensorNetwork.
value_t operator[](const size_t _position) const
Read the value at a specific position.
Internal representation of an readable and writeable indexed Tensor or TensorNetwork.
double contraction_cost(const size_t _nodeId1, const size_t _nodeId2) const
Approximates the cost of contraction two given nodes.
virtual bool specialized_contraction(std::unique_ptr< internal::IndexedTensorMoveable< TensorNetwork >> &_out, internal::IndexedTensorReadOnly< TensorNetwork > &&_me, internal::IndexedTensorReadOnly< TensorNetwork > &&_other) const
(Internal) Calculates the contraction between _me and _other and stores the result in _out...
FileFormat
possible file formats for tensor storage
virtual void require_correct_format() const
Sanity check for the TensorNetwork and if applicable for the specific format.
void reshuffle_nodes(const std::function< size_t(size_t)> &_f)
reshuffled the nodes according to the given function
virtual void resize_mode(const size_t _mode, const size_t _newDim, const size_t _cutPos=~0ul)
Resizes a specific mode of the TensorNetwork.
virtual bool specialized_sum(std::unique_ptr< internal::IndexedTensorMoveable< TensorNetwork >> &_out, internal::IndexedTensorReadOnly< TensorNetwork > &&_me, internal::IndexedTensorReadOnly< TensorNetwork > &&_other) const
(Internal) Calculates the sum between _me and _other and stores the result in _out. Requires that *this is the tensorObjectReadOnly of _me.
bool external
Flag indicating whether this link correspond to an external index.
size_t other
The index of the otherNode this Link links to.
TensorNetwork()
Constructs an order zero TensorNetwork.
constexpr const value_t EPSILON
The default epsilon value in xerus.
std::vector< Link > externalLinks
The open links of the network in order.
size_t indexPosition
IndexPosition on the other node or index of external index.
void stream_writer(std::ostream &_stream, const TensorNetwork &_obj, const FileFormat _format)
Pipes all information necessary to restore the current TensorNetwork into _stream.
void require_valid_network(const bool _check_erased=true) const
Sanity checks the network.
Abstract internal representation of an read and writeable indexed Tensor or TensorNetwork.
double value_t
The type of values to be used by xerus.
virtual ~TensorNetwork()=default
Destructor.
std::vector< size_t > RankTuple
: Represention of the ranks of a TensorNetwork.
bool approx_equal(const xerus::Tensor &_a, const xerus::Tensor &_b, const xerus::value_t _eps=EPSILON)
Checks whether two tensors are approximately equal.
std::unique_ptr< Tensor > tensorObject
Save slot for the tensorObject associated with this node.
virtual void operator/=(const value_t _divisor)
Performs the entrywise divison by a constant _divisor.
virtual value_t frob_norm() const
Calculates the frobenious norm of the TensorNetwork.
std::vector< Link > init_from_dimension_array()
: Sets the externalLinks and returns an Link vector for a node, assuming that this node is the only n...
virtual void transfer_core(const size_t _from, const size_t _to, const bool _allowRankReduction=true)
Transfers the core from one given node to another.
virtual void fix_mode(const size_t _mode, const size_t _slatePosition)
Fixes a specific mode to a specific value, effectively reducing the order by one. ...
std::vector< Link > neighbors
Vector of links defining the connection of this node to the network.
virtual void round_edge(const size_t _nodeA, const size_t _nodeB, const size_t _maxRank, const double _eps, const double _softThreshold)
Thresholds the rank between two given nodes.
void swap_external_links(const size_t _i, const size_t _j)
Swaps the external indices _i and _j, effectively changing those indices for the represented Tensor (...
#define XERUS_force_inline
Collection of attributes to force gcc to inline a specific function.
internal::IndexedTensor< TensorNetwork > operator()(args... _args)
Indexes the TensorNetwork for read/write use.
virtual void operator*=(const value_t _factor)
Performs the entrywise multiplication with a constant _factor.
std::vector< TensorNode > nodes
The nodes constituting the network. The order determines the ids of the nodes.
internal::IndexedTensorMoveable< Tensor > operator/(internal::IndexedTensorReadOnly< Tensor > &&_b, internal::IndexedTensorReadOnly< Tensor > &&_A)
virtual void specialized_evaluation(internal::IndexedTensorWritable< TensorNetwork > &&_me, internal::IndexedTensorReadOnly< TensorNetwork > &&_other)
(Internal) Evaluates _other into _me. Requires that *this is the tensorObjectReadOnly of _me...
Header file for the IndexedTensor class.
std::vector< size_t > dimensions
Dimensions of the external indices, i.e. the dimensions of the tensor represented by the network...
void stream_reader(std::istream &_stream, TensorNetwork &_obj, const FileFormat _format)
Restores the TensorNetwork from a stream of data.