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

Added subclasses of TensorOperation:

 1. Create tensor
 2. Destroy tensor
 3. Transform tensor
 4. Add tensors
 5. Contract tensors
parent 7b07f5fa
......@@ -9,9 +9,14 @@ add_library(${LIBRARY_NAME}
tensor_shape.cpp
tensor_leg.cpp
tensor.cpp
tensor_operation.cpp
tensor_connected.cpp
space_register.cpp
tensor_operation.cpp
tensor_op_create.cpp
tensor_op_destroy.cpp
tensor_op_transform.cpp
tensor_op_add.cpp
tensor_op_contract.cpp
num_server.cpp)
target_include_directories(${LIBRARY_NAME}
......
/** ExaTN::Numerics: Tensor operation: Adds a tensor to another tensor
REVISION: 2019/05/30
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
#include "tensor_op_add.hpp"
namespace exatn{
namespace numerics{
TensorOpAdd::TensorOpAdd():
TensorOperation(2,1)
{
this->setScalar(0,std::complex<double>{1.0,0.0}); //default alpha prefactor
}
bool TensorOpAdd::isSet() const
{
return (this->getNumOperandsSet() == this->getNumOperands() && this->getIndexPattern().length() > 0);
}
} //namespace numerics
} //namespace exatn
/** ExaTN::Numerics: Tensor operation: Adds a tensor to another tensor
REVISION: 2019/05/30
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
/** Rationale:
(a) Adds a tensor to another tensor inside the processing backend.
**/
#ifndef EXATN_NUMERICS_TENSOR_OP_ADD_HPP_
#define EXATN_NUMERICS_TENSOR_OP_ADD_HPP_
#include "tensor_basic.hpp"
#include "tensor_operation.hpp"
namespace exatn{
namespace numerics{
class TensorOpAdd: public TensorOperation{
public:
TensorOpAdd();
TensorOpAdd(const TensorOpAdd &) = default;
TensorOpAdd & operator=(const TensorOpAdd &) = default;
TensorOpAdd(TensorOpAdd &&) noexcept = default;
TensorOpAdd & operator=(TensorOpAdd &&) noexcept = default;
virtual ~TensorOpAdd() = default;
/** Returns TRUE iff the tensor operation is fully set. **/
virtual bool isSet() const override;
private:
};
} //namespace numerics
} //namespace exatn
#endif //EXATN_NUMERICS_TENSOR_OP_ADD_HPP_
/** ExaTN::Numerics: Tensor operation: Contracts two tensors and accumulates the result into another tensor
REVISION: 2019/05/30
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
#include "tensor_op_contract.hpp"
namespace exatn{
namespace numerics{
TensorOpContract::TensorOpContract():
TensorOperation(3,2)
{
this->setScalar(0,std::complex<double>{1.0,0.0}); //default alpha prefactor
this->setScalar(1,std::complex<double>{1.0,0.0}); //default beta prefactor (accumulative)
}
bool TensorOpContract::isSet() const
{
return (this->getNumOperandsSet() == this->getNumOperands() && this->getIndexPattern().length() > 0);
}
} //namespace numerics
} //namespace exatn
/** ExaTN::Numerics: Tensor operation: Contracts two tensors and accumulates the result into another tensor
REVISION: 2019/05/30
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
/** Rationale:
(a) Contracts two tensors and accumulates the result into another tensor
inside the processing backend.
**/
#ifndef EXATN_NUMERICS_TENSOR_OP_CONTRACT_HPP_
#define EXATN_NUMERICS_TENSOR_OP_CONTRACT_HPP_
#include "tensor_basic.hpp"
#include "tensor_operation.hpp"
namespace exatn{
namespace numerics{
class TensorOpContract: public TensorOperation{
public:
TensorOpContract();
TensorOpContract(const TensorOpContract &) = default;
TensorOpContract & operator=(const TensorOpContract &) = default;
TensorOpContract(TensorOpContract &&) noexcept = default;
TensorOpContract & operator=(TensorOpContract &&) noexcept = default;
virtual ~TensorOpContract() = default;
/** Returns TRUE iff the tensor operation is fully set. **/
virtual bool isSet() const override;
private:
};
} //namespace numerics
} //namespace exatn
#endif //EXATN_NUMERICS_TENSOR_OP_CONTRACT_HPP_
/** ExaTN::Numerics: Tensor operation: Creates a tensor
REVISION: 2019/05/30
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
#include "tensor_op_create.hpp"
namespace exatn{
namespace numerics{
TensorOpCreate::TensorOpCreate():
TensorOperation(1,0)
{
}
bool TensorOpCreate::isSet() const
{
return (this->getNumOperandsSet() == this->getNumOperands());
}
} //namespace numerics
} //namespace exatn
/** ExaTN::Numerics: Tensor operation: Creates a tensor
REVISION: 2019/05/30
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
/** Rationale:
(a) Creates a tensor inside the processing backend.
**/
#ifndef EXATN_NUMERICS_TENSOR_OP_CREATE_HPP_
#define EXATN_NUMERICS_TENSOR_OP_CREATE_HPP_
#include "tensor_basic.hpp"
#include "tensor_operation.hpp"
namespace exatn{
namespace numerics{
class TensorOpCreate: public TensorOperation{
public:
TensorOpCreate();
TensorOpCreate(const TensorOpCreate &) = default;
TensorOpCreate & operator=(const TensorOpCreate &) = default;
TensorOpCreate(TensorOpCreate &&) noexcept = default;
TensorOpCreate & operator=(TensorOpCreate &&) noexcept = default;
virtual ~TensorOpCreate() = default;
/** Returns TRUE iff the tensor operation is fully set. **/
virtual bool isSet() const override;
private:
};
} //namespace numerics
} //namespace exatn
#endif //EXATN_NUMERICS_TENSOR_OP_CREATE_HPP_
/** ExaTN::Numerics: Tensor operation: Destroys a tensor
REVISION: 2019/05/30
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
#include "tensor_op_destroy.hpp"
namespace exatn{
namespace numerics{
TensorOpDestroy::TensorOpDestroy():
TensorOperation(1,0)
{
}
bool TensorOpDestroy::isSet() const
{
return (this->getNumOperandsSet() == this->getNumOperands());
}
} //namespace numerics
} //namespace exatn
/** ExaTN::Numerics: Tensor operation: Destroys a tensor
REVISION: 2019/05/30
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
/** Rationale:
(a) Destroys a tensor inside the processing backend.
**/
#ifndef EXATN_NUMERICS_TENSOR_OP_DESTROY_HPP_
#define EXATN_NUMERICS_TENSOR_OP_DESTROY_HPP_
#include "tensor_basic.hpp"
#include "tensor_operation.hpp"
namespace exatn{
namespace numerics{
class TensorOpDestroy: public TensorOperation{
public:
TensorOpDestroy();
TensorOpDestroy(const TensorOpDestroy &) = default;
TensorOpDestroy & operator=(const TensorOpDestroy &) = default;
TensorOpDestroy(TensorOpDestroy &&) noexcept = default;
TensorOpDestroy & operator=(TensorOpDestroy &&) noexcept = default;
virtual ~TensorOpDestroy() = default;
/** Returns TRUE iff the tensor operation is fully set. **/
virtual bool isSet() const override;
private:
};
} //namespace numerics
} //namespace exatn
#endif //EXATN_NUMERICS_TENSOR_OP_DESTROY_HPP_
/** ExaTN::Numerics: Tensor operation: Transforms/initializes a tensor
REVISION: 2019/05/30
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
#include "tensor_op_transform.hpp"
namespace exatn{
namespace numerics{
TensorOpTransform::TensorOpTransform():
TensorOperation(1,1)
{
this->setScalar(0,std::complex<double>{0.0,0.0}); //default numerical initialization value
}
bool TensorOpTransform::isSet() const
{
return (this->getNumOperandsSet() == this->getNumOperands());
}
} //namespace numerics
} //namespace exatn
/** ExaTN::Numerics: Tensor operation: Transforms/initializes a tensor
REVISION: 2019/05/30
Copyright (C) 2018-2019 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2019 Oak Ridge National Laboratory (UT-Battelle) **/
/** Rationale:
(a) Transforms/initializes a tensor inside the processing backend.
**/
#ifndef EXATN_NUMERICS_TENSOR_OP_TRANSFORM_HPP_
#define EXATN_NUMERICS_TENSOR_OP_TRANSFORM_HPP_
#include "tensor_basic.hpp"
#include "tensor_operation.hpp"
namespace exatn{
namespace numerics{
class TensorOpTransform: public TensorOperation{
public:
TensorOpTransform();
TensorOpTransform(const TensorOpTransform &) = default;
TensorOpTransform & operator=(const TensorOpTransform &) = default;
TensorOpTransform(TensorOpTransform &&) noexcept = default;
TensorOpTransform & operator=(TensorOpTransform &&) noexcept = default;
virtual ~TensorOpTransform() = default;
/** Returns TRUE iff the tensor operation is fully set. **/
virtual bool isSet() const override;
private:
};
} //namespace numerics
} //namespace exatn
#endif //EXATN_NUMERICS_TENSOR_OP_TRANSFORM_HPP_
......@@ -11,10 +11,9 @@ namespace exatn{
namespace numerics{
TensorOperation::TensorOperation(unsigned int num_operands, unsigned int num_scalars):
num_operands_(num_operands), num_scalars_(num_scalars)
num_operands_(num_operands), num_scalars_(num_scalars), scalars_(num_scalars,std::complex<double>{0.0,0.0})
{
operands_.reserve(num_operands);
scalars_.reserve(num_scalars);
}
unsigned int TensorOperation::getNumOperands() const
......@@ -57,10 +56,10 @@ std::complex<double> TensorOperation::getScalar(unsigned int scalar_num) const
return scalars_[scalar_num];
}
void TensorOperation::setScalar(const std::complex<double> scalar)
void TensorOperation::setScalar(unsigned int scalar_num, const std::complex<double> scalar)
{
assert(scalars_.size() < num_scalars_);
scalars_.push_back(scalar);
assert(scalar_num < scalars_.size());
scalars_[scalar_num] = scalar;
return;
}
......
......@@ -61,7 +61,8 @@ public:
std::complex<double> getScalar(unsigned int scalar_num) const;
/** Sets the next scalar argument. **/
void setScalar(const std::complex<double> scalar);
void setScalar(unsigned int scalar_num,
const std::complex<double> scalar);
/** Returns the symbolic tensor operation specification (index pattern). **/
const std::string & getIndexPattern() const;
......@@ -70,7 +71,7 @@ public:
The tensor operation must have all its tensor/scalar operands set at this point.**/
void setIndexPattern(const std::string & pattern);
private:
protected:
std::string pattern_; //symbolic index pattern
std::vector<const Tensor *> operands_; //tensor operands (non-owning pointers)
......
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