Crate torsh_sparse

Crate torsh_sparse 

Source
Expand description

Sparse tensor operations for ToRSh

This crate provides comprehensive sparse tensor representations and operations, supporting multiple sparse formats including COO, CSR, CSC, BSR, DIA, ELL, DSR, and RLE.

§Key Features

  • Multiple Sparse Formats: Support for COO, CSR, CSC, BSR, DIA, ELL, DSR, and RLE formats
  • Automatic Format Selection: Intelligent format selection based on sparsity patterns
  • Neural Network Integration: Sparse layers, optimizers, and activation functions
  • GPU Acceleration: CUDA support for sparse operations
  • Memory Management: Advanced memory pooling and optimization
  • Interoperability: Integration with SciPy, MATLAB, and HDF5
  • Performance Tools: Profiling, benchmarking, and autotuning capabilities

§Usage Examples

use torsh_sparse::{CooTensor, CsrTensor, SparseFormat};
use torsh_core::Shape;

// Create a COO tensor from triplets
let triplets = vec![(0, 0, 1.0f32), (1, 1, 2.0f32), (2, 2, 3.0f32)];
let coo = CooTensor::from_triplets(triplets, (3, 3)).unwrap();

// Convert to CSR format for efficient row operations
let csr = coo.to_csr().unwrap();

// Perform sparse operations
let result = csr.transpose().unwrap();

§Performance Considerations

  • COO: Best for construction and format conversion
  • CSR: Optimized for row-based operations and matrix-vector multiplication
  • CSC: Optimized for column-based operations
  • BSR: Efficient for block-structured sparse matrices
  • DIA: Memory-efficient for diagonal-dominant matrices
  • ELL: SIMD-friendly format for GPU operations

Re-exports§

pub use bsr::BsrTensor;
pub use coo::CooTensor;
pub use csc::CscTensor;
pub use csr::CsrTensor;
pub use dia::DiaTensor;
pub use dsr::DsrTensor;
pub use ell::EllTensor;
pub use rle::RleTensor;
pub use symmetric::SymmetricMode;
pub use symmetric::SymmetricTensor;
pub use gpu::CudaSparseOps;
pub use gpu::CudaSparseTensor;
pub use gpu::CudaSparseTensorFactory;
pub use autograd::SparseAutogradTensor;
pub use autograd::SparseData;
pub use autograd::SparseGradFn;
pub use autograd::SparseGradientAccumulator;
pub use scirs2_sparse_integration::create_gpu_sparse_processor;
pub use scirs2_sparse_integration::create_nn_sparse_processor;
pub use scirs2_sparse_integration::create_sparse_processor;
pub use scirs2_sparse_integration::SciRS2SparseProcessor;
pub use scirs2_sparse_integration::SparseConfig as ScirsSparseConfig;
pub use nn::Format;
pub use nn::GraphConvolution;
pub use nn::InitConfig;
pub use nn::LayerConfig;
pub use nn::SparseAdam;
pub use nn::SparseAttention;
pub use nn::SparseConv2d;
pub use nn::SparseConverter;
pub use nn::SparseEmbedding;
pub use nn::SparseEmbeddingStats;
pub use nn::SparseInitConfig;
pub use nn::SparseLayer;
pub use nn::SparseLayerConfig;
pub use nn::SparseLinear;
pub use nn::SparseMemoryStats;
pub use nn::SparseOptimizer;
pub use nn::SparsePatternAnalysis;
pub use nn::SparseSGD;
pub use nn::SparseStats;
pub use nn::SparseWeightGenerator;
pub use hybrid::auto_select_format;
pub use hybrid::HybridTensor;
pub use hybrid::PartitionStrategy;
pub use hybrid::SparsityPattern;
pub use pattern_analysis::AdvancedSparsityPattern;
pub use pattern_analysis::ClusteringAlgorithm;
pub use pattern_analysis::MatrixReorderer;
pub use pattern_analysis::PatternAnalyzer;
pub use pattern_analysis::PatternStatistics;
pub use pattern_analysis::PatternVisualizer;
pub use pattern_analysis::ReorderingAlgorithm;
pub use performance_tools::AutoTuner;
pub use performance_tools::BenchmarkConfig;
pub use performance_tools::CachePerformanceResult;
pub use performance_tools::HardwareBenchmark;
pub use performance_tools::MemoryAnalysis;
pub use performance_tools::OperationStatistics;
pub use performance_tools::PerformanceExporter;
pub use performance_tools::PerformanceMeasurement;
pub use performance_tools::PerformanceReport;
pub use performance_tools::PlotData;
pub use performance_tools::SparseProfiler;
pub use performance_tools::SystemInfo;
pub use performance_tools::TensorBoardExporter;
pub use performance_tools::TrendAnalysis;
pub use performance_tools::TrendAnalyzer;
pub use performance_tools::TrendDirection;
pub use matrix_market::MatrixMarketField;
pub use matrix_market::MatrixMarketFormat;
pub use matrix_market::MatrixMarketHeader;
pub use matrix_market::MatrixMarketIO;
pub use matrix_market::MatrixMarketObject;
pub use matrix_market::MatrixMarketSize;
pub use matrix_market::MatrixMarketSymmetry;
pub use matrix_market::MatrixMarketUtils;
pub use custom_kernels::ElementWiseKernels;
pub use custom_kernels::FormatConversionKernels;
pub use custom_kernels::KernelDispatcher;
pub use custom_kernels::ReductionKernels;
pub use custom_kernels::SparseMatMulKernels;
pub use scipy_sparse::ScipyFormat;
pub use scipy_sparse::ScipySparseData;
pub use scipy_sparse::ScipySparseIntegration;
pub use matlab_compat::export_to_matlab_script;
pub use matlab_compat::matlab_sparse_from_triplets;
pub use matlab_compat::MatlabSparseCompat;
pub use matlab_compat::MatlabSparseMatrix;
pub use hdf5_support::load_sparse_matrix;
pub use hdf5_support::save_sparse_matrix;
pub use hdf5_support::Hdf5SparseIO;
pub use hdf5_support::Hdf5SparseMetadata;
pub use unified_interface::AccessPatterns;
pub use unified_interface::MemoryStats;
pub use unified_interface::OptimizationConfig;
pub use unified_interface::OptimizationFlags;
pub use unified_interface::OptimizationReport;
pub use unified_interface::PerformanceHints;
pub use unified_interface::PerformanceSummary;
pub use unified_interface::TensorMetadata;
pub use unified_interface::UnifiedSparseTensor;
pub use unified_interface::UnifiedSparseTensorFactory;
pub use memory_management::create_sparse_with_memory_management;
pub use memory_management::MemoryAwareSparseBuilder;
pub use memory_management::MemoryPoolConfig;
pub use memory_management::MemoryReport;
pub use memory_management::MemoryStatistics;
pub use memory_management::SparseMemoryHandle;
pub use memory_management::SparseMemoryManager;
pub use memory_management::SparseMemoryPool;
pub use conversions::direct_conversions;
pub use conversions::optimization;
pub use conversions::patterns;
pub use conversions::validation;
pub use conversions::ConversionHints;

