Commits

Janez Demšar  committed 511875f

Transposed the result of bottleneck.contingency

  • Participants
  • Parent commits 19dd2b1

Comments (0)

Files changed (4)

File bottleneck/src/func/32bit/func.c

-/* Generated by Cython 0.17.2 on Tue Jan  1 17:13:57 2013 */
+/* Generated by Cython 0.17.2 on Thu Jan  3 17:03:06 2013 */
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
 
 /* Python wrapper */
 static PyObject *__pyx_pw_4func_2141contingency(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_4func_2140contingency[] = "contingency(arr, b, max_val, max_val2, weights=None, mask=None)\n\n    Compute the contingency matrices for each column (excluding the masked)\n    versus the vector b.\n\n    If the array is 1-dimensional, a 2d contingency matrix is returned. If the\n    array is 2d, the function returns a 3d array, with the first dimension\n    corresponding to column index (variable in the input array).\n\n    The rows of contingency matrix correspond to values of variables, the\n    columns correspond to values in vector `b`. The number of rows is\n    `max_val+1`, the nuber of columns is `max_val2+1`.\n\n    Rows in the input array can be weights (argument `weights`). A subset of\n    columns can be selected by additional argument `mask`.\n\n    The function also returns a count of NaN values per each value of `b`.\n\n    Parameters\n    ----------\n    x : array_like, 1 or 2 dimensions, nonnegative elements\n        Input array.\n    b : array_like, 1 dimension, of type int8\n        The values of the second variable.\n    max_val : int\n        The maximal value in the array\n    max_val2 : int\n        The maximal value in `b`\n    weights : array_like, optional\n        Weights, array of the same length as `x`.\n    mask: array_like, of type char (interpreted as bool)\n        Selects the columns\n\n    Returns\n    -------\n    out : ndarray of ints, 1- or 2-dimensional\n        The result of binning the input array.\n    nans: the number of NaNs; a 1-d vector of length `max_val`, or 2-d array `(x.shape[1], max_val2)`\n\n    Raises\n    ------\n    ValueError\n        If the input is not 1- or 2-dimensional, or contains elements that are\n        not close enough to integers, negative or grater than max_val, or if the\n        length of the weight vector does not match the length of the array\n\n    ";
+static char __pyx_doc_4func_2140contingency[] = "contingency(arr, b, max_val, max_val2, weights=None, mask=None)\n\n    Compute the contingency matrices for each column (excluding the masked)\n    versus the vector b.\n\n    If the array is 1-dimensional, a 2d contingency matrix is returned. If the\n    array is 2d, the function returns a 3d array, with the first dimension\n    corresponding to column index (variable in the input array).\n\n    The rows of contingency matrix correspond to values of variables, the\n    columns correspond to values in vector `b`. The number of rows is\n    `max_val+1`, the nuber of columns is `max_val2+1`.\n\n    Rows in the input array can be weights (argument `weights`). A subset of\n    columns can be selected by additional argument `mask`.\n\n    The function also returns a count of NaN values per each value of `b`.\n\n    Parameters\n    ----------\n    x : array_like, 1 or 2 dimensions, nonnegative elements\n        Input array.\n    b : array_like, 1 dimension, of type int8\n        The values of the second variable.\n    max_val : int\n        The maximal value in the array\n    max_val2 : int\n        The maximal value in `b`\n    weights : array_like, optional\n        Weights, array of the same length as `x`.\n    mask: array_like, of type char (interpreted as bool)\n        Selects the columns\n\n    Returns\n    -------\n    out : ndarray of ints, 1- or 2-dimensional\n        The result of binning the input array.\n    nans: the number of NaNs; a 1-d vector of length `max_val`, or 2-d array `(max_val2, x.shape[1])`\n\n    Raises\n    ------\n    ValueError\n        If the input is not 1- or 2-dimensional, or contains elements that are\n        not close enough to integers, negative or grater than max_val, or if the\n        length of the weight vector does not match the length of the array\n\n    ";
 static PyMethodDef __pyx_mdef_4func_2141contingency = {__Pyx_NAMESTR("contingency"), (PyCFunction)__pyx_pw_4func_2141contingency, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_4func_2140contingency)};
 static PyObject *__pyx_pw_4func_2141contingency(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
   PyObject *__pyx_v_arr = 0;
   PyObject *__pyx_t_13 = NULL;
   PyObject *__pyx_t_14 = NULL;
   Py_ssize_t __pyx_t_15;
-  int __pyx_t_16;
-  char __pyx_t_17;
+  char __pyx_t_16;
+  int __pyx_t_17;
   Py_ssize_t __pyx_t_18;
   Py_ssize_t __pyx_t_19;
   Py_ssize_t __pyx_t_20;
-  int __pyx_t_21;
-  char __pyx_t_22;
+  char __pyx_t_21;
+  int __pyx_t_22;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":123
  * 
  *     cdef:
- *         np.npy_intp *dims = [max_val + 1, max_val2 + 1]             # <<<<<<<<<<<<<<
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)
  *         np.npy_intp *nandims = [max_val2 + 1]
  */
-  __pyx_t_6[0] = (__pyx_v_max_val + 1);
-  __pyx_t_6[1] = (__pyx_v_max_val2 + 1);
+  __pyx_t_6[0] = (__pyx_v_max_val2 + 1);
+  __pyx_t_6[1] = (__pyx_v_max_val + 1);
   __pyx_v_dims = __pyx_t_6;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":124
  *     cdef:
- *         np.npy_intp *dims = [max_val + 1, max_val2 + 1]
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)             # <<<<<<<<<<<<<<
  *         np.npy_intp *nandims = [max_val2 + 1]
  *         np.ndarray[np.float_t, ndim=1] nans = PyArray_ZEROS(1, nandims, NPY_float64, 0)
   __pyx_t_5 = 0;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":125
- *         np.npy_intp *dims = [max_val + 1, max_val2 + 1]
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)
  *         np.npy_intp *nandims = [max_val2 + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float_t, ndim=1] nans = PyArray_ZEROS(1, nandims, NPY_float64, 0)
  *             if bin > max_val2:
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))             # <<<<<<<<<<<<<<
- *             y[ai, bin] += 1
+ *             y[bin, ai] += 1
  *     else:
  */
         __pyx_t_13 = PyInt_FromLong(__pyx_v_bin); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":143
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))
- *             y[ai, bin] += 1             # <<<<<<<<<<<<<<
- *     else:
- *         for i0 in range(n0):
- */
-      __pyx_t_16 = __pyx_v_ai;
-      __pyx_t_17 = __pyx_v_bin;
+ *             y[bin, ai] += 1             # <<<<<<<<<<<<<<
+ *     else:
+ *         for i0 in range(n0):
+ */
+      __pyx_t_16 = __pyx_v_bin;
+      __pyx_t_17 = __pyx_v_ai;
       *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_17, __pyx_pybuffernd_y.diminfo[1].strides) += 1.0;
     }
     goto __pyx_L5;
   /*else*/ {
 
     /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":145
- *             y[ai, bin] += 1
+ *             y[bin, ai] += 1
  *     else:
  *         for i0 in range(n0):             # <<<<<<<<<<<<<<
  *             ai = a[i0]
  *             if bin > max_val2:
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))             # <<<<<<<<<<<<<<
- *             y[ai, bin] += w[i0]
+ *             y[bin, ai] += w[i0]
  *     return y, nans
  */
         __pyx_t_5 = PyInt_FromLong(__pyx_v_bin); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":156
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))
- *             y[ai, bin] += w[i0]             # <<<<<<<<<<<<<<
+ *             y[bin, ai] += w[i0]             # <<<<<<<<<<<<<<
  *     return y, nans
  * 
  */
       __pyx_t_20 = __pyx_v_i0;
-      __pyx_t_21 = __pyx_v_ai;
-      __pyx_t_22 = __pyx_v_bin;
+      __pyx_t_21 = __pyx_v_bin;
+      __pyx_t_22 = __pyx_v_ai;
       *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_y.diminfo[1].strides) += (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_w.diminfo[0].strides));
     }
   }
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":157
  *                                  (bin, max_val2))
- *             y[ai, bin] += w[i0]
+ *             y[bin, ai] += w[i0]
  *     return y, nans             # <<<<<<<<<<<<<<
  * 
  * @cython.boundscheck(False)
   PyObject *__pyx_t_13 = NULL;
   PyObject *__pyx_t_14 = NULL;
   Py_ssize_t __pyx_t_15;
-  int __pyx_t_16;
-  char __pyx_t_17;
+  char __pyx_t_16;
+  int __pyx_t_17;
   Py_ssize_t __pyx_t_18;
   Py_ssize_t __pyx_t_19;
   Py_ssize_t __pyx_t_20;
-  int __pyx_t_21;
-  char __pyx_t_22;
+  char __pyx_t_21;
+  int __pyx_t_22;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":176
  * 
  *     cdef:
- *         np.npy_intp *dims = [max_val + 1, max_val2 + 1]             # <<<<<<<<<<<<<<
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)
  *         np.npy_intp *nandims = [max_val2 + 1]
  */
-  __pyx_t_6[0] = (__pyx_v_max_val + 1);
-  __pyx_t_6[1] = (__pyx_v_max_val2 + 1);
+  __pyx_t_6[0] = (__pyx_v_max_val2 + 1);
+  __pyx_t_6[1] = (__pyx_v_max_val + 1);
   __pyx_v_dims = __pyx_t_6;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":177
  *     cdef:
- *         np.npy_intp *dims = [max_val + 1, max_val2 + 1]
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)             # <<<<<<<<<<<<<<
  *         np.npy_intp *nandims = [max_val2 + 1]
  *         np.ndarray[np.float_t, ndim=1] nans = PyArray_ZEROS(1, nandims, NPY_float64, 0)
   __pyx_t_5 = 0;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":178
- *         np.npy_intp *dims = [max_val + 1, max_val2 + 1]
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)
  *         np.npy_intp *nandims = [max_val2 + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float_t, ndim=1] nans = PyArray_ZEROS(1, nandims, NPY_float64, 0)
  *             if bin > max_val2:
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))             # <<<<<<<<<<<<<<
- *             y[ai, bin] += 1
+ *             y[bin, ai] += 1
  *     else:
  */
         __pyx_t_13 = PyInt_FromLong(__pyx_v_bin); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":196
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))
- *             y[ai, bin] += 1             # <<<<<<<<<<<<<<
- *     else:
- *         for i0 in range(n0):
- */
-      __pyx_t_16 = __pyx_v_ai;
-      __pyx_t_17 = __pyx_v_bin;
+ *             y[bin, ai] += 1             # <<<<<<<<<<<<<<
+ *     else:
+ *         for i0 in range(n0):
+ */
+      __pyx_t_16 = __pyx_v_bin;
+      __pyx_t_17 = __pyx_v_ai;
       *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_17, __pyx_pybuffernd_y.diminfo[1].strides) += 1.0;
     }
     goto __pyx_L5;
   /*else*/ {
 
     /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":198
- *             y[ai, bin] += 1
+ *             y[bin, ai] += 1
  *     else:
  *         for i0 in range(n0):             # <<<<<<<<<<<<<<
  *             ai = a[i0]
  *             if bin > max_val2:
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))             # <<<<<<<<<<<<<<
- *             y[ai, bin] += w[i0]
+ *             y[bin, ai] += w[i0]
  *     return y, nans
  */
         __pyx_t_5 = PyInt_FromLong(__pyx_v_bin); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":209
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))
- *             y[ai, bin] += w[i0]             # <<<<<<<<<<<<<<
+ *             y[bin, ai] += w[i0]             # <<<<<<<<<<<<<<
  *     return y, nans
  * 
  */
       __pyx_t_20 = __pyx_v_i0;
-      __pyx_t_21 = __pyx_v_ai;
-      __pyx_t_22 = __pyx_v_bin;
+      __pyx_t_21 = __pyx_v_bin;
+      __pyx_t_22 = __pyx_v_ai;
       *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_y.diminfo[1].strides) += (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_w.diminfo[0].strides));
     }
   }
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":210
  *                                  (bin, max_val2))
- *             y[ai, bin] += w[i0]
+ *             y[bin, ai] += w[i0]
  *     return y, nans             # <<<<<<<<<<<<<<
  * 
  * @cython.boundscheck(False)
   PyObject *__pyx_t_13 = NULL;
   PyObject *__pyx_t_14 = NULL;
   Py_ssize_t __pyx_t_15;
-  int __pyx_t_16;
-  char __pyx_t_17;
+  char __pyx_t_16;
+  int __pyx_t_17;
   Py_ssize_t __pyx_t_18;
   Py_ssize_t __pyx_t_19;
   Py_ssize_t __pyx_t_20;
-  int __pyx_t_21;
-  char __pyx_t_22;
+  char __pyx_t_21;
+  int __pyx_t_22;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":229
  * 
  *     cdef:
- *         np.npy_intp *dims = [max_val + 1, max_val2 + 1]             # <<<<<<<<<<<<<<
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)
  *         np.npy_intp *nandims = [max_val2 + 1]
  */
-  __pyx_t_6[0] = (__pyx_v_max_val + 1);
-  __pyx_t_6[1] = (__pyx_v_max_val2 + 1);
+  __pyx_t_6[0] = (__pyx_v_max_val2 + 1);
+  __pyx_t_6[1] = (__pyx_v_max_val + 1);
   __pyx_v_dims = __pyx_t_6;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":230
  *     cdef:
- *         np.npy_intp *dims = [max_val + 1, max_val2 + 1]
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)             # <<<<<<<<<<<<<<
  *         np.npy_intp *nandims = [max_val2 + 1]
  *         np.ndarray[np.float_t, ndim=1] nans = PyArray_ZEROS(1, nandims, NPY_float64, 0)
   __pyx_t_5 = 0;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":231
- *         np.npy_intp *dims = [max_val + 1, max_val2 + 1]
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)
  *         np.npy_intp *nandims = [max_val2 + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float_t, ndim=1] nans = PyArray_ZEROS(1, nandims, NPY_float64, 0)
  *             if bin > max_val2:
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))             # <<<<<<<<<<<<<<
- *             y[ai, bin] += 1
+ *             y[bin, ai] += 1
  *     else:
  */
         __pyx_t_13 = PyInt_FromLong(__pyx_v_bin); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":249
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))
- *             y[ai, bin] += 1             # <<<<<<<<<<<<<<
- *     else:
- *         for i0 in range(n0):
- */
-      __pyx_t_16 = __pyx_v_ai;
-      __pyx_t_17 = __pyx_v_bin;
+ *             y[bin, ai] += 1             # <<<<<<<<<<<<<<
+ *     else:
+ *         for i0 in range(n0):
+ */
+      __pyx_t_16 = __pyx_v_bin;
+      __pyx_t_17 = __pyx_v_ai;
       *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_17, __pyx_pybuffernd_y.diminfo[1].strides) += 1.0;
     }
     goto __pyx_L5;
   /*else*/ {
 
     /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":251
- *             y[ai, bin] += 1
+ *             y[bin, ai] += 1
  *     else:
  *         for i0 in range(n0):             # <<<<<<<<<<<<<<
  *             ai = a[i0]
  *             if bin > max_val2:
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))             # <<<<<<<<<<<<<<
- *             y[ai, bin] += w[i0]
+ *             y[bin, ai] += w[i0]
  *     return y, nans
  */
         __pyx_t_5 = PyInt_FromLong(__pyx_v_bin); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":262
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))
- *             y[ai, bin] += w[i0]             # <<<<<<<<<<<<<<
+ *             y[bin, ai] += w[i0]             # <<<<<<<<<<<<<<
  *     return y, nans
  * 
  */
       __pyx_t_20 = __pyx_v_i0;
-      __pyx_t_21 = __pyx_v_ai;
-      __pyx_t_22 = __pyx_v_bin;
+      __pyx_t_21 = __pyx_v_bin;
+      __pyx_t_22 = __pyx_v_ai;
       *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_y.diminfo[1].strides) += (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_w.diminfo[0].strides));
     }
   }
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":263
  *                                  (bin, max_val2))
- *             y[ai, bin] += w[i0]
+ *             y[bin, ai] += w[i0]
  *     return y, nans             # <<<<<<<<<<<<<<
  * 
  * @cython.boundscheck(False)
   Py_ssize_t __pyx_t_19;
   Py_ssize_t __pyx_t_20;
   Py_ssize_t __pyx_t_21;
-  int __pyx_t_22;
-  char __pyx_t_23;
+  char __pyx_t_22;
+  int __pyx_t_23;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":283
  * 
  *     cdef:
