LibraryLink Utilities  3.0.1
Modern C++ wrapper over LibraryLink and WSTP
Generic/Tensor.hpp
Go to the documentation of this file.
1 
6 #ifndef LLU_CONTAINERS_GENERIC_TENSOR_HPP
7 #define LLU_CONTAINERS_GENERIC_TENSOR_HPP
8 
11 
12 namespace LLU {
13 
14  template<>
15  class MContainer<MArgumentType::Tensor>;
16 
18  using GenericTensor = MContainer<MArgumentType::Tensor>;
19 
23  template<>
24  class MContainer<MArgumentType::Tensor> : public TensorInterface, public MContainerBase<MArgumentType::Tensor> {
25  public:
28 
30  MContainer() = default;
31 
39  MContainer(mint type, mint rank, const mint* dims);
40 
46  MContainer clone() const {
47  return MContainer {cloneContainer(), Ownership::Library};
48  }
49 
51  mint getRank() const override {
52  return LibraryData::API()->MTensor_getRank(this->getContainer());
53  }
54 
56  mint const* getDimensions() const override {
57  return LibraryData::API()->MTensor_getDimensions(this->getContainer());
58  }
59 
61  mint getFlattenedLength() const override {
62  return LibraryData::API()->MTensor_getFlattenedLength(this->getContainer());
63  }
64 
66  mint type() const override {
67  return LibraryData::API()->MTensor_getType(this->getContainer());
68  }
69 
71  void* rawData() const override;
72 
73  private:
74 
79  mint shareCountImpl() const noexcept override {
80  return LibraryData::API()->MTensor_shareCount(this->getContainer());
81  }
82 
84  void passImpl(MArgument& res) const noexcept override {
85  MArgument_setMTensor(res, this->getContainer());
86  }
87 
92  Container cloneImpl() const override;
93  };
94 
95 } // namespace LLU
96 
97 #endif // LLU_CONTAINERS_GENERIC_TENSOR_HPP
LLU::MContainerBase
Template of the base class for all generic containers.
Definition: Base.hpp:35
LLU
Main namespace of LibraryLink Utilities.
Definition: Queue.h:13
LLU::MContainer
MContainer is an abstract class template for generic containers. Only specializations shall be used.
Definition: Base.hpp:245
LLU::MContainer< MArgumentType::Tensor >::type
mint type() const override
Get the data type of this tensor.
Definition: Generic/Tensor.hpp:66
LLU::LibraryData::API
static WolframLibraryData API()
Get currently owned WolframLibraryData, if any.
Definition: LibraryData.cpp:22
LLU::Ownership::Library
@ Library
The library (LLU) is responsible for managing the container's memory. Used for Manual passing and con...
LLU::TensorInterface
Abstract class that defines a basic set of operations on a tensor.
Definition: Interfaces.h:157
LLU::MContainer< MArgumentType::Tensor >::getRank
mint getRank() const override
Get rank.
Definition: Generic/Tensor.hpp:51
Base.hpp
Definitions of MContainerBase and MContainer class templates.
LLU::MContainer< MArgumentType::Tensor >::clone
MContainer clone() const
Clone this MContainer, performs a deep copy of the underlying MTensor.
Definition: Generic/Tensor.hpp:46
LLU::MArgumentType
MArgumentType
Strongly type enum with possible types of data stored in MArgument.
Definition: MArgument.h:22
LLU::MContainer< MArgumentType::Tensor >
MContainer specialization for MTensor.
Definition: Generic/Tensor.hpp:24
LLU::MContainer< MArgumentType::Tensor >::MContainer
MContainer()=default
Default constructor, the MContainer does not manage any instance of MTensor.
Interfaces.h
LLU::Argument::Typed::Tensor
MContainer< MArgumentType::Tensor > Tensor
Tensor stands for a GenericTensor - type agnostic wrapper over MTensor.
Definition: TypedMArgument.h:47
LLU::MContainer< MArgumentType::Tensor >::getDimensions
mint const * getDimensions() const override
Get dimensions.
Definition: Generic/Tensor.hpp:56
LLU::MContainer< MArgumentType::Tensor >::getFlattenedLength
mint getFlattenedLength() const override
Get total length.
Definition: Generic/Tensor.hpp:61