slogdet#

ivy.slogdet(x, /)[source]#

Return the sign and the natural logarithm of the absolute value of the determinant of a square matrix (or a stack of square matrices) x. .. note:

The purpose of this function is to calculate the determinant more accurately when the determinant is either very small or very large, as calling ``det`` may overflow or underflow.
Parameters:

x (Union[Array, NativeArray]) – input array having shape (..., M, M) and whose innermost two dimensions form square matrices. Should have a real-valued floating-point data type.

Return type:

Tuple[Union[Array, NativeArray], Union[Array, NativeArray]]

Returns:

  • ret – a namedtuple (sign, logabsdet) whose - first element must have the field name sign and must be an array containing a number representing the sign of the determinant for each square matrix. - second element must have the field name logabsdet and must be an array containing the determinant for each square matrix. For a real matrix, the sign of the determinant must be either 1, 0, or -1. Each returned array must have shape shape(x)[:-2] and a real-valued floating-point data type determined by type-promotion. .. note:

    If a determinant is zero, then the corresponding ``sign`` should be ``0`` and ``logabsdet`` should be ``-infinity``; however, depending on the underlying algorithm, the returned result may differ. In all cases, the determinant should be equal to ``sign * exp(logsabsdet)`` (although, again, the result may be subject to numerical precision errors).
    
  • This function conforms to the `Array API Standard

  • <https (//data-apis.org/array-api/latest/>`_. This docstring is an extension of the)

  • `docstring <https (//data-apis.org/array-api/latest/extensions/generated/ signatures.linalg.slogdet.html>`_ # noqa)

  • in the standard.

  • Both the description and the type hints above assumes an array input for simplicity,

  • but this function is nestable, and therefore also accepts ivy.Container

  • instances in place of any of the arguments.

Functional Examples

With ivy.Array input:

>>> x = ivy.array([[2.0, 1.0],
...                [3.0, 4.0]])
>>> y = ivy.slogdet(x)
>>> print(y)
slogdet(sign=ivy.array(1.), logabsdet=ivy.array(1.609438))
>>> x = ivy.array([[1.2, 2.0, 3.1],
...                [6.0, 5.2, 4.0],
...                [9.0, 8.0, 7.0]])
>>> y = ivy.slogdet(x)
>>> print(y)
slogdet(sign=ivy.array(-1.), logabsdet=ivy.array(1.098611))

With ivy.Container input:

>>> x = ivy.Container(a=ivy.array([[1.0, 2.0],
...                                [3.0, 4.0]]),
...                   b=ivy.array([[1.0, 2.0],
...                                [2.0, 1.0]]))
>>> y = ivy.slogdet(x)
>>> print(y)
{
    a: [
        sign = ivy.array(-1.),
        logabsdet = ivy.array(0.6931472)
    ],
    b: [
        sign = ivy.array(-1.),
        logabsdet = ivy.array(1.0986123)
    ]
}
Array.slogdet(self)#

ivy.Array instance method variant of ivy.slogdet. This method simply wraps the function, and so the docstring for ivy.slogdet also applies to this method with minimal changes.

Parameters:

self (Array) – input array having shape (…, M, M) and whose innermost two dimensions form square matrices. Should have a floating-point data type.

Return type:

Tuple[Array, Array]

Returns:

ret

This function returns NamedTuple with two values -

sign: An array containing a number representing the sign of the determinant for each square matrix.

logabsdet: An array containing natural log of the absolute determinant of each square matrix.

Examples

>>> x = ivy.array([[1.0, 2.0],
...                [3.0, 4.0]])
>>> y = x.slogdet()
>>> print(y)
slogdet(sign=ivy.array(-1.), logabsdet=ivy.array(0.6931472))
>>> x = ivy.array([[1.2, 2.0, 3.1],
...                [6.0, 5.2, 4.0],
...                [9.0, 8.0, 7.0]])
>>> y = x.slogdet()
>>> print(y)
slogdet(sign=ivy.array(-1.), logabsdet=ivy.array(1.098611))
Container.slogdet(self, /, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)#

ivy.Container instance method variant of ivy.slogdet. This method simply wraps the function, and so the docstring for ivy.slogdet also applies to this method with minimal changes.

Parameters:
  • self (Container) – input container having shape (…, M, M) and whose innermost two dimensions form square matrices. Should have a floating-point data type.

  • key_chains (Optional[Union[List[str], Dict[str, str]]]) – The key-chains to apply or not apply the method to. Default is None. (default: None)

  • to_apply (bool) – If True, the method will be applied to key_chains, otherwise key_chains (default: True) will be skipped. Default is True.

  • prune_unapplied (bool) – Whether to prune key_chains for which the function was not applied. (default: False) Default is False.

  • map_sequences (bool) – Whether to also map method to sequences (lists, tuples). (default: False) Default is False.

Return type:

Container

Returns:

ret – This function returns container containing NamedTuples. Each NamedTuple of output will have -

sign: An array of a number representing the sign of the determinant of each square.

logabsdet: An array of the natural log of the absolute value of the determinant of each square.

Examples

>>> x = ivy.Container(a=ivy.array([[1.0, 2.0],
...                                [3.0, 4.0]]),
...                   b=ivy.array([[1.0, 2.0],
...                                [2.0, 1.0]]))
>>> y = x.slogdet()
>>> print(y)
{
    a: [
        sign = ivy.array(-1.),
        logabsdet = ivy.array(0.6931472)
    ],
    b: [
        sign = ivy.array(-1.),
        logabsdet = ivy.array(1.0986123)
    ]
}