use crate::arr::core::{shape_size, Reshape, Shape};
pub struct ArrVec<T> {
pub(super) buff: Vec<T>,
pub(super) shape: Vec<usize>,
}
impl<T> ArrVec<T>
where
T: Clone,
{
pub fn new(value: T, shape: Vec<usize>) -> Self {
ArrVec {
buff: vec![value; shape_size(&shape)],
shape,
}
}
}
impl<T> Clone for ArrVec<T>
where
T: Clone,
{
fn clone(&self) -> Self {
Self {
buff: self.buff.clone(),
shape: self.shape.clone(),
}
}
}
impl<T> Shape for ArrVec<T> {
fn shape(&self) -> Vec<usize> {
self.shape.clone()
}
}
impl<T> Reshape for ArrVec<T> {
fn reshape(&mut self, new_shape: &Vec<usize>) {
assert_eq!(self.shape_size(), shape_size(new_shape));
self.shape = new_shape.clone();
}
}