warp.tile_cholesky#
- warp.tile_cholesky( ) Tile[Float, tuple[int, int]]#
Compute the Cholesky factor of a symmetric positive-definite matrix
Aand return it in a new tile.With
fill_mode="lower", returns the lower-triangularLsuch thatL @ L^T = A; withfill_mode="upper", returns the upper-triangularUsuch thatU^T @ U = A.fill_modemust be a compile-time constant.Only the triangle of
Aselected byfill_modeis read, so the opposite triangle may hold anything.Aitself is not modified; usetile_cholesky_inplace()to factorAin place instead.Amust be symmetric positive definite.This is a cooperative operation, so every thread in the block must call it.
Supported dtypes are
float32andfloat64.On CUDA devices, Warp uses cuSolverDx when it is built with libmathdx and
warp.config.enable_mathdx_solver(or theenable_mathdx_solvermodule option) isTrue. Otherwise, and on the CPU, it uses a cooperative fallback implementation, which is slower than cuSolverDx on CUDA devices.Backward propagation computes gradients with respect to the corresponding triangular parameterization of
A(lower triangle whenfill_mode="lower", upper triangle whenfill_mode="upper").- Parameters:
A – A square, symmetric positive-definite tile with
shape=(N, N).fill_mode –
"lower"or"upper". Must be a compile-time constant.
- Returns:
A new tile in shared memory with the same shape and dtype as
A, holding the factorLorU. The opposite triangle is zero, so the tile can be used directly in a matrix product.
Example
@wp.kernel def solve_spd(a: wp.array2d[float], b: wp.array[float], ell: wp.array2d[float], x: wp.array[float]): a_tile = wp.tile_load(a, shape=(3, 3)) b_tile = wp.tile_load(b, shape=3) l_tile = wp.tile_cholesky(a_tile) x_tile = wp.tile_cholesky_solve(l_tile, b_tile) wp.tile_store(ell, l_tile) wp.tile_store(x, x_tile) a = wp.array(np.array([[4.0, 2.0, 0.0], [2.0, 5.0, 1.0], [0.0, 1.0, 3.0]], dtype=np.float32)) b = wp.array(np.array([8.0, 15.0, 11.0], dtype=np.float32)) ell = wp.zeros((3, 3), dtype=float) x = wp.zeros(3, dtype=float) # one full warp cooperates on the factorization and solve wp.launch_tiled(solve_spd, dim=1, inputs=[a, b], outputs=[ell, x], block_dim=32) print(np.round(ell.numpy(), 3)) print(np.round(x.numpy(), 3))
[[2. 0. 0. ] [1. 2. 0. ] [0. 0.5 1.658]] [1. 2. 3.]