spateo.alignment.methods.backend

Attributes

Classes

Backend

Backend abstract class.

NumpyBackend

NumPy implementation of the backend.

TorchBackend

PyTorch implementation of the backend

Functions

_register_backend_implementation(backend_impl)

_get_backend_instance(backend_impl)

_check_args_backend(backend_impl, args)

get_backend_list()

Returns instances of all available backends.

get_available_backend_implementations()

Returns the list of available backend implementations.

get_backend(*args)

Returns the proper backend for a list of input arrays

to_numpy(*args)

Returns numpy arrays from any compatible backend

Module Contents

spateo.alignment.methods.backend.DISABLE_TORCH_KEY = 'SPATEO_BACKEND_DISABLE_PYTORCH'[source]
spateo.alignment.methods.backend.torch_type[source]
spateo.alignment.methods.backend.str_type_error = 'All array should be from the same type/backend. Current types are : {}'[source]
spateo.alignment.methods.backend._BACKEND_IMPLEMENTATIONS = [][source]
spateo.alignment.methods.backend._BACKENDS[source]
spateo.alignment.methods.backend._register_backend_implementation(backend_impl)[source]
spateo.alignment.methods.backend._get_backend_instance(backend_impl)[source]
spateo.alignment.methods.backend._check_args_backend(backend_impl, args)[source]
spateo.alignment.methods.backend.get_backend_list()[source]

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.

spateo.alignment.methods.backend.get_available_backend_implementations()[source]

Returns the list of available backend implementations.

spateo.alignment.methods.backend.get_backend(*args)[source]

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

spateo.alignment.methods.backend.to_numpy(*args)[source]

Returns numpy arrays from any compatible backend

class spateo.alignment.methods.backend.Backend[source]

Backend abstract class. Implementations: JaxBackend, NumpyBackend, TorchBackend, CupyBackend, 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.

__name__ = None[source]
__type__ = None[source]
__type_list__ = None[source]
rng_ = None[source]
__str__()[source]
to_numpy(*arrays)[source]

Returns the numpy version of tensors

abstract _to_numpy(a)[source]

Returns the numpy version of a tensor

from_numpy(*arrays, type_as=None)[source]

Creates tensors cloning a numpy array, with the given precision (defaulting to input’s precision) and the given device (in case of GPUs)

abstract _from_numpy(a, type_as=None)[source]

Creates a tensor cloning a numpy array, with the given precision (defaulting to input’s precision) and the given device (in case of GPUs)

abstract zeros(shape, type_as=None)[source]

Creates a tensor full of zeros.

This function follows the api from numpy.zeros

See: https://numpy.org/doc/stable/reference/generated/numpy.zeros.html

abstract ones(shape, type_as=None)[source]

Creates a tensor full of ones.

This function follows the api from numpy.ones

See: https://numpy.org/doc/stable/reference/generated/numpy.ones.html

abstract full(shape, fill_value, type_as=None)[source]

Creates a tensor with given shape, filled with given value.

This function follows the api from numpy.full

See: https://numpy.org/doc/stable/reference/generated/numpy.full.html

abstract eye(N, M=None, type_as=None)[source]

Creates the identity matrix of given size.

This function follows the api from numpy.eye

See: https://numpy.org/doc/stable/reference/generated/numpy.eye.html

abstract sum(a, axis=None, keepdims=False)[source]

Sums tensor elements over given dimensions.

This function follows the api from numpy.sum

See: https://numpy.org/doc/stable/reference/generated/numpy.sum.html

abstract arange(stop, start=0, step=1, type_as=None)[source]

Returns evenly spaced values within a given interval.

This function follows the api from numpy.arange

See: https://numpy.org/doc/stable/reference/generated/numpy.arange.html

abstract max(a, axis=None, keepdims=False)[source]

Returns the maximum of an array or maximum along given dimensions.

This function follows the api from numpy.amax

See: https://numpy.org/doc/stable/reference/generated/numpy.amax.html

abstract min(a, axis=None, keepdims=False)[source]

Returns the maximum of an array or maximum along given dimensions.

This function follows the api from numpy.amin

