Skip to main content

SparseSynapticMap

Struct SparseSynapticMap 

Source
pub struct SparseSynapticMap<const N: usize> {
    pub row_ptr: Vec<usize>,
    pub col_indices: Vec<u16>,
    pub values: Vec<f32>,
}
Expand description

Compressed Sparse Row representation of the synaptic weight matrix.

Generic over N (number of neurons) to support both small channel routers and full 2048-neuron routing fabrics.

N must be at most MAX_SPARSE_NEURONS (65,536): target index 65,535 is representable as u16, target 65,536 is not. Constructors and insertion APIs reject out-of-range or non-u16 indices rather than truncating them into a different valid connection.

Fields§

§row_ptr: Vec<usize>

Row pointers: row_ptr[i] gives the start index in col_indices/values for neuron i. Length is N + 1.

§col_indices: Vec<u16>

Column indices: target neuron for each non-zero entry.

§values: Vec<f32>

Non-zero weight values.

Implementations§

Source§

impl<const N: usize> SparseSynapticMap<N>

Source

pub fn new() -> Self

Create an empty sparse synaptic map with N neurons.

§Panics

Panics if N exceeds MAX_SPARSE_NEURONS. Prefer SparseSynapticMap::try_new for a recoverable error.

Source

pub fn try_new() -> Result<Self>

Fallible constructor that rejects an N larger than the u16 target address space.

Source

pub fn from_dense(matrix: &[[f32; N]; N], sparsity_threshold: f32) -> Self

Build from a dense weight matrix (for migration from dense representations).

§Panics

Panics if N exceeds MAX_SPARSE_NEURONS.

Source

pub fn try_from_dense( matrix: &[[f32; N]; N], sparsity_threshold: f32, ) -> Result<Self>

Fallible counterpart of SparseSynapticMap::from_dense.

Source

pub fn from_adjacency(adjacency: &[Vec<Synapse>]) -> Self

Build from explicit adjacency lists.

§Panics

Panics if N is unsupported, adjacency.len() is not N, or any stored target is >= N. Prefer SparseSynapticMap::try_from_adjacency.

Source

pub fn try_from_adjacency(adjacency: &[Vec<Synapse>]) -> Result<Self>

Fallible counterpart of SparseSynapticMap::from_adjacency.

Source

pub fn get_row(&self, row: usize) -> impl Iterator<Item = (u16, f32)> + '_

Get all synapses for a given neuron (row).

Source

pub fn get_weight(&self, row: usize, col: usize) -> f32

Get the weight from neuron row to neuron col. Returns 0.0 if not connected.

Source

pub fn set_weight( &mut self, row: usize, col: usize, weight: f32, sparsity_threshold: f32, )

Update a single synaptic weight. Creates the connection if it doesn’t exist (when weight exceeds threshold) or removes it (when weight drops below).

§Panics

Panics if row or col is >= N, or if col cannot be represented as u16. Prefer SparseSynapticMap::try_set_weight.

Source

pub fn try_set_weight( &mut self, row: usize, col: usize, weight: f32, sparsity_threshold: f32, ) -> Result<()>

Fallible counterpart of SparseSynapticMap::set_weight.

On error the map is left unchanged.

Source

pub fn nnz(&self) -> usize

Number of non-zero synapses.

Source

pub fn sparsity(&self) -> f32

Sparsity ratio: fraction of zero entries in the full $N \times N$ matrix.

The denominator is computed in u64 so N = 65_536 does not overflow usize on 32-bit targets (65_536² = 2³²).

Source

pub fn to_dense(&self) -> [[f32; N]; N]

Convert back to dense matrix (for debugging / interoperability).

Source

pub fn to_gpu_arrays(&self) -> (Vec<u32>, Vec<u32>, Vec<f32>)

Export as GPU-ready flat arrays for kernel launch. Returns (row_ptr, col_indices, values) as owned vectors.

§Panics

Panics if a row-pointer offset exceeds u32::MAX. Prefer SparseSynapticMap::try_to_gpu_arrays.

Source

pub fn try_to_gpu_arrays(&self) -> Result<(Vec<u32>, Vec<u32>, Vec<f32>)>

Fallible counterpart of SparseSynapticMap::to_gpu_arrays.

Trait Implementations§

Source§

impl<const N: usize> Clone for SparseSynapticMap<N>

Source§

fn clone(&self) -> SparseSynapticMap<N>

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<const N: usize> Debug for SparseSynapticMap<N>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Default for SparseSynapticMap<N>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, const N: usize> Deserialize<'de> for SparseSynapticMap<N>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<const N: usize> Serialize for SparseSynapticMap<N>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<const N: usize> Freeze for SparseSynapticMap<N>

§

impl<const N: usize> RefUnwindSafe for SparseSynapticMap<N>

§

impl<const N: usize> Send for SparseSynapticMap<N>

§

impl<const N: usize> Sync for SparseSynapticMap<N>

§

impl<const N: usize> Unpin for SparseSynapticMap<N>

§

impl<const N: usize> UnsafeUnpin for SparseSynapticMap<N>

§

impl<const N: usize> UnwindSafe for SparseSynapticMap<N>

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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

Source§

type Output = T

Should always be Self
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.