pub trait Dictionary<T: SignalType> {
// Required methods
fn get_atom(&self, index: &AtomIndex) -> Result<Signal<T>>;
fn get_atom_data(&self, index: &AtomIndex) -> Result<&[T]>;
fn find_best_match(&self, signal: &Signal<T>) -> Result<(AtomIndex, T)>;
fn size(&self) -> usize;
fn signal_length(&self) -> usize;
}Expand description
Dictionary trait for Matching Pursuit
Defines the interface for atom dictionaries used in sparse decomposition. Implementations should provide efficient atom access and best-match finding.
§Method Selection Guide
-
get_atom(): ReturnsSignal<T>with full signal metadata. Use when:- You need signal operations (boundary handling, transforms, etc.)
- Convenience is more important than performance
- Typical use: examples, tests, user-facing code
-
get_atom_data(): Returns&[T]for zero-copy access. Use when:- Performance is critical (avoids allocation and copy)
- You only need raw data access
- Typical use: internal algorithms (MP/OMP), hot loops
Required Methods§
Sourcefn get_atom(&self, index: &AtomIndex) -> Result<Signal<T>>
fn get_atom(&self, index: &AtomIndex) -> Result<Signal<T>>
Get the atom at the specified index
Returns a Signal<T> containing the atom data. This allocates and copies
the atom data, but provides convenient access to signal operations.
Performance Note: This method allocates and clones data (~N * sizeof(T) bytes).
For performance-critical code, prefer get_atom_data() for zero-copy access.
§Arguments
index- Atom identifier
§Returns
The atom signal, or error if index is invalid
§Example
use iron_wave::decomposition::matching_pursuit::*;
use iron_wave::wavelets::Haar;
use iron_wave::{Signal, Wavelet};
let signal = Signal::new(vec![1.0, 2.0, 3.0, 4.0]);
let wavelets: Vec<Box<dyn Wavelet>> = vec![Box::new(Haar::new())];
let dict = WaveletDictionary::new(wavelets, 2, signal.len())?;
let index = AtomIndex::new(0, 0, 0);
let atom = dict.get_atom(&index)?;
assert_eq!(atom.len(), signal.len());Sourcefn get_atom_data(&self, index: &AtomIndex) -> Result<&[T]>
fn get_atom_data(&self, index: &AtomIndex) -> Result<&[T]>
Get read-only access to atom data without cloning
Returns a reference to the atom data without allocation or copying. This is the preferred method for performance-critical code.
Performance Note: Zero-copy access. Use this in hot loops and algorithms.
§Arguments
index- Atom identifier
§Returns
Reference to atom data, or error if index is invalid
§Example
use iron_wave::decomposition::matching_pursuit::*;
use iron_wave::wavelets::Haar;
use iron_wave::{Signal, Wavelet};
let signal = Signal::new(vec![1.0, 2.0, 3.0, 4.0]);
let wavelets: Vec<Box<dyn Wavelet>> = vec![Box::new(Haar::new())];
let dict = WaveletDictionary::new(wavelets, 2, signal.len())?;
let index = AtomIndex::new(0, 0, 0);
let atom_data = dict.get_atom_data(&index)?;
assert_eq!(atom_data.len(), signal.len());Sourcefn find_best_match(&self, signal: &Signal<T>) -> Result<(AtomIndex, T)>
fn find_best_match(&self, signal: &Signal<T>) -> Result<(AtomIndex, T)>
Sourcefn signal_length(&self) -> usize
fn signal_length(&self) -> usize
Signal length that this dictionary supports