opensrdk_symbolic_computation/expression/matrix_expression/
assign.rs

1use crate::{ConstantValue, Expression, MatrixExpression};
2use std::collections::HashMap;
3
4impl MatrixExpression {
5    pub fn assign(self, variables: &HashMap<&str, ConstantValue>) -> Expression {
6        match self {
7            MatrixExpression::T(v) => v.assign(variables).t(),
8            MatrixExpression::Inv(v) => v.assign(variables).inv(),
9            MatrixExpression::Det(v) => v.assign(variables).det(),
10        }
11    }
12}
13
14#[cfg(test)]
15mod tests {
16    use std::collections::HashMap;
17
18    use opensrdk_linear_algebra::{sparse::SparseTensor, Matrix};
19
20    use crate::{
21        new_variable, new_variable_tensor, AbstractSize, ConstantValue, Expression,
22        MatrixExpression, Size,
23    };
24
25    #[test]
26    fn it_works1() {
27        let id = "x";
28        let ea = new_variable_tensor((id).to_string(), vec![Size::Many, Size::Many]);
29
30        let ea_t = ea.clone().t();
31        let mut hash1 = HashMap::new();
32
33        let len = 7usize;
34        let a = Matrix::from(len, vec![1.0; len * len]).unwrap();
35
36        hash1.insert(id, ConstantValue::Matrix(a.clone()));
37
38        let result = ea_t.assign(&hash1);
39
40        assert_eq!(result, Expression::from(ConstantValue::Matrix(a.t())))
41    }
42}