Thefaceofbo

GE Test (C)

Nov 10th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int ge_fw(float *, int, int, float *);
  5. int ge_bw(float *, int, int, float *);
  6. int display(float *, int, int);
  7.  
  8. #include "ge.c"
  9.  
  10. int display(float *m, int rows, int cols) {
  11.    int x,y = 0;
  12.    for (x=0; x < rows; x++) {
  13.       for (y=0; y < cols; y++) {
  14.          printf("%f ", m[x*cols + y]);
  15.       }
  16.       printf("\n");
  17.    }
  18. }
  19. int main(void) {
  20.    int rows,cols,x,y,colsz,rowsz,rowsr,colsr,rowsh,colsh = 0;
  21.    float *i, *out, *out0, *z, *outz, *outz0, *r, *outr, *outr0, *h, *outh, *outh0 = NULL;
  22.    rows = 3;
  23.    cols = 4;
  24.    i = (float *)malloc(sizeof(float)*rows*cols);
  25.    out = (float *)malloc(sizeof(float)*rows*cols);
  26.    out0 = (float *)malloc(sizeof(float)*rows*cols);
  27.    /* Set vals for initial Matrix */
  28.    i[0] = 1;
  29.    i[1] = 1;
  30.    i[2] = 1;
  31.    i[3] = 3;
  32.    i[4] = 2;
  33.    i[5] = 3;
  34.    i[6] = 7;
  35.    i[7] = 0;
  36.    i[8] = 1;
  37.    i[9] = 3;
  38.    i[10] = -2;
  39.    i[11] = 17;
  40.    ge_fw(i, rows, cols, out);
  41.    ge_bw(out, rows, cols, out0);
  42.    display(out0, rows, cols);
  43.    printf("\n");
  44.    /* Next Test */
  45.    rowsz = 4;
  46.    colsz = 5;
  47.    z = (float *)malloc(sizeof(float)*rowsz*colsz);
  48.    outz = (float *)malloc(sizeof(float)*rowsz*colsz);
  49.    outz0 = (float *)malloc(sizeof(float)*rowsz*colsz);
  50.    z[0] = 0;
  51.    z[1] = 1;
  52.    z[2] =-3;
  53.    z[3] = 4;
  54.    z[4] = 1;
  55.    z[5] = 2;
  56.    z[6] = -2;
  57.    z[7] = 1;
  58.    z[8] = 0;
  59.    z[9] = -1;
  60.    z[10] = 2;
  61.    z[11] = -1;
  62.    z[12] = -2;
  63.    z[13] = 4;
  64.    z[14] = 0;
  65.    z[15] = -6;
  66.    z[16] = 4;
  67.    z[17] = 3;
  68.    z[18] = -8;
  69.    z[19] = 1;
  70.    ge_fw(z, rowsz, colsz, outz);
  71.    ge_bw(outz, rowsz, colsz, outz0);
  72.    display(outz0, rowsz, colsz);
  73.    printf("\n");
  74.    /* Next Test */
  75.    rowsr = 3;
  76.    colsr = 3;
  77.    r = (float *)malloc(sizeof(float)*rowsr*colsr);
  78.    outr = (float *)malloc(sizeof(float)*rowsr*colsr);
  79.    outr0 = (float *)malloc(sizeof(float)*rowsr*colsr);
  80.    r[0] = 1;
  81.    r[1] = 1;
  82.    r[2] = 0;
  83.    r[3] = 1;
  84.    r[4] = 1;
  85.    r[5] = 4;
  86.    r[6] = 1;
  87.    r[7] = 1;
  88.    r[8] = 8;
  89.    ge_fw(r, rowsr, colsr, outr);
  90.    ge_bw(outr, rowsr, colsr, outr0);
  91.    display(outr0, rowsr, colsr);
  92.    printf("\n");
  93.    /* Next Test */
  94.    rowsh = 3;
  95.    colsh = 3;
  96.    h = (float *)malloc(sizeof(float)*rowsh*colsh);
  97.    outh = (float *)malloc(sizeof(float)*rowsh*colsh);
  98.    outh0 = (float *)malloc(sizeof(float)*rowsh*colsh);
  99.    h[0] = 1;
  100.    h[1] = 0;
  101.    h[2] = 0;
  102.    h[3] = 4;
  103.    h[4] = 4;
  104.    h[5] = 0;
  105.    h[6] = 0;
  106.    h[7] = 7;
  107.    h[8] = 6;
  108.    ge_fw(h, rowsh, colsh, outh);
  109.    ge_bw(outh, rowsh, colsh, outh0);
  110.    display(outh0, rowsh, colsh);
  111.    return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment