use std::ops::{Add, Mul};
use crate::tensor::*;
impl<T: Copy> Broadcast<T, 1> for Vec<T> {
fn broadcast(&self, other: &Tensor<T, 1>) -> Result<Tensor<T, 1>, TensorBroadcastError> {
Tensor::<T, 1>::new_vec(self).broadcast(other)
}
fn broadcast_inplace(&mut self, new_shape: [usize; 1]) {
Tensor::<T, 1>::new_vec(self).broadcast_inplace(new_shape)
}
fn broadcast_shape(&self, shape: [usize; 1]) -> Tensor<T, 1> {
Tensor::<T, 1>::new_vec(&self).broadcast_shape(shape)
}
fn get_broadcast_shape(&self, other: &Tensor<T, 1>) -> Result<[usize; 1], TensorBroadcastError> {
Tensor::<T, 1>::new_vec(self).get_broadcast_shape(other)
}
}
impl<T: Copy + Mul<Output = T> + Add<Output = T> + Default> DotProduct for Vec<T> {
type Output = T;
fn dot(&self, rhs: &Vec<T>) -> Self::Output {
assert_eq!(self.len(), rhs.len(), "Shapes must match for dot product");
self.iter().zip(rhs.iter()).map(|(&a, &b)| a * b).fold(T::default(), |acc, x| acc + x)
}
}