1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use std::mem::{size_of};
use crate::quantify::Quantifiable;
#[derive(Debug)]
pub struct Matrix<T>
{
data: Vec<T>,
num_columns: usize,
}
impl<T> Matrix<T>
{
pub fn get(&self,row:usize,column:usize) -> &T
{
&self.data[row*self.num_columns+column]
}
pub fn get_mut(&mut self,row:usize,column:usize) -> &mut T
{
&mut self.data[row*self.num_columns+column]
}
pub fn constant(value:T,num_rows:usize,num_columns:usize) -> Matrix<T> where T:Clone
{
Matrix{
data: vec![value;num_rows*num_columns],
num_columns,
}
}
}
impl<T:Quantifiable> Quantifiable for Matrix<T>
{
fn total_memory(&self) -> usize
{
return size_of::<Matrix<T>>() + self.data.total_memory();
}
fn print_memory_breakdown(&self)
{
unimplemented!();
}
fn forecast_total_memory(&self) -> usize
{
unimplemented!();
}
}