PP's Ndarray
Loading...
Searching...
No Matches
pp::Range Struct Reference

Class for slicing index. More...

#include <ndarray-11.hpp>

Public Member Functions

 Range ()
 Slicing constructor.
 
 Range (const std::string &str)
 
 Range (int start, int stop, int step, bool has_stop=true)
 

Static Public Member Functions

static Range parseRange (const std::string &str)
 

Public Attributes

int start
 
int stop
 
int step
 
bool has_stop
 Flag to check if stop is given.
 

Detailed Description

Class for slicing index.

Constructor & Destructor Documentation

◆ Range()

pp::Range::Range ( )
inline

Slicing constructor.

Parameters
str

Example

#include "ndarray-11.hpp"
int main() {
{
{0, 1, 2},
{3, 4, 5}
},
{
{6, 7, 8},
{9,10,11}
},
};
// start at 1, end to 1, step 1
pp::Range s1("0:1");
auto result1 = array.slice(s1);
// start <= i < end
// pp::Ndarray<int[3]> result1 = {
// {
// {0, 1, 2},
// {3, 4, 5}
// }
// };
pp::Range s2("1:"); // start at 1, to the end, step 1
pp::Range s3("::2"); // start at 0, to the end, step 2
pp::Range s4(":2"); // start at 0, end to 2, step 1
// Equivalent to `pp::Range(0, 1, 2, false)`
pp::Range s5("0:1:2"); // start at 0, end to 1, step 2
// 2D Slicing
auto result2 = array["0:1, 1:"];
// pp::Ndarray<int[3]> result2 = {
// {
// {3, 4, 5}
// }
// };
// 3D Slicing
// Equivalent to array.slice(s1, s2, s3)
auto result3 = array.slice["0:1, 1:, ::2"];
// pp::Ndarray<int[3]> result3 = {
// {
// {3, 5}
// }
// };
}
A simple multi-dimensional array implementation in C++11.
An interface to create Ndarray.
Definition ndarray-11.hpp:375
Class for slicing index.
Definition ndarray-11.hpp:57

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