Computes the Cholesky decomposition of a symmetric positive-definite matrix. Supports batched inputs: axes before the last two are batch axes.
Usage
nv_chol(x, lower = FALSE)
# S3 method for class 'AnvlArray'
chol(x, ..., lower = FALSE)Arguments
- x
(
arrayish)
One input, a symmetric positive-definite matrix with at least 2 axes, the last two forming the square matrix and any leading ones batch axes. Can be any numeric data type: a float keeps its own, and an integer one is converted to the default float data type (seedefault_dtypes()). An R value materializes at its default data type and is converted in the same way.- lower
(
logical(1))
IfTRUE, return the lower-triangular factor.- ...
No additional arguments.
Value
(arrayish)
Triangular matrix with the input's shape, and its data type – or the
default float data type (see default_dtypes()) where the input was an
integer one. The values in the triangle not selected by lower are
implementation-defined.
Details
Differentiation is only implemented for a single matrix: a gradient() of a
batched decomposition errors.
Examples
# the factor has the matrix's shape and data type
a <- nv_matrix(c(4, 2, 2, 3), nrow = 2, dtype = "f32")
nv_chol(a)
#> AnvlArray
#> 2.0000 1.0000
#> 0.0000 1.4142
#> [ CPUf32{2,2} ]
# an integer matrix is factored at the default float data type
nv_chol(nv_matrix(c(4L, 2L, 2L, 3L), nrow = 2))
#> AnvlArray
#> 2.0000 1.0000
#> 0.0000 1.4142
#> [ CPUf32{2,2} ]