module onnx_tools.onnx_grammar.onnx_translator
#
Short summary#
module mlprodict.onnx_tools.onnx_grammar.onnx_translator
One class which visits a syntax tree.
Classes#
class |
truncated documentation |
---|---|
Class which converts a Python function into something else. It must implements methods visit and depart. |
|
Class which converts a Python function into an ONNX function. It must implements methods visit and depart. … |
Methods#
method |
truncated documentation |
---|---|
Maps default values with parameter names. |
|
Simplifies some operator such as |
|
Leaves a node. |
|
Visits a node. |
|
Exports the parsed python code into something. |
|
Returns an ONNX graph or a piece of code which could generate the graph. |
|
Make a message with line and column information. |
|
Visits a node. |
|
Visits a node. |
Documentation#
One class which visits a syntax tree.
- class mlprodict.onnx_tools.onnx_grammar.onnx_translator.CodeTranslator(visitor)#
Bases:
object
Class which converts a Python function into something else. It must implements methods visit and depart.
- Parameters:
visitor –
CodeNodeVisitor
- __init__(visitor)#
- Parameters:
visitor –
CodeNodeVisitor
- depart(node, info)#
Leaves a node.
- Parameters:
node – visited node
info – info extracted by the visitor
- visit(node, info)#
Visits a node.
- Parameters:
node – visited node
info – info extracted by the visitor
- class mlprodict.onnx_tools.onnx_grammar.onnx_translator.OnnxTranslator(visitor)#
Bases:
CodeTranslator
Class which converts a Python function into an ONNX function. It must implements methods visit and depart.
- Parameters:
visitor –
CodeNodeVisitor
- class Parameter(name, value=('#NODEFAULT#',), annotation=None)#
Bases:
object
Holds parameter information.
- Parameters:
name – parameter name
value – parameter value
- __init__(name, value=('#NODEFAULT#',), annotation=None)#
- Parameters:
name – parameter name
value – parameter value
- __str__()#
Into python syntax.
- static format_value(value)#
Returns a formatted value in python code.
- property formatted_value#
Returns a formatted value in python code.
- __init__(visitor)#
- Parameters:
visitor –
CodeNodeVisitor
- _binary_operators = {'Add': 'Add', 'Div': 'Div', 'MatMult': 'MatMul', 'Mult': 'Mul', 'Pow': 'Pow', 'Sub': 'Sub'}#
- _fix_default_values(code_fct)#
Maps default values with parameter names.
- _get_last(name, info=None)#
- _is_stacked(name)#
- _numpy2onnx_op = {'absolute': 'Abs', 'cos': 'Cos', 'exp': 'Exp', 'inner': 'inner', 'power': 'Pow', 'sin': 'Sin', 'transpose': 'Transpose'}#
- _parameter_mapping = {'Transpose': {'axes': 'perm'}}#
- _post_process(op, node)#
Simplifies some operator such as
OnnxNeg(2)
.
- _unary_operators = {'Sub': 'Neg'}#
- depart(node, info)#
Visits a node.
- Parameters:
node – visited node
info – info extracted by the visitor
- export(context=None, format='code', output_names=None)#
Returns an ONNX graph or a piece of code which could generate the graph.
- Parameters:
context – function used in the function code
format –
'code'
output_names – add code in the final function to overwrite the names of the outputs in the ONNX graph
- Returns:
string or onnx graph
This method is used in function
translate_fct2onnx
. An example of code can be found there.
- make_msg(info)#
Make a message with line and column information.
- visit(node, info)#
Visits a node.
- Parameters:
node – visited node
info – info extracted by the visitor