See: https://numpy.org/doc/stable/reference/generated/numpy.amin.html

abstract maximum(a, b)[source]

Returns element-wise maximum of array elements.

This function follows the api from numpy.maximum

See: https://numpy.org/doc/stable/reference/generated/numpy.maximum.html

abstract minimum(a, b)[source]

Returns element-wise minimum of array elements.

This function follows the api from numpy.minimum

See: https://numpy.org/doc/stable/reference/generated/numpy.minimum.html

abstract dot(a, b)[source]

Returns the dot product of two tensors.

This function follows the api from numpy.dot

See: https://numpy.org/doc/stable/reference/generated/numpy.dot.html

abstract log(a)[source]

Computes the natural logarithm, element-wise.

This function follows the api from numpy.log

See: https://numpy.org/doc/stable/reference/generated/numpy.log.html

abstract sqrt(a)[source]

Returns the non-ngeative square root of a tensor, element-wise.

This function follows the api from numpy.sqrt

See: https://numpy.org/doc/stable/reference/generated/numpy.sqrt.html

abstract power(a, exponents)[source]

First tensor elements raised to powers from second tensor, element-wise.

This function follows the api from numpy.power

See: https://numpy.org/doc/stable/reference/generated/numpy.power.html

abstract norm(a, axis=None, keepdims=False)[source]

Computes the matrix frobenius norm.

This function follows the api from numpy.linalg.norm

See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.norm.html

abstract any(a)[source]

Tests whether any tensor element along given dimensions evaluates to True.

This function follows the api from numpy.any

See: https://numpy.org/doc/stable/reference/generated/numpy.any.html

abstract isnan(a)[source]

Tests element-wise for NaN and returns result as a boolean tensor.

This function follows the api from numpy.isnan

See: https://numpy.org/doc/stable/reference/generated/numpy.isnan.html

abstract isinf(a)[source]

Tests element-wise for positive or negative infinity and returns result as a boolean tensor.

This function follows the api from numpy.isinf

See: https://numpy.org/doc/stable/reference/generated/numpy.isinf.html

abstract einsum(subscripts, *operands)[source]

Evaluates the Einstein summation convention on the operands.

This function follows the api from numpy.einsum

See: https://numpy.org/doc/stable/reference/generated/numpy.einsum.html

abstract sort(a, axis=-1)[source]

Returns a sorted copy of a tensor.

This function follows the api from numpy.sort

See: https://numpy.org/doc/stable/reference/generated/numpy.sort.html

abstract argsort(a, axis=None)[source]

Returns the indices that would sort a tensor.

This function follows the api from numpy.argsort

See: https://numpy.org/doc/stable/reference/generated/numpy.argsort.html

abstract searchsorted(a, v, side='left')[source]

Finds indices where elements should be inserted to maintain order in given tensor.

This function follows the api from numpy.searchsorted

See: https://numpy.org/doc/stable/reference/generated/numpy.searchsorted.html

abstract flip(a, axis=None)[source]

Reverses the order of elements in a tensor along given dimensions.

This function follows the api from numpy.flip

See: https://numpy.org/doc/stable/reference/generated/numpy.flip.html

abstract clip(a, a_min, a_max)[source]

Limits the values in a tensor.

This function follows the api from numpy.clip

See: https://numpy.org/doc/stable/reference/generated/numpy.clip.html

abstract repeat(a, repeats, axis=None)[source]

Repeats elements of a tensor.

This function follows the api from numpy.repeat

See: https://numpy.org/doc/stable/reference/generated/numpy.repeat.html

abstract take_along_axis(arr, indices, axis)[source]

Gathers elements of a tensor along given dimensions.

This function follows the api from numpy.take_along_axis

See: https://numpy.org/doc/stable/reference/generated/numpy.take_along_axis.html

abstract concatenate(arrays, axis=0)[source]

Joins a sequence of tensors along an existing dimension.

This function follows the api from numpy.concatenate

See: https://numpy.org/doc/stable/reference/generated/numpy.concatenate.html

abstract zero_pad(a, pad_width, value=0)[source]

Pads a tensor with a given value (0 by default).

This function follows the api from numpy.pad

