 |
LibraryLink Utilities
3.0.1
Modern C++ wrapper over LibraryLink and WSTP
|
Go to the documentation of this file.
9 #ifndef LLU_CONTAINERS_TENSOR_H_
10 #define LLU_CONTAINERS_TENSOR_H_
12 #include <initializer_list>
13 #include <type_traits>
37 T* getData()
const noexcept
override;
40 virtual MTensor getInternal()
const = 0;
69 template<
class Container,
typename = std::enable_if_t<is_iterable_container_with_matching_type_v<Container, T> && has_size_v<Container>>>
78 template<
class Container,
typename = std::enable_if_t<is_iterable_container_with_matching_type_v<Container, T>>>
91 template<
class InputIt,
typename = enable_if_input_iterator<InputIt>>
109 template<
class InputIt,
typename = enable_if_input_iterator<InputIt>>
144 MTensor getInternal() const noexcept
override {
153 template<
class InputIt,
typename>
159 std::fill(this->
begin(), this->
end(), init);
163 template<
class InputIt,
typename>
169 std::copy(first, last, this->
begin());
174 if (TensorType<T> != GenericBase::type()) {
Tensor(T init, MArrayDimensions dims)
Constructs the Tensor of given shape with all elements initialized to given value.
Definition: Tensor.h:157
Typed interface for Tensor.
Definition: Tensor.h:29
Main namespace of LibraryLink Utilities.
Definition: Queue.h:13
constexpr mint TensorType
Utility structure that matches a C++ type with a corresponding MTensor data type.
Definition: Utilities.hpp:295
const std::string TensorNewError
creating new MTensor failed
Tensor(const Container &c, MArrayDimensions dims)
Constructs a Tensor with contents copied from a given collection of data and dimensions passed as par...
Definition: Tensor.h:79
Tensor clone() const
Clone this Tensor, performing a deep copy of the underlying MTensor.
Definition: Tensor.h:137
Helper class that carries meta-information about container's size and dimensions.
Definition: MArrayDimensions.h:23
Argument::CType< Type > Container
The type of underlying LibraryLink structure (e.g. MTensor, MImage, etc.) will be called "Container".
Definition: Base.hpp:38
This is a class template, where template parameter T is the type of data elements....
Definition: MArray.hpp:36
This is a class template, where template parameter T is the type of data elements....
Definition: Tensor.h:53
Tensor(MTensor t, Ownership owner)
Constructs Tensor based on MTensor.
Definition: Tensor.h:180
GenericTensor definition and implementation.
@ Library
The library (LLU) is responsible for managing the container's memory. Used for Manual passing and con...
Template base class for C++ wrappers of LibraryLink containers.
Container getContainer() const noexcept
Get internal container.
Definition: Base.hpp:97
Container cloneContainer() const
Clone the raw container, if it's present.
Definition: Base.hpp:150
const std::string TensorTypeError
Tensor type mismatch.
Tensor()=default
Default constructor, creates a Tensor that does not wrap over any raw MTensor.
mint getRank() const override
Get rank.
Definition: Generic/Tensor.hpp:51
static void throwException(const std::string &errorName, T &&... args)
Throw exception with given name.
Definition: ErrorManager.h:199
Tensor(GenericTensor t)
Create new Tensor from a GenericTensor.
Definition: Tensor.h:173
Tensor(InputIt first, InputIt last, MArrayDimensions dims)
Constructs the Tensor of given shape with elements from range [first, last)
Definition: Tensor.h:164
MContainer specialization for MTensor.
Definition: Generic/Tensor.hpp:24
iterator begin() noexcept
Get iterator at the beginning of underlying data.
Definition: IterableContainer.hpp:71
Tensor(InputIt first, InputIt last)
Constructs flat Tensor with elements from range [first, last)
Definition: Tensor.h:154
mint const * getDimensions() const override
Get dimensions.
Definition: Generic/Tensor.hpp:56
mint getFlattenedLength() const override
Get total length.
Definition: Generic/Tensor.hpp:61
Ownership
An enum listing possible owners of a LibraryLink container.
Definition: Base.hpp:22
Short but generally useful functions.
Tensor(const Container &c)
Constructs flat Tensor with contents copied from a given collection of data.
Definition: Tensor.h:70
iterator end() noexcept
Get iterator after the end of underlying data.
Definition: IterableContainer.hpp:92
Tensor(std::initializer_list< T > v)
Constructs flat Tensor based on a list of elements.
Definition: Tensor.h:150