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
use crate::{matrix::Matrix, number::c64};
impl Matrix<f64> {
pub fn dipowi(self, exp: i32) -> Self {
let n = self.rows;
let mut slf = self;
for i in 0..n {
slf[i][i] = slf[i][i].powi(exp);
}
slf
}
}
impl Matrix<c64> {
pub fn dipowi(self, exp: i32) -> Self {
let n = self.rows;
let mut slf = self;
for i in 0..n {
slf[i][i] = slf[i][i].powi(exp);
}
slf
}
}
#[cfg(test)]
mod tests {
use crate::prelude::*;
#[test]
fn it_works() {
let a = Matrix::<f64>::identity(2);
let a_inv = a.clone().diinv();
assert_eq!(a[0][0], a_inv[0][0]);
let a = Matrix::<c64>::identity(2);
let a_inv = a.clone().diinv();
assert_eq!(a[0][0], a_inv[0][0]);
}
}