mod ops;
mod polar;
#[derive(Debug)]
pub struct VectorN<const N: usize> {
data: [f64; N]
}
impl<const N: usize> VectorN<N> {
pub fn new(data: [f64; N]) -> Self {
Self {
data
}
}
pub fn dimensions(&self) -> usize {
N
}
pub fn get(&self, i: usize) -> Option<f64> {
if i > self.data.len() {
return None;
} else {
return Some(self.data[i]);
}
}
pub fn data(&self) -> &[f64] {
&self.data
}
}
#[cfg(test)]
mod vector_tests {
use super::VectorN;
#[test]
pub fn test_dotproduct() {
let a = VectorN::new([1.0, 2.0, 3.0, 4.0]);
let b = VectorN::new([6.9, 4.2, 3.5, 6.7]);
let dotproduct = a.dotproduct(&b);
assert!(dotproduct.is_ok());
let dotproduct = dotproduct.unwrap();
assert_eq!(dotproduct, 52.6);
}
}