示例#1
0
文件: net.c 项目: bensteinberg/aleph
// pickle the network!
u8* net_pickle(u8* dst) {
  u32 i;
  op_t* op;
  u32 val = 0;

  // store count of operators
  // (use 4 bytes for alignment)
  dst = pickle_32((u32)(net->numOps), dst);

  // loop over operators
  for(i=0; i<net->numOps; ++i) {
    op = net->ops[i];
    // store type id
    dst = pickle_32(op->type, dst);
    // pickle the operator state (if needed)
    if(op->pickle != NULL) {
      dst = (*(op->pickle))(op, dst);
    }
  }

  // write input nodes
  //  for(i=0; i < (net->numIns + net->numParams); ++i) {
  /// FIXME: doing params is breaking stuff, somehow...!! arg

#if 1
  for(i=0; i < (NET_INS_MAX); ++i) {
    dst = inode_pickle(&(net->ins[i]), dst);
  }

  // write output nodes
  for(i=0; i < NET_OUTS_MAX; ++i) {
    dst = onode_pickle(&(net->outs[i]), dst);
  }
#else
  for(i=0; i < (net->numIns); ++i) {
    dst = inode_pickle(&(net->ins[i]), dst);
  }

  // write output nodes
  for(i=0; i < net->numOuts; ++i) {
    dst = onode_pickle(&(net->outs[i]), dst);
  }
#endif

  // write count of parameters
  val = (u32)(net->numParams);
  dst = pickle_32(val, dst);

  // write parameter nodes (includes value and descriptor)
  for(i=0; i<net->numParams; ++i) {
    dst = param_pickle(&(net->params[i]), dst);
  }

  return dst;
}
示例#2
0
文件: net.c 项目: catfact/aleph-old
// pickle the network!
u8* net_pickle(u8* dst) {
  u32 i;
  op_t* op;
  u32 val = 0;

  // write count of operators
  // ( 4 bytes for alignment)
  dst = pickle_32((u32)(net->numOps), dst);

  // loop over operators
  for(i=0; i<net->numOps; ++i) {
    op = net->ops[i];
    // store type id
    dst = pickle_32(op->type, dst);
    // pickle the operator state (if needed)
    if(op->pickle != NULL) {
      dst = (*(op->pickle))(op, dst);
    }
  }

  // write input nodes
#if 1
  //// all nodes, even unused
  for(i=0; i < (NET_INS_MAX); ++i) {
    dst = inode_pickle(&(net->ins[i]), dst);
  }

  // write output nodes
  for(i=0; i < NET_OUTS_MAX; ++i) {
    dst = onode_pickle(&(net->outs[i]), dst);
  }
#else
  /* for(i=0; i < (net->numIns); ++i) { */
  /*   dst = inode_pickle(&(net->ins[i]), dst); */
  /* } */

  /* // write output nodes */
  /* for(i=0; i < net->numOuts; ++i) { */
  /*   dst = onode_pickle(&(net->outs[i]), dst); */
  /* } */
#endif

  // write count of parameters
  // 4 bytes for alignment
  val = (u32)(net->numParams);
  dst = pickle_32(val, dst);

  // write parameter nodes (includes value and descriptor)
  for(i=0; i<net->numParams; ++i) {
    dst = param_pickle(&(net->params[i]), dst);
  }

  return dst;
}