Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int ge_fw(float *, int, int, float *);
- int ge_bw(float *, int, int, float *);
- int display(float *, int, int);
- #include "ge.c"
- int display(float *m, int rows, int cols) {
- int x,y = 0;
- for (x=0; x < rows; x++) {
- for (y=0; y < cols; y++) {
- printf("%f ", m[x*cols + y]);
- }
- printf("\n");
- }
- }
- int main(void) {
- int rows,cols,x,y,colsz,rowsz,rowsr,colsr,rowsh,colsh = 0;
- float *i, *out, *out0, *z, *outz, *outz0, *r, *outr, *outr0, *h, *outh, *outh0 = NULL;
- rows = 3;
- cols = 4;
- i = (float *)malloc(sizeof(float)*rows*cols);
- out = (float *)malloc(sizeof(float)*rows*cols);
- out0 = (float *)malloc(sizeof(float)*rows*cols);
- /* Set vals for initial Matrix */
- i[0] = 1;
- i[1] = 1;
- i[2] = 1;
- i[3] = 3;
- i[4] = 2;
- i[5] = 3;
- i[6] = 7;
- i[7] = 0;
- i[8] = 1;
- i[9] = 3;
- i[10] = -2;
- i[11] = 17;
- ge_fw(i, rows, cols, out);
- ge_bw(out, rows, cols, out0);
- display(out0, rows, cols);
- printf("\n");
- /* Next Test */
- rowsz = 4;
- colsz = 5;
- z = (float *)malloc(sizeof(float)*rowsz*colsz);
- outz = (float *)malloc(sizeof(float)*rowsz*colsz);
- outz0 = (float *)malloc(sizeof(float)*rowsz*colsz);
- z[0] = 0;
- z[1] = 1;
- z[2] =-3;
- z[3] = 4;
- z[4] = 1;
- z[5] = 2;
- z[6] = -2;
- z[7] = 1;
- z[8] = 0;
- z[9] = -1;
- z[10] = 2;
- z[11] = -1;
- z[12] = -2;
- z[13] = 4;
- z[14] = 0;
- z[15] = -6;
- z[16] = 4;
- z[17] = 3;
- z[18] = -8;
- z[19] = 1;
- ge_fw(z, rowsz, colsz, outz);
- ge_bw(outz, rowsz, colsz, outz0);
- display(outz0, rowsz, colsz);
- printf("\n");
- /* Next Test */
- rowsr = 3;
- colsr = 3;
- r = (float *)malloc(sizeof(float)*rowsr*colsr);
- outr = (float *)malloc(sizeof(float)*rowsr*colsr);
- outr0 = (float *)malloc(sizeof(float)*rowsr*colsr);
- r[0] = 1;
- r[1] = 1;
- r[2] = 0;
- r[3] = 1;
- r[4] = 1;
- r[5] = 4;
- r[6] = 1;
- r[7] = 1;
- r[8] = 8;
- ge_fw(r, rowsr, colsr, outr);
- ge_bw(outr, rowsr, colsr, outr0);
- display(outr0, rowsr, colsr);
- printf("\n");
- /* Next Test */
- rowsh = 3;
- colsh = 3;
- h = (float *)malloc(sizeof(float)*rowsh*colsh);
- outh = (float *)malloc(sizeof(float)*rowsh*colsh);
- outh0 = (float *)malloc(sizeof(float)*rowsh*colsh);
- h[0] = 1;
- h[1] = 0;
- h[2] = 0;
- h[3] = 4;
- h[4] = 4;
- h[5] = 0;
- h[6] = 0;
- h[7] = 7;
- h[8] = 6;
- ge_fw(h, rowsh, colsh, outh);
- ge_bw(outh, rowsh, colsh, outh0);
- display(outh0, rowsh, colsh);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment