mlx_rs::linalg

Function norm_device

Source
pub fn norm_device<'a>(
    array: impl AsRef<Array>,
    ord: impl IntoOption<Ord<'a>>,
    axes: impl IntoOption<&'a [i32]>,
    keep_dims: impl Into<Option<bool>>,
    stream: impl AsRef<Stream>,
) -> Result<Array>
Expand description

Matrix or vector norm.

For values of ord < 1, the result is, strictly speaking, not a mathematical norm, but it may still be useful for various numerical purposes.

The following norms can be calculated:

ordnorm for matricesnorm for vectors
NoneFrobenius norm2-norm
‘fro’Frobenius norm
infmax(sum(abs(x), axis-1))max(abs(x))
-infmin(sum(abs(x), axis-1))min(abs(x))
0sum(x !- 0)
1max(sum(abs(x), axis-0))as below
-1min(sum(abs(x), axis-0))as below
22-norm (largest sing. value)as below
-2smallest singular valueas below
othersum(abs(x)ord)(1./ord)

Nuclear norm and norms based on singular values are not yet implemented.

The Frobenius norm is given by G. H. Golub and C. F. Van Loan, Matrix Computations, Baltimore, MD, Johns Hopkins University Press, 1985, pg. 15

The nuclear norm is the sum of the singular values.

Both the Frobenius and nuclear norm orders are only defined for matrices and produce a fatal error when array.ndim != 2

§Params

  • array: input array
  • ord: order of the norm, see table
  • axes: axes that hold 2d matrices
  • keep_dims: if true the axes which are normed over are left in the result as dimensions with size one