Last active
October 17, 2019 03:02
-
-
Save AllanChen/fe61ef9c15e280faaff5ae6dab26e3f5 to your computer and use it in GitHub Desktop.
cpp mat multiply
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
void create_mat(int height, int width, float *outMat){ | |
for (int h=0; h<height; h++){ | |
for (int w=0; w<width; w++){ | |
float value = h * width + (w+1); | |
int int_value = (int) value -1; | |
outMat[int_value] = value; | |
} | |
} | |
return; | |
} | |
int main(){ | |
float *mat_a_s = new float; | |
float *mat_b_s = new float; | |
float mat_result[4]; | |
int height = 4; | |
int width = 3; | |
create_mat(height, width, mat_a_s); | |
create_mat(3, 1, mat_b_s); | |
for (int h=0; h<height; h++){ | |
float result = 0; | |
for (int w=0; w < width; w++){ | |
float value = h * width + (w+1); | |
int int_value = (int) value -1; | |
float mat_a_value1 = mat_a_s[int_value]; | |
float mat_b_value1 = mat_b_s[w]; | |
result += mat_a_value1 * mat_b_value1; | |
} | |
mat_result[h] = result; | |
} | |
for(int i=0; i<height; i++){ | |
printf("mat_result = %f \n", mat_result[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment