numpy/numpy — pull request #2938 by raulcota (2013-01-21 23:36:29+00:00)
Title: Avoid calls that result on Python exceptions.

After profiling numpy I found out bottlenecks when doing calls that
result in Python internally raising an error
e.g.
PyObject_GetAttrString(obj, "__array_priority__")
when __array_priority__ is not an attribute of obj

The changes are in general,
- avoid calls to PyObject_GetAttrString when I know the type is
List, None, Tuple, Float, Int, String or Unicode

- avoid calls to PyObject_GetBuffer when I know the type is
List, None or Tuple

Using Windows Python 2.6, the changes resulted in the following speed up,
RATIO	TEST
1)	1.1	Array * Array
2)	1.1	PyFloat * Array
3)	1.1	Float64 * Array
4)	1.1	PyFloat + Array
5)	1.2	Float64 + Array
6)	1.0	PyFloat * PyFloat
7)	1.7	Float64 * Float64
8)	2.8	PyFloat * Float64
9)	2.1	PyFloat * vector1[1]
10)	2.8	PyFloat + Float64
11)	3.3	PyFloat < Float64
12)	3.3	if PyFloat < Float64:
13)	3.2	Create array from list
14)	1.2	Assign PyFloat to all
15)	1.2	Assign Float64 to all
16)	2.9	Float64 * pyFloat * pyFloat * pyFloat * pyFloat

where RATIO is defined as the time it took to run before the changes divided by the time it too to run after the changes. The bigger the ratio, the bigger the speedup.