[pypy-commit] pypy arm-backend-2: (arigo, bivab): move this hack to rmmap and make it a bit cleaner

2011-12-05 Thread bivab
Author: David Schneider david.schnei...@picle.org
Branch: arm-backend-2
Changeset: r50163:7873941fd23b
Date: 2011-12-02 12:23 +0100
http://bitbucket.org/pypy/pypy/changeset/7873941fd23b/

Log:(arigo, bivab): move this hack to rmmap and make it a bit cleaner

diff --git a/pypy/rlib/rmmap.py b/pypy/rlib/rmmap.py
--- a/pypy/rlib/rmmap.py
+++ b/pypy/rlib/rmmap.py
@@ -14,6 +14,8 @@
 _MS_WINDOWS = os.name == nt
 _LINUX = linux in sys.platform
 _64BIT = 64bit in platform.architecture()[0]
+_ARM = platform.machine().startswith('arm')
+_PPC = platform.machine().startswith('ppc')
 
 class RValueError(Exception):
 def __init__(self, message):
@@ -112,7 +114,11 @@
 
 if _POSIX:
 has_mremap = cConfig['has_mremap']
-c_mmap, c_mmap_safe = external('mmap', [PTR, size_t, rffi.INT, rffi.INT,
+if _ARM or _PPC:
+funcname = 'mmap64'
+else:
+funcname = 'mmap'
+c_mmap, c_mmap_safe = external(funcname, [PTR, size_t, rffi.INT, rffi.INT,
rffi.INT, off_t], PTR)
 _, c_munmap_safe = external('munmap', [PTR, size_t], rffi.INT)
 c_msync, _ = external('msync', [PTR, size_t, rffi.INT], rffi.INT)
diff --git a/pypy/rpython/lltypesystem/ll2ctypes.py 
b/pypy/rpython/lltypesystem/ll2ctypes.py
--- a/pypy/rpython/lltypesystem/ll2ctypes.py
+++ b/pypy/rpython/lltypesystem/ll2ctypes.py
@@ -1024,9 +1024,6 @@
 
 old_eci = funcptr._obj.compilation_info
 funcname = funcptr._obj._name
-#XXX Fix this, hack for ARM
-if funcname == 'mmap':
-funcname = 'mmap64'
 if hasattr(old_eci, '_with_ctypes'):
 old_eci = old_eci._with_ctypes
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy arm-backend-2: (arigo, bivab): clear CPU cache everty time instructions are written to memory and put breakpoints at the locations that are going to be patched

2011-12-05 Thread bivab
Author: David Schneider david.schnei...@picle.org
Branch: arm-backend-2
Changeset: r50166:8fbef9af526f
Date: 2011-12-02 23:04 +0100
http://bitbucket.org/pypy/pypy/changeset/8fbef9af526f/

Log:(arigo, bivab): clear CPU cache everty time instructions are written
to memory and put breakpoints at the locations that are going to be
patched

diff --git a/pypy/jit/backend/arm/codebuilder.py 
b/pypy/jit/backend/arm/codebuilder.py
--- a/pypy/jit/backend/arm/codebuilder.py
+++ b/pypy/jit/backend/arm/codebuilder.py
@@ -6,12 +6,19 @@
 
 from pypy.rlib.rmmap import alloc, PTR
 from pypy.rpython.annlowlevel import llhelper
-from pypy.rpython.lltypesystem import lltype, rffi
+from pypy.rpython.lltypesystem import lltype, rffi, llmemory
 from pypy.jit.metainterp.history import ConstInt, BoxInt, AbstractFailDescr
 from pypy.rlib.objectmodel import we_are_translated
 from pypy.jit.backend.llsupport.asmmemmgr import BlockBuilderMixin
 from pypy.tool.udir import udir
 
+__clear_cache = rffi.llexternal(
+__clear_cache,
+[llmemory.Address, llmemory.Address],
+lltype.Void,
+_nowrapper=True,
+sandboxsafe=True)
+
 def binary_helper_call(name):
 signature = getattr(arch, 'arm_%s_sign' % name)
 function = getattr(arch, 'arm_%s' % name)
@@ -284,8 +291,14 @@
 gcrootmap.put(rawstart + pos, mark)
 return rawstart
 
+def clear_cache(self, addr):
+startaddr = rffi.cast(llmemory.Address, addr)
+endaddr = rffi.cast(llmemory.Address, addr + self.get_relative_pos())
+__clear_cache(startaddr, endaddr)
+
 def copy_to_raw_memory(self, addr):
 self._copy_to_raw_memory(addr)
+self.clear_cache(addr)
 self._dump(addr, jit-backend-dump, 'arm')
 
 def currpos(self):
diff --git a/pypy/jit/backend/arm/opassembler.py 
b/pypy/jit/backend/arm/opassembler.py
--- a/pypy/jit/backend/arm/opassembler.py
+++ b/pypy/jit/backend/arm/opassembler.py
@@ -199,7 +199,7 @@
print 'Failargs: ', op.getfailargs()
 
 pos = self.mc.currpos()
-self.mc.NOP()
+self.mc.BKPT()
 self.pending_guards.append(GuardToken(descr,
 failargs=op.getfailargs(),
 faillocs=arglocs,
@@ -495,7 +495,7 @@
 self.mc.TST_ri(r.ip.value, imm=ofs)
 
 jz_location = self.mc.currpos()
-self.mc.NOP()
+self.mc.BKPT()
 
 # the following is supposed to be the slow path, so whenever possible
 # we choose the most compact encoding over the most efficient one.
@@ -958,7 +958,7 @@
 regalloc.possibly_free_var(resbox)
 
 fast_jmp_pos = self.mc.currpos()
-self.mc.NOP()
+self.mc.BKPT()
 
 # Path A: use assembler helper
 #if values are equal we take the fast path
@@ -981,7 +981,7 @@
 # jump to merge point
 jmp_pos = self.mc.currpos()
 #jmp_location = self.mc.curraddr()
-self.mc.NOP()
+self.mc.BKPT()
 
 # Path B: load return value and reset token
 # Fast Path using result boxes
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: A test and a fix

2011-12-05 Thread fijal
Author: Maciej Fijalkowski fij...@gmail.com
Branch: 
Changeset: r50168:6b51800a7ece
Date: 2011-12-05 13:09 +0200
http://bitbucket.org/pypy/pypy/changeset/6b51800a7ece/

Log:A test and a fix

diff --git a/pypy/jit/backend/llsupport/gc.py b/pypy/jit/backend/llsupport/gc.py
--- a/pypy/jit/backend/llsupport/gc.py
+++ b/pypy/jit/backend/llsupport/gc.py
@@ -823,6 +823,15 @@
 bool(v.value)): # store a non-NULL
 self._gen_write_barrier(newops, op.getarg(0), v)
 op = op.copy_and_change(rop.SETFIELD_RAW)
+# -- write barrier for SETINTERIORFIELD_GC --
+if op.getopnum() == rop.SETINTERIORFIELD_GC:
+val = op.getarg(0)
+if val is not last_malloc:
+v = op.getarg(2)
+if isinstance(v, BoxPtr) or (isinstance(v, ConstPtr) and
+bool(v.value)): # store a non-NULL
+self._gen_write_barrier(newops, op.getarg(0), v)
+op = op.copy_and_change(rop.SETINTERIORFIELD_RAW)
 # -- write barrier for SETARRAYITEM_GC --
 if op.getopnum() == rop.SETARRAYITEM_GC:
 val = op.getarg(0)
diff --git a/pypy/jit/backend/llsupport/test/test_gc.py 
b/pypy/jit/backend/llsupport/test/test_gc.py
--- a/pypy/jit/backend/llsupport/test/test_gc.py
+++ b/pypy/jit/backend/llsupport/test/test_gc.py
@@ -570,6 +570,28 @@
 assert operations[1].getarg(2) == v_value
 assert operations[1].getdescr() == array_descr
 
+def test_rewrite_assembler_5(self):
+S = lltype.GcStruct('S')
+A = lltype.GcArray(lltype.Struct('A', ('x', lltype.Ptr(S
+interiordescr = get_interiorfield_descr(self.gc_ll_descr, A,
+A.OF, 'x')
+wbdescr = self.gc_ll_descr.write_barrier_descr
+ops = parse(
+[p1, p2]
+setinteriorfield_gc(p1, 0, p2, descr=interiordescr)
+jump(p1, p2)
+, namespace=locals())
+expected = parse( 
+[p1, p2]
+cond_call_gc_wb(p1, p2, descr=wbdescr)
+setinteriorfield_raw(p1, 0, p2, descr=interiordescr)
+jump(p1, p2)
+, namespace=locals())
+operations = get_deep_immutable_oplist(ops.operations)
+operations = self.gc_ll_descr.rewrite_assembler(self.fake_cpu,
+operations, [])
+equaloplists(operations, expected.operations)
+
 def test_rewrite_assembler_initialization_store(self):
 S = lltype.GcStruct('S', ('parent', OBJECT),
 ('x', lltype.Signed))
diff --git a/pypy/jit/backend/x86/test/test_zrpy_gc.py 
b/pypy/jit/backend/x86/test/test_zrpy_gc.py
--- a/pypy/jit/backend/x86/test/test_zrpy_gc.py
+++ b/pypy/jit/backend/x86/test/test_zrpy_gc.py
@@ -492,7 +492,6 @@
 i += 1
 n -= x.foo
 return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
-f(123, *[None]*11)  # check that the check() are ok
 return None, f, None
 
 def test_compile_framework_7_interior(self):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy type-specialized-instances: fixed mapdict tests

2011-12-05 Thread l . diekmann
Author: Lukas Diekmann lukas.diekm...@uni-duesseldorf.de
Branch: type-specialized-instances
Changeset: r50169:591a337d364f
Date: 2011-12-05 12:32 +0100
http://bitbucket.org/pypy/pypy/changeset/591a337d364f/

Log:fixed mapdict tests

diff --git a/pypy/objspace/std/test/test_mapdict.py 
b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -25,17 +25,17 @@
 class typedef:
 hasdict = False
 
-def erase_storage_items(items):
-return [IntAttribute.erase_item(item) for item in items]
+def erase_storage_items(items, eraser=PlainAttribute):
+return [eraser.erase_item(item) for item in items]
 
-def unerase_storage_items(storage, uneraser=IntAttribute):
+def unerase_storage_items(storage, uneraser=PlainAttribute):
 return [uneraser.unerase_item(item) for item in storage]
 
 def test_plain_attribute():
 
 w_cls = class
-aa = IntAttribute((b, DICT),
-IntAttribute((a, DICT),
+aa = PlainAttribute((b, DICT),
+PlainAttribute((a, DICT),
Terminator(space, w_cls)))
 assert aa.space is space
 assert aa.terminator.w_cls is w_cls
@@ -81,7 +81,8 @@
 def test_add_attribute():
 cls = Class()
 obj = cls.instantiate()
-obj.setdictvalue(space, a, 10)
+obj.setdictvalue(space, a, space.wrap(10))
+print obj.map
 assert unerase_storage_items(obj.storage) == [10]
 assert obj.getdictvalue(space, a) == 10
 assert obj.getdictvalue(space, b) is None
@@ -159,9 +160,7 @@
 assert obj.getdictvalue(space, a) == 50
 assert obj.getdictvalue(space, b) == 60
 assert obj.getdictvalue(space, c) == 70
-#assert unerase_storage_items(obj.storage) == [50, 60, 70, lifeline1]
-assert unerase_storage_items(obj.storage[:-1], IntAttribute) == [50, 60, 
70]
-assert unerase_storage_items(obj.storage[-1:], PlainAttribute) == 
[lifeline1]
+assert unerase_storage_items(obj.storage) == [50, 60, 70, lifeline1]
 assert obj.getweakref() is lifeline1
 
 obj2 = c.instantiate()
@@ -169,9 +168,7 @@
 obj2.setdictvalue(space, b, 160)
 obj2.setdictvalue(space, c, 170)
 obj2.setweakref(space, lifeline2)
-#assert unerase_storage_items(obj2.storage) == [150, 160, 170, lifeline2]
-assert unerase_storage_items(obj2.storage[:-1], IntAttribute) == [150, 
160, 170]
-assert unerase_storage_items(obj2.storage[-1:], PlainAttribute) == 
[lifeline2]
+assert unerase_storage_items(obj2.storage) == [150, 160, 170, lifeline2]
 assert obj2.getweakref() is lifeline2
 
 assert obj2.map is obj.map
@@ -282,9 +279,7 @@
 assert flag
 materialize_r_dict(space, obj, d)
 assert d == {a: 5, b: 6, c: 7}
-#assert unerase_storage_items(obj.storage) == [50, 60, 70, w_d]
-assert unerase_storage_items(obj.storage[:-1], IntAttribute) == [50, 60, 
70]
-assert unerase_storage_items(obj.storage[-1:], PlainAttribute) == [w_d]
+assert unerase_storage_items(obj.storage) == [50, 60, 70, w_d]
 
 
 def test_size_prediction():
@@ -766,12 +761,21 @@
 def test_delete_slot(self):
 class A(object):
 __slots__ = ['x']
-
+
 a = A()
 a.x = 42
 del a.x
 raises(AttributeError, a.x)
 
+def test_subclassed_int(self):
+class Integer(int):
+pass
+
+a = Integer()
+a.x = 5
+
+assert a.x == 5
+
 class AppTestWithMapDictAndCounters(object):
 def setup_class(cls):
 from pypy.interpreter import gateway
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy nedbat-sandbox: Remove some pypy dependencies from sandlib.

2011-12-05 Thread ned
Author: Ned Batchelder n...@nedbatchelder.com
Branch: nedbat-sandbox
Changeset: r50170:4fe097ff1a9b
Date: 2011-12-05 08:49 -0500
http://bitbucket.org/pypy/pypy/changeset/4fe097ff1a9b/

Log:Remove some pypy dependencies from sandlib.

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
@@ -6,9 +6,7 @@
 
 import py
 import sys, os, posixpath, errno, stat, time
-from pypy.rpython.module.ll_os_stat import s_StatResult
 from pypy.tool.ansi_print import AnsiLog
-from pypy.rlib.rarithmetic import r_longlong
 import subprocess
 from pypy.tool.killsubprocess import killsubprocess
 
@@ -34,6 +32,9 @@
 from pypy.tool.lib_pypy import import_from_lib_pypy
 marshal = import_from_lib_pypy('marshal')
 
+# Non-marshal result types
+RESULTTYPE_STATRESULT, RESULTTYPE_LONGLONG = range(2)
+
 def read_message(f, timeout=None):
 # warning: 'timeout' is not really reliable and should only be used
 # for testing.  Also, it doesn't work if the file f does any buffering.
@@ -50,7 +51,7 @@
 marshal.dump(msg, g)
 else:
 marshal.dump(msg, g, 0)
-elif resulttype is s_StatResult:
+elif resulttype is RESULTTYPE_STATRESULT:
 # Hand-coded marshal for stat results that mimics what rmarshal 
expects.
 # marshal.dump(tuple(msg)) would have been too easy. rmarshal insists
 # on 64-bit ints at places, even when the value fits in 32 bits.
@@ -69,12 +70,11 @@
 buf.append(struct.pack(cB, c, len(fstr)))
 buf.append(fstr)
 g.write(''.join(buf))
+elif resulttype is RESULTTYPE_LONGLONG:
+import struct
+g.write(struct.pack(cq, 'I', msg))
 else:
-# use the exact result type for encoding
-from pypy.rlib.rmarshal import get_marshaller
-buf = []
-get_marshaller(resulttype)(buf, msg)
-g.write(''.join(buf))
+raise Exception(Can't marshal: %r (%r) % (msg, resulttype))
 
 # keep the table in sync with rsandbox.reraise_error()
 EXCEPTION_TABLE = [
@@ -444,7 +444,7 @@
 def do_ll_os__ll_os_stat(self, vpathname):
 node = self.get_node(vpathname)
 return node.stat()
-do_ll_os__ll_os_stat.resulttype = s_StatResult
+do_ll_os__ll_os_stat.resulttype = RESULTTYPE_STATRESULT
 
 do_ll_os__ll_os_lstat = do_ll_os__ll_os_stat
 
@@ -505,13 +505,13 @@
 def do_ll_os__ll_os_fstat(self, fd):
 f, node = self.get_fd(fd)
 return node.stat()
-do_ll_os__ll_os_fstat.resulttype = s_StatResult
+do_ll_os__ll_os_fstat.resulttype = RESULTTYPE_STATRESULT
 
 def do_ll_os__ll_os_lseek(self, fd, pos, how):
 f = self.get_file(fd)
 f.seek(pos, how)
 return f.tell()
-do_ll_os__ll_os_lseek.resulttype = r_longlong
+do_ll_os__ll_os_lseek.resulttype = RESULTTYPE_LONGLONG
 
 def do_ll_os__ll_os_getcwd(self):
 return self.virtual_cwd
diff --git a/pypy/translator/sandbox/test/test_sandbox.py 
b/pypy/translator/sandbox/test/test_sandbox.py
--- a/pypy/translator/sandbox/test/test_sandbox.py
+++ b/pypy/translator/sandbox/test/test_sandbox.py
@@ -80,7 +80,7 @@
 assert tail == 
 
 def test_stat_ftruncate():
-from pypy.rpython.module.ll_os_stat import s_StatResult
+from pypy.translator.sandbox.sandlib import RESULTTYPE_STATRESULT
 from pypy.rlib.rarithmetic import r_longlong
 r0x1238007 = r_longlong(0x1238007)
 
@@ -93,7 +93,7 @@
 g, f = os.popen2(exe, t, 0)
 st = os.stat_result((55, 0, 0, 0, 0, 0, 0x1238007, 0, 0, 0))
 expect(f, g, ll_os.ll_os_stat, (somewhere,), st,
-   resulttype = s_StatResult)
+   resulttype = RESULTTYPE_STATRESULT)
 expect(f, g, ll_os.ll_os_ftruncate, (55, 0x1238007), None)
 g.close()
 tail = f.read()
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy ppc-jit-backend: Add cashe flushing

2011-12-05 Thread hager
Author: hager sven.ha...@uni-duesseldorf.de
Branch: ppc-jit-backend
Changeset: r50171:22a892ccc25e
Date: 2011-12-05 17:24 +0100
http://bitbucket.org/pypy/pypy/changeset/22a892ccc25e/

Log:Add cashe flushing

diff --git a/pypy/jit/backend/ppc/ppcgen/codebuilder.py 
b/pypy/jit/backend/ppc/ppcgen/codebuilder.py
--- a/pypy/jit/backend/ppc/ppcgen/codebuilder.py
+++ b/pypy/jit/backend/ppc/ppcgen/codebuilder.py
@@ -18,7 +18,7 @@
  compute_vars_longevity)
 from pypy.jit.backend.llsupport import symbolic
 from pypy.jit.backend.model import CompiledLoopToken
-from pypy.rpython.lltypesystem import lltype, rffi, rstr
+from pypy.rpython.lltypesystem import lltype, rffi, rstr, llmemory
 from pypy.jit.metainterp.resoperation import rop
 from pypy.jit.metainterp.history import (BoxInt, ConstInt, ConstPtr,
  ConstFloat, Box, INT, REF, FLOAT)
@@ -26,6 +26,8 @@
 from pypy.tool.udir import udir
 from pypy.rlib.objectmodel import we_are_translated
 
+from pypy.translator.tool.cbuild import ExternalCompilationInfo
+
 A = Form(frD, frA, frB, XO3, Rc)
 A1 = Form(frD, frB, XO3, Rc)
 A2 = Form(frD, frA, frC, XO3, Rc)
@@ -918,6 +920,20 @@
 def high(w):
 return (w  16)  0x
 
+# XXX check this
+if we_are_translated():
+eci = ExternalCompilationInfo(includes = ['asm_ppc.h'])
+
+flush_icache = rffi.llexternal(
+LL_flush_icache,
+[lltype.Signed, lltype.Signed],
+lltype.Void,
+compilation_info=eci,
+_nowrapper=True,
+sandboxsafe=True)
+else:
+def flush_icache(x, y): pass
+
 class GuardToken(object):
 def __init__(self, descr, failargs, faillocs, offset,
 save_exc=False, is_invalidate=False):
@@ -1039,8 +1055,14 @@
 def currpos(self):
 return self.get_rel_pos()
 
+def flush_cache(self, addr):
+startaddr = rffi.cast(lltype.Signed, addr)
+size = rffi.cast(lltype.Signed, self.get_relative_pos())
+flush_icache(startaddr, size)
+
 def copy_to_raw_memory(self, addr):
 self._copy_to_raw_memory(addr)
+self.flush_cache(addr)
 
 def cmp_op(self, block, a, b, imm=False, signed=True):
 if IS_PPC_32:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jit-targets: hg merge default

2011-12-05 Thread hakanardo
Author: Hakan Ardo ha...@debian.org
Branch: jit-targets
Changeset: r50172:d638586fc5b1
Date: 2011-12-05 16:16 +0100
http://bitbucket.org/pypy/pypy/changeset/d638586fc5b1/

Log:hg merge default

diff --git a/pypy/jit/backend/llsupport/gc.py b/pypy/jit/backend/llsupport/gc.py
--- a/pypy/jit/backend/llsupport/gc.py
+++ b/pypy/jit/backend/llsupport/gc.py
@@ -823,6 +823,15 @@
 bool(v.value)): # store a non-NULL
 self._gen_write_barrier(newops, op.getarg(0), v)
 op = op.copy_and_change(rop.SETFIELD_RAW)
+# -- write barrier for SETINTERIORFIELD_GC --
+if op.getopnum() == rop.SETINTERIORFIELD_GC:
+val = op.getarg(0)
+if val is not last_malloc:
+v = op.getarg(2)
+if isinstance(v, BoxPtr) or (isinstance(v, ConstPtr) and
+bool(v.value)): # store a non-NULL
+self._gen_write_barrier(newops, op.getarg(0), v)
+op = op.copy_and_change(rop.SETINTERIORFIELD_RAW)
 # -- write barrier for SETARRAYITEM_GC --
 if op.getopnum() == rop.SETARRAYITEM_GC:
 val = op.getarg(0)
diff --git a/pypy/jit/backend/llsupport/test/test_gc.py 
b/pypy/jit/backend/llsupport/test/test_gc.py
--- a/pypy/jit/backend/llsupport/test/test_gc.py
+++ b/pypy/jit/backend/llsupport/test/test_gc.py
@@ -570,6 +570,28 @@
 assert operations[1].getarg(2) == v_value
 assert operations[1].getdescr() == array_descr
 
+def test_rewrite_assembler_5(self):
+S = lltype.GcStruct('S')
+A = lltype.GcArray(lltype.Struct('A', ('x', lltype.Ptr(S
+interiordescr = get_interiorfield_descr(self.gc_ll_descr, A,
+A.OF, 'x')
+wbdescr = self.gc_ll_descr.write_barrier_descr
+ops = parse(
+[p1, p2]
+setinteriorfield_gc(p1, 0, p2, descr=interiordescr)
+jump(p1, p2)
+, namespace=locals())
+expected = parse( 
+[p1, p2]
+cond_call_gc_wb(p1, p2, descr=wbdescr)
+setinteriorfield_raw(p1, 0, p2, descr=interiordescr)
+jump(p1, p2)
+, namespace=locals())
+operations = get_deep_immutable_oplist(ops.operations)
+operations = self.gc_ll_descr.rewrite_assembler(self.fake_cpu,
+operations, [])
+equaloplists(operations, expected.operations)
+
 def test_rewrite_assembler_initialization_store(self):
 S = lltype.GcStruct('S', ('parent', OBJECT),
 ('x', lltype.Signed))
diff --git a/pypy/jit/backend/x86/test/test_zrpy_gc.py 
b/pypy/jit/backend/x86/test/test_zrpy_gc.py
--- a/pypy/jit/backend/x86/test/test_zrpy_gc.py
+++ b/pypy/jit/backend/x86/test/test_zrpy_gc.py
@@ -490,8 +490,8 @@
 check(a[i].y.i == n + i * 100 + 2)
 check(a[i].z.i == n + i * 100 + 3)
 i += 1
+n -= x.foo
 return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
-f(123, *[None]*11)  # check that the check() are ok
 return None, f, None
 
 def test_compile_framework_7_interior(self):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jit-targets: dont crash if two equal virtuals become not equal

2011-12-05 Thread hakanardo
Author: Hakan Ardo ha...@debian.org
Branch: jit-targets
Changeset: r50173:9f840860f2cb
Date: 2011-12-05 17:35 +0100
http://bitbucket.org/pypy/pypy/changeset/9f840860f2cb/

Log:dont crash if two equal virtuals become not equal

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
@@ -172,6 +172,27 @@
 with raises(InvalidLoop):
 self.optimize_loop(ops, ops)
 
+def test_virtual_turns_constant(self):
+ops = 
+[p1]
+p3 = new_with_vtable(ConstClass(node_vtable))
+label(p3)
+guard_value(p3, ConstPtr(myptr)) []
+jump(p3)
+
+with raises(InvalidLoop):
+self.optimize_loop(ops, ops)
+
+def test_virtuals_turns_not_equal(self):
+ops = 
+[p1, p2]
+p3 = new_with_vtable(ConstClass(node_vtable))
+label(p3, p3)
+p4 = new_with_vtable(ConstClass(node_vtable))
+jump(p3, p4)
+
+with raises(InvalidLoop):
+self.optimize_loop(ops, ops)
 
 
 class TestLLtype(BaseTestMultiLabel, LLtypeMixin):
diff --git a/pypy/jit/metainterp/optimizeopt/unroll.py 
b/pypy/jit/metainterp/optimizeopt/unroll.py
--- a/pypy/jit/metainterp/optimizeopt/unroll.py
+++ b/pypy/jit/metainterp/optimizeopt/unroll.py
@@ -281,6 +281,13 @@
 
 # Inline the short preamble at the end of the loop
 jmp_to_short_args = virtual_state.make_inputargs(values, 
self.optimizer, keyboxes=True)
+assert len(short_inputargs) == len(jmp_to_short_args)
+args = {}
+for i in range(len(short_inputargs)):
+if short_inputargs[i] in args:
+if args[short_inputargs[i]] != jmp_to_short_args[i]:
+raise InvalidLoop
+args[short_inputargs[i]] = jmp_to_short_args[i]
 self.short_inliner = Inliner(short_inputargs, jmp_to_short_args)
 for box, const in constant_inputargs.items():
 self.short_inliner.argmap[box] = const
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Add a failing test.

2011-12-05 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r50174:0d1f6b514b53
Date: 2011-12-05 18:22 +0100
http://bitbucket.org/pypy/pypy/changeset/0d1f6b514b53/

Log:Add a failing test.

diff --git a/pypy/jit/metainterp/test/test_recursive.py 
b/pypy/jit/metainterp/test/test_recursive.py
--- a/pypy/jit/metainterp/test/test_recursive.py
+++ b/pypy/jit/metainterp/test/test_recursive.py
@@ -1238,6 +1238,30 @@
 self.meta_interp(portal, [0, 0, 0], inline=True)
 self.check_resops(call_may_force=0, call=0)
 
+def test_dont_repeatedly_trace_from_the_same_guard(self):
+driver = JitDriver(greens = [], reds = ['level', 'i'])
+
+def portal(level):
+if level == 0:
+i = -10
+else:
+i = 0
+#
+while True:
+driver.jit_merge_point(level=level, i=i)
+if level == 25:
+return 42
+i += 1
+if i = 0:  # - guard
+continue# first make a loop
+else:
+# then we fail the guard above, doing a recursive call
+return portal(level + 1)
+
+self.meta_interp(portal, [0])
+assert self.check_loop_count_at_most(3)   # and not, e.g., 24
+
+
 class TestLLtype(RecursiveTests, LLJitMixin):
 pass
 
___
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-05 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r50175:5abc8457062e
Date: 2011-12-05 19:05 +0100
http://bitbucket.org/pypy/pypy/changeset/5abc8457062e/

Log:Fix the test.

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
@@ -298,7 +298,7 @@
 pass
 
 class ResumeGuardDescr(ResumeDescr):
-_counter = 0# if  0, there is one counter per value;
+_counter = 0# on a GUARD_VALUE, there is one counter per value;
 _counters = None# they get stored in _counters then.
 
 # this class also gets the following attributes stored by resume.py code
@@ -309,10 +309,13 @@
 rd_virtuals = None
 rd_pendingfields = lltype.nullptr(PENDINGFIELDSP.TO)
 
-CNT_INT   = -0x2000
-CNT_REF   = -0x4000
-CNT_FLOAT = -0x6000
-CNT_MASK  =  0x1FFF
+CNT_BASE_MASK  =  0x0FFF # the base counter value
+CNT_BUSY_FLAG  =  0x1000 # if set, busy tracing from the guard
+CNT_TYPE_MASK  =  0x6000 # mask for the type
+
+CNT_INT=  0x2000
+CNT_REF=  0x4000
+CNT_FLOAT  =  0x6000
 
 def store_final_boxes(self, guard_op, boxes):
 guard_op.setfailargs(boxes)
@@ -326,6 +329,8 @@
 except ValueError:
 return # xxx probably very rare
 else:
+if i  self.CNT_BASE_MASK:
+return# probably never, but better safe than sorry
 if box.type == history.INT:
 cnt = self.CNT_INT
 elif box.type == history.REF:
@@ -334,14 +339,17 @@
 cnt = self.CNT_FLOAT
 else:
 assert 0, box.type
-# we build the following value for _counter, which is always
-# a negative value
+assert cnt  self.CNT_BASE_MASK
 self._counter = cnt | i
 
 def handle_fail(self, metainterp_sd, jitdriver_sd):
 if self.must_compile(metainterp_sd, jitdriver_sd):
-return self._trace_and_compile_from_bridge(metainterp_sd,
-   jitdriver_sd)
+self.start_compiling()
+try:
+return self._trace_and_compile_from_bridge(metainterp_sd,
+   jitdriver_sd)
+finally:
+self.done_compiling()
 else:
 from pypy.jit.metainterp.blackhole import resume_in_blackhole
 resume_in_blackhole(metainterp_sd, jitdriver_sd, self)
@@ -359,12 +367,22 @@
 
 def must_compile(self, metainterp_sd, jitdriver_sd):
 trace_eagerness = jitdriver_sd.warmstate.trace_eagerness
-if self._counter = 0:
+#
+if self._counter = self.CNT_BASE_MASK:
+# simple case: just counting from 0 to trace_eagerness
 self._counter += 1
 return self._counter = trace_eagerness
-else:
-index = self._counter  self.CNT_MASK
-typetag = self._counter  ~ self.CNT_MASK
+#
+# do we have the BUSY flag?  If so, we're tracing right now, e.g. in an
+# outer invocation of the same function, so don't trace again for now.
+elif self._counter  self.CNT_BUSY_FLAG:
+return False
+#
+else: # we have a GUARD_VALUE that fails.  Make a _counters instance
+# (only now, when the guard is actually failing at least once),
+# and use it to record some statistics about the failing values.
+index = self._counter  self.CNT_BASE_MASK
+typetag = self._counter  self.CNT_TYPE_MASK
 counters = self._counters
 if typetag == self.CNT_INT:
 intvalue = metainterp_sd.cpu.get_latest_value_int(index)
@@ -391,7 +409,16 @@
 assert 0, typetag
 return counter = trace_eagerness
 
-def reset_counter_from_failure(self):
+def start_compiling(self):
+# start tracing and compiling from this guard.
+self._counter |= self.CNT_BUSY_FLAG
+
+def done_compiling(self):
+# done tracing and compiling from this guard.  Either the bridge has
+# been successfully compiled, in which case whatever value we store
+# in self._counter will not be seen any more, or not, in which case
+# we should reset the counter to 0, in order to wait a bit until the
+# next attempt.
 if self._counter = 0:
 self._counter = 0
 self._counters = None
@@ -608,9 +635,6 @@
 metainterp.set_compiled_merge_points(self.original_greenkey,
  old_loop_tokens)
 
-def reset_counter_from_failure(self):
-pass
-
 
 def compile_new_bridge(metainterp, old_loop_tokens, resumekey, retraced=False):
 Try to compile a new bridge leading from the beginning of 

[pypy-commit] pypy numpy-dtype-refactor-complex: merged default

2011-12-05 Thread alex_gaynor
Author: Alex Gaynor alex.gay...@gmail.com
Branch: numpy-dtype-refactor-complex
Changeset: r50177:006352005df1
Date: 2011-12-05 13:53 -0500
http://bitbucket.org/pypy/pypy/changeset/006352005df1/

Log:merged default

diff --git a/pypy/jit/backend/llsupport/gc.py b/pypy/jit/backend/llsupport/gc.py
--- a/pypy/jit/backend/llsupport/gc.py
+++ b/pypy/jit/backend/llsupport/gc.py
@@ -823,6 +823,15 @@
 bool(v.value)): # store a non-NULL
 self._gen_write_barrier(newops, op.getarg(0), v)
 op = op.copy_and_change(rop.SETFIELD_RAW)
+# -- write barrier for SETINTERIORFIELD_GC --
+if op.getopnum() == rop.SETINTERIORFIELD_GC:
+val = op.getarg(0)
+if val is not last_malloc:
+v = op.getarg(2)
+if isinstance(v, BoxPtr) or (isinstance(v, ConstPtr) and
+bool(v.value)): # store a non-NULL
+self._gen_write_barrier(newops, op.getarg(0), v)
+op = op.copy_and_change(rop.SETINTERIORFIELD_RAW)
 # -- write barrier for SETARRAYITEM_GC --
 if op.getopnum() == rop.SETARRAYITEM_GC:
 val = op.getarg(0)
diff --git a/pypy/jit/backend/llsupport/test/test_gc.py 
b/pypy/jit/backend/llsupport/test/test_gc.py
--- a/pypy/jit/backend/llsupport/test/test_gc.py
+++ b/pypy/jit/backend/llsupport/test/test_gc.py
@@ -570,6 +570,28 @@
 assert operations[1].getarg(2) == v_value
 assert operations[1].getdescr() == array_descr
 
+def test_rewrite_assembler_5(self):
+S = lltype.GcStruct('S')
+A = lltype.GcArray(lltype.Struct('A', ('x', lltype.Ptr(S
+interiordescr = get_interiorfield_descr(self.gc_ll_descr, A,
+A.OF, 'x')
+wbdescr = self.gc_ll_descr.write_barrier_descr
+ops = parse(
+[p1, p2]
+setinteriorfield_gc(p1, 0, p2, descr=interiordescr)
+jump(p1, p2)
+, namespace=locals())
+expected = parse( 
+[p1, p2]
+cond_call_gc_wb(p1, p2, descr=wbdescr)
+setinteriorfield_raw(p1, 0, p2, descr=interiordescr)
+jump(p1, p2)
+, namespace=locals())
+operations = get_deep_immutable_oplist(ops.operations)
+operations = self.gc_ll_descr.rewrite_assembler(self.fake_cpu,
+operations, [])
+equaloplists(operations, expected.operations)
+
 def test_rewrite_assembler_initialization_store(self):
 S = lltype.GcStruct('S', ('parent', OBJECT),
 ('x', lltype.Signed))
diff --git a/pypy/jit/backend/x86/test/test_zrpy_gc.py 
b/pypy/jit/backend/x86/test/test_zrpy_gc.py
--- a/pypy/jit/backend/x86/test/test_zrpy_gc.py
+++ b/pypy/jit/backend/x86/test/test_zrpy_gc.py
@@ -490,8 +490,8 @@
 check(a[i].y.i == n + i * 100 + 2)
 check(a[i].z.i == n + i * 100 + 3)
 i += 1
+n -= x.foo
 return n, x, x0, x1, x2, x3, x4, x5, x6, x7, l, s
-f(123, *[None]*11)  # check that the check() are ok
 return None, f, None
 
 def test_compile_framework_7_interior(self):
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
@@ -298,7 +298,7 @@
 pass
 
 class ResumeGuardDescr(ResumeDescr):
-_counter = 0# if  0, there is one counter per value;
+_counter = 0# on a GUARD_VALUE, there is one counter per value;
 _counters = None# they get stored in _counters then.
 
 # this class also gets the following attributes stored by resume.py code
@@ -309,10 +309,13 @@
 rd_virtuals = None
 rd_pendingfields = lltype.nullptr(PENDINGFIELDSP.TO)
 
-CNT_INT   = -0x2000
-CNT_REF   = -0x4000
-CNT_FLOAT = -0x6000
-CNT_MASK  =  0x1FFF
+CNT_BASE_MASK  =  0x0FFF # the base counter value
+CNT_BUSY_FLAG  =  0x1000 # if set, busy tracing from the guard
+CNT_TYPE_MASK  =  0x6000 # mask for the type
+
+CNT_INT=  0x2000
+CNT_REF=  0x4000
+CNT_FLOAT  =  0x6000
 
 def store_final_boxes(self, guard_op, boxes):
 guard_op.setfailargs(boxes)
@@ -326,6 +329,8 @@
 except ValueError:
 return # xxx probably very rare
 else:
+if i  self.CNT_BASE_MASK:
+return# probably never, but better safe than sorry
 if box.type == history.INT:
 cnt = self.CNT_INT
 elif box.type == history.REF:
@@ -334,14 +339,17 @@
 cnt = self.CNT_FLOAT
 else:
 assert 0, box.type
-# we build the following value for 

[pypy-commit] pypy numpy-dtype-refactor-complex: added real and imag descriptors to complex objs

2011-12-05 Thread alex_gaynor
Author: Alex Gaynor alex.gay...@gmail.com
Branch: numpy-dtype-refactor-complex
Changeset: r50176:7a810c2bdf0d
Date: 2011-12-05 13:51 -0500
http://bitbucket.org/pypy/pypy/changeset/7a810c2bdf0d/

Log:added real and imag descriptors to complex objs

diff --git a/pypy/module/micronumpy/interp_boxes.py 
b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -1,7 +1,7 @@
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.error import operationerrfmt
 from pypy.interpreter.gateway import interp2app
-from pypy.interpreter.typedef import TypeDef
+from pypy.interpreter.typedef import TypeDef, GetSetProperty
 from pypy.objspace.std.complextype import complex_typedef
 from pypy.objspace.std.floattype import float_typedef
 from pypy.objspace.std.inttype import int_typedef
@@ -65,6 +65,14 @@
 dtype = self.get_dtype(space)
 return space.wrap(dtype.itemtype.bool(self))
 
+def descr_get_real(self, space):
+dtype = self.get_dtype(space)
+return dtype.itemtype.real(self)
+
+def descr_get_imag(self, space):
+dtype = self.get_dtype(space)
+return dtype.itemtype.imag(self)
+
 def _binop_impl(ufunc_name):
 def impl(self, space, w_other):
 from pypy.module.micronumpy import interp_ufuncs
@@ -197,6 +205,9 @@
 
 __neg__ = interp2app(W_GenericBox.descr_neg),
 __abs__ = interp2app(W_GenericBox.descr_abs),
+
+real = GetSetProperty(W_GenericBox.descr_get_real),
+imag = GetSetProperty(W_GenericBox.descr_get_imag),
 )
 
 W_BoolBox.typedef = TypeDef(bool_, W_GenericBox.typedef,
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -34,6 +34,15 @@
 )
 return dispatcher
 
+def raw_unary_op(func):
+specialize.argtype(1)
+@functools.wraps(func)
+def dispatcher(self, v):
+return func(self,
+self.for_computation(self.unbox(v))
+)
+return dispatcher
+
 def raw_binary_op(func):
 specialize.argtype(1, 2)(func)
 @functools.wraps(func)
@@ -429,20 +438,28 @@
 
 def __init__(self, itemtypes):
 BaseCompositeType.__init__(self, itemtypes)
-[self.real, self.imag] = self.itemtypes
+[self.real_type, self.imag_type] = self.itemtypes
 
 def coerce(self, space, w_item):
 if isinstance(w_item, self.BoxType):
 return w_item
 real, imag = space.unpackcomplex(w_item)
-return self.box([self.real.box(real), self.imag.box(imag)])
-
+return self.box([self.real_type.box(real), self.imag_type.box(imag)])
+
 def for_computation(self, (real, imag)):
 return [
-self.real.for_computation(self.real.unbox(real)),
-self.imag.for_computation(self.imag.unbox(imag)),
+self.real_type.for_computation(self.real_type.unbox(real)),
+self.imag_type.for_computation(self.imag_type.unbox(imag)),
 ]
 
 @raw_binary_op
 def eq(self, (real1, imag1), (real2, imag2)):
 return real1 == real2 and imag1 == imag2
+
+@raw_unary_op
+def real(self, (real, imag)):
+return self.real_type.box(real)
+
+@raw_unary_op
+def imag(self, (real, imag)):
+return self.imag_type.box(imag)
\ No newline at end of file
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy numpy-dtype-refactor-complex: fix, make this numpypy

2011-12-05 Thread alex_gaynor
Author: Alex Gaynor alex.gay...@gmail.com
Branch: numpy-dtype-refactor-complex
Changeset: r50178:22862d325dba
Date: 2011-12-05 13:57 -0500
http://bitbucket.org/pypy/pypy/changeset/22862d325dba/

Log:fix, make this numpypy

diff --git a/pypy/module/micronumpy/interp_boxes.py 
b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -294,9 +294,9 @@
 )
 
 W_ComplexFloatingBox.typedef = TypeDef(complexfloating, W_InexactBox.typedef,
-__module__ = numpy,
+__module__ = numpypy,
 )
 
 W_Complex128Box.typedef = TypeDef(complex128, (W_ComplexFloatingBox.typedef, 
complex_typedef),
-__module__ = numpy,
-)
\ No newline at end of file
+__module__ = numpypy,
+)
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -462,4 +462,4 @@
 
 @raw_unary_op
 def imag(self, (real, imag)):
-return self.imag_type.box(imag)
\ No newline at end of file
+return self.imag_type.box(imag)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Add a test that I wrote long ago, but apparently forgot to check in.

2011-12-05 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r50179:ed550a1d0c11
Date: 2011-12-05 20:07 +0100
http://bitbucket.org/pypy/pypy/changeset/ed550a1d0c11/

Log:Add a test that I wrote long ago, but apparently forgot to check in.

diff --git a/pypy/jit/metainterp/test/test_math.py 
b/pypy/jit/metainterp/test/test_math.py
new file mode 100644
--- /dev/null
+++ b/pypy/jit/metainterp/test/test_math.py
@@ -0,0 +1,47 @@
+import math
+from pypy.jit.metainterp.test.support import LLJitMixin, OOJitMixin
+from pypy.rlib.rfloat import isinf, isnan, INFINITY, NAN
+
+class MathTests:
+
+def test_math_sqrt(self):
+def f(x):
+try:
+return math.sqrt(x)
+except ValueError:
+return -INFINITY
+
+res = self.interp_operations(f, [0.0])
+assert res == 0.0
+self.check_operations_history(call_pure=1)
+#
+res = self.interp_operations(f, [25.0])
+assert res == 5.0
+self.check_operations_history(call_pure=1)
+#
+res = self.interp_operations(f, [-0.0])
+assert str(res) == '-0.0'
+self.check_operations_history(call_pure=1)
+#
+res = self.interp_operations(f, [100.0])
+assert res == 1000.0
+self.check_operations_history(call_pure=1)
+#
+res = self.interp_operations(f, [-1.0])
+assert res == -INFINITY
+self.check_operations_history(call_pure=0)
+#
+res = self.interp_operations(f, [INFINITY])
+assert isinf(res) and not isnan(res) and res  0.0
+self.check_operations_history(call_pure=0)
+#
+res = self.interp_operations(f, [NAN])
+assert isnan(res) and not isinf(res)
+self.check_operations_history(call_pure=0)
+
+
+class TestOOtype(MathTests, OOJitMixin):
+pass
+
+class TestLLtype(MathTests, LLJitMixin):
+pass
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Test and fix.

2011-12-05 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r50180:92d4f8f7bcfb
Date: 2011-12-05 20:31 +0100
http://bitbucket.org/pypy/pypy/changeset/92d4f8f7bcfb/

Log:Test and fix.

diff --git a/pypy/module/_collections/app_defaultdict.py 
b/pypy/module/_collections/app_defaultdict.py
--- a/pypy/module/_collections/app_defaultdict.py
+++ b/pypy/module/_collections/app_defaultdict.py
@@ -13,12 +13,14 @@
 class defaultdict(dict):
 
 def __init__(self, *args, **kwds):
-self.default_factory = None
-if 'default_factory' in kwds:
-self.default_factory = kwds.pop('default_factory')
-elif len(args)  0 and (callable(args[0]) or args[0] is None):
-self.default_factory = args[0]
+if len(args)  0:
+default_factory = args[0]
 args = args[1:]
+if not callable(default_factory) and default_factory is not None:
+raise TypeError(first argument must be callable)
+else:
+default_factory = None
+self.default_factory = default_factory
 super(defaultdict, self).__init__(*args, **kwds)
  
 def __missing__(self, key):
diff --git a/pypy/module/_collections/test/test_defaultdict.py 
b/pypy/module/_collections/test/test_defaultdict.py
--- a/pypy/module/_collections/test/test_defaultdict.py
+++ b/pypy/module/_collections/test/test_defaultdict.py
@@ -19,11 +19,22 @@
 
 def test_keyerror_without_factory(self):
 from _collections import defaultdict
-d1 = defaultdict()
-for key in ['foo', (1,)]:
-try:
-d1[key]
-except KeyError, err:
-assert err.args[0] == key
-else:
-assert 0, expected KeyError
+for d1 in [defaultdict(), defaultdict(None)]:
+for key in ['foo', (1,)]:
+try:
+d1[key]
+except KeyError, err:
+assert err.args[0] == key
+else:
+assert 0, expected KeyError
+
+def test_noncallable(self):
+from _collections import defaultdict
+raises(TypeError, defaultdict, [('a', 5)])
+d = defaultdict(None, [('a', 5)])
+assert d.items() == [('a', 5)]
+
+def test_kwds(self):
+from _collections import defaultdict
+d = defaultdict(default_factory=5)
+assert d.keys() == ['default_factory']
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Forgot this version of the file. Thanks amaury.

2011-12-05 Thread arigo
Author: Armin Rigo ar...@tunes.org
Branch: 
Changeset: r50181:0732486f6a76
Date: 2011-12-05 20:39 +0100
http://bitbucket.org/pypy/pypy/changeset/0732486f6a76/

Log:Forgot this version of the file. Thanks amaury.

diff --git a/lib_pypy/_collections.py b/lib_pypy/_collections.py
--- a/lib_pypy/_collections.py
+++ b/lib_pypy/_collections.py
@@ -379,12 +379,14 @@
 class defaultdict(dict):
 
 def __init__(self, *args, **kwds):
-self.default_factory = None
-if 'default_factory' in kwds:
-self.default_factory = kwds.pop('default_factory')
-elif len(args)  0 and (callable(args[0]) or args[0] is None):
-self.default_factory = args[0]
+if len(args)  0:
+default_factory = args[0]
 args = args[1:]
+if not callable(default_factory) and default_factory is not None:
+raise TypeError(first argument must be callable)
+else:
+default_factory = None
+self.default_factory = default_factory
 super(defaultdict, self).__init__(*args, **kwds)
  
 def __missing__(self, key):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy jit-targets: Dont rgc.collect() more than we have too (not working when run in a separate process by test_all)

2011-12-05 Thread hakanardo
Author: Hakan Ardo ha...@debian.org
Branch: jit-targets
Changeset: r50182:417d2384375b
Date: 2011-12-05 22:10 +0100
http://bitbucket.org/pypy/pypy/changeset/417d2384375b/

Log:Dont rgc.collect() more than we have too (not working when run in a
separate process by test_all)

diff --git a/pypy/jit/metainterp/test/test_memmgr.py 
b/pypy/jit/metainterp/test/test_memmgr.py
--- a/pypy/jit/metainterp/test/test_memmgr.py
+++ b/pypy/jit/metainterp/test/test_memmgr.py
@@ -15,6 +15,8 @@
 from pypy.jit.metainterp.test.support import LLJitMixin
 from pypy.rlib.jit import JitDriver, dont_look_inside
 from pypy.jit.metainterp.warmspot import get_stats
+from pypy.jit.metainterp.warmstate import JitCell
+from pypy.rlib import rgc
 
 class FakeLoopToken:
 generation = 0
@@ -81,6 +83,20 @@
 # See comments in TestMemoryManager.  To get temporarily the normal
 # behavior just rename this class to TestIntegration.
 
+# We need an extra rgc.collect in get_procedure_token() for some of
+# these tests to pass. But we dont want it there always since that will
+# make all other tests take forever.
+def setup_class(cls):
+original_get_procedure_token = JitCell.get_procedure_token
+def get_procedure_token(self):
+rgc.collect();
+return original_get_procedure_token(self)
+JitCell.get_procedure_token = get_procedure_token
+cls.original_get_procedure_token = original_get_procedure_token
+
+def teardown_class(cls):
+JitCell.get_procedure_token = cls.original_get_procedure_token
+
 def test_loop_kept_alive(self):
 myjitdriver = JitDriver(greens=[], reds=['n'])
 def g():
diff --git a/pypy/jit/metainterp/warmstate.py b/pypy/jit/metainterp/warmstate.py
--- a/pypy/jit/metainterp/warmstate.py
+++ b/pypy/jit/metainterp/warmstate.py
@@ -173,9 +173,6 @@
 wref_procedure_token = None
 
 def get_procedure_token(self):
-if not we_are_translated():
-from pypy.rlib import rgc
-rgc.collect();
 if self.wref_procedure_token is not None:
 token = self.wref_procedure_token()
 if token and not token.invalidated:
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy matrixmath-dot: Merge with default

2011-12-05 Thread mattip
Author: mattip
Branch: matrixmath-dot
Changeset: r50185:55693d8b2b89
Date: 2011-12-04 21:49 +0200
http://bitbucket.org/pypy/pypy/changeset/55693d8b2b89/

Log:Merge with default

diff --git a/lib_pypy/_sha.py b/lib_pypy/_sha.py
--- a/lib_pypy/_sha.py
+++ b/lib_pypy/_sha.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# -*- coding: iso-8859-1
+# -*- coding: iso-8859-1 -*-
 
 # Note that PyPy contains also a built-in module 'sha' which will hide
 # this one if compiled in.
diff --git a/lib_pypy/itertools.py b/lib_pypy/itertools.py
--- a/lib_pypy/itertools.py
+++ b/lib_pypy/itertools.py
@@ -25,7 +25,7 @@
 
 __all__ = ['chain', 'count', 'cycle', 'dropwhile', 'groupby', 'ifilter',
'ifilterfalse', 'imap', 'islice', 'izip', 'repeat', 'starmap',
-   'takewhile', 'tee']
+   'takewhile', 'tee', 'compress', 'product']
 
 try: from __pypy__ import builtinify
 except ImportError: builtinify = lambda f: f
diff --git a/pypy/module/_codecs/interp_codecs.py 
b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -67,10 +67,7 @@
 if self.unicodedata_handler:
 return self.unicodedata_handler
 try:
-w_builtin = space.getbuiltinmodule('__builtin__')
-w_import = space.getattr(w_builtin, space.wrap(__import__))
-w_unicodedata = space.call_function(w_import,
-space.wrap(unicodedata))
+w_unicodedata = space.getbuiltinmodule(unicodedata)
 w_getcode = space.getattr(w_unicodedata, space.wrap(_get_code))
 except OperationError:
 return None
diff --git a/pypy/module/_multiprocessing/interp_connection.py 
b/pypy/module/_multiprocessing/interp_connection.py
--- a/pypy/module/_multiprocessing/interp_connection.py
+++ b/pypy/module/_multiprocessing/interp_connection.py
@@ -100,7 +100,6 @@
 
 res, newbuf = self.do_recv_string(
 space, self.BUFFER_SIZE, maxlength)
-res = intmask(res) # XXX why?
 try:
 if newbuf:
 return space.wrap(rffi.charpsize2str(newbuf, res))
@@ -117,7 +116,6 @@
 
 res, newbuf = self.do_recv_string(
 space, length - offset, PY_SSIZE_T_MAX)
-res = intmask(res) # XXX why?
 try:
 if newbuf:
 raise BufferTooShort(space, space.wrap(
@@ -148,7 +146,6 @@
 
 res, newbuf = self.do_recv_string(
 space, self.BUFFER_SIZE, PY_SSIZE_T_MAX)
-res = intmask(res) # XXX why?
 try:
 if newbuf:
 w_received = space.wrap(rffi.charpsize2str(newbuf, res))
@@ -413,7 +410,7 @@
self.buffer, min(self.BUFFER_SIZE, buflength),
read_ptr, rffi.NULL)
 if result:
-return read_ptr[0], lltype.nullptr(rffi.CCHARP.TO)
+return intmask(read_ptr[0]), lltype.nullptr(rffi.CCHARP.TO)
 
 err = rwin32.GetLastError()
 if err == ERROR_BROKEN_PIPE:
@@ -476,7 +473,7 @@
 block = timeout  0
 if not block:
 # XXX does not check for overflow
-deadline = _GetTickCount() + int(1000 * timeout + 0.5)
+deadline = intmask(_GetTickCount()) + int(1000 * timeout + 0.5)
 else:
 deadline = 0
 
@@ -500,7 +497,7 @@
 return True
 
 if not block:
-now = _GetTickCount()
+now = intmask(_GetTickCount())
 if now  deadline:
 return False
 diff = deadline - now
diff --git a/pypy/module/_multiprocessing/interp_semaphore.py 
b/pypy/module/_multiprocessing/interp_semaphore.py
--- a/pypy/module/_multiprocessing/interp_semaphore.py
+++ b/pypy/module/_multiprocessing/interp_semaphore.py
@@ -235,7 +235,7 @@
 elif timeout = 0.5 * rwin32.INFINITE: # 25 days
 raise OperationError(space.w_OverflowError,
  space.wrap(timeout is too large))
-full_msecs = int(timeout + 0.5)
+full_msecs = r_uint(int(timeout + 0.5))
 
 # check whether we can acquire without blocking
 res = rwin32.WaitForSingleObject(self.handle, 0)
@@ -243,7 +243,7 @@
 if res != rwin32.WAIT_TIMEOUT:
 return True
 
-msecs = r_uint(full_msecs)
+msecs = full_msecs
 start = _GetTickCount()
 
 while True:
@@ -269,7 +269,7 @@
 ticks = _GetTickCount()
 if r_uint(ticks - start) = full_msecs:
 return False
-msecs = r_uint(full_msecs - (ticks - start))
+msecs = full_msecs - r_uint(ticks - start)
 
 # handle result
 if res != rwin32.WAIT_TIMEOUT:
diff --git a/pypy/module/_rawffi/interp_rawffi.py 
b/pypy/module/_rawffi/interp_rawffi.py
--- 

[pypy-commit] pypy matrixmath-dot: fix for renamed class

2011-12-05 Thread mattip
Author: mattip
Branch: matrixmath-dot
Changeset: r50184:0f00b31fe95a
Date: 2011-12-04 21:48 +0200
http://bitbucket.org/pypy/pypy/changeset/0f00b31fe95a/

Log:fix for renamed class

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
@@ -500,7 +500,7 @@
 dtype = interp_ufuncs.find_binop_result_dtype(space, 
  self.find_dtype(), w_other.find_dtype())
 #TODO: what should the order be? C or F?
-arr = NDimArray(out_size, out_shape, dtype=dtype)
+arr = W_NDimArray(out_size, out_shape, dtype=dtype)
 out_iter = ArrayIterator(out_size)
 #TODO: invalidate self, w_other with arr
 me_iter = BroadcastIterator(self,self.shape[:-1] + [1])
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy matrixmath-dot: experimental approach to dot iterator problem

2011-12-05 Thread mattip
Author: mattip
Branch: matrixmath-dot
Changeset: r50188:885d36165f89
Date: 2011-12-04 23:22 +0200
http://bitbucket.org/pypy/pypy/changeset/885d36165f89/

Log:experimental approach to dot iterator problem

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
@@ -121,6 +121,11 @@
 def get_offset(self):
 raise NotImplementedError
 
+class DummyIterator(object):
+'''Dummy placeholder
+'''
+pass
+
 class ArrayIterator(BaseIterator):
 def __init__(self, size):
 self.offset = 0
@@ -354,8 +359,10 @@
 descr_abs = _unaryop_impl(absolute)
 
 def _binop_impl(ufunc_name):
-def impl(self, space, w_other):
-return getattr(interp_ufuncs.get(space), ufunc_name).call(space, 
[self, w_other])
+def impl(self, space, w_other, w_selfiter=DummyIterator(), 
+  w_otheriter=DummyIterator()):
+return getattr(interp_ufuncs.get(space), ufunc_name).call(space, 
+ [self, w_other, w_selfiter, w_otheriter])
 return func_with_new_name(impl, binop_%s_impl % ufunc_name)
 
 descr_add = _binop_impl(add)
@@ -980,12 +987,15 @@
 
 Intermediate class for performing binary operations.
 
-def __init__(self, signature, shape, calc_dtype, res_dtype, left, right):
+def __init__(self, signature, shape, calc_dtype, res_dtype, left, right, 
+ liter = DummyIterator(), riter = DummyIterator()):
 # XXX do something if left.order != right.order
 VirtualArray.__init__(self, signature, shape, res_dtype, left.order)
 self.left = left
 self.right = right
 self.calc_dtype = calc_dtype
+self.liter = liter
+self.riter = riter
 self.size = 1
 for s in self.shape:
 self.size *= s
@@ -1002,8 +1012,15 @@
 return self.forced_result.start_iter(res_shape)
 if res_shape is None:
 res_shape = self.shape  # we still force the shape on children
-return Call2Iterator(self.left.start_iter(res_shape),
- self.right.start_iter(res_shape))
+if not getattr(self.liter, 'get_offest', ''):
+_liter = self.left.start_iter(res_shape)
+else:
+_liter = self.liter
+if not getattr(self.riter, 'get_offest', ''):
+_riter = self.right.start_iter(res_shape)
+else:
+_riter = self.riter
+return Call2Iterator(_liter, _riter)
 
 def _eval(self, iter):
 assert isinstance(iter, Call2Iterator)
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
@@ -139,8 +139,10 @@
 def call(self, space, args_w):
 from pypy.module.micronumpy.interp_numarray import (Call2,
 convert_to_array, Scalar, shape_agreement)
-
-[w_lhs, w_rhs] = args_w
+if len(args_w)2:
+[w_lhs, w_rhs, w_liter, w_riter] = args_w
+else:
+[w_lhs, w_rhs] = args_w
 w_lhs = convert_to_array(space, w_lhs)
 w_rhs = convert_to_array(space, w_rhs)
 calc_dtype = find_binop_result_dtype(space,
@@ -162,8 +164,12 @@
 self.signature, w_lhs.signature, w_rhs.signature
 ])
 new_shape = shape_agreement(space, w_lhs.shape, w_rhs.shape)
-w_res = Call2(new_sig, new_shape, calc_dtype,
-  res_dtype, w_lhs, w_rhs)
+if len(args_w)2:
+w_res = Call2(new_sig, new_shape, calc_dtype,
+  res_dtype, w_lhs, w_rhs, w_liter, w_riter)
+else:
+w_res = Call2(new_sig, new_shape, calc_dtype, 
+  res_dtype, w_lhs, w_rhs)
 w_lhs.add_invalidates(w_res)
 w_rhs.add_invalidates(w_res)
 return w_res
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy matrixmath-dot: bad merge

2011-12-05 Thread mattip
Author: mattip
Branch: matrixmath-dot
Changeset: r50186:55f149559e25
Date: 2011-12-04 22:06 +0200
http://bitbucket.org/pypy/pypy/changeset/55f149559e25/

Log:bad merge

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
@@ -3,13 +3,16 @@
 It should not be imported by the module itself
 
 
+import re
+
 from pypy.interpreter.baseobjspace import InternalSpaceCache, W_Root
-from pypy.module.micronumpy.interp_dtype import W_Float64Dtype, W_BoolDtype
+from pypy.module.micronumpy import interp_boxes
+from pypy.module.micronumpy.interp_dtype import get_dtype_cache
 from pypy.module.micronumpy.interp_numarray import (Scalar, BaseArray,
- descr_new_array, scalar_w, NDimArray)
+ scalar_w, W_NDimArray, array)
 from pypy.module.micronumpy import interp_ufuncs
-from pypy.rlib.objectmodel import specialize
-import re
+from pypy.rlib.objectmodel import specialize, instantiate
+
 
 class BogusBytecode(Exception):
 pass
@@ -49,15 +52,12 @@
 def __init__(self):
 NOT_RPYTHON
 self.fromcache = InternalSpaceCache(self).getorbuild
-self.w_float64dtype = W_Float64Dtype(self)
 
 def issequence_w(self, w_obj):
-return isinstance(w_obj, ListObject) or isinstance(w_obj, NDimArray)
+return isinstance(w_obj, ListObject) or isinstance(w_obj, W_NDimArray)
 
 def isinstance_w(self, w_obj, w_tp):
-if w_obj.tp == w_tp:
-return True
-return False
+return w_obj.tp == w_tp
 
 def decode_index4(self, w_idx, size):
 if isinstance(w_idx, IntObject):
@@ -98,8 +98,10 @@
 fixedview = listview
 
 def float(self, w_obj):
-assert isinstance(w_obj, FloatObject)
-return w_obj
+if isinstance(w_obj, FloatObject):
+return w_obj
+assert isinstance(w_obj, interp_boxes.W_GenericBox)
+return self.float(w_obj.descr_float(self))
 
 def float_w(self, w_obj):
 assert isinstance(w_obj, FloatObject)
@@ -113,7 +115,10 @@
 raise NotImplementedError
 
 def int(self, w_obj):
-return w_obj
+if isinstance(w_obj, IntObject):
+return w_obj
+assert isinstance(w_obj, interp_boxes.W_GenericBox)
+return self.int(w_obj.descr_int(self))
 
 def is_true(self, w_obj):
 assert isinstance(w_obj, BoolObject)
@@ -136,6 +141,9 @@
 assert isinstance(what, tp)
 return what
 
+def allocate_instance(self, klass, w_subtype):
+return instantiate(klass)
+
 def len_w(self, w_obj):
 if isinstance(w_obj, ListObject):
 return len(w_obj.items)
@@ -248,7 +256,7 @@
 w_rhs = self.rhs.execute(interp)
 if not isinstance(w_lhs, BaseArray):
 # scalar
-dtype = interp.space.fromcache(W_Float64Dtype)
+dtype = get_dtype_cache(interp.space).w_float64dtype
 w_lhs = scalar_w(interp.space, dtype, w_lhs)
 assert isinstance(w_lhs, BaseArray)
 if self.name == '+':
@@ -265,8 +273,9 @@
 w_res = w_lhs.descr_getitem(interp.space, w_rhs)
 else:
 raise NotImplementedError
-if not isinstance(w_res, BaseArray):
-dtype = interp.space.fromcache(W_Float64Dtype)
+if (not isinstance(w_res, BaseArray) and
+not isinstance(w_res, interp_boxes.W_GenericBox)):
+dtype = get_dtype_cache(interp.space).w_float64dtype
 w_res = scalar_w(interp.space, dtype, w_res)
 return w_res
 
@@ -284,7 +293,7 @@
 return space.wrap(self.v)
 
 def execute(self, interp):
-return FloatObject(self.v)
+return interp.space.wrap(self.v)
 
 class RangeConstant(Node):
 def __init__(self, v):
@@ -292,10 +301,10 @@
 
 def execute(self, interp):
 w_list = interp.space.newlist(
-[interp.space.wrap(float(i)) for i in range(self.v)])
-dtype = interp.space.fromcache(W_Float64Dtype)
-return descr_new_array(interp.space, None, w_list, w_dtype=dtype,
-   w_order=None)
+[interp.space.wrap(float(i)) for i in range(self.v)]
+)
+dtype = get_dtype_cache(interp.space).w_float64dtype
+return array(interp.space, w_list, w_dtype=dtype, w_order=None)
 
 def __repr__(self):
 return 'Range(%s)' % self.v
@@ -316,9 +325,8 @@
 
 def execute(self, interp):
 w_list = self.wrap(interp.space)
-dtype = interp.space.fromcache(W_Float64Dtype)
-return descr_new_array(interp.space, None, w_list, w_dtype=dtype,
-   w_order=None)
+dtype = get_dtype_cache(interp.space).w_float64dtype
+return array(interp.space, w_list, w_dtype=dtype, w_order=None)
 
 def __repr__(self):
 return [ + , .join([repr(item) for item in self.items]) + ]
@@ -398,9 +406,11 @@
 if 

[pypy-commit] pypy matrixmath-dot: clean compile a bit

2011-12-05 Thread mattip
Author: mattip
Branch: matrixmath-dot
Changeset: r50189:dc6c3373f647
Date: 2011-12-05 09:02 +0200
http://bitbucket.org/pypy/pypy/changeset/dc6c3373f647/

Log:clean compile a bit

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
@@ -399,8 +399,10 @@
 raise ArgumentNotAnArray
 if not isinstance(arr1, BaseArray):
 raise ArgumentNotAnArray
-elif self.name == dot:
+if self.name == dot:
 w_res = arr0.descr_dot(interp.space, arr1)
+else:
+assert False # unreachable code
 else:
 raise WrongFunctionName
 if isinstance(w_res, BaseArray):
diff --git a/pypy/module/micronumpy/test/test_compile.py 
b/pypy/module/micronumpy/test/test_compile.py
--- a/pypy/module/micronumpy/test/test_compile.py
+++ b/pypy/module/micronumpy/test/test_compile.py
@@ -235,6 +235,7 @@
 a - 3
 )
 assert interp.results[0].value == 11
+
 def test_dot(self):
 interp = self.run(
 a = [[1, 2], [3, 4]]
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy matrixmath-dot: bad merge

2011-12-05 Thread mattip
Author: mattip
Branch: matrixmath-dot
Changeset: r50187:09f8917ecaf3
Date: 2011-12-04 22:09 +0200
http://bitbucket.org/pypy/pypy/changeset/09f8917ecaf3/

Log:bad merge

diff --git a/pypy/module/micronumpy/test/test_compile.py 
b/pypy/module/micronumpy/test/test_compile.py
--- a/pypy/module/micronumpy/test/test_compile.py
+++ b/pypy/module/micronumpy/test/test_compile.py
@@ -1,9 +1,10 @@
+import py
 
-import py
 from pypy.module.micronumpy.compile import (numpy_compile, Assignment,
 ArrayConstant, FloatConstant, Operator, Variable, RangeConstant, Execute,
 FunctionCall, FakeSpace)
 
+
 class TestCompiler(object):
 def compile(self, code):
 return numpy_compile(code)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy matrixmath-dot: add failing test for sum return value

2011-12-05 Thread mattip
Author: mattip
Branch: matrixmath-dot
Changeset: r50194:699511d4d5d5
Date: 2011-12-05 16:36 +0200
http://bitbucket.org/pypy/pypy/changeset/699511d4d5d5/

Log:add failing test for sum return value

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
@@ -411,6 +411,7 @@
 b = a * a
 for i in range(5):
 assert b[i] == i * i
+assert b.dtype is numpypy.dtype(int)
 
 a = numpypy.array(range(5), dtype=bool)
 b = a * a
@@ -629,8 +630,10 @@
 def test_sum(self):
 from numpypy import array
 a = array(range(5))
-assert a.sum() == 10.0
-assert a[:4].sum() == 6.0
+b = a.sum()
+assert b == 10
+assert isinstance(b,int)
+assert a[:4].sum() == 6
 
 a = array([True] * 5, bool)
 assert a.sum() == 5
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy matrixmath-dot: Backed out changeset: 885d36165f89

2011-12-05 Thread mattip
Author: mattip
Branch: matrixmath-dot
Changeset: r50190:1ae4feb97953
Date: 2011-12-05 09:03 +0200
http://bitbucket.org/pypy/pypy/changeset/1ae4feb97953/

Log:Backed out changeset: 885d36165f89

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
@@ -121,11 +121,6 @@
 def get_offset(self):
 raise NotImplementedError
 
-class DummyIterator(object):
-'''Dummy placeholder
-'''
-pass
-
 class ArrayIterator(BaseIterator):
 def __init__(self, size):
 self.offset = 0
@@ -359,10 +354,8 @@
 descr_abs = _unaryop_impl(absolute)
 
 def _binop_impl(ufunc_name):
-def impl(self, space, w_other, w_selfiter=DummyIterator(), 
-  w_otheriter=DummyIterator()):
-return getattr(interp_ufuncs.get(space), ufunc_name).call(space, 
- [self, w_other, w_selfiter, w_otheriter])
+def impl(self, space, w_other):
+return getattr(interp_ufuncs.get(space), ufunc_name).call(space, 
[self, w_other])
 return func_with_new_name(impl, binop_%s_impl % ufunc_name)
 
 descr_add = _binop_impl(add)
@@ -987,15 +980,12 @@
 
 Intermediate class for performing binary operations.
 
-def __init__(self, signature, shape, calc_dtype, res_dtype, left, right, 
- liter = DummyIterator(), riter = DummyIterator()):
+def __init__(self, signature, shape, calc_dtype, res_dtype, left, right):
 # XXX do something if left.order != right.order
 VirtualArray.__init__(self, signature, shape, res_dtype, left.order)
 self.left = left
 self.right = right
 self.calc_dtype = calc_dtype
-self.liter = liter
-self.riter = riter
 self.size = 1
 for s in self.shape:
 self.size *= s
@@ -1012,15 +1002,8 @@
 return self.forced_result.start_iter(res_shape)
 if res_shape is None:
 res_shape = self.shape  # we still force the shape on children
-if not getattr(self.liter, 'get_offest', ''):
-_liter = self.left.start_iter(res_shape)
-else:
-_liter = self.liter
-if not getattr(self.riter, 'get_offest', ''):
-_riter = self.right.start_iter(res_shape)
-else:
-_riter = self.riter
-return Call2Iterator(_liter, _riter)
+return Call2Iterator(self.left.start_iter(res_shape),
+ self.right.start_iter(res_shape))
 
 def _eval(self, iter):
 assert isinstance(iter, Call2Iterator)
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
@@ -139,10 +139,8 @@
 def call(self, space, args_w):
 from pypy.module.micronumpy.interp_numarray import (Call2,
 convert_to_array, Scalar, shape_agreement)
-if len(args_w)2:
-[w_lhs, w_rhs, w_liter, w_riter] = args_w
-else:
-[w_lhs, w_rhs] = args_w
+
+[w_lhs, w_rhs] = args_w
 w_lhs = convert_to_array(space, w_lhs)
 w_rhs = convert_to_array(space, w_rhs)
 calc_dtype = find_binop_result_dtype(space,
@@ -164,12 +162,8 @@
 self.signature, w_lhs.signature, w_rhs.signature
 ])
 new_shape = shape_agreement(space, w_lhs.shape, w_rhs.shape)
-if len(args_w)2:
-w_res = Call2(new_sig, new_shape, calc_dtype,
-  res_dtype, w_lhs, w_rhs, w_liter, w_riter)
-else:
-w_res = Call2(new_sig, new_shape, calc_dtype, 
-  res_dtype, w_lhs, w_rhs)
+w_res = Call2(new_sig, new_shape, calc_dtype,
+  res_dtype, w_lhs, w_rhs)
 w_lhs.add_invalidates(w_res)
 w_rhs.add_invalidates(w_res)
 return w_res
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy matrixmath-dot: dot works

2011-12-05 Thread mattip
Author: mattip
Branch: matrixmath-dot
Changeset: r50197:d28b98fc74ed
Date: 2011-12-05 23:17 +0200
http://bitbucket.org/pypy/pypy/changeset/d28b98fc74ed/

Log:dot works

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
@@ -152,7 +152,7 @@
 return arr
 
 def done(self):
-return self.offset == self.size
+return self.offset = self.size
 
 def get_offset(self):
 return self.offset
@@ -197,7 +197,7 @@
 class BroadcastIterator(BaseIterator):
 '''Like a view iterator, but will repeatedly access values
for all iterations across a res_shape, folding the offset
-   using mod() arithmetic
+   using stride = backstride = 0
 '''
 def __init__(self, arr, res_shape):
 self.indices = [0] * len(res_shape)
@@ -522,7 +522,7 @@
 assert other_critical_dim = 0
 out_shape += self.shape[:-1] + \
  w_other.shape[0:other_critical_dim] + \
- w_other.shape[other_critical_dim:]
+ w_other.shape[other_critical_dim + 1:]
 elif len(w_other.shape)  0:
 #dot does not reduce
 out_shape += self.shape[:-1]
@@ -535,25 +535,28 @@
 out_ndims = len(out_shape)
 #TODO: what should the order be? C or F?
 arr = W_NDimArray(out_size, out_shape, dtype=dtype)
-out_iter = ArrayIterator(out_size)
+out_iter = ViewIterator(arr)
 #TODO: invalidate self, w_other with arr ?
-me_iter = BroadcastIterator(self, self.shape[:-1] + [1])
-assert other_critical_dim = 0
-other_iter = BroadcastIterator(self,
-   w_other.shape[:other_critical_dim] + [1] + \
-   w_other.shape[other_critical_dim:])
 while not out_iter.done():
-w_ssd = space.newlist([space.wrap(me_iter.get_offset()), 
-   space.wrap(len(self.shape)-1)])
-w_osd = space.newlist([space.wrap(other_iter.get_offset()), 
+my_index = self.start
+other_index = w_other.start
+i = 0
+while i  len(self.shape) - 1:
+my_index += out_iter.indices[i] * self.strides[i]
+i += 1
+for j in range(len(w_other.shape) - 2):
+other_index += out_iter.indices[i] * w_other.strides[j]
+other_index += out_iter.indices[-1] * w_other.strides[-1]
+w_ssd = space.newlist([space.wrap(my_index),
+   space.wrap(len(self.shape) - 1)])
+w_osd = space.newlist([space.wrap(other_index),
space.wrap(other_critical_dim)])
 w_res = self.descr_mul1d(space, w_other, w_ssd, w_osd)
+assert isinstance(w_res, BaseArray)
 value = w_res.descr_sum(space)
-abc=hgk
-arr.setitem(out_iter, value)
+arr.setitem(out_iter.get_offset(), value)
 out_iter = out_iter.next(out_ndims)
-me_iter = me_iter.next(0)
-other_iter = other_iter.next(0)
+ii += 1
 return arr
 
 def get_concrete(self):
@@ -818,7 +821,8 @@
  shape[:])
 
 def descr_mean(self, space):
-return space.div(self.descr_sumpromote(space), 
space.wrap(self.find_size()))
+return space.div(self.descr_sumpromote(space), 
+ space.wrap(self.find_size()))
 
 def descr_nonzero(self, space):
 if self.find_size()  1:
@@ -940,7 +944,7 @@
  shapelen=shapelen,
  result_size=result_size, i=i, ri=ri,
  self=self, result=result)
-result.dtype.setitem(result.storage, ri.offset, self.eval(i))
+result.dtype.setitem(result.storage, ri.get_offset(), self.eval(i))
 i = i.next(shapelen)
 ri = ri.next(shapelen)
 return result
@@ -1045,6 +1049,14 @@
 if res_shape is None:
 res_shape = self.shape  # we still force the shape on children
 #TODO: use left_start_dim, right_start_dim if they are not [-1, -1]
+if self.left_start_dim[0] = 0:
+ldim = self.left_start_dim[1]
+rdim = self.right_start_dim[1]
+left_iter = OneDimIterator(self.left_start_dim[0],
+self.left.strides[ldim], self.left.shape[ldim])
+right_iter = OneDimIterator(self.right_start_dim[0],
+self.right.strides[rdim], self.right.shape[rdim])
+return Call2Iterator(left_iter, right_iter)
 return Call2Iterator(self.left.start_iter(res_shape),
  

[pypy-commit] pypy matrixmath-dot: merge

2011-12-05 Thread mattip
Author: mattip
Branch: matrixmath-dot
Changeset: r50191:5a5cfa32fe70
Date: 2011-12-05 09:04 +0200
http://bitbucket.org/pypy/pypy/changeset/5a5cfa32fe70/

Log:merge

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
@@ -121,11 +121,6 @@
 def get_offset(self):
 raise NotImplementedError
 
-class DummyIterator(object):
-'''Dummy placeholder
-'''
-pass
-
 class ArrayIterator(BaseIterator):
 def __init__(self, size):
 self.offset = 0
@@ -359,10 +354,8 @@
 descr_abs = _unaryop_impl(absolute)
 
 def _binop_impl(ufunc_name):
-def impl(self, space, w_other, w_selfiter=DummyIterator(), 
-  w_otheriter=DummyIterator()):
-return getattr(interp_ufuncs.get(space), ufunc_name).call(space, 
- [self, w_other, w_selfiter, w_otheriter])
+def impl(self, space, w_other):
+return getattr(interp_ufuncs.get(space), ufunc_name).call(space, 
[self, w_other])
 return func_with_new_name(impl, binop_%s_impl % ufunc_name)
 
 descr_add = _binop_impl(add)
@@ -987,15 +980,12 @@
 
 Intermediate class for performing binary operations.
 
-def __init__(self, signature, shape, calc_dtype, res_dtype, left, right, 
- liter = DummyIterator(), riter = DummyIterator()):
+def __init__(self, signature, shape, calc_dtype, res_dtype, left, right):
 # XXX do something if left.order != right.order
 VirtualArray.__init__(self, signature, shape, res_dtype, left.order)
 self.left = left
 self.right = right
 self.calc_dtype = calc_dtype
-self.liter = liter
-self.riter = riter
 self.size = 1
 for s in self.shape:
 self.size *= s
@@ -1012,15 +1002,8 @@
 return self.forced_result.start_iter(res_shape)
 if res_shape is None:
 res_shape = self.shape  # we still force the shape on children
-if not getattr(self.liter, 'get_offest', ''):
-_liter = self.left.start_iter(res_shape)
-else:
-_liter = self.liter
-if not getattr(self.riter, 'get_offest', ''):
-_riter = self.right.start_iter(res_shape)
-else:
-_riter = self.riter
-return Call2Iterator(_liter, _riter)
+return Call2Iterator(self.left.start_iter(res_shape),
+ self.right.start_iter(res_shape))
 
 def _eval(self, iter):
 assert isinstance(iter, Call2Iterator)
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
@@ -139,10 +139,8 @@
 def call(self, space, args_w):
 from pypy.module.micronumpy.interp_numarray import (Call2,
 convert_to_array, Scalar, shape_agreement)
-if len(args_w)2:
-[w_lhs, w_rhs, w_liter, w_riter] = args_w
-else:
-[w_lhs, w_rhs] = args_w
+
+[w_lhs, w_rhs] = args_w
 w_lhs = convert_to_array(space, w_lhs)
 w_rhs = convert_to_array(space, w_rhs)
 calc_dtype = find_binop_result_dtype(space,
@@ -164,12 +162,8 @@
 self.signature, w_lhs.signature, w_rhs.signature
 ])
 new_shape = shape_agreement(space, w_lhs.shape, w_rhs.shape)
-if len(args_w)2:
-w_res = Call2(new_sig, new_shape, calc_dtype,
-  res_dtype, w_lhs, w_rhs, w_liter, w_riter)
-else:
-w_res = Call2(new_sig, new_shape, calc_dtype, 
-  res_dtype, w_lhs, w_rhs)
+w_res = Call2(new_sig, new_shape, calc_dtype,
+  res_dtype, w_lhs, w_rhs)
 w_lhs.add_invalidates(w_res)
 w_rhs.add_invalidates(w_res)
 return w_res
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy matrixmath-dot: translation fixes: avoid negative slices

2011-12-05 Thread mattip
Author: mattip
Branch: matrixmath-dot
Changeset: r50192:26e6b2238d4a
Date: 2011-12-05 10:30 +0200
http://bitbucket.org/pypy/pypy/changeset/26e6b2238d4a/

Log:translation fixes: avoid negative slices

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
@@ -482,30 +482,43 @@
 w_res = self.descr_mul(space, w_other)
 assert isinstance(w_res, BaseArray)
 return w_res.descr_sum(space)
+dtype = interp_ufuncs.find_binop_result_dtype(space, 
+ self.find_dtype(), w_other.find_dtype())
+if self.find_size()  1 and w_other.find_size() 1:
+#numpy compatability
+return scalar_w(space, dtype,space.wrap(0))
 #Do the dims match?
 my_critical_dim_size = self.shape[-1]
 other_critical_dim_size = w_other.shape[0]
+other_critical_dim = 0
 other_critical_dim_stride = w_other.strides[0] 
-if len(w_other.shape)  2:
-other_critical_dim_size = w_other.shape[-2]
-other_critical_dim_stride = w_other.strides[-2] 
+out_shape = []
+if len(w_other.shape)  1:
+other_critical_dim = len(w_other.shape)-1
+other_critical_dim_size = w_other.shape[other_critical_dim]
+other_critical_dim_stride = w_other.strides[other_critical_dim]
+assert other_critical_dim = 0
+out_shape += self.shape[:-1] + w_other.shape[0:other_critical_dim] 
+ w_other.shape[other_critical_dim:]
+elif len(w_other.shape)  0:
+#dot does not reduce
+out_shape += self.shape[:-1]
 if my_critical_dim_size != other_critical_dim_size:
 raise OperationError(space.w_ValueError, space.wrap(
 objects are not aligned))
-out_shape = self.shape[:-1] + w_other.shape[0:-2] + w_other.shape[-1:]
 out_size = 1
 for os in out_shape:
 out_size *= os
 out_ndims = len(out_shape)
-dtype = interp_ufuncs.find_binop_result_dtype(space, 
- self.find_dtype(), w_other.find_dtype())
 #TODO: what should the order be? C or F?
 arr = W_NDimArray(out_size, out_shape, dtype=dtype)
 out_iter = ArrayIterator(out_size)
-#TODO: invalidate self, w_other with arr
+#TODO: invalidate self, w_other with arr ?
+
 me_iter = BroadcastIterator(self,self.shape[:-1] + [1])
+assert other_critical_dim = 0
 other_iter = BroadcastIterator(self, 
-   w_other.shape[:-2] + [1] + w_other.shape[-1:])
+   w_other.shape[:other_critical_dim] + [1] + \
+   w_other.shape[other_critical_dim:])
 while not out_iter.done():
 i = OneDimIterator(me_iter.get_offset(), self.strides[-1], 
self.shape[-1])
 j = OneDimIterator(other_iter.get_offset(), 
other_critical_dim_stride, other_critical_dim_size)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy matrixmath-dot: add bin_impl_one_dim, would be nice to have some tests

2011-12-05 Thread mattip
Author: mattip
Branch: matrixmath-dot
Changeset: r50193:beba9400c9dd
Date: 2011-12-05 15:41 +0200
http://bitbucket.org/pypy/pypy/changeset/beba9400c9dd/

Log:add bin_impl_one_dim, would be nice to have some 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
@@ -403,6 +403,7 @@
 greens=['shapelen', 'signature'],
 reds=['result', 'idx', 'i', 'self', 'cur_best', 'dtype']
 )
+
 def loop(self):
 i = self.start_iter()
 cur_best = self.eval(i)
@@ -424,6 +425,7 @@
 i = i.next(shapelen)
 idx += 1
 return result
+
 def impl(self, space):
 size = self.find_size()
 if size == 0:
@@ -444,6 +446,7 @@
 return False
 i = i.next(shapelen)
 return True
+
 def descr_all(self, space):
 return space.wrap(self._all())
 
@@ -459,22 +462,39 @@
 return True
 i = i.next(shapelen)
 return False
+
 def descr_any(self, space):
 return space.wrap(self._any())
 
 descr_argmax = _reduce_argmax_argmin_impl(max)
 descr_argmin = _reduce_argmax_argmin_impl(min)
 
+def _binop_impl_one_dim(ufunc_name):
+#The third and fourth arguments allow the operator to proceed on a
+#single dimension starting at a particular index
+#i.e. ssd = self start, dimension; osd = other start, dimension
+def impl(self, space, w_other, w_ssd, w_osd):
+return getattr(interp_ufuncs.get(space), ufunc_name).call(space,
+ [self, w_other, w_ssd, w_osd])
+return func_with_new_name(impl, binop_%s_impl % ufunc_name)
+
+descr_add1d = _binop_impl_one_dim(add)
+descr_sub1d = _binop_impl_one_dim(subtract)
+descr_mul1d = _binop_impl_one_dim(multiply)
+descr_div1d = _binop_impl_one_dim(divide)
+descr_pow1d = _binop_impl_one_dim(power)
+descr_mod1d = _binop_impl_one_dim(mod)
+
 def descr_dot(self, space, w_other):
 '''Dot product of two arrays.
-
+
 For 2-D arrays it is equivalent to matrix multiplication, and for 1-D
 arrays to inner product of vectors (without complex conjugation). For
 N dimensions it is a sum product over the last axis of `a` and
 the second-to-last of `b`::
-
+
 dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])'''
-#numpy's doc string :) 
+#numpy's doc string :)
 w_other = convert_to_array(space, w_other)
 if isinstance(w_other, Scalar):
 return self.descr_mul(space, w_other)
@@ -482,23 +502,25 @@
 w_res = self.descr_mul(space, w_other)
 assert isinstance(w_res, BaseArray)
 return w_res.descr_sum(space)
-dtype = interp_ufuncs.find_binop_result_dtype(space, 
+dtype = interp_ufuncs.find_binop_result_dtype(space,
  self.find_dtype(), w_other.find_dtype())
-if self.find_size()  1 and w_other.find_size() 1:
+if self.find_size()  1 and w_other.find_size()  1:
 #numpy compatability
-return scalar_w(space, dtype,space.wrap(0))
+return scalar_w(space, dtype, space.wrap(0))
 #Do the dims match?
 my_critical_dim_size = self.shape[-1]
 other_critical_dim_size = w_other.shape[0]
 other_critical_dim = 0
-other_critical_dim_stride = w_other.strides[0] 
+other_critical_dim_stride = w_other.strides[0]
 out_shape = []
 if len(w_other.shape)  1:
-other_critical_dim = len(w_other.shape)-1
+other_critical_dim = len(w_other.shape) - 1
 other_critical_dim_size = w_other.shape[other_critical_dim]
 other_critical_dim_stride = w_other.strides[other_critical_dim]
 assert other_critical_dim = 0
-out_shape += self.shape[:-1] + w_other.shape[0:other_critical_dim] 
+ w_other.shape[other_critical_dim:]
+out_shape += self.shape[:-1] + \
+ w_other.shape[0:other_critical_dim] + \
+ w_other.shape[other_critical_dim:]
 elif len(w_other.shape)  0:
 #dot does not reduce
 out_shape += self.shape[:-1]
@@ -513,15 +535,16 @@
 arr = W_NDimArray(out_size, out_shape, dtype=dtype)
 out_iter = ArrayIterator(out_size)
 #TODO: invalidate self, w_other with arr ?
-
-me_iter = BroadcastIterator(self,self.shape[:-1] + [1])
+me_iter = BroadcastIterator(self, self.shape[:-1] + [1])
 assert other_critical_dim = 0
-other_iter = BroadcastIterator(self, 
+other_iter = BroadcastIterator(self,
w_other.shape[:other_critical_dim] + [1] + \
   

[pypy-commit] pypy matrixmath-dot: need to fix failing sum test before continuing

2011-12-05 Thread mattip
Author: mattip
Branch: matrixmath-dot
Changeset: r50195:ee2362c0cec8
Date: 2011-12-05 16:37 +0200
http://bitbucket.org/pypy/pypy/changeset/ee2362c0cec8/

Log:need to fix failing sum test before continuing

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
@@ -514,7 +514,7 @@
 other_critical_dim_stride = w_other.strides[0]
 out_shape = []
 if len(w_other.shape)  1:
-other_critical_dim = len(w_other.shape) - 1
+other_critical_dim = len(w_other.shape) - 2
 other_critical_dim_size = w_other.shape[other_critical_dim]
 other_critical_dim_stride = w_other.strides[other_critical_dim]
 assert other_critical_dim = 0
@@ -541,13 +541,14 @@
w_other.shape[:other_critical_dim] + [1] + \
w_other.shape[other_critical_dim:])
 while not out_iter.done():
-i = OneDimIterator(me_iter.get_offset(),
-  self.strides[-1], self.shape[-1])
-j = OneDimIterator(other_iter.get_offset(),
-  other_critical_dim_stride, other_critical_dim_size)
-#Heres what I would like to do, but how?
-#value = sum(mult_with_iters(self, i, w_other, j))
-#arr.setitem(out_iter, value)
+w_ssd = space.newlist([space.wrap(me_iter.get_offset()), 
+   space.wrap(len(self.shape)-1)])
+w_osd = space.newlist([space.wrap(other_iter.get_offset()), 
+   space.wrap(other_critical_dim)])
+w_res = self.descr_mul1d(space, w_other, w_ssd, w_osd)
+value = w_res.descr_sum(space)
+abc=hgk
+arr.setitem(out_iter, value)
 out_iter = out_iter.next(out_ndims)
 me_iter = me_iter.next(0)
 other_iter = other_iter.next(0)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy matrixmath-dot: expose promote_to_largest to reduce functions, fixes sum() prod() bug without ruining mean()

2011-12-05 Thread mattip
Author: mattip
Branch: matrixmath-dot
Changeset: r50196:924460a509cd
Date: 2011-12-05 17:36 +0200
http://bitbucket.org/pypy/pypy/changeset/924460a509cd/

Log:expose promote_to_largest to reduce functions, fixes sum() prod()
bug without ruining mean()

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
@@ -388,15 +388,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):
 def impl(self, space):
-return getattr(interp_ufuncs.get(space), ufunc_name).reduce(space, 
self, multidim=True)
+return getattr(interp_ufuncs.get(space), ufunc_name).reduce(space,
+   self, multidim=True, promote_to_largest=promote_to_largest)
 return func_with_new_name(impl, reduce_%s_impl % ufunc_name)
 
-descr_sum = _reduce_ufunc_impl(add)
-descr_prod = _reduce_ufunc_impl(multiply)
-descr_max = _reduce_ufunc_impl(maximum)
-descr_min = _reduce_ufunc_impl(minimum)
+descr_sum = _reduce_ufunc_impl(add, False)
+descr_prod = _reduce_ufunc_impl(multiply, False)
+descr_max = _reduce_ufunc_impl(maximum, False)
+descr_min = _reduce_ufunc_impl(minimum, False)
+descr_sumpromote = _reduce_ufunc_impl(add, True)
 
 def _reduce_argmax_argmin_impl(op_name):
 reduce_driver = jit.JitDriver(
@@ -816,7 +818,7 @@
  shape[:])
 
 def descr_mean(self, space):
-return space.div(self.descr_sum(space), space.wrap(self.find_size()))
+return space.div(self.descr_sumpromote(space), 
space.wrap(self.find_size()))
 
 def descr_nonzero(self, space):
 if self.find_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
@@ -46,9 +46,9 @@
 return self.call(space, __args__.arguments_w)
 
 def descr_reduce(self, space, w_obj):
-return self.reduce(space, w_obj, multidim=False)
+return self.reduce(space, w_obj, multidim=False, 
promote_to_largest=False)
 
-def reduce(self, space, w_obj, multidim):
+def reduce(self, space, w_obj, multidim, promote_to_largest):
 from pypy.module.micronumpy.interp_numarray import convert_to_array, 
Scalar
 if self.argcount != 2:
 raise OperationError(space.w_ValueError, space.wrap(reduce only 
@@ -63,7 +63,8 @@
 size = obj.find_size()
 dtype = find_unaryop_result_dtype(
 space, obj.find_dtype(),
-promote_to_largest=True
+promote_to_largest = promote_to_largest,
+promote_bools = True,
 )
 start = obj.start_iter(obj.shape)
 shapelen = len(obj.shape)
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy matrixmath-dot: dot seems to work, more of a proof-of-concept than usable

2011-12-05 Thread mattip
Author: mattip
Branch: matrixmath-dot
Changeset: r50198:8ee1a24557b8
Date: 2011-12-05 23:31 +0200
http://bitbucket.org/pypy/pypy/changeset/8ee1a24557b8/

Log:dot seems to work, more of a proof-of-concept than usable

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
@@ -152,7 +152,7 @@
 return arr
 
 def done(self):
-return self.offset = self.size
+return self.offset == self.size
 
 def get_offset(self):
 return self.offset
@@ -556,7 +556,6 @@
 value = w_res.descr_sum(space)
 arr.setitem(out_iter.get_offset(), value)
 out_iter = out_iter.next(out_ndims)
-ii += 1
 return arr
 
 def get_concrete(self):
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: expose numpy.float32, thanks to jterrance for pointing it out

2011-12-05 Thread alex_gaynor
Author: Alex Gaynor alex.gay...@gmail.com
Branch: 
Changeset: r50199:24a17a8610e1
Date: 2011-12-05 18:11 -0500
http://bitbucket.org/pypy/pypy/changeset/24a17a8610e1/

Log:expose numpy.float32, thanks to jterrance for pointing it out

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
@@ -32,6 +32,7 @@
 'int_': 'interp_boxes.W_LongBox',
 'inexact': 'interp_boxes.W_InexactBox',
 'floating': 'interp_boxes.W_FloatingBox',
+'float32': 'interp_boxes.W_Float32Box',
 'float64': 'interp_boxes.W_Float64Box',
 }
 
diff --git a/pypy/module/micronumpy/interp_boxes.py 
b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -258,6 +258,8 @@
 
 W_Float32Box.typedef = TypeDef(float32, W_FloatingBox.typedef,
 __module__ = numpypy,
+
+__new__ = interp2app(W_Float32Box.descr__new__.im_func),
 )
 
 W_Float64Box.typedef = TypeDef(float64, (W_FloatingBox.typedef, 
float_typedef),
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
@@ -240,6 +240,13 @@
 assert numpy.dtype(numpy.int64).type is numpy.int64
 assert numpy.int64(3) == 3
 
+def test_float32(self):
+import numpypy as numpy
+
+assert numpy.float32.mro() == [numpy.float32, numpy.floating, 
numpy.inexact, numpy.number, numpy.generic, object]
+
+assert numpy.float32(12) == numpy.float64(12)
+
 def test_float64(self):
 import numpypy as numpy
 
___
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit