# Backend#

Numpy based computation backend.

geomstats._backend.numpy.array_from_sparse(indices, data, target_shape)[source]#

Create an array of given shape, with values at specific indices.

The rest of the array will be filled with zeros.

Parameters:
• indices (iterable(tuple(int))) – Index of each element which will be assigned a specific value.

• data (iterable(scalar)) – Value associated at each index.

• target_shape (tuple(int)) – Shape of the output array.

Returns:

a (array, shape=target_shape) – Array of zeros with specified values assigned to specified indices.

geomstats._backend.numpy.assignment(x, values, indices, axis=0)[source]#

Assign values at given indices of an array.

Parameters:
• x (array-like, shape=[dim]) – Initial array.

• values ({float, list(float)}) – Value or list of values to be assigned.

• indices ({int, tuple, list(int), list(tuple)}) – Single int or tuple, or list of ints or tuples of indices where value is assigned. If the length of the tuples is shorter than ndim(x), values are assigned to each copy along axis.

• axis (int, optional) – Axis along which values are assigned, if vectorized.

Returns:

x_new (array-like, shape=[dim]) – Copy of x with the values assigned at the given indices.

Notes

If a single value is provided, it is assigned at all the indices. If a list is given, it must have the same length as indices.

geomstats._backend.numpy.assignment_by_sum(x, values, indices, axis=0)[source]#

Add values at given indices of an array.

Parameters:
• x (array-like, shape=[dim]) – Initial array.

• values ({float, list(float)}) – Value or list of values to be assigned.

• indices ({int, tuple, list(int), list(tuple)}) – Single int or tuple, or list of ints or tuples of indices where value is assigned. If the length of the tuples is shorter than ndim(x), values are assigned to each copy along axis.

• axis (int, optional) – Axis along which values are assigned, if vectorized.

Returns:

x_new (array-like, shape=[dim]) – Copy of x with the values assigned at the given indices.

Notes

If a single value is provided, it is assigned at all the indices. If a list is given, it must have the same length as indices.

Create a 1D array of zeros with one element at one, with floating type.

Parameters:
• i (int) – Index of the non-zero element.

• n (n) – Length of the created array.

Returns:

mask_i_float (array-like, shape=[n,]) – 1D array of zeros except at index i, where it is one

geomstats._backend.numpy.get_slice(x, indices)[source]#

Return a slice of an array, following Numpy’s style.

Parameters:
• x (array-like, shape=[dim]) – Initial array.

• indices (iterable(iterable(int))) – Indices which are kept along each axis, starting from 0.

Returns:

slice (array-like) – Slice of x given by indices.

Notes

This follows Numpy’s convention: indices are grouped by axis.

Examples

>>> a = np.array(range(30)).reshape(3,10)
>>> get_slice(a, ((0, 2), (8, 9)))
array([8, 29])

geomstats._backend.numpy.mat_from_diag_triu_tril(diag, tri_upp, tri_low)[source]#

Build matrix from given components.

Forms a matrix from diagonal, strictly upper triangular and strictly lower traingular parts.

Parameters:
• diag (array_like, shape=[…, n])

• tri_upp (array_like, shape=[…, (n * (n - 1)) / 2])

• tri_low (array_like, shape=[…, (n * (n - 1)) / 2])

Returns:

mat (array_like, shape=[…, n, n])

geomstats._backend.numpy.set_diag(x, new_diag)[source]#

Set the diagonal along the last two axis.

Parameters:
• x (array-like, shape=[dim]) – Initial array.

• new_diag (array-like, shape=[dim[-2]]) – Values to set on the diagonal.

Returns:

None

Notes

This mimics tensorflow.linalg.set_diag(x, new_diag), when new_diag is a 1-D array, but modifies x instead of creating a copy.

geomstats._backend.numpy.vec_to_diag(vec)[source]#

Convert vector to diagonal matrix.

Pytorch based computation backend.

geomstats._backend.pytorch.amax()#

max(input) -> Tensor

Returns the maximum value of all elements in the input tensor.

Warning

This function produces deterministic (sub)gradients unlike max(dim=0)

Args:

input (Tensor): the input tensor.

Example:

>>> a = torch.randn(1, 3)
>>> a
tensor([[ 0.6763,  0.7445, -2.2369]])
>>> torch.max(a)
tensor(0.7445)

geomstats._backend.pytorch.max(input, dim, keepdim=False, *, out=None)

Returns a namedtuple (values, indices) where values is the maximum value of each row of the input tensor in the given dimension dim. And indices is the index location of each maximum value found (argmax).

If keepdim is True, the output tensors are of the same size as input except in the dimension dim where they are of size 1. Otherwise, dim is squeezed (see torch.squeeze()), resulting in the output tensors having 1 fewer dimension than input.

Note

If there are multiple maximal values in a reduced row then the indices of the first maximal value are returned.

Args:

input (Tensor): the input tensor. dim (int): the dimension to reduce. keepdim (bool): whether the output tensor has dim retained or not. Default: False.

Keyword args:

out (tuple, optional): the result tuple of two output tensors (max, max_indices)

Example:

>>> a = torch.randn(4, 4)
>>> a
tensor([[-1.2360, -0.2942, -0.1222,  0.8475],
[ 1.1949, -1.1127, -2.2379, -0.6702],
[ 1.5717, -0.9207,  0.1297, -1.8768],
[-0.6172,  1.0036, -0.6060, -0.2432]])
>>> torch.max(a, 1)
torch.return_types.max(values=tensor([0.8475, 1.1949, 1.5717, 1.0036]), indices=tensor([3, 0, 0, 1]))

geomstats._backend.pytorch.max(input, other, *, out=None) Tensor

See torch.maximum().

geomstats._backend.pytorch.angle(input, *, out=None) Tensor#

Computes the element-wise angle (in radians) of the given input tensor.

$\text{out}_{i} = angle(\text{input}_{i})$
Args:

input (Tensor): the input tensor.

Keyword args:

out (Tensor, optional): the output tensor.

Note

Starting in PyTorch 1.8, angle returns pi for negative real numbers, zero for non-negative real numbers, and propagates NaNs. Previously the function would return zero for all real numbers and not propagate floating-point NaNs.

