Commit 6e49fb9a

6e49fb9acb0bMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 6 files · +1 added · ~5 modified

Description

Add FloatArray type (sp_FloatArray) for float-valued arrays

New type SPINEL_TYPE_FLOAT_ARRAY with full runtime support: sp_FloatArray_new, push, get, set, length, dup. Array.new(n, 0.0) and float array literals auto-detect as FloatArray.

matmul benchmark (150x150): Spinel <0.01s vs CRuby 0.32s (>32x) 74/74 tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) [email protected]

Details

Commit
6e49fb9acb0b
Parent
d1ce6031ff7e

examples/bm_matmul.rbaddedView file

1+def matgen(n)
2+ a = Array.new(n * n, 0.0)
3+ i = 0
4+ while i < n
5+ j = 0
6+ while j < n
7+ a[i * n + j] = (1.0 / n / n) * (i - j) * (i + j)
8+ j = j + 1
9+ end
10+ i = i + 1
11+ end
12+ a
13+end
14+
15+def matmul(a, b, n)
16+ c = Array.new(n * n, 0.0)
17+ i = 0
18+ while i < n
19+ k = 0
20+ while k < n
21+ aik = a[i * n + k]
22+ j = 0
23+ while j < n
24+ c[i * n + j] = c[i * n + j] + aik * b[k * n + j]
25+ j = j + 1
26+ end
27+ k = k + 1
28+ end
29+ i = i + 1
30+ end
31+ c
32+end
33+
34+n = 150
35+a = matgen(n)
36+b = matgen(n)
37+c = matmul(a, b, n)
38+
39+# Print checksum (integer part of first and last elements)
40+puts (c[0] * 1000000).to_i
41+puts (c[n * n - 1] * 1000000).to_i
42+puts "done"