[pypy-commit] pypy default: provide get_printable_location for numpy

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50895:59d04a0ce4a7
Date: 2011-12-27 13:43 +0200
http://bitbucket.org/pypy/pypy/changeset/59d04a0ce4a7/

Log:provide get_printable_location for numpy

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
@@ -1,6 +1,6 @@
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.gateway import interp2app, unwrap_spec, NoneNotWrapped
+from pypy.interpreter.gateway import interp2app, NoneNotWrapped
 from pypy.interpreter.typedef import TypeDef, GetSetProperty
 from pypy.module.micronumpy import interp_ufuncs, interp_dtype, signature
 from pypy.module.micronumpy.strides import calculate_slice_strides
@@ -14,22 +14,26 @@
 numpy_driver = jit.JitDriver(
 greens=['shapelen', 'sig'],
 virtualizables=['frame'],
-reds=['result_size', 'frame', 'ri', 'self', 'result']
+reds=['result_size', 'frame', 'ri', 'self', 'result'],
+get_printable_location=signature.new_printable_location('numpy'),
 )
 all_driver = jit.JitDriver(
 greens=['shapelen', 'sig'],
 virtualizables=['frame'],
-reds=['frame', 'self', 'dtype']
+reds=['frame', 'self', 'dtype'],
+get_printable_location=signature.new_printable_location('all'),
 )
 any_driver = jit.JitDriver(
 greens=['shapelen', 'sig'],
 virtualizables=['frame'],
-reds=['frame', 'self', 'dtype']
+reds=['frame', 'self', 'dtype'],
+get_printable_location=signature.new_printable_location('any'),
 )
 slice_driver = jit.JitDriver(
 greens=['shapelen', 'sig'],
 virtualizables=['frame'],
-reds=['self', 'frame', 'source', 'res_iter']
+reds=['self', 'frame', 'source', 'res_iter'],
+get_printable_location=signature.new_printable_location('slice'),
 )
 
 def _find_shape_and_elems(space, w_iterable):
@@ -291,7 +295,8 @@
 def _reduce_argmax_argmin_impl(op_name):
 reduce_driver = jit.JitDriver(
 greens=['shapelen', 'sig'],
-reds=['result', 'idx', 'frame', 'self', 'cur_best', 'dtype']
+reds=['result', 'idx', 'frame', 'self', 'cur_best', 'dtype'],
+get_printable_location=signature.new_printable_location(op_name),
 )
 def loop(self):
 sig = self.find_sig()
diff --git a/pypy/module/micronumpy/interp_ufuncs.py 
b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -1,9 +1,10 @@
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.gateway import interp2app, unwrap_spec
+from pypy.interpreter.gateway import interp2app
 from pypy.interpreter.typedef import TypeDef, GetSetProperty, 
interp_attrproperty
-from pypy.module.micronumpy import interp_boxes, interp_dtype, types
-from pypy.module.micronumpy.signature import ReduceSignature, ScalarSignature, 
find_sig
+from pypy.module.micronumpy import interp_boxes, interp_dtype
+from pypy.module.micronumpy.signature import ReduceSignature, ScalarSignature,\
+ find_sig, new_printable_location
 from pypy.rlib import jit
 from pypy.rlib.rarithmetic import LONG_BIT
 from pypy.tool.sourcetools import func_with_new_name
@@ -11,7 +12,8 @@
 reduce_driver = jit.JitDriver(
 greens = ['shapelen', "sig"],
 virtualizables = ["frame"],
-reds = ["frame", "self", "dtype", "value", "obj"]
+reds = ["frame", "self", "dtype", "value", "obj"],
+get_printable_location=new_printable_location('reduce'),
 )
 
 class W_Ufunc(Wrappable):
diff --git a/pypy/module/micronumpy/signature.py 
b/pypy/module/micronumpy/signature.py
--- a/pypy/module/micronumpy/signature.py
+++ b/pypy/module/micronumpy/signature.py
@@ -5,6 +5,11 @@
 from pypy.module.micronumpy.strides import calculate_slice_strides
 from pypy.rlib.jit import hint, unroll_safe, promote
 
+def new_printable_location(driver_name):
+def get_printable_location(shapelen, sig):
+return sig.debug_repr() + ' [%d dims,%s]' % (shapelen, driver_name)
+return get_printable_location
+
 def sigeq(one, two):
 return one.eq(two)
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: pass the loop name around

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50893:2971cd3e5323
Date: 2011-12-27 13:31 +0200
http://bitbucket.org/pypy/pypy/changeset/2971cd3e5323/

Log:pass the loop name around

diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py
--- a/pypy/jit/metainterp/compile.py
+++ b/pypy/jit/metainterp/compile.py
@@ -114,6 +114,7 @@
 
 metainterp_sd = metainterp.staticdata
 jitdriver_sd = metainterp.jitdriver_sd
+history = metainterp.history
 
 jitcell_token = make_jitcell_token(jitdriver_sd)
 part = create_empty_loop(metainterp)
@@ -311,7 +312,10 @@
 metainterp_sd.stats.compiled()
 metainterp_sd.log("compiled new " + type)
 #
-metainterp_sd.logger_ops.log_loop(loop.inputargs, loop.operations, n, 
type, ops_offset)
+loopname = jitdriver_sd.warmstate.get_location_str(greenkey)
+metainterp_sd.logger_ops.log_loop(loop.inputargs, loop.operations, n,
+  type, ops_offset,
+  name=loopname)
 #
 if metainterp_sd.warmrunnerdesc is not None:# for tests
 
metainterp_sd.warmrunnerdesc.memory_manager.keep_loop_alive(original_jitcell_token)
diff --git a/pypy/jit/metainterp/logger.py b/pypy/jit/metainterp/logger.py
--- a/pypy/jit/metainterp/logger.py
+++ b/pypy/jit/metainterp/logger.py
@@ -13,14 +13,14 @@
 self.metainterp_sd = metainterp_sd
 self.guard_number = guard_number
 
-def log_loop(self, inputargs, operations, number=0, type=None, 
ops_offset=None):
+def log_loop(self, inputargs, operations, number=0, type=None, 
ops_offset=None, name=''):
 if type is None:
 debug_start("jit-log-noopt-loop")
 logops = self._log_operations(inputargs, operations, ops_offset)
 debug_stop("jit-log-noopt-loop")
 else:
 debug_start("jit-log-opt-loop")
-debug_print("# Loop", number, ":", type,
+debug_print("# Loop", number, '(%s)' % name , ":", type,
 "with", len(operations), "ops")
 logops = self._log_operations(inputargs, operations, ops_offset)
 debug_stop("jit-log-opt-loop")
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: this can be unrolled sometimes

2011-12-27 Thread alex_gaynor
Author: Alex Gaynor 
Branch: 
Changeset: r50907:653d45fce4df
Date: 2011-12-27 10:15 -0600
http://bitbucket.org/pypy/pypy/changeset/653d45fce4df/

Log:this can be unrolled sometimes

diff --git a/pypy/module/micronumpy/strides.py 
b/pypy/module/micronumpy/strides.py
--- a/pypy/module/micronumpy/strides.py
+++ b/pypy/module/micronumpy/strides.py
@@ -1,4 +1,9 @@
+from pypy.rlib import jit
 
+
+@jit.look_inside_iff(lambda shape, start, strides, backstrides, chunks:
+jit.isconstant(len(chunks))
+)
 def calculate_slice_strides(shape, start, strides, backstrides, chunks):
 rstrides = []
 rbackstrides = []
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] jitviewer default: simplify and reintroduce cssclass, this time saneish

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r182:7d2ec216e348
Date: 2011-12-27 12:25 +0200
http://bitbucket.org/pypy/jitviewer/changeset/7d2ec216e348/

Log:simplify and reintroduce cssclass, this time saneish

diff --git a/_jitviewer/parser.py b/_jitviewer/parser.py
--- a/_jitviewer/parser.py
+++ b/_jitviewer/parser.py
@@ -2,20 +2,6 @@
 import cgi
 from pypy.tool.jitlogparser import parser
 
-class Html(str):
-def __html__(self):
-return self
-
-def plaintext(self):
-# This is not a general way to strip tags, but it's good enough to use
-# in tests
-s = re.sub('<.*?>', '', self)
-s = s.replace("<", "<")
-s = s.replace(">", ">")
-s = s.replace("&", "&")
-return s
-
-
 def cssclass(cls, s, **kwds):
 cls = re.sub("[^\w]", "_", cls)
 attrs = ['%s="%s"' % (name, value) for name, value in kwds.iteritems()]
@@ -26,9 +12,15 @@
 def _new_binop(name):
 name = cgi.escape(name)
 def f(self):
-return '%s = %s %s %s' % (self.getres(), self.getarg(0), name, 
self.getarg(1))
+return '%s = %s %s %s' % (self.wrap_html(self.res),
+  self.wrap_html(self.args[0]),
+  name, self.wrap_html(self.args[1]))
 return f
 
+class Html(str):
+def __html__(self):
+return self
+
 class OpHtml(parser.Op):
 """
 Subclass of Op with human-friendly html representation
@@ -43,11 +35,11 @@
 return "single-operation"
 
 def html_repr(self):
-s = getattr(self, 'repr_' + self.name, self.repr)()
+s = getattr(self, 'repr_' + self.name, self.default_repr)()
 return Html(s)
 
-#def _getvar(self, v):
-#return cssclass(v, v, onmouseover='highlight_var(this)', 
onmouseout='disable_var(this)')
+def wrap_html(self, v):
+return cssclass(v, v, onmouseover='highlight_var(this)', 
onmouseout='disable_var(this)')
 
 for bin_op, name in [('==', 'int_eq'),
  ('!=', 'int_ne'),
@@ -67,20 +59,22 @@
 locals()['repr_' + name] = _new_binop(bin_op)
 
 def repr_guard_true(self):
-return 'guard(%s is true)' % self.getarg(0)
+return 'guard(%s is true)' % self.wrap_html(self.args[0])
 
 def repr_guard_false(self):
-return 'guard(%s is false)' % self.getarg(0)
+return 'guard(%s is false)' % self.wrap_html(self.args[0])
 
 def repr_guard_value(self):
-return 'guard(%s == %s)' % (self.getarg(0), self.getarg(1))
+return 'guard(%s == %s)' % (self.wrap_html(self.args[0]),
+self.wrap_html(self.args[1]))
 
 def repr_guard_isnull(self):
-return 'guard(%s is null)' % self.getarg(0)
+return 'guard(%s is null)' % self.wrap_html(self.args[0])
 
 def repr_getfield_raw(self):
 name, field = self.descr.split(' ')[1].rsplit('.', 1)
-return '%s = ((%s)%s).%s' % (self.getres(), name, self.getarg(0), 
field[2:])
+return '%s = ((%s)%s).%s' % (self.wrap_html(self.res), name,
+ self.wrap_html(self.args[0]), field[2:])
 
 def repr_getfield_gc(self):
 fullname, field = self.descr.split(' ')[1].rsplit('.', 1)
@@ -95,29 +89,40 @@
 field = cssclass('fieldname', field)
 
 obj = self.getarg(0)
-return '%s = ((%s.%s)%s).%s' % (self.getres(), namespace, classname, 
obj, field)
+return '%s = ((%s.%s)%s).%s' % (self.wrap_html(self.res),
+namespace, classname, obj, field)
 
 def repr_getfield_gc_pure(self):
 return self.repr_getfield_gc() + " [pure]"
 
 def repr_setfield_raw(self):
 name, field = self.descr.split(' ')[1].rsplit('.', 1)
-return '((%s)%s).%s = %s' % (name, self.getarg(0), field[2:], 
self.getarg(1))
+return '((%s)%s).%s = %s' % (name, self.wrap_html(self.args[0]),
+ field[2:], self.wrap_html(self.args[1]))
 
 def repr_setfield_gc(self):
 name, field = self.descr.split(' ')[1].rsplit('.', 1)
-return '((%s)%s).%s = %s' % (name, self.getarg(0), field, 
self.getarg(1))
+return '((%s)%s).%s = %s' % (name, self.wrap_html(self.args[0]),
+ field, self.wrap_html(self.args[1]))
 
 def repr_jump(self):
 no = int(re.search("\d+", self.descr).group(0))
 return ("" % no +
-self.repr() + "")
+self.default_repr() + "")
+
+def default_repr(self):
+args = [self.wrap_html(arg) for arg in self.args]
+if self.descr is not None:
+args.append('descr=%s' % cgi.escape(self.descr))
+arglist = ', '.join(args)
+if self.res is not None:
+return '%s = %s(%s)' % (self.wrap_html(self.res), self.name,
+arglist)
+else:
+return '%s(%s)' % (self.name, arglist)
 

[pypy-commit] pypy default: a neat debugging feature

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50902:a8481f7a34ed
Date: 2011-12-27 15:18 +0200
http://bitbucket.org/pypy/pypy/changeset/a8481f7a34ed/

Log:a neat debugging feature

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
@@ -4,6 +4,7 @@
 class PyPyModule(MixedModule):
 interpleveldefs = {
 'debug_repr': 'interp_extras.debug_repr',
+'remove_invalidates': 'interp_extras.remove_invalidates',
 }
 appleveldefs = {}
 
diff --git a/pypy/module/micronumpy/interp_extras.py 
b/pypy/module/micronumpy/interp_extras.py
--- a/pypy/module/micronumpy/interp_extras.py
+++ b/pypy/module/micronumpy/interp_extras.py
@@ -5,3 +5,11 @@
 @unwrap_spec(array=BaseArray)
 def debug_repr(space, array):
 return space.wrap(array.find_sig().debug_repr())
+
+@unwrap_spec(array=BaseArray)
+def remove_invalidates(space, array):
+""" Array modification will no longer invalidate any of it's
+potential children. Use only for performance debugging
+"""
+del array.invalidates[:]
+return space.w_None
diff --git a/pypy/module/micronumpy/test/test_numarray.py 
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -898,6 +898,15 @@
 b[0] = 3
 assert debug_repr(b) == 'Array'
 
+def test_remove_invalidates(self):
+from numpypy import array
+from numpypy.pypy import remove_invalidates
+a = array([1, 2, 3])
+b = a + a
+remove_invalidates(a)
+a[0] = 14
+assert b[0] == 28
+
 def test_virtual_views(self):
 from numpypy import arange
 a = arange(15)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: some simplifications

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50889:7924477d6680
Date: 2011-12-27 12:23 +0200
http://bitbucket.org/pypy/pypy/changeset/7924477d6680/

Log:some simplifications

diff --git a/pypy/tool/jitlogparser/parser.py b/pypy/tool/jitlogparser/parser.py
--- a/pypy/tool/jitlogparser/parser.py
+++ b/pypy/tool/jitlogparser/parser.py
@@ -24,19 +24,13 @@
 self.failargs = failargs
 
 def getarg(self, i):
-return self._getvar(self.args[i])
+return self.args[i]
 
 def getargs(self):
-return [self._getvar(v) for v in self.args]
+return self.args
 
 def getres(self):
-return self._getvar(self.res)
-
-def getdescr(self):
-return self.descr
-
-def _getvar(self, v):
-return v
+return self.res
 
 def is_guard(self):
 return self._is_guard
@@ -44,7 +38,7 @@
 def repr(self):
 args = self.getargs()
 if self.descr is not None:
-args.append('descr=%s' % self.getdescr())
+args.append('descr=%s' % self.descr)
 arglist = ', '.join(args)
 if self.res is not None:
 return '%s = %s(%s)' % (self.getres(), self.name, arglist)
@@ -53,8 +47,6 @@
 
 def __repr__(self):
 return self.repr()
-## return '<%s (%s)>' % (self.name, ', '.join([repr(a)
-## for a in self.args]))
 
 class SimpleParser(OpParser):
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix another test

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50896:13448846544c
Date: 2011-12-27 13:45 +0200
http://bitbucket.org/pypy/pypy/changeset/13448846544c/

Log:fix another test

diff --git a/pypy/jit/metainterp/test/test_logger.py 
b/pypy/jit/metainterp/test/test_logger.py
--- a/pypy/jit/metainterp/test/test_logger.py
+++ b/pypy/jit/metainterp/test/test_logger.py
@@ -180,7 +180,7 @@
 def test_intro_loop(self):
 bare_logger = logger.Logger(self.make_metainterp_sd())
 output = capturing(bare_logger.log_loop, [], [], 1, "foo")
-assert output.splitlines()[0] == "# Loop 1 : foo with 0 ops"
+assert output.splitlines()[0] == "# Loop 1 () : foo with 0 ops"
 pure_parse(output)
 
 def test_intro_bridge(self):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: A guard can't invalidate the heap cache in the metainterp.

2011-12-27 Thread alex_gaynor
Author: Alex Gaynor 
Branch: 
Changeset: r50908:c2d42bf471da
Date: 2011-12-27 10:39 -0600
http://bitbucket.org/pypy/pypy/changeset/c2d42bf471da/

Log:A guard can't invalidate the heap cache in the metainterp.

diff --git a/pypy/jit/metainterp/heapcache.py b/pypy/jit/metainterp/heapcache.py
--- a/pypy/jit/metainterp/heapcache.py
+++ b/pypy/jit/metainterp/heapcache.py
@@ -79,9 +79,9 @@
 opnum == rop.COPYSTRCONTENT or
 opnum == rop.COPYUNICODECONTENT):
 return
-if rop._OVF_FIRST <= opnum <= rop._OVF_LAST:
-return
-if rop._NOSIDEEFFECT_FIRST <= opnum <= rop._NOSIDEEFFECT_LAST:
+if (rop._OVF_FIRST <= opnum <= rop._OVF_LAST or
+rop._NOSIDEEFFECT_FIRST <= opnum <= rop._NOSIDEEFFECT_LAST or
+rop._GUARD_FIRST <= opnum <= rop._GUARD_LAST):
 return
 if opnum == rop.CALL or opnum == rop.CALL_LOOPINVARIANT:
 effectinfo = descr.get_extra_info()
diff --git a/pypy/jit/metainterp/test/test_heapcache.py 
b/pypy/jit/metainterp/test/test_heapcache.py
--- a/pypy/jit/metainterp/test/test_heapcache.py
+++ b/pypy/jit/metainterp/test/test_heapcache.py
@@ -255,6 +255,11 @@
 assert h.getarrayitem(box1, descr1, index1) is box2
 assert h.getarrayitem(box1, descr1, index2) is box4
 
+h.invalidate_caches(rop.GUARD_TRUE, None, [])
+assert h.getfield(box1, descr1) is box2
+assert h.getarrayitem(box1, descr1, index1) is box2
+assert h.getarrayitem(box1, descr1, index2) is box4
+
 h.invalidate_caches(
 rop.CALL_LOOPINVARIANT, 
FakeCallDescr(FakeEffektinfo.EF_LOOPINVARIANT), [])
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: remove some nonsense

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50892:d69a1af57f0c
Date: 2011-12-27 13:28 +0200
http://bitbucket.org/pypy/pypy/changeset/d69a1af57f0c/

Log:remove some nonsense

diff --git a/pypy/jit/metainterp/compile.py b/pypy/jit/metainterp/compile.py
--- a/pypy/jit/metainterp/compile.py
+++ b/pypy/jit/metainterp/compile.py
@@ -112,33 +112,25 @@
 """
 from pypy.jit.metainterp.optimizeopt import optimize_trace
 
-history = metainterp.history
 metainterp_sd = metainterp.staticdata
 jitdriver_sd = metainterp.jitdriver_sd
 
-if False:
-part = partial_trace
-assert False
-procedur_token = metainterp.get_procedure_token(greenkey)
-assert procedure_token
-all_target_tokens = []
-else:
-jitcell_token = make_jitcell_token(jitdriver_sd)
-part = create_empty_loop(metainterp)
-part.inputargs = inputargs[:]
-h_ops = history.operations
-part.resume_at_jump_descr = resume_at_jump_descr
-part.operations = [ResOperation(rop.LABEL, inputargs, None, 
descr=TargetToken(jitcell_token))] + \
-  [h_ops[i].clone() for i in range(start, len(h_ops))] 
+ \
-  [ResOperation(rop.LABEL, jumpargs, None, 
descr=jitcell_token)]
+jitcell_token = make_jitcell_token(jitdriver_sd)
+part = create_empty_loop(metainterp)
+part.inputargs = inputargs[:]
+h_ops = history.operations
+part.resume_at_jump_descr = resume_at_jump_descr
+part.operations = [ResOperation(rop.LABEL, inputargs, None, 
descr=TargetToken(jitcell_token))] + \
+  [h_ops[i].clone() for i in range(start, len(h_ops))] + \
+  [ResOperation(rop.LABEL, jumpargs, None, 
descr=jitcell_token)]
 
-try:
-optimize_trace(metainterp_sd, part, 
jitdriver_sd.warmstate.enable_opts)
-except InvalidLoop:
-return None
-target_token = part.operations[0].getdescr()
-assert isinstance(target_token, TargetToken)
-all_target_tokens = [target_token]
+try:
+optimize_trace(metainterp_sd, part, jitdriver_sd.warmstate.enable_opts)
+except InvalidLoop:
+return None
+target_token = part.operations[0].getdescr()
+assert isinstance(target_token, TargetToken)
+all_target_tokens = [target_token]
 
 loop = create_empty_loop(metainterp)
 loop.inputargs = part.inputargs
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: some fixes

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50887:a91f8bee90b0
Date: 2011-12-27 11:37 +0200
http://bitbucket.org/pypy/pypy/changeset/a91f8bee90b0/

Log:some fixes

diff --git a/pypy/tool/jitlogparser/parser.py b/pypy/tool/jitlogparser/parser.py
--- a/pypy/tool/jitlogparser/parser.py
+++ b/pypy/tool/jitlogparser/parser.py
@@ -147,17 +147,19 @@
 inline_level = None
 
 def __init__(self, operations, storage):
