Commit 8ad0ee82 authored by Dmitry I. Lyakh's avatar Dmitry I. Lyakh
Browse files

Added missing methods in numerics::TensorConn.

parent 4b840336
/** ExaTN::Numerics: Tensor
REVISION: 2019/06/05
REVISION: 2019/07/02
Copyright (C) 2018-2018 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2018 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -76,6 +76,26 @@ std::pair<SpaceId,SubspaceId> Tensor::getDimSpaceAttr(unsigned int dim_id) const
return signature_.getDimSpaceAttr(dim_id);
}
void Tensor::deleteDimension(unsigned int dim_id)
{
signature_.deleteDimension(dim_id);
shape_.deleteDimension(dim_id);
return;
}
void Tensor::appendDimension(std::pair<SpaceId,SubspaceId> subspace, DimExtent dim_extent)
{
signature_.appendDimension(subspace);
shape_.appendDimension(dim_extent);
return;
}
void Tensor::appendDimension(DimExtent dim_extent)
{
this->appendDimension(std::pair<SpaceId,SubspaceId>{SOME_SPACE,0},dim_extent);
return;
}
std::size_t Tensor::getTensorId() const
{
return reinterpret_cast<std::size_t>(this);
......
/** ExaTN::Numerics: Abstract Tensor
REVISION: 2019/06/05
REVISION: 2019/07/02
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -102,6 +102,14 @@ public:
SubspaceId getDimSubspaceId(unsigned int dim_id) const;
std::pair<SpaceId,SubspaceId> getDimSpaceAttr(unsigned int dim_id) const;
/** Deletes a specific tensor dimension, reducing the tensor rank by one. **/
void deleteDimension(unsigned int dim_id);
/** Appends a new dimension to the tensor at the end, increasing the tensor rank by one. **/
void appendDimension(std::pair<SpaceId,SubspaceId> subspace,
DimExtent dim_extent);
void appendDimension(DimExtent dim_extent);
/** Get the unique integer tensor id. **/
std::size_t getTensorId() const;
......
/** ExaTN::Numerics: Tensor connected to other tensors inside a tensor network
REVISION: 2019/06/03
REVISION: 2019/07/02
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -7,6 +7,7 @@ Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
#include "tensor_connected.hpp"
#include <iostream>
#include <assert.h>
namespace exatn{
......@@ -27,6 +28,11 @@ void TensorConn::printIt() const
return;
}
unsigned int TensorConn::getNumLegs() const
{
return tensor_->getRank();
}
std::shared_ptr<Tensor> TensorConn::getTensor()
{
return tensor_;
......@@ -37,7 +43,7 @@ unsigned int TensorConn::getTensorId() const
return id_;
}
TensorLeg TensorConn::getTensorLeg(unsigned int leg_id) const
TensorLeg & TensorConn::getTensorLeg(unsigned int leg_id)
{
assert(leg_id < legs_.size());
return legs_[leg_id];
......@@ -48,6 +54,41 @@ const std::vector<TensorLeg> & TensorConn::getTensorLegs() const
return legs_;
}
DimExtent TensorConn::getDimExtent(unsigned int dim_id) const
{
return tensor_->getDimExtent(dim_id);
}
void TensorConn::resetLeg(unsigned int leg_id, TensorLeg tensor_leg)
{
assert(leg_id < legs_.size());
legs_[leg_id].resetConnection(tensor_leg.getTensorId(),
tensor_leg.getDimensionId(),
tensor_leg.getDirection());
return;
}
void TensorConn::deleteLeg(unsigned int leg_id)
{
assert(leg_id < legs_.size());
legs_.erase(legs_.cbegin()+leg_id);
tensor_->deleteDimension(leg_id);
return;
}
void TensorConn::appendLeg(std::pair<SpaceId,SubspaceId> subspace, DimExtent dim_extent, TensorLeg tensor_leg)
{
tensor_->appendDimension(subspace,dim_extent);
legs_.emplace_back(tensor_leg);
return;
}
void TensorConn::appendLeg(DimExtent dim_extent, TensorLeg tensor_leg)
{
this->appendLeg(std::pair<SpaceId,SubspaceId>{SOME_SPACE,0},dim_extent,tensor_leg);
return;
}
} //namespace numerics
} //namespace exatn
/** ExaTN::Numerics: Tensor connected to other tensors in a tensor network
REVISION: 2019/06/03
REVISION: 2019/07/02
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -47,6 +47,9 @@ public:
/** Prints. **/
void printIt() const;
/** Returns the total number of legs (tensor rank/order). **/
unsigned int getNumLegs() const;
/** Returns a co-owned pointer to the tensor. **/
std::shared_ptr<Tensor> getTensor();
......@@ -54,11 +57,28 @@ public:
unsigned int getTensorId() const;
/** Returns a specific tensor leg. **/
TensorLeg getTensorLeg(unsigned int leg_id) const;
TensorLeg & getTensorLeg(unsigned int leg_id);
/** Returns all tensor legs. **/
const std::vector<TensorLeg> & getTensorLegs() const;
/** Returns the dimension extent of a specific tensor leg. **/
DimExtent getDimExtent(unsigned int dim_id) const;
/** Resets an existing tensor leg (specific connection to another tensor). **/
void resetLeg(unsigned int leg_id, //in: leg id to reset
TensorLeg tensor_leg); //in: new leg configuration
/** Deletes an existing tensor leg, reducing the tensor rank by one. **/
void deleteLeg(unsigned int leg_id); //in: leg id to delete
/** Appends a new tensor leg as the last leg, increasing the tensor rank by one. **/
void appendLeg(std::pair<SpaceId,SubspaceId> subspace, //in: subspace defining the new leg
DimExtent dim_extent, //in: dimension extent of the new leg
TensorLeg tensor_leg); //in: new leg configuration
void appendLeg(DimExtent dim_extent,
TensorLeg tensor_leg);
private:
std::shared_ptr<Tensor> tensor_; //co-owned pointer to the tensor
......
/** ExaTN::Numerics: Tensor network
REVISION: 2019/05/31
REVISION: 2019/07/02
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -13,9 +13,15 @@ Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
(d) A tensor leg can connect a given tensor with one or more
other tensors in the same tensor network. Thus, tensor
legs can be binary, ternary, etc.
(e) A tensor network is always closed, which in some
cases requires introducing an explicit output tensor
collecting all open ends of the original tensor network.
(e) A tensor network is always closed, which requires introducing
an explicit output tensor collecting all open legs of the original
tensor network. If the original tensor network does not have open
legs, the output tensor is simply a scalar which the original tensor
network evaluates to; otherwise, a tensor network evaluates to a tensor.
(f) Tensor enumeration:
0: Output tensor/scalar which the tensor network evaluates to;
1..N: Input tensors/scalars constituting the original tensor network;
N+1..M: Intermediate tensors obtained by contractions of input tensors.
**/
#ifndef EXATN_NUMERICS_TENSOR_NETWORK_HPP_
......@@ -34,6 +40,10 @@ namespace numerics{
class TensorNetwork{
public:
static constexpr unsigned int NUM_WALKERS = 1024; //default number of walkers for tensor contraction sequence optimization
using ContractionSequence = std::vector<std::pair<unsigned int, unsigned int>>; //pairs of contracted tensor id's
TensorNetwork() = default;
TensorNetwork(const TensorNetwork &) = default;
......@@ -42,11 +52,11 @@ public:
TensorNetwork & operator=(TensorNetwork &&) noexcept = default;
virtual ~TensorNetwork() = default;
private:
std::unordered_map<unsigned int, TensorConn> tensors_; //tensors connected to each other via legs (tensor connections)
//map: Nonnegative tensor id --> Connected tensor
//map: Non-negative tensor id --> Connected tensor
};
} //namespace numerics
......
/** ExaTN::Numerics: Tensor shape
REVISION: 2019/05/27
REVISION: 2019/07/02
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -8,6 +8,7 @@ Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
#include <iostream>
#include <iterator>
#include <assert.h>
namespace exatn{
......@@ -43,6 +44,19 @@ const std::vector<DimExtent> & TensorShape::getDimExtents() const
return extents_;
}
void TensorShape::deleteDimension(unsigned int dim_id)
{
assert(dim_id < extents_.size());
extents_.erase(extents_.cbegin()+dim_id);
return;
}
void TensorShape::appendDimension(DimExtent dim_extent)
{
extents_.emplace_back(dim_extent);
return;
}
} //namespace numerics
} //namespace exatn
/** ExaTN::Numerics: Tensor shape
REVISION: 2019/06/05
REVISION: 2019/07/02
Copyright (C) 2018-2018 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2018 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -52,6 +52,12 @@ public:
/** Get the extents of all tensor dimensions. **/
const std::vector<DimExtent> & getDimExtents() const;
/** Deletes a specific dimension, reducing the shape rank by one. **/
void deleteDimension(unsigned int dim_id);
/** Appends a new dimension at the end, increasing the shape rank by one. **/
void appendDimension(DimExtent dim_extent);
private:
std::vector<DimExtent> extents_; //tensor dimension extents
......
/** ExaTN::Numerics: Tensor signature
REVISION: 2018/11/16
REVISION: 2019/07/02
Copyright (C) 2018-2018 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2018 Oak Ridge National Laboratory (UT-Battelle) **/
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
#include "tensor_signature.hpp"
#include <assert.h>
#include <iostream>
#include <iterator>
#include <assert.h>
namespace exatn{
......@@ -67,6 +66,19 @@ std::pair<SpaceId,SubspaceId> TensorSignature::getDimSpaceAttr(unsigned int dim_
return subspaces_[dim_id];
}
void TensorSignature::deleteDimension(unsigned int dim_id)
{
assert(dim_id < subspaces_.size());
subspaces_.erase(subspaces_.cbegin()+dim_id);
return;
}
void TensorSignature::appendDimension(std::pair<SpaceId,SubspaceId> subspace)
{
subspaces_.emplace_back(subspace);
return;
}
} //namespace numerics
} //namespace exatn
/** ExaTN::Numerics: Tensor signature
REVISION: 2019/05/27
REVISION: 2019/07/02
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -58,6 +58,12 @@ public:
SubspaceId getDimSubspaceId(unsigned int dim_id) const;
std::pair<SpaceId,SubspaceId> getDimSpaceAttr(unsigned int dim_id) const;
/** Deletes a specific subspace, reducing the signature rank by one. **/
void deleteDimension(unsigned int dim_id);
/** Appends a new subspace at the end, increasing the signature rank by one. **/
void appendDimension(std::pair<SpaceId,SubspaceId> subspace = {SOME_SPACE,0});
private:
std::vector<std::pair<SpaceId,SubspaceId>> subspaces_; //tensor signature
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment