|
2 | 2 | import sys |
3 | 3 | import warnings |
4 | 4 | from copy import copy |
5 | | -from functools import singledispatch |
6 | 5 | from textwrap import dedent |
7 | 6 |
|
8 | 7 | import numba |
|
21 | 20 | from pytensor.compile.builders import OpFromGraph |
22 | 21 | from pytensor.compile.function.types import add_supervisor_to_fgraph |
23 | 22 | from pytensor.compile.ops import DeepCopyOp |
| 23 | +from pytensor.graph import Op |
24 | 24 | from pytensor.graph.basic import Apply |
25 | 25 | from pytensor.graph.fg import FunctionGraph |
26 | 26 | from pytensor.graph.type import Type |
27 | 27 | from pytensor.ifelse import IfElse |
28 | 28 | from pytensor.link.numba.dispatch.sparse import CSCMatrixType, CSRMatrixType |
| 29 | +from pytensor.link.numba.linker import numba_funcify, numba_typify |
29 | 30 | from pytensor.link.utils import ( |
30 | 31 | compile_function_src, |
31 | 32 | fgraph_to_python, |
@@ -276,11 +277,6 @@ def create_arg_string(x): |
276 | 277 | return args |
277 | 278 |
|
278 | 279 |
|
279 | | -@singledispatch |
280 | | -def numba_typify(data, dtype=None, **kwargs): |
281 | | - return data |
282 | | - |
283 | | - |
284 | 280 | def generate_fallback_impl(op, node=None, storage_map=None, **kwargs): |
285 | 281 | """Create a Numba compatible function from a Pytensor `Op`.""" |
286 | 282 |
|
@@ -326,14 +322,8 @@ def perform(*inputs): |
326 | 322 | return perform |
327 | 323 |
|
328 | 324 |
|
329 | | -@singledispatch |
330 | | -def numba_funcify(op, node=None, storage_map=None, **kwargs): |
331 | | - """Generate a numba function for a given op and apply node. |
332 | | -
|
333 | | - The resulting function will usually use the `no_cpython_wrapper` |
334 | | - argument in numba, so it can not be called directly from python, |
335 | | - but only from other jit functions. |
336 | | - """ |
| 325 | +@numba_funcify.register(Op) |
| 326 | +def numba_funcify_op(op, node=None, storage_map=None, **kwargs): |
337 | 327 | return generate_fallback_impl(op, node, storage_map, **kwargs) |
338 | 328 |
|
339 | 329 |
|
|
0 commit comments