Skip to main content

prism_tensor/
lib.rs

1//! Prism standard-library tensor-compute sub-crate.
2//!
3//! `prism-tensor` realizes the tensor Layer-3 of the standard library
4//! named in [Wiki ADR-031][09-adr-031]: declares `TensorAxis` and
5//! `ActivationAxis` through the [`axis!`][09-adr-030] SDK macro and
6//! supplies parametric CPU integer-precision reference impls
7//! preserving bit-determinism per fixed `(HostTypes, HostBounds,
8//! AxisTuple)` selection (per ADR-030's per-axis
9//! substitution-determinism note).
10//!
11//! ## Scope
12//!
13//! - **`TensorAxis`** — fixed-shape matmul. Parametric reference:
14//!   [`CpuI8MatmulSquare<DIM>`] for `DIM × DIM` `i8` × `i8` → `i16`
15//!   matrices. `DIM` is unconstrained at the axis level: per
16//!   [ADR-060][09-adr-060] there is no `AXIS_OUTPUT_BYTES_MAX` cap —
17//!   axis-kernel output flows through the source-polymorphic
18//!   `TermValue` carrier (`Inline`/`Borrowed`/`Stream`), whose inline
19//!   width derives from the application's `HostBounds` structural-count
20//!   primitives via foundation `const fn`s. The axis impl performs only
21//!   a `DIM == 0` structural well-formedness check.
22//! - **`ActivationAxis`** — element-wise nonlinearity. Parametric
23//!   reference: [`CpuI8VectorActivation<N>`] for length-`N` `i8`
24//!   vectors. `N` is likewise unconstrained at the axis level per
25//!   ADR-060; the impl performs only an `N == 0` structural check.
26//! - **[`dtype`]** — GGML / GGUF / ONNX tensor element-type alphabet
27//!   per [ADR-057][09-adr-057]: 43 sealed [`dtype::Dtype`] impls
28//!   (continuous floats, ONNX FLOAT8 / complex / packed-4-bit,
29//!   signed / unsigned integers, boolean, GGML legacy block-32
30//!   quantization, GGML K-series block-256 quantization, GGML
31//!   IQ-series importance-aware quantization) exposed through the
32//!   [`dtype::TensorDtypeRegistry`] shape-IRI registry as
33//!   `Term::Recurse` targets for container-format realizations.
34//!   Compression-operator codomain context: per [ADR-058][09-adr-058]
35//!   the κ-derivation is the framework's compression operator; tensor
36//!   element types occupy the R-level of the operator-geometry
37//!   codomain per [ADR-059][09-adr-059].
38//! - **[`shape`]** — higher-rank tensor shape carriers:
39//!   [`shape::Tensor3Shape`] (rank-3) and [`shape::Tensor4Shape`]
40//!   (rank-4). Common GGUF / ONNX rank coverage; higher ranks compose
41//!   through `partition_product!` per ADR-033/044.
42//!
43//! ## ConstrainedTypeShape declarations
44//!
45//! Per ADR-031's `Tensor<Element, Shape>` shape commitment:
46//!
47//! - **[`MatrixShape<ROWS, COLS, ELEM_BYTES>`]** — rank-2 tensor shape.
48//! - **[`VectorShape<N, ELEM_BYTES>`]** — rank-1 tensor shape.
49//! - **[`Tensor3Shape<D0, D1, D2, ELEM_BYTES>`][shape::Tensor3Shape]** — rank-3 tensor shape.
50//! - **[`Tensor4Shape<D0, D1, D2, D3, ELEM_BYTES>`][shape::Tensor4Shape]** — rank-4 tensor shape.
51//! - **[`dtype`]** — 43 fixed-byte-count element-type shapes
52//!   (continuous floats, ONNX FLOAT8 / complex / packed-4-bit,
53//!   signed / unsigned integers, boolean, GGML legacy / K-series /
54//!   IQ-series quantization).
55//!
56//! Higher-rank tensors compose through `partition_product!` per
57//! ADR-033/044; the axis layer fixes the atom shape.
58//!
59//! ## Closure under uor-foundation (ADR-013)
60//!
61//! Every axis trait declared here has
62//! `::uor_foundation::pipeline::AxisExtension` as a supertrait;
63//! parametric impls hand-write their `AxisExtension` impl since the
64//! `axis!`-emitted companion macro takes `:ident`.
65//!
66//! ## See also
67//!
68//! - [Wiki: 09 Architecture Decisions § ADR-030 — `axis!` SDK macro][09-adr-030]
69//! - [Wiki: 09 Architecture Decisions § ADR-031 — `prism` is the standard library][09-adr-031]
70//! - [Wiki: 09 Architecture Decisions § ADR-037 — `HostBounds` ceilings on the principal data path][09-adr-037]
71//! - [Wiki: 09 Architecture Decisions § ADR-057 — Bounded recursive structural typing][09-adr-057]
72//! - [Wiki: 09 Architecture Decisions § ADR-058 — κ-derivation as the framework's compression operator][09-adr-058]
73//! - [Wiki: 09 Architecture Decisions § ADR-059 — Atlas image inside E₈ as the codomain of κ-derivation][09-adr-059]
74//! - [Wiki: 09 Architecture Decisions § ADR-060 — source-polymorphic value carrier (removes the byte-width caps)][09-adr-060]
75//!
76//! [09-adr-030]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
77//! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
78//! [09-adr-037]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
79//! [09-adr-057]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
80//! [09-adr-058]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
81//! [09-adr-059]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
82//! [09-adr-060]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
83
84#![no_std]
85#![cfg_attr(docsrs, feature(doc_cfg))]
86
87pub mod activation;
88pub mod dtype;
89pub mod shape;
90pub mod tensor;
91pub mod verbs;
92
93pub use activation::{ActivationAxis, CpuI8VectorActivation};
94pub use shape::{Tensor3Shape, Tensor4Shape};
95pub use tensor::{CpuI8MatmulSquare, MatrixShape, TensorAxis, VectorShape};
96
97/// Wiki ADR-031 standard-library version banner.
98pub const STANDARD_LIBRARY_VERSION: &str = env!("CARGO_PKG_VERSION");