opensrdk_symbolic_computation/expression/matrix_expression/
variable.rs1use crate::MatrixExpression;
2use std::collections::HashSet;
3
4impl MatrixExpression {
5 pub fn variable_ids(&self) -> HashSet<&str> {
6 match self {
7 MatrixExpression::T(v) => v.variable_ids(),
8 MatrixExpression::Inv(v) => v.variable_ids(),
9 MatrixExpression::Det(v) => v.variable_ids(),
10 }
11 }
12}
13
14#[cfg(test)]
15mod tests {
16 use std::collections::HashSet;
17
18 use crate::{new_variable, new_variable_tensor, size, MatrixExpression, Size};
19
20 #[test]
21 fn it_works() {
22 let id = "x";
23 let a = HashSet::from([id; 1]);
24 let ea = new_variable_tensor((id).to_string(), vec![Size::Many, Size::Many]);
25
26 let ea_t = ea.clone().t();
27 let a_t = ea_t.variable_ids();
28
29 assert_eq!(a, a_t);
30
31 let ea_inv = ea.clone().inv();
32 let a_inv = ea_inv.variable_ids();
33
34 assert_eq!(a, a_inv);
35
36 let ea_det = ea.clone().det();
37 let a_det = ea_det.variable_ids();
38
39 assert_eq!(a, a_det);
40 }
41}