Skip to content

Commit

Permalink
Switch to use 'ndims' instead of 'skip_1d' in templates
Browse files Browse the repository at this point in the history
  • Loading branch information
shoyer committed May 29, 2014
1 parent e8f5171 commit 6925ae0
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 57 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ PYTHON=python

srcdir := bottleneck/src

NDIM_MAX=3

help:
@echo "Available tasks:"
@echo "help --> This help page"
Expand All @@ -22,7 +20,7 @@ help:
all: clean pyx cfiles build test

pyx:
${PYTHON} -c "from bottleneck.src.makepyx import makepyx; makepyx(${NDIM_MAX})"
${PYTHON} -c "from bottleneck.src.makepyx import makepyx; makepyx();"

cfiles:
cython ${srcdir}/func/func.pyx
Expand Down
6 changes: 3 additions & 3 deletions bottleneck/src/makepyx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
from bottleneck.src.template.move.move import movepyx


def makepyx(ndim_max=3):
funcpyx(ndim_max=ndim_max)
movepyx(ndim_max=ndim_max)
def makepyx():
funcpyx()
movepyx()
7 changes: 4 additions & 3 deletions bottleneck/src/template/func/allnan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from copy import deepcopy
import bottleneck as bn
from bottleneck.src.template.template import NDIM_MAX

__all__ = ["allnan"]

Expand All @@ -12,10 +13,10 @@

floats = {}
floats['dtypes'] = FLOAT_DTYPES
floats['ndims'] = range(2, NDIM_MAX + 1)
floats['axisNone'] = False
floats['force_output_dtype'] = 'bool'
floats['reuse_non_nan_func'] = False
floats['skip_1d'] = True

floats['top'] = """
@cython.boundscheck(False)
Expand Down Expand Up @@ -43,8 +44,8 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Float dtypes (axis=None) --------------------------------------------------

floats_None = deepcopy(floats)
floats_None['ndims'] = range(1, NDIM_MAX + 1)
floats_None['axisNone'] = True
floats_None['skip_1d'] = False

floats_None['loop'] = """\
for iINDEXN in PRODUCT_RANGE|nINDEXN|NDIM|:
Expand Down Expand Up @@ -72,8 +73,8 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
# Int dtypes (axis=None) ----------------------------------------------------

ints_None = deepcopy(ints)
ints_None['ndims'] = range(1, NDIM_MAX + 1)
ints_None['axisNone'] = True
floats_None['skip_1d'] = False

ints_None['loop'] = """\
if PyArray_SIZE(a) == 0:
Expand Down
7 changes: 4 additions & 3 deletions bottleneck/src/template/func/anynan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from copy import deepcopy
import bottleneck as bn
from bottleneck.src.template.template import NDIM_MAX

__all__ = ["anynan"]

Expand All @@ -12,10 +13,10 @@

floats = {}
floats['dtypes'] = FLOAT_DTYPES
floats['ndims'] = range(2, NDIM_MAX + 1)
floats['axisNone'] = False
floats['force_output_dtype'] = 'bool'
floats['reuse_non_nan_func'] = False
floats['skip_1d'] = True

floats['top'] = """
@cython.boundscheck(False)
Expand Down Expand Up @@ -44,7 +45,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):

floats_None = deepcopy(floats)
floats_None['axisNone'] = True
floats_None['skip_1d'] = False
floats_None['ndims'] = range(1, NDIM_MAX + 1)

floats_None['loop'] = """\
for iINDEXN in PRODUCT_RANGE|nINDEXN|NDIM|:
Expand All @@ -69,7 +70,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):

ints_None = deepcopy(ints)
ints_None['axisNone'] = True
ints_None['skip_1d'] = False
ints_None['ndims'] = range(1, NDIM_MAX + 1)

ints_None['loop'] = """\
return np.bool_(False)
Expand Down
4 changes: 2 additions & 2 deletions bottleneck/src/template/func/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@
"""


def funcpyx(funcs=funcs, ndim_max=3):
def funcpyx(funcs=funcs):
for func in funcs:
template(funcs[func], ndim_max)
template(funcs[func])
template_path = os.path.dirname(tempmod.__file__)
fid = open(os.path.join(template_path, '..', "func/func.pyx"), 'w')
fid.write(header)
Expand Down
7 changes: 4 additions & 3 deletions bottleneck/src/template/func/nanmax.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from copy import deepcopy
import bottleneck as bn
from bottleneck.src.template.template import NDIM_MAX

__all__ = ["nanmax"]

Expand All @@ -13,9 +14,9 @@
floats = {}
floats['dtypes'] = FLOAT_DTYPES
floats['axisNone'] = False
floats['ndims'] = range(2, NDIM_MAX + 1)
floats['force_output_dtype'] = False
floats['reuse_non_nan_func'] = False
floats['skip_1d'] = True

floats['top'] = """
@cython.boundscheck(False)
Expand Down Expand Up @@ -49,7 +50,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):

