asgn
 
Loading...
Searching...
No Matches
dcnnsol::tensor_class< E, TL > Class Template Reference

A tensor - a multi-dimensional tagged generalization of vector/matrix. More...

#include <tagged.hpp>

Public Types

using view_type = extract_tensor_view< E, TL ...>
 
using const_view_type = extract_tensor_view< const E, TL ...>
 

Public Member Functions

template<tag ... TL2>
requires (sizeof...(TL2) == sizeof...(TL))
 tensor_class (const range_class< TL2 ... > &rng)
 Initialize the tensor_class to a size defined by a range_class.
 
template<tag ... TL2>
requires (sizeof...(TL2) == sizeof...(TL))
 tensor_class (const range_class< TL2 ... > &rng, const E &e) noexcept
 Initialize the tensor_class to a size defined by a range_class.
 
view_type view ()
 Return tensor_view acting as a reference to the complete tensor_class.
 
const_view_type view () const
 Return tensor_view acting as a const reference to the complete tensor_class.
 
template<tag ... TL2>
requires (sizeof...(TL2) < sizeof...(TL)) && impl::subset_selector< tag_list< TL2...>, tag_list< TL...>>
auto operator[] (const index_class< TL2 ... > &i)
 Extract a reference to a sub-space of this tensor.
 
template<tag ... TL2>
requires (sizeof...(TL2) < sizeof...(TL)) && impl::subset_selector< tag_list< TL2...>, tag_list< TL...>>
auto operator[] (const index_class< TL2 ... > &i) const
 Extract an immutable reference to a sub-space of this tensor.
 
template<tag ... TL2>
requires (sizeof...(TL2) == sizeof...(TL)) && impl::subset_selector< tag_list< TL2...>, tag_list< TL...>>
E & operator[] (const index_class< TL2... > &i)
 Access an element of this tensor.
 
template<tag ... TL2>
requires (sizeof...(TL2) == sizeof...(TL)) && impl::subset_selector< tag_list< TL2...>, tag_list< TL...>>
const E & operator[] (const index_class< TL2... > &i) const
 Read an element of this tensor.
 
const range_class< TL ... > & range () const
 The range corresponding to this tensor.
 
E * data ()
 A pointer to the beginning of the array containing the data.
 
const E * data () const
 A const pointer to the beginning of the array containing the data.
 
E * flat_data ()
 A pointer to the beginning of the array containing the data.
 
const E * flat_data () const
 A const pointer to the beginning of the array containing the data.
 

Detailed Description

template<typename E, tag ... TL>
class dcnnsol::tensor_class< E, TL >

A tensor - a multi-dimensional tagged generalization of vector/matrix.

The order of tags in the template argument list defines the layout. The right-most tag becomes the inner-most dimension (with contiguously stored elements).

The tensor contains precomputed multipliers for each dimension so that indexing in each dimension works in constant time.

Optimization: If K rightmost tags have statically defined range, the multipliers of the righmost (K+1) dimensions are precomputed statically and not stored as run-time data inside the class. The same precomputation is applied in every tensor_view referencing this tensor_class.

Template Parameters
EElement type
...TLTag list

Constructor & Destructor Documentation

◆ tensor_class() [1/2]

template<typename E, tag ... TL>
template<tag ... TL2>
requires (sizeof...(TL2) == sizeof...(TL))
tagged::tensor_class< E, TL >::tensor_class ( const range_class< TL2 ... > & rng)
inlineexplicit

Initialize the tensor_class to a size defined by a range_class.

Template Parameters
...TL2Tag list
Parameters
rngMulti-tagged range

◆ tensor_class() [2/2]

template<typename E, tag ... TL>
template<tag ... TL2>
requires (sizeof...(TL2) == sizeof...(TL))
tagged::tensor_class< E, TL >::tensor_class ( const range_class< TL2 ... > & rng,
const E & e )
inlinenoexcept

Initialize the tensor_class to a size defined by a range_class.

Template Parameters
...TL2Tag list
Parameters
rngMulti-tagged range
eInitial values for all elements

Member Function Documentation

◆ data() [1/2]

