+/EE312
software design
git clone https://git.julia.blue/+/EE312
0211622
master
1// matrix-multiplication Project2.cpp 2// EE 312 Project 2 submission by 3// Joseph Ryan 4// jbr2558 5// Slip days used: 0 6 7#include <stdio.h> 8#include <stdint.h> 9#include <stdlib.h> 10#include "MatrixMultiply.h" 11 12void multiplyMatrices (double a [],const uint32_t a_rows ,const uint32_t a_cols , 13double b [],const uint32_t b_cols ,double c []) { 14for (uint32_t i = 0 ;i < a_rows ;++ i ) { 15for (uint32_t j = 0 ;j < b_cols ;++ j ) { 16double sum = 0 ; 17for (uint32_t k = 0 ;k < a_cols ;++ k ) { 18sum += a [i * a_cols + k ]* b [b_cols * k + j ]; 19 } 20c [i * b_cols + j ]= sum ; 21 } 22 } 23} 24 25double ** createMatrix (const uint32_t rows ,const uint32_t cols ) { 26double ** m = (double ** )malloc (cols * sizeof (double * )); 27for (uint32_t i = 0 ;i < cols ;++ i ) { 28m [i ]= (double * )malloc (rows * sizeof (double )); 29 } 30return m ; 31} 32 33double ** multiplyMatricesPtr (double ** a ,const uint32_t a_rows , 34const uint32_t a_cols ,double ** b , 35const uint32_t b_cols ) { 36double ** result = createMatrix (a_rows ,b_cols ); 37for (uint32_t i = 0 ;i < a_rows ;++ i ) { 38for (uint32_t j = 0 ;j < b_cols ;++ j ) { 39double sum = 0 ; 40for (uint32_t k = 0 ;k < a_cols ;++ k ) { 41sum += a [i ][k ]* b [k ][j ]; 42 } 43result [i ][j ]= sum ; 44 } 45 } 46return result ; 47} 48 49double ** transposeMatrix (double ** a , 50const uint32_t a_rows , 51const uint32_t a_cols ) { 52double ** result = createMatrix (a_rows ,a_cols ); 53for (uint32_t i = 0 ;i < a_cols ;++ i ) { 54for (uint32_t j = 0 ;j < a_rows ;++ j ) { 55result [i ][j ]= a [j ][i ]; 56 } 57 } 58return result ; 59}