3 releases (stable)
new 1.1.0 | Nov 7, 2024 |
---|---|
1.0.0 | Nov 7, 2024 |
0.1.0 | Nov 7, 2024 |
#396 in Math
307 downloads per month
8KB
83 lines
Vector Operations
This is a collection of vector operations for Rust.
Usage
To use this crate, add the following to your Cargo.toml
file:
[dependencies]
vector_operations = "0.1.0"
Then, add this to your crate root:
use vector_operations::*;
Examples
Addition
let a = vec![1, 2, 3];
let b = vec![4, 5, 6];
let c = add(a, b);
assert_eq!(c, vec![5, 7, 9]);
Subtraction
let a = vec![1, 2, 3];
let b = vec![4, 5, 6];
let c = sub(a, b);
assert_eq!(c, vec![-3, -3, -3]);
Scaling
let a = vec![1, 2, 3];
let b = 2;
let c = scale(a, b);
assert_eq!(c, vec![2, 4, 6]);
Matrix-Vector Multiplication
let a = vec![
vec![1, 2, 3],
vec![4, 5, 6],
vec![7, 8, 9],
];
let b = vec![1, 2, 3];
let c = mat_vec_mul(a, b);
assert_eq!(c, vec![30, 36, 42]);