-
Notifications
You must be signed in to change notification settings - Fork 24
Ranges
ikaros-project edited this page Aug 2, 2024
·
1 revision
Ranges are used to iterate over indices in one or several dimensions. Ranges are used in connections in ikaros to describe which part of a matrix is copied, but ranges can also be used directly in code.
range(n) // range of a single value nrange(n,m) // range from n to m-1range(n,m,i) // range from n to m-1 with step irange(n,m,-i) // range from n to m-1 with step i in reverse orderRange over several dimensions
range r;
r.push(0, 5); // first dimension goes from 0 to 4
r.push(2, 4); // second dimension goes from 2 to 3Loop over a range in one or several dimensions:
for(; r.more(); r++)
std::cout << r << std::endl;Print a range in bracket style by converting to a string:
std::cout << std::string(r) << std::endl; // will print [0:5][2:4]Set a range from a string:
range r("[0:5][2:4:-1]");This looks like ranges in Python but the semantics is different. The first value should always be the lower number even for a negative increment. A negative increment will generate exactly the same numbers as a positive but in reverse order.
Examples:
range r(0,16,7); // generates 0, 7, 14
range r(0,16,-7); // generates 14, 7, 0Print numbers 0 to 4.
for(range r=range(0,5);r.more();r++)
std::cout << r << std::endl;More information can be found at the project web site: ikaros-project.