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
/*
 * // Copyright (c) 2021 Feng Yang
 * //
 * // I am making my contributions/submissions to this project solely in my
 * // personal capacity and am not conveying any rights to any intellectual
 * // property of any third parties.
 */

use crate::matrix_expression::MatrixExpression;
use crate::usize2::USize2;

///
/// # Static-sized M x N matrix class.
///
/// This class defines M x N row-major matrix data where its size is determined
/// statically at compile time.
///
/// - tparam T - Real number type.
/// - tparam M - Number of rows.
/// - tparam N - Number of columns.
///

pub struct Matrix<const M: usize, const N: usize, const TOTAL: usize> {
    _elements: [f64; TOTAL],
}

impl<const M: usize, const N: usize, const TOTAL: usize> MatrixExpression for Matrix<M, N, TOTAL> {
    fn size(&self) -> USize2 {
        return USize2::new(M, N);
    }

    fn rows(&self) -> usize {
        return M;
    }

    fn cols(&self) -> usize {
        return N;
    }

    fn eval(&self, x: usize, y: usize) -> f64 {
        return self._elements[x * N + y];
    }
}