|
2 | 2 | # |
3 | 3 | # SPDX-License-Identifier: Apache-2.0 |
4 | 4 |
|
| 5 | +import logging |
| 6 | + |
5 | 7 | import dpnp |
6 | 8 | import numpy as np |
7 | 9 | from numba.core import types |
@@ -34,14 +36,33 @@ class DpnpRulesArrayOperator(NumpyRulesArrayOperator): |
34 | 36 | @property |
35 | 37 | def ufunc(self): |
36 | 38 | try: |
37 | | - op = getattr(dpnp, self._op_map[self.key]) |
| 39 | + dpnpop = getattr(dpnp, self._op_map[self.key]) |
38 | 40 | npop = getattr(np, self._op_map[self.key]) |
39 | | - op.nin = npop.nin |
40 | | - op.nout = npop.nout |
41 | | - op.nargs = npop.nargs |
42 | | - op.types = npop.types |
43 | | - op.is_dpnp_ufunc = True |
44 | | - return op |
| 41 | + if not hasattr(dpnpop, "nin"): |
| 42 | + dpnpop.nin = npop.nin |
| 43 | + if not hasattr(dpnpop, "nout"): |
| 44 | + dpnpop.nout = npop.nout |
| 45 | + if not hasattr(dpnpop, "nargs"): |
| 46 | + dpnpop.nargs = dpnpop.nin + dpnpop.nout |
| 47 | + |
| 48 | + # Check if the dpnp operation has a `types` attribute and if an |
| 49 | + # AttributeError gets raised then "monkey patch" the attribute from |
| 50 | + # numpy. If the attribute lookup raised a ValueError, it indicates |
| 51 | + # that dpnp could not be resolve the supported types for the |
| 52 | + # operation. Dpnp will fail to resolve the `types` if no SYCL |
| 53 | + # devices are available on the system. For such a scenario, we print |
| 54 | + # a user-level warning. |
| 55 | + try: |
| 56 | + dpnpop.types |
| 57 | + except ValueError: |
| 58 | + logging.exception( |
| 59 | + f"The types attribute for the {dpnpop} fuction could not " |
| 60 | + "be determined." |
| 61 | + ) |
| 62 | + except AttributeError: |
| 63 | + dpnpop.types = npop.types |
| 64 | + dpnpop.is_dpnp_ufunc = True |
| 65 | + return dpnpop |
45 | 66 | except: |
46 | 67 | pass |
47 | 68 |
|
|
0 commit comments