usearch 2.21.3 → 2.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (602) hide show
  1. package/README.md +24 -24
  2. package/binding.gyp +15 -37
  3. package/c/CMakeLists.txt +4 -5
  4. package/c/README.md +7 -7
  5. package/c/lib.cpp +32 -14
  6. package/c/test.c +83 -1
  7. package/c/usearch.h +24 -3
  8. package/cpp/CMakeLists.txt +4 -0
  9. package/cpp/README.md +5 -5
  10. package/cpp/bench.cpp +97 -116
  11. package/cpp/test.cpp +117 -20
  12. package/include/usearch/index.hpp +235 -52
  13. package/include/usearch/index_dense.hpp +105 -40
  14. package/include/usearch/index_plugins.hpp +1387 -204
  15. package/javascript/dist/cjs/usearch.d.ts +8 -3
  16. package/javascript/dist/cjs/usearch.js +12 -4
  17. package/javascript/dist/esm/usearch.d.ts +8 -3
  18. package/javascript/dist/esm/usearch.js +12 -4
  19. package/javascript/lib.cpp +17 -0
  20. package/javascript/usearch.ts +14 -6
  21. package/numkong/.clang-tidy +30 -0
  22. package/{simsimd → numkong}/.cmake-format.py +18 -0
  23. package/numkong/.editorconfig +12 -0
  24. package/numkong/.git-blame-ignore-revs +123 -0
  25. package/numkong/.mailmap +15 -0
  26. package/numkong/.spi.yml +11 -0
  27. package/numkong/.swift-format +14 -0
  28. package/numkong/CITATION.cff +81 -0
  29. package/numkong/CONTRIBUTING.md +500 -0
  30. package/numkong/Cargo.toml +54 -0
  31. package/numkong/MANIFEST.in +8 -0
  32. package/numkong/Package.swift +84 -0
  33. package/numkong/README.md +569 -0
  34. package/numkong/bench/README.md +217 -0
  35. package/numkong/bench/bench-browser.html +323 -0
  36. package/numkong/bench/bench.cpp +344 -0
  37. package/numkong/bench/bench.hpp +816 -0
  38. package/numkong/bench/bench.js +148 -0
  39. package/numkong/bench/bench.mjs +616 -0
  40. package/numkong/bench/bench_attention.cpp +113 -0
  41. package/numkong/bench/bench_cast.cpp +264 -0
  42. package/numkong/bench/bench_cross_amx.cpp +62 -0
  43. package/numkong/bench/bench_cross_arm.cpp +245 -0
  44. package/numkong/bench/bench_cross_blas.cpp +309 -0
  45. package/numkong/bench/bench_cross_loongarch.cpp +106 -0
  46. package/numkong/bench/bench_cross_power.cpp +84 -0
  47. package/numkong/bench/bench_cross_rvv.cpp +121 -0
  48. package/numkong/bench/bench_cross_serial.cpp +151 -0
  49. package/numkong/bench/bench_cross_sme.cpp +163 -0
  50. package/numkong/bench/bench_cross_wasm.cpp +142 -0
  51. package/numkong/bench/bench_cross_x86.cpp +455 -0
  52. package/numkong/bench/bench_curved.cpp +210 -0
  53. package/numkong/bench/bench_dot.cpp +315 -0
  54. package/numkong/bench/bench_each.cpp +503 -0
  55. package/numkong/bench/bench_geospatial.cpp +112 -0
  56. package/numkong/bench/bench_maxsim.cpp +154 -0
  57. package/numkong/bench/bench_mesh.cpp +148 -0
  58. package/numkong/bench/bench_probability.cpp +60 -0
  59. package/numkong/bench/bench_reduce.cpp +371 -0
  60. package/numkong/bench/bench_set.cpp +73 -0
  61. package/numkong/bench/bench_sparse.cpp +198 -0
  62. package/numkong/bench/bench_spatial.cpp +347 -0
  63. package/numkong/bench/bench_trigonometry.cpp +137 -0
  64. package/numkong/bench/swift/Bench.swift +506 -0
  65. package/numkong/binding.gyp +169 -0
  66. package/numkong/build.rs +484 -0
  67. package/numkong/c/dispatch.h +512 -0
  68. package/numkong/c/dispatch_bf16.c +447 -0
  69. package/numkong/c/dispatch_bf16c.c +52 -0
  70. package/numkong/c/dispatch_e2m3.c +296 -0
  71. package/numkong/c/dispatch_e3m2.c +284 -0
  72. package/numkong/c/dispatch_e4m3.c +318 -0
  73. package/numkong/c/dispatch_e5m2.c +316 -0
  74. package/numkong/c/dispatch_f16.c +452 -0
  75. package/numkong/c/dispatch_f16c.c +58 -0
  76. package/numkong/c/dispatch_f32.c +434 -0
  77. package/numkong/c/dispatch_f32c.c +99 -0
  78. package/numkong/c/dispatch_f64.c +348 -0
  79. package/numkong/c/dispatch_f64c.c +98 -0
  80. package/numkong/c/dispatch_i16.c +96 -0
  81. package/numkong/c/dispatch_i32.c +89 -0
  82. package/numkong/c/dispatch_i4.c +153 -0
  83. package/numkong/c/dispatch_i64.c +86 -0
  84. package/numkong/c/dispatch_i8.c +348 -0
  85. package/numkong/c/dispatch_other.c +348 -0
  86. package/numkong/c/dispatch_u1.c +193 -0
  87. package/numkong/c/dispatch_u16.c +124 -0
  88. package/numkong/c/dispatch_u32.c +118 -0
  89. package/numkong/c/dispatch_u4.c +153 -0
  90. package/numkong/c/dispatch_u64.c +102 -0
  91. package/numkong/c/dispatch_u8.c +364 -0
  92. package/numkong/c/numkong.c +940 -0
  93. package/numkong/cmake/nk_arm_isa_probes.cmake +61 -0
  94. package/numkong/cmake/nk_isa_probe.cmake +90 -0
  95. package/numkong/cmake/nk_loongarch_isa_probes.cmake +15 -0
  96. package/numkong/cmake/nk_math_lib.cmake +46 -0
  97. package/numkong/cmake/nk_power_isa_probes.cmake +15 -0
  98. package/numkong/cmake/nk_riscv_isa_probes.cmake +19 -0
  99. package/numkong/cmake/nk_x86_isa_probes.cmake +35 -0
  100. package/numkong/cmake/toolchain-aarch64-gnu.cmake +86 -0
  101. package/numkong/cmake/toolchain-android-arm64.cmake +25 -0
  102. package/numkong/cmake/toolchain-android-armv7.cmake +25 -0
  103. package/numkong/cmake/toolchain-loongarch64-gnu.cmake +68 -0
  104. package/numkong/cmake/toolchain-ppc64le-gnu.cmake +74 -0
  105. package/numkong/cmake/toolchain-riscv64-gnu.cmake +107 -0
  106. package/numkong/cmake/toolchain-riscv64-llvm.cmake +114 -0
  107. package/numkong/cmake/toolchain-wasi.cmake +77 -0
  108. package/numkong/cmake/toolchain-wasm.cmake +70 -0
  109. package/numkong/cmake/toolchain-wasm64.cmake +62 -0
  110. package/numkong/cmake/toolchain-x86_64-llvm.cmake +47 -0
  111. package/numkong/include/README.md +643 -0
  112. package/numkong/include/module.modulemap +129 -0
  113. package/numkong/include/numkong/attention/sapphireamx.h +1363 -0
  114. package/numkong/include/numkong/attention/sme.h +2075 -0
  115. package/numkong/include/numkong/attention.h +49 -0
  116. package/numkong/include/numkong/capabilities.h +930 -0
  117. package/numkong/include/numkong/cast/README.md +262 -0
  118. package/numkong/include/numkong/cast/diamond.h +64 -0
  119. package/numkong/include/numkong/cast/haswell.h +823 -0
  120. package/numkong/include/numkong/cast/icelake.h +475 -0
  121. package/numkong/include/numkong/cast/loongsonasx.h +252 -0
  122. package/numkong/include/numkong/cast/neon.h +1174 -0
  123. package/numkong/include/numkong/cast/powervsx.h +449 -0
  124. package/numkong/include/numkong/cast/rvv.h +970 -0
  125. package/numkong/include/numkong/cast/sapphire.h +262 -0
  126. package/numkong/include/numkong/cast/serial.h +2336 -0
  127. package/numkong/include/numkong/cast/skylake.h +915 -0
  128. package/numkong/include/numkong/cast/v128relaxed.h +537 -0
  129. package/numkong/include/numkong/cast.h +254 -0
  130. package/numkong/include/numkong/cast.hpp +44 -0
  131. package/numkong/include/numkong/curved/README.md +223 -0
  132. package/numkong/include/numkong/curved/genoa.h +182 -0
  133. package/numkong/include/numkong/curved/haswell.h +276 -0
  134. package/numkong/include/numkong/curved/neon.h +329 -0
  135. package/numkong/include/numkong/curved/neonbfdot.h +211 -0
  136. package/numkong/include/numkong/curved/rvv.h +305 -0
  137. package/numkong/include/numkong/curved/serial.h +207 -0
  138. package/numkong/include/numkong/curved/skylake.h +457 -0
  139. package/numkong/include/numkong/curved/smef64.h +530 -0
  140. package/numkong/include/numkong/curved.h +513 -0
  141. package/numkong/include/numkong/curved.hpp +144 -0
  142. package/numkong/include/numkong/dot/README.md +442 -0
  143. package/numkong/include/numkong/dot/alder.h +563 -0
  144. package/numkong/include/numkong/dot/diamond.h +158 -0
  145. package/numkong/include/numkong/dot/genoa.h +289 -0
  146. package/numkong/include/numkong/dot/haswell.h +1723 -0
  147. package/numkong/include/numkong/dot/icelake.h +997 -0
  148. package/numkong/include/numkong/dot/loongsonasx.h +671 -0
  149. package/numkong/include/numkong/dot/neon.h +869 -0
  150. package/numkong/include/numkong/dot/neonbfdot.h +243 -0
  151. package/numkong/include/numkong/dot/neonfhm.h +358 -0
  152. package/numkong/include/numkong/dot/neonfp8.h +323 -0
  153. package/numkong/include/numkong/dot/neonsdot.h +622 -0
  154. package/numkong/include/numkong/dot/powervsx.h +752 -0
  155. package/numkong/include/numkong/dot/rvv.h +722 -0
  156. package/numkong/include/numkong/dot/rvvbb.h +72 -0
  157. package/numkong/include/numkong/dot/rvvbf16.h +123 -0
  158. package/numkong/include/numkong/dot/rvvhalf.h +129 -0
  159. package/numkong/include/numkong/dot/sapphire.h +141 -0
  160. package/numkong/include/numkong/dot/serial.h +874 -0
  161. package/numkong/include/numkong/dot/sierra.h +405 -0
  162. package/numkong/include/numkong/dot/skylake.h +1116 -0
  163. package/numkong/include/numkong/dot/sve.h +420 -0
  164. package/numkong/include/numkong/dot/svebfdot.h +75 -0
  165. package/numkong/include/numkong/dot/svehalf.h +168 -0
  166. package/numkong/include/numkong/dot/svesdot.h +90 -0
  167. package/numkong/include/numkong/dot/v128relaxed.h +1293 -0
  168. package/numkong/include/numkong/dot.h +1136 -0
  169. package/numkong/include/numkong/dot.hpp +94 -0
  170. package/numkong/include/numkong/dots/README.md +496 -0
  171. package/numkong/include/numkong/dots/alder.h +117 -0
  172. package/numkong/include/numkong/dots/diamond.h +86 -0
  173. package/numkong/include/numkong/dots/genoa.h +100 -0
  174. package/numkong/include/numkong/dots/graniteamx.h +733 -0
  175. package/numkong/include/numkong/dots/haswell.h +310 -0
  176. package/numkong/include/numkong/dots/icelake.h +180 -0
  177. package/numkong/include/numkong/dots/loongsonasx.h +176 -0
  178. package/numkong/include/numkong/dots/neon.h +123 -0
  179. package/numkong/include/numkong/dots/neonbfdot.h +59 -0
  180. package/numkong/include/numkong/dots/neonfhm.h +96 -0
  181. package/numkong/include/numkong/dots/neonfp8.h +99 -0
  182. package/numkong/include/numkong/dots/neonsdot.h +144 -0
  183. package/numkong/include/numkong/dots/powervsx.h +194 -0
  184. package/numkong/include/numkong/dots/rvv.h +2593 -0
  185. package/numkong/include/numkong/dots/sapphireamx.h +4017 -0
  186. package/numkong/include/numkong/dots/serial.h +2867 -0
  187. package/numkong/include/numkong/dots/sierra.h +100 -0
  188. package/numkong/include/numkong/dots/skylake.h +207 -0
  189. package/numkong/include/numkong/dots/sme.h +5041 -0
  190. package/numkong/include/numkong/dots/smebi32.h +477 -0
  191. package/numkong/include/numkong/dots/smef64.h +1328 -0
  192. package/numkong/include/numkong/dots/smehalf.h +47 -0
  193. package/numkong/include/numkong/dots/v128relaxed.h +317 -0
  194. package/numkong/include/numkong/dots.h +3110 -0
  195. package/numkong/include/numkong/dots.hpp +641 -0
  196. package/numkong/include/numkong/each/README.md +465 -0
  197. package/numkong/include/numkong/each/haswell.h +1658 -0
  198. package/numkong/include/numkong/each/icelake.h +272 -0
  199. package/numkong/include/numkong/each/neon.h +1138 -0
  200. package/numkong/include/numkong/each/neonbfdot.h +211 -0
  201. package/numkong/include/numkong/each/neonhalf.h +318 -0
  202. package/numkong/include/numkong/each/rvv.h +1121 -0
  203. package/numkong/include/numkong/each/sapphire.h +343 -0
  204. package/numkong/include/numkong/each/serial.h +282 -0
  205. package/numkong/include/numkong/each/skylake.h +1562 -0
  206. package/numkong/include/numkong/each/v128relaxed.h +562 -0
  207. package/numkong/include/numkong/each.h +2232 -0
  208. package/numkong/include/numkong/each.hpp +434 -0
  209. package/numkong/include/numkong/geospatial/README.md +147 -0
  210. package/numkong/include/numkong/geospatial/haswell.h +633 -0
  211. package/numkong/include/numkong/geospatial/neon.h +615 -0
  212. package/numkong/include/numkong/geospatial/rvv.h +701 -0
  213. package/numkong/include/numkong/geospatial/serial.h +309 -0
  214. package/numkong/include/numkong/geospatial/skylake.h +613 -0
  215. package/numkong/include/numkong/geospatial/v128relaxed.h +652 -0
  216. package/numkong/include/numkong/geospatial.h +453 -0
  217. package/numkong/include/numkong/geospatial.hpp +235 -0
  218. package/numkong/include/numkong/matrix.hpp +336 -0
  219. package/numkong/include/numkong/maxsim/README.md +187 -0
  220. package/numkong/include/numkong/maxsim/alder.h +511 -0
  221. package/numkong/include/numkong/maxsim/genoa.h +115 -0
  222. package/numkong/include/numkong/maxsim/haswell.h +553 -0
  223. package/numkong/include/numkong/maxsim/icelake.h +480 -0
  224. package/numkong/include/numkong/maxsim/neonsdot.h +394 -0
  225. package/numkong/include/numkong/maxsim/sapphireamx.h +877 -0
  226. package/numkong/include/numkong/maxsim/serial.h +490 -0
  227. package/numkong/include/numkong/maxsim/sme.h +993 -0
  228. package/numkong/include/numkong/maxsim/v128relaxed.h +280 -0
  229. package/numkong/include/numkong/maxsim.h +571 -0
  230. package/numkong/include/numkong/maxsim.hpp +133 -0
  231. package/numkong/include/numkong/mesh/README.md +219 -0
  232. package/numkong/include/numkong/mesh/haswell.h +2013 -0
  233. package/numkong/include/numkong/mesh/neon.h +1821 -0
  234. package/numkong/include/numkong/mesh/neonbfdot.h +771 -0
  235. package/numkong/include/numkong/mesh/rvv.h +936 -0
  236. package/numkong/include/numkong/mesh/serial.h +721 -0
  237. package/numkong/include/numkong/mesh/skylake.h +2344 -0
  238. package/numkong/include/numkong/mesh/v128relaxed.h +1081 -0
  239. package/numkong/include/numkong/mesh.h +666 -0
  240. package/numkong/include/numkong/mesh.hpp +701 -0
  241. package/numkong/include/numkong/numkong.h +78 -0
  242. package/numkong/include/numkong/numkong.hpp +58 -0
  243. package/numkong/include/numkong/probability/README.md +177 -0
  244. package/numkong/include/numkong/probability/haswell.h +267 -0
  245. package/numkong/include/numkong/probability/neon.h +255 -0
  246. package/numkong/include/numkong/probability/rvv.h +414 -0
  247. package/numkong/include/numkong/probability/serial.h +181 -0
  248. package/numkong/include/numkong/probability/skylake.h +324 -0
  249. package/numkong/include/numkong/probability.h +380 -0
  250. package/numkong/include/numkong/probability.hpp +120 -0
  251. package/numkong/include/numkong/random.h +50 -0
  252. package/numkong/include/numkong/random.hpp +285 -0
  253. package/numkong/include/numkong/reduce/README.md +552 -0
  254. package/numkong/include/numkong/reduce/alder.h +636 -0
  255. package/numkong/include/numkong/reduce/genoa.h +201 -0
  256. package/numkong/include/numkong/reduce/haswell.h +3785 -0
  257. package/numkong/include/numkong/reduce/icelake.h +549 -0
  258. package/numkong/include/numkong/reduce/neon.h +3980 -0
  259. package/numkong/include/numkong/reduce/neonbfdot.h +142 -0
  260. package/numkong/include/numkong/reduce/neonfhm.h +293 -0
  261. package/numkong/include/numkong/reduce/neonsdot.h +357 -0
  262. package/numkong/include/numkong/reduce/rvv.h +3533 -0
  263. package/numkong/include/numkong/reduce/serial.h +753 -0
  264. package/numkong/include/numkong/reduce/sierra.h +338 -0
  265. package/numkong/include/numkong/reduce/skylake.h +3794 -0
  266. package/numkong/include/numkong/reduce/sve.h +52 -0
  267. package/numkong/include/numkong/reduce/v128relaxed.h +2302 -0
  268. package/numkong/include/numkong/reduce.h +1582 -0
  269. package/numkong/include/numkong/reduce.hpp +778 -0
  270. package/numkong/include/numkong/scalar/README.md +89 -0
  271. package/numkong/include/numkong/scalar/haswell.h +122 -0
  272. package/numkong/include/numkong/scalar/loongsonasx.h +74 -0
  273. package/numkong/include/numkong/scalar/neon.h +122 -0
  274. package/numkong/include/numkong/scalar/neonhalf.h +70 -0
  275. package/numkong/include/numkong/scalar/powervsx.h +96 -0
  276. package/numkong/include/numkong/scalar/rvv.h +211 -0
  277. package/numkong/include/numkong/scalar/sapphire.h +74 -0
  278. package/numkong/include/numkong/scalar/serial.h +332 -0
  279. package/numkong/include/numkong/scalar/v128relaxed.h +56 -0
  280. package/numkong/include/numkong/scalar.h +696 -0
  281. package/numkong/include/numkong/set/README.md +179 -0
  282. package/numkong/include/numkong/set/haswell.h +334 -0
  283. package/numkong/include/numkong/set/icelake.h +485 -0
  284. package/numkong/include/numkong/set/loongsonasx.h +181 -0
  285. package/numkong/include/numkong/set/neon.h +363 -0
  286. package/numkong/include/numkong/set/powervsx.h +326 -0
  287. package/numkong/include/numkong/set/rvv.h +226 -0
  288. package/numkong/include/numkong/set/rvvbb.h +117 -0
  289. package/numkong/include/numkong/set/serial.h +174 -0
  290. package/numkong/include/numkong/set/sve.h +187 -0
  291. package/numkong/include/numkong/set/v128relaxed.h +240 -0
  292. package/numkong/include/numkong/set.h +471 -0
  293. package/numkong/include/numkong/set.hpp +114 -0
  294. package/numkong/include/numkong/sets/README.md +149 -0
  295. package/numkong/include/numkong/sets/haswell.h +63 -0
  296. package/numkong/include/numkong/sets/icelake.h +66 -0
  297. package/numkong/include/numkong/sets/loongsonasx.h +52 -0
  298. package/numkong/include/numkong/sets/neon.h +61 -0
  299. package/numkong/include/numkong/sets/powervsx.h +65 -0
  300. package/numkong/include/numkong/sets/serial.h +43 -0
  301. package/numkong/include/numkong/sets/smebi32.h +1135 -0
  302. package/numkong/include/numkong/sets/v128relaxed.h +58 -0
  303. package/numkong/include/numkong/sets.h +382 -0
  304. package/numkong/include/numkong/sparse/README.md +156 -0
  305. package/numkong/include/numkong/sparse/icelake.h +463 -0
  306. package/numkong/include/numkong/sparse/neon.h +288 -0
  307. package/numkong/include/numkong/sparse/serial.h +117 -0
  308. package/numkong/include/numkong/sparse/sve2.h +504 -0
  309. package/numkong/include/numkong/sparse/turin.h +322 -0
  310. package/numkong/include/numkong/sparse.h +363 -0
  311. package/numkong/include/numkong/sparse.hpp +113 -0
  312. package/numkong/include/numkong/spatial/README.md +439 -0
  313. package/numkong/include/numkong/spatial/alder.h +604 -0
  314. package/numkong/include/numkong/spatial/diamond.h +240 -0
  315. package/numkong/include/numkong/spatial/genoa.h +222 -0
  316. package/numkong/include/numkong/spatial/haswell.h +979 -0
  317. package/numkong/include/numkong/spatial/icelake.h +1067 -0
  318. package/numkong/include/numkong/spatial/loongsonasx.h +483 -0
  319. package/numkong/include/numkong/spatial/neon.h +846 -0
  320. package/numkong/include/numkong/spatial/neonbfdot.h +164 -0
  321. package/numkong/include/numkong/spatial/neonfp8.h +258 -0
  322. package/numkong/include/numkong/spatial/neonsdot.h +429 -0
  323. package/numkong/include/numkong/spatial/powervsx.h +738 -0
  324. package/numkong/include/numkong/spatial/rvv.h +991 -0
  325. package/numkong/include/numkong/spatial/rvvbf16.h +128 -0
  326. package/numkong/include/numkong/spatial/rvvhalf.h +120 -0
  327. package/numkong/include/numkong/spatial/serial.h +347 -0
  328. package/numkong/include/numkong/spatial/sierra.h +516 -0
  329. package/numkong/include/numkong/spatial/skylake.h +605 -0
  330. package/numkong/include/numkong/spatial/sve.h +246 -0
  331. package/numkong/include/numkong/spatial/svebfdot.h +125 -0
  332. package/numkong/include/numkong/spatial/svehalf.h +136 -0
  333. package/numkong/include/numkong/spatial/svesdot.h +143 -0
  334. package/numkong/include/numkong/spatial/v128relaxed.h +969 -0
  335. package/numkong/include/numkong/spatial.h +1681 -0
  336. package/numkong/include/numkong/spatial.hpp +183 -0
  337. package/numkong/include/numkong/spatials/README.md +580 -0
  338. package/numkong/include/numkong/spatials/alder.h +94 -0
  339. package/numkong/include/numkong/spatials/diamond.h +82 -0
  340. package/numkong/include/numkong/spatials/genoa.h +94 -0
  341. package/numkong/include/numkong/spatials/graniteamx.h +173 -0
  342. package/numkong/include/numkong/spatials/haswell.h +219 -0
  343. package/numkong/include/numkong/spatials/icelake.h +113 -0
  344. package/numkong/include/numkong/spatials/loongsonasx.h +153 -0
  345. package/numkong/include/numkong/spatials/neon.h +109 -0
  346. package/numkong/include/numkong/spatials/neonbfdot.h +60 -0
  347. package/numkong/include/numkong/spatials/neonfhm.h +92 -0
  348. package/numkong/include/numkong/spatials/neonfp8.h +111 -0
  349. package/numkong/include/numkong/spatials/neonsdot.h +143 -0
  350. package/numkong/include/numkong/spatials/powervsx.h +153 -0
  351. package/numkong/include/numkong/spatials/rvv.h +1976 -0
  352. package/numkong/include/numkong/spatials/sapphireamx.h +1149 -0
  353. package/numkong/include/numkong/spatials/serial.h +248 -0
  354. package/numkong/include/numkong/spatials/sierra.h +96 -0
  355. package/numkong/include/numkong/spatials/skylake.h +184 -0
  356. package/numkong/include/numkong/spatials/sme.h +1927 -0
  357. package/numkong/include/numkong/spatials/smef64.h +483 -0
  358. package/numkong/include/numkong/spatials/v128relaxed.h +240 -0
  359. package/numkong/include/numkong/spatials.h +3374 -0
  360. package/numkong/include/numkong/spatials.hpp +509 -0
  361. package/numkong/include/numkong/tensor.hpp +1981 -0
  362. package/numkong/include/numkong/trigonometry/README.md +184 -0
  363. package/numkong/include/numkong/trigonometry/haswell.h +653 -0
  364. package/numkong/include/numkong/trigonometry/neon.h +638 -0
  365. package/numkong/include/numkong/trigonometry/rvv.h +700 -0
  366. package/numkong/include/numkong/trigonometry/serial.h +703 -0
  367. package/numkong/include/numkong/trigonometry/skylake.h +725 -0
  368. package/numkong/include/numkong/trigonometry/v128relaxed.h +667 -0
  369. package/numkong/include/numkong/trigonometry.h +467 -0
  370. package/numkong/include/numkong/trigonometry.hpp +166 -0
  371. package/numkong/include/numkong/types.h +1695 -0
  372. package/numkong/include/numkong/types.hpp +6027 -0
  373. package/numkong/include/numkong/vector.hpp +766 -0
  374. package/numkong/javascript/@numkong-darwin-arm64/package.json +26 -0
  375. package/numkong/javascript/@numkong-darwin-x64/package.json +26 -0
  376. package/numkong/javascript/@numkong-linux-arm64/package.json +25 -0
  377. package/numkong/javascript/@numkong-linux-x64/package.json +25 -0
  378. package/numkong/javascript/@numkong-win32-arm64/package.json +25 -0
  379. package/numkong/javascript/@numkong-win32-x64/package.json +25 -0
  380. package/numkong/javascript/README.md +254 -0
  381. package/numkong/javascript/node-gyp-build.d.ts +4 -0
  382. package/numkong/javascript/numkong-browser.ts +40 -0
  383. package/numkong/javascript/numkong-wasm.ts +750 -0
  384. package/numkong/javascript/numkong.c +712 -0
  385. package/numkong/javascript/numkong.ts +613 -0
  386. package/{simsimd → numkong}/javascript/tsconfig-base.json +6 -3
  387. package/numkong/javascript/tsconfig-cjs.json +13 -0
  388. package/{simsimd → numkong}/javascript/tsconfig-esm.json +1 -1
  389. package/numkong/javascript/types.ts +784 -0
  390. package/numkong/numkong.gypi +104 -0
  391. package/numkong/package.json +108 -0
  392. package/numkong/probes/arm_neon.c +8 -0
  393. package/numkong/probes/arm_neon_bfdot.c +9 -0
  394. package/numkong/probes/arm_neon_fhm.c +9 -0
  395. package/numkong/probes/arm_neon_half.c +8 -0
  396. package/numkong/probes/arm_neon_sdot.c +9 -0
  397. package/numkong/probes/arm_neonfp8.c +9 -0
  398. package/numkong/probes/arm_sme.c +16 -0
  399. package/numkong/probes/arm_sme2.c +16 -0
  400. package/numkong/probes/arm_sme2p1.c +16 -0
  401. package/numkong/probes/arm_sme_bf16.c +16 -0
  402. package/numkong/probes/arm_sme_bi32.c +16 -0
  403. package/numkong/probes/arm_sme_f64.c +16 -0
  404. package/numkong/probes/arm_sme_fa64.c +14 -0
  405. package/numkong/probes/arm_sme_half.c +16 -0
  406. package/numkong/probes/arm_sme_lut2.c +15 -0
  407. package/numkong/probes/arm_sve.c +18 -0
  408. package/numkong/probes/arm_sve2.c +20 -0
  409. package/numkong/probes/arm_sve2p1.c +18 -0
  410. package/numkong/probes/arm_sve_bfdot.c +20 -0
  411. package/numkong/probes/arm_sve_half.c +18 -0
  412. package/numkong/probes/arm_sve_sdot.c +21 -0
  413. package/numkong/probes/loongarch_lasx.c +12 -0
  414. package/numkong/probes/power_vsx.c +12 -0
  415. package/numkong/probes/probe.js +127 -0
  416. package/numkong/probes/riscv_rvv.c +14 -0
  417. package/numkong/probes/riscv_rvv_bb.c +15 -0
  418. package/numkong/probes/riscv_rvv_bf16.c +17 -0
  419. package/numkong/probes/riscv_rvv_half.c +14 -0
  420. package/numkong/probes/wasm_v128relaxed.c +11 -0
  421. package/numkong/probes/x86_alder.c +17 -0
  422. package/numkong/probes/x86_diamond.c +17 -0
  423. package/numkong/probes/x86_genoa.c +17 -0
  424. package/numkong/probes/x86_graniteamx.c +19 -0
  425. package/numkong/probes/x86_haswell.c +11 -0
  426. package/numkong/probes/x86_icelake.c +17 -0
  427. package/numkong/probes/x86_sapphire.c +16 -0
  428. package/numkong/probes/x86_sapphireamx.c +18 -0
  429. package/numkong/probes/x86_sierra.c +17 -0
  430. package/numkong/probes/x86_skylake.c +15 -0
  431. package/numkong/probes/x86_turin.c +17 -0
  432. package/numkong/rust/README.md +698 -0
  433. package/numkong/rust/capabilities.rs +96 -0
  434. package/numkong/rust/cast.rs +314 -0
  435. package/numkong/rust/curved.rs +391 -0
  436. package/numkong/rust/each.rs +2721 -0
  437. package/numkong/rust/geospatial.rs +343 -0
  438. package/numkong/rust/matrix.rs +5424 -0
  439. package/numkong/rust/maxsim.rs +540 -0
  440. package/numkong/rust/mesh.rs +837 -0
  441. package/numkong/rust/numkong.rs +409 -0
  442. package/numkong/rust/probability.rs +272 -0
  443. package/numkong/rust/reduce.rs +1249 -0
  444. package/numkong/rust/set.rs +194 -0
  445. package/numkong/rust/sparse.rs +513 -0
  446. package/numkong/rust/spatial.rs +1815 -0
  447. package/numkong/rust/tensor.rs +7565 -0
  448. package/numkong/rust/types.rs +3666 -0
  449. package/numkong/rust/vector.rs +1899 -0
  450. package/numkong/rustfmt.toml +2 -0
  451. package/numkong/swift/Matrix.swift +1388 -0
  452. package/numkong/swift/MaxSim.swift +151 -0
  453. package/numkong/swift/NumKong.swift +283 -0
  454. package/numkong/swift/Numerics.swift +329 -0
  455. package/numkong/swift/README.md +433 -0
  456. package/numkong/swift/Scalar.swift +741 -0
  457. package/numkong/swift/Tensor.swift +209 -0
  458. package/numkong/test/README.md +315 -0
  459. package/numkong/test/playwright.config.ts +16 -0
  460. package/numkong/test/swift/Test.swift +534 -0
  461. package/numkong/test/test-browser-bundle-runner.mjs +36 -0
  462. package/numkong/test/test-browser-bundle.html +188 -0
  463. package/numkong/test/test-browser-runner.mjs +43 -0
  464. package/numkong/test/test-browser.html +305 -0
  465. package/numkong/test/test-dtypes.mjs +453 -0
  466. package/numkong/test/test-wasm.mjs +267 -0
  467. package/numkong/test/test.cpp +442 -0
  468. package/numkong/test/test.hpp +580 -0
  469. package/numkong/test/test.mjs +363 -0
  470. package/numkong/test/test_base.py +1041 -0
  471. package/numkong/test/test_cast.cpp +242 -0
  472. package/numkong/test/test_cross.hpp +551 -0
  473. package/numkong/test/test_cross.py +467 -0
  474. package/numkong/test/test_cross_amx.cpp +50 -0
  475. package/numkong/test/test_cross_arm.cpp +225 -0
  476. package/numkong/test/test_cross_blas.cpp +354 -0
  477. package/numkong/test/test_cross_loongarch.cpp +90 -0
  478. package/numkong/test/test_cross_power.cpp +73 -0
  479. package/numkong/test/test_cross_rvv.cpp +109 -0
  480. package/numkong/test/test_cross_serial.cpp +181 -0
  481. package/numkong/test/test_cross_sme.cpp +148 -0
  482. package/numkong/test/test_cross_wasm.cpp +141 -0
  483. package/numkong/test/test_cross_x86.cpp +442 -0
  484. package/numkong/test/test_curved.cpp +182 -0
  485. package/numkong/test/test_curved.py +207 -0
  486. package/numkong/test/test_dot.cpp +353 -0
  487. package/numkong/test/test_dot.py +296 -0
  488. package/numkong/test/test_each.cpp +437 -0
  489. package/numkong/test/test_each.py +756 -0
  490. package/numkong/test/test_geospatial.cpp +155 -0
  491. package/numkong/test/test_geospatial.py +241 -0
  492. package/numkong/test/test_maxsim.cpp +138 -0
  493. package/numkong/test/test_maxsim.py +209 -0
  494. package/numkong/test/test_mesh.cpp +203 -0
  495. package/numkong/test/test_mesh.py +394 -0
  496. package/numkong/test/test_probability.cpp +136 -0
  497. package/numkong/test/test_probability.py +166 -0
  498. package/numkong/test/test_reduce.cpp +563 -0
  499. package/numkong/test/test_reduce.py +781 -0
  500. package/numkong/test/test_set.cpp +151 -0
  501. package/numkong/test/test_set.py +120 -0
  502. package/numkong/test/test_similarities.py +579 -0
  503. package/numkong/test/test_sparse.cpp +121 -0
  504. package/numkong/test/test_sparse.py +118 -0
  505. package/numkong/test/test_spatial.cpp +518 -0
  506. package/numkong/test/test_spatial.py +269 -0
  507. package/numkong/test/test_tensor.cpp +884 -0
  508. package/numkong/test/test_tensor.py +1417 -0
  509. package/numkong/test/test_trigonometry.cpp +156 -0
  510. package/numkong/test/test_trigonometry.py +180 -0
  511. package/package.json +7 -8
  512. package/prebuilds/darwin-arm64+x64/usearch.node +0 -0
  513. package/prebuilds/linux-arm64/usearch.node +0 -0
  514. package/prebuilds/linux-x64/usearch.node +0 -0
  515. package/fp16/CMakeLists.txt +0 -176
  516. package/fp16/LICENSE +0 -11
  517. package/fp16/README.md +0 -20
  518. package/fp16/bench/alt-element.cc +0 -89
  519. package/fp16/bench/from-alt-array.cc +0 -175
  520. package/fp16/bench/from-ieee-array.cc +0 -399
  521. package/fp16/bench/ieee-element.cc +0 -272
  522. package/fp16/bench/to-alt-array.cc +0 -91
  523. package/fp16/bench/to-ieee-array.cc +0 -303
  524. package/fp16/cmake/DownloadGoogleBenchmark.cmake +0 -15
  525. package/fp16/cmake/DownloadGoogleTest.cmake +0 -15
  526. package/fp16/cmake/DownloadPSimd.cmake +0 -15
  527. package/fp16/configure.py +0 -65
  528. package/fp16/confu.yaml +0 -8
  529. package/fp16/include/fp16/__init__.py +0 -0
  530. package/fp16/include/fp16/avx.py +0 -50
  531. package/fp16/include/fp16/avx2.py +0 -53
  532. package/fp16/include/fp16/bitcasts.h +0 -92
  533. package/fp16/include/fp16/fp16.h +0 -451
  534. package/fp16/include/fp16/psimd.h +0 -131
  535. package/fp16/include/fp16.h +0 -11
  536. package/fp16/jni/Android.mk +0 -6
  537. package/fp16/jni/Application.mk +0 -4
  538. package/fp16/test/alt-from-fp32-value.cc +0 -498
  539. package/fp16/test/alt-to-fp32-bits.cc +0 -263
  540. package/fp16/test/alt-to-fp32-psimd.cc +0 -145
  541. package/fp16/test/alt-to-fp32-value.cc +0 -348
  542. package/fp16/test/alt-to-fp32x2-psimd.cc +0 -245
  543. package/fp16/test/bitcasts.cc +0 -56
  544. package/fp16/test/ieee-from-fp32-value.cc +0 -523
  545. package/fp16/test/ieee-to-fp32-bits.cc +0 -333
  546. package/fp16/test/ieee-to-fp32-psimd.cc +0 -312
  547. package/fp16/test/ieee-to-fp32-value.cc +0 -420
  548. package/fp16/test/ieee-to-fp32x2-psimd.cc +0 -541
  549. package/fp16/test/peachpy/alt-xmm-to-fp32-xmm-avx.cc +0 -96
  550. package/fp16/test/peachpy/alt-xmm-to-fp32-ymm-avx2.cc +0 -96
  551. package/fp16/test/peachpy/stubs.py +0 -38
  552. package/fp16/test/tables.cc +0 -530
  553. package/fp16/test/tables.h +0 -13
  554. package/fp16/third-party/THHalf.h +0 -92
  555. package/fp16/third-party/eigen-half.h +0 -170
  556. package/fp16/third-party/float16-compressor.h +0 -80
  557. package/fp16/third-party/half.hpp +0 -2916
  558. package/fp16/third-party/npy-halffloat.h +0 -328
  559. package/simsimd/.git-blame-ignore-revs +0 -2
  560. package/simsimd/CONTRIBUTING.md +0 -321
  561. package/simsimd/Cargo.toml +0 -49
  562. package/simsimd/MANIFEST.in +0 -4
  563. package/simsimd/Package.swift +0 -28
  564. package/simsimd/README.md +0 -1493
  565. package/simsimd/binding.gyp +0 -35
  566. package/simsimd/build.rs +0 -70
  567. package/simsimd/c/lib.c +0 -374
  568. package/simsimd/include/module.modulemap +0 -4
  569. package/simsimd/include/simsimd/binary.h +0 -486
  570. package/simsimd/include/simsimd/curved.h +0 -1541
  571. package/simsimd/include/simsimd/dot.h +0 -1853
  572. package/simsimd/include/simsimd/elementwise.h +0 -2465
  573. package/simsimd/include/simsimd/geospatial.h +0 -43
  574. package/simsimd/include/simsimd/mesh.h +0 -69
  575. package/simsimd/include/simsimd/probability.h +0 -606
  576. package/simsimd/include/simsimd/simsimd.h +0 -2567
  577. package/simsimd/include/simsimd/sparse.h +0 -1384
  578. package/simsimd/include/simsimd/spatial.h +0 -2335
  579. package/simsimd/include/simsimd/types.h +0 -666
  580. package/simsimd/javascript/fallback.ts +0 -233
  581. package/simsimd/javascript/lib.c +0 -125
  582. package/simsimd/javascript/node-gyp-build.d.ts +0 -1
  583. package/simsimd/javascript/simsimd.ts +0 -179
  584. package/simsimd/javascript/tsconfig-cjs.json +0 -8
  585. package/simsimd/package-lock.json +0 -1761
  586. package/simsimd/package.json +0 -61
  587. package/simsimd/rust/lib.rs +0 -1821
  588. package/simsimd/scripts/bench.cxx +0 -1170
  589. package/simsimd/scripts/bench.ipynb +0 -187
  590. package/simsimd/scripts/bench.js +0 -127
  591. package/simsimd/scripts/bench.rs +0 -876
  592. package/simsimd/scripts/bench_vectors.py +0 -734
  593. package/simsimd/scripts/bench_vectors_live.py +0 -213
  594. package/simsimd/scripts/test.c +0 -187
  595. package/simsimd/scripts/test.mjs +0 -220
  596. package/simsimd/scripts/test.py +0 -1505
  597. package/simsimd/swift/SimSIMD.swift +0 -149
  598. package/simsimd/swift/Test.swift +0 -128
  599. /package/{simsimd → numkong}/CODE_OF_CONDUCT.md +0 -0
  600. /package/{simsimd → numkong}/LICENSE +0 -0
  601. /package/{simsimd → numkong}/javascript/dist-package-cjs.json +0 -0
  602. /package/{simsimd → numkong}/javascript/dist-package-esm.json +0 -0
@@ -0,0 +1,1388 @@
1
+ // Matrix.swift
2
+ // NumKong
3
+ //
4
+ // Created by Ash Vardanian on March 14, 2026.
5
+ //
6
+
7
+ import CNumKong
8
+
9
+ /// Errors thrown by matrix operations.
10
+ public enum NumKongMatrixError: Error {
11
+ /// The matrix has zero or negative rows/cols.
12
+ case invalidDimensions
13
+ /// The row stride is smaller than `cols * MemoryLayout<Element>.stride`.
14
+ case invalidStride
15
+ /// The output matrix shape does not match the expected dimensions.
16
+ case outputShapeMismatch
17
+ /// The vector depth (cols) of the two matrices differs.
18
+ case depthMismatch
19
+ /// The requested row window exceeds matrix bounds.
20
+ case rowWindowOutOfBounds
21
+ /// The packed buffer size returned by the kernel is zero.
22
+ case packedBufferTooSmall
23
+ }
24
+
25
+ /// Non-owning, immutable view over a row-major matrix stored in contiguous memory.
26
+ public struct MatrixView<Element> {
27
+ public let baseAddress: UnsafePointer<Element>
28
+ public let rows: Int
29
+ public let cols: Int
30
+ public let rowStrideBytes: Int
31
+
32
+ @inlinable
33
+ public init(
34
+ baseAddress: UnsafePointer<Element>,
35
+ rows: Int,
36
+ cols: Int,
37
+ rowStrideBytes: Int? = nil
38
+ ) {
39
+ self.baseAddress = baseAddress
40
+ self.rows = rows
41
+ self.cols = cols
42
+ self.rowStrideBytes = rowStrideBytes ?? cols * MemoryLayout<Element>.stride
43
+ }
44
+ }
45
+
46
+ /// Non-owning, mutable view over a row-major matrix stored in contiguous memory.
47
+ public struct MatrixSpan<Element> {
48
+ public let baseAddress: UnsafeMutablePointer<Element>
49
+ public let rows: Int
50
+ public let cols: Int
51
+ public let rowStrideBytes: Int
52
+
53
+ @inlinable
54
+ public init(
55
+ baseAddress: UnsafeMutablePointer<Element>,
56
+ rows: Int,
57
+ cols: Int,
58
+ rowStrideBytes: Int? = nil
59
+ ) {
60
+ self.baseAddress = baseAddress
61
+ self.rows = rows
62
+ self.cols = cols
63
+ self.rowStrideBytes = rowStrideBytes ?? cols * MemoryLayout<Element>.stride
64
+ }
65
+ }
66
+
67
+ // MARK: - Deprecated Aliases
68
+
69
+ @available(*, deprecated, renamed: "MatrixView")
70
+ public typealias Matrix = MatrixView
71
+
72
+ @available(*, deprecated, renamed: "MatrixSpan")
73
+ public typealias MutableMatrix = MatrixSpan
74
+
75
+ // MARK: - PackedMatrix
76
+
77
+ /// Owns a kernel-optimized packed copy of a matrix for batch distance computations.
78
+ public final class PackedMatrix<Element>: @unchecked Sendable {
79
+ public let rows: Int
80
+ public let cols: Int
81
+ public let byteCount: Int
82
+
83
+ @usableFromInline
84
+ let rawPointer: UnsafeMutableRawPointer
85
+
86
+ @usableFromInline
87
+ init(rows: Int, cols: Int, byteCount: Int, rawPointer: UnsafeMutableRawPointer) {
88
+ self.rows = rows
89
+ self.cols = cols
90
+ self.byteCount = byteCount
91
+ self.rawPointer = rawPointer
92
+ }
93
+
94
+ deinit {
95
+ rawPointer.deallocate()
96
+ }
97
+
98
+ /// Provides read-only access to the underlying packed bytes.
99
+ @inlinable
100
+ public var rawBuffer: UnsafeRawBufferPointer {
101
+ UnsafeRawBufferPointer(start: rawPointer, count: byteCount)
102
+ }
103
+ }
104
+
105
+ // MARK: - Validation
106
+
107
+ @usableFromInline
108
+ func _nkValidateMatrixView<Element>(_ matrix: MatrixView<Element>) throws {
109
+ guard matrix.rows > 0 && matrix.cols > 0 else {
110
+ throw NumKongMatrixError.invalidDimensions
111
+ }
112
+ let minStride = matrix.cols * MemoryLayout<Element>.stride
113
+ guard matrix.rowStrideBytes >= minStride else {
114
+ throw NumKongMatrixError.invalidStride
115
+ }
116
+ }
117
+
118
+ @usableFromInline
119
+ func _nkValidateMatrixSpan<Element>(_ matrix: MatrixSpan<Element>) throws {
120
+ guard matrix.rows > 0 && matrix.cols > 0 else {
121
+ throw NumKongMatrixError.invalidDimensions
122
+ }
123
+ let minStride = matrix.cols * MemoryLayout<Element>.stride
124
+ guard matrix.rowStrideBytes >= minStride else {
125
+ throw NumKongMatrixError.invalidStride
126
+ }
127
+ }
128
+
129
+ // MARK: - Dots Protocol
130
+
131
+ /// Element type that supports batch dot-product matrix operations.
132
+ public protocol NumKongDotsMatrixElement {
133
+ associatedtype DotsOutput
134
+
135
+ static func _nk_dots_packed_size(_ n: Int, _ k: Int) -> Int
136
+ static func _nk_dots_pack(
137
+ _ b: UnsafePointer<Self>, _ n: Int, _ k: Int, _ bStride: Int, _ packed: UnsafeMutableRawPointer)
138
+ static func _nk_dots_packed(
139
+ _ a: UnsafePointer<Self>,
140
+ _ bPacked: UnsafeRawPointer,
141
+ _ c: UnsafeMutablePointer<DotsOutput>,
142
+ _ m: Int,
143
+ _ n: Int,
144
+ _ k: Int,
145
+ _ aStride: Int,
146
+ _ cStride: Int
147
+ )
148
+ static func _nk_dots_symmetric(
149
+ _ vectors: UnsafePointer<Self>,
150
+ _ result: UnsafeMutablePointer<DotsOutput>,
151
+ _ nVectors: Int,
152
+ _ depth: Int,
153
+ _ stride: Int,
154
+ _ resultStride: Int,
155
+ _ rowStart: Int,
156
+ _ rowCount: Int
157
+ )
158
+ }
159
+
160
+ // MARK: - Spatials Protocol
161
+
162
+ /// Element type that supports batch angular and Euclidean matrix operations.
163
+ public protocol NumKongSpatialsMatrixElement: NumKongDotsMatrixElement {
164
+ associatedtype SpatialOutput
165
+
166
+ static func _nk_angulars_packed(
167
+ _ a: UnsafePointer<Self>,
168
+ _ bPacked: UnsafeRawPointer,
169
+ _ result: UnsafeMutablePointer<SpatialOutput>,
170
+ _ rows: Int,
171
+ _ cols: Int,
172
+ _ depth: Int,
173
+ _ aStride: Int,
174
+ _ rStride: Int
175
+ )
176
+ static func _nk_euclideans_packed(
177
+ _ a: UnsafePointer<Self>,
178
+ _ bPacked: UnsafeRawPointer,
179
+ _ result: UnsafeMutablePointer<SpatialOutput>,
180
+ _ rows: Int,
181
+ _ cols: Int,
182
+ _ depth: Int,
183
+ _ aStride: Int,
184
+ _ rStride: Int
185
+ )
186
+ static func _nk_angulars_symmetric(
187
+ _ vectors: UnsafePointer<Self>,
188
+ _ result: UnsafeMutablePointer<SpatialOutput>,
189
+ _ nVectors: Int,
190
+ _ depth: Int,
191
+ _ stride: Int,
192
+ _ resultStride: Int,
193
+ _ rowStart: Int,
194
+ _ rowCount: Int
195
+ )
196
+ static func _nk_euclideans_symmetric(
197
+ _ vectors: UnsafePointer<Self>,
198
+ _ result: UnsafeMutablePointer<SpatialOutput>,
199
+ _ nVectors: Int,
200
+ _ depth: Int,
201
+ _ stride: Int,
202
+ _ resultStride: Int,
203
+ _ rowStart: Int,
204
+ _ rowCount: Int
205
+ )
206
+ }
207
+
208
+ // MARK: - Sets Protocol
209
+
210
+ /// Element type that supports batch Hamming and Jaccard matrix operations.
211
+ public protocol NumKongSetsMatrixElement: NumKongDotsMatrixElement {
212
+ associatedtype HammingOutput
213
+ associatedtype JaccardOutput
214
+
215
+ static func _nk_hammings_packed(
216
+ _ a: UnsafePointer<Self>,
217
+ _ bPacked: UnsafeRawPointer,
218
+ _ result: UnsafeMutablePointer<HammingOutput>,
219
+ _ rows: Int,
220
+ _ cols: Int,
221
+ _ depth: Int,
222
+ _ aStride: Int,
223
+ _ rStride: Int
224
+ )
225
+ static func _nk_hammings_symmetric(
226
+ _ vectors: UnsafePointer<Self>,
227
+ _ result: UnsafeMutablePointer<HammingOutput>,
228
+ _ nVectors: Int,
229
+ _ depth: Int,
230
+ _ stride: Int,
231
+ _ resultStride: Int,
232
+ _ rowStart: Int,
233
+ _ rowCount: Int
234
+ )
235
+ static func _nk_jaccards_packed(
236
+ _ a: UnsafePointer<Self>,
237
+ _ bPacked: UnsafeRawPointer,
238
+ _ result: UnsafeMutablePointer<JaccardOutput>,
239
+ _ rows: Int,
240
+ _ cols: Int,
241
+ _ depth: Int,
242
+ _ aStride: Int,
243
+ _ rStride: Int
244
+ )
245
+ static func _nk_jaccards_symmetric(
246
+ _ vectors: UnsafePointer<Self>,
247
+ _ result: UnsafeMutablePointer<JaccardOutput>,
248
+ _ nVectors: Int,
249
+ _ depth: Int,
250
+ _ stride: Int,
251
+ _ resultStride: Int,
252
+ _ rowStart: Int,
253
+ _ rowCount: Int
254
+ )
255
+ }
256
+
257
+ // MARK: - PackedMatrix Packing
258
+
259
+ extension PackedMatrix where Element: NumKongDotsMatrixElement {
260
+ /// Packs the given matrix view into a kernel-optimized layout for batch dot products.
261
+ public convenience init(packing matrix: MatrixView<Element>) throws {
262
+ try _nkValidateMatrixView(matrix)
263
+ let bytes = Element._nk_dots_packed_size(matrix.rows, matrix.cols)
264
+ guard bytes > 0 else { throw NumKongMatrixError.packedBufferTooSmall }
265
+ let ptr = UnsafeMutableRawPointer.allocate(byteCount: bytes, alignment: 64)
266
+ Element._nk_dots_pack(matrix.baseAddress, matrix.rows, matrix.cols, matrix.rowStrideBytes, ptr)
267
+ self.init(rows: matrix.rows, cols: matrix.cols, byteCount: bytes, rawPointer: ptr)
268
+ }
269
+ }
270
+
271
+ // MARK: - Dots Functions
272
+
273
+ /// Computes dot products between each row of `a` and every row packed in `bPacked`.
274
+ @inlinable
275
+ public func dots_packed<Element: NumKongDotsMatrixElement>(
276
+ _ a: MatrixView<Element>,
277
+ _ bPacked: PackedMatrix<Element>,
278
+ _ result: inout MatrixSpan<Element.DotsOutput>
279
+ ) throws {
280
+ try _nkValidateMatrixView(a)
281
+ try _nkValidateMatrixSpan(result)
282
+
283
+ guard a.cols == bPacked.cols else { throw NumKongMatrixError.depthMismatch }
284
+ guard result.rows == a.rows && result.cols == bPacked.rows else {
285
+ throw NumKongMatrixError.outputShapeMismatch
286
+ }
287
+
288
+ Element._nk_dots_packed(
289
+ a.baseAddress,
290
+ UnsafeRawPointer(bPacked.rawPointer),
291
+ result.baseAddress,
292
+ a.rows,
293
+ bPacked.rows,
294
+ a.cols,
295
+ a.rowStrideBytes,
296
+ result.rowStrideBytes
297
+ )
298
+ }
299
+
300
+ /// Computes the symmetric dot-product matrix for all row pairs in `vectors`.
301
+ @inlinable
302
+ public func dots_symmetric<Element: NumKongDotsMatrixElement>(
303
+ _ vectors: MatrixView<Element>,
304
+ _ result: inout MatrixSpan<Element.DotsOutput>,
305
+ rowStart: Int = 0,
306
+ rowCount: Int? = nil
307
+ ) throws {
308
+ try _nkValidateMatrixView(vectors)
309
+ try _nkValidateMatrixSpan(result)
310
+
311
+ guard result.rows == vectors.rows && result.cols == vectors.rows else {
312
+ throw NumKongMatrixError.outputShapeMismatch
313
+ }
314
+
315
+ let count = rowCount ?? (vectors.rows - rowStart)
316
+ guard rowStart >= 0 && count >= 0 && rowStart + count <= vectors.rows else {
317
+ throw NumKongMatrixError.rowWindowOutOfBounds
318
+ }
319
+
320
+ Element._nk_dots_symmetric(
321
+ vectors.baseAddress,
322
+ result.baseAddress,
323
+ vectors.rows,
324
+ vectors.cols,
325
+ vectors.rowStrideBytes,
326
+ result.rowStrideBytes,
327
+ rowStart,
328
+ count
329
+ )
330
+ }
331
+
332
+ // MARK: - Spatials Functions
333
+
334
+ /// Computes angular distances between each row of `a` and every row packed in `bPacked`.
335
+ @inlinable
336
+ public func angulars_packed<Element: NumKongSpatialsMatrixElement>(
337
+ _ a: MatrixView<Element>,
338
+ _ bPacked: PackedMatrix<Element>,
339
+ _ result: inout MatrixSpan<Element.SpatialOutput>
340
+ ) throws {
341
+ try _nkValidateMatrixView(a)
342
+ try _nkValidateMatrixSpan(result)
343
+
344
+ guard a.cols == bPacked.cols else { throw NumKongMatrixError.depthMismatch }
345
+ guard result.rows == a.rows && result.cols == bPacked.rows else {
346
+ throw NumKongMatrixError.outputShapeMismatch
347
+ }
348
+
349
+ Element._nk_angulars_packed(
350
+ a.baseAddress,
351
+ UnsafeRawPointer(bPacked.rawPointer),
352
+ result.baseAddress,
353
+ a.rows,
354
+ bPacked.rows,
355
+ a.cols,
356
+ a.rowStrideBytes,
357
+ result.rowStrideBytes
358
+ )
359
+ }
360
+
361
+ /// Computes Euclidean distances between each row of `a` and every row packed in `bPacked`.
362
+ @inlinable
363
+ public func euclideans_packed<Element: NumKongSpatialsMatrixElement>(
364
+ _ a: MatrixView<Element>,
365
+ _ bPacked: PackedMatrix<Element>,
366
+ _ result: inout MatrixSpan<Element.SpatialOutput>
367
+ ) throws {
368
+ try _nkValidateMatrixView(a)
369
+ try _nkValidateMatrixSpan(result)
370
+
371
+ guard a.cols == bPacked.cols else { throw NumKongMatrixError.depthMismatch }
372
+ guard result.rows == a.rows && result.cols == bPacked.rows else {
373
+ throw NumKongMatrixError.outputShapeMismatch
374
+ }
375
+
376
+ Element._nk_euclideans_packed(
377
+ a.baseAddress,
378
+ UnsafeRawPointer(bPacked.rawPointer),
379
+ result.baseAddress,
380
+ a.rows,
381
+ bPacked.rows,
382
+ a.cols,
383
+ a.rowStrideBytes,
384
+ result.rowStrideBytes
385
+ )
386
+ }
387
+
388
+ /// Computes the symmetric angular-distance matrix for all row pairs in `vectors`.
389
+ @inlinable
390
+ public func angulars_symmetric<Element: NumKongSpatialsMatrixElement>(
391
+ _ vectors: MatrixView<Element>,
392
+ _ result: inout MatrixSpan<Element.SpatialOutput>,
393
+ rowStart: Int = 0,
394
+ rowCount: Int? = nil
395
+ ) throws {
396
+ try _nkValidateMatrixView(vectors)
397
+ try _nkValidateMatrixSpan(result)
398
+
399
+ guard result.rows == vectors.rows && result.cols == vectors.rows else {
400
+ throw NumKongMatrixError.outputShapeMismatch
401
+ }
402
+
403
+ let count = rowCount ?? (vectors.rows - rowStart)
404
+ guard rowStart >= 0 && count >= 0 && rowStart + count <= vectors.rows else {
405
+ throw NumKongMatrixError.rowWindowOutOfBounds
406
+ }
407
+
408
+ Element._nk_angulars_symmetric(
409
+ vectors.baseAddress,
410
+ result.baseAddress,
411
+ vectors.rows,
412
+ vectors.cols,
413
+ vectors.rowStrideBytes,
414
+ result.rowStrideBytes,
415
+ rowStart,
416
+ count
417
+ )
418
+ }
419
+
420
+ /// Computes the symmetric Euclidean-distance matrix for all row pairs in `vectors`.
421
+ @inlinable
422
+ public func euclideans_symmetric<Element: NumKongSpatialsMatrixElement>(
423
+ _ vectors: MatrixView<Element>,
424
+ _ result: inout MatrixSpan<Element.SpatialOutput>,
425
+ rowStart: Int = 0,
426
+ rowCount: Int? = nil
427
+ ) throws {
428
+ try _nkValidateMatrixView(vectors)
429
+ try _nkValidateMatrixSpan(result)
430
+
431
+ guard result.rows == vectors.rows && result.cols == vectors.rows else {
432
+ throw NumKongMatrixError.outputShapeMismatch
433
+ }
434
+
435
+ let count = rowCount ?? (vectors.rows - rowStart)
436
+ guard rowStart >= 0 && count >= 0 && rowStart + count <= vectors.rows else {
437
+ throw NumKongMatrixError.rowWindowOutOfBounds
438
+ }
439
+
440
+ Element._nk_euclideans_symmetric(
441
+ vectors.baseAddress,
442
+ result.baseAddress,
443
+ vectors.rows,
444
+ vectors.cols,
445
+ vectors.rowStrideBytes,
446
+ result.rowStrideBytes,
447
+ rowStart,
448
+ count
449
+ )
450
+ }
451
+
452
+ // MARK: - Sets Functions
453
+
454
+ /// Computes Hamming distances between each row of `a` and every row packed in `bPacked`.
455
+ @inlinable
456
+ public func hammings_packed<Element: NumKongSetsMatrixElement>(
457
+ _ a: MatrixView<Element>,
458
+ _ bPacked: PackedMatrix<Element>,
459
+ _ result: inout MatrixSpan<Element.HammingOutput>
460
+ ) throws {
461
+ try _nkValidateMatrixView(a)
462
+ try _nkValidateMatrixSpan(result)
463
+
464
+ guard a.cols == bPacked.cols else { throw NumKongMatrixError.depthMismatch }
465
+ guard result.rows == a.rows && result.cols == bPacked.rows else {
466
+ throw NumKongMatrixError.outputShapeMismatch
467
+ }
468
+
469
+ Element._nk_hammings_packed(
470
+ a.baseAddress,
471
+ UnsafeRawPointer(bPacked.rawPointer),
472
+ result.baseAddress,
473
+ a.rows,
474
+ bPacked.rows,
475
+ a.cols,
476
+ a.rowStrideBytes,
477
+ result.rowStrideBytes
478
+ )
479
+ }
480
+
481
+ /// Computes the symmetric Hamming-distance matrix for all row pairs in `vectors`.
482
+ @inlinable
483
+ public func hammings_symmetric<Element: NumKongSetsMatrixElement>(
484
+ _ vectors: MatrixView<Element>,
485
+ _ result: inout MatrixSpan<Element.HammingOutput>,
486
+ rowStart: Int = 0,
487
+ rowCount: Int? = nil
488
+ ) throws {
489
+ try _nkValidateMatrixView(vectors)
490
+ try _nkValidateMatrixSpan(result)
491
+
492
+ guard result.rows == vectors.rows && result.cols == vectors.rows else {
493
+ throw NumKongMatrixError.outputShapeMismatch
494
+ }
495
+
496
+ let count = rowCount ?? (vectors.rows - rowStart)
497
+ guard rowStart >= 0 && count >= 0 && rowStart + count <= vectors.rows else {
498
+ throw NumKongMatrixError.rowWindowOutOfBounds
499
+ }
500
+
501
+ Element._nk_hammings_symmetric(
502
+ vectors.baseAddress,
503
+ result.baseAddress,
504
+ vectors.rows,
505
+ vectors.cols,
506
+ vectors.rowStrideBytes,
507
+ result.rowStrideBytes,
508
+ rowStart,
509
+ count
510
+ )
511
+ }
512
+
513
+ /// Computes Jaccard distances between each row of `a` and every row packed in `bPacked`.
514
+ @inlinable
515
+ public func jaccards_packed<Element: NumKongSetsMatrixElement>(
516
+ _ a: MatrixView<Element>,
517
+ _ bPacked: PackedMatrix<Element>,
518
+ _ result: inout MatrixSpan<Element.JaccardOutput>
519
+ ) throws {
520
+ try _nkValidateMatrixView(a)
521
+ try _nkValidateMatrixSpan(result)
522
+
523
+ guard a.cols == bPacked.cols else { throw NumKongMatrixError.depthMismatch }
524
+ guard result.rows == a.rows && result.cols == bPacked.rows else {
525
+ throw NumKongMatrixError.outputShapeMismatch
526
+ }
527
+
528
+ Element._nk_jaccards_packed(
529
+ a.baseAddress,
530
+ UnsafeRawPointer(bPacked.rawPointer),
531
+ result.baseAddress,
532
+ a.rows,
533
+ bPacked.rows,
534
+ a.cols,
535
+ a.rowStrideBytes,
536
+ result.rowStrideBytes
537
+ )
538
+ }
539
+
540
+ /// Computes the symmetric Jaccard-distance matrix for all row pairs in `vectors`.
541
+ @inlinable
542
+ public func jaccards_symmetric<Element: NumKongSetsMatrixElement>(
543
+ _ vectors: MatrixView<Element>,
544
+ _ result: inout MatrixSpan<Element.JaccardOutput>,
545
+ rowStart: Int = 0,
546
+ rowCount: Int? = nil
547
+ ) throws {
548
+ try _nkValidateMatrixView(vectors)
549
+ try _nkValidateMatrixSpan(result)
550
+
551
+ guard result.rows == vectors.rows && result.cols == vectors.rows else {
552
+ throw NumKongMatrixError.outputShapeMismatch
553
+ }
554
+
555
+ let count = rowCount ?? (vectors.rows - rowStart)
556
+ guard rowStart >= 0 && count >= 0 && rowStart + count <= vectors.rows else {
557
+ throw NumKongMatrixError.rowWindowOutOfBounds
558
+ }
559
+
560
+ Element._nk_jaccards_symmetric(
561
+ vectors.baseAddress,
562
+ result.baseAddress,
563
+ vectors.rows,
564
+ vectors.cols,
565
+ vectors.rowStrideBytes,
566
+ result.rowStrideBytes,
567
+ rowStart,
568
+ count
569
+ )
570
+ }
571
+
572
+ // MARK: - Kernel Bindings: Float32
573
+
574
+ extension Float32: NumKongDotsMatrixElement {
575
+ public typealias DotsOutput = Float64
576
+
577
+ public static func _nk_dots_packed_size(_ n: Int, _ k: Int) -> Int {
578
+ Int(nk_dots_packed_size_f32(UInt64(n), UInt64(k)))
579
+ }
580
+
581
+ public static func _nk_dots_pack(
582
+ _ b: UnsafePointer<Float32>, _ n: Int, _ k: Int, _ bStride: Int, _ packed: UnsafeMutableRawPointer
583
+ ) {
584
+ nk_dots_pack_f32(b, UInt64(n), UInt64(k), UInt64(bStride), packed)
585
+ }
586
+
587
+ public static func _nk_dots_packed(
588
+ _ a: UnsafePointer<Float32>, _ bPacked: UnsafeRawPointer, _ c: UnsafeMutablePointer<Float64>, _ m: Int,
589
+ _ n: Int, _ k: Int, _ aStride: Int, _ cStride: Int
590
+ ) {
591
+ nk_dots_packed_f32(a, bPacked, c, UInt64(m), UInt64(n), UInt64(k), UInt64(aStride), UInt64(cStride))
592
+ }
593
+
594
+ public static func _nk_dots_symmetric(
595
+ _ vectors: UnsafePointer<Float32>, _ result: UnsafeMutablePointer<Float64>, _ nVectors: Int, _ depth: Int,
596
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
597
+ ) {
598
+ nk_dots_symmetric_f32(
599
+ vectors, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
600
+ UInt64(rowCount))
601
+ }
602
+ }
603
+
604
+ extension Float32: NumKongSpatialsMatrixElement {
605
+ public typealias SpatialOutput = Float64
606
+
607
+ public static func _nk_angulars_packed(
608
+ _ a: UnsafePointer<Float32>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float64>, _ rows: Int,
609
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
610
+ ) {
611
+ nk_angulars_packed_f32(
612
+ a, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
613
+ }
614
+
615
+ public static func _nk_euclideans_packed(
616
+ _ a: UnsafePointer<Float32>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float64>, _ rows: Int,
617
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
618
+ ) {
619
+ nk_euclideans_packed_f32(
620
+ a, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
621
+ }
622
+
623
+ public static func _nk_angulars_symmetric(
624
+ _ vectors: UnsafePointer<Float32>, _ result: UnsafeMutablePointer<Float64>, _ nVectors: Int, _ depth: Int,
625
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
626
+ ) {
627
+ nk_angulars_symmetric_f32(
628
+ vectors, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
629
+ UInt64(rowCount))
630
+ }
631
+
632
+ public static func _nk_euclideans_symmetric(
633
+ _ vectors: UnsafePointer<Float32>, _ result: UnsafeMutablePointer<Float64>, _ nVectors: Int, _ depth: Int,
634
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
635
+ ) {
636
+ nk_euclideans_symmetric_f32(
637
+ vectors, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
638
+ UInt64(rowCount))
639
+ }
640
+ }
641
+
642
+ // MARK: - Kernel Bindings: Float64
643
+
644
+ extension Float64: NumKongDotsMatrixElement {
645
+ public typealias DotsOutput = Float64
646
+
647
+ public static func _nk_dots_packed_size(_ n: Int, _ k: Int) -> Int {
648
+ Int(nk_dots_packed_size_f64(UInt64(n), UInt64(k)))
649
+ }
650
+
651
+ public static func _nk_dots_pack(
652
+ _ b: UnsafePointer<Float64>, _ n: Int, _ k: Int, _ bStride: Int, _ packed: UnsafeMutableRawPointer
653
+ ) {
654
+ nk_dots_pack_f64(b, UInt64(n), UInt64(k), UInt64(bStride), packed)
655
+ }
656
+
657
+ public static func _nk_dots_packed(
658
+ _ a: UnsafePointer<Float64>, _ bPacked: UnsafeRawPointer, _ c: UnsafeMutablePointer<Float64>, _ m: Int,
659
+ _ n: Int, _ k: Int, _ aStride: Int, _ cStride: Int
660
+ ) {
661
+ nk_dots_packed_f64(a, bPacked, c, UInt64(m), UInt64(n), UInt64(k), UInt64(aStride), UInt64(cStride))
662
+ }
663
+
664
+ public static func _nk_dots_symmetric(
665
+ _ vectors: UnsafePointer<Float64>, _ result: UnsafeMutablePointer<Float64>, _ nVectors: Int, _ depth: Int,
666
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
667
+ ) {
668
+ nk_dots_symmetric_f64(
669
+ vectors, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
670
+ UInt64(rowCount))
671
+ }
672
+ }
673
+
674
+ extension Float64: NumKongSpatialsMatrixElement {
675
+ public typealias SpatialOutput = Float64
676
+
677
+ public static func _nk_angulars_packed(
678
+ _ a: UnsafePointer<Float64>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float64>, _ rows: Int,
679
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
680
+ ) {
681
+ nk_angulars_packed_f64(
682
+ a, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
683
+ }
684
+
685
+ public static func _nk_euclideans_packed(
686
+ _ a: UnsafePointer<Float64>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float64>, _ rows: Int,
687
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
688
+ ) {
689
+ nk_euclideans_packed_f64(
690
+ a, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
691
+ }
692
+
693
+ public static func _nk_angulars_symmetric(
694
+ _ vectors: UnsafePointer<Float64>, _ result: UnsafeMutablePointer<Float64>, _ nVectors: Int, _ depth: Int,
695
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
696
+ ) {
697
+ nk_angulars_symmetric_f64(
698
+ vectors, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
699
+ UInt64(rowCount))
700
+ }
701
+
702
+ public static func _nk_euclideans_symmetric(
703
+ _ vectors: UnsafePointer<Float64>, _ result: UnsafeMutablePointer<Float64>, _ nVectors: Int, _ depth: Int,
704
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
705
+ ) {
706
+ nk_euclideans_symmetric_f64(
707
+ vectors, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
708
+ UInt64(rowCount))
709
+ }
710
+ }
711
+
712
+ // MARK: - Kernel Bindings: Int8
713
+
714
+ extension Int8: NumKongDotsMatrixElement {
715
+ public typealias DotsOutput = Int32
716
+
717
+ public static func _nk_dots_packed_size(_ n: Int, _ k: Int) -> Int {
718
+ Int(nk_dots_packed_size_i8(UInt64(n), UInt64(k)))
719
+ }
720
+
721
+ public static func _nk_dots_pack(
722
+ _ b: UnsafePointer<Int8>, _ n: Int, _ k: Int, _ bStride: Int, _ packed: UnsafeMutableRawPointer
723
+ ) {
724
+ nk_dots_pack_i8(b, UInt64(n), UInt64(k), UInt64(bStride), packed)
725
+ }
726
+
727
+ public static func _nk_dots_packed(
728
+ _ a: UnsafePointer<Int8>, _ bPacked: UnsafeRawPointer, _ c: UnsafeMutablePointer<Int32>, _ m: Int, _ n: Int,
729
+ _ k: Int, _ aStride: Int, _ cStride: Int
730
+ ) {
731
+ nk_dots_packed_i8(a, bPacked, c, UInt64(m), UInt64(n), UInt64(k), UInt64(aStride), UInt64(cStride))
732
+ }
733
+
734
+ public static func _nk_dots_symmetric(
735
+ _ vectors: UnsafePointer<Int8>, _ result: UnsafeMutablePointer<Int32>, _ nVectors: Int, _ depth: Int,
736
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
737
+ ) {
738
+ nk_dots_symmetric_i8(
739
+ vectors, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
740
+ UInt64(rowCount))
741
+ }
742
+ }
743
+
744
+ extension Int8: NumKongSpatialsMatrixElement {
745
+ public typealias SpatialOutput = Float32
746
+
747
+ public static func _nk_angulars_packed(
748
+ _ a: UnsafePointer<Int8>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float32>, _ rows: Int,
749
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
750
+ ) {
751
+ nk_angulars_packed_i8(
752
+ a, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
753
+ }
754
+
755
+ public static func _nk_euclideans_packed(
756
+ _ a: UnsafePointer<Int8>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float32>, _ rows: Int,
757
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
758
+ ) {
759
+ nk_euclideans_packed_i8(
760
+ a, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
761
+ }
762
+
763
+ public static func _nk_angulars_symmetric(
764
+ _ vectors: UnsafePointer<Int8>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
765
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
766
+ ) {
767
+ nk_angulars_symmetric_i8(
768
+ vectors, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
769
+ UInt64(rowCount))
770
+ }
771
+
772
+ public static func _nk_euclideans_symmetric(
773
+ _ vectors: UnsafePointer<Int8>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
774
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
775
+ ) {
776
+ nk_euclideans_symmetric_i8(
777
+ vectors, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
778
+ UInt64(rowCount))
779
+ }
780
+ }
781
+
782
+ // MARK: - Kernel Bindings: UInt8
783
+
784
+ extension UInt8: NumKongDotsMatrixElement {
785
+ public typealias DotsOutput = UInt32
786
+
787
+ public static func _nk_dots_packed_size(_ n: Int, _ k: Int) -> Int {
788
+ Int(nk_dots_packed_size_u8(UInt64(n), UInt64(k)))
789
+ }
790
+
791
+ public static func _nk_dots_pack(
792
+ _ b: UnsafePointer<UInt8>, _ n: Int, _ k: Int, _ bStride: Int, _ packed: UnsafeMutableRawPointer
793
+ ) {
794
+ nk_dots_pack_u8(b, UInt64(n), UInt64(k), UInt64(bStride), packed)
795
+ }
796
+
797
+ public static func _nk_dots_packed(
798
+ _ a: UnsafePointer<UInt8>, _ bPacked: UnsafeRawPointer, _ c: UnsafeMutablePointer<UInt32>, _ m: Int, _ n: Int,
799
+ _ k: Int, _ aStride: Int, _ cStride: Int
800
+ ) {
801
+ nk_dots_packed_u8(a, bPacked, c, UInt64(m), UInt64(n), UInt64(k), UInt64(aStride), UInt64(cStride))
802
+ }
803
+
804
+ public static func _nk_dots_symmetric(
805
+ _ vectors: UnsafePointer<UInt8>, _ result: UnsafeMutablePointer<UInt32>, _ nVectors: Int, _ depth: Int,
806
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
807
+ ) {
808
+ nk_dots_symmetric_u8(
809
+ vectors, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
810
+ UInt64(rowCount))
811
+ }
812
+ }
813
+
814
+ extension UInt8: NumKongSpatialsMatrixElement {
815
+ public typealias SpatialOutput = Float32
816
+
817
+ public static func _nk_angulars_packed(
818
+ _ a: UnsafePointer<UInt8>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float32>, _ rows: Int,
819
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
820
+ ) {
821
+ nk_angulars_packed_u8(
822
+ a, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
823
+ }
824
+
825
+ public static func _nk_euclideans_packed(
826
+ _ a: UnsafePointer<UInt8>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float32>, _ rows: Int,
827
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
828
+ ) {
829
+ nk_euclideans_packed_u8(
830
+ a, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
831
+ }
832
+
833
+ public static func _nk_angulars_symmetric(
834
+ _ vectors: UnsafePointer<UInt8>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
835
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
836
+ ) {
837
+ nk_angulars_symmetric_u8(
838
+ vectors, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
839
+ UInt64(rowCount))
840
+ }
841
+
842
+ public static func _nk_euclideans_symmetric(
843
+ _ vectors: UnsafePointer<UInt8>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
844
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
845
+ ) {
846
+ nk_euclideans_symmetric_u8(
847
+ vectors, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
848
+ UInt64(rowCount))
849
+ }
850
+ }
851
+
852
+ // MARK: - Kernel Bindings: Float16
853
+
854
+ #if !arch(x86_64)
855
+ @available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
856
+ extension Float16: NumKongDotsMatrixElement {
857
+ public typealias DotsOutput = Float32
858
+
859
+ public static func _nk_dots_packed_size(_ n: Int, _ k: Int) -> Int {
860
+ Int(nk_dots_packed_size_f16(UInt64(n), UInt64(k)))
861
+ }
862
+
863
+ public static func _nk_dots_pack(
864
+ _ b: UnsafePointer<Float16>, _ n: Int, _ k: Int, _ bStride: Int, _ packed: UnsafeMutableRawPointer
865
+ ) {
866
+ let cPtr = UnsafeRawPointer(b).assumingMemoryBound(to: nk_f16_t.self)
867
+ nk_dots_pack_f16(cPtr, UInt64(n), UInt64(k), UInt64(bStride), packed)
868
+ }
869
+
870
+ public static func _nk_dots_packed(
871
+ _ a: UnsafePointer<Float16>, _ bPacked: UnsafeRawPointer, _ c: UnsafeMutablePointer<Float32>, _ m: Int,
872
+ _ n: Int, _ k: Int, _ aStride: Int, _ cStride: Int
873
+ ) {
874
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_f16_t.self)
875
+ nk_dots_packed_f16(cPtr, bPacked, c, UInt64(m), UInt64(n), UInt64(k), UInt64(aStride), UInt64(cStride))
876
+ }
877
+
878
+ public static func _nk_dots_symmetric(
879
+ _ vectors: UnsafePointer<Float16>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
880
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
881
+ ) {
882
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_f16_t.self)
883
+ nk_dots_symmetric_f16(
884
+ cPtr, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
885
+ UInt64(rowCount))
886
+ }
887
+ }
888
+
889
+ @available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
890
+ extension Float16: NumKongSpatialsMatrixElement {
891
+ public typealias SpatialOutput = Float32
892
+
893
+ public static func _nk_angulars_packed(
894
+ _ a: UnsafePointer<Float16>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float32>, _ rows: Int,
895
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
896
+ ) {
897
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_f16_t.self)
898
+ nk_angulars_packed_f16(
899
+ cPtr, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
900
+ }
901
+
902
+ public static func _nk_euclideans_packed(
903
+ _ a: UnsafePointer<Float16>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float32>, _ rows: Int,
904
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
905
+ ) {
906
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_f16_t.self)
907
+ nk_euclideans_packed_f16(
908
+ cPtr, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
909
+ }
910
+
911
+ public static func _nk_angulars_symmetric(
912
+ _ vectors: UnsafePointer<Float16>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
913
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
914
+ ) {
915
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_f16_t.self)
916
+ nk_angulars_symmetric_f16(
917
+ cPtr, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
918
+ UInt64(rowCount))
919
+ }
920
+
921
+ public static func _nk_euclideans_symmetric(
922
+ _ vectors: UnsafePointer<Float16>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
923
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
924
+ ) {
925
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_f16_t.self)
926
+ nk_euclideans_symmetric_f16(
927
+ cPtr, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
928
+ UInt64(rowCount))
929
+ }
930
+ }
931
+ #endif
932
+
933
+ // MARK: - Kernel Bindings: Minifloats
934
+
935
+ extension BFloat16: NumKongDotsMatrixElement {
936
+ public typealias DotsOutput = Float32
937
+
938
+ public static func _nk_dots_packed_size(_ n: Int, _ k: Int) -> Int {
939
+ Int(nk_dots_packed_size_bf16(UInt64(n), UInt64(k)))
940
+ }
941
+
942
+ public static func _nk_dots_pack(
943
+ _ b: UnsafePointer<BFloat16>, _ n: Int, _ k: Int, _ bStride: Int, _ packed: UnsafeMutableRawPointer
944
+ ) {
945
+ let cPtr = UnsafeRawPointer(b).assumingMemoryBound(to: nk_bf16_t.self)
946
+ nk_dots_pack_bf16(cPtr, UInt64(n), UInt64(k), UInt64(bStride), packed)
947
+ }
948
+
949
+ public static func _nk_dots_packed(
950
+ _ a: UnsafePointer<BFloat16>, _ bPacked: UnsafeRawPointer, _ c: UnsafeMutablePointer<Float32>, _ m: Int,
951
+ _ n: Int, _ k: Int, _ aStride: Int, _ cStride: Int
952
+ ) {
953
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_bf16_t.self)
954
+ nk_dots_packed_bf16(cPtr, bPacked, c, UInt64(m), UInt64(n), UInt64(k), UInt64(aStride), UInt64(cStride))
955
+ }
956
+
957
+ public static func _nk_dots_symmetric(
958
+ _ vectors: UnsafePointer<BFloat16>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
959
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
960
+ ) {
961
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_bf16_t.self)
962
+ nk_dots_symmetric_bf16(
963
+ cPtr, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
964
+ UInt64(rowCount))
965
+ }
966
+ }
967
+
968
+ extension BFloat16: NumKongSpatialsMatrixElement {
969
+ public typealias SpatialOutput = Float32
970
+
971
+ public static func _nk_angulars_packed(
972
+ _ a: UnsafePointer<BFloat16>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float32>, _ rows: Int,
973
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
974
+ ) {
975
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_bf16_t.self)
976
+ nk_angulars_packed_bf16(
977
+ cPtr, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
978
+ }
979
+
980
+ public static func _nk_euclideans_packed(
981
+ _ a: UnsafePointer<BFloat16>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float32>, _ rows: Int,
982
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
983
+ ) {
984
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_bf16_t.self)
985
+ nk_euclideans_packed_bf16(
986
+ cPtr, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
987
+ }
988
+
989
+ public static func _nk_angulars_symmetric(
990
+ _ vectors: UnsafePointer<BFloat16>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
991
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
992
+ ) {
993
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_bf16_t.self)
994
+ nk_angulars_symmetric_bf16(
995
+ cPtr, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
996
+ UInt64(rowCount))
997
+ }
998
+
999
+ public static func _nk_euclideans_symmetric(
1000
+ _ vectors: UnsafePointer<BFloat16>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
1001
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
1002
+ ) {
1003
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_bf16_t.self)
1004
+ nk_euclideans_symmetric_bf16(
1005
+ cPtr, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
1006
+ UInt64(rowCount))
1007
+ }
1008
+ }
1009
+
1010
+ extension E4M3: NumKongDotsMatrixElement {
1011
+ public typealias DotsOutput = Float32
1012
+
1013
+ public static func _nk_dots_packed_size(_ n: Int, _ k: Int) -> Int {
1014
+ Int(nk_dots_packed_size_e4m3(UInt64(n), UInt64(k)))
1015
+ }
1016
+
1017
+ public static func _nk_dots_pack(
1018
+ _ b: UnsafePointer<E4M3>, _ n: Int, _ k: Int, _ bStride: Int, _ packed: UnsafeMutableRawPointer
1019
+ ) {
1020
+ let cPtr = UnsafeRawPointer(b).assumingMemoryBound(to: nk_e4m3_t.self)
1021
+ nk_dots_pack_e4m3(cPtr, UInt64(n), UInt64(k), UInt64(bStride), packed)
1022
+ }
1023
+
1024
+ public static func _nk_dots_packed(
1025
+ _ a: UnsafePointer<E4M3>, _ bPacked: UnsafeRawPointer, _ c: UnsafeMutablePointer<Float32>, _ m: Int, _ n: Int,
1026
+ _ k: Int, _ aStride: Int, _ cStride: Int
1027
+ ) {
1028
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_e4m3_t.self)
1029
+ nk_dots_packed_e4m3(cPtr, bPacked, c, UInt64(m), UInt64(n), UInt64(k), UInt64(aStride), UInt64(cStride))
1030
+ }
1031
+
1032
+ public static func _nk_dots_symmetric(
1033
+ _ vectors: UnsafePointer<E4M3>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
1034
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
1035
+ ) {
1036
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_e4m3_t.self)
1037
+ nk_dots_symmetric_e4m3(
1038
+ cPtr, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
1039
+ UInt64(rowCount))
1040
+ }
1041
+ }
1042
+
1043
+ extension E4M3: NumKongSpatialsMatrixElement {
1044
+ public typealias SpatialOutput = Float32
1045
+
1046
+ public static func _nk_angulars_packed(
1047
+ _ a: UnsafePointer<E4M3>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float32>, _ rows: Int,
1048
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
1049
+ ) {
1050
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_e4m3_t.self)
1051
+ nk_angulars_packed_e4m3(
1052
+ cPtr, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
1053
+ }
1054
+
1055
+ public static func _nk_euclideans_packed(
1056
+ _ a: UnsafePointer<E4M3>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float32>, _ rows: Int,
1057
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
1058
+ ) {
1059
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_e4m3_t.self)
1060
+ nk_euclideans_packed_e4m3(
1061
+ cPtr, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
1062
+ }
1063
+
1064
+ public static func _nk_angulars_symmetric(
1065
+ _ vectors: UnsafePointer<E4M3>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
1066
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
1067
+ ) {
1068
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_e4m3_t.self)
1069
+ nk_angulars_symmetric_e4m3(
1070
+ cPtr, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
1071
+ UInt64(rowCount))
1072
+ }
1073
+
1074
+ public static func _nk_euclideans_symmetric(
1075
+ _ vectors: UnsafePointer<E4M3>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
1076
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
1077
+ ) {
1078
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_e4m3_t.self)
1079
+ nk_euclideans_symmetric_e4m3(
1080
+ cPtr, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
1081
+ UInt64(rowCount))
1082
+ }
1083
+ }
1084
+
1085
+ extension E5M2: NumKongDotsMatrixElement {
1086
+ public typealias DotsOutput = Float32
1087
+
1088
+ public static func _nk_dots_packed_size(_ n: Int, _ k: Int) -> Int {
1089
+ Int(nk_dots_packed_size_e5m2(UInt64(n), UInt64(k)))
1090
+ }
1091
+
1092
+ public static func _nk_dots_pack(
1093
+ _ b: UnsafePointer<E5M2>, _ n: Int, _ k: Int, _ bStride: Int, _ packed: UnsafeMutableRawPointer
1094
+ ) {
1095
+ let cPtr = UnsafeRawPointer(b).assumingMemoryBound(to: nk_e5m2_t.self)
1096
+ nk_dots_pack_e5m2(cPtr, UInt64(n), UInt64(k), UInt64(bStride), packed)
1097
+ }
1098
+
1099
+ public static func _nk_dots_packed(
1100
+ _ a: UnsafePointer<E5M2>, _ bPacked: UnsafeRawPointer, _ c: UnsafeMutablePointer<Float32>, _ m: Int, _ n: Int,
1101
+ _ k: Int, _ aStride: Int, _ cStride: Int
1102
+ ) {
1103
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_e5m2_t.self)
1104
+ nk_dots_packed_e5m2(cPtr, bPacked, c, UInt64(m), UInt64(n), UInt64(k), UInt64(aStride), UInt64(cStride))
1105
+ }
1106
+
1107
+ public static func _nk_dots_symmetric(
1108
+ _ vectors: UnsafePointer<E5M2>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
1109
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
1110
+ ) {
1111
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_e5m2_t.self)
1112
+ nk_dots_symmetric_e5m2(
1113
+ cPtr, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
1114
+ UInt64(rowCount))
1115
+ }
1116
+ }
1117
+
1118
+ extension E5M2: NumKongSpatialsMatrixElement {
1119
+ public typealias SpatialOutput = Float32
1120
+
1121
+ public static func _nk_angulars_packed(
1122
+ _ a: UnsafePointer<E5M2>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float32>, _ rows: Int,
1123
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
1124
+ ) {
1125
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_e5m2_t.self)
1126
+ nk_angulars_packed_e5m2(
1127
+ cPtr, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
1128
+ }
1129
+
1130
+ public static func _nk_euclideans_packed(
1131
+ _ a: UnsafePointer<E5M2>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float32>, _ rows: Int,
1132
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
1133
+ ) {
1134
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_e5m2_t.self)
1135
+ nk_euclideans_packed_e5m2(
1136
+ cPtr, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
1137
+ }
1138
+
1139
+ public static func _nk_angulars_symmetric(
1140
+ _ vectors: UnsafePointer<E5M2>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
1141
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
1142
+ ) {
1143
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_e5m2_t.self)
1144
+ nk_angulars_symmetric_e5m2(
1145
+ cPtr, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
1146
+ UInt64(rowCount))
1147
+ }
1148
+
1149
+ public static func _nk_euclideans_symmetric(
1150
+ _ vectors: UnsafePointer<E5M2>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
1151
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
1152
+ ) {
1153
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_e5m2_t.self)
1154
+ nk_euclideans_symmetric_e5m2(
1155
+ cPtr, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
1156
+ UInt64(rowCount))
1157
+ }
1158
+ }
1159
+
1160
+ extension E2M3: NumKongDotsMatrixElement {
1161
+ public typealias DotsOutput = Float32
1162
+
1163
+ public static func _nk_dots_packed_size(_ n: Int, _ k: Int) -> Int {
1164
+ Int(nk_dots_packed_size_e2m3(UInt64(n), UInt64(k)))
1165
+ }
1166
+
1167
+ public static func _nk_dots_pack(
1168
+ _ b: UnsafePointer<E2M3>, _ n: Int, _ k: Int, _ bStride: Int, _ packed: UnsafeMutableRawPointer
1169
+ ) {
1170
+ let cPtr = UnsafeRawPointer(b).assumingMemoryBound(to: nk_e2m3_t.self)
1171
+ nk_dots_pack_e2m3(cPtr, UInt64(n), UInt64(k), UInt64(bStride), packed)
1172
+ }
1173
+
1174
+ public static func _nk_dots_packed(
1175
+ _ a: UnsafePointer<E2M3>, _ bPacked: UnsafeRawPointer, _ c: UnsafeMutablePointer<Float32>, _ m: Int, _ n: Int,
1176
+ _ k: Int, _ aStride: Int, _ cStride: Int
1177
+ ) {
1178
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_e2m3_t.self)
1179
+ nk_dots_packed_e2m3(cPtr, bPacked, c, UInt64(m), UInt64(n), UInt64(k), UInt64(aStride), UInt64(cStride))
1180
+ }
1181
+
1182
+ public static func _nk_dots_symmetric(
1183
+ _ vectors: UnsafePointer<E2M3>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
1184
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
1185
+ ) {
1186
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_e2m3_t.self)
1187
+ nk_dots_symmetric_e2m3(
1188
+ cPtr, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
1189
+ UInt64(rowCount))
1190
+ }
1191
+ }
1192
+
1193
+ extension E2M3: NumKongSpatialsMatrixElement {
1194
+ public typealias SpatialOutput = Float32
1195
+
1196
+ public static func _nk_angulars_packed(
1197
+ _ a: UnsafePointer<E2M3>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float32>, _ rows: Int,
1198
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
1199
+ ) {
1200
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_e2m3_t.self)
1201
+ nk_angulars_packed_e2m3(
1202
+ cPtr, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
1203
+ }
1204
+
1205
+ public static func _nk_euclideans_packed(
1206
+ _ a: UnsafePointer<E2M3>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float32>, _ rows: Int,
1207
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
1208
+ ) {
1209
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_e2m3_t.self)
1210
+ nk_euclideans_packed_e2m3(
1211
+ cPtr, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
1212
+ }
1213
+
1214
+ public static func _nk_angulars_symmetric(
1215
+ _ vectors: UnsafePointer<E2M3>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
1216
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
1217
+ ) {
1218
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_e2m3_t.self)
1219
+ nk_angulars_symmetric_e2m3(
1220
+ cPtr, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
1221
+ UInt64(rowCount))
1222
+ }
1223
+
1224
+ public static func _nk_euclideans_symmetric(
1225
+ _ vectors: UnsafePointer<E2M3>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
1226
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
1227
+ ) {
1228
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_e2m3_t.self)
1229
+ nk_euclideans_symmetric_e2m3(
1230
+ cPtr, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
1231
+ UInt64(rowCount))
1232
+ }
1233
+ }
1234
+
1235
+ extension E3M2: NumKongDotsMatrixElement {
1236
+ public typealias DotsOutput = Float32
1237
+
1238
+ public static func _nk_dots_packed_size(_ n: Int, _ k: Int) -> Int {
1239
+ Int(nk_dots_packed_size_e3m2(UInt64(n), UInt64(k)))
1240
+ }
1241
+
1242
+ public static func _nk_dots_pack(
1243
+ _ b: UnsafePointer<E3M2>, _ n: Int, _ k: Int, _ bStride: Int, _ packed: UnsafeMutableRawPointer
1244
+ ) {
1245
+ let cPtr = UnsafeRawPointer(b).assumingMemoryBound(to: nk_e3m2_t.self)
1246
+ nk_dots_pack_e3m2(cPtr, UInt64(n), UInt64(k), UInt64(bStride), packed)
1247
+ }
1248
+
1249
+ public static func _nk_dots_packed(
1250
+ _ a: UnsafePointer<E3M2>, _ bPacked: UnsafeRawPointer, _ c: UnsafeMutablePointer<Float32>, _ m: Int, _ n: Int,
1251
+ _ k: Int, _ aStride: Int, _ cStride: Int
1252
+ ) {
1253
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_e3m2_t.self)
1254
+ nk_dots_packed_e3m2(cPtr, bPacked, c, UInt64(m), UInt64(n), UInt64(k), UInt64(aStride), UInt64(cStride))
1255
+ }
1256
+
1257
+ public static func _nk_dots_symmetric(
1258
+ _ vectors: UnsafePointer<E3M2>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
1259
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
1260
+ ) {
1261
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_e3m2_t.self)
1262
+ nk_dots_symmetric_e3m2(
1263
+ cPtr, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
1264
+ UInt64(rowCount))
1265
+ }
1266
+ }
1267
+
1268
+ extension E3M2: NumKongSpatialsMatrixElement {
1269
+ public typealias SpatialOutput = Float32
1270
+
1271
+ public static func _nk_angulars_packed(
1272
+ _ a: UnsafePointer<E3M2>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float32>, _ rows: Int,
1273
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
1274
+ ) {
1275
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_e3m2_t.self)
1276
+ nk_angulars_packed_e3m2(
1277
+ cPtr, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
1278
+ }
1279
+
1280
+ public static func _nk_euclideans_packed(
1281
+ _ a: UnsafePointer<E3M2>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float32>, _ rows: Int,
1282
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
1283
+ ) {
1284
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_e3m2_t.self)
1285
+ nk_euclideans_packed_e3m2(
1286
+ cPtr, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth), UInt64(aStride), UInt64(rStride))
1287
+ }
1288
+
1289
+ public static func _nk_angulars_symmetric(
1290
+ _ vectors: UnsafePointer<E3M2>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
1291
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
1292
+ ) {
1293
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_e3m2_t.self)
1294
+ nk_angulars_symmetric_e3m2(
1295
+ cPtr, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
1296
+ UInt64(rowCount))
1297
+ }
1298
+
1299
+ public static func _nk_euclideans_symmetric(
1300
+ _ vectors: UnsafePointer<E3M2>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
1301
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
1302
+ ) {
1303
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_e3m2_t.self)
1304
+ nk_euclideans_symmetric_e3m2(
1305
+ cPtr, UInt64(nVectors), UInt64(depth), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
1306
+ UInt64(rowCount))
1307
+ }
1308
+ }
1309
+
1310
+ // MARK: - Kernel Bindings: U1x8 Dots
1311
+
1312
+ extension U1x8: NumKongDotsMatrixElement {
1313
+ public typealias DotsOutput = UInt32
1314
+
1315
+ public static func _nk_dots_packed_size(_ n: Int, _ k: Int) -> Int {
1316
+ Int(nk_dots_packed_size_u1(UInt64(n), UInt64(k * 8)))
1317
+ }
1318
+
1319
+ public static func _nk_dots_pack(
1320
+ _ b: UnsafePointer<U1x8>, _ n: Int, _ k: Int, _ bStride: Int, _ packed: UnsafeMutableRawPointer
1321
+ ) {
1322
+ let cPtr = UnsafeRawPointer(b).assumingMemoryBound(to: nk_u1x8_t.self)
1323
+ nk_dots_pack_u1(cPtr, UInt64(n), UInt64(k * 8), UInt64(bStride), packed)
1324
+ }
1325
+
1326
+ public static func _nk_dots_packed(
1327
+ _ a: UnsafePointer<U1x8>, _ bPacked: UnsafeRawPointer, _ c: UnsafeMutablePointer<UInt32>, _ m: Int, _ n: Int,
1328
+ _ k: Int, _ aStride: Int, _ cStride: Int
1329
+ ) {
1330
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_u1x8_t.self)
1331
+ nk_dots_packed_u1(cPtr, bPacked, c, UInt64(m), UInt64(n), UInt64(k * 8), UInt64(aStride), UInt64(cStride))
1332
+ }
1333
+
1334
+ public static func _nk_dots_symmetric(
1335
+ _ vectors: UnsafePointer<U1x8>, _ result: UnsafeMutablePointer<UInt32>, _ nVectors: Int, _ depth: Int,
1336
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
1337
+ ) {
1338
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_u1x8_t.self)
1339
+ nk_dots_symmetric_u1(
1340
+ cPtr, UInt64(nVectors), UInt64(depth * 8), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
1341
+ UInt64(rowCount))
1342
+ }
1343
+ }
1344
+
1345
+ // MARK: - Kernel Bindings: U1x8 Sets
1346
+
1347
+ extension U1x8: NumKongSetsMatrixElement {
1348
+ public typealias HammingOutput = UInt32
1349
+ public typealias JaccardOutput = Float32
1350
+
1351
+ public static func _nk_hammings_packed(
1352
+ _ a: UnsafePointer<U1x8>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<UInt32>, _ rows: Int,
1353
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
1354
+ ) {
1355
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_u1x8_t.self)
1356
+ nk_hammings_packed_u1(
1357
+ cPtr, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth * 8), UInt64(aStride), UInt64(rStride))
1358
+ }
1359
+
1360
+ public static func _nk_hammings_symmetric(
1361
+ _ vectors: UnsafePointer<U1x8>, _ result: UnsafeMutablePointer<UInt32>, _ nVectors: Int, _ depth: Int,
1362
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
1363
+ ) {
1364
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_u1x8_t.self)
1365
+ nk_hammings_symmetric_u1(
1366
+ cPtr, UInt64(nVectors), UInt64(depth * 8), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
1367
+ UInt64(rowCount))
1368
+ }
1369
+
1370
+ public static func _nk_jaccards_packed(
1371
+ _ a: UnsafePointer<U1x8>, _ bPacked: UnsafeRawPointer, _ result: UnsafeMutablePointer<Float32>, _ rows: Int,
1372
+ _ cols: Int, _ depth: Int, _ aStride: Int, _ rStride: Int
1373
+ ) {
1374
+ let cPtr = UnsafeRawPointer(a).assumingMemoryBound(to: nk_u1x8_t.self)
1375
+ nk_jaccards_packed_u1(
1376
+ cPtr, bPacked, result, UInt64(rows), UInt64(cols), UInt64(depth * 8), UInt64(aStride), UInt64(rStride))
1377
+ }
1378
+
1379
+ public static func _nk_jaccards_symmetric(
1380
+ _ vectors: UnsafePointer<U1x8>, _ result: UnsafeMutablePointer<Float32>, _ nVectors: Int, _ depth: Int,
1381
+ _ stride: Int, _ resultStride: Int, _ rowStart: Int, _ rowCount: Int
1382
+ ) {
1383
+ let cPtr = UnsafeRawPointer(vectors).assumingMemoryBound(to: nk_u1x8_t.self)
1384
+ nk_jaccards_symmetric_u1(
1385
+ cPtr, UInt64(nVectors), UInt64(depth * 8), UInt64(stride), result, UInt64(resultStride), UInt64(rowStart),
1386
+ UInt64(rowCount))
1387
+ }
1388
+ }