Skip to main content

StreamingBorderGram

Struct StreamingBorderGram 

Source
pub struct StreamingBorderGram { /* private fields */ }
Expand description

Chunked, out-of-core, bit-reproducible border-Gram accumulator.

Accumulates G = Σ_n x_n x_nᵀ ∈ ℝ^{k×k} over n_rows rows submitted as fixed-size chunks (any submission order), with f64 accumulation throughout and a deterministic pairwise reduction tree whose shape is a pure function of (n_rows, chunk_size). See the module docs for the determinism contract.

Implementations§

Source§

impl StreamingBorderGram

Source

pub fn new( border_dim: usize, n_rows: usize, chunk_size: usize, ) -> Result<Self, String>

Create an empty accumulator for n_rows total rows of border dimension border_dim, streamed in chunks of chunk_size rows.

Source

pub fn n_chunks(&self) -> usize

Total number of chunks of the pass: ceil(n_rows / chunk_size).

Source

pub fn chunk_rows(&self, chunk_index: usize) -> Range<usize>

Row range covered by chunk chunk_index: [chunk_index·chunk_size, min((chunk_index+1)·chunk_size, n_rows)). A pure function of the partition parameters — the caller slices its shard rows with exactly this range.

Source

pub fn frontier(&self) -> usize

Number of chunks already consumed by the in-order cascade (the chunk cursor). Pending out-of-order chunks are not counted.

Source

pub fn is_complete(&self) -> bool

true once every chunk of the pass has been submitted.

Source

pub fn submit_chunk( &mut self, chunk_index: usize, rows: ArrayView2<'_, f64>, ) -> Result<(), String>

Submit the rows of chunk chunk_index (shape (chunk_rows(chunk_index).len(), border_dim)).

Chunks may arrive in any order; each may be submitted exactly once. The per-chunk Gram contribution is computed immediately (each entry a pairwise_sum over the chunk’s rows, in row order), so the caller’s row buffer can be dropped/remapped right after this returns.

Source

pub fn submit_chunk_gram( &mut self, chunk_index: usize, gram: Vec<f64>, ) -> Result<(), String>

Submit chunk chunk_index as a precomputed per-chunk Gram partial (flattened k·k row-major), produced by chunk_gram_flat over exactly the rows of Self::chunk_rows(chunk_index).

This is the cross-node ingestion seam (crate::cross_node): a worker node computes its chunks’ partials locally and ships the k·k values; the coordinator folds them through the same fixed in-order cascade as row-level submission, so the result is bit-identical to a single process having seen all the rows. The validation here is structural (index range, duplicate, partial length); the content contract — that the partial really is chunk_gram_flat of the chunk’s rows — is the producer’s, enforced by routing both producers through the one free function.

Source

pub fn checkpoint(&self) -> BorderGramCheckpoint

Serialize the full accumulation state — partial Grams + chunk cursor — for checkpointing. StreamingBorderGram::resume reconstructs an accumulator whose future behavior is bit-identical to never having stopped.

Source

pub fn resume(state: BorderGramCheckpoint) -> Result<Self, String>

Reconstruct an accumulator from a checkpoint. Validates the structural invariants so a corrupted checkpoint is rejected loudly instead of silently producing a wrong (but plausible-looking) Gram.

Source

pub fn finish(self) -> Result<Array2<f64>, String>

Finish the pass, returning the k×k border Gram. Errors if any chunk is missing (out-of-order pending chunks the frontier never reached, or chunks never submitted). The result is a pure function of the row content: identical bits for any submission order and for any checkpoint/resume history.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

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> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V