pub struct TritFloatTensor {
pub data: Vec<TritFloat>,
pub shape: Vec<usize>,
}Expand description
An N-dimensional tensor of TritFloats laid out in row-major order.
Each element carries its own confidence field. The tensor’s overall
confidence is determined by min_confidence() or mean_confidence().
Fields§
§data: Vec<TritFloat>§shape: Vec<usize>Implementations§
Source§impl TritFloatTensor
impl TritFloatTensor
Sourcepub fn zeros(shape: &[usize]) -> Self
pub fn zeros(shape: &[usize]) -> Self
All-zero tensor with neutral confidence (0.5) at every element.
Sourcepub fn from_f32_slice(data: &[f32], shape: &[usize]) -> Self
pub fn from_f32_slice(data: &[f32], shape: &[usize]) -> Self
Build from a flat f32 slice, all elements get confidence=1.0.
Sourcepub fn from_f32_with_confidence(
vals: &[f32],
conf: &[f32],
shape: &[usize],
) -> Self
pub fn from_f32_with_confidence( vals: &[f32], conf: &[f32], shape: &[usize], ) -> Self
Build from f32 values with per-element confidence.
Sourcepub fn from_tritmatrix(m: &TritMatrix) -> Self
pub fn from_tritmatrix(m: &TritMatrix) -> Self
Convert a TritMatrix to a 2D TritFloatTensor.
Weights are exactly {-1, 0, +1} — they carry maximum confidence (1.0).
pub fn shape(&self) -> &[usize]
pub fn ndim(&self) -> usize
pub fn numel(&self) -> usize
pub fn get(&self, idx: &[usize]) -> TritFloat
pub fn set(&mut self, idx: &[usize], val: TritFloat)
Sourcepub fn matmul(a: &Self, b: &Self) -> Self
pub fn matmul(a: &Self, b: &Self) -> Self
2D matrix multiply: [m, k] × [k, n] → [m, n].
Each output element’s confidence = min confidence over all contributing (a_i × b_i) multiplications. Zero-phase activations skip their MAC (@sparseskip at activation level) but still participate in the confidence running-minimum so uncertain zeros don’t disappear. Rows are computed in parallel via Rayon.
Sourcepub fn matmul_sparse(a: &Self, b: &Self) -> (Self, usize)
pub fn matmul_sparse(a: &Self, b: &Self) -> (Self, usize)
Matmul returning (result, total_macs_skipped) for sparsity instrumentation.
Sourcepub fn matmul_trit(activations: &Self, weights: &TritMatrix) -> (Self, usize)
pub fn matmul_trit(activations: &Self, weights: &TritMatrix) -> (Self, usize)
Multiply float activations by exact ternary weights (TritMatrix).
This is the inference-time hot path: activations carry live confidence, weights are exact {-1,0,+1} with confidence=1.0, so output confidence = min activation confidence over each dot product.
@sparseskip fires on BOTH activation zeros (is_zero()) AND weight zeros (w == 0), giving the full combined sparsity savings.
Returns (output_tensor, total_macs_skipped).
pub fn add_elementwise(a: &Self, b: &Self) -> Self
pub fn mul_elementwise(a: &Self, b: &Self) -> Self
pub fn sum_all(&self) -> TritFloat
pub fn mean_all(&self) -> TritFloat
Sourcepub fn min_confidence(&self) -> f32
pub fn min_confidence(&self) -> f32
Minimum confidence across all elements: how certain is the least-certain value?
Sourcepub fn mean_confidence(&self) -> f32
pub fn mean_confidence(&self) -> f32
Mean confidence: average epistemic certainty across the tensor.
Sourcepub fn confidence_histogram(&self) -> [usize; 9]
pub fn confidence_histogram(&self) -> [usize; 9]
Histogram of confidence states across all elements. Index i = count of elements with confidence ≈ i/8. The 9 bins correspond to the 9 discrete states of the 2-trit confidence field.
Sourcepub fn to_f32_vec(&self) -> Vec<f32>
pub fn to_f32_vec(&self) -> Vec<f32>
Extract f32 values, discarding confidence information.
Sourcepub fn to_tritmatrix(&self) -> TritMatrix
pub fn to_tritmatrix(&self) -> TritMatrix
Quantize to TritMatrix: positive phase → Affirm, negative → Reject, zero → Tend.
Sourcepub fn softmax_rows(&self) -> Self
pub fn softmax_rows(&self) -> Self
Apply softmax along each row of a 2D tensor.
Trait Implementations§
Source§impl Clone for TritFloatTensor
impl Clone for TritFloatTensor
Source§fn clone(&self) -> TritFloatTensor
fn clone(&self) -> TritFloatTensor
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for TritFloatTensor
impl RefUnwindSafe for TritFloatTensor
impl Send for TritFloatTensor
impl Sync for TritFloatTensor
impl Unpin for TritFloatTensor
impl UnsafeUnpin for TritFloatTensor
impl UnwindSafe for TritFloatTensor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more