template<typename E, tag ... TL>
E * tagged::tensor_class< E, TL >::data ( )
inline

A pointer to the beginning of the array containing the data.

Available only if the tensor_view is single-dimensional

Returns
A modifiable pointer to the underlying contiguous data array

◆ data() [2/2]

template<typename E, tag ... TL>
const E * tagged::tensor_class< E, TL >::data ( ) const
inline

A const pointer to the beginning of the array containing the data.

Available only if the tensor_view is single-dimensional

Returns
A const pointer to the underlying contiguous data array

◆ flat_data() [1/2]

template<typename E, tag ... TL>
E * tagged::tensor_class< E, TL >::flat_data ( )
inline

A pointer to the beginning of the array containing the data.

It is the responsibility of the user to properly analyze the layout of the data

Returns
A modifiable pointer to the underlying single-dimensional data array

◆ flat_data() [2/2]

template<typename E, tag ... TL>
const E * tagged::tensor_class< E, TL >::flat_data ( ) const
inline

A const pointer to the beginning of the array containing the data.

It is the responsibility of the user to properly analyze the layout of the data

Returns
A const pointer to the underlying single-dimensional data array

◆ operator[]() [1/4]

template<typename E, tag ... TL>
template<tag ... TL2>
requires (sizeof...(TL2) < sizeof...(TL)) && impl::subset_selector< tag_list< TL2...>, tag_list< TL...>>
auto tagged::tensor_class< E, TL >::operator[] ( const index_class< TL2 ... > & i)
inline

Extract a reference to a sub-space of this tensor.

The new sub-space is defined by fixing one or more indexes defined by the tagged (multi-dimensional) index argument to the operator

Template Parameters
...TL2Tag list
Parameters
iA (multi-)tagged index
Returns
A tensor_view

◆ operator[]() [2/4]

template<typename E, tag ... TL>
template<tag ... TL2>
requires (sizeof...(TL2) < sizeof...(TL)) && impl::subset_selector< tag_list< TL2...>, tag_list< TL...>>
auto tagged::tensor_class< E, TL >::operator[] ( const index_class< TL2 ... > & i) const
inline

Extract an immutable reference to a sub-space of this tensor.

The new sub-space is defined by fixing one or more indexes defined by the tagged (multi-dimensional) index argument to the operator

Template Parameters
...TL2Tag list
Parameters
iA (multi-)tagged index
Returns
An immutable tensor_view

◆ operator[]() [3/4]

template<typename E, tag ... TL>
template<tag ... TL2>
requires (sizeof...(TL2) == sizeof...(TL)) && impl::subset_selector< tag_list< TL2...>, tag_list< TL...>>
E & tagged::tensor_class< E, TL >::operator[] ( const index_class< TL2... > & i)
inline

Access an element of this tensor.

Template Parameters
...TL2Tag list
Parameters
iA (multi-)tagged index covering (in any order) all the dimensions of this tensor
Returns
A modifiable reference to the element

◆ operator[]() [4/4]

template<typename E, tag ... TL>
template<tag ... TL2>
requires (sizeof...(TL2) == sizeof...(TL)) && impl::subset_selector< tag_list< TL2...>, tag_list< TL...>>
const E & tagged::tensor_class< E, TL >::operator[] ( const index_class< TL2... > & i) const
inline

Read an element of this tensor.

Template Parameters
...TL2Tag list
Parameters
iA (multi-)tagged index covering (in any order) all the dimensions of this tensor
Returns
A const reference to the element

◆ range()

template<typename E, tag ... TL>
const range_class< TL ... > & tagged::tensor_class< E, TL >::range ( ) const
inline

The range corresponding to this tensor.

Returns

◆ view() [1/2]

template<typename E, tag ... TL>
view_type tagged::tensor_class< E, TL >::view ( )
inline

Return tensor_view acting as a reference to the complete tensor_class.

Returns
A tensor_view

◆ view() [2/2]

template<typename E, tag ... TL>
const_view_type tagged::tensor_class< E, TL >::view ( ) const
inline

Return tensor_view acting as a const reference to the complete tensor_class.

Returns
A tensor_view

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