Expand description
§Vectra - A multi-dimensional array library for Rust
Vectra is a high-performance multi-dimensional array library for Rust, inspired by NumPy. It provides efficient array operations, mathematical functions, and linear algebra capabilities with a focus on performance and ergonomics.
§Features
- Multi-dimensional Arrays: Support for N-dimensional arrays with flexible indexing
- Broadcasting: NumPy-style broadcasting for element-wise operations
- Mathematical Functions: Comprehensive set of mathematical operations including:
- Trigonometric functions (sin, cos, tan, etc.)
- Hyperbolic functions (sinh, cosh, tanh, etc.)
- Logarithmic and exponential functions
- Power and root functions
- Linear Algebra: Matrix multiplication with multiple backend options:
- BLAS integration for high performance
- Faer backend for pure Rust implementation
- Custom optimized implementations
- Random Number Generation: Built-in support for random array creation
- Memory Efficient: Zero-copy operations where possible
- Type Safety: Compile-time dimension checking
§Quick Start
use vectra::prelude::*;
// Create arrays
let zeros = Array::<_, f64>::zeros([2, 3]);
let ones = Array::<_, i32>::ones([3, 3]);
let eye = Array::<_, f32>::eye(3); // Identity matrix
// Create from vector
let data = vec![1, 2, 3, 4, 5, 6];
let arr = Array::from_vec(data, [2, 3]);
// Array operations
let reshaped = arr.reshape([3, 2]);
let transposed = arr.transpose();
// Mathematical operations
let a = Array::from_vec(vec![1.0, 2.0, 3.0, 4.0], [2, 2]);
let b = Array::from_vec(vec![5.0, 6.0, 7.0, 8.0], [2, 2]);
let sum = &a + &b; // Element-wise addition
let product = &a * &b; // Element-wise multiplication
let dot_product = a.matmul(&b); // Matrix multiplication
// Mathematical functions
let angles = Array::from_vec(vec![0.0, std::f64::consts::PI/2.0], [2]);
let sines = angles.sin();
let exponentials = angles.exp();
// Random arrays
let random_arr = Array::<_, f64>::random([3, 3]);
let normal_arr = Array::<_, f64>::randn([2, 4]);§Array Creation
Vectra provides multiple ways to create arrays:
use vectra::prelude::*;
// Create arrays filled with specific values
let zeros = Array::<_, f64>::zeros([2, 3]);
let ones = Array::<_, i32>::ones([3, 3]);
let filled = Array::full([2, 2], 42);
// Create from existing data
let data = vec![1, 2, 3, 4, 5, 6];
let arr = Array::from_vec(data, [2, 3]);
// Create ranges
let range1d = Array::arange(0, 10, 1); // [0, 1, 2, ..., 9]
let range_count = Array::arange_c(0, 2, 5); // 5 elements starting from 0 with step 2
// Random arrays
let random = Array::<_, f64>::random([3, 3]); // Uniform [0, 1)
let uniform = Array::uniform([2, 2], -1.0, 1.0); // Uniform [-1, 1)
let normal = Array::<_, f64>::randn([2, 3]); // Standard normal distribution
// Identity matrix
let identity = Array::<_, f64>::eye(4);§Performance
Vectra is designed for high performance with multiple optimization strategies:
- BLAS Integration: Optional BLAS backend for optimized linear algebra operations
- Faer Backend: Pure Rust high-performance linear algebra
- SIMD Optimizations: Vectorized operations where supported
- Memory Layout Control: Support for both row-major and column-major layouts
- Zero-copy Operations: Efficient memory usage through view-based operations
Modules§
- prelude
- Prelude module that re-exports the most commonly used items.