
/* WARNING: This file has been generated by Nettool3 */


/**** Here is the Non Linear Function */

/* This is the default function:
 * Update according to the SN settings.
 */

static double squash(x)
double x;
{
   double tanh();
   return 1.7159*tanh(x*0.6666);
}


/**** Here is the Forward Propagation Code */

void fprop(input, output, wbase)
 float input[16][16];
 float output[10][1];
 float wbase[746];
{
  float hidden_1[8][8];
  float hidden_2[8][8];
  float prepro_1[4][4];
  float prepro_2[4][4];
  float prepro_3[4][4];
  float prepro_4[4][4];

   /**** LAYER hidden_1 *****/

  /* SHARED-BIAS-CONNECT */
  {  int i,j;
     float w = wbase[0];
     for (i=0; i<8; i++)
       for (j=0; j<8; j++)
          hidden_1[i][j] = w;
  }

  /* CT-MASK-TORIC-CONNECT from input to hidden_1 */
  {  int i1,i2,k1,k2,l1,l2;
     float sum;
     float (*w)[3] = (void*)(wbase + 16);
     for(i1=k1=0; i1<8; i1+=1,k1+=2)
       for(i2=k2=0; i2<8; i2+=1,k2+=2) {
         sum = 0.0;
         for(l1=0;l1<3;l1++)
           for(l2=0;l2<3;l2++) {
             int kl1 = k1+l1;
             int kl2 = k2+l2;
             if (kl1>=16) kl1 -= 16;
             if (kl2>=16) kl2 -= 16;
             sum += w[l1][l2] * input[kl1][kl2];
           }
         hidden_1[i1][i2] += sum;
       }
   }

  /* Sigmoid */
  {  int i,j;
     for (j=0; j<8; j++) 
       for (i=0; i<8; i++)
          hidden_1[i][j] = squash(hidden_1[i][j]);
  }

   /**** LAYER hidden_2 *****/

  /* SHARED-BIAS-CONNECT */
  {  int i,j;
     float w = wbase[1];
     for (i=0; i<8; i++)
       for (j=0; j<8; j++)
          hidden_2[i][j] = w;
  }

  /* CT-MASK-TORIC-CONNECT from input to hidden_2 */
  {  int i1,i2,k1,k2,l1,l2;
     float sum;
     float (*w)[3] = (void*)(wbase + 25);
     for(i1=k1=0; i1<8; i1+=1,k1+=2)
       for(i2=k2=0; i2<8; i2+=1,k2+=2) {
         sum = 0.0;
         for(l1=0;l1<3;l1++)
           for(l2=0;l2<3;l2++) {
             int kl1 = k1+l1;
             int kl2 = k2+l2;
             if (kl1>=16) kl1 -= 16;
             if (kl2>=16) kl2 -= 16;
             sum += w[l1][l2] * input[kl1][kl2];
           }
         hidden_2[i1][i2] += sum;
       }
   }

  /* Sigmoid */
  {  int i,j;
     for (j=0; j<8; j++) 
       for (i=0; i<8; i++)
          hidden_2[i][j] = squash(hidden_2[i][j]);
  }

   /**** LAYER prepro_1 *****/

  /* SHARED-BIAS-CONNECT */
  {  int i,j;
     float w = wbase[2];
     for (i=0; i<4; i++)
       for (j=0; j<4; j++)
          prepro_1[i][j] = w;
  }

  /* CT-MASK-TORIC-CONNECT from hidden_1 to prepro_1 */
  {  int i1,i2,k1,k2,l1,l2;
     float sum;
     float (*w)[3] = (void*)(wbase + 34);
     for(i1=k1=0; i1<4; i1+=1,k1+=2)
       for(i2=k2=0; i2<4; i2+=1,k2+=2) {
         sum = 0.0;
         for(l1=0;l1<3;l1++)
           for(l2=0;l2<3;l2++) {
             int kl1 = k1+l1;
             int kl2 = k2+l2;
             if (kl1>=8) kl1 -= 8;
             if (kl2>=8) kl2 -= 8;
             sum += w[l1][l2] * hidden_1[kl1][kl2];
           }
         prepro_1[i1][i2] += sum;
       }
   }

  /* CT-MASK-TORIC-CONNECT from hidden_2 to prepro_1 */
  {  int i1,i2,k1,k2,l1,l2;
     float sum;
     float (*w)[3] = (void*)(wbase + 70);
     for(i1=k1=0; i1<4; i1+=1,k1+=2)
       for(i2=k2=0; i2<4; i2+=1,k2+=2) {
         sum = 0.0;
         for(l1=0;l1<3;l1++)
           for(l2=0;l2<3;l2++) {
             int kl1 = k1+l1;
             int kl2 = k2+l2;
             if (kl1>=8) kl1 -= 8;
             if (kl2>=8) kl2 -= 8;
             sum += w[l1][l2] * hidden_2[kl1][kl2];
           }
         prepro_1[i1][i2] += sum;
       }
   }

  /* Sigmoid */
  {  int i,j;
     for (j=0; j<4; j++) 
       for (i=0; i<4; i++)
          prepro_1[i][j] = squash(prepro_1[i][j]);
  }

   /**** LAYER prepro_2 *****/

  /* SHARED-BIAS-CONNECT */
  {  int i,j;
     float w = wbase[3];
     for (i=0; i<4; i++)
       for (j=0; j<4; j++)
          prepro_2[i][j] = w;
  }

  /* CT-MASK-TORIC-CONNECT from hidden_1 to prepro_2 */
  {  int i1,i2,k1,k2,l1,l2;
     float sum;
     float (*w)[3] = (void*)(wbase + 43);
     for(i1=k1=0; i1<4; i1+=1,k1+=2)
       for(i2=k2=0; i2<4; i2+=1,k2+=2) {
         sum = 0.0;
         for(l1=0;l1<3;l1++)
           for(l2=0;l2<3;l2++) {
             int kl1 = k1+l1;
             int kl2 = k2+l2;
             if (kl1>=8) kl1 -= 8;
             if (kl2>=8) kl2 -= 8;
             sum += w[l1][l2] * hidden_1[kl1][kl2];
           }
         prepro_2[i1][i2] += sum;
       }
   }

  /* CT-MASK-TORIC-CONNECT from hidden_2 to prepro_2 */
  {  int i1,i2,k1,k2,l1,l2;
     float sum;
     float (*w)[3] = (void*)(wbase + 79);
     for(i1=k1=0; i1<4; i1+=1,k1+=2)
       for(i2=k2=0; i2<4; i2+=1,k2+=2) {
         sum = 0.0;
         for(l1=0;l1<3;l1++)
           for(l2=0;l2<3;l2++) {
             int kl1 = k1+l1;
             int kl2 = k2+l2;
             if (kl1>=8) kl1 -= 8;
             if (kl2>=8) kl2 -= 8;
             sum += w[l1][l2] * hidden_2[kl1][kl2];
           }
         prepro_2[i1][i2] += sum;
       }
   }

  /* Sigmoid */
  {  int i,j;
     for (j=0; j<4; j++) 
       for (i=0; i<4; i++)
          prepro_2[i][j] = squash(prepro_2[i][j]);
  }

   /**** LAYER prepro_3 *****/

  /* SHARED-BIAS-CONNECT */
  {  int i,j;
     float w = wbase[4];
     for (i=0; i<4; i++)
       for (j=0; j<4; j++)
          prepro_3[i][j] = w;
  }

  /* CT-MASK-TORIC-CONNECT from hidden_1 to prepro_3 */
  {  int i1,i2,k1,k2,l1,l2;
     float sum;
     float (*w)[3] = (void*)(wbase + 52);
     for(i1=k1=0; i1<4; i1+=1,k1+=2)
       for(i2=k2=0; i2<4; i2+=1,k2+=2) {
         sum = 0.0;
         for(l1=0;l1<3;l1++)
           for(l2=0;l2<3;l2++) {
             int kl1 = k1+l1;
             int kl2 = k2+l2;
             if (kl1>=8) kl1 -= 8;
             if (kl2>=8) kl2 -= 8;
             sum += w[l1][l2] * hidden_1[kl1][kl2];
           }
         prepro_3[i1][i2] += sum;
       }
   }

  /* CT-MASK-TORIC-CONNECT from hidden_2 to prepro_3 */
  {  int i1,i2,k1,k2,l1,l2;
     float sum;
     float (*w)[3] = (void*)(wbase + 88);
     for(i1=k1=0; i1<4; i1+=1,k1+=2)
       for(i2=k2=0; i2<4; i2+=1,k2+=2) {
         sum = 0.0;
         for(l1=0;l1<3;l1++)
           for(l2=0;l2<3;l2++) {
             int kl1 = k1+l1;
             int kl2 = k2+l2;
             if (kl1>=8) kl1 -= 8;
             if (kl2>=8) kl2 -= 8;
             sum += w[l1][l2] * hidden_2[kl1][kl2];
           }
         prepro_3[i1][i2] += sum;
       }
   }

  /* Sigmoid */
  {  int i,j;
     for (j=0; j<4; j++) 
       for (i=0; i<4; i++)
          prepro_3[i][j] = squash(prepro_3[i][j]);
  }

   /**** LAYER prepro_4 *****/

  /* SHARED-BIAS-CONNECT */
  {  int i,j;
     float w = wbase[5];
     for (i=0; i<4; i++)
       for (j=0; j<4; j++)
          prepro_4[i][j] = w;
  }

  /* CT-MASK-TORIC-CONNECT from hidden_1 to prepro_4 */
  {  int i1,i2,k1,k2,l1,l2;
     float sum;
     float (*w)[3] = (void*)(wbase + 61);
     for(i1=k1=0; i1<4; i1+=1,k1+=2)
       for(i2=k2=0; i2<4; i2+=1,k2+=2) {
         sum = 0.0;
         for(l1=0;l1<3;l1++)
           for(l2=0;l2<3;l2++) {
             int kl1 = k1+l1;
             int kl2 = k2+l2;
             if (kl1>=8) kl1 -= 8;
             if (kl2>=8) kl2 -= 8;
             sum += w[l1][l2] * hidden_1[kl1][kl2];
           }
         prepro_4[i1][i2] += sum;
       }
   }

  /* CT-MASK-TORIC-CONNECT from hidden_2 to prepro_4 */
  {  int i1,i2,k1,k2,l1,l2;
     float sum;
     float (*w)[3] = (void*)(wbase + 97);
     for(i1=k1=0; i1<4; i1+=1,k1+=2)
       for(i2=k2=0; i2<4; i2+=1,k2+=2) {
         sum = 0.0;
         for(l1=0;l1<3;l1++)
           for(l2=0;l2<3;l2++) {
             int kl1 = k1+l1;
             int kl2 = k2+l2;
             if (kl1>=8) kl1 -= 8;
             if (kl2>=8) kl2 -= 8;
             sum += w[l1][l2] * hidden_2[kl1][kl2];
           }
         prepro_4[i1][i2] += sum;
       }
   }

  /* Sigmoid */
  {  int i,j;
     for (j=0; j<4; j++) 
       for (i=0; i<4; i++)
          prepro_4[i][j] = squash(prepro_4[i][j]);
  }

   /**** LAYER output *****/

  /* BIAS-CONNECT */
  {  int i,j;
     float *w = wbase+6;
     for (i=0; i<10; i++)
       for (j=0; j<1; j++)
          output[i][j] = *w++;
  }

  /* CT-CONNECT from prepro_1 to output */
  {  int i,j,k,l;
     float sum;
     float (*w)[4][10][1] = (void*)(wbase + 106);
     for(i=0;i<10;i++)
       for(j=0;j<1;j++) {
         sum = 0.0;
         for(k=0;k<4;k++)
           for(l=0;l<4;l++)
             sum += w[k][l][i][j] * prepro_1[k][l];
         output[i][j] += sum;
       }
   }

  /* CT-CONNECT from prepro_2 to output */
  {  int i,j,k,l;
     float sum;
     float (*w)[4][10][1] = (void*)(wbase + 266);
     for(i=0;i<10;i++)
       for(j=0;j<1;j++) {
         sum = 0.0;
         for(k=0;k<4;k++)
           for(l=0;l<4;l++)
             sum += w[k][l][i][j] * prepro_2[k][l];
         output[i][j] += sum;
       }
   }

  /* CT-CONNECT from prepro_3 to output */
  {  int i,j,k,l;
     float sum;
     float (*w)[4][10][1] = (void*)(wbase + 426);
     for(i=0;i<10;i++)
       for(j=0;j<1;j++) {
         sum = 0.0;
         for(k=0;k<4;k++)
           for(l=0;l<4;l++)
             sum += w[k][l][i][j] * prepro_3[k][l];
         output[i][j] += sum;
       }
   }

  /* CT-CONNECT from prepro_4 to output */
  {  int i,j,k,l;
     float sum;
     float (*w)[4][10][1] = (void*)(wbase + 586);
     for(i=0;i<10;i++)
       for(j=0;j<1;j++) {
         sum = 0.0;
         for(k=0;k<4;k++)
           for(l=0;l<4;l++)
             sum += w[k][l][i][j] * prepro_4[k][l];
         output[i][j] += sum;
       }
   }

  /* Sigmoid */
  {  int i,j;
     for (j=0; j<10; j++) 
       for (i=0; i<1; i++)
          output[i][j] = squash(output[i][j]);
  }
}




/**** Here is the DX interface function */

#include "header.h"

DX(xfprop)
{
  ARG_NUMBER(3);
  ALL_ARGS_EVAL;
  fprop( get_std_matrix(APOINTER(1),16,16),
         get_std_matrix(APOINTER(2),10,1),
         get_std_vector(APOINTER(3),746) );
  return NIL;
}