See: https://numpy.org/doc/stable/reference/generated/numpy.pad.html

abstract argmax(a, axis=None)[source]

Returns the indices of the maximum values of a tensor along given dimensions.

This function follows the api from numpy.argmax

See: https://numpy.org/doc/stable/reference/generated/numpy.argmax.html

abstract argmin(a, axis=None)[source]

Returns the indices of the minimum values of a tensor along given dimensions.

This function follows the api from numpy.argmin

See: https://numpy.org/doc/stable/reference/generated/numpy.argmin.html

abstract mean(a, axis=None)[source]

Computes the arithmetic mean of a tensor along given dimensions.

This function follows the api from numpy.mean

See: https://numpy.org/doc/stable/reference/generated/numpy.mean.html

abstract median(a, axis=None)[source]

Computes the median of a tensor along given dimensions.

This function follows the api from numpy.median

See: https://numpy.org/doc/stable/reference/generated/numpy.median.html

abstract std(a, axis=None)[source]

Computes the standard deviation of a tensor along given dimensions.

This function follows the api from numpy.std

See: https://numpy.org/doc/stable/reference/generated/numpy.std.html

abstract linspace(start, stop, num, type_as=None)[source]

Returns a specified number of evenly spaced values over a given interval.

This function follows the api from numpy.linspace

See: https://numpy.org/doc/stable/reference/generated/numpy.linspace.html

abstract meshgrid(a, b)[source]

Returns coordinate matrices from coordinate vectors (Numpy convention).

This function follows the api from numpy.meshgrid

See: https://numpy.org/doc/stable/reference/generated/numpy.meshgrid.html

abstract diag(a, k=0)[source]

Extracts or constructs a diagonal tensor.

This function follows the api from numpy.diag

See: https://numpy.org/doc/stable/reference/generated/numpy.diag.html

abstract unique(a, return_inverse=False)[source]

Finds unique elements of given tensor.

This function follows the api from numpy.unique

See: https://numpy.org/doc/stable/reference/generated/numpy.unique.html

abstract logsumexp(a, axis=None)[source]

Computes the log of the sum of exponentials of input elements.

This function follows the api from scipy.special.logsumexp

See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.logsumexp.html

abstract stack(arrays, axis=0)[source]

Joins a sequence of tensors along a new dimension.

This function follows the api from numpy.stack

See: https://numpy.org/doc/stable/reference/generated/numpy.stack.html

abstract outer(a, b)[source]

Computes the outer product between two vectors.

This function follows the api from numpy.outer

See: https://numpy.org/doc/stable/reference/generated/numpy.outer.html

abstract reshape(a, shape)[source]

Gives a new shape to a tensor without changing its data.

This function follows the api from numpy.reshape

See: https://numpy.org/doc/stable/reference/generated/numpy.reshape.html

abstract seed(seed=None)[source]

Sets the seed for the random generator.

This function follows the api from numpy.random.seed

See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.seed.html

abstract rand(*size, type_as=None)[source]

Generate uniform random numbers.

This function follows the api from numpy.random.rand

See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.rand.html

abstract randn(*size, type_as=None)[source]

Generate normal Gaussian random numbers.

This function follows the api from numpy.random.rand

See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.rand.html

abstract coo_matrix(data, rows, cols, shape=None, type_as=None)[source]

Creates a sparse tensor in COOrdinate format.

This function follows the api from scipy.sparse.coo_matrix

See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.html

abstract issparse(a)[source]

Checks whether or not the input tensor is a sparse tensor.

This function follows the api from scipy.sparse.issparse

See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.issparse.html

abstract tocsr(a)[source]

Converts this matrix to Compressed Sparse Row format.

This function follows the api from scipy.sparse.coo_matrix.tocsr

See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.tocsr.html

abstract eliminate_zeros(a, threshold=0.0)[source]

Removes entries smaller than the given threshold from the sparse tensor.

This function follows the api from 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

abstract todense(a)[source]

Converts a sparse tensor to a dense tensor.

This function follows the api from scipy.sparse.csr_matrix.toarray

See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csr_matrix.toarray.html

abstract where(condition, x, y)[source]

