string Weaver::Serialize()

in tensorflow_fold/loom/weaver.cc [249:292]


string Weaver::Serialize() const {
  WeaverMessage message;

  for (const LoomResult &r : loom_results_) {
    message.add_depth(r.depth);
    message.add_ts_idx(r.ts_idx);
    message.add_op_idx(r.op_idx);
    message.add_op_output_idx(r.op_output_idx);
    message.add_pos_idx(r.pos_idx);
    message.add_cached_passthrough(r.cached_passthrough);
  }

  for (tensor_idx_t ts_idx = 0; ts_idx < num_type_shapes_ ; ++ts_idx) {
    message.add_num_constants_by_type_shape(
        num_constants_by_type_shape_[ts_idx]);
    TensorProto *constants = message.add_constant_values_by_type_shape();
    Tensor stacked = BatchConstantValues(ts_idx);
    stacked.AsProtoTensorContent(constants);
  }

  for (const auto &pair : wiring_results_) {
    tensor_idx_t depth, op_idx, arg_idx;
    std::tie(depth, op_idx, arg_idx) = pair.first;
    auto *wiring = message.add_wiring();
    wiring->set_depth(depth);
    wiring->set_op_idx(op_idx);
    wiring->set_arg_idx(arg_idx);
    for (tensor_idx_t result_id : pair.second) {
      wiring->add_result_id(result_id);
    }
  }

  for (tensor_idx_t result_id : output_result_ids_) {
    message.add_output_result_id(result_id);
  }

  string result;
  if (!message.SerializeToString(&result)) {
    error_string_ = "Serialization to WeaverMessage failed.  "
        "Did you run into the protocol buffer size limit?";
    return "";
  }
  return result;
}