1use std::fmt::Debug;
2
3#[derive(Debug, Clone)]
4pub struct TensorView<'a, T> {
5 pub data: &'a [T],
6 pub shape: &'a [usize],
7}
8
9impl<'a, T> TensorView<'a, T> {
10 pub fn new(data: &'a [T], shape: &'a [usize]) -> Self {
11 Self { data, shape }
12 }
13
14 pub fn len(&self) -> usize {
15 self.data.len()
16 }
17
18 pub fn is_empty(&self) -> bool {
19 self.data.is_empty()
20 }
21}
22
23#[derive(Debug)]
24pub struct TensorViewMut<'a, T> {
25 pub data: &'a mut [T],
26 pub shape: &'a [usize],
27}
28
29impl<'a, T> TensorViewMut<'a, T> {
30 pub fn new(data: &'a mut [T], shape: &'a [usize]) -> Self {
31 Self { data, shape }
32 }
33
34 pub fn len(&self) -> usize {
35 self.data.len()
36 }
37
38 pub fn is_empty(&self) -> bool {
39 self.data.is_empty()
40 }
41}