On Fri, Oct 10, 2008 at 4:28 AM, Aaron DeVore <[EMAIL PROTECTED]> wrote:
> Tragically, I can't show my implementation of __eq__. However, I will
> say this: I absolutely cannot change __eq__ to work with identities.

Then have you tried to make __eq__ strict about types, and do something like:

cdef MyClass:
  def __richcmp__(self, other, int op):
     if not isinstance(self, MyClass): return NotImplemented
     if not isinstance(other, MyClass): return NotImplemented
     # and now impement the rest:
     if op == 2: # eq
         return True if condition else False
     elif op == 3: #ne
         # like above
     else:
          raise TypeError # only == and !=

>
> For a relatively short list (usually 0-20 items, sometimes up to 1000)
> would this work and still be blindingly fast? "----" indicates
> indentation.:
>
> int index
> for index from 0 <= index < len(a_list):
> ----if a_list[index] is my_type_instance:
> --------break
>
> Or would I need to do this to get correct behavior:
> int index
> for index from 0 <= index < len(a_list):
> ----if id(a_list[index]) == id(my_type_instance):
> --------break
>
> 2008/10/9 Lisandro Dalcin <[EMAIL PROTECTED]>:
>> On Wed, Oct 8, 2008 at 4:15 PM, Aaron DeVore <[EMAIL PROTECTED]> wrote:
>>> I have a my_type.__eq__
>>> function but it doesn't give the correct behavior. Which behavior does
>>> Cython use?
>>
>> Could you show us the way you implemented your __eq__ method?
>>
>>
>>
>> --
>> Lisandro Dalcín
>> ---------------
>> Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
>> Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
>> Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
>> PTLC - Güemes 3450, (3000) Santa Fe, Argentina
>> Tel/Fax: +54-(0)342-451.1594
>> _______________________________________________
>> Cython-dev mailing list
>> [email protected]
>> http://codespeak.net/mailman/listinfo/cython-dev
>>
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>



-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to