spateo.alignment.methods.backend_ot =================================== .. py:module:: spateo.alignment.methods.backend_ot .. autoapi-nested-parse:: Multi-lib backend for POT The goal is to write backend-agnostic code. Whether you're using Numpy, PyTorch, Jax, Cupy, or Tensorflow, POT code should work nonetheless. To achieve that, POT provides backend classes which implements functions in their respective backend imitating Numpy API. As a convention, we use nx instead of np to refer to the backend. .. rubric:: Examples >>> from ot.utils import list_to_array >>> from ot.backend import get_backend >>> def f(a, b): # the function does not know which backend to use ... a, b = list_to_array(a, b) # if a list in given, make it an array ... nx = get_backend(a, b) # infer the backend from the arguments ... c = nx.dot(a, b) # now use the backend to do any calculation ... return c .. warning:: Tensorflow only works with the Numpy API. To activate it, please run the following: .. code-block:: from tensorflow.python.ops.numpy_ops import np_config np_config.enable_numpy_behavior() Performance ----------- - CPU: Intel(R) Xeon(R) Gold 6248 CPU @ 2.50GHz - GPU: Tesla V100-SXM2-32GB - Date of the benchmark: December 8th, 2021 - Commit of benchmark: PR #316, https://github.com/PythonOT/POT/pull/316 .. raw:: html
Sinkhorn Knopp - Averaged on 100 runs
Bitsize32 bits
DeviceCPUGPU
Sample sizeNumpyPytorchTensorflowCupyJaxPytorchTensorflow
500.00080.00220.01510.00950.01930.00510.0293
1000.00050.00130.00970.00570.01150.00290.0173
5000.00090.00160.01100.00580.01150.00290.0166
10000.00210.00210.01450.00560.01180.00290.0168
20000.00690.00430.02780.00590.01180.00300.0165
50000.07070.03140.13950.00740.01250.00350.0198
 
