Repository: onnx/onnx
File: onnx/cpp2py_export.cc (C++)

Code before:
    }
    std::string data;
    attr->SerializeToString(&data);
    return py::bytes(data);
  });
  inference_ctx.def("get_num_inputs", &InferenceContext::getNumInputs);
  inference_ctx.def("has_input", &InferenceContext::hasInput);
  inference_ctx.def("__get_input_type", [](InferenceContext* ctx, size_t index) {
    if (ctx == nullptr) {
      fail_shape_inference("Internal error: `ctx` is nullptr in `__get_input_type`");
    }
    auto type = ctx->getInputType(index);
    if (type == nullptr) {
      fail_shape_inference("Internal error: `type` is nullptr in `__get_input_type`");
    }
    std::string data;
    type->SerializeToString(&data);
    return py::bytes(data);
  });
  inference_ctx.def("__get_input_data", [](InferenceContext* ctx, size_t index) {
    if (ctx == nullptr) {
      fail_shape_inference("Internal error: `ctx` is nullptr in `__get_input_data`");
    }
    auto tensor = ctx->getInputData(index);
    if (tensor == nullptr) {
      fail_shape_inference("Internal error: `tensor` is nullptr in `__get_input_data`");
    }
    std::string data;
    tensor->SerializeToString(&data);
    return py::bytes(data);
  });
  inference_ctx.def("__get_input_sparse_data", [](InferenceContext* ctx, size_t index) {
    if (ctx == nullptr) {
      fail_shape_inference("Internal error: `ctx` is nullptr in `__get_input_sparse_data`");
    }
    auto stensor = ctx->getInputSparseData(index);
    if (stensor == nullptr) {
      fail_shape_inference("Internal error: `stensor` is nullptr in `__get_input_sparse_data`");
    }
    std::string data;
    stensor->SerializeToString(&data);
    return py::bytes(data);
  });
  inference_ctx.def("__get_symbolic_input", [](InferenceContext* ctx, size_t index) {
    if (ctx == nullptr) {
      fail_shape_inference("Internal error: `ctx` is nullptr in `__get_symbolic_input`");
    }
    auto shape = ctx->getSymbolicInput(index);
    if (shape == nullptr) {
      fail_shape_inference("Internal error: `shape` is nullptr in `__get_symbolic_input`");
    }

Review comment (suggestion):
Again, not an error. Signifies no static-constant-value is known for this input. Best to map this to `None` or some similar thing

Code after:
        ParseProtoFromPyBytes(&proto, bytes);
        checker::check_model(proto, full_check, skip_opset_compatibility_check, check_custom_domain);
      },
      "bytes"_a,
      "full_check"_a = false,
      "skip_opset_compatibility_check"_a = false,
      "check_custom_domain"_a = false);

  checker.def(
      "check_model_path",
      (void (*)(
          const std::string& path,
          bool full_check,
          bool skip_opset_compatibility_check,
          bool check_custom_domain))&checker::check_model,
      "path"_a,
      "full_check"_a = false,
      "skip_opset_compatibility_check"_a = false,
      "check_custom_domain"_a = false);

  checker.def("_resolve_external_data_location", &checker::resolve_external_data_location);

  // Submodule `version_converter`
  auto version_converter = onnx_cpp2py_export.def_submodule("version_converter");
  version_converter.doc() = "VersionConverter submodule";
  py::register_exception<ConvertError>(version_converter, "ConvertError");

  version_converter.def("convert_version", [](const py::bytes& bytes, const py::int_& target) {
    ModelProto proto{};
    ParseProtoFromPyBytes(&proto, bytes);
    shape_inference::InferShapes(proto);
    auto result = version_conversion::ConvertVersion(proto, target);
    std::string out;
    result.SerializeToString(&out);
    return py::bytes(out);
  });

  // Submodule `inliner`
  auto inliner = onnx_cpp2py_export.def_submodule("inliner");
  inliner.doc() = "Inliner submodule";

  inliner.def("inline_local_functions", [](const py::bytes& bytes, bool convert_version) {
    ModelProto model{};
    ParseProtoFromPyBytes(&model, bytes);
    inliner::InlineLocalFunctions(model, convert_version);
    std::string out;
    model.SerializeToString(&out);
    return py::bytes(out);
  });

  // inline_selected_functions: Inlines all functions specified in function_ids, unless