Repository navigation
Tensors #95
Copy link
Copy link
Closed
4 / 54 of 5 issues completedDescription
Title: Minimal Implementation of Tensors in Kotlin Multiplatform
Description
We need a minimal implementation of Tensors in Kotlin Multiplatform that will serve as a foundation for future extensions. This implementation should focus on correctness, simplicity, and architectural flexibility while adhering to the following decisions and requirements.
Architectural Decisions
- Memory layout: Row-major (C-style ordering).
- Separation of concerns: Tensor memory definition and tensor operators must be kept separate.
- Data types: Support custom/experimental data types (e.g.,
int4, ternary, etc.). - Hardware flexibility: Allow the possibility to implement tensor operations on various hardware backends (CPU, GPU, accelerators).
- Slicing and views: Support creation of views/slices without memory copies (strides).
Requirements
-
Core Tensor abstraction
- Define a minimal
Tensorinterface/class to represent n-dimensional data. - Support arbitrary dimensionality (
shape,stride). - Ensure row-major layout by default.
- Define a minimal
-
Memory representation
- Encapsulate storage (contiguous memory buffer).
- Keep data storage independent of operator logic.
- Abstract over data type, allowing for built-in (e.g.,
Float32,Int32) and custom (e.g.,Int4) types.
-
Operators layer (separate from storage)
- Define an initial set of minimal operators (e.g., element access, reshape, transpose).
- Operators should work via interfaces/extensions and not be tied to the underlying memory representation.
-
Slicing and views
- Implement slicing using stride manipulation, not memory copies.
- Views should reflect changes in the underlying data.
-
Extensibility & HW ops
- Define hooks/abstractions for plugging in hardware-specific operator implementations later.
-
Testing & simplicity
-
Minimal API surface that is easy to reason about and test.
-
Provide unit tests covering:
- Creation of tensors.
- Shape/stride correctness.
- View/slice behavior.
- Simple operator correctness.
-
Out of Scope (for this issue)
- Full operator suite (e.g., matmul, convolutions).
- Advanced broadcasting semantics.
- Performance optimizations.
- Hardware-specific kernels.
Acceptance Criteria
- Can create tensors of arbitrary shape with row-major layout.
- Can slice tensors and obtain views without copying data.
- Operators are implemented outside the memory layer.
- Implementaion of operators supports broadcasting
- Custom data types can be registered/used in a basic way
- Code is simple, minimal, and well-tested across JVM/Native/JS targets.
- Factory for create a special types of tensors like zeros, ones or reandom values with different radn generators
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
Add support for reshape operator and implement DType based factories …
Rename fromGGUFData to fromByteArray in factories.
Implement missing tensor's factories.
Implement next missing tensor's factories.
Refactor TensorView
Fix Tensor issues with views
Add missing support for FP16
Improve test with reshaping
Remove duplicated GGUF calls and use endiag for fromByteArray factories
Implement low level XXXArray classes holding custom types. Uses with …
Add initial version of builder pattern
Add DSL for tensor factory
Add DSL for tensor factory
Add initial version of slicing DSL and underlaying implementaion
Add unut tests