[docs]deftranslate(proto:ModelProto,single_line:bool=False,api:str="light")->str:""" Translates an ONNX proto into a code using :ref:`l-light-api` to describe the ONNX graph. :param proto: model to translate :param single_line: as a single line or not :param api: API to export into, default is `"light"` and this is handle by class :class:`onnx_array_api.translate_api.light_emitter.LightEmitter`, another value is `"onnx"` which is the inner API implemented in onnx package, `"builder"` follows the syntax for the class :class:`onnx_array_api.graph_api.GraphBuilder` :return: code .. runpython:: :showcode: from onnx_array_api.light_api import start from onnx_array_api.translate_api import translate onx = ( start() .vin("X") .reshape((-1, 1)) .Transpose(perm=[1, 0]) .rename("Y") .vout() .to_onnx() ) code = translate(onx) print(code) The inner API from onnx package is also available. .. runpython:: :showcode: from onnx_array_api.light_api import start from onnx_array_api.translate_api import translate onx = ( start() .vin("X") .reshape((-1, 1)) .Transpose(perm=[1, 0]) .rename("Y") .vout() .to_onnx() ) code = translate(onx, api="onnx") print(code) The :class:`GraphBuilder <onnx_array_api.graph_api.GraphBuilder>` API returns this: .. runpython:: :showcode: from onnx_array_api.light_api import start from onnx_array_api.translate_api import translate onx = ( start() .vin("X") .reshape((-1, 1)) .Transpose(perm=[1, 0]) .rename("Y") .vout() .to_onnx() ) code = translate(onx, api="builder") print(code) """ifapi=="light":tr=Translater(proto)returntr.export(single_line=single_line,as_str=True)ifapi=="onnx":tr=Translater(proto,emitter=InnerEmitter())returntr.export(as_str=True)ifapi=="builder":tr=Translater(proto,emitter=BuilderEmitter())returntr.export(as_str=True)raiseValueError(f"Unexpected value {api!r} for api.")