warp.tile_lu#
- warp.tile_lu( ) tuple[Tile[Float, tuple[int, int]], Tile[int32, tuple[int]], Tile[int32, tuple[int]]]#
Compute an LU factorization with partial pivoting of a square tile
A.Ais not modified. The factorization completes even for singular inputs.Supports
float32andfloat64. On CUDA, uses cuSOLVERDx when available andwarp.config.enable_mathdx_solveris enabled (also configurable per module). Otherwise uses a cooperative native implementation, including on CPU. Pivot choices may differ between backends when magnitudes are tied.This is a cooperative operation, so every thread in the block must call it.
Gradients propagate through
lutoAwith the recorded pivot sequence held fixed.pivotsandinfoare nondifferentiable. Gradients are undefined for singular inputs and where the selected pivot sequence changes.- Parameters:
A – A square tile with
shape=(N, N).- Returns:
lu: The packed factors, withshape=(N, N). The upper triangle holdsU. The strict lower triangle holdsL, whose unit diagonal is implicit and not stored.pivots: Zero-based row-swap indices, as anint32tile withshape=(N,). Swapping rowskandpivots[k]ofAfork = 0, 1, ..., N-1in that order givesP @ A = L @ U. The indices are a sequence of swaps, not a permutation vector.info: Anint32tile withshape=(1,).info[0] == 0indicates success. A positive valueiindicates thatU[i-1, i-1]is exactly zero, so the factors cannot be used for a nonsingular solve.infodoes not estimate conditioning.
- Return type:
A tuple
(lu, pivots, info)of tiles in shared storage
Example
@wp.kernel def solve_linear_system(a: wp.array2d[float], b: wp.array[float], x: wp.array[float], status: wp.array[int]): lu, pivots, info = wp.tile_lu(wp.tile_load(a, shape=(3, 3))) status[0] = info[0] if info[0] == 0: # every thread solves the small system with the shared factors y = wp.vec3(b[0], b[1], b[2]) # apply the row swaps to the right-hand side in order for k in range(3): p = pivots[k] swapped = y[k] y[k] = y[p] y[p] = swapped # forward substitution with the implicit unit diagonal of L for i in range(3): for j in range(i): y[i] -= lu[i, j] * y[j] # back substitution with U for i in range(2, -1, -1): for j in range(i + 1, 3): y[i] -= lu[i, j] * y[j] y[i] /= lu[i, i] for i in range(3): x[i] = y[i] # the zero in the top-left corner requires a row swap a = wp.array(np.array([[0.0, 2.0, 1.0], [1.0, 1.0, 1.0], [2.0, 1.0, 0.0]], dtype=np.float32)) b = wp.array(np.array([7.0, 6.0, 4.0], dtype=np.float32)) x = wp.zeros(3, dtype=float) status = wp.zeros(1, dtype=int) wp.launch_tiled(solve_linear_system, dim=1, inputs=[a, b], outputs=[x, status], block_dim=32) print(status.numpy()[0]) print(np.round(x.numpy(), 3))
0 [1. 2. 3.]