- *        np.npy_intp *dims = [n1, max_val+1, max_val2+1]             # <<<<<<<<<<<<<<
+ *        np.npy_intp *dims = [n1, max_val2 + 1, max_val + 1]             # <<<<<<<<<<<<<<
  *        np.ndarray[np.float_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
  *        np.npy_intp *nandims = [n1, max_val2+1]
  */
   __pyx_t_7[0] = __pyx_v_n1;
-  __pyx_t_7[1] = (__pyx_v_max_val + 1);
-  __pyx_t_7[2] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[1] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[2] = (__pyx_v_max_val + 1);
   __pyx_v_dims = __pyx_t_7;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":284
  *     cdef:
- *        np.npy_intp *dims = [n1, max_val+1, max_val2+1]
+ *        np.npy_intp *dims = [n1, max_val2 + 1, max_val + 1]
  *        np.ndarray[np.float_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)             # <<<<<<<<<<<<<<
  *        np.npy_intp *nandims = [n1, max_val2+1]
  *        np.ndarray[np.float64_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
   __pyx_t_6 = 0;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":285
- *        np.npy_intp *dims = [n1, max_val+1, max_val2+1]
+ *        np.npy_intp *dims = [n1, max_val2 + 1, max_val + 1]
  *        np.ndarray[np.float_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
  *        np.npy_intp *nandims = [n1, max_val2+1]             # <<<<<<<<<<<<<<
  *        np.ndarray[np.float64_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
  *                 if ai > max_val:
  *                     raise ValueError("value %i is greater than max_val (%i)"
  *                                      % (ai, max_val))             # <<<<<<<<<<<<<<
- *                 y[i1, ai, bin] += wt
+ *                 y[i1, bin, ai] += wt
  *     return y, nans
  */
           __pyx_t_12 = PyInt_FromLong(__pyx_v_ai); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 303; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":304
  *                     raise ValueError("value %i is greater than max_val (%i)"
  *                                      % (ai, max_val))
- *                 y[i1, ai, bin] += wt             # <<<<<<<<<<<<<<
+ *                 y[i1, bin, ai] += wt             # <<<<<<<<<<<<<<
  *     return y, nans
  * 
  */
         __pyx_t_21 = __pyx_v_i1;
-        __pyx_t_22 = __pyx_v_ai;
-        __pyx_t_23 = __pyx_v_bin;
+        __pyx_t_22 = __pyx_v_bin;
+        __pyx_t_23 = __pyx_v_ai;
         *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_y.diminfo[1].strides, __pyx_t_23, __pyx_pybuffernd_y.diminfo[2].strides) += __pyx_v_wt;
         goto __pyx_L9;
       }
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":305
  *                                      % (ai, max_val))
- *                 y[i1, ai, bin] += wt
+ *                 y[i1, bin, ai] += wt
  *     return y, nans             # <<<<<<<<<<<<<<
  * 
  * @cython.boundscheck(False)
   Py_ssize_t __pyx_t_19;
   Py_ssize_t __pyx_t_20;
   Py_ssize_t __pyx_t_21;
-  int __pyx_t_22;
-  char __pyx_t_23;
+  char __pyx_t_22;
+  int __pyx_t_23;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":325
  * 
  *     cdef:
- *        np.npy_intp *dims = [n1, max_val+1, max_val2+1]             # <<<<<<<<<<<<<<
+ *        np.npy_intp *dims = [n1, max_val2 + 1, max_val + 1]             # <<<<<<<<<<<<<<
  *        np.ndarray[np.float_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
  *        np.npy_intp *nandims = [n1, max_val2+1]
  */
   __pyx_t_7[0] = __pyx_v_n1;
-  __pyx_t_7[1] = (__pyx_v_max_val + 1);
-  __pyx_t_7[2] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[1] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[2] = (__pyx_v_max_val + 1);
   __pyx_v_dims = __pyx_t_7;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":326
  *     cdef:
- *        np.npy_intp *dims = [n1, max_val+1, max_val2+1]
+ *        np.npy_intp *dims = [n1, max_val2 + 1, max_val + 1]
  *        np.ndarray[np.float_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)             # <<<<<<<<<<<<<<
  *        np.npy_intp *nandims = [n1, max_val2+1]
  *        np.ndarray[np.float64_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
   __pyx_t_6 = 0;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":327
- *        np.npy_intp *dims = [n1, max_val+1, max_val2+1]
+ *        np.npy_intp *dims = [n1, max_val2 + 1, max_val + 1]
  *        np.ndarray[np.float_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
  *        np.npy_intp *nandims = [n1, max_val2+1]             # <<<<<<<<<<<<<<
  *        np.ndarray[np.float64_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
  *                 if ai > max_val:
  *                     raise ValueError("value %i is greater than max_val (%i)"
  *                                      % (ai, max_val))             # <<<<<<<<<<<<<<
- *                 y[i1, ai, bin] += wt
+ *                 y[i1, bin, ai] += wt
  *     return y, nans
  */
           __pyx_t_12 = PyInt_FromLong(__pyx_v_ai); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 345; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":346
  *                     raise ValueError("value %i is greater than max_val (%i)"
  *                                      % (ai, max_val))
- *                 y[i1, ai, bin] += wt             # <<<<<<<<<<<<<<
+ *                 y[i1, bin, ai] += wt             # <<<<<<<<<<<<<<
  *     return y, nans
  * 
  */
         __pyx_t_21 = __pyx_v_i1;
-        __pyx_t_22 = __pyx_v_ai;
-        __pyx_t_23 = __pyx_v_bin;
+        __pyx_t_22 = __pyx_v_bin;
+        __pyx_t_23 = __pyx_v_ai;
         *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_y.diminfo[1].strides, __pyx_t_23, __pyx_pybuffernd_y.diminfo[2].strides) += __pyx_v_wt;
         goto __pyx_L9;
       }
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":347
  *                                      % (ai, max_val))
- *                 y[i1, ai, bin] += wt
+ *                 y[i1, bin, ai] += wt
  *     return y, nans             # <<<<<<<<<<<<<<
  * 
  * @cython.boundscheck(False)
   Py_ssize_t __pyx_t_19;
   Py_ssize_t __pyx_t_20;
   Py_ssize_t __pyx_t_21;
-  int __pyx_t_22;
-  char __pyx_t_23;
+  char __pyx_t_22;
+  int __pyx_t_23;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":367
  * 
  *     cdef:
- *        np.npy_intp *dims = [n1, max_val+1, max_val2+1]             # <<<<<<<<<<<<<<
+ *        np.npy_intp *dims = [n1, max_val2 + 1, max_val + 1]             # <<<<<<<<<<<<<<
  *        np.ndarray[np.float_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
  *        np.npy_intp *nandims = [n1, max_val2+1]
  */
   __pyx_t_7[0] = __pyx_v_n1;
-  __pyx_t_7[1] = (__pyx_v_max_val + 1);
-  __pyx_t_7[2] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[1] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[2] = (__pyx_v_max_val + 1);
   __pyx_v_dims = __pyx_t_7;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":368
  *     cdef:
- *        np.npy_intp *dims = [n1, max_val+1, max_val2+1]
+ *        np.npy_intp *dims = [n1, max_val2 + 1, max_val + 1]
  *        np.ndarray[np.float_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)             # <<<<<<<<<<<<<<
  *        np.npy_intp *nandims = [n1, max_val2+1]
  *        np.ndarray[np.float64_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
   __pyx_t_6 = 0;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":369
- *        np.npy_intp *dims = [n1, max_val+1, max_val2+1]
+ *        np.npy_intp *dims = [n1, max_val2 + 1, max_val + 1]
  *        np.ndarray[np.float_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
  *        np.npy_intp *nandims = [n1, max_val2+1]             # <<<<<<<<<<<<<<
  *        np.ndarray[np.float64_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
  *                 if ai > max_val:
  *                     raise ValueError("value %i is greater than max_val (%i)"
  *                                      % (ai, max_val))             # <<<<<<<<<<<<<<
- *                 y[i1, ai, bin] += wt
+ *                 y[i1, bin, ai] += wt
  *     return y, nans
  */
           __pyx_t_12 = PyInt_FromLong(__pyx_v_ai); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 387; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":388
  *                     raise ValueError("value %i is greater than max_val (%i)"
  *                                      % (ai, max_val))
- *                 y[i1, ai, bin] += wt             # <<<<<<<<<<<<<<
+ *                 y[i1, bin, ai] += wt             # <<<<<<<<<<<<<<
  *     return y, nans
  * 
  */
         __pyx_t_21 = __pyx_v_i1;
-        __pyx_t_22 = __pyx_v_ai;
-        __pyx_t_23 = __pyx_v_bin;
+        __pyx_t_22 = __pyx_v_bin;
+        __pyx_t_23 = __pyx_v_ai;
         *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_y.diminfo[1].strides, __pyx_t_23, __pyx_pybuffernd_y.diminfo[2].strides) += __pyx_v_wt;
         goto __pyx_L9;
       }
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":389
  *                                      % (ai, max_val))
- *                 y[i1, ai, bin] += wt
+ *                 y[i1, bin, ai] += wt
  *     return y, nans             # <<<<<<<<<<<<<<
  * 
  * @cython.boundscheck(False)
   int __pyx_t_25;
   int __pyx_t_26;
   int __pyx_t_27;
-  __pyx_t_5numpy_int8_t __pyx_t_28;
-  char __pyx_t_29;
+  char __pyx_t_28;
+  __pyx_t_5numpy_int8_t __pyx_t_29;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":409
  * 
  *     cdef:
- *         np.npy_intp *dims = [n_cols, max_val+1, max_val2+1]             # <<<<<<<<<<<<<<
+ *         np.npy_intp *dims = [n_cols, max_val2 + 1, max_val + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
  *         np.npy_intp *nandims = [n_cols, max_val2+1]
  */
   __pyx_t_7[0] = __pyx_v_n_cols;
-  __pyx_t_7[1] = (__pyx_v_max_val + 1);
-  __pyx_t_7[2] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[1] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[2] = (__pyx_v_max_val + 1);
   __pyx_v_dims = __pyx_t_7;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":410
  *     cdef:
- *         np.npy_intp *dims = [n_cols, max_val+1, max_val2+1]
+ *         np.npy_intp *dims = [n_cols, max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)             # <<<<<<<<<<<<<<
  *         np.npy_intp *nandims = [n_cols, max_val2+1]
  *         np.ndarray[np.float_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
   __pyx_t_1 = 0;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":411
- *         np.npy_intp *dims = [n_cols, max_val+1, max_val2+1]
+ *         np.npy_intp *dims = [n_cols, max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
  *         np.npy_intp *nandims = [n_cols, max_val2+1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
  *         for i in range(indptr[ri], indptr[ri + 1]):
  *             ci = indices[i]             # <<<<<<<<<<<<<<
  *             if mask is None or mask[ci]:
- *                 y[ci, data[i], bin] += wt
+ *                 y[ci, bin, data[i]] += wt
  */
       __pyx_t_24 = __pyx_v_i;
       __pyx_v_ci = (*__Pyx_BufPtrStrided1d(int *, __pyx_pybuffernd_indices.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_indices.diminfo[0].strides));
  *         for i in range(indptr[ri], indptr[ri + 1]):
  *             ci = indices[i]
  *             if mask is None or mask[ci]:             # <<<<<<<<<<<<<<
- *                 y[ci, data[i], bin] += wt
+ *                 y[ci, bin, data[i]] += wt
  *     return y, nans
  */
       __pyx_t_6 = (((PyObject *)__pyx_v_mask) == Py_None);
         /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":429
  *             ci = indices[i]
  *             if mask is None or mask[ci]:
- *                 y[ci, data[i], bin] += wt             # <<<<<<<<<<<<<<
+ *                 y[ci, bin, data[i]] += wt             # <<<<<<<<<<<<<<
  *     return y, nans
  * 
  */
         __pyx_t_26 = __pyx_v_i;
         __pyx_t_27 = __pyx_v_ci;
-        __pyx_t_28 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int8_t *, __pyx_pybuffernd_data.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_data.diminfo[0].strides));
-        __pyx_t_29 = __pyx_v_bin;
+        __pyx_t_28 = __pyx_v_bin;
+        __pyx_t_29 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int8_t *, __pyx_pybuffernd_data.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_data.diminfo[0].strides));
         *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_28, __pyx_pybuffernd_y.diminfo[1].strides, __pyx_t_29, __pyx_pybuffernd_y.diminfo[2].strides) += __pyx_v_wt;
         goto __pyx_L9;
       }
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":430
  *             if mask is None or mask[ci]:
- *                 y[ci, data[i], bin] += wt
+ *                 y[ci, bin, data[i]] += wt
  *     return y, nans             # <<<<<<<<<<<<<<
  * 
  * 
   int __pyx_t_25;
   int __pyx_t_26;
   int __pyx_t_27;
-  __pyx_t_5numpy_int32_t __pyx_t_28;
-  char __pyx_t_29;
+  char __pyx_t_28;
+  __pyx_t_5numpy_int32_t __pyx_t_29;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":452
  * 
  *     cdef:
- *         np.npy_intp *dims = [n_cols, max_val+1, max_val2+1]             # <<<<<<<<<<<<<<
+ *         np.npy_intp *dims = [n_cols, max_val2 + 1, max_val + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
  *         np.npy_intp *nandims = [n_cols, max_val2+1]
  */
   __pyx_t_7[0] = __pyx_v_n_cols;
-  __pyx_t_7[1] = (__pyx_v_max_val + 1);
-  __pyx_t_7[2] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[1] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[2] = (__pyx_v_max_val + 1);
   __pyx_v_dims = __pyx_t_7;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":453
  *     cdef:
- *         np.npy_intp *dims = [n_cols, max_val+1, max_val2+1]
+ *         np.npy_intp *dims = [n_cols, max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)             # <<<<<<<<<<<<<<
  *         np.npy_intp *nandims = [n_cols, max_val2+1]
  *         np.ndarray[np.float_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
   __pyx_t_1 = 0;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":454
- *         np.npy_intp *dims = [n_cols, max_val+1, max_val2+1]
+ *         np.npy_intp *dims = [n_cols, max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
  *         np.npy_intp *nandims = [n_cols, max_val2+1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
  *         for i in range(indptr[ri], indptr[ri + 1]):
  *             ci = indices[i]             # <<<<<<<<<<<<<<
  *             if mask is None or mask[ci]:
- *                 y[ci, data[i], bin] += wt
+ *                 y[ci, bin, data[i]] += wt
  */
       __pyx_t_24 = __pyx_v_i;
       __pyx_v_ci = (*__Pyx_BufPtrStrided1d(int *, __pyx_pybuffernd_indices.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_indices.diminfo[0].strides));
  *         for i in range(indptr[ri], indptr[ri + 1]):
  *             ci = indices[i]
  *             if mask is None or mask[ci]:             # <<<<<<<<<<<<<<
- *                 y[ci, data[i], bin] += wt
+ *                 y[ci, bin, data[i]] += wt
  *     return y, nans
  */
       __pyx_t_6 = (((PyObject *)__pyx_v_mask) == Py_None);
         /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":472
  *             ci = indices[i]
  *             if mask is None or mask[ci]:
- *                 y[ci, data[i], bin] += wt             # <<<<<<<<<<<<<<
+ *                 y[ci, bin, data[i]] += wt             # <<<<<<<<<<<<<<
  *     return y, nans
  * 
  */
         __pyx_t_26 = __pyx_v_i;
         __pyx_t_27 = __pyx_v_ci;
-        __pyx_t_28 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_data.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_data.diminfo[0].strides));
-        __pyx_t_29 = __pyx_v_bin;
+        __pyx_t_28 = __pyx_v_bin;
+        __pyx_t_29 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_data.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_data.diminfo[0].strides));
         *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_28, __pyx_pybuffernd_y.diminfo[1].strides, __pyx_t_29, __pyx_pybuffernd_y.diminfo[2].strides) += __pyx_v_wt;
         goto __pyx_L9;
       }
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":473
  *             if mask is None or mask[ci]:
