@@ -45,11 +45,83 @@ The objective is to speed up the implementation of converter libraries.
4545CHANGELOGS
4646license
4747
48+ Sources available on
49+ `github/onnx-array-api <https://github.com/sdpython/onnx-array-api >`_.
50+
51+ GraphBuilder API
52+ ++++++++++++++++
53+
54+ Almost every converting library (converting a machine learned model to ONNX) is implementing
55+ its own graph builder and customizes it for its needs.
56+ It handles some frequent tasks such as giving names to intermediate
57+ results, loading, saving onnx models. It can be used as well to extend an existing graph.
58+ See:ref: `l-graph-api `.
59+
60+ ..runpython ::
61+ :showcode:
62+
63+ import numpy as np
64+ from onnx_array_api.graph_api import GraphBuilder
65+ from onnx_array_api.plotting.text_plot import onnx_simple_text_plot
66+
67+ g = GraphBuilder()
68+ g.make_tensor_input("X", np.float32, (None, None))
69+ g.make_tensor_input("Y", np.float32, (None, None))
70+ r1 = g.make_node("Sub", ["X", "Y"]) # the name given to the output is given by the class,
71+ # it ensures the name is unique
72+ init = g.make_initializer(np.array([2], dtype=np.int64)) # the class automatically
73+ # converts the array to a tensor
74+ r2 = g.make_node("Pow", [r1, init])
75+ g.make_node("ReduceSum", [r2], outputs=["Z"]) # the output name is given because
76+ # the user wants to choose the name
77+ g.make_tensor_output("Z", np.float32, (None, None))
78+
79+ onx = g.to_onnx() # final conversion to onnx
80+
81+ print(onnx_simple_text_plot(onx))
82+
83+ Light API
84+ +++++++++
85+
86+ The syntax is inspired from the
87+ `Reverse Polish Notation <https://en.wikipedia.org/wiki/Reverse_Polish_notation >`_.
88+ This kind of API is easy to use to build new graphs,
89+ less easy to extend an existing graph. See:ref: `l-light-api `.
90+
91+ ..runpython ::
92+ :showcode:
93+
94+ import numpy as np
95+ from onnx_array_api.light_api import start
96+ from onnx_array_api.plotting.text_plot import onnx_simple_text_plot
97+
98+ model = (
99+ start()
100+ .vin("X")
101+ .vin("Y")
102+ .bring("X", "Y")
103+ .Sub()
104+ .rename("dxy")
105+ .cst(np.array([2], dtype=np.int64), "two")
106+ .bring("dxy", "two")
107+ .Pow()
108+ .ReduceSum()
109+ .rename("Z")
110+ .vout()
111+ .to_onnx()
112+ )
113+
114+ print(onnx_simple_text_plot(model))
115+
48116Numpy API
49117+++++++++
50118
51- Sources available on
52- `github/onnx-array-api <https://github.com/sdpython/onnx-array-api >`_.
119+ Writing ONNX graphs requires to know ONNX syntax unless
120+ it is possible to reuse an existing syntax such as:epkg: `numpy `.
121+ This is what this API is doing.
122+ This kind of API is easy to use to build new graphs,
123+ almost impossible to use to extend new graphs as it usually requires
124+ to know onnx for that. See:ref: `l-numpy-api-onnx `.
53125
54126..runpython ::
55127:showcode:
@@ -110,35 +182,6 @@ Sources available on
110182 res = jitted_myloss(x, y)
111183 print(to_dot(jitted_myloss.get_onnx()))
112184
113- Light API
114- +++++++++
115-
116- ..runpython ::
117- :showcode:
118-
119- import numpy as np
120- from onnx_array_api.light_api import start
121- from onnx_array_api.plotting.text_plot import onnx_simple_text_plot
122-
123- model = (
124- start()
125- .vin("X")
126- .vin("Y")
127- .bring("X", "Y")
128- .Sub()
129- .rename("dxy")
130- .cst(np.array([2], dtype=np.int64), "two")
131- .bring("dxy", "two")
132- .Pow()
133- .ReduceSum()
134- .rename("Z")
135- .vout()
136- .to_onnx()
137- )
138-
139- print(onnx_simple_text_plot(model))
140-
141-
142185Older versions
143186++++++++++++++
144187