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.

Special cases

For real-valued floating-point operands,

  • If the determinant is zero, the sign should be 0``and ``logabsdet

should be infinity.

For complex floating-point operands,

  • If the detereminant is 0 + 0j, the sign should be 0 + 0j

and logabsdet should be infinity + 0j.

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. If x is complex, the returned array must have a real-valued floating-point data type having the same precision as x (1.g., if x is complex64, logabsdet must have a float32 data type) .. 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/array_api.linalg.slogdet.html>`_

  • 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.

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.60943794))
>>> ivy.set_backend('numpy') # As the precision of results depends on backend.
>>> 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:

>>> ivy.unset_backend() # unset backend again.
>>> 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: ivy.array(-1.),
    b: ivy.array(-1.)
}, {
    a: ivy.array(0.69314718),
    b: ivy.array(1.09861231)
}]
Array.slogdet(self)[source]#

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.69314718))
>>> 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)[source]#

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], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

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

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

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). 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: ivy.array(-1.),
    b: ivy.array(-1.)
}, {
    a: ivy.array(0.69314718),
    b: ivy.array(1.09861231)
}]