- *                 y[ci, data[i], bin] += wt
+ *                 y[ci, bin, data[i]] += wt
  *     return y, nans             # <<<<<<<<<<<<<<
  * 
  * 
   int __pyx_t_25;
   int __pyx_t_26;
   int __pyx_t_27;
-  __pyx_t_5numpy_int64_t __pyx_t_28;
-  char __pyx_t_29;
+  char __pyx_t_28;
+  __pyx_t_5numpy_int64_t __pyx_t_29;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":495
  * 
  *     cdef:
- *         np.npy_intp *dims = [n_cols, max_val+1, max_val2+1]             # <<<<<<<<<<<<<<
+ *         np.npy_intp *dims = [n_cols, max_val2 + 1, max_val + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
  *         np.npy_intp *nandims = [n_cols, max_val2+1]
  */
   __pyx_t_7[0] = __pyx_v_n_cols;
-  __pyx_t_7[1] = (__pyx_v_max_val + 1);
-  __pyx_t_7[2] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[1] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[2] = (__pyx_v_max_val + 1);
   __pyx_v_dims = __pyx_t_7;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":496
  *     cdef:
- *         np.npy_intp *dims = [n_cols, max_val+1, max_val2+1]
+ *         np.npy_intp *dims = [n_cols, max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)             # <<<<<<<<<<<<<<
  *         np.npy_intp *nandims = [n_cols, max_val2+1]
  *         np.ndarray[np.float_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
   __pyx_t_1 = 0;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":497
- *         np.npy_intp *dims = [n_cols, max_val+1, max_val2+1]
+ *         np.npy_intp *dims = [n_cols, max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
  *         np.npy_intp *nandims = [n_cols, max_val2+1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
  *         for i in range(indptr[ri], indptr[ri + 1]):
  *             ci = indices[i]             # <<<<<<<<<<<<<<
  *             if mask is None or mask[ci]:
- *                 y[ci, data[i], bin] += wt
+ *                 y[ci, bin, data[i]] += wt
  */
       __pyx_t_24 = __pyx_v_i;
       __pyx_v_ci = (*__Pyx_BufPtrStrided1d(int *, __pyx_pybuffernd_indices.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_indices.diminfo[0].strides));
  *         for i in range(indptr[ri], indptr[ri + 1]):
  *             ci = indices[i]
  *             if mask is None or mask[ci]:             # <<<<<<<<<<<<<<
- *                 y[ci, data[i], bin] += wt
+ *                 y[ci, bin, data[i]] += wt
  *     return y, nans
  */
       __pyx_t_6 = (((PyObject *)__pyx_v_mask) == Py_None);
         /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":515
  *             ci = indices[i]
  *             if mask is None or mask[ci]:
- *                 y[ci, data[i], bin] += wt             # <<<<<<<<<<<<<<
+ *                 y[ci, bin, data[i]] += wt             # <<<<<<<<<<<<<<
  *     return y, nans
  * 
  */
         __pyx_t_26 = __pyx_v_i;
         __pyx_t_27 = __pyx_v_ci;
-        __pyx_t_28 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_data.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_data.diminfo[0].strides));
-        __pyx_t_29 = __pyx_v_bin;
+        __pyx_t_28 = __pyx_v_bin;
+        __pyx_t_29 = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int64_t *, __pyx_pybuffernd_data.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_data.diminfo[0].strides));
         *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_28, __pyx_pybuffernd_y.diminfo[1].strides, __pyx_t_29, __pyx_pybuffernd_y.diminfo[2].strides) += __pyx_v_wt;
         goto __pyx_L9;
       }
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":516
  *             if mask is None or mask[ci]:
- *                 y[ci, data[i], bin] += wt
+ *                 y[ci, bin, data[i]] += wt
  *     return y, nans             # <<<<<<<<<<<<<<
  * 
  * 
   Py_ssize_t __pyx_t_15;
   char __pyx_t_16;
   float __pyx_t_17;
-  int __pyx_t_18;
-  char __pyx_t_19;
+  char __pyx_t_18;
+  int __pyx_t_19;
   Py_ssize_t __pyx_t_20;
   Py_ssize_t __pyx_t_21;
   char __pyx_t_22;
   Py_ssize_t __pyx_t_23;
-  int __pyx_t_24;
-  char __pyx_t_25;
+  char __pyx_t_24;
+  int __pyx_t_25;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":539
  * 
  *     cdef:
- *         np.npy_intp *dims = [max_val+1, max_val2+1]             # <<<<<<<<<<<<<<
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)
- *         np.npy_intp *nandims = [max_val2+1]
- */
-  __pyx_t_6[0] = (__pyx_v_max_val + 1);
-  __pyx_t_6[1] = (__pyx_v_max_val2 + 1);
+ *         np.npy_intp *nandims = [max_val2 + 1]
+ */
+  __pyx_t_6[0] = (__pyx_v_max_val2 + 1);
+  __pyx_t_6[1] = (__pyx_v_max_val + 1);
   __pyx_v_dims = __pyx_t_6;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":540
  *     cdef:
- *         np.npy_intp *dims = [max_val+1, max_val2+1]
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)             # <<<<<<<<<<<<<<
- *         np.npy_intp *nandims = [max_val2+1]
+ *         np.npy_intp *nandims = [max_val2 + 1]
  *         np.ndarray[np.float_t, ndim=1] nans = PyArray_ZEROS(1, nandims, NPY_float64, 0)
  */
   __pyx_t_3 = PyArray_ZEROS(2, __pyx_v_dims, NPY_FLOAT64, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 540; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_t_3 = 0;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":541
- *         np.npy_intp *dims = [max_val+1, max_val2+1]
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)
- *         np.npy_intp *nandims = [max_val2+1]             # <<<<<<<<<<<<<<
+ *         np.npy_intp *nandims = [max_val2 + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float_t, ndim=1] nans = PyArray_ZEROS(1, nandims, NPY_float64, 0)
  *         int ain
  */
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":542
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)
- *         np.npy_intp *nandims = [max_val2+1]
+ *         np.npy_intp *nandims = [max_val2 + 1]
  *         np.ndarray[np.float_t, ndim=1] nans = PyArray_ZEROS(1, nandims, NPY_float64, 0)             # <<<<<<<<<<<<<<
  *         int ain
  *         char bin
  *             if ain > max_val:
  *                 raise ValueError("value %i is greater than max_val (%i)" %
  *                                  (ain, max_val))             # <<<<<<<<<<<<<<
- *             y[ain, bin] += 1
+ *             y[bin, ain] += 1
  *     else:
  */
         __pyx_t_14 = PyInt_FromLong(__pyx_v_ain); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 565; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":566
  *                 raise ValueError("value %i is greater than max_val (%i)" %
  *                                  (ain, max_val))
