From ba5548ebcc7f434018b9e215d38090b995554e91 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Fri, 21 Nov 2008 20:17:00 -0500 Subject: [PATCH] Automatically register numpy scalars as constants, if available. --- src/primitives.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/primitives.py b/src/primitives.py index d8361b4..851c769 100644 --- a/src/primitives.py +++ b/src/primitives.py @@ -624,9 +624,18 @@ def quotient(numerator, denominator): # tool functions -------------------------------------------------------------- +global VALID_CONSTANT_CLASSES +global VALID_OPERANDS VALID_CONSTANT_CLASSES = (int, float, complex) VALID_OPERANDS = (Expression,) +try: + import numpy + VALID_CONSTANT_CLASSES += (numpy.number,) +except ImportError: + pass + + def is_constant(value): @@ -639,9 +648,13 @@ def is_valid_operand(value): def register_constant_class(class_): + global VALID_CONSTANT_CLASSES + VALID_CONSTANT_CLASSES += (class_,) def unregister_constant_class(class_): + global VALID_CONSTANT_CLASSES + tmp = list(VALID_CONSTANT_CLASSES) tmp.remove(class_) VALID_CONSTANT_CLASSES = tuple(tmp) @@ -660,6 +673,3 @@ def is_zero(value): - - - -- GitLab