Skip to main content

Crate torsh_tensor

Crate torsh_tensor 

Source
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 optimization
  • core_ops - Core tensor operations, creation, and gradient management
  • shape_ops - Shape manipulation, views, and dimension operations
  • data_ops - Data access, indexing, and manipulation operations
  • advanced_ops - Advanced operations, reductions, and backend integration
  • math_ops - Mathematical operations and functions
  • complex_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

Constants§

VERSION
VERSION_MAJOR
VERSION_MINOR
VERSION_PATCH