Returns elements chosen from x or y depending on condition.

This function follows the api from numpy.where

See: https://numpy.org/doc/stable/reference/generated/numpy.where.html

abstract copy(a)[source]

Returns a copy of the given tensor.

This function follows the api from numpy.copy

See: https://numpy.org/doc/stable/reference/generated/numpy.copy.html

abstract allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]

Returns True if two arrays are element-wise equal within a tolerance.

This function follows the api from numpy.allclose

See: https://numpy.org/doc/stable/reference/generated/numpy.allclose.html

abstract dtype_device(a)[source]

Returns the dtype and the device of the given tensor.

abstract assert_same_dtype_device(a, b)[source]

Checks whether or not the two given inputs have the same dtype as well as the same device

abstract squeeze(a, axis=None)[source]

Remove axes of length one from a.

This function follows the api from numpy.squeeze.

See: https://numpy.org/doc/stable/reference/generated/numpy.squeeze.html

abstract bitsize(type_as)[source]

Gives the number of bits used by the data type of the given tensor.

abstract device_type(type_as)[source]

Returns CPU or GPU depending on the device where the given tensor is located.

abstract _bench(callable, *args, n_runs=1, warmup_runs=1)[source]

Executes a benchmark of the given callable with the given arguments.

abstract solve(a, b)[source]

Solves a linear matrix equation, or system of linear scalar equations.

This function follows the api from numpy.linalg.solve.

See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.solve.html

abstract trace(a)[source]

Returns the sum along diagonals of the array.

This function follows the api from numpy.trace.

See: https://numpy.org/doc/stable/reference/generated/numpy.trace.html

abstract inv(a)[source]

Computes the inverse of a matrix.

This function follows the api from scipy.linalg.inv.

See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.inv.html

abstract sqrtm(a)[source]

Computes the matrix square root. Requires input to be definite positive.

This function follows the api from scipy.linalg.sqrtm.

See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.sqrtm.html

abstract eigh(a)[source]

Computes the eigenvalues and eigenvectors of a symmetric tensor.

This function follows the api from scipy.linalg.eigh.

See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.eigh.html

abstract kl_div(p, q, mass=False, eps=1e-16)[source]

Computes the (Generalized) Kullback-Leibler divergence.

This function follows the api from scipy.stats.entropy.

Parameter eps is used to avoid numerical errors and is added in the log.

\[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

abstract isfinite(a)[source]

Tests element-wise for finiteness (not infinity and not Not a Number).

This function follows the api from numpy.isfinite.

See: https://numpy.org/doc/stable/reference/generated/numpy.isfinite.html

abstract array_equal(a, b)[source]

True if two arrays have the same shape and elements, False otherwise.

This function follows the api from numpy.array_equal.

See: https://numpy.org/doc/stable/reference/generated/numpy.array_equal.html

abstract is_floating_point(a)[source]

Returns whether or not the input consists of floats

abstract tile(a, reps)[source]

Construct an array by repeating a the number of times given by reps

See: https://numpy.org/doc/stable/reference/generated/numpy.tile.html

abstract floor(a)[source]

Return the floor of the input element-wise

See: https://numpy.org/doc/stable/reference/generated/numpy.floor.html

abstract prod(a, axis=None)[source]

Return the product of all elements.

See: https://numpy.org/doc/stable/reference/generated/numpy.prod.html

abstract sort2(a, axis=None)[source]

Return the sorted array and the indices to sort the array

See: https://pytorch.org/docs/stable/generated/torch.sort.html

abstract qr(a)[source]

Return the QR factorization

See: https://numpy.org/doc/stable/reference/generated/numpy.linalg.qr.html

abstract atan2(a, b)[source]

Element wise arctangent

See: https://numpy.org/doc/stable/reference/generated/numpy.arctan2.html

abstract transpose(a, axes=None)[source]

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

abstract matmul(a, b)[source]

Matrix product of two arrays.

See: https://numpy.org/doc/stable/reference/generated/numpy.matmul.html#numpy.matmul

abstract nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None)[source]

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

abstract randperm(length)[source]

Returns a random permutation of integers from 0 to length - 1.

See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.permutation.html

