Repository: onnx/onnx
File: onnx/defs/traditionalml/defs.cc (C++)

Code before:
            "The output is a tensor of strings or integers. Its shape will be the same as the input shape.")
        .Attr(
            "cats_strings",
            "The strings of the map. This sequence must be the same length as the 'cats_int64s' sequence",
            AttributeProto::STRINGS,
            OPTIONAL_VALUE)
        .Attr(
            "cats_int64s",
            "The integers of the map. This sequence must be the same length as the 'cats_strings' sequence.",
            AttributeProto::INTS,
            OPTIONAL_VALUE)
        .Attr(
            "default_string",
            "A string to use when an input integer value is not found in the map.<br>One and only one of the "
            "'default_*' attributes must be defined.",
            AttributeProto::STRING,
            std::string("_Unused"))
        .Attr(
            "default_int64",
            "An integer to use when an input string value is not found in the map.<br>One and only one of the "
            "'default_*' attributes must be defined.",
            AttributeProto::INT,
            static_cast<int64_t>(-1))
        .TypeAndShapeInferenceFunction([](InferenceContext& ctx) {
          auto* cats_int64s = ctx.getAttribute("cats_int64s");
          if (nullptr == cats_int64s) {
            fail_shape_inference("Attribute 'cats_int64s' is required.");
          }
          auto* cats_strings = ctx.getAttribute("cats_strings");
          if (nullptr == cats_strings) {
            fail_shape_inference("Attribute 'cats_strings' is required.");
          }
          if (cats_int64s->ints_size() != cats_strings->strings_size()) {
            fail_shape_inference("Attributes 'cats_int64s' and 'cats_strings' are required to be the same length.");
          }
          if (nullptr == ctx.getInputType(0)) {
            return;
          }
          auto input_elem_type = ctx.getInputType(0)->tensor_type().elem_type();
          if (TensorProto::STRING == input_elem_type) {
            updateOutputElemType(ctx, 0, TensorProto::INT64);
          } else if (TensorProto::INT64 == input_elem_type) {
            updateOutputElemType(ctx, 0, TensorProto::STRING);
          }
          if (hasInputShape(ctx, 0)) {
            propagateShapeFromInputToOutput(ctx, 0, 0);
          }
        }));

static const char* DictVectorizer_ver1_doc = R"DOC(
    Uses an index mapping to convert a dictionary to an array.<br>

Review comment (bug):
Is there a need for yoda conditions, or will `cats_int64s == nullptr` do?

Code after:
            "The output is a tensor of strings or integers. Its shape will be the same as the input shape.")
        .Attr(
            "cats_strings",
            "The strings of the map. This sequence must be the same length as the 'cats_int64s' sequence",
            AttributeProto::STRINGS,
            OPTIONAL_VALUE)
        .Attr(
            "cats_int64s",
            "The integers of the map. This sequence must be the same length as the 'cats_strings' sequence.",
            AttributeProto::INTS,
            OPTIONAL_VALUE)
        .Attr(
            "default_string",
            "A string to use when an input integer value is not found in the map.<br>One and only one of the "
            "'default_*' attributes must be defined.",
            AttributeProto::STRING,
            std::string("_Unused"))
        .Attr(
            "default_int64",
            "An integer to use when an input string value is not found in the map.<br>One and only one of the "
            "'default_*' attributes must be defined.",
            AttributeProto::INT,
            static_cast<int64_t>(-1))
        .TypeAndShapeInferenceFunction([](InferenceContext& ctx) {
          auto* cats_int64s = ctx.getAttribute("cats_int64s");
          if (cats_int64s == nullptr) {
            fail_shape_inference("Attribute 'cats_int64s' is required.");
          }
          auto* cats_strings = ctx.getAttribute("cats_strings");
          if (cats_strings == nullptr) {
            fail_shape_inference("Attribute 'cats_strings' is required.");
          }
          if (cats_int64s->ints_size() != cats_strings->strings_size()) {
            fail_shape_inference("Attributes 'cats_int64s' and 'cats_strings' are required to be the same length.");
          }
          if (nullptr == ctx.getInputType(0)) {
            return;
          }
          auto input_elem_type = ctx.getInputType(0)->tensor_type().elem_type();
          if (TensorProto::STRING == input_elem_type) {
            updateOutputElemType(ctx, 0, TensorProto::INT64);
          } else if (TensorProto::INT64 == input_elem_type) {
            updateOutputElemType(ctx, 0, TensorProto::STRING);
          }
          if (hasInputShape(ctx, 0)) {
            propagateShapeFromInputToOutput(ctx, 0, 0);
          }
        }));

static const char* DictVectorizer_ver1_doc = R"DOC(
    Uses an index mapping to convert a dictionary to an array.<br>