-
Notifications
You must be signed in to change notification settings - Fork 5
Slice and Subtensor Examples
This wiki contains examples for both the slice and the subtensor as they both are interlinked with each other. This will describe how to construct and use them.
CAUTION
All the example which has an extent in their comments are the values after transforming them e.g
// original value (start: -6, end: -1, step: 1)
// after transformation ( start: extent - 6, end: extent - 1, step: 1 )
auto s1 = span::slice<-6,-1>{};
This kind of slice will get a single element from a given extent. The result will be having an equal start and end value and step of 1 as the default value;
using namespace boost::numeric::ublas;
auto s1 = span::slice<3>{};
auto s2 = span::slice<-3>{};
auto s3 = span::slice<>{3};
auto s4 = span::slice<>{-3};
This kind of slice will get elements in a given range and step is set to 1 as default.
using namespace boost::numeric::ublas;
// dynamic slice ( start: 0, end: 10, step: 1 )
auto s1 = span::slice<>{0,10};
// static slice ( start: 0, end: 10, step: 1 )
auto s2 = span::slice<0,10>{};
// dynamic slice ( start: 1, end: ( extent - 2 ), step: 1 )
auto s3 = span::slice<>{1,-2};
// static slice ( start: 1, end: ( extent - 2 ), step: 1 )
auto s4 = span::slice<1,-2>{};
// dynamic slice ( start: ( extent - 2 ), end: ( extent - 1 ), step: 1 )
auto s5 = span::slice<>{-2,-1};
// dynamic slice ( start: ( extent - 2 ), end: ( extent - 1 ), step: 1 )
auto s6 = span::slice<-2,-1>{};
This kind of slice will get elements in a given range and step is set to 1 as default.
using namespace boost::numeric::ublas;
// dynamic slice ( start: 0, end: 10, step: 4 )
auto s1 = span::slice<>{0,10, 4};
// static slice ( start: 0, end: 10, step: 4 )
auto s2 = span::slice<0,10,4>{};
// dynamic slice ( start: 1, end: ( extent - 2 ), step: 3 )
auto s3 = span::slice<>{1,-2, 3};
// static slice ( start: 1, end: ( extent - 2 ), step: 3 )
auto s4 = span::slice<1,-2,3>{};
// dynamic slice ( start: ( extent - 2 ), end: ( extent - 1 ), step: 1 )
auto s5 = span::slice<>{-2,-1,1};
// dynamic slice ( start: ( extent - 2 ), end: ( extent - 1 ), step: 1 )
auto s6 = span::slice<-2,-1,1>{};
First of all, there was an ambiguity which I needed to make a decision on which was, should basic_slice<ptrdiff_t>
or slice<>
be static slice or dynamic slice and I chose it to be dynamic as most of the dynamic slice be of this form. So when we create slice<>
, it will be treated as the dynamic slice.
using namespace boost::numeric::ublas;
// dynamic slice ( start: 0, end: 0, step: 1 )
auto s1 = span::slice<>{};
using namespace boost::numeric::ublas;
auto t1 = tensor{static_extents<10,10>{},1.f};
auto t2 = tensor{static_extents<10,10>{},1.f};
// static subtensor
auto s1 = subtensor<decltype(t1),span::slice<0,5>,span::slice<4>>{ t1 };
// dynamic subtensor
auto s2 = subtensor{ t1, ,span::slice<>{0,5},span::slice<>{4} };
using namespace boost::numeric::ublas;
auto t1 = tensor{static_extents<10,10>{},1.f};
auto t2 = tensor{static_extents<10,10>{},1.f};
// static subtensor
// here span::slice<>{} considered as static slice
auto s1 = t1(span::slice<2,3>{}, span::slice<>{});
// dynamic subtensor
auto s2 = t1(span::slice<>{2,3}, span::slice<>{});
// dynamic subtensor
auto s3 = t2(span::slice<>{2,3}, span::slice<>{});
We both would like to thank our mentor Cem for his constant support and help in achieving our goals. We always find him helpful and he was always easy to reach for help or discussion regarding the work. We would also like to thank Google for the Google Summer of Code Programme, without which all these wouldn't be possible. Lastly, we express our gratitude to our parents for helping and providing us with all the indirect or direct needs for carrying out our work nicely in our homes.
- Home
- Project Proposal
- Milestones and Tasks
- Implementation
- Documentation
- Discussions
- Examples
- Experimental features
- Project Proposal
- Milestones and Tasks
- Implementation
- Documentation
- Discussions
- Example Code