Example:

>>> torch.angle(torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j]))*180/3.14159
tensor([ 135.,  135,  -45])

geomstats._backend.pytorch.arange(start=0, end, step=1, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) Tensor#

Returns a 1-D tensor of size $$\left\lceil \frac{\text{end} - \text{start}}{\text{step}} \right\rceil$$ with values from the interval [start, end) taken with common difference step beginning from start.

Note that non-integer step is subject to floating point rounding errors when comparing against end; to avoid inconsistency, we advise adding a small epsilon to end in such cases.

$\text{out}_{{i+1}} = \text{out}_{i} + \text{step}$
Args:

start (Number): the starting value for the set of points. Default: 0. end (Number): the ending value for the set of points step (Number): the gap between each pair of adjacent points. Default: 1.

Keyword args:

out (Tensor, optional): the output tensor. dtype (torch.dtype, optional): the desired data type of returned tensor.

Default: if None, uses a global default (see torch.set_default_tensor_type()). If dtype is not given, infer the data type from the other input arguments. If any of start, end, or stop are floating-point, the dtype is inferred to be the default dtype, see get_default_dtype(). Otherwise, the dtype is inferred to be torch.int64.

layout (torch.layout, optional): the desired layout of returned Tensor.

Default: torch.strided.

device (torch.device, optional): the desired device of returned tensor.

Default: if None, uses the current device for the default tensor type (see torch.set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

returned tensor. Default: False.

Example:

>>> torch.arange(5)
tensor([ 0,  1,  2,  3,  4])
>>> torch.arange(1, 4)
tensor([ 1,  2,  3])
>>> torch.arange(1, 2.5, 0.5)
tensor([ 1.0000,  1.5000,  2.0000])

geomstats._backend.pytorch.arccos(input, *, out=None) Tensor#

Alias for torch.acos().

geomstats._backend.pytorch.arccosh(input, *, out=None) Tensor#

Alias for torch.acosh().

geomstats._backend.pytorch.arcsin(input, *, out=None) Tensor#

Alias for torch.asin().

geomstats._backend.pytorch.arctan2()#

atan2(input, other, *, out=None) -> Tensor

Element-wise arctangent of $$\text{input}_{i} / \text{other}_{i}$$ with consideration of the quadrant. Returns a new tensor with the signed angles in radians between vector $$(\text{other}_{i}, \text{input}_{i})$$ and vector $$(1, 0)$$. (Note that $$\text{other}_{i}$$, the second parameter, is the x-coordinate, while $$\text{input}_{i}$$, the first parameter, is the y-coordinate.)

The shapes of input and other must be broadcastable.

Args:

input (Tensor): the first input tensor other (Tensor): the second input tensor

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> a = torch.randn(4)
>>> a
tensor([ 0.9041,  0.0196, -0.3108, -2.4423])
>>> torch.atan2(a, torch.randn(4))
tensor([ 0.9833,  0.0811, -1.9743, -1.4151])

geomstats._backend.pytorch.arctanh(input, *, out=None) Tensor#

Alias for torch.atanh().

geomstats._backend.pytorch.argmin(input, dim=None, keepdim=False) LongTensor#

Returns the indices of the minimum value(s) of the flattened tensor or along a dimension

This is the second value returned by torch.min(). See its documentation for the exact semantics of this method.

Note

If there are multiple minimal values then the indices of the first minimal value are returned.

Args:

input (Tensor): the input tensor. dim (int): the dimension to reduce. If None, the argmin of the flattened input is returned. keepdim (bool): whether the output tensor has dim retained or not. Ignored if dim=None.

Example:

>>> a = torch.randn(4, 4)
>>> a
tensor([[ 0.1139,  0.2254, -0.1381,  0.3687],
[ 1.0100, -1.1975, -0.0102, -0.4732],
[-0.9240,  0.1207, -0.7506, -1.0213],
[ 1.7809, -1.2960,  0.9384,  0.1438]])
>>> torch.argmin(a)
tensor(13)
>>> torch.argmin(a, dim=1)
tensor([ 2,  1,  3,  1])
>>> torch.argmin(a, dim=1, keepdim=True)
tensor([[2],
[1],
[3],
[1]])

geomstats._backend.pytorch.array_from_sparse(indices, data, target_shape)[source]#

Create an array of given shape, with values at specific indices.

The rest of the array will be filled with zeros.

Parameters:
• indices (iterable(tuple(int))) – Index of each element which will be assigned a specific value.

• data (iterable(scalar)) – Value associated at each index.

• target_shape (tuple(int)) – Shape of the output array.

Returns:

a (array, shape=target_shape) – Array of zeros with specified values assigned to specified indices.

geomstats._backend.pytorch.assignment(x, values, indices, axis=0)[source]#

Assign values at given indices of an array.

Parameters:
• x (array-like, shape=[dim]) – Initial array.

• values ({float, list(float)}) – Value or list of values to be assigned.

• indices ({int, tuple, list(int), list(tuple)}) – Single int or tuple, or list of ints or tuples of indices where value is assigned. If the length of the tuples is shorter than ndim(x), values are assigned to each copy along axis.

• axis (int, optional) – Axis along which values are assigned, if vectorized.

Returns:

x_new (array-like, shape=[dim]) – Copy of x with the values assigned at the given indices.

Notes

If a single value is provided, it is assigned at all the indices. If a list is given, it must have the same length as indices.

geomstats._backend.pytorch.assignment_by_sum(x, values, indices, axis=0)[source]#

Add values at given indices of an array.

Parameters:
• x (array-like, shape=[dim]) – Initial array.

• values ({float, list(float)}) – Value or list of values to be assigned.

• indices ({int, tuple, list(int), list(tuple)}) – Single int or tuple, or list of ints or tuples of indices where value is assigned. If the length of the tuples is shorter than ndim(x), values are assigned to each copy along axis.

• axis (int, optional) – Axis along which values are assigned, if vectorized.

Returns:

x_new (array-like, shape=[dim]) – Copy of x with the values assigned at the given indices.

Notes

If a single value is provided, it is assigned at all the indices. If a list is given, it must have the same length as indices.

geomstats._backend.pytorch.ceil(input, *, out=None) Tensor#

Returns a new tensor with the ceil of the elements of input, the smallest integer greater than or equal to each element.

$\text{out}_{i} = \left\lceil \text{input}_{i} \right\rceil$
Args:

input (Tensor): the input tensor.

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> a = torch.randn(4)
>>> a
tensor([-0.6341, -1.4208, -1.0900,  0.5826])
>>> torch.ceil(a)
tensor([-0., -1., -1.,  1.])

geomstats._backend.pytorch.clip(input, min=None, max=None, *, out=None) Tensor#

Alias for torch.clamp().

geomstats._backend.pytorch.conj(input) Tensor#

Returns a view of input with a flipped conjugate bit. If input has a non-complex dtype, this function just returns input.

Note

torch.conj() performs a lazy conjugation, but the actual conjugated tensor can be materialized at any time using torch.resolve_conj().

Warning

In the future, torch.conj() may return a non-writeable view for an input of non-complex dtype. It’s recommended that programs not modify the tensor returned by torch.conj_physical() when input is of non-complex dtype to be compatible with this change.

Args:

input (Tensor): the input tensor.

Example:

>>> x = torch.tensor([-1 + 1j, -2 + 2j, 3 - 3j])
>>> x.is_conj()
False
>>> y = torch.conj(x)
>>> y.is_conj()
True

geomstats._backend.pytorch.cos(input, *, out=None) Tensor#

Returns a new tensor with the cosine of the elements of input.

$\text{out}_{i} = \cos(\text{input}_{i})$
Args:

input (Tensor): the input tensor.

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> a = torch.randn(4)
>>> a
tensor([ 1.4309,  1.2706, -0.8562,  0.9796])
>>> torch.cos(a)
tensor([ 0.1395,  0.2957,  0.6553,  0.5574])

geomstats._backend.pytorch.cosh(input, *, out=None) Tensor#

Returns a new tensor with the hyperbolic cosine of the elements of input.

$\text{out}_{i} = \cosh(\text{input}_{i})$
Args:

input (Tensor): the input tensor.

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> a = torch.randn(4)
>>> a
tensor([ 0.1632,  1.1835, -0.6979, -0.7325])
>>> torch.cosh(a)
tensor([ 1.0133,  1.7860,  1.2536,  1.2805])


Note

When input is on the CPU, the implementation of torch.cosh may use the Sleef library, which rounds very large results to infinity or negative infinity. See here for details.

geomstats._backend.pytorch.empty_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) Tensor#

