1use burn::tensor::{Tensor, backend::Backend};
2
3#[derive(Clone, Debug)]
6pub struct Mat<B: Backend, const D: usize> {
7 pub tensor: Tensor<B, D>,
9}
10
11impl<B: Backend, const D: usize> Mat<B, D> {
12 pub fn new(tensor: Tensor<B, D>) -> Self {
14 Self { tensor }
15 }
16
17 pub fn shape(&self) -> Vec<usize> {
19 self.tensor.dims().to_vec()
20 }
21
22 pub fn total(&self) -> usize {
24 self.tensor.shape().num_elements()
25 }
26}
27
28#[cfg(test)]
29mod tests {
30 use super::*;
31 use crate::test_helpers::{TestBackend, test_device};
32 use burn::tensor::{Tensor, TensorData};
33
34 #[test]
35 fn test_mat_operations() {
36 let device = test_device();
37 let tensor = Tensor::<TestBackend, 2>::from_data(
38 TensorData::new(vec![1.0f32, 2.0, 3.0, 4.0], [2, 2]),
39 &device,
40 );
41 let mat = Mat::new(tensor);
42 assert_eq!(mat.shape(), vec![2, 2]);
43 assert_eq!(mat.total(), 4);
44 }
45}