int main(){
  tnn_param p, io;
  tnn_state in, out, *s;
  tnn_module m;
  int i;

  printf("Initializing state in: %s\n", TEST_FUNC(tnn_state_init(&in, A)));
  printf("Initializing state out: %s\n", TEST_FUNC(tnn_state_init(&out, B)));
  printf("Initializing paramter p: %s\n", TEST_FUNC(tnn_param_init(&p)));
  printf("Initializing paramter io: %s\n", TEST_FUNC(tnn_param_init(&io)));
  printf("Allocating state in: %s\n", TEST_FUNC(tnn_param_state_alloc(&io, &in)));
  printf("Allocating state out: %s\n", TEST_FUNC(tnn_param_state_alloc(&io, &out)));
  printf("Initializing module m: %s\n", TEST_FUNC(tnn_module_init_sum(&m, &in, &out, &io)));
  printf("Debugging module m: %s\n", TEST_FUNC(tnn_module_debug(&m)));

  printf("Setting input\n");
  for(i = 0; i < in.size; i = i + 1){
    gsl_vector_set(&in.x, i, (double)(C+i));
  }

  printf("Setting output\n");
  for(i = 0; i < out.size; i = i + 1){
    gsl_vector_set(&out.dx, i, 2.0*(double)(D+i));
  }

  printf("Radomizing weights using polymorphic call: %s\n", TEST_FUNC(tnn_module_randomize(&m, 1.0)));
  printf("Debugging module m: %s\n", TEST_FUNC(tnn_module_debug(&m)));

  printf("Executing fprop using polymorphic call: %s\n", TEST_FUNC(tnn_module_fprop(&m)));
  printf("Debugging module m: %s\n", TEST_FUNC(tnn_module_debug(&m)));

  printf("Executing bprop using polymorphic call: %s\n", TEST_FUNC(tnn_module_bprop(&m)));
  printf("Debugging module m: %s\n", TEST_FUNC(tnn_module_debug(&m)));

  for(i = 0; i < A/B; i = i + 1){
    printf("Executing get: %s\n", TEST_FUNC(tnn_module_sum_get(&m, &s, i)));
    printf("Debugging s: %s\n", TEST_FUNC(tnn_state_debug(s)));
  }

  printf("Debugging parameter p: %s\n", TEST_FUNC(tnn_param_debug(&p)));
  printf("Debugging parameter io: %s\n", TEST_FUNC(tnn_param_debug(&io)));

  printf("Destroying paramter p: %s\n", TEST_FUNC(tnn_param_destroy(&p)));
  printf("Destroying paramter io: %s\n", TEST_FUNC(tnn_param_destroy(&io)));
  printf("Destroy module m using polymorphic call: %s\n", TEST_FUNC(tnn_module_destroy(&m)));
  printf("Debugging module m: %s\n", TEST_FUNC(tnn_module_debug(&m)));
  
  return 0;
}
int main(){
  tnn_param p, q, io, oi;
  tnn_state in, out;
  tnn_module m, l;
  int i;
  tnn_pstable t;

  srand(time(NULL));

  printf("Initializing state in: %s\n", TEST_FUNC(tnn_state_init(&in, A)));
  printf("Initializing state out: %s\n", TEST_FUNC(tnn_state_init(&out, B)));
  printf("Initializing paramter p: %s\n", TEST_FUNC(tnn_param_init(&p)));
  printf("Initializing paramter io: %s\n", TEST_FUNC(tnn_param_init(&io)));
  printf("Allocating state in: %s\n", TEST_FUNC(tnn_param_state_alloc(&io, &in)));
  printf("Allocating state out: %s\n", TEST_FUNC(tnn_param_state_alloc(&io, &out)));
  printf("Allocating state out again: %s\n", TEST_FUNC(tnn_param_state_alloc(&io, &out)));
  printf("Initializing module m: %s\n", TEST_FUNC(tnn_module_init_linear(&m, &in, &out, &p)));
  printf("Initialized module t = %ld, c = %ld, w.size = %d, input = %ld, output = %ld, bprop = %ld, fprop = %ld, randomize = %ld, destroy = %ld\n",
	 (long)m.t, (long)m.c, (int)m.w.size, (long)m.input, (long)m.output, (long)m.bprop, (long)m.fprop, (long)m.randomize, (long)m.destroy);

  printf("Setting input\n");
  for(i = 0; i < in.size; i = i + 1){
    gsl_vector_set(&in.x, i, (double)(C+i));
  }
  printf("Debugging using polymorphic call: %s\n", TEST_FUNC(tnn_module_debug(&m)));

  printf("Setting output\n");
  for(i = 0; i < out.size; i = i + 1){
    gsl_vector_set(&out.dx, i, E + (double)i/10.0);
  }
  printf("Debugging using polymorphic call: %s\n", TEST_FUNC(tnn_module_debug(&m)));

  printf("Radomizing weights using polymorphic call: %s\n", TEST_FUNC(tnn_module_randomize(&m, 1.0)));
  printState(&m.w);
  printf("Executing fprop using polymorphic call: %s\n", TEST_FUNC(tnn_module_fprop(&m)));
  printState(&out);
  printf("Executing bprop using polymorphic call: %s\n", TEST_FUNC(tnn_module_bprop(&m)));
  printf("Debugging using polymorphic call: %s\n", TEST_FUNC(tnn_module_debug(&m)));

  //Cloning test
  printf("Initializing parameter q: %s\n", TEST_FUNC(tnn_param_init(&q)));
  printf("Initializing parameter oi: %s\n", TEST_FUNC(tnn_param_init(&oi)));
  printf("Initializing pstable t: %s\n", TEST_FUNC(tnn_pstable_init(&t)));
  printf("Constructing t with oi from io: %s\n", TEST_FUNC(tnn_pstable_param_alloc(&t, &io, &oi)));
  printf("Debugging pstable t: %s\n", TEST_FUNC(tnn_pstable_debug(&t)));
  printf("Debugging paramter oi: %s\n", TEST_FUNC(tnn_param_debug(&oi)));
  printf("Cloning m to l: %s\n", TEST_FUNC(tnn_module_clone(&m,&l,&q, &t)));
  printf("Debugging l: %s\n", TEST_FUNC(tnn_module_debug(&l)));
  printf("Radomizing weights using polymorphic call: %s\n", TEST_FUNC(tnn_module_randomize(&l, 1.0)));
  printf("Executing fprop using polymorphic call: %s\n", TEST_FUNC(tnn_module_fprop(&l)));
  printf("Executing bprop using polymorphic call: %s\n", TEST_FUNC(tnn_module_bprop(&l)));
  printf("Debugging l: %s\n", TEST_FUNC(tnn_module_debug(&l)));

  printf("Freeing paramter oi: %s\n", TEST_FUNC(tnn_param_free(&oi)));
  printf("Destroying paramter q: %s\n", TEST_FUNC(tnn_param_destroy(&q)));
  printf("Destroying pstable t: %s\n", TEST_FUNC(tnn_pstable_destroy(&t)));

  printf("Destroying paramter p: %s\n", TEST_FUNC(tnn_param_destroy(&p)));
  printf("Destroying paramter io: %s\n", TEST_FUNC(tnn_param_destroy(&io)));
  printf("Radomizing weights using polymorphic call: %s\n", TEST_FUNC(tnn_module_randomize(&m, 1.0)));
  printf("Executing fprop using polymorphic call: %s\n", TEST_FUNC(tnn_module_fprop(&m)));
  printf("Executing bprop using polymorphic call: %s\n", TEST_FUNC(tnn_module_bprop(&m)));
  printf("Destroy module m using polymorphic call: %s\n", TEST_FUNC(tnn_module_destroy(&m)));
  return 0;
}