diff --git a/README.rst b/README.rst index 7a65693e38..04c05fac52 100644 --- a/README.rst +++ b/README.rst @@ -206,10 +206,14 @@ Benchmarks for the low-level Cython functions:: Slow ==== -Currently only 1d, 2d, and 3d input arrays with data type (dtype) int32, -int64, float32, and float64 are accelerated. All other ndim/dtype +By default, only 1d, 2d, and 3d input arrays with data type (dtype) +int32, int64, float32, and float64 are accelerated. All other ndim/dtype combinations result in calls to slower, unaccelerated functions. +With the development version of bottleneck, it is possible to accelerate higher +dimensional arrays if an appropriate flag is set at compile-time (see +`Fast functions for higher dimensions`_ below). + License ======= @@ -258,7 +262,8 @@ Cython.) Bottleneck takes a few minutes to build on newer machines. On older machines it can take a lot longer (one user reported 30 minutes!). -**GNU/Linux, Mac OS X, et al.** +GNU/Linux, Mac OS X, et al. +--------------------------- To install Bottleneck:: @@ -271,7 +276,8 @@ Or, if you wish to specify where Bottleneck is installed, for example inside $ python setup.py build $ sudo python setup.py install --prefix=/usr/local -**Windows** +Windows +------- You can compile Bottleneck using the instructions below or you can use the Windows binaries created by Christoph Gohlke: @@ -286,7 +292,21 @@ commands:: python setup.py build --compiler=mingw32 python setup.py install -**Post install** +Fast functions for higher dimensions +------------------------------------ + +If Cython is available, it is possible to adjust the number of supported +dimensions at *compile-time* by setting the environment variable ``NDIM_MAX``, +which defaults to 3. For example, to build 1d, 2d, 3d and 4d versions of all +functions:: + + NDIM_MAX=4 make clean pyx cfiles build + +The size of the generated code (and the time required to compile it) scales as +``NDIM_MAX`` squared. + +Post install +------------ After you have installed Bottleneck, run the suite of unit tests:: diff --git a/RELEASE.rst b/RELEASE.rst index c333b36c2b..1f52441302 100644 --- a/RELEASE.rst +++ b/RELEASE.rst @@ -15,6 +15,9 @@ Bottleneck 0.9.0 - bn.slow.move functions with method='strides' no longer limited to ndim < 4 - Use setuptools to enable automatic installation of numpy by pip +- A new compile time option NDIM_MAX allows for adjusting the number of + dimensions for which fast functions are generated +- Moving window functions now release Python's global interpreter lock Older versions ============== diff --git a/bottleneck/src/template/template.py b/bottleneck/src/template/template.py index 04c61d73de..6a073624bb 100644 --- a/bottleneck/src/template/template.py +++ b/bottleneck/src/template/template.py @@ -381,7 +381,6 @@ def _parse_product_range_line(line): 'range(%s)' % range_inside) for_statement = for_statement.replace('INDEXN', 'INDEX%d') range_list = eval('range(%s)' % prod_inside) - # range_list = range(*[int(n) for n in prod_inside.split(',')]) return [TAB * i + for_statement % (n, n) for i, n in enumerate(range_list)] @@ -443,9 +442,24 @@ def loop_expand_product_range(text): def unindex_0dimensional(text, ydtype): """ If a loop template includes assignments to 0-dimensional return variables - like 'y[] = ', replace them with return statemetns. + like 'y[] = ', replace them with return statements (cast to ydtype), after + removing all existing return statements. + + Examples + -------- + + >>> text = '''\ + ... if foo: + ... PyArray_FillWithScalar(y, NAN) + ... y[] = a + ... return y + ... '''' + >>> print(unindex_0dimensional(text, 'float64')) + if foo: + return np.float64(NAN) + return np.float64(a) """ - if '[] = ' in text: + if 'y[] = ' in text: text = text.replace('return y', '') text = re.sub(r'PyArray_FillWithScalar\(y, (\w+)\)', r'return np.%s(\1)' % ydtype, text)