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
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 interface.
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 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.
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.
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.
Use the caches (GPU only).
Attributes Documentation
-
backend
¶ Backend interface.
-
bool_type
¶ Data type used for boolean comparisons.
Methods Documentation
-
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”.
-
fexp
(a)[source]¶ Calculate the exponential of an array of numbers. The input array must be unidimensional.
-
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.
-
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
-
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
-
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
-
is_inside
(data, lb, ub)[source]¶ Return the decision whether the input data is within the given bounds or not.
- Parameters
data (farray) – input data array.
lb (numpy.ndarray) – lower bounds.
ub (numpy.ndarray) – upper bounds.
- Returns
array with the decisions.
- Return type
-
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
-
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.
-
log
(a)[source]¶ Calculate the logarithm of an array of numbers. The input array must be unidimensional.
-
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.
-
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.
-
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
lb (numpy.ndarray) – lower bounds.
ub (numpy.ndarray) – upper bounds.
size (numpy.ndarray) – size of the grid to generate.
-
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
orminkit.iarray
instance.- Parameters
a (numpy.ndarray) – input array.
- Returns
array representation in the given backend.
- Return type
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.
-
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
lb (numpy.ndarray) – lower bounds.
ub (numpy.ndarray) – upper bounds.
size (int or numpy.ndarray) – size of the grid.
- Returns
random grid.
- Return type
-
set_rndm_seed
(seed)[source]¶ Set the seed of the random number generator.
- Parameters
seed (int) – new seed to use.
-
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