floats_None = deepcopy(floats)
floats_None['axisNone'] = True
floats_None['skip_1d'] = False
floats_None['ndims'] = range(1, NDIM_MAX + 1)

floats_None['loop'] = """\
if PyArray_SIZE(a) == 0:
Expand Down Expand Up @@ -90,7 +91,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):

ints_None = deepcopy(ints)
ints_None['axisNone'] = True
ints_None['skip_1d'] = False
ints_None['ndims'] = range(1, NDIM_MAX + 1)

ints_None['loop'] = """\
if PyArray_SIZE(a) == 0:
Expand Down
7 changes: 4 additions & 3 deletions bottleneck/src/template/func/nanmean.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from copy import deepcopy
import bottleneck as bn
from bottleneck.src.template.template import NDIM_MAX

__all__ = ["nanmean"]

Expand All @@ -13,9 +14,9 @@
floats = {}
floats['dtypes'] = FLOAT_DTYPES
floats['axisNone'] = False
floats['ndims'] = range(2, NDIM_MAX + 1)
floats['force_output_dtype'] = False
floats['reuse_non_nan_func'] = False
floats['skip_1d'] = True

floats['top'] = """
@cython.boundscheck(False)
Expand Down Expand Up @@ -46,7 +47,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):

floats_None = deepcopy(floats)
floats_None['axisNone'] = True
floats_None['skip_1d'] = False
floats_None['ndims'] = range(1, NDIM_MAX + 1)

floats_None['loop'] = """\
for iINDEXN in PRODUCT_RANGE|nINDEXN|NDIM|:
Expand Down Expand Up @@ -91,7 +92,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
ints_None = deepcopy(ints)
ints_None['top'] = ints['top'] + " cdef Py_ssize_t size\n"
ints_None['axisNone'] = True
ints_None['skip_1d'] = False
ints_None['ndims'] = range(1, NDIM_MAX + 1)

ints_None['loop'] = """\
size = PyArray_SIZE(a)
Expand Down
7 changes: 4 additions & 3 deletions bottleneck/src/template/func/nanmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from copy import deepcopy
import bottleneck as bn
from bottleneck.src.template.template import NDIM_MAX

__all__ = ["nanmin"]

Expand All @@ -13,9 +14,9 @@
floats = {}
floats['dtypes'] = FLOAT_DTYPES
floats['axisNone'] = False
floats['ndims'] = range(2, NDIM_MAX + 1)
floats['force_output_dtype'] = False
floats['reuse_non_nan_func'] = False
floats['skip_1d'] = True

floats['top'] = """
@cython.boundscheck(False)
Expand Down Expand Up @@ -49,7 +50,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):

floats_None = deepcopy(floats)
floats_None['axisNone'] = True
floats_None['skip_1d'] = False
floats_None['ndims'] = range(1, NDIM_MAX + 1)

floats_None['loop'] = """\
if PyArray_SIZE(a) == 0:
Expand Down Expand Up @@ -90,7 +91,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):

ints_None = deepcopy(ints)
ints_None['axisNone'] = True
ints_None['skip_1d'] = False
ints_None['ndims'] = range(1, NDIM_MAX + 1)

ints_None['loop'] = """\
if PyArray_SIZE(a) == 0:
Expand Down
7 changes: 4 additions & 3 deletions bottleneck/src/template/func/nanstd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from copy import deepcopy
import bottleneck as bn
from bottleneck.src.template.template import NDIM_MAX

__all__ = ["nanstd"]

Expand All @@ -13,9 +14,9 @@
floats = {}
floats['dtypes'] = FLOAT_DTYPES
floats['axisNone'] = False
floats['ndims'] = range(2, NDIM_MAX + 1)
floats['force_output_dtype'] = False
floats['reuse_non_nan_func'] = False
floats['skip_1d'] = True

floats['top'] = """
@cython.boundscheck(False)
Expand Down Expand Up @@ -53,7 +54,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a, int ddof):

floats_None = deepcopy(floats)
floats_None['axisNone'] = True
floats_None['skip_1d'] = False
floats_None['ndims'] = range(1, NDIM_MAX + 1)

floats_None['loop'] = """\
for iINDEXN in PRODUCT_RANGE|nINDEXN|NDIM|:
Expand Down Expand Up @@ -111,7 +112,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a, int ddof):
ints_None = deepcopy(ints)
ints_None['top'] = ints['top'] + " cdef Py_ssize_t size\n"
ints_None['axisNone'] = True
ints_None['skip_1d'] = False
ints_None['ndims'] = range(1, NDIM_MAX + 1)

