77from typing import Any , Dict , Generic , Optional , Tuple , TypeVar , Union
88
99import mpmath
10+ import numpy
1011import sympy
1112from sympy .core import numbers as sympy_numbers
1213
13- try : # pragma: no cover - optional dependency handled at runtime
14- import numpy
15- except ImportError : # pragma: no cover - numpy is optional at import time
16- numpy = None
17-
1814from mathics .core .element import BoxElementMixin , ImmutableValueMixin
1915from mathics .core .keycomparable import (
2016 BASIC_ATOM_BYTEARRAY_ELT_ORDER ,
@@ -1108,27 +1104,24 @@ def is_zero(self) -> bool:
11081104# NumericArray
11091105#
11101106
1111- if numpy is not None :
1112- NUMERIC_ARRAY_TYPE_MAP = {
1113- "UnsignedInteger8" : numpy .dtype ("uint8" ),
1114- "UnsignedInteger16" : numpy .dtype ("uint16" ),
1115- "UnsignedInteger32" : numpy .dtype ("uint32" ),
1116- "UnsignedInteger64" : numpy .dtype ("uint64" ),
1117- "Integer8" : numpy .dtype ("int8" ),
1118- "Integer16" : numpy .dtype ("int16" ),
1119- "Integer32" : numpy .dtype ("int32" ),
1120- "Integer64" : numpy .dtype ("int64" ),
1121- "Real32" : numpy .dtype ("float32" ),
1122- "Real64" : numpy .dtype ("float64" ),
1123- "ComplexReal32" : numpy .dtype ("complex64" ),
1124- "ComplexReal64" : numpy .dtype ("complex128" ),
1125- }
1126- NUMERIC_ARRAY_DTYPE_TO_NAME = {
1127- dtype : name for name , dtype in NUMERIC_ARRAY_TYPE_MAP .items ()
1128- }
1129- else : # pragma: no cover - executed only when numpy is absent
1130- NUMERIC_ARRAY_TYPE_MAP = {}
1131- NUMERIC_ARRAY_DTYPE_TO_NAME = {}
1107+ NUMERIC_ARRAY_TYPE_MAP = {
1108+ "UnsignedInteger8" : numpy .dtype ("uint8" ),
1109+ "UnsignedInteger16" : numpy .dtype ("uint16" ),
1110+ "UnsignedInteger32" : numpy .dtype ("uint32" ),
1111+ "UnsignedInteger64" : numpy .dtype ("uint64" ),
1112+ "Integer8" : numpy .dtype ("int8" ),
1113+ "Integer16" : numpy .dtype ("int16" ),
1114+ "Integer32" : numpy .dtype ("int32" ),
1115+ "Integer64" : numpy .dtype ("int64" ),
1116+ "Real32" : numpy .dtype ("float32" ),
1117+ "Real64" : numpy .dtype ("float64" ),
1118+ "ComplexReal32" : numpy .dtype ("complex64" ),
1119+ "ComplexReal64" : numpy .dtype ("complex128" ),
1120+ }
1121+
1122+ NUMERIC_ARRAY_DTYPE_TO_NAME = {
1123+ dtype : name for name , dtype in NUMERIC_ARRAY_TYPE_MAP .items ()
1124+ }
11321125
11331126
11341127class NumericArray (Atom , ImmutableValueMixin ):
@@ -1140,8 +1133,6 @@ class NumericArray(Atom, ImmutableValueMixin):
11401133 class_head_name = "NumericArray"
11411134
11421135 def __init__ (self , value , dtype = None ):
1143- if numpy is None :
1144- raise ImportError ("numpy is required for NumericArray" )
11451136
11461137 # compute value
11471138 if not isinstance (value , numpy .ndarray ):
0 commit comments