| Crates.io | leopard_vec |
| lib.rs | leopard_vec |
| version | 0.1.0 |
| created_at | 2025-11-30 21:16:16.554978+00 |
| updated_at | 2025-11-30 21:16:16.554978+00 |
| description | A high-performance parallelized vector container with deferred execution for bulk parallel operations |
| homepage | https://github.com/MajidAbdelilah/Leopard_rust |
| repository | https://github.com/MajidAbdelilah/Leopard_rust |
| max_upload_size | |
| id | 1958862 |
| size | 77,851 |
A high-performance parallelized vector container library for Rust with deferred execution.
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.
q.start() and q.end(), then executed in one parallel batchLQueue can manage LVec<T> of different types (u32, f64, etc.)+, -, *, / operatorsArc for efficient data sharingAdd to your Cargo.toml:
[dependencies]
leopard_vec = "0.1.0"
use leopard_vec::{LQueue, LVec, LMask};
fn main() {
// Create a queue
let q = LQueue::new();
// Create vectors (not yet initialized)
let x: LVec<f64> = q.lvec_with_capacity(1000);
let y: LVec<f64> = q.lvec_with_capacity(1000);
// Start recording operations
q.start();
// All operations are recorded, not executed
let x = x.fill_with(|i| i as f64);
let y = y.fill_with(|i| (i * 2) as f64);
let z = &x * &y + &x; // Operator overloading works!
// Execute all operations in one parallel batch
q.end();
// Retrieve results
let result = z.materialize().unwrap();
println!("z[0..5] = {:?}", &result[0..5]);
}
The operation queue that records and executes operations.
let q = LQueue::new();
// Create vectors
let vec: LVec<f64> = q.lvec(); // Default capacity (128)
let vec: LVec<f64> = q.lvec_with_capacity(1000); // Custom capacity
// Recording session
q.start(); // Begin recording
// ... operations ...
q.end(); // Execute all recorded operations
q.is_recording(); // Check if currently recording
All operations must be called between q.start() and q.end().
let a = vec.fill(42.0); // Fill with constant
let b = vec.fill_with(|i| i as f64); // Fill with closure
let mapped = a.map(|i, val| val * 2.0); // Transform each element
let branched = a.map_where(
|i, val| *val > 10.0, // Condition
|i, val| val * 2.0, // If true
|i, val| val + 1.0, // If false
);
let sum = &a + &b;
let diff = &a - &b;
let prod = &a * &b;
let quot = &a / &b;
let mask = LMask::from_fn(len, |i| i >= 5);
let blended = a.blend(&b, &mask); // a where false, b where true
let selected = LVec::select(&mask, &a, &b); // Same as blend
let applied = a.masked_apply(&mask, |i, v| v * 2.0);
let filled = a.masked_fill(&mask, 999.0);
Boolean masks for conditional operations.
// Creation
let mask = LMask::new(len, true); // All true
let mask = LMask::from_fn(len, |i| i % 2 == 0); // 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[index];
After q.end(), use materialize() to get the computed data:
if let Some(data) = result.materialize() {
println!("{:?}", &data[0..10]);
}
Recording Phase: Between q.start() and q.end(), operations create "pending" LVec instances 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's into_par_iter() for parallel element-wise computation.
Result Retrieval: materialize() returns the computed Arc<Vec<T>> for any pending LVec.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
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
Majid Abdelilah - GitHub
Contributions are welcome! Please open an issue or submit a pull request.