- *             y[ain, bin] += 1             # <<<<<<<<<<<<<<
- *     else:
- *         for i0 in range(n0):
- */
-      __pyx_t_18 = __pyx_v_ain;
-      __pyx_t_19 = __pyx_v_bin;
+ *             y[bin, ain] += 1             # <<<<<<<<<<<<<<
+ *     else:
+ *         for i0 in range(n0):
+ */
+      __pyx_t_18 = __pyx_v_bin;
+      __pyx_t_19 = __pyx_v_ain;
       *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_19, __pyx_pybuffernd_y.diminfo[1].strides) += 1.0;
       __pyx_L7_continue:;
     }
   /*else*/ {
 
     /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":568
- *             y[ain, bin] += 1
+ *             y[bin, ain] += 1
  *     else:
  *         for i0 in range(n0):             # <<<<<<<<<<<<<<
  *             wt = w[i0]
  *             if bin > max_val2:
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))             # <<<<<<<<<<<<<<
- *             y[ain, bin] += wt
+ *             y[bin, ain] += wt
  *     return y, nans
  */
         __pyx_t_3 = PyInt_FromLong(__pyx_v_bin); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 582; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":583
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))
- *             y[ain, bin] += wt             # <<<<<<<<<<<<<<
+ *             y[bin, ain] += wt             # <<<<<<<<<<<<<<
  *     return y, nans
  * 
  */
-      __pyx_t_24 = __pyx_v_ain;
-      __pyx_t_25 = __pyx_v_bin;
+      __pyx_t_24 = __pyx_v_bin;
+      __pyx_t_25 = __pyx_v_ain;
       *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_25, __pyx_pybuffernd_y.diminfo[1].strides) += __pyx_v_wt;
       __pyx_L14_continue:;
     }
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":584
  *                                  (bin, max_val2))
- *             y[ain, bin] += wt
+ *             y[bin, ain] += wt
  *     return y, nans             # <<<<<<<<<<<<<<
  * 
  * @cython.boundscheck(False)
   Py_ssize_t __pyx_t_15;
   char __pyx_t_16;
   float __pyx_t_17;
-  int __pyx_t_18;
-  char __pyx_t_19;
+  char __pyx_t_18;
+  int __pyx_t_19;
   Py_ssize_t __pyx_t_20;
   Py_ssize_t __pyx_t_21;
   char __pyx_t_22;
   Py_ssize_t __pyx_t_23;
-  int __pyx_t_24;
-  char __pyx_t_25;
+  char __pyx_t_24;
+  int __pyx_t_25;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":605
  * 
  *     cdef:
- *         np.npy_intp *dims = [max_val+1, max_val2+1]             # <<<<<<<<<<<<<<
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)
- *         np.npy_intp *nandims = [max_val2+1]
- */
-  __pyx_t_6[0] = (__pyx_v_max_val + 1);
-  __pyx_t_6[1] = (__pyx_v_max_val2 + 1);
+ *         np.npy_intp *nandims = [max_val2 + 1]
+ */
+  __pyx_t_6[0] = (__pyx_v_max_val2 + 1);
+  __pyx_t_6[1] = (__pyx_v_max_val + 1);
   __pyx_v_dims = __pyx_t_6;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":606
  *     cdef:
- *         np.npy_intp *dims = [max_val+1, max_val2+1]
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)             # <<<<<<<<<<<<<<
- *         np.npy_intp *nandims = [max_val2+1]
+ *         np.npy_intp *nandims = [max_val2 + 1]
  *         np.ndarray[np.float_t, ndim=1] nans = PyArray_ZEROS(1, nandims, NPY_float64, 0)
  */
   __pyx_t_3 = PyArray_ZEROS(2, __pyx_v_dims, NPY_FLOAT64, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 606; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_t_3 = 0;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":607
- *         np.npy_intp *dims = [max_val+1, max_val2+1]
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)
- *         np.npy_intp *nandims = [max_val2+1]             # <<<<<<<<<<<<<<
+ *         np.npy_intp *nandims = [max_val2 + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float_t, ndim=1] nans = PyArray_ZEROS(1, nandims, NPY_float64, 0)
  *         int ain
  */
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":608
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)
- *         np.npy_intp *nandims = [max_val2+1]
+ *         np.npy_intp *nandims = [max_val2 + 1]
  *         np.ndarray[np.float_t, ndim=1] nans = PyArray_ZEROS(1, nandims, NPY_float64, 0)             # <<<<<<<<<<<<<<
  *         int ain
  *         char bin
  *             if ain > max_val:
  *                 raise ValueError("value %i is greater than max_val (%i)" %
  *                                  (ain, max_val))             # <<<<<<<<<<<<<<
- *             y[ain, bin] += 1
+ *             y[bin, ain] += 1
  *     else:
  */
         __pyx_t_14 = PyInt_FromLong(__pyx_v_ain); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":632
  *                 raise ValueError("value %i is greater than max_val (%i)" %
  *                                  (ain, max_val))
- *             y[ain, bin] += 1             # <<<<<<<<<<<<<<
- *     else:
- *         for i0 in range(n0):
- */
-      __pyx_t_18 = __pyx_v_ain;
-      __pyx_t_19 = __pyx_v_bin;
+ *             y[bin, ain] += 1             # <<<<<<<<<<<<<<
+ *     else:
+ *         for i0 in range(n0):
+ */
+      __pyx_t_18 = __pyx_v_bin;
+      __pyx_t_19 = __pyx_v_ain;
       *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_19, __pyx_pybuffernd_y.diminfo[1].strides) += 1.0;
       __pyx_L7_continue:;
     }
   /*else*/ {
 
     /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":634
- *             y[ain, bin] += 1
+ *             y[bin, ain] += 1
  *     else:
  *         for i0 in range(n0):             # <<<<<<<<<<<<<<
  *             wt = w[i0]
  *             if bin > max_val2:
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))             # <<<<<<<<<<<<<<
- *             y[ain, bin] += wt
+ *             y[bin, ain] += wt
  *     return y, nans
  */
         __pyx_t_3 = PyInt_FromLong(__pyx_v_bin); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 648; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":649
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))
- *             y[ain, bin] += wt             # <<<<<<<<<<<<<<
+ *             y[bin, ain] += wt             # <<<<<<<<<<<<<<
  *     return y, nans
  * 
  */
-      __pyx_t_24 = __pyx_v_ain;
-      __pyx_t_25 = __pyx_v_bin;
+      __pyx_t_24 = __pyx_v_bin;
+      __pyx_t_25 = __pyx_v_ain;
       *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_25, __pyx_pybuffernd_y.diminfo[1].strides) += __pyx_v_wt;
       __pyx_L14_continue:;
     }
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":650
  *                                  (bin, max_val2))
- *             y[ain, bin] += wt
+ *             y[bin, ain] += wt
  *     return y, nans             # <<<<<<<<<<<<<<
  * 
  * @cython.boundscheck(False)
   char __pyx_t_22;
   float __pyx_t_23;
   Py_ssize_t __pyx_t_24;
-  int __pyx_t_25;
-  char __pyx_t_26;
+  char __pyx_t_25;
+  int __pyx_t_26;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":672
  * 
  *     cdef:
- *        np.npy_intp *dims = [n1, max_val+1, max_val2+1]             # <<<<<<<<<<<<<<
+ *        np.npy_intp *dims = [n1, max_val2 + 1, max_val + 1]             # <<<<<<<<<<<<<<
  *        np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
- *        np.npy_intp *nandims = [n1, max_val2+1]
+ *        np.npy_intp *nandims = [n1, max_val2 + 1]
  */
   __pyx_t_7[0] = __pyx_v_n1;
-  __pyx_t_7[1] = (__pyx_v_max_val + 1);
-  __pyx_t_7[2] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[1] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[2] = (__pyx_v_max_val + 1);
   __pyx_v_dims = __pyx_t_7;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":673
  *     cdef:
- *        np.npy_intp *dims = [n1, max_val+1, max_val2+1]
+ *        np.npy_intp *dims = [n1, max_val2 + 1, max_val + 1]
  *        np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)             # <<<<<<<<<<<<<<
- *        np.npy_intp *nandims = [n1, max_val2+1]
+ *        np.npy_intp *nandims = [n1, max_val2 + 1]
  *        np.ndarray[np.float_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
  */
   __pyx_t_3 = PyArray_ZEROS(3, __pyx_v_dims, NPY_FLOAT64, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 673; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_t_3 = 0;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":674
- *        np.npy_intp *dims = [n1, max_val+1, max_val2+1]
+ *        np.npy_intp *dims = [n1, max_val2 + 1, max_val + 1]
  *        np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
- *        np.npy_intp *nandims = [n1, max_val2+1]             # <<<<<<<<<<<<<<
+ *        np.npy_intp *nandims = [n1, max_val2 + 1]             # <<<<<<<<<<<<<<
  *        np.ndarray[np.float_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
  *        int ain
  */
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":675
  *        np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
- *        np.npy_intp *nandims = [n1, max_val2+1]
+ *        np.npy_intp *nandims = [n1, max_val2 + 1]
  *        np.ndarray[np.float_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)             # <<<<<<<<<<<<<<
  *        int ain
  *        char bin
  *                 if ain > max_val:
  *                     raise ValueError("value %i is greater than max_val (%i)" %
  *                                      (ain, max_val))             # <<<<<<<<<<<<<<
- *                 y[i1, ain, bin] += wt
+ *                 y[i1, bin, ain] += wt
  *     return y, nans
  */
           __pyx_t_15 = PyInt_FromLong(__pyx_v_ain); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 698; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":699
  *                     raise ValueError("value %i is greater than max_val (%i)" %
  *                                      (ain, max_val))
- *                 y[i1, ain, bin] += wt             # <<<<<<<<<<<<<<
+ *                 y[i1, bin, ain] += wt             # <<<<<<<<<<<<<<
  *     return y, nans
  * 
  */
         __pyx_t_24 = __pyx_v_i1;
-        __pyx_t_25 = __pyx_v_ain;
-        __pyx_t_26 = __pyx_v_bin;
+        __pyx_t_25 = __pyx_v_bin;
+        __pyx_t_26 = __pyx_v_ain;
         *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_25, __pyx_pybuffernd_y.diminfo[1].strides, __pyx_t_26, __pyx_pybuffernd_y.diminfo[2].strides) += __pyx_v_wt;
         goto __pyx_L10;
       }
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":700
  *                                      (ain, max_val))