Returns an uninitialized tensor with the same size as input. torch.empty_like(input) is equivalent to torch.empty(input.size(), dtype=input.dtype, layout=input.layout, device=input.device).

Args:

input (Tensor): the size of input will determine size of the output tensor.

Keyword args:
dtype (torch.dtype, optional): the desired data type of returned Tensor.

Default: if None, defaults to the dtype of input.

layout (torch.layout, optional): the desired layout of returned tensor.

Default: if None, defaults to the layout of input.

device (torch.device, optional): the desired device of returned tensor.

Default: if None, defaults to the device of input.

returned tensor. Default: False.

memory_format (torch.memory_format, optional): the desired memory format of

returned Tensor. Default: torch.preserve_format.

Example:

>>> a=torch.empty((2,3), dtype=torch.int32, device = 'cuda')
>>> torch.empty_like(a)
tensor([[0, 0, 0],
[0, 0, 0]], device='cuda:0', dtype=torch.int32)

geomstats._backend.pytorch.erf(input, *, out=None) Tensor#

Alias for torch.special.erf().

geomstats._backend.pytorch.exp(input, *, out=None) Tensor#

Returns a new tensor with the exponential of the elements of the input tensor input.

$y_{i} = e^{x_{i}}$
Args:

input (Tensor): the input tensor.

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> torch.exp(torch.tensor([0, math.log(2.)]))
tensor([ 1.,  2.])

geomstats._backend.pytorch.eye(n, m=None, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) Tensor#

Returns a 2-D tensor with ones on the diagonal and zeros elsewhere.

Args:

n (int): the number of rows m (int, optional): the number of columns with default being n

Keyword arguments:

out (Tensor, optional): the output tensor. dtype (torch.dtype, optional): the desired data type of returned tensor.

Default: if None, uses a global default (see torch.set_default_tensor_type()).

layout (torch.layout, optional): the desired layout of returned Tensor.

Default: torch.strided.

device (torch.device, optional): the desired device of returned tensor.

