← 返回 tesla 的题目列表Standard and Sparse Matrix Multiplication with Optimization
类型:online_judge
tesla
Assuming you are designing a matrix multiplication program. First, implement the standard matrix multiplication, and then implement sparse matrix multiplication. Given two matrices A and B, where A is an m × k matrix and B is a k × n matrix. A sparse matrix is defined as a matrix in which most elements are zero. Write a function to perform both standard matrix multiplication and sparse matrix multiplication, optimizing computations for sparsity in the latter. Please accomplish the following tasks:
Complete the code implementation for the standard matrix multiplication.
Complete the code implementation for the sparse matrix multiplication, optimizing for sparsity.
Write test cases to validate the correctness of matrix multiplication.
Input: Two matrices A and B.
Output: Resultant matrix C.
Example:
Given matrix A:
[[1, 2],
[3, 4],
[5, 6]]
and matrix B:
[[7, 8, 9],
[10, 11, 12]]
The matrix multiplication result is:
[[27, 30, 33],
[61, 68, 75],
[95, 106, 117]]
Example
Input
[[1,2],[3,4],[5,6]]
[[7,8,9],[10,11,12]]