September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
58
Task/Matrix-multiplication/Rust/matrix-multiplication.rust
Normal file
58
Task/Matrix-multiplication/Rust/matrix-multiplication.rust
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
struct Matrix {
|
||||
dat: [[f32; 3]; 3]
|
||||
}
|
||||
|
||||
impl Matrix {
|
||||
pub fn mult_m(a: Matrix, b: Matrix) -> Matrix
|
||||
{
|
||||
let mut out = Matrix {
|
||||
dat: [[0., 0., 0.],
|
||||
[0., 0., 0.],
|
||||
[0., 0., 0.]
|
||||
]
|
||||
};
|
||||
|
||||
for i in 0..3{
|
||||
for j in 0..3 {
|
||||
for k in 0..3 {
|
||||
out.dat[i][j] += a.dat[i][k] * b.dat[k][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out
|
||||
}
|
||||
|
||||
pub fn print(self)
|
||||
{
|
||||
for i in 0..3 {
|
||||
for j in 0..3 {
|
||||
print!("{} ", self.dat[i][j]);
|
||||
}
|
||||
print!("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main()
|
||||
{
|
||||
let a = Matrix {
|
||||
dat: [[1., 2., 3.],
|
||||
[4., 5., 6.],
|
||||
[7., 8., 9.]
|
||||
]
|
||||
};
|
||||
|
||||
let b = Matrix {
|
||||
dat: [[1., 0., 0.],
|
||||
[0., 1., 0.],
|
||||
[0., 0., 1.]]
|
||||
};
|
||||
|
||||
|
||||
|
||||
let c = Matrix::mult_m(a, b);
|
||||
|
||||
|
||||
c.print();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue