Leopard Vec
A high-performance parallelized vector container library for Rust with deferred execution.
Overview
Leopard Vec provides LVec, a parallel vector container that records operations and executes them in a single bulk parallel pass. This design minimizes thread pool creation overhead by batching all operations together, making it ideal for compute-intensive workloads.
Key Features
- Deferred Execution: All operations are recorded between
q.start()andq.end(), then executed in one parallel batch - Type-Agnostic Queue: A single
LQueuecan manageLVec<T>of different types (u32, f64, etc.) - SIMD-Style Masking: Boolean masks with blend, select, and masked operations
- Operator Overloading: Natural syntax with
+,-,*,/operators - Dependency Graph: Operations are automatically ordered based on data dependencies
- Zero-Copy Where Possible: Uses
Arcfor efficient data sharing
Installation
Add to your Cargo.toml:
[]
= "0.1.0"
Quick Start
use ;
API Overview
LQueue
The operation queue that records and executes operations.
let q = new;
// Create vectors
let vec: = q.lvec; // Default capacity (128)
let vec: = q.lvec_with_capacity; // Custom capacity
// Recording session
q.start; // Begin recording
// ... operations ...
q.end; // Execute all recorded operations
q.is_recording; // Check if currently recording
LVec Operations
All operations must be called between q.start() and q.end().
Initialization
let a = vec.fill; // Fill with constant
let b = vec.fill_with; // Fill with closure
Transformation
let mapped = a.map; // Transform each element
let branched = a.map_where;
Arithmetic Operators
let sum = &a + &b;
let diff = &a - &b;
let prod = &a * &b;
let quot = &a / &b;
Masking Operations
let mask = from_fn;
let blended = a.blend; // a where false, b where true
let selected = select; // Same as blend
let applied = a.masked_apply;
let filled = a.masked_fill;
LMask
Boolean masks for conditional operations.
// Creation
let mask = new; // All true
let mask = from_fn; // Pattern
// Logical operations
let and = &mask_a & &mask_b;
let or = &mask_a | &mask_b;
let xor = &mask_a ^ &mask_b;
let not = !&mask_a;
// Inspection
mask.len;
mask.as_slice;
mask;
Retrieving Results
After q.end(), use materialize() to get the computed data:
if let Some = result.materialize
How It Works
-
Recording Phase: Between
q.start()andq.end(), operations create "pending"LVecinstances and push operation descriptors to the queue. -
Dependency Analysis: The queue builds a dependency graph to determine execution order.
-
Parallel Execution: At
q.end(), operations are executed level-by-level. Each operation uses Rayon'sinto_par_iter()for parallel element-wise computation. -
Result Retrieval:
materialize()returns the computedArc<Vec<T>>for any pendingLVec.
Performance Benefits
- Minimized Thread Pool Overhead: One parallel execution context instead of many
- Optimized Scheduling: Dependency-aware execution order
- Memory Efficiency: Arc-based sharing avoids unnecessary copies
- Bulk Operations: Better cache utilization through batched execution
Requirements
- Rust 1.70+
- Rayon 1.8+
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Attribution Requirement
If you use this library in your project, you must include attribution in your documentation. Example:
This project uses leopard_vec by Majid Abdelilah
https://github.com/MajidAbdelilah/Leopard_rust
Author
Majid Abdelilah - GitHub
Contributing
Contributions are welcome! Please open an issue or submit a pull request.