 |
LibraryLink Utilities
3.0.1
Modern C++ wrapper over LibraryLink and WSTP
|
Go to the documentation of this file.
6 #ifndef LLU_CONTAINERS_VIEWS_TENSOR_HPP
7 #define LLU_CONTAINERS_VIEWS_TENSOR_HPP
63 default:
return nullptr;
72 class TensorTypedView :
public TensorView,
public IterableContainer<T> {
74 TensorTypedView() =
default;
81 TensorTypedView(
const GenericTensor& gTen) : TensorView(gTen) {
82 if (TensorType<T> != type()) {
92 TensorTypedView(TensorView tv) : TensorView(std::move(tv)) {
93 if (TensorType<T> !=
type()) {
103 TensorTypedView(MTensor mt) : TensorView(mt) {
104 if (TensorType<T> !=
type()) {
110 T* getData() const noexcept
override {
111 return static_cast<T*
>(
rawData());
114 mint getSize() const noexcept
override {
127 template<
typename TensorT,
typename F>
130 case MType_Integer:
return std::forward<F>(callable)(TensorTypedView<mint> {std::forward<TensorT>(t)});
131 case MType_Real:
return std::forward<F>(callable)(TensorTypedView<double> {std::forward<TensorT>(t)});
132 case MType_Complex:
return std::forward<F>(callable)(TensorTypedView<std::complex<double>> {std::forward<TensorT>(t)});
141 return asTypedTensor(TensorView {t}, std::forward<F>(callable));
146 #endif // LLU_CONTAINERS_VIEWS_TENSOR_HPP
mint getFlattenedLength() const override
Get total length.
Definition: Views/Tensor.hpp:48
Main namespace of LibraryLink Utilities.
Definition: Queue.h:13
mint const * getDimensions() const override
Get dimensions.
Definition: Views/Tensor.hpp:43
static WolframLibraryData API()
Get currently owned WolframLibraryData, if any.
Definition: LibraryData.cpp:22
TensorView(const GenericTensor &gTen)
Create a NumericArrayView from a GenericNumericArray.
Definition: Views/Tensor.hpp:29
mint getRank() const override
Get rank.
Definition: Views/Tensor.hpp:38
TensorView(MTensor mt)
Create a NumericArrayView from a raw MNumericArray.
Definition: Views/Tensor.hpp:35
MContainer< MArgumentType::Tensor > GenericTensor
MContainer specialization for MTensor is called GenericTensor.
Definition: Generic/Tensor.hpp:18
GenericTensor definition and implementation.
Abstract class that defines a basic set of operations on a tensor.
Definition: Interfaces.h:157
Container getContainer() const noexcept
Get internal container.
Definition: Base.hpp:97
const std::string TensorTypeError
Tensor type mismatch.
auto asTypedTensor(TensorT &&t, F &&callable)
Take a Tensor-like object t and a function callable and call the function with a TensorTypedView crea...
Definition: Views/Tensor.hpp:128
static void throwException(const std::string &errorName, T &&... args)
Throw exception with given name.
Definition: ErrorManager.h:199
void * rawData() const override
Get raw pointer to the data of this tensor.
Definition: Views/Tensor.hpp:58
MContainer specialization for MTensor.
Definition: Generic/Tensor.hpp:24
Simple, light-weight, non-owning wrappper over MTensor.
Definition: Views/Tensor.hpp:21
mint type() const final
Get the data type of this tensor.
Definition: Views/Tensor.hpp:53
Implementation of the IterableContainer class.