onnx_chainer.replace_func.fake_as_funcnode¶
-
onnx_chainer.replace_func.
fake_as_funcnode
(alt_func, name, rename_attributes=None)[source]¶ The target function fakes FunctionNode
The target function is replaced to the alternative function to connect variable node by acting function node.
alt_func
must satisfy the following restrictions.- Inputs includes one or more
chainer.Variable
to trace variables. - Output consists nothing but
ndarray
orchainer.Variable
Even if
alt_func
returnsndarray
, the value forced to be converted tochainer.Variable
. A caller of the target function have to care both cases, returningndarray
andchainer.Variable
.When
alt_func
returnslist
of variable, the wrapped function will also returns multiple variables astuple
. Howeverdict
cannot be return, the wrapped function breaks down the returned values astuple
of values, keys will be ignored.Arguments of
alt_func
except forchainer.Variable
are set as function attributes. Attribute names are setargN
(N is index number) or keyword on default.Example
>>> def func(x, a, b, c=1, d=2): pass >>> # x is variable >>> func = onnx_chainer.replace_func.fake_as_funcnode( ... func, 'CustomNode', ... rename_attributes=[(1, 'value'), ('c', 'y')])
Then
func
will be operated as a function node named “CustomNode”, and'value'
,'b'
,'y'
,'d'
are set as function’s attributes. See tests/test_replace_func.py more details.Parameters: - alt_func (func) – actual called function. There are some constrains, see the above documentation.
- name (str) – function name. This name is used for what ONNX operator to be assigned.
- rename_attributes (list or tuple) – rename attribute name, set list
of
tuple(index_of_args, new_name)
ortuple(kwargs_name, new_name)
Returns: wrapped function, called on exporting.
Return type: func
- Inputs includes one or more