Commit 28d64605 authored by Dmitry I. Lyakh's avatar Dmitry I. Lyakh
Browse files

Implemented TensorNetwork default ctor and printIt.

parent 8ad0ee82
......@@ -6,9 +6,8 @@ Copyright (C) 2018-2018 Oak Ridge National Laboratory (UT-Battelle) **/
#include "tensor.hpp"
#include <assert.h>
#include <iostream>
#include <assert.h>
namespace exatn{
......@@ -30,6 +29,11 @@ name_(name), shape_(shape), signature_(shape.getRank())
{
}
Tensor::Tensor(const std::string & name):
name_(name)
{
}
void Tensor::printIt() const
{
std::cout << name_; signature_.printIt(); shape_.printIt();
......
......@@ -75,6 +75,8 @@ public:
template<typename T>
Tensor(const std::string & name, //tensor name
const std::vector<T> & extents); //tensor dimension extents
/** Create a rank-0 tensor (scalar). **/
Tensor(const std::string & name); //tensor name
Tensor(const Tensor & tensor) = default;
Tensor & operator=(const Tensor & tensor) = default;
......
/** 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) **/
#include "tensor_network.hpp"
#include <iostream>
#include <assert.h>
namespace exatn{
namespace numerics{
TensorNetwork::TensorNetwork(const std::string & name):
name_(name)
{
tensors_.emplace(
std::make_pair(
0U,
TensorConn(std::make_shared<Tensor>(name),0U,std::vector<TensorLeg>())
)
);
}
TensorNetwork::TensorNetwork()
{
tensors_.emplace(
std::make_pair(
0U,
TensorConn(std::make_shared<Tensor>("_SMOKY_TENSOR_"),0U,std::vector<TensorLeg>())
)
);
}
void TensorNetwork::printIt() const
{
std::cout << "TensorNetwork[" << name_ << "](" << this->getNumTensors() << "){" << std::endl;
for(const auto & kv: tensors_) kv.second.printIt();
std::cout << "}" << std::endl;
return;
}
unsigned int TensorNetwork::getNumTensors() const
{
return static_cast<unsigned int>(tensors_.size() - 1); //output tensor is not counted
}
} //namespace numerics
......
......@@ -32,6 +32,7 @@ Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
#include "tensor_op_factory.hpp"
#include <unordered_map>
#include <string>
namespace exatn{
......@@ -44,7 +45,10 @@ public:
using ContractionSequence = std::vector<std::pair<unsigned int, unsigned int>>; //pairs of contracted tensor id's
TensorNetwork() = default;
/** Creates an unnamed empty tensor network with a single scalar output tensor named "_SMOKY_TENSOR_" **/
TensorNetwork();
/** Creates a named empty tensor network with a single scalar output tensor named with the same name. **/
TensorNetwork(const std::string & name);
TensorNetwork(const TensorNetwork &) = default;
TensorNetwork & operator=(const TensorNetwork &) = default;
......@@ -52,9 +56,16 @@ public:
TensorNetwork & operator=(TensorNetwork &&) noexcept = default;
virtual ~TensorNetwork() = default;
/** Prints **/
void printIt() const;
/** Returns the number of input tensors in the tensor network.
Note that the output tensor (tensor #0) is not counted here. **/
unsigned int getNumTensors() const;
private:
std::string name_; //tensor network name
std::unordered_map<unsigned int, TensorConn> tensors_; //tensors connected to each other via legs (tensor connections)
//map: Non-negative tensor id --> Connected tensor
};
......
......@@ -14,6 +14,10 @@ namespace exatn{
namespace numerics{
TensorShape::TensorShape()
{
}
void TensorShape::printIt() const
{
std::cout << "{";
......
......@@ -33,6 +33,8 @@ public:
TensorShape(std::initializer_list<T> extents);
template<typename T>
TensorShape(const std::vector<T> & extents);
/** Create an empty tensor shape. **/
TensorShape();
TensorShape(const TensorShape & tens_shape) = default;
TensorShape & operator=(const TensorShape & tens_shape) = default;
......
......@@ -29,6 +29,10 @@ subspaces_(rank,std::pair<SpaceId,SubspaceId>(SOME_SPACE,0))
{
}
TensorSignature::TensorSignature()
{
}
void TensorSignature::printIt() const
{
std::cout << "{";
......
......@@ -37,9 +37,10 @@ public:
Case 2: space_id != SOME_SPACE: Then space is registered and subspace_id refers to its registered subspace. **/
TensorSignature(std::initializer_list<std::pair<SpaceId,SubspaceId>> subspaces);
TensorSignature(const std::vector<std::pair<SpaceId,SubspaceId>> & subspaces);
/** Create a default tensor signature of std::pair<SOME_SPACE,0> by providing the tensor rank only. **/
TensorSignature(unsigned int rank);
/** Create an empty tensor signature. **/
TensorSignature();
TensorSignature(const TensorSignature & tens_signature) = default;
TensorSignature & operator=(const TensorSignature & tens_signature) = default;
......
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