-if operations[0].name == 'debug_merge_point':
-self.inline_level = int(operations[0].args[0])
-m = re.search('\w]+)\. file \'(.+?)\'\. line 
(\d+)> #(\d+) (\w+)',
- operations[0].args[1])
-if m is None:
-# a non-code loop, like StrLiteralSearch or something
-self.bytecode_name = operations[0].args[1][1:-1]
-else:
-self.name, self.filename, lineno, bytecode_no, 
self.bytecode_name = m.groups()
-self.startlineno = int(lineno)
-self.bytecode_no = int(bytecode_no)
+for op in operations:
+if op.name == 'debug_merge_point':
+self.inline_level = int(op.args[0])
+m = re.search('\w]+)\. file \'(.+?)\'\. line 
(\d+)> #(\d+) (\w+)',
+ op.args[1])
+if m is None:
+# a non-code loop, like StrLiteralSearch or something
+self.bytecode_name = op.args[1][1:-1]
+else:
+self.name, self.filename, lineno, bytecode_no, 
self.bytecode_name = m.groups()
+self.startlineno = int(lineno)
+self.bytecode_no = int(bytecode_no)
+break
 self.operations = operations
 self.storage = storage
 self.code = storage.disassemble_code(self.filename, self.startlineno,
@@ -225,6 +227,7 @@
 Also detect inlined functions and make them Function
 """
 stack = []
+seen_dmp = False
 
 def getpath(stack):
 return ",".join([str(len(v)) for v in stack])
@@ -245,11 +248,14 @@
 stack = []
 for op in operations:
 if op.name == 'debug_merge_point':
-if so_far:
-append_to_res(cls.TraceForOpcode(so_far, storage))
-if limit:
-break
-so_far = []
+if seen_dmp:
+if so_far:
+append_to_res(cls.TraceForOpcode(so_far, storage))
+if limit:
+break
+so_far = []
+else:
+seen_dmp = True
 so_far.append(op)
 if so_far:
 append_to_res(cls.TraceForOpcode(so_far, storage))
@@ -405,6 +411,7 @@
 part = copy(trace)
 part.operations = trace.operations[start : stop + 1]
 part.descr = descrs[i]
+part.comment = trace.comment
 parts.append(part)
 
 return parts
diff --git a/pypy/tool/jitlogparser/test/test_parser.py 
b/pypy/tool/jitlogparser/test/test_parser.py
--- a/pypy/tool/jitlogparser/test/test_parser.py
+++ b/pypy/tool/jitlogparser/test/test_parser.py
@@ -38,6 +38,7 @@
 def test_split():
 ops = parse('''
 [i0]
+label()
 debug_merge_point(0, " #10 ADD")
 debug_merge_point(0, " #11 SUB")
 i1 = int_add(i0, 1)
@@ -46,7 +47,7 @@
 ''')
 res = Function.from_operations(ops.operations, LoopStorage())
 assert len(res.chunks) == 3
-assert len(res.chunks[0].operations) == 1
+assert len(res.chunks[0].operations) == 2
 assert len(res.chunks[1].operations) == 2
 assert len(res.chunks[2].operations) == 2
 assert res.chunks[2].bytecode_no == 11
@@ -96,7 +97,7 @@
 i2 = int_add(i1, 1)
 ''')
 res = Function.from_operations(ops.operations, LoopStorage())
-assert res.repr() == res.chunks[1].repr()
+assert res.repr() == res.chunks[0].repr()
 
 def test_lineno():
 fname = str(py.path.local(__file__).join('..', 'x.py'))
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: adjust to new situation

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50903:974244d55fe2
Date: 2011-12-27 16:41 +0200
http://bitbucket.org/pypy/pypy/changeset/974244d55fe2/

Log:adjust to new situation

diff --git a/pypy/tool/jitlogparser/parser.py b/pypy/tool/jitlogparser/parser.py
--- a/pypy/tool/jitlogparser/parser.py
+++ b/pypy/tool/jitlogparser/parser.py
@@ -219,7 +219,6 @@
 Also detect inlined functions and make them Function
 """
 stack = []
-seen_dmp = False
 
 def getpath(stack):
 return ",".join([str(len(v)) for v in stack])
@@ -240,14 +239,11 @@
 stack = []
 for op in operations:
 if op.name == 'debug_merge_point':
-if seen_dmp:
-if so_far:
-append_to_res(cls.TraceForOpcode(so_far, storage))
-if limit:
-break
-so_far = []
-else:
-seen_dmp = True
+if so_far:
+append_to_res(cls.TraceForOpcode(so_far, storage))
+if limit:
+break
+so_far = []
 so_far.append(op)
 if so_far:
 append_to_res(cls.TraceForOpcode(so_far, storage))
@@ -391,7 +387,7 @@
 if trace.comment and 'Guard' in trace.comment:
 descrs = ['bridge ' + re.search('Guard (\d+)', trace.comment).group(1)]
 else:
-descrs = ['']
+descrs = ['entry ' + re.search('Loop (\d+)', trace.comment).group(1)]
 for i, op in enumerate(trace.operations):
 if op.name == 'label':
 labels.append(i)
diff --git a/pypy/tool/jitlogparser/test/test_parser.py 
b/pypy/tool/jitlogparser/test/test_parser.py
--- a/pypy/tool/jitlogparser/test/test_parser.py
+++ b/pypy/tool/jitlogparser/test/test_parser.py
@@ -38,7 +38,6 @@
 def test_split():
 ops = parse('''
 [i0]
-label()
 debug_merge_point(0, " #10 ADD")
 debug_merge_point(0, " #11 SUB")
 i1 = int_add(i0, 1)
@@ -47,7 +46,7 @@
 ''')
 res = Function.from_operations(ops.operations, LoopStorage())
 assert len(res.chunks) == 3
-assert len(res.chunks[0].operations) == 2
+assert len(res.chunks[0].operations) == 1
 assert len(res.chunks[1].operations) == 2
 assert len(res.chunks[2].operations) == 2
 assert res.chunks[2].bytecode_no == 11
@@ -97,7 +96,7 @@
 i2 = int_add(i1, 1)
 ''')
 res = Function.from_operations(ops.operations, LoopStorage())
-assert res.repr() == res.chunks[0].repr()
+assert res.repr() == res.chunks[1].repr()
 
 def test_lineno():
 fname = str(py.path.local(__file__).join('..', 'x.py'))
@@ -246,6 +245,7 @@
 guard_true(i19, descr=) []
 i113 = getfield_raw(151937600, descr=)
 ''')
+loop.comment = 'Loop 0'
 parts = split_trace(loop)
 assert len(parts) == 3
 assert len(parts[0].operations) == 2
@@ -273,7 +273,7 @@
 finish(i0)
 ''')
 bridge.comment = 'bridge out of Guard 2 with 1 ops'
-loop.comment = ''
+loop.comment = 'Loop 0'
 loops = split_trace(loop) + split_trace(bridge)
 input = ['grrr:123\nasb:12\nbridge 2:1234']
 parse_log_counts(input, loops)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: more small fixes

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50891:8417bf8c3a59
Date: 2011-12-27 13:27 +0200
http://bitbucket.org/pypy/pypy/changeset/8417bf8c3a59/

Log:more small fixes

diff --git a/pypy/tool/jitlogparser/parser.py b/pypy/tool/jitlogparser/parser.py
--- a/pypy/tool/jitlogparser/parser.py
+++ b/pypy/tool/jitlogparser/parser.py
@@ -27,7 +27,7 @@
 return self.args[i]
 
 def getargs(self):
-return self.args
+return self.args[:]
 
 def getres(self):
 return self.res
@@ -159,7 +159,7 @@
 
 def repr(self):
 if self.filename is None:
-return "Unknown"
+return self.bytecode_name
 return "%s, file '%s', line %d" % (self.name, self.filename,
self.startlineno)
 
diff --git a/pypy/tool/jitlogparser/test/test_parser.py 
b/pypy/tool/jitlogparser/test/test_parser.py
--- a/pypy/tool/jitlogparser/test/test_parser.py
+++ b/pypy/tool/jitlogparser/test/test_parser.py
@@ -33,7 +33,7 @@
 ''')
 res = Function.from_operations(ops.operations, LoopStorage())
 assert len(res.chunks) == 1