abstract choice(a, size, replace=False)[source]

Generates a random sample from a given 1-D array.

See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.choice.html

abstract topk(a, topk, axis=-1)[source]

Returns the indices of the topk elements along a given axis.

See: https://numpy.org/doc/stable/reference/generated/numpy.argpartition.html

abstract dstack(a)[source]

Stack arrays in sequence along the third axis.

See: https://numpy.org/doc/stable/reference/generated/numpy.dstack.html

abstract vstack(a)[source]

Stack arrays in sequence vertically (row wise).

See: https://numpy.org/doc/stable/reference/generated/numpy.vstack.html

abstract hstack(a)[source]

Stack arrays in sequence horizontally (column wise).

See: https://numpy.org/doc/stable/reference/generated/numpy.hstack.html

abstract chunk(a, chunk_num, axis=0)[source]

Split the tensor into a list of sub-tensors.

See: https://numpy.org/doc/stable/reference/generated/numpy.array_split.html

abstract roll(a, shift, axis=None)[source]

Roll array elements along a given axis.

See: https://numpy.org/doc/stable/reference/generated/numpy.roll.html

abstract pi(type_as=None)[source]

Return the value of pi.

See: https://numpy.org/doc/stable/reference/constants.html

class spateo.alignment.methods.backend.NumpyBackend[source]

Bases: Backend

NumPy implementation of the backend.

  • __name__ is “numpy”

  • __type__ is np.ndarray

__name__ = 'numpy'[source]
__type__[source]
__type_list__[source]
rng_[source]
_to_numpy(a)[source]

Returns the numpy version of a tensor

_from_numpy(a, type_as=None)[source]

Creates a tensor cloning a numpy array, with the given precision (defaulting to input’s precision) and the given device (in case of GPUs)

zeros(shape, type_as=None)[source]

Creates a tensor full of zeros.

This function follows the api from numpy.zeros

See: https://numpy.org/doc/stable/reference/generated/numpy.zeros.html

einsum(subscripts, *operands)[source]

Evaluates the Einstein summation convention on the operands.

This function follows the api from numpy.einsum

See: https://numpy.org/doc/stable/reference/generated/numpy.einsum.html

mean(a, axis=None)[source]

Computes the arithmetic mean of a tensor along given dimensions.

This function follows the api from numpy.mean

See: https://numpy.org/doc/stable/reference/generated/numpy.mean.html

full(shape, fill_value, type_as=None)[source]

Creates a tensor with given shape, filled with given value.

This function follows the api from numpy.full

See: https://numpy.org/doc/stable/reference/generated/numpy.full.html

sqrt(a)[source]

Returns the non-ngeative square root of a tensor, element-wise.

This function follows the api from numpy.sqrt

See: https://numpy.org/doc/stable/reference/generated/numpy.sqrt.html

ones(shape, type_as=None)[source]

Creates a tensor full of ones.

This function follows the api from numpy.ones

See: https://numpy.org/doc/stable/reference/generated/numpy.ones.html

maximum(a, b)[source]

Returns element-wise maximum of array elements.

This function follows the api from numpy.maximum

See: https://numpy.org/doc/stable/reference/generated/numpy.maximum.html

minimum(a, b)[source]

Returns element-wise minimum of array elements.

This function follows the api from numpy.minimum

See: https://numpy.org/doc/stable/reference/generated/numpy.minimum.html

max(a, axis=None, keepdims=False)[source]

Returns the maximum of an array or maximum along given dimensions.

This function follows the api from numpy.amax

See: https://numpy.org/doc/stable/reference/generated/numpy.amax.html

min(a, axis=None, keepdims=False)[source]

Returns the maximum of an array or maximum along given dimensions.

This function follows the api from numpy.amin

See: https://numpy.org/doc/stable/reference/generated/numpy.amin.html

eye(N, M=None, type_as=None)[source]

Creates the identity matrix of given size.

This function follows the api from numpy.eye

See: https://numpy.org/doc/stable/reference/generated/numpy.eye.html

argsort(a, axis=-1)[source]

Returns the indices that would sort a tensor.

This function follows the api from numpy.argsort

See: https://numpy.org/doc/stable/reference/generated/numpy.argsort.html

exp(a)[source]
log(a)[source]

Computes the natural logarithm, element-wise.

This function follows the api from numpy.log

See: https://numpy.org/doc/stable/reference/generated/numpy.log.html

concatenate(arrays, axis=0)[source]

Joins a sequence of tensors along an existing dimension.

This function follows the api from numpy.concatenate

See: https://numpy.org/doc/stable/reference/generated/numpy.concatenate.html

sum(a, axis=None, keepdims=False)[source]

Sums tensor elements over given dimensions.

This function follows the api from numpy.sum

See: https://numpy.org/doc/stable/reference/generated/numpy.sum.html

arange(stop, start=0, step=1, type_as=None)[source]

Returns evenly spaced values within a given interval.

This function follows the api from numpy.arange

See: https://numpy.org/doc/stable/reference/generated/numpy.arange.html

data(a, type_as=None)[source]
unique(a, return_inverse=False, axis=None)[source]

Finds unique elements of given tensor.

This function follows the api from numpy.unique

See: https://numpy.org/doc/stable/reference/generated/numpy.unique.html

unsqueeze(a, axis=-1)[source]
multiply(a, b)[source]
power(a, exponents)[source]

First tensor elements raised to powers from second tensor, element-wise.

This function follows the api from numpy.power

See: https://numpy.org/doc/stable/reference/generated/numpy.power.html

dot(a, b)[source]

Returns the dot product of two tensors.

This function follows the api from numpy.dot

See: https://numpy.org/doc/stable/reference/generated/numpy.dot.html

prod(a, axis=0)[source]

Return the product of all elements.

See: https://numpy.org/doc/stable/reference/generated/numpy.prod.html

pi(type_as=None)[source]

Return the value of pi.

See: https://numpy.org/doc/stable/reference/constants.html

chunk(a, chunk_num, axis=0)[source]

Split the tensor into a list of sub-tensors.

See: https://numpy.org/doc/stable/reference/generated/numpy.array_split.html

randperm(length)[source]

Returns a random permutation of integers from 0 to length - 1.

See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.permutation.html

roll(a, shift, axis=None)[source]

Roll array elements along a given axis.

See: https://numpy.org/doc/stable/reference/generated/numpy.roll.html

choice(a, size, replace=False)[source]

Generates a random sample from a given 1-D array.

See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.choice.html

topk(a, topk, axis=-1)[source]

Returns the indices of the topk elements along a given axis.

See: https://numpy.org/doc/stable/reference/generated/numpy.argpartition.html

dstack(a)[source]

Stack arrays in sequence along the third axis.

See: https://numpy.org/doc/stable/reference/generated/numpy.dstack.html

vstack(a)[source]

Stack arrays in sequence vertically (row wise).

See: https://numpy.org/doc/stable/reference/generated/numpy.vstack.html

hstack(a)[source]

Stack arrays in sequence horizontally (column wise).

See: https://numpy.org/doc/stable/reference/generated/numpy.hstack.html

stack(arrays, axis=0)[source]

Joins a sequence of tensors along a new dimension.

This function follows the api from numpy.stack

See: https://numpy.org/doc/stable/reference/generated/numpy.stack.html

where(condition, x=None, y=None)[source]

Returns elements chosen from x or y depending on condition.

This function follows the api from numpy.where

See: https://numpy.org/doc/stable/reference/generated/numpy.where.html

copy(a)[source]

Returns a copy of the given tensor.

This function follows the api from numpy.copy

See: https://numpy.org/doc/stable/reference/generated/numpy.copy.html

repeat(a, repeats, axis=None)[source]

Repeats elements of a tensor.

This function follows the api from numpy.repeat

See: https://numpy.org/doc/stable/reference/generated/numpy.repeat.html

sort2(a, axis=-1, descending=False)[source]

Return the sorted array and the indices to sort the array

See: https://pytorch.org/docs/stable/generated/torch.sort.html

coo_matrix(data, rows, cols, shape=None, type_as=None)[source]

Creates a sparse tensor in COOrdinate format.

This function follows the api from scipy.sparse.coo_matrix

