use std::vec::Vec;
use crate::types::ValueType;
pub trait Vector<'a>
where Self: Sized + Clone {
type Value: 'a + ValueType;
type IterVal: Iterator<Item = Self::Value>;
fn iter(&'a self) -> Self::IterVal;
fn with_capacity(cap: usize) -> Self;
fn from_vec(vec: Vec<Self::Value>) -> Self;
fn new() -> Self {
Self::with_capacity(0)
}
fn dim(&self) -> usize;
fn get(&self, i: usize) -> Self::Value;
fn get_mut(&mut self, i: usize) -> &mut Self::Value;
fn add(&'a mut self, rhs: &Self);
fn sub(&'a mut self, rhs: &Self);
fn scale(&'a mut self, rhs: Self::Value);
fn set(&mut self, i: usize, val: Self::Value) {
*self.get_mut(i) = val;
}
fn add_to(&mut self, i: usize, val: Self::Value) {
*self.get_mut(i) += val;
}
fn inner_prod<V>(&'a self, rhs: &'a V) -> Self::Value
where V: Vector<'a, Value = Self::Value> {
self.iter().zip(rhs.iter()).map(|(x, y)| x * y).sum()
}
fn norm_squared(&'a self) -> Self::Value {
self.iter().map(|x| x * x).sum()
}
fn norm(&'a self) -> f64 {
f64::sqrt(self.norm_squared().into())
}
}