Clustering
C++20 header-only: DBSCAN, HDBSCAN, k-means.
Loading...
Searching...
No Matches
gemm.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <type_traits>
5
10
11namespace clustering::math {
12
30template <class T, Layout LA, Layout LB, class Backend = defaults::Backend>
31void gemm(const NDArray<T, 2, LA> &A, const NDArray<T, 2, LB> &B, NDArray<T, 2> &C, Pool pool,
32 T alpha = T{1}, T beta = T{0}) {
33 // Integer NDArrays are permitted as label / index storage but must never reach numeric math:
34 // the microkernel pack layout keys on kKernelMr<T> / kKernelNr<T> which default to 0 for any
35 // unspecialized T, so without this gate integer T would divide by zero inside gemm_pack.h.
36 static_assert(std::is_same_v<T, float> || std::is_same_v<T, double>,
37 "gemm<T> requires T to be float or double");
38 // Mutability check precedes descriptor extraction: describeMatrixMut's debug-only assert would
39 // otherwise mask the violation in release builds.
41
42 CLUSTERING_ALWAYS_ASSERT(A.dim(1) == B.dim(0));
43 CLUSTERING_ALWAYS_ASSERT(A.dim(0) == C.dim(0));
44 CLUSTERING_ALWAYS_ASSERT(B.dim(1) == C.dim(1));
45
46 if (C.dim(0) == 0 || C.dim(1) == 0) {
47 return;
48 }
49
50 Backend::template run<T, LA, LB>(A, B, C, pool, alpha, beta);
51}
52
53} // namespace clustering::math
#define CLUSTERING_ALWAYS_ASSERT(cond)
Release-active assertion: evaluates cond in every build configuration.
Represents a multidimensional array (NDArray) of a fixed number of dimensions N and element type T.
Definition ndarray.h:136
size_t dim(std::size_t index) const noexcept
Returns the size of a specific dimension of the NDArray.
Definition ndarray.h:461
bool isMutable() const noexcept
Reports whether writes through operator(), Accessor, or flatIndex are allowed.
Definition ndarray.h:488
void gemm(const NDArray< T, 2, LA > &A, const NDArray< T, 2, LB > &B, NDArray< T, 2 > &C, Pool pool, T alpha=T{1}, T beta=T{0})
One-shot dense matrix-matrix multiply: C := alpha * A * B + beta * C.
Definition gemm.h:31
Thin injection wrapper around a BS::light_thread_pool.
Definition thread.h:63