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

Merge branch 'devel'

parents 1d81b176 73baec79
/** ExaTN::Numerics: Tensor
REVISION: 2019/07/02
REVISION: 2019/07/08
Copyright (C) 2018-2018 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2018 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -34,6 +34,58 @@ name_(name)
{
}
Tensor::Tensor(const std::string & name, //tensor name
const Tensor & left_tensor, //left tensor
const Tensor & right_tensor, //right tensor
const std::vector<TensorLeg> & contraction): //tensor contraction pattern
name_(name)
{
//Import shape/signature of the input tensors:
auto left_rank = left_tensor.getRank();
TensorShape left_shape = left_tensor.getShape();
TensorSignature left_signa = left_tensor.getSignature();
auto right_rank = right_tensor.getRank();
TensorShape right_shape = right_tensor.getShape();
TensorSignature right_signa = right_tensor.getSignature();
//Extract the output tensor dimensions:
if(left_rank + right_rank > 0){
unsigned int out_mode = 0;
unsigned int inp_mode = 0;
unsigned int argt = 1; if(left_rank == 0) argt = 2;
unsigned int max_out_dim = 0;
unsigned int contr[left_rank+right_rank][2] = {0};
for(const auto & leg: contraction){
auto tens_id = leg.getTensorId();
if(tens_id == 0){ //uncontracted leg of either input tensor
unsigned int out_dim = leg.getDimensionId(); //output tensor mode id
if(out_dim > max_out_dim) max_out_dim = out_dim;
contr[out_dim][0] = argt; //input tensor argument: {1,2}
contr[out_dim][1] = inp_mode; //input tensor mode id
++out_mode;
}else{
assert(tens_id == 1 || tens_id == 2); //checking validity of argument <contraction>
}
++inp_mode;
if(argt == 1 && inp_mode == left_rank){inp_mode = 0; argt = 2;};
}
assert(max_out_dim < out_mode);
//Form the output tensor shape/signature:
for(unsigned int i = 0; i <= max_out_dim; ++i){
inp_mode = contr[i][1];
if(contr[i][0] == 1){
shape_.appendDimension(left_tensor.getDimExtent(inp_mode));
signature_.appendDimension(left_tensor.getDimSpaceAttr(inp_mode));
}else if(contr[i][0] == 2){
shape_.appendDimension(right_tensor.getDimExtent(inp_mode));
signature_.appendDimension(right_tensor.getDimSpaceAttr(inp_mode));
}else{
std::cout << "#ERROR(Tensor::Tensor): Invalid function argument: contraction: Missing output tensor mode!" << std::endl;
assert(false); //missing output tensor dimension
}
}
}
}
void Tensor::printIt() const
{
std::cout << name_; signature_.printIt(); shape_.printIt();
......
/** ExaTN::Numerics: Abstract Tensor
REVISION: 2019/07/02
REVISION: 2019/07/08
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -34,6 +34,7 @@ Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
#include "tensor_basic.hpp"
#include "tensor_shape.hpp"
#include "tensor_signature.hpp"
#include "tensor_leg.hpp"
#include <assert.h>
......@@ -77,6 +78,16 @@ public:
const std::vector<T> & extents); //tensor dimension extents
/** Create a rank-0 tensor (scalar). **/
Tensor(const std::string & name); //tensor name
/** Create a tensor by contracting two other tensors.
The vectors of tensor legs specify the tensor contraction pattern:
contraction.size() = left_rank + right_rank;
Output tensor id = 0;
Left input tensor id = 1;
Right input tensor id = 2. **/
Tensor(const std::string & name, //tensor name
const Tensor & left_tensor, //left tensor
const Tensor & right_tensor, //right tensor
const std::vector<TensorLeg> & contraction); //tensor contraction pattern
Tensor(const Tensor & tensor) = default;
Tensor & operator=(const Tensor & tensor) = default;
......
/** ExaTN::Numerics: Tensor network
REVISION: 2019/07/07
REVISION: 2019/07/08
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -94,8 +94,22 @@ bool TensorNetwork::appendTensorNetwork(TensorNetwork && network,
return true;
}
bool TensorNetwork::reoderOutputModes(const std::vector<unsigned int> & order)
void TensorNetwork::reoderOutputModes(const std::vector<unsigned int> & order)
{
//`Finish
return;
}
bool TensorNetwork::deleteTensor(unsigned int tensor_id)
{
assert(tensor_id != 0); //output tensor cannot be deleted
//`Finish
return true;
}
bool TensorNetwork::contractTensors(unsigned int left_id, unsigned int right_id, unsigned int result_id)
{
assert(left_id != right_id && left_id != result_id && right_id != result_id);
//`Finish
return true;
}
......
/** ExaTN::Numerics: Tensor network
REVISION: 2019/07/07
REVISION: 2019/07/08
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -102,7 +102,7 @@ public:
with the modes of the input tensors already present in the tensor network.
The unmatched modes of the newly appended tensor will be appended to the
existing modes of the output tensor of the tensor network (at the end). **/
bool appendTensor(unsigned int tensor_id, //in: tensor id (unique within the tensor network)
bool appendTensor(unsigned int tensor_id, //in: appended tensor id (unique within the tensor network)
std::shared_ptr<Tensor> tensor, //in: appended tensor
const std::vector<TensorLeg> & connections); //in: tensor connections
......@@ -110,7 +110,7 @@ public:
with the modes of the output tensor of the tensor network. The unmatched modes
of the newly appended tensor will be appended to the existing modes of the
output tensor of the tensor network (at the end). **/
bool appendTensor(unsigned int tensor_id, //in: tensor id (unique within the tensor network)
bool appendTensor(unsigned int tensor_id, //in: appended tensor id (unique within the tensor network)
std::shared_ptr<Tensor> tensor, //in: appended tensor
const std::vector<std::pair<unsigned int, unsigned int>> & pairing); //in: leg pairing: output tensor mode -> appended tensor mode
......@@ -122,8 +122,20 @@ public:
bool appendTensorNetwork(TensorNetwork && network, //in: appended tensor network
const std::vector<std::pair<unsigned int, unsigned int>> & pairing); //in: leg pairing: output tensor mode (primary) -> output tensor mode (appended)
/** Reoders the modes of the output tensor of the tensor network. **/
bool reoderOutputModes(const std::vector<unsigned int> & order); //in: new order of the output tensor modes (N2O)
/** Reoders the modes of the output tensor of the tensor network:
order[x] = y: yth mode of the output tensor becomes its xth mode. **/
void reoderOutputModes(const std::vector<unsigned int> & order); //in: new order of the output tensor modes (N2O)
/** Deletes a tensor from the tensor network (output tensor cannot be deleted!).
The released tensor legs will be joined at the end of the output tensor. **/
bool deleteTensor(unsigned int tensor_id); //in: id of the tensor to be deleted
/** Contracts two tensors in the tensor network, producing another tensor: result = left * right.
The uncontracted modes of the left tensor will precede the uncontracted modes
of the right tensor in the tensor-result. **/
bool contractTensors(unsigned int left_id, //in: left tensor id (present in the tensor network)
unsigned int right_id, //in: right tensor id (present in the tensor network)
unsigned int result_id); //in: result tensor id (absent in the tensor network, to be appended)
private:
......
/** ExaTN::Numerics: Tensor shape
REVISION: 2019/07/02
REVISION: 2019/07/08
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -48,6 +48,13 @@ const std::vector<DimExtent> & TensorShape::getDimExtents() const
return extents_;
}
void TensorShape::resetDimension(unsigned int dim_id, DimExtent extent)
{
assert(dim_id < extents_.size()); //debug
extents_[dim_id] = extent;
return;
}
void TensorShape::deleteDimension(unsigned int dim_id)
{
assert(dim_id < extents_.size());
......
/** ExaTN::Numerics: Tensor shape
REVISION: 2019/07/02
REVISION: 2019/07/08
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) **/
/** Rationale:
(a) Tensor shape is an ordered set of tensor dimension extents.
......@@ -54,6 +54,9 @@ public:
/** Get the extents of all tensor dimensions. **/
const std::vector<DimExtent> & getDimExtents() const;
/** Resets a specific dimension. **/
void resetDimension(unsigned int dim_id, DimExtent extent);
/** Deletes a specific dimension, reducing the shape rank by one. **/
void deleteDimension(unsigned int dim_id);
......
/** ExaTN::Numerics: Tensor signature
REVISION: 2019/07/02
REVISION: 2019/07/08
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -70,6 +70,13 @@ std::pair<SpaceId,SubspaceId> TensorSignature::getDimSpaceAttr(unsigned int dim_
return subspaces_[dim_id];
}
void TensorSignature::resetDimension(unsigned int dim_id, std::pair<SpaceId,SubspaceId> subspace)
{
assert(dim_id < subspaces_.size()); //debug
subspaces_[dim_id] = subspace;
return;
}
void TensorSignature::deleteDimension(unsigned int dim_id)
{
assert(dim_id < subspaces_.size());
......
/** ExaTN::Numerics: Tensor signature
REVISION: 2019/07/02
REVISION: 2019/07/08
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
......@@ -59,6 +59,9 @@ public:
SubspaceId getDimSubspaceId(unsigned int dim_id) const;
std::pair<SpaceId,SubspaceId> getDimSpaceAttr(unsigned int dim_id) const;
/** Resets a specific subspace. **/
void resetDimension(unsigned int dim_id, std::pair<SpaceId,SubspaceId> subspace);
/** Deletes a specific subspace, reducing the signature rank by one. **/
void deleteDimension(unsigned int dim_id);
......
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