Bitsize64 bits
DeviceCPUGPU
Sample sizeNumpyPytorchTensorflowCupyJaxPytorchTensorflow
500.00080.00200.01540.00930.01910.00510.0328
1000.00050.00130.00940.00560.01140.00290.0169
5000.00130.00170.01200.00590.01160.00290.0168
10000.00340.00270.01770.00580.01180.00290.0167
20000.01460.00750.04360.00590.01200.00290.0165
50000.14670.05680.24680.00770.01460.00450.0204
Attributes ---------- .. autoapisummary:: spateo.alignment.methods.backend_ot.DISABLE_TORCH_KEY spateo.alignment.methods.backend_ot.DISABLE_JAX_KEY spateo.alignment.methods.backend_ot.DISABLE_CUPY_KEY spateo.alignment.methods.backend_ot.DISABLE_TF_KEY spateo.alignment.methods.backend_ot.torch_type spateo.alignment.methods.backend_ot.jax_type spateo.alignment.methods.backend_ot.cp_type spateo.alignment.methods.backend_ot.tf_type spateo.alignment.methods.backend_ot.str_type_error spateo.alignment.methods.backend_ot._BACKEND_IMPLEMENTATIONS spateo.alignment.methods.backend_ot._BACKENDS Classes ------- .. autoapisummary:: spateo.alignment.methods.backend_ot.Backend spateo.alignment.methods.backend_ot.NumpyBackend spateo.alignment.methods.backend_ot.JaxBackend spateo.alignment.methods.backend_ot.TorchBackend spateo.alignment.methods.backend_ot.CupyBackend spateo.alignment.methods.backend_ot.TensorflowBackend Functions --------- .. autoapisummary:: spateo.alignment.methods.backend_ot._register_backend_implementation spateo.alignment.methods.backend_ot._get_backend_instance spateo.alignment.methods.backend_ot._check_args_backend spateo.alignment.methods.backend_ot.get_backend_list spateo.alignment.methods.backend_ot.get_available_backend_implementations spateo.alignment.methods.backend_ot.get_backend spateo.alignment.methods.backend_ot.to_numpy Module Contents --------------- .. py:data:: DISABLE_TORCH_KEY :value: 'POT_BACKEND_DISABLE_PYTORCH' .. py:data:: DISABLE_JAX_KEY :value: 'POT_BACKEND_DISABLE_JAX' .. py:data:: DISABLE_CUPY_KEY :value: 'POT_BACKEND_DISABLE_CUPY' .. py:data:: DISABLE_TF_KEY :value: 'POT_BACKEND_DISABLE_TENSORFLOW' .. py:data:: torch_type .. py:data:: jax_type .. py:data:: cp_type .. py:data:: tf_type .. py:data:: str_type_error :value: 'All array should be from the same type/backend. Current types are : {}' .. py:data:: _BACKEND_IMPLEMENTATIONS :value: [] .. py:data:: _BACKENDS .. py:function:: _register_backend_implementation(backend_impl) .. py:function:: _get_backend_instance(backend_impl) .. py:function:: _check_args_backend(backend_impl, args) .. py:function:: get_backend_list() Returns instances of all available backends. Note that the function forces all detected implementations to be instantiated even if specific backend was not use before. Be careful as instantiation of the backend might lead to side effects, like GPU memory pre-allocation. See the documentation for more details. If you only need to know which implementations are available, use `:py:func:`ot.backend.get_available_backend_implementations`, which does not force instance of the backend object to be created. .. py:function:: get_available_backend_implementations() Returns the list of available backend implementations. .. py:function:: get_backend(*args) Returns the proper backend for a list of input arrays Accepts None entries in the arguments, and ignores them Also raises TypeError if all arrays are not from the same backend .. py:function:: to_numpy(*args) Returns numpy arrays from any compatible backend .. py:class:: Backend Backend abstract class. Implementations: :py:class:`JaxBackend`, :py:class:`NumpyBackend`, :py:class:`TorchBackend`, :py:class:`CupyBackend`, :py:class:`TensorflowBackend` - The `__name__` class attribute refers to the name of the backend. - The `__type__` class attribute refers to the data structure used by the backend. .. py:attribute:: __name__ :value: None .. py:attribute:: __type__ :value: None .. py:attribute:: __type_list__ :value: None .. py:attribute:: rng_ :value: None .. py:method:: __str__() .. py:method:: to_numpy(*arrays) Returns the numpy version of tensors .. py:method:: _to_numpy(a) :abstractmethod: Returns the numpy version of a tensor .. py:method:: from_numpy(*arrays, type_as=None) Creates tensors cloning a numpy array, with the given precision (defaulting to input's precision) and the given device (in case of GPUs) .. py:method:: _from_numpy(a, type_as=None) :abstractmethod: Creates a tensor cloning a numpy array, with the given precision (defaulting to input's precision) and the given device (in case of GPUs) .. py:method:: set_gradients(val, inputs, grads) :abstractmethod: Define the gradients for the value val wrt the inputs .. py:method:: detach(*arrays) Detach the tensors from the computation graph See: https://pytorch.org/docs/stable/generated/torch.Tensor.detach.html .. py:method:: _detach(a) :abstractmethod: Detach the tensor from the computation graph .. py:method:: zeros(shape, type_as=None) :abstractmethod: Creates a tensor full of zeros. This function follows the api from :any:`numpy.zeros` See: https://numpy.org/doc/stable/reference/generated/numpy.zeros.html .. py:method:: ones(shape, type_as=None) :abstractmethod: Creates a tensor full of ones. This function follows the api from :any:`numpy.ones` See: https://numpy.org/doc/stable/reference/generated/numpy.ones.html .. py:method:: arange(stop, start=0, step=1, type_as=None) :abstractmethod: Returns evenly spaced values within a given interval. This function follows the api from :any:`numpy.arange` See: https://numpy.org/doc/stable/reference/generated/numpy.arange.html .. py:method:: full(shape, fill_value, type_as=None) :abstractmethod: Creates a tensor with given shape, filled with given value. This function follows the api from :any:`numpy.full` See: https://numpy.org/doc/stable/reference/generated/numpy.full.html .. py:method:: eye(N, M=None, type_as=None) :abstractmethod: Creates the identity matrix of given size. This function follows the api from :any:`numpy.eye` See: https://numpy.org/doc/stable/reference/generated/numpy.eye.html .. py:method:: sum(a, axis=None, keepdims=False) :abstractmethod: Sums tensor elements over given dimensions. This function follows the api from :any:`numpy.sum` See: https://numpy.org/doc/stable/reference/generated/numpy.sum.html .. py:method:: cumsum(a, axis=None) :abstractmethod: Returns the cumulative sum of tensor elements over given dimensions. This function follows the api from :any:`numpy.cumsum` See: https://numpy.org/doc/stable/reference/generated/numpy.cumsum.html .. py:method:: max(a, axis=None, keepdims=False) :abstractmethod: Returns the maximum of an array or maximum along given dimensions. This function follows the api from :any:`numpy.amax` See: https://numpy.org/doc/stable/reference/generated/numpy.amax.html .. py:method:: min(a, axis=None, keepdims=False) :abstractmethod: Returns the maximum of an array or maximum along given dimensions. This function follows the api from :any:`numpy.amin` See: https://numpy.org/doc/stable/reference/generated/numpy.amin.html .. py:method:: maximum(a, b) :abstractmethod: Returns element-wise maximum of array elements. This function follows the api from :any:`numpy.maximum` See: https://numpy.org/doc/stable/reference/generated/numpy.maximum.html .. py:method:: minimum(a, b) :abstractmethod: Returns element-wise minimum of array elements. This function follows the api from :any:`numpy.minimum` See: https://numpy.org/doc/stable/reference/generated/numpy.minimum.html .. py:method:: sign(a) :abstractmethod: Returns an element-wise indication of the sign of a number. This function follows the api from :any:`numpy.sign` See: https://numpy.org/doc/stable/reference/generated/numpy.sign.html .. py:method:: dot(a, b) :abstractmethod: Returns the dot product of two tensors. This function follows the api from :any:`numpy.dot` See: https://numpy.org/doc/stable/reference/generated/numpy.dot.html .. py:method:: abs(a) :abstractmethod: Computes the absolute value element-wise. This function follows the api from :any:`numpy.absolute` See: https://numpy.org/doc/stable/reference/generated/numpy.absolute.html .. py:method:: exp(a) :abstractmethod: Computes the exponential value element-wise. This function follows the api from :any:`numpy.exp` See: https://numpy.org/doc/stable/reference/generated/numpy.exp.html .. py:method:: log(a) :abstractmethod: Computes the natural logarithm, element-wise. This function follows the api from :any:`numpy.log` See: https://numpy.org/doc/stable/reference/generated/numpy.log.html .. py:method:: sqrt(a) :abstractmethod: Returns the non-ngeative square root of a tensor, element-wise. This function follows the api from :any:`numpy.sqrt` See: https://numpy.org/doc/stable/reference/generated/numpy.sqrt.html .. py:method:: power(a, exponents) :abstractmethod: First tensor elements raised to powers from second tensor, element-wise. This function follows the api from :any:`numpy.power` See: https://numpy.org/doc/stable/reference/generated/numpy.power.html .. py:method:: norm(a, axis=None, keepdims=False) :abstractmethod: Computes the matrix frobenius norm. This function follows the api from :any:`numpy.linalg.norm` See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.norm.html .. py:method:: any(a) :abstractmethod: Tests whether any tensor element along given dimensions evaluates to True. This function follows the api from :any:`numpy.any` See: https://numpy.org/doc/stable/reference/generated/numpy.any.html .. py:method:: isnan(a) :abstractmethod: Tests element-wise for NaN and returns result as a boolean tensor. This function follows the api from :any:`numpy.isnan` See: https://numpy.org/doc/stable/reference/generated/numpy.isnan.html .. py:method:: isinf(a) :abstractmethod: Tests element-wise for positive or negative infinity and returns result as a boolean tensor. This function follows the api from :any:`numpy.isinf` See: https://numpy.org/doc/stable/reference/generated/numpy.isinf.html .. py:method:: einsum(subscripts, *operands) :abstractmethod: Evaluates the Einstein summation convention on the operands. This function follows the api from :any:`numpy.einsum` See: https://numpy.org/doc/stable/reference/generated/numpy.einsum.html .. py:method:: sort(a, axis=-1) :abstractmethod: Returns a sorted copy of a tensor. This function follows the api from :any:`numpy.sort` See: https://numpy.org/doc/stable/reference/generated/numpy.sort.html .. py:method:: argsort(a, axis=None) :abstractmethod: Returns the indices that would sort a tensor. This function follows the api from :any:`numpy.argsort` See: https://numpy.org/doc/stable/reference/generated/numpy.argsort.html .. py:method:: searchsorted(a, v, side='left') :abstractmethod: Finds indices where elements should be inserted to maintain order in given tensor. This function follows the api from :any:`numpy.searchsorted` See: https://numpy.org/doc/stable/reference/generated/numpy.searchsorted.html .. py:method:: flip(a, axis=None) :abstractmethod: Reverses the order of elements in a tensor along given dimensions. This function follows the api from :any:`numpy.flip` See: https://numpy.org/doc/stable/reference/generated/numpy.flip.html .. py:method:: clip(a, a_min, a_max) :abstractmethod: Limits the values in a tensor. This function follows the api from :any:`numpy.clip` See: https://numpy.org/doc/stable/reference/generated/numpy.clip.html .. py:method:: repeat(a, repeats, axis=None) :abstractmethod: Repeats elements of a tensor. This function follows the api from :any:`numpy.repeat` See: https://numpy.org/doc/stable/reference/generated/numpy.repeat.html .. py:method:: take_along_axis(arr, indices, axis) :abstractmethod: Gathers elements of a tensor along given dimensions. This function follows the api from :any:`numpy.take_along_axis` See: https://numpy.org/doc/stable/reference/generated/numpy.take_along_axis.html .. py:method:: concatenate(arrays, axis=0) :abstractmethod: Joins a sequence of tensors along an existing dimension. This function follows the api from :any:`numpy.concatenate` See: https://numpy.org/doc/stable/reference/generated/numpy.concatenate.html .. py:method:: zero_pad(a, pad_width, value=0) :abstractmethod: Pads a tensor with a given value (0 by default). This function follows the api from :any:`numpy.pad` See: https://numpy.org/doc/stable/reference/generated/numpy.pad.html .. py:method:: argmax(a, axis=None) :abstractmethod: Returns the indices of the maximum values of a tensor along given dimensions. This function follows the api from :any:`numpy.argmax` See: https://numpy.org/doc/stable/reference/generated/numpy.argmax.html .. py:method:: argmin(a, axis=None) :abstractmethod: Returns the indices of the minimum values of a tensor along given dimensions. This function follows the api from :any:`numpy.argmin` See: https://numpy.org/doc/stable/reference/generated/numpy.argmin.html .. py:method:: mean(a, axis=None) :abstractmethod: Computes the arithmetic mean of a tensor along given dimensions. This function follows the api from :any:`numpy.mean` See: https://numpy.org/doc/stable/reference/generated/numpy.mean.html .. py:method:: median(a, axis=None) :abstractmethod: Computes the median of a tensor along given dimensions. This function follows the api from :any:`numpy.median` See: https://numpy.org/doc/stable/reference/generated/numpy.median.html .. py:method:: std(a, axis=None) :abstractmethod: Computes the standard deviation of a tensor along given dimensions. This function follows the api from :any:`numpy.std` See: https://numpy.org/doc/stable/reference/generated/numpy.std.html .. py:method:: linspace(start, stop, num, type_as=None) :abstractmethod: Returns a specified number of evenly spaced values over a given interval. This function follows the api from :any:`numpy.linspace` See: https://numpy.org/doc/stable/reference/generated/numpy.linspace.html .. py:method:: meshgrid(a, b) :abstractmethod: Returns coordinate matrices from coordinate vectors (Numpy convention). This function follows the api from :any:`numpy.meshgrid` See: https://numpy.org/doc/stable/reference/generated/numpy.meshgrid.html .. py:method:: diag(a, k=0) :abstractmethod: Extracts or constructs a diagonal tensor. This function follows the api from :any:`numpy.diag` See: https://numpy.org/doc/stable/reference/generated/numpy.diag.html .. py:method:: unique(a, return_inverse=False) :abstractmethod: Finds unique elements of given tensor. This function follows the api from :any:`numpy.unique` See: https://numpy.org/doc/stable/reference/generated/numpy.unique.html .. py:method:: logsumexp(a, axis=None) :abstractmethod: Computes the log of the sum of exponentials of input elements. This function follows the api from :any:`scipy.special.logsumexp` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.logsumexp.html .. py:method:: stack(arrays, axis=0) :abstractmethod: Joins a sequence of tensors along a new dimension. This function follows the api from :any:`numpy.stack` See: https://numpy.org/doc/stable/reference/generated/numpy.stack.html .. py:method:: outer(a, b) :abstractmethod: Computes the outer product between two vectors. This function follows the api from :any:`numpy.outer` See: https://numpy.org/doc/stable/reference/generated/numpy.outer.html .. py:method:: reshape(a, shape) :abstractmethod: Gives a new shape to a tensor without changing its data. This function follows the api from :any:`numpy.reshape` See: https://numpy.org/doc/stable/reference/generated/numpy.reshape.html .. py:method:: seed(seed=None) :abstractmethod: Sets the seed for the random generator. This function follows the api from :any:`numpy.random.seed` See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.seed.html .. py:method:: rand(*size, type_as=None) :abstractmethod: Generate uniform random numbers. This function follows the api from :any:`numpy.random.rand` See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.rand.html .. py:method:: randn(*size, type_as=None) :abstractmethod: Generate normal Gaussian random numbers. This function follows the api from :any:`numpy.random.rand` See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.rand.html .. py:method:: coo_matrix(data, rows, cols, shape=None, type_as=None) :abstractmethod: Creates a sparse tensor in COOrdinate format. This function follows the api from :any:`scipy.sparse.coo_matrix` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.html .. py:method:: issparse(a) :abstractmethod: Checks whether or not the input tensor is a sparse tensor. This function follows the api from :any:`scipy.sparse.issparse` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.issparse.html .. py:method:: tocsr(a) :abstractmethod: Converts this matrix to Compressed Sparse Row format. This function follows the api from :any:`scipy.sparse.coo_matrix.tocsr` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.tocsr.html .. py:method:: eliminate_zeros(a, threshold=0.0) :abstractmethod: Removes entries smaller than the given threshold from the sparse tensor. This function follows the api from :any:`scipy.sparse.csr_matrix.eliminate_zeros` See: https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.sparse.csr_matrix.eliminate_zeros.html .. py:method:: todense(a) :abstractmethod: Converts a sparse tensor to a dense tensor. This function follows the api from :any:`scipy.sparse.csr_matrix.toarray` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csr_matrix.toarray.html .. py:method:: where(condition, x, y) :abstractmethod: Returns elements chosen from x or y depending on condition. This function follows the api from :any:`numpy.where` See: https://numpy.org/doc/stable/reference/generated/numpy.where.html .. py:method:: copy(a) :abstractmethod: Returns a copy of the given tensor. This function follows the api from :any:`numpy.copy` See: https://numpy.org/doc/stable/reference/generated/numpy.copy.html .. py:method:: allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False) :abstractmethod: Returns True if two arrays are element-wise equal within a tolerance. This function follows the api from :any:`numpy.allclose` See: https://numpy.org/doc/stable/reference/generated/numpy.allclose.html .. py:method:: dtype_device(a) :abstractmethod: Returns the dtype and the device of the given tensor. .. py:method:: assert_same_dtype_device(a, b) :abstractmethod: Checks whether or not the two given inputs have the same dtype as well as the same device .. py:method:: squeeze(a, axis=None) :abstractmethod: Remove axes of length one from a. This function follows the api from :any:`numpy.squeeze`. See: https://numpy.org/doc/stable/reference/generated/numpy.squeeze.html .. py:method:: bitsize(type_as) :abstractmethod: Gives the number of bits used by the data type of the given tensor. .. py:method:: device_type(type_as) :abstractmethod: Returns CPU or GPU depending on the device where the given tensor is located. .. py:method:: _bench(callable, *args, n_runs=1, warmup_runs=1) :abstractmethod: Executes a benchmark of the given callable with the given arguments. .. py:method:: solve(a, b) :abstractmethod: Solves a linear matrix equation, or system of linear scalar equations. This function follows the api from :any:`numpy.linalg.solve`. See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.solve.html .. py:method:: trace(a) :abstractmethod: Returns the sum along diagonals of the array. This function follows the api from :any:`numpy.trace`. See: https://numpy.org/doc/stable/reference/generated/numpy.trace.html .. py:method:: inv(a) :abstractmethod: Computes the inverse of a matrix. This function follows the api from :any:`scipy.linalg.inv`. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.inv.html .. py:method:: sqrtm(a) :abstractmethod: Computes the matrix square root. Requires input to be definite positive. This function follows the api from :any:`scipy.linalg.sqrtm`. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.sqrtm.html .. py:method:: eigh(a) :abstractmethod: Computes the eigenvalues and eigenvectors of a symmetric tensor. This function follows the api from :any:`scipy.linalg.eigh`. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.eigh.html .. py:method:: kl_div(p, q, mass=False, eps=1e-16) :abstractmethod: Computes the (Generalized) Kullback-Leibler divergence. This function follows the api from :any:`scipy.stats.entropy`. Parameter eps is used to avoid numerical errors and is added in the log. .. math:: KL(p,q) = \langle \mathbf{p}, log(\mathbf{p} / \mathbf{q} + eps \rangle + \mathbb{1}_{mass=True} \langle \mathbf{q} - \mathbf{p}, \mathbf{1} \rangle See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.entropy.html .. py:method:: isfinite(a) :abstractmethod: Tests element-wise for finiteness (not infinity and not Not a Number). This function follows the api from :any:`numpy.isfinite`. See: https://numpy.org/doc/stable/reference/generated/numpy.isfinite.html .. py:method:: array_equal(a, b) :abstractmethod: True if two arrays have the same shape and elements, False otherwise. This function follows the api from :any:`numpy.array_equal`. See: https://numpy.org/doc/stable/reference/generated/numpy.array_equal.html .. py:method:: is_floating_point(a) :abstractmethod: Returns whether or not the input consists of floats .. py:method:: tile(a, reps) :abstractmethod: Construct an array by repeating a the number of times given by reps See: https://numpy.org/doc/stable/reference/generated/numpy.tile.html .. py:method:: floor(a) :abstractmethod: Return the floor of the input element-wise See: https://numpy.org/doc/stable/reference/generated/numpy.floor.html .. py:method:: prod(a, axis=None) :abstractmethod: Return the product of all elements. See: https://numpy.org/doc/stable/reference/generated/numpy.prod.html .. py:method:: sort2(a, axis=None) :abstractmethod: Return the sorted array and the indices to sort the array See: https://pytorch.org/docs/stable/generated/torch.sort.html .. py:method:: qr(a) :abstractmethod: Return the QR factorization See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.qr.html .. py:method:: atan2(a, b) :abstractmethod: Element wise arctangent See: https://numpy.org/doc/stable/reference/generated/numpy.arctan2.html .. py:method:: transpose(a, axes=None) :abstractmethod: Returns a tensor that is a transposed version of a. The given dimensions dim0 and dim1 are swapped. See: https://numpy.org/doc/stable/reference/generated/numpy.transpose.html .. py:method:: matmul(a, b) :abstractmethod: Matrix product of two arrays. See: https://numpy.org/doc/stable/reference/generated/numpy.matmul.html#numpy.matmul .. py:method:: nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None) :abstractmethod: Replace NaN with zero and infinity with large finite numbers or with the numbers defined by the user. See: https://numpy.org/doc/stable/reference/generated/numpy.nan_to_num.html#numpy.nan_to_num .. py:class:: NumpyBackend Bases: :py:obj:`Backend` NumPy implementation of the backend - `__name__` is "numpy" - `__type__` is np.ndarray .. py:attribute:: __name__ :value: 'numpy' .. py:attribute:: __type__ .. py:attribute:: __type_list__ .. py:attribute:: rng_ .. py:method:: _to_numpy(a) Returns the numpy version of a tensor .. py:method:: _from_numpy(a, type_as=None) Creates a tensor cloning a numpy array, with the given precision (defaulting to input's precision) and the given device (in case of GPUs) .. py:method:: set_gradients(val, inputs, grads) Define the gradients for the value val wrt the inputs .. py:method:: _detach(a) Detach the tensor from the computation graph .. py:method:: zeros(shape, type_as=None) Creates a tensor full of zeros. This function follows the api from :any:`numpy.zeros` See: https://numpy.org/doc/stable/reference/generated/numpy.zeros.html .. py:method:: ones(shape, type_as=None) Creates a tensor full of ones. This function follows the api from :any:`numpy.ones` See: https://numpy.org/doc/stable/reference/generated/numpy.ones.html .. py:method:: arange(stop, start=0, step=1, type_as=None) Returns evenly spaced values within a given interval. This function follows the api from :any:`numpy.arange` See: https://numpy.org/doc/stable/reference/generated/numpy.arange.html .. py:method:: full(shape, fill_value, type_as=None) Creates a tensor with given shape, filled with given value. This function follows the api from :any:`numpy.full` See: https://numpy.org/doc/stable/reference/generated/numpy.full.html .. py:method:: eye(N, M=None, type_as=None) Creates the identity matrix of given size. This function follows the api from :any:`numpy.eye` See: https://numpy.org/doc/stable/reference/generated/numpy.eye.html .. py:method:: sum(a, axis=None, keepdims=False) Sums tensor elements over given dimensions. This function follows the api from :any:`numpy.sum` See: https://numpy.org/doc/stable/reference/generated/numpy.sum.html .. py:method:: cumsum(a, axis=None) Returns the cumulative sum of tensor elements over given dimensions. This function follows the api from :any:`numpy.cumsum` See: https://numpy.org/doc/stable/reference/generated/numpy.cumsum.html .. py:method:: max(a, axis=None, keepdims=False) Returns the maximum of an array or maximum along given dimensions. This function follows the api from :any:`numpy.amax` See: https://numpy.org/doc/stable/reference/generated/numpy.amax.html .. py:method:: min(a, axis=None, keepdims=False) Returns the maximum of an array or maximum along given dimensions. This function follows the api from :any:`numpy.amin` See: https://numpy.org/doc/stable/reference/generated/numpy.amin.html .. py:method:: maximum(a, b) Returns element-wise maximum of array elements. This function follows the api from :any:`numpy.maximum` See: https://numpy.org/doc/stable/reference/generated/numpy.maximum.html .. py:method:: minimum(a, b) Returns element-wise minimum of array elements. This function follows the api from :any:`numpy.minimum` See: https://numpy.org/doc/stable/reference/generated/numpy.minimum.html .. py:method:: sign(a) Returns an element-wise indication of the sign of a number. This function follows the api from :any:`numpy.sign` See: https://numpy.org/doc/stable/reference/generated/numpy.sign.html .. py:method:: dot(a, b) Returns the dot product of two tensors. This function follows the api from :any:`numpy.dot` See: https://numpy.org/doc/stable/reference/generated/numpy.dot.html .. py:method:: abs(a) Computes the absolute value element-wise. This function follows the api from :any:`numpy.absolute` See: https://numpy.org/doc/stable/reference/generated/numpy.absolute.html .. py:method:: exp(a) Computes the exponential value element-wise. This function follows the api from :any:`numpy.exp` See: https://numpy.org/doc/stable/reference/generated/numpy.exp.html .. py:method:: log(a) Computes the natural logarithm, element-wise. This function follows the api from :any:`numpy.log` See: https://numpy.org/doc/stable/reference/generated/numpy.log.html .. py:method:: sqrt(a) Returns the non-ngeative square root of a tensor, element-wise. This function follows the api from :any:`numpy.sqrt` See: https://numpy.org/doc/stable/reference/generated/numpy.sqrt.html .. py:method:: power(a, exponents) First tensor elements raised to powers from second tensor, element-wise. This function follows the api from :any:`numpy.power` See: https://numpy.org/doc/stable/reference/generated/numpy.power.html .. py:method:: norm(a, axis=None, keepdims=False) Computes the matrix frobenius norm. This function follows the api from :any:`numpy.linalg.norm` See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.norm.html .. py:method:: any(a) Tests whether any tensor element along given dimensions evaluates to True. This function follows the api from :any:`numpy.any` See: https://numpy.org/doc/stable/reference/generated/numpy.any.html .. py:method:: isnan(a) Tests element-wise for NaN and returns result as a boolean tensor. This function follows the api from :any:`numpy.isnan` See: https://numpy.org/doc/stable/reference/generated/numpy.isnan.html .. py:method:: isinf(a) Tests element-wise for positive or negative infinity and returns result as a boolean tensor. This function follows the api from :any:`numpy.isinf` See: https://numpy.org/doc/stable/reference/generated/numpy.isinf.html .. py:method:: einsum(subscripts, *operands) Evaluates the Einstein summation convention on the operands. This function follows the api from :any:`numpy.einsum` See: https://numpy.org/doc/stable/reference/generated/numpy.einsum.html .. py:method:: sort(a, axis=-1) Returns a sorted copy of a tensor. This function follows the api from :any:`numpy.sort` See: https://numpy.org/doc/stable/reference/generated/numpy.sort.html .. py:method:: argsort(a, axis=-1) Returns the indices that would sort a tensor. This function follows the api from :any:`numpy.argsort` See: https://numpy.org/doc/stable/reference/generated/numpy.argsort.html .. py:method:: searchsorted(a, v, side='left') Finds indices where elements should be inserted to maintain order in given tensor. This function follows the api from :any:`numpy.searchsorted` See: https://numpy.org/doc/stable/reference/generated/numpy.searchsorted.html .. py:method:: flip(a, axis=None) Reverses the order of elements in a tensor along given dimensions. This function follows the api from :any:`numpy.flip` See: https://numpy.org/doc/stable/reference/generated/numpy.flip.html .. py:method:: outer(a, b) Computes the outer product between two vectors. This function follows the api from :any:`numpy.outer` See: https://numpy.org/doc/stable/reference/generated/numpy.outer.html .. py:method:: clip(a, a_min, a_max) Limits the values in a tensor. This function follows the api from :any:`numpy.clip` See: https://numpy.org/doc/stable/reference/generated/numpy.clip.html .. py:method:: repeat(a, repeats, axis=None) Repeats elements of a tensor. This function follows the api from :any:`numpy.repeat` See: https://numpy.org/doc/stable/reference/generated/numpy.repeat.html .. py:method:: take_along_axis(arr, indices, axis) Gathers elements of a tensor along given dimensions. This function follows the api from :any:`numpy.take_along_axis` See: https://numpy.org/doc/stable/reference/generated/numpy.take_along_axis.html .. py:method:: concatenate(arrays, axis=0) Joins a sequence of tensors along an existing dimension. This function follows the api from :any:`numpy.concatenate` See: https://numpy.org/doc/stable/reference/generated/numpy.concatenate.html .. py:method:: zero_pad(a, pad_width, value=0) Pads a tensor with a given value (0 by default). This function follows the api from :any:`numpy.pad` See: https://numpy.org/doc/stable/reference/generated/numpy.pad.html .. py:method:: argmax(a, axis=None) Returns the indices of the maximum values of a tensor along given dimensions. This function follows the api from :any:`numpy.argmax` See: https://numpy.org/doc/stable/reference/generated/numpy.argmax.html .. py:method:: argmin(a, axis=None) Returns the indices of the minimum values of a tensor along given dimensions. This function follows the api from :any:`numpy.argmin` See: https://numpy.org/doc/stable/reference/generated/numpy.argmin.html .. py:method:: mean(a, axis=None) Computes the arithmetic mean of a tensor along given dimensions. This function follows the api from :any:`numpy.mean` See: https://numpy.org/doc/stable/reference/generated/numpy.mean.html .. py:method:: median(a, axis=None) Computes the median of a tensor along given dimensions. This function follows the api from :any:`numpy.median` See: https://numpy.org/doc/stable/reference/generated/numpy.median.html .. py:method:: std(a, axis=None) Computes the standard deviation of a tensor along given dimensions. This function follows the api from :any:`numpy.std` See: https://numpy.org/doc/stable/reference/generated/numpy.std.html .. py:method:: linspace(start, stop, num, type_as=None) Returns a specified number of evenly spaced values over a given interval. This function follows the api from :any:`numpy.linspace` See: https://numpy.org/doc/stable/reference/generated/numpy.linspace.html .. py:method:: meshgrid(a, b) Returns coordinate matrices from coordinate vectors (Numpy convention). This function follows the api from :any:`numpy.meshgrid` See: https://numpy.org/doc/stable/reference/generated/numpy.meshgrid.html .. py:method:: diag(a, k=0) Extracts or constructs a diagonal tensor. This function follows the api from :any:`numpy.diag` See: https://numpy.org/doc/stable/reference/generated/numpy.diag.html .. py:method:: unique(a, return_inverse=False) Finds unique elements of given tensor. This function follows the api from :any:`numpy.unique` See: https://numpy.org/doc/stable/reference/generated/numpy.unique.html .. py:method:: logsumexp(a, axis=None) Computes the log of the sum of exponentials of input elements. This function follows the api from :any:`scipy.special.logsumexp` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.logsumexp.html .. py:method:: stack(arrays, axis=0) Joins a sequence of tensors along a new dimension. This function follows the api from :any:`numpy.stack` See: https://numpy.org/doc/stable/reference/generated/numpy.stack.html .. py:method:: reshape(a, shape) Gives a new shape to a tensor without changing its data. This function follows the api from :any:`numpy.reshape` See: https://numpy.org/doc/stable/reference/generated/numpy.reshape.html .. py:method:: seed(seed=None) Sets the seed for the random generator. This function follows the api from :any:`numpy.random.seed` See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.seed.html .. py:method:: rand(*size, type_as=None) Generate uniform random numbers. This function follows the api from :any:`numpy.random.rand` See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.rand.html .. py:method:: randn(*size, type_as=None) Generate normal Gaussian random numbers. This function follows the api from :any:`numpy.random.rand` See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.rand.html .. py:method:: coo_matrix(data, rows, cols, shape=None, type_as=None) Creates a sparse tensor in COOrdinate format. This function follows the api from :any:`scipy.sparse.coo_matrix` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.html .. py:method:: issparse(a) Checks whether or not the input tensor is a sparse tensor. This function follows the api from :any:`scipy.sparse.issparse` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.issparse.html .. py:method:: tocsr(a) Converts this matrix to Compressed Sparse Row format. This function follows the api from :any:`scipy.sparse.coo_matrix.tocsr` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.tocsr.html .. py:method:: eliminate_zeros(a, threshold=0.0) Removes entries smaller than the given threshold from the sparse tensor. This function follows the api from :any:`scipy.sparse.csr_matrix.eliminate_zeros` See: https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.sparse.csr_matrix.eliminate_zeros.html .. py:method:: todense(a) Converts a sparse tensor to a dense tensor. This function follows the api from :any:`scipy.sparse.csr_matrix.toarray` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csr_matrix.toarray.html .. py:method:: where(condition, x=None, y=None) Returns elements chosen from x or y depending on condition. This function follows the api from :any:`numpy.where` See: https://numpy.org/doc/stable/reference/generated/numpy.where.html .. py:method:: copy(a) Returns a copy of the given tensor. This function follows the api from :any:`numpy.copy` See: https://numpy.org/doc/stable/reference/generated/numpy.copy.html .. py:method:: allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False) Returns True if two arrays are element-wise equal within a tolerance. This function follows the api from :any:`numpy.allclose` See: https://numpy.org/doc/stable/reference/generated/numpy.allclose.html .. py:method:: dtype_device(a) Returns the dtype and the device of the given tensor. .. py:method:: assert_same_dtype_device(a, b) Checks whether or not the two given inputs have the same dtype as well as the same device .. py:method:: squeeze(a, axis=None) Remove axes of length one from a. This function follows the api from :any:`numpy.squeeze`. See: https://numpy.org/doc/stable/reference/generated/numpy.squeeze.html .. py:method:: bitsize(type_as) Gives the number of bits used by the data type of the given tensor. .. py:method:: device_type(type_as) Returns CPU or GPU depending on the device where the given tensor is located. .. py:method:: _bench(callable, *args, n_runs=1, warmup_runs=1) Executes a benchmark of the given callable with the given arguments. .. py:method:: solve(a, b) Solves a linear matrix equation, or system of linear scalar equations. This function follows the api from :any:`numpy.linalg.solve`. See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.solve.html .. py:method:: trace(a) Returns the sum along diagonals of the array. This function follows the api from :any:`numpy.trace`. See: https://numpy.org/doc/stable/reference/generated/numpy.trace.html .. py:method:: inv(a) Computes the inverse of a matrix. This function follows the api from :any:`scipy.linalg.inv`. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.inv.html .. py:method:: sqrtm(a) Computes the matrix square root. Requires input to be definite positive. This function follows the api from :any:`scipy.linalg.sqrtm`. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.sqrtm.html .. py:method:: eigh(a) Computes the eigenvalues and eigenvectors of a symmetric tensor. This function follows the api from :any:`scipy.linalg.eigh`. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.eigh.html .. py:method:: kl_div(p, q, mass=False, eps=1e-16) Computes the (Generalized) Kullback-Leibler divergence. This function follows the api from :any:`scipy.stats.entropy`. Parameter eps is used to avoid numerical errors and is added in the log. .. math:: KL(p,q) = \langle \mathbf{p}, log(\mathbf{p} / \mathbf{q} + eps \rangle + \mathbb{1}_{mass=True} \langle \mathbf{q} - \mathbf{p}, \mathbf{1} \rangle See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.entropy.html .. py:method:: isfinite(a) Tests element-wise for finiteness (not infinity and not Not a Number). This function follows the api from :any:`numpy.isfinite`. See: https://numpy.org/doc/stable/reference/generated/numpy.isfinite.html .. py:method:: array_equal(a, b) True if two arrays have the same shape and elements, False otherwise. This function follows the api from :any:`numpy.array_equal`. See: https://numpy.org/doc/stable/reference/generated/numpy.array_equal.html .. py:method:: is_floating_point(a) Returns whether or not the input consists of floats .. py:method:: tile(a, reps) Construct an array by repeating a the number of times given by reps See: https://numpy.org/doc/stable/reference/generated/numpy.tile.html .. py:method:: floor(a) Return the floor of the input element-wise See: https://numpy.org/doc/stable/reference/generated/numpy.floor.html .. py:method:: prod(a, axis=0) Return the product of all elements. See: https://numpy.org/doc/stable/reference/generated/numpy.prod.html .. py:method:: sort2(a, axis=-1) Return the sorted array and the indices to sort the array See: https://pytorch.org/docs/stable/generated/torch.sort.html .. py:method:: qr(a) Return the QR factorization See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.qr.html .. py:method:: atan2(a, b) Element wise arctangent See: https://numpy.org/doc/stable/reference/generated/numpy.arctan2.html .. py:method:: transpose(a, axes=None) Returns a tensor that is a transposed version of a. The given dimensions dim0 and dim1 are swapped. See: https://numpy.org/doc/stable/reference/generated/numpy.transpose.html .. py:method:: matmul(a, b) Matrix product of two arrays. See: https://numpy.org/doc/stable/reference/generated/numpy.matmul.html#numpy.matmul .. py:method:: nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None) Replace NaN with zero and infinity with large finite numbers or with the numbers defined by the user. See: https://numpy.org/doc/stable/reference/generated/numpy.nan_to_num.html#numpy.nan_to_num .. py:class:: JaxBackend Bases: :py:obj:`Backend` JAX implementation of the backend - `__name__` is "jax" - `__type__` is jax.numpy.ndarray .. py:attribute:: __name__ :value: 'jax' .. py:attribute:: __type__ .. py:attribute:: __type_list__ :value: None .. py:attribute:: rng_ :value: None .. py:attribute:: jax_new_version .. py:method:: _to_numpy(a) Returns the numpy version of a tensor .. py:method:: _get_device(a) .. py:method:: _change_device(a, type_as) .. py:method:: _from_numpy(a, type_as=None) Creates a tensor cloning a numpy array, with the given precision (defaulting to input's precision) and the given device (in case of GPUs) .. py:method:: set_gradients(val, inputs, grads) Define the gradients for the value val wrt the inputs .. py:method:: _detach(a) Detach the tensor from the computation graph .. py:method:: zeros(shape, type_as=None) Creates a tensor full of zeros. This function follows the api from :any:`numpy.zeros` See: https://numpy.org/doc/stable/reference/generated/numpy.zeros.html .. py:method:: ones(shape, type_as=None) Creates a tensor full of ones. This function follows the api from :any:`numpy.ones` See: https://numpy.org/doc/stable/reference/generated/numpy.ones.html .. py:method:: arange(stop, start=0, step=1, type_as=None) Returns evenly spaced values within a given interval. This function follows the api from :any:`numpy.arange` See: https://numpy.org/doc/stable/reference/generated/numpy.arange.html .. py:method:: full(shape, fill_value, type_as=None) Creates a tensor with given shape, filled with given value. This function follows the api from :any:`numpy.full` See: https://numpy.org/doc/stable/reference/generated/numpy.full.html .. py:method:: eye(N, M=None, type_as=None) Creates the identity matrix of given size. This function follows the api from :any:`numpy.eye` See: https://numpy.org/doc/stable/reference/generated/numpy.eye.html .. py:method:: sum(a, axis=None, keepdims=False) Sums tensor elements over given dimensions. This function follows the api from :any:`numpy.sum` See: https://numpy.org/doc/stable/reference/generated/numpy.sum.html .. py:method:: cumsum(a, axis=None) Returns the cumulative sum of tensor elements over given dimensions. This function follows the api from :any:`numpy.cumsum` See: https://numpy.org/doc/stable/reference/generated/numpy.cumsum.html .. py:method:: max(a, axis=None, keepdims=False) Returns the maximum of an array or maximum along given dimensions. This function follows the api from :any:`numpy.amax` See: https://numpy.org/doc/stable/reference/generated/numpy.amax.html .. py:method:: min(a, axis=None, keepdims=False) Returns the maximum of an array or maximum along given dimensions. This function follows the api from :any:`numpy.amin` See: https://numpy.org/doc/stable/reference/generated/numpy.amin.html .. py:method:: maximum(a, b) Returns element-wise maximum of array elements. This function follows the api from :any:`numpy.maximum` See: https://numpy.org/doc/stable/reference/generated/numpy.maximum.html .. py:method:: minimum(a, b) Returns element-wise minimum of array elements. This function follows the api from :any:`numpy.minimum` See: https://numpy.org/doc/stable/reference/generated/numpy.minimum.html .. py:method:: sign(a) Returns an element-wise indication of the sign of a number. This function follows the api from :any:`numpy.sign` See: https://numpy.org/doc/stable/reference/generated/numpy.sign.html .. py:method:: dot(a, b) Returns the dot product of two tensors. This function follows the api from :any:`numpy.dot` See: https://numpy.org/doc/stable/reference/generated/numpy.dot.html .. py:method:: abs(a) Computes the absolute value element-wise. This function follows the api from :any:`numpy.absolute` See: https://numpy.org/doc/stable/reference/generated/numpy.absolute.html .. py:method:: exp(a) Computes the exponential value element-wise. This function follows the api from :any:`numpy.exp` See: https://numpy.org/doc/stable/reference/generated/numpy.exp.html .. py:method:: log(a) Computes the natural logarithm, element-wise. This function follows the api from :any:`numpy.log` See: https://numpy.org/doc/stable/reference/generated/numpy.log.html .. py:method:: sqrt(a) Returns the non-ngeative square root of a tensor, element-wise. This function follows the api from :any:`numpy.sqrt` See: https://numpy.org/doc/stable/reference/generated/numpy.sqrt.html .. py:method:: power(a, exponents) First tensor elements raised to powers from second tensor, element-wise. This function follows the api from :any:`numpy.power` See: https://numpy.org/doc/stable/reference/generated/numpy.power.html .. py:method:: norm(a, axis=None, keepdims=False) Computes the matrix frobenius norm. This function follows the api from :any:`numpy.linalg.norm` See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.norm.html .. py:method:: any(a) Tests whether any tensor element along given dimensions evaluates to True. This function follows the api from :any:`numpy.any` See: https://numpy.org/doc/stable/reference/generated/numpy.any.html .. py:method:: isnan(a) Tests element-wise for NaN and returns result as a boolean tensor. This function follows the api from :any:`numpy.isnan` See: https://numpy.org/doc/stable/reference/generated/numpy.isnan.html .. py:method:: isinf(a) Tests element-wise for positive or negative infinity and returns result as a boolean tensor. This function follows the api from :any:`numpy.isinf` See: https://numpy.org/doc/stable/reference/generated/numpy.isinf.html .. py:method:: einsum(subscripts, *operands) Evaluates the Einstein summation convention on the operands. This function follows the api from :any:`numpy.einsum` See: https://numpy.org/doc/stable/reference/generated/numpy.einsum.html .. py:method:: sort(a, axis=-1) Returns a sorted copy of a tensor. This function follows the api from :any:`numpy.sort` See: https://numpy.org/doc/stable/reference/generated/numpy.sort.html .. py:method:: argsort(a, axis=-1) Returns the indices that would sort a tensor. This function follows the api from :any:`numpy.argsort` See: https://numpy.org/doc/stable/reference/generated/numpy.argsort.html .. py:method:: searchsorted(a, v, side='left') Finds indices where elements should be inserted to maintain order in given tensor. This function follows the api from :any:`numpy.searchsorted` See: https://numpy.org/doc/stable/reference/generated/numpy.searchsorted.html .. py:method:: flip(a, axis=None) Reverses the order of elements in a tensor along given dimensions. This function follows the api from :any:`numpy.flip` See: https://numpy.org/doc/stable/reference/generated/numpy.flip.html .. py:method:: outer(a, b) Computes the outer product between two vectors. This function follows the api from :any:`numpy.outer` See: https://numpy.org/doc/stable/reference/generated/numpy.outer.html .. py:method:: clip(a, a_min, a_max) Limits the values in a tensor. This function follows the api from :any:`numpy.clip` See: https://numpy.org/doc/stable/reference/generated/numpy.clip.html .. py:method:: repeat(a, repeats, axis=None) Repeats elements of a tensor. This function follows the api from :any:`numpy.repeat` See: https://numpy.org/doc/stable/reference/generated/numpy.repeat.html .. py:method:: take_along_axis(arr, indices, axis) Gathers elements of a tensor along given dimensions. This function follows the api from :any:`numpy.take_along_axis` See: https://numpy.org/doc/stable/reference/generated/numpy.take_along_axis.html .. py:method:: concatenate(arrays, axis=0) Joins a sequence of tensors along an existing dimension. This function follows the api from :any:`numpy.concatenate` See: https://numpy.org/doc/stable/reference/generated/numpy.concatenate.html .. py:method:: zero_pad(a, pad_width, value=0) Pads a tensor with a given value (0 by default). This function follows the api from :any:`numpy.pad` See: https://numpy.org/doc/stable/reference/generated/numpy.pad.html .. py:method:: argmax(a, axis=None) Returns the indices of the maximum values of a tensor along given dimensions. This function follows the api from :any:`numpy.argmax` See: https://numpy.org/doc/stable/reference/generated/numpy.argmax.html .. py:method:: argmin(a, axis=None) Returns the indices of the minimum values of a tensor along given dimensions. This function follows the api from :any:`numpy.argmin` See: https://numpy.org/doc/stable/reference/generated/numpy.argmin.html .. py:method:: mean(a, axis=None) Computes the arithmetic mean of a tensor along given dimensions. This function follows the api from :any:`numpy.mean` See: https://numpy.org/doc/stable/reference/generated/numpy.mean.html .. py:method:: median(a, axis=None) Computes the median of a tensor along given dimensions. This function follows the api from :any:`numpy.median` See: https://numpy.org/doc/stable/reference/generated/numpy.median.html .. py:method:: std(a, axis=None) Computes the standard deviation of a tensor along given dimensions. This function follows the api from :any:`numpy.std` See: https://numpy.org/doc/stable/reference/generated/numpy.std.html .. py:method:: linspace(start, stop, num, type_as=None) Returns a specified number of evenly spaced values over a given interval. This function follows the api from :any:`numpy.linspace` See: https://numpy.org/doc/stable/reference/generated/numpy.linspace.html .. py:method:: meshgrid(a, b) Returns coordinate matrices from coordinate vectors (Numpy convention). This function follows the api from :any:`numpy.meshgrid` See: https://numpy.org/doc/stable/reference/generated/numpy.meshgrid.html .. py:method:: diag(a, k=0) Extracts or constructs a diagonal tensor. This function follows the api from :any:`numpy.diag` See: https://numpy.org/doc/stable/reference/generated/numpy.diag.html .. py:method:: unique(a, return_inverse=False) Finds unique elements of given tensor. This function follows the api from :any:`numpy.unique` See: https://numpy.org/doc/stable/reference/generated/numpy.unique.html .. py:method:: logsumexp(a, axis=None) Computes the log of the sum of exponentials of input elements. This function follows the api from :any:`scipy.special.logsumexp` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.logsumexp.html .. py:method:: stack(arrays, axis=0) Joins a sequence of tensors along a new dimension. This function follows the api from :any:`numpy.stack` See: https://numpy.org/doc/stable/reference/generated/numpy.stack.html .. py:method:: reshape(a, shape) Gives a new shape to a tensor without changing its data. This function follows the api from :any:`numpy.reshape` See: https://numpy.org/doc/stable/reference/generated/numpy.reshape.html .. py:method:: seed(seed=None) Sets the seed for the random generator. This function follows the api from :any:`numpy.random.seed` See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.seed.html .. py:method:: rand(*size, type_as=None) Generate uniform random numbers. This function follows the api from :any:`numpy.random.rand` See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.rand.html .. py:method:: randn(*size, type_as=None) Generate normal Gaussian random numbers. This function follows the api from :any:`numpy.random.rand` See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.rand.html .. py:method:: coo_matrix(data, rows, cols, shape=None, type_as=None) Creates a sparse tensor in COOrdinate format. This function follows the api from :any:`scipy.sparse.coo_matrix` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.html .. py:method:: issparse(a) Checks whether or not the input tensor is a sparse tensor. This function follows the api from :any:`scipy.sparse.issparse` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.issparse.html .. py:method:: tocsr(a) Converts this matrix to Compressed Sparse Row format. This function follows the api from :any:`scipy.sparse.coo_matrix.tocsr` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.tocsr.html .. py:method:: eliminate_zeros(a, threshold=0.0) Removes entries smaller than the given threshold from the sparse tensor. This function follows the api from :any:`scipy.sparse.csr_matrix.eliminate_zeros` See: https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.sparse.csr_matrix.eliminate_zeros.html .. py:method:: todense(a) Converts a sparse tensor to a dense tensor. This function follows the api from :any:`scipy.sparse.csr_matrix.toarray` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csr_matrix.toarray.html .. py:method:: where(condition, x=None, y=None) Returns elements chosen from x or y depending on condition. This function follows the api from :any:`numpy.where` See: https://numpy.org/doc/stable/reference/generated/numpy.where.html .. py:method:: copy(a) Returns a copy of the given tensor. This function follows the api from :any:`numpy.copy` See: https://numpy.org/doc/stable/reference/generated/numpy.copy.html .. py:method:: allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False) Returns True if two arrays are element-wise equal within a tolerance. This function follows the api from :any:`numpy.allclose` See: https://numpy.org/doc/stable/reference/generated/numpy.allclose.html .. py:method:: dtype_device(a) Returns the dtype and the device of the given tensor. .. py:method:: assert_same_dtype_device(a, b) Checks whether or not the two given inputs have the same dtype as well as the same device .. py:method:: squeeze(a, axis=None) Remove axes of length one from a. This function follows the api from :any:`numpy.squeeze`. See: https://numpy.org/doc/stable/reference/generated/numpy.squeeze.html .. py:method:: bitsize(type_as) Gives the number of bits used by the data type of the given tensor. .. py:method:: device_type(type_as) Returns CPU or GPU depending on the device where the given tensor is located. .. py:method:: _bench(callable, *args, n_runs=1, warmup_runs=1) Executes a benchmark of the given callable with the given arguments. .. py:method:: solve(a, b) Solves a linear matrix equation, or system of linear scalar equations. This function follows the api from :any:`numpy.linalg.solve`. See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.solve.html .. py:method:: trace(a) Returns the sum along diagonals of the array. This function follows the api from :any:`numpy.trace`. See: https://numpy.org/doc/stable/reference/generated/numpy.trace.html .. py:method:: inv(a) Computes the inverse of a matrix. This function follows the api from :any:`scipy.linalg.inv`. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.inv.html .. py:method:: sqrtm(a) Computes the matrix square root. Requires input to be definite positive. This function follows the api from :any:`scipy.linalg.sqrtm`. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.sqrtm.html .. py:method:: eigh(a) Computes the eigenvalues and eigenvectors of a symmetric tensor. This function follows the api from :any:`scipy.linalg.eigh`. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.eigh.html .. py:method:: kl_div(p, q, mass=False, eps=1e-16) Computes the (Generalized) Kullback-Leibler divergence. This function follows the api from :any:`scipy.stats.entropy`. Parameter eps is used to avoid numerical errors and is added in the log. .. math:: KL(p,q) = \langle \mathbf{p}, log(\mathbf{p} / \mathbf{q} + eps \rangle + \mathbb{1}_{mass=True} \langle \mathbf{q} - \mathbf{p}, \mathbf{1} \rangle See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.entropy.html .. py:method:: isfinite(a) Tests element-wise for finiteness (not infinity and not Not a Number). This function follows the api from :any:`numpy.isfinite`. See: https://numpy.org/doc/stable/reference/generated/numpy.isfinite.html .. py:method:: array_equal(a, b) True if two arrays have the same shape and elements, False otherwise. This function follows the api from :any:`numpy.array_equal`. See: https://numpy.org/doc/stable/reference/generated/numpy.array_equal.html .. py:method:: is_floating_point(a) Returns whether or not the input consists of floats .. py:method:: tile(a, reps) Construct an array by repeating a the number of times given by reps See: https://numpy.org/doc/stable/reference/generated/numpy.tile.html .. py:method:: floor(a) Return the floor of the input element-wise See: https://numpy.org/doc/stable/reference/generated/numpy.floor.html .. py:method:: prod(a, axis=0) Return the product of all elements. See: https://numpy.org/doc/stable/reference/generated/numpy.prod.html .. py:method:: sort2(a, axis=-1) Return the sorted array and the indices to sort the array See: https://pytorch.org/docs/stable/generated/torch.sort.html .. py:method:: qr(a) Return the QR factorization See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.qr.html .. py:method:: atan2(a, b) Element wise arctangent See: https://numpy.org/doc/stable/reference/generated/numpy.arctan2.html .. py:method:: transpose(a, axes=None) Returns a tensor that is a transposed version of a. The given dimensions dim0 and dim1 are swapped. See: https://numpy.org/doc/stable/reference/generated/numpy.transpose.html .. py:method:: matmul(a, b) Matrix product of two arrays. See: https://numpy.org/doc/stable/reference/generated/numpy.matmul.html#numpy.matmul .. py:method:: nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None) Replace NaN with zero and infinity with large finite numbers or with the numbers defined by the user. See: https://numpy.org/doc/stable/reference/generated/numpy.nan_to_num.html#numpy.nan_to_num .. py:class:: TorchBackend Bases: :py:obj:`Backend` PyTorch implementation of the backend - `__name__` is "torch" - `__type__` is torch.Tensor .. py:attribute:: __name__ :value: 'torch' .. py:attribute:: __type__ .. py:attribute:: __type_list__ :value: None .. py:attribute:: rng_ :value: None .. py:attribute:: ValFunction .. py:method:: _to_numpy(a) Returns the numpy version of a tensor .. py:method:: _from_numpy(a, type_as=None) Creates a tensor cloning a numpy array, with the given precision (defaulting to input's precision) and the given device (in case of GPUs) .. py:method:: set_gradients(val, inputs, grads) Define the gradients for the value val wrt the inputs .. py:method:: _detach(a) Detach the tensor from the computation graph .. py:method:: zeros(shape, type_as=None) Creates a tensor full of zeros. This function follows the api from :any:`numpy.zeros` See: https://numpy.org/doc/stable/reference/generated/numpy.zeros.html .. py:method:: ones(shape, type_as=None) Creates a tensor full of ones. This function follows the api from :any:`numpy.ones` See: https://numpy.org/doc/stable/reference/generated/numpy.ones.html .. py:method:: arange(stop, start=0, step=1, type_as=None) Returns evenly spaced values within a given interval. This function follows the api from :any:`numpy.arange` See: https://numpy.org/doc/stable/reference/generated/numpy.arange.html .. py:method:: full(shape, fill_value, type_as=None) Creates a tensor with given shape, filled with given value. This function follows the api from :any:`numpy.full` See: https://numpy.org/doc/stable/reference/generated/numpy.full.html .. py:method:: eye(N, M=None, type_as=None) Creates the identity matrix of given size. This function follows the api from :any:`numpy.eye` See: https://numpy.org/doc/stable/reference/generated/numpy.eye.html .. py:method:: sum(a, axis=None, keepdims=False) Sums tensor elements over given dimensions. This function follows the api from :any:`numpy.sum` See: https://numpy.org/doc/stable/reference/generated/numpy.sum.html .. py:method:: cumsum(a, axis=None) Returns the cumulative sum of tensor elements over given dimensions. This function follows the api from :any:`numpy.cumsum` See: https://numpy.org/doc/stable/reference/generated/numpy.cumsum.html .. py:method:: max(a, axis=None, keepdims=False) Returns the maximum of an array or maximum along given dimensions. This function follows the api from :any:`numpy.amax` See: https://numpy.org/doc/stable/reference/generated/numpy.amax.html .. py:method:: min(a, axis=None, keepdims=False) Returns the maximum of an array or maximum along given dimensions. This function follows the api from :any:`numpy.amin` See: https://numpy.org/doc/stable/reference/generated/numpy.amin.html .. py:method:: maximum(a, b) Returns element-wise maximum of array elements. This function follows the api from :any:`numpy.maximum` See: https://numpy.org/doc/stable/reference/generated/numpy.maximum.html .. py:method:: minimum(a, b) Returns element-wise minimum of array elements. This function follows the api from :any:`numpy.minimum` See: https://numpy.org/doc/stable/reference/generated/numpy.minimum.html .. py:method:: sign(a) Returns an element-wise indication of the sign of a number. This function follows the api from :any:`numpy.sign` See: https://numpy.org/doc/stable/reference/generated/numpy.sign.html .. py:method:: dot(a, b) Returns the dot product of two tensors. This function follows the api from :any:`numpy.dot` See: https://numpy.org/doc/stable/reference/generated/numpy.dot.html .. py:method:: abs(a) Computes the absolute value element-wise. This function follows the api from :any:`numpy.absolute` See: https://numpy.org/doc/stable/reference/generated/numpy.absolute.html .. py:method:: exp(a) Computes the exponential value element-wise. This function follows the api from :any:`numpy.exp` See: https://numpy.org/doc/stable/reference/generated/numpy.exp.html .. py:method:: log(a) Computes the natural logarithm, element-wise. This function follows the api from :any:`numpy.log` See: https://numpy.org/doc/stable/reference/generated/numpy.log.html .. py:method:: sqrt(a) Returns the non-ngeative square root of a tensor, element-wise. This function follows the api from :any:`numpy.sqrt` See: https://numpy.org/doc/stable/reference/generated/numpy.sqrt.html .. py:method:: power(a, exponents) First tensor elements raised to powers from second tensor, element-wise. This function follows the api from :any:`numpy.power` See: https://numpy.org/doc/stable/reference/generated/numpy.power.html .. py:method:: norm(a, axis=None, keepdims=False) Computes the matrix frobenius norm. This function follows the api from :any:`numpy.linalg.norm` See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.norm.html .. py:method:: any(a) Tests whether any tensor element along given dimensions evaluates to True. This function follows the api from :any:`numpy.any` See: https://numpy.org/doc/stable/reference/generated/numpy.any.html .. py:method:: isnan(a) Tests element-wise for NaN and returns result as a boolean tensor. This function follows the api from :any:`numpy.isnan` See: https://numpy.org/doc/stable/reference/generated/numpy.isnan.html .. py:method:: isinf(a) Tests element-wise for positive or negative infinity and returns result as a boolean tensor. This function follows the api from :any:`numpy.isinf` See: https://numpy.org/doc/stable/reference/generated/numpy.isinf.html .. py:method:: einsum(subscripts, *operands) Evaluates the Einstein summation convention on the operands. This function follows the api from :any:`numpy.einsum` See: https://numpy.org/doc/stable/reference/generated/numpy.einsum.html .. py:method:: sort(a, axis=-1) Returns a sorted copy of a tensor. This function follows the api from :any:`numpy.sort` See: https://numpy.org/doc/stable/reference/generated/numpy.sort.html .. py:method:: argsort(a, axis=-1) Returns the indices that would sort a tensor. This function follows the api from :any:`numpy.argsort` See: https://numpy.org/doc/stable/reference/generated/numpy.argsort.html .. py:method:: searchsorted(a, v, side='left') Finds indices where elements should be inserted to maintain order in given tensor. This function follows the api from :any:`numpy.searchsorted` See: https://numpy.org/doc/stable/reference/generated/numpy.searchsorted.html .. py:method:: flip(a, axis=None) Reverses the order of elements in a tensor along given dimensions. This function follows the api from :any:`numpy.flip` See: https://numpy.org/doc/stable/reference/generated/numpy.flip.html .. py:method:: outer(a, b) Computes the outer product between two vectors. This function follows the api from :any:`numpy.outer` See: https://numpy.org/doc/stable/reference/generated/numpy.outer.html .. py:method:: clip(a, a_min, a_max) Limits the values in a tensor. This function follows the api from :any:`numpy.clip` See: https://numpy.org/doc/stable/reference/generated/numpy.clip.html .. py:method:: repeat(a, repeats, axis=None) Repeats elements of a tensor. This function follows the api from :any:`numpy.repeat` See: https://numpy.org/doc/stable/reference/generated/numpy.repeat.html .. py:method:: take_along_axis(arr, indices, axis) Gathers elements of a tensor along given dimensions. This function follows the api from :any:`numpy.take_along_axis` See: https://numpy.org/doc/stable/reference/generated/numpy.take_along_axis.html .. py:method:: concatenate(arrays, axis=0) Joins a sequence of tensors along an existing dimension. This function follows the api from :any:`numpy.concatenate` See: https://numpy.org/doc/stable/reference/generated/numpy.concatenate.html .. py:method:: zero_pad(a, pad_width, value=0) Pads a tensor with a given value (0 by default). This function follows the api from :any:`numpy.pad` See: https://numpy.org/doc/stable/reference/generated/numpy.pad.html .. py:method:: argmax(a, axis=None) Returns the indices of the maximum values of a tensor along given dimensions. This function follows the api from :any:`numpy.argmax` See: https://numpy.org/doc/stable/reference/generated/numpy.argmax.html .. py:method:: argmin(a, axis=None) Returns the indices of the minimum values of a tensor along given dimensions. This function follows the api from :any:`numpy.argmin` See: https://numpy.org/doc/stable/reference/generated/numpy.argmin.html .. py:method:: mean(a, axis=None) Computes the arithmetic mean of a tensor along given dimensions. This function follows the api from :any:`numpy.mean` See: https://numpy.org/doc/stable/reference/generated/numpy.mean.html .. py:method:: median(a, axis=None) Computes the median of a tensor along given dimensions. This function follows the api from :any:`numpy.median` See: https://numpy.org/doc/stable/reference/generated/numpy.median.html .. py:method:: std(a, axis=None) Computes the standard deviation of a tensor along given dimensions. This function follows the api from :any:`numpy.std` See: https://numpy.org/doc/stable/reference/generated/numpy.std.html .. py:method:: linspace(start, stop, num, type_as=None) Returns a specified number of evenly spaced values over a given interval. This function follows the api from :any:`numpy.linspace` See: https://numpy.org/doc/stable/reference/generated/numpy.linspace.html .. py:method:: meshgrid(a, b) Returns coordinate matrices from coordinate vectors (Numpy convention). This function follows the api from :any:`numpy.meshgrid` See: https://numpy.org/doc/stable/reference/generated/numpy.meshgrid.html .. py:method:: diag(a, k=0) Extracts or constructs a diagonal tensor. This function follows the api from :any:`numpy.diag` See: https://numpy.org/doc/stable/reference/generated/numpy.diag.html .. py:method:: unique(a, return_inverse=False) Finds unique elements of given tensor. This function follows the api from :any:`numpy.unique` See: https://numpy.org/doc/stable/reference/generated/numpy.unique.html .. py:method:: logsumexp(a, axis=None) Computes the log of the sum of exponentials of input elements. This function follows the api from :any:`scipy.special.logsumexp` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.logsumexp.html .. py:method:: stack(arrays, axis=0) Joins a sequence of tensors along a new dimension. This function follows the api from :any:`numpy.stack` See: https://numpy.org/doc/stable/reference/generated/numpy.stack.html .. py:method:: reshape(a, shape) Gives a new shape to a tensor without changing its data. This function follows the api from :any:`numpy.reshape` See: https://numpy.org/doc/stable/reference/generated/numpy.reshape.html .. py:method:: seed(seed=None) Sets the seed for the random generator. This function follows the api from :any:`numpy.random.seed` See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.seed.html .. py:method:: rand(*size, type_as=None) Generate uniform random numbers. This function follows the api from :any:`numpy.random.rand` See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.rand.html .. py:method:: randn(*size, type_as=None) Generate normal Gaussian random numbers. This function follows the api from :any:`numpy.random.rand` See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.rand.html .. py:method:: coo_matrix(data, rows, cols, shape=None, type_as=None) Creates a sparse tensor in COOrdinate format. This function follows the api from :any:`scipy.sparse.coo_matrix` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.html .. py:method:: issparse(a) Checks whether or not the input tensor is a sparse tensor. This function follows the api from :any:`scipy.sparse.issparse` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.issparse.html .. py:method:: tocsr(a) Converts this matrix to Compressed Sparse Row format. This function follows the api from :any:`scipy.sparse.coo_matrix.tocsr` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.tocsr.html .. py:method:: eliminate_zeros(a, threshold=0.0) Removes entries smaller than the given threshold from the sparse tensor. This function follows the api from :any:`scipy.sparse.csr_matrix.eliminate_zeros` See: https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.sparse.csr_matrix.eliminate_zeros.html .. py:method:: todense(a) Converts a sparse tensor to a dense tensor. This function follows the api from :any:`scipy.sparse.csr_matrix.toarray` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csr_matrix.toarray.html .. py:method:: where(condition, x=None, y=None) Returns elements chosen from x or y depending on condition. This function follows the api from :any:`numpy.where` See: https://numpy.org/doc/stable/reference/generated/numpy.where.html .. py:method:: copy(a) Returns a copy of the given tensor. This function follows the api from :any:`numpy.copy` See: https://numpy.org/doc/stable/reference/generated/numpy.copy.html .. py:method:: allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False) Returns True if two arrays are element-wise equal within a tolerance. This function follows the api from :any:`numpy.allclose` See: https://numpy.org/doc/stable/reference/generated/numpy.allclose.html .. py:method:: dtype_device(a) Returns the dtype and the device of the given tensor. .. py:method:: assert_same_dtype_device(a, b) Checks whether or not the two given inputs have the same dtype as well as the same device .. py:method:: squeeze(a, axis=None) Remove axes of length one from a. This function follows the api from :any:`numpy.squeeze`. See: https://numpy.org/doc/stable/reference/generated/numpy.squeeze.html .. py:method:: bitsize(type_as) Gives the number of bits used by the data type of the given tensor. .. py:method:: device_type(type_as) Returns CPU or GPU depending on the device where the given tensor is located. .. py:method:: _bench(callable, *args, n_runs=1, warmup_runs=1) Executes a benchmark of the given callable with the given arguments. .. py:method:: solve(a, b) Solves a linear matrix equation, or system of linear scalar equations. This function follows the api from :any:`numpy.linalg.solve`. See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.solve.html .. py:method:: trace(a) Returns the sum along diagonals of the array. This function follows the api from :any:`numpy.trace`. See: https://numpy.org/doc/stable/reference/generated/numpy.trace.html .. py:method:: inv(a) Computes the inverse of a matrix. This function follows the api from :any:`scipy.linalg.inv`. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.inv.html .. py:method:: sqrtm(a) Computes the matrix square root. Requires input to be definite positive. This function follows the api from :any:`scipy.linalg.sqrtm`. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.sqrtm.html .. py:method:: eigh(a) Computes the eigenvalues and eigenvectors of a symmetric tensor. This function follows the api from :any:`scipy.linalg.eigh`. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.eigh.html .. py:method:: kl_div(p, q, mass=False, eps=1e-16) Computes the (Generalized) Kullback-Leibler divergence. This function follows the api from :any:`scipy.stats.entropy`. Parameter eps is used to avoid numerical errors and is added in the log. .. math:: KL(p,q) = \langle \mathbf{p}, log(\mathbf{p} / \mathbf{q} + eps \rangle + \mathbb{1}_{mass=True} \langle \mathbf{q} - \mathbf{p}, \mathbf{1} \rangle See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.entropy.html .. py:method:: isfinite(a) Tests element-wise for finiteness (not infinity and not Not a Number). This function follows the api from :any:`numpy.isfinite`. See: https://numpy.org/doc/stable/reference/generated/numpy.isfinite.html .. py:method:: array_equal(a, b) True if two arrays have the same shape and elements, False otherwise. This function follows the api from :any:`numpy.array_equal`. See: https://numpy.org/doc/stable/reference/generated/numpy.array_equal.html .. py:method:: is_floating_point(a) Returns whether or not the input consists of floats .. py:method:: tile(a, reps) Construct an array by repeating a the number of times given by reps See: https://numpy.org/doc/stable/reference/generated/numpy.tile.html .. py:method:: floor(a) Return the floor of the input element-wise See: https://numpy.org/doc/stable/reference/generated/numpy.floor.html .. py:method:: prod(a, axis=0) Return the product of all elements. See: https://numpy.org/doc/stable/reference/generated/numpy.prod.html .. py:method:: sort2(a, axis=-1) Return the sorted array and the indices to sort the array See: https://pytorch.org/docs/stable/generated/torch.sort.html .. py:method:: qr(a) Return the QR factorization See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.qr.html .. py:method:: atan2(a, b) Element wise arctangent See: https://numpy.org/doc/stable/reference/generated/numpy.arctan2.html .. py:method:: transpose(a, axes=None) Returns a tensor that is a transposed version of a. The given dimensions dim0 and dim1 are swapped. See: https://numpy.org/doc/stable/reference/generated/numpy.transpose.html .. py:method:: matmul(a, b) Matrix product of two arrays. See: https://numpy.org/doc/stable/reference/generated/numpy.matmul.html#numpy.matmul .. py:method:: nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None) Replace NaN with zero and infinity with large finite numbers or with the numbers defined by the user. See: https://numpy.org/doc/stable/reference/generated/numpy.nan_to_num.html#numpy.nan_to_num .. py:class:: CupyBackend Bases: :py:obj:`Backend` CuPy implementation of the backend - `__name__` is "cupy" - `__type__` is cp.ndarray .. py:attribute:: __name__ :value: 'cupy' .. py:attribute:: __type__ .. py:attribute:: __type_list__ :value: None .. py:attribute:: rng_ :value: None .. py:method:: _to_numpy(a) Returns the numpy version of a tensor .. py:method:: _from_numpy(a, type_as=None) Creates a tensor cloning a numpy array, with the given precision (defaulting to input's precision) and the given device (in case of GPUs) .. py:method:: set_gradients(val, inputs, grads) Define the gradients for the value val wrt the inputs .. py:method:: _detach(a) Detach the tensor from the computation graph .. py:method:: zeros(shape, type_as=None) Creates a tensor full of zeros. This function follows the api from :any:`numpy.zeros` See: https://numpy.org/doc/stable/reference/generated/numpy.zeros.html .. py:method:: ones(shape, type_as=None) Creates a tensor full of ones. This function follows the api from :any:`numpy.ones` See: https://numpy.org/doc/stable/reference/generated/numpy.ones.html .. py:method:: arange(stop, start=0, step=1, type_as=None) Returns evenly spaced values within a given interval. This function follows the api from :any:`numpy.arange` See: https://numpy.org/doc/stable/reference/generated/numpy.arange.html .. py:method:: full(shape, fill_value, type_as=None) Creates a tensor with given shape, filled with given value. This function follows the api from :any:`numpy.full` See: https://numpy.org/doc/stable/reference/generated/numpy.full.html .. py:method:: eye(N, M=None, type_as=None) Creates the identity matrix of given size. This function follows the api from :any:`numpy.eye` See: https://numpy.org/doc/stable/reference/generated/numpy.eye.html .. py:method:: sum(a, axis=None, keepdims=False) Sums tensor elements over given dimensions. This function follows the api from :any:`numpy.sum` See: https://numpy.org/doc/stable/reference/generated/numpy.sum.html .. py:method:: cumsum(a, axis=None) Returns the cumulative sum of tensor elements over given dimensions. This function follows the api from :any:`numpy.cumsum` See: https://numpy.org/doc/stable/reference/generated/numpy.cumsum.html .. py:method:: max(a, axis=None, keepdims=False) Returns the maximum of an array or maximum along given dimensions. This function follows the api from :any:`numpy.amax` See: https://numpy.org/doc/stable/reference/generated/numpy.amax.html .. py:method:: min(a, axis=None, keepdims=False) Returns the maximum of an array or maximum along given dimensions. This function follows the api from :any:`numpy.amin` See: https://numpy.org/doc/stable/reference/generated/numpy.amin.html .. py:method:: maximum(a, b) Returns element-wise maximum of array elements. This function follows the api from :any:`numpy.maximum` See: https://numpy.org/doc/stable/reference/generated/numpy.maximum.html .. py:method:: minimum(a, b) Returns element-wise minimum of array elements. This function follows the api from :any:`numpy.minimum` See: https://numpy.org/doc/stable/reference/generated/numpy.minimum.html .. py:method:: sign(a) Returns an element-wise indication of the sign of a number. This function follows the api from :any:`numpy.sign` See: https://numpy.org/doc/stable/reference/generated/numpy.sign.html .. py:method:: abs(a) Computes the absolute value element-wise. This function follows the api from :any:`numpy.absolute` See: https://numpy.org/doc/stable/reference/generated/numpy.absolute.html .. py:method:: exp(a) Computes the exponential value element-wise. This function follows the api from :any:`numpy.exp` See: https://numpy.org/doc/stable/reference/generated/numpy.exp.html .. py:method:: log(a) Computes the natural logarithm, element-wise. This function follows the api from :any:`numpy.log` See: https://numpy.org/doc/stable/reference/generated/numpy.log.html .. py:method:: sqrt(a) Returns the non-ngeative square root of a tensor, element-wise. This function follows the api from :any:`numpy.sqrt` See: https://numpy.org/doc/stable/reference/generated/numpy.sqrt.html .. py:method:: power(a, exponents) First tensor elements raised to powers from second tensor, element-wise. This function follows the api from :any:`numpy.power` See: https://numpy.org/doc/stable/reference/generated/numpy.power.html .. py:method:: dot(a, b) Returns the dot product of two tensors. This function follows the api from :any:`numpy.dot` See: https://numpy.org/doc/stable/reference/generated/numpy.dot.html .. py:method:: norm(a, axis=None, keepdims=False) Computes the matrix frobenius norm. This function follows the api from :any:`numpy.linalg.norm` See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.norm.html .. py:method:: any(a) Tests whether any tensor element along given dimensions evaluates to True. This function follows the api from :any:`numpy.any` See: https://numpy.org/doc/stable/reference/generated/numpy.any.html .. py:method:: isnan(a) Tests element-wise for NaN and returns result as a boolean tensor. This function follows the api from :any:`numpy.isnan` See: https://numpy.org/doc/stable/reference/generated/numpy.isnan.html .. py:method:: isinf(a) Tests element-wise for positive or negative infinity and returns result as a boolean tensor. This function follows the api from :any:`numpy.isinf` See: https://numpy.org/doc/stable/reference/generated/numpy.isinf.html .. py:method:: einsum(subscripts, *operands) Evaluates the Einstein summation convention on the operands. This function follows the api from :any:`numpy.einsum` See: https://numpy.org/doc/stable/reference/generated/numpy.einsum.html .. py:method:: sort(a, axis=-1) Returns a sorted copy of a tensor. This function follows the api from :any:`numpy.sort` See: https://numpy.org/doc/stable/reference/generated/numpy.sort.html .. py:method:: argsort(a, axis=-1) Returns the indices that would sort a tensor. This function follows the api from :any:`numpy.argsort` See: https://numpy.org/doc/stable/reference/generated/numpy.argsort.html .. py:method:: searchsorted(a, v, side='left') Finds indices where elements should be inserted to maintain order in given tensor. This function follows the api from :any:`numpy.searchsorted` See: https://numpy.org/doc/stable/reference/generated/numpy.searchsorted.html .. py:method:: flip(a, axis=None) Reverses the order of elements in a tensor along given dimensions. This function follows the api from :any:`numpy.flip` See: https://numpy.org/doc/stable/reference/generated/numpy.flip.html .. py:method:: outer(a, b) Computes the outer product between two vectors. This function follows the api from :any:`numpy.outer` See: https://numpy.org/doc/stable/reference/generated/numpy.outer.html .. py:method:: clip(a, a_min, a_max) Limits the values in a tensor. This function follows the api from :any:`numpy.clip` See: https://numpy.org/doc/stable/reference/generated/numpy.clip.html .. py:method:: repeat(a, repeats, axis=None) Repeats elements of a tensor. This function follows the api from :any:`numpy.repeat` See: https://numpy.org/doc/stable/reference/generated/numpy.repeat.html .. py:method:: take_along_axis(arr, indices, axis) Gathers elements of a tensor along given dimensions. This function follows the api from :any:`numpy.take_along_axis` See: https://numpy.org/doc/stable/reference/generated/numpy.take_along_axis.html .. py:method:: concatenate(arrays, axis=0) Joins a sequence of tensors along an existing dimension. This function follows the api from :any:`numpy.concatenate` See: https://numpy.org/doc/stable/reference/generated/numpy.concatenate.html .. py:method:: zero_pad(a, pad_width, value=0) Pads a tensor with a given value (0 by default). This function follows the api from :any:`numpy.pad` See: https://numpy.org/doc/stable/reference/generated/numpy.pad.html .. py:method:: argmax(a, axis=None) Returns the indices of the maximum values of a tensor along given dimensions. This function follows the api from :any:`numpy.argmax` See: https://numpy.org/doc/stable/reference/generated/numpy.argmax.html .. py:method:: argmin(a, axis=None) Returns the indices of the minimum values of a tensor along given dimensions. This function follows the api from :any:`numpy.argmin` See: https://numpy.org/doc/stable/reference/generated/numpy.argmin.html .. py:method:: mean(a, axis=None) Computes the arithmetic mean of a tensor along given dimensions. This function follows the api from :any:`numpy.mean` See: https://numpy.org/doc/stable/reference/generated/numpy.mean.html .. py:method:: median(a, axis=None) Computes the median of a tensor along given dimensions. This function follows the api from :any:`numpy.median` See: https://numpy.org/doc/stable/reference/generated/numpy.median.html .. py:method:: std(a, axis=None) Computes the standard deviation of a tensor along given dimensions. This function follows the api from :any:`numpy.std` See: https://numpy.org/doc/stable/reference/generated/numpy.std.html .. py:method:: linspace(start, stop, num, type_as=None) Returns a specified number of evenly spaced values over a given interval. This function follows the api from :any:`numpy.linspace` See: https://numpy.org/doc/stable/reference/generated/numpy.linspace.html .. py:method:: meshgrid(a, b) Returns coordinate matrices from coordinate vectors (Numpy convention). This function follows the api from :any:`numpy.meshgrid` See: https://numpy.org/doc/stable/reference/generated/numpy.meshgrid.html .. py:method:: diag(a, k=0) Extracts or constructs a diagonal tensor. This function follows the api from :any:`numpy.diag` See: https://numpy.org/doc/stable/reference/generated/numpy.diag.html .. py:method:: unique(a, return_inverse=False) Finds unique elements of given tensor. This function follows the api from :any:`numpy.unique` See: https://numpy.org/doc/stable/reference/generated/numpy.unique.html .. py:method:: logsumexp(a, axis=None) Computes the log of the sum of exponentials of input elements. This function follows the api from :any:`scipy.special.logsumexp` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.logsumexp.html .. py:method:: stack(arrays, axis=0) Joins a sequence of tensors along a new dimension. This function follows the api from :any:`numpy.stack` See: https://numpy.org/doc/stable/reference/generated/numpy.stack.html .. py:method:: reshape(a, shape) Gives a new shape to a tensor without changing its data. This function follows the api from :any:`numpy.reshape` See: https://numpy.org/doc/stable/reference/generated/numpy.reshape.html .. py:method:: seed(seed=None) Sets the seed for the random generator. This function follows the api from :any:`numpy.random.seed` See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.seed.html .. py:method:: rand(*size, type_as=None) Generate uniform random numbers. This function follows the api from :any:`numpy.random.rand` See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.rand.html .. py:method:: randn(*size, type_as=None) Generate normal Gaussian random numbers. This function follows the api from :any:`numpy.random.rand` See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.rand.html .. py:method:: coo_matrix(data, rows, cols, shape=None, type_as=None) Creates a sparse tensor in COOrdinate format. This function follows the api from :any:`scipy.sparse.coo_matrix` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.html .. py:method:: issparse(a) Checks whether or not the input tensor is a sparse tensor. This function follows the api from :any:`scipy.sparse.issparse` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.issparse.html .. py:method:: tocsr(a) Converts this matrix to Compressed Sparse Row format. This function follows the api from :any:`scipy.sparse.coo_matrix.tocsr` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.tocsr.html .. py:method:: eliminate_zeros(a, threshold=0.0) Removes entries smaller than the given threshold from the sparse tensor. This function follows the api from :any:`scipy.sparse.csr_matrix.eliminate_zeros` See: https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.sparse.csr_matrix.eliminate_zeros.html .. py:method:: todense(a) Converts a sparse tensor to a dense tensor. This function follows the api from :any:`scipy.sparse.csr_matrix.toarray` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csr_matrix.toarray.html .. py:method:: where(condition, x=None, y=None) Returns elements chosen from x or y depending on condition. This function follows the api from :any:`numpy.where` See: https://numpy.org/doc/stable/reference/generated/numpy.where.html .. py:method:: copy(a) Returns a copy of the given tensor. This function follows the api from :any:`numpy.copy` See: https://numpy.org/doc/stable/reference/generated/numpy.copy.html .. py:method:: allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False) Returns True if two arrays are element-wise equal within a tolerance. This function follows the api from :any:`numpy.allclose` See: https://numpy.org/doc/stable/reference/generated/numpy.allclose.html .. py:method:: dtype_device(a) Returns the dtype and the device of the given tensor. .. py:method:: assert_same_dtype_device(a, b) Checks whether or not the two given inputs have the same dtype as well as the same device .. py:method:: squeeze(a, axis=None) Remove axes of length one from a. This function follows the api from :any:`numpy.squeeze`. See: https://numpy.org/doc/stable/reference/generated/numpy.squeeze.html .. py:method:: bitsize(type_as) Gives the number of bits used by the data type of the given tensor. .. py:method:: device_type(type_as) Returns CPU or GPU depending on the device where the given tensor is located. .. py:method:: _bench(callable, *args, n_runs=1, warmup_runs=1) Executes a benchmark of the given callable with the given arguments. .. py:method:: solve(a, b) Solves a linear matrix equation, or system of linear scalar equations. This function follows the api from :any:`numpy.linalg.solve`. See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.solve.html .. py:method:: trace(a) Returns the sum along diagonals of the array. This function follows the api from :any:`numpy.trace`. See: https://numpy.org/doc/stable/reference/generated/numpy.trace.html .. py:method:: inv(a) Computes the inverse of a matrix. This function follows the api from :any:`scipy.linalg.inv`. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.inv.html .. py:method:: sqrtm(a) Computes the matrix square root. Requires input to be definite positive. This function follows the api from :any:`scipy.linalg.sqrtm`. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.sqrtm.html .. py:method:: eigh(a) Computes the eigenvalues and eigenvectors of a symmetric tensor. This function follows the api from :any:`scipy.linalg.eigh`. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.eigh.html .. py:method:: kl_div(p, q, mass=False, eps=1e-16) Computes the (Generalized) Kullback-Leibler divergence. This function follows the api from :any:`scipy.stats.entropy`. Parameter eps is used to avoid numerical errors and is added in the log. .. math:: KL(p,q) = \langle \mathbf{p}, log(\mathbf{p} / \mathbf{q} + eps \rangle + \mathbb{1}_{mass=True} \langle \mathbf{q} - \mathbf{p}, \mathbf{1} \rangle See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.entropy.html .. py:method:: isfinite(a) Tests element-wise for finiteness (not infinity and not Not a Number). This function follows the api from :any:`numpy.isfinite`. See: https://numpy.org/doc/stable/reference/generated/numpy.isfinite.html .. py:method:: array_equal(a, b) True if two arrays have the same shape and elements, False otherwise. This function follows the api from :any:`numpy.array_equal`. See: https://numpy.org/doc/stable/reference/generated/numpy.array_equal.html .. py:method:: is_floating_point(a) Returns whether or not the input consists of floats .. py:method:: tile(a, reps) Construct an array by repeating a the number of times given by reps See: https://numpy.org/doc/stable/reference/generated/numpy.tile.html .. py:method:: floor(a) Return the floor of the input element-wise See: https://numpy.org/doc/stable/reference/generated/numpy.floor.html .. py:method:: prod(a, axis=0) Return the product of all elements. See: https://numpy.org/doc/stable/reference/generated/numpy.prod.html .. py:method:: sort2(a, axis=-1) Return the sorted array and the indices to sort the array See: https://pytorch.org/docs/stable/generated/torch.sort.html .. py:method:: qr(a) Return the QR factorization See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.qr.html .. py:method:: atan2(a, b) Element wise arctangent See: https://numpy.org/doc/stable/reference/generated/numpy.arctan2.html .. py:method:: transpose(a, axes=None) Returns a tensor that is a transposed version of a. The given dimensions dim0 and dim1 are swapped. See: https://numpy.org/doc/stable/reference/generated/numpy.transpose.html .. py:method:: matmul(a, b) Matrix product of two arrays. See: https://numpy.org/doc/stable/reference/generated/numpy.matmul.html#numpy.matmul .. py:method:: nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None) Replace NaN with zero and infinity with large finite numbers or with the numbers defined by the user. See: https://numpy.org/doc/stable/reference/generated/numpy.nan_to_num.html#numpy.nan_to_num .. py:class:: TensorflowBackend Bases: :py:obj:`Backend` Backend abstract class. Implementations: :py:class:`JaxBackend`, :py:class:`NumpyBackend`, :py:class:`TorchBackend`, :py:class:`CupyBackend`, :py:class:`TensorflowBackend` - The `__name__` class attribute refers to the name of the backend. - The `__type__` class attribute refers to the data structure used by the backend. .. py:attribute:: __name__ :value: 'tf' .. py:attribute:: __type__ .. py:attribute:: __type_list__ :value: None .. py:attribute:: rng_ :value: None .. py:method:: _to_numpy(a) Returns the numpy version of a tensor .. py:method:: _from_numpy(a, type_as=None) Creates a tensor cloning a numpy array, with the given precision (defaulting to input's precision) and the given device (in case of GPUs) .. py:method:: set_gradients(val, inputs, grads) Define the gradients for the value val wrt the inputs .. py:method:: _detach(a) Detach the tensor from the computation graph .. py:method:: zeros(shape, type_as=None) Creates a tensor full of zeros. This function follows the api from :any:`numpy.zeros` See: https://numpy.org/doc/stable/reference/generated/numpy.zeros.html .. py:method:: ones(shape, type_as=None) Creates a tensor full of ones. This function follows the api from :any:`numpy.ones` See: https://numpy.org/doc/stable/reference/generated/numpy.ones.html .. py:method:: arange(stop, start=0, step=1, type_as=None) Returns evenly spaced values within a given interval. This function follows the api from :any:`numpy.arange` See: https://numpy.org/doc/stable/reference/generated/numpy.arange.html .. py:method:: full(shape, fill_value, type_as=None) Creates a tensor with given shape, filled with given value. This function follows the api from :any:`numpy.full` See: https://numpy.org/doc/stable/reference/generated/numpy.full.html .. py:method:: eye(N, M=None, type_as=None) Creates the identity matrix of given size. This function follows the api from :any:`numpy.eye` See: https://numpy.org/doc/stable/reference/generated/numpy.eye.html .. py:method:: sum(a, axis=None, keepdims=False) Sums tensor elements over given dimensions. This function follows the api from :any:`numpy.sum` See: https://numpy.org/doc/stable/reference/generated/numpy.sum.html .. py:method:: cumsum(a, axis=None) Returns the cumulative sum of tensor elements over given dimensions. This function follows the api from :any:`numpy.cumsum` See: https://numpy.org/doc/stable/reference/generated/numpy.cumsum.html .. py:method:: max(a, axis=None, keepdims=False) Returns the maximum of an array or maximum along given dimensions. This function follows the api from :any:`numpy.amax` See: https://numpy.org/doc/stable/reference/generated/numpy.amax.html .. py:method:: min(a, axis=None, keepdims=False) Returns the maximum of an array or maximum along given dimensions. This function follows the api from :any:`numpy.amin` See: https://numpy.org/doc/stable/reference/generated/numpy.amin.html .. py:method:: maximum(a, b) Returns element-wise maximum of array elements. This function follows the api from :any:`numpy.maximum` See: https://numpy.org/doc/stable/reference/generated/numpy.maximum.html .. py:method:: minimum(a, b) Returns element-wise minimum of array elements. This function follows the api from :any:`numpy.minimum` See: https://numpy.org/doc/stable/reference/generated/numpy.minimum.html .. py:method:: sign(a) Returns an element-wise indication of the sign of a number. This function follows the api from :any:`numpy.sign` See: https://numpy.org/doc/stable/reference/generated/numpy.sign.html .. py:method:: dot(a, b) Returns the dot product of two tensors. This function follows the api from :any:`numpy.dot` See: https://numpy.org/doc/stable/reference/generated/numpy.dot.html .. py:method:: abs(a) Computes the absolute value element-wise. This function follows the api from :any:`numpy.absolute` See: https://numpy.org/doc/stable/reference/generated/numpy.absolute.html .. py:method:: exp(a) Computes the exponential value element-wise. This function follows the api from :any:`numpy.exp` See: https://numpy.org/doc/stable/reference/generated/numpy.exp.html .. py:method:: log(a) Computes the natural logarithm, element-wise. This function follows the api from :any:`numpy.log` See: https://numpy.org/doc/stable/reference/generated/numpy.log.html .. py:method:: sqrt(a) Returns the non-ngeative square root of a tensor, element-wise. This function follows the api from :any:`numpy.sqrt` See: https://numpy.org/doc/stable/reference/generated/numpy.sqrt.html .. py:method:: power(a, exponents) First tensor elements raised to powers from second tensor, element-wise. This function follows the api from :any:`numpy.power` See: https://numpy.org/doc/stable/reference/generated/numpy.power.html .. py:method:: norm(a, axis=None, keepdims=False) Computes the matrix frobenius norm. This function follows the api from :any:`numpy.linalg.norm` See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.norm.html .. py:method:: any(a) Tests whether any tensor element along given dimensions evaluates to True. This function follows the api from :any:`numpy.any` See: https://numpy.org/doc/stable/reference/generated/numpy.any.html .. py:method:: isnan(a) Tests element-wise for NaN and returns result as a boolean tensor. This function follows the api from :any:`numpy.isnan` See: https://numpy.org/doc/stable/reference/generated/numpy.isnan.html .. py:method:: isinf(a) Tests element-wise for positive or negative infinity and returns result as a boolean tensor. This function follows the api from :any:`numpy.isinf` See: https://numpy.org/doc/stable/reference/generated/numpy.isinf.html .. py:method:: einsum(subscripts, *operands) Evaluates the Einstein summation convention on the operands. This function follows the api from :any:`numpy.einsum` See: https://numpy.org/doc/stable/reference/generated/numpy.einsum.html .. py:method:: sort(a, axis=-1) Returns a sorted copy of a tensor. This function follows the api from :any:`numpy.sort` See: https://numpy.org/doc/stable/reference/generated/numpy.sort.html .. py:method:: argsort(a, axis=-1) Returns the indices that would sort a tensor. This function follows the api from :any:`numpy.argsort` See: https://numpy.org/doc/stable/reference/generated/numpy.argsort.html .. py:method:: searchsorted(a, v, side='left') Finds indices where elements should be inserted to maintain order in given tensor. This function follows the api from :any:`numpy.searchsorted` See: https://numpy.org/doc/stable/reference/generated/numpy.searchsorted.html .. py:method:: flip(a, axis=None) Reverses the order of elements in a tensor along given dimensions. This function follows the api from :any:`numpy.flip` See: https://numpy.org/doc/stable/reference/generated/numpy.flip.html .. py:method:: outer(a, b) Computes the outer product between two vectors. This function follows the api from :any:`numpy.outer` See: https://numpy.org/doc/stable/reference/generated/numpy.outer.html .. py:method:: clip(a, a_min, a_max) Limits the values in a tensor. This function follows the api from :any:`numpy.clip` See: https://numpy.org/doc/stable/reference/generated/numpy.clip.html .. py:method:: repeat(a, repeats, axis=None) Repeats elements of a tensor. This function follows the api from :any:`numpy.repeat` See: https://numpy.org/doc/stable/reference/generated/numpy.repeat.html .. py:method:: take_along_axis(arr, indices, axis) Gathers elements of a tensor along given dimensions. This function follows the api from :any:`numpy.take_along_axis` See: https://numpy.org/doc/stable/reference/generated/numpy.take_along_axis.html .. py:method:: concatenate(arrays, axis=0) Joins a sequence of tensors along an existing dimension. This function follows the api from :any:`numpy.concatenate` See: https://numpy.org/doc/stable/reference/generated/numpy.concatenate.html .. py:method:: zero_pad(a, pad_width, value=0) Pads a tensor with a given value (0 by default). This function follows the api from :any:`numpy.pad` See: https://numpy.org/doc/stable/reference/generated/numpy.pad.html .. py:method:: argmax(a, axis=None) Returns the indices of the maximum values of a tensor along given dimensions. This function follows the api from :any:`numpy.argmax` See: https://numpy.org/doc/stable/reference/generated/numpy.argmax.html .. py:method:: argmin(a, axis=None) Returns the indices of the minimum values of a tensor along given dimensions. This function follows the api from :any:`numpy.argmin` See: https://numpy.org/doc/stable/reference/generated/numpy.argmin.html .. py:method:: mean(a, axis=None) Computes the arithmetic mean of a tensor along given dimensions. This function follows the api from :any:`numpy.mean` See: https://numpy.org/doc/stable/reference/generated/numpy.mean.html .. py:method:: median(a, axis=None) Computes the median of a tensor along given dimensions. This function follows the api from :any:`numpy.median` See: https://numpy.org/doc/stable/reference/generated/numpy.median.html .. py:method:: std(a, axis=None) Computes the standard deviation of a tensor along given dimensions. This function follows the api from :any:`numpy.std` See: https://numpy.org/doc/stable/reference/generated/numpy.std.html .. py:method:: linspace(start, stop, num, type_as=None) Returns a specified number of evenly spaced values over a given interval. This function follows the api from :any:`numpy.linspace` See: https://numpy.org/doc/stable/reference/generated/numpy.linspace.html .. py:method:: meshgrid(a, b) Returns coordinate matrices from coordinate vectors (Numpy convention). This function follows the api from :any:`numpy.meshgrid` See: https://numpy.org/doc/stable/reference/generated/numpy.meshgrid.html .. py:method:: diag(a, k=0) Extracts or constructs a diagonal tensor. This function follows the api from :any:`numpy.diag` See: https://numpy.org/doc/stable/reference/generated/numpy.diag.html .. py:method:: unique(a, return_inverse=False) Finds unique elements of given tensor. This function follows the api from :any:`numpy.unique` See: https://numpy.org/doc/stable/reference/generated/numpy.unique.html .. py:method:: logsumexp(a, axis=None) Computes the log of the sum of exponentials of input elements. This function follows the api from :any:`scipy.special.logsumexp` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.logsumexp.html .. py:method:: stack(arrays, axis=0) Joins a sequence of tensors along a new dimension. This function follows the api from :any:`numpy.stack` See: https://numpy.org/doc/stable/reference/generated/numpy.stack.html .. py:method:: reshape(a, shape) Gives a new shape to a tensor without changing its data. This function follows the api from :any:`numpy.reshape` See: https://numpy.org/doc/stable/reference/generated/numpy.reshape.html .. py:method:: seed(seed=None) Sets the seed for the random generator. This function follows the api from :any:`numpy.random.seed` See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.seed.html .. py:method:: rand(*size, type_as=None) Generate uniform random numbers. This function follows the api from :any:`numpy.random.rand` See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.rand.html .. py:method:: randn(*size, type_as=None) Generate normal Gaussian random numbers. This function follows the api from :any:`numpy.random.rand` See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.rand.html .. py:method:: _convert_to_index_for_coo(tensor) .. py:method:: coo_matrix(data, rows, cols, shape=None, type_as=None) Creates a sparse tensor in COOrdinate format. This function follows the api from :any:`scipy.sparse.coo_matrix` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.html .. py:method:: issparse(a) Checks whether or not the input tensor is a sparse tensor. This function follows the api from :any:`scipy.sparse.issparse` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.issparse.html .. py:method:: tocsr(a) Converts this matrix to Compressed Sparse Row format. This function follows the api from :any:`scipy.sparse.coo_matrix.tocsr` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.tocsr.html .. py:method:: eliminate_zeros(a, threshold=0.0) Removes entries smaller than the given threshold from the sparse tensor. This function follows the api from :any:`scipy.sparse.csr_matrix.eliminate_zeros` See: https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.sparse.csr_matrix.eliminate_zeros.html .. py:method:: todense(a) Converts a sparse tensor to a dense tensor. This function follows the api from :any:`scipy.sparse.csr_matrix.toarray` See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csr_matrix.toarray.html .. py:method:: where(condition, x=None, y=None) Returns elements chosen from x or y depending on condition. This function follows the api from :any:`numpy.where` See: https://numpy.org/doc/stable/reference/generated/numpy.where.html .. py:method:: copy(a) Returns a copy of the given tensor. This function follows the api from :any:`numpy.copy` See: https://numpy.org/doc/stable/reference/generated/numpy.copy.html .. py:method:: allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False) Returns True if two arrays are element-wise equal within a tolerance. This function follows the api from :any:`numpy.allclose` See: https://numpy.org/doc/stable/reference/generated/numpy.allclose.html .. py:method:: dtype_device(a) Returns the dtype and the device of the given tensor. .. py:method:: assert_same_dtype_device(a, b) Checks whether or not the two given inputs have the same dtype as well as the same device .. py:method:: squeeze(a, axis=None) Remove axes of length one from a. This function follows the api from :any:`numpy.squeeze`. See: https://numpy.org/doc/stable/reference/generated/numpy.squeeze.html .. py:method:: bitsize(type_as) Gives the number of bits used by the data type of the given tensor. .. py:method:: device_type(type_as) Returns CPU or GPU depending on the device where the given tensor is located. .. py:method:: _bench(callable, *args, n_runs=1, warmup_runs=1) Executes a benchmark of the given callable with the given arguments. .. py:method:: solve(a, b) Solves a linear matrix equation, or system of linear scalar equations. This function follows the api from :any:`numpy.linalg.solve`. See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.solve.html .. py:method:: trace(a) Returns the sum along diagonals of the array. This function follows the api from :any:`numpy.trace`. See: https://numpy.org/doc/stable/reference/generated/numpy.trace.html .. py:method:: inv(a) Computes the inverse of a matrix. This function follows the api from :any:`scipy.linalg.inv`. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.inv.html .. py:method:: sqrtm(a) Computes the matrix square root. Requires input to be definite positive. This function follows the api from :any:`scipy.linalg.sqrtm`. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.sqrtm.html .. py:method:: eigh(a) Computes the eigenvalues and eigenvectors of a symmetric tensor. This function follows the api from :any:`scipy.linalg.eigh`. See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.eigh.html .. py:method:: kl_div(p, q, mass=False, eps=1e-16) Computes the (Generalized) Kullback-Leibler divergence. This function follows the api from :any:`scipy.stats.entropy`. Parameter eps is used to avoid numerical errors and is added in the log. .. math:: KL(p,q) = \langle \mathbf{p}, log(\mathbf{p} / \mathbf{q} + eps \rangle + \mathbb{1}_{mass=True} \langle \mathbf{q} - \mathbf{p}, \mathbf{1} \rangle See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.entropy.html .. py:method:: isfinite(a) Tests element-wise for finiteness (not infinity and not Not a Number). This function follows the api from :any:`numpy.isfinite`. See: https://numpy.org/doc/stable/reference/generated/numpy.isfinite.html .. py:method:: array_equal(a, b) True if two arrays have the same shape and elements, False otherwise. This function follows the api from :any:`numpy.array_equal`. See: https://numpy.org/doc/stable/reference/generated/numpy.array_equal.html .. py:method:: is_floating_point(a) Returns whether or not the input consists of floats .. py:method:: tile(a, reps) Construct an array by repeating a the number of times given by reps See: https://numpy.org/doc/stable/reference/generated/numpy.tile.html .. py:method:: floor(a) Return the floor of the input element-wise See: https://numpy.org/doc/stable/reference/generated/numpy.floor.html .. py:method:: prod(a, axis=0) Return the product of all elements. See: https://numpy.org/doc/stable/reference/generated/numpy.prod.html .. py:method:: sort2(a, axis=-1) Return the sorted array and the indices to sort the array See: https://pytorch.org/docs/stable/generated/torch.sort.html .. py:method:: qr(a) Return the QR factorization See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.qr.html .. py:method:: atan2(a, b) Element wise arctangent See: https://numpy.org/doc/stable/reference/generated/numpy.arctan2.html .. py:method:: transpose(a, axes=None) Returns a tensor that is a transposed version of a. The given dimensions dim0 and dim1 are swapped. See: https://numpy.org/doc/stable/reference/generated/numpy.transpose.html .. py:method:: matmul(a, b) Matrix product of two arrays. See: https://numpy.org/doc/stable/reference/generated/numpy.matmul.html#numpy.matmul .. py:method:: nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None) Replace NaN with zero and infinity with large finite numbers or with the numbers defined by the user. See: https://numpy.org/doc/stable/reference/generated/numpy.nan_to_num.html#numpy.nan_to_num