See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.html

issparse(a)[source]

Checks whether or not the input tensor is a sparse tensor.

This function follows the api from scipy.sparse.issparse

See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.issparse.html

eliminate_zeros(a, threshold=0.0)[source]

Removes entries smaller than the given threshold from the sparse tensor.

This function follows the api from 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

todense(a)[source]

Converts a sparse tensor to a dense tensor.

This function follows the api from scipy.sparse.csr_matrix.toarray

See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csr_matrix.toarray.html

dtype_device(a)[source]

Returns the dtype and the device of the given tensor.

class spateo.alignment.methods.backend.TorchBackend[source]

Bases: Backend

PyTorch implementation of the backend

  • __name__ is “torch”

  • __type__ is torch.Tensor

__name__ = 'torch'[source]
__type__[source]
__type_list__ = None[source]
rng_ = None[source]
ValFunction[source]
_to_numpy(a)[source]

Returns the numpy version of a tensor

_from_numpy(a, type_as=None)[source]

Creates a tensor cloning a numpy array, with the given precision (defaulting to input’s precision) and the given device (in case of GPUs)

zeros(shape, type_as=None)[source]

Creates a tensor full of zeros.

This function follows the api from numpy.zeros

See: https://numpy.org/doc/stable/reference/generated/numpy.zeros.html

einsum(subscripts, *operands)[source]

Evaluates the Einstein summation convention on the operands.

This function follows the api from numpy.einsum

See: https://numpy.org/doc/stable/reference/generated/numpy.einsum.html

mean(a, axis=None)[source]

Computes the arithmetic mean of a tensor along given dimensions.

This function follows the api from numpy.mean

See: https://numpy.org/doc/stable/reference/generated/numpy.mean.html

full(shape, fill_value, type_as=None)[source]

Creates a tensor with given shape, filled with given value.

This function follows the api from numpy.full

See: https://numpy.org/doc/stable/reference/generated/numpy.full.html

sqrt(a)[source]

Returns the non-ngeative square root of a tensor, element-wise.

This function follows the api from numpy.sqrt

See: https://numpy.org/doc/stable/reference/generated/numpy.sqrt.html

ones(shape, type_as=None)[source]

Creates a tensor full of ones.

This function follows the api from numpy.ones

See: https://numpy.org/doc/stable/reference/generated/numpy.ones.html

arange(stop, start=0, step=1, type_as=None)[source]

Returns evenly spaced values within a given interval.

This function follows the api from numpy.arange

See: https://numpy.org/doc/stable/reference/generated/numpy.arange.html

maximum(a, b)[source]

Returns element-wise maximum of array elements.

This function follows the api from numpy.maximum

See: https://numpy.org/doc/stable/reference/generated/numpy.maximum.html

minimum(a, b)[source]

Returns element-wise minimum of array elements.

This function follows the api from numpy.minimum

See: https://numpy.org/doc/stable/reference/generated/numpy.minimum.html

max(a, axis=None, keepdims=False)[source]

Returns the maximum of an array or maximum along given dimensions.

This function follows the api from numpy.amax

See: https://numpy.org/doc/stable/reference/generated/numpy.amax.html

min(a, axis=None, keepdims=False)[source]

Returns the maximum of an array or maximum along given dimensions.

This function follows the api from numpy.amin

See: https://numpy.org/doc/stable/reference/generated/numpy.amin.html

eye(N, M=None, type_as=None)[source]

Creates the identity matrix of given size.

This function follows the api from numpy.eye

See: https://numpy.org/doc/stable/reference/generated/numpy.eye.html

argsort(a, axis=-1)[source]

Returns the indices that would sort a tensor.

This function follows the api from numpy.argsort

See: https://numpy.org/doc/stable/reference/generated/numpy.argsort.html

exp(a)[source]
log(a)[source]

Computes the natural logarithm, element-wise.

This function follows the api from numpy.log

See: https://numpy.org/doc/stable/reference/generated/numpy.log.html

concatenate(arrays, axis=0)[source]

Joins a sequence of tensors along an existing dimension.

This function follows the api from numpy.concatenate

