ArrayOperations

class minkit.ArrayOperations(backend, **kwargs)[source]

Bases: object

Build the object to do operations within a backend. Only the necessary operators have been defined.

Parameters:
  • backend (Backend) – backend where the operations will be done.
  • kwargs (dict) – arguments forwarded to the backend constructor (cuda and opencl backends only).

The possible keyword arguments in GPU backends are:

  • device: device to be used.
  • interactive: whether to ask the user a device if not specified or if the proposed device is not available.

Attributes Summary

backend Backend interface.
bool_type Data type used for boolean comparisons.

Methods Summary

access_pdf(name, ndata_pars[, nvar_arg_pars]) Access the PDF with the given name.
argmax(a) Return the index with the maximum value.
bempty(size) Create an empty barray instance with the given length.
bones(size) Create an array of “true” values of the given size.
bzeros(size) Create an array of “false” values of the given size.
carange(n) Create an array of elements from 0 to n.
cexp(a) Calculate the exponential of an array of numbers.
concatenate(arrays[, maximum]) Concatenate several arrays.
concatenated_linspace(edges, nsteps) Create a set of concatenated arrays obtained from linspace calls with the given edges.
count_nonzero(a) Count the number of elements that are different from zero.
dempty(size[, ndim]) Create an empty darray instance with the given length.
dexp(a) Calculate the exponential of an array of numbers.
dones(size) Create an array of the given size filled with ones.
dzeros(size[, ndim]) Create an array of the given size filled with zeros.
fftconvolve(a, b, data) Calculate the convolution of two arrays that correspond to the output from the evaluation of two PDFs in the given data.
ge(a, b) Compare two arrays \(a \geq b\).
iarange(n) Create an array of elements from 0 to n.
iempty(size) Create an empty iarray instance with the given length.
is_bool(a) Check whether the data type of the given array is of boolean type.
is_complex(a) Check whether the data type of the given array is of complex type.
is_float(a) Check whether the data type of the given array is of floating point type.
is_inside(data, lb, ub) Return the decision whether the input data is within the given bounds or not.
is_int(a) Check whether the data type of the given array is of integral type.
le(a, b) Compare two arrays \(a \leq b\).
linspace(vmin, vmax, size) Create an array where the values are in increasing order by a constant step.
log(a) Calculate the logarithm of an array of numbers.
logical_and(a, b[, out]) Do the logical “and” operation element by element.
logical_or(a, b[, out]) Do the logical “or” operation element by element.
lt(a, b) Compare two arrays \(a < b\).
make_linear_interpolator(xp, yp) Create a function that, given an array of points in x, provides the interpolated values using a linear interpolator.
make_spline_interpolator(xp, yp) Create a function that, given an array of points in x, provides the interpolated values using an spline of order 3.
max(a) Calculate the maximum value in an array.
meshgrid(lb, ub, size) Create a grid of values using the given set of bounds.
min(a) Calculate the minimum value in an array.
ndarray_to_backend(a) Create an array in the backend of this object.
product_by_zero_is_zero(f, s) Do a product of two arrays in such a way that if any of the elements is zero the output will be zero.
random_grid(lb, ub, size) Create a random grid using the given bounds.
random_uniform(vmin, vmax, size)
restrict_data_size(maximum, data) Drop the last elements of an array of data.
set_rndm_seed(seed) Set the seed of the random number generator.
shuffling_index(n) Calculate a set of indices to shuffle an array.
simpson_factors(size[, nbins]) Return an array with the coefficients for the Simpson numerical integration method.
slice_from_boolean(a, v) Get a slice of the given array using a mask array.
slice_from_integer(a, i) Get a slice of the given array using an array of indices.
steps_from_edges(edges) Calculate the bin sizes from the given set of edges.
sum(a) Sum the elements of the given array.
sum_arrays(arrays) Sum arrays element by element.
sum_inside(indices, gaps, centers, edges[, …]) Sum the occurrences inside the given bounds.
take_column(a[, i]) Take elements of the array using a period.
take_slice(a[, start, end]) Take a slice of entries from the array.
using_caches() Use the caches (GPU only).

Attributes Documentation

backend

Backend interface.

bool_type

Data type used for boolean comparisons.

Methods Documentation

access_pdf(name, ndata_pars, nvar_arg_pars=None)[source]

Access the PDF with the given name.

Parameters:
  • name (str) – name of the PDF.
  • ndata_pars (int) – number of data parameters.
  • nvar_arg_pars (int or None) – number of variable arguments.
Returns:

proxy for the different evaluation functions.

Return type:

FunctionsProxy

Raises:

FileNotFoundError – If the XML file associated to the PDF can not be found.

argmax(a)[source]

Return the index with the maximum value.

Parameters:a (marray, numpy.ndarray or reikna.cluda.api.Array) – input array.
Returns:Index with the maximum value.
Return type:int
bempty(size)[source]

Create an empty barray instance with the given length.

Parameters:size (int) – length of the output array.
Returns:empty array.
Return type:barray
bones(size)[source]

Create an array of “true” values of the given size.

Parameters:size (int) – length of the output array.
Returns:array of “true”.
Return type:barray
bzeros(size)[source]

Create an array of “false” values of the given size.

Parameters:size (int) – length of the output array.
Returns:array of “false”.
Return type:barray
carange(n)[source]

Create an array of elements from 0 to n.

Parameters:n (int) – the next to last item in the array.
Returns:output array.
Return type:carray
cexp(a)[source]

Calculate the exponential of an array of numbers.

Parameters:a (carray) – input array.
Returns:exponential values.
Return type:carray
concatenate(arrays, maximum=None)[source]

Concatenate several arrays. If “maximum” is specified, the last elements will be dropped, so the length of the output array is “maximum”.

Parameters:
  • arrays (tuple(farray)) – collection of arrays.
  • maximum (int or None) – possible maximum length of the output array.
Returns:

concatenated array.

Return type:

darray

concatenated_linspace(edges, nsteps)[source]

Create a set of concatenated arrays obtained from linspace calls with the given edges.

Parameters:
  • edges (darray) – edges of the bins.
  • nsteps (int) – number of steps in the arrays.
Returns:

Concatenated array.

Return type:

darray

count_nonzero(a)[source]

Count the number of elements that are different from zero.

Parameters:a (barray) – input array.
Returns:number of elements that are different from zero.
Return type:int
dempty(size, ndim=1)[source]

Create an empty darray instance with the given length.

Parameters:
  • size (int) – length of the output array.
  • ndim (int) – number of dimensions of the output array.
Returns:

empty array.

Return type:

darray

dexp(a)[source]

Calculate the exponential of an array of numbers. The input array must be unidimensional.

Parameters:a (darray) – input array.
Returns:exponential values.
Return type:darray
dones(size)[source]

Create an array of the given size filled with ones.

Parameters:size (int) – length of the output array.
Returns:array of ones.
Return type:darray
dzeros(size, ndim=1)[source]

Create an array of the given size filled with zeros.

Parameters:
  • size (int) – length of the output array.
  • ndim (int) – number of dimensions of the output array.
Returns:

array of zeros.

Return type:

darray

fftconvolve(a, b, data)[source]

Calculate the convolution of two arrays that correspond to the output from the evaluation of two PDFs in the given data.

Parameters:
  • a (farray) – first array.
  • b (farray) – second array.
  • data (farray) – array of data (only 1D is supported).
Returns:

convolution of the two arrays.

Return type:

darray

ge(a, b)[source]

Compare two arrays \(a \geq b\). The input arrays must be unidimensional.

Parameters:
Returns:

result of the comparison.

Return type:

barray

iarange(n)[source]

Create an array of elements from 0 to n.

Parameters:n (int) – the next to last item in the array.
Returns:output array.
Return type:iarray
iempty(size)[source]

Create an empty iarray instance with the given length.

Parameters:size (int) – length of the output array.
Returns:empty array.
Return type:iarray
is_bool(a)[source]

Check whether the data type of the given array is of boolean type.

Parameters:a (marray, numpy.ndarray or reikna.cluda.api.Array) – input array.
Returns:decision.
Return type:bool
is_complex(a)[source]

Check whether the data type of the given array is of complex type.

Parameters:a (marray, numpy.ndarray or reikna.cluda.api.Array) – input array.
Returns:decision.
Return type:bool
is_float(a)[source]

Check whether the data type of the given array is of floating point type.

Parameters:a (marray, numpy.ndarray or reikna.cluda.api.Array) – input array.
Returns:decision.
Return type:bool
is_inside(data, lb, ub)[source]

Return the decision whether the input data is within the given bounds or not.

Parameters:
Returns:

array with the decisions.

Return type:

barray

is_int(a)[source]

Check whether the data type of the given array is of integral type.

Parameters:a (marray, numpy.ndarray or reikna.cluda.api.Array) – input array.
Returns:decision.
Return type:bool
le(a, b)[source]

Compare two arrays \(a \leq b\). The input arrays must be unidimensional.

Parameters:
Returns:

result of the comparison.

Return type:

barray

linspace(vmin, vmax, size)[source]

Create an array where the values are in increasing order by a constant step. Points in “vmin” and “vmax” are included.

Parameters:
  • vmin (float) – where to start generating values.
  • vmax (float) – where to end generating values.
  • size (int) – length of the output array.
Returns:

array.

Return type:

darray

log(a)[source]

Calculate the logarithm of an array of numbers. The input array must be unidimensional.

Parameters:a (farray) – input array.
Returns:logarithm values.
Return type:darray
logical_and(a, b, out=None)[source]

Do the logical “and” operation element by element.

Parameters:
  • a (farray) – first array.
  • b (farray) – second array.
  • out (barray or None) – possible output array to write the data.
Returns:

array of decisions.

Return type:

barray

logical_or(a, b, out=None)[source]

Do the logical “or” operation element by element.

Parameters:
  • a (farray) – first array.
  • b (farray) – second array.
  • out (barray or None) – possible output array to write the data.
Returns:

array of decisions.

Return type:

barray

lt(a, b)[source]

