[issue15573] Support unknown formats in memoryview comparisons

Martin v. Löwis report at bugs.python.org
Sat Aug 11 22:28:23 CEST 2012


Martin v. Löwis added the comment:

Am 11.08.12 21:59, schrieb Antoine Pitrou:
> Le samedi 11 août 2012 à 19:52 +0000, Nick Coghlan a écrit :
>> I'd be happier if the compare-by-value didn't make complete copies of
>> the entire array though.
>
> Ditto. If a and b are bytes objects, comparing memoryview(a) and
> memoryview(b) should be as cheap as comparing a and b.

I agree with Antoine's requirement, generalizing it to "the simple
cases should be efficient". I wonder why the procedure couldn't instead
be

1. compare shapes
2. if the format strings are string-equal, compare the
    memory representation
3. else unpack values

Then, comparing two 1D 'B' memoryviews would be a memcmp
(i.e. it wouldn't do compare-by-value in this case).

For unpacking, I don't see any way to have it efficient
and still maintainable, since mixed-type comparisons
are quite tedious to write in C, and really best done with
type normalization and multiple dispatch in the way that
unpacking will do it.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15573>
_______________________________________


More information about the Python-bugs-list mailing list