Default: if None, uses the current device for the default tensor type (see torch.set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

returned tensor. Default: False.

Returns:

Tensor: A 2-D tensor with ones on the diagonal and zeros elsewhere

Example:

>>> torch.eye(3)
tensor([[ 1.,  0.,  0.],
[ 0.,  1.,  0.],
[ 0.,  0.,  1.]])

geomstats._backend.pytorch.flatten(input, start_dim=0, end_dim=- 1) Tensor#

Flattens input by reshaping it into a one-dimensional tensor. If start_dim or end_dim are passed, only dimensions starting with start_dim and ending with end_dim are flattened. The order of elements in input is unchanged.

Unlike NumPy’s flatten, which always copies input’s data, this function may return the original object, a view, or copy. If no dimensions are flattened, then the original object input is returned. Otherwise, if input can be viewed as the flattened shape, then that view is returned. Finally, only if the input cannot be viewed as the flattened shape is input’s data copied. See torch.Tensor.view() for details on when a view will be returned.

Note

Flattening a zero-dimensional tensor will return a one-dimensional view.

Args:

input (Tensor): the input tensor. start_dim (int): the first dim to flatten end_dim (int): the last dim to flatten

Example:

>>> t = torch.tensor([[[1, 2],
...                    [3, 4]],
...                   [[5, 6],
...                    [7, 8]]])
>>> torch.flatten(t)
tensor([1, 2, 3, 4, 5, 6, 7, 8])
>>> torch.flatten(t, start_dim=1)
tensor([[1, 2, 3, 4],
[5, 6, 7, 8]])

geomstats._backend.pytorch.floor(input, *, out=None) Tensor#

Returns a new tensor with the floor of the elements of input, the largest integer less than or equal to each element.

$\text{out}_{i} = \left\lfloor \text{input}_{i} \right\rfloor$
Args:

input (Tensor): the input tensor.

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> a = torch.randn(4)
>>> a
tensor([-0.8166,  1.5308, -0.2530, -0.2091])
>>> torch.floor(a)
tensor([-1.,  1., -1., -1.])


Create a 1D array of zeros with one element at one, with floating type.

Parameters:
• i (int) – Index of the non-zero element.

• n (n) – Length of the created array.

Returns:

mask_i_float (array-like, shape=[n,]) – 1D array of zeros except at index i, where it is one

geomstats._backend.pytorch.get_slice(x, indices)[source]#

Return a slice of an array, following Numpy’s style.

Parameters:
• x (array-like, shape=[dim]) – Initial array.

• indices (iterable(iterable(int))) – Indices which are kept along each axis, starting from 0.

Returns:

slice (array-like) – Slice of x given by indices.

Notes

This follows Numpy’s convention: indices are grouped by axis.

Examples

>>> a = torch.tensor(range(30)).reshape(3,10)
>>> get_slice(a, ((0, 2), (8, 9)))
tensor([8, 29])

geomstats._backend.pytorch.greater(input, other, *, out=None) Tensor#

Alias for torch.gt().

geomstats._backend.pytorch.hstack(tensors, *, out=None) Tensor#

Stack tensors in sequence horizontally (column wise).

This is equivalent to concatenation along the first axis for 1-D tensors, and along the second axis for all other tensors.

Args:

tensors (sequence of Tensors): sequence of tensors to concatenate

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> a = torch.tensor([1, 2, 3])
>>> b = torch.tensor([4, 5, 6])
>>> torch.hstack((a,b))
tensor([1, 2, 3, 4, 5, 6])
>>> a = torch.tensor([[1],[2],[3]])
>>> b = torch.tensor([[4],[5],[6]])
>>> torch.hstack((a,b))
tensor([[1, 4],
[2, 5],
[3, 6]])

geomstats._backend.pytorch.imag(input) Tensor#

Returns a new tensor containing imaginary values of the self tensor. The returned tensor and self share the same underlying storage.

Warning

imag() is only supported for tensors with complex dtypes.

Args:

input (Tensor): the input tensor.

Example:

>>> x=torch.randn(4, dtype=torch.cfloat)
>>> x
tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
>>> x.imag
tensor([ 0.3553, -0.7896, -0.0633, -0.8119])

geomstats._backend.pytorch.isnan(input) Tensor#

Returns a new tensor with boolean elements representing if each element of input is NaN or not. Complex values are considered NaN when either their real and/or imaginary part is NaN.

Arguments:

input (Tensor): the input tensor.

Returns:

A boolean tensor that is True where input is NaN and False elsewhere

Example:

>>> torch.isnan(torch.tensor([1, float('nan'), 2]))
tensor([False, True, False])

geomstats._backend.pytorch.kron(input, other, *, out=None) Tensor#

Computes the Kronecker product, denoted by $$\otimes$$, of input and other.

If input is a $$(a_0 \times a_1 \times \dots \times a_n)$$ tensor and other is a $$(b_0 \times b_1 \times \dots \times b_n)$$ tensor, the result will be a $$(a_0*b_0 \times a_1*b_1 \times \dots \times a_n*b_n)$$ tensor with the following entries:

$(\text{input} \otimes \text{other})_{k_0, k_1, \dots, k_n} = \text{input}_{i_0, i_1, \dots, i_n} * \text{other}_{j_0, j_1, \dots, j_n},$

where $$k_t = i_t * b_t + j_t$$ for $$0 \leq t \leq n$$. If one tensor has fewer dimensions than the other it is unsqueezed until it has the same number of dimensions.

Supports real-valued and complex-valued inputs.

Note

This function generalizes the typical definition of the Kronecker product for two matrices to two tensors, as described above. When input is a $$(m \times n)$$ matrix and other is a $$(p \times q)$$ matrix, the result will be a $$(p*m \times q*n)$$ block matrix:

$\begin{split}\mathbf{A} \otimes \mathbf{B}=\begin{bmatrix} a_{11} \mathbf{B} & \cdots & a_{1 n} \mathbf{B} \\ \vdots & \ddots & \vdots \\ a_{m 1} \mathbf{B} & \cdots & a_{m n} \mathbf{B} \end{bmatrix}\end{split}$

where input is $$\mathbf{A}$$ and other is $$\mathbf{B}$$.

Arguments:

input (Tensor) other (Tensor)

Keyword args:

out (Tensor, optional): The output tensor. Ignored if None. Default: None

Examples:

>>> mat1 = torch.eye(2)
>>> mat2 = torch.ones(2, 2)
>>> torch.kron(mat1, mat2)
tensor([[1., 1., 0., 0.],
[1., 1., 0., 0.],
[0., 0., 1., 1.],
[0., 0., 1., 1.]])

>>> mat1 = torch.eye(2)
>>> mat2 = torch.arange(1, 5).reshape(2, 2)
>>> torch.kron(mat1, mat2)
tensor([[1., 2., 0., 0.],
[3., 4., 0., 0.],
[0., 0., 1., 2.],
[0., 0., 3., 4.]])

geomstats._backend.pytorch.less(input, other, *, out=None) Tensor#

Alias for torch.lt().

geomstats._backend.pytorch.log(input, *, out=None) Tensor#

Returns a new tensor with the natural logarithm of the elements of input.

$y_{i} = \log_{e} (x_{i})$
Args:

input (Tensor): the input tensor.

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> a = torch.randn(5)
>>> a
tensor([-0.7168, -0.5471, -0.8933, -1.4428, -0.1190])
>>> torch.log(a)
tensor([ nan,  nan,  nan,  nan,  nan])

geomstats._backend.pytorch.logical_or(input, other, *, out=None) Tensor#

Computes the element-wise logical OR of the given input tensors. Zeros are treated as False and nonzeros are treated as True.

Args:

input (Tensor): the input tensor. other (Tensor): the tensor to compute OR with

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> torch.logical_or(torch.tensor([True, False, True]), torch.tensor([True, False, False]))
tensor([ True, False,  True])
>>> a = torch.tensor([0, 1, 10, 0], dtype=torch.int8)
>>> b = torch.tensor([4, 0, 1, 0], dtype=torch.int8)
>>> torch.logical_or(a, b)
tensor([ True,  True,  True, False])
>>> torch.logical_or(a.double(), b.double())
tensor([ True,  True,  True, False])
>>> torch.logical_or(a.double(), b)
tensor([ True,  True,  True, False])
>>> torch.logical_or(a, b, out=torch.empty(4, dtype=torch.bool))
tensor([ True,  True,  True, False])

geomstats._backend.pytorch.mat_from_diag_triu_tril(diag, tri_upp, tri_low)[source]#

Build matrix from given components.

Forms a matrix from diagonal, strictly upper triangular and strictly lower traingular parts.

Parameters:
• diag (array_like, shape=[…, n])

• tri_upp (array_like, shape=[…, (n * (n - 1)) / 2])

• tri_low (array_like, shape=[…, (n * (n - 1)) / 2])

Returns:

mat (array_like, shape=[…, n, n])

geomstats._backend.pytorch.mean(input, *, dtype=None) Tensor#

Returns the mean value of all elements in the input tensor.

Args:

input (Tensor): the input tensor.

Keyword args:
dtype (torch.dtype, optional): the desired data type of returned tensor.

If specified, the input tensor is casted to dtype before the operation is performed. This is useful for preventing data type overflows. Default: None.

Example:

>>> a = torch.randn(1, 3)
>>> a
tensor([[ 0.2294, -0.5481,  1.3288]])
>>> torch.mean(a)
tensor(0.3367)

geomstats._backend.pytorch.mean(input, dim, keepdim=False, *, dtype=None, out=None) Tensor

Returns the mean value of each row of the input tensor in the given dimension dim. If dim is a list of dimensions, reduce over all of them.

If keepdim is True, the output tensor is of the same size as input except in the dimension(s) dim where it is of size 1. Otherwise, dim is squeezed (see torch.squeeze()), resulting in the output tensor having 1 (or len(dim)) fewer dimension(s).

Args:

input (Tensor): the input tensor. dim (int or tuple of ints): the dimension or dimensions to reduce. keepdim (bool): whether the output tensor has dim retained or not.

Keyword args:
dtype (torch.dtype, optional): the desired data type of returned tensor.

If specified, the input tensor is casted to dtype before the operation is performed. This is useful for preventing data type overflows. Default: None.

out (Tensor, optional): the output tensor.

torch.nanmean() computes the mean value of non-NaN elements.

Example:

>>> a = torch.randn(4, 4)
>>> a
tensor([[-0.3841,  0.6320,  0.4254, -0.7384],
[-0.9644,  1.0131, -0.6549, -1.4279],
[-0.2951, -1.3350, -0.7694,  0.5600],
[ 1.0842, -0.9580,  0.3623,  0.2343]])
>>> torch.mean(a, 1)
tensor([-0.0163, -0.5085, -0.4599,  0.1807])
>>> torch.mean(a, 1, True)
tensor([[-0.0163],
[-0.5085],
[-0.4599],
[ 0.1807]])

geomstats._backend.pytorch.mod()#

fmod(input, other, *, out=None) -> Tensor

Applies C++’s std::fmod entrywise. The result has the same sign as the dividend input and its absolute value is less than that of other.

This function may be defined in terms of torch.div() as

torch.fmod(a, b) == a - a.div(b, rounding_mode="trunc") * b


Supports broadcasting to a common shape, type promotion, and integer and float inputs.

Note

When the divisor is zero, returns NaN for floating point dtypes on both CPU and GPU; raises RuntimeError for integer division by zero on CPU; Integer division by zero on GPU may return any value.

Note

Complex inputs are not supported. In some cases, it is not mathematically possible to satisfy the definition of a modulo operation with complex numbers.

torch.remainder() which implements Python’s modulus operator. This one is defined using division rounding down the result.

Args:

input (Tensor): the dividend other (Tensor or Scalar): the divisor

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> torch.fmod(torch.tensor([-3., -2, -1, 1, 2, 3]), 2)
tensor([-1., -0., -1.,  1.,  0.,  1.])
>>> torch.fmod(torch.tensor([1, 2, 3, 4, 5]), -1.5)
tensor([1.0000, 0.5000, 0.0000, 1.0000, 0.5000])

geomstats._backend.pytorch.moveaxis(input, source, destination) Tensor#

Alias for torch.movedim().

This function is equivalent to NumPy’s moveaxis function.

Examples:

>>> t = torch.randn(3,2,1)
>>> t
tensor([[[-0.3362],
[-0.8437]],

[[-0.9627],
[ 0.1727]],

[[ 0.5173],
[-0.1398]]])
>>> torch.moveaxis(t, 1, 0).shape
torch.Size([2, 3, 1])
>>> torch.moveaxis(t, 1, 0)
tensor([[[-0.3362],
[-0.9627],
[ 0.5173]],

[[-0.8437],
[ 0.1727],
[-0.1398]]])
>>> torch.moveaxis(t, (1, 2), (0, 1)).shape
torch.Size([2, 1, 3])
>>> torch.moveaxis(t, (1, 2), (0, 1))
tensor([[[-0.3362, -0.9627,  0.5173]],

[[-0.8437,  0.1727, -0.1398]]])

geomstats._backend.pytorch.ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) Tensor#

