Files
tensor/linalg/mat_scratch_test.go
T
petrbalvin af4ee19703
Release / gates (push) Successful in 4m38s
Test / test (push) Successful in 5m16s
Release / release (push) Successful in 35s
feat: initial release
Assisted-by: GLM 5.3 Flash
2026-09-03 10:00:00 +02:00

41 lines
1.1 KiB
Go

// 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])
}
}
}
}