NumPy 2.0 with hardware acceleration, strict APIs and string functions

The Python extension for mathematical calculations is accelerated in version 2.0.0 with hardware support and offers many new functions.

Save to Pocket listen Print view

(Image: Funtap / Shutterstock.com)

3 min. read
This article was originally published in German and has been automatically translated.

NumPy, the mathematical library for Python, has received its first major release since 2006 with version 2.0.0. This not only offers new functions, but also performance improvements for Intel and Mac environments. Due to some breaking changes, it is not completely backwards-compatible; rules in the Python and C APIs have been changed, and many objects have been abandoned.

Behind the 212 contributors of the new version lie 11 months of work with over 1078 pulls. The result is a range of new functions: For string operations, there is a new data type element with variable length, numpy.dtypes.StringDType, and the namespace numpy.strings with high-performance universal functions. The float32 and longdouble data types can now be used with all numpy.fft functions. And the numpy namespace now supports the Array API.

Many changes also relate to the API. With version 2.0, there is a strict separation between private and public APIs in the Python API thanks to a new model structure. Each public function is assigned a unique location. The team has also removed many obsolete objects and aliases, around ten percent in the main namespace and as much as eighty percent in numpy.lib. "This should make it easier to learn and use NumPy ," write the contributors.

The C-API also had to lose some feathers. Functions and macros were removed or hidden "to simplify future extensibility".

One focus of the work on the new release concerned the speed of calculations. NumPy now uses hardware acceleration for sorting (sort, argsort, partition, argpartition), firstly with Intel's sort commands for the SIMD x86 extensions and secondly with Google Highway. This achieves "large (hardware-specific) speed-ups". On the Mac (>=14) it is also likely to be up to three times as fast: NumPy 2.0 offers accelerated wheels for linear algebra.

To keep an eye on performance at all times, NumPy 2.0 has a tracing interface, numpy.lib.introspect.opt_func_info, which can be used to determine which hardware cores are available.

In detail, the team has incorporated many other changes, for example, the behavior of the type extension (with NEP 50) has been improved so that fewer misleading error messages occur. An overview of all the new features can be found in the release notes and on theGitHub page .Due to the breaking changes, we recommend reading the migration guide and the information for downstream packages, which often have to be adapted. The next version is already available as 2.1.dev0 .

(who)