MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / vectorNorm

Function vectorNorm

src/api/c/norm.cpp:62–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60
61template<typename T>
62double vectorNorm(const Array<T> &A, double p) {
63 using RT = normReductionResult<T>;
64 if (p == 1) { return getScalar<RT>(reduce_all<af_add_t, T, RT>(A)); }
65 if (p == af::Inf) {
66 return getScalar<RT>(reduce_all<af_max_t, RT, RT>(cast<RT>(A)));
67 } else if (p == 2) {
68 Array<T> A_sq = arithOp<T, af_mul_t>(A, A, A.dims());
69 return std::sqrt(getScalar<RT>(reduce_all<af_add_t, T, RT>(A_sq)));
70 }
71
72 Array<T> P = createValueArray<T>(A.dims(), scalar<T>(p));
73 Array<T> A_p = arithOp<T, af_pow_t>(A, P, A.dims());
74 return std::pow(getScalar<RT>(reduce_all<af_add_t, T, RT>(A_p)), (1.0 / p));
75}
76
77template<typename T>
78double LPQNorm(const Array<T> &A, double p, double q) {

Callers 1

normFunction · 0.85

Calls 3

sqrtFunction · 0.85
powFunction · 0.85
dimsMethod · 0.45

Tested by

no test coverage detected