bool Weaver::Deserialize()

in tensorflow_fold/loom/weaver.cc [294:343]


bool Weaver::Deserialize(const string &weaver_message) {
  WeaverMessage message;
  if (!message.ParseFromString(weaver_message)) {
    error_string_ = "WeaverMessage couldn't be parsed.";
    return false;
  }

  if (num_constants_by_type_shape_.size() !=
      message.num_constants_by_type_shape_size()) {
    error_string_ =
        "WeaverMessage didn't have the expected number of type-shapes.";
    return false;
  }

  Reset();

  tensor_idx_t num_loom_results = message.depth_size();

  for (tensor_idx_t i = 0; i < num_loom_results; ++i) {
    loom_results_.emplace_back(LoomResultFromMessage(message, i));

    deepest_ = std::max(deepest_, loom_results_.back().depth);
  }

  for (tensor_idx_t ts_idx = 0; ts_idx < num_type_shapes_; ++ts_idx) {
    num_constants_by_type_shape_[ts_idx] =
        message.num_constants_by_type_shape(ts_idx);
    Tensor constants(metadata_.type_shape_metadata(ts_idx).dtype());
    if (!constants.FromProto(message.constant_values_by_type_shape(ts_idx))) {
      error_string_ = StrCat(
          "Conversion from TensorProto to Tensor failed in deserialization.  ",
          "ts_idx=", ts_idx);
      return false;
    }
    constant_values_by_type_shape_[ts_idx] = UnstackTensors(constants);
  }

  for (const auto &w : message.wiring()) {
    std::vector<tensor_idx_t> result_ids(
        w.result_id().begin(), w.result_id().end());
    auto key = std::make_tuple(w.depth(), w.op_idx(), w.arg_idx());
    wiring_results_.emplace_hint(wiring_results_.end(), key, result_ids);
  }

  output_result_ids_.insert(
      output_result_ids_.end(),
      message.output_result_id().begin(),
      message.output_result_id().end());
  return true;
}