feat: initial release
Assisted-by: GLM 5.3 Flash
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package linalg
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
|
||||
"sourcedock.dev/petrbalvin/tensor/internal/core"
|
||||
)
|
||||
|
||||
// TestFitEvaluatePolynomial moved with FitPolynomial from the root
|
||||
// package: a quadratic fit of y = 2 + x must recover it perfectly.
|
||||
func TestFitEvaluatePolynomial(t *testing.T) {
|
||||
x := mustFloats(t, []float64{0, 1, 2}, 3)
|
||||
y := mustFloats(t, []float64{2, 3, 4}, 3)
|
||||
coeffs, err := FitPolynomial(x, y, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if math.Abs(coeffs.FloatAt(0)-2) > 1e-9 || math.Abs(coeffs.FloatAt(1)-1) > 1e-9 {
|
||||
t.Errorf("poly coeffs: %v", coeffs.RawFloats())
|
||||
}
|
||||
q, _ := core.FromFloats([]float64{5, 7}, 2)
|
||||
out, err := core.EvaluatePolynomial(coeffs, q)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if math.Abs(out.FloatAt(0)-7) > 1e-9 || math.Abs(out.FloatAt(1)-9) > 1e-9 {
|
||||
t.Errorf("poly eval: %v", out.RawFloats())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user