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
6
#include "
clustering/always_assert.h
"
7
#include "
clustering/math/defaults.h
"
8
#include "
clustering/math/thread.h
"
9
#include "
clustering/ndarray.h
"
10
11
namespace
clustering::math
{
12
30
template
<
class
T, Layout LA, Layout LB,
class
Backend = defaults::Backend>
31
void
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.
40
CLUSTERING_ALWAYS_ASSERT
(C.
isMutable
());
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
always_assert.h
CLUSTERING_ALWAYS_ASSERT
#define CLUSTERING_ALWAYS_ASSERT(cond)
Release-active assertion: evaluates cond in every build configuration.
Definition
always_assert.h:30
clustering::NDArray
Represents a multidimensional array (NDArray) of a fixed number of dimensions N and element type T.
Definition
ndarray.h:136
clustering::NDArray::dim
size_t dim(std::size_t index) const noexcept
Returns the size of a specific dimension of the NDArray.
Definition
ndarray.h:461
clustering::NDArray::isMutable
bool isMutable() const noexcept
Reports whether writes through operator(), Accessor, or flatIndex are allowed.
Definition
ndarray.h:488
defaults.h
clustering::math
Definition
aabb.h:12
clustering::math::gemm
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
ndarray.h
clustering::math::Pool
Thin injection wrapper around a BS::light_thread_pool.
Definition
thread.h:63
thread.h
include
clustering
math
gemm.h
Generated by
1.16.1