Skip to content

Commit

Permalink
remove evalf debug checker meta class
Browse files Browse the repository at this point in the history
`evaluable.compile` adds debug checks to output of every compiled `Array`. If
an `Evaluable` compiles itself using `Evaluable.evalf` the debug checker meta
class double checks the output. This patch removes the latter.
  • Loading branch information
joostvanzwieten committed May 6, 2024
1 parent 22e18d6 commit 2b92604
Showing 1 changed file with 0 additions and 27 deletions.
27 changes: 0 additions & 27 deletions nutils/evaluable.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,33 +703,6 @@ def __new__(mcls, name, bases, namespace):
namespace['_assparse'] = _chunked_assparse_checker(namespace['_assparse'])
return super().__new__(mcls, name, bases, namespace)

if debug_flags.evalf:
class _evalf_checker:
def __init__(self, orig):
self.orig = orig

def __set_name__(self, owner, name):
if hasattr(self.orig, '__set_name__'):
self.orig.__set_name__(owner, name)

def __get__(self, instance, owner):
evalf = self.orig.__get__(instance, owner)

@functools.wraps(evalf)
def evalf_with_check(*args, **kwargs):
res = evalf(*args, **kwargs)
assert not hasattr(instance, 'dtype') or asdtype(res.dtype) == instance.dtype, ((instance.dtype, res.dtype), instance, res)
assert not hasattr(instance, 'ndim') or res.ndim == instance.ndim
assert not hasattr(instance, 'shape') or all(m == n for m, n in zip(res.shape, instance.shape) if isinstance(n, int)), 'shape mismatch'
return res
return evalf_with_check

class _ArrayMeta(_ArrayMeta):
def __new__(mcls, name, bases, namespace):
if 'evalf' in namespace:
namespace['evalf'] = _evalf_checker(namespace['evalf'])
return super().__new__(mcls, name, bases, namespace)


class AsEvaluableArray(Protocol):
'Protocol for conversion into an :class:`Array`.'
Expand Down

0 comments on commit 2b92604

Please sign in to comment.