numerics 0.1.0
Loading...
Searching...
No Matches
reduce.hpp
Go to the documentation of this file.
1/// @file kernel/reduce.hpp
2/// @brief Scalar reduction kernels (namespace num::kernel::reduce)
3///
4/// These operations collapse a Vector to a single scalar via a single memory
5/// pass. Unlike dot/norm (which live in num:: with full Backend dispatch),
6/// these are new reductions that have no existing parallel paths:
7///
8/// l1_norm(x) -- sum |x[i]| (BLAS cblas_dasum via raw:: on seq_t path)
9/// linf_norm(x) -- max |x[i]| (BLAS cblas_idamax via raw:: on seq_t path)
10/// sum(x) -- sum x[i] (no BLAS equivalent; seq loop or OMP)
11///
12/// Each has seq_t / par_t overloads and a default that selects par_t when
13/// NUMERICS_HAS_OMP is defined at configure time.
14///
15/// Include kernel/kernel.hpp to get all kernel sub-modules together.
16#pragma once
17
18#include "core/types.hpp"
19#include "core/vector.hpp"
20#include "kernel/policy.hpp"
21
23
24// ---------------------------------------------------------------------------
25// l1_norm: sum |x[i]|
26// ---------------------------------------------------------------------------
27
28/// @brief Sequential: calls raw::l1_norm (routes to cblas_dasum when BLAS
29/// available; otherwise auto-vectorizable seq loop).
30[[nodiscard]] real l1_norm(const Vector& x, seq_t) noexcept;
31
32/// @brief Parallel: OMP reduction(+) over abs values; falls back to seq_t
33/// when NUMERICS_HAS_OMP is not defined.
34[[nodiscard]] real l1_norm(const Vector& x, par_t);
35
36/// @brief Default policy
37[[nodiscard]] inline real l1_norm(const Vector& x) {
38 return l1_norm(x, default_policy{});
39}
40
41// ---------------------------------------------------------------------------
42// linf_norm: max |x[i]|
43// ---------------------------------------------------------------------------
44
45/// @brief Sequential: calls raw::linf_norm (routes to cblas_idamax when BLAS
46/// available; otherwise plain max loop).
47[[nodiscard]] real linf_norm(const Vector& x, seq_t) noexcept;
48
49/// @brief Parallel: OMP reduction(max) over abs values; falls back to seq_t
50/// when NUMERICS_HAS_OMP is not defined.
51[[nodiscard]] real linf_norm(const Vector& x, par_t);
52
53/// @brief Default policy
54[[nodiscard]] inline real linf_norm(const Vector& x) {
55 return linf_norm(x, default_policy{});
56}
57
58// ---------------------------------------------------------------------------
59// sum: sum x[i]
60// ---------------------------------------------------------------------------
61
62/// @brief Sequential: auto-vectorizable summation loop (no BLAS equivalent).
63[[nodiscard]] real sum(const Vector& x, seq_t) noexcept;
64
65/// @brief Parallel: OMP reduction(+) over x[i]; falls back to seq_t
66/// when NUMERICS_HAS_OMP is not defined.
67[[nodiscard]] real sum(const Vector& x, par_t);
68
69/// @brief Default policy
70[[nodiscard]] inline real sum(const Vector& x) {
71 return sum(x, default_policy{});
72}
73
74} // namespace num::kernel::reduce
Core type definitions.
Compile-time dispatch policy tags for the kernel module.
real l1_norm(const Vector &x, seq_t) noexcept
Sequential: calls raw::l1_norm (routes to cblas_dasum when BLAS available; otherwise auto-vectorizabl...
Definition reduce.cpp:20
real sum(const Vector &x, seq_t) noexcept
Sequential: auto-vectorizable summation loop (no BLAS equivalent).
Definition reduce.cpp:69
real linf_norm(const Vector &x, seq_t) noexcept
Sequential: calls raw::linf_norm (routes to cblas_idamax when BLAS available; otherwise plain max loo...
Definition reduce.cpp:43
double real
Definition types.hpp:10
Parallel execution policy tag. Activates OMP parallel-for / reduction constructs when NUMERICS_HAS_OM...
Definition policy.hpp:43
Sequential execution policy tag. Guarantees no OMP parallel regions; safe to call inside an existing ...
Definition policy.hpp:38
Vector operations.