Returns a tensor filled with the scalar value 1, with the shape defined by the variable argument size.

Args:
size (int…): a sequence of integers defining the shape of the output tensor.

Can be a variable number of arguments or a collection like a list or tuple.

Keyword arguments:

out (Tensor, optional): the output tensor. dtype (torch.dtype, optional): the desired data type of returned tensor.

Default: if None, uses a global default (see torch.set_default_tensor_type()).

layout (torch.layout, optional): the desired layout of returned Tensor.

Default: torch.strided.

device (torch.device, optional): the desired device of returned tensor.

Default: if None, uses the current device for the default tensor type (see torch.set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

returned tensor. Default: False.

Example:

>>> torch.ones(2, 3)
tensor([[ 1.,  1.,  1.],
[ 1.,  1.,  1.]])

>>> torch.ones(5)
tensor([ 1.,  1.,  1.,  1.,  1.])

geomstats._backend.pytorch.ones_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) Tensor#

Returns a tensor filled with the scalar value 1, with the same size as input. torch.ones_like(input) is equivalent to torch.ones(input.size(), dtype=input.dtype, layout=input.layout, device=input.device).

Warning

As of 0.4, this function does not support an out keyword. As an alternative, the old torch.ones_like(input, out=output) is equivalent to torch.ones(input.size(), out=output).

Args:

input (Tensor): the size of input will determine size of the output tensor.

Keyword arguments:
dtype (torch.dtype, optional): the desired data type of returned Tensor.

Default: if None, defaults to the dtype of input.

layout (torch.layout, optional): the desired layout of returned tensor.

Default: if None, defaults to the layout of input.

device (torch.device, optional): the desired device of returned tensor.

Default: if None, defaults to the device of input.

returned tensor. Default: False.

memory_format (torch.memory_format, optional): the desired memory format of

returned Tensor. Default: torch.preserve_format.

Example:

>>> input = torch.empty(2, 3)
>>> torch.ones_like(input)
tensor([[ 1.,  1.,  1.],
[ 1.,  1.,  1.]])

geomstats._backend.pytorch.polygamma(n, input, *, out=None) Tensor#

Alias for torch.special.polygamma().

geomstats._backend.pytorch.power()#

pow(input, exponent, *, out=None) -> Tensor

Takes the power of each element in input with exponent and returns a tensor with the result.

exponent can be either a single float number or a Tensor with the same number of elements as input.

When exponent is a scalar value, the operation applied is:

$\text{out}_i = x_i ^ \text{exponent}$

When exponent is a tensor, the operation applied is:

$\text{out}_i = x_i ^ {\text{exponent}_i}$

When exponent is a tensor, the shapes of input and exponent must be broadcastable.

Args:

input (Tensor): the input tensor. exponent (float or tensor): the exponent value

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> a = torch.randn(4)
>>> a
tensor([ 0.4331,  1.2475,  0.6834, -0.2791])
>>> torch.pow(a, 2)
tensor([ 0.1875,  1.5561,  0.4670,  0.0779])
>>> exp = torch.arange(1., 5.)

>>> a = torch.arange(1., 5.)
>>> a
tensor([ 1.,  2.,  3.,  4.])
>>> exp
tensor([ 1.,  2.,  3.,  4.])
>>> torch.pow(a, exp)
tensor([   1.,    4.,   27.,  256.])

geomstats._backend.pytorch.pow(self, exponent, *, out=None) Tensor

self is a scalar float value, and exponent is a tensor. The returned tensor out is of the same shape as exponent

The operation applied is:

$\text{out}_i = \text{self} ^ {\text{exponent}_i}$
Args:

self (float): the scalar base value for the power operation exponent (Tensor): the exponent tensor

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> exp = torch.arange(1., 5.)
>>> base = 2
>>> torch.pow(base, exp)
tensor([  2.,   4.,   8.,  16.])

geomstats._backend.pytorch.real(input) Tensor#

Returns a new tensor containing real values of the self tensor. The returned tensor and self share the same underlying storage.

Warning

real() is only supported for tensors with complex dtypes.

Args:

input (Tensor): the input tensor.

Example:

>>> x=torch.randn(4, dtype=torch.cfloat)
>>> x
tensor([(0.3100+0.3553j), (-0.5445-0.7896j), (-1.6492-0.0633j), (-0.0638-0.8119j)])
>>> x.real
tensor([ 0.3100, -0.5445, -1.6492, -0.0638])

geomstats._backend.pytorch.repeat()#

repeat_interleave(input, repeats, dim=None, *, output_size=None) -> Tensor

Repeat elements of a tensor.

Warning

This is different from torch.Tensor.repeat() but similar to numpy.repeat.

Args:

input (Tensor): the input tensor. repeats (Tensor or int): The number of repetitions for each element.

repeats is broadcasted to fit the shape of the given axis.

dim (int, optional): The dimension along which to repeat values.

By default, use the flattened input array, and return a flat output array.

Keyword args:
output_size (int, optional): Total output size for the given axis

( e.g. sum of repeats). If given, it will avoid stream syncronization needed to calculate output shape of the tensor.

Returns:

Tensor: Repeated tensor which has the same shape as input, except along the given axis.

Example:

>>> x = torch.tensor([1, 2, 3])
>>> x.repeat_interleave(2)
tensor([1, 1, 2, 2, 3, 3])
>>> y = torch.tensor([[1, 2], [3, 4]])
>>> torch.repeat_interleave(y, 2)
tensor([1, 1, 2, 2, 3, 3, 4, 4])
>>> torch.repeat_interleave(y, 3, dim=1)
tensor([[1, 1, 1, 2, 2, 2],
[3, 3, 3, 4, 4, 4]])
>>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0)
tensor([[1, 2],
[3, 4],
[3, 4]])
>>> torch.repeat_interleave(y, torch.tensor([1, 2]), dim=0, output_size=3)
tensor([[1, 2],
[3, 4],
[3, 4]])

geomstats._backend.pytorch.repeat_interleave(repeats, *, output_size=None) Tensor

If the repeats is tensor([n1, n2, n3, …]), then the output will be tensor([0, 0, …, 1, 1, …, 2, 2, …, …]) where 0 appears n1 times, 1 appears n2 times, 2 appears n3 times, etc.

geomstats._backend.pytorch.reshape(input, shape) Tensor#

Returns a tensor with the same data and number of elements as input, but with the specified shape. When possible, the returned tensor will be a view of input. Otherwise, it will be a copy. Contiguous inputs and inputs with compatible strides can be reshaped without copying, but you should not depend on the copying vs. viewing behavior.

See torch.Tensor.view() on when it is possible to return a view.

A single dimension may be -1, in which case it’s inferred from the remaining dimensions and the number of elements in input.

Args:

input (Tensor): the tensor to be reshaped shape (tuple of ints): the new shape

Example:

