lucid.linalg.det

lucid.linalg.det(a: Tensor, /) Tensor

The det function computes the determinant of a square matrix.

Function Signature

def det(a: Tensor) -> Tensor

Parameters

  • a (Tensor):

    The input tensor, which must be a square matrix (same number of rows and columns).

Returns

  • Tensor:

    A tensor containing the determinant of the input matrix.

Forward Calculation

The forward calculation for det is:

\[\text{det}(\mathbf{A})\]

where \(\mathbf{A}\) is the input square matrix.

Backward Gradient Calculation

For a tensor \(\mathbf{A}\), the gradient of the determinant with respect to the input is given by:

\[\frac{\partial \text{det}(\mathbf{A})}{\partial \mathbf{A}} = \text{det}(\mathbf{A}) \cdot (\mathbf{A}^{-1})^\top\]

This involves the determinant and inverse of the matrix \(\mathbf{A}\), and the gradients are propagated accordingly during backpropagation.

Raises

Attention

  • ValueError: If the input tensor is not a square matrix.

  • LinAlgError: If the determinant cannot be computed (e.g., for singular or ill-conditioned matrices).

Example

>>> import lucid
>>> a = lucid.Tensor([[1.0, 2.0], [3.0, 4.0]])
>>> det_a = lucid.linalg.det(a)
>>> print(det_a)
Tensor(-2.0)

Note

  • The determinant is a scalar value that describes certain properties of a matrix, such as whether it is invertible.

  • The input tensor must have two dimensions and be square, i.e., \(a.shape[0] == a.shape[1]\).