Welvet examples

4. weights — FormatNone MatVec

Open original example ↗Recorded results · not a live execution

Part: II · Foundation
Package: github.com/openfluke/welvet/weights
Status: ok — ✅

When

You need the weights foundation package.

Where

import "github.com/openfluke/welvet/weights"

cd 04-weights && source ../env.sh && go run .

Why

Unquantized matrices still need a typed store that streams MatVec and SGD without forcing a float32 master or Morph-as-training.

What

Store holds DType + Format + Native/Packed bytes. New[T], MatVec, MatVecT, DecodeRow, SelectWire (F32/F64/I8), ApplySGD. FormatNone: update in native lanes (float32 payload is the only f32 buffer; float64 uses native ALU; other dtypes decode→update→re-encode). Packed: unpack→update→re-Pack then drop scratch. RetainsF32Master() is true only for FormatNone+float32. Dense and composite projs share this store.

Sample output (captured)

[3 4]

Live capture from go run ./cmd/runall on local ../../welvet (exit 0).

Source

Copied from the Welvet feature book examples (openfluke.github.io/welvet/examples/04-weights).

main.go

Download source ↓
package main

import (
	"fmt"

	"github.com/openfluke/welvet/core"
	"github.com/openfluke/welvet/quant"
	"github.com/openfluke/welvet/weights"
)

func main() {
	s, err := weights.New[float32](2, 2, []float32{1, 0, 0, 1}, core.DTypeFloat32, quant.FormatNone)
	if err != nil {
		panic(err)
	}
	y := make([]float32, 2)
	if err := weights.MatVec(s, []float32{3, 4}, y); err != nil {
		panic(err)
	}
	fmt.Println(y) // ≈ [3, 4]
}