code: def main(args: Args) -> None:
      base_dir = os.path.dirname(
          os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
      )
      docs_dir = os.path.join(base_dir, "docs")
  
      with open(
          os.path.join(docs_dir, args.changelog),
          "w",
          newline="",
          encoding="utf-8",
      ) as fout:
          fout.write("<!--- SPDX-License-Identifier: Apache-2.0 -->\n")
          fout.write("## Operator Changelog\n")
          fout.write(
              "*This file is automatically generated from the\n"
              "            [def files](/onnx/defs) via [this script](/onnx/defs/gen_doc.py).\n"
              "            Do not modify directly and instead edit operator definitions.*\n"
              "\n"
              "For an operator input/output's differentiability, it can be differentiable,\n"
              "            non-differentiable, or undefined. If a variable's differentiability\n"
              "            is not specified, that variable has undefined differentiability.\n"
          )
  
          # domain -> version -> [schema]
          dv_index: Dict[str, Dict[int, List[OpSchema]]] = defaultdict(
              lambda: defaultdict(list)
          )
          for schema in defs.get_all_schemas_with_history():
              dv_index[schema.domain][schema.since_version].append(
                  schema
              )
  
          fout.write("\n")
  
          for domain, versionmap in sorted(dv_index.items()):
              if not should_render_domain(domain, args.output):
                  continue
  
              s = f"# {display_domain_short(domain)}\n"
  
              for version, unsorted_schemas in sorted(
                  versionmap.items()
              ):
                  s += f"## Version {version} of {display_domain(domain)}\n"
                  for schema in sorted(
                      unsorted_schemas, key=lambda s: s.name
                  ):
                      name_with_ver = f"{format_name_with_domain(domain, schema.name)}-{schema.since_version}"
                      s += (
                          '### <a name="{}"></a>**{}**'
                          + (
                              " (deprecated)"
                              if schema.deprecated
                              else ""
                          )
                          + "</a>\n"
                      ).format(name_with_ver, name_with_ver)
                      s += display_schema(
                          schema, [schema], args.changelog
                      )
                      s += "\n"
  
              fout.write(s)
  
      with open(
          os.path.join(docs_dir, args.output),
          "w",
          newline="",
          encoding="utf-8",
      ) as fout:
          fout.write("<!--- SPDX-License-Identifier: Apache-2.0 -->\n")
          fout.write("## Operator Schemas\n")
          fout.write(
              "*This file is automatically generated from the\n"
              "            [def files](/onnx/defs) via [this script](/onnx/defs/gen_doc.py).\n"
              "            Do not modify directly and instead edit operator definitions.*\n"
              "\n"
              "For an operator input/output's differentiability, it can be differentiable,\n"
              "            non-differentiable, or undefined. If a variable's differentiability\n"
              "            is not specified, that variable has undefined differentiability.\n"
          )
  
          # domain -> support level -> name -> [schema]
          index: Dict[
              str, Dict[int, Dict[str, List[OpSchema]]]
          ] = defaultdict(
              lambda: defaultdict(lambda: defaultdict(list))
          )
          for schema in defs.get_all_schemas_with_history():
              index[schema.domain][int(schema.support_level)][
                  schema.name
              ].append(schema)
  
          fout.write("\n")
  
          # Preprocess the Operator Schemas
          # [(domain, [(support_level, [(schema name, current schema, all versions schemas)])])]
          operator_schemas: List[
              Tuple[
                  str,
                  List[
                      Tuple[
                          int,
                          List[Tuple[str, OpSchema, List[OpSchema]]],
                      ]
                  ],
              ]
          ] = []
          existing_ops: Set[str] = set()
          for domain, _supportmap in sorted(index.items()):
              if not should_render_domain(domain, args.output):
                  continue
  
              processed_supportmap = []
              for _support, _namemap in sorted(_supportmap.items()):
                  processed_namemap = []
                  for n, unsorted_versions in sorted(_namemap.items()):
                      versions = sorted(
                          unsorted_versions,
                          key=lambda s: s.since_version,
                      )
                      schema = versions[-1]
                      if schema.name in existing_ops:
                          continue
                      existing_ops.add(schema.name)
                      processed_namemap.append((n, schema, versions))
                  processed_supportmap.append(
                      (_support, processed_namemap)
                  )
              operator_schemas.append((domain, processed_supportmap))
  
          # Table of contents
          for domain, supportmap in operator_schemas:
              s = f"### {display_domain_short(domain)}\n"
              fout.write(s)
  
              fout.write("|**Operator**|**Since version**||\n")
              fout.write("|-|-|-|\n")
  
              function_ops = []
              for _, namemap in supportmap:
                  for n, schema, versions in namemap:
                      if schema.has_function or schema.has_context_dependent_function:  # type: ignore
                          function_versions = schema.all_function_opset_versions  # type: ignore
                          function_ops.append(
                              (n, schema, versions, function_versions)
                          )
                          continue
                      s = '|{}<a href="#{}">{}</a>{}|{}|\n'.format(
                          support_level_str(schema.support_level),
                          format_name_with_domain(domain, n),
                          format_name_with_domain(domain, n),
                          " (deprecated)" if schema.deprecated else "",
                          format_versions(versions, args.changelog),
                      )
                      fout.write(s)
              if function_ops:
                  fout.write(
                      "|**Function**|**Since version**|**Function version**|\n"
                  )
                  for (
                      n,
                      schema,
                      versions,
                      function_versions,
                  ) in function_ops:
                      s = '|{}<a href="#{}">{}</a>|{}|{}|\n'.format(
                          support_level_str(schema.support_level),
                          format_name_with_domain(domain, n),
                          format_name_with_domain(domain, n),
                          format_versions(versions, args.changelog),
                          format_function_versions(function_versions),
                      )
                      fout.write(s)
  
              fout.write("\n")
  
          fout.write("\n")
  
          for domain, supportmap in operator_schemas:
              s = f"## {display_domain_short(domain)}\n"
              fout.write(s)
  
              for _, namemap in supportmap:
                  for op_type, schema, versions in namemap:
                      # op_type
                      s = (
                          '### {}<a name="{}"></a><a name="{}">**{}**'
                          + (
                              " (deprecated)"
                              if schema.deprecated
                              else ""
                          )
                          + "</a>\n"
                      ).format(
                          support_level_str(schema.support_level),
                          format_name_with_domain(domain, op_type),
                          format_name_with_domain(
                              domain, op_type.lower()
                          ),
                          format_name_with_domain(domain, op_type),
                      )
  
                      s += display_schema(
                          schema, versions, args.changelog
                      )
  
                      s += "\n\n"
  
                      if op_type in SNIPPETS:
                          s += "#### Examples\n\n"
                          for summary, code in sorted(
                              SNIPPETS[op_type]
                          ):
                              s += "<details>\n"
                              s += f"<summary>{summary}</summary>\n\n"
                              s += f"```python\n{code}\n```\n\n"
                              s += "</details>\n"
                              s += "\n\n"
                      if op_type.lower() in SAMPLE_IMPLEMENTATIONS:
                          s += "#### Sample Implementation\n\n"
                          s += "<details>\n"
                          s += f"<summary>{op_type}</summary>\n\n"
                          s += f"```python\n{SAMPLE_IMPLEMENTATIONS[op_type.lower()]}\n```\n\n"
                          s += "</details>\n"
                          s += "\n\n"
  
                      fout.write(s)
  
imports: import os
  from collections import defaultdict
  from typing import Any, Dict, List, NamedTuple, Sequence, Set, Tuple
  import numpy
  from onnx import defs, helper
  from onnx.backend.sample.ops import collect_sample_implementations
  from onnx.backend.test.case import collect_snippets
  from onnx.defs import ONNX_ML_DOMAIN, OpSchema
label_desc: Use image node_id 13 for calling a global function with example usage: main(args) without return types