nrm2

Returns the euclidean norm of a vector. Uses unrolled loops for stride equal to one.

  1. F nrm2(Slice!(Iterator, N, kind) x)
    @fastmath
    F
    nrm2
    (
    F
    SliceKind kind
    size_t N
    Iterator
    )
    (
    Slice!(Iterator, N, kind) x
    )
  2. auto nrm2(Slice!(Iterator, N, kind) x)

Parameters

F

type for summation (optional template parameter)

x Slice!(Iterator, N, kind)

n-dimensional tensor BLAS: SNRM2, DNRM2, SCNRM2, DZNRM2

Return Value

Type: F

euclidean norm sqrt(conj(xᐪ) × x)

Examples

SNRM2, DNRM2

import mir.ndslice.allocation: slice;
import std.math: sqrt, approxEqual;
auto x = slice!double(4);
x[] = [0, 1, 2, 3];
assert(nrm2(x).approxEqual(sqrt(1.0 + 4 + 9)));

SCNRM2, DZNRM2

import mir.ndslice.allocation: slice;
import std.math: sqrt, approxEqual;

auto x = slice!cdouble(2);
x[] = [0 + 1i, 2 + 3i];

assert(nrm2(x).approxEqual(sqrt(1.0 + 4 + 9)));

Meta