- *                 y[i1, ain, bin] += wt
+ *                 y[i1, bin, ain] += wt
  *     return y, nans             # <<<<<<<<<<<<<<
  * 
  * @cython.boundscheck(False)
   char __pyx_t_22;
   float __pyx_t_23;
   Py_ssize_t __pyx_t_24;
-  int __pyx_t_25;
-  char __pyx_t_26;
+  char __pyx_t_25;
+  int __pyx_t_26;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":722
  * 
  *     cdef:
- *        np.npy_intp *dims = [n1, max_val+1, max_val2+1]             # <<<<<<<<<<<<<<
+ *        np.npy_intp *dims = [n1, max_val2 + 1, max_val + 1]             # <<<<<<<<<<<<<<
  *        np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
- *        np.npy_intp *nandims = [n1, max_val2+1]
+ *        np.npy_intp *nandims = [n1, max_val2 + 1]
  */
   __pyx_t_7[0] = __pyx_v_n1;
-  __pyx_t_7[1] = (__pyx_v_max_val + 1);
-  __pyx_t_7[2] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[1] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[2] = (__pyx_v_max_val + 1);
   __pyx_v_dims = __pyx_t_7;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":723
  *     cdef:
- *        np.npy_intp *dims = [n1, max_val+1, max_val2+1]
+ *        np.npy_intp *dims = [n1, max_val2 + 1, max_val + 1]
  *        np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)             # <<<<<<<<<<<<<<
- *        np.npy_intp *nandims = [n1, max_val2+1]
+ *        np.npy_intp *nandims = [n1, max_val2 + 1]
  *        np.ndarray[np.float_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
  */
   __pyx_t_3 = PyArray_ZEROS(3, __pyx_v_dims, NPY_FLOAT64, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 723; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_t_3 = 0;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":724
- *        np.npy_intp *dims = [n1, max_val+1, max_val2+1]
+ *        np.npy_intp *dims = [n1, max_val2 + 1, max_val + 1]
  *        np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
- *        np.npy_intp *nandims = [n1, max_val2+1]             # <<<<<<<<<<<<<<
+ *        np.npy_intp *nandims = [n1, max_val2 + 1]             # <<<<<<<<<<<<<<
  *        np.ndarray[np.float_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
  *        int ain
  */
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":725
  *        np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
- *        np.npy_intp *nandims = [n1, max_val2+1]
+ *        np.npy_intp *nandims = [n1, max_val2 + 1]
  *        np.ndarray[np.float_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)             # <<<<<<<<<<<<<<
  *        int ain
  *        char bin
  *                 if ain > max_val:
  *                     raise ValueError("value %i is greater than max_val (%i)" %
  *                                      (ain, max_val))             # <<<<<<<<<<<<<<
- *                 y[i1, ain, bin] += wt
+ *                 y[i1, bin, ain] += wt
  *     return y, nans
  */
           __pyx_t_15 = PyInt_FromLong(__pyx_v_ain); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":749
  *                     raise ValueError("value %i is greater than max_val (%i)" %
  *                                      (ain, max_val))
- *                 y[i1, ain, bin] += wt             # <<<<<<<<<<<<<<
+ *                 y[i1, bin, ain] += wt             # <<<<<<<<<<<<<<
  *     return y, nans
  * 
  */
         __pyx_t_24 = __pyx_v_i1;
-        __pyx_t_25 = __pyx_v_ain;
-        __pyx_t_26 = __pyx_v_bin;
+        __pyx_t_25 = __pyx_v_bin;
+        __pyx_t_26 = __pyx_v_ain;
         *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_25, __pyx_pybuffernd_y.diminfo[1].strides, __pyx_t_26, __pyx_pybuffernd_y.diminfo[2].strides) += __pyx_v_wt;
         goto __pyx_L10;
       }
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":750
  *                                      (ain, max_val))
- *                 y[i1, ain, bin] += wt
+ *                 y[i1, bin, ain] += wt
  *     return y, nans             # <<<<<<<<<<<<<<
  * 
  * @cython.boundscheck(False)
   char __pyx_t_29;
   __pyx_t_5numpy_float32_t __pyx_t_30;
   int __pyx_t_31;
-  int __pyx_t_32;
-  char __pyx_t_33;
+  char __pyx_t_32;
+  int __pyx_t_33;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":772
  * 
  *     cdef:
