| 1 |
from pypy.interpreter.mixedmodule import MixedModule |
| 2 |
|
| 3 |
|
| 4 |
class MultiArrayModule(MixedModule): |
| 5 |
appleveldefs = { |
| 6 |
'arange': 'app_numpy.arange', |
| 7 |
'add_docstring': 'app_numpy.add_docstring'} |
| 8 |
interpleveldefs = { |
| 9 |
'ndarray': 'ndarray.W_NDimArray', |
| 10 |
'dtype': 'descriptor.W_Dtype', |
| 11 |
'flatiter': 'flatiter.W_FlatIterator', |
| 12 |
'flagsobj': 'flagsobj.W_FlagsObject', |
| 13 |
|
| 14 |
'_reconstruct' : 'ndarray._reconstruct', |
| 15 |
'scalar' : 'ctors.build_scalar', |
| 16 |
'array': 'ctors.array', |
| 17 |
'zeros': 'ctors.zeros', |
| 18 |
'empty': 'ctors.empty', |
| 19 |
'empty_like': 'ctors.empty_like', |
| 20 |
'fromstring': 'ctors.fromstring', |
| 21 |
'frombuffer': 'ctors.frombuffer', |
| 22 |
|
| 23 |
'concatenate': 'arrayops.concatenate', |
| 24 |
'count_nonzero': 'arrayops.count_nonzero', |
| 25 |
'dot': 'arrayops.dot', |
| 26 |
'where': 'arrayops.where', |
| 27 |
'result_type': 'casting.result_type', |
| 28 |
'can_cast': 'casting.can_cast', |
| 29 |
'min_scalar_type': 'casting.min_scalar_type', |
| 30 |
'promote_types': 'casting.w_promote_types', |
| 31 |
|
| 32 |
'set_string_function': 'appbridge.set_string_function', |
| 33 |
'typeinfo': 'descriptor.get_dtype_cache(space).w_typeinfo', |
| 34 |
'nditer': 'nditer.W_NDIter', |
| 35 |
'broadcast': 'broadcast.W_Broadcast', |
| 36 |
|
| 37 |
'set_docstring': 'support.descr_set_docstring', |
| 38 |
'VisibleDeprecationWarning': 'support.W_VisibleDeprecationWarning', |
| 39 |
} |
| 40 |
for c in ['MAXDIMS', 'CLIP', 'WRAP', 'RAISE']: |
| 41 |
interpleveldefs[c] = 'space.wrap(constants.%s)' % c |
| 42 |
|
| 43 |
def startup(self, space): |
| 44 |
from pypy.module.micronumpy.concrete import _setup |
| 45 |
_setup() |
| 46 |
|
| 47 |
|
| 48 |
class UMathModule(MixedModule): |
| 49 |
appleveldefs = {} |
| 50 |
interpleveldefs = { |
| 51 |
'FLOATING_POINT_SUPPORT': 'space.newint(1)', |
| 52 |
'frompyfunc': 'ufuncs.frompyfunc', |
| 53 |
} |
| 54 |
|
| 55 |
for exposed, impl in [ |
| 56 |
("absolute", "absolute"), |
| 57 |
("add", "add"), |
| 58 |
("arccos", "arccos"), |
| 59 |
("arcsin", "arcsin"), |
| 60 |
("arctan", "arctan"), |
| 61 |
("arctan2", "arctan2"), |
| 62 |
("arccosh", "arccosh"), |
| 63 |
("arcsinh", "arcsinh"), |
| 64 |
("arctanh", "arctanh"), |
| 65 |
("conj", "conjugate"), |
| 66 |
("conjugate", "conjugate"), |
| 67 |
("copysign", "copysign"), |
| 68 |
("cos", "cos"), |
| 69 |
("cosh", "cosh"), |
| 70 |
("divide", "divide"), |
| 71 |
("true_divide", "true_divide"), |
| 72 |
("equal", "equal"), |
| 73 |
("exp", "exp"), |
| 74 |
("exp2", "exp2"), |
| 75 |
("expm1", "expm1"), |
| 76 |
("fabs", "fabs"), |
| 77 |
("fmax", "fmax"), |
| 78 |
("fmin", "fmin"), |
| 79 |
("fmod", "fmod"), |
| 80 |
("floor", "floor"), |
| 81 |
("ceil", "ceil"), |
| 82 |
("trunc", "trunc"), |
| 83 |
("greater", "greater"), |
| 84 |
("greater_equal", "greater_equal"), |
| 85 |
("less", "less"), |
| 86 |
("less_equal", "less_equal"), |
| 87 |
("maximum", "maximum"), |
| 88 |
("minimum", "minimum"), |
| 89 |
("mod", "mod"), |
| 90 |
("multiply", "multiply"), |
| 91 |
("negative", "negative"), |
| 92 |
("not_equal", "not_equal"), |
| 93 |
("radians", "radians"), |
| 94 |
("degrees", "degrees"), |
| 95 |
("deg2rad", "radians"), |
| 96 |
("rad2deg", "degrees"), |
| 97 |
("reciprocal", "reciprocal"), |
| 98 |
("rint", "rint"), |
| 99 |
("sign", "sign"), |
| 100 |
("signbit", "signbit"), |
| 101 |
("sin", "sin"), |
| 102 |
("sinh", "sinh"), |
| 103 |
("subtract", "subtract"), |
| 104 |
('sqrt', 'sqrt'), |
| 105 |
('square', 'square'), |
| 106 |
("tan", "tan"), |
| 107 |
("tanh", "tanh"), |
| 108 |
('bitwise_and', 'bitwise_and'), |
| 109 |
('bitwise_or', 'bitwise_or'), |
| 110 |
('bitwise_xor', 'bitwise_xor'), |
| 111 |
('bitwise_not', 'invert'), |
| 112 |
('left_shift', 'left_shift'), |
| 113 |
('right_shift', 'right_shift'), |
| 114 |
('invert', 'invert'), |
| 115 |
('isnan', 'isnan'), |
| 116 |
('isinf', 'isinf'), |
| 117 |
('isfinite', 'isfinite'), |
| 118 |
('logical_and', 'logical_and'), |
| 119 |
('logical_xor', 'logical_xor'), |
| 120 |
('logical_not', 'logical_not'), |
| 121 |
('logical_or', 'logical_or'), |
| 122 |
('log', 'log'), |
| 123 |
('log2', 'log2'), |
| 124 |
('log10', 'log10'), |
| 125 |
('log1p', 'log1p'), |
| 126 |
('power', 'power'), |
| 127 |
('floor_divide', 'floor_divide'), |
| 128 |
('logaddexp', 'logaddexp'), |
| 129 |
('logaddexp2', 'logaddexp2'), |
| 130 |
('real', 'real'), |
| 131 |
('imag', 'imag'), |
| 132 |
]: |
| 133 |
interpleveldefs[exposed] = "ufuncs.get(space).%s" % impl |
| 134 |
|
| 135 |
|
| 136 |
class Module(MixedModule): |
| 137 |
applevel_name = '_numpypy' |
| 138 |
appleveldefs = {} |
| 139 |
interpleveldefs = {} |
| 140 |
submodules = { |
| 141 |
'multiarray': MultiArrayModule, |
| 142 |
'umath': UMathModule, |
| 143 |
} |
| 144 |
|
| 145 |
def setup_after_space_initialization(self): |
| 146 |
from pypy.module.micronumpy.support import W_VisibleDeprecationWarning |
| 147 |
for name, w_type in {'VisibleDeprecationWarning': W_VisibleDeprecationWarning}.items(): |
| 148 |
setattr(self.space, 'w_' + name, self.space.gettypefor(w_type)) |
| 149 |
|