Skip to content

gHashTag/go-half

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-half

Pure Go f16/bf16 ML operations — No CGo overhead.

Features

  • 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)

Installation

go get github.com/gHashTag/go-half

Usage

Ternary Packing

import "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)
}

Sparse Ternary Dot Product

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

Performance

  • Pure Go — No CGo overhead, clean FFI boundaries
  • Memory efficient — Uses minimal allocations
  • Zero-skip optimization — 30-50% faster on sparse data (66% zeros)

Origin

Companion to https://github.com/gHashTag/zig-half (Zig implementation).

Extracted from https://github.com/gHashTag/trinity HSLM training infrastructure.

License

MIT License — see LICENSE file.

Contributing

PRs welcome! Please:

  1. Follow Go standard conventions
  2. Add tests for new functions
  3. Run go vet before commit
  4. Update documentation

See Also

About

Pure Go f16/bf16 with ternary operations. No CGo overhead. Companion to zig-half.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages