1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
use std::ops::{Add, Div, Mul, Neg, Rem, Sub}; use rayon::prelude::*; use crate::value::PqlValue; #[derive(Debug, Default, Clone, PartialEq)] pub struct PqlVector(pub Vec<PqlValue>); impl From<PqlVector> for PqlValue { fn from(v: PqlVector) -> Self { Self::Array(v.0) } } impl Neg for PqlVector { type Output = Self; fn neg(self) -> Self::Output { let v = self.0.into_iter().map(|value| -value).collect::<Vec<_>>(); Self(v) } } impl Add for PqlVector { type Output = Self; fn add(self, other: Self) -> Self::Output { let v = self .0 .into_iter() .zip(other.0.into_iter()) .map(|(a, b)| a + b) .collect::<Vec<PqlValue>>(); Self(v) } } impl Sub for PqlVector { type Output = Self; fn sub(self, other: Self) -> Self::Output { let v = self .0 .into_iter() .zip(other.0.into_iter()) .map(|(a, b)| a - b) .collect::<Vec<PqlValue>>(); Self(v) } } impl Mul for PqlVector { type Output = Self; fn mul(self, other: Self) -> Self::Output { let v = self .0 .into_iter() .zip(other.0.into_iter()) .map(|(a, b)| a * b) .collect::<Vec<PqlValue>>(); Self(v) } } impl Div for PqlVector { type Output = Self; fn div(self, other: Self) -> Self::Output { let v = self .0 .into_iter() .zip(other.0.into_iter()) .map(|(a, b)| a / b) .collect::<Vec<PqlValue>>(); Self(v) } } impl Rem for PqlVector { type Output = Self; fn rem(self, other: Self) -> Self::Output { let v = self .0 .into_iter() .zip(other.0.into_iter()) .map(|(a, b)| a % b) .collect::<Vec<PqlValue>>(); Self(v) } }