Jive reference manual
|
A collection of functions operating on arrays. More...
Functions | |
template<class T , int N> | |
T | jem::min (const ArrayExpr< T, N > &e) |
Computes the minimum value of an array expression. More... | |
template<class T , int N> | |
T | jem::max (const ArrayExpr< T, N > &e) |
Computes the maximum value of an array expression. More... | |
template<class T , int N> | |
T | jem::sum (const ArrayExpr< T, N > &e) |
Computes the sum of all elements in an array expression. More... | |
template<class T , int N> | |
T | jem::product (const ArrayExpr< T, N > &e) |
Computes the product of all elements in an array expression. More... | |
template<class T , int N> | |
bool | jem::testall (const ArrayExpr< T, N > &e) |
Tests whether all elements in an array expression are true. More... | |
template<class T , int N> | |
bool | jem::testany (const ArrayExpr< T, N > &e) |
Tests whether at least one element in an array expression is true. More... | |
template<class T > | |
void | jem::shift (const ArrayExpr< T, 1 > &e, int k) |
Shifts all elements in a one-dimensional array expresion. More... | |
template<class T > | |
void | jem::cshift (const ArrayExpr< T, 1 > &e, int k) |
Shifts all elements in a one-dimensional array expression in a circular way. More... | |
template<class T > | |
void | jem::reverse (const ArrayExpr< T, 1 > &e) |
Reverses the elements in a one-dimensional array expression. More... | |
template<class T , int N> | |
Array< T, N > | jem::reshape (const Array< T, 1 > &a, const Tuple< int, N > &sh) |
Converts a one-dimensional array to a multi-dimcnsional array. More... | |
template<class T , int N> | |
bool | jem::equal (const ArrayExpr< T, N > &lhs, const ArrayExpr< T, N > &rhs) |
Tests whether two array expressions are equal. More... | |
ArrayExpr< int, 1 > | jem::iarray (int n) |
Returns an enumeration of integers as an array expression. More... | |
ArrayExpr< int, 1 > | jem::iarray (const SliceTo &s) |
Returns an enumeration of integers as an array expression. More... | |
ArrayExpr< int, 1 > | jem::iarray (const Slice &s) |
Returns an enumeration of integers as an array expression. More... | |
ArrayExpr< int, 1 > | jem::iarray (const SliceFromTo &s) |
Returns an enumeration of integers as an array expression. More... | |
template<class T , int N> | |
Array< T, N > | jem::makeContiguous (const Array< T, N > &a) |
Converts an array to a contiguous array. More... | |
template<class T > | |
void | jem::sort (const Array< T > &a) |
Sorts a one-dimensional array in ascending order. More... | |
template<class T > | |
void | jem::sort (const Array< int > &perm, const Array< T > &a) |
Sorts an array in ascending order through an index array. More... | |
template<class T > | |
int | jem::binarySearch (const T &value, const Array< T > &a) |
Searches a sorted array for an element with a specific value. More... | |
template<class T > | |
int | jem::lowerBound (const T &value, const Array< T > &a) |
Searches a sorted array for the first element with a specific value. More... | |
template<class T > | |
int | jem::upperBound (const T &value, const Array< T > &a) |
Searches a sorted array for the first element that is larger than a specific value. More... | |
template<class T > | |
SliceFromTo | jem::equalRange (const T &value, const Array< T > &a) |
Searches a sorted array for a set of elements that all have a specific value. More... | |
#include <jem/base/array/utilities.h>
This header file exports a collection of functions that perform various operations on Array
objects and array expressions. Supported operations are:
Note that these functions are also available through the general header file <jem/base/Array.h>
.
T jem::min | ( | const ArrayExpr< T, N > & | e | ) |
T jem::max | ( | const ArrayExpr< T, N > & | e | ) |
T jem::sum | ( | const ArrayExpr< T, N > & | e | ) |
T jem::product | ( | const ArrayExpr< T, N > & | e | ) |
Computes the product of all elements in the array expression or Array
object e.
e | - an array expression or an Array object. |
*
operator. bool jem::testall | ( | const ArrayExpr< T, N > & | e | ) |
Tests whether all elements in the array expression or Array
object e are true.
e | - an array expression or an Array object. |
true
if all elements in the array evaluate to true
, and false
otherwise. The return value is undefined if the array is empty.bool jem::testany | ( | const ArrayExpr< T, N > & | e | ) |
Tests whether at least one element in the array expression or Array
object e is true.
e | - an array expression or an Array object. |
true
if at least one elements in the array evaluates to true
, and false
otherwise. The return value is undefined if the array is empty.void jem::shift | ( | const ArrayExpr< T, 1 > & | e, |
int | k | ||
) |
Shifts all elements in the one-dimensional array expression e k places to the right. Thus, element e
[i] becomes element e[i + k]
. If k is negative, the elements are shifted to the left. The last k elements (or the first k elements if k is negative) are discarded, while the first k (or last k) elements are unchanged.
If k is larger than or equal to the size of the array expression e, then this functin does nothing.
e | - a one-dimensional, lvalue array expression. |
k | - an integer specifying how many places the elements in a should be shifted to the right. |
void jem::cshift | ( | const ArrayExpr< T, 1 > & | e, |
int | k | ||
) |
Like the function shift()
, this function shifts all elements in the one-dimensional array expression e k places to the right. Thus, element e
[i] becomes element e[i + k]
. If k is negative, the elements are shifted to the left. Unlike shift()
, however, the last k elements (or the first k elements if k is negative) are `wrapped around' and become the first (or last) k elements.
If k is larger than the size of the array a, then k is replaced by (k % a.size())
.
e | - a one-dimensional, lvalue array expression. |
k | - an integer specifying the number of places that the elements in a should be shifted to the right. |
void jem::reverse | ( | const ArrayExpr< T, 1 > & | e | ) |
Reverses the order in which the elements are stored in the one-dimensional array expression e. That is, the first element becomes the last element; the second element becomes the second last element; and so on.
e | - a one-dimensional, lvalue array expression. |
Array<T,N> jem::reshape | ( | const Array< T, 1 > & | a, |
const Tuple< int, N > & | sh | ||
) |
Converts the one-dimensional array a to an N-dimensional array with shape sh. The returned array points to the same data block as the argument array a. Any modifications to the returned array are therefore visible in a, and the other way around.
Let r denote the array returned by this function. The mapping of the elements in r and the argument array a is defined as follows:
r(i,j) == a[ i + j * sh[0] ]
;r(i,j,k) == a[ i + j * sh[0] + k * sh[0] * sh[1] ]
;r(i,j,k,p) == a [ i + j * sh[0] + k * sh[0] * sh[1] + p * sh[0] * sh[1] * sh[2] ]
.A different mapping can be obtained by invoking the member function Array::transpose()
on the returned array.
a | - a one-dimensional Array . |
sh | - the shape of the converted array. |
product(sh) == a.size()
ArrayExpr<int,1> jem::iarray | ( | int | n | ) |
Returns a one-dimensional array expression of length n that represents the integer array
[0, 1, 2, ..., n - 1]
.
n | - the length of the returned array expression. |
n >= 0
ArrayExpr<int,1> jem::iarray | ( | const SliceTo & | s | ) |
Returns a one-dimensional array expression that represents the integer array
[0, 1, 2, ..., s.last() - 1]
.
s | - a slice specifying the length of the returned array expression. |
ArrayExpr<int,1> jem::iarray | ( | const Slice & | s | ) |
Returns a one-dimensional array expression that represents the integer array
[i, i + k, i + 2 * k, ..., i + n * k]
with i = s.first()
and k = s.stride()
, and with n
the largest integer such that
i + n * k < s.last()
.
s | - a slice specifying the integers in the returned array expression. |
ArrayExpr<int,1> jem::iarray | ( | const SliceFromTo & | s | ) |
Returns a one-dimensional array expression that represents the integer array
[i, i + 1, i + 2, ..., j - 1]
with i = s.first()
and j = s.last()
.
s | - a slice specifying the integers in the returned array expression. |
Array<T,N> jem::makeContiguous | ( | const Array< T, N > & | a | ) |
Returns an array that has the same shape as the array a; that has the same elements as a; and that is stored contiguously in memory. If the array a is already contiguous, then this function simply returns a.
a | - an Array object. |
Array::isContiguous()
. void jem::sort | ( | const Array< T > & | a | ) |
Sorts the elements stored in the one-dimensional array a in such a way that
a[i + 1] >= a[i]
for all valid indices i
.
The worst-case time compexity of this function is O(n*log(n)) with n the length of the array a.
a | - a one-dimensional Array that is to be sorted. |
<
operator.Sorts the elements in the index array perm in such a way that
a[ perm[i + 1] ] >= a[ perm[i] ]
for all valid indices i
.
The worst-case time compexity of this function is O(n*log(n)) with n the length of the array perm.
perm | - an Array of which the elements are valid indices into the array a. |
a | - an Array object. |
<
operator.int jem::binarySearch | ( | const T & | value, |
const Array< T > & | a | ||
) |
Returns the index of the element with value value in the sorted array a. If there is no such element, a negative integer is returned. If there are multiple elements with the value value, the index of any one of those elements is returned.
The worst-case time complexity of this function is O(log(n)) with n the length of the array a.
value | - the value of the element to be found. |
a | - an Array that has been sorted in ascending order. |
<
operator.sort()
. int jem::lowerBound | ( | const T & | value, |
const Array< T > & | a | ||
) |
Returns the index of the first element with value value in the sorted array a. If there is no such element, the returned index refers to the first element with a value larger than value. If value is larger than the largest element in the array, the size of the array is returned.
The worst-case time complexity of this function is O(log(n)) with n the length of the array a.
value | - the value of the element to be found. |
a | - an Array that has been sorted in ascending order. |
<
operator. int jem::upperBound | ( | const T & | value, |
const Array< T > & | a | ||
) |
Returns the index of the first element with a value that is larger than value in the sorted array a. If there is no such element, the size of the array a is returned.
The worst-case time complexity of this function is O(log(n)) with n the length of the array a.
value | - the value of the element to be found. |
a | - an Array that has been sorted in ascending order. |
<
operator.sort()
. SliceFromTo jem::equalRange | ( | const T & | value, |
const Array< T > & | a | ||
) |
Returns a SliceFromTo
object representing the indices of the elements that all have the value value in the sorted array a. If s denotes the returned slice object, then
a[i] == value
for all indices i that meet the condition
i >= s.first() && i < s.last()
If there are no elements with the value value, then the returned slice object represents an empty range of indices.
The worst-case time complexity of this function is O(log(n)) with n the length of the array a.
value | - the value of the elements to be found. |
a | - an Array that has been sorted in ascending order. |
SliceFromTo
representing the indices of the elements with value value.<
operator.sort()
.