ruvector_sparse_inference/sparse/
mod.rs

1//! Sparse computation module.
2//!
3//! This module provides sparse implementations of neural network layers.
4
5mod ffn;
6
7pub use ffn::SparseFfn;
8pub use crate::config::ActivationType;
9
10/// Trait for feed-forward network layers.
11pub trait FeedForward: Send + Sync {
12    /// Sparse forward pass using only active neurons.
13    fn forward_sparse(&self, input: &[f32], active_neurons: &[usize]) -> crate::error::Result<Vec<f32>>;
14
15    /// Dense forward pass using all neurons.
16    fn forward_dense(&self, input: &[f32]) -> crate::error::Result<Vec<f32>>;
17}
18
19impl FeedForward for SparseFfn {
20    fn forward_sparse(&self, input: &[f32], active_neurons: &[usize]) -> crate::error::Result<Vec<f32>> {
21        SparseFfn::forward_sparse(self, input, active_neurons)
22    }
23
24    fn forward_dense(&self, input: &[f32]) -> crate::error::Result<Vec<f32>> {
25        SparseFfn::forward_dense(self, input)
26    }
27}
28
29/// SwiGLU FFN (placeholder for future implementation).
30pub struct SwiGLUFfn;
31
32impl SwiGLUFfn {
33    /// Create a new SwiGLU FFN.
34    pub fn new(_input_dim: usize, _hidden_dim: usize) -> Self {
35        Self
36    }
37}
38
39impl FeedForward for SwiGLUFfn {
40    fn forward_sparse(&self, _input: &[f32], _active_neurons: &[usize]) -> crate::error::Result<Vec<f32>> {
41        unimplemented!("SwiGLUFfn not yet implemented")
42    }
43
44    fn forward_dense(&self, _input: &[f32]) -> crate::error::Result<Vec<f32>> {
45        unimplemented!("SwiGLUFfn not yet implemented")
46    }
47}