9 #include "estd/estd.hpp" 15 #ifndef ETEQ_INODE_HPP 16 #define ETEQ_INODE_HPP 25 static_assert(egen::TypeInfo<T>::type != egen::BAD_TYPE,
26 "Cannot create node of unknown type");
28 virtual ~iNode (
void) =
default;
49 virtual T*
data (
void) = 0;
52 virtual void update (
void) = 0;
67 using NodesT = std::vector<NodeptrT<T>>;
78 static std::unordered_map<size_t,NodeBuilderF<T>>
builders_;
83 const std::type_info& tp =
typeid(*tens);
84 return estd::must_getf(
builders_, tp.hash_code(),
85 "unknown tensor type `%s` with `%s` dtype",
86 tp.name(), egen::name_type(egen::get_type<T>()).c_str())(tens);
97 template <
typename TensType,
typename T>
100 const std::type_info& tp =
typeid(TensType);
102 emplace(tp.hash_code(), builder).second;
106 #define TO_NODE(tens) NodeConverters<T>::to_node(tens) 110 #endif // ETEQ_INODE_HPP virtual void update(void)=0
Trigger internal typed tensor update.
Definition: constant.hpp:17
std::string to_string(void) const
Return string representation of internal tensor.
Definition: inode.hpp:43
static NodeptrT< T > to_node(teq::TensptrT tens)
Return node associated with tensor type.
Definition: inode.hpp:81
Interface node for wrapping typed tensor.
Definition: inode.hpp:23
NodeConverters(void)=delete
std::vector< NodeptrT< T > > NodesT
Vector of nodes.
Definition: inode.hpp:67
teq::Shape shape(void)
Return shape of internal tensor.
Definition: inode.hpp:37
static std::unordered_map< size_t, NodeBuilderF< T > > builders_
Map tensor type to node creation function.
Definition: inode.hpp:78
std::shared_ptr< iTensor > TensptrT
Tensor smart pointer.
Definition: itensor.hpp:51
bool register_builder(NodeBuilderF< T > builder)
Definition: inode.hpp:98
virtual iNode< T > * clone_impl(void) const =0
std::function< NodeptrT< T >(teq::TensptrT)> NodeBuilderF
Function for building a node from tensor.
Definition: inode.hpp:71
std::shared_ptr< iNode< T > > NodeptrT
Smart pointer of node.
Definition: inode.hpp:63
virtual teq::TensptrT get_tensor(void) const =0
Return internal tensor.
iNode< T > * clone(void) const
Return deep copy of node where internal typed tensor is copied.
Definition: inode.hpp:31
virtual T * data(void)=0
Return raw data stored in internal typed tensor.
virtual ~iNode(void)=default
Node registry of tensor types and tensor to node function.
Definition: inode.hpp:75