numerics 0.1.0
Loading...
Searching...
No Matches
num::kernel::array Namespace Reference

Functions

void axpby (real a, const Vector &x, real b, Vector &y, seq_t) noexcept
 Sequential: y[i] = a*x[i] + b*y[i] (single-pass; calls raw::axpby)
 
void axpby (real a, const Vector &x, real b, Vector &y, par_t)
 Parallel: y[i] = a*x[i] + b*y[i] (OMP parallel-for; falls back to seq_t when NUMERICS_HAS_OMP is not defined)
 
void axpby (real a, const Vector &x, real b, Vector &y)
 Default policy (par_t if OMP available, seq_t otherwise)
 
void axpbyz (real a, const Vector &x, real b, const Vector &y, Vector &z, seq_t) noexcept
 Sequential: z[i] = a*x[i] + b*y[i] (single-pass; calls raw::axpbyz)
 
void axpbyz (real a, const Vector &x, real b, const Vector &y, Vector &z, par_t)
 Parallel: z[i] = a*x[i] + b*y[i] (OMP parallel-for)
 
void axpbyz (real a, const Vector &x, real b, const Vector &y, Vector &z)
 Default policy.
 
template<typename F >
void map (Vector &x, F &&f)
 In-place elementwise map: x[i] = f(x[i])
 
template<typename F >
void map (CVector &x, F &&f)
 In-place elementwise map on CVector.
 
template<typename T , typename F >
void zip_map (const BasicVector< T > &x, const BasicVector< T > &y, BasicVector< T > &z, F &&f)
 Fused binary map: z[i] = f(x[i], y[i])
 
template<typename F >
real reduce (const Vector &x, real init, F &&f)
 Single-pass left fold: f(f(f(init, x[0]), x[1]), ..., x[n-1])
 

Function Documentation

◆ axpby() [1/3]

void num::kernel::array::axpby ( real  a,
const Vector x,
real  b,
Vector y 
)
inline

Default policy (par_t if OMP available, seq_t otherwise)

Definition at line 39 of file array.hpp.

References axpby().

◆ axpby() [2/3]

void num::kernel::array::axpby ( real  a,
const Vector x,
real  b,
Vector y,
par_t   
)

Parallel: y[i] = a*x[i] + b*y[i] (OMP parallel-for; falls back to seq_t when NUMERICS_HAS_OMP is not defined)

Definition at line 24 of file array.cpp.

References axpby(), num::BasicVector< T >::data(), and num::BasicVector< T >::size().

◆ axpby() [3/3]

void num::kernel::array::axpby ( real  a,
const Vector x,
real  b,
Vector y,
seq_t   
)
noexcept

Sequential: y[i] = a*x[i] + b*y[i] (single-pass; calls raw::axpby)

Definition at line 20 of file array.cpp.

References num::kernel::raw::axpby().

Referenced by axpby(), and axpby().

◆ axpbyz() [1/3]

void num::kernel::array::axpbyz ( real  a,
const Vector x,
real  b,
const Vector y,
Vector z 
)
inline

Default policy.

Definition at line 56 of file array.hpp.

References axpbyz().

◆ axpbyz() [2/3]

void num::kernel::array::axpbyz ( real  a,
const Vector x,
real  b,
const Vector y,
Vector z,
par_t   
)

Parallel: z[i] = a*x[i] + b*y[i] (OMP parallel-for)

Definition at line 47 of file array.cpp.

References axpbyz(), num::BasicVector< T >::data(), and num::BasicVector< T >::size().

◆ axpbyz() [3/3]

void num::kernel::array::axpbyz ( real  a,
const Vector x,
real  b,
const Vector y,
Vector z,
seq_t   
)
noexcept

Sequential: z[i] = a*x[i] + b*y[i] (single-pass; calls raw::axpbyz)

Definition at line 42 of file array.cpp.

References num::kernel::raw::axpbyz().

Referenced by axpbyz(), and axpbyz().

◆ map() [1/2]

template<typename F >
void num::kernel::array::map ( CVector x,
F &&  f 
)

In-place elementwise map on CVector.

Definition at line 84 of file array.hpp.

References num::BasicVector< T >::data(), and num::BasicVector< T >::size().

◆ map() [2/2]

template<typename F >
void num::kernel::array::map ( Vector x,
F &&  f 
)

In-place elementwise map: x[i] = f(x[i])

The compiler inlines f into the loop and can vectorize if f is a simple arithmetic expression. No policy needed.

num::kernel::array::map(v, [](real x) { return x * x; });
void map(Vector &x, F &&f)
In-place elementwise map: x[i] = f(x[i])
Definition array.hpp:74
double real
Definition types.hpp:10

Definition at line 74 of file array.hpp.

References num::BasicVector< T >::data(), and num::BasicVector< T >::size().

◆ reduce()

template<typename F >
real num::kernel::array::reduce ( const Vector x,
real  init,
F &&  f 
)

Single-pass left fold: f(f(f(init, x[0]), x[1]), ..., x[n-1])

real max_val = num::kernel::array::reduce(v, -1e300,
[](real acc, real xi) { return acc > xi ? acc : xi; });
real reduce(const Vector &x, real init, F &&f)
Single-pass left fold: f(f(f(init, x[0]), x[1]), ..., x[n-1])
Definition array.hpp:117

Definition at line 117 of file array.hpp.

References num::BasicVector< T >::data(), reduce(), and num::BasicVector< T >::size().

Referenced by reduce().

◆ zip_map()

template<typename T , typename F >
void num::kernel::array::zip_map ( const BasicVector< T > &  x,
const BasicVector< T > &  y,
BasicVector< T > &  z,
F &&  f 
)

Fused binary map: z[i] = f(x[i], y[i])

Single pass over memory; no temporary allocation. x, y, z must have the same size.

[](real a, real b) { return a * b; });
void zip_map(const BasicVector< T > &x, const BasicVector< T > &y, BasicVector< T > &z, F &&f)
Fused binary map: z[i] = f(x[i], y[i])
Definition array.hpp:102

Definition at line 102 of file array.hpp.

References num::BasicVector< T >::size().