1mod ops;
4mod polar;
5
6#[derive(Debug)]
7pub struct VectorN<const N: usize> {
9 data: [f64; N]
10}
11
12impl<const N: usize> VectorN<N> {
13 pub fn new(data: [f64; N]) -> Self {
15 Self {
16 data
17 }
18 }
19
20 pub fn dimensions(&self) -> usize {
22 N
23 }
24
25 pub fn get(&self, i: usize) -> Option<f64> {
27 if i > self.data.len() {
28 return None;
29 } else {
30 return Some(self.data[i]);
31 }
32
33 }
34
35 pub fn data(&self) -> &[f64] {
37 &self.data
38 }
39
40}
41
42
43#[cfg(test)]
44mod vector_tests {
45 use super::VectorN;
46
47 #[test]
48 pub fn test_dotproduct() {
49 let a = VectorN::new([1.0, 2.0, 3.0, 4.0]);
50
51 let b = VectorN::new([6.9, 4.2, 3.5, 6.7]);
52
53 let dotproduct = a.dotproduct(&b);
54
55 assert!(dotproduct.is_ok());
56
57 let dotproduct = dotproduct.unwrap();
58
59 assert_eq!(dotproduct, 52.6);
60
61 }
62}