feat: initial release
Assisted-by: GLM 5.3 Flash
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package linalg
|
||||
|
||||
import (
|
||||
"sourcedock.dev/petrbalvin/tensor/internal/core"
|
||||
"testing"
|
||||
|
||||
"sourcedock.dev/petrbalvin/tensor/internal/engine"
|
||||
)
|
||||
|
||||
// TestMatMul2DFloat32ScratchCleaned pins the regression where the
|
||||
// pooled accumulation buffer was handed back dirty: leftover values
|
||||
// from an earlier borrower used to leak into every float32 product sum,
|
||||
// making results depend on allocation history instead of inputs alone.
|
||||
func TestMatMul2DFloat32ScratchCleaned(t *testing.T) {
|
||||
const size = 35
|
||||
warm := engine.GetFloat64Buf(size)
|
||||
for i := range warm {
|
||||
warm[i] = 1.5 // leave obvious residue in the pooled window
|
||||
}
|
||||
engine.PutFloat64Buf(warm)
|
||||
|
||||
a := mustFromFloat32s(t, []float32{1, 2, 3, 4}, 2, 2)
|
||||
b := mustFromFloat32s(t, []float32{0.5, 0, 2, 1}, 2, 2)
|
||||
want := []float32{4.5, 2, 9.5, 4}
|
||||
|
||||
for run := range 2 {
|
||||
got, err := core.MatMul2D(a, b)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i := range want {
|
||||
if g := got.RawFloat32s()[i]; g != want[i] {
|
||||
t.Fatalf("run %d: c[%d] = %v, want %v", run, i, g, want[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user