Categories: MATLAB/Octave

Matrix Multiplication Tests in Octave (or Matlab)

I was recently implementing matrix multiplication on the GPU (using CUDA). For my application, I was generating random numbers and generating statistics about the performance of matrix multiplication variants (e.g. using shared memory vs naive multiplication). Some of the results tended to differ from the CPU’s results. Therefore, I decided to use deterministic matrices for the inputs to ensure my algorithm is correct. What I needed was a neutral (3rd party) matrix multiplication algorithm. This seems like a job for MATLAB. Unfortunately, my license expired a few years ago. My robotics professor at the University of Washington was a fan of Octave because it is open source and free. Here is the script I created to generate matrices with the positive integers.

A = 1:10000;
B = 10001:20000;

A = reshape(A, [100,100]);
B = reshape(B, [100,100]);

A = transpose(A);
B = transpose(B);

C = A * B;

# format short;

save 'mmult100x100.txt' C;

Backstory

It has been a while since I used MATLAB. Here are the searches I used to create the script.

  1. array 1 2 3 4 5 matlab – Google Search
  2. display full precision matlab – Google Search
  3. write matlab array to file – Google Search
  4. write matlab matrix to file – Google Search
  5. My matrix multiplication algorithms use floats so comparisons fail. use float32 in matlab – Search (bing.com)
  6. check matlab matrix datatype – Google Search >
  7. create matrix of float32 matlab – Google Search >

Article info




Leave a Reply

Your email address will not be published. Required fields are marked *