You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Augusto 8eb53b5bfd Add test and subject of exercise `matrix_mult` 4 years ago
..
README.md Add test and subject of exercise `matrix_mult` 4 years ago

README.md

matrix_mult

Instructions

Implement the methods:

  • number_of_cols which returns the number of columns of the matrix.

  • number_of_rows which returns the number of rows of the matrix.

  • row(n) which returns the nth row in the matrix.

  • col(n) which returns the nth

Define the matrix multiplication by implementing the std::ops::Mul for the type matrix

Expected Functions

impl Matrix<T> {
	pub fn number_of_cols(&self) -> usize {
	}

	pub fn rows(&self) -> usize {
	}

	pub fn number_of_row(&self, n: usize) -> Vec<T> {
	}

	pub fn col(&self, n: usize) -> Vec<T> {
	}
}

impl Mul for Matrix<T> {
}

Usage

Here is a program to test your function.

fn main() {
	let matrix: Matrix<u32> = Matrix(vec![vec![3, 6], vec![8, 0]]);
	println!("{:?}", matrix.col(0));
	println!("{:?}", matrix.row(1));

	let matrix_1: Matrix<u32> = Matrix(vec![vec![0, 1], vec![0, 0]]);
	let matrix_2: Matrix<u32> = Matrix(vec![vec![0, 0], vec![1, 0]]);
	let mult = matrix_1.clone() * matrix_2.clone();
	println!("{:?}", mult);
	println!("{:?}", matrix_1.number_of_cols());
	println!("{:?}", matrix_2.number_of_rows());
}

And its output

student@ubuntu:~/[[ROOT]]/test$ cargo run
[3, 8]
[8, 0]
Some(Matrix([[1, 0], [0, 0]]))
2
2
student@ubuntu:~/[[ROOT]]/test$