aboutsummaryrefslogtreecommitdiff
path: root/cbits/arith.c
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-06-10 10:02:59 +0200
committerTom Smeding <t.j.smeding@uu.nl>2024-06-10 16:17:09 +0200
commit205a20fd581bb7c5728fd457a15e4f78fbee9e75 (patch)
treef6669ea87b56dde0f6168c109b3d7d7fcbf06136 /cbits/arith.c
parentc211316a4ab43cf34d6567c6919a3922d5840ae0 (diff)
Dot product
Diffstat (limited to 'cbits/arith.c')
-rw-r--r--cbits/arith.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/cbits/arith.c b/cbits/arith.c
index 5594c80..751fe33 100644
--- a/cbits/arith.c
+++ b/cbits/arith.c
@@ -200,6 +200,20 @@ static double log1pexp_double(double x) { LOG1PEXP_IMPL(x); }
} \
}
+#define DOTPROD_OP(typ) \
+ typ oxarop_dotprod_ ## typ(i64 length, const typ *arr1, const typ *arr2) { \
+ typ res = 0; \
+ for (i64 i = 0; i < length; i++) res += arr1[i] * arr2[i]; \
+ return res; \
+ }
+
+#define DOTPROD_STRIDED_OP(typ) \
+ typ oxarop_dotprod_ ## typ ## _strided(i64 length, i64 offset1, i64 stride1, const typ *arr1, i64 offset2, i64 stride2, const typ *arr2) { \
+ typ res = 0; \
+ for (i64 i = 0; i < length; i++) res += arr1[offset1 + stride1 * i] * arr2[offset2 + stride2 * i]; \
+ return res; \
+ }
+
/*****************************************************************************
* Entry point functions *
@@ -370,7 +384,9 @@ enum redop_tag_t {
ENTRY_UNARY_OPS(typ) \
ENTRY_REDUCE_OPS(typ) \
EXTREMUM_OP(min, <, typ) \
- EXTREMUM_OP(max, >, typ)
+ EXTREMUM_OP(max, >, typ) \
+ DOTPROD_OP(typ) \
+ DOTPROD_STRIDED_OP(typ)
NUM_TYPES_XLIST
#undef X