From c02a14ba379bed7475a595f3cf6557ca99d8e078 Mon Sep 17 00:00:00 2001 From: Florian Agbuya Date: Mon, 18 Sep 2023 17:51:44 +0800 Subject: [PATCH] compiler: fix lit tests numpy.transpose error (#2190) --- artiq/compiler/embedding.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/artiq/compiler/embedding.py b/artiq/compiler/embedding.py index 8eb5cfae2..f695029cf 100644 --- a/artiq/compiler/embedding.py +++ b/artiq/compiler/embedding.py @@ -18,6 +18,13 @@ from . import types, builtins, asttyped, math_fns, prelude from .transforms import ASTTypedRewriter, Inferencer, IntMonomorphizer, TypedtreePrinter from .transforms.asttyped_rewriter import LocalExtractor +try: + # From numpy=1.25.0 dispatching for `__array_function__` is done via + # a C wrapper: https://github.com/numpy/numpy/pull/23020 + from numpy.core._multiarray_umath import _ArrayFunctionDispatcher +except ImportError: + _ArrayFunctionDispatcher = None + class SpecializedFunction: def __init__(self, instance_type, host_function): @@ -336,7 +343,9 @@ class ASTSynthesizer: elif inspect.isfunction(value) or inspect.ismethod(value) or \ isinstance(value, pytypes.BuiltinFunctionType) or \ isinstance(value, SpecializedFunction) or \ - isinstance(value, numpy.ufunc): + isinstance(value, numpy.ufunc) or \ + (isinstance(value, _ArrayFunctionDispatcher) if + _ArrayFunctionDispatcher is not None else False): if inspect.ismethod(value): quoted_self = self.quote(value.__self__) function_type = self.quote_function(value.__func__, self.expanded_from)