Modules§

autograd
Autograd support for sparse tensors
bsr
BSR (Block Sparse Row) sparse tensor format
conversions
Consolidated conversion utilities for sparse tensor formats
coo
COO (Coordinate) sparse tensor format
csc
CSC (Compressed Sparse Column) sparse tensor format
csr
CSR (Compressed Sparse Row) sparse tensor format
custom_kernels
Custom optimized kernels for sparse tensor operations
dia
DIA (Diagonal) sparse tensor format
dsr
Dynamic Sparse Row (DSR) format for sparse tensors
ell
ELL (ELLPACK) sparse tensor format
gpu
GPU support for sparse tensors
hdf5_support
HDF5 sparse matrix support
hybrid
Hybrid sparse formats that combine multiple sparse representations
layers
Sparse neural network layers
linalg
Sparse linear algebra operations
matlab_compat
MATLAB sparse matrix compatibility
matrix_market
Matrix Market I/O support for sparse matrices
memory_management
Advanced memory management for sparse operations
nn
Sparse neural network components
ops
Sparse tensor operations
optimizers
Sparse optimizers
pattern_analysis
Advanced pattern analysis for sparse matrices
performance_tools
Unified Performance Tools Interface
rle
Run-Length Encoded (RLE) sparse tensor format
scipy_sparse
SciPy sparse matrix interoperability
scirs2_sparse_integration
Comprehensive scirs2-sparse integration for advanced sparse matrix operations
symmetric
Symmetric sparse tensor format
unified_interface
Unified sparse tensor interfaces to reduce technical debt

Macros§

from_scipy
Macro to simplify creation from SciPy data
to_scipy
Macro to simplify SciPy conversion

Structs§

FormatConfig
Format selection configuration for advanced users
FormatPerformanceComparison
Format performance comparison result
FormatPerformanceResult
Performance result for a specific format
SparseAnalysis
Analyze sparse tensor characteristics for format optimization

Enums§

SparseFormat
Layout format for sparse tensors

Traits§

SparseTensor
Trait for sparse tensor operations

Functions§

analyze_sparse_tensor
Analyze a sparse tensor and provide optimization recommendations
compare_format_performance
Compare performance across different sparse formats for a given tensor
convert_sparse_format
Utility to convert between sparse formats
sparse_auto_from_dense
Automatically create the optimal sparse tensor format from a dense tensor
sparse_from_dense
Create a sparse tensor from a dense tensor
sparse_from_dense_with_config
Advanced sparse tensor creation with detailed configuration
sparse_hybrid_from_dense
Create a hybrid sparse tensor with automatic partitioning

Type Aliases§

TorshResult
Convenience type alias for Results in this crate