- *         np.npy_intp *dims = [n_cols, max_val+1, max_val2+1]             # <<<<<<<<<<<<<<
+ *         np.npy_intp *dims = [n_cols, max_val2 + 1, max_val + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
- *         np.npy_intp *nandims = [n_cols, max_val2+1]
+ *         np.npy_intp *nandims = [n_cols, max_val2 + 1]
  */
   __pyx_t_7[0] = __pyx_v_n_cols;
-  __pyx_t_7[1] = (__pyx_v_max_val + 1);
-  __pyx_t_7[2] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[1] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[2] = (__pyx_v_max_val + 1);
   __pyx_v_dims = __pyx_t_7;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":773
  *     cdef:
- *         np.npy_intp *dims = [n_cols, max_val+1, max_val2+1]
+ *         np.npy_intp *dims = [n_cols, max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)             # <<<<<<<<<<<<<<
- *         np.npy_intp *nandims = [n_cols, max_val2+1]
+ *         np.npy_intp *nandims = [n_cols, max_val2 + 1]
  *         np.ndarray[np.float_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
  */
   __pyx_t_1 = PyArray_ZEROS(3, __pyx_v_dims, NPY_FLOAT64, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_t_1 = 0;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":774
- *         np.npy_intp *dims = [n_cols, max_val+1, max_val2+1]
+ *         np.npy_intp *dims = [n_cols, max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
- *         np.npy_intp *nandims = [n_cols, max_val2+1]             # <<<<<<<<<<<<<<
+ *         np.npy_intp *nandims = [n_cols, max_val2 + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
  *         float wt
  */
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":775
  *         np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
- *         np.npy_intp *nandims = [n_cols, max_val2+1]
+ *         np.npy_intp *nandims = [n_cols, max_val2 + 1]
  *         np.ndarray[np.float_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)             # <<<<<<<<<<<<<<
  *         float wt
  * 
  *                 if ain > max_val:
  *                     raise ValueError("value %i is greater than max_val (%i)" %
  *                                      (ain, max_val))             # <<<<<<<<<<<<<<
- *                 y[ci, ain, bin] += wt
+ *                 y[ci, bin, ain] += wt
  *     return y, nans
  */
           __pyx_t_19 = PyInt_FromLong(__pyx_v_ain); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":804
  *                     raise ValueError("value %i is greater than max_val (%i)" %
  *                                      (ain, max_val))
- *                 y[ci, ain, bin] += wt             # <<<<<<<<<<<<<<
+ *                 y[ci, bin, ain] += wt             # <<<<<<<<<<<<<<
  *     return y, nans
  * 
  */
         __pyx_t_31 = __pyx_v_ci;
-        __pyx_t_32 = __pyx_v_ain;
-        __pyx_t_33 = __pyx_v_bin;
+        __pyx_t_32 = __pyx_v_bin;
+        __pyx_t_33 = __pyx_v_ain;
         *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_31, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_32, __pyx_pybuffernd_y.diminfo[1].strides, __pyx_t_33, __pyx_pybuffernd_y.diminfo[2].strides) += __pyx_v_wt;
         goto __pyx_L10;
       }
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":805
  *                                      (ain, max_val))
- *                 y[ci, ain, bin] += wt
+ *                 y[ci, bin, ain] += wt
  *     return y, nans             # <<<<<<<<<<<<<<
  * 
  * 
   char __pyx_t_29;
   __pyx_t_5numpy_float64_t __pyx_t_30;
   int __pyx_t_31;
-  int __pyx_t_32;
-  char __pyx_t_33;
+  char __pyx_t_32;
+  int __pyx_t_33;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":829
  * 
  *     cdef:
- *         np.npy_intp *dims = [n_cols, max_val+1, max_val2+1]             # <<<<<<<<<<<<<<
+ *         np.npy_intp *dims = [n_cols, max_val2 + 1, max_val + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
- *         np.npy_intp *nandims = [n_cols, max_val2+1]
+ *         np.npy_intp *nandims = [n_cols, max_val2 + 1]
  */
   __pyx_t_7[0] = __pyx_v_n_cols;
-  __pyx_t_7[1] = (__pyx_v_max_val + 1);
-  __pyx_t_7[2] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[1] = (__pyx_v_max_val2 + 1);
+  __pyx_t_7[2] = (__pyx_v_max_val + 1);
   __pyx_v_dims = __pyx_t_7;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":830
  *     cdef:
- *         np.npy_intp *dims = [n_cols, max_val+1, max_val2+1]
+ *         np.npy_intp *dims = [n_cols, max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)             # <<<<<<<<<<<<<<
- *         np.npy_intp *nandims = [n_cols, max_val2+1]
+ *         np.npy_intp *nandims = [n_cols, max_val2 + 1]
  *         np.ndarray[np.float_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
  */
   __pyx_t_1 = PyArray_ZEROS(3, __pyx_v_dims, NPY_FLOAT64, 0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
   __pyx_t_1 = 0;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":831
- *         np.npy_intp *dims = [n_cols, max_val+1, max_val2+1]
+ *         np.npy_intp *dims = [n_cols, max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
- *         np.npy_intp *nandims = [n_cols, max_val2+1]             # <<<<<<<<<<<<<<
+ *         np.npy_intp *nandims = [n_cols, max_val2 + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)
  *         float wt
  */
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":832
  *         np.ndarray[np.float64_t, ndim=3] y = PyArray_ZEROS(3, dims, NPY_float64, 0)
- *         np.npy_intp *nandims = [n_cols, max_val2+1]
+ *         np.npy_intp *nandims = [n_cols, max_val2 + 1]
  *         np.ndarray[np.float_t, ndim=2] nans = PyArray_ZEROS(2, nandims, NPY_float64, 0)             # <<<<<<<<<<<<<<
  *         float wt
  * 
  *                 if ain > max_val:
  *                     raise ValueError("value %i is greater than max_val (%i)" %
  *                                      (ain, max_val))             # <<<<<<<<<<<<<<
- *                 y[ci, ain, bin] += wt
+ *                 y[ci, bin, ain] += wt
  *     return y, nans
  */
           __pyx_t_19 = PyInt_FromLong(__pyx_v_ain); if (unlikely(!__pyx_t_19)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 860; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
         /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":861
  *                     raise ValueError("value %i is greater than max_val (%i)" %
  *                                      (ain, max_val))
- *                 y[ci, ain, bin] += wt             # <<<<<<<<<<<<<<
+ *                 y[ci, bin, ain] += wt             # <<<<<<<<<<<<<<
  *     return y, nans
  * 
  */
         __pyx_t_31 = __pyx_v_ci;
-        __pyx_t_32 = __pyx_v_ain;
-        __pyx_t_33 = __pyx_v_bin;
+        __pyx_t_32 = __pyx_v_bin;
+        __pyx_t_33 = __pyx_v_ain;
         *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_31, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_32, __pyx_pybuffernd_y.diminfo[1].strides, __pyx_t_33, __pyx_pybuffernd_y.diminfo[2].strides) += __pyx_v_wt;
         goto __pyx_L10;
       }
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/32bit/contingency.pyx":862
  *                                      (ain, max_val))
- *                 y[ci, ain, bin] += wt
+ *                 y[ci, bin, ain] += wt
  *     return y, nans             # <<<<<<<<<<<<<<
  * 
  * 

File bottleneck/src/func/64bit/func.c

-/* Generated by Cython 0.17.2 on Tue Jan  1 17:14:09 2013 */
+/* Generated by Cython 0.17.2 on Thu Jan  3 17:03:18 2013 */
 
 #define PY_SSIZE_T_CLEAN
 #include "Python.h"
 
 /* Python wrapper */
 static PyObject *__pyx_pw_4func_2141contingency(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
-static char __pyx_doc_4func_2140contingency[] = "contingency(arr, b, max_val, max_val2, weights=None, mask=None)\n\n    Compute the contingency matrices for each column (excluding the masked)\n    versus the vector b.\n\n    If the array is 1-dimensional, a 2d contingency matrix is returned. If the\n    array is 2d, the function returns a 3d array, with the first dimension\n    corresponding to column index (variable in the input array).\n\n    The rows of contingency matrix correspond to values of variables, the\n    columns correspond to values in vector `b`. The number of rows is\n    `max_val+1`, the nuber of columns is `max_val2+1`.\n\n    Rows in the input array can be weights (argument `weights`). A subset of\n    columns can be selected by additional argument `mask`.\n\n    The function also returns a count of NaN values per each value of `b`.\n\n    Parameters\n    ----------\n    x : array_like, 1 or 2 dimensions, nonnegative elements\n        Input array.\n    b : array_like, 1 dimension, of type int8\n        The values of the second variable.\n    max_val : int\n        The maximal value in the array\n    max_val2 : int\n        The maximal value in `b`\n    weights : array_like, optional\n        Weights, array of the same length as `x`.\n    mask: array_like, of type char (interpreted as bool)\n        Selects the columns\n\n    Returns\n    -------\n    out : ndarray of ints, 1- or 2-dimensional\n        The result of binning the input array.\n    nans: the number of NaNs; a 1-d vector of length `max_val`, or 2-d array `(x.shape[1], max_val2)`\n\n    Raises\n    ------\n    ValueError\n        If the input is not 1- or 2-dimensional, or contains elements that are\n        not close enough to integers, negative or grater than max_val, or if the\n        length of the weight vector does not match the length of the array\n\n    ";
+static char __pyx_doc_4func_2140contingency[] = "contingency(arr, b, max_val, max_val2, weights=None, mask=None)\n\n    Compute the contingency matrices for each column (excluding the masked)\n    versus the vector b.\n\n    If the array is 1-dimensional, a 2d contingency matrix is returned. If the\n    array is 2d, the function returns a 3d array, with the first dimension\n    corresponding to column index (variable in the input array).\n\n    The rows of contingency matrix correspond to values of variables, the\n    columns correspond to values in vector `b`. The number of rows is\n    `max_val+1`, the nuber of columns is `max_val2+1`.\n\n    Rows in the input array can be weights (argument `weights`). A subset of\n    columns can be selected by additional argument `mask`.\n\n    The function also returns a count of NaN values per each value of `b`.\n\n    Parameters\n    ----------\n    x : array_like, 1 or 2 dimensions, nonnegative elements\n        Input array.\n    b : array_like, 1 dimension, of type int8\n        The values of the second variable.\n    max_val : int\n        The maximal value in the array\n    max_val2 : int\n        The maximal value in `b`\n    weights : array_like, optional\n        Weights, array of the same length as `x`.\n    mask: array_like, of type char (interpreted as bool)\n        Selects the columns\n\n    Returns\n    -------\n    out : ndarray of ints, 1- or 2-dimensional\n        The result of binning the input array.\n    nans: the number of NaNs; a 1-d vector of length `max_val`, or 2-d array `(max_val2, x.shape[1])`\n\n    Raises\n    ------\n    ValueError\n        If the input is not 1- or 2-dimensional, or contains elements that are\n        not close enough to integers, negative or grater than max_val, or if the\n        length of the weight vector does not match the length of the array\n\n    ";
 static PyMethodDef __pyx_mdef_4func_2141contingency = {__Pyx_NAMESTR("contingency"), (PyCFunction)__pyx_pw_4func_2141contingency, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_4func_2140contingency)};
 static PyObject *__pyx_pw_4func_2141contingency(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
   PyObject *__pyx_v_arr = 0;
   PyObject *__pyx_t_13 = NULL;
   PyObject *__pyx_t_14 = NULL;
   Py_ssize_t __pyx_t_15;
-  int __pyx_t_16;
-  char __pyx_t_17;
+  char __pyx_t_16;
+  int __pyx_t_17;
   Py_ssize_t __pyx_t_18;
   Py_ssize_t __pyx_t_19;
   Py_ssize_t __pyx_t_20;
-  int __pyx_t_21;
-  char __pyx_t_22;
+  char __pyx_t_21;
+  int __pyx_t_22;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":123
  * 
  *     cdef:
- *         np.npy_intp *dims = [max_val + 1, max_val2 + 1]             # <<<<<<<<<<<<<<
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)
  *         np.npy_intp *nandims = [max_val2 + 1]
  */
-  __pyx_t_6[0] = (__pyx_v_max_val + 1);
-  __pyx_t_6[1] = (__pyx_v_max_val2 + 1);
+  __pyx_t_6[0] = (__pyx_v_max_val2 + 1);
+  __pyx_t_6[1] = (__pyx_v_max_val + 1);
   __pyx_v_dims = __pyx_t_6;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":124
  *     cdef:
- *         np.npy_intp *dims = [max_val + 1, max_val2 + 1]
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)             # <<<<<<<<<<<<<<
  *         np.npy_intp *nandims = [max_val2 + 1]
  *         np.ndarray[np.float_t, ndim=1] nans = PyArray_ZEROS(1, nandims, NPY_float64, 0)
   __pyx_t_5 = 0;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":125
- *         np.npy_intp *dims = [max_val + 1, max_val2 + 1]
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)
  *         np.npy_intp *nandims = [max_val2 + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float_t, ndim=1] nans = PyArray_ZEROS(1, nandims, NPY_float64, 0)
  *             if bin > max_val2:
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))             # <<<<<<<<<<<<<<
- *             y[ai, bin] += 1
+ *             y[bin, ai] += 1
  *     else:
  */
         __pyx_t_13 = PyInt_FromLong(__pyx_v_bin); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 142; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":143
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))
- *             y[ai, bin] += 1             # <<<<<<<<<<<<<<
- *     else:
- *         for i0 in range(n0):
- */
-      __pyx_t_16 = __pyx_v_ai;
-      __pyx_t_17 = __pyx_v_bin;
+ *             y[bin, ai] += 1             # <<<<<<<<<<<<<<
+ *     else:
+ *         for i0 in range(n0):
+ */
+      __pyx_t_16 = __pyx_v_bin;
+      __pyx_t_17 = __pyx_v_ai;
       *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_17, __pyx_pybuffernd_y.diminfo[1].strides) += 1.0;
     }
     goto __pyx_L5;
   /*else*/ {
 
     /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":145
- *             y[ai, bin] += 1
+ *             y[bin, ai] += 1
  *     else:
  *         for i0 in range(n0):             # <<<<<<<<<<<<<<
  *             ai = a[i0]
  *             if bin > max_val2:
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))             # <<<<<<<<<<<<<<
- *             y[ai, bin] += w[i0]
+ *             y[bin, ai] += w[i0]
  *     return y, nans
  */
         __pyx_t_5 = PyInt_FromLong(__pyx_v_bin); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":156
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))
- *             y[ai, bin] += w[i0]             # <<<<<<<<<<<<<<
+ *             y[bin, ai] += w[i0]             # <<<<<<<<<<<<<<
  *     return y, nans
  * 
  */
       __pyx_t_20 = __pyx_v_i0;
