mod mul_impl;
mod add_impl;
use crate::matrix::Matrix;
#[allow(dead_code)]
#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct Vector<T>
{
list : Vec<T>
}
#[allow(dead_code)]
impl<T> Vector<T>
{
pub fn into_col_matrix(self) -> Matrix<T> {
let mut matrix = Vec::with_capacity(self.len());
for param in self.list {
matrix.push(vec![param])
}
Matrix::from(matrix)
}
pub fn into_row_matrix(self) -> Matrix<T> {
Matrix::from(vec![self.list])
}
pub fn lambda<F>(&self, funct: F) -> Vector<T>
where
F: Fn(&T) -> T
{
let mut params = Vec::with_capacity(self.len());
for item in self.list() {
params.push(funct(item))
}
Vector::from(params)
}
pub fn map<F>(&self, other: &Vector<T>, funct: F) -> Vector<T>
where
F: Fn(&T, &T) -> T
{
if self.len() != other.len() {
panic!("Cannot map vectors of different lengths.")
}
let mut params = Vec::with_capacity(self.len());
let lhs = self.list();
let rhs = other.list();
for idx in 0..self.len() {
params.push(funct(&lhs[idx], &rhs[idx]))
}
Vector::from(params)
}
pub fn len(&self) -> usize {
self.list.len()
}
pub fn list(&self) -> &Vec<T> {
&self.list
}
}
impl<T> From<Vec<T>> for Vector<T>
{
fn from(vec: Vec<T>) -> Self {
Vector {
list : vec
}
}
}