| Crates.io | metal-matrix |
| lib.rs | metal-matrix |
| version | 0.1.0 |
| created_at | 2025-03-08 08:49:34.292343+00 |
| updated_at | 2025-03-08 08:49:34.292343+00 |
| description | High-performance linear algebra library with Metal GPU acceleration |
| homepage | |
| repository | https://github.com/yourusername/metal-matrix |
| max_upload_size | |
| id | 1584227 |
| size | 60,162 |
A high-performance linear algebra library with Metal GPU acceleration for macOS and iOS.
Metal Matrix is a Rust library that provides GPU-accelerated matrix operations using Apple's Metal framework. It's designed for efficient computation of common linear algebra operations like matrix multiplication, addition, subtraction, transposition, and scalar multiplication.
Add this to your Cargo.toml:
[dependencies]
metal-matrix = "0.1.0"
use metal_matrix::{MetalContext, Matrix, matrix_multiply};
use anyhow::Result;
fn main() -> Result<()> {
// Initialize Metal context
let context = MetalContext::new()?;
// Create matrices
let a = Matrix::with_data(2, 3, vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0])?;
let b = Matrix::with_data(3, 2, vec![7.0, 8.0, 9.0, 10.0, 11.0, 12.0])?;
// Multiply matrices
let result = matrix_multiply(&context, &a, &b)?;
// Print result
for i in 0..result.rows {
for j in 0..result.cols {
print!("{:.1} ", result.get(i, j));
}
println!();
}
Ok(())
}
matrix_multiply(context, &a, &b)matrix_add(context, &a, &b)matrix_subtract(context, &a, &b)matrix_transpose(context, &a)matrix_scalar_multiply(context, scalar, &a)Vectors are represented as 1D matrices (either a single row or a single column):
// Create a column vector
let vec_a = Matrix::vector(vec![1.0, 2.0, 3.0, 4.0, 5.0]);
// Check if a matrix is a vector
if vec_a.is_vector() {
println!("Vector size: {}", vec_a.vector_size());
}
// Get a specific element from a vector
let value = vec_a.vector_get(2)?; // Gets the third element
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.