See: https://numpy.org/doc/stable/reference/generated/numpy.concatenate.html

sum(a, axis=None, keepdims=False)[source]

Sums tensor elements over given dimensions.

This function follows the api from numpy.sum

See: https://numpy.org/doc/stable/reference/generated/numpy.sum.html

data(a, type_as=None)[source]
unique(a, return_inverse=False, axis=None)[source]

Finds unique elements of given tensor.

This function follows the api from numpy.unique

See: https://numpy.org/doc/stable/reference/generated/numpy.unique.html

unsqueeze(a, axis=-1)[source]
multiply(a, b)[source]
power(a, exponents)[source]

First tensor elements raised to powers from second tensor, element-wise.

This function follows the api from numpy.power

See: https://numpy.org/doc/stable/reference/generated/numpy.power.html

dot(a, b)[source]

Returns the dot product of two tensors.

This function follows the api from numpy.dot

See: https://numpy.org/doc/stable/reference/generated/numpy.dot.html

prod(a, axis=0)[source]

Return the product of all elements.

See: https://numpy.org/doc/stable/reference/generated/numpy.prod.html

pi(type_as=None)[source]

Return the value of pi.

See: https://numpy.org/doc/stable/reference/constants.html

chunk(a, chunk_num, axis=0)[source]

Split the tensor into a list of sub-tensors.

See: https://numpy.org/doc/stable/reference/generated/numpy.array_split.html

randperm(length)[source]

Returns a random permutation of integers from 0 to length - 1.

See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.permutation.html

roll(a, shift, axis=None)[source]

Roll array elements along a given axis.

See: https://numpy.org/doc/stable/reference/generated/numpy.roll.html

choice(a, size, replace=False)[source]

Generates a random sample from a given 1-D array.

See: https://numpy.org/doc/stable/reference/random/generated/numpy.random.choice.html

topk(a, topk, axis=-1)[source]

Returns the indices of the topk elements along a given axis.

See: https://numpy.org/doc/stable/reference/generated/numpy.argpartition.html

dstack(a)[source]

Stack arrays in sequence along the third axis.

See: https://numpy.org/doc/stable/reference/generated/numpy.dstack.html

vstack(a)[source]

Stack arrays in sequence vertically (row wise).

See: https://numpy.org/doc/stable/reference/generated/numpy.vstack.html

hstack(a)[source]

Stack arrays in sequence horizontally (column wise).

See: https://numpy.org/doc/stable/reference/generated/numpy.hstack.html

stack(arrays, axis=0)[source]

Joins a sequence of tensors along a new dimension.

This function follows the api from numpy.stack

See: https://numpy.org/doc/stable/reference/generated/numpy.stack.html

where(condition, x=None, y=None)[source]

Returns elements chosen from x or y depending on condition.

This function follows the api from numpy.where

See: https://numpy.org/doc/stable/reference/generated/numpy.where.html

copy(a)[source]

Returns a copy of the given tensor.

This function follows the api from numpy.copy

See: https://numpy.org/doc/stable/reference/generated/numpy.copy.html

repeat(a, repeats, axis=None)[source]

Repeats elements of a tensor.

This function follows the api from numpy.repeat

See: https://numpy.org/doc/stable/reference/generated/numpy.repeat.html

sort2(a, axis=-1, descending=False)[source]

Return the sorted array and the indices to sort the array

See: https://pytorch.org/docs/stable/generated/torch.sort.html

coo_matrix(data, rows, cols, shape=None, type_as=None)[source]

Creates a sparse tensor in COOrdinate format.

This function follows the api from scipy.sparse.coo_matrix

See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.coo_matrix.html

issparse(a)[source]

Checks whether or not the input tensor is a sparse tensor.

This function follows the api from scipy.sparse.issparse

See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.issparse.html

eliminate_zeros(a, threshold=0.0)[source]

Removes entries smaller than the given threshold from the sparse tensor.

This function follows the api from 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

todense(a)[source]

Converts a sparse tensor to a dense tensor.

This function follows the api from scipy.sparse.csr_matrix.toarray

See: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csr_matrix.toarray.html

dtype_device(a)[source]

Returns the dtype and the device of the given tensor.