A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-March/062885.html below:

[Python-Dev] INPLACE_ADD and INPLACE_MULTIPLY oddities in ceval.c

[Python-Dev] INPLACE_ADD and INPLACE_MULTIPLY oddities in ceval.cTravis Oliphant oliphant.travis at ieee.org
Tue Mar 28 03:08:00 CEST 2006
If you have Numeric or numpy installed try this:

#import Numeric as N
import numpy as N

a = range(10)
b = N.arange(10)

a.__iadd__(b)

print a

Result:

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]


Contrast the returned output with

import numpy as N

a = range(10)
b = N.arange(10)

a += b

print a

Result:

[ 0  2  4  6  8 10 12 14 16 18]


Having "a+=b" and "a.__iadd__(b)" do different things seems like an 
unfortunate bug.

It seems to me that the problem is that the INPLACE_ADD and 
INPLACE_MULTIPLY cases in ceval.c  use PyNumber_InPlace<YYY> instead of 
trying PySequence_InPlace<YYY> when the object doesn't support the 
in-place number protocol.

I could submit a patch if there is agreement that this is a problem.

-Travis









More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4