-assert res.chunks[0].repr()
+assert 'SomeRandomStuff' in res.chunks[0].repr()
 
 def test_split():
 ops = parse('''
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: fix the test

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50894:17fd3576a153
Date: 2011-12-27 13:36 +0200
http://bitbucket.org/pypy/pypy/changeset/17fd3576a153/

Log:fix the test

diff --git a/pypy/jit/metainterp/test/test_compile.py 
b/pypy/jit/metainterp/test/test_compile.py
--- a/pypy/jit/metainterp/test/test_compile.py
+++ b/pypy/jit/metainterp/test/test_compile.py
@@ -18,7 +18,7 @@
 self.seen.append((inputargs, operations, token))
 
 class FakeLogger(object):
-def log_loop(self, inputargs, operations, number=0, type=None, 
ops_offset=None):
+def log_loop(self, inputargs, operations, number=0, type=None, 
ops_offset=None, name=''):
 pass
 
 def repr_of_resop(self, op):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: improvements

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50904:6406dbf9a60e
Date: 2011-12-27 16:58 +0200
http://bitbucket.org/pypy/pypy/changeset/6406dbf9a60e/

Log:improvements

diff --git a/pypy/tool/jitlogparser/parser.py b/pypy/tool/jitlogparser/parser.py
--- a/pypy/tool/jitlogparser/parser.py
+++ b/pypy/tool/jitlogparser/parser.py
@@ -138,20 +138,27 @@
 is_bytecode = True
 inline_level = None
 
-def __init__(self, operations, storage):
+def parse_code_data(self, arg):
+m = re.search('\w]+)[\.,] file \'(.+?)\'[\.,] line 
(\d+)> #(\d+) (\w+)',
+  arg)
+if m is None:
+# a non-code loop, like StrLiteralSearch or something
+self.bytecode_name = arg
+else:
+self.name, self.filename, lineno, bytecode_no, self.bytecode_name 
= m.groups()
+self.startlineno = int(lineno)
+self.bytecode_no = int(bytecode_no)
+
+
+def __init__(self, operations, storage, loopname):
 for op in operations:
 if op.name == 'debug_merge_point':
 self.inline_level = int(op.args[0])
-m = re.search('\w]+)\. file \'(.+?)\'\. line 
(\d+)> #(\d+) (\w+)',
- op.args[1])
-if m is None:
-# a non-code loop, like StrLiteralSearch or something
-self.bytecode_name = op.args[1][1:-1]
-else:
-self.name, self.filename, lineno, bytecode_no, 
self.bytecode_name = m.groups()
-self.startlineno = int(lineno)
-self.bytecode_no = int(bytecode_no)
+self.parse_code_data(op.args[1])
 break
+else:
+self.inline_level = 0
+self.parse_code_data(loopname)
 self.operations = operations
 self.storage = storage
 self.code = storage.disassemble_code(self.filename, self.startlineno,
@@ -214,7 +221,8 @@
 self.storage = storage
 
 @classmethod
-def from_operations(cls, operations, storage, limit=None, inputargs=''):
+def from_operations(cls, operations, storage, limit=None, inputargs='',
+loopname=''):
 """ Slice given operation list into a chain of TraceForOpcode chunks.
 Also detect inlined functions and make them Function
 """
@@ -240,13 +248,13 @@
 for op in operations:
 if op.name == 'debug_merge_point':
 if so_far:
-append_to_res(cls.TraceForOpcode(so_far, storage))
+append_to_res(cls.TraceForOpcode(so_far, storage, 
loopname))
 if limit:
 break
 so_far = []
 so_far.append(op)
 if so_far:
-append_to_res(cls.TraceForOpcode(so_far, storage))
+append_to_res(cls.TraceForOpcode(so_far, storage, loopname))
 # wrap stack back up
 if not stack:
 # no ops whatsoever
@@ -294,7 +302,7 @@
 
 def repr(self):
 if self.filename is None:
-return "Unknown"
+return self.chunks[0].bytecode_name
 return "%s, file '%s', line %d" % (self.name, self.filename,
self.startlineno)
 
diff --git a/pypy/tool/jitlogparser/test/test_parser.py 
b/pypy/tool/jitlogparser/test/test_parser.py
--- a/pypy/tool/jitlogparser/test/test_parser.py
+++ b/pypy/tool/jitlogparser/test/test_parser.py
@@ -38,18 +38,21 @@
 def test_split():
 ops = parse('''
 [i0]
+label()
 debug_merge_point(0, " #10 ADD")
 debug_merge_point(0, " #11 SUB")
 i1 = int_add(i0, 1)
 debug_merge_point(0, " #11 SUB")
 i2 = int_add(i1, 1)
 ''')
-res = Function.from_operations(ops.operations, LoopStorage())
-assert len(res.chunks) == 3
+res = Function.from_operations(ops.operations, LoopStorage(), 
loopname='')
+assert len(res.chunks) == 4
 assert len(res.chunks[0].operations) == 1
-assert len(res.chunks[1].operations) == 2
+assert len(res.chunks[1].operations) == 1
 assert len(res.chunks[2].operations) == 2
-assert res.chunks[2].bytecode_no == 11
+assert len(res.chunks[3].operations) == 2
+assert res.chunks[3].bytecode_no == 11
+assert res.chunks[0].bytecode_name == 'loopname'
 
 def test_inlined_call():
 ops = parse("""
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: add some info "we're in re" or "we're in numpy"

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50906:ff4589dda2b1
Date: 2011-12-27 17:09 +0200
http://bitbucket.org/pypy/pypy/changeset/ff4589dda2b1/

Log:add some info "we're in re" or "we're in numpy"

diff --git a/pypy/module/micronumpy/signature.py 
b/pypy/module/micronumpy/signature.py
--- a/pypy/module/micronumpy/signature.py
+++ b/pypy/module/micronumpy/signature.py
@@ -7,7 +7,7 @@
 
 def new_printable_location(driver_name):
 def get_printable_location(shapelen, sig):
-return sig.debug_repr() + ' [%d dims,%s]' % (shapelen, driver_name)
+return 'numpy ' + sig.debug_repr() + ' [%d dims,%s]' % (shapelen, 
driver_name)
 return get_printable_location
 
 def sigeq(one, two):
diff --git a/pypy/rlib/rsre/rsre_jit.py b/pypy/rlib/rsre/rsre_jit.py
--- a/pypy/rlib/rsre/rsre_jit.py
+++ b/pypy/rlib/rsre/rsre_jit.py
@@ -22,7 +22,7 @@
 info = '%s/%d' % (info, args[debugprint[2]])
 else:
 info = ''
-return '%s%s %s' % (name, info, s)
+return 're %s%s %s' % (name, info, s)
 #
 self.get_printable_location = get_printable_location
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: remove some unnecessary dependencies

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50897:ecf82a6d3959
Date: 2011-12-27 13:54 +0200
http://bitbucket.org/pypy/pypy/changeset/ecf82a6d3959/

Log:remove some unnecessary dependencies

diff --git a/pypy/translator/sandbox/pypy_interact.py 
b/pypy/translator/sandbox/pypy_interact.py
--- a/pypy/translator/sandbox/pypy_interact.py
+++ b/pypy/translator/sandbox/pypy_interact.py
@@ -26,7 +26,8 @@
 from pypy.translator.sandbox.sandlib import SimpleIOSandboxedProc
 from pypy.translator.sandbox.sandlib import VirtualizedSandboxedProc
 from pypy.translator.sandbox.vfs import Dir, RealDir, RealFile
-from pypy.tool.lib_pypy import LIB_ROOT
+import pypy
+LIB_ROOT = os.path.dirname(os.path.dirname(pypy.__file__))
 
 class PyPySandboxedProc(VirtualizedSandboxedProc, SimpleIOSandboxedProc):
 debug = True
diff --git a/pypy/translator/sandbox/sandlib.py 
b/pypy/translator/sandbox/sandlib.py
--- a/pypy/translator/sandbox/sandlib.py
+++ b/pypy/translator/sandbox/sandlib.py
@@ -30,8 +30,9 @@
 # load().  Also, marshal.load(f) blocks with the GIL held when
 # f is a pipe with no data immediately avaialble, preventing the
 # _waiting_thread to run.
-from pypy.tool.lib_pypy import import_from_lib_pypy
-marshal = import_from_lib_pypy('marshal')
+import pypy
+marshal = py.path.local(pypy.__file__).join('..', '..', 'lib_pypy',
+'marshal.py').pyimport()
 
 # Non-marshal result types
 RESULTTYPE_STATRESULT = object()
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jit-improve-nested-loops: prevent a BadVirtualState exception from escaping here, the loop will be discovered to be invalid later in any case

2011-12-27 Thread hakanardo
Author: Hakan Ardo 
Branch: jit-improve-nested-loops
Changeset: r50888:3eafa11552d5
Date: 2011-12-27 11:11 +0100
http://bitbucket.org/pypy/pypy/changeset/3eafa11552d5/

Log:prevent a BadVirtualState exception from escaping here, the loop
will be discovered to be invalid later in any case

diff --git a/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py 
b/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py
--- a/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py
+++ b/pypy/jit/metainterp/optimizeopt/test/test_multilabel.py
@@ -386,6 +386,17 @@
 """
 self.optimize_loop(ops, expected)
 
+def test_virtual_as_field_of_forced_box(self):
+ops = """
+[p0]
+pv1 = new_with_vtable(ConstClass(node_vtable))
+label(pv1, p0)
+pv2 = new_with_vtable(ConstClass(node_vtable))
+setfield_gc(pv2, pv1, descr=valuedescr)
+jump(pv1, pv2)
+"""
+with raises(InvalidLoop):
+self.optimize_loop(ops, ops)
 
 class OptRenameStrlen(Optimization):
 def propagate_forward(self, op):
diff --git a/pypy/jit/metainterp/optimizeopt/virtualstate.py 
b/pypy/jit/metainterp/optimizeopt/virtualstate.py
--- a/pypy/jit/metainterp/optimizeopt/virtualstate.py
+++ b/pypy/jit/metainterp/optimizeopt/virtualstate.py
@@ -409,7 +409,13 @@
 if self.level == LEVEL_CONSTANT:
 return
 assert 0 <= self.position_in_notvirtuals
-boxes[self.position_in_notvirtuals] = value.force_box(optimizer)
+if optimizer:
+box = value.force_box(optimizer)
+else:
+if value.is_virtual():
+raise BadVirtualState
+box = value.get_key_box()
+boxes[self.position_in_notvirtuals] = box
 
 def _enum(self, virtual_state):
 if self.level == LEVEL_CONSTANT:
@@ -471,8 +477,14 @@
 optimizer = optimizer.optearlyforce
 assert len(values) == len(self.state)
 inputargs = [None] * len(self.notvirtuals)
+
+# We try twice. The first time around we allow boxes to be forced
+# which might change the virtual state if the box appear in more
+# than one place among the inputargs.
 for i in range(len(values)):
 self.state[i].enum_forced_boxes(inputargs, values[i], optimizer)
+for i in range(len(values)):
+self.state[i].enum_forced_boxes(inputargs, values[i], None)
 
 if keyboxes:
 for i in range(len(values)):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] jitviewer default: some progress. Disable css_class because it's outrageous

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r181:18fe3ae6deff
Date: 2011-12-27 11:42 +0200
http://bitbucket.org/pypy/jitviewer/changeset/18fe3ae6deff/

Log:some progress. Disable css_class because it's outrageous

diff --git a/_jitviewer/parser.py b/_jitviewer/parser.py
--- a/_jitviewer/parser.py
+++ b/_jitviewer/parser.py
@@ -46,8 +46,8 @@
 s = getattr(self, 'repr_' + self.name, self.repr)()
 return Html(s)
 
-def _getvar(self, v):
-return cssclass(v, v, onmouseover='highlight_var(this)', 
onmouseout='disable_var(this)')
+#def _getvar(self, v):
+#return cssclass(v, v, onmouseover='highlight_var(this)', 
onmouseout='disable_var(this)')
 
 for bin_op, name in [('==', 'int_eq'),
  ('!=', 'int_ne'),
diff --git a/templates/loop.html b/templates/loop.html
--- a/templates/loop.html
+++ b/templates/loop.html
@@ -10,18 +10,20 @@
   {% for chunk in sourceline.chunks %}
  {% if chunk.is_bytecode %}
{{chunk.html_repr()}}
-   {% for op in chunk.operations[1:] %}
-  {% if op.bridge %}
-{{op.html_repr()}} >>show 
bridge (taken {{op.percentage}}%)
-{% if op.asm %}
-  {{op.asm}}
+   {% for op in chunk.operations %}
+  {% if op.name != "debug_merge_point" %}
+{% if op.bridge %}
+  {{op.html_repr()}} >>show 
bridge (taken {{op.percentage}}%)
+  {% if op.asm %}
+{{op.asm}}
+  {% endif %}
+{% else %}
+  {{op.html_repr()}}
+  {% if op.asm %}
+  {{op.asm}}
+  {% endif %}
 {% endif %}
-  {% else %}
-{{op.html_repr()}}
-{% if op.asm %}
-{{op.asm}}
-{% endif %}
-  {% endif %}
+ {% endif %}
{% endfor %}
  {% else %}
{{(chunk.html_repr())|safe}}
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] jitviewer default: fix PATH

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r180:0768b9ec165c
Date: 2011-12-26 23:42 +0200
http://bitbucket.org/pypy/jitviewer/changeset/0768b9ec165c/

Log:fix PATH

diff --git a/bin/jitviewer.py b/bin/jitviewer.py
--- a/bin/jitviewer.py
+++ b/bin/jitviewer.py
@@ -172,8 +172,7 @@
 BaseServer.__init__ = __init__
 
 def main():
-PATH = os.path.join(os.path.dirname((_jitviewer.__file__)))
-print PATH
+PATH = os.path.dirname(os.path.dirname((_jitviewer.__file__)))
 if not '__pypy__' in sys.builtin_module_names:
 print "Please run it using pypy-c"
 sys.exit(1)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Fix assembler to differentiate between 3 kinds of counters

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50898:b67ec3f6c00f
Date: 2011-12-27 14:13 +0200
http://bitbucket.org/pypy/pypy/changeset/b67ec3f6c00f/

Log:Fix assembler to differentiate between 3 kinds of counters

diff --git a/pypy/jit/backend/x86/assembler.py 
b/pypy/jit/backend/x86/assembler.py
--- a/pypy/jit/backend/x86/assembler.py
+++ b/pypy/jit/backend/x86/assembler.py
@@ -59,7 +59,8 @@
 self.is_guard_not_invalidated = is_guard_not_invalidated
 
 DEBUG_COUNTER = lltype.Struct('DEBUG_COUNTER', ('i', lltype.Signed),
-  ('bridge', lltype.Signed), # 0 or 1
+  ('type', lltype.Char), # 'b'ridge, 'l'abel or
+ # 'e'ntry point
   ('number', lltype.Signed))
 
 class Assembler386(object):
@@ -150,10 +151,12 @@
 debug_start('jit-backend-counts')
 for i in range(len(self.loop_run_counters)):
 struct = self.loop_run_counters[i]
-if not struct.bridge:
+if struct.type == 'l':
 prefix = 'TargetToken(%d)' % struct.number
+elif struct.type == 'b':
+prefix = 'bridge ' + str(struct.number)
 else:
-prefix = 'bridge ' + str(struct.number)
+prefix = 'entry ' + str(struct.number)
 debug_print(prefix + ':' + str(struct.i))
 debug_stop('jit-backend-counts')
 
@@ -425,7 +428,7 @@
 self.setup(looptoken)
 if log:
 operations = self._inject_debugging_code(looptoken, operations,
- False, looptoken.number)
+ 'e', looptoken.number)
 
 regalloc = RegAlloc(self, self.cpu.translate_support_code)
 #
@@ -492,7 +495,7 @@
 self.setup(original_loop_token)
 if log:
 operations = self._inject_debugging_code(faildescr, operations,
- True, descr_number)
+ 'b', descr_number)
 
 arglocs = self.rebuild_faillocs_from_descr(failure_recovery)
 if not we_are_translated():
@@ -599,15 +602,15 @@
 return self.mc.materialize(self.cpu.asmmemmgr, allblocks,
self.cpu.gc_ll_descr.gcrootmap)
 
-def _register_counter(self, bridge, number, token):
+def _register_counter(self, tp, number, token):
 # YYY very minor leak -- we need the counters to stay alive
 # forever, just because we want to report them at the end
 # of the process
 struct = lltype.malloc(DEBUG_COUNTER, flavor='raw',
track_allocation=False)
 struct.i = 0
-struct.bridge = int(bridge)
-if bridge:
+struct.type = tp
+if tp == 'b' or tp == 'e':
 struct.number = number
 else:
 assert token
@@ -657,8 +660,8 @@
 targettoken._x86_loop_code += rawstart
 self.target_tokens_currently_compiling = None
 
-def _append_debugging_code(self, operations, bridge, number, token):
-counter = self._register_counter(bridge, number, token)
+def _append_debugging_code(self, operations, tp, number, token):
+counter = self._register_counter(tp, number, token)
 c_adr = ConstInt(rffi.cast(lltype.Signed, counter))
 box = BoxInt()
 box2 = BoxInt()
@@ -670,7 +673,7 @@
 operations.extend(ops)
 
 @specialize.argtype(1)
-def _inject_debugging_code(self, looptoken, operations, bridge, number):
+def _inject_debugging_code(self, looptoken, operations, tp, number):
 if self._debug:
 # before doing anything, let's increase a counter
 s = 0
@@ -679,12 +682,12 @@
 looptoken._x86_debug_checksum = s
 
 newoperations = []
-self._append_debugging_code(newoperations, bridge, number,
+self._append_debugging_code(newoperations, tp, number,
 None)
 for op in operations:
 newoperations.append(op)
 if op.getopnum() == rop.LABEL:
-self._append_debugging_code(newoperations, bridge, number,
+self._append_debugging_code(newoperations, 'l', number,
 op.getdescr())
 operations = newoperations
 return operations
diff --git a/pypy/jit/backend/x86/test/test_runner.py 
b/pypy/jit/backend/x86/test/test_runner.py
--- a/pypy/jit/backend/x86/test/test_runner.py
+++ b/pypy/jit/backend/x86/test/test_runner.py
@@ -546,6 +546,8 @@
 struct = self.cpu.assembler.loop_run_counters[0]
 assert struct.i == 1
 struct = self.cpu.assembler.loop_run_c

[pypy-commit] pypy jit-improve-nested-loops: hg merge c8ddbb442986

2011-12-27 Thread hakanardo
Author: Hakan Ardo 
Branch: jit-improve-nested-loops
Changeset: r50905:4481b4f255f7
Date: 2011-12-27 16:05 +0100
http://bitbucket.org/pypy/pypy/changeset/4481b4f255f7/

Log:hg merge c8ddbb442986

diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -619,7 +619,8 @@
   self.descr_reqcls,
   args)
 except Exception, e:
-raise self.handle_exception(space, e)
+self.handle_exception(space, e)
+w_result = None
 if w_result is None:
 w_result = space.w_None
 return w_result
@@ -655,7 +656,8 @@
   self.descr_reqcls,
   args)
 except Exception, e:
-raise self.handle_exception(space, e)
+self.handle_exception(space, e)
+w_result = None
 if w_result is None:
 w_result = space.w_None
 return w_result
@@ -674,7 +676,8 @@
   self.descr_reqcls,
   args.prepend(w_obj))
 except Exception, e:
-raise self.handle_exception(space, e)
+self.handle_exception(space, e)
+w_result = None
 if w_result is None:
 w_result = space.w_None
 return w_result
@@ -690,7 +693,8 @@
 raise OperationError(space.w_SystemError,
  space.wrap("unexpected DescrMismatch error"))
 except Exception, e:
-raise self.handle_exception(space, e)
+self.handle_exception(space, e)
+w_result = None
 if w_result is None:
 w_result = space.w_None
 return w_result
@@ -708,7 +712,8 @@
self.descr_reqcls,
Arguments(space, [w1]))
 except Exception, e:
-raise self.handle_exception(space, e)
+self.handle_exception(space, e)
+w_result = None
 if w_result is None:
 w_result = space.w_None
 return w_result
@@ -726,7 +731,8 @@
self.descr_reqcls,
Arguments(space, [w1, w2]))
 except Exception, e:
-raise self.handle_exception(space, e)
+self.handle_exception(space, e)
+w_result = None
 if w_result is None:
 w_result = space.w_None
 return w_result
@@ -744,7 +750,8 @@
self.descr_reqcls,
Arguments(space, [w1, w2, w3]))
 except Exception, e:
-raise self.handle_exception(space, e)
+self.handle_exception(space, e)
+w_result = None
 if w_result is None:
 w_result = space.w_None
 return w_result
@@ -763,7 +770,8 @@
Arguments(space,
  [w1, w2, w3, w4]))
 except Exception, e:
-raise self.handle_exception(space, e)
+self.handle_exception(space, e)
+w_result = None
 if w_result is None:
 w_result = space.w_None
 return w_result
diff --git a/pypy/jit/codewriter/support.py b/pypy/jit/codewriter/support.py
--- a/pypy/jit/codewriter/support.py
+++ b/pypy/jit/codewriter/support.py
@@ -162,7 +162,6 @@
 _ll_4_list_setslice = rlist.ll_listsetslice
 _ll_2_list_delslice_startonly = rlist.ll_listdelslice_startonly
 _ll_3_list_delslice_startstop = rlist.ll_listdelslice_startstop
-_ll_1_list_list2fixed = lltypesystem_rlist.ll_list2fixed
 _ll_2_list_inplace_mul = rlist.ll_inplace_mul
 
 _ll_2_list_getitem_foldable = _ll_2_list_getitem
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
@@ -578,8 +578,8 @@
 strides.append(concrete.strides[i])
 backstrides.append(concrete.backstrides[i])
 shape.append(concrete.shape[i])
-return space.wrap(W_NDimSlice(concrete.start, strides[:],
-  backstrides[:], shape[:], concrete))
+return space.wrap(W_NDimSlice(concrete.start, strides,
+  backstrides, shape, concrete))
 
 def descr_get_flatiter(self, space):
 return space.wrap(W_FlatIterator(self))
@@ -820,8 +820,8 @@
 if self.order == 'C':
 strides.reverse()
 backstrides.reverse()
-self.strides = strides[:]
-self.backstrides = backstrides[:]
+self.strid

[pypy-commit] pypy default: fix the test

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50899:6d97be67953c
Date: 2011-12-27 14:22 +0200
http://bitbucket.org/pypy/pypy/changeset/6d97be67953c/

Log:fix the test

diff --git a/pypy/jit/backend/x86/test/test_runner.py 
b/pypy/jit/backend/x86/test/test_runner.py
--- a/pypy/jit/backend/x86/test/test_runner.py
+++ b/pypy/jit/backend/x86/test/test_runner.py
@@ -552,9 +552,10 @@
 self.cpu.finish_once()
 finally:
 debug._log = None
+l0 = ('debug_print', 'entry -1:1')
 l1 = ('debug_print', preambletoken.repr_of_descr() + ':1')
 l2 = ('debug_print', targettoken.repr_of_descr() + ':9')
-assert ('jit-backend-counts', [l1, l2]) in dlog
+assert ('jit-backend-counts', [l0, l1, l2]) in dlog
 
 def test_debugger_checksum(self):
 loop = """
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: append debugging code at the beginning even if for loops

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50890:e105505cc286
Date: 2011-12-27 13:16 +0200
http://bitbucket.org/pypy/pypy/changeset/e105505cc286/

Log:append debugging code at the beginning even if for loops

diff --git a/pypy/jit/backend/x86/assembler.py 
b/pypy/jit/backend/x86/assembler.py
--- a/pypy/jit/backend/x86/assembler.py
+++ b/pypy/jit/backend/x86/assembler.py
@@ -679,9 +679,8 @@
 looptoken._x86_debug_checksum = s
 
 newoperations = []
-if bridge:
-self._append_debugging_code(newoperations, bridge, number,
-None)
+self._append_debugging_code(newoperations, bridge, number,
+None)
 for op in operations:
 newoperations.append(op)
 if op.getopnum() == rop.LABEL:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] extradoc extradoc: Fix the description

2011-12-27 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r3994:e88672794b8f
Date: 2011-12-27 18:05 +0100
http://bitbucket.org/pypy/extradoc/changeset/e88672794b8f/

Log:Fix the description

diff --git a/sprintinfo/leysin-winter-2012/announcement.txt 
b/sprintinfo/leysin-winter-2012/announcement.txt
--- a/sprintinfo/leysin-winter-2012/announcement.txt
+++ b/sprintinfo/leysin-winter-2012/announcement.txt
@@ -10,9 +10,9 @@
 Goals and topics of the sprint
 --
 
-* Py3k topics: ...
+* Py3k: work towards supporting Python 3 in PyPy 
 
-* NumPyPy topics: ...
+* NumPyPy: work towards supporting the numpy module in PyPy 
 
 * JIT backends: integrate tests for ARM; look at the PowerPC 64;
   maybe try again to write an LLVM- or GCC-based one
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: a minor fix

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50909:84b731e827a6
Date: 2011-12-27 19:45 +0200
http://bitbucket.org/pypy/pypy/changeset/84b731e827a6/

Log:a minor fix

diff --git a/pypy/tool/jitlogparser/parser.py b/pypy/tool/jitlogparser/parser.py
--- a/pypy/tool/jitlogparser/parser.py
+++ b/pypy/tool/jitlogparser/parser.py
@@ -154,7 +154,7 @@
 for op in operations:
 if op.name == 'debug_merge_point':
 self.inline_level = int(op.args[0])
-self.parse_code_data(op.args[1])
+self.parse_code_data(op.args[1][1:-1])
 break
 else:
 self.inline_level = 0
diff --git a/pypy/tool/jitlogparser/test/test_parser.py 
b/pypy/tool/jitlogparser/test/test_parser.py
--- a/pypy/tool/jitlogparser/test/test_parser.py
+++ b/pypy/tool/jitlogparser/test/test_parser.py
@@ -52,7 +52,7 @@
 assert len(res.chunks[2].operations) == 2
 assert len(res.chunks[3].operations) == 2
 assert res.chunks[3].bytecode_no == 11
-assert res.chunks[0].bytecode_name == 'loopname'
+assert res.chunks[0].bytecode_name == ''
 
 def test_inlined_call():
 ops = parse("""
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: merge

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50910:56272f637518
Date: 2011-12-27 20:27 +0200
http://bitbucket.org/pypy/pypy/changeset/56272f637518/

Log:merge

diff --git a/pypy/jit/metainterp/heapcache.py b/pypy/jit/metainterp/heapcache.py
--- a/pypy/jit/metainterp/heapcache.py
+++ b/pypy/jit/metainterp/heapcache.py
@@ -79,9 +79,9 @@
 opnum == rop.COPYSTRCONTENT or
 opnum == rop.COPYUNICODECONTENT):
 return
-if rop._OVF_FIRST <= opnum <= rop._OVF_LAST:
-return
-if rop._NOSIDEEFFECT_FIRST <= opnum <= rop._NOSIDEEFFECT_LAST:
+if (rop._OVF_FIRST <= opnum <= rop._OVF_LAST or
+rop._NOSIDEEFFECT_FIRST <= opnum <= rop._NOSIDEEFFECT_LAST or
+rop._GUARD_FIRST <= opnum <= rop._GUARD_LAST):
 return
 if opnum == rop.CALL or opnum == rop.CALL_LOOPINVARIANT:
 effectinfo = descr.get_extra_info()
diff --git a/pypy/jit/metainterp/test/test_heapcache.py 
b/pypy/jit/metainterp/test/test_heapcache.py
--- a/pypy/jit/metainterp/test/test_heapcache.py
+++ b/pypy/jit/metainterp/test/test_heapcache.py
@@ -255,6 +255,11 @@
 assert h.getarrayitem(box1, descr1, index1) is box2
 assert h.getarrayitem(box1, descr1, index2) is box4
 
+h.invalidate_caches(rop.GUARD_TRUE, None, [])
+assert h.getfield(box1, descr1) is box2
+assert h.getarrayitem(box1, descr1, index1) is box2
+assert h.getarrayitem(box1, descr1, index2) is box4
+
 h.invalidate_caches(
 rop.CALL_LOOPINVARIANT, 
FakeCallDescr(FakeEffektinfo.EF_LOOPINVARIANT), [])
 
diff --git a/pypy/module/micronumpy/strides.py 
b/pypy/module/micronumpy/strides.py
--- a/pypy/module/micronumpy/strides.py
+++ b/pypy/module/micronumpy/strides.py
@@ -1,4 +1,9 @@
+from pypy.rlib import jit
 
+
+@jit.look_inside_iff(lambda shape, start, strides, backstrides, chunks:
+jit.isconstant(len(chunks))
+)
 def calculate_slice_strides(shape, start, strides, backstrides, chunks):
 rstrides = []
 rbackstrides = []
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] jitviewer default: slightly better - display loops at least

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r184:e9485a7845a0
Date: 2011-12-27 16:57 +0200
http://bitbucket.org/pypy/jitviewer/changeset/e9485a7845a0/

Log:slightly better - display loops at least

diff --git a/bin/jitviewer.py b/bin/jitviewer.py
--- a/bin/jitviewer.py
+++ b/bin/jitviewer.py
@@ -71,14 +71,14 @@
 all = flask.request.args.get('all', None)
 loops = []
 for index, loop in enumerate(self.storage.loops):
-if 'entry bridge' in loop.comment:
-is_entry = True
-else:
-is_entry = False
+is_entry = False
 try:
+start, stop = loop.comment.find('('), loop.comment.rfind(')')
+name = loop.comment[start + 1:stop]
 func = FunctionHtml.from_operations(loop.operations, 
self.storage,
 limit=1,
-inputargs=loop.inputargs)
+inputargs=loop.inputargs,
+loopname=name)
 except CannotFindFile:
 func = DummyFunc()
 func.count = getattr(loop, 'count', '?')
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Meh, at least raise error in case there is a typo

2011-12-27 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r50911:94e9969b5f00
Date: 2011-12-27 22:46 +0200
http://bitbucket.org/pypy/pypy/changeset/94e9969b5f00/

Log:Meh, at least raise error in case there is a typo

diff --git a/pypy/rlib/jit.py b/pypy/rlib/jit.py
--- a/pypy/rlib/jit.py
+++ b/pypy/rlib/jit.py
@@ -528,6 +528,8 @@
 set_param(driver, name1, int(value))
 except ValueError:
 raise
+else:
+raise ValueError
 set_user_param._annspecialcase_ = 'specialize:arg(0)'
 
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy numpypy-axisops: add tests for numpypy.reduce

2011-12-27 Thread mattip
Author: mattip
Branch: numpypy-axisops
Changeset: r50912:e5b246bae93a
Date: 2011-12-25 21:09 +0200
http://bitbucket.org/pypy/pypy/changeset/e5b246bae93a/

Log:add tests for numpypy.reduce

diff --git a/pypy/module/micronumpy/interp_ufuncs.py 
b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -3,7 +3,8 @@
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import TypeDef, GetSetProperty, 
interp_attrproperty
 from pypy.module.micronumpy import interp_boxes, interp_dtype, types
-from pypy.module.micronumpy.signature import ReduceSignature, ScalarSignature, 
find_sig
+from pypy.module.micronumpy.signature import (ReduceSignature, 
ScalarSignature, 
+ArraySignature, find_sig)
 from pypy.rlib import jit
 from pypy.rlib.rarithmetic import LONG_BIT
 from pypy.tool.sourcetools import func_with_new_name
@@ -46,8 +47,60 @@
 )
 return self.call(space, __args__.arguments_w)
 
-def descr_reduce(self, space, w_obj):
-return self.reduce(space, w_obj, False, space.wrap(-1))
+def descr_reduce(self, space, w_obj, w_dim=0):
+'''reduce(...)
+reduce(a, axis=0)
+
+Reduces `a`'s dimension by one, by applying ufunc along one axis.
+
+Let :math:`a.shape = (N_0, ..., N_i, ..., N_{M-1})`.  Then
+:math:`ufunc.reduce(a, axis=i)[k_0, ..,k_{i-1}, k_{i+1}, .., k_{M-1}]` =
+the result of iterating `j` over :math:`range(N_i)`, cumulatively applying
+ufunc to each :math:`a[k_0, ..,k_{i-1}, j, k_{i+1}, .., k_{M-1}]`.
+For a one-dimensional array, reduce produces results equivalent to:
+::
+
+ r = op.identity # op = ufunc
+ for i in xrange(len(A)):
+   r = op(r, A[i])
+ return r
+
+For example, add.reduce() is equivalent to sum().
+
+Parameters
+--
+a : array_like
+The array to act on.
+axis : int, optional
+The axis along which to apply the reduction.
+
+Examples
+
+>>> np.multiply.reduce([2,3,5])
+30
+
+A multi-dimensional array example:
+
+>>> X = np.arange(8).reshape((2,2,2))
+>>> X
+array([[[0, 1],
+[2, 3]],
+   [[4, 5],
+[6, 7]]])
+>>> np.add.reduce(X, 0)
+array([[ 4,  6],
+   [ 8, 10]])
+>>> np.add.reduce(X) # confirm: default axis value is 0
+array([[ 4,  6],
+   [ 8, 10]])
+>>> np.add.reduce(X, 1)
+array([[ 2,  4],
+   [10, 12]])
+>>> np.add.reduce(X, 2)
+array([[ 1,  5],
+   [ 9, 13]])
+'''
+return self.reduce(space, w_obj, False, w_dim)
 
 def reduce(self, space, w_obj, multidim, w_dim):
 from pypy.module.micronumpy.interp_numarray import convert_to_array, 
Scalar
@@ -57,6 +110,8 @@
 dim = -1
 if not space.is_w(w_dim, space.w_None):
 dim = space.int_w(w_dim)
+if not multidim and space.is_w(w_dim, space.w_None):
+dim = 0
 assert isinstance(self, W_Ufunc2)
 obj = convert_to_array(space, w_obj)
 if isinstance(obj, Scalar):
@@ -69,14 +124,15 @@
 promote_to_largest=True
 )
 shapelen = len(obj.shape)
-#TODO: if dim>=0 return a ArraySignature?
-sig = find_sig(ReduceSignature(self.func, self.name, dtype,
+if dim>=0 or 0:
+sig = find_sig(ReduceSignature(self.func, self.name, dtype,
+   ArraySignature(dtype),
+   obj.create_sig(obj.shape)), obj)
+else:
+sig = find_sig(ReduceSignature(self.func, self.name, dtype,
ScalarSignature(dtype),
obj.create_sig(obj.shape)), obj)
 frame = sig.create_frame(obj)
-if shapelen > 1 and not multidim:
-raise OperationError(space.w_NotImplementedError,
-space.wrap("not implemented yet"))
 if self.identity is None:
 if size == 0:
 raise operationerrfmt(space.w_ValueError, "zero-size array to "
diff --git a/pypy/module/micronumpy/test/test_ufuncs.py 
b/pypy/module/micronumpy/test/test_ufuncs.py
--- a/pypy/module/micronumpy/test/test_ufuncs.py
+++ b/pypy/module/micronumpy/test/test_ufuncs.py
@@ -339,12 +339,15 @@
 raises(TypeError, add.reduce, 1)
 
 def test_reduce(self):
-from numpypy import add, maximum
+from numpypy import add, maximum, arange
 
 assert add.reduce([1, 2, 3]) == 6
 assert maximum.reduce([1]) == 1
 assert maximum.reduce([1, 2, 3]) == 3
 raises(ValueError, maximum.reduce, [])
+a = arange(12).reshape(3,4)
+assert add.reduce(a, 0) == add.reduce(a)
+assert (add.reduce(a, 1) == [ 6, 22, 38]).all()
 
 def test_comparisons(self):
 import operator
___

[pypy-commit] pypy numpypy-axisops: checkpoint

2011-12-27 Thread mattip
Author: mattip
Branch: numpypy-axisops
Changeset: r50913:da091f2c5c7d
Date: 2011-12-26 23:32 +0200
http://bitbucket.org/pypy/pypy/changeset/da091f2c5c7d/

Log:checkpoint

diff --git a/pypy/module/micronumpy/interp_iter.py 
b/pypy/module/micronumpy/interp_iter.py
--- a/pypy/module/micronumpy/interp_iter.py
+++ b/pypy/module/micronumpy/interp_iter.py
@@ -103,34 +103,49 @@
 def next(self, shapelen):
 return self
 
-# -- other iterators that are not part of the computation frame --
+def axis_iter_from_arr(arr, dim=-1, start=[]):
+return AxisIterator(arr.start, arr.strides, arr.backstrides, arr.shape,
+dim, start)
 
 class AxisIterator(object):
 """ This object will return offsets of each start of a stride on the 
 desired dimension, starting at the desired index
 """
-def __init__(self, arr, dim=-1, start=[]):
-self.arr = arr
+def __init__(self, start, strides, backstrides, shape, dim=-1, start=[]):
+self.shape = shape
 self.indices = [0] * len(arr.shape)
 self.done = False
-self.offset = arr.start
-self.dim = len(arr.shape) - 1
+self.offset = start
+self.dim = len(shape) - 1
 if dim >= 0:
 self.dim = dim
-if len(start) == len(arr.shape):
+if len(start) == len(shape):
 for i in range(len(start)):
-self.offset += arr.strides[i] * start[i]
-def next(self):
-for i in range(len(self.arr.shape) - 1, -1, -1):
+self.offset += strides[i] * start[i]
+def next(self, shapelen):
+offset = self.offset
+indices = [0] * shapelen
+for i in range(shapelen):
+indices[i] = self.indices[i]
+for i in range(shapelen - 1, -1, -1):
 if i == self.dim:
 continue
-if self.indices[i] < self.arr.shape[i] - 1:
-self.indices[i] += 1
-self.offset += self.arr.strides[i]
+if indices[i] < self.shape[i] - 1:
+indices[i] += 1
+offset += self.strides[i]
 break
 else:
-self.indices[i] = 0
-self.offset -= self.arr.backstrides[i]
+indices[i] = 0
+offset -= self.backstrides[i]
 else:
 self.done = True
-
+res = instantiate(AxisIterator)
+res.offset = offset
+res.indices = indices
+res.strides = self.strides
+res.backstrides = self.backstrides
+res.shape = self.shape
+res.dim = self.dim
+res.done = done
+return res
+
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
@@ -664,7 +664,8 @@
 self.name = name
 
 def _del_sources(self):
-# Function for deleting references to source arrays, to allow 
garbage-collecting them
+# Function for deleting references to source arrays, 
+# to allow garbage-collecting them
 raise NotImplementedError
 
 def compute(self):
@@ -730,6 +731,42 @@
 def _del_sources(self):
 self.child = None
 
+class Reduce(VirtualArray):
+def __init__(self, ufunc, name, dim, res_dtype, values):
+shape=values.shape[0:dim] + values.shape[dim+1:len(values.shape)]
+VirtualArray.__init__(self, name, shape, res_dtype)
+self.values = values
+self.size = values.size
+self.ufunc = ufunc
+self.res_dtype = res_dtype
+self.dim = dim
+
+def _del_sources(self):
+self.values = None
+
+def create_sig(self, res_shape):
+if self.forced_result is not None:
+return self.forced_result.create_sig(res_shape)
+return signature.ReduceSignature(self.ufunc, self.name, self.res_dtype,
+   signature.ViewSignature(self.res_dtype),
+   self.values.create_sig(res_shape))
+
+def compute(self):
+result = W_NDimArray(self.size, self.shape, self.find_dtype())
+shapelen = len(result.shape)
+sig = self.find_sig()
+ri = ArrayIterator(self.size)
+si = AxisIterator(self,self.dim)
+while not ri.done():
+frame = sig.create_frame(self, self.values, chunks = si.indices)
+val = sig.eval(frame, self)
+result.dtype.setitem(result.storage, ri.offset, val)
+ri = ri.next(shapelen)
+si = si.next(shapelen)
+return result
+
+
+
 class Call1(VirtualArray):
 def __init__(self, ufunc, name, shape, res_dtype, values):
 VirtualArray.__init__(self, name, shape, res_dtype)
diff --git a/pypy/module/micronumpy/interp_ufuncs.py 
b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/i

[pypy-commit] pypy numpypy-axisops: rework AxisIterator, make single tests pass

2011-12-27 Thread mattip
Author: mattip
Branch: numpypy-axisops
Changeset: r50914:b12a872f0961
Date: 2011-12-27 07:32 +0200
http://bitbucket.org/pypy/pypy/changeset/b12a872f0961/

Log:rework AxisIterator, make single tests pass

diff --git a/pypy/module/micronumpy/interp_iter.py 
b/pypy/module/micronumpy/interp_iter.py
--- a/pypy/module/micronumpy/interp_iter.py
+++ b/pypy/module/micronumpy/interp_iter.py
@@ -111,17 +111,19 @@
 """ This object will return offsets of each start of a stride on the 
 desired dimension, starting at the desired index
 """
-def __init__(self, start, strides, backstrides, shape, dim=-1, start=[]):
+def __init__(self, arr_start, strides, backstrides, shape, dim=-1, 
slice_start=[]):
 self.shape = shape
-self.indices = [0] * len(arr.shape)
+self.indices = [0] * len(shape)
 self.done = False
-self.offset = start
+self.offset = arr_start
 self.dim = len(shape) - 1
+self.strides = strides
+self.backstrides = backstrides
 if dim >= 0:
 self.dim = dim
-if len(start) == len(shape):
-for i in range(len(start)):
-self.offset += strides[i] * start[i]
+if len(slice_start) == len(shape):
+for i in range(len(slice_start)):
+self.offset += strides[i] * slice_start[i]
 def next(self, shapelen):
 offset = self.offset
 indices = [0] * shapelen
@@ -146,6 +148,6 @@
 res.backstrides = self.backstrides
 res.shape = self.shape
 res.dim = self.dim
-res.done = done
+res.done = self.done
 return res
 
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
@@ -9,7 +9,7 @@
 from pypy.tool.sourcetools import func_with_new_name
 from pypy.rlib.rstring import StringBuilder
 from pypy.module.micronumpy.interp_iter import ArrayIterator,\
- view_iter_from_arr, OneDimIterator, AxisIterator
+ view_iter_from_arr, OneDimIterator, axis_iter_from_arr
 
 numpy_driver = jit.JitDriver(
 greens=['shapelen', 'sig'],
@@ -280,6 +280,8 @@
 
 def _reduce_ufunc_impl(ufunc_name):
 def impl(self, space, w_dim=None):
+if w_dim is None:
+w_dim = space.wrap(w_dim)
 return getattr(interp_ufuncs.get(space), ufunc_name).reduce(space,
self, True, w_dim)
 return func_with_new_name(impl, "reduce_%s_impl" % ufunc_name)
@@ -756,7 +758,7 @@
 shapelen = len(result.shape)
 sig = self.find_sig()
 ri = ArrayIterator(self.size)
-si = AxisIterator(self,self.dim)
+si = axis_iter_from_arr(self, self.dim)
 while not ri.done():
 frame = sig.create_frame(self, self.values, chunks = si.indices)
 val = sig.eval(frame, self)
@@ -985,23 +987,24 @@
 def _fast_setslice(self, space, w_value):
 assert isinstance(w_value, ConcreteArray)
 itemsize = self.dtype.itemtype.get_element_size()
-if len(self.shape) == 1:
+shapelen = len(self.shape)
+if shapelen == 1:
 rffi.c_memcpy(
 rffi.ptradd(self.storage, self.start * itemsize),
 rffi.ptradd(w_value.storage, w_value.start * itemsize),
 self.size * itemsize
 )
 else:
-dest = AxisIterator(self)
-source = AxisIterator(w_value)
+dest = axis_iter_from_arr(self)
+source = axis_iter_from_arr(w_value)
 while not dest.done:
 rffi.c_memcpy(
 rffi.ptradd(self.storage, dest.offset * itemsize),
 rffi.ptradd(w_value.storage, source.offset * itemsize),
 self.shape[-1] * itemsize
 )
-source.next()
-dest.next()
+source = source.next(shapelen)
+dest = dest.next(shapelen)
 
 def _sliceloop(self, source, res_shape):
 sig = source.find_sig(res_shape)
diff --git a/pypy/module/micronumpy/test/test_iterators.py 
b/pypy/module/micronumpy/test/test_iterators.py
--- a/pypy/module/micronumpy/test/test_iterators.py
+++ b/pypy/module/micronumpy/test/test_iterators.py
@@ -8,24 +8,31 @@
 
 class TestAxisIteratorDirect(object):
 def test_axis_iterator(self):
+a = W_NDimArray(5*3, [5, 3], MockDtype(), 'C')
+i = AxisIterator(a)
+ret = []
+while not i.done:
+ret.append(i.offset)
+i = i.next()
+assert ret == [0, 3, 6, 9, 12]
 a = W_NDimArray(7*5*3, [7, 5, 3], MockDtype(), 'C')
 i = AxisIterator(a)
 ret = []
 while not i.done:
 ret.append(i.offset)
-i.next()
+i = i.next()
 assert ret == [3*v for v i

[pypy-commit] pypy numpypy-axisops: why do default args cause problems?

2011-12-27 Thread mattip
Author: mattip
Branch: numpypy-axisops
Changeset: r50915:cd8f7d57fe3e
Date: 2011-12-27 08:12 +0200
http://bitbucket.org/pypy/pypy/changeset/cd8f7d57fe3e/

Log:why do default args cause problems?

diff --git a/pypy/module/micronumpy/signature.py 
b/pypy/module/micronumpy/signature.py
--- a/pypy/module/micronumpy/signature.py
+++ b/pypy/module/micronumpy/signature.py
@@ -90,11 +90,13 @@
 allnumbers.append(no)
 self.iter_no = no
 
-def create_frame(self, arr, res_shape=None, chunks = []):
+def create_frame(self, arr, res_shape=None):
+#def create_frame(self, arr, res_shape=None, chunks = []):
 res_shape = res_shape or arr.shape
 iterlist = []
 arraylist = []
-self._create_iter(iterlist, arraylist, arr, res_shape, chunks)
+#self._create_iter(iterlist, arraylist, arr, res_shape, chunks)
+self._create_iter(iterlist, arraylist, arr, res_shape, [])
 return NumpyEvalFrame(iterlist, arraylist)
 
 class ConcreteSignature(Signature):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy numpypy-axisops: iterators, frames in place, but still not correct

2011-12-27 Thread mattip
Author: mattip
Branch: numpypy-axisops
Changeset: r50916:a1810346784a
Date: 2011-12-27 22:46 +0200
http://bitbucket.org/pypy/pypy/changeset/a1810346784a/

Log:iterators, frames in place, but still not correct

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
@@ -756,15 +756,19 @@
 def compute(self):
 result = W_NDimArray(self.size, self.shape, self.find_dtype())
 shapelen = len(result.shape)
-sig = self.find_sig()
+#sig = self.find_sig(result.shape) ##Don't do this, it causes an 
infinite recursion
+sig = self.create_sig(result.shape)
 ri = ArrayIterator(self.size)
-si = axis_iter_from_arr(self, self.dim)
+si = axis_iter_from_arr(self.values, self.dim)
 while not ri.done():
-frame = sig.create_frame(self, self.values, chunks = si.indices)
-val = sig.eval(frame, self)
+#frame = sig.create_frame(self.values, chunks = [si.indices])
+#Frame should be returning self.func applied to the axis starting 
at si.offset
+frame = sig.create_frame(self.values, chunks = [])
+val = sig.eval(frame, self.values).convert_to( self.find_dtype())
 result.dtype.setitem(result.storage, ri.offset, val)
 ri = ri.next(shapelen)
 si = si.next(shapelen)
+frame = frame.next
 return result
 
 
diff --git a/pypy/module/micronumpy/signature.py 
b/pypy/module/micronumpy/signature.py
--- a/pypy/module/micronumpy/signature.py
+++ b/pypy/module/micronumpy/signature.py
@@ -90,13 +90,11 @@
 allnumbers.append(no)
 self.iter_no = no
 
-def create_frame(self, arr, res_shape=None):
-#def create_frame(self, arr, res_shape=None, chunks = []):
+def create_frame(self, arr, res_shape=None, chunks = []):
 res_shape = res_shape or arr.shape
 iterlist = []
 arraylist = []
-#self._create_iter(iterlist, arraylist, arr, res_shape, chunks)
-self._create_iter(iterlist, arraylist, arr, res_shape, [])
+self._create_iter(iterlist, arraylist, arr, res_shape, chunks)
 return NumpyEvalFrame(iterlist, arraylist)
 
 class ConcreteSignature(Signature):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy numpypy-axisops: fix test_axis_iterator, start to see some results

2011-12-27 Thread mattip
Author: mattip
Branch: numpypy-axisops
Changeset: r50917:4e517ebe55c0
Date: 2011-12-28 02:31 +0200
http://bitbucket.org/pypy/pypy/changeset/4e517ebe55c0/

Log:fix test_axis_iterator, start to see some results

diff --git a/pypy/module/micronumpy/interp_iter.py 
b/pypy/module/micronumpy/interp_iter.py
--- a/pypy/module/micronumpy/interp_iter.py
+++ b/pypy/module/micronumpy/interp_iter.py
@@ -113,6 +113,7 @@
 """
 def __init__(self, arr_start, strides, backstrides, shape, dim=-1, 
slice_start=[]):
 self.shape = shape
+self.shapelen = len(shape)
 self.indices = [0] * len(shape)
 self.done = False
 self.offset = arr_start
@@ -125,11 +126,12 @@
 for i in range(len(slice_start)):
 self.offset += strides[i] * slice_start[i]
 def next(self, shapelen):
+#shapelen will always be one less than self.shapelen
 offset = self.offset
-indices = [0] * shapelen
-for i in range(shapelen):
+indices = [0] * self.shapelen
+for i in range(self.shapelen):
 indices[i] = self.indices[i]
-for i in range(shapelen - 1, -1, -1):
+for i in range(self.shapelen - 1, -1, -1):
 if i == self.dim:
 continue
 if indices[i] < self.shape[i] - 1:
@@ -147,6 +149,7 @@
 res.strides = self.strides
 res.backstrides = self.backstrides
 res.shape = self.shape
+res.shapelen = self.shapelen
 res.dim = self.dim
 res.done = self.done
 return res
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
@@ -734,7 +734,7 @@
 self.child = None
 
 class Reduce(VirtualArray):
-def __init__(self, ufunc, name, dim, res_dtype, values):
+def __init__(self, ufunc, name, dim, res_dtype, values, identity=None):
 shape=values.shape[0:dim] + values.shape[dim+1:len(values.shape)]
 VirtualArray.__init__(self, name, shape, res_dtype)
 self.values = values
@@ -742,9 +742,11 @@
 self.ufunc = ufunc
 self.res_dtype = res_dtype
 self.dim = dim
+self.identity = identity
 
 def _del_sources(self):
 self.values = None
+pass
 
 def create_sig(self, res_shape):
 if self.forced_result is not None:
@@ -754,21 +756,37 @@
self.values.create_sig(res_shape))
 
 def compute(self):
-result = W_NDimArray(self.size, self.shape, self.find_dtype())
+dtype = self.res_dtype
+result = W_NDimArray(self.size, self.shape, dtype)
 shapelen = len(result.shape)
+objlen = len(self.values.shape)
+target_len = self.values.shape[self.dim]
 #sig = self.find_sig(result.shape) ##Don't do this, it causes an 
infinite recursion
 sig = self.create_sig(result.shape)
 ri = ArrayIterator(self.size)
 si = axis_iter_from_arr(self.values, self.dim)
 while not ri.done():
-#frame = sig.create_frame(self.values, chunks = [si.indices])
-#Frame should be returning self.func applied to the axis starting 
at si.offset
-frame = sig.create_frame(self.values, chunks = [])
-val = sig.eval(frame, self.values).convert_to( self.find_dtype())
-result.dtype.setitem(result.storage, ri.offset, val)
+chunks = []
+for i in range(objlen - 1, -1, -1):
+if i==self.dim:
+chunks.append((0, target_len, 1, target_len))
+else:
+chunks.append((si.indices[i], 0, 0, 1))
+frame = sig.create_frame(self.values, 
+ res_shape = [target_len], chunks = [chunks,])
+if self.identity is None:
+value = sig.eval(frame, self.values).convert_to(dtype)
+frame.next(shapelen)
+else:
+value = self.identity.convert_to(dtype)
+while not frame.done():
+assert isinstance(sig, signature.ReduceSignature)
+nextval = sig.eval(frame, self.values).convert_to(dtype)
+value = sig.binfunc(dtype, value, nextval)
+frame.next(shapelen)
+result.dtype.setitem(result.storage, ri.offset, value)
 ri = ri.next(shapelen)
 si = si.next(shapelen)
-frame = frame.next
 return result
 
 
diff --git a/pypy/module/micronumpy/interp_ufuncs.py 
b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -121,20 +121,20 @@
 size = obj.size
 dtype = find_unaryop_result_dtype(
 space, obj.find_dtype(),
-promote_to_largest=True
+promote_to_float=self.promote_to_float
 )

[pypy-commit] pypy numpypy-axisops: merge with default

2011-12-27 Thread mattip
Author: mattip
Branch: numpypy-axisops
Changeset: r50919:1714b0167e37
Date: 2011-12-28 03:02 +0200
http://bitbucket.org/pypy/pypy/changeset/1714b0167e37/

Log:merge with default

diff --git a/pypy/interpreter/eval.py b/pypy/interpreter/eval.py
--- a/pypy/interpreter/eval.py
+++ b/pypy/interpreter/eval.py
@@ -98,7 +98,6 @@
 "Abstract. Get the expected number of locals."
 raise TypeError, "abstract"
 
-@jit.dont_look_inside
 def fast2locals(self):
 # Copy values from the fastlocals to self.w_locals
 if self.w_locals is None:
@@ -112,7 +111,6 @@
 w_name = self.space.wrap(name)
 self.space.setitem(self.w_locals, w_name, w_value)
 
-@jit.dont_look_inside
 def locals2fast(self):
 # Copy values from self.w_locals to the fastlocals
 assert self.w_locals is not None
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -619,7 +619,8 @@
   self.descr_reqcls,
   args)
 except Exception, e:
-raise self.handle_exception(space, e)
+self.handle_exception(space, e)
+w_result = None
 if w_result is None:
 w_result = space.w_None
 return w_result
@@ -655,7 +656,8 @@
   self.descr_reqcls,
   args)
 except Exception, e:
-raise self.handle_exception(space, e)
+self.handle_exception(space, e)
+w_result = None
 if w_result is None:
 w_result = space.w_None
 return w_result
@@ -674,7 +676,8 @@
   self.descr_reqcls,
   args.prepend(w_obj))
 except Exception, e:
-raise self.handle_exception(space, e)
+self.handle_exception(space, e)
+w_result = None
 if w_result is None:
 w_result = space.w_None
 return w_result
@@ -690,7 +693,8 @@
 raise OperationError(space.w_SystemError,
  space.wrap("unexpected DescrMismatch error"))
 except Exception, e:
-raise self.handle_exception(space, e)
+self.handle_exception(space, e)
+w_result = None
 if w_result is None:
 w_result = space.w_None
 return w_result
@@ -708,7 +712,8 @@
self.descr_reqcls,
Arguments(space, [w1]))
 except Exception, e:
-raise self.handle_exception(space, e)
+self.handle_exception(space, e)
+w_result = None
 if w_result is None:
 w_result = space.w_None
 return w_result
@@ -726,7 +731,8 @@
self.descr_reqcls,
Arguments(space, [w1, w2]))
 except Exception, e:
-raise self.handle_exception(space, e)
+self.handle_exception(space, e)
+w_result = None
 if w_result is None:
 w_result = space.w_None
 return w_result
@@ -744,7 +750,8 @@
self.descr_reqcls,
Arguments(space, [w1, w2, w3]))
 except Exception, e:
-raise self.handle_exception(space, e)
+self.handle_exception(space, e)
+w_result = None
 if w_result is None:
 w_result = space.w_None
 return w_result
@@ -763,7 +770,8 @@
Arguments(space,
  [w1, w2, w3, w4]))
 except Exception, e:
-raise self.handle_exception(space, e)
+self.handle_exception(space, e)
+w_result = None
 if w_result is None:
 w_result = space.w_None
 return w_result
diff --git a/pypy/jit/backend/x86/assembler.py 
b/pypy/jit/backend/x86/assembler.py
--- a/pypy/jit/backend/x86/assembler.py
+++ b/pypy/jit/backend/x86/assembler.py
@@ -39,6 +39,7 @@
 from pypy.jit.codewriter.effectinfo import EffectInfo
 from pypy.jit.codewriter import longlong
 from pypy.rlib.rarithmetic import intmask
+from pypy.rlib.objectmodel import compute_unique_id
 
 # darwin requires the stack to be 16 bytes aligned on calls. Same for gcc 
4.5.0,
 # better safe than sorry
@@ -58,7 +59,8 @@
 self.is_guard_not_invalidated = is_guard_not_invalidated
 
 DEBUG_COUNTER = lltype.Struct('DEBUG_COUNTER', ('i', lltype.Signed),
-  ('bridge', lltype.Signed), # 0 or 1
+  ('type', lltype.Char), # 'b'ridge, 'l'abel or

[pypy-commit] pypy numpypy-axisops: bugfix, passes tests

2011-12-27 Thread mattip
Author: mattip
Branch: numpypy-axisops
Changeset: r50918:ff482782c5fe
Date: 2011-12-28 02:57 +0200
http://bitbucket.org/pypy/pypy/changeset/ff482782c5fe/

Log:bugfix, passes tests

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
@@ -738,7 +738,9 @@
 shape=values.shape[0:dim] + values.shape[dim+1:len(values.shape)]
 VirtualArray.__init__(self, name, shape, res_dtype)
 self.values = values
-self.size = values.size
+self.size = 1
+for s in shape:
+self.size *= s
 self.ufunc = ufunc
 self.res_dtype = res_dtype
 self.dim = dim
@@ -758,16 +760,18 @@
 def compute(self):
 dtype = self.res_dtype
 result = W_NDimArray(self.size, self.shape, dtype)
+self.values = self.values.get_concrete()
 shapelen = len(result.shape)
 objlen = len(self.values.shape)
 target_len = self.values.shape[self.dim]
 #sig = self.find_sig(result.shape) ##Don't do this, it causes an 
infinite recursion
 sig = self.create_sig(result.shape)
-ri = ArrayIterator(self.size)
+ri = ArrayIterator(result.size)
 si = axis_iter_from_arr(self.values, self.dim)
 while not ri.done():
 chunks = []
-for i in range(objlen - 1, -1, -1):
+#for i in range(objlen - 1, -1, -1):
+for i in range(objlen):
 if i==self.dim:
 chunks.append((0, target_len, 1, target_len))
 else:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy numpypy-axisops: whoops, start fixes for translate

2011-12-27 Thread mattip
Author: mattip
Branch: numpypy-axisops
Changeset: r50921:f1a8c490b279
Date: 2011-12-28 03:56 +0200
http://bitbucket.org/pypy/pypy/changeset/f1a8c490b279/

Log:whoops, start fixes for translate

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
@@ -319,7 +319,6 @@
   idx=idx,
   cur_best=cur_best)
 new_best = getattr(dtype.itemtype, op_name)(cur_best, 
sig.eval(frame, self))
-print 'new_best',new_best.value,'cur_best',cur_best.value
 if dtype.itemtype.ne(new_best, cur_best):
 result = idx
 cur_best = new_best
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy numpypy-axisops: more finely distinguish between different 'promote_?' s

2011-12-27 Thread mattip
Author: mattip
Branch: numpypy-axisops
Changeset: r50920:e3824eb2fc4c
Date: 2011-12-28 03:38 +0200
http://bitbucket.org/pypy/pypy/changeset/e3824eb2fc4c/

Log:more finely distinguish between different 'promote_?' s

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
@@ -282,16 +282,17 @@
 descr_rpow = _binop_right_impl("power")
 descr_rmod = _binop_right_impl("mod")
 
-def _reduce_ufunc_impl(ufunc_name):
+def _reduce_ufunc_impl(ufunc_name, promote_to_largest = False):
 def impl(self, space, w_dim=None):
 if w_dim is None:
 w_dim = space.wrap(w_dim)
 return getattr(interp_ufuncs.get(space), ufunc_name).reduce(space,
-   self, True, w_dim)
+self, True, promote_to_largest, w_dim)
 return func_with_new_name(impl, "reduce_%s_impl" % ufunc_name)
 
 descr_sum = _reduce_ufunc_impl("add")
-descr_prod = _reduce_ufunc_impl("multiply")
+descr_sum_promote = _reduce_ufunc_impl("add", True)
+descr_prod = _reduce_ufunc_impl("multiply", True)
 descr_max = _reduce_ufunc_impl("maximum")
 descr_min = _reduce_ufunc_impl("minimum")
 
@@ -318,6 +319,7 @@
   idx=idx,
   cur_best=cur_best)
 new_best = getattr(dtype.itemtype, op_name)(cur_best, 
sig.eval(frame, self))
+print 'new_best',new_best.value,'cur_best',cur_best.value
 if dtype.itemtype.ne(new_best, cur_best):
 result = idx
 cur_best = new_best
@@ -560,7 +562,7 @@
 return w_result
 
 def descr_mean(self, space):
-return space.div(self.descr_sum(space), space.wrap(self.size))
+return space.div(self.descr_sum_promote(space), space.wrap(self.size))
 
 def descr_nonzero(self, space):
 if self.size > 1:
diff --git a/pypy/module/micronumpy/interp_ufuncs.py 
b/pypy/module/micronumpy/interp_ufuncs.py
--- a/pypy/module/micronumpy/interp_ufuncs.py
+++ b/pypy/module/micronumpy/interp_ufuncs.py
@@ -101,9 +101,9 @@
 array([[ 1,  5],
[ 9, 13]])
 '''
-return self.reduce(space, w_obj, False, w_dim)
+return self.reduce(space, w_obj, False, False, w_dim)
 
-def reduce(self, space, w_obj, multidim, w_dim):
+def reduce(self, space, w_obj, multidim, promote_to_largest, w_dim):
 from pypy.module.micronumpy.interp_numarray import convert_to_array, 
Scalar
 if self.argcount != 2:
 raise OperationError(space.w_ValueError, space.wrap("reduce only "
@@ -122,7 +122,9 @@
 size = obj.size
 dtype = find_unaryop_result_dtype(
 space, obj.find_dtype(),
-promote_to_float=self.promote_to_float
+promote_to_float=self.promote_to_float,
+promote_to_largest = promote_to_largest,
+promote_bools = True
 )
 shapelen = len(obj.shape)
 if self.identity is None and size == 0:
diff --git a/pypy/module/micronumpy/test/test_numarray.py 
b/pypy/module/micronumpy/test/test_numarray.py
--- a/pypy/module/micronumpy/test/test_numarray.py
+++ b/pypy/module/micronumpy/test/test_numarray.py
@@ -722,7 +722,7 @@
 raises(TypeError, 'a.sum(2, 3)')
 
 def test_sumND(self):
-skip('Not finished yet')
+from numpypy import arange
 a = arange(15).reshape(5, 3)
 assert (a.sum(0) == [30, 35, 40]).all()
 assert (a.sum(1) == [3, 12, 21, 30, 39]).all()
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit