NumPy 1.4.0 Release Notes#
This minor includes numerous bug fixes, as well as a few new features. Itis backward compatible with 1.3.0 release.
Highlights#
New datetime dtype support to deal with dates in arrays
Faster import time
Extended array wrapping mechanism for ufuncs
New Neighborhood iterator (C-level only)
C99-like complex functions in npymath
New features#
Extended array wrapping mechanism for ufuncs#
An __array_prepare__ method has been added to ndarray to provide subclassesgreater flexibility to interact with ufuncs and ufunc-like functions. ndarrayalready provided __array_wrap__, which allowed subclasses to set the array typefor the result and populate metadata on the way out of the ufunc (as seen inthe implementation of MaskedArray). For some applications it is necessary toprovide checks and populate metadataon the way in. __array_prepare__ istherefore called just after the ufunc has initialized the output array butbefore computing the results and populating it. This way, checks can be madeand errors raised before operations which may modify data in place.
Automatic detection of forward incompatibilities#
Previously, if an extension was built against a version N of NumPy, and used ona system with NumPy M < N, the import_array was successful, which could causecrashes because the version M does not have a function in N. Starting fromNumPy 1.4.0, this will cause a failure in import_array, so the error will becaught early on.
New iterators#
A new neighborhood iterator has been added to the C API. It can be used toiterate over the items in a neighborhood of an array, and can handle boundariesconditions automatically. Zero and one padding are available, as well asarbitrary constant value, mirror and circular padding.
New polynomial support#
New modules chebyshev and polynomial have been added. The new polynomial moduleis not compatible with the current polynomial support in numpy, but is muchlike the new chebyshev module. The most noticeable difference to most willbe that coefficients are specified from low to high power, that the lowlevel functions donot work with the Chebyshev and Polynomial classes asarguments, and that the Chebyshev and Polynomial classes include a domain.Mapping between domains is a linear substitution and the two classes can beconverted one to the other, allowing, for instance, a Chebyshev series inone domain to be expanded as a polynomial in another domain. The new classesshould generally be used instead of the low level functions, the latter areprovided for those who wish to build their own classes.
The new modules are not automatically imported into the numpy namespace,they must be explicitly brought in with an “import numpy.polynomial”statement.
New C API#
The following C functions have been added to the C API:
PyArray_GetNDArrayCFeatureVersion: return theAPI version of theloaded numpy.
PyArray_Correlate2 - like PyArray_Correlate, but implements the usualdefinition of correlation. Inputs are not swapped, and conjugate istaken for complex arrays.
PyArray_NeighborhoodIterNew - a new iterator to iterate over aneighborhood of a point, with automatic boundaries handling. It isdocumented in the iterators section of the C-API reference, and you canfind some examples in the multiarray_test.c.src file in numpy.core.
New ufuncs#
The following ufuncs have been added to the C API:
copysign - return the value of the first argument with the sign copiedfrom the second argument.
nextafter - return the next representable floating point value of thefirst argument toward the second argument.
New defines#
The alpha processor is now defined and available in numpy/npy_cpu.h. Thefailed detection of the PARISC processor has been fixed. The defines are:
NPY_CPU_HPPA: PARISC
NPY_CPU_ALPHA: Alpha
Testing#
deprecated decorator: this decorator may be used to avoid clutteringtesting output while testing DeprecationWarning is effectively raised bythe decorated test.
assert_array_almost_equal_nulp: new method to compare two arrays offloating point values. With this function, two values are consideredclose if there are not many representable floating point values inbetween, thus being more robust than assert_array_almost_equal when thevalues fluctuate a lot.
assert_array_max_ulp: raise an assertion if there are more than Nrepresentable numbers between two floating point values.
assert_warns: raise an AssertionError if a callable does not generate awarning of the appropriate class, without altering the warning state.
Reusing npymath#
In 1.3.0, we started putting portable C math routines in npymath library, sothat people can use those to write portable extensions. Unfortunately, it wasnot possible to easily link against this library: in 1.4.0, support has beenadded to numpy.distutils so that 3rd party can reuse this library. See coremathdocumentation for more information.
Improved set operations#
In previous versions of NumPy some set functions (intersect1d,setxor1d, setdiff1d and setmember1d) could return incorrect results ifthe input arrays contained duplicate items. These now work correctlyfor input arrays with duplicates. setmember1d has been renamed toin1d, as with the change to accept arrays with duplicates it isno longer a set operation, and is conceptually similar to anelementwise version of the Python operator ‘in’. All of thesefunctions now accept the boolean keyword assume_unique. This is Falseby default, but can be set True if the input arrays are known notto contain duplicates, which can increase the functions’ executionspeed.
Improvements#
numpy import is noticeably faster (from 20 to 30 % depending on theplatform and computer)
The sort functions now sort nans to the end.
Real sort order is [R, nan]
Complex sort order is [R + Rj, R + nanj, nan + Rj, nan + nanj]
Complex numbers with the same nan placements are sorted according tothe non-nan part if it exists.
The type comparison functions have been made consistent with the newsort order of nans. Searchsorted now works with sorted arrayscontaining nan values.
Complex division has been made more resistant to overflow.
Complex floor division has been made more resistant to overflow.
Deprecations#
The following functions are deprecated:
correlate: it takes a new keyword argument old_behavior. When True (thedefault), it returns the same result as before. When False, compute theconventional correlation, and take the conjugate for complex arrays. Theold behavior will be removed in NumPy 1.5, and raises aDeprecationWarning in 1.4.
unique1d: use unique instead. unique1d raises a deprecationwarning in 1.4, and will be removed in 1.5.
intersect1d_nu: use intersect1d instead. intersect1d_nu raisesa deprecation warning in 1.4, and will be removed in 1.5.
setmember1d: use in1d instead. setmember1d raises a deprecationwarning in 1.4, and will be removed in 1.5.
The following raise errors:
When operating on 0-d arrays,
numpy.maxand other functions acceptonlyaxis=0,axis=-1andaxis=None. Using an out-of-boundsaxes is an indication of a bug, so Numpy raises an error for these casesnow.Specifying
axis>MAX_DIMSis no longer allowed; Numpy raises now anerror instead of behaving similarly as foraxis=None.
Internal changes#
Use C99 complex functions when available#
The numpy complex types are now guaranteed to be ABI compatible with C99complex type, if available on the platform. Moreover, the complex ufunc now usethe platform C99 functions instead of our own.
split multiarray and umath source code#
The source code of multiarray and umath has been split into separate logiccompilation units. This should make the source code more amenable fornewcomers.
Separate compilation#
By default, every file of multiarray (and umath) is merged into one forcompilation as was the case before, but if NPY_SEPARATE_COMPILATION envvariable is set to a non-negative value, experimental individual compilation ofeach file is enabled. This makes the compile/debug cycle much faster whenworking on core numpy.
Separate core math library#
New functions which have been added:
npy_copysign
npy_nextafter
npy_cpack
npy_creal
npy_cimag
npy_cabs
npy_cexp
npy_clog
npy_cpow
npy_csqr
npy_ccos
npy_csin