Navigation Menu

Skip to content

Commit

Permalink
Update README and RELEASE notes with NDIM_MAX
Browse files Browse the repository at this point in the history
Also added an example to the "unindex_0dimensional" function in template.py.
  • Loading branch information
shoyer committed Jun 2, 2014
1 parent 91514cb commit c3d0d0f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
30 changes: 25 additions & 5 deletions README.rst
Expand Up @@ -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
=======

Expand Down Expand Up @@ -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::

Expand All @@ -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:
Expand All @@ -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::

Expand Down
3 changes: 3 additions & 0 deletions RELEASE.rst
Expand Up @@ -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
==============
Expand Down
20 changes: 17 additions & 3 deletions bottleneck/src/template/template.py
Expand Up @@ -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)]

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c3d0d0f

Please sign in to comment.