>>> a = torch.arange(4.)
>>> torch.reshape(a, (2, 2))
tensor([[ 0.,  1.],
[ 2.,  3.]])
>>> b = torch.tensor([[0, 1], [2, 3]])
>>> torch.reshape(b, (-1,))
tensor([ 0,  1,  2,  3])

geomstats._backend.pytorch.set_diag(x, new_diag)[source]#

Set the diagonal along the last two axis.

Parameters:
• x (array-like, shape=[dim]) – Initial array.

• new_diag (array-like, shape=[dim[-2]]) – Values to set on the diagonal.

Returns:

None

Notes

This mimics tensorflow.linalg.set_diag(x, new_diag), when new_diag is a 1-D array, but modifies x instead of creating a copy.

geomstats._backend.pytorch.sign(input, *, out=None) Tensor#

Returns a new tensor with the signs of the elements of input.

$\text{out}_{i} = \operatorname{sgn}(\text{input}_{i})$
Args:

input (Tensor): the input tensor.

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> a = torch.tensor([0.7, -1.2, 0., 2.3])
>>> a
tensor([ 0.7000, -1.2000,  0.0000,  2.3000])
>>> torch.sign(a)
tensor([ 1., -1.,  0.,  1.])

geomstats._backend.pytorch.sin(input, *, out=None) Tensor#

Returns a new tensor with the sine of the elements of input.

$\text{out}_{i} = \sin(\text{input}_{i})$
Args:

input (Tensor): the input tensor.

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> a = torch.randn(4)
>>> a
tensor([-0.5461,  0.1347, -2.7266, -0.2746])
>>> torch.sin(a)
tensor([-0.5194,  0.1343, -0.4032, -0.2711])

geomstats._backend.pytorch.sinh(input, *, out=None) Tensor#

Returns a new tensor with the hyperbolic sine of the elements of input.

$\text{out}_{i} = \sinh(\text{input}_{i})$
Args:

input (Tensor): the input tensor.

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> a = torch.randn(4)
>>> a
tensor([ 0.5380, -0.8632, -0.1265,  0.9399])
>>> torch.sinh(a)
tensor([ 0.5644, -0.9744, -0.1268,  1.0845])


Note

When input is on the CPU, the implementation of torch.sinh may use the Sleef library, which rounds very large results to infinity or negative infinity. See here for details.

geomstats._backend.pytorch.stack(tensors, dim=0, *, out=None) Tensor#

Concatenates a sequence of tensors along a new dimension.

All tensors need to be of the same size.

Arguments:

tensors (sequence of Tensors): sequence of tensors to concatenate dim (int): dimension to insert. Has to be between 0 and the number

of dimensions of concatenated tensors (inclusive)

Keyword args:

out (Tensor, optional): the output tensor.

geomstats._backend.pytorch.std(input, dim, unbiased, keepdim=False, *, out=None) Tensor#

If unbiased is True, Bessel’s correction will be used. Otherwise, the sample deviation is calculated, without any correction.

Args:

input (Tensor): the input tensor. dim (int or tuple of ints): the dimension or dimensions to reduce.

Keyword args:

unbiased (bool): whether to use Bessel’s correction ($$\delta N = 1$$). keepdim (bool): whether the output tensor has dim retained or not. out (Tensor, optional): the output tensor.

geomstats._backend.pytorch.std(input, unbiased) Tensor

Calculates the standard deviation of all elements in the input tensor.

If unbiased is True, Bessel’s correction will be used. Otherwise, the sample deviation is calculated, without any correction.

Args:

input (Tensor): the input tensor. unbiased (bool): whether to use Bessel’s correction ($$\delta N = 1$$).

Example:

>>> a = torch.tensor([[-0.8166, -1.3802, -0.3560]])
>>> torch.std(a, unbiased=False)
tensor(0.4188)

geomstats._backend.pytorch.tan(input, *, out=None) Tensor#

Returns a new tensor with the tangent of the elements of input.

$\text{out}_{i} = \tan(\text{input}_{i})$
Args:

input (Tensor): the input tensor.

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> a = torch.randn(4)
>>> a
tensor([-1.2027, -1.7687,  0.4412, -1.3856])
>>> torch.tan(a)
tensor([-2.5930,  4.9859,  0.4722, -5.3366])

geomstats._backend.pytorch.tanh(input, *, out=None) Tensor#

Returns a new tensor with the hyperbolic tangent of the elements of input.

$\text{out}_{i} = \tanh(\text{input}_{i})$
Args:

input (Tensor): the input tensor.

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> a = torch.randn(4)
>>> a
tensor([ 0.8986, -0.7279,  1.1745,  0.2611])
>>> torch.tanh(a)
tensor([ 0.7156, -0.6218,  0.8257,  0.2553])

geomstats._backend.pytorch.trapz(y, x, *, dim=- 1) Tensor#

Alias for torch.trapezoid().

geomstats._backend.pytorch.vstack(tensors, *, out=None) Tensor#

Stack tensors in sequence vertically (row wise).

This is equivalent to concatenation along the first axis after all 1-D tensors have been reshaped by torch.atleast_2d().

Args:

tensors (sequence of Tensors): sequence of tensors to concatenate

Keyword args:

out (Tensor, optional): the output tensor.

Example:

>>> a = torch.tensor([1, 2, 3])
>>> b = torch.tensor([4, 5, 6])
>>> torch.vstack((a,b))
tensor([[1, 2, 3],
[4, 5, 6]])
>>> a = torch.tensor([[1],[2],[3]])
>>> b = torch.tensor([[4],[5],[6]])
>>> torch.vstack((a,b))
tensor([[1],
[2],
[3],
[4],
[5],
[6]])

geomstats._backend.pytorch.zeros(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) Tensor#

Returns a tensor filled with the scalar value 0, with the shape defined by the variable argument size.

Args:
size (int…): a sequence of integers defining the shape of the output tensor.

Can be a variable number of arguments or a collection like a list or tuple.

Keyword args:

out (Tensor, optional): the output tensor. dtype (torch.dtype, optional): the desired data type of returned tensor.

Default: if None, uses a global default (see torch.set_default_tensor_type()).

layout (torch.layout, optional): the desired layout of returned Tensor.

Default: torch.strided.

device (torch.device, optional): the desired device of returned tensor.

