function¶
dragon.
function
(
func=None,
input_signature=None
)[source]¶Compile a function into the callable graph.
Only the tensor operations could be compiled:
def foo(x, y): return dragon.math.add([x + y, x]) bar = dragon.function(foo) print(bar(1, 2))
Above usages which can simplified as follows:
@dragon.function def foo(x, y): return dragon.math.add([x + y, x]) print(foo(1, 2))
Tensor shape and dtype will be required sometimes:
@dragon.function(input_signature=[ dragon.Tensor(shape=[], dtype='float32'), dragon.Tensor(shape=[], dtype='float32')]) def foo(x, y): return dragon.math.add([x + y, x]) print(foo(1, 2))
- Parameters:
- func (callable, optional) – The function to be compiled.
- input_signature (Sequence[dragon.Tensor], optional) – The tensors to hint the input.
- Returns:
callable – A callable to execute the compiled function.