Skip to content

Conversation

@kolkov
Copy link
Contributor

@kolkov kolkov commented Jan 6, 2026

Summary

Refactors the public API packages to use proper Go interfaces instead of type aliases where possible. This improves pkg.go.dev documentation by hiding internal implementation paths and provides proper interfaces for external consumers.

Changes

  • tensor/: Add Backend interface with all 40+ methods, use public tensor types
  • nn/: Add Module interface with full method definitions, keep Parameter as type alias (required for Go's type system)
  • onnx/: Add Model interface for ONNX model operations
  • optim/: Use public nn.Parameter in function signatures
  • autodiff/: Use public tensor types
  • loader/: Keep ModelReader as type alias (internal types in method signatures)
  • backend/cpu, backend/webgpu: Add compile-time interface checks

Technical Notes

Some interfaces (Optimizer, ModelReader) remain as type aliases because their method signatures reference internal tensor types. Go's type system treats internal/tensor.Backend and tensor.Backend as different types even when they have identical methods.

Test plan

  • All existing tests pass (go test ./...)
  • Linter passes with 0 issues (golangci-lint run ./...)
  • Build succeeds for all packages
  • New tests added for interface implementations

Fixes #25

@codecov
Copy link

codecov bot commented Jan 6, 2026

Codecov Report

❌ Patch coverage is 10.81081% with 33 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
nn/module.go 0.00% 22 Missing ⚠️
onnx/onnx.go 0.00% 10 Missing ⚠️
backend/cpu/cpu.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

- tensor/: Add Backend interface with all 40+ methods, use public tensor types
- nn/: Add Module interface, use public tensor.Backend constraint
- onnx/: Add Model interface for ONNX model operations
- optim/: Use public nn.Parameter in function signatures
- autodiff/: Use public tensor types
- loader/: Use type alias for ModelReader (internal types in signature)
- backend/cpu, backend/webgpu: Add compile-time interface checks

This change improves pkg.go.dev documentation by hiding internal paths
where possible and provides proper interfaces for external consumers.

Fixes #25
@kolkov kolkov force-pushed the fix/onnx-public-api branch from 3f9efce to fbbf33a Compare January 6, 2026 18:55
@kolkov kolkov merged commit b2dccb6 into main Jan 6, 2026
9 checks passed
@kolkov kolkov deleted the fix/onnx-public-api branch January 6, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to use ONNX import

2 participants