Expand description
Tensor implementation for ToRSh with PyTorch-compatible API
This crate provides a high-level tensor API that wraps scirs2’s autograd functionality with a familiar PyTorch-like interface.
§Architecture
The tensor implementation is organized into specialized modules:
storage- Storage management with automatic memory mapping optimizationcore_ops- Core tensor operations, creation, and gradient managementshape_ops- Shape manipulation, views, and dimension operationsdata_ops- Data access, indexing, and manipulation operationsadvanced_ops- Advanced operations, reductions, and backend integrationmath_ops- Mathematical operations and functionscomplex_ops- Complex number operations and specialized autograd
§Quick Start
use torsh_tensor::Tensor;
use torsh_core::device::DeviceType;
// Create a tensor
let data = vec![1.0f32, 2.0, 3.0, 4.0];
let tensor = Tensor::from_data(data, vec![2, 2], DeviceType::Cpu)?;
// Basic operations
let reshaped = tensor.view(&[4, 1])?;
let sum = tensor.sum()?;
let norm_val = tensor.norm()?.item()?;
let normalized = tensor.div_scalar(norm_val)?;
// Enable gradients for autograd
let x = tensor.requires_grad_(true);
let y = x.pow(2.0)?;
let loss = y.sum()?; // Create scalar for backward pass
loss.backward()?;§Features
- Automatic memory management: Optimized storage with memory mapping for large tensors
- Zero-copy views: Efficient tensor views with shared underlying data
- PyTorch compatibility: Familiar API for easy migration from PyTorch
- Automatic differentiation: Full gradient computation support
- Device abstraction: CPU and GPU device support
- Complex numbers: Native complex tensor operations
- SciRS2 integration: Optimized backend operations for performance
Re-exports§
pub use core_ops::Operation;pub use core_ops::Tensor;pub use convenience::FluentTensor;pub use convenience::TensorConvenience;pub use convenience::TensorFluentExt;pub use sparse::SparseCSC;pub use sparse::SparseCSR;pub use sparse::SparseTensor;pub use custom_ops::global_registry;pub use custom_ops::CustomOperation;pub use custom_ops::CustomOperationRegistry;pub use custom_ops::OperationMetadata;pub use custom_ops::OperationParams;pub use custom_ops::TensorCustomOps;pub use storage::MemoryMappedStorage;pub use storage::TensorStorage;pub use tensor_view::TensorView;pub use tensor_view::TensorViewMut;
Modules§
- adaptive_
auto_ tuner - Adaptive Auto-Tuning System for Ultimate Performance Optimization
- advanced_
ops - Advanced tensor operations including reductions, linear algebra, and backend integration
- advanced_
simd_ ops - Advanced SIMD Vectorization Optimizations for ToRSh Tensor Operations
- algorithmic_
optimizations - Algorithmic Efficiency Optimizations for Core Tensor Operations
- auto_
batching - Automatic Operation Batching for Performance Optimization
- backend_
integration - Backend integration module for device-specific optimizations and cross-device operations 🚀 Enhanced with SciRS2 GPU acceleration capabilities
- bfloat16_
ops - BFloat16 tensor operations and optimizations
- broadcast
- Tensor broadcasting operations with comprehensive error handling
- cache_
optimization - complex_
ops - Complex number operations for tensors
- comprehensive_
integration_ tests - Comprehensive Integration Tests for ToRSh Optimization Systems
- computation_
graph - Computation Graph for Lazy Evaluation and Optimization
- conv
- Convolution and signal processing operations for tensors
- convenience
- Convenience methods for tensor manipulation
- core_
ops - Auto-generated module structure
- creation
- Tensor creation functions
- cross_
platform_ validator - Cross-Platform Performance Validation and Hardware-Specific Optimizations
- custom_
dtype - Custom Data Type Registration System
- custom_
ops - Custom operation registration system for torsh-tensor
- data_
ops - Auto-generated module structure
- expression_
optimizer - Tensor Expression Optimization Framework
- expression_
templates - Expression Templates for Compile-Time Tensor Operation Optimization
- fft
- Fast Fourier Transform (FFT) operations for tensors
- hardware_
accelerators - Hardware-Specific Accelerators and Optimization Engines
- indexing
- Tensor indexing and slicing operations
- lazy_
loading - Lazy Loading for Memory-Mapped Tensor Data
- lockfree_
cache - Lock-Free Cache Structures for High-Performance Concurrent Access
- manipulation
- Tensor manipulation operations
- math_
ops - Mathematical operations for tensors - Enhanced with SciRS2 Performance Features
- memory_
optimization - Advanced Memory Optimization for ToRSh Tensor Operations
- memory_
pool - nan_
inf_ detection - NaN and Infinity Detection Utilities
- optimization_
cli - ToRSh Optimization CLI - User-Friendly Command Line Interface
- prelude
- scirs2_
backend - SciRS2 Backend Integration for ToRSh Tensors
- scirs2_
stats_ integration - Comprehensive scirs2-stats integration for advanced statistical computing
- shape_
inference_ debugger - Shape Inference Debugging with Detailed Traces
- shape_
ops - Shape and view operations for tensors
- sparse
- Sparse tensor implementation with multiple storage formats
- stats
- Comprehensive tensor statistical operations
- storage
- Storage management for tensor data
- tensor_
comprehension - Tensor Comprehensions - Declarative Tensor Creation
- tensor_
tracker - Tensor Value Tracking for Debugging
- tensor_
utils - Tensor Manipulation Utilities
- tensor_
view - Zero-Copy Tensor Views for ToRSh
- tensor_
views - type_
conversions - SIMD-optimized type conversions for tensors
- ultimate_
integration_ optimizer - Ultimate Integration Optimizer - System-Wide Performance Tuning
- ultra_
performance_ profiler - Ultra-Performance Profiler and Bottleneck Analyzer
Macros§
- define_
custom_ operation - Helper macro for defining custom operations
- fancy_
idx - Advanced indexing macros
- idx
- Convenience macros for indexing
- mask_
idx - s
- tensor
- Tensor creation macro similar to PyTorch
- tensor_
2d - 2D tensor creation macro
- tensor_
comp - Macro for tensor comprehensions
- tensor_
eye - Macro for creating identity-like tensors
- tensor_
repeat - Macro for creating tensors with repeated values