[pypy-commit] pypy numpy-dtype: trying to satisfy the annotator. disabled some functions to simplify debugging temporarily.
justinpeel
noreply at buildbot.pypy.org
Sun Aug 7 03:00:10 CEST 2011
Author: Justin Peel <notmuchtotell at gmail.com>
Branch: numpy-dtype
Changeset: r46343:9fe913a49303
Date: 2011-08-06 19:01 -0600
http://bitbucket.org/pypy/pypy/changeset/9fe913a49303/
Log: trying to satisfy the annotator. disabled some functions to simplify
debugging temporarily.
diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -6,7 +6,7 @@
applevel_name = 'numpy'
interpleveldefs = {
- 'array': 'interp_numarray.SingleDimArray',
+ 'array': 'interp_numarray.BaseArray',
'zeros': 'interp_numarray.zeros',
'empty': 'interp_numarray.zeros',
'ones': 'interp_numarray.ones',
diff --git a/pypy/module/micronumpy/compile.py b/pypy/module/micronumpy/compile.py
--- a/pypy/module/micronumpy/compile.py
+++ b/pypy/module/micronumpy/compile.py
@@ -4,13 +4,13 @@
"""
from pypy.module.micronumpy.interp_dtype import Float64_dtype
-from pypy.module.micronumpy.interp_numarray import FloatWrapper, SingleDimArray, BaseArray
+from pypy.module.micronumpy.interp_numarray import FloatWrapper, create_sdarray, BaseArray
class BogusBytecode(Exception):
pass
def create_array(size):
- a = SingleDimArray(size, Float64_dtype)
+ a = create_sdarray(size, Float64_dtype)
for i in range(size):
a.storage[i] = float(i % 10)
return a
diff --git a/pypy/module/micronumpy/interp_numarray.py b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -2,7 +2,7 @@
from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import TypeDef, GetSetProperty
-from pypy.module.micronumpy.interp_dtype import Dtype, Float64_num, Int32_num, Float64_dtype, get_dtype, find_scalar_dtype, find_result_dtype
+from pypy.module.micronumpy.interp_dtype import Dtype, Float64_num, Int32_num, Float64_dtype, get_dtype, find_scalar_dtype, find_result_dtype, _dtype_list
from pypy.module.micronumpy.interp_support import Signature
from pypy.module.micronumpy import interp_ufuncs
from pypy.objspace.std.floatobject import float2string as float2string_orig
@@ -184,12 +184,12 @@
def descr_any(self, space):
return space.wrap(self._any())
- descr_sum = _reduce_sum_prod_impl(add, 0.0)
- descr_prod = _reduce_sum_prod_impl(mul, 1.0)
- descr_max = _reduce_max_min_impl(maximum)
- descr_min = _reduce_max_min_impl(minimum)
- descr_argmax = _reduce_argmax_argmin_impl(maximum)
- descr_argmin = _reduce_argmax_argmin_impl(minimum)
+# descr_sum = _reduce_sum_prod_impl(add, 0.0)
+# descr_prod = _reduce_sum_prod_impl(mul, 1.0)
+# descr_max = _reduce_max_min_impl(maximum)
+# descr_min = _reduce_max_min_impl(minimum)
+# descr_argmax = _reduce_argmax_argmin_impl(maximum)
+# descr_argmin = _reduce_argmax_argmin_impl(minimum)
def descr_dot(self, space, w_other):
if isinstance(w_other, BaseArray):
@@ -200,11 +200,12 @@
return self.descr_mul(space, w_other)
def _getnums(self, comma):
- kind = self.find_dtype().kind
- if kind == 'f':
- format_func = float2string
- else:
- format_func = str
+ #d = self.find_dtype()
+ #kind = d.kind
+ #if kind == 'f':
+ format_func = float2string
+ #else:
+ # format_func = str
if self.find_size() > 1000:
nums = [
format_func(self.eval(index))
@@ -324,7 +325,7 @@
"""
Intermediate class representing a float literal.
"""
- _immutable_fields_ = ["value", "dtype"]
+ _immutable_fields_ = ["value"]
signature = Signature()
def __init__(self, value, dtype):
@@ -363,7 +364,7 @@
i = 0
signature = self.signature
result_size = self.find_size()
- result = SingleDimArray(result_size, self.dtype)
+ result = create_sdarray(result_size, self.dtype)
while i < result_size:
numpy_driver.jit_merge_point(signature=signature,
result_size=result_size, i=i,
@@ -465,6 +466,7 @@
BaseArray.__init__(self)
self.signature = signature
self.parent = parent
+ self.dtype = parent.dtype
self.invalidates = parent.invalidates
def get_concrete(self):
@@ -488,7 +490,7 @@
raise NotImplementedError
def find_dtype(self):
- return self.parent.dtype
+ return self.dtype
class SingleDimSlice(ViewArray):
_immutable_fields_ = ["start", "stop", "step", "size"]
@@ -527,55 +529,67 @@
def calc_index(self, item):
return (self.start + item * self.step)
-
class SingleDimArray(BaseArray):
signature = Signature()
- def __init__(self, size, dtype):
+ def __init__(self):
BaseArray.__init__(self)
- self.size = size
- self.dtype = dtype
- TP = TPs[dtype.num]
- self.storage = lltype.malloc(TP, size, zero=True,
- flavor='raw', track_allocation=False,
- add_memory_pressure=True)
- # XXX find out why test_zjit explodes with trackign of allocations
def get_concrete(self):
return self
- def get_root_storage(self):
- return self.storage
-
def find_size(self):
return self.size
- def eval(self, i):
- return self.storage[i]
-
def descr_len(self, space):
return space.wrap(self.size)
- def find_dtype(self):
- return self.dtype
-
- def setitem(self, item, value):
- self.invalidated()
- self.storage[item] = value
-
def setslice(self, space, start, stop, step, slice_length, arr):
if step > 0:
self._sliceloop1(start, stop, step, arr, self)
else:
self._sliceloop2(start, stop, step, arr, self)
- def __del__(self):
- lltype.free(self.storage, flavor='raw', track_allocation=False)
+def make_class(num):
+ TP = TPs[num]
+ class TypedSingleDimArray(SingleDimArray):
+ def __init__(self, size, dtype):
+ SingleDimArray.__init__(self)
+ self.size = size
+ self.dtype = dtype
+ self.storage = lltype.malloc(TP, size, zero=True,
+ flavor='raw', track_allocation=False,
+ add_memory_pressure=True)
+ # XXX find out why test_zjit explodes with trackign of allocations
+
+ def get_root_storage(self):
+ return self.storage
+
+ def eval(self, i):
+ return self.storage[i]
+
+ def setitem(self, item, value):
+ self.invalidated()
+ self.storage[item] = value
+
+ def find_dtype(self):
+ return self.dtype
+
+ def __del__(self):
+ lltype.free(self.storage, flavor='raw', track_allocation=False)
+
+ TypedSingleDimArray.__name__ = 'SingleDimArray' + str(num)
+ return TypedSingleDimArray
+
+_array_classes = tuple(make_class(i) for i in xrange(14))
+
+def create_sdarray(L, dtype):
+ return _array_classes[dtype.num](L, dtype)
def new_numarray(space, iterable, dtype):
l = space.listview(iterable)
dtype = get_dtype(space, dtype)
- arr = SingleDimArray(len(l), dtype)
+ arr = create_sdarray(len(l), dtype)
i = 0
unwrap = dtype.unwrap
cast = dtype.cast
@@ -604,11 +618,11 @@
@unwrap_spec(size=int)
def zeros(space, size):
- return space.wrap(SingleDimArray(size, Float64_dtype))
+ return space.wrap(create_sdarray(size, Float64_dtype))
@unwrap_spec(size=int)
def ones(space, size):
- arr = SingleDimArray(size, Float64_dtype)
+ arr = create_sdarray(size, Float64_dtype)
for i in xrange(size):
arr.storage[i] = 1.0
return space.wrap(arr)
@@ -643,14 +657,14 @@
__repr__ = interp2app(BaseArray.descr_repr),
__str__ = interp2app(BaseArray.descr_str),
- mean = interp2app(BaseArray.descr_mean),
- sum = interp2app(BaseArray.descr_sum),
- prod = interp2app(BaseArray.descr_prod),
- max = interp2app(BaseArray.descr_max),
- min = interp2app(BaseArray.descr_min),
- argmax = interp2app(BaseArray.descr_argmax),
- argmin = interp2app(BaseArray.descr_argmin),
- all = interp2app(BaseArray.descr_all),
- any = interp2app(BaseArray.descr_any),
- dot = interp2app(BaseArray.descr_dot),
+# mean = interp2app(BaseArray.descr_mean),
+# sum = interp2app(BaseArray.descr_sum),
+# prod = interp2app(BaseArray.descr_prod),
+# max = interp2app(BaseArray.descr_max),
+# min = interp2app(BaseArray.descr_min),
+# argmax = interp2app(BaseArray.descr_argmax),
+# argmin = interp2app(BaseArray.descr_argmin),
+# all = interp2app(BaseArray.descr_all),
+# any = interp2app(BaseArray.descr_any),
+# dot = interp2app(BaseArray.descr_dot),
)
diff --git a/pypy/module/micronumpy/interp_support.py b/pypy/module/micronumpy/interp_support.py
--- a/pypy/module/micronumpy/interp_support.py
+++ b/pypy/module/micronumpy/interp_support.py
@@ -9,7 +9,7 @@
@unwrap_spec(s=str)
def fromstring(space, s):
- from pypy.module.micronumpy.interp_numarray import SingleDimArray
+ from pypy.module.micronumpy.interp_numarray import create_sdarray
length = len(s)
if length % FLOAT_SIZE == 0:
@@ -18,7 +18,7 @@
raise OperationError(space.w_ValueError, space.wrap(
"string length %d not divisable by %d" % (length, FLOAT_SIZE)))
- a = SingleDimArray(number, Float64_dtype)
+ a = create_sdarray(number, Float64_dtype)
start = 0
end = FLOAT_SIZE
diff --git a/pypy/module/micronumpy/test/test_base.py b/pypy/module/micronumpy/test/test_base.py
--- a/pypy/module/micronumpy/test/test_base.py
+++ b/pypy/module/micronumpy/test/test_base.py
@@ -1,5 +1,5 @@
from pypy.conftest import gettestobjspace
-from pypy.module.micronumpy.interp_numarray import SingleDimArray, FloatWrapper, ScalarWrapper
+from pypy.module.micronumpy.interp_numarray import create_sdarray, FloatWrapper, ScalarWrapper
from pypy.module.micronumpy.interp_dtype import Float64_dtype
class BaseNumpyAppTest(object):
@@ -8,7 +8,7 @@
class TestSignature(object):
def test_binop_signature(self, space):
- ar = SingleDimArray(10, Float64_dtype)
+ ar = create_sdarray(10, Float64_dtype)
v1 = ar.descr_add(space, ar)
v2 = ar.descr_add(space, FloatWrapper(2.0))
assert v1.signature is not v2.signature
@@ -18,7 +18,7 @@
assert v1.signature is v4.signature
def test_slice_signature(self, space):
- ar = SingleDimArray(10, Float64_dtype)
+ ar = create_sdarray(10, Float64_dtype)
v1 = ar.descr_getitem(space, space.wrap(slice(1, 5, 1)))
v2 = ar.descr_getitem(space, space.wrap(slice(4, 6, 1)))
assert v1.signature is v2.signature
diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -67,6 +67,6 @@
('b','Q','d'), ('B','H','H'), ('B','I','I'), ('B','Q','Q'),
('B','h','h'), ('h','H','i'), ('h','i','i'), ('H','i','i'),
('H','I','I'), ('i','I','q'), ('I','q','q'), ('q','Q','d'),
- ('i','f','f'), ('q','f','d'), ('Q','f','d'))
+ ('i','f','f'), ('q','f','d'), ('q','d','d'), ('Q','f','d'))
for d1, d2, dout in tests:
assert (array([1], d1) + array([1], d2)).dtype is dtype(dout)
diff --git a/pypy/module/micronumpy/test/test_zjit.py b/pypy/module/micronumpy/test/test_zjit.py
--- a/pypy/module/micronumpy/test/test_zjit.py
+++ b/pypy/module/micronumpy/test/test_zjit.py
@@ -2,7 +2,7 @@
from pypy.rpython.test.test_llinterp import interpret
from pypy.module.micronumpy.interp_dtype import Float64_dtype
from pypy.module.micronumpy.interp_numarray import (SingleDimArray, Signature,
- FloatWrapper, Call2, SingleDimSlice, add, mul, Call1)
+ FloatWrapper, Call2, SingleDimSlice, add, mul, Call1, create_sdarray)
from pypy.module.micronumpy.interp_ufuncs import negative
from pypy.module.micronumpy.compile import numpy_compile
from pypy.rlib.objectmodel import specialize
@@ -27,7 +27,7 @@
def test_add(self):
def f(i):
- ar = SingleDimArray(i, Float64_dtype)
+ ar = create_sdarray(i, Float64_dtype)
v = Call2(add, ar, ar, Signature())
return v.get_concrete().storage[3]
@@ -39,7 +39,7 @@
def test_floatadd(self):
def f(i):
- ar = SingleDimArray(i, Float64_dtype)
+ ar = create_sdarray(i, Float64_dtype)
v = Call2(add, ar, FloatWrapper(4.5), Signature())
return v.get_concrete().storage[3]
@@ -53,7 +53,7 @@
space = self.space
def f(i):
- ar = SingleDimArray(i, Float64_dtype)
+ ar = create_sdarray(i, Float64_dtype)
return ar.descr_add(space, ar).descr_sum(space)
result = self.meta_interp(f, [5], listops=True, backendopt=True)
@@ -66,7 +66,7 @@
space = self.space
def f(i):
- ar = SingleDimArray(i, Float64_dtype)
+ ar = create_sdarray(i, Float64_dtype)
return ar.descr_add(space, ar).descr_prod(space)
result = self.meta_interp(f, [5], listops=True, backendopt=True)
@@ -79,7 +79,7 @@
space = self.space
def f(i):
- ar = SingleDimArray(i, Float64_dtype)
+ ar = create_sdarray(i, Float64_dtype)
j = 0
while j < i:
ar.get_concrete().storage[j] = float(j)
@@ -97,7 +97,7 @@
space = self.space
def f(i):
- ar = SingleDimArray(i, Float64_dtype)
+ ar = create_sdarray(i, Float64_dtype)
j = 0
while j < i:
ar.get_concrete().storage[j] = float(j)
@@ -115,7 +115,7 @@
space = self.space
def f(i):
- ar = SingleDimArray(i, Float64_dtype)
+ ar = create_sdarray(i, Float64_dtype)
j = 0
while j < i:
ar.get_concrete().storage[j] = float(j)
@@ -133,7 +133,7 @@
space = self.space
def f(i):
- ar = SingleDimArray(i, Float64_dtype)
+ ar = create_sdarray(i, Float64_dtype)
j = 0
while j < i:
ar.get_concrete().storage[j] = 1.0
@@ -149,7 +149,7 @@
space = self.space
def f(i):
- ar = SingleDimArray(i, Float64_dtype)
+ ar = create_sdarray(i, Float64_dtype)
return ar.descr_add(space, ar).descr_any(space)
result = self.meta_interp(f, [5], listops=True, backendopt=True)
@@ -160,7 +160,7 @@
def test_already_forecd(self):
def f(i):
- ar = SingleDimArray(i, Float64_dtype)
+ ar = create_sdarray(i, Float64_dtype)
v1 = Call2(add, ar, FloatWrapper(4.5), Signature())
v2 = Call2(mul, v1, FloatWrapper(4.5), Signature())
v1.force_if_needed()
@@ -178,7 +178,7 @@
def test_ufunc(self):
space = self.space
def f(i):
- ar = SingleDimArray(i, Float64_dtype)
+ ar = create_sdarray(i, Float64_dtype)
v1 = Call2(add, ar, ar, Signature())
v2 = negative(space, v1)
return v2.get_concrete().storage[3]
@@ -195,7 +195,7 @@
def f(i):
add_sig = Signature()
mul_sig = Signature()
- ar = SingleDimArray(i, Float64_dtype)
+ ar = create_sdarray(i, Float64_dtype)
v1 = Call2(add, ar, ar, ar.signature.transition(add_sig))
v2 = negative(space, v1)
@@ -213,7 +213,7 @@
def test_slice(self):
def f(i):
step = 3
- ar = SingleDimArray(step*i, Float64_dtype)
+ ar = create_sdarray(step*i, Float64_dtype)
s = SingleDimSlice(0, step*i, step, i, ar, ar.signature.transition(SingleDimSlice.static_signature))
v = Call2(add, s, s, Signature())
return v.get_concrete().storage[3]
@@ -228,7 +228,7 @@
def f(i):
step1 = 2
step2 = 3
- ar = SingleDimArray(step2*i, Float64_dtype)
+ ar = create_sdarray(step2*i, Float64_dtype)
s1 = SingleDimSlice(0, step1*i, step1, i, ar, ar.signature.transition(SingleDimSlice.static_signature))
s2 = SingleDimSlice(0, step2*i, step2, i, ar, ar.signature.transition(SingleDimSlice.static_signature))
v = Call2(add, s1, s2, Signature())
@@ -245,8 +245,8 @@
def f(i):
step = NonConstant(3)
- ar = SingleDimArray(step*i, Float64_dtype)
- ar2 = SingleDimArray(i, Float64_dtype)
+ ar = create_sdarray(step*i, Float64_dtype)
+ ar2 = create_sdarray(i, Float64_dtype)
ar2.storage[1] = 5.5
if NonConstant(False):
arg = ar2
More information about the pypy-commit
mailing list