
/* 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(layer_1, layer_4, wbase)
 float layer_1[65][16];
 float layer_4[10][1];
 float wbase[1338];
{
  float layer_2[32][8];
  float layer_3[6][8];

   /**** LAYER layer_2 *****/

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

  /* CT-TDNN-CONNECT from layer_1 to layer_2 */
  {  int i1,i2,k,l1,l2;
     float sum;
     float (*w)[16][8] = (void*)(wbase + 26);
     for(i1=k=0; i1<32; i1+=1,k+=2)
       for(i2=0; i2<8; i2+=1) {
         sum = 0.0;
         for(l1=0;l1<3;l1++)
           for(l2=0;l2<16;l2++)
             sum += w[l1][l2][i2] * layer_1[k+l1][l2];
         layer_2[i1][i2] += sum;
       }
   }

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

   /**** LAYER layer_3 *****/

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

  /* CT-TDNN-CONNECT from layer_2 to layer_3 */
  {  int i1,i2,k,l1,l2;
     float sum;
     float (*w)[8][8] = (void*)(wbase + 410);
     for(i1=k=0; i1<6; i1+=1,k+=5)
       for(i2=0; i2<8; i2+=1) {
         sum = 0.0;
         for(l1=0;l1<7;l1++)
           for(l2=0;l2<8;l2++)
             sum += w[l1][l2][i2] * layer_2[k+l1][l2];
         layer_3[i1][i2] += sum;
       }
   }

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

   /**** LAYER layer_4 *****/

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

  /* CT-CONNECT from layer_3 to layer_4 */
  {  int i,j,k,l;
     float sum;
     float (*w)[8][10][1] = (void*)(wbase + 858);
     for(i=0;i<10;i++)
       for(j=0;j<1;j++) {
         sum = 0.0;
         for(k=0;k<6;k++)
           for(l=0;l<8;l++)
             sum += w[k][l][i][j] * layer_3[k][l];
         layer_4[i][j] += sum;
       }
   }

  /* Sigmoid */
  {  int i,j;
     for (j=0; j<10; j++) 
       for (i=0; i<1; i++)
          layer_4[i][j] = squash(layer_4[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),65,16),
         get_std_matrix(APOINTER(2),10,1),
         get_std_vector(APOINTER(3),1338) );
  return NIL;
}