Compare two arrays \(a < b\). The input arrays must be unidimensional.

Parameters:
Returns:

result of the comparison.

Return type:

barray

make_linear_interpolator(xp, yp)[source]

Create a function that, given an array of points in x, provides the interpolated values using a linear interpolator.

Parameters:
  • xp (darray) – reference points in the x axis.
  • yp (darray) – reference points in the y axis.
Returns:

interpolator.

make_spline_interpolator(xp, yp)[source]

Create a function that, given an array of points in x, provides the interpolated values using an spline of order 3.

Parameters:
  • xp (darray) – reference points in the x axis.
  • yp (darray) – reference points in the y axis.
Returns:

interpolator.

max(a)[source]

Calculate the maximum value in an array.

Parameters:a (farray) – input array.
Returns:maximum value.
Return type:float
meshgrid(lb, ub, size)[source]

Create a grid of values using the given set of bounds. The size can be specified as a single value or as a set of sizes for each dimension. If it is a single value, then the output array will be of length \(size \times size \times ...\), depending on the number of dimensions.

Parameters:
min(a)[source]

Calculate the minimum value in an array.

Parameters:a (farray) – input array.
Returns:minimum value.
Return type:float
ndarray_to_backend(a)[source]

Create an array in the backend of this object. This will directly create an object of the underlying array type of the minkit.barray, minkit.farray or minkit.iarray instance.

Parameters:a (numpy.ndarray) – input array.
Returns:array representation in the given backend.
Return type:numpy.ndarray or reikna.cluda.api.Array

Warning

This function must be used carefully since the output array does not track to which backend it belongs.

product_by_zero_is_zero(f, s)[source]

Do a product of two arrays in such a way that if any of the elements is zero the output will be zero.

Parameters:
  • f (darray) – first array.
  • s – second array.
Returns:

Product of the two arrays.

Return type:

darray

random_grid(lb, ub, size)[source]

Create a random grid using the given bounds. The size can be specified as a single value or as a set of sizes for each dimension. If it is a single value, then the output array will be of length \(size \times size \times ...\), depending on the number of dimensions.

Parameters:
Returns:

random grid.

Return type:

darray

random_uniform(vmin, vmax, size)[source]
restrict_data_size(maximum, data)[source]

Drop the last elements of an array of data.

Parameters:
  • maximum (int) – maximum length of the data sample.
  • data (farray) – data sample.
Returns:

reduced data array.

Return type:

darray

set_rndm_seed(seed)[source]

Set the seed of the random number generator.

Parameters:seed (int) – new seed to use.
shuffling_index(n)[source]

Calculate a set of indices to shuffle an array.

Parameters:n (int) – length of the array.
Returns:array of indices.
Return type:iarray
simpson_factors(size, nbins=None)[source]

Return an array with the coefficients for the Simpson numerical integration method.

Parameters:
  • size (int) – number of steps.
  • nbins – if provided, the factors are returned assuming that there are size values for each bin.
  • nbins – int or None
Returns:

Array with the coefficients.

Return type:

darray

slice_from_boolean(a, v)[source]

Get a slice of the given array using a mask array.

Parameters:
  • a (farray) – input data array.
  • v (barray) – mask array.
Returns:

slice of the array.

Return type:

darray

slice_from_integer(a, i)[source]

Get a slice of the given array using an array of indices.

Parameters:
  • a (farray) – input data array.
  • i (iarray) – array of indices.
Returns:

slice of the array.

Return type:

darray

steps_from_edges(edges)[source]

Calculate the bin sizes from the given set of edges. Only works for one-dimensional arrays.

Parameters:edges (darray) – edges defining the bins.
Returns:step for each bin.
Return type:darray
sum(a)[source]

Sum the elements of the given array.

Parameters:a (farray) – input array.
Returns:sum of elements.
Return type:float
sum_arrays(arrays)[source]

Sum arrays element by element.

Parameters:arrays (tuple(farray)) – set of arrays.
Returns:array with the sum.
Return type:darray
sum_inside(indices, gaps, centers, edges, values=None)[source]

Sum the occurrences inside the given bounds. If “values” is specified, then the values in it are used instead.

Parameters:
  • indices (numpy.ndarray) – array of indices.
  • gaps (numpy.ndarray) – gaps to access the data.
  • centers (farray) – centers corresponding to a data sample.
  • edges (farray) – edges defining the bins.
  • values (farray or None) – possible values (or weights) associated to the data sample.
Returns:

sum inside each bin.

Return type:

darray

take_column(a, i=0)[source]

Take elements of the array using a period.

Parameters:
  • a (farray) – input array.
  • i (int) – column to take the elements.
Returns:

reduced array.

Return type:

darray

take_slice(a, start=0, end=None)[source]

Take a slice of entries from the array.

Parameters:
  • a (farray) – input array.
  • start (int) – where to start taking entries.
  • end (int or None) – where to end taking entries.
Returns:

slice of the array.

Return type:

darray

using_caches()[source]

Use the caches (GPU only). Only those caches related to arrays and functions (not the PDFs) will be removed.