ArrayOperations¶
-
class
minkit.ArrayOperations(backend, **kwargs)[source]¶ Bases:
objectBuild 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
backendBackend interface. bool_typeData 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 barrayinstance 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 darrayinstance 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 iarrayinstance 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: 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
barrayinstance 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: Returns: concatenated array.
Return type:
-
concatenated_linspace(edges, nsteps)[source]¶ Create a set of concatenated arrays obtained from linspace calls with the given edges.
Parameters: Returns: Concatenated array.
Return type:
-
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
darrayinstance with the given length.Parameters: Returns: empty array.
Return type:
-
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: Returns: array of zeros.
Return type:
-
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: Returns: convolution of the two arrays.
Return type:
-
ge(a, b)[source]¶ Compare two arrays \(a \geq b\). The input arrays must be unidimensional.
Parameters: Returns: result of the comparison.
Return type:
-
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
iarrayinstance 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: - 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: 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:
-
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: Returns: array.
Return type:
-
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: Returns: array of decisions.
Return type:
-
logical_or(a, b, out=None)[source]¶ Do the logical “or” operation element by element.
Parameters: Returns: array of decisions.
Return type:
-
lt(a, b)[source]¶ Compare two arrays \(a < b\). The input arrays must be unidimensional.
Parameters: Returns: result of the comparison.
Return type:
-
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: 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: 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: - lb (numpy.ndarray) – lower bounds.
- ub (numpy.ndarray) – upper bounds.
- size (numpy.ndarray) – size of the grid to generate.
-
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.farrayorminkit.iarrayinstance.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:
-
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: - lb (numpy.ndarray) – lower bounds.
- ub (numpy.ndarray) – upper bounds.
- size (int or numpy.ndarray) – size of the grid.
Returns: random grid.
Return type:
-
restrict_data_size(maximum, data)[source]¶ Drop the last elements of an array of data.
Parameters: Returns: reduced data array.
Return type:
-
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:
-
slice_from_boolean(a, v)[source]¶ Get a slice of the given array using a mask array.
Parameters: Returns: slice of the array.
Return type:
-
slice_from_integer(a, i)[source]¶ Get a slice of the given array using an array of indices.
Parameters: Returns: slice of the array.
Return type:
-
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:
-
take_column(a, i=0)[source]¶ Take elements of the array using a period.
Parameters: Returns: reduced array.
Return type: