Module sparse_optimizations

Module sparse_optimizations 

Source
Expand description

Sparse Matrix Optimizations for Preprocessing

This module provides memory-efficient sparse matrix implementations optimized for preprocessing operations on high-dimensional sparse data commonly found in text processing, categorical encoding, and feature engineering.

§Features

  • Compressed Sparse Row (CSR) format for efficient row operations
  • Compressed Sparse Column (CSC) format for efficient column operations
  • Coordinate (COO) format for efficient construction and modification
  • Sparse-aware preprocessing transformers
  • Memory-efficient sparse matrix arithmetic
  • Automatic density optimization

§Examples

use sklears_preprocessing::sparse_optimizations::{
    SparseMatrix, SparseFormat, SparseStandardScaler
};
use scirs2_core::ndarray::Array1;

fn example() -> Result<(), Box<dyn std::error::Error>> {
    // Create sparse matrix from coordinates
    let rows = vec![0, 0, 1, 2, 2, 2];
    let cols = vec![0, 2, 1, 0, 1, 2];
    let data = vec![1.0, 3.0, 2.0, 4.0, 5.0, 6.0];

    let sparse = SparseMatrix::from_triplets(
        (3, 3), rows, cols, data, SparseFormat::CSR
    )?;

    // Sparse-aware scaling
    let scaler = SparseStandardScaler::new();
    let scaler_fitted = scaler.fit(&sparse, &())?;
    let scaled = scaler_fitted.transform(&sparse)?;

    println!("Original density: {:.2}%", sparse.density() * 100.0);
    println!("Scaled density: {:.2}%", scaled.density() * 100.0);

    Ok(())
}

Structs§

SparseConfig
Configuration for sparse operations
SparseMatrix
Sparse matrix representation with multiple format support
SparseStandardScaler
Sparse-aware standard scaler
SparseStandardScalerConfig
Configuration for SparseStandardScaler
SparseStandardScalerFitted
Fitted sparse standard scaler

Enums§

SparseFormat
Sparse matrix storage formats

Functions§

sparse_matvec
Sparse matrix vector multiplication