TRIQS/nda 2.0.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
nda::tensor::tensor_view< T >

#include <nda/tensor/tools.hpp>

Detailed Description

template<typename T>
struct nda::tensor::tensor_view< T >

A type-erased, non-owning view of an nda::MemoryArray or a conjugate lazy expression.

It holds a pointer to the data, extents and strides of the viewed array or conjugate expression, as well as its rank and an element-wise unary operation to apply to each element (see nda::tensor::unary_op).

All pointers are non-owning and must remain valid for the lifetime of this object.

Template Parameters
TValue type of the tensor.

Definition at line 146 of file tools.hpp.

Public Types

using value_type = T
 Value type of the tensor (can be const).

Public Member Functions

 tensor_view ()=default
 Default constructor initializes an empty view.
template<BlasArrayOrConj A>
requires std::convertible_to<data_ptr_t<A>, T *>
 tensor_view (A &&a)
 Construct a tensor view from an nda::MemoryArray or a conjugate lazy expression.
template<BlasArray A>
requires std::convertible_to<data_ptr_t<A>, T *>
 tensor_view (A &&a, unary_op op)
 Construct a tensor view from an nda::MemoryArray and an nda::tensor::unary_op.
 tensor_view (T *p)
 Construct a rank-0 tensor view from a pointer to a scalar value.
template<typename U>
requires (!std::same_as<U, T> && std::convertible_to<U *, T *>)
 tensor_view (tensor_view< U > tv)
 Construct a tensor view from from another tensor view with a convertible value type.

Public Attributes

T * data = nullptr
 Pointer to the tensor data.
const long * extents = nullptr
 Pointer to the array of extents.
int ndim = 0
 Number of dimensions (rank) of the tensor.
unary_op op = unary_op::IDENTITY
 Element-wise unary operation to apply.
const long * strides = nullptr
 Pointer to the array of strides.

Constructor & Destructor Documentation

◆ tensor_view() [1/4]

template<typename T>
nda::tensor::tensor_view< T >::tensor_view ( T * p)
inline

Construct a rank-0 tensor view from a pointer to a scalar value.

This creates a tensor view with ndim == 0 and extents == strides == nullptr, viewing the scalar as a rank-0 tensor. The pointer must remain valid for the lifetime of this view.

Parameters
pPointer to the scalar value.

Definition at line 176 of file tools.hpp.

◆ tensor_view() [2/4]

template<typename T>
template<BlasArray A>
requires std::convertible_to<data_ptr_t<A>, T *>
nda::tensor::tensor_view< T >::tensor_view ( A && a,
unary_op op )
inline

Construct a tensor view from an nda::MemoryArray and an nda::tensor::unary_op.

The value type is deduced from the data pointer of the (underlying) array which can be const or non-const.

Template Parameters
Anda::blas_lapack::BlasArrayOrConj type.
Parameters
aArray or view to wrap.
opUnary operation to apply to each element.

Definition at line 190 of file tools.hpp.

◆ tensor_view() [3/4]

template<typename T>
template<BlasArrayOrConj A>
requires std::convertible_to<data_ptr_t<A>, T *>
nda::tensor::tensor_view< T >::tensor_view ( A && a)
inline

Construct a tensor view from an nda::MemoryArray or a conjugate lazy expression.

The value type is deduced from the data pointer of the (underlying) array which can be const or non-const.

Template Parameters
Anda::blas_lapack::BlasArrayOrConj type.
Parameters
aArray, view or conjugate expression to wrap.

Definition at line 208 of file tools.hpp.

◆ tensor_view() [4/4]

template<typename T>
template<typename U>
requires (!std::same_as<U, T> && std::convertible_to<U *, T *>)
nda::tensor::tensor_view< T >::tensor_view ( tensor_view< U > tv)
inline

Construct a tensor view from from another tensor view with a convertible value type.

This enables implicit conversion from tensor_view<T> to tensor_view<const T>, analogous to T* converting to const T*.

Template Parameters
UValue type of the source.
Parameters
tvSource tensor view.

Definition at line 221 of file tools.hpp.


The documentation for this struct was generated from the following file: