
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2013-09-23 16:27 byClaudiu.Popa, last changed2022-04-11 14:57 byadmin. This issue is nowclosed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| memoryview.patch | Claudiu.Popa,2013-09-23 16:27 | review | ||
| Messages (12) | |||
|---|---|---|---|
| msg198324 -(view) | Author: PCManticore (Claudiu.Popa)*![]() | Date: 2013-09-23 16:27 | |
Hello. The following seems a little weird:Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32>>> m = memoryview(b'123')>>> list(m[::-1])[51, 50, 49]>>> list(reversed(m))Traceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: object of type 'memoryview' has no len()>>>The attached patch allows `reversed` to be called with memoryviews and it could potentially fixissue18690. | |||
| msg198342 -(view) | Author: Antoine Pitrou (pitrou)*![]() | Date: 2013-09-23 20:52 | |
So the dilemma with len() was: does it return the number of bytes, or the number of items?Given the new memoryview semantics, I'd say it should return the number of items. | |||
| msg198348 -(view) | Author: Alyssa Coghlan (ncoghlan)*![]() | Date: 2013-09-23 23:08 | |
Aye, with the 3.3 changes, I think we should continue down themulti-dimensional array path. I suggest we run with whatever NumPy uses forndarray, which I believe is "number of items in the first dimension". | |||
| msg198383 -(view) | Author: PCManticore (Claudiu.Popa)*![]() | Date: 2013-09-25 13:06 | |
So, in the following case, len shouldn't return 4, but the number of items? Also, is it ok to assume that the number of items is((*shape)[0] * ... * (*shape)[ndims-1])?>>> x = np.array([[1, 2, 3], [4, 5, 6], [4,5,6], [4,4,4]], np.int32)>>> x.shape(4, 3)>>> x.shape[0] * x.shape[1]12>>> len(x)4>>> memoryview(x)<memory at 0x0217C378>>>> len(memoryview(x))4>>> memoryview(x).shape(4, 3)>>> | |||
| msg198384 -(view) | Author: Antoine Pitrou (pitrou)*![]() | Date: 2013-09-25 13:46 | |
No, you're right, it should probably return 4. | |||
| msg198516 -(view) | Author: Stefan Krah (skrah)*![]() | Date: 2013-09-28 14:28 | |
Yes, len() should return the number of items. +1 for making reversed()work.NumPy does this:>>> x = numpy.array([1,2,3,4,5,6,7,8])>>> list(reversed(x))[8, 7, 6, 5, 4, 3, 2, 1]>>>>>> x = numpy.array([[1,2,3], [4,5,6]])>>> list(reversed(x))[array([4, 5, 6]), array([1, 2, 3])]>>> | |||
| msg198518 -(view) | Author: Stefan Krah (skrah)*![]() | Date: 2013-09-28 14:30 | |
Hmm, I meant: Number of items in the first dimension, thus 4 inClaudiu's example. | |||
| msg198566 -(view) | Author: PCManticore (Claudiu.Popa)*![]() | Date: 2013-09-29 06:22 | |
For multidimensional arrays it doesn't seem to work (yet).>>> x = numpy.array([[1,2,3], [4,5,6]])>>> list(reversed(x))[array([4, 5, 6]), array([1, 2, 3])]>>> x.data<memory at 0x8032d06b8>>>> list(reversed(x.data))Traceback (most recent call last): File "<stdin>", line 1, in <module>NotImplementedError: multi-dimensional sub-views are not implemented>>> | |||
| msg198612 -(view) | Author: Antoine Pitrou (pitrou)*![]() | Date: 2013-09-29 17:28 | |
Stefan, what do you think about Claudiu's patch? Should a test be added to test_buffer as well? | |||
| msg198680 -(view) | Author: Raymond Hettinger (rhettinger)*![]() | Date: 2013-09-30 06:28 | |
Claudiu's patch looks correct. | |||
| msg198824 -(view) | Author: Stefan Krah (skrah)*![]() | Date: 2013-10-02 10:30 | |
> Stefan, what do you think about Claudiu's patch? Should a test be added to test_buffer as well?I think the patch is good. We can add more tests when (if?) multi-dimensionalsupport is added to memoryview.In that case we should probably do the same as NumPy and return a list ofsubviews. So testing against tolist() like in the test case will only workfor one-dimensional views.I can't commit right now (the machine with my ssh-key won't have Internetaccess for some time), so if someone has time to do it ... | |||
| msg198829 -(view) | Author: Roundup Robot (python-dev)![]() | Date: 2013-10-02 12:07 | |
New changeset0dc604d58949 by Nick Coghlan in branch 'default':Close#19078: memoryview now supports reversedhttp://hg.python.org/cpython/rev/0dc604d58949 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:57:51 | admin | set | github: 63278 |
| 2013-10-02 12:07:06 | python-dev | set | status: open -> closed nosy: +python-dev messages: +msg198829 resolution: fixed stage: patch review -> resolved |
| 2013-10-02 12:00:50 | ncoghlan | set | assignee:ncoghlan |
| 2013-10-02 10:30:27 | skrah | set | messages: +msg198824 |
| 2013-09-30 06:28:23 | rhettinger | set | nosy: +rhettinger messages: +msg198680 |
| 2013-09-29 17:28:01 | pitrou | set | messages: +msg198612 |
| 2013-09-29 06:22:21 | Claudiu.Popa | set | messages: +msg198566 |
| 2013-09-28 20:52:59 | terry.reedy | set | type: behavior -> enhancement stage: patch review |
| 2013-09-28 14:30:09 | skrah | set | messages: +msg198518 |
| 2013-09-28 14:28:27 | skrah | set | messages: +msg198516 |
| 2013-09-25 13:46:43 | pitrou | set | messages: +msg198384 |
| 2013-09-25 13:06:26 | Claudiu.Popa | set | messages: +msg198383 |
| 2013-09-23 23:08:42 | ncoghlan | set | messages: +msg198348 title: Allow reversed(memoryview), like memoryview[::-1] -> Allow reversed(memoryview), like memoryview |
| 2013-09-23 20:52:18 | pitrou | set | nosy: +ncoghlan,skrah messages: +msg198342 |
| 2013-09-23 16:32:33 | serhiy.storchaka | set | nosy: +pitrou |
| 2013-09-23 16:27:16 | Claudiu.Popa | create | |