-      __pyx_t_21 = __pyx_v_ai;
-      __pyx_t_22 = __pyx_v_bin;
+      __pyx_t_21 = __pyx_v_bin;
+      __pyx_t_22 = __pyx_v_ai;
       *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_y.diminfo[1].strides) += (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_w.diminfo[0].strides));
     }
   }
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":157
  *                                  (bin, max_val2))
- *             y[ai, bin] += w[i0]
+ *             y[bin, ai] += w[i0]
  *     return y, nans             # <<<<<<<<<<<<<<
  * 
  * @cython.boundscheck(False)
   PyObject *__pyx_t_13 = NULL;
   PyObject *__pyx_t_14 = NULL;
   Py_ssize_t __pyx_t_15;
-  int __pyx_t_16;
-  char __pyx_t_17;
+  char __pyx_t_16;
+  int __pyx_t_17;
   Py_ssize_t __pyx_t_18;
   Py_ssize_t __pyx_t_19;
   Py_ssize_t __pyx_t_20;
-  int __pyx_t_21;
-  char __pyx_t_22;
+  char __pyx_t_21;
+  int __pyx_t_22;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":176
  * 
  *     cdef:
- *         np.npy_intp *dims = [max_val + 1, max_val2 + 1]             # <<<<<<<<<<<<<<
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)
  *         np.npy_intp *nandims = [max_val2 + 1]
  */
-  __pyx_t_6[0] = (__pyx_v_max_val + 1);
-  __pyx_t_6[1] = (__pyx_v_max_val2 + 1);
+  __pyx_t_6[0] = (__pyx_v_max_val2 + 1);
+  __pyx_t_6[1] = (__pyx_v_max_val + 1);
   __pyx_v_dims = __pyx_t_6;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":177
  *     cdef:
- *         np.npy_intp *dims = [max_val + 1, max_val2 + 1]
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)             # <<<<<<<<<<<<<<
  *         np.npy_intp *nandims = [max_val2 + 1]
  *         np.ndarray[np.float_t, ndim=1] nans = PyArray_ZEROS(1, nandims, NPY_float64, 0)
   __pyx_t_5 = 0;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":178
- *         np.npy_intp *dims = [max_val + 1, max_val2 + 1]
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)
  *         np.npy_intp *nandims = [max_val2 + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float_t, ndim=1] nans = PyArray_ZEROS(1, nandims, NPY_float64, 0)
  *             if bin > max_val2:
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))             # <<<<<<<<<<<<<<
- *             y[ai, bin] += 1
+ *             y[bin, ai] += 1
  *     else:
  */
         __pyx_t_13 = PyInt_FromLong(__pyx_v_bin); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 195; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":196
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))
- *             y[ai, bin] += 1             # <<<<<<<<<<<<<<
- *     else:
- *         for i0 in range(n0):
- */
-      __pyx_t_16 = __pyx_v_ai;
-      __pyx_t_17 = __pyx_v_bin;
+ *             y[bin, ai] += 1             # <<<<<<<<<<<<<<
+ *     else:
+ *         for i0 in range(n0):
+ */
+      __pyx_t_16 = __pyx_v_bin;
+      __pyx_t_17 = __pyx_v_ai;
       *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_17, __pyx_pybuffernd_y.diminfo[1].strides) += 1.0;
     }
     goto __pyx_L5;
   /*else*/ {
 
     /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":198
- *             y[ai, bin] += 1
+ *             y[bin, ai] += 1
  *     else:
  *         for i0 in range(n0):             # <<<<<<<<<<<<<<
  *             ai = a[i0]
  *             if bin > max_val2:
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))             # <<<<<<<<<<<<<<
- *             y[ai, bin] += w[i0]
+ *             y[bin, ai] += w[i0]
  *     return y, nans
  */
         __pyx_t_5 = PyInt_FromLong(__pyx_v_bin); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 208; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":209
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))
- *             y[ai, bin] += w[i0]             # <<<<<<<<<<<<<<
+ *             y[bin, ai] += w[i0]             # <<<<<<<<<<<<<<
  *     return y, nans
  * 
  */
       __pyx_t_20 = __pyx_v_i0;
-      __pyx_t_21 = __pyx_v_ai;
-      __pyx_t_22 = __pyx_v_bin;
+      __pyx_t_21 = __pyx_v_bin;
+      __pyx_t_22 = __pyx_v_ai;
       *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_y.diminfo[1].strides) += (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_w.diminfo[0].strides));
     }
   }
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":210
  *                                  (bin, max_val2))
- *             y[ai, bin] += w[i0]
+ *             y[bin, ai] += w[i0]
  *     return y, nans             # <<<<<<<<<<<<<<
  * 
  * @cython.boundscheck(False)
   PyObject *__pyx_t_13 = NULL;
   PyObject *__pyx_t_14 = NULL;
   Py_ssize_t __pyx_t_15;
-  int __pyx_t_16;
-  char __pyx_t_17;
+  char __pyx_t_16;
+  int __pyx_t_17;
   Py_ssize_t __pyx_t_18;
   Py_ssize_t __pyx_t_19;
   Py_ssize_t __pyx_t_20;
-  int __pyx_t_21;
-  char __pyx_t_22;
+  char __pyx_t_21;
+  int __pyx_t_22;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":229
  * 
  *     cdef:
- *         np.npy_intp *dims = [max_val + 1, max_val2 + 1]             # <<<<<<<<<<<<<<
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)
  *         np.npy_intp *nandims = [max_val2 + 1]
  */
-  __pyx_t_6[0] = (__pyx_v_max_val + 1);
-  __pyx_t_6[1] = (__pyx_v_max_val2 + 1);
+  __pyx_t_6[0] = (__pyx_v_max_val2 + 1);
+  __pyx_t_6[1] = (__pyx_v_max_val + 1);
   __pyx_v_dims = __pyx_t_6;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":230
  *     cdef:
- *         np.npy_intp *dims = [max_val + 1, max_val2 + 1]
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)             # <<<<<<<<<<<<<<
  *         np.npy_intp *nandims = [max_val2 + 1]
  *         np.ndarray[np.float_t, ndim=1] nans = PyArray_ZEROS(1, nandims, NPY_float64, 0)
   __pyx_t_5 = 0;
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":231
- *         np.npy_intp *dims = [max_val + 1, max_val2 + 1]
+ *         np.npy_intp *dims = [max_val2 + 1, max_val + 1]
  *         np.ndarray[np.float64_t, ndim=2] y = PyArray_ZEROS(2, dims, NPY_float64, 0)
  *         np.npy_intp *nandims = [max_val2 + 1]             # <<<<<<<<<<<<<<
  *         np.ndarray[np.float_t, ndim=1] nans = PyArray_ZEROS(1, nandims, NPY_float64, 0)
  *             if bin > max_val2:
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))             # <<<<<<<<<<<<<<
- *             y[ai, bin] += 1
+ *             y[bin, ai] += 1
  *     else:
  */
         __pyx_t_13 = PyInt_FromLong(__pyx_v_bin); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":249
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))
- *             y[ai, bin] += 1             # <<<<<<<<<<<<<<
- *     else:
- *         for i0 in range(n0):
- */
-      __pyx_t_16 = __pyx_v_ai;
-      __pyx_t_17 = __pyx_v_bin;
+ *             y[bin, ai] += 1             # <<<<<<<<<<<<<<
+ *     else:
+ *         for i0 in range(n0):
+ */
+      __pyx_t_16 = __pyx_v_bin;
+      __pyx_t_17 = __pyx_v_ai;
       *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_17, __pyx_pybuffernd_y.diminfo[1].strides) += 1.0;
     }
     goto __pyx_L5;
   /*else*/ {
 
     /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":251
- *             y[ai, bin] += 1
+ *             y[bin, ai] += 1
  *     else:
  *         for i0 in range(n0):             # <<<<<<<<<<<<<<
  *             ai = a[i0]
  *             if bin > max_val2:
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))             # <<<<<<<<<<<<<<
- *             y[ai, bin] += w[i0]
+ *             y[bin, ai] += w[i0]
  *     return y, nans
  */
         __pyx_t_5 = PyInt_FromLong(__pyx_v_bin); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[22]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
       /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":262
  *                 raise ValueError("value %i is greater than max_val2 (%i)" %
  *                                  (bin, max_val2))
- *             y[ai, bin] += w[i0]             # <<<<<<<<<<<<<<
+ *             y[bin, ai] += w[i0]             # <<<<<<<<<<<<<<
  *     return y, nans
  * 
  */
       __pyx_t_20 = __pyx_v_i0;
-      __pyx_t_21 = __pyx_v_ai;
-      __pyx_t_22 = __pyx_v_bin;
+      __pyx_t_21 = __pyx_v_bin;
+      __pyx_t_22 = __pyx_v_ai;
       *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_float64_t *, __pyx_pybuffernd_y.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_y.diminfo[0].strides, __pyx_t_22, __pyx_pybuffernd_y.diminfo[1].strides) += (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_float_t *, __pyx_pybuffernd_w.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_w.diminfo[0].strides));
     }
   }
 
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":263
  *                                  (bin, max_val2))
- *             y[ai, bin] += w[i0]
+ *             y[bin, ai] += w[i0]
  *     return y, nans             # <<<<<<<<<<<<<<
  * 
  * @cython.boundscheck(False)
   Py_ssize_t __pyx_t_19;
   Py_ssize_t __pyx_t_20;
   Py_ssize_t __pyx_t_21;
-  int __pyx_t_22;
-  char __pyx_t_23;
+  char __pyx_t_22;
+  int __pyx_t_23;
   int __pyx_lineno = 0;
   const char *__pyx_filename = NULL;
   int __pyx_clineno = 0;
   /* "/Users/janezdemsar/bottleneck/bottleneck/src/func/64bit/contingency.pyx":283
  * 
  *     cdef:
- *        np.npy_intp *dims = [n1, max_val+1, max_val2+1]             # <<<<<<<<<<<<<<