Re: [Numpy-discussion] Implementing hashing protocol for dtypes
2009/3/12 David Cournapeau courn...@gmail.com: Sorry, the link is http://codereview.appspot.com/26052/show I've tried the patch, and it works well! Bonus marks for all the useful comments and tests! I am +1. Cheers Stéfan ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Implementing hashing protocol for dtypes
On Thu, Mar 12, 2009 at 9:13 PM, David Cournapeau courn...@gmail.com wrote: On Thu, Mar 12, 2009 at 1:00 PM, Robert Kern robert.k...@gmail.com wrote: It was an example. Ok, guess I will have to learn the difference between i.e. and e.g. one day. Anyway, here is a first shot at it: http://codereview.appspot.com/26052 Sorry, the link is http://codereview.appspot.com/26052/show David ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Implementing hashing protocol for dtypes
On Thu, Mar 12, 2009 at 1:00 PM, Robert Kern robert.k...@gmail.com wrote: It was an example. Ok, guess I will have to learn the difference between i.e. and e.g. one day. Anyway, here is a first shot at it: http://codereview.appspot.com/26052 I added a few tests which fail with trunk and work with the patch (for example, two equivalent types now hash the same), only tested on Linux so far. I am not sure I took into account every case: I am not familiar with the PyArray_Descr API (this patch was a good excuse to dive into this part of the code), and I also noticed a few discrepancies with the doc (the fields struct member never seems to be NULL, but set to None for builtin types). cheers, David ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Implementing hashing protocol for dtypes
2009/3/12 David Cournapeau courn...@gmail.com: Anyway, here is a first shot at it: http://codereview.appspot.com/26052 Design question: should [('x', float), ('y', float)] and [('t', float), ('s', float)] hash to the same value or not? Regards Stéfan ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Implementing hashing protocol for dtypes
Stéfan van der Walt wrote: 2009/3/12 David Cournapeau courn...@gmail.com: Anyway, here is a first shot at it: http://codereview.appspot.com/26052 Design question: should [('x', float), ('y', float)] and [('t', float), ('s', float)] hash to the same value or not? According to: http://docs.python.org/reference/datamodel.html#object.__hash__ The only constraint is that a == b - hash(a) == hash(b) (which is broken currently in numpy, even for builtin dtypes). The main problem is that I am not very clear yet on what a == b is for dtypes (the code for PyArray_EquivTypes goes through PyObject_Compare for compound types). In your example, both dtypes are not equal (and they do not hash the same). cheers, David ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Implementing hashing protocol for dtypes
On Wed, Mar 11, 2009 at 15:06, David Cournapeau courn...@gmail.com wrote: Hi, I was looking at #936, to implement correctly the hashing protocol for dtypes. Am I right to believe that tp_hash should recursively descend fields for compound dtypes, and the hash value should depend on the size/ndim/typenum/byteorder for each atomic dtype + fields name (and titles) ? Contrary to comparison, we can't reuse the python C api, since PyObject_Hash cannot be applied to the fields dict, right ? Usually, one constructs a hashable analogue; e.g. taking the .descr and converting all of the lists to tuples. Then use PyObject_Hash on that. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Implementing hashing protocol for dtypes
On Thu, Mar 12, 2009 at 5:36 AM, Robert Kern robert.k...@gmail.com wrote: On Wed, Mar 11, 2009 at 15:06, David Cournapeau courn...@gmail.com wrote: Hi, I was looking at #936, to implement correctly the hashing protocol for dtypes. Am I right to believe that tp_hash should recursively descend fields for compound dtypes, and the hash value should depend on the size/ndim/typenum/byteorder for each atomic dtype + fields name (and titles) ? Contrary to comparison, we can't reuse the python C api, since PyObject_Hash cannot be applied to the fields dict, right ? Usually, one constructs a hashable analogue; e.g. taking the .descr and converting all of the lists to tuples. Then use PyObject_Hash on that. Is the .descr of two dtypes guaranteed to be equal whenever the dtypes are equal ? It is not obvious to me that PyArray_EquivTypes is equivalent to comparing the descr ? David ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Implementing hashing protocol for dtypes
On Wed, Mar 11, 2009 at 22:49, David Cournapeau courn...@gmail.com wrote: On Thu, Mar 12, 2009 at 5:36 AM, Robert Kern robert.k...@gmail.com wrote: On Wed, Mar 11, 2009 at 15:06, David Cournapeau courn...@gmail.com wrote: Hi, I was looking at #936, to implement correctly the hashing protocol for dtypes. Am I right to believe that tp_hash should recursively descend fields for compound dtypes, and the hash value should depend on the size/ndim/typenum/byteorder for each atomic dtype + fields name (and titles) ? Contrary to comparison, we can't reuse the python C api, since PyObject_Hash cannot be applied to the fields dict, right ? Usually, one constructs a hashable analogue; e.g. taking the .descr and converting all of the lists to tuples. Then use PyObject_Hash on that. Is the .descr of two dtypes guaranteed to be equal whenever the dtypes are equal ? It is not obvious to me that PyArray_EquivTypes is equivalent to comparing the descr ? It was an example. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion