Skip to content

Introduction to static strides and static extents for static Tensor

amitsingh19975 edited this page Jun 14, 2019 · 22 revisions

Abstract

Introduction to static strides and static extents is one step closer to making static Tensor which will make Tensor more efficient.

New To Tensor

  1. static_extents

It helps you to create extents at compile and runtime as you can create whole extents at compile time or create extents at runtime or mix of both but with compile time rank so you cannot change the rank afterwards if you want dynamic rank then choose basic_extents.

template<classT, ptrdiff_t R, ptrdiff_t ...E>
struct static_extents;

template<ptrdiff_t R, ptrdiff_t... E>
using shape; // selects if you want to use basic_extents or static_extents 
  1. static_strides

It helps you to create strides at compile using static_extents

template <class ExtentType, class Layout> 
struct static_strides;

template <class E, class Layout> 
struct stride_type; // selects if you want to use basic_strides or static_strides 

New tensor class

/**
* ....
* @tparam E type of basic_extents or static_extents defaulted to shape<dynamic_rank>
* ....
*/
template<class T, class E, class F, class A>
class tensor;

Examples

auto t1 = tensor<int>{}; // tensor with dynamic extents and dynamic strides
auto t2 = tensor<int,shape<4>>{1,2,3,4}; // tensor with static rank but dynamic extents and static_strides
auto t3 = tensor<int,shape<4,1,dynamic_extent,dynamic_extent,4>>{2,3}; // tensor with static rank, mix of dynamic extents and static extents and static strides
auto t3 = tensor<int,shape<4,1,2,3,4>>{}; // tensor with static_rank, static extents and static_strides
Clone this wiki locally