Jive reference manual
|
Functions for selecting non-regular sections of an array. More...
Functions | |
template<class T , class I > | |
ArrayExpr< T, 1 > | jem::select (const ArrayExpr< T, 1 > &a, const I &idx) |
Selects a section of a one-dimensional array. More... | |
template<class T , class I , class J > | |
ArrayExpr< T, 2 > | jem::select (const ArrayExpr< T, 2 > &a, const I &idx, const J &jdx) |
Selects a section of a two-dimensional array. More... | |
template<class T , class I , class J , class K > | |
ArrayExpr< T, 3 > | jem::select (const ArrayExpr< T, 3 > &a, const I &idx, const J &jdx, const K &kdx) |
Selects a section of a three-dimensional array. More... | |
template<class T , class I , class J , class K , class L > | |
ArrayExpr< T, 4 > | jem::select (const ArrayExpr< T, 4 > &a, const I &idx, const J &jdx, const K &kdx, const L &ldx) |
Selects a section of a four-dimensional array. More... | |
#include <jem/base/array/select.h>
This header file exports the select()
function that can be used to select non-regular, rectangular sections of Array
objects and array expressions. This function is especially handy when writing code that uses an index array to access the elements in an Array
or an array expression.
An example:
The above select statement is equivalent with:
Although the select
function provides a similar functionality as the slice operators of the Array
class, they differ in three ways. First, the select
function returns array expressions whereas the overloaded slice operators return Array
objects. Second, the select
function can be used to select non-regular sections of an array, while the slice operators can only be used to select regular sections of an array. Third, the select
function always returns an array expression that has the same rank as the original array. The slice operators, on the other hand, can return an Array
object that has a lower rank than the original array.
Note that the select()
function is also available through the general header file <jem/base/Array.h>
.
ArrayExpr<T,1> jem::select | ( | const ArrayExpr< T, 1 > & | a, |
const I & | idx | ||
) |
Returns a one-dimensional array expression representing a rectangular section of the one-dimensional array expression a. The parameter idx specifies which elements are selected. This parameter can be a Slice
instance (or an instance of a class derived from Slice
), an Array<int>
object, or a one-dimensional array expression of which the elements have type int
. If the parameter idx is a Slice
, this function returns an array expression representing the elements selected by the Slice
object. Otherwise, this function returns an array expression representing the elements indexed by the array object or the array expression idx.
The returned array expression has the same flavor as the parameter a. That is, the returned expression is an rvalue expression if a is an rvalue expression, and an lvalue expression if a is an lvalue expression. The size of the returned expression is equal to the number of elements selected by the parameter idx.
Here is an example:
The last statement is equivalent with:
a | - an array expression or an Array object. |
idx | - a Slice , an Array<int> object, or an array expression of which the elements have type int . |
idx[i] >= 0 && idx[i] < a.size()
ArrayExpr<T,2> jem::select | ( | const ArrayExpr< T, 2 > & | a, |
const I & | idx, | ||
const J & | jdx | ||
) |
Returns a two-dimensional array expression representing a rectangular section of the two-dimensional array expression a. The parameters idx and jdx specify the selected array indices in the first and second dimension, respectively. Each parameter can be a Slice
instance (or an instance of a class derived from Slice
), an Array<int>
object, or a one-dimensional array expression of which the elements have type int
.
The returned array expression has the same flavor as the parameter a. That is, the returned expression is an rvalue expression if a is an rvalue expression, and an lvalue expression if a is an lvalue expression. The returned expression has shape (m,n) with m the number of indices selected by idx, and n the number of indices selected by jdx.
Here is an example:
The last statement is equivalent with:
a | - an array expression or an Array object. |
idx | - a Slice , an Array<int> object, or an array expression of which the elements have type int . |
jdx | - a Slice , an Array<int> object, or array expression of which the elements have type int . |
idx[i] >= 0 && idx[i] < a.shape()[0]
jdx[i] >= 0 && jdx[i] < a.shape()[1]
ArrayExpr<T,3> jem::select | ( | const ArrayExpr< T, 3 > & | a, |
const I & | idx, | ||
const J & | jdx, | ||
const K & | kdx | ||
) |
Returns a three-dimensional array expression representing a rectangular section of the three-dimensional array expression a. The parameters idx, jdx and kdx specify the selected array indices in the first, second and third dimension, respectively. Each parameter can be a Slice
instance (or an instance of a class derived from Slice
), an Array<int>
object, or a one-dimensional array expression of which the elements have type int
.
The returned array expression has the same flavor as the parameter a. That is, the returned expression is an rvalue expression if a is an rvalue expression, and an lvalue expression if a is an lvalue expression. The returned expression has shape (m,n,p) with m, n and p the number of indices selected by idx, jdx and kdx, respectively.
Here is an example:
The last statement is equivalent with:
a | - an array expression or an Array object. |
idx | - a Slice , an Array<int> object, or an array expression of which the elements have type int . |
jdx | - a Slice , an Array<int> object, or an array expression of which the elements have type int . |
kdx | - a Slice , an Array<int> object, or an array expression of which the elements have type int . |
idx[i] >= 0 && idx[i] < a.shape()[0]
jdx[i] >= 0 && jdx[i] < a.shape()[1]
kdx[i] >= 0 && kdx[i] < a.shape()[2]
ArrayExpr<T,4> jem::select | ( | const ArrayExpr< T, 4 > & | a, |
const I & | idx, | ||
const J & | jdx, | ||
const K & | kdx, | ||
const L & | ldx | ||
) |
Returns a four-dimensional array expression representing a rectangular section of the four-dimensional array expression a. The parameters idx, jdx, kdx and ldx specify the selected array indices in the first, second, third and fourth dimension, respectively. Each parameter can be a Slice
instance (or an instance of a class derived from Slice
), an Array<int>
object, or a one-dimensional array expression of which the elements have type int
.
The returned array expression has the same flavor as the parameter a. That is, the returned expression is an rvalue expression if a is an rvalue expression, and an lvalue expression if a is an lvalue expression. The returned expression has shape (m,n,p,q) with m, n, p and q the number of indices selected by idx, jdx, kdx, ldx, respectively.
Here is an example:
The last statement is equivalent with:
a | - an array expression or an Array object. |
idx | - a Slice , an Array<int> object, or an array expression of which the elements have type int . |
jdx | - a Slice , an Array<int> object, or an array expression of which the elements have type int . |
kdx | - a Slice , an Array<int> object, or an array expression of which the elements have type int . |
ldx | - a Slice , an Array<int> object, or an array expression of which the elements have type int . |
idx[i] >= 0 && idx[i] < a.shape()[0]
jdx[i] >= 0 && jdx[i] < a.shape()[1]
kdx[i] >= 0 && kdx[i] < a.shape()[2]
ldx[i] >= 0 && ldx[i] < a.shape()[3]