TVM Packed Function.
| 25 | * TVM Packed Function. |
| 26 | */ |
| 27 | public class Function extends TVMObject { |
| 28 | /** |
| 29 | * Get registered function. |
| 30 | * @param name full function name. |
| 31 | * @return TVM function. |
| 32 | */ |
| 33 | public static Function getFunction(final String name) { |
| 34 | return getGlobalFunc(name, true); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Get list of global functions registered. |
| 39 | * @return List of global functions names. |
| 40 | */ |
| 41 | private static List<String> listGlobalFuncNames() { |
| 42 | List<String> names = new ArrayList<String>(); |
| 43 | Base.checkCall(Base._LIB.tvmFFIFunctionListGlobalNames(names)); |
| 44 | return Collections.unmodifiableList(names); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Get a global function by name. |
| 49 | * @param name The name of the function. |
| 50 | * @param allowMissing Whether allow missing function or raise an error. |
| 51 | * @return The function to be returned, None if function is missing. |
| 52 | */ |
| 53 | private static Function getGlobalFunc(String name, boolean allowMissing) { |
| 54 | Base.RefLong handle = new Base.RefLong(); |
| 55 | Base.checkCall(Base._LIB.tvmFFIFunctionGetGlobal(name, handle)); |
| 56 | if (handle.value != 0) { |
| 57 | return new Function(handle.value); |
| 58 | } else { |
| 59 | if (allowMissing) { |
| 60 | return null; |
| 61 | } else { |
| 62 | throw new IllegalArgumentException("Cannot find global function " + name); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | Function(long handle) { |
| 68 | super(handle, TypeIndex.kTVMFFIFunction); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Easy for user to get the instance from returned TVMValue. |
| 73 | * @return this |
| 74 | */ |
| 75 | @Override |
| 76 | public Function asFunction() { |
| 77 | return this; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Invoke the function. |
| 82 | * @return the result. |
| 83 | */ |
| 84 | public TVMValue invoke() { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…