2013-08-22 16:55:51 +02:00
|
|
|
.. highlight:: c
|
|
|
|
|
|
|
|
.. _arr_range:
|
|
|
|
|
|
|
|
range
|
|
|
|
=========
|
|
|
|
|
2014-10-17 18:15:19 +02:00
|
|
|
`range` mimics the Python `range`. Arguments of the constructor can be:
|
2013-08-22 16:55:51 +02:00
|
|
|
|
2014-10-17 18:15:19 +02:00
|
|
|
* no argument: it then takes the whole set of indices in the dimension (like `:` in python) ::
|
2013-08-22 16:55:51 +02:00
|
|
|
|
|
|
|
A(range(), 0) // take the first column of A
|
|
|
|
|
|
|
|
* two arguments to specify a range ::
|
|
|
|
|
|
|
|
A(range (0,3), 0) // means A(0,0), A(1,0), A(2,0)
|
|
|
|
|
|
|
|
.. warning::
|
2014-10-17 18:15:19 +02:00
|
|
|
the second element is excluded: range(0,3) is 0,1,2, like in Python.
|
2013-08-22 16:55:51 +02:00
|
|
|
|
2014-10-17 18:15:19 +02:00
|
|
|
* three arguments : a range with a step ::
|
2013-08-22 16:55:51 +02:00
|
|
|
|
|
|
|
A(range(0,4,2), 0) // means A(0,0), A(2,0)
|
|
|
|
|
|
|
|
|
|
|
|
.. _arr_ellipsis:
|
|
|
|
|
|
|
|
ellipsis
|
|
|
|
===============
|
|
|
|
|
|
|
|
* Ellipsis can be provided in place of `range`, as in python. The type `ellipsis` is similar to range
|
|
|
|
except that it is implicitely repeated to as much as necessary.
|
|
|
|
|
|
|
|
* Example:
|
|
|
|
|
2014-05-31 19:12:21 +02:00
|
|
|
.. triqs_example:: ./range_ell_0.cpp
|
2014-10-17 18:15:19 +02:00
|
|
|
* NB: there can be at most one ellipsis per expression (otherwise it would be meaningless).
|
2013-08-22 16:55:51 +02:00
|
|
|
|
2014-10-17 18:15:19 +02:00
|
|
|
* Example of usage:
|
2013-08-22 16:55:51 +02:00
|
|
|
|
|
|
|
Ellipsis are useful to write generic algorithms. For example, imagine that you want to sum
|
|
|
|
arrays on their first index :
|
|
|
|
|
2014-05-31 19:12:21 +02:00
|
|
|
.. triqs_example:: ./range_ell_1.cpp
|