ints_None['loop'] = """\
size = PyArray_SIZE(a)
Expand Down
7 changes: 4 additions & 3 deletions bottleneck/src/template/func/nansum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from copy import deepcopy
import bottleneck as bn
from bottleneck.src.template.template import NDIM_MAX

__all__ = ["nansum"]

Expand All @@ -14,9 +15,9 @@
floats = {}
floats['dtypes'] = FLOAT_DTYPES
floats['axisNone'] = False
floats['ndims'] = range(2, NDIM_MAX + 1)
floats['force_output_dtype'] = False
floats['reuse_non_nan_func'] = False
floats['skip_1d'] = True

floats['top'] = """
@cython.boundscheck(False)
Expand Down Expand Up @@ -47,7 +48,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):

floats_None = deepcopy(floats)
floats_None['axisNone'] = True
floats_None['skip_1d'] = False
floats_None['ndims'] = range(1, NDIM_MAX + 1)

floats_None['loop'] = """\
for iINDEXN in PRODUCT_RANGE|nINDEXN|NDIM|:
Expand Down Expand Up @@ -88,7 +89,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):
ints_None = deepcopy(ints)
ints_None['top'] = ints['top'] + " cdef Py_ssize_t size\n"
ints_None['axisNone'] = True
ints_None['skip_1d'] = False
ints_None['ndims'] = range(1, NDIM_MAX + 1)

ints_None['loop'] = """\
size = PyArray_SIZE(a)
Expand Down
7 changes: 4 additions & 3 deletions bottleneck/src/template/func/nanvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from copy import deepcopy
import bottleneck as bn
from bottleneck.src.template.template import NDIM_MAX

__all__ = ["nanvar"]

Expand All @@ -13,9 +14,9 @@
floats = {}
floats['dtypes'] = FLOAT_DTYPES
floats['axisNone'] = False
floats['ndims'] = range(2, NDIM_MAX + 1)
floats['force_output_dtype'] = False
floats['reuse_non_nan_func'] = False
floats['skip_1d'] = True

floats['top'] = """
@cython.boundscheck(False)
Expand Down Expand Up @@ -53,7 +54,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a, int ddof):

floats_None = deepcopy(floats)
floats_None['axisNone'] = True
floats_None['skip_1d'] = False
floats_None['ndims'] = range(1, NDIM_MAX + 1)

floats_None['loop'] = """\
for iINDEXN in PRODUCT_RANGE|nINDEXN|NDIM|:
Expand Down Expand Up @@ -111,7 +112,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a, int ddof):
ints_None = deepcopy(ints)
ints_None['top'] = ints['top'] + " cdef Py_ssize_t size\n"
ints_None['axisNone'] = True
ints_None['skip_1d'] = False
ints_None['ndims'] = range(1, NDIM_MAX + 1)

ints_None['loop'] = """\
size = PyArray_SIZE(a)
Expand Down
5 changes: 2 additions & 3 deletions bottleneck/src/template/func/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
floats = {}
floats['dtypes'] = FLOAT_DTYPES
floats['axisNone'] = False
floats['ndims'] = [2]
floats['force_output_dtype'] = False
floats['reuse_non_nan_func'] = False

Expand All @@ -28,8 +29,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=2] a,
Py_ssize_t imin = -1, n, a0size
"""

loop = {}
loop[2] = """\
floats['loop'] = """\
a0size = PyArray_SIZE(a0)
if nAXIS != a0size:
raise ValueError("`a0` must match size of `a` along specified axis")
Expand All @@ -48,7 +48,6 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=2] a,
dist = sqrt(xsummin)
return dist, imin
"""
floats['loop'] = loop

# Int dtypes (not axis=None) ------------------------------------------------

Expand Down
5 changes: 3 additions & 2 deletions bottleneck/src/template/func/ss.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from copy import deepcopy
import bottleneck as bn
from bottleneck.src.template.template import NDIM_MAX

__all__ = ["ss"]

Expand All @@ -14,9 +15,9 @@
floats = {}
floats['dtypes'] = FLOAT_DTYPES
floats['axisNone'] = False
floats['ndims'] = range(2, NDIM_MAX + 1)
floats['force_output_dtype'] = False
floats['reuse_non_nan_func'] = False
floats['skip_1d'] = True

floats['top'] = """
@cython.boundscheck(False)
Expand All @@ -40,7 +41,7 @@ def NAME_NDIMd_DTYPE_axisAXIS(np.ndarray[np.DTYPE_t, ndim=NDIM] a):

floats_None = deepcopy(floats)
floats_None['axisNone'] = True
floats_None['skip_1d'] = False
floats_None['ndims'] = range(1, NDIM_MAX + 1)

floats_None['loop'] = """\
for iINDEXN in PRODUCT_RANGE|nINDEXN|NDIM|:
Expand Down
Loading

0 comments on commit 6925ae0

Please sign in to comment.