Default: if None, uses the current device for the default tensor type (see torch.set_default_tensor_type()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types.

returned tensor. Default: False.

Example:

>>> torch.zeros(2, 3)
tensor([[ 0.,  0.,  0.],
[ 0.,  0.,  0.]])

>>> torch.zeros(5)
tensor([ 0.,  0.,  0.,  0.,  0.])

geomstats._backend.pytorch.zeros_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) Tensor#

Returns a tensor filled with the scalar value 0, with the same size as input. torch.zeros_like(input) is equivalent to torch.zeros(input.size(), dtype=input.dtype, layout=input.layout, device=input.device).

Warning

As of 0.4, this function does not support an out keyword. As an alternative, the old torch.zeros_like(input, out=output) is equivalent to torch.zeros(input.size(), out=output).

Args:

input (Tensor): the size of input will determine size of the output tensor.

Keyword args:
dtype (torch.dtype, optional): the desired data type of returned Tensor.

Default: if None, defaults to the dtype of input.

layout (torch.layout, optional): the desired layout of returned tensor.

Default: if None, defaults to the layout of input.

device (torch.device, optional): the desired device of returned tensor.

Default: if None, defaults to the device of input.

returned tensor. Default: False.

memory_format (torch.memory_format, optional): the desired memory format of

returned Tensor. Default: torch.preserve_format.

Example:

>>> input = torch.empty(2, 3)
>>> torch.zeros_like(input)
tensor([[ 0.,  0.,  0.],
[ 0.,  0.,  0.]])


Tensorflow based computation backend.

geomstats._backend.tensorflow.array_from_sparse(indices, data, target_shape)[source]#

Create an array of given shape, with values at specific indices.

The rest of the array will be filled with zeros.

Parameters:
• indices (iterable(tuple(int))) – Index of each element which will be assigned a specific value.

• data (iterable(scalar)) – Value associated at each index.

• target_shape (tuple(int)) – Shape of the output array.

Returns:

a (array, shape=target_shape) – Array of zeros with specified values assigned to specified indices.

geomstats._backend.tensorflow.assignment(x, values, indices, axis=0)[source]#

Add values at given indices of an array.

Parameters:
• x (array-like, shape=[dim]) – Initial array.

• values ({float, list(float)}) – Value or list of values to be assigned.

• indices ({)

• int, tuple(int), array-like({int, tuple, boolean}) – Single index or array of indices where values are assigned. If the length of the tuples is shorter than ndim(x) by one, values are assigned to each copy along axis. If indices is a list of booleans and ndim(x) > 1, values are assigned across all dimensions.

• axis (int, optional) – Axis along which values are assigned, if vectorized.

Returns:

x_new (array-like, shape=[dim]) – Copy of x as the sum of x and the values at the given indices.

Notes

If a single value is provided, it is assigned at all the indices. If a single index is provided, and len(indices) == ndim(x) - 1, then values are assigned along axis.

Examples

Most examples translate as assignment(x, indices, values) <=> x[indices] = values Some special cases are given by vectorisation. (Beware that copies are always returned). if ndim(x) == 3, assignment(x, 1, (1, 0), 1) <=> x[1, :, 0] = 1 if ndim(x) == 2, assignment(x, [1, 2], [(0, 1), (2, 3)]) <=>

x[((0, 2), (1, 3))] = [1, 2]

geomstats._backend.tensorflow.assignment_by_sum(x, values, indices, axis=0)[source]#

Add values at given indices of an array.

Parameters:
• x (array-like, shape=[dim]) – Initial array.

• values ({float, list(float)}) – Value or list of values to be assigned.

• indices ({)

• int, tuple(int), array-like({int, tuple, boolean}) – Single index or array of indices where values are assigned. If the length of the tuples is shorter than ndim(x) by one, values are assigned to each copy along axis. If indices is a list of booleans and ndim(x) > 1, values are assigned across all dimensions.

• axis (int, optional) – Axis along which values are assigned, if vectorized.

Returns:

x_new (array-like, shape=[dim]) – Copy of x as the sum of x and the values at the given indices.

Notes

If a single value is provided, it is assigned at all the indices. If a single index is provided, and len(indices) == ndim(x) - 1, then values are assigned along axis.

Examples

Most examples translate as assignment_by_sum(x, indices, values) <=> x[indices] = x[indices] + values Some special cases are given by vectorisation. (Beware that copies are always returned). if ndim(x) == 3, assignment_by_sum(x, 1, (1, 0), 1) <=> x[1, :, 0] += 1 if ndim(x) == 2, assignment_by_sum(x, [1, 2], [(0, 1), (2, 3)]) <=>

x[((0, 2), (1, 3))] += [1, 2]

geomstats._backend.tensorflow.flatten(x)[source]#

Collapse the tensor into 1-D.

Create a 1D array of zeros with one element at one, with floating type.

Parameters:
• i (int) – Index of the non-zero element.

• n (n) – Length of the created array.

Returns:

mask_i_float (array-like, shape=[n,]) – 1D array of zeros except at index i, where it is one

geomstats._backend.tensorflow.get_slice(x, indices)[source]#

Return a slice of an array, following Numpy’s style.

Parameters:
• x (array-like, shape=[dim]) – Initial array.

• indices (iterable(iterable(int))) – Indices which are kept along each axis, starting from 0.

Returns:

slice (array-like) – Slice of x given by indices.

Notes

This follows Numpy’s convention: indices are grouped by axis.

Examples

>>> a = tf.reshape(_tf.convert_to_tensor(range(30)), (3,10))
>>> get_slice(a, ((0, 2), (8, 9)))
<tf.Tensor: id=41, shape=(2,), dtype=int32, numpy=array([ 8, 29])>

geomstats._backend.tensorflow.mat_from_diag_triu_tril(diag, tri_upp, tri_low)[source]#

Build matrix from given components.

Forms a matrix from diagonal, strictly upper triangular and strictly lower traingular parts.

Parameters:
• diag (array_like, shape=[…, n])

• tri_upp (array_like, shape=[…, (n * (n - 1)) / 2])

• tri_low (array_like, shape=[…, (n * (n - 1)) / 2])

Returns:

mat (array_like, shape=[…, n, n])