Pure Go f16/bf16 ML operations — No CGo overhead.
-
Ternary pack/unpack (2-bit encoding)
Pack16/Unpack16— 16 trits ↔ 32 bits- Encoding: -1→
01, 0→00, +1→10
-
Sparse ternary dot product
TernaryDotSparse— Zero-skip optimization (30-50% faster on 66% sparse)
go get github.com/gHashTag/go-halfimport "github.com/gHashTag/go-half/half"
func main() {
trits := []int8{-1, 0, 1, -1}
packed := half.Pack16([16]int8(trits))
unpacked := half.Unpack16(packed)
fmt.Printf("packed: 0x%08x, unpacked: %v\n", packed, unpacked)
}import "github.com/gHashTag/go-half/half"
func main() {
trits := []int8{1, 0, -1, 0, 1}
values := []float32{0.5, 0.3, -0.7, 0.2, 0.5}
// Sparse indices (only compute at these positions)
indices := []int{0, 2, 4}
result := half.TernaryDotSparse(trits, values, indices)
fmt.Printf("Sparse dot: %.2f\n", result)
}- Pure Go — No CGo overhead, clean FFI boundaries
- Memory efficient — Uses minimal allocations
- Zero-skip optimization — 30-50% faster on sparse data (66% zeros)
Companion to https://github.com/gHashTag/zig-half (Zig implementation).
Extracted from https://github.com/gHashTag/trinity HSLM training infrastructure.
MIT License — see LICENSE file.
PRs welcome! Please:
- Follow Go standard conventions
- Add tests for new functions
- Run
go vetbefore commit - Update documentation
- https://github.com/gHashTag/zig-half — Zig implementation
- https://github.com/gHashTag/zig-half-rs — Rust companion
- https://github.com/gHashTag/trinity — Full HSLM training