Skip to content
fn

norm_op

→TensorImplPtr
int norm_op(const int & a, double ord, int axis, bool keepdims)

Python wrappers

Public Python APIs implemented by this engine symbol.

Compute the p-norm of a float tensor over the specified axes.

Math

∥A∥p=(∑i∣ai∣p)1/p. \|A\|_p = \Bigl(\sum_i |a_i|^p\Bigr)^{1/p}.

For p=2p = 2 on a matrix this is the Frobenius norm; for p=1p = 1 on a matrix this is the entrywise L1 norm (not the operator 1-norm).

Shape

  • a: arbitrary float shape.
  • Output:
    • axis empty, keepdims=false →\to scalar (rank 0).
    • axis empty, keepdims=true →\to all-ones shape of the same rank as a.
    • Otherwise: rank of a minus the number of reduced axes (keepdims=false) or rank preserved with those axes set to 1 (keepdims=true).

See Also

SVD.h : Underpins operator norms (spectral, nuclear) once exposed.

Parameters

aTensorImplPtr
Input tensor (any float dtype, any shape).
orddouble
Norm order. 2.0 selects the Frobenius / Euclidean norm ∥A∥F=∑aij2\|A\|_F = \sqrt{\sum a_{ij}^2}; 1.0 selects the entrywise L1 norm ∥A∥1=∑∣aij∣\|A\|_1 = \sum |a_{ij}|. Other values may be forwarded to the backend in the forward pass but have no registered backward.
axisstd::vector<int>
Axes to reduce. Empty means a global reduction over every element; negative indices are accepted and normalised.
keepdimsbool
If true the reduced axes are retained as size-1 stubs in the output; otherwise they are removed.

Returns

TensorImplPtr

Reduced norm tensor.

Raises

ValueError
If a is non-float.
NotImplementedError
(At backward time.) If ord is not 1.0 or 2.0 and a gradient is requested.

Notes

Operator norms (spectral, nuclear, induced 1-/inf-norm) are not yet dispatched here — they would require SVD and a separate backward. This op currently covers only the entrywise reductions.