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§
- Format
Config - Format selection configuration for advanced users
- Format
Performance Comparison - Format performance comparison result
- Format
Performance Result - Performance result for a specific format
- Sparse
Analysis - Analyze sparse tensor characteristics for format optimization
Enums§
- Sparse
Format - Layout format for sparse tensors
Traits§
- Sparse
Tensor - 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§
- Torsh
Result - Convenience type alias for Results in this crate