Skip to main content

TritFloatTensor

Struct TritFloatTensor 

Source
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

Source

pub fn zeros(shape: &[usize]) -> Self

All-zero tensor with neutral confidence (0.5) at every element.

Source

pub fn ones(shape: &[usize]) -> Self

All-ones tensor with maximum confidence at every element.

Source

pub fn from_f32_slice(data: &[f32], shape: &[usize]) -> Self

Build from a flat f32 slice, all elements get confidence=1.0.

Source

pub fn from_f32_with_confidence( vals: &[f32], conf: &[f32], shape: &[usize], ) -> Self

Build from f32 values with per-element confidence.

Source

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

Source

pub fn shape(&self) -> &[usize]

Source

pub fn ndim(&self) -> usize

Source

pub fn numel(&self) -> usize

Source

pub fn get(&self, idx: &[usize]) -> TritFloat

Source

pub fn set(&mut self, idx: &[usize], val: TritFloat)

Source

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.

Source

pub fn matmul_sparse(a: &Self, b: &Self) -> (Self, usize)

Matmul returning (result, total_macs_skipped) for sparsity instrumentation.

Source

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

Source

pub fn add_elementwise(a: &Self, b: &Self) -> Self

Source

pub fn mul_elementwise(a: &Self, b: &Self) -> Self

Source

pub fn map<F>(&self, f: F) -> Self
where F: Fn(TritFloat) -> TritFloat + Sync + Send,

Apply a function to every element in parallel.

Source

pub fn sum_all(&self) -> TritFloat

Source

pub fn mean_all(&self) -> TritFloat

Source

pub fn min_confidence(&self) -> f32

Minimum confidence across all elements: how certain is the least-certain value?

Source

pub fn mean_confidence(&self) -> f32

Mean confidence: average epistemic certainty across the tensor.

Source

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.

Source

pub fn sparsity(&self) -> f64

Fraction of elements with zero phase (exactly 0.0 value).

Source

pub fn to_f32_vec(&self) -> Vec<f32>

Extract f32 values, discarding confidence information.

Source

pub fn to_tritmatrix(&self) -> TritMatrix

Quantize to TritMatrix: positive phase → Affirm, negative → Reject, zero → Tend.

Source

pub fn softmax_rows(&self) -> Self

Apply softmax along each row of a 2D tensor.

Trait Implementations§

Source§

impl Clone for TritFloatTensor

Source§

fn clone(&self) -> TritFloatTensor

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TritFloatTensor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.