Speclib  0.1.2
The library for writing better CUDA libraries
sp::StaticTensor< T, Dims > Class Template Reference

A Tensor that has constexpr dimensions. More...

#include <StaticTensor.hpp>

Inheritance diagram for sp::StaticTensor< T, Dims >:
[legend]

Public Types

using ValueType = sp::remove_cvref_t< T >
 
using ThisType = StaticTensor< T, Dims... >
 
using Opts = sp::MostAggressiveTensorOptions
 
template<typename NewT >
using InValueType = StaticTensor< NewT, Dims... >
 
using VType = typename StorageType< T, Dims... >::type
 

Public Member Functions

constexpr StaticTensor (const VType &&values)
 Construct directly from values. More...
 
template<typename Q , int... OtherDims>
constexpr bool operator== (const StaticTensor< Q, OtherDims... > &other) const
 Comparison operators. More...
 
template<typename Q , int... OtherDims>
constexpr bool operator!= (const StaticTensor< Q, OtherDims... > &other) const
 
constexpr ThisType operator- () const
 
template<typename Q >
constexpr auto & operator= (const Q &value)
 Scalar-fill operator. More...
 
constexpr auto & operator[] (int offset) const
 
constexpr auto & operator[] (int offset)
 
constexpr void hFlip ()
 Invert the matrix horizontally. More...
 
constexpr void vFlip ()
 Invert the matrix vertically. More...
 
template<int I, int J, typename F >
constexpr void map (const F &f)
 Apply an element-wise operation using a templated loop, to guarantee unrolling. More...
 
constexpr auto transpose () const
 Get the transpose of this matrix. More...
 
constexpr auto rowVec (int targetRow) const
 Get the I'th row. TODO: Implement submatrix views, so assignment can work nicely. More...
 
constexpr sp::Vec< T, DimsVec[0]> colVec (int targetCol) const
 Get a copy of the I'th column, as a Vec. More...
 
template<int Dummy = 0>
constexpr auto row (int targetRow)
 Get a TensorLike representing the requested row. More...
 
template<int Dummy = 0>
constexpr auto col (int targetCol)
 Get a TensorLike representing the requested column. More...
 
constexpr T * ptr (const sp::Vec< int, Rank > &d)
 
constexpr T * ptr (const sp::Vec< int, Rank > &d) const
 
- Public Member Functions inherited from sp::TensorLike< StaticTensor< T, Dims... >, sizeof...(Dims)>
auto dims () const
 
bool boundsCheck (const Vec< int, Rank > &pos) const
 
auto vectorRead (const Vec< int, Rank > &pos) const
 
auto vectorOffsetRead (const Vec< int, Rank > &base, const Vec< int, Rank > &offset) const
 
auto maskedVectorRead (const Vec< int, Rank > &pos) const
 
void vectorWrite (const Vec< int, Rank > &pos, const Vec< T, L > &values)
 
void maskedVectorWrite (const Vec< int, Rank > &pos, const Vec< T, L > &values)
 
int sizeQuantisation () const
 
int totalSize () const
 Get the total memory occupied by the Tensor, in terms of elements. More...
 
auto getView (const sp::Vec< int, Rank > &start, const sp::Vec< int, Rank > &size)
 Get an object that represents (and aliases) a portion of this object. More...
 
int dim (int d) const
 Behaviour common to all TensorLikes ///. More...
 
auto read (const Vec< int, Rank > &pos) const
 Get the element at a given position. More...
 
void write (const Vec< int, Rank > &pos, const T &value)
 Set a single element. More...
 
int size () const
 
void boundsCheckAccess (Vec< int, Rank > pos) const
 Bounds-check an L-element vector read at pos. More...
 

Public Attributes

VType values
 

Static Public Attributes

constexpr static int Rank = Base::Rank
 
constexpr static sp::Vec< int, Rank > DimsVec {Dims...}
 
constexpr static int LastDim = DimsVec[Rank - 1]
 
- Static Public Attributes inherited from sp::TensorLike< StaticTensor< T, Dims... >, sizeof...(Dims)>
constexpr static int Rank
 

Protected Member Functions

constexpr auto dimsImpl () const
 
template<int L, CacheMode Mode>
constexpr sp::Vec< T, L > vectorReadImpl (const Vec< int, Rank > &pos) const
 
