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
  • btype (str) – backend type (‘cpu’, ‘cuda’, ‘opencl’).

  • 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.

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.

count_nonzero(a)

Count the number of elements that are different from zero.

fempty(size[, ndim])

Create an empty darray instance with the given length.

fexp(a)

Calculate the exponential of an array of numbers.

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.

fones(size)

Create an array of the given size filled with ones.

fzeros(size[, ndim])

Create an array of the given size filled with zeros.

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.

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.

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) – number of variable arguments.

Returns

proxy for the different evaluation functions.

Return type

FunctionsProxy

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) – possible maximum length of the output array.

Returns

concatenated array.

Return type

farray

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

fempty(size, ndim=1)[source]

Create an empty darray instance with the given length.

Parameters

size (int) – length of the output array.

Returns

empty array.

Return type

darray

fexp(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

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

farray

fones(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

farray

fzeros(size, ndim=1)[source]

Create an array of the given size filled with zeros.

Parameters

size (int) – length of the output array.

Returns

array of zeros.

Return type

farray

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

farray

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

farray

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) – 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) – 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 imes size imes ...\), 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 imes size imes ...\), depending on the number of dimensions.

Parameters
Returns

random grid.

Return type

farray

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

farray

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

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

farray

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

farray

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

farray

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

farray

take_column(a, i=0)[source]

Take elements of the array using a period.

Parameters

i (int) – column to take the elements.

Returns

reduced array.

Return type

marray

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

Take a slice of entries from the array.

Parameters
  • start (int) – where to start taking entries.

  • end (int) – where to end taking entries.

Returns

slice of the array.

Return type

marray

using_caches()[source]

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