cholesky#

ivy.cholesky(x, /, *, upper=False, out=None)[source]#

Compute the cholesky decomposition of the x matrix.

Parameters:
  • x (Union[Array, NativeArray]) – input array having shape (…, M, M) and whose innermost two dimensions form square symmetric positive-definite matrices. Should have a floating-point data type.

  • upper (bool, default: False) – If True, the result must be the upper-triangular Cholesky factor U. If False, the result must be the lower-triangular Cholesky factor L. Default: False.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – an array containing the Cholesky factors for each square matrix. If upper is False, the returned array must contain lower-triangular matrices; otherwise, the returned array must contain upper-triangular matrices. The returned array must have a floating-point data type determined by Type Promotion Rules and must have the same shape as x.

This function conforms to the Array API Standard. This docstring is an extension of the docstring 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([[4.0, 1.0, 2.0, 0.5, 2.0],
...                [1.0, 0.5, 0.0, 0.0, 0.0],
...                [2.0, 0.0, 3.0, 0.0, 0.0],
...                [0.5, 0.0, 0.0, 0.625, 0.0],
...                [2.0, 0.0, 0.0, 0.0, 16.0]])
>>> l = ivy.cholesky(x, upper='false')
>>> print(l)
ivy.array([[ 2.  ,  0.5 ,  1.  ,  0.25,  1.  ],
           [ 0.  ,  0.5 , -1.  , -0.25, -1.  ],
           [ 0.  ,  0.  ,  1.  , -0.5 , -2.  ],
           [ 0.  ,  0.  ,  0.  ,  0.5 , -3.  ],
           [ 0.  ,  0.  ,  0.  ,  0.  ,  1.  ]])
>>> x = ivy.array([[4.0, 1.0, 2.0, 0.5, 2.0],
...                [1.0, 0.5, 0.0, 0.0, 0.0],
...                [2.0, 0.0, 3.0, 0.0, 0.0],
...                [0.5, 0.0, 0.0, 0.625, 0.0],
...                [2.0, 0.0, 0.0, 0.0, 16.0]])
>>> y = ivy.zeros([5,5])
>>> ivy.cholesky(x, upper='false', out=y)
>>> print(y)
ivy.array([[ 2.  ,  0.5 ,  1.  ,  0.25,  1.  ],
           [ 0.  ,  0.5 , -1.  , -0.25, -1.  ],
           [ 0.  ,  0.  ,  1.  , -0.5 , -2.  ],
           [ 0.  ,  0.  ,  0.  ,  0.5 , -3.  ],
           [ 0.  ,  0.  ,  0.  ,  0.  ,  1.  ]])
>>> x = ivy.array([[4.0, 1.0, 2.0, 0.5, 2.0],
...                [1.0, 0.5, 0.0, 0.0, 0.0],
...                [2.0, 0.0, 3.0, 0.0, 0.0],
...                [0.5, 0.0, 0.0, 0.625, 0.0],
...                [2.0, 0.0, 0.0, 0.0, 16.0]])
>>> ivy.cholesky(x, upper='false', out=x)
>>> print(x)
ivy.array([[ 2.  ,  0.5 ,  1.  ,  0.25,  1.  ],
           [ 0.  ,  0.5 , -1.  , -0.25, -1.  ],
           [ 0.  ,  0.  ,  1.  , -0.5 , -2.  ],
           [ 0.  ,  0.  ,  0.  ,  0.5 , -3.  ],
           [ 0.  ,  0.  ,  0.  ,  0.  ,  1.  ]])
>>> x = ivy.array([[1., -2.], [2., 5.]])
>>> u = ivy.cholesky(x, upper='false')
>>> print(u)
ivy.array([[ 1., -2.],
           [ 0.,  1.]])

With ivy.Container input:

>>> x = ivy.Container(a=ivy.array([[3., -1],[-1., 3.]]),
...                   b=ivy.array([[2., 1.],[1., 1.]]))
>>> y = ivy.cholesky(x, upper='false')
>>> print(y)
{
    a: ivy.array([[1.73, -0.577],
                  [0., 1.63]]),
    b: ivy.array([[1.41, 0.707],
                  [0., 0.707]])
}

With multiple ivy.Container inputs:

>>> x = ivy.Container(a=ivy.array([[3., -1],[-1., 3.]]),
...                   b=ivy.array([[2., 1.],[1., 1.]]))
>>> upper = ivy.Container(a=1, b=-1)
>>> y = ivy.cholesky(x, upper='false')
>>> print(y)
{
    a: ivy.array([[1.73, -0.577],
                  [0., 1.63]]),
    b: ivy.array([[1.41, 0.707],
                  [0., 0.707]])
}

With a mix of ivy.Array and ivy.Container inputs:

>>> x = ivy.array([[1., -2.], [2., 5.]])
>>> upper = ivy.Container(a=1, b=-1)
>>> y = ivy.cholesky(x, upper='false')
>>> print(y)
ivy.array([[ 1., -2.],
           [ 0.,  1.]])
Array.cholesky(self, /, *, upper=False, out=None)[source]#

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

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

  • upper (bool, default: False) – If True, the result must be the upper-triangular Cholesky factor U. If False, the result must be the lower-triangular Cholesky factor L. Default: False.

  • out (Optional[Array], default: None) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – an array containing the Cholesky factors for each square matrix. If upper is False, the returned array must contain lower-triangular matrices; otherwise, the returned array must contain upper-triangular matrices. The returned array must have a floating-point data type determined by Type Promotion Rules and must have the same shape as self.

Examples

>>> x = ivy.array([[4.0, 1.0, 2.0, 0.5, 2.0],
...               [1.0, 0.5, 0.0, 0.0, 0.0],
...               [2.0, 0.0, 3.0, 0.0, 0.0],
...               [0.5, 0.0, 0.0, 0.625, 0.0],
...               [2.0, 0.0, 0.0, 0.0, 16.0]])
>>> y = x.cholesky(upper='false')
>>> print(y)
ivy.array([[ 2.  ,  0.5 ,  1.  ,  0.25,  1.  ],
...        [ 0.  ,  0.5 , -1.  , -0.25, -1.  ],
...        [ 0.  ,  0.  ,  1.  , -0.5 , -2.  ],
...        [ 0.  ,  0.  ,  0.  ,  0.5 , -3.  ],
...        [ 0.  ,  0.  ,  0.  ,  0.  ,  1.  ]])
Container.cholesky(self, /, *, upper=False, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

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

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

  • upper (Union[bool, Container], default: False) – If True, the result must be the upper-triangular Cholesky factor U. If False, the result must be the lower-triangular Cholesky factor L. Default: False.

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

  • out (Optional[Container], default: None) – optional output container, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Container

Returns:

ret – a container containing the Cholesky factors for each square matrix. If upper is False, the returned container must contain lower-triangular matrices; otherwise, the returned container must contain upper-triangular matrices. The returned container must have a floating-point data type determined by Type Promotion Rules and must have the same shape as self.

Examples

>>> x = ivy.Container(a=ivy.array([[3., -1],[-1., 3.]]),
...                      b=ivy.array([[2., 1.],[1., 1.]]))
>>> y = x.cholesky(upper='false')
>>> print(y)
{
    a: ivy.array([[1.73, -0.577],
                    [0., 1.63]]),
    b: ivy.array([[1.41, 0.707],
                    [0., 0.707]])
}