template<int L, CacheMode Mode, typename Q >
constexpr void vectorWriteImpl (const Vec< int, Rank > &pos, const Vec< Q, L > &inValues)
 
- Protected Member Functions inherited from sp::TensorLike< StaticTensor< T, Dims... >, sizeof...(Dims)>
auto dimsImpl () const
 Get an sp::Vec<int, X> representing the dimensions of the object. More...
 
bool boundsCheckImpl (const sp::Vec< int, Rank > &) const
 Return true iff the given coordinates are inside the object (Default implementation below) More...
 
int sizeQuantisationImpl () const
 The last dimension is rounded up to the next multiple of this value for the purposes of bounds checks. More...
 
auto vectorReadImpl (const Vec< int, Rank > &) const
 Read L elements, adjacent in the last dimension, starting at the given position. More...
 
auto vectorOffsetReadImpl (const Vec< int, Rank > &base, const Vec< int, Rank > &offset) const
 Read L elements, adjacent in the last dimension, from position base + offset. More...
 
auto maskedVectorReadImpl (const Vec< int, Rank > &pos) const
 Do a vectorRead that copes with the possibility of part of the vector being out of bounds. More...
 
void maskedVectorWriteImpl (const Vec< int, Rank > &pos, const Vec< T, L > &values)
 Do a vectorWrite that copes with the possibility of part of the vector being out of bounds. More...
 
void vectorWriteImpl (const Vec< int, Rank > &pos, const Vec< T, L > &values)
 Write L elements, adjacent in the last dimension, starting at the given position. More...
 
auto getViewImpl (const sp::Vec< int, Rank > &start, const sp::Vec< int, Rank > &size)
 The default implementation just makes a TensorView. Not hugely fast, but always works. More...
 

Detailed Description

template<typename T, int... Dims>
class sp::StaticTensor< T, Dims >

A Tensor that has constexpr dimensions.

This allows it to exist on the stack, in registers, or even be used in constexpr contexts.

Constructor & Destructor Documentation

◆ StaticTensor()

template<typename T , int... Dims>
constexpr sp::StaticTensor< T, Dims >::StaticTensor ( const VType &&  values)
constexpr

Construct directly from values.

Member Function Documentation

◆ col()

template<typename T , int... Dims>
template<int Dummy = 0>
constexpr auto sp::StaticTensor< T, Dims >::col ( int  targetCol)
constexpr

Get a TensorLike representing the requested column.

◆ colVec()

template<typename T , int... Dims>
constexpr sp::Vec< T, DimsVec[0]> sp::StaticTensor< T, Dims >::colVec ( int  targetCol) const
constexpr

Get a copy of the I'th column, as a Vec.

◆ hFlip()

template<typename T , int... Dims>
constexpr void sp::StaticTensor< T, Dims >::hFlip ( )
constexpr

Invert the matrix horizontally.

◆ map()

template<typename T , int... Dims>
template<int I, int J, typename F >
constexpr void sp::StaticTensor< T, Dims >::map ( const F &  f)
constexpr

Apply an element-wise operation using a templated loop, to guarantee unrolling.

◆ operator=()

template<typename T , int... Dims>
template<typename Q >
constexpr auto & sp::StaticTensor< T, Dims >::operator= ( const Q &  value)
constexpr

Scalar-fill operator.

◆ operator==()

template<typename T , int... Dims>
template<typename Q , int... OtherDims>
constexpr bool sp::StaticTensor< T, Dims >::operator== ( const StaticTensor< Q, OtherDims... > &  other) const
constexpr

Comparison operators.

◆ row()

template<typename T , int... Dims>
template<int Dummy = 0>
constexpr auto sp::StaticTensor< T, Dims >::row ( int  targetRow)
constexpr

Get a TensorLike representing the requested row.

◆ rowVec()

template<typename T , int... Dims>
constexpr auto sp::StaticTensor< T, Dims >::rowVec ( int  targetRow) const
constexpr

Get the I'th row. TODO: Implement submatrix views, so assignment can work nicely.

◆ transpose()

template<typename T , int... Dims>
constexpr auto sp::StaticTensor< T, Dims >::transpose ( ) const
constexpr

Get the transpose of this matrix.

◆ vFlip()

template<typename T , int... Dims>
constexpr void sp::StaticTensor< T, Dims >::vFlip ( )
constexpr

Invert the matrix vertically.