Skip to content

Span Docs

Kannav Mehta edited this page Aug 20, 2021 · 2 revisions

Introduction

A span object is used to specify how to span extents. You can specify where to start the slicing, and where to end.. This way you can define the span of range in a single dimension you want to include in you subtensor.

span

I took the span implementation from Cem Bassoy's previous implementation of span and changed I few things. Firstly I did away with two different types of spans and made one cohesive span for simple subtensors(sliced or strided). Initially I also created a concept of span with negative stirides similar to Amit's work. But after discussing with Cem, we decided to drop the idea.

So finally there are following ways to create span types.

  • span() => span(0,1,max) (all)
  • span(val) => span(val,1,val)
  • span(first, last) => span(first,1,last)
  • span(first, last, step)

Current span vs Old span

  1. I have combined both stridden and sliced span as the previous one used the tag to identify them.

  2. Changed the evaluation criteria for spans. Spans are clipped before they are evaluated when they are used to create a subtensor.

  3. Made size a function rather than a part of the span class.

  4. Removed concept of ran function

Examples

using namespace boost::numeric::ublas;

// span with no arguments ( start: 0, last: max, step: 1 )
auto s1 = span{};

// span with one argument (start: 4, last: 4, step: 1)
auto s2 = span{4};

// span with two arguments (start: 0, last: 10, step: 1)
auto s3 = span{0,10};

// span with three arguments ( start: 0, last: 10, step: 4 )
auto s4 = span{0, 4, 10};