![]() |
LibraryLink Utilities
3.0.1
Modern C++ wrapper over LibraryLink and WSTP
|
This is a class template, where template parameter T is the type of data elements. Tensor is derived from MArray.
Tensor<> classes automate creation and deletion of MTensors. They are strongly typed (no void* to underlying memory) and almost all functions from <algorithms> can be used on Tensor.
| T | - type of underlying data |
Inheritance diagram for LLU::Tensor< T >:
Collaboration diagram for LLU::Tensor< T >:#include <Tensor.h>
Public Types | |
| using | value_type = T |
| Type of elements stored. More... | |
| using | iterator = value_type * |
| Iterator type. More... | |
| using | const_iterator = const value_type * |
| Constant iterator type. More... | |
| using | reverse_iterator = std::reverse_iterator< iterator > |
| Reverse iterator type. More... | |
| using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
| Constant reverse iterator type. More... | |
| using | reference = value_type & |
| Reference type. More... | |
| using | const_reference = const value_type & |
| Constant reference type. More... | |
| using | Container = Argument::CType< Type > |
| The type of underlying LibraryLink structure (e.g. MTensor, MImage, etc.) will be called "Container". More... | |
Public Member Functions | |
| Tensor (std::initializer_list< T > v) | |
| Constructs flat Tensor based on a list of elements. More... | |
| template<class Container , typename = std::enable_if_t<is_iterable_container_with_matching_type_v<Container, T> && has_size_v<Container>>> | |
| Tensor (const Container &c) | |
| Constructs flat Tensor with contents copied from a given collection of data. More... | |
| template<class Container , typename = std::enable_if_t<is_iterable_container_with_matching_type_v<Container, T>>> | |
| Tensor (const Container &c, MArrayDimensions dims) | |
| Constructs a Tensor with contents copied from a given collection of data and dimensions passed as parameter. More... | |
| template<class InputIt , typename = enable_if_input_iterator<InputIt>> | |
| Tensor (InputIt first, InputIt last) | |
| Constructs flat Tensor with elements from range [first, last) More... | |
| Tensor (T init, MArrayDimensions dims) | |
| Constructs the Tensor of given shape with all elements initialized to given value. More... | |
| template<class InputIt , typename = enable_if_input_iterator<InputIt>> | |
| Tensor (InputIt first, InputIt last, MArrayDimensions dims) | |
| Constructs the Tensor of given shape with elements from range [first, last) More... | |
| Tensor (MTensor t, Ownership owner) | |
| Constructs Tensor based on MTensor. More... | |
| Tensor (GenericTensor t) | |
| Create new Tensor from a GenericTensor. More... | |
| Tensor ()=default | |
| Default constructor, creates a Tensor that does not wrap over any raw MTensor. More... | |
| Tensor | clone () const |
| Clone this Tensor, performing a deep copy of the underlying MTensor. More... | |
| mint | rank () const noexcept |
| Get container rank. More... | |
| bool | empty () const noexcept |
| Check whether container is empty. More... | |
| mint | dimension (mint index) const |
Get dimension value at position index. More... | |
| const MArrayDimensions & | dimensions () const |
| Get a const reference to dimensions object. More... | |
| T & | operator[] (const std::vector< mint > &indices) |
| Get a reference to the data element at given position in a multidimensional container. More... | |
| const T & | operator[] (const std::vector< mint > &indices) const |
| Get a constant reference to the data element at given position in a multidimensional container. More... | |
| reference | operator[] (mint index) |
| Get a reference to the data element at given position. More... | |
| const_reference | operator[] (mint index) const |
| Get a constant reference to the data element at given position. More... | |
| T & | at (mint index) |
| Get a reference to the data element at given position with bound checking. More... | |
| const T & | at (mint index) const |
| Get a constant reference to the data element at given position with bound checking. More... | |
| T & | at (const std::vector< mint > &indices) |
| Get a reference to the data element at given position in a multidimensional container. More... | |
| const T & | at (const std::vector< mint > &indices) const |
| Get a constant reference to the data element at given position in a multidimensional container. More... | |
| value_type * | data () noexcept |
| Get raw pointer to underlying data. More... | |
| const value_type * | data () const noexcept |
| Get raw pointer to const underlying data. More... | |
| mint | size () const noexcept |
| Get total number of elements in the container. More... | |
| iterator | begin () noexcept |
| Get iterator at the beginning of underlying data. More... | |
| const_iterator | begin () const noexcept |
| Get constant iterator at the beginning of underlying data. More... | |
| const_iterator | cbegin () const noexcept |
| Get constant iterator at the beginning of underlying data. More... | |
| iterator | end () noexcept |
| Get iterator after the end of underlying data. More... | |
| const_iterator | end () const noexcept |
| Get constant iterator after the end of underlying data. More... | |
| const_iterator | cend () const noexcept |
| Get constant iterator after the end of underlying data. More... | |
| reverse_iterator | rbegin () noexcept |
| Get iterator at the beginning of underlying data. More... | |
| const_reverse_iterator | rbegin () const noexcept |
| Get constant iterator at the beginning of underlying data. More... | |
| const_reverse_iterator | crbegin () const noexcept |
| Get constant iterator at the beginning of underlying data. More... | |
| reverse_iterator | rend () noexcept |
| Get iterator after the end of underlying data. More... | |
| const_reverse_iterator | rend () const noexcept |
| Get constant iterator after the end of underlying data. More... | |
| const_reverse_iterator | crend () const noexcept |
| Get constant iterator after the end of underlying data. More... | |
| reference | front () |
| Get reference to the first element. More... | |
| const_reference | front () const |
| Get constant reference to the first element. More... | |
| reference | back () |
| Get reference to the last element. More... | |
| const_reference | back () const |
| Get constant reference to the last element. More... | |
| std::vector< value_type > | asVector () const |
| Copy contents of the data to a std::vector of matching type. More... | |
| mint | getRank () const override |
| Get rank. More... | |
| mint const * | getDimensions () const override |
| Get dimensions. More... | |
| mint | getFlattenedLength () const override |
| Get total length. More... | |
| mint | type () const override |
| Get the data type of this tensor. More... | |
| void * | rawData () const override |
| Get raw pointer to the data of this tensor. More... | |
| Container | getContainer () const noexcept |
| Get internal container. More... | |
| Container | abandonContainer () const noexcept |
| Give a handle to internal container and stop owning it. More... | |
| mint | shareCount () const noexcept |
| Return share count of internal container, if present and 0 otherwise. More... | |
| void | pass (MArgument &res) const |
| Pass the internal container as result of a LibraryLink function. More... | |
| Ownership | getOwner () const noexcept |
| Get ownership information. More... | |
Protected Member Functions | |
| Container | cloneContainer () const |
| Clone the raw container, if it's present. More... | |
| void | disown () const noexcept |
| Disown internal container if present. More... | |
| void | free () const noexcept |
| Free internal container if present. More... | |
| void | reset (Container newCont, Ownership newOwnerMode=Ownership::Library) noexcept |
| Set a new internal container safely disposing of the old one. More... | |
|
inherited |
Constant iterator type.
|
inherited |
Constant reference type.
|
inherited |
Constant reverse iterator type.
|
inherited |
The type of underlying LibraryLink structure (e.g. MTensor, MImage, etc.) will be called "Container".
|
inherited |
Iterator type.
|
inherited |
Reference type.
|
inherited |
Reverse iterator type.
|
inherited |
Type of elements stored.
| LLU::Tensor< T >::Tensor | ( | std::initializer_list< T > | v | ) |
|
inlineexplicit |
Constructs flat Tensor with contents copied from a given collection of data.
| Container | - any iterable (begin(), end()) collection of data that has a value_type alias member and a size() member function |
| c | - const reference to a collection from which data will be copied to the Tensor |
|
inline |
| LLU::Tensor< T >::Tensor | ( | InputIt | first, |
| InputIt | last | ||
| ) |
Constructs flat Tensor with elements from range [first, last)
| [in] | first | - iterator to the beginning of range |
| [in] | last | - iterator past the end of range |
| InputIt | - any iterator conforming to InputIterator concept |
| see | Tensor<T>::Tensor(InputIt, InputIt, std::initializer_list<mint>) |
| LLU::Tensor< T >::Tensor | ( | T | init, |
| MArrayDimensions | dims | ||
| ) |
Constructs the Tensor of given shape with all elements initialized to given value.
| [in] | init | - value of type T to initialize all elements of the Tensor |
| [in] | dims | - MArrayDimensions object with Tensor dimensions |
| LLU::Tensor< T >::Tensor | ( | InputIt | first, |
| InputIt | last, | ||
| MArrayDimensions | dims | ||
| ) |
Constructs the Tensor of given shape with elements from range [first, last)
| [in] | first | - iterator to the beginning of range |
| [in] | last | - iterator past the end of range |
| [in] | dims | - container with Tensor dimensions |
| InputIt | - any iterator conforming to InputIterator concept |
| ErrorName::TensorNewError | - if number of elements in v does not match total Tensor size indicated by dims |
| LLU::Tensor< T >::Tensor | ( | MTensor< T > | t, |
| Ownership | owner | ||
| ) |
Constructs Tensor based on MTensor.
| [in] | t | - LibraryLink structure to be wrapped |
| [in] | owner | - who manages the memory the raw MTensor |
| ErrorName::TensorTypeError | - if the Tensor template type T does not match the actual data type of the MTensor |
|
explicit |
|
default |
Default constructor, creates a Tensor that does not wrap over any raw MTensor.
|
inlinenoexceptinherited |
Give a handle to internal container and stop owning it.
Should be used with caution as it may potentially result with resource leak.
|
inlineinherited |
Copy contents of the data to a std::vector of matching type.
|
inherited |
Get a reference to the data element at given position in a multidimensional container.
| [in] | indices | - vector with coordinates of desired data element |
| indexError() | - if indices are out-of-bounds |
|
inherited |
Get a constant reference to the data element at given position in a multidimensional container.
| [in] | indices | - vector with coordinates of desired data element |
| indexError() | - if indices are out-of-bounds |
|
inherited |
Get a reference to the data element at given position with bound checking.
| [in] | index | - position of desired data element |
| indexError() | - if index is out-of-bounds |
|
inherited |
Get a constant reference to the data element at given position with bound checking.
| [in] | index | - position of desired data element |
| indexError() | - if index is out-of-bounds |
|
inlineinherited |
Get reference to the last element.
|
inlineinherited |
Get constant reference to the last element.
|
inlinenoexceptinherited |
Get constant iterator at the beginning of underlying data.
|
inlinenoexceptinherited |
Get iterator at the beginning of underlying data.
|
inlinenoexceptinherited |
Get constant iterator at the beginning of underlying data.
|
inlinenoexceptinherited |
Get constant iterator after the end of underlying data.
|
inline |
Clone this Tensor, performing a deep copy of the underlying MTensor.
|
inlineprotectedinherited |
Clone the raw container, if it's present.
|
inlinenoexceptinherited |
Get constant iterator at the beginning of underlying data.
|
inlinenoexceptinherited |
Get constant iterator after the end of underlying data.
|
inlinenoexceptinherited |
Get raw pointer to const underlying data.
|
inlinenoexceptinherited |
Get raw pointer to underlying data.
|
inlineinherited |
Get dimension value at position index.
|
inlineinherited |
Get a const reference to dimensions object.
|
inlineprotectednoexceptinherited |
Disown internal container if present.
|
inlinenoexceptinherited |
Check whether container is empty.
|
inlinenoexceptinherited |
Get constant iterator after the end of underlying data.
|
inlinenoexceptinherited |
Get iterator after the end of underlying data.
|
inlineprotectednoexceptinherited |
Free internal container if present.
|
inlineinherited |
Get reference to the first element.
|
inlineinherited |
Get constant reference to the first element.
|
inlinenoexceptinherited |
Get internal container.
|
inlineoverridevirtualinherited |
|
inlineoverridevirtualinherited |
Get total length.
Implements LLU::TensorInterface.
|
inlinenoexceptinherited |
Get ownership information.
|
inlineoverridevirtualinherited |
|
inlineinherited |
Get a reference to the data element at given position in a multidimensional container.
| [in] | indices | - vector with coordinates of desired data element |
|
inlineinherited |
Get a constant reference to the data element at given position in a multidimensional container.
| [in] | indices | - vector with coordinates of desired data element |
|
inlineinherited |
Get a reference to the data element at given position.
| [in] | index | - position of desired data element |
|
inlineinherited |
Get a constant reference to the data element at given position.
| [in] | index | - position of desired data element |
|
inlineinherited |
Pass the internal container as result of a LibraryLink function.
| res | - MArgument which will hold internal container of this MContainerBase |
|
inlinenoexceptinherited |
Get container rank.
|
overridevirtualinherited |
Get raw pointer to the data of this tensor.
Implements LLU::TensorInterface.
|
inlinenoexceptinherited |
Get constant iterator at the beginning of underlying data.
|
inlinenoexceptinherited |
Get iterator at the beginning of underlying data.
|
inlinenoexceptinherited |
Get constant iterator after the end of underlying data.
|
inlinenoexceptinherited |
Get iterator after the end of underlying data.
|
inlineprotectednoexceptinherited |
Set a new internal container safely disposing of the old one.
| newCont | - new internal container |
| newOwnerMode | - owner of the new container |
|
inlinenoexceptinherited |
Return share count of internal container, if present and 0 otherwise.
|
inlinenoexceptinherited |
Get total number of elements in the container.
|
inlineoverridevirtualinherited |
Get the data type of this tensor.
Implements LLU::TensorInterface.