[pypy-commit] stmgc c5: Put all write_history_s from a thread in the same page, as far as it fits
Author: Armin Rigo ar...@tunes.org Branch: c5 Changeset: r559:fff713ac3eb7 Date: 2013-12-19 10:12 +0100 http://bitbucket.org/pypy/stmgc/changeset/fff713ac3eb7/ Log:Put all write_history_s from a thread in the same page, as far as it fits diff --git a/c5/core.c b/c5/core.c --- a/c5/core.c +++ b/c5/core.c @@ -73,8 +73,8 @@ struct read_marker_s { /* We associate a single byte to every object, by simply dividing - the address of the object by 16. This is the last byte of the - last time we have read the object. See stm_read(). */ + the address of the object by 16. The number in this single byte + gives the last time we have read the object. See stm_read(). */ unsigned char c; }; @@ -482,14 +482,25 @@ __sync_fetch_and_add(d-next_transaction_version, 1u); assert(stm_local.transaction_version = 0x); -struct page_header_s *newpage = _stm_reserve_page(); -newpage-kind = PGKIND_WRITE_HISTORY; - -struct write_history_s *cur = (struct write_history_s *)(newpage + 1); +struct write_history_s *cur = NULL; +if (stm_local.writes_by_this_transaction != NULL) { +cur = stm_local.writes_by_this_transaction; +char *next, *page_limit = (char *)cur; +page_limit += 4096 - (((uintptr_t)page_limit) 4095); +next = (char *)(cur + 1) + 8 * cur-nb_updates; +if (page_limit - next sizeof(struct write_history_s) + 8) +cur = NULL; +else +cur = (struct write_history_s *)next; +} +if (cur == NULL) { +struct page_header_s *newpage = _stm_reserve_page(); +newpage-kind = PGKIND_WRITE_HISTORY; +cur = (struct write_history_s *)(newpage + 1); +} cur-previous_older_transaction = NULL; cur-transaction_version = stm_local.transaction_version; cur-nb_updates = 0; -assert(stm_local.writes_by_this_transaction == NULL); stm_local.writes_by_this_transaction = cur; struct write_history_s *hist = d-most_recent_committed_transaction; @@ -520,7 +531,6 @@ hist, cur)) break; } -stm_local.writes_by_this_transaction = NULL; if (stm_get_read_marker_number() 0xff) { stm_local.current_read_markers++; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c5: Fix the test.
Author: Armin Rigo ar...@tunes.org Branch: c5 Changeset: r561:2c3f26799678 Date: 2013-12-19 12:04 +0100 http://bitbucket.org/pypy/stmgc/changeset/2c3f26799678/ Log:Fix the test. diff --git a/c5/core.c b/c5/core.c --- a/c5/core.c +++ b/c5/core.c @@ -98,7 +98,7 @@ char _pad1[CACHE_LINE_SIZE]; }; union { -unsigned int next_transaction_version; +unsigned int next_transaction_version; /* always EVEN */ char _pad2[CACHE_LINE_SIZE]; }; union { @@ -118,7 +118,7 @@ different forked processes. */ char *read_markers; struct read_marker_s *current_read_markers; -uint16_t transaction_version; +uint16_t transaction_version;/* always EVEN */ struct write_history_s *base_page_mapping; struct write_history_s *writes_by_this_transaction; struct alloc_for_size_s alloc[LARGE_OBJECT_WORDS]; @@ -335,7 +335,7 @@ /* the page at index 0 contains the '*stm_shared_descriptor' structure */ /* the page at index 1 is reserved for history_fast_forward() */ stm_shared_descriptor-index_page_never_used = 2; -stm_shared_descriptor-next_transaction_version = 1; +stm_shared_descriptor-next_transaction_version = 2; } void _stm_teardown(void) @@ -400,6 +400,22 @@ return (struct object_s *)(((char *)page) + offset); } +static _Bool must_merge_page(struct page_header_s *page) +{ +/* The remote page was modified. Look at the local page (at + 'page'). If 'page-version' is equal to: + + - stm_local.transaction_version: the local page was + also modified in this transaction. Then we need to merge. + + - stm_local.transaction_version - 1: the local page was + not, strictly speaking, modified, but *new* objects have + been written to it. In order not to loose them, ask for + a merge too. +*/ +return ((uint32_t)(stm_local.transaction_version - page-version)) = 1; +} + static int history_fast_forward(struct write_history_s *new, int conflict) { /* XXX do a non-recursive version, which also should avoid repeated @@ -419,7 +435,7 @@ struct page_header_s *page = get_page_by_local_index(local_index); struct page_header_s *mypage = page; -if (!conflict page-version == stm_local.transaction_version) { +if (!conflict must_merge_page(page)) { /* If we have also modified this page, then we must merge our changes with the ones done at 'new_pgoff'. In this case we map 'new_pgoff' at the local index 1. */ @@ -479,8 +495,9 @@ { struct shared_descriptor_s *d = stm_shared_descriptor; stm_local.transaction_version = -__sync_fetch_and_add(d-next_transaction_version, 1u); +__sync_fetch_and_add(d-next_transaction_version, 2u); assert(stm_local.transaction_version = 0x); +assert((stm_local.transaction_version 1) == 0); /* EVEN number */ struct write_history_s *cur = NULL; if (stm_local.writes_by_this_transaction != NULL) { @@ -507,6 +524,16 @@ if (hist != stm_local.base_page_mapping) { history_fast_forward(hist, 1); } + +int i; +for (i = 2; i LARGE_OBJECT_WORDS; i++) { +struct page_header_s *page; +char *ptr = stm_local.alloc[i].next; +if (ptr != NULL) { +page = (struct page_header_s *)(((uintptr_t)ptr) ~4095); +page-version = stm_local.transaction_version - 1; +} +} } _Bool stm_stop_transaction(void) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy stmgc-c4: missing emitting_an_operation_that_can_collect() for the inevitable-fallback
Author: Remi Meier Branch: stmgc-c4 Changeset: r68485:853e37ea12e1 Date: 2013-12-19 14:36 +0100 http://bitbucket.org/pypy/pypy/changeset/853e37ea12e1/ Log:missing emitting_an_operation_that_can_collect() for the inevitable- fallback diff --git a/rpython/jit/backend/llsupport/stmrewrite.py b/rpython/jit/backend/llsupport/stmrewrite.py --- a/rpython/jit/backend/llsupport/stmrewrite.py +++ b/rpython/jit/backend/llsupport/stmrewrite.py @@ -154,6 +154,9 @@ self.newops.append(op) continue # -- fall-back -- +# Check that none of the ops handled here can_collect +# or cause a transaction break. This is not done by +# the fallback here self.fallback_inevitable(op) debug_print(fallback for, op.repr()) # @@ -316,6 +319,7 @@ def fallback_inevitable(self, op): self.known_category.clear() if not self.always_inevitable: +self.emitting_an_operation_that_can_collect() self._do_stm_call('stm_try_inevitable', [], None) self.always_inevitable = True self.newops.append(op) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c5: The next test to pass
Author: Armin Rigo ar...@tunes.org Branch: c5 Changeset: r565:99e3546e6233 Date: 2013-12-19 14:02 +0100 http://bitbucket.org/pypy/stmgc/changeset/99e3546e6233/ Log:The next test to pass diff --git a/c5/test/test_basic.py b/c5/test/test_basic.py --- a/c5/test/test_basic.py +++ b/c5/test/test_basic.py @@ -234,3 +234,14 @@ assert p1[8] == 'B' assert p2[8] == 'b' assert p3[8] == ':' + +def test_overflow_write_history(self): +stm_start_transaction() +plist = [stm_allocate(n) for n in range(16, 256, 8)] +stm_stop_transaction(False) +# +for i in range(20): +stm_start_transaction() +for p in plist: +stm_write(p) +stm_stop_transaction(False) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c5: in-progress
Author: Armin Rigo ar...@tunes.org Branch: c5 Changeset: r566:3c9724af3fb5 Date: 2013-12-19 14:58 +0100 http://bitbucket.org/pypy/stmgc/changeset/3c9724af3fb5/ Log:in-progress diff --git a/c5/core.c b/c5/core.c --- a/c5/core.c +++ b/c5/core.c @@ -87,15 +87,15 @@ char _pad0[CACHE_LINE_SIZE]; }; union { -uint64_t index_page_never_used; +uint64_t volatile index_page_never_used; char _pad1[CACHE_LINE_SIZE]; }; union { -unsigned int next_transaction_version; /* always EVEN */ +unsigned int volatile next_transaction_version; /* always EVEN */ char _pad2[CACHE_LINE_SIZE]; }; union { -struct write_history_s *most_recent_committed_transaction; +struct write_history_s *volatile most_recent_committed_transaction; char _pad3[CACHE_LINE_SIZE]; }; }; @@ -166,6 +166,13 @@ return result; } +static struct write_history_s *_reserve_page_write_history(void) +{ +struct page_header_s *newpage = _stm_reserve_page(); +newpage-kind = PGKIND_WRITE_HISTORY; +return (struct write_history_s *)(newpage + 1); +} + static uint32_t get_pgoff(struct page_header_s *page) { @@ -216,9 +223,17 @@ assert(page-pgoff == new_pgoff); struct write_history_s *cur = stm_local.writes_by_this_transaction; +size_t history_size_max = 4096 - (((uintptr_t)cur) 4095); +if (sizeof(*cur) + (cur-nb_updates + 1) * 8 history_size_max) { +/* The buffer would overflow its page. Allocate a new one. */ +cur = _reserve_page_write_history(); +cur-previous_older_transaction = +stm_local.writes_by_this_transaction; +cur-transaction_version = stm_transaction_version; +cur-nb_updates = 0; +stm_local.writes_by_this_transaction = cur; +} uint64_t i = cur-nb_updates++; -size_t history_size_max = 4096 - (((uintptr_t)cur) 4095); -assert(sizeof(*cur) + cur-nb_updates * 8 = history_size_max);//XXX cur-updates[i * 2 + 0] = get_local_index(page); cur-updates[i * 2 + 1] = new_pgoff; } @@ -487,15 +502,11 @@ char *next, *page_limit = (char *)cur; page_limit += 4096 - (((uintptr_t)page_limit) 4095); next = (char *)(cur + 1) + 8 * cur-nb_updates; -if (page_limit - next sizeof(struct write_history_s) + 8) -cur = NULL; -else +if (page_limit - next = sizeof(struct write_history_s) + 8) cur = (struct write_history_s *)next; } if (cur == NULL) { -struct page_header_s *newpage = _stm_reserve_page(); -newpage-kind = PGKIND_WRITE_HISTORY; -cur = (struct write_history_s *)(newpage + 1); +cur = _reserve_page_write_history(); } cur-previous_older_transaction = NULL; cur-transaction_version = stm_transaction_version; @@ -527,6 +538,12 @@ int conflict = 0; //fprintf(stderr, stm_stop_transaction\n); +struct write_history_s *cur_head = stm_local.writes_by_this_transaction; +struct write_history_s *cur_tail = cur_head; +while (cur_tail-previous_older_transaction != NULL) { +cur_tail = cur_tail-previous_older_transaction; +} + while (1) { struct write_history_s *hist = d-most_recent_committed_transaction; if (hist != stm_local.base_page_mapping) { @@ -536,10 +553,9 @@ else continue; /* retry from the start of the loop */ } -struct write_history_s *cur = stm_local.writes_by_this_transaction; -cur-previous_older_transaction = hist; +cur_tail-previous_older_transaction = hist; if (__sync_bool_compare_and_swap(d-most_recent_committed_transaction, - hist, cur)) + hist, cur_head)) break; } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c5: Move stm_read() and stm_write() to core.h, from where calls to them can
Author: Armin Rigo ar...@tunes.org Branch: c5 Changeset: r564:a41dc13ba646 Date: 2013-12-19 14:02 +0100 http://bitbucket.org/pypy/stmgc/changeset/a41dc13ba646/ Log:Move stm_read() and stm_write() to core.h, from where calls to them can be inlined. diff --git a/c5/core.c b/c5/core.c --- a/c5/core.c +++ b/c5/core.c @@ -71,13 +71,6 @@ uint32_t pgoff; /* the mm page offset */ }; -struct read_marker_s { -/* We associate a single byte to every object, by simply dividing - the address of the object by 16. The number in this single byte - gives the last time we have read the object. See stm_read(). */ -unsigned char c; -}; - struct write_history_s { struct write_history_s *previous_older_transaction; uint16_t transaction_version; @@ -116,47 +109,36 @@ /* This is just a bunch of global variables, but during testing, we save it all away and restore different ones to simulate different forked processes. */ -char *read_markers; -struct read_marker_s *current_read_markers; -uint16_t transaction_version;/* always EVEN */ struct write_history_s *base_page_mapping; struct write_history_s *writes_by_this_transaction; struct alloc_for_size_s alloc[LARGE_OBJECT_WORDS]; +char *read_markers; +#ifdef STM_TESTS +struct _read_marker_s *_current_read_markers; +uint16_t _transaction_version; +#endif }; struct shared_descriptor_s *stm_shared_descriptor; +struct _read_marker_s *stm_current_read_markers; struct local_data_s stm_local; +uint16_t stm_transaction_version; /* always EVEN */ -void stm_read(struct object_s *object) -{ -stm_local.current_read_markers[((uintptr_t)object) 4].c = -(unsigned char)(uintptr_t)stm_local.current_read_markers; -} - _Bool _stm_was_read(struct object_s *object) { -return (stm_local.current_read_markers[((uintptr_t)object) 4].c == -(unsigned char)(uintptr_t)stm_local.current_read_markers); +return (stm_current_read_markers[((uintptr_t)object) 4].c == +(unsigned char)(uintptr_t)stm_current_read_markers); } -static struct read_marker_s *get_current_read_marker(struct object_s *object) +static struct _read_marker_s *get_current_read_marker(struct object_s *object) { -return stm_local.current_read_markers + (((uintptr_t)object) 4); -} - -void _stm_write_slowpath(struct object_s *); - -void stm_write(struct object_s *object) -{ -if (__builtin_expect(object-modified != stm_local.transaction_version, - 0)) -_stm_write_slowpath(object); +return stm_current_read_markers + (((uintptr_t)object) 4); } _Bool _stm_was_written(struct object_s *object) { -return (object-modified == stm_local.transaction_version); +return (object-modified == stm_transaction_version); } @@ -216,21 +198,21 @@ page = (struct page_header_s *)(((uintptr_t)object) ~4095); assert(2 = page-kind page-kind LARGE_OBJECT_WORDS); -if (page-version != stm_local.transaction_version) { +if (page-version != stm_transaction_version) { struct page_header_s *newpage = _stm_reserve_page(); uint32_t old_pgoff = get_pgoff(page); uint32_t new_pgoff = get_pgoff(newpage); pagecopy(newpage, page); -newpage-version = stm_local.transaction_version; +newpage-version = stm_transaction_version; newpage-modif_head = 0xff; newpage-pgoff = new_pgoff; -assert(page-version != stm_local.transaction_version); +assert(page-version != stm_transaction_version); assert(page-pgoff == old_pgoff); remap_file_pages((void *)page, 4096, 0, new_pgoff, MAP_PAGES_FLAGS); -assert(page-version == stm_local.transaction_version); +assert(page-version == stm_transaction_version); assert(page-pgoff == new_pgoff); struct write_history_s *cur = stm_local.writes_by_this_transaction; @@ -240,7 +222,7 @@ cur-updates[i * 2 + 0] = get_local_index(page); cur-updates[i * 2 + 1] = new_pgoff; } -object-modified = stm_local.transaction_version; +object-modified = stm_transaction_version; object-modif_next = page-modif_head; page-modif_head = (uint8_t)(((uintptr_t)object) 4); assert(page-modif_head != 0xff); @@ -271,7 +253,7 @@ p = _stm_alloc_next_page(i); struct object_s *result = (struct object_s *)p; -result-modified = stm_local.transaction_version; +result-modified = stm_transaction_version; /*result-modif_next is uninitialized*/ result-flags = 0x42; /* for debugging */ return result; @@ -280,17 +262,17 @@ unsigned char stm_get_read_marker_number(void) { -return (unsigned char)(uintptr_t)stm_local.current_read_markers; +return (unsigned char)(uintptr_t)stm_current_read_markers; } void stm_set_read_marker_number(uint8_t num) { char *stm_pages = ((char
[pypy-commit] stmgc c5: Bah, fix
Author: Armin Rigo ar...@tunes.org Branch: c5 Changeset: r567:57a9caca7c44 Date: 2013-12-19 15:21 +0100 http://bitbucket.org/pypy/stmgc/changeset/57a9caca7c44/ Log:Bah, fix diff --git a/c5/core.c b/c5/core.c --- a/c5/core.c +++ b/c5/core.c @@ -502,12 +502,15 @@ char *next, *page_limit = (char *)cur; page_limit += 4096 - (((uintptr_t)page_limit) 4095); next = (char *)(cur + 1) + 8 * cur-nb_updates; -if (page_limit - next = sizeof(struct write_history_s) + 8) +if (page_limit - next sizeof(struct write_history_s) + 8) +cur = NULL; +else cur = (struct write_history_s *)next; } if (cur == NULL) { cur = _reserve_page_write_history(); } +assert(cur != d-most_recent_committed_transaction); cur-previous_older_transaction = NULL; cur-transaction_version = stm_transaction_version; cur-nb_updates = 0; @@ -553,6 +556,7 @@ else continue; /* retry from the start of the loop */ } +assert(cur_head == stm_local.writes_by_this_transaction); cur_tail-previous_older_transaction = hist; if (__sync_bool_compare_and_swap(d-most_recent_committed_transaction, hist, cur_head)) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c5: Add three XXX'es
Author: Armin Rigo ar...@tunes.org Branch: c5 Changeset: r563:2ec0dda36009 Date: 2013-12-19 13:46 +0100 http://bitbucket.org/pypy/stmgc/changeset/2ec0dda36009/ Log:Add three XXX'es diff --git a/c5/core.c b/c5/core.c --- a/c5/core.c +++ b/c5/core.c @@ -236,7 +236,7 @@ struct write_history_s *cur = stm_local.writes_by_this_transaction; uint64_t i = cur-nb_updates++; size_t history_size_max = 4096 - (((uintptr_t)cur) 4095); -assert(sizeof(*cur) + cur-nb_updates * 8 = history_size_max); +assert(sizeof(*cur) + cur-nb_updates * 8 = history_size_max);//XXX cur-updates[i * 2 + 0] = get_local_index(page); cur-updates[i * 2 + 1] = new_pgoff; } @@ -262,7 +262,7 @@ { assert(size % 8 == 0); size_t i = size / 8; -assert(2 = i i LARGE_OBJECT_WORDS); +assert(2 = i i LARGE_OBJECT_WORDS);//XXX struct alloc_for_size_s *alloc = stm_local.alloc[i]; char *p = alloc-next; @@ -356,8 +356,8 @@ abort(); } -stm_set_read_marker_number(42); -assert(stm_get_read_marker_number() == 42); +assert((stm_set_read_marker_number(42), +stm_get_read_marker_number() == 42)); stm_set_read_marker_number(1); } @@ -476,7 +476,7 @@ struct object_s *myobj = (struct object_s *) (((char *)obj) + diff_to_mypage); assert(obj-flags == 0x42); -assert(myobj-flags == 0x42); // || myobj-flags == 0); +assert(myobj-flags == 0x42); if (_stm_was_read(myobj)) { fprintf(stderr, # conflict: %p\n, myobj); conflict = 1; @@ -496,7 +496,7 @@ struct shared_descriptor_s *d = stm_shared_descriptor; stm_local.transaction_version = __sync_fetch_and_add(d-next_transaction_version, 2u); -assert(stm_local.transaction_version = 0x); +assert(stm_local.transaction_version = 0x);//XXX assert((stm_local.transaction_version 1) == 0); /* EVEN number */ assert(stm_local.transaction_version = 2); @@ -533,6 +533,8 @@ if (ptr != NULL) { page = (struct page_header_s *)(((uintptr_t)ptr) ~4095); page-version = stm_local.transaction_version - 1; +/* ^^^ this is one of the only writes to shared memory; + usually it is read-only */ } } } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c5: A completely new page doesn't need a version.
Author: Armin Rigo ar...@tunes.org Branch: c5 Changeset: r562:fec50fbe7690 Date: 2013-12-19 12:12 +0100 http://bitbucket.org/pypy/stmgc/changeset/fec50fbe7690/ Log:A completely new page doesn't need a version. diff --git a/c5/core.c b/c5/core.c --- a/c5/core.c +++ b/c5/core.c @@ -250,8 +250,8 @@ { struct page_header_s *newpage = _stm_reserve_page(); newpage-modif_head = 0xff; -newpage-kind = i; /* object size in words */ -newpage-version = stm_local.transaction_version; +newpage-kind = i; /* object size in words */ +newpage-version = 0; /* a completely new page doesn't need a version */ stm_local.alloc[i].next = ((char *)(newpage + 1)) + (i * 8); stm_local.alloc[i].end = ((char *)newpage) + 4096; assert(stm_local.alloc[i].next = stm_local.alloc[i].end); @@ -498,6 +498,7 @@ __sync_fetch_and_add(d-next_transaction_version, 2u); assert(stm_local.transaction_version = 0x); assert((stm_local.transaction_version 1) == 0); /* EVEN number */ +assert(stm_local.transaction_version = 2); struct write_history_s *cur = NULL; if (stm_local.writes_by_this_transaction != NULL) { ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] lang-smalltalk rbitblt: finish copying squeakjs bitblt
Author: Tim Felgentreff timfelgentr...@gmail.com Branch: rbitblt Changeset: r543:fb979403239a Date: 2013-12-19 16:26 +0100 http://bitbucket.org/pypy/lang-smalltalk/changeset/fb979403239a/ Log:finish copying squeakjs bitblt diff --git a/spyvm/primitives.py b/spyvm/primitives.py --- a/spyvm/primitives.py +++ b/spyvm/primitives.py @@ -649,7 +649,7 @@ if (combinationRule == 22 or combinationRule == 32): s_frame.pop() # pops the next value under BitBlt s_frame.push(s_bitblt.bitCount()) -else if w_dest_form.is_same_object(space.objtable['w_display']): +elif w_dest_form.is_same_object(space.objtable['w_display']): w_bitmap = w_dest_form.fetch(space, 0) assert isinstance(w_bitmap, model.W_DisplayBitmap) w_bitmap.flush_to_screen() diff --git a/spyvm/shadow.py b/spyvm/shadow.py --- a/spyvm/shadow.py +++ b/spyvm/shadow.py @@ -1178,19 +1178,19 @@ def loadBitBlt(self): self.success = True -self.destForm = self.fetch(0) -self.dest = self.loadForm(self.destForm) -self.sourceForm = self.fetch(1) -if self.sourceForm is not self.space.w_nil: -self.source = self.loadForm(self.sourceForm) +self.w_destForm = self.fetch(0) +self.dest = self.loadForm(self.w_destForm) +self.w_sourceForm = self.fetch(1) +if self.w_sourceForm is not self.space.w_nil: +self.source = self.loadForm(self.w_sourceForm) else: self.source = None self.halftone = self.loadHalftone(self.fetch(2)) self.combinationRule = self.space.unwrap_int(self.fetch(3)) self.destX = self.intOrIfNil(self.fetch(4), 0) self.destY = self.intOrIfNil(self.fetch(5), 0) -self.width = self.intOrIfNil(self.fetch(6), self.dest_form.width) -self.height = self.intOrIfNil(self.fetch(7), self.dest_form.height) +self.width = self.intOrIfNil(self.fetch(6), self.dest.width) +self.height = self.intOrIfNil(self.fetch(7), self.dest.height) self.clipX = self.intOrIfNil(self.fetch(10), 0) self.clipY = self.intOrIfNil(self.fetch(11), 0) self.clipW = self.intOrIfNil(self.fetch(12), self.width) @@ -1206,19 +1206,72 @@ def copyBits(self): self.bitCount = 0 self.clipRange() -if (self.bbW = 0 ir self.bbH = 0): +if (self.bbW = 0 or self.bbH = 0): return self.destMaskAndPointerInit() if not self.source: self.copyLoopNoSource() else: self.checkSourceOverlap() -if self.source.depth !== self.dest.depth: +if self.source.depth != self.dest.depth: self.copyLoopPixMap() else: self.sourceSkewAndPointerInit() self.copyLoop() +def checkSourceOverlap(self): +if (self.w_sourceForm is self.w_destForm and self.dy = self.sy): +if (self.dy self.sy): +self.vDir = -1 +self.sy = (self.sy + self.bbH) - 1 +self.dy = (self.dy + self.bbH) - 1 +else: +if (self.dy == self.sy and self.dx self.sx): +self.hDir = -1 +self.sx = (self.sx + self.bbW) - 1 # start at right +self.dx = (self.dx + self.bbW) - 1 +if (self.nWords 1): +t = self.mask1 # and fix up masks +self.mask1 = self.mask2 +self.mask2 = t +self.destIndex = (self.dy * self.dest.pitch) + (self.dx / self.dest.pixPerWord | 0) # recompute since dx, dy change +self.destDelta = (self.dest.pitch * self.vDir) - (self.nWords * self.hDir) + +def sourceSkewAndPointerInit(self): +pixPerM1 = self.dest.pixPerWord - 1 # Pix per word is power of two, so self makes a mask +sxLowBits = self.sx pixPerM1 +dxLowBits = self.dx pixPerM1 +# check if need to preload buffer +# (i.e., two words of source needed for first word of destination) +dWid = -1 +if (self.hDir 0): +if self.bbW (self.dest.pixPerWord - dxLowBits): +dWid = self.bbW +else: +dWid = self.dest.pixPerWord - dxLowBits +self.preload = (sxLowBits + dWid) pixPerM1 +else: +if self.bbW (dxLowBits + 1): +dWid = self.bbW +else: +dWid = dxLowBits + 1 +self.preload = ((sxLowBits - dWid) + 1) 0 + +if self.source.msb: +self.skew = (sxLowBits - dxLowBits) * self.dest.depth +else: +self.skew = (dxLowBits - sxLowBits) * self.dest.depth +if (self.preload): +if (self.skew 0): +self.skew += 32 +else: +self.skew -= 32 +# calculate increments from end of one line to start of next +
[pypy-commit] lang-smalltalk rbitblt: fix translation, displays 4.5 image, but crashes in various places along the copyLoopPixMap path
Author: Tim Felgentreff timfelgentr...@gmail.com Branch: rbitblt Changeset: r544:d4bb7a494adf Date: 2013-12-19 17:50 +0100 http://bitbucket.org/pypy/lang-smalltalk/changeset/d4bb7a494adf/ Log:fix translation, displays 4.5 image, but crashes in various places along the copyLoopPixMap path diff --git a/spyvm/primitives.py b/spyvm/primitives.py --- a/spyvm/primitives.py +++ b/spyvm/primitives.py @@ -648,7 +648,7 @@ w_dest_form = w_rcvr.fetch(space, 0) if (combinationRule == 22 or combinationRule == 32): s_frame.pop() # pops the next value under BitBlt -s_frame.push(s_bitblt.bitCount()) +s_frame.push(interp.space.wrap_int(s_bitblt.bitCount)) elif w_dest_form.is_same_object(space.objtable['w_display']): w_bitmap = w_dest_form.fetch(space, 0) assert isinstance(w_bitmap, model.W_DisplayBitmap) diff --git a/spyvm/shadow.py b/spyvm/shadow.py --- a/spyvm/shadow.py +++ b/spyvm/shadow.py @@ -1132,7 +1132,7 @@ MaskTable = [rarithmetic.r_uint(0)] for i in xrange(WordSize): MaskTable.append(rarithmetic.r_uint((2 ** (i + 1)) - 1)) -AllOnes = rarithmetic.r_uint((2 ** WordSize) - 1) +AllOnes = rarithmetic.r_uint(0x) def sync_cache(self): self.loadBitBlt() @@ -1146,10 +1146,10 @@ def loadForm(self, w_form): try: if not isinstance(w_form, model.W_PointersObject): -raise PrimitiveFailedError() +raise error.PrimitiveFailedError() s_form = w_form.as_form_get_shadow(self.space) if not isinstance(s_form, FormShadow): -raise PrimitiveFailedError() +raise error.PrimitiveFailedError() return s_form except error.PrimitiveFailedError, e: w_self = self.w_self() @@ -1171,10 +1171,10 @@ def loadColorMap(self, w_color_map): if isinstance(w_color_map, model.W_WordsObject): -self.cmLookupTable = w_color_map.words -self.cmMask = len(self.cmLookupTable) - 1 +self.w_cmLookupTable = w_color_map +self.cmMask = self.w_cmLookupTable.size() - 1 else: -self.cmLookupTable = None +self.w_cmLookupTable = None def loadBitBlt(self): self.success = True @@ -1316,18 +1316,19 @@ self.bbH -= (self.sy + self.bbH) - self.source.height def rshift(self, val, n): -return rarithmetic.intmask(val n if val = 0 else (val + 0x1) n) +# return rarithmetic.r_uint(val n if val = 0 else (val + 0x1) n) +return rarithmetic.r_uint(rarithmetic.r_uint(val) n BitBltShadow.AllOnes) def destMaskAndPointerInit(self): pixPerM1 = self.dest.pixPerWord - 1 # pixPerWord is power-of-two, so this makes a mask startBits = self.dest.pixPerWord - (self.dx pixPerM1) # how many px in 1st word endBits = (((self.dx + self.bbW) - 1) pixPerM1) + 1 if self.dest.msb: -self.mask1 = self.rshift(0x, (32 - (startBits * self.dest.depth))) -self.mask2 = 0x (32 - (endBits * self.dest.depth)) +self.mask1 = self.rshift(BitBltShadow.AllOnes, (32 - (startBits * self.dest.depth))) +self.mask2 = BitBltShadow.AllOnes (32 - (endBits * self.dest.depth)) else: -self.mask1 = 0x (32 - (startBits * self.dest.depth)) -self.mask2 = self.rshift(0x, (32 - (endBits * self.dest.depth))) +self.mask1 = BitBltShadow.AllOnes (32 - (startBits * self.dest.depth)) +self.mask2 = self.rshift(BitBltShadow.AllOnes, (32 - (endBits * self.dest.depth))) if self.bbW startBits: self.mask1 = self.mask1 self.mask2 self.mask2 = 0 @@ -1340,10 +1341,10 @@ self.destDelta = (self.dest.pitch * self.vDir) - (self.nWords * self.hDir) def copyLoopNoSource(self): -halftoneWord = 0x +halftoneWord = BitBltShadow.AllOnes for i in range(self.bbH): if self.halftone: -halftoneWord = self.halftone[(self.dy + i) % len(self.halftone)] +halftoneWord = rarithmetic.r_uint(self.halftone[(self.dy + i) % len(self.halftone)]) # first word in row is masked destMask = self.mask1 destWord = self.dest.w_bits.getword(self.destIndex) @@ -1351,7 +1352,7 @@ destWord = (destMask mergeWord) | (destWord (~destMask)) self.dest.w_bits.setword(self.destIndex, destWord) self.destIndex += 1 -destMask = 0x +destMask = BitBltShadow.AllOnes # the central horizontal loop requires no store masking if self.combinationRule == 3: # store rule requires no dest merging for word in range(2, self.nWords): @@ -1385,8 +1386,8 @@ # The loop has been rewritten to use
[pypy-commit] pypy default: cleanup, make the prod test pass for numpypy and numpy ( -A )
Author: Matti Picus matti.pi...@gmail.com Branch: Changeset: r68486:862f40eff396 Date: 2013-12-19 21:03 +0200 http://bitbucket.org/pypy/pypy/changeset/862f40eff396/ Log:cleanup, make the prod test pass for numpypy and numpy ( -A ) diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py --- a/pypy/module/micronumpy/interp_dtype.py +++ b/pypy/module/micronumpy/interp_dtype.py @@ -1,4 +1,3 @@ -import sys from pypy.interpreter.baseobjspace import W_Root from pypy.interpreter.error import OperationError, operationerrfmt from pypy.interpreter.gateway import interp2app, unwrap_spec 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 @@ -1400,18 +1400,18 @@ assert (array([[1,2],[3,4]]).prod(1) == [2, 12]).all() def test_prod(self): -from numpypy import array, int_, dtype +from numpypy import array, dtype a = array(range(1, 6)) assert a.prod() == 120.0 assert a[:4].prod() == 24.0 for dt in ['bool', 'int8', 'uint8', 'int16', 'uint16']: a = array([True, False], dtype=dt) assert a.prod() == 0 -assert a.prod().dtype is dtype('uint' if dt[0] == 'u' else 'int') +assert a.prod().dtype == dtype('uint' if dt[0] == 'u' else 'int') for dt in ['l', 'L', 'q', 'Q', 'e', 'f', 'd', 'F', 'D']: a = array([True, False], dtype=dt) assert a.prod() == 0 -assert a.prod().dtype is dtype(dt) +assert a.prod().dtype == dtype(dt) def test_max(self): from numpypy import array, zeros ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] stmgc c5: in-progress
Author: Armin Rigo ar...@tunes.org Branch: c5 Changeset: r568:7171e5c9d978 Date: 2013-12-19 22:13 +0100 http://bitbucket.org/pypy/stmgc/changeset/7171e5c9d978/ Log:in-progress diff --git a/c5/largemalloc.c b/c5/largemalloc.c new file mode 100644 --- /dev/null +++ b/c5/largemalloc.c @@ -0,0 +1,190 @@ +/* This contains a lot of inspiration from malloc() in the GNU C Library. + More precisely, this is (a subset of) the part that handles large + blocks, which in our case means at least 288 bytes. +*/ + + +#define MMAP_LIMIT(1280*1024) + +#define largebin_index(sz) \ +sz) 6) = 47) ? ((sz) 6): /* 0 - 47 */\ + (((sz) 9) = 23) ? 42 + ((sz) 9): /* 48 - 65 */\ + (((sz) 12) = 11) ? 63 + ((sz) 12): /* 66 - 74 */\ + (((sz) 15) = 5) ? 74 + ((sz) 15): /* 75 - 79 */\ + (((sz) 18) = 2) ? 80 + ((sz) 18): /* 80 - 82 */\ +83) +#define N_BINS 84 + +typedef struct malloc_chunk { +size_t prev_size; /* - if the previous chunk is free: its size + - otherwise, if this chunk is free: 1 + - otherwise, 0. */ +size_t size; /* size of this chunk */ + +union { +char data[1]; /* if not free: start of the user data */ +struct malloc_chunk *next; /* if free: a doubly-linked list */ +}; +struct malloc_chunk *prev; + +/* The chunk has a total size of 'size'. It is immediately followed + in memory by another chunk. This list ends with the last chunk + being actually only one word long, 'size_t prev_size'. Both this + last chunk and the theoretical chunk before the first one are + considered not free. */ +} *mchunk_t; + +#define THIS_CHUNK_FREE 1 +#define BOTH_CHUNKS_USED 0 +#define CHUNK_HEADER_SIZEoffsetof(struct malloc_chunk, data) +#define MINSIZE sizeof(struct malloc_chunk) + +#define chunk_at_offset(p, ofs) ((mchunk_t *)(((char *)(p)) + ofs)) +#define next_chunk(p)chunk_at_offset(p, (p)-size) + + +/* The free chunks are stored in bins. Each bin is a doubly-linked + list of chunks. There are 84 bins, with largebin_index() giving the + correspondence between sizes are bin indices. + + Each free chunk is preceeded in memory by a non-free chunk (or no + chunk at all). Each free chunk is followed in memory by a non-free + chunk (or no chunk at all). Chunks are consolidated with their + neighbors to ensure this. + + In each bin's doubly-linked list, chunks are sorted by their size in + decreasing order . Among chunks of equal size, they are ordered with + the most recently freed first, and we take them from the back. This + results in FIFO order, which is better to give each block a while to + rest in the list and be consolidated into potentially larger blocks. +*/ + +static struct { mchunk_t *head, mchunk_t *tail; } largebins[N_BINS]; + + +static char *allocate_more(size_t request_size); + +static void insert_sort(mchunk_t *new) +{ +size_t index = largebin_index(new-size); +mchunk_t *head = largebins[index]-head; + +if (head == NULL) { +assert(largebins[index]-tail == NULL); +new-prev = NULL; +new-next = NULL; +largebins[index]-tail = new; +largebins[index]-head = new; +return; +} +assert(largebins[index]-tail != NULL); + +size_t new_size = new-size; +if (new_size = head-size) { +new-prev = NULL; +new-next = head; +assert(head-prev == NULL); +head-prev = new; +largebins[index]-head = new; +return; +} +mchunk_t *search; +for (search = head; search != NULL; search = search-next) { +if (new_size = search-size) { +new-prev = search-prev; +new-prev-next = new; +new-next = search; +search-prev = new; +return; +} +} +new-prev = largebins[index]-tail; +new-prev-next = new; +new-next = NULL; +largebins[index]-tail = new; +} + +char *stm_large_malloc(size_t request_size) +{ +/* 'request_size' should already be a multiple of the word size here */ +assert((request_size (sizeof(char *)-1)) == 0); + +size_t chunk_size = request_size + CHUNK_HEADER_SIZE; +if (chunk_size request_size) { +/* 'request_size' is so large that the addition wrapped around */ +fprintf(stderr, allocation request too large\n); +abort(); +} + +size_t index = largebin_index(chunk_size); + +/* scan through the chunks of current bin in reverse order + to find the smallest that fits. */ +mchunk_t *scan = largebins[index]-tail; +mchunk_t *head = largebins[index]-head; +while (scan != head) { +assert(scan-prev_size == THIS_CHUNK_FREE); +assert(next_chunk(scan)-prev_size == scan-size); + +if
[pypy-commit] pypy py3k: merge default
Author: Philip Jenvey pjen...@underboss.org Branch: py3k Changeset: r68488:a2ebaff30cc5 Date: 2013-12-19 13:20 -0800 http://bitbucket.org/pypy/pypy/changeset/a2ebaff30cc5/ Log:merge default diff --git a/lib-python/2.7/ctypes/__init__.py b/lib-python/2.7/ctypes/__init__.py --- a/lib-python/2.7/ctypes/__init__.py +++ b/lib-python/2.7/ctypes/__init__.py @@ -371,10 +371,9 @@ self._handle = handle def __repr__(self): -return %s '%s', handle %r at %x % \ - (self.__class__.__name__, self._name, -(self._handle), -id(self) (_sys.maxint*2 + 1)) +return %s '%s', handle %r at 0x%x % ( +self.__class__.__name__, self._name, self._handle, +id(self) (_sys.maxint * 2 + 1)) def __getattr__(self, name): diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py --- a/pypy/module/micronumpy/interp_dtype.py +++ b/pypy/module/micronumpy/interp_dtype.py @@ -1,4 +1,3 @@ -import sys from pypy.interpreter.baseobjspace import W_Root from pypy.interpreter.error import OperationError, operationerrfmt from pypy.interpreter.gateway import interp2app, unwrap_spec 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 @@ -498,13 +498,14 @@ promote_bools=False, promote_to_largest=False): if promote_to_largest: if dt.kind == NPY_GENBOOLLTR or dt.kind == NPY_SIGNEDLTR: -return interp_dtype.get_dtype_cache(space).w_int64dtype +if dt.get_size() * 8 LONG_BIT: +return interp_dtype.get_dtype_cache(space).w_longdtype elif dt.kind == NPY_UNSIGNEDLTR: -return interp_dtype.get_dtype_cache(space).w_uint64dtype -elif dt.kind == NPY_FLOATINGLTR or dt.kind == NPY_COMPLEXLTR: -return dt +if dt.get_size() * 8 LONG_BIT: +return interp_dtype.get_dtype_cache(space).w_ulongdtype else: -assert False +assert dt.kind == NPY_FLOATINGLTR or dt.kind == NPY_COMPLEXLTR +return dt if promote_bools and (dt.kind == NPY_GENBOOLLTR): return interp_dtype.get_dtype_cache(space).w_int8dtype if promote_to_float: 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 @@ -1400,16 +1400,18 @@ assert (array([[1,2],[3,4]]).prod(1) == [2, 12]).all() def test_prod(self): -from numpypy import array, int_, dtype +from numpypy import array, dtype a = array(range(1, 6)) assert a.prod() == 120.0 assert a[:4].prod() == 24.0 -a = array([True, False]) -assert a.prod() == 0 -assert type(a.prod()) is int_ -a = array([True, False], dtype='uint') -assert a.prod() == 0 -assert type(a.prod()) is dtype('uint').type +for dt in ['bool', 'int8', 'uint8', 'int16', 'uint16']: +a = array([True, False], dtype=dt) +assert a.prod() == 0 +assert a.prod().dtype == dtype('uint' if dt[0] == 'u' else 'int') +for dt in ['l', 'L', 'q', 'Q', 'e', 'f', 'd', 'F', 'D']: +a = array([True, False], dtype=dt) +assert a.prod() == 0 +assert a.prod().dtype == dtype(dt) def test_max(self): from numpypy import array, zeros ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3k: bring over @xfail from default
Author: Philip Jenvey pjen...@underboss.org Branch: py3k Changeset: r68490:2cba9ecdb773 Date: 2013-12-19 13:21 -0800 http://bitbucket.org/pypy/pypy/changeset/2cba9ecdb773/ Log:bring over @xfail from default diff --git a/lib-python/3/ctypes/test/test_python_api.py b/lib-python/3/ctypes/test/test_python_api.py --- a/lib-python/3/ctypes/test/test_python_api.py +++ b/lib-python/3/ctypes/test/test_python_api.py @@ -73,6 +73,7 @@ del pyobj self.assertEqual(grc(s), ref) +@xfail def test_PyOS_snprintf(self): PyOS_snprintf = pythonapi.PyOS_snprintf PyOS_snprintf.argtypes = POINTER(c_char), c_size_t, c_char_p ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3k: fix __repr__
Author: Philip Jenvey pjen...@underboss.org Branch: py3k Changeset: r68489:ea48ea97deda Date: 2013-12-19 13:21 -0800 http://bitbucket.org/pypy/pypy/changeset/ea48ea97deda/ Log:fix __repr__ diff --git a/lib-python/3/ctypes/__init__.py b/lib-python/3/ctypes/__init__.py --- a/lib-python/3/ctypes/__init__.py +++ b/lib-python/3/ctypes/__init__.py @@ -359,10 +359,9 @@ self._handle = handle def __repr__(self): -return %s '%s', handle %x at %x % \ - (self.__class__.__name__, self._name, -(self._handle (_sys.maxsize*2 + 1)), -id(self) (_sys.maxsize*2 + 1)) +return %s '%s', handle %r at 0x%x % ( +self.__class__.__name__, self._name, self._handle, +id(self) (_sys.maxsize * 2 + 1)) def __getattr__(self, name): if name.startswith('__') and name.endswith('__'): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: cleanup
Author: Philip Jenvey pjen...@underboss.org Branch: Changeset: r68487:6ae2e7a522af Date: 2013-12-19 13:20 -0800 http://bitbucket.org/pypy/pypy/changeset/6ae2e7a522af/ Log:cleanup diff --git a/lib-python/2.7/ctypes/__init__.py b/lib-python/2.7/ctypes/__init__.py --- a/lib-python/2.7/ctypes/__init__.py +++ b/lib-python/2.7/ctypes/__init__.py @@ -371,10 +371,9 @@ self._handle = handle def __repr__(self): -return %s '%s', handle %r at %x % \ - (self.__class__.__name__, self._name, -(self._handle), -id(self) (_sys.maxint*2 + 1)) +return %s '%s', handle %r at 0x%x % ( +self.__class__.__name__, self._name, self._handle, +id(self) (_sys.maxint * 2 + 1)) def __getattr__(self, name): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: the is comparison is important in this test, put it back
Author: Brian Kearns bdkea...@gmail.com Branch: Changeset: r68492:cee13fb60662 Date: 2013-12-19 16:38 -0500 http://bitbucket.org/pypy/pypy/changeset/cee13fb60662/ Log:the is comparison is important in this test, put it back 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 @@ -1407,11 +1407,11 @@ for dt in ['bool', 'int8', 'uint8', 'int16', 'uint16']: a = array([True, False], dtype=dt) assert a.prod() == 0 -assert a.prod().dtype == dtype('uint' if dt[0] == 'u' else 'int') +assert a.prod().dtype is dtype('uint' if dt[0] == 'u' else 'int') for dt in ['l', 'L', 'q', 'Q', 'e', 'f', 'd', 'F', 'D']: a = array([True, False], dtype=dt) assert a.prod() == 0 -assert a.prod().dtype == dtype(dt) +assert a.prod().dtype is dtype(dt) def test_max(self): from numpypy import array, zeros ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix confusion between numpy int types by making LongBox a real box so we can differentiate it
Author: Brian Kearns bdkea...@gmail.com Branch: Changeset: r68491:3a4a7e1a41a1 Date: 2013-12-19 16:28 -0500 http://bitbucket.org/pypy/pypy/changeset/3a4a7e1a41a1/ Log:fix confusion between numpy int types by making LongBox a real box so we can differentiate it 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 @@ -350,28 +350,22 @@ descr__new__, _get_dtype, descr_reduce = new_dtype_getter(uint16) class W_Int32Box(W_SignedIntegerBox, PrimitiveBox): -descr__new__, _get_dtype, descr_reduce = new_dtype_getter(int32) +descr__new__, _get_dtype, descr_reduce = new_dtype_getter(i) class W_UInt32Box(W_UnsignedIntegerBox, PrimitiveBox): -descr__new__, _get_dtype, descr_reduce = new_dtype_getter(uint32) +descr__new__, _get_dtype, descr_reduce = new_dtype_getter(I) + +class W_Int64Box(W_SignedIntegerBox, PrimitiveBox): +descr__new__, _get_dtype, descr_reduce = new_dtype_getter(q) + +class W_UInt64Box(W_UnsignedIntegerBox, PrimitiveBox): +descr__new__, _get_dtype, descr_reduce = new_dtype_getter(Q) class W_LongBox(W_SignedIntegerBox, PrimitiveBox): -descr__new__, _get_dtype, descr_reduce = new_dtype_getter(long) +descr__new__, _get_dtype, descr_reduce = new_dtype_getter(l) class W_ULongBox(W_UnsignedIntegerBox, PrimitiveBox): -descr__new__, _get_dtype, descr_reduce = new_dtype_getter(ulong) - -class W_Int64Box(W_SignedIntegerBox, PrimitiveBox): -descr__new__, _get_dtype, descr_reduce = new_dtype_getter(int64) - -class W_LongLongBox(W_SignedIntegerBox, PrimitiveBox): -descr__new__, _get_dtype, descr_reduce = new_dtype_getter('longlong') - -class W_UInt64Box(W_UnsignedIntegerBox, PrimitiveBox): -descr__new__, _get_dtype, descr_reduce = new_dtype_getter(uint64) - -class W_ULongLongBox(W_SignedIntegerBox, PrimitiveBox): -descr__new__, _get_dtype, descr_reduce = new_dtype_getter('ulonglong') +descr__new__, _get_dtype, descr_reduce = new_dtype_getter(L) class W_InexactBox(W_NumberBox): pass @@ -663,13 +657,6 @@ __reduce__ = interp2app(W_Int64Box.descr_reduce), ) -if LONG_BIT == 32: -W_LongBox = W_Int32Box -W_ULongBox = W_UInt32Box -elif LONG_BIT == 64: -W_LongBox = W_Int64Box -W_ULongBox = W_UInt64Box - W_UInt64Box.typedef = TypeDef(uint64, W_UnsignedIntegerBox.typedef, __module__ = numpy, __new__ = interp2app(W_UInt64Box.descr__new__.im_func), @@ -677,6 +664,22 @@ __reduce__ = interp2app(W_UInt64Box.descr_reduce), ) +W_LongBox.typedef = TypeDef(int%d % LONG_BIT, +(W_SignedIntegerBox.typedef, int_typedef), +__module__ = numpy, +__new__ = interp2app(W_LongBox.descr__new__.im_func), +__index__ = interp2app(W_LongBox.descr_index), +__reduce__ = interp2app(W_LongBox.descr_reduce), +) + +W_ULongBox.typedef = TypeDef(uint%d % LONG_BIT, +(W_UnsignedIntegerBox.typedef, int_typedef), +__module__ = numpy, +__new__ = interp2app(W_ULongBox.descr__new__.im_func), +__index__ = interp2app(W_ULongBox.descr_index), +__reduce__ = interp2app(W_ULongBox.descr_reduce), +) + W_InexactBox.typedef = TypeDef(inexact, W_NumberBox.typedef, __module__ = numpy, ) diff --git a/pypy/module/micronumpy/test/test_scalar.py b/pypy/module/micronumpy/test/test_scalar.py --- a/pypy/module/micronumpy/test/test_scalar.py +++ b/pypy/module/micronumpy/test/test_scalar.py @@ -4,7 +4,7 @@ spaceconfig = dict(usemodules=[micronumpy, binascii, struct]) def test_init(self): -import numpypy as np +import numpy as np import math assert np.intp() == np.intp(0) assert np.intp('123') == np.intp(123) @@ -17,6 +17,8 @@ assert np.complex_() == np.complex_(0) #raises(TypeError, np.complex_, '1+2j') assert math.isnan(np.complex_(None)) +for c in ['i', 'I', 'l', 'L', 'q', 'Q']: +assert np.dtype(c).type().dtype.char == c def test_builtin(self): import numpy as np @@ -37,7 +39,7 @@ assert len(np.string_('123')) == 3 def test_pickle(self): -from numpypy import dtype, zeros +from numpy import dtype, zeros try: from numpy.core.multiarray import scalar except ImportError: @@ -112,7 +114,7 @@ raises(TypeError, a.squeeze, 2) def test_attributes(self): -import numpypy as np +import numpy as np value = np.dtype('int64').type(12345) assert value.dtype == np.dtype('int64') assert value.size == 1 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix uint64 mro
Author: Brian Kearns bdkea...@gmail.com Branch: Changeset: r68493:4d06bf382d94 Date: 2013-12-19 16:54 -0500 http://bitbucket.org/pypy/pypy/changeset/4d06bf382d94/ Log:fix uint64 mro 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 @@ -672,8 +672,7 @@ __reduce__ = interp2app(W_LongBox.descr_reduce), ) -W_ULongBox.typedef = TypeDef(uint%d % LONG_BIT, -(W_UnsignedIntegerBox.typedef, int_typedef), +W_ULongBox.typedef = TypeDef(uint%d % LONG_BIT, W_UnsignedIntegerBox.typedef, __module__ = numpy, __new__ = interp2app(W_ULongBox.descr__new__.im_func), __index__ = interp2app(W_ULongBox.descr_index), ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: simplify/fix some intp attributes
Author: Brian Kearns bdkea...@gmail.com Branch: Changeset: r68494:5076b09e7c83 Date: 2013-12-19 17:15 -0500 http://bitbucket.org/pypy/pypy/changeset/5076b09e7c83/ Log:simplify/fix some intp attributes diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py --- a/pypy/module/micronumpy/interp_dtype.py +++ b/pypy/module/micronumpy/interp_dtype.py @@ -735,38 +735,21 @@ char=NPY_HALFLTR, w_box_type=space.gettypefor(interp_boxes.W_Float16Box), ) -ptr_size = rffi.sizeof(rffi.CCHARP) -if ptr_size == 4: -intp_box = interp_boxes.W_Int32Box -intp_type = types.Int32() -intp_num = NPY_INT -uintp_box = interp_boxes.W_UInt32Box -uintp_type = types.UInt32() -uintp_num = NPY_UINT -elif ptr_size == 8: -intp_box = interp_boxes.W_Int64Box -intp_type = types.Int64() -intp_num = NPY_LONG -uintp_box = interp_boxes.W_UInt64Box -uintp_type = types.UInt64() -uintp_num = NPY_ULONG -else: -raise ValueError('unknown point size %d' % ptr_size) self.w_intpdtype = W_Dtype( -intp_type, -num=intp_num, -kind=NPY_INTPLTR, +types.Long(), +num=NPY_LONG, +kind=NPY_SIGNEDLTR, name='intp', char=NPY_INTPLTR, -w_box_type = space.gettypefor(intp_box), +w_box_type = space.gettypefor(interp_boxes.W_LongBox), ) self.w_uintpdtype = W_Dtype( -uintp_type, -num=uintp_num, -kind=NPY_UINTPLTR, +types.ULong(), +num=NPY_ULONG, +kind=NPY_UNSIGNEDLTR, name='uintp', char=NPY_UINTPLTR, -w_box_type = space.gettypefor(uintp_box), +w_box_type = space.gettypefor(interp_boxes.W_ULongBox), ) float_dtypes = [self.w_float16dtype, self.w_float32dtype, self.w_float64dtype, self.w_floatlongdtype] 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 @@ -715,10 +715,14 @@ assert numpy.int16 is numpy.short assert numpy.int8 is numpy.byte assert numpy.bool_ is numpy.bool8 +assert numpy.intp().dtype.num == 7 +assert numpy.intp().dtype.char == 'l' if self.ptr_size == 4: +assert numpy.intp().dtype.name == 'int32' assert numpy.intp is numpy.int32 assert numpy.uintp is numpy.uint32 elif self.ptr_size == 8: +assert numpy.intp().dtype.name == 'int64' assert numpy.intp is numpy.int64 assert numpy.uintp is numpy.uint64 @@ -787,8 +791,22 @@ def test_intp(self): from numpypy import dtype -assert dtype('p') == dtype('intp') -assert dtype('P') == dtype('uintp') +assert dtype('p') is dtype('intp') +assert dtype('P') is dtype('uintp') +#assert dtype('p') is dtype('int') +#assert dtype('P') is dtype('uint') +assert dtype('p').num == 7 +assert dtype('P').num == 8 +#assert dtype('p').char == 'l' +#assert dtype('P').char == 'L' +assert dtype('p').kind == 'i' +assert dtype('P').kind == 'u' +#if self.ptr_size == 4: +#assert dtype('p').name == 'int32' +#assert dtype('P').name == 'uint32' +#else: +#assert dtype('p').name == 'int64' +#assert dtype('P').name == 'uint64' def test_alignment(self): from numpypy import dtype ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: test typeinfo of intp also
Author: Brian Kearns bdkea...@gmail.com Branch: Changeset: r68495:b91626777307 Date: 2013-12-19 17:22 -0500 http://bitbucket.org/pypy/pypy/changeset/b91626777307/ Log:test typeinfo of intp also 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 @@ -33,6 +33,10 @@ assert typeinfo['CFLOAT'] == ('F', 14, 64, 8, np.complex64) assert typeinfo['CDOUBLE'] == ('D', 15, 128, 16, np.complex128) assert typeinfo['HALF'] == ('e', 23, 16, 2, np.float16) +assert typeinfo['INTP'] == ('p', 7, 64, 8, +2**(self.ptr_size*8 - 1) - 1, +-2**(self.ptr_size*8 - 1), +np.int64) def test_dtype_basic(self): from numpypy import dtype ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: for 32bit also
Author: Brian Kearns bdkea...@gmail.com Branch: Changeset: r68496:808bd00c35ee Date: 2013-12-19 17:24 -0500 http://bitbucket.org/pypy/pypy/changeset/808bd00c35ee/ Log:for 32bit also 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 @@ -33,10 +33,11 @@ assert typeinfo['CFLOAT'] == ('F', 14, 64, 8, np.complex64) assert typeinfo['CDOUBLE'] == ('D', 15, 128, 16, np.complex128) assert typeinfo['HALF'] == ('e', 23, 16, 2, np.float16) -assert typeinfo['INTP'] == ('p', 7, 64, 8, +assert typeinfo['INTP'] == ('p', np.dtype('int').num, +self.ptr_size*8, self.ptr_size, 2**(self.ptr_size*8 - 1) - 1, -2**(self.ptr_size*8 - 1), -np.int64) +np.dtype('int').type) def test_dtype_basic(self): from numpypy import dtype ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: cleanup
Author: Brian Kearns bdkea...@gmail.com Branch: Changeset: r68497:df40c2b6928d Date: 2013-12-19 17:36 -0500 http://bitbucket.org/pypy/pypy/changeset/df40c2b6928d/ Log:cleanup 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 @@ -478,8 +478,7 @@ assert numpy.int16('32768') == -32768 def test_uint16(self): -import numpypy as numpy - +import numpy assert numpy.uint16(65535) == 65535 assert numpy.uint16(65536) == 0 assert numpy.uint16('65535') == 65535 @@ -487,8 +486,7 @@ def test_int32(self): import sys -import numpypy as numpy - +import numpy x = numpy.int32(23) assert x == 23 assert numpy.int32(2147483647) == 2147483647 @@ -503,10 +501,8 @@ def test_uint32(self): import sys -import numpypy as numpy - +import numpy assert numpy.uint32(10) == 10 - if sys.maxint 2 ** 31 - 1: assert numpy.uint32(4294967295) == 4294967295 assert numpy.uint32(4294967296) == 0 @@ -523,8 +519,7 @@ def test_int64(self): import sys -import numpypy as numpy - +import numpy if sys.maxint == 2 ** 63 -1: assert numpy.int64.mro() == [numpy.int64, numpy.signedinteger, numpy.integer, numpy.number, @@ -539,30 +534,30 @@ assert numpy.int64(9223372036854775807) == 9223372036854775807 assert numpy.int64(9223372036854775807) == 9223372036854775807 - raises(OverflowError, numpy.int64, 9223372036854775808) raises(OverflowError, numpy.int64, 9223372036854775808L) def test_uint64(self): -import sys -import numpypy as numpy - +import numpy +assert numpy.dtype(numpy.uint64).type is numpy.uint64 assert numpy.uint64.mro() == [numpy.uint64, numpy.unsignedinteger, numpy.integer, numpy.number, numpy.generic, object] - -assert numpy.dtype(numpy.uint64).type is numpy.uint64 -skip(see comment) -# These tests pass by chance on numpy, things that are larger than -# platform long (i.e. a python int), don't get put in a normal box, -# instead they become an object array containing a long, we don't have -# yet, so these can't pass. -assert numpy.uint64(9223372036854775808) == 9223372036854775808 -assert numpy.uint64(18446744073709551615) == 18446744073709551615 -raises(OverflowError, numpy.uint64(18446744073709551616)) +import sys +if '__pypy__' not in sys.builtin_module_names: +# These tests pass by chance on numpy, things that are larger than +# platform long (i.e. a python int), don't get put in a normal box, +# instead they become an object array containing a long, we don't have +# yet, so these can't pass. +assert numpy.uint64(9223372036854775808) == 9223372036854775808 +assert numpy.uint64(18446744073709551615) == 18446744073709551615 +else: +raises(OverflowError, numpy.int64, 9223372036854775808) +raises(OverflowError, numpy.int64, 18446744073709551615) +raises(OverflowError, numpy.uint64, 18446744073709551616) def test_float16(self): -import numpypy as numpy +import numpy assert numpy.float16.mro() == [numpy.float16, numpy.floating, numpy.inexact, numpy.number, numpy.generic, object] @@ -573,8 +568,7 @@ def test_float32(self): -import numpypy as numpy - +import numpy assert numpy.float32.mro() == [numpy.float32, numpy.floating, numpy.inexact, numpy.number, numpy.generic, object] @@ -584,8 +578,7 @@ raises(ValueError, numpy.float32, '23.2df') def test_float64(self): -import numpypy as numpy - +import numpy assert numpy.float64.mro() == [numpy.float64, numpy.floating, numpy.inexact, numpy.number, numpy.generic, float, object] @@ -601,14 +594,14 @@ raises(ValueError, numpy.float64, '23.2df') def test_float_None(self): -import numpypy as numpy +import numpy from math import isnan assert isnan(numpy.float32(None)) assert isnan(numpy.float64(None)) assert isnan(numpy.longdouble(None)) def test_longfloat(self): -import numpypy as numpy +import numpy # it can be float96 or float128 if numpy.longfloat != numpy.float64:
[pypy-commit] pypy default: cleanup
Author: Brian Kearns bdkea...@gmail.com Branch: Changeset: r68498:4e4d5daef8fe Date: 2013-12-19 18:17 -0500 http://bitbucket.org/pypy/pypy/changeset/4e4d5daef8fe/ Log:cleanup 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 @@ -2978,17 +2978,18 @@ assert j[0] == 12 k = fromstring(self.float16val, dtype='float16') assert k[0] == dtype('float16').type(5.) -dt = array([5],dtype='longfloat').dtype -if dt.itemsize == 12: +dt = array([5], dtype='longfloat').dtype +if dt.itemsize == 8: +m = fromstring('\x00\x00\x00\x00\x00\x00\x14@', + dtype='float64') +elif dt.itemsize == 12: m = fromstring('\x00\x00\x00\x00\x00\x00\x00\xa0\x01@\x00\x00', dtype='float96') elif dt.itemsize == 16: m = fromstring('\x00\x00\x00\x00\x00\x00\x00\xa0\x01@\x00\x00' \ '\x00\x00\x00\x00', dtype='float128') -elif dt.itemsize == 8: -skip('longfloat is float64') else: -skip('unknown itemsize for longfloat') +assert False, 'unknown itemsize for longfloat' assert m[0] == dtype('longfloat').type(5.) def test_fromstring_invalid(self): @@ -3311,14 +3312,16 @@ a = array([('', 1.0, 8.0, [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])], dtype=dt) -s = str(a) i = a.item() assert isinstance(i, tuple) assert len(i) == 4 -skip('incorrect formatting via dump_data') -assert s.endswith([('', 1.0, 8.0, [[[1, 2, 3], [4, 5, 6]], - [[7, 8, 9], [10, 11, 12]]])]) - +import sys +if '__pypy__' not in sys.builtin_module_names: +assert str(a) == [('', 1.0, 8.0, [[[1, 2, 3], [4, 5, 6]], \ + [[7, 8, 9], [10, 11, 12]]])] +else: +assert str(a) == array([('', 1.0, 8.0, [1, 2, 3, 4, 5, 6, \ +7, 8, 9, 10, 11, 12])]) def test_issue_1589(self): import numpypy as numpy 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 @@ -390,23 +390,17 @@ assert (a == ref).all() def test_signbit(self): -from numpypy import signbit, add - +from numpy import signbit, add +assert signbit(add.identity) == False assert (signbit([0, 0.0, 1, 1.0, float('inf')]) == -[False, False, False, False, False]).all() +[False, False, False, False, False]).all() assert (signbit([-0, -0.0, -1, -1.0, float('-inf')]) == -[False, True, True, True, True]).all() - -a = add.identity -assert signbit(a) == False - -skip('sign of nan is non-determinant') +[False, True, True, True, True]).all() assert (signbit([float('nan'), float('-nan'), -float('nan')]) == -[False, True, True]).all() +[False, True, True]).all() def test_reciprocal(self): -from numpypy import array, reciprocal - +from numpy import array, reciprocal inf = float('inf') nan = float('nan') reference = [-0.2, inf, -inf, 2.0, nan] ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: remove bogus test (testing uninitialized memory)
Author: Brian Kearns bdkea...@gmail.com Branch: Changeset: r68499:11541c9f799a Date: 2013-12-19 18:42 -0500 http://bitbucket.org/pypy/pypy/changeset/11541c9f799a/ Log:remove bogus test (testing uninitialized memory) 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 @@ -217,6 +217,7 @@ assert get(1, 0) == 2 assert get(1, 1) == 3 + class AppTestNumArray(BaseNumpyAppTest): spaceconfig = dict(usemodules=[micronumpy, struct, binascii]) @@ -2185,12 +2186,6 @@ a[b] = 1. assert (a == [[1., 1., 1.]]).all() -@py.test.mark.xfail -def test_boolean_array(self): -import numpypy as np -a = np.ndarray([1], dtype=bool) -assert a[0] == True - class AppTestNumArrayFromBuffer(BaseNumpyAppTest): spaceconfig = dict(usemodules=[micronumpy, array, mmap]) @@ -2253,7 +2248,6 @@ f.close() - class AppTestMultiDim(BaseNumpyAppTest): def test_init(self): import numpypy @@ -3334,6 +3328,7 @@ a = np.array([1,2,3], dtype='int16') assert (a * 2).dtype == np.dtype('int16') + class AppTestPyPy(BaseNumpyAppTest): def setup_class(cls): if option.runappdirect and '__pypy__' not in sys.builtin_module_names: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix ndarray.take with axis argument
Author: Brian Kearns bdkea...@gmail.com Branch: Changeset: r68500:aca7d2177494 Date: 2013-12-19 18:37 -0500 http://bitbucket.org/pypy/pypy/changeset/aca7d2177494/ Log:fix ndarray.take with axis argument 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 @@ -1187,10 +1187,11 @@ if axis is None: res = a.ravel()[indices] else: +from operator import mul if axis 0: axis += len(a.shape) s0, s1 = a.shape[:axis], a.shape[axis+1:] -l0 = prod(s0) if s0 else 1 -l1 = prod(s1) if s1 else 1 +l0 = reduce(mul, s0) if s0 else 1 +l1 = reduce(mul, s1) if s1 else 1 res = a.reshape((l0, -1, l1))[:,indices,:].reshape(s0 + (-1,) + s1) if out is not None: out[:] = res 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 @@ -2722,6 +2722,8 @@ raises(IndexError, arange(3).take([15])) a = arange(6).reshape(2, 3) assert (a.take([1, 0, 3]) == [1, 0, 3]).all() +assert (a.take([1], axis=0) == [[3, 4, 5]]).all() +assert (a.take([1], axis=1) == [[1], [4]]).all() assert ((a + a).take([3]) == [6]).all() a = arange(12).reshape(2, 6) assert (a[:,::2].take([3, 2, 1]) == [6, 4, 2]).all() ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: this test works now
Author: Brian Kearns bdkea...@gmail.com Branch: Changeset: r68501:13ac2969a2eb Date: 2013-12-19 19:11 -0500 http://bitbucket.org/pypy/pypy/changeset/13ac2969a2eb/ Log:this test works now diff --git a/pypy/module/micronumpy/test/test_sorting.py b/pypy/module/micronumpy/test/test_sorting.py --- a/pypy/module/micronumpy/test/test_sorting.py +++ b/pypy/module/micronumpy/test/test_sorting.py @@ -306,9 +306,8 @@ # tests from numpy/core/tests/test_regression.py def test_sort_bigendian(self): -skip('not implemented yet') -from numpypy import array, dtype -a = array(range(11),dtype='float64') +from numpy import array, dtype +a = array(range(11), dtype='float64') c = a.astype(dtype('f8')) c.sort() assert max(abs(a-c)) 1e-32 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix test on 32bit
Author: Brian Kearns bdkea...@gmail.com Branch: Changeset: r68502:1fa0a9d16200 Date: 2013-12-19 19:29 -0500 http://bitbucket.org/pypy/pypy/changeset/1fa0a9d16200/ Log:fix test on 32bit 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 @@ -114,15 +114,11 @@ assert dtype(bool).num == 0 if self.ptr_size == 4: -assert dtype('intp').num == 5 -assert dtype('uintp').num == 6 assert dtype('int32').num == 7 assert dtype('uint32').num == 8 assert dtype('int64').num == 9 assert dtype('uint64').num == 10 else: -assert dtype('intp').num == 7 -assert dtype('uintp').num == 8 assert dtype('int32').num == 5 assert dtype('uint32').num == 6 assert dtype('int64').num == 7 @@ -130,6 +126,8 @@ assert dtype(int).num == 7 assert dtype('int').num == 7 assert dtype('uint').num == 8 +assert dtype('intp').num == 7 +assert dtype('uintp').num == 8 assert dtype(long).num == 9 assert dtype(float).num == 12 assert dtype('float').num == 12 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: add ufunc.__name__ property
Author: Brian Kearns bdkea...@gmail.com Branch: Changeset: r68503:91105b7ff82b Date: 2013-12-19 20:03 -0500 http://bitbucket.org/pypy/pypy/changeset/91105b7ff82b/ Log:add ufunc.__name__ property 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 @@ -33,6 +33,9 @@ self.allow_complex = allow_complex self.complex_to_float = complex_to_float +def descr_get_name(self, space): +return space.wrap(self.name) + def descr_repr(self, space): return space.wrap(ufunc '%s' % self.name) @@ -417,6 +420,7 @@ __call__ = interp2app(W_Ufunc.descr_call), __repr__ = interp2app(W_Ufunc.descr_repr), +__name__ = GetSetProperty(W_Ufunc.descr_get_name), identity = GetSetProperty(W_Ufunc.descr_get_identity), accumulate = interp2app(W_Ufunc.descr_accumulate), 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 @@ -82,6 +82,7 @@ assert isinstance(add, ufunc) assert repr(add) == ufunc 'add' assert repr(ufunc) == type 'numpy.ufunc' +assert add.__name__ == 'add' def test_ufunc_attrs(self): from numpypy import add, multiply, sin ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: implement dtype.descr for record types
Author: Brian Kearns bdkea...@gmail.com Branch: Changeset: r68504:7a6f7ca7c635 Date: 2013-12-19 22:23 -0500 http://bitbucket.org/pypy/pypy/changeset/7a6f7ca7c635/ Log:implement dtype.descr for record types diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py --- a/pypy/module/micronumpy/interp_dtype.py +++ b/pypy/module/micronumpy/interp_dtype.py @@ -157,8 +157,20 @@ return space.newlist([space.newtuple([space.wrap(), self.descr_get_str(space)])]) else: -raise OperationError(space.w_NotImplementedError, space.wrap( -descr not implemented for record types)) +descr = [] +for name in self.fieldnames: +subdtype = self.fields[name][1] +subdescr = [space.wrap(name)] +if subdtype.is_record_type(): +subdescr.append(subdtype.descr_get_descr(space)) +elif subdtype.subdtype is not None: +subdescr.append(subdtype.subdtype.descr_get_str(space)) +else: +subdescr.append(subdtype.descr_get_str(space)) +if subdtype.shape != []: +subdescr.append(subdtype.descr_get_shape(space)) +descr.append(space.newtuple(subdescr)) +return space.newlist(descr) def descr_get_base(self, space): return space.wrap(self.base) 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 @@ -849,12 +849,12 @@ import numpy as np assert np.dtype('i8').descr == [('', 'i8')] assert np.dtype('|S4').descr == [('', '|S4')] +assert np.dtype(('i8', (5,))).descr == [('', '|V40')] d = [('test', 'i8'), ('blah', 'i2', (2, 3))] -import sys -if '__pypy__' in sys.builtin_module_names: -raises(NotImplementedError, np.dtype(d).descr) -else: -assert np.dtype(d).descr == d +assert np.dtype(d).descr == d +a = [('x', 'i8'), ('y', 'f8')] +b = [('x', 'i4'), ('y', a)] +assert np.dtype(b).descr == b class AppTestStrUnicodeDtypes(BaseNumpyAppTest): def test_mro(self): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix translation (odd?)
Author: Brian Kearns bdkea...@gmail.com Branch: Changeset: r68505:70c1284ebcc9 Date: 2013-12-19 22:57 -0500 http://bitbucket.org/pypy/pypy/changeset/70c1284ebcc9/ Log:fix translation (odd?) diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py --- a/pypy/module/micronumpy/interp_dtype.py +++ b/pypy/module/micronumpy/interp_dtype.py @@ -169,7 +169,7 @@ subdescr.append(subdtype.descr_get_str(space)) if subdtype.shape != []: subdescr.append(subdtype.descr_get_shape(space)) -descr.append(space.newtuple(subdescr)) +descr.append(space.newtuple(subdescr[:])) return space.newlist(descr) def descr_get_base(self, space): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: fix dtype creation from some abstract numpy types
Author: Brian Kearns bdkea...@gmail.com Branch: Changeset: r68506:7126a9a7a21e Date: 2013-12-19 23:41 -0500 http://bitbucket.org/pypy/pypy/changeset/7126a9a7a21e/ Log:fix dtype creation from some abstract numpy types diff --git a/pypy/module/micronumpy/interp_dtype.py b/pypy/module/micronumpy/interp_dtype.py --- a/pypy/module/micronumpy/interp_dtype.py +++ b/pypy/module/micronumpy/interp_dtype.py @@ -662,6 +662,7 @@ w_box_type = space.gettypefor(interp_boxes.W_Float64Box), alternate_constructors=[space.w_float, space.gettypefor(interp_boxes.W_NumberBox), + space.gettypefor(interp_boxes.W_FloatingBox), ], aliases=[float, double], ) @@ -691,7 +692,8 @@ name=complex128, char=NPY_CDOUBLELTR, w_box_type = space.gettypefor(interp_boxes.W_Complex128Box), -alternate_constructors=[space.w_complex], +alternate_constructors=[space.w_complex, + space.gettypefor(interp_boxes.W_ComplexFloatingBox)], aliases=[complex, 'cfloat', 'cdouble'], float_type = self.w_float64dtype, ) @@ -713,7 +715,8 @@ name='string', char=NPY_STRINGLTR, w_box_type = space.gettypefor(interp_boxes.W_StringBox), -alternate_constructors=[space.w_str, space.gettypefor(interp_boxes.W_CharacterBox)], +alternate_constructors=[space.w_str, + space.gettypefor(interp_boxes.W_CharacterBox)], aliases=[str], ) self.w_unicodedtype = W_Dtype( 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 @@ -369,16 +369,22 @@ # numpy allows abstract types in array creation a_n = numpy.array([4,4], numpy.number) +a_f = numpy.array([4,4], numpy.floating) +a_c = numpy.array([4,4], numpy.complexfloating) a_i = numpy.array([4,4], numpy.integer) a_s = numpy.array([4,4], numpy.signedinteger) a_u = numpy.array([4,4], numpy.unsignedinteger) assert a_n.dtype.num == 12 +assert a_f.dtype.num == 12 +assert a_c.dtype.num == 15 assert a_i.dtype.num == 7 assert a_s.dtype.num == 7 assert a_u.dtype.num == 8 assert a_n.dtype is numpy.dtype('float64') +assert a_f.dtype is numpy.dtype('float64') +assert a_c.dtype is numpy.dtype('complex128') if self.ptr_size == 4: assert a_i.dtype is numpy.dtype('int32') assert a_s.dtype is numpy.dtype('int32') ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit