Generated by Cython 0.29.35

Yellow lines hint at Python interaction.
Click on a line that starts with a "+" to see the C code that Cython generated for it.

Raw output: cyutils.c

+0001: """Module for methods implemented in cython.
  __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_3) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 0002: 
 0003: To use and load this module, you will need to build the cython extension using:
 0004: 
 0005: $ python setup.py build_ext -i
 0006: 
 0007: from the holodeck root directory (containing the `setup.py` file).
 0008: 
 0009: And you still need to install holodeck in develop mode, using:
 0010: 
 0011: $ python setup.py develop
 0012: 
 0013: """
 0014: 
 0015: cimport cython
+0016: import numpy as np
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 16, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(0, 16, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 0017: cimport numpy as np
+0018: np.import_array()
  __pyx_t_2 = __pyx_f_5numpy_import_array(); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 18, __pyx_L1_error)
 0019: 
 0020: # There is a special implementation of `scipy.special` for use with cython
 0021: cimport scipy.special.cython_special as sp_special
 0022: 
 0023: from libc.stdio cimport printf
 0024: from libc.stdlib cimport malloc, free, qsort
 0025: # make sure to use c-native math functions instead of python/numpy
 0026: from libc.math cimport pow, sqrt, abs, M_PI, NAN
 0027: 
 0028: from cpython.pycapsule cimport PyCapsule_IsValid, PyCapsule_GetPointer
 0029: from numpy.random cimport bitgen_t
+0030: from numpy.random import PCG64
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 30, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_PCG64);
  __Pyx_GIVEREF(__pyx_n_s_PCG64);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_PCG64);
  __pyx_t_3 = __Pyx_Import(__pyx_n_s_numpy_random, __pyx_t_1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 30, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PCG64); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 30, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_PCG64, __pyx_t_1) < 0) __PYX_ERR(0, 30, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 0031: from numpy.random.c_distributions cimport random_poisson, random_normal
 0032: 
 0033: 
 0034: # DTYPE = np.float64 # define as this type
 0035: # ctypedef np.float64_t DTYPE_t # accept in cython function as this type
 0036: 
 0037: # ---- Define Parameters
 0038: 
+0039: cdef double ECCEN_ZERO_LIMIT = 1.0e-12   #: below this value, strains are calculated as circular
  __pyx_v_8holodeck_7cyutils_ECCEN_ZERO_LIMIT = 1.0e-12;
 0040: 
 0041: # ---- Define Constants
 0042: 
+0043: cdef double MY_NWTG = 6.6742999e-08
  __pyx_v_8holodeck_7cyutils_MY_NWTG = 6.6742999e-08;
+0044: cdef double MY_SPLC = 29979245800.0
  __pyx_v_8holodeck_7cyutils_MY_SPLC = 29979245800.0;
+0045: cdef double MY_MPC = 3.08567758e+24
  __pyx_v_8holodeck_7cyutils_MY_MPC = 3.08567758e+24;
+0046: cdef double MY_YR = 31557600.0
  __pyx_v_8holodeck_7cyutils_MY_YR = 31557600.0;
+0047: cdef double GW_DADT_SEP_CONST = - 64.0 * pow(MY_NWTG, 3) / 5.0 / pow(MY_SPLC, 5)
  __pyx_t_4 = ((-64.0 * pow(__pyx_v_8holodeck_7cyutils_MY_NWTG, 3.0)) / 5.0);
  __pyx_t_5 = pow(__pyx_v_8holodeck_7cyutils_MY_SPLC, 5.0);
  if (unlikely(__pyx_t_5 == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    __PYX_ERR(0, 47, __pyx_L1_error)
  }
  __pyx_v_8holodeck_7cyutils_GW_DADT_SEP_CONST = (__pyx_t_4 / __pyx_t_5);
+0048: cdef double GW_SRC_CONST = 8.0 * pow(MY_NWTG, 5.0/3.0) * pow(M_PI, 2.0/3.0) / sqrt(10.0) / pow(MY_SPLC, 4.0)
  __pyx_t_5 = ((8.0 * pow(__pyx_v_8holodeck_7cyutils_MY_NWTG, (5.0 / 3.0))) * pow(M_PI, (2.0 / 3.0)));
  __pyx_t_4 = sqrt(10.0);
  if (unlikely(__pyx_t_4 == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    __PYX_ERR(0, 48, __pyx_L1_error)
  }
  __pyx_t_6 = (__pyx_t_5 / __pyx_t_4);
  __pyx_t_4 = pow(__pyx_v_8holodeck_7cyutils_MY_SPLC, 4.0);
  if (unlikely(__pyx_t_4 == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    __PYX_ERR(0, 48, __pyx_L1_error)
  }
  __pyx_v_8holodeck_7cyutils_GW_SRC_CONST = (__pyx_t_6 / __pyx_t_4);
 0049: 
 0050: 
 0051: # ====    Utility Functions    ====
 0052: 
 0053: 
+0054: cdef double bessel_recursive(int nn, double ne, double jn_m1, double jn_m2):
static double __pyx_f_8holodeck_7cyutils_bessel_recursive(int __pyx_v_nn, double __pyx_v_ne, double __pyx_v_jn_m1, double __pyx_v_jn_m2) {
  double __pyx_v_jn;
  double __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("bessel_recursive", 0);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("holodeck.cyutils.bessel_recursive", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 0055:     """Recursive relation for calculating bessel functions
 0056: 
 0057:     J_n(x) = 2 * [(n-1) / x] * J_n-1(x) - J_n-2(x)
 0058: 
 0059:     NOTE: the recursive function fails when the argument `ne` is zero (divide by zero).  These
 0060:           cases should be caught manually and set to the known values.
 0061:           This happens at the level of calculating the frequency distribution function g(n,e).
 0062: 
 0063:     Parameters
 0064:     ----------
 0065:     int nn : order of the bessel function
 0066:     double ne : argument of the bessel function (in this case, product of order and eccentricity)
 0067:     double jn_m1 : the value of the Bessel function of order n-1 of the same argument
 0068:     double jn_m2 : the value of the Bessel function of order n-2 of the same argument
 0069: 
 0070:     Returns
 0071:     -------
 0072:     double jn : the value of the Bessel function of the desired order.
 0073: 
 0074:     """
+0075:     cdef double jn = (2*(nn-1) / ne) * jn_m1 - jn_m2
  __pyx_t_1 = (2 * (__pyx_v_nn - 1));
  if (unlikely(__pyx_v_ne == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    __PYX_ERR(0, 75, __pyx_L1_error)
  }
  __pyx_v_jn = (((((double)__pyx_t_1) / __pyx_v_ne) * __pyx_v_jn_m1) - __pyx_v_jn_m2);
+0076:     return jn
  __pyx_r = __pyx_v_jn;
  goto __pyx_L0;
 0077: 
 0078: 
+0079: cdef double _gw_ecc_func(double eccen):
static double __pyx_f_8holodeck_7cyutils__gw_ecc_func(double __pyx_v_eccen) {
  double __pyx_v_e2;
  double __pyx_v_fe;
  double __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_gw_ecc_func", 0);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("holodeck.cyutils._gw_ecc_func", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 0080:     """Calculate the GW Hardening rate eccentricitiy dependence F(e).
 0081: 
 0082:     See [Peters1964]_ Eq. 5.6, or [EN2007]_ Eq. 2.3
 0083: 
 0084:     Parameters
 0085:     ----------
 0086:     eccen : double
 0087:         Eccentricity
 0088: 
 0089:     Returns
 0090:     -------
 0091:     fe : double
 0092:         The value of F(e).
 0093: 
 0094:     """
+0095:     cdef double e2 = eccen*eccen
  __pyx_v_e2 = (__pyx_v_eccen * __pyx_v_eccen);
+0096:     cdef double fe = (1.0 + (73.0/24.0)*e2 + (37.0/96.0)*e2*e2) / pow(1.0 - e2, 7.0/2.0)
  __pyx_t_1 = ((1.0 + ((73.0 / 24.0) * __pyx_v_e2)) + (((37.0 / 96.0) * __pyx_v_e2) * __pyx_v_e2));
  __pyx_t_2 = pow((1.0 - __pyx_v_e2), (7.0 / 2.0));
  if (unlikely(__pyx_t_2 == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    __PYX_ERR(0, 96, __pyx_L1_error)
  }
  __pyx_v_fe = (__pyx_t_1 / __pyx_t_2);
+0097:     return fe
  __pyx_r = __pyx_v_fe;
  goto __pyx_L0;
 0098: 
 0099: 
 0100: @cython.boundscheck(False)
 0101: @cython.wraparound(False)
+0102: cdef void my_trapz_grid_weight(int index, int size, double[:] grid, double *rv):
static void __pyx_f_8holodeck_7cyutils_my_trapz_grid_weight(int __pyx_v_index, int __pyx_v_size, __Pyx_memviewslice __pyx_v_grid, double *__pyx_v_rv) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("my_trapz_grid_weight", 0);
/* … */
  /* function exit code */
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}
 0103:     """Determine the trapezoid-rule weight and bin-width for the given grid point.
 0104: 
 0105:     Parameters
 0106:     ----------
 0107:     index : int,
 0108:         Index into the array of `grid` positions along the desired dimension.
 0109:     size : int,
 0110:         Size of the array of grid positions along the desired dimension.
 0111:     grid : double *
 0112:         Pointer to an array that specifies the location of grid points along the desired dimension.
 0113:     rv : double *
 0114:         Pointer to a (2,) array to store the output values.  The two values are:
 0115:         0: the (inverse) weight of this grid point,
 0116:         1: the grid-width for this grid point (i.e. 'dx').
 0117: 
 0118:     Returns
 0119:     -------
 0120:     None
 0121:         Note that output values are stored in the `rv` parameter.
 0122: 
 0123:     """
 0124:     # Left edge
+0125:     if index == 0:
  __pyx_t_1 = ((__pyx_v_index == 0) != 0);
  if (__pyx_t_1) {
/* … */
  }
+0126:         rv[0] = 2.0
    (__pyx_v_rv[0]) = 2.0;
+0127:         rv[1] = <double>(grid[1] - grid[0])   # i.e. grid[index+1] - grid[index]
    __pyx_t_2 = 1;
    __pyx_t_3 = 0;
    (__pyx_v_rv[1]) = ((double)((*((double *) ( /* dim=0 */ (__pyx_v_grid.data + __pyx_t_2 * __pyx_v_grid.strides[0]) ))) - (*((double *) ( /* dim=0 */ (__pyx_v_grid.data + __pyx_t_3 * __pyx_v_grid.strides[0]) )))));
+0128:         return
    goto __pyx_L0;
 0129: 
 0130:     # Right edge
+0131:     if index == size - 1:
  __pyx_t_1 = ((__pyx_v_index == (__pyx_v_size - 1)) != 0);
  if (__pyx_t_1) {
/* … */
  }
+0132:         rv[0] = 2.0
    (__pyx_v_rv[0]) = 2.0;
+0133:         rv[1] = <double>(grid[index] - grid[index-1])
    __pyx_t_3 = __pyx_v_index;
    __pyx_t_2 = (__pyx_v_index - 1);
    (__pyx_v_rv[1]) = ((double)((*((double *) ( /* dim=0 */ (__pyx_v_grid.data + __pyx_t_3 * __pyx_v_grid.strides[0]) ))) - (*((double *) ( /* dim=0 */ (__pyx_v_grid.data + __pyx_t_2 * __pyx_v_grid.strides[0]) )))));
+0134:         return
    goto __pyx_L0;
 0135: 
 0136:     # center points
+0137:     rv[0] = 1.0
  (__pyx_v_rv[0]) = 1.0;
 0138:     # this is the same as the average of dx values on each side of the grid-point, i.e.:
 0139:     #     0.5 * ((grid[index] - grid[index-1]) + (grid[index+1] - grid[index]))
+0140:     rv[1] = 0.5 * (<double>(grid[index+1] - grid[index-1]))
  __pyx_t_2 = (__pyx_v_index + 1);
  __pyx_t_3 = (__pyx_v_index - 1);
  (__pyx_v_rv[1]) = (0.5 * ((double)((*((double *) ( /* dim=0 */ (__pyx_v_grid.data + __pyx_t_2 * __pyx_v_grid.strides[0]) ))) - (*((double *) ( /* dim=0 */ (__pyx_v_grid.data + __pyx_t_3 * __pyx_v_grid.strides[0]) ))))));
 0141: 
+0142:     return
  goto __pyx_L0;
 0143: 
 0144: 
+0145: cdef double gw_freq_dist_func__scalar_scalar(int nn, double ee):
static double __pyx_f_8holodeck_7cyutils_gw_freq_dist_func__scalar_scalar(int __pyx_v_nn, double __pyx_v_ee) {
  double __pyx_v_jn_m2;
  double __pyx_v_jn_m1;
  double __pyx_v_jn;
  double __pyx_v_jn_p1;
  double __pyx_v_jn_p2;
  double __pyx_v_aa;
  double __pyx_v_bb;
  double __pyx_v_cc;
  double __pyx_v_gg;
  double __pyx_v_ne;
  double __pyx_v_n2;
  double __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("gw_freq_dist_func__scalar_scalar", 0);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("holodeck.cyutils.gw_freq_dist_func__scalar_scalar", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 0146:     """Calculate the GW frequency distribution function at the given harmonic and eccentricity, g(n,e).
 0147: 
 0148:     See [EN2007]_ Eq. 2.4
 0149: 
 0150:     NOTE: the recursive Bessel-function calculation is much faster, but fails when the argument (n*e) is zero.
 0151:         For this reason, zero arguments are manually detected and the known values of the function are returned.
 0152:         g(n, e=0.0) is 1.0 if n=2, and otherwise 0
 0153: 
 0154:     Parameters
 0155:     ----------
 0156:     nn : int,
 0157:         The harmonic to consider.
 0158:     ee : double,
 0159:         The eccentricity value.
 0160: 
 0161:     Returns
 0162:     -------
 0163:     gg : double,
 0164:         The value of g(n,e).
 0165: 
 0166:     """
 0167: 
+0168:     if ee < ECCEN_ZERO_LIMIT:
  __pyx_t_1 = ((__pyx_v_ee < __pyx_v_8holodeck_7cyutils_ECCEN_ZERO_LIMIT) != 0);
  if (__pyx_t_1) {
/* … */
  }
+0169:         if nn == 2:
    __pyx_t_1 = ((__pyx_v_nn == 2) != 0);
    if (__pyx_t_1) {
/* … */
    }
+0170:             return 1.0
      __pyx_r = 1.0;
      goto __pyx_L0;
 0171: 
+0172:         return 0.0
    __pyx_r = 0.0;
    goto __pyx_L0;
 0173: 
 0174:     cdef double jn_m2, jn_m1, jn, jn_p1, jn_p2
 0175:     cdef double aa, bb, cc, gg
 0176: 
+0177:     cdef double ne = nn*ee
  __pyx_v_ne = (__pyx_v_nn * __pyx_v_ee);
+0178:     cdef double n2 = nn * nn
  __pyx_v_n2 = (__pyx_v_nn * __pyx_v_nn);
 0179: 
+0180:     jn_m2 = sp_special.jv(nn-2, ne)
  __pyx_v_jn_m2 = __pyx_fuse_1__pyx_f_5scipy_7special_14cython_special_jv((__pyx_v_nn - 2), __pyx_v_ne, 0);
+0181:     jn_m1 = sp_special.jv(nn-1, ne)
  __pyx_v_jn_m1 = __pyx_fuse_1__pyx_f_5scipy_7special_14cython_special_jv((__pyx_v_nn - 1), __pyx_v_ne, 0);
 0182: 
+0183:     jn = bessel_recursive(nn, ne, jn_m1, jn_m2)
  __pyx_v_jn = __pyx_f_8holodeck_7cyutils_bessel_recursive(__pyx_v_nn, __pyx_v_ne, __pyx_v_jn_m1, __pyx_v_jn_m2);
+0184:     jn_p1 = bessel_recursive(nn+1, ne, jn, jn_m1)
  __pyx_v_jn_p1 = __pyx_f_8holodeck_7cyutils_bessel_recursive((__pyx_v_nn + 1), __pyx_v_ne, __pyx_v_jn, __pyx_v_jn_m1);
+0185:     jn_p2 = bessel_recursive(nn+2, ne, jn_p1, jn)
  __pyx_v_jn_p2 = __pyx_f_8holodeck_7cyutils_bessel_recursive((__pyx_v_nn + 2), __pyx_v_ne, __pyx_v_jn_p1, __pyx_v_jn);
 0186: 
+0187:     aa = jn_m2 - 2.0*ee*jn_m1 + (2/nn)*jn + 2*ee*jn_p1 - jn_p2
  if (unlikely(__pyx_v_nn == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    __PYX_ERR(0, 187, __pyx_L1_error)
  }
  __pyx_v_aa = ((((__pyx_v_jn_m2 - ((2.0 * __pyx_v_ee) * __pyx_v_jn_m1)) + ((2.0 / ((double)__pyx_v_nn)) * __pyx_v_jn)) + ((2.0 * __pyx_v_ee) * __pyx_v_jn_p1)) - __pyx_v_jn_p2);
+0188:     aa = aa * aa
  __pyx_v_aa = (__pyx_v_aa * __pyx_v_aa);
+0189:     bb = jn_m2 - 2*ee*jn + jn_p2
  __pyx_v_bb = ((__pyx_v_jn_m2 - ((2.0 * __pyx_v_ee) * __pyx_v_jn)) + __pyx_v_jn_p2);
+0190:     bb = (1 - ee*ee)*bb*bb
  __pyx_v_bb = (((1.0 - (__pyx_v_ee * __pyx_v_ee)) * __pyx_v_bb) * __pyx_v_bb);
+0191:     cc = (4.0/(3.0*n2)) * jn * jn
  __pyx_t_2 = (3.0 * __pyx_v_n2);
  if (unlikely(__pyx_t_2 == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    __PYX_ERR(0, 191, __pyx_L1_error)
  }
  __pyx_v_cc = (((4.0 / __pyx_t_2) * __pyx_v_jn) * __pyx_v_jn);
+0192:     gg = (n2*n2/32) * (aa + bb + cc)
  __pyx_v_gg = (((__pyx_v_n2 * __pyx_v_n2) / 32.0) * ((__pyx_v_aa + __pyx_v_bb) + __pyx_v_cc));
 0193: 
+0194:     return gg
  __pyx_r = __pyx_v_gg;
  goto __pyx_L0;
 0195: 
 0196: 
 0197: @cython.boundscheck(False)
 0198: @cython.wraparound(False)
 0199: @cython.nonecheck(False)
 0200: @cython.cdivision(True)
+0201: cdef void unravel(int idx, int[] shape, int *ii_out, int *jj_out):
static void __pyx_f_8holodeck_7cyutils_unravel(int __pyx_v_idx, int *__pyx_v_shape, int *__pyx_v_ii_out, int *__pyx_v_jj_out) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("unravel", 0);
/* … */
  /* function exit code */
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}
 0202:     """Convert from a 1D/flattened index into a 2D pair of (unraveled) indices.
 0203: 
 0204:     NOTE: row-major / c-style ordering is assumed.  This is the numpy default.
 0205: 
 0206:     Parameters
 0207:     ----------
 0208:     idx : int,
 0209:         Index into a 1D array to be unraveled.
 0210:     shape : int *,
 0211:         Array specifying the 2D shape of the array being indexed.
 0212:     ii_out : int *,
 0213:         Pointer to the memory location to store the output value for the 0th dimension index (x/i).
 0214:     jj_out : int *,
 0215:         Pointer to the memory location to store the output value for the 1th dimension index (y/j).
 0216: 
 0217:     Returns
 0218:     -------
 0219:     None
 0220:         NOTE: return values are set to the `ii_out` and `jj_out` parameters.
 0221: 
 0222:     """
 0223:     # find the 0th index from the size of each 0th element, `shape[1]`
+0224:     ii_out[0] = idx // shape[1]
  (__pyx_v_ii_out[0]) = (__pyx_v_idx / (__pyx_v_shape[1]));
 0225:     # find the 1th index based on the remainder
+0226:     jj_out[0] = idx - ii_out[0] * shape[1]
  (__pyx_v_jj_out[0]) = (__pyx_v_idx - ((__pyx_v_ii_out[0]) * (__pyx_v_shape[1])));
+0227:     return
  goto __pyx_L0;
 0228: 
 0229: 
 0230: # @cython.boundscheck(False)
 0231: # @cython.wraparound(False)
 0232: # @cython.nonecheck(False)
 0233: # @cython.cdivision(True)
 0234: # cdef void ravel(int ii, int jj, int[] shape, int *idx_out):
 0235: #     """Convert from a 2D pair of indices into a 1D (raveled) index.
 0236: 
 0237: #     NOTE: row-major / c-style ordering is assumed.  This is the numpy default.
 0238: 
 0239: #     Parameters
 0240: #     ----------
 0241: #     ii : int,
 0242: #         0th dimension index (i.e. x).
 0243: #     jj : int,
 0244: #         1th dimension index (i.e. y).
 0245: #     shape : int *,
 0246: #         Array specifying the 2D shape of the array being indexed.
 0247: #     idx_out : int *,
 0248: #         Pointer to the memory location to store the 1D/flattened index.
 0249: 
 0250: #     Returns
 0251: #     -------
 0252: #     None
 0253: #         NOTE: return values are set to the `idx_out` parameter.
 0254: 
 0255: #     """
 0256: #     idx_out[0] = ii * shape[1] + jj
 0257: #     return
 0258: 
 0259: 
 0260: """Structure that stores both the index and value of a given array element to use in sorting.
 0261: """
+0262: cdef struct sorter:
struct __pyx_t_8holodeck_7cyutils_sorter {
  int index;
  double value;
};
 0263:     int index
 0264:     double value
 0265: 
 0266: 
+0267: cdef int sort_compare(const void *a, const void *b) nogil:
static int __pyx_f_8holodeck_7cyutils_sort_compare(void const *__pyx_v_a, void const *__pyx_v_b) {
  struct __pyx_t_8holodeck_7cyutils_sorter *__pyx_v_a1;
  struct __pyx_t_8holodeck_7cyutils_sorter *__pyx_v_a2;
  int __pyx_r;
/* … */
  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}
 0268:     """Comparison function used by the `qsort` builtin method to perform an array-sort by index.
 0269: 
 0270:     Parameters
 0271:     ----------
 0272:     a : void *
 0273:         Pointer to first  element of comparison, should point to a `sorter` struct instance.
 0274:     b : void *
 0275:         Pointer to second element of comparison, should point to a `sorter` struct instance.
 0276: 
 0277:     Returns
 0278:     -------
 0279:     int
 0280:         -1 if a < b, +1 if b > a, and 0 otherwise
 0281: 
 0282:     """
+0283:     cdef sorter *a1 = <sorter *>a;
  __pyx_v_a1 = ((struct __pyx_t_8holodeck_7cyutils_sorter *)__pyx_v_a);
+0284:     cdef sorter *a2 = <sorter *>b;
  __pyx_v_a2 = ((struct __pyx_t_8holodeck_7cyutils_sorter *)__pyx_v_b);
+0285:     if ((a1[0]).value < (a2[0]).value):
  __pyx_t_1 = (((__pyx_v_a1[0]).value < (__pyx_v_a2[0]).value) != 0);
  if (__pyx_t_1) {
/* … */
  }
+0286:         return -1
    __pyx_r = -1;
    goto __pyx_L0;
+0287:     elif ((a1[0]).value > (a2[0]).value):
  __pyx_t_1 = (((__pyx_v_a1[0]).value > (__pyx_v_a2[0]).value) != 0);
  if (__pyx_t_1) {
/* … */
  }
+0288:         return 1
    __pyx_r = 1;
    goto __pyx_L0;
 0289:     else:
+0290:         return 0
  /*else*/ {
    __pyx_r = 0;
    goto __pyx_L0;
  }
 0291: 
 0292: 
+0293: cdef void argsort(double *values, int size, int **indices):
static void __pyx_f_8holodeck_7cyutils_argsort(double *__pyx_v_values, int __pyx_v_size, int **__pyx_v_indices) {
  struct __pyx_t_8holodeck_7cyutils_sorter *__pyx_v_testers;
  int __pyx_v_ii;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("argsort", 0);
/* … */
  /* function exit code */
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}
 0294:     """Find the indices that sort the given 1D array of double values.
 0295: 
 0296:     This is done using an array of `sorter` struct instances which store both index and value.
 0297: 
 0298:     Usage example:
 0299: 
 0300:         ```
 0301:         cdef double test[4]
 0302:         test[:] = [1.0, -2.3, 7.8, 0.0]
 0303: 
 0304:         cdef (int *)indices = <int *>malloc(4 * sizeof(int))
 0305:         argsort(test, 4, &indices)
 0306:         ```
 0307: 
 0308:     """
+0309:     cdef (sorter *)testers = <sorter *>malloc(size * sizeof(sorter))
  __pyx_v_testers = ((struct __pyx_t_8holodeck_7cyutils_sorter *)malloc((__pyx_v_size * (sizeof(struct __pyx_t_8holodeck_7cyutils_sorter)))));
 0310:     cdef int ii
+0311:     for ii in range(size):
  __pyx_t_1 = __pyx_v_size;
  __pyx_t_2 = __pyx_t_1;
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
    __pyx_v_ii = __pyx_t_3;
+0312:         testers[ii].index = ii
    (__pyx_v_testers[__pyx_v_ii]).index = __pyx_v_ii;
+0313:         testers[ii].value = values[ii]
    (__pyx_v_testers[__pyx_v_ii]).value = (__pyx_v_values[__pyx_v_ii]);
  }
 0314: 
+0315:     qsort(testers, size, sizeof(testers[0]), sort_compare)
  qsort(__pyx_v_testers, __pyx_v_size, (sizeof((__pyx_v_testers[0]))), __pyx_f_8holodeck_7cyutils_sort_compare);
+0316:     for ii in range(size):
  __pyx_t_1 = __pyx_v_size;
  __pyx_t_2 = __pyx_t_1;
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
    __pyx_v_ii = __pyx_t_3;
+0317:         indices[0][ii] = testers[ii].index
    __pyx_t_4 = (__pyx_v_testers[__pyx_v_ii]).index;
    ((__pyx_v_indices[0])[__pyx_v_ii]) = __pyx_t_4;
  }
 0318: 
+0319:     return
  goto __pyx_L0;
 0320: 
 0321: 
 0322: @cython.boundscheck(False)
 0323: @cython.wraparound(False)
 0324: @cython.nonecheck(False)
 0325: @cython.cdivision(True)
+0326: cdef double _interp_between_vals(double xnew, double xl, double xr, double yl, double yr):
static double __pyx_f_8holodeck_7cyutils__interp_between_vals(double __pyx_v_xnew, double __pyx_v_xl, double __pyx_v_xr, double __pyx_v_yl, double __pyx_v_yr) {
  double __pyx_v_ynew;
  double __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_interp_between_vals", 0);
/* … */
  /* function exit code */
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
+0327:     cdef double ynew = yl + (yr - yl) * (xnew - xl) / (xr - xl)
  __pyx_v_ynew = (__pyx_v_yl + (((__pyx_v_yr - __pyx_v_yl) * (__pyx_v_xnew - __pyx_v_xl)) / (__pyx_v_xr - __pyx_v_xl)));
+0328:     return ynew
  __pyx_r = __pyx_v_ynew;
  goto __pyx_L0;
 0329: 
 0330: 
 0331: @cython.boundscheck(False)
 0332: @cython.wraparound(False)
 0333: @cython.nonecheck(False)
 0334: @cython.cdivision(True)
+0335: cdef double interp_at_index(int idx, double xnew, double[:] xold, double[:] yold):
static double __pyx_f_8holodeck_7cyutils_interp_at_index(int __pyx_v_idx, double __pyx_v_xnew, __Pyx_memviewslice __pyx_v_xold, __Pyx_memviewslice __pyx_v_yold) {
  double __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("interp_at_index", 0);
/* … */
  /* function exit code */
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 0336:     """Perform linear interpolation at the given index in a pair of arrays.
 0337: 
 0338:     Parameters
 0339:     ----------
 0340:     idx : int
 0341:         Index in the arrays specifying the left reference value to interpolate between, with `idx+1`
 0342:         giving the right value.
 0343:     xnew : double
 0344:         The independent (x) value to interpolate to.
 0345:     xold : double *
 0346:         Array of x-values giving the independent variables where the functions are evaluated.
 0347:     yold : double *
 0348:         Array of y-values giving the dependent variable (function values) of array.
 0349: 
 0350:     Returns
 0351:     -------
 0352:     ynew : double
 0353:         Interpolated function value.
 0354: 
 0355:     """
 0356:     # cdef double ynew = yold[idx] + (yold[idx+1] - yold[idx])/(xold[idx+1] - xold[idx]) * (xnew - xold[idx])
 0357:     # return ynew
+0358:     return _interp_between_vals(xnew, xold[idx], xold[idx+1], yold[idx], yold[idx+1])
  __pyx_t_1 = __pyx_v_idx;
  __pyx_t_2 = (__pyx_v_idx + 1);
  __pyx_t_3 = __pyx_v_idx;
  __pyx_t_4 = (__pyx_v_idx + 1);
  __pyx_r = __pyx_f_8holodeck_7cyutils__interp_between_vals(__pyx_v_xnew, (*((double *) ( /* dim=0 */ (__pyx_v_xold.data + __pyx_t_1 * __pyx_v_xold.strides[0]) ))), (*((double *) ( /* dim=0 */ (__pyx_v_xold.data + __pyx_t_2 * __pyx_v_xold.strides[0]) ))), (*((double *) ( /* dim=0 */ (__pyx_v_yold.data + __pyx_t_3 * __pyx_v_yold.strides[0]) ))), (*((double *) ( /* dim=0 */ (__pyx_v_yold.data + __pyx_t_4 * __pyx_v_yold.strides[0]) ))));
  goto __pyx_L0;
 0359: 
 0360: 
+0361: def sam_calc_gwb_single_eccen(ndens, mtot_log10, mrat, redz, dcom, gwfobs, sepa_evo, eccen_evo, nharms=100):
/* Python wrapper */
static PyObject *__pyx_pw_8holodeck_7cyutils_1sam_calc_gwb_single_eccen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8holodeck_7cyutils_sam_calc_gwb_single_eccen[] = "Pure-python wrapper for the SAM eccentric GWB calculation method.  See: `_sam_calc_gwb_single_eccen()`.\n    ";
static PyMethodDef __pyx_mdef_8holodeck_7cyutils_1sam_calc_gwb_single_eccen = {"sam_calc_gwb_single_eccen", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8holodeck_7cyutils_1sam_calc_gwb_single_eccen, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8holodeck_7cyutils_sam_calc_gwb_single_eccen};
static PyObject *__pyx_pw_8holodeck_7cyutils_1sam_calc_gwb_single_eccen(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_ndens = 0;
  PyObject *__pyx_v_mtot_log10 = 0;
  PyObject *__pyx_v_mrat = 0;
  PyObject *__pyx_v_redz = 0;
  PyObject *__pyx_v_dcom = 0;
  PyObject *__pyx_v_gwfobs = 0;
  PyObject *__pyx_v_sepa_evo = 0;
  PyObject *__pyx_v_eccen_evo = 0;
  PyObject *__pyx_v_nharms = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sam_calc_gwb_single_eccen (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_ndens,&__pyx_n_s_mtot_log10,&__pyx_n_s_mrat,&__pyx_n_s_redz,&__pyx_n_s_dcom,&__pyx_n_s_gwfobs,&__pyx_n_s_sepa_evo,&__pyx_n_s_eccen_evo,&__pyx_n_s_nharms,0};
    PyObject* values[9] = {0,0,0,0,0,0,0,0,0};
    values[8] = ((PyObject *)__pyx_int_100);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        CYTHON_FALLTHROUGH;
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ndens)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mtot_log10)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sam_calc_gwb_single_eccen", 0, 8, 9, 1); __PYX_ERR(0, 361, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mrat)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sam_calc_gwb_single_eccen", 0, 8, 9, 2); __PYX_ERR(0, 361, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_redz)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sam_calc_gwb_single_eccen", 0, 8, 9, 3); __PYX_ERR(0, 361, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dcom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sam_calc_gwb_single_eccen", 0, 8, 9, 4); __PYX_ERR(0, 361, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_gwfobs)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sam_calc_gwb_single_eccen", 0, 8, 9, 5); __PYX_ERR(0, 361, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (likely((values[6] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sepa_evo)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sam_calc_gwb_single_eccen", 0, 8, 9, 6); __PYX_ERR(0, 361, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  7:
        if (likely((values[7] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_eccen_evo)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sam_calc_gwb_single_eccen", 0, 8, 9, 7); __PYX_ERR(0, 361, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  8:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_nharms);
          if (value) { values[8] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sam_calc_gwb_single_eccen") < 0)) __PYX_ERR(0, 361, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        CYTHON_FALLTHROUGH;
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_ndens = values[0];
    __pyx_v_mtot_log10 = values[1];
    __pyx_v_mrat = values[2];
    __pyx_v_redz = values[3];
    __pyx_v_dcom = values[4];
    __pyx_v_gwfobs = values[5];
    __pyx_v_sepa_evo = values[6];
    __pyx_v_eccen_evo = values[7];
    __pyx_v_nharms = values[8];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("sam_calc_gwb_single_eccen", 0, 8, 9, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 361, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("holodeck.cyutils.sam_calc_gwb_single_eccen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_8holodeck_7cyutils_sam_calc_gwb_single_eccen(__pyx_self, __pyx_v_ndens, __pyx_v_mtot_log10, __pyx_v_mrat, __pyx_v_redz, __pyx_v_dcom, __pyx_v_gwfobs, __pyx_v_sepa_evo, __pyx_v_eccen_evo, __pyx_v_nharms);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8holodeck_7cyutils_sam_calc_gwb_single_eccen(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_ndens, PyObject *__pyx_v_mtot_log10, PyObject *__pyx_v_mrat, PyObject *__pyx_v_redz, PyObject *__pyx_v_dcom, PyObject *__pyx_v_gwfobs, PyObject *__pyx_v_sepa_evo, PyObject *__pyx_v_eccen_evo, PyObject *__pyx_v_nharms) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sam_calc_gwb_single_eccen", 0);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __PYX_XDEC_MEMVIEW(&__pyx_t_1, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_2, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_3, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_4, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("holodeck.cyutils.sam_calc_gwb_single_eccen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__24 = PyTuple_Pack(9, __pyx_n_s_ndens, __pyx_n_s_mtot_log10, __pyx_n_s_mrat, __pyx_n_s_redz, __pyx_n_s_dcom, __pyx_n_s_gwfobs, __pyx_n_s_sepa_evo, __pyx_n_s_eccen_evo, __pyx_n_s_nharms); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 361, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__24);
  __Pyx_GIVEREF(__pyx_tuple__24);
/* … */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_8holodeck_7cyutils_1sam_calc_gwb_single_eccen, NULL, __pyx_n_s_holodeck_cyutils); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 361, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sam_calc_gwb_single_eccen, __pyx_t_3) < 0) __PYX_ERR(0, 361, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_codeobj__25 = (PyObject*)__Pyx_PyCode_New(9, 0, 9, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__24, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_holodeck_cyutils_pyx, __pyx_n_s_sam_calc_gwb_single_eccen, 361, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__25)) __PYX_ERR(0, 361, __pyx_L1_error)
 0362:     """Pure-python wrapper for the SAM eccentric GWB calculation method.  See: `_sam_calc_gwb_single_eccen()`.
 0363:     """
+0364:     return _sam_calc_gwb_single_eccen(ndens, mtot_log10, mrat, redz, dcom, gwfobs, sepa_evo, eccen_evo, nharms)
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_double(__pyx_v_ndens, PyBUF_WRITABLE); if (unlikely(!__pyx_t_1.memview)) __PYX_ERR(0, 364, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_mtot_log10, PyBUF_WRITABLE); if (unlikely(!__pyx_t_2.memview)) __PYX_ERR(0, 364, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_mrat, PyBUF_WRITABLE); if (unlikely(!__pyx_t_3.memview)) __PYX_ERR(0, 364, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_redz, PyBUF_WRITABLE); if (unlikely(!__pyx_t_4.memview)) __PYX_ERR(0, 364, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_dcom, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 364, __pyx_L1_error)
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_gwfobs, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 364, __pyx_L1_error)
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_sepa_evo, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 364, __pyx_L1_error)
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_eccen_evo, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 364, __pyx_L1_error)
  __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_v_nharms); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 364, __pyx_L1_error)
  __pyx_t_10 = __pyx_f_8holodeck_7cyutils__sam_calc_gwb_single_eccen(__pyx_t_1, __pyx_t_2, __pyx_t_3, __pyx_t_4, __pyx_t_5, __pyx_t_6, __pyx_t_7, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 364, __pyx_L1_error)
  __PYX_XDEC_MEMVIEW(&__pyx_t_1, 1);
  __pyx_t_1.memview = NULL;
  __pyx_t_1.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_2, 1);
  __pyx_t_2.memview = NULL;
  __pyx_t_2.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_3, 1);
  __pyx_t_3.memview = NULL;
  __pyx_t_3.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_4, 1);
  __pyx_t_4.memview = NULL;
  __pyx_t_4.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
  __pyx_t_5.memview = NULL;
  __pyx_t_5.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;
  __pyx_t_11 = __pyx_memoryview_fromslice(__pyx_t_10, 2, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 364, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;
  __pyx_r = __pyx_t_11;
  __pyx_t_11 = 0;
  goto __pyx_L0;
 0365: 
 0366: @cython.boundscheck(False)
 0367: @cython.wraparound(False)
 0368: @cython.nonecheck(False)
 0369: @cython.cdivision(True)
+0370: cdef double[:, :] _sam_calc_gwb_single_eccen(
static __Pyx_memviewslice __pyx_f_8holodeck_7cyutils__sam_calc_gwb_single_eccen(__Pyx_memviewslice __pyx_v_ndens, __Pyx_memviewslice __pyx_v_mtot_log10, __Pyx_memviewslice __pyx_v_mrat, __Pyx_memviewslice __pyx_v_redz, __Pyx_memviewslice __pyx_v_dcom, __Pyx_memviewslice __pyx_v_gwfobs, __Pyx_memviewslice __pyx_v_sepa_evo_in, __Pyx_memviewslice __pyx_v_eccen_evo_in, int __pyx_v_nharms) {
  int __pyx_v_nfreqs;
  int __pyx_v_n_mtot;
  int __pyx_v_n_mrat;
  int __pyx_v_n_redz;
  int __pyx_v_n_eccs;
  int __pyx_v_num_freq_harm;
  int *__pyx_v_shape;
  int __pyx_v_ii;
  int __pyx_v_nh;
  int __pyx_v_jj;
  int __pyx_v_kk;
  int __pyx_v_aa;
  int __pyx_v_bb;
  int __pyx_v_ff;
  int __pyx_v_ecc_idx;
  int __pyx_v_ecc_idx_beg;
  int __pyx_v_ii_mm;
  double __pyx_v_m1;
  double __pyx_v_m2;
  double __pyx_v_mchirp;
  double __pyx_v_sa;
  double __pyx_v_tau;
  double __pyx_v_gwfr;
  double __pyx_v_zterm;
  double __pyx_v_dc_cm;
  double __pyx_v_dc_mpc;
  double __pyx_v_dc_term;
  double __pyx_v_gne;
  double __pyx_v_hterm;
  double __pyx_v_weight_ik;
  double __pyx_v_weight;
  double __pyx_v_four_over_nh_squared;
  double __pyx_v_sa_fourth;
  double __pyx_v_fe_ecc;
  double __pyx_v_mt;
  double __pyx_v_mt_sqrt;
  double __pyx_v_hterm_pref;
  double __pyx_v_frst_evo_lo;
  double __pyx_v_frst_evo_hi;
  double __pyx_v_four_pi_c_mpc;
  double __pyx_v_kep_sa_term;
  double __pyx_v_one_third;
  double __pyx_v_two_third;
  double __pyx_v_four_third;
  double __pyx_v_three_fifths;
  double __pyx_v_six_fifths;
  PyArrayObject *__pyx_v_gwb = 0;
  double *__pyx_v_mtot;
  double *__pyx_v_ival;
  double *__pyx_v_jval;
  double *__pyx_v_kval;
  double *__pyx_v_sepa_evo;
  double *__pyx_v_eccen_evo;
  double __pyx_v__freq_pref;
  double *__pyx_v_frst_evo_pref;
  double *__pyx_v_freq_harms;
  int *__pyx_v_sorted_index;
  double __pyx_v_kep_sa_mass_term;
  double __pyx_v_ecc;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_gwb;
  __Pyx_Buffer __pyx_pybuffer_gwb;
  __Pyx_memviewslice __pyx_r = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_sam_calc_gwb_single_eccen", 0);
  __pyx_pybuffer_gwb.pybuffer.buf = NULL;
  __pyx_pybuffer_gwb.refcount = 0;
  __pyx_pybuffernd_gwb.data = NULL;
  __pyx_pybuffernd_gwb.rcbuffer = &__pyx_pybuffer_gwb;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __PYX_XDEC_MEMVIEW(&__pyx_t_25, 1);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_gwb.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __pyx_r.data = NULL;
  __pyx_r.memview = NULL;
  __Pyx_AddTraceback("holodeck.cyutils._sam_calc_gwb_single_eccen", __pyx_clineno, __pyx_lineno, __pyx_filename);
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_gwb.rcbuffer->pybuffer);
  if (unlikely(!__pyx_r.memview)) {
    PyErr_SetString(PyExc_TypeError, "Memoryview return value is not initialized");
  }
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_gwb);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 0371:     double[:, :, :] ndens,
 0372:     double[:] mtot_log10,
 0373:     double[:] mrat,
 0374:     double[:] redz,
 0375:     double[:] dcom,
 0376:     double[:] gwfobs,
 0377:     double[:] sepa_evo_in,
 0378:     double[:] eccen_evo_in,
 0379:     int nharms
 0380: ):
 0381:     """Calculate the GWB from an eccentric SAM evolution model.
 0382: 
 0383:     This function uses the precomputed binary-evolution of eccentricities over some range of separations.
 0384:     This assumes a single eccentricity evolution e(a) for all binaries.
 0385:     Redshifts are assumed to stay constant during this evolution.
 0386: 
 0387:     h_c^2 = (dn/dz) * h_{s,n}^2 * 4*pi*c * d_c^2 * (1+z) * tau
 0388: 
 0389:     h_{s,n}^2 = (32 / 5) * c^-8 * (2/n)^2 * (G Mchirp)^(10/3) * d_c^-2 * (2*pi*forb_r)^(4/3) * g(n,e)
 0390:               = GW_SRC_CONST^2 * (2/n)^2 * Mchirp^(10/3) * d_c^-2 * forb_r^(4/3) * g(n,e)
 0391: 
 0392: 
 0393:     Parameters
 0394:     ----------
 0395:     ndens : (double ***)
 0396:         3D array specifying the SAM number-density of binaries in each bin, in total-mass, mass-ratio, and redshift.
 0397:         This is typically `sam.static_binary_density`, corresponding to 'd^3 n / [dlog10M dq dz]' in units of [Mpc^-3].
 0398:     mtot_log10 : (double *)
 0399:         Array of log10 values of the total-mass (in grams) grid edges in the SAM model.  i.e. `log10(sam.mtot)`.
 0400:     mrat : (double *)
 0401:         Array of mass-ratio grid edges in the SAM model.  i.e. `sam.mrat`.
 0402:     redz : (double *)
 0403:         Array of values for the redshift grid edges in the SAM model.  i.e. `sam.redz`.
 0404:     dcom : (double *)
 0405:         Comoving distances in units of [Mpc] corresponding to each `redz` value.
 0406:     gwfobs : (double *)
 0407:         Array of GW observer-frame frequencies at which to evaluate the GWB.
 0408:     sepa_evo_in : (double *)
 0409:         The values of binary separation in units of [cm] at which the binaries have been evolved.
 0410:     eccen_evo_in : (double *)
 0411:         The values of binary eccentricity at each separation at which the binaries have been evolved.
 0412:     nharms : int,
 0413:         Number of harmonics at which to calculate GW strains.
 0414: 
 0415:     Returns
 0416:     -------
 0417:     gwb : (double **)
 0418:         2D array giving the characteristic-strain _squared_, at each observer-frame frequency and each harmonic.
 0419:         Shape is (nfreqs, nharms), where `nfreqs` is the length of the `gwfobs` parameters, and `nharms` is given
 0420:         as an input parameter directly.
 0421:         The characteristic strain spectrum, h_c(f) is then `np.sqrt(gwb.sum(axis=1))`; i.e. the sum in quadrature of
 0422:         strain at each harmonic.
 0423: 
 0424:     """
 0425: 
 0426:     # Initialize sizes and shapes
+0427:     cdef int nfreqs = len(gwfobs)
  __pyx_t_1 = __Pyx_MemoryView_Len(__pyx_v_gwfobs); 
  __pyx_v_nfreqs = __pyx_t_1;
+0428:     cdef int n_mtot = len(mtot_log10)
  __pyx_t_1 = __Pyx_MemoryView_Len(__pyx_v_mtot_log10); 
  __pyx_v_n_mtot = __pyx_t_1;
+0429:     cdef int n_mrat = len(mrat)
  __pyx_t_1 = __Pyx_MemoryView_Len(__pyx_v_mrat); 
  __pyx_v_n_mrat = __pyx_t_1;
+0430:     cdef int n_redz = len(redz)
  __pyx_t_1 = __Pyx_MemoryView_Len(__pyx_v_redz); 
  __pyx_v_n_redz = __pyx_t_1;
+0431:     cdef int n_eccs = len(sepa_evo_in)
  __pyx_t_1 = __Pyx_MemoryView_Len(__pyx_v_sepa_evo_in); 
  __pyx_v_n_eccs = __pyx_t_1;
+0432:     cdef int num_freq_harm = nfreqs * nharms
  __pyx_v_num_freq_harm = (__pyx_v_nfreqs * __pyx_v_nharms);
+0433:     cdef (int *)shape = <int *>malloc(2 * sizeof(int))
  __pyx_v_shape = ((int *)malloc((2 * (sizeof(int)))));
+0434:     shape[0] = nfreqs
  (__pyx_v_shape[0]) = __pyx_v_nfreqs;
+0435:     shape[1] = nharms
  (__pyx_v_shape[1]) = __pyx_v_nharms;
 0436: 
 0437:     # Declare variables used later
 0438:     cdef int ii, nh, jj, kk, aa, bb, ff, ecc_idx, ecc_idx_beg, ii_mm, kk_zz
 0439:     cdef double m1, m2, mchirp, sa, qq, tau, num_pois
 0440:     cdef double gwfr, zterm, dc_cm, dc_mpc, dc_term, gne, hterm, number_term, number_term_pref
 0441:     cdef double weight_ik, weight, volume_ik, volume, four_over_nh_squared, sa_fourth
 0442:     cdef double fe_ecc, mt, mt_sqrt, nd, hterm_pref, frst_evo_lo, frst_evo_hi
 0443: 
 0444:     # Initialize constants
+0445:     cdef double four_pi_c_mpc = 4 * M_PI * (MY_SPLC / MY_MPC)
  __pyx_v_four_pi_c_mpc = ((4.0 * M_PI) * (__pyx_v_8holodeck_7cyutils_MY_SPLC / __pyx_v_8holodeck_7cyutils_MY_MPC));
+0446:     cdef double kep_sa_term = MY_NWTG / pow(2.0*M_PI, 2)
  __pyx_v_kep_sa_term = (__pyx_v_8holodeck_7cyutils_MY_NWTG / pow((2.0 * M_PI), 2.0));
+0447:     cdef double one_third = 1.0 / 3.0
  __pyx_v_one_third = (1.0 / 3.0);
+0448:     cdef double two_third = 2.0 / 3.0
  __pyx_v_two_third = (2.0 / 3.0);
+0449:     cdef double four_third = 4.0 / 3.0
  __pyx_v_four_third = (4.0 / 3.0);
+0450:     cdef double three_fifths = 3.0 / 5.0
  __pyx_v_three_fifths = (3.0 / 5.0);
+0451:     cdef double six_fifths = 6.0 / 5.0
  __pyx_v_six_fifths = (6.0 / 5.0);
 0452: 
 0453:     # Initialize arrays
+0454:     cdef np.ndarray[np.double_t, ndim=2] gwb = np.zeros((nfreqs, nharms))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 454, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_zeros); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 454, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_nfreqs); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 454, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_nharms); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 454, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 454, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5);
  __pyx_t_3 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_6);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 454, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 454, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_gwb.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_gwb = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_gwb.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 454, __pyx_L1_error)
    } else {__pyx_pybuffernd_gwb.diminfo[0].strides = __pyx_pybuffernd_gwb.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_gwb.diminfo[0].shape = __pyx_pybuffernd_gwb.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_gwb.diminfo[1].strides = __pyx_pybuffernd_gwb.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_gwb.diminfo[1].shape = __pyx_pybuffernd_gwb.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_7 = 0;
  __pyx_v_gwb = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;
+0455:     cdef double *mtot = <double *>malloc(n_mtot * sizeof(double))
  __pyx_v_mtot = ((double *)malloc((__pyx_v_n_mtot * (sizeof(double)))));
+0456:     cdef double *ival = <double *>malloc(2 * sizeof(double))
  __pyx_v_ival = ((double *)malloc((2 * (sizeof(double)))));
+0457:     cdef double *jval = <double *>malloc(2 * sizeof(double))
  __pyx_v_jval = ((double *)malloc((2 * (sizeof(double)))));
+0458:     cdef double *kval = <double *>malloc(2 * sizeof(double))
  __pyx_v_kval = ((double *)malloc((2 * (sizeof(double)))));
+0459:     cdef double *sepa_evo = <double *>malloc(n_eccs * sizeof(double))
  __pyx_v_sepa_evo = ((double *)malloc((__pyx_v_n_eccs * (sizeof(double)))));
+0460:     cdef double *eccen_evo = <double *>malloc(n_eccs * sizeof(double))
  __pyx_v_eccen_evo = ((double *)malloc((__pyx_v_n_eccs * (sizeof(double)))));
+0461:     cdef double _freq_pref = (1.0/(2.0*M_PI)) * sqrt(MY_NWTG)
  __pyx_v__freq_pref = ((1.0 / (2.0 * M_PI)) * sqrt(__pyx_v_8holodeck_7cyutils_MY_NWTG));
+0462:     cdef double *frst_evo_pref = <double *>malloc(n_eccs * sizeof(double))
  __pyx_v_frst_evo_pref = ((double *)malloc((__pyx_v_n_eccs * (sizeof(double)))));
 0463:     # Convert from numpy arrays to c-arrays (for possible speed improvements)
+0464:     for ii in range(n_eccs):
  __pyx_t_8 = __pyx_v_n_eccs;
  __pyx_t_9 = __pyx_t_8;
  for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) {
    __pyx_v_ii = __pyx_t_10;
+0465:         sepa_evo[ii] = <double>sepa_evo_in[ii]
    __pyx_t_11 = __pyx_v_ii;
    (__pyx_v_sepa_evo[__pyx_v_ii]) = ((double)(*((double *) ( /* dim=0 */ (__pyx_v_sepa_evo_in.data + __pyx_t_11 * __pyx_v_sepa_evo_in.strides[0]) ))));
+0466:         eccen_evo[ii] = <double>eccen_evo_in[ii]
    __pyx_t_11 = __pyx_v_ii;
    (__pyx_v_eccen_evo[__pyx_v_ii]) = ((double)(*((double *) ( /* dim=0 */ (__pyx_v_eccen_evo_in.data + __pyx_t_11 * __pyx_v_eccen_evo_in.strides[0]) ))));
 0467:         # calculate the prefactor (i.e. everything except the mass) for kepler's law
+0468:         frst_evo_pref[ii] = _freq_pref / pow(sepa_evo[ii], 1.5)
    (__pyx_v_frst_evo_pref[__pyx_v_ii]) = (__pyx_v__freq_pref / pow((__pyx_v_sepa_evo[__pyx_v_ii]), 1.5));
  }
 0469: 
 0470:     # Calculate all of the frequency harmonics (flattened) that are needed
+0471:     cdef (double *)freq_harms = <double *>malloc(num_freq_harm * sizeof(double))
  __pyx_v_freq_harms = ((double *)malloc((__pyx_v_num_freq_harm * (sizeof(double)))));
+0472:     for ii in range(num_freq_harm):
  __pyx_t_8 = __pyx_v_num_freq_harm;
  __pyx_t_9 = __pyx_t_8;
  for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) {
    __pyx_v_ii = __pyx_t_10;
 0473:         # convert from 1D index to 2D grid of (F, H) frequencies and harmonics
+0474:         unravel(ii, shape, &aa, &bb)
    __pyx_f_8holodeck_7cyutils_unravel(__pyx_v_ii, __pyx_v_shape, (&__pyx_v_aa), (&__pyx_v_bb));
 0475:         # calculate the n = bb+1 harmonic
+0476:         freq_harms[ii] = gwfobs[aa] / (bb + 1)
    __pyx_t_11 = __pyx_v_aa;
    (__pyx_v_freq_harms[__pyx_v_ii]) = ((*((double *) ( /* dim=0 */ (__pyx_v_gwfobs.data + __pyx_t_11 * __pyx_v_gwfobs.strides[0]) ))) / ((double)(__pyx_v_bb + 1)));
  }
 0477: 
 0478:     # Find the indices by which to sort the frequency harmonics (flattened)
+0479:     cdef (int *)sorted_index = <int *>malloc(num_freq_harm * sizeof(int))
  __pyx_v_sorted_index = ((int *)malloc((__pyx_v_num_freq_harm * (sizeof(int)))));
+0480:     argsort(freq_harms, num_freq_harm, &sorted_index)
  __pyx_f_8holodeck_7cyutils_argsort(__pyx_v_freq_harms, __pyx_v_num_freq_harm, (&__pyx_v_sorted_index));
 0481: 
 0482:     # iterate over redshifts Z
+0483:     for kk in range(n_redz):
  __pyx_t_8 = __pyx_v_n_redz;
  __pyx_t_9 = __pyx_t_8;
  for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_9; __pyx_t_10+=1) {
    __pyx_v_kk = __pyx_t_10;
 0484:         # fill `kval` with the weight of this grid point (kval[0]), and the grid-width (kval[1])
+0485:         my_trapz_grid_weight(kk, n_redz, redz, kval)
    __pyx_f_8holodeck_7cyutils_my_trapz_grid_weight(__pyx_v_kk, __pyx_v_n_redz, __pyx_v_redz, __pyx_v_kval);
+0486:         zterm = (1.0 + redz[kk])
    __pyx_t_11 = __pyx_v_kk;
    __pyx_v_zterm = (1.0 + (*((double *) ( /* dim=0 */ (__pyx_v_redz.data + __pyx_t_11 * __pyx_v_redz.strides[0]) ))));
+0487:         dc_mpc = dcom[kk]   # this is still in units of [Mpc]
    __pyx_t_11 = __pyx_v_kk;
    __pyx_v_dc_mpc = (*((double *) ( /* dim=0 */ (__pyx_v_dcom.data + __pyx_t_11 * __pyx_v_dcom.strides[0]) )));
+0488:         dc_cm = dc_mpc * MY_MPC  # convert to [cm]
    __pyx_v_dc_cm = (__pyx_v_dc_mpc * __pyx_v_8holodeck_7cyutils_MY_MPC);
+0489:         dc_term = four_pi_c_mpc * pow(dc_mpc, 2)
    __pyx_v_dc_term = (__pyx_v_four_pi_c_mpc * pow(__pyx_v_dc_mpc, 2.0));
 0490: 
 0491:         # iterate over mtot M
+0492:         ecc_idx_beg = 0   # we will keep track of evolution/eccentricity indices for our target
    __pyx_v_ecc_idx_beg = 0;
 0493:                           # frequencies to make suring the arrays faster
 0494:         # iterate over total masses in reverse, so that's we're always going to increasing frequencies
+0495:         for ii_mm in range(n_mtot):
    __pyx_t_12 = __pyx_v_n_mtot;
    __pyx_t_13 = __pyx_t_12;
    for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
      __pyx_v_ii_mm = __pyx_t_14;
 0496:             # convert from forward to backward indices
+0497:             ii = n_mtot - 1 - ii_mm
      __pyx_v_ii = ((__pyx_v_n_mtot - 1) - __pyx_v_ii_mm);
 0498: 
 0499:             # convert from log10 to regular total masses, only the first time through the loop
+0500:             if kk == 0:
      __pyx_t_15 = ((__pyx_v_kk == 0) != 0);
      if (__pyx_t_15) {
/* … */
        goto __pyx_L11;
      }
+0501:                 mt = pow(10.0, mtot_log10[ii])
        __pyx_t_11 = __pyx_v_ii;
        __pyx_v_mt = pow(10.0, (*((double *) ( /* dim=0 */ (__pyx_v_mtot_log10.data + __pyx_t_11 * __pyx_v_mtot_log10.strides[0]) ))));
+0502:                 mtot[ii] = mt
        (__pyx_v_mtot[__pyx_v_ii]) = __pyx_v_mt;
 0503:             else:
+0504:                 mt = mtot[ii]
      /*else*/ {
        __pyx_v_mt = (__pyx_v_mtot[__pyx_v_ii]);
      }
      __pyx_L11:;
 0505: 
 0506:             # calculate some needed quantities
+0507:             mt_sqrt = sqrt(mt)
      __pyx_v_mt_sqrt = sqrt(__pyx_v_mt);
+0508:             kep_sa_mass_term = kep_sa_term * mt
      __pyx_v_kep_sa_mass_term = (__pyx_v_kep_sa_term * __pyx_v_mt);
 0509:             # fill `ival` with weight and grid-width in the mtot dimension
+0510:             my_trapz_grid_weight(ii, n_mtot, mtot_log10, ival)
      __pyx_f_8holodeck_7cyutils_my_trapz_grid_weight(__pyx_v_ii, __pyx_v_n_mtot, __pyx_v_mtot_log10, __pyx_v_ival);
 0511: 
 0512:             # precalculate some of the weighting factors over the 2D we have so far
+0513:             weight_ik = ival[1] * kval[1] / (ival[0] * kval[0])
      __pyx_v_weight_ik = (((__pyx_v_ival[1]) * (__pyx_v_kval[1])) / ((__pyx_v_ival[0]) * (__pyx_v_kval[0])));
 0514: 
 0515:             # iterate over mass ratios
+0516:             for jj in range(n_mrat):
      __pyx_t_16 = __pyx_v_n_mrat;
      __pyx_t_17 = __pyx_t_16;
      for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18+=1) {
        __pyx_v_jj = __pyx_t_18;
 0517:                 # fill `jval` with weight and grid-width in the mrat dimension
+0518:                 my_trapz_grid_weight(jj, n_mrat, mrat, jval)
        __pyx_f_8holodeck_7cyutils_my_trapz_grid_weight(__pyx_v_jj, __pyx_v_n_mrat, __pyx_v_mrat, __pyx_v_jval);
 0519:                 # calculate the weight factor for this grid-cell
 0520: 
+0521:                 weight = weight_ik * (jval[1] / jval[0])
        __pyx_v_weight = (__pyx_v_weight_ik * ((__pyx_v_jval[1]) / (__pyx_v_jval[0])));
 0522: 
 0523:                 # convert for mtot, mrat to m1, m2 s.t. m2 <= m1    [grams]
+0524:                 m1 = mt / (1.0 + mrat[jj])
        __pyx_t_11 = __pyx_v_jj;
        __pyx_v_m1 = (__pyx_v_mt / (1.0 + (*((double *) ( /* dim=0 */ (__pyx_v_mrat.data + __pyx_t_11 * __pyx_v_mrat.strides[0]) )))));
+0525:                 m2 = mt - m1
        __pyx_v_m2 = (__pyx_v_mt - __pyx_v_m1);
 0526:                 # calculate chirp-mass [grams]
+0527:                 mchirp = mt * pow(mrat[jj], three_fifths) / pow(1 + mrat[jj], six_fifths)
        __pyx_t_11 = __pyx_v_jj;
        __pyx_t_19 = __pyx_v_jj;
        __pyx_v_mchirp = ((__pyx_v_mt * pow((*((double *) ( /* dim=0 */ (__pyx_v_mrat.data + __pyx_t_11 * __pyx_v_mrat.strides[0]) ))), __pyx_v_three_fifths)) / pow((1.0 + (*((double *) ( /* dim=0 */ (__pyx_v_mrat.data + __pyx_t_19 * __pyx_v_mrat.strides[0]) )))), __pyx_v_six_fifths));
 0528: 
 0529:                 # n_c * (4*pi*c*d_c^2) * (1 + z)
+0530:                 hterm_pref = ndens[ii, jj, kk] * dc_term * zterm
        __pyx_t_19 = __pyx_v_ii;
        __pyx_t_11 = __pyx_v_jj;
        __pyx_t_20 = __pyx_v_kk;
        __pyx_v_hterm_pref = (((*((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_ndens.data + __pyx_t_19 * __pyx_v_ndens.strides[0]) ) + __pyx_t_11 * __pyx_v_ndens.strides[1]) ) + __pyx_t_20 * __pyx_v_ndens.strides[2]) ))) * __pyx_v_dc_term) * __pyx_v_zterm);
 0531:                 # GW_SRC_CONST^2 * 2^(4/3) * Mc^(10/3) * dc^-2 * n_c * (4*pi*d_c^2) * (1 + z)
+0532:                 hterm_pref *= pow(GW_SRC_CONST * mchirp * pow(2.0*mchirp, two_third) / dc_cm, 2)
        __pyx_v_hterm_pref = (__pyx_v_hterm_pref * pow((((__pyx_v_8holodeck_7cyutils_GW_SRC_CONST * __pyx_v_mchirp) * pow((2.0 * __pyx_v_mchirp), __pyx_v_two_third)) / __pyx_v_dc_cm), 2.0));
 0533: 
+0534:                 ecc_idx = ecc_idx_beg
        __pyx_v_ecc_idx = __pyx_v_ecc_idx_beg;
+0535:                 for ff in range(num_freq_harm):
        __pyx_t_21 = __pyx_v_num_freq_harm;
        __pyx_t_22 = __pyx_t_21;
        for (__pyx_t_23 = 0; __pyx_t_23 < __pyx_t_22; __pyx_t_23+=1) {
          __pyx_v_ff = __pyx_t_23;
+0536:                     unravel(sorted_index[ff], shape, &aa, &bb)
          __pyx_f_8holodeck_7cyutils_unravel((__pyx_v_sorted_index[__pyx_v_ff]), __pyx_v_shape, (&__pyx_v_aa), (&__pyx_v_bb));
 0537: 
+0538:                     nh = bb + 1
          __pyx_v_nh = (__pyx_v_bb + 1);
+0539:                     four_over_nh_squared = 4.0 / (nh * nh)
          __pyx_v_four_over_nh_squared = (4.0 / ((double)(__pyx_v_nh * __pyx_v_nh)));
+0540:                     gwfr = gwfobs[aa] * zterm / nh
          __pyx_t_20 = __pyx_v_aa;
          __pyx_v_gwfr = (((*((double *) ( /* dim=0 */ (__pyx_v_gwfobs.data + __pyx_t_20 * __pyx_v_gwfobs.strides[0]) ))) * __pyx_v_zterm) / ((double)__pyx_v_nh));
 0541: 
 0542:                     # rest-frame frequency corresponding to target observer-frame frequency of GW observations
+0543:                     sa = pow(kep_sa_mass_term / pow(gwfr, 2), one_third)
          __pyx_v_sa = pow((__pyx_v_kep_sa_mass_term / pow(__pyx_v_gwfr, 2.0)), __pyx_v_one_third);
+0544:                     sa_fourth = pow(sa, 4)
          __pyx_v_sa_fourth = pow(__pyx_v_sa, 4.0);
 0545: 
 0546:                     # ---- Interpolate eccentricity to this frequency
 0547: 
 0548:                     # try to get `ecc_idx` such that   frst[idx] < gwfr < frst[idx+1]
+0549:                     frst_evo_lo = frst_evo_pref[ecc_idx] * mt_sqrt
          __pyx_v_frst_evo_lo = ((__pyx_v_frst_evo_pref[__pyx_v_ecc_idx]) * __pyx_v_mt_sqrt);
+0550:                     frst_evo_hi = frst_evo_pref[ecc_idx+1] * mt_sqrt
          __pyx_v_frst_evo_hi = ((__pyx_v_frst_evo_pref[(__pyx_v_ecc_idx + 1)]) * __pyx_v_mt_sqrt);
+0551:                     while (gwfr > frst_evo_hi) & (ecc_idx < n_eccs - 2):
          while (1) {
            __pyx_t_15 = (((__pyx_v_gwfr > __pyx_v_frst_evo_hi) & (__pyx_v_ecc_idx < (__pyx_v_n_eccs - 2))) != 0);
            if (!__pyx_t_15) break;
+0552:                         frst_evo_lo = frst_evo_hi
            __pyx_v_frst_evo_lo = __pyx_v_frst_evo_hi;
+0553:                         ecc_idx += 1
            __pyx_v_ecc_idx = (__pyx_v_ecc_idx + 1);
+0554:                         frst_evo_hi = frst_evo_pref[ecc_idx+1] * mt_sqrt
            __pyx_v_frst_evo_hi = ((__pyx_v_frst_evo_pref[(__pyx_v_ecc_idx + 1)]) * __pyx_v_mt_sqrt);
          }
 0555: 
+0556:                     if jj == 0 and ff == 0:
          __pyx_t_24 = ((__pyx_v_jj == 0) != 0);
          if (__pyx_t_24) {
          } else {
            __pyx_t_15 = __pyx_t_24;
            goto __pyx_L19_bool_binop_done;
          }
          __pyx_t_24 = ((__pyx_v_ff == 0) != 0);
          __pyx_t_15 = __pyx_t_24;
          __pyx_L19_bool_binop_done:;
          if (__pyx_t_15) {
/* … */
          }
+0557:                         ecc_idx_beg = ecc_idx
            __pyx_v_ecc_idx_beg = __pyx_v_ecc_idx;
 0558: 
 0559:                     # if `gwfr` is lower than lowest evolution point, continue to next frequency
+0560:                     if (gwfr < frst_evo_lo):
          __pyx_t_15 = ((__pyx_v_gwfr < __pyx_v_frst_evo_lo) != 0);
          if (__pyx_t_15) {
/* … */
          }
+0561:                         continue
            goto __pyx_L14_continue;
 0562: 
 0563:                     # if `gwfr` is > highest evolution point, also be true for all following frequencies, so break
+0564:                     if (gwfr > frst_evo_hi):
          __pyx_t_15 = ((__pyx_v_gwfr > __pyx_v_frst_evo_hi) != 0);
          if (__pyx_t_15) {
/* … */
          }
+0565:                         break
            goto __pyx_L15_break;
 0566: 
 0567:                     # calculate slope M
+0568:                     ecc = ((eccen_evo[ecc_idx+1] - eccen_evo[ecc_idx])/(frst_evo_hi - frst_evo_lo))
          __pyx_v_ecc = (((__pyx_v_eccen_evo[(__pyx_v_ecc_idx + 1)]) - (__pyx_v_eccen_evo[__pyx_v_ecc_idx])) / (__pyx_v_frst_evo_hi - __pyx_v_frst_evo_lo));
 0569:                     # y = y_0 + M * dx
+0570:                     ecc = eccen_evo[ecc_idx] + (gwfr - frst_evo_lo) * ecc
          __pyx_v_ecc = ((__pyx_v_eccen_evo[__pyx_v_ecc_idx]) + ((__pyx_v_gwfr - __pyx_v_frst_evo_lo) * __pyx_v_ecc));
 0571: 
 0572:                     # ---- Calculate GWB contribution with this eccentricity
 0573: 
+0574:                     gne = gw_freq_dist_func__scalar_scalar(nh, ecc)
          __pyx_v_gne = __pyx_f_8holodeck_7cyutils_gw_freq_dist_func__scalar_scalar(__pyx_v_nh, __pyx_v_ecc);
 0575: 
+0576:                     fe_ecc = _gw_ecc_func(ecc)
          __pyx_v_fe_ecc = __pyx_f_8holodeck_7cyutils__gw_ecc_func(__pyx_v_ecc);
 0577:                     # da/dt values are negative, convert to a positive timescale
+0578:                     tau = - sa_fourth / (GW_DADT_SEP_CONST * fe_ecc * m1 * m2 * mt)
          __pyx_v_tau = ((-__pyx_v_sa_fourth) / ((((__pyx_v_8holodeck_7cyutils_GW_DADT_SEP_CONST * __pyx_v_fe_ecc) * __pyx_v_m1) * __pyx_v_m2) * __pyx_v_mt));
 0579: 
 0580:                     # Calculate the GW spectral strain at each harmonic
 0581:                     #    see: [Amaro-seoane+2010 Eq.9]
 0582:                     # GW_SRC_CONST^2 * 2^(4/3) * Mc^(10/3) * dc^-2 * n_c * (4*pi*c*d_c^2) * (1 + z)
 0583:                     #     tau * gne * (2/n)^2 * forb_r^(4/3)
+0584:                     hterm = hterm_pref * tau * gne * four_over_nh_squared * pow(gwfr, four_third)
          __pyx_v_hterm = ((((__pyx_v_hterm_pref * __pyx_v_tau) * __pyx_v_gne) * __pyx_v_four_over_nh_squared) * pow(__pyx_v_gwfr, __pyx_v_four_third));
+0585:                     gwb[aa, bb] += hterm * weight
          __pyx_t_20 = __pyx_v_aa;
          __pyx_t_11 = __pyx_v_bb;
          *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_gwb.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_gwb.diminfo[0].strides, __pyx_t_11, __pyx_pybuffernd_gwb.diminfo[1].strides) += (__pyx_v_hterm * __pyx_v_weight);
          __pyx_L14_continue:;
        }
        __pyx_L15_break:;
      }
    }
  }
 0586: 
+0587:     free(shape)
  free(__pyx_v_shape);
+0588:     free(sepa_evo)
  free(__pyx_v_sepa_evo);
+0589:     free(eccen_evo)
  free(__pyx_v_eccen_evo);
+0590:     free(frst_evo_pref)
  free(__pyx_v_frst_evo_pref);
+0591:     free(freq_harms)
  free(__pyx_v_freq_harms);
+0592:     free(sorted_index)
  free(__pyx_v_sorted_index);
+0593:     free(mtot)
  free(__pyx_v_mtot);
+0594:     free(ival)
  free(__pyx_v_ival);
+0595:     free(jval)
  free(__pyx_v_jval);
+0596:     free(kval)
  free(__pyx_v_kval);
+0597:     return gwb
  __pyx_t_25 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(((PyObject *)__pyx_v_gwb), PyBUF_WRITABLE); if (unlikely(!__pyx_t_25.memview)) __PYX_ERR(0, 597, __pyx_L1_error)
  __pyx_r = __pyx_t_25;
  __pyx_t_25.memview = NULL;
  __pyx_t_25.data = NULL;
  goto __pyx_L0;
 0598: 
 0599: 
+0600: def sam_calc_gwb_single_eccen_discrete(ndens, mtot_log10, mrat, redz, dcom, gwfobs, sepa_evo, eccen_evo, nharms, nreals):
/* Python wrapper */
static PyObject *__pyx_pw_8holodeck_7cyutils_3sam_calc_gwb_single_eccen_discrete(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8holodeck_7cyutils_2sam_calc_gwb_single_eccen_discrete[] = "Pure-python wrapper for the SAM eccentric GWB calculation method.  See: `_sam_calc_gwb_single_eccen()`.\n    ";
static PyMethodDef __pyx_mdef_8holodeck_7cyutils_3sam_calc_gwb_single_eccen_discrete = {"sam_calc_gwb_single_eccen_discrete", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8holodeck_7cyutils_3sam_calc_gwb_single_eccen_discrete, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8holodeck_7cyutils_2sam_calc_gwb_single_eccen_discrete};
static PyObject *__pyx_pw_8holodeck_7cyutils_3sam_calc_gwb_single_eccen_discrete(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_ndens = 0;
  PyObject *__pyx_v_mtot_log10 = 0;
  PyObject *__pyx_v_mrat = 0;
  PyObject *__pyx_v_redz = 0;
  PyObject *__pyx_v_dcom = 0;
  PyObject *__pyx_v_gwfobs = 0;
  PyObject *__pyx_v_sepa_evo = 0;
  PyObject *__pyx_v_eccen_evo = 0;
  PyObject *__pyx_v_nharms = 0;
  PyObject *__pyx_v_nreals = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sam_calc_gwb_single_eccen_discrete (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_ndens,&__pyx_n_s_mtot_log10,&__pyx_n_s_mrat,&__pyx_n_s_redz,&__pyx_n_s_dcom,&__pyx_n_s_gwfobs,&__pyx_n_s_sepa_evo,&__pyx_n_s_eccen_evo,&__pyx_n_s_nharms,&__pyx_n_s_nreals,0};
    PyObject* values[10] = {0,0,0,0,0,0,0,0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        CYTHON_FALLTHROUGH;
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        CYTHON_FALLTHROUGH;
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ndens)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mtot_log10)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sam_calc_gwb_single_eccen_discrete", 1, 10, 10, 1); __PYX_ERR(0, 600, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mrat)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sam_calc_gwb_single_eccen_discrete", 1, 10, 10, 2); __PYX_ERR(0, 600, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_redz)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sam_calc_gwb_single_eccen_discrete", 1, 10, 10, 3); __PYX_ERR(0, 600, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dcom)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sam_calc_gwb_single_eccen_discrete", 1, 10, 10, 4); __PYX_ERR(0, 600, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_gwfobs)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sam_calc_gwb_single_eccen_discrete", 1, 10, 10, 5); __PYX_ERR(0, 600, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (likely((values[6] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sepa_evo)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sam_calc_gwb_single_eccen_discrete", 1, 10, 10, 6); __PYX_ERR(0, 600, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  7:
        if (likely((values[7] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_eccen_evo)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sam_calc_gwb_single_eccen_discrete", 1, 10, 10, 7); __PYX_ERR(0, 600, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  8:
        if (likely((values[8] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_nharms)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sam_calc_gwb_single_eccen_discrete", 1, 10, 10, 8); __PYX_ERR(0, 600, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  9:
        if (likely((values[9] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_nreals)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sam_calc_gwb_single_eccen_discrete", 1, 10, 10, 9); __PYX_ERR(0, 600, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sam_calc_gwb_single_eccen_discrete") < 0)) __PYX_ERR(0, 600, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 10) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
      values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
      values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
      values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
      values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
    }
    __pyx_v_ndens = values[0];
    __pyx_v_mtot_log10 = values[1];
    __pyx_v_mrat = values[2];
    __pyx_v_redz = values[3];
    __pyx_v_dcom = values[4];
    __pyx_v_gwfobs = values[5];
    __pyx_v_sepa_evo = values[6];
    __pyx_v_eccen_evo = values[7];
    __pyx_v_nharms = values[8];
    __pyx_v_nreals = values[9];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("sam_calc_gwb_single_eccen_discrete", 1, 10, 10, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 600, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("holodeck.cyutils.sam_calc_gwb_single_eccen_discrete", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_8holodeck_7cyutils_2sam_calc_gwb_single_eccen_discrete(__pyx_self, __pyx_v_ndens, __pyx_v_mtot_log10, __pyx_v_mrat, __pyx_v_redz, __pyx_v_dcom, __pyx_v_gwfobs, __pyx_v_sepa_evo, __pyx_v_eccen_evo, __pyx_v_nharms, __pyx_v_nreals);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8holodeck_7cyutils_2sam_calc_gwb_single_eccen_discrete(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_ndens, PyObject *__pyx_v_mtot_log10, PyObject *__pyx_v_mrat, PyObject *__pyx_v_redz, PyObject *__pyx_v_dcom, PyObject *__pyx_v_gwfobs, PyObject *__pyx_v_sepa_evo, PyObject *__pyx_v_eccen_evo, PyObject *__pyx_v_nharms, PyObject *__pyx_v_nreals) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sam_calc_gwb_single_eccen_discrete", 0);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __PYX_XDEC_MEMVIEW(&__pyx_t_1, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_2, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_3, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_4, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_11, 1);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_AddTraceback("holodeck.cyutils.sam_calc_gwb_single_eccen_discrete", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__26 = PyTuple_Pack(10, __pyx_n_s_ndens, __pyx_n_s_mtot_log10, __pyx_n_s_mrat, __pyx_n_s_redz, __pyx_n_s_dcom, __pyx_n_s_gwfobs, __pyx_n_s_sepa_evo, __pyx_n_s_eccen_evo, __pyx_n_s_nharms, __pyx_n_s_nreals); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 600, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__26);
  __Pyx_GIVEREF(__pyx_tuple__26);
/* … */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_8holodeck_7cyutils_3sam_calc_gwb_single_eccen_discrete, NULL, __pyx_n_s_holodeck_cyutils); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 600, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sam_calc_gwb_single_eccen_discre, __pyx_t_3) < 0) __PYX_ERR(0, 600, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(10, 0, 10, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_holodeck_cyutils_pyx, __pyx_n_s_sam_calc_gwb_single_eccen_discre, 600, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 600, __pyx_L1_error)
 0601:     """Pure-python wrapper for the SAM eccentric GWB calculation method.  See: `_sam_calc_gwb_single_eccen()`.
 0602:     """
+0603:     return _sam_calc_gwb_single_eccen_discrete(ndens, mtot_log10, mrat, redz, dcom, gwfobs, sepa_evo, eccen_evo, nharms, nreals)
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_double(__pyx_v_ndens, PyBUF_WRITABLE); if (unlikely(!__pyx_t_1.memview)) __PYX_ERR(0, 603, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_mtot_log10, PyBUF_WRITABLE); if (unlikely(!__pyx_t_2.memview)) __PYX_ERR(0, 603, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_mrat, PyBUF_WRITABLE); if (unlikely(!__pyx_t_3.memview)) __PYX_ERR(0, 603, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_redz, PyBUF_WRITABLE); if (unlikely(!__pyx_t_4.memview)) __PYX_ERR(0, 603, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_dcom, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 603, __pyx_L1_error)
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_gwfobs, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 603, __pyx_L1_error)
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_sepa_evo, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 603, __pyx_L1_error)
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_eccen_evo, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 603, __pyx_L1_error)
  __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_v_nharms); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 603, __pyx_L1_error)
  __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_v_nreals); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 603, __pyx_L1_error)
  __pyx_t_11 = __pyx_f_8holodeck_7cyutils__sam_calc_gwb_single_eccen_discrete(__pyx_t_1, __pyx_t_2, __pyx_t_3, __pyx_t_4, __pyx_t_5, __pyx_t_6, __pyx_t_7, __pyx_t_8, __pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_11.memview)) __PYX_ERR(0, 603, __pyx_L1_error)
  __PYX_XDEC_MEMVIEW(&__pyx_t_1, 1);
  __pyx_t_1.memview = NULL;
  __pyx_t_1.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_2, 1);
  __pyx_t_2.memview = NULL;
  __pyx_t_2.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_3, 1);
  __pyx_t_3.memview = NULL;
  __pyx_t_3.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_4, 1);
  __pyx_t_4.memview = NULL;
  __pyx_t_4.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
  __pyx_t_5.memview = NULL;
  __pyx_t_5.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;
  __pyx_t_12 = __pyx_memoryview_fromslice(__pyx_t_11, 3, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 603, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __PYX_XDEC_MEMVIEW(&__pyx_t_11, 1);
  __pyx_t_11.memview = NULL;
  __pyx_t_11.data = NULL;
  __pyx_r = __pyx_t_12;
  __pyx_t_12 = 0;
  goto __pyx_L0;
 0604: 
 0605: @cython.boundscheck(False)
 0606: @cython.wraparound(False)
 0607: @cython.nonecheck(False)
 0608: @cython.cdivision(True)
+0609: cdef double[:, :, :] _sam_calc_gwb_single_eccen_discrete(
static __Pyx_memviewslice __pyx_f_8holodeck_7cyutils__sam_calc_gwb_single_eccen_discrete(__Pyx_memviewslice __pyx_v_ndens, __Pyx_memviewslice __pyx_v_mtot_log10, __Pyx_memviewslice __pyx_v_mrat, __Pyx_memviewslice __pyx_v_redz, __Pyx_memviewslice __pyx_v_dcom, __Pyx_memviewslice __pyx_v_gwfobs, __Pyx_memviewslice __pyx_v_sepa_evo_in, __Pyx_memviewslice __pyx_v_eccen_evo_in, int __pyx_v_nharms, int __pyx_v_nreals) {
  int __pyx_v_nfreqs;
  int __pyx_v_n_mtot;
  int __pyx_v_n_mrat;
  int __pyx_v_n_redz;
  int __pyx_v_n_eccs;
  int __pyx_v_num_freq_harm;
  int *__pyx_v_shape;
  bitgen_t *__pyx_v_rng;
  char const *__pyx_v_capsule_name;
  PyObject *__pyx_v_capsule = NULL;
  int __pyx_v_ii;
  int __pyx_v_nh;
  int __pyx_v_jj;
  int __pyx_v_kk;
  int __pyx_v_aa;
  int __pyx_v_bb;
  int __pyx_v_ff;
  int __pyx_v_rr;
  int __pyx_v_ecc_idx;
  int __pyx_v_ecc_idx_beg;
  int __pyx_v_ii_mm;
  double __pyx_v_m1;
  double __pyx_v_m2;
  double __pyx_v_mchirp;
  double __pyx_v_sa;
  double __pyx_v_tau;
  double __pyx_v_gwfr;
  double __pyx_v_zterm;
  double __pyx_v_dc_cm;
  double __pyx_v_dc_mpc;
  double __pyx_v_dc_term;
  double __pyx_v_gne;
  double __pyx_v_hterm;
  double __pyx_v_number_term;
  double __pyx_v_weight_ik;
  double __pyx_v_weight;
  double __pyx_v_four_over_nh_squared;
  double __pyx_v_sa_fourth;
  double __pyx_v_fe_ecc;
  double __pyx_v_mt;
  double __pyx_v_mt_sqrt;
  double __pyx_v_hterm_pref;
  double __pyx_v_frst_evo_lo;
  double __pyx_v_frst_evo_hi;
  double __pyx_v_four_pi_c_mpc;
  double __pyx_v_kep_sa_term;
  double __pyx_v_one_third;
  double __pyx_v_two_third;
  double __pyx_v_four_third;
  double __pyx_v_three_fifths;
  double __pyx_v_six_fifths;
  PyArrayObject *__pyx_v_gwb = 0;
  double *__pyx_v_mtot;
  double *__pyx_v_ival;
  double *__pyx_v_jval;
  double *__pyx_v_kval;
  double *__pyx_v_sepa_evo;
  double *__pyx_v_eccen_evo;
  double __pyx_v__freq_pref;
  double *__pyx_v_frst_evo_pref;
  double *__pyx_v_freq_harms;
  int *__pyx_v_sorted_index;
  double __pyx_v_kep_sa_mass_term;
  double __pyx_v_volume_ik;
  double __pyx_v_volume;
  PyObject *__pyx_v_number_term_pref = NULL;
  double __pyx_v_ecc;
  double __pyx_v_num_pois;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_gwb;
  __Pyx_Buffer __pyx_pybuffer_gwb;
  __Pyx_memviewslice __pyx_r = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_sam_calc_gwb_single_eccen_discrete", 0);
  __pyx_pybuffer_gwb.pybuffer.buf = NULL;
  __pyx_pybuffer_gwb.refcount = 0;
  __pyx_pybuffernd_gwb.data = NULL;
  __pyx_pybuffernd_gwb.rcbuffer = &__pyx_pybuffer_gwb;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __PYX_XDEC_MEMVIEW(&__pyx_t_31, 1);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_gwb.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __pyx_r.data = NULL;
  __pyx_r.memview = NULL;
  __Pyx_AddTraceback("holodeck.cyutils._sam_calc_gwb_single_eccen_discrete", __pyx_clineno, __pyx_lineno, __pyx_filename);
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_gwb.rcbuffer->pybuffer);
  if (unlikely(!__pyx_r.memview)) {
    PyErr_SetString(PyExc_TypeError, "Memoryview return value is not initialized");
  }
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_capsule);
  __Pyx_XDECREF((PyObject *)__pyx_v_gwb);
  __Pyx_XDECREF(__pyx_v_number_term_pref);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 0610:     double[:, :, :] ndens,
 0611:     double[:] mtot_log10,
 0612:     double[:] mrat,
 0613:     double[:] redz,
 0614:     double[:] dcom,
 0615:     double[:] gwfobs,
 0616:     double[:] sepa_evo_in,
 0617:     double[:] eccen_evo_in,
 0618:     int nharms,
 0619:     int nreals
 0620: ):
 0621:     """Calculate the GWB from an eccentric SAM evolution model.
 0622: 
 0623:     This function uses the precomputed binary-evolution of eccentricities over some range of separations.
 0624:     This assumes a single eccentricity evolution e(a) for all binaries.
 0625:     Redshifts are assumed to stay constant during this evolution.
 0626: 
 0627:     Parameters
 0628:     ----------
 0629:     ndens : (double ***)
 0630:         3D array specifying the SAM number-density of binaries in each bin, in total-mass, mass-ratio, and redshift.
 0631:         This is typically `sam.static_binary_density`, corresponding to 'd^3 n / [dlog10M dq dz]' in units of [Mpc^-3].
 0632:     mtot_log10 : (double *)
 0633:         Array of log10 values of the total-mass (in grams) grid edges in the SAM model.  i.e. `log10(sam.mtot)`.
 0634:     mrat : (double *)
 0635:         Array of mass-ratio grid edges in the SAM model.  i.e. `sam.mrat`.
 0636:     redz : (double *)
 0637:         Array of values for the redshift grid edges in the SAM model.  i.e. `sam.redz`.
 0638:     dcom : (double *)
 0639:         Comoving distances in units of [Mpc] corresponding to each `redz` value.
 0640:     gwfobs : (double *)
 0641:         Array of GW observer-frame frequencies at which to evaluate the GWB.
 0642:     sepa_evo_in : (double *)
 0643:         The values of binary separation in units of [cm] at which the binaries have been evolved.
 0644:     eccen_evo_in : (double *)
 0645:         The values of binary eccentricity at each separation at which the binaries have been evolved.
 0646:     nharms : int,
 0647:         Number of harmonics at which to calculate GW strains.
 0648: 
 0649:     Returns
 0650:     -------
 0651:     gwb : (double **)
 0652:         2D array giving the characteristic-strain _squared_, at each observer-frame frequency and each harmonic.
 0653:         Shape is (nfreqs, nharms), where `nfreqs` is the length of the `gwfobs` parameters, and `nharms` is given
 0654:         as an input parameter directly.
 0655:         The characteristic strain spectrum, h_c(f) is then `np.sqrt(gwb.sum(axis=1))`; i.e. the sum in quadrature of
 0656:         strain at each harmonic.
 0657: 
 0658:     """
 0659: 
 0660:     # Initialize sizes and shapes
+0661:     cdef int nfreqs = len(gwfobs)
  __pyx_t_1 = __Pyx_MemoryView_Len(__pyx_v_gwfobs); 
  __pyx_v_nfreqs = __pyx_t_1;
+0662:     cdef int n_mtot = len(mtot_log10)
  __pyx_t_1 = __Pyx_MemoryView_Len(__pyx_v_mtot_log10); 
  __pyx_v_n_mtot = __pyx_t_1;
+0663:     cdef int n_mrat = len(mrat)
  __pyx_t_1 = __Pyx_MemoryView_Len(__pyx_v_mrat); 
  __pyx_v_n_mrat = __pyx_t_1;
+0664:     cdef int n_redz = len(redz)
  __pyx_t_1 = __Pyx_MemoryView_Len(__pyx_v_redz); 
  __pyx_v_n_redz = __pyx_t_1;
+0665:     cdef int n_eccs = len(sepa_evo_in)
  __pyx_t_1 = __Pyx_MemoryView_Len(__pyx_v_sepa_evo_in); 
  __pyx_v_n_eccs = __pyx_t_1;
+0666:     cdef int num_freq_harm = nfreqs * nharms
  __pyx_v_num_freq_harm = (__pyx_v_nfreqs * __pyx_v_nharms);
+0667:     cdef (int *)shape = <int *>malloc(2 * sizeof(int))
  __pyx_v_shape = ((int *)malloc((2 * (sizeof(int)))));
+0668:     shape[0] = nfreqs
  (__pyx_v_shape[0]) = __pyx_v_nfreqs;
+0669:     shape[1] = nharms
  (__pyx_v_shape[1]) = __pyx_v_nharms;
 0670: 
 0671:     # Setup random number generator from numpy library
 0672:     cdef bitgen_t *rng
+0673:     cdef const char *capsule_name = "BitGenerator"
  __pyx_v_capsule_name = ((char const *)"BitGenerator");
+0674:     capsule = PCG64().capsule
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_PCG64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 674, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 674, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_capsule); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 674, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_capsule = __pyx_t_3;
  __pyx_t_3 = 0;
 0675:     # Cast the pointer
+0676:     rng = <bitgen_t *> PyCapsule_GetPointer(capsule, capsule_name)
  __pyx_t_5 = PyCapsule_GetPointer(__pyx_v_capsule, __pyx_v_capsule_name); if (unlikely(__pyx_t_5 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 676, __pyx_L1_error)
  __pyx_v_rng = ((bitgen_t *)__pyx_t_5);
 0677: 
 0678:     # Declare variables used later
 0679:     cdef int ii, nh, jj, kk, aa, bb, ff, rr, ecc_idx, ecc_idx_beg, ii_mm, kk_zz
 0680:     cdef double m1, m2, mchirp, sa, qq, tau
 0681:     cdef double gwfr, zterm, dc_cm, dc_mpc, dc_term, gne, hterm, number_term
 0682:     cdef double weight_ik, weight, four_over_nh_squared, sa_fourth
 0683:     cdef double fe_ecc, mt, mt_sqrt, nd, hterm_pref, frst_evo_lo, frst_evo_hi
 0684: 
 0685:     # Initialize constants
+0686:     cdef double four_pi_c_mpc = 4 * M_PI * (MY_SPLC / MY_MPC)
  __pyx_v_four_pi_c_mpc = ((4.0 * M_PI) * (__pyx_v_8holodeck_7cyutils_MY_SPLC / __pyx_v_8holodeck_7cyutils_MY_MPC));
+0687:     cdef double kep_sa_term = MY_NWTG / pow(2.0*M_PI, 2)
  __pyx_v_kep_sa_term = (__pyx_v_8holodeck_7cyutils_MY_NWTG / pow((2.0 * M_PI), 2.0));
+0688:     cdef double one_third = 1.0 / 3.0
  __pyx_v_one_third = (1.0 / 3.0);
+0689:     cdef double two_third = 2.0 / 3.0
  __pyx_v_two_third = (2.0 / 3.0);
+0690:     cdef double four_third = 4.0 / 3.0
  __pyx_v_four_third = (4.0 / 3.0);
+0691:     cdef double three_fifths = 3.0 / 5.0
  __pyx_v_three_fifths = (3.0 / 5.0);
+0692:     cdef double six_fifths = 6.0 / 5.0
  __pyx_v_six_fifths = (6.0 / 5.0);
 0693: 
 0694:     # Initialize arrays
+0695:     cdef np.ndarray[np.double_t, ndim=3] gwb = np.zeros((nfreqs, nharms, nreals))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_nfreqs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_nharms); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_nreals); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7);
  __pyx_t_2 = 0;
  __pyx_t_6 = 0;
  __pyx_t_7 = 0;
  __pyx_t_7 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_7, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_8);
  __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 695, __pyx_L1_error)
  __pyx_t_9 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_gwb.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_gwb = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_gwb.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 695, __pyx_L1_error)
    } else {__pyx_pybuffernd_gwb.diminfo[0].strides = __pyx_pybuffernd_gwb.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_gwb.diminfo[0].shape = __pyx_pybuffernd_gwb.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_gwb.diminfo[1].strides = __pyx_pybuffernd_gwb.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_gwb.diminfo[1].shape = __pyx_pybuffernd_gwb.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_gwb.diminfo[2].strides = __pyx_pybuffernd_gwb.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_gwb.diminfo[2].shape = __pyx_pybuffernd_gwb.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_9 = 0;
  __pyx_v_gwb = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;
+0696:     cdef double *mtot = <double *>malloc(n_mtot * sizeof(double))
  __pyx_v_mtot = ((double *)malloc((__pyx_v_n_mtot * (sizeof(double)))));
+0697:     cdef double *ival = <double *>malloc(2 * sizeof(double))
  __pyx_v_ival = ((double *)malloc((2 * (sizeof(double)))));
+0698:     cdef double *jval = <double *>malloc(2 * sizeof(double))
  __pyx_v_jval = ((double *)malloc((2 * (sizeof(double)))));
+0699:     cdef double *kval = <double *>malloc(2 * sizeof(double))
  __pyx_v_kval = ((double *)malloc((2 * (sizeof(double)))));
+0700:     cdef double *sepa_evo = <double *>malloc(n_eccs * sizeof(double))
  __pyx_v_sepa_evo = ((double *)malloc((__pyx_v_n_eccs * (sizeof(double)))));
+0701:     cdef double *eccen_evo = <double *>malloc(n_eccs * sizeof(double))
  __pyx_v_eccen_evo = ((double *)malloc((__pyx_v_n_eccs * (sizeof(double)))));
+0702:     cdef double _freq_pref = (1.0/(2.0*M_PI)) * sqrt(MY_NWTG)
  __pyx_v__freq_pref = ((1.0 / (2.0 * M_PI)) * sqrt(__pyx_v_8holodeck_7cyutils_MY_NWTG));
+0703:     cdef double *frst_evo_pref = <double *>malloc(n_eccs * sizeof(double))
  __pyx_v_frst_evo_pref = ((double *)malloc((__pyx_v_n_eccs * (sizeof(double)))));
 0704:     # Convert from numpy arrays to c-arrays (for possible speed improvements)
+0705:     for ii in range(n_eccs):
  __pyx_t_10 = __pyx_v_n_eccs;
  __pyx_t_11 = __pyx_t_10;
  for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {
    __pyx_v_ii = __pyx_t_12;
+0706:         sepa_evo[ii] = <double>sepa_evo_in[ii]
    __pyx_t_13 = __pyx_v_ii;
    (__pyx_v_sepa_evo[__pyx_v_ii]) = ((double)(*((double *) ( /* dim=0 */ (__pyx_v_sepa_evo_in.data + __pyx_t_13 * __pyx_v_sepa_evo_in.strides[0]) ))));
+0707:         eccen_evo[ii] = <double>eccen_evo_in[ii]
    __pyx_t_13 = __pyx_v_ii;
    (__pyx_v_eccen_evo[__pyx_v_ii]) = ((double)(*((double *) ( /* dim=0 */ (__pyx_v_eccen_evo_in.data + __pyx_t_13 * __pyx_v_eccen_evo_in.strides[0]) ))));
 0708:         # calculate the prefactor (i.e. everything except the mass) for kepler's law
+0709:         frst_evo_pref[ii] = _freq_pref / pow(sepa_evo[ii], 1.5)
    (__pyx_v_frst_evo_pref[__pyx_v_ii]) = (__pyx_v__freq_pref / pow((__pyx_v_sepa_evo[__pyx_v_ii]), 1.5));
  }
 0710: 
 0711:     # Calculate all of the frequency harmonics (flattened) that are needed
+0712:     cdef (double *)freq_harms = <double *>malloc(num_freq_harm * sizeof(double))
  __pyx_v_freq_harms = ((double *)malloc((__pyx_v_num_freq_harm * (sizeof(double)))));
+0713:     for ii in range(num_freq_harm):
  __pyx_t_10 = __pyx_v_num_freq_harm;
  __pyx_t_11 = __pyx_t_10;
  for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {
    __pyx_v_ii = __pyx_t_12;
 0714:         # convert from 1D index to 2D grid of (F, H) frequencies and harmonics
+0715:         unravel(ii, shape, &aa, &bb)
    __pyx_f_8holodeck_7cyutils_unravel(__pyx_v_ii, __pyx_v_shape, (&__pyx_v_aa), (&__pyx_v_bb));
 0716:         # calculate the n = bb+1 harmonic
+0717:         freq_harms[ii] = gwfobs[aa] / (bb + 1)
    __pyx_t_13 = __pyx_v_aa;
    (__pyx_v_freq_harms[__pyx_v_ii]) = ((*((double *) ( /* dim=0 */ (__pyx_v_gwfobs.data + __pyx_t_13 * __pyx_v_gwfobs.strides[0]) ))) / ((double)(__pyx_v_bb + 1)));
  }
 0718: 
 0719:     # Find the indices by which to sort the frequency harmonics (flattened)
+0720:     cdef (int *)sorted_index = <int *>malloc(num_freq_harm * sizeof(int))
  __pyx_v_sorted_index = ((int *)malloc((__pyx_v_num_freq_harm * (sizeof(int)))));
+0721:     argsort(freq_harms, num_freq_harm, &sorted_index)
  __pyx_f_8holodeck_7cyutils_argsort(__pyx_v_freq_harms, __pyx_v_num_freq_harm, (&__pyx_v_sorted_index));
 0722: 
 0723:     # iterate over redshifts Z
+0724:     for kk in range(n_redz):
  __pyx_t_10 = __pyx_v_n_redz;
  __pyx_t_11 = __pyx_t_10;
  for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {
    __pyx_v_kk = __pyx_t_12;
 0725:         # fill `kval` with the weight of this grid point (kval[0]), and the grid-width (kval[1])
+0726:         my_trapz_grid_weight(kk, n_redz, redz, kval)
    __pyx_f_8holodeck_7cyutils_my_trapz_grid_weight(__pyx_v_kk, __pyx_v_n_redz, __pyx_v_redz, __pyx_v_kval);
+0727:         zterm = (1.0 + redz[kk])
    __pyx_t_13 = __pyx_v_kk;
    __pyx_v_zterm = (1.0 + (*((double *) ( /* dim=0 */ (__pyx_v_redz.data + __pyx_t_13 * __pyx_v_redz.strides[0]) ))));
+0728:         dc_mpc = dcom[kk]   # this is still in units of [Mpc]
    __pyx_t_13 = __pyx_v_kk;
    __pyx_v_dc_mpc = (*((double *) ( /* dim=0 */ (__pyx_v_dcom.data + __pyx_t_13 * __pyx_v_dcom.strides[0]) )));
+0729:         dc_cm = dc_mpc * MY_MPC  # convert to [cm]
    __pyx_v_dc_cm = (__pyx_v_dc_mpc * __pyx_v_8holodeck_7cyutils_MY_MPC);
+0730:         dc_term = four_pi_c_mpc * pow(dc_mpc, 2)
    __pyx_v_dc_term = (__pyx_v_four_pi_c_mpc * pow(__pyx_v_dc_mpc, 2.0));
 0731: 
 0732:         # iterate over mtot M
+0733:         ecc_idx_beg = 0   # we will keep track of evolution/eccentricity indices for our target
    __pyx_v_ecc_idx_beg = 0;
 0734:                           # frequencies to make suring the arrays faster
 0735:         # iterate over total masses in reverse, so that's we're always going to increasing frequencies
+0736:         for ii_mm in range(n_mtot):
    __pyx_t_14 = __pyx_v_n_mtot;
    __pyx_t_15 = __pyx_t_14;
    for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
      __pyx_v_ii_mm = __pyx_t_16;
 0737:             # convert from forward to backward indices
+0738:             ii = n_mtot - 1 - ii_mm
      __pyx_v_ii = ((__pyx_v_n_mtot - 1) - __pyx_v_ii_mm);
 0739: 
 0740:             # convert from log10 to regular total masses, only the first time through the loop
+0741:             if kk == 0:
      __pyx_t_17 = ((__pyx_v_kk == 0) != 0);
      if (__pyx_t_17) {
/* … */
        goto __pyx_L11;
      }
+0742:                 mt = pow(10.0, mtot_log10[ii])
        __pyx_t_13 = __pyx_v_ii;
        __pyx_v_mt = pow(10.0, (*((double *) ( /* dim=0 */ (__pyx_v_mtot_log10.data + __pyx_t_13 * __pyx_v_mtot_log10.strides[0]) ))));
+0743:                 mtot[ii] = mt
        (__pyx_v_mtot[__pyx_v_ii]) = __pyx_v_mt;
 0744:             else:
+0745:                 mt = mtot[ii]
      /*else*/ {
        __pyx_v_mt = (__pyx_v_mtot[__pyx_v_ii]);
      }
      __pyx_L11:;
 0746: 
 0747:             # calculate some needed quantities
+0748:             mt_sqrt = sqrt(mt)
      __pyx_v_mt_sqrt = sqrt(__pyx_v_mt);
+0749:             kep_sa_mass_term = kep_sa_term * mt
      __pyx_v_kep_sa_mass_term = (__pyx_v_kep_sa_term * __pyx_v_mt);
 0750:             # fill `ival` with weight and grid-width in the mtot dimension
+0751:             my_trapz_grid_weight(ii, n_mtot, mtot_log10, ival)
      __pyx_f_8holodeck_7cyutils_my_trapz_grid_weight(__pyx_v_ii, __pyx_v_n_mtot, __pyx_v_mtot_log10, __pyx_v_ival);
 0752: 
 0753:             # precalculate some of the weighting factors over the 2D we have so far
+0754:             volume_ik = ival[1] * kval[1]
      __pyx_v_volume_ik = ((__pyx_v_ival[1]) * (__pyx_v_kval[1]));
+0755:             weight_ik = ival[0] * kval[0]
      __pyx_v_weight_ik = ((__pyx_v_ival[0]) * (__pyx_v_kval[0]));
 0756: 
 0757:             # iterate over mass ratios
+0758:             for jj in range(n_mrat):
      __pyx_t_18 = __pyx_v_n_mrat;
      __pyx_t_19 = __pyx_t_18;
      for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_19; __pyx_t_20+=1) {
        __pyx_v_jj = __pyx_t_20;
 0759:                 # fill `jval` with weight and grid-width in the mrat dimension
+0760:                 my_trapz_grid_weight(jj, n_mrat, mrat, jval)
        __pyx_f_8holodeck_7cyutils_my_trapz_grid_weight(__pyx_v_jj, __pyx_v_n_mrat, __pyx_v_mrat, __pyx_v_jval);
 0761:                 # calculate the weight factor for this grid-cell
 0762:                 # weight = weight_ik * (jval[1] / jval[0])
 0763: 
+0764:                 volume = volume_ik * jval[1]
        __pyx_v_volume = (__pyx_v_volume_ik * (__pyx_v_jval[1]));
+0765:                 weight = weight_ik * jval[0]
        __pyx_v_weight = (__pyx_v_weight_ik * (__pyx_v_jval[0]));
 0766: 
 0767:                 # convert for mtot, mrat to m1, m2 s.t. m2 <= m1    [grams]
+0768:                 m1 = mt / (1.0 + mrat[jj])
        __pyx_t_13 = __pyx_v_jj;
        __pyx_v_m1 = (__pyx_v_mt / (1.0 + (*((double *) ( /* dim=0 */ (__pyx_v_mrat.data + __pyx_t_13 * __pyx_v_mrat.strides[0]) )))));
+0769:                 m2 = mt - m1
        __pyx_v_m2 = (__pyx_v_mt - __pyx_v_m1);
 0770:                 # calculate chirp-mass [grams]
+0771:                 mchirp = mt * pow(mrat[jj], three_fifths) / pow(1 + mrat[jj], six_fifths)
        __pyx_t_13 = __pyx_v_jj;
        __pyx_t_21 = __pyx_v_jj;
        __pyx_v_mchirp = ((__pyx_v_mt * pow((*((double *) ( /* dim=0 */ (__pyx_v_mrat.data + __pyx_t_13 * __pyx_v_mrat.strides[0]) ))), __pyx_v_three_fifths)) / pow((1.0 + (*((double *) ( /* dim=0 */ (__pyx_v_mrat.data + __pyx_t_21 * __pyx_v_mrat.strides[0]) )))), __pyx_v_six_fifths));
 0772: 
 0773:                 # n_c * (4*pi*c*d_c^2) * (1 + z)
+0774:                 number_term_pref = ndens[ii, jj, kk] * dc_term * zterm
        __pyx_t_21 = __pyx_v_ii;
        __pyx_t_13 = __pyx_v_jj;
        __pyx_t_22 = __pyx_v_kk;
        __pyx_t_3 = PyFloat_FromDouble((((*((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_ndens.data + __pyx_t_21 * __pyx_v_ndens.strides[0]) ) + __pyx_t_13 * __pyx_v_ndens.strides[1]) ) + __pyx_t_22 * __pyx_v_ndens.strides[2]) ))) * __pyx_v_dc_term) * __pyx_v_zterm)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 774, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_XDECREF_SET(__pyx_v_number_term_pref, __pyx_t_3);
        __pyx_t_3 = 0;
 0775:                 # GW_SRC_CONST^2 * 2^(4/3) * Mc^(10/3) * dc^-2
+0776:                 hterm_pref = pow(GW_SRC_CONST * mchirp * pow(2.0*mchirp, two_third) / dc_cm, 2)
        __pyx_v_hterm_pref = pow((((__pyx_v_8holodeck_7cyutils_GW_SRC_CONST * __pyx_v_mchirp) * pow((2.0 * __pyx_v_mchirp), __pyx_v_two_third)) / __pyx_v_dc_cm), 2.0);
 0777: 
+0778:                 ecc_idx = ecc_idx_beg
        __pyx_v_ecc_idx = __pyx_v_ecc_idx_beg;
+0779:                 for ff in range(num_freq_harm):
        __pyx_t_23 = __pyx_v_num_freq_harm;
        __pyx_t_24 = __pyx_t_23;
        for (__pyx_t_25 = 0; __pyx_t_25 < __pyx_t_24; __pyx_t_25+=1) {
          __pyx_v_ff = __pyx_t_25;
+0780:                     unravel(sorted_index[ff], shape, &aa, &bb)
          __pyx_f_8holodeck_7cyutils_unravel((__pyx_v_sorted_index[__pyx_v_ff]), __pyx_v_shape, (&__pyx_v_aa), (&__pyx_v_bb));
 0781: 
+0782:                     nh = bb + 1
          __pyx_v_nh = (__pyx_v_bb + 1);
+0783:                     four_over_nh_squared = 4.0 / (nh * nh)
          __pyx_v_four_over_nh_squared = (4.0 / ((double)(__pyx_v_nh * __pyx_v_nh)));
+0784:                     gwfr = gwfobs[aa] * zterm / nh
          __pyx_t_22 = __pyx_v_aa;
          __pyx_v_gwfr = (((*((double *) ( /* dim=0 */ (__pyx_v_gwfobs.data + __pyx_t_22 * __pyx_v_gwfobs.strides[0]) ))) * __pyx_v_zterm) / ((double)__pyx_v_nh));
 0785: 
 0786:                     # rest-frame frequency corresponding to target observer-frame frequency of GW observations
+0787:                     sa = pow(kep_sa_mass_term / pow(gwfr, 2), one_third)
          __pyx_v_sa = pow((__pyx_v_kep_sa_mass_term / pow(__pyx_v_gwfr, 2.0)), __pyx_v_one_third);
+0788:                     sa_fourth = pow(sa, 4)
          __pyx_v_sa_fourth = pow(__pyx_v_sa, 4.0);
 0789: 
 0790:                     # ---- Interpolate eccentricity to this frequency
 0791: 
 0792:                     # try to get `ecc_idx` such that   frst[idx] < gwfr < frst[idx+1]
+0793:                     frst_evo_lo = frst_evo_pref[ecc_idx] * mt_sqrt
          __pyx_v_frst_evo_lo = ((__pyx_v_frst_evo_pref[__pyx_v_ecc_idx]) * __pyx_v_mt_sqrt);
+0794:                     frst_evo_hi = frst_evo_pref[ecc_idx+1] * mt_sqrt
          __pyx_v_frst_evo_hi = ((__pyx_v_frst_evo_pref[(__pyx_v_ecc_idx + 1)]) * __pyx_v_mt_sqrt);
+0795:                     while (gwfr > frst_evo_hi) & (ecc_idx < n_eccs - 2):
          while (1) {
            __pyx_t_17 = (((__pyx_v_gwfr > __pyx_v_frst_evo_hi) & (__pyx_v_ecc_idx < (__pyx_v_n_eccs - 2))) != 0);
            if (!__pyx_t_17) break;
+0796:                         frst_evo_lo = frst_evo_hi
            __pyx_v_frst_evo_lo = __pyx_v_frst_evo_hi;
+0797:                         ecc_idx += 1
            __pyx_v_ecc_idx = (__pyx_v_ecc_idx + 1);
+0798:                         frst_evo_hi = frst_evo_pref[ecc_idx+1] * mt_sqrt
            __pyx_v_frst_evo_hi = ((__pyx_v_frst_evo_pref[(__pyx_v_ecc_idx + 1)]) * __pyx_v_mt_sqrt);
          }
 0799: 
+0800:                     if jj == 0 and ff == 0:
          __pyx_t_26 = ((__pyx_v_jj == 0) != 0);
          if (__pyx_t_26) {
          } else {
            __pyx_t_17 = __pyx_t_26;
            goto __pyx_L19_bool_binop_done;
          }
          __pyx_t_26 = ((__pyx_v_ff == 0) != 0);
          __pyx_t_17 = __pyx_t_26;
          __pyx_L19_bool_binop_done:;
          if (__pyx_t_17) {
/* … */
          }
+0801:                         ecc_idx_beg = ecc_idx
            __pyx_v_ecc_idx_beg = __pyx_v_ecc_idx;
 0802: 
 0803:                     # if `gwfr` is lower than lowest evolution point, continue to next frequency
+0804:                     if (gwfr < frst_evo_lo):
          __pyx_t_17 = ((__pyx_v_gwfr < __pyx_v_frst_evo_lo) != 0);
          if (__pyx_t_17) {
/* … */
          }
+0805:                         continue
            goto __pyx_L14_continue;
 0806: 
 0807:                     # if `gwfr` is > highest evolution point, also be true for all following frequencies, so break
+0808:                     if (gwfr > frst_evo_hi):
          __pyx_t_17 = ((__pyx_v_gwfr > __pyx_v_frst_evo_hi) != 0);
          if (__pyx_t_17) {
/* … */
          }
+0809:                         break
            goto __pyx_L15_break;
 0810: 
 0811:                     # calculate slope M
+0812:                     ecc = (eccen_evo[ecc_idx+1] - eccen_evo[ecc_idx]) / (frst_evo_hi - frst_evo_lo)
          __pyx_v_ecc = (((__pyx_v_eccen_evo[(__pyx_v_ecc_idx + 1)]) - (__pyx_v_eccen_evo[__pyx_v_ecc_idx])) / (__pyx_v_frst_evo_hi - __pyx_v_frst_evo_lo));
 0813:                     # y = y_0 + M * dx
+0814:                     ecc = eccen_evo[ecc_idx] + (gwfr - frst_evo_lo) * ecc
          __pyx_v_ecc = ((__pyx_v_eccen_evo[__pyx_v_ecc_idx]) + ((__pyx_v_gwfr - __pyx_v_frst_evo_lo) * __pyx_v_ecc));
 0815: 
 0816:                     # ---- Calculate GWB contribution with this eccentricity
 0817: 
+0818:                     gne = gw_freq_dist_func__scalar_scalar(nh, ecc)
          __pyx_v_gne = __pyx_f_8holodeck_7cyutils_gw_freq_dist_func__scalar_scalar(__pyx_v_nh, __pyx_v_ecc);
 0819: 
+0820:                     fe_ecc = _gw_ecc_func(ecc)
          __pyx_v_fe_ecc = __pyx_f_8holodeck_7cyutils__gw_ecc_func(__pyx_v_ecc);
 0821:                     # da/dt values are negative, convert to a positive timescale
+0822:                     tau = - sa_fourth / (GW_DADT_SEP_CONST * fe_ecc * m1 * m2 * mt)
          __pyx_v_tau = ((-__pyx_v_sa_fourth) / ((((__pyx_v_8holodeck_7cyutils_GW_DADT_SEP_CONST * __pyx_v_fe_ecc) * __pyx_v_m1) * __pyx_v_m2) * __pyx_v_mt));
 0823: 
 0824:                     # Calculate the GW spectral strain at each harmonic
 0825:                     #    see: [Amaro-seoane+2010 Eq.9]
 0826: 
 0827:                     # n_c * (4*pi*c*d_c^2) * (1 + z) * tau * dM*dq*dz
+0828:                     number_term = number_term_pref * tau * volume
          __pyx_t_3 = PyFloat_FromDouble(__pyx_v_tau); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 828, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_4 = PyNumber_Multiply(__pyx_v_number_term_pref, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 828, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_3 = PyFloat_FromDouble(__pyx_v_volume); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 828, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_8 = PyNumber_Multiply(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 828, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_27 = __pyx_PyFloat_AsDouble(__pyx_t_8); if (unlikely((__pyx_t_27 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 828, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_v_number_term = __pyx_t_27;
 0829: 
 0830:                     # GW_SRC_CONST^2 * 2^(4/3) * Mc^(10/3) * gne * (2/n)^2 * forb_r^(4/3) * dc^-2
+0831:                     hterm = hterm_pref * gne * four_over_nh_squared * pow(gwfr, four_third)
          __pyx_v_hterm = (((__pyx_v_hterm_pref * __pyx_v_gne) * __pyx_v_four_over_nh_squared) * pow(__pyx_v_gwfr, __pyx_v_four_third));
 0832: 
+0833:                     for rr in range(nreals):
          __pyx_t_28 = __pyx_v_nreals;
          __pyx_t_29 = __pyx_t_28;
          for (__pyx_t_30 = 0; __pyx_t_30 < __pyx_t_29; __pyx_t_30+=1) {
            __pyx_v_rr = __pyx_t_30;
 0834:                         # npy_int64 random_poisson(bitgen_t *bitgen_state, double lam)
+0835:                         num_pois = <double>random_poisson(rng, number_term)
            /* "holodeck/cyutils.pyx":835
 *                     for rr in range(nreals):
 *                         # npy_int64 random_poisson(bitgen_t *bitgen_state, double lam)
 *                         num_pois = <double>random_poisson(rng, number_term)             # <<<<<<<<<<<<<<
 * 
 *                         # GW_SRC_CONST^2 * 2^(4/3) * Mc^(10/3) * gne * (2/n)^2 * forb_r^(4/3) * dc^-2 *
 */
            __pyx_v_num_pois = ((double)random_poisson(__pyx_v_rng, __pyx_v_number_term));
 0836: 
 0837:                         # GW_SRC_CONST^2 * 2^(4/3) * Mc^(10/3) * gne * (2/n)^2 * forb_r^(4/3) * dc^-2 *
 0838:                         #     n_c * (4*pi*c*d_c^2) * (1 + z) * tau * dM*dq*dz * trapz-weight
+0839:                         gwb[aa, bb, rr] += hterm * num_pois / weight
            __pyx_t_22 = __pyx_v_aa;
            __pyx_t_13 = __pyx_v_bb;
            __pyx_t_21 = __pyx_v_rr;
            *__Pyx_BufPtrStrided3d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_gwb.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_gwb.diminfo[0].strides, __pyx_t_13, __pyx_pybuffernd_gwb.diminfo[1].strides, __pyx_t_21, __pyx_pybuffernd_gwb.diminfo[2].strides) += ((__pyx_v_hterm * __pyx_v_num_pois) / __pyx_v_weight);
          }
          __pyx_L14_continue:;
        }
        __pyx_L15_break:;
      }
    }
  }
 0840: 
+0841:     free(shape)
  free(__pyx_v_shape);
+0842:     free(sepa_evo)
  free(__pyx_v_sepa_evo);
+0843:     free(eccen_evo)
  free(__pyx_v_eccen_evo);
+0844:     free(frst_evo_pref)
  free(__pyx_v_frst_evo_pref);
+0845:     free(freq_harms)
  free(__pyx_v_freq_harms);
+0846:     free(sorted_index)
  free(__pyx_v_sorted_index);
+0847:     free(mtot)
  free(__pyx_v_mtot);
+0848:     free(ival)
  free(__pyx_v_ival);
+0849:     free(jval)
  free(__pyx_v_jval);
+0850:     free(kval)
  free(__pyx_v_kval);
+0851:     return gwb
  __pyx_t_31 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_double(((PyObject *)__pyx_v_gwb), PyBUF_WRITABLE); if (unlikely(!__pyx_t_31.memview)) __PYX_ERR(0, 851, __pyx_L1_error)
  __pyx_r = __pyx_t_31;
  __pyx_t_31.memview = NULL;
  __pyx_t_31.data = NULL;
  goto __pyx_L0;
 0852: 
 0853: 
+0854: def sam_poisson_gwb(dist, hc2, nreals, normal_threshold=1e10):
/* Python wrapper */
static PyObject *__pyx_pw_8holodeck_7cyutils_5sam_poisson_gwb(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_8holodeck_7cyutils_5sam_poisson_gwb = {"sam_poisson_gwb", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8holodeck_7cyutils_5sam_poisson_gwb, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_8holodeck_7cyutils_5sam_poisson_gwb(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_dist = 0;
  PyObject *__pyx_v_hc2 = 0;
  PyObject *__pyx_v_nreals = 0;
  PyObject *__pyx_v_normal_threshold = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sam_poisson_gwb (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_dist,&__pyx_n_s_hc2,&__pyx_n_s_nreals,&__pyx_n_s_normal_threshold,0};
    PyObject* values[4] = {0,0,0,0};
    values[3] = ((PyObject *)__pyx_float_1e10);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dist)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_hc2)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sam_poisson_gwb", 0, 3, 4, 1); __PYX_ERR(0, 854, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_nreals)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sam_poisson_gwb", 0, 3, 4, 2); __PYX_ERR(0, 854, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_normal_threshold);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sam_poisson_gwb") < 0)) __PYX_ERR(0, 854, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_dist = values[0];
    __pyx_v_hc2 = values[1];
    __pyx_v_nreals = values[2];
    __pyx_v_normal_threshold = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("sam_poisson_gwb", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 854, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("holodeck.cyutils.sam_poisson_gwb", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_8holodeck_7cyutils_4sam_poisson_gwb(__pyx_self, __pyx_v_dist, __pyx_v_hc2, __pyx_v_nreals, __pyx_v_normal_threshold);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8holodeck_7cyutils_4sam_poisson_gwb(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_dist, PyObject *__pyx_v_hc2, PyObject *__pyx_v_nreals, PyObject *__pyx_v_normal_threshold) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sam_poisson_gwb", 0);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __Pyx_AddTraceback("holodeck.cyutils.sam_poisson_gwb", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__28 = PyTuple_Pack(4, __pyx_n_s_dist, __pyx_n_s_hc2, __pyx_n_s_nreals, __pyx_n_s_normal_threshold); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 854, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__28);
  __Pyx_GIVEREF(__pyx_tuple__28);
/* … */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_8holodeck_7cyutils_5sam_poisson_gwb, NULL, __pyx_n_s_holodeck_cyutils); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 854, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sam_poisson_gwb, __pyx_t_3) < 0) __PYX_ERR(0, 854, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_codeobj__29 = (PyObject*)__Pyx_PyCode_New(4, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_holodeck_cyutils_pyx, __pyx_n_s_sam_poisson_gwb, 854, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__29)) __PYX_ERR(0, 854, __pyx_L1_error)
+0855:     return _sam_poisson_gwb(np.array(dist.shape), dist, hc2, nreals, long(normal_threshold))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 855, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 855, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_dist, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 855, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 855, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 855, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_double(__pyx_v_dist, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 855, __pyx_L1_error)
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_double(__pyx_v_hc2, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 855, __pyx_L1_error)
  __pyx_t_8 = __Pyx_PyInt_As_int(__pyx_v_nreals); if (unlikely((__pyx_t_8 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 855, __pyx_L1_error)
  __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyLong_Type)), __pyx_v_normal_threshold); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 855, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_9 = __Pyx_PyInt_As_long(__pyx_t_1); if (unlikely((__pyx_t_9 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 855, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_10 = __pyx_f_8holodeck_7cyutils__sam_poisson_gwb(__pyx_t_5, __pyx_t_6, __pyx_t_7, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 855, __pyx_L1_error)
  __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
  __pyx_t_5.memview = NULL;
  __pyx_t_5.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;
  __pyx_t_1 = __pyx_memoryview_fromslice(__pyx_t_10, 2, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 855, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;
 0856: 
 0857: 
 0858: @cython.boundscheck(False)
 0859: @cython.wraparound(False)
 0860: @cython.nonecheck(False)
 0861: @cython.cdivision(True)
+0862: cdef double[:, :] _sam_poisson_gwb(
static __Pyx_memviewslice __pyx_f_8holodeck_7cyutils__sam_poisson_gwb(__Pyx_memviewslice __pyx_v_shape, __Pyx_memviewslice __pyx_v_dist, __Pyx_memviewslice __pyx_v_hc2, int __pyx_v_nreals, long __pyx_v_thresh) {
  int __pyx_v_nm;
  int __pyx_v_nq;
  int __pyx_v_nz;
  int __pyx_v_nf;
  int __pyx_v_ii;
  int __pyx_v_jj;
  int __pyx_v_kk;
  int __pyx_v_ff;
  int __pyx_v_rr;
  double __pyx_v_num;
  double __pyx_v_bin_hc2;
  double __pyx_v_bin_num;
  bitgen_t *__pyx_v_rng;
  char const *__pyx_v_capsule_name;
  PyObject *__pyx_v_capsule = NULL;
  PyArrayObject *__pyx_v_gwb = 0;
  double __pyx_v_bin_std;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_gwb;
  __Pyx_Buffer __pyx_pybuffer_gwb;
  __Pyx_memviewslice __pyx_r = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_sam_poisson_gwb", 0);
  __pyx_pybuffer_gwb.pybuffer.buf = NULL;
  __pyx_pybuffer_gwb.refcount = 0;
  __pyx_pybuffernd_gwb.data = NULL;
  __pyx_pybuffernd_gwb.rcbuffer = &__pyx_pybuffer_gwb;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __PYX_XDEC_MEMVIEW(&__pyx_t_28, 1);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_gwb.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __pyx_r.data = NULL;
  __pyx_r.memview = NULL;
  __Pyx_AddTraceback("holodeck.cyutils._sam_poisson_gwb", __pyx_clineno, __pyx_lineno, __pyx_filename);
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_gwb.rcbuffer->pybuffer);
  if (unlikely(!__pyx_r.memview)) {
    PyErr_SetString(PyExc_TypeError, "Memoryview return value is not initialized");
  }
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_capsule);
  __Pyx_XDECREF((PyObject *)__pyx_v_gwb);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 0863:     long[:] shape, double[:, :, :, :] dist, double[:, :, :, :] hc2, int nreals, long thresh
 0864: ):
+0865:     cdef int nm = shape[0]
  __pyx_t_1 = 0;
  __pyx_v_nm = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+0866:     cdef int nq = shape[1]
  __pyx_t_1 = 1;
  __pyx_v_nq = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+0867:     cdef int nz = shape[2]
  __pyx_t_1 = 2;
  __pyx_v_nz = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+0868:     cdef int nf = shape[3]
  __pyx_t_1 = 3;
  __pyx_v_nf = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
 0869:     cdef int ii, jj, kk, ff, rr
 0870:     cdef double num, bin_hc2, bin_num
 0871: 
 0872:     # Setup random number generator from numpy library
 0873:     cdef bitgen_t *rng
+0874:     cdef const char *capsule_name = "BitGenerator"
  __pyx_v_capsule_name = ((char const *)"BitGenerator");
+0875:     capsule = PCG64().capsule
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_PCG64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 875, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 875, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_capsule); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 875, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_capsule = __pyx_t_3;
  __pyx_t_3 = 0;
 0876:     # Cast the pointer
+0877:     rng = <bitgen_t *> PyCapsule_GetPointer(capsule, capsule_name)
  __pyx_t_5 = PyCapsule_GetPointer(__pyx_v_capsule, __pyx_v_capsule_name); if (unlikely(__pyx_t_5 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 877, __pyx_L1_error)
  __pyx_v_rng = ((bitgen_t *)__pyx_t_5);
 0878: 
 0879: 
+0880:     cdef np.ndarray[np.double_t, ndim=2] gwb = np.zeros((nf, nreals))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 880, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 880, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_nf); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 880, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_nreals); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 880, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 880, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
  __pyx_t_2 = 0;
  __pyx_t_6 = 0;
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_7);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 880, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 880, __pyx_L1_error)
  __pyx_t_8 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_gwb.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_gwb = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_gwb.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 880, __pyx_L1_error)
    } else {__pyx_pybuffernd_gwb.diminfo[0].strides = __pyx_pybuffernd_gwb.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_gwb.diminfo[0].shape = __pyx_pybuffernd_gwb.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_gwb.diminfo[1].strides = __pyx_pybuffernd_gwb.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_gwb.diminfo[1].shape = __pyx_pybuffernd_gwb.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_8 = 0;
  __pyx_v_gwb = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;
+0881:     for ii in range(nm):
  __pyx_t_9 = __pyx_v_nm;
  __pyx_t_10 = __pyx_t_9;
  for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) {
    __pyx_v_ii = __pyx_t_11;
+0882:         for jj in range(nq):
    __pyx_t_12 = __pyx_v_nq;
    __pyx_t_13 = __pyx_t_12;
    for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
      __pyx_v_jj = __pyx_t_14;
+0883:             for kk in range(nz):
      __pyx_t_15 = __pyx_v_nz;
      __pyx_t_16 = __pyx_t_15;
      for (__pyx_t_17 = 0; __pyx_t_17 < __pyx_t_16; __pyx_t_17+=1) {
        __pyx_v_kk = __pyx_t_17;
+0884:                 for ff in range(nf):
        __pyx_t_18 = __pyx_v_nf;
        __pyx_t_19 = __pyx_t_18;
        for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_19; __pyx_t_20+=1) {
          __pyx_v_ff = __pyx_t_20;
+0885:                     bin_num = dist[ii, jj, kk, ff]
          __pyx_t_1 = __pyx_v_ii;
          __pyx_t_21 = __pyx_v_jj;
          __pyx_t_22 = __pyx_v_kk;
          __pyx_t_23 = __pyx_v_ff;
          __pyx_v_bin_num = (*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_dist.data + __pyx_t_1 * __pyx_v_dist.strides[0]) ) + __pyx_t_21 * __pyx_v_dist.strides[1]) ) + __pyx_t_22 * __pyx_v_dist.strides[2]) ) + __pyx_t_23 * __pyx_v_dist.strides[3]) )));
+0886:                     bin_hc2 = hc2[ii, jj, kk, ff]
          __pyx_t_23 = __pyx_v_ii;
          __pyx_t_22 = __pyx_v_jj;
          __pyx_t_21 = __pyx_v_kk;
          __pyx_t_1 = __pyx_v_ff;
          __pyx_v_bin_hc2 = (*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_hc2.data + __pyx_t_23 * __pyx_v_hc2.strides[0]) ) + __pyx_t_22 * __pyx_v_hc2.strides[1]) ) + __pyx_t_21 * __pyx_v_hc2.strides[2]) ) + __pyx_t_1 * __pyx_v_hc2.strides[3]) )));
+0887:                     if bin_num > thresh:
          __pyx_t_24 = ((__pyx_v_bin_num > __pyx_v_thresh) != 0);
          if (__pyx_t_24) {
/* … */
            goto __pyx_L11;
          }
+0888:                         bin_std = sqrt(bin_num)
            __pyx_v_bin_std = sqrt(__pyx_v_bin_num);
+0889:                         for rr in range(nreals):
            __pyx_t_25 = __pyx_v_nreals;
            __pyx_t_26 = __pyx_t_25;
            for (__pyx_t_27 = 0; __pyx_t_27 < __pyx_t_26; __pyx_t_27+=1) {
              __pyx_v_rr = __pyx_t_27;
+0890:                             num = <double>random_normal(rng, bin_num, bin_std)
              __pyx_v_num = ((double)random_normal(__pyx_v_rng, __pyx_v_bin_num, __pyx_v_bin_std));
+0891:                             gwb[ff, rr] += num * bin_hc2
              __pyx_t_1 = __pyx_v_ff;
              __pyx_t_21 = __pyx_v_rr;
              *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_gwb.rcbuffer->pybuffer.buf, __pyx_t_1, __pyx_pybuffernd_gwb.diminfo[0].strides, __pyx_t_21, __pyx_pybuffernd_gwb.diminfo[1].strides) += (__pyx_v_num * __pyx_v_bin_hc2);
            }
 0892:                     else:
+0893:                         for rr in range(nreals):
          /*else*/ {
            __pyx_t_25 = __pyx_v_nreals;
            __pyx_t_26 = __pyx_t_25;
            for (__pyx_t_27 = 0; __pyx_t_27 < __pyx_t_26; __pyx_t_27+=1) {
              __pyx_v_rr = __pyx_t_27;
+0894:                             num = <double>random_poisson(rng, bin_num)
              __pyx_v_num = ((double)random_poisson(__pyx_v_rng, __pyx_v_bin_num));
+0895:                             gwb[ff, rr] += num * bin_hc2
              __pyx_t_21 = __pyx_v_ff;
              __pyx_t_1 = __pyx_v_rr;
              *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_gwb.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_gwb.diminfo[0].strides, __pyx_t_1, __pyx_pybuffernd_gwb.diminfo[1].strides) += (__pyx_v_num * __pyx_v_bin_hc2);
            }
          }
          __pyx_L11:;
        }
      }
    }
  }
 0896: 
+0897:     return gwb
  __pyx_t_28 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(((PyObject *)__pyx_v_gwb), PyBUF_WRITABLE); if (unlikely(!__pyx_t_28.memview)) __PYX_ERR(0, 897, __pyx_L1_error)
  __pyx_r = __pyx_t_28;
  __pyx_t_28.memview = NULL;
  __pyx_t_28.data = NULL;
  goto __pyx_L0;
 0898: 
 0899: 
+0900: def ss_bg_hc(number, h2fdf, nreals, normal_threshold=1e10):
/* Python wrapper */
static PyObject *__pyx_pw_8holodeck_7cyutils_7ss_bg_hc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8holodeck_7cyutils_6ss_bg_hc[] = " Calculates the characteristic strain from loud single sources and a background of all other sources.\n\n    Parameters\n    ----------\n    number : [M, Q, Z, F] ndarray\n        number in each bin\n    h2fdf : [M, Q, Z, F] ndarray\n        strain squared x frequency / frequency bin width for each bin\n    nreals\n        number of realizations\n\n    Returns\n    -------\n    hc2ss : (F, R) Ndarray of scalars\n    hc2bg : (F, R) Ndarray of scalars\n    ssidx : (3, F, R) Ndarray of ints\n        Index of the loudest single source, -1 if there are none at the frequency/realization.\n\n    ";
static PyMethodDef __pyx_mdef_8holodeck_7cyutils_7ss_bg_hc = {"ss_bg_hc", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8holodeck_7cyutils_7ss_bg_hc, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8holodeck_7cyutils_6ss_bg_hc};
static PyObject *__pyx_pw_8holodeck_7cyutils_7ss_bg_hc(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_number = 0;
  PyObject *__pyx_v_h2fdf = 0;
  PyObject *__pyx_v_nreals = 0;
  PyObject *__pyx_v_normal_threshold = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("ss_bg_hc (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_number,&__pyx_n_s_h2fdf,&__pyx_n_s_nreals,&__pyx_n_s_normal_threshold,0};
    PyObject* values[4] = {0,0,0,0};
    values[3] = ((PyObject *)__pyx_float_1e10);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_number)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_h2fdf)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ss_bg_hc", 0, 3, 4, 1); __PYX_ERR(0, 900, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_nreals)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ss_bg_hc", 0, 3, 4, 2); __PYX_ERR(0, 900, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_normal_threshold);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "ss_bg_hc") < 0)) __PYX_ERR(0, 900, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_number = values[0];
    __pyx_v_h2fdf = values[1];
    __pyx_v_nreals = values[2];
    __pyx_v_normal_threshold = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("ss_bg_hc", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 900, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("holodeck.cyutils.ss_bg_hc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_8holodeck_7cyutils_6ss_bg_hc(__pyx_self, __pyx_v_number, __pyx_v_h2fdf, __pyx_v_nreals, __pyx_v_normal_threshold);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8holodeck_7cyutils_6ss_bg_hc(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_number, PyObject *__pyx_v_h2fdf, PyObject *__pyx_v_nreals, PyObject *__pyx_v_normal_threshold) {
  __Pyx_memviewslice __pyx_v_shape = { 0, 0, { 0 }, { 0 }, { 0 } };
  PyObject *__pyx_v_F = NULL;
  PyObject *__pyx_v_R = NULL;
  PyArrayObject *__pyx_v_hc2ss = 0;
  PyArrayObject *__pyx_v_hc2bg = 0;
  PyArrayObject *__pyx_v_ssidx = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_hc2bg;
  __Pyx_Buffer __pyx_pybuffer_hc2bg;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_hc2ss;
  __Pyx_Buffer __pyx_pybuffer_hc2ss;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ssidx;
  __Pyx_Buffer __pyx_pybuffer_ssidx;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("ss_bg_hc", 0);
  __pyx_pybuffer_hc2ss.pybuffer.buf = NULL;
  __pyx_pybuffer_hc2ss.refcount = 0;
  __pyx_pybuffernd_hc2ss.data = NULL;
  __pyx_pybuffernd_hc2ss.rcbuffer = &__pyx_pybuffer_hc2ss;
  __pyx_pybuffer_hc2bg.pybuffer.buf = NULL;
  __pyx_pybuffer_hc2bg.refcount = 0;
  __pyx_pybuffernd_hc2bg.data = NULL;
  __pyx_pybuffernd_hc2bg.rcbuffer = &__pyx_pybuffer_hc2bg;
  __pyx_pybuffer_ssidx.pybuffer.buf = NULL;
  __pyx_pybuffer_ssidx.refcount = 0;
  __pyx_pybuffernd_ssidx.data = NULL;
  __pyx_pybuffernd_ssidx.rcbuffer = &__pyx_pybuffer_ssidx;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_11, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_12, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_15, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_16, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_17, 1);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2bg.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2ss.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ssidx.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("holodeck.cyutils.ss_bg_hc", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2bg.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2ss.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ssidx.rcbuffer->pybuffer);
  __pyx_L2:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_shape, 1);
  __Pyx_XDECREF(__pyx_v_F);
  __Pyx_XDECREF(__pyx_v_R);
  __Pyx_XDECREF((PyObject *)__pyx_v_hc2ss);
  __Pyx_XDECREF((PyObject *)__pyx_v_hc2bg);
  __Pyx_XDECREF((PyObject *)__pyx_v_ssidx);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__30 = PyTuple_Pack(10, __pyx_n_s_number, __pyx_n_s_h2fdf, __pyx_n_s_nreals, __pyx_n_s_normal_threshold, __pyx_n_s_shape, __pyx_n_s_F, __pyx_n_s_R, __pyx_n_s_hc2ss, __pyx_n_s_hc2bg, __pyx_n_s_ssidx); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 900, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__30);
  __Pyx_GIVEREF(__pyx_tuple__30);
/* … */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_8holodeck_7cyutils_7ss_bg_hc, NULL, __pyx_n_s_holodeck_cyutils); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 900, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ss_bg_hc, __pyx_t_3) < 0) __PYX_ERR(0, 900, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_codeobj__31 = (PyObject*)__Pyx_PyCode_New(4, 0, 10, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__30, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_holodeck_cyutils_pyx, __pyx_n_s_ss_bg_hc, 900, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__31)) __PYX_ERR(0, 900, __pyx_L1_error)
 0901:     """ Calculates the characteristic strain from loud single sources and a background of all other sources.
 0902: 
 0903:     Parameters
 0904:     ----------
 0905:     number : [M, Q, Z, F] ndarray
 0906:         number in each bin
 0907:     h2fdf : [M, Q, Z, F] ndarray
 0908:         strain squared x frequency / frequency bin width for each bin
 0909:     nreals
 0910:         number of realizations
 0911: 
 0912:     Returns
 0913:     -------
 0914:     hc2ss : (F, R) Ndarray of scalars
 0915:     hc2bg : (F, R) Ndarray of scalars
 0916:     ssidx : (3, F, R) Ndarray of ints
 0917:         Index of the loudest single source, -1 if there are none at the frequency/realization.
 0918: 
 0919:     """
 0920: 
+0921:     cdef long[:] shape = np.array(number.shape)
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 921, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 921, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_number, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 921, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 921, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 921, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_shape = __pyx_t_5;
  __pyx_t_5.memview = NULL;
  __pyx_t_5.data = NULL;
+0922:     F = shape[3]
  __pyx_t_6 = 3;
  __pyx_t_7 = -1;
  if (__pyx_t_6 < 0) {
    __pyx_t_6 += __pyx_v_shape.shape[0];
    if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
  } else if (unlikely(__pyx_t_6 >= __pyx_v_shape.shape[0])) __pyx_t_7 = 0;
  if (unlikely(__pyx_t_7 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_7);
    __PYX_ERR(0, 922, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyInt_From_long((*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_6 * __pyx_v_shape.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 922, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_F = __pyx_t_1;
  __pyx_t_1 = 0;
+0923:     R = nreals
  __Pyx_INCREF(__pyx_v_nreals);
  __pyx_v_R = __pyx_v_nreals;
+0924:     cdef np.ndarray[np.double_t, ndim=2] hc2ss = np.zeros((F,R))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 924, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 924, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 924, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_R);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 924, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 924, __pyx_L1_error)
  __pyx_t_8 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_hc2ss.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_hc2ss = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 924, __pyx_L1_error)
    } else {__pyx_pybuffernd_hc2ss.diminfo[0].strides = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_hc2ss.diminfo[0].shape = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_hc2ss.diminfo[1].strides = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_hc2ss.diminfo[1].shape = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_8 = 0;
  __pyx_v_hc2ss = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
+0925:     cdef np.ndarray[np.double_t, ndim=2] hc2bg = np.zeros((F,R))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 925, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 925, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 925, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_R);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 925, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 925, __pyx_L1_error)
  __pyx_t_9 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_hc2bg.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_hc2bg = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 925, __pyx_L1_error)
    } else {__pyx_pybuffernd_hc2bg.diminfo[0].strides = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_hc2bg.diminfo[0].shape = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_hc2bg.diminfo[1].strides = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_hc2bg.diminfo[1].shape = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_9 = 0;
  __pyx_v_hc2bg = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
+0926:     cdef np.ndarray[np.longlong_t, ndim=3] ssidx = np.zeros((3,F,R), dtype=int)
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 926, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 926, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 926, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_int_3);
  __Pyx_GIVEREF(__pyx_int_3);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_3);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_R);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 926, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 926, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, ((PyObject *)(&PyInt_Type))) < 0) __PYX_ERR(0, 926, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 926, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 926, __pyx_L1_error)
  __pyx_t_10 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ssidx.rcbuffer->pybuffer, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_5numpy_longlong_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_ssidx = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 926, __pyx_L1_error)
    } else {__pyx_pybuffernd_ssidx.diminfo[0].strides = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ssidx.diminfo[0].shape = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_ssidx.diminfo[1].strides = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_ssidx.diminfo[1].shape = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_ssidx.diminfo[2].strides = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_ssidx.diminfo[2].shape = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_10 = 0;
  __pyx_v_ssidx = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;
+0927:     _ss_bg_hc(shape, h2fdf, number, nreals, normal_threshold,
  __pyx_t_11 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_double(__pyx_v_h2fdf, PyBUF_WRITABLE); if (unlikely(!__pyx_t_11.memview)) __PYX_ERR(0, 927, __pyx_L1_error)
  __pyx_t_12 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_double(__pyx_v_number, PyBUF_WRITABLE); if (unlikely(!__pyx_t_12.memview)) __PYX_ERR(0, 927, __pyx_L1_error)
  __pyx_t_13 = __Pyx_PyInt_As_long(__pyx_v_nreals); if (unlikely((__pyx_t_13 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 927, __pyx_L1_error)
  __pyx_t_14 = __Pyx_PyInt_As_long(__pyx_v_normal_threshold); if (unlikely((__pyx_t_14 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 927, __pyx_L1_error)
/* … */
  __pyx_f_8holodeck_7cyutils__ss_bg_hc(__pyx_v_shape, __pyx_t_11, __pyx_t_12, __pyx_t_13, __pyx_t_14, __pyx_t_15, __pyx_t_16, __pyx_t_17);
  __PYX_XDEC_MEMVIEW(&__pyx_t_11, 1);
  __pyx_t_11.memview = NULL;
  __pyx_t_11.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_12, 1);
  __pyx_t_12.memview = NULL;
  __pyx_t_12.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_15, 1);
  __pyx_t_15.memview = NULL;
  __pyx_t_15.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_16, 1);
  __pyx_t_16.memview = NULL;
  __pyx_t_16.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_17, 1);
  __pyx_t_17.memview = NULL;
  __pyx_t_17.data = NULL;
+0928:                 hc2ss, hc2bg, ssidx)
  __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(((PyObject *)__pyx_v_hc2ss), PyBUF_WRITABLE); if (unlikely(!__pyx_t_15.memview)) __PYX_ERR(0, 928, __pyx_L1_error)
  __pyx_t_16 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(((PyObject *)__pyx_v_hc2bg), PyBUF_WRITABLE); if (unlikely(!__pyx_t_16.memview)) __PYX_ERR(0, 928, __pyx_L1_error)
  __pyx_t_17 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_long(((PyObject *)__pyx_v_ssidx), PyBUF_WRITABLE); if (unlikely(!__pyx_t_17.memview)) __PYX_ERR(0, 928, __pyx_L1_error)
 0929:     # print(hc2ss, hc2bg, ssidx)
+0930:     return hc2ss, hc2bg, ssidx
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 930, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(((PyObject *)__pyx_v_hc2ss));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_hc2ss));
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_hc2ss));
  __Pyx_INCREF(((PyObject *)__pyx_v_hc2bg));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_hc2bg));
  PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_hc2bg));
  __Pyx_INCREF(((PyObject *)__pyx_v_ssidx));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_ssidx));
  PyTuple_SET_ITEM(__pyx_t_4, 2, ((PyObject *)__pyx_v_ssidx));
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;
 0931: 
 0932: @cython.boundscheck(False)
 0933: @cython.wraparound(False)
 0934: @cython.nonecheck(False)
 0935: @cython.cdivision(True)
+0936: cdef void _ss_bg_hc(long[:] shape, double[:,:,:,:] h2fdf, double[:,:,:,:] number,
static void __pyx_f_8holodeck_7cyutils__ss_bg_hc(__Pyx_memviewslice __pyx_v_shape, __Pyx_memviewslice __pyx_v_h2fdf, __Pyx_memviewslice __pyx_v_number, long __pyx_v_nreals, long __pyx_v_thresh, __Pyx_memviewslice __pyx_v_hc2ss, __Pyx_memviewslice __pyx_v_hc2bg, __Pyx_memviewslice __pyx_v_ssidx) {
  int __pyx_v_M;
  int __pyx_v_Q;
  int __pyx_v_Z;
  int __pyx_v_F;
  int __pyx_v_R;
  int __pyx_v_mm;
  int __pyx_v_qq;
  int __pyx_v_zz;
  int __pyx_v_ff;
  int __pyx_v_rr;
  int __pyx_v_m_max;
  int __pyx_v_q_max;
  int __pyx_v_z_max;
  double __pyx_v_max;
  double __pyx_v_num;
  double __pyx_v_sum;
  bitgen_t *__pyx_v_rng;
  char const *__pyx_v_capsule_name;
  PyObject *__pyx_v_capsule = NULL;
  PyObject *__pyx_v_cur = NULL;
  double __pyx_v_std;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_ss_bg_hc", 0);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_WriteUnraisable("holodeck.cyutils._ss_bg_hc", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_capsule);
  __Pyx_XDECREF(__pyx_v_cur);
  __Pyx_RefNannyFinishContext();
}
 0937:             long nreals, long thresh,
 0938:             double[:,:] hc2ss, double[:,:] hc2bg, long[:,:,:] ssidx):
 0939:     """
 0940:     Calculates the characteristic strain from loud single sources and a background of all other sources.
 0941: 
 0942:     Parameters
 0943:     ----------
 0944:     shape : long[:] array
 0945:         shape of number, [M, Q, Z, F]
 0946:     number : double[:,:,:,:] array
 0947:         number per bin
 0948:     h2fdf : double[:,:,:,:] array
 0949:         strain amplitude squared * f/Delta f for a single source in each bin.
 0950:     nreals : int
 0951:         number of realizations.
 0952:     hc2ss : double[:,:] array
 0953:         (memory address of) single source characteristic strain squared array.
 0954:     hc2bg : double[:,:] array
 0955:         (memory address of) background characteristic strain squared array.
 0956:     ssidx : [:,:,:] long array
 0957:         (memory address of) array for indices of max strain bins.
 0958:     bgpar :
 0959:         (memory address of) array of effective average parameters
 0960: 
 0961:     Returns
 0962:     -------
 0963:     void
 0964:     updated via memory address: hc2ss, hc2bg, ssidx
 0965:     """
 0966: 
+0967:     cdef int M = shape[0]
  __pyx_t_1 = 0;
  __pyx_v_M = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+0968:     cdef int Q = shape[1]
  __pyx_t_1 = 1;
  __pyx_v_Q = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+0969:     cdef int Z = shape[2]
  __pyx_t_1 = 2;
  __pyx_v_Z = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+0970:     cdef int F = shape[3]
  __pyx_t_1 = 3;
  __pyx_v_F = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+0971:     cdef int R = nreals
  __pyx_v_R = __pyx_v_nreals;
 0972: 
 0973:     cdef int mm, qq, zz, ff, rr, m_max, q_max, z_max
 0974:     cdef double max, num, sum
 0975: 
 0976: 
 0977:     # Setup random number generator from numpy library
 0978:     cdef bitgen_t *rng
+0979:     cdef const char *capsule_name = "BitGenerator"
  __pyx_v_capsule_name = ((char const *)"BitGenerator");
+0980:     capsule = PCG64().capsule
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_PCG64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 980, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 980, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_capsule); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 980, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_capsule = __pyx_t_3;
  __pyx_t_3 = 0;
 0981:     # Cast the pointer
+0982:     rng = <bitgen_t *> PyCapsule_GetPointer(capsule, capsule_name)
  __pyx_t_5 = PyCapsule_GetPointer(__pyx_v_capsule, __pyx_v_capsule_name); if (unlikely(__pyx_t_5 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 982, __pyx_L1_error)
  __pyx_v_rng = ((bitgen_t *)__pyx_t_5);
 0983: 
+0984:     for rr in range(R):
  __pyx_t_6 = __pyx_v_R;
  __pyx_t_7 = __pyx_t_6;
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_rr = __pyx_t_8;
+0985:         for ff in range(F):
    __pyx_t_9 = __pyx_v_F;
    __pyx_t_10 = __pyx_t_9;
    for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) {
      __pyx_v_ff = __pyx_t_11;
+0986:             max=0
      __pyx_v_max = 0.0;
+0987:             sum=0
      __pyx_v_sum = 0.0;
+0988:             m_max=-1
      __pyx_v_m_max = -1;
+0989:             q_max=-1
      __pyx_v_q_max = -1;
+0990:             z_max=-1
      __pyx_v_z_max = -1;
+0991:             for mm in range(M):
      __pyx_t_12 = __pyx_v_M;
      __pyx_t_13 = __pyx_t_12;
      for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
        __pyx_v_mm = __pyx_t_14;
+0992:                 for qq in range(Q):
        __pyx_t_15 = __pyx_v_Q;
        __pyx_t_16 = __pyx_t_15;
        for (__pyx_t_17 = 0; __pyx_t_17 < __pyx_t_16; __pyx_t_17+=1) {
          __pyx_v_qq = __pyx_t_17;
+0993:                     for zz in range(Z):
          __pyx_t_18 = __pyx_v_Z;
          __pyx_t_19 = __pyx_t_18;
          for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_19; __pyx_t_20+=1) {
            __pyx_v_zz = __pyx_t_20;
+0994:                         num = number[mm,qq,zz,ff]
            __pyx_t_1 = __pyx_v_mm;
            __pyx_t_21 = __pyx_v_qq;
            __pyx_t_22 = __pyx_v_zz;
            __pyx_t_23 = __pyx_v_ff;
            __pyx_v_num = (*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_number.data + __pyx_t_1 * __pyx_v_number.strides[0]) ) + __pyx_t_21 * __pyx_v_number.strides[1]) ) + __pyx_t_22 * __pyx_v_number.strides[2]) ) + __pyx_t_23 * __pyx_v_number.strides[3]) )));
+0995:                         cur = h2fdf[mm,qq,zz,ff]
            __pyx_t_23 = __pyx_v_mm;
            __pyx_t_22 = __pyx_v_qq;
            __pyx_t_21 = __pyx_v_zz;
            __pyx_t_1 = __pyx_v_ff;
            __pyx_t_3 = PyFloat_FromDouble((*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_h2fdf.data + __pyx_t_23 * __pyx_v_h2fdf.strides[0]) ) + __pyx_t_22 * __pyx_v_h2fdf.strides[1]) ) + __pyx_t_21 * __pyx_v_h2fdf.strides[2]) ) + __pyx_t_1 * __pyx_v_h2fdf.strides[3]) )))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 995, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_XDECREF_SET(__pyx_v_cur, __pyx_t_3);
            __pyx_t_3 = 0;
+0996:                         if (num>thresh):
            __pyx_t_24 = ((__pyx_v_num > __pyx_v_thresh) != 0);
            if (__pyx_t_24) {
/* … */
              goto __pyx_L13;
            }
+0997:                             std = sqrt(num)
              __pyx_v_std = sqrt(__pyx_v_num);
+0998:                             num = <double>random_normal(rng, num, std)
              __pyx_v_num = ((double)random_normal(__pyx_v_rng, __pyx_v_num, __pyx_v_std));
 0999:                         else:
+1000:                             num = <double>random_poisson(rng, num)
            /*else*/ {
              __pyx_v_num = ((double)random_poisson(__pyx_v_rng, __pyx_v_num));
            }
            __pyx_L13:;
+1001:                         if(cur > max and num > 0):
            __pyx_t_3 = PyFloat_FromDouble(__pyx_v_max); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1001, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_2 = PyObject_RichCompare(__pyx_v_cur, __pyx_t_3, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1001, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __pyx_t_25 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_25 < 0)) __PYX_ERR(0, 1001, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            if (__pyx_t_25) {
            } else {
              __pyx_t_24 = __pyx_t_25;
              goto __pyx_L15_bool_binop_done;
            }
            __pyx_t_25 = ((__pyx_v_num > 0.0) != 0);
            __pyx_t_24 = __pyx_t_25;
            __pyx_L15_bool_binop_done:;
            if (__pyx_t_24) {
/* … */
            }
+1002:                             max = h2fdf[mm,qq,zz,ff]
              __pyx_t_1 = __pyx_v_mm;
              __pyx_t_21 = __pyx_v_qq;
              __pyx_t_22 = __pyx_v_zz;
              __pyx_t_23 = __pyx_v_ff;
              __pyx_v_max = (*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_h2fdf.data + __pyx_t_1 * __pyx_v_h2fdf.strides[0]) ) + __pyx_t_21 * __pyx_v_h2fdf.strides[1]) ) + __pyx_t_22 * __pyx_v_h2fdf.strides[2]) ) + __pyx_t_23 * __pyx_v_h2fdf.strides[3]) )));
+1003:                             m_max = mm # -1 if no single sources
              __pyx_v_m_max = __pyx_v_mm;
+1004:                             q_max = qq # -1 if no single sources
              __pyx_v_q_max = __pyx_v_qq;
+1005:                             z_max = zz # -1 if no single sources
              __pyx_v_z_max = __pyx_v_zz;
+1006:                         sum += num * cur
            __pyx_t_2 = PyFloat_FromDouble(__pyx_v_sum); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1006, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_3 = PyFloat_FromDouble(__pyx_v_num); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1006, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_4 = PyNumber_Multiply(__pyx_t_3, __pyx_v_cur); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1006, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1006, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __pyx_t_26 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_26 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 1006, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __pyx_v_sum = __pyx_t_26;
          }
        }
      }
+1007:             hc2ss[ff,rr] = max
      __pyx_t_23 = __pyx_v_ff;
      __pyx_t_22 = __pyx_v_rr;
      *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_hc2ss.data + __pyx_t_23 * __pyx_v_hc2ss.strides[0]) ) + __pyx_t_22 * __pyx_v_hc2ss.strides[1]) )) = __pyx_v_max;
+1008:             hc2bg[ff,rr] = sum - max
      __pyx_t_22 = __pyx_v_ff;
      __pyx_t_23 = __pyx_v_rr;
      *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_hc2bg.data + __pyx_t_22 * __pyx_v_hc2bg.strides[0]) ) + __pyx_t_23 * __pyx_v_hc2bg.strides[1]) )) = (__pyx_v_sum - __pyx_v_max);
 1009:             # ssidx[:,ff,rr] = m_max, q_max, z_max
+1010:             ssidx[0,ff,rr] = m_max
      __pyx_t_23 = 0;
      __pyx_t_22 = __pyx_v_ff;
      __pyx_t_21 = __pyx_v_rr;
      *((long *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_ssidx.data + __pyx_t_23 * __pyx_v_ssidx.strides[0]) ) + __pyx_t_22 * __pyx_v_ssidx.strides[1]) ) + __pyx_t_21 * __pyx_v_ssidx.strides[2]) )) = __pyx_v_m_max;
+1011:             ssidx[1,ff,rr] = q_max
      __pyx_t_21 = 1;
      __pyx_t_22 = __pyx_v_ff;
      __pyx_t_23 = __pyx_v_rr;
      *((long *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_ssidx.data + __pyx_t_21 * __pyx_v_ssidx.strides[0]) ) + __pyx_t_22 * __pyx_v_ssidx.strides[1]) ) + __pyx_t_23 * __pyx_v_ssidx.strides[2]) )) = __pyx_v_q_max;
+1012:             ssidx[2,ff,rr] = z_max
      __pyx_t_23 = 2;
      __pyx_t_22 = __pyx_v_ff;
      __pyx_t_21 = __pyx_v_rr;
      *((long *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_ssidx.data + __pyx_t_23 * __pyx_v_ssidx.strides[0]) ) + __pyx_t_22 * __pyx_v_ssidx.strides[1]) ) + __pyx_t_21 * __pyx_v_ssidx.strides[2]) )) = __pyx_v_z_max;
+1013:             if (max==0):
      __pyx_t_24 = ((__pyx_v_max == 0.0) != 0);
      if (__pyx_t_24) {
/* … */
      }
    }
  }
+1014:                 print('No sources found at %dth frequency' % ff) # could warn
        __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_ff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1014, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = PyUnicode_Format(__pyx_kp_u_No_sources_found_at_dth_frequenc, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1014, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_print, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1014, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 1015:     # still need to sqrt and sum! (or do this back in python)
 1016: 
+1017:     return
  goto __pyx_L0;
 1018: 
 1019: # I also need to pass the edges to calculate the avged ones
+1020: def ss_bg_hc_and_par(number, h2fdf, nreals, mt, mr, rz, normal_threshold=1e10):
/* Python wrapper */
static PyObject *__pyx_pw_8holodeck_7cyutils_9ss_bg_hc_and_par(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8holodeck_7cyutils_8ss_bg_hc_and_par[] = "\n    Calculates the characteristic strain from loud single sources and a background of all other sources.\n\n    Parameters\n    ------------------------\n    number : [M, Q, Z, F] NDarray\n        number in each bin\n    h2fdf : [M, Q, Z, F] NDarray\n        Strain amplitude squared x frequency / frequency bin width for each bin.\n    nreals\n        Number of realizations.\n    mt : (M,) 1Darray of scalars\n        Total masses, M, of each bin center.\n    mr : (Q,) 1Darray of scalars\n        Mass ratios, q, of each bin center.\n    rz : (Z,) 1Darray of scalars\n        Redshifts, z, of each bin center.\n\n    Returns\n    --------------------------\n    hc2ss : (F, R) Ndarray of scalars\n        Char strain squared of the loudest single sources.\n    hc2bg : (F, R) Ndarray of scalars\n        Char strain squared of the background.\n    ssidx : (3, F, R) NDarray of ints\n        Indices of the loudest single sources. -1 if there are\n        no single sources at that frequency/realization.\n    bgpar : (3, F, R) NDarray of scalars\n        Average effective M, q, z parameters of the background.\n    sspar : (3, F, R) NDarray of scalars\n        M, q, z parameters of the loudest single sources.\n    ";
static PyMethodDef __pyx_mdef_8holodeck_7cyutils_9ss_bg_hc_and_par = {"ss_bg_hc_and_par", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8holodeck_7cyutils_9ss_bg_hc_and_par, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8holodeck_7cyutils_8ss_bg_hc_and_par};
static PyObject *__pyx_pw_8holodeck_7cyutils_9ss_bg_hc_and_par(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_number = 0;
  PyObject *__pyx_v_h2fdf = 0;
  PyObject *__pyx_v_nreals = 0;
  PyObject *__pyx_v_mt = 0;
  PyObject *__pyx_v_mr = 0;
  PyObject *__pyx_v_rz = 0;
  PyObject *__pyx_v_normal_threshold = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("ss_bg_hc_and_par (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_number,&__pyx_n_s_h2fdf,&__pyx_n_s_nreals,&__pyx_n_s_mt,&__pyx_n_s_mr,&__pyx_n_s_rz,&__pyx_n_s_normal_threshold,0};
    PyObject* values[7] = {0,0,0,0,0,0,0};
    values[6] = ((PyObject *)__pyx_float_1e10);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_number)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_h2fdf)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ss_bg_hc_and_par", 0, 6, 7, 1); __PYX_ERR(0, 1020, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_nreals)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ss_bg_hc_and_par", 0, 6, 7, 2); __PYX_ERR(0, 1020, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mt)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ss_bg_hc_and_par", 0, 6, 7, 3); __PYX_ERR(0, 1020, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mr)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ss_bg_hc_and_par", 0, 6, 7, 4); __PYX_ERR(0, 1020, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_rz)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("ss_bg_hc_and_par", 0, 6, 7, 5); __PYX_ERR(0, 1020, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_normal_threshold);
          if (value) { values[6] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "ss_bg_hc_and_par") < 0)) __PYX_ERR(0, 1020, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_number = values[0];
    __pyx_v_h2fdf = values[1];
    __pyx_v_nreals = values[2];
    __pyx_v_mt = values[3];
    __pyx_v_mr = values[4];
    __pyx_v_rz = values[5];
    __pyx_v_normal_threshold = values[6];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("ss_bg_hc_and_par", 0, 6, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1020, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("holodeck.cyutils.ss_bg_hc_and_par", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_8holodeck_7cyutils_8ss_bg_hc_and_par(__pyx_self, __pyx_v_number, __pyx_v_h2fdf, __pyx_v_nreals, __pyx_v_mt, __pyx_v_mr, __pyx_v_rz, __pyx_v_normal_threshold);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8holodeck_7cyutils_8ss_bg_hc_and_par(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_number, PyObject *__pyx_v_h2fdf, PyObject *__pyx_v_nreals, PyObject *__pyx_v_mt, PyObject *__pyx_v_mr, PyObject *__pyx_v_rz, PyObject *__pyx_v_normal_threshold) {
  __Pyx_memviewslice __pyx_v_shape = { 0, 0, { 0 }, { 0 }, { 0 } };
  PyObject *__pyx_v_F = NULL;
  PyObject *__pyx_v_R = NULL;
  PyArrayObject *__pyx_v_hc2ss = 0;
  PyArrayObject *__pyx_v_hc2bg = 0;
  PyArrayObject *__pyx_v_ssidx = 0;
  PyArrayObject *__pyx_v_bgpar = 0;
  PyArrayObject *__pyx_v_sspar = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_bgpar;
  __Pyx_Buffer __pyx_pybuffer_bgpar;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_hc2bg;
  __Pyx_Buffer __pyx_pybuffer_hc2bg;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_hc2ss;
  __Pyx_Buffer __pyx_pybuffer_hc2ss;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ssidx;
  __Pyx_Buffer __pyx_pybuffer_ssidx;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_sspar;
  __Pyx_Buffer __pyx_pybuffer_sspar;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("ss_bg_hc_and_par", 0);
  __pyx_pybuffer_hc2ss.pybuffer.buf = NULL;
  __pyx_pybuffer_hc2ss.refcount = 0;
  __pyx_pybuffernd_hc2ss.data = NULL;
  __pyx_pybuffernd_hc2ss.rcbuffer = &__pyx_pybuffer_hc2ss;
  __pyx_pybuffer_hc2bg.pybuffer.buf = NULL;
  __pyx_pybuffer_hc2bg.refcount = 0;
  __pyx_pybuffernd_hc2bg.data = NULL;
  __pyx_pybuffernd_hc2bg.rcbuffer = &__pyx_pybuffer_hc2bg;
  __pyx_pybuffer_ssidx.pybuffer.buf = NULL;
  __pyx_pybuffer_ssidx.refcount = 0;
  __pyx_pybuffernd_ssidx.data = NULL;
  __pyx_pybuffernd_ssidx.rcbuffer = &__pyx_pybuffer_ssidx;
  __pyx_pybuffer_bgpar.pybuffer.buf = NULL;
  __pyx_pybuffer_bgpar.refcount = 0;
  __pyx_pybuffernd_bgpar.data = NULL;
  __pyx_pybuffernd_bgpar.rcbuffer = &__pyx_pybuffer_bgpar;
  __pyx_pybuffer_sspar.pybuffer.buf = NULL;
  __pyx_pybuffer_sspar.refcount = 0;
  __pyx_pybuffernd_sspar.data = NULL;
  __pyx_pybuffernd_sspar.rcbuffer = &__pyx_pybuffer_sspar;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_13, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_14, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_17, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_18, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_19, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_20, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_21, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_22, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_23, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_24, 1);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bgpar.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2bg.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2ss.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ssidx.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_sspar.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("holodeck.cyutils.ss_bg_hc_and_par", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bgpar.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2bg.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2ss.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ssidx.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_sspar.rcbuffer->pybuffer);
  __pyx_L2:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_shape, 1);
  __Pyx_XDECREF(__pyx_v_F);
  __Pyx_XDECREF(__pyx_v_R);
  __Pyx_XDECREF((PyObject *)__pyx_v_hc2ss);
  __Pyx_XDECREF((PyObject *)__pyx_v_hc2bg);
  __Pyx_XDECREF((PyObject *)__pyx_v_ssidx);
  __Pyx_XDECREF((PyObject *)__pyx_v_bgpar);
  __Pyx_XDECREF((PyObject *)__pyx_v_sspar);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__32 = PyTuple_Pack(15, __pyx_n_s_number, __pyx_n_s_h2fdf, __pyx_n_s_nreals, __pyx_n_s_mt, __pyx_n_s_mr, __pyx_n_s_rz, __pyx_n_s_normal_threshold, __pyx_n_s_shape, __pyx_n_s_F, __pyx_n_s_R, __pyx_n_s_hc2ss, __pyx_n_s_hc2bg, __pyx_n_s_ssidx, __pyx_n_s_bgpar, __pyx_n_s_sspar); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 1020, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__32);
  __Pyx_GIVEREF(__pyx_tuple__32);
/* … */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_8holodeck_7cyutils_9ss_bg_hc_and_par, NULL, __pyx_n_s_holodeck_cyutils); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1020, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ss_bg_hc_and_par, __pyx_t_3) < 0) __PYX_ERR(0, 1020, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_codeobj__33 = (PyObject*)__Pyx_PyCode_New(7, 0, 15, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__32, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_holodeck_cyutils_pyx, __pyx_n_s_ss_bg_hc_and_par, 1020, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__33)) __PYX_ERR(0, 1020, __pyx_L1_error)
 1021:     """
 1022:     Calculates the characteristic strain from loud single sources and a background of all other sources.
 1023: 
 1024:     Parameters
 1025:     ------------------------
 1026:     number : [M, Q, Z, F] NDarray
 1027:         number in each bin
 1028:     h2fdf : [M, Q, Z, F] NDarray
 1029:         Strain amplitude squared x frequency / frequency bin width for each bin.
 1030:     nreals
 1031:         Number of realizations.
 1032:     mt : (M,) 1Darray of scalars
 1033:         Total masses, M, of each bin center.
 1034:     mr : (Q,) 1Darray of scalars
 1035:         Mass ratios, q, of each bin center.
 1036:     rz : (Z,) 1Darray of scalars
 1037:         Redshifts, z, of each bin center.
 1038: 
 1039:     Returns
 1040:     --------------------------
 1041:     hc2ss : (F, R) Ndarray of scalars
 1042:         Char strain squared of the loudest single sources.
 1043:     hc2bg : (F, R) Ndarray of scalars
 1044:         Char strain squared of the background.
 1045:     ssidx : (3, F, R) NDarray of ints
 1046:         Indices of the loudest single sources. -1 if there are
 1047:         no single sources at that frequency/realization.
 1048:     bgpar : (3, F, R) NDarray of scalars
 1049:         Average effective M, q, z parameters of the background.
 1050:     sspar : (3, F, R) NDarray of scalars
 1051:         M, q, z parameters of the loudest single sources.
 1052:     """
 1053: 
+1054:     cdef long[:] shape = np.array(number.shape)
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1054, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1054, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_number, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1054, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1054, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 1054, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_shape = __pyx_t_5;
  __pyx_t_5.memview = NULL;
  __pyx_t_5.data = NULL;
+1055:     F = shape[3]
  __pyx_t_6 = 3;
  __pyx_t_7 = -1;
  if (__pyx_t_6 < 0) {
    __pyx_t_6 += __pyx_v_shape.shape[0];
    if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
  } else if (unlikely(__pyx_t_6 >= __pyx_v_shape.shape[0])) __pyx_t_7 = 0;
  if (unlikely(__pyx_t_7 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_7);
    __PYX_ERR(0, 1055, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyInt_From_long((*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_6 * __pyx_v_shape.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1055, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_F = __pyx_t_1;
  __pyx_t_1 = 0;
+1056:     R = nreals
  __Pyx_INCREF(__pyx_v_nreals);
  __pyx_v_R = __pyx_v_nreals;
+1057:     cdef np.ndarray[np.double_t, ndim=2] hc2ss = np.zeros((F,R))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_R);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1057, __pyx_L1_error)
  __pyx_t_8 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_hc2ss.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_hc2ss = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 1057, __pyx_L1_error)
    } else {__pyx_pybuffernd_hc2ss.diminfo[0].strides = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_hc2ss.diminfo[0].shape = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_hc2ss.diminfo[1].strides = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_hc2ss.diminfo[1].shape = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_8 = 0;
  __pyx_v_hc2ss = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
+1058:     cdef np.ndarray[np.double_t, ndim=2] hc2bg = np.zeros((F,R))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1058, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1058, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1058, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_R);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1058, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1058, __pyx_L1_error)
  __pyx_t_9 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_hc2bg.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_hc2bg = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 1058, __pyx_L1_error)
    } else {__pyx_pybuffernd_hc2bg.diminfo[0].strides = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_hc2bg.diminfo[0].shape = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_hc2bg.diminfo[1].strides = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_hc2bg.diminfo[1].shape = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_9 = 0;
  __pyx_v_hc2bg = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
+1059:     cdef np.ndarray[np.longlong_t, ndim=3] ssidx = np.zeros((3,F,R), dtype=int)
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1059, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1059, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1059, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_int_3);
  __Pyx_GIVEREF(__pyx_int_3);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_3);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_R);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1059, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1059, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, ((PyObject *)(&PyInt_Type))) < 0) __PYX_ERR(0, 1059, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1059, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1059, __pyx_L1_error)
  __pyx_t_10 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ssidx.rcbuffer->pybuffer, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_5numpy_longlong_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_ssidx = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 1059, __pyx_L1_error)
    } else {__pyx_pybuffernd_ssidx.diminfo[0].strides = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ssidx.diminfo[0].shape = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_ssidx.diminfo[1].strides = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_ssidx.diminfo[1].shape = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_ssidx.diminfo[2].strides = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_ssidx.diminfo[2].shape = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_10 = 0;
  __pyx_v_ssidx = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;
+1060:     cdef np.ndarray[np.double_t, ndim=3] bgpar = np.zeros((3,F,R))
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1060, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1060, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1060, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_int_3);
  __Pyx_GIVEREF(__pyx_int_3);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_3);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_R);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_3, __pyx_t_1) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1060, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1060, __pyx_L1_error)
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_bgpar.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_bgpar = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 1060, __pyx_L1_error)
    } else {__pyx_pybuffernd_bgpar.diminfo[0].strides = __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_bgpar.diminfo[0].shape = __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_bgpar.diminfo[1].strides = __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_bgpar.diminfo[1].shape = __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_bgpar.diminfo[2].strides = __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_bgpar.diminfo[2].shape = __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_11 = 0;
  __pyx_v_bgpar = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;
+1061:     cdef np.ndarray[np.double_t, ndim=3] sspar = np.zeros((3,F,R))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1061, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1061, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1061, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_int_3);
  __Pyx_GIVEREF(__pyx_int_3);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_3);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_R);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_4 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1061, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1061, __pyx_L1_error)
  __pyx_t_12 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_sspar.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_sspar = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_sspar.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 1061, __pyx_L1_error)
    } else {__pyx_pybuffernd_sspar.diminfo[0].strides = __pyx_pybuffernd_sspar.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_sspar.diminfo[0].shape = __pyx_pybuffernd_sspar.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_sspar.diminfo[1].strides = __pyx_pybuffernd_sspar.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_sspar.diminfo[1].shape = __pyx_pybuffernd_sspar.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_sspar.diminfo[2].strides = __pyx_pybuffernd_sspar.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_sspar.diminfo[2].shape = __pyx_pybuffernd_sspar.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_12 = 0;
  __pyx_v_sspar = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;
+1062:     _ss_bg_hc_and_par(shape, h2fdf, number, nreals, normal_threshold,
  __pyx_t_13 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_double(__pyx_v_h2fdf, PyBUF_WRITABLE); if (unlikely(!__pyx_t_13.memview)) __PYX_ERR(0, 1062, __pyx_L1_error)
  __pyx_t_14 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_double(__pyx_v_number, PyBUF_WRITABLE); if (unlikely(!__pyx_t_14.memview)) __PYX_ERR(0, 1062, __pyx_L1_error)
  __pyx_t_15 = __Pyx_PyInt_As_long(__pyx_v_nreals); if (unlikely((__pyx_t_15 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1062, __pyx_L1_error)
  __pyx_t_16 = __Pyx_PyInt_As_long(__pyx_v_normal_threshold); if (unlikely((__pyx_t_16 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1062, __pyx_L1_error)
/* … */
  __pyx_f_8holodeck_7cyutils__ss_bg_hc_and_par(__pyx_v_shape, __pyx_t_13, __pyx_t_14, __pyx_t_15, __pyx_t_16, __pyx_t_17, __pyx_t_18, __pyx_t_19, __pyx_t_20, __pyx_t_21, __pyx_t_22, __pyx_t_23, __pyx_t_24);
  __PYX_XDEC_MEMVIEW(&__pyx_t_13, 1);
  __pyx_t_13.memview = NULL;
  __pyx_t_13.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_14, 1);
  __pyx_t_14.memview = NULL;
  __pyx_t_14.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_17, 1);
  __pyx_t_17.memview = NULL;
  __pyx_t_17.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_18, 1);
  __pyx_t_18.memview = NULL;
  __pyx_t_18.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_19, 1);
  __pyx_t_19.memview = NULL;
  __pyx_t_19.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_20, 1);
  __pyx_t_20.memview = NULL;
  __pyx_t_20.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_21, 1);
  __pyx_t_21.memview = NULL;
  __pyx_t_21.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_22, 1);
  __pyx_t_22.memview = NULL;
  __pyx_t_22.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_23, 1);
  __pyx_t_23.memview = NULL;
  __pyx_t_23.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_24, 1);
  __pyx_t_24.memview = NULL;
  __pyx_t_24.data = NULL;
+1063:                  mt, mr, rz,
  __pyx_t_17 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_mt, PyBUF_WRITABLE); if (unlikely(!__pyx_t_17.memview)) __PYX_ERR(0, 1063, __pyx_L1_error)
  __pyx_t_18 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_mr, PyBUF_WRITABLE); if (unlikely(!__pyx_t_18.memview)) __PYX_ERR(0, 1063, __pyx_L1_error)
  __pyx_t_19 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_rz, PyBUF_WRITABLE); if (unlikely(!__pyx_t_19.memview)) __PYX_ERR(0, 1063, __pyx_L1_error)
+1064:                 hc2ss, hc2bg, ssidx, bgpar, sspar)
  __pyx_t_20 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(((PyObject *)__pyx_v_hc2ss), PyBUF_WRITABLE); if (unlikely(!__pyx_t_20.memview)) __PYX_ERR(0, 1064, __pyx_L1_error)
  __pyx_t_21 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(((PyObject *)__pyx_v_hc2bg), PyBUF_WRITABLE); if (unlikely(!__pyx_t_21.memview)) __PYX_ERR(0, 1064, __pyx_L1_error)
  __pyx_t_22 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_long(((PyObject *)__pyx_v_ssidx), PyBUF_WRITABLE); if (unlikely(!__pyx_t_22.memview)) __PYX_ERR(0, 1064, __pyx_L1_error)
  __pyx_t_23 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_double(((PyObject *)__pyx_v_bgpar), PyBUF_WRITABLE); if (unlikely(!__pyx_t_23.memview)) __PYX_ERR(0, 1064, __pyx_L1_error)
  __pyx_t_24 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_double(((PyObject *)__pyx_v_sspar), PyBUF_WRITABLE); if (unlikely(!__pyx_t_24.memview)) __PYX_ERR(0, 1064, __pyx_L1_error)
 1065:     # print(hc2ss, hc2bg, ssidx)
+1066:     return hc2ss, hc2bg, ssidx, bgpar, sspar
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = PyTuple_New(5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1066, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(((PyObject *)__pyx_v_hc2ss));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_hc2ss));
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_hc2ss));
  __Pyx_INCREF(((PyObject *)__pyx_v_hc2bg));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_hc2bg));
  PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_hc2bg));
  __Pyx_INCREF(((PyObject *)__pyx_v_ssidx));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_ssidx));
  PyTuple_SET_ITEM(__pyx_t_4, 2, ((PyObject *)__pyx_v_ssidx));
  __Pyx_INCREF(((PyObject *)__pyx_v_bgpar));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_bgpar));
  PyTuple_SET_ITEM(__pyx_t_4, 3, ((PyObject *)__pyx_v_bgpar));
  __Pyx_INCREF(((PyObject *)__pyx_v_sspar));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_sspar));
  PyTuple_SET_ITEM(__pyx_t_4, 4, ((PyObject *)__pyx_v_sspar));
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;
 1067: 
 1068: @cython.boundscheck(True)
 1069: @cython.wraparound(True)
 1070: @cython.nonecheck(True)
 1071: @cython.cdivision(True)
+1072: cdef void _ss_bg_hc_and_par(long[:] shape, double[:,:,:,:] h2fdf, double[:,:,:,:] number,
static void __pyx_f_8holodeck_7cyutils__ss_bg_hc_and_par(__Pyx_memviewslice __pyx_v_shape, __Pyx_memviewslice __pyx_v_h2fdf, __Pyx_memviewslice __pyx_v_number, long __pyx_v_nreals, long __pyx_v_thresh, __Pyx_memviewslice __pyx_v_mt, __Pyx_memviewslice __pyx_v_mr, __Pyx_memviewslice __pyx_v_rz, __Pyx_memviewslice __pyx_v_hc2ss, __Pyx_memviewslice __pyx_v_hc2bg, __Pyx_memviewslice __pyx_v_ssidx, __Pyx_memviewslice __pyx_v_bgpar, __Pyx_memviewslice __pyx_v_sspar) {
  int __pyx_v_M;
  int __pyx_v_Q;
  int __pyx_v_Z;
  int __pyx_v_F;
  int __pyx_v_R;
  int __pyx_v_mm;
  int __pyx_v_qq;
  int __pyx_v_zz;
  int __pyx_v_ff;
  int __pyx_v_rr;
  int __pyx_v_m_max;
  int __pyx_v_q_max;
  int __pyx_v_z_max;
  double __pyx_v_max;
  double __pyx_v_num;
  double __pyx_v_sum;
  double __pyx_v_m_avg;
  double __pyx_v_q_avg;
  double __pyx_v_z_avg;
  bitgen_t *__pyx_v_rng;
  char const *__pyx_v_capsule_name;
  PyObject *__pyx_v_capsule = NULL;
  PyObject *__pyx_v_cur = NULL;
  double __pyx_v_std;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_ss_bg_hc_and_par", 0);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_28);
  __Pyx_WriteUnraisable("holodeck.cyutils._ss_bg_hc_and_par", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_capsule);
  __Pyx_XDECREF(__pyx_v_cur);
  __Pyx_RefNannyFinishContext();
}
 1073:             long nreals, long thresh,
 1074:             double[:] mt, double[:] mr, double[:] rz,
 1075:             double[:,:] hc2ss, double[:,:] hc2bg, long[:,:,:] ssidx,
 1076:             double[:,:,:] bgpar, double[:,:,:] sspar):
 1077:     """
 1078:     Calculates the characteristic strain from loud single sources and a background of all other sources.
 1079: 
 1080:     Parameters
 1081:     __________
 1082:     shape : long[:] array
 1083:         shape of number, [M, Q, Z, F]
 1084:     number : double[:,:,:,:] array
 1085:         number per bin
 1086:     h2fdf : double[:,:,:,:] array
 1087:         strain amplitude squared * f/Delta f for a single source in each bin.
 1088:     nreals : int
 1089:         number of realizations.
 1090:     mt : (M,) 1Darray of scalars
 1091:         total masses of each bin center
 1092:     mr : (Q,) 1Darray of scalars
 1093:         mass ratios of each bin center
 1094:     rz : (Z,) 1Darray of scalars
 1095:         redshifts of each bin center
 1096: 
 1097:     hc2ss : double[:,:] array
 1098:         (memory address of) single source characteristic strain squared array.
 1099:     hc2bg : double[:,:] array
 1100:         (memory address of) background characteristic strain squared array.
 1101:     ssidx : [:,:,:] long array
 1102:         (memory address of) array for indices of max strain bins.
 1103:     bgpar :
 1104:         (memory address of) array of effective average parameters
 1105:     Returns
 1106:     _________
 1107:     void
 1108:     updated via memory address: hc2ss, hc2bg, ssidx, bg_par
 1109:     """
 1110: 
+1111:     cdef int M = shape[0]
  if (unlikely(((PyObject *) __pyx_v_shape.memview) == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
    __PYX_ERR(0, 1111, __pyx_L1_error)
  }
  __pyx_t_1 = 0;
  __pyx_t_2 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_shape.shape[0];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_shape.shape[0])) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 1111, __pyx_L1_error)
  }
  __pyx_v_M = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+1112:     cdef int Q = shape[1]
  if (unlikely(((PyObject *) __pyx_v_shape.memview) == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
    __PYX_ERR(0, 1112, __pyx_L1_error)
  }
  __pyx_t_1 = 1;
  __pyx_t_2 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_shape.shape[0];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_shape.shape[0])) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 1112, __pyx_L1_error)
  }
  __pyx_v_Q = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+1113:     cdef int Z = shape[2]
  if (unlikely(((PyObject *) __pyx_v_shape.memview) == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
    __PYX_ERR(0, 1113, __pyx_L1_error)
  }
  __pyx_t_1 = 2;
  __pyx_t_2 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_shape.shape[0];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_shape.shape[0])) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 1113, __pyx_L1_error)
  }
  __pyx_v_Z = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+1114:     cdef int F = shape[3]
  if (unlikely(((PyObject *) __pyx_v_shape.memview) == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
    __PYX_ERR(0, 1114, __pyx_L1_error)
  }
  __pyx_t_1 = 3;
  __pyx_t_2 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_shape.shape[0];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_shape.shape[0])) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 1114, __pyx_L1_error)
  }
  __pyx_v_F = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+1115:     cdef int R = nreals
  __pyx_v_R = __pyx_v_nreals;
 1116: 
 1117:     cdef int mm, qq, zz, ff, rr, m_max, q_max, z_max
 1118:     cdef double max, num, sum, m_avg, q_avg, z_avg
 1119: 
 1120: 
 1121:     # Setup random number generator from numpy library
 1122:     cdef bitgen_t *rng
+1123:     cdef const char *capsule_name = "BitGenerator"
  __pyx_v_capsule_name = ((char const *)"BitGenerator");
+1124:     capsule = PCG64().capsule
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_PCG64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1124, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1124, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_capsule); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1124, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_capsule = __pyx_t_4;
  __pyx_t_4 = 0;
 1125:     # Cast the pointer
+1126:     rng = <bitgen_t *> PyCapsule_GetPointer(capsule, capsule_name)
  __pyx_t_6 = PyCapsule_GetPointer(__pyx_v_capsule, __pyx_v_capsule_name); if (unlikely(__pyx_t_6 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 1126, __pyx_L1_error)
  __pyx_v_rng = ((bitgen_t *)__pyx_t_6);
+1127:     for rr in range(R):
  __pyx_t_2 = __pyx_v_R;
  __pyx_t_7 = __pyx_t_2;
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_rr = __pyx_t_8;
+1128:         for ff in range(F):
    __pyx_t_9 = __pyx_v_F;
    __pyx_t_10 = __pyx_t_9;
    for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) {
      __pyx_v_ff = __pyx_t_11;
+1129:             max=0
      __pyx_v_max = 0.0;
+1130:             sum=0
      __pyx_v_sum = 0.0;
+1131:             m_avg=0
      __pyx_v_m_avg = 0.0;
+1132:             q_avg=0
      __pyx_v_q_avg = 0.0;
+1133:             z_avg=0
      __pyx_v_z_avg = 0.0;
+1134:             m_max=-1
      __pyx_v_m_max = -1;
+1135:             q_max=-1
      __pyx_v_q_max = -1;
+1136:             z_max=-1
      __pyx_v_z_max = -1;
+1137:             for mm in range(M):
      __pyx_t_12 = __pyx_v_M;
      __pyx_t_13 = __pyx_t_12;
      for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
        __pyx_v_mm = __pyx_t_14;
+1138:                 for qq in range(Q):
        __pyx_t_15 = __pyx_v_Q;
        __pyx_t_16 = __pyx_t_15;
        for (__pyx_t_17 = 0; __pyx_t_17 < __pyx_t_16; __pyx_t_17+=1) {
          __pyx_v_qq = __pyx_t_17;
+1139:                     for zz in range(Z):
          __pyx_t_18 = __pyx_v_Z;
          __pyx_t_19 = __pyx_t_18;
          for (__pyx_t_20 = 0; __pyx_t_20 < __pyx_t_19; __pyx_t_20+=1) {
            __pyx_v_zz = __pyx_t_20;
+1140:                         num = number[mm,qq,zz,ff]
            if (unlikely(((PyObject *) __pyx_v_number.memview) == Py_None)) {
              PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
              __PYX_ERR(0, 1140, __pyx_L1_error)
            }
            __pyx_t_1 = __pyx_v_mm;
            __pyx_t_21 = __pyx_v_qq;
            __pyx_t_22 = __pyx_v_zz;
            __pyx_t_23 = __pyx_v_ff;
            __pyx_t_24 = -1;
            if (__pyx_t_1 < 0) {
              __pyx_t_1 += __pyx_v_number.shape[0];
              if (unlikely(__pyx_t_1 < 0)) __pyx_t_24 = 0;
            } else if (unlikely(__pyx_t_1 >= __pyx_v_number.shape[0])) __pyx_t_24 = 0;
            if (__pyx_t_21 < 0) {
              __pyx_t_21 += __pyx_v_number.shape[1];
              if (unlikely(__pyx_t_21 < 0)) __pyx_t_24 = 1;
            } else if (unlikely(__pyx_t_21 >= __pyx_v_number.shape[1])) __pyx_t_24 = 1;
            if (__pyx_t_22 < 0) {
              __pyx_t_22 += __pyx_v_number.shape[2];
              if (unlikely(__pyx_t_22 < 0)) __pyx_t_24 = 2;
            } else if (unlikely(__pyx_t_22 >= __pyx_v_number.shape[2])) __pyx_t_24 = 2;
            if (__pyx_t_23 < 0) {
              __pyx_t_23 += __pyx_v_number.shape[3];
              if (unlikely(__pyx_t_23 < 0)) __pyx_t_24 = 3;
            } else if (unlikely(__pyx_t_23 >= __pyx_v_number.shape[3])) __pyx_t_24 = 3;
            if (unlikely(__pyx_t_24 != -1)) {
              __Pyx_RaiseBufferIndexError(__pyx_t_24);
              __PYX_ERR(0, 1140, __pyx_L1_error)
            }
            __pyx_v_num = (*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_number.data + __pyx_t_1 * __pyx_v_number.strides[0]) ) + __pyx_t_21 * __pyx_v_number.strides[1]) ) + __pyx_t_22 * __pyx_v_number.strides[2]) ) + __pyx_t_23 * __pyx_v_number.strides[3]) )));
+1141:                         cur = h2fdf[mm,qq,zz,ff]
            if (unlikely(((PyObject *) __pyx_v_h2fdf.memview) == Py_None)) {
              PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
              __PYX_ERR(0, 1141, __pyx_L1_error)
            }
            __pyx_t_23 = __pyx_v_mm;
            __pyx_t_22 = __pyx_v_qq;
            __pyx_t_21 = __pyx_v_zz;
            __pyx_t_1 = __pyx_v_ff;
            __pyx_t_24 = -1;
            if (__pyx_t_23 < 0) {
              __pyx_t_23 += __pyx_v_h2fdf.shape[0];
              if (unlikely(__pyx_t_23 < 0)) __pyx_t_24 = 0;
            } else if (unlikely(__pyx_t_23 >= __pyx_v_h2fdf.shape[0])) __pyx_t_24 = 0;
            if (__pyx_t_22 < 0) {
              __pyx_t_22 += __pyx_v_h2fdf.shape[1];
              if (unlikely(__pyx_t_22 < 0)) __pyx_t_24 = 1;
            } else if (unlikely(__pyx_t_22 >= __pyx_v_h2fdf.shape[1])) __pyx_t_24 = 1;
            if (__pyx_t_21 < 0) {
              __pyx_t_21 += __pyx_v_h2fdf.shape[2];
              if (unlikely(__pyx_t_21 < 0)) __pyx_t_24 = 2;
            } else if (unlikely(__pyx_t_21 >= __pyx_v_h2fdf.shape[2])) __pyx_t_24 = 2;
            if (__pyx_t_1 < 0) {
              __pyx_t_1 += __pyx_v_h2fdf.shape[3];
              if (unlikely(__pyx_t_1 < 0)) __pyx_t_24 = 3;
            } else if (unlikely(__pyx_t_1 >= __pyx_v_h2fdf.shape[3])) __pyx_t_24 = 3;
            if (unlikely(__pyx_t_24 != -1)) {
              __Pyx_RaiseBufferIndexError(__pyx_t_24);
              __PYX_ERR(0, 1141, __pyx_L1_error)
            }
            __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_h2fdf.data + __pyx_t_23 * __pyx_v_h2fdf.strides[0]) ) + __pyx_t_22 * __pyx_v_h2fdf.strides[1]) ) + __pyx_t_21 * __pyx_v_h2fdf.strides[2]) ) + __pyx_t_1 * __pyx_v_h2fdf.strides[3]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1141, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_XDECREF_SET(__pyx_v_cur, __pyx_t_4);
            __pyx_t_4 = 0;
+1142:                         if (num>thresh):
            __pyx_t_25 = ((__pyx_v_num > __pyx_v_thresh) != 0);
            if (__pyx_t_25) {
/* … */
              goto __pyx_L13;
            }
+1143:                             std = sqrt(num)
              __pyx_v_std = sqrt(__pyx_v_num);
+1144:                             num = <double>random_normal(rng, num, std)
              __pyx_v_num = ((double)random_normal(__pyx_v_rng, __pyx_v_num, __pyx_v_std));
 1145:                         else:
+1146:                             num = <double>random_poisson(rng, num)
            /*else*/ {
              __pyx_v_num = ((double)random_poisson(__pyx_v_rng, __pyx_v_num));
            }
            __pyx_L13:;
+1147:                         if(cur > max and num > 0):
            __pyx_t_4 = PyFloat_FromDouble(__pyx_v_max); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1147, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __pyx_t_3 = PyObject_RichCompare(__pyx_v_cur, __pyx_t_4, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1147, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __pyx_t_26 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_26 < 0)) __PYX_ERR(0, 1147, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            if (__pyx_t_26) {
            } else {
              __pyx_t_25 = __pyx_t_26;
              goto __pyx_L15_bool_binop_done;
            }
            __pyx_t_26 = ((__pyx_v_num > 0.0) != 0);
            __pyx_t_25 = __pyx_t_26;
            __pyx_L15_bool_binop_done:;
            if (__pyx_t_25) {
/* … */
            }
+1148:                             max = cur
              __pyx_t_27 = __pyx_PyFloat_AsDouble(__pyx_v_cur); if (unlikely((__pyx_t_27 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 1148, __pyx_L1_error)
              __pyx_v_max = __pyx_t_27;
+1149:                             m_max = mm
              __pyx_v_m_max = __pyx_v_mm;
+1150:                             q_max = qq
              __pyx_v_q_max = __pyx_v_qq;
+1151:                             z_max = zz
              __pyx_v_z_max = __pyx_v_zz;
+1152:                         sum += num * cur
            __pyx_t_3 = PyFloat_FromDouble(__pyx_v_sum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1152, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_4 = PyFloat_FromDouble(__pyx_v_num); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1152, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __pyx_t_5 = PyNumber_Multiply(__pyx_t_4, __pyx_v_cur); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1152, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1152, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __pyx_t_27 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_27 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 1152, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __pyx_v_sum = __pyx_t_27;
+1153:                         m_avg += num * cur * mt[mm]
            __pyx_t_4 = PyFloat_FromDouble(__pyx_v_m_avg); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1153, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __pyx_t_5 = PyFloat_FromDouble(__pyx_v_num); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1153, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_5);
            __pyx_t_3 = PyNumber_Multiply(__pyx_t_5, __pyx_v_cur); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1153, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            if (unlikely(((PyObject *) __pyx_v_mt.memview) == Py_None)) {
              PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
              __PYX_ERR(0, 1153, __pyx_L1_error)
            }
            __pyx_t_1 = __pyx_v_mm;
            __pyx_t_24 = -1;
            if (__pyx_t_1 < 0) {
              __pyx_t_1 += __pyx_v_mt.shape[0];
              if (unlikely(__pyx_t_1 < 0)) __pyx_t_24 = 0;
            } else if (unlikely(__pyx_t_1 >= __pyx_v_mt.shape[0])) __pyx_t_24 = 0;
            if (unlikely(__pyx_t_24 != -1)) {
              __Pyx_RaiseBufferIndexError(__pyx_t_24);
              __PYX_ERR(0, 1153, __pyx_L1_error)
            }
            __pyx_t_5 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_mt.data + __pyx_t_1 * __pyx_v_mt.strides[0]) )))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1153, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_5);
            __pyx_t_28 = PyNumber_Multiply(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 1153, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_28);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_t_4, __pyx_t_28); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1153, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0;
            __pyx_t_27 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_27 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 1153, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __pyx_v_m_avg = __pyx_t_27;
+1154:                         q_avg += num * cur * mr[qq]
            __pyx_t_5 = PyFloat_FromDouble(__pyx_v_q_avg); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1154, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_5);
            __pyx_t_28 = PyFloat_FromDouble(__pyx_v_num); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 1154, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_28);
            __pyx_t_4 = PyNumber_Multiply(__pyx_t_28, __pyx_v_cur); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1154, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0;
            if (unlikely(((PyObject *) __pyx_v_mr.memview) == Py_None)) {
              PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
              __PYX_ERR(0, 1154, __pyx_L1_error)
            }
            __pyx_t_1 = __pyx_v_qq;
            __pyx_t_24 = -1;
            if (__pyx_t_1 < 0) {
              __pyx_t_1 += __pyx_v_mr.shape[0];
              if (unlikely(__pyx_t_1 < 0)) __pyx_t_24 = 0;
            } else if (unlikely(__pyx_t_1 >= __pyx_v_mr.shape[0])) __pyx_t_24 = 0;
            if (unlikely(__pyx_t_24 != -1)) {
              __Pyx_RaiseBufferIndexError(__pyx_t_24);
              __PYX_ERR(0, 1154, __pyx_L1_error)
            }
            __pyx_t_28 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_mr.data + __pyx_t_1 * __pyx_v_mr.strides[0]) )))); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 1154, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_28);
            __pyx_t_3 = PyNumber_Multiply(__pyx_t_4, __pyx_t_28); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1154, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0;
            __pyx_t_28 = PyNumber_InPlaceAdd(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 1154, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_28);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __pyx_t_27 = __pyx_PyFloat_AsDouble(__pyx_t_28); if (unlikely((__pyx_t_27 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 1154, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0;
            __pyx_v_q_avg = __pyx_t_27;
+1155:                         z_avg += num * cur * rz[zz]
            __pyx_t_28 = PyFloat_FromDouble(__pyx_v_z_avg); if (unlikely(!__pyx_t_28)) __PYX_ERR(0, 1155, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_28);
            __pyx_t_3 = PyFloat_FromDouble(__pyx_v_num); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1155, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_5 = PyNumber_Multiply(__pyx_t_3, __pyx_v_cur); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1155, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            if (unlikely(((PyObject *) __pyx_v_rz.memview) == Py_None)) {
              PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
              __PYX_ERR(0, 1155, __pyx_L1_error)
            }
            __pyx_t_1 = __pyx_v_zz;
            __pyx_t_24 = -1;
            if (__pyx_t_1 < 0) {
              __pyx_t_1 += __pyx_v_rz.shape[0];
              if (unlikely(__pyx_t_1 < 0)) __pyx_t_24 = 0;
            } else if (unlikely(__pyx_t_1 >= __pyx_v_rz.shape[0])) __pyx_t_24 = 0;
            if (unlikely(__pyx_t_24 != -1)) {
              __Pyx_RaiseBufferIndexError(__pyx_t_24);
              __PYX_ERR(0, 1155, __pyx_L1_error)
            }
            __pyx_t_3 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_rz.data + __pyx_t_1 * __pyx_v_rz.strides[0]) )))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1155, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_4 = PyNumber_Multiply(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1155, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_28, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1155, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_28); __pyx_t_28 = 0;
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __pyx_t_27 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_27 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 1155, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __pyx_v_z_avg = __pyx_t_27;
          }
        }
      }
 1156:             # characteristic frequencies squared
+1157:             hc2ss[ff,rr] = max
      if (unlikely(((PyObject *) __pyx_v_hc2ss.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1157, __pyx_L1_error)
      }
      __pyx_t_1 = __pyx_v_ff;
      __pyx_t_21 = __pyx_v_rr;
      __pyx_t_12 = -1;
      if (__pyx_t_1 < 0) {
        __pyx_t_1 += __pyx_v_hc2ss.shape[0];
        if (unlikely(__pyx_t_1 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_1 >= __pyx_v_hc2ss.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_21 < 0) {
        __pyx_t_21 += __pyx_v_hc2ss.shape[1];
        if (unlikely(__pyx_t_21 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_21 >= __pyx_v_hc2ss.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1157, __pyx_L1_error)
      }
      *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_hc2ss.data + __pyx_t_1 * __pyx_v_hc2ss.strides[0]) ) + __pyx_t_21 * __pyx_v_hc2ss.strides[1]) )) = __pyx_v_max;
+1158:             hc2bg[ff,rr] = sum - max
      if (unlikely(((PyObject *) __pyx_v_hc2bg.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1158, __pyx_L1_error)
      }
      __pyx_t_21 = __pyx_v_ff;
      __pyx_t_1 = __pyx_v_rr;
      __pyx_t_12 = -1;
      if (__pyx_t_21 < 0) {
        __pyx_t_21 += __pyx_v_hc2bg.shape[0];
        if (unlikely(__pyx_t_21 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_21 >= __pyx_v_hc2bg.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_1 < 0) {
        __pyx_t_1 += __pyx_v_hc2bg.shape[1];
        if (unlikely(__pyx_t_1 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_1 >= __pyx_v_hc2bg.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1158, __pyx_L1_error)
      }
      *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_hc2bg.data + __pyx_t_21 * __pyx_v_hc2bg.strides[0]) ) + __pyx_t_1 * __pyx_v_hc2bg.strides[1]) )) = (__pyx_v_sum - __pyx_v_max);
 1159: 
 1160:             # single source indices
+1161:             if (m_max<0):
      __pyx_t_25 = ((__pyx_v_m_max < 0) != 0);
      if (unlikely(__pyx_t_25)) {
/* … */
      }
+1162:                 raise
        __Pyx_ReraiseException(); __PYX_ERR(0, 1162, __pyx_L1_error)
+1163:             ssidx[0,ff,rr] = m_max # -1 if no single sources
      if (unlikely(((PyObject *) __pyx_v_ssidx.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1163, __pyx_L1_error)
      }
      __pyx_t_1 = 0;
      __pyx_t_21 = __pyx_v_ff;
      __pyx_t_22 = __pyx_v_rr;
      __pyx_t_12 = -1;
      if (__pyx_t_1 < 0) {
        __pyx_t_1 += __pyx_v_ssidx.shape[0];
        if (unlikely(__pyx_t_1 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_1 >= __pyx_v_ssidx.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_21 < 0) {
        __pyx_t_21 += __pyx_v_ssidx.shape[1];
        if (unlikely(__pyx_t_21 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_21 >= __pyx_v_ssidx.shape[1])) __pyx_t_12 = 1;
      if (__pyx_t_22 < 0) {
        __pyx_t_22 += __pyx_v_ssidx.shape[2];
        if (unlikely(__pyx_t_22 < 0)) __pyx_t_12 = 2;
      } else if (unlikely(__pyx_t_22 >= __pyx_v_ssidx.shape[2])) __pyx_t_12 = 2;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1163, __pyx_L1_error)
      }
      *((long *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_ssidx.data + __pyx_t_1 * __pyx_v_ssidx.strides[0]) ) + __pyx_t_21 * __pyx_v_ssidx.strides[1]) ) + __pyx_t_22 * __pyx_v_ssidx.strides[2]) )) = __pyx_v_m_max;
+1164:             ssidx[1,ff,rr] = q_max # -1 if no single sources
      if (unlikely(((PyObject *) __pyx_v_ssidx.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1164, __pyx_L1_error)
      }
      __pyx_t_22 = 1;
      __pyx_t_21 = __pyx_v_ff;
      __pyx_t_1 = __pyx_v_rr;
      __pyx_t_12 = -1;
      if (__pyx_t_22 < 0) {
        __pyx_t_22 += __pyx_v_ssidx.shape[0];
        if (unlikely(__pyx_t_22 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_22 >= __pyx_v_ssidx.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_21 < 0) {
        __pyx_t_21 += __pyx_v_ssidx.shape[1];
        if (unlikely(__pyx_t_21 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_21 >= __pyx_v_ssidx.shape[1])) __pyx_t_12 = 1;
      if (__pyx_t_1 < 0) {
        __pyx_t_1 += __pyx_v_ssidx.shape[2];
        if (unlikely(__pyx_t_1 < 0)) __pyx_t_12 = 2;
      } else if (unlikely(__pyx_t_1 >= __pyx_v_ssidx.shape[2])) __pyx_t_12 = 2;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1164, __pyx_L1_error)
      }
      *((long *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_ssidx.data + __pyx_t_22 * __pyx_v_ssidx.strides[0]) ) + __pyx_t_21 * __pyx_v_ssidx.strides[1]) ) + __pyx_t_1 * __pyx_v_ssidx.strides[2]) )) = __pyx_v_q_max;
+1165:             ssidx[2,ff,rr] = z_max # -1 if no single sources
      if (unlikely(((PyObject *) __pyx_v_ssidx.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1165, __pyx_L1_error)
      }
      __pyx_t_1 = 2;
      __pyx_t_21 = __pyx_v_ff;
      __pyx_t_22 = __pyx_v_rr;
      __pyx_t_12 = -1;
      if (__pyx_t_1 < 0) {
        __pyx_t_1 += __pyx_v_ssidx.shape[0];
        if (unlikely(__pyx_t_1 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_1 >= __pyx_v_ssidx.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_21 < 0) {
        __pyx_t_21 += __pyx_v_ssidx.shape[1];
        if (unlikely(__pyx_t_21 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_21 >= __pyx_v_ssidx.shape[1])) __pyx_t_12 = 1;
      if (__pyx_t_22 < 0) {
        __pyx_t_22 += __pyx_v_ssidx.shape[2];
        if (unlikely(__pyx_t_22 < 0)) __pyx_t_12 = 2;
      } else if (unlikely(__pyx_t_22 >= __pyx_v_ssidx.shape[2])) __pyx_t_12 = 2;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1165, __pyx_L1_error)
      }
      *((long *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_ssidx.data + __pyx_t_1 * __pyx_v_ssidx.strides[0]) ) + __pyx_t_21 * __pyx_v_ssidx.strides[1]) ) + __pyx_t_22 * __pyx_v_ssidx.strides[2]) )) = __pyx_v_z_max;
 1166: 
 1167:             # background average parameters
+1168:             bgpar[0,ff,rr] = ((m_avg - h2fdf[m_max, q_max, z_max, ff] * mt[m_max])
      if (unlikely(((PyObject *) __pyx_v_h2fdf.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1168, __pyx_L1_error)
      }
      __pyx_t_22 = __pyx_v_m_max;
      __pyx_t_21 = __pyx_v_q_max;
      __pyx_t_1 = __pyx_v_z_max;
      __pyx_t_23 = __pyx_v_ff;
      __pyx_t_12 = -1;
      if (__pyx_t_22 < 0) {
        __pyx_t_22 += __pyx_v_h2fdf.shape[0];
        if (unlikely(__pyx_t_22 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_22 >= __pyx_v_h2fdf.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_21 < 0) {
        __pyx_t_21 += __pyx_v_h2fdf.shape[1];
        if (unlikely(__pyx_t_21 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_21 >= __pyx_v_h2fdf.shape[1])) __pyx_t_12 = 1;
      if (__pyx_t_1 < 0) {
        __pyx_t_1 += __pyx_v_h2fdf.shape[2];
        if (unlikely(__pyx_t_1 < 0)) __pyx_t_12 = 2;
      } else if (unlikely(__pyx_t_1 >= __pyx_v_h2fdf.shape[2])) __pyx_t_12 = 2;
      if (__pyx_t_23 < 0) {
        __pyx_t_23 += __pyx_v_h2fdf.shape[3];
        if (unlikely(__pyx_t_23 < 0)) __pyx_t_12 = 3;
      } else if (unlikely(__pyx_t_23 >= __pyx_v_h2fdf.shape[3])) __pyx_t_12 = 3;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1168, __pyx_L1_error)
      }
      if (unlikely(((PyObject *) __pyx_v_mt.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1168, __pyx_L1_error)
      }
      __pyx_t_29 = __pyx_v_m_max;
      __pyx_t_12 = -1;
      if (__pyx_t_29 < 0) {
        __pyx_t_29 += __pyx_v_mt.shape[0];
        if (unlikely(__pyx_t_29 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_29 >= __pyx_v_mt.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1168, __pyx_L1_error)
      }
/* … */
      if (unlikely(((PyObject *) __pyx_v_bgpar.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1168, __pyx_L1_error)
      }
/* … */
      __pyx_t_30 = 0;
      __pyx_t_31 = __pyx_v_ff;
      __pyx_t_32 = __pyx_v_rr;
      __pyx_t_12 = -1;
      if (__pyx_t_30 < 0) {
        __pyx_t_30 += __pyx_v_bgpar.shape[0];
        if (unlikely(__pyx_t_30 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_30 >= __pyx_v_bgpar.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_31 < 0) {
        __pyx_t_31 += __pyx_v_bgpar.shape[1];
        if (unlikely(__pyx_t_31 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_31 >= __pyx_v_bgpar.shape[1])) __pyx_t_12 = 1;
      if (__pyx_t_32 < 0) {
        __pyx_t_32 += __pyx_v_bgpar.shape[2];
        if (unlikely(__pyx_t_32 < 0)) __pyx_t_12 = 2;
      } else if (unlikely(__pyx_t_32 >= __pyx_v_bgpar.shape[2])) __pyx_t_12 = 2;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1168, __pyx_L1_error)
      }
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_bgpar.data + __pyx_t_30 * __pyx_v_bgpar.strides[0]) ) + __pyx_t_31 * __pyx_v_bgpar.strides[1]) ) + __pyx_t_32 * __pyx_v_bgpar.strides[2]) )) = ((__pyx_v_m_avg - ((*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_h2fdf.data + __pyx_t_22 * __pyx_v_h2fdf.strides[0]) ) + __pyx_t_21 * __pyx_v_h2fdf.strides[1]) ) + __pyx_t_1 * __pyx_v_h2fdf.strides[2]) ) + __pyx_t_23 * __pyx_v_h2fdf.strides[3]) ))) * (*((double *) ( /* dim=0 */ (__pyx_v_mt.data + __pyx_t_29 * __pyx_v_mt.strides[0]) ))))) / (__pyx_v_sum - __pyx_v_max));
 1169:                                 /(sum-max))
+1170:             bgpar[1,ff,rr] = ((q_avg - h2fdf[m_max, q_max, z_max, ff] * mr[q_max])
      if (unlikely(((PyObject *) __pyx_v_h2fdf.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1170, __pyx_L1_error)
      }
      __pyx_t_29 = __pyx_v_m_max;
      __pyx_t_23 = __pyx_v_q_max;
      __pyx_t_1 = __pyx_v_z_max;
      __pyx_t_21 = __pyx_v_ff;
      __pyx_t_12 = -1;
      if (__pyx_t_29 < 0) {
        __pyx_t_29 += __pyx_v_h2fdf.shape[0];
        if (unlikely(__pyx_t_29 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_29 >= __pyx_v_h2fdf.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_23 < 0) {
        __pyx_t_23 += __pyx_v_h2fdf.shape[1];
        if (unlikely(__pyx_t_23 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_23 >= __pyx_v_h2fdf.shape[1])) __pyx_t_12 = 1;
      if (__pyx_t_1 < 0) {
        __pyx_t_1 += __pyx_v_h2fdf.shape[2];
        if (unlikely(__pyx_t_1 < 0)) __pyx_t_12 = 2;
      } else if (unlikely(__pyx_t_1 >= __pyx_v_h2fdf.shape[2])) __pyx_t_12 = 2;
      if (__pyx_t_21 < 0) {
        __pyx_t_21 += __pyx_v_h2fdf.shape[3];
        if (unlikely(__pyx_t_21 < 0)) __pyx_t_12 = 3;
      } else if (unlikely(__pyx_t_21 >= __pyx_v_h2fdf.shape[3])) __pyx_t_12 = 3;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1170, __pyx_L1_error)
      }
      if (unlikely(((PyObject *) __pyx_v_mr.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1170, __pyx_L1_error)
      }
      __pyx_t_22 = __pyx_v_q_max;
      __pyx_t_12 = -1;
      if (__pyx_t_22 < 0) {
        __pyx_t_22 += __pyx_v_mr.shape[0];
        if (unlikely(__pyx_t_22 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_22 >= __pyx_v_mr.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1170, __pyx_L1_error)
      }
/* … */
      if (unlikely(((PyObject *) __pyx_v_bgpar.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1170, __pyx_L1_error)
      }
/* … */
      __pyx_t_32 = 1;
      __pyx_t_31 = __pyx_v_ff;
      __pyx_t_30 = __pyx_v_rr;
      __pyx_t_12 = -1;
      if (__pyx_t_32 < 0) {
        __pyx_t_32 += __pyx_v_bgpar.shape[0];
        if (unlikely(__pyx_t_32 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_32 >= __pyx_v_bgpar.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_31 < 0) {
        __pyx_t_31 += __pyx_v_bgpar.shape[1];
        if (unlikely(__pyx_t_31 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_31 >= __pyx_v_bgpar.shape[1])) __pyx_t_12 = 1;
      if (__pyx_t_30 < 0) {
        __pyx_t_30 += __pyx_v_bgpar.shape[2];
        if (unlikely(__pyx_t_30 < 0)) __pyx_t_12 = 2;
      } else if (unlikely(__pyx_t_30 >= __pyx_v_bgpar.shape[2])) __pyx_t_12 = 2;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1170, __pyx_L1_error)
      }
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_bgpar.data + __pyx_t_32 * __pyx_v_bgpar.strides[0]) ) + __pyx_t_31 * __pyx_v_bgpar.strides[1]) ) + __pyx_t_30 * __pyx_v_bgpar.strides[2]) )) = ((__pyx_v_q_avg - ((*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_h2fdf.data + __pyx_t_29 * __pyx_v_h2fdf.strides[0]) ) + __pyx_t_23 * __pyx_v_h2fdf.strides[1]) ) + __pyx_t_1 * __pyx_v_h2fdf.strides[2]) ) + __pyx_t_21 * __pyx_v_h2fdf.strides[3]) ))) * (*((double *) ( /* dim=0 */ (__pyx_v_mr.data + __pyx_t_22 * __pyx_v_mr.strides[0]) ))))) / (__pyx_v_sum - __pyx_v_max));
 1171:                                 /(sum-max))
+1172:             bgpar[2,ff,rr] = ((z_avg - h2fdf[m_max, q_max, z_max, ff] * rz[z_max])
      if (unlikely(((PyObject *) __pyx_v_h2fdf.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1172, __pyx_L1_error)
      }
      __pyx_t_22 = __pyx_v_m_max;
      __pyx_t_21 = __pyx_v_q_max;
      __pyx_t_1 = __pyx_v_z_max;
      __pyx_t_23 = __pyx_v_ff;
      __pyx_t_12 = -1;
      if (__pyx_t_22 < 0) {
        __pyx_t_22 += __pyx_v_h2fdf.shape[0];
        if (unlikely(__pyx_t_22 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_22 >= __pyx_v_h2fdf.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_21 < 0) {
        __pyx_t_21 += __pyx_v_h2fdf.shape[1];
        if (unlikely(__pyx_t_21 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_21 >= __pyx_v_h2fdf.shape[1])) __pyx_t_12 = 1;
      if (__pyx_t_1 < 0) {
        __pyx_t_1 += __pyx_v_h2fdf.shape[2];
        if (unlikely(__pyx_t_1 < 0)) __pyx_t_12 = 2;
      } else if (unlikely(__pyx_t_1 >= __pyx_v_h2fdf.shape[2])) __pyx_t_12 = 2;
      if (__pyx_t_23 < 0) {
        __pyx_t_23 += __pyx_v_h2fdf.shape[3];
        if (unlikely(__pyx_t_23 < 0)) __pyx_t_12 = 3;
      } else if (unlikely(__pyx_t_23 >= __pyx_v_h2fdf.shape[3])) __pyx_t_12 = 3;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1172, __pyx_L1_error)
      }
      if (unlikely(((PyObject *) __pyx_v_rz.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1172, __pyx_L1_error)
      }
      __pyx_t_29 = __pyx_v_z_max;
      __pyx_t_12 = -1;
      if (__pyx_t_29 < 0) {
        __pyx_t_29 += __pyx_v_rz.shape[0];
        if (unlikely(__pyx_t_29 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_29 >= __pyx_v_rz.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1172, __pyx_L1_error)
      }
/* … */
      if (unlikely(((PyObject *) __pyx_v_bgpar.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1172, __pyx_L1_error)
      }
/* … */
      __pyx_t_30 = 2;
      __pyx_t_31 = __pyx_v_ff;
      __pyx_t_32 = __pyx_v_rr;
      __pyx_t_12 = -1;
      if (__pyx_t_30 < 0) {
        __pyx_t_30 += __pyx_v_bgpar.shape[0];
        if (unlikely(__pyx_t_30 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_30 >= __pyx_v_bgpar.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_31 < 0) {
        __pyx_t_31 += __pyx_v_bgpar.shape[1];
        if (unlikely(__pyx_t_31 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_31 >= __pyx_v_bgpar.shape[1])) __pyx_t_12 = 1;
      if (__pyx_t_32 < 0) {
        __pyx_t_32 += __pyx_v_bgpar.shape[2];
        if (unlikely(__pyx_t_32 < 0)) __pyx_t_12 = 2;
      } else if (unlikely(__pyx_t_32 >= __pyx_v_bgpar.shape[2])) __pyx_t_12 = 2;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1172, __pyx_L1_error)
      }
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_bgpar.data + __pyx_t_30 * __pyx_v_bgpar.strides[0]) ) + __pyx_t_31 * __pyx_v_bgpar.strides[1]) ) + __pyx_t_32 * __pyx_v_bgpar.strides[2]) )) = ((__pyx_v_z_avg - ((*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_h2fdf.data + __pyx_t_22 * __pyx_v_h2fdf.strides[0]) ) + __pyx_t_21 * __pyx_v_h2fdf.strides[1]) ) + __pyx_t_1 * __pyx_v_h2fdf.strides[2]) ) + __pyx_t_23 * __pyx_v_h2fdf.strides[3]) ))) * (*((double *) ( /* dim=0 */ (__pyx_v_rz.data + __pyx_t_29 * __pyx_v_rz.strides[0]) ))))) / (__pyx_v_sum - __pyx_v_max));
 1173:                                 /(sum-max))
 1174:             # single source parameters
+1175:             sspar[0,ff,rr] = mt[m_max]
      if (unlikely(((PyObject *) __pyx_v_mt.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1175, __pyx_L1_error)
      }
      __pyx_t_29 = __pyx_v_m_max;
      __pyx_t_12 = -1;
      if (__pyx_t_29 < 0) {
        __pyx_t_29 += __pyx_v_mt.shape[0];
        if (unlikely(__pyx_t_29 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_29 >= __pyx_v_mt.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1175, __pyx_L1_error)
      }
      if (unlikely(((PyObject *) __pyx_v_sspar.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1175, __pyx_L1_error)
      }
      __pyx_t_23 = 0;
      __pyx_t_1 = __pyx_v_ff;
      __pyx_t_21 = __pyx_v_rr;
      __pyx_t_12 = -1;
      if (__pyx_t_23 < 0) {
        __pyx_t_23 += __pyx_v_sspar.shape[0];
        if (unlikely(__pyx_t_23 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_23 >= __pyx_v_sspar.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_1 < 0) {
        __pyx_t_1 += __pyx_v_sspar.shape[1];
        if (unlikely(__pyx_t_1 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_1 >= __pyx_v_sspar.shape[1])) __pyx_t_12 = 1;
      if (__pyx_t_21 < 0) {
        __pyx_t_21 += __pyx_v_sspar.shape[2];
        if (unlikely(__pyx_t_21 < 0)) __pyx_t_12 = 2;
      } else if (unlikely(__pyx_t_21 >= __pyx_v_sspar.shape[2])) __pyx_t_12 = 2;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1175, __pyx_L1_error)
      }
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_sspar.data + __pyx_t_23 * __pyx_v_sspar.strides[0]) ) + __pyx_t_1 * __pyx_v_sspar.strides[1]) ) + __pyx_t_21 * __pyx_v_sspar.strides[2]) )) = (*((double *) ( /* dim=0 */ (__pyx_v_mt.data + __pyx_t_29 * __pyx_v_mt.strides[0]) )));
+1176:             sspar[1,ff,rr] = mr[q_max]
      if (unlikely(((PyObject *) __pyx_v_mr.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1176, __pyx_L1_error)
      }
      __pyx_t_29 = __pyx_v_q_max;
      __pyx_t_12 = -1;
      if (__pyx_t_29 < 0) {
        __pyx_t_29 += __pyx_v_mr.shape[0];
        if (unlikely(__pyx_t_29 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_29 >= __pyx_v_mr.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1176, __pyx_L1_error)
      }
      if (unlikely(((PyObject *) __pyx_v_sspar.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1176, __pyx_L1_error)
      }
      __pyx_t_21 = 1;
      __pyx_t_1 = __pyx_v_ff;
      __pyx_t_23 = __pyx_v_rr;
      __pyx_t_12 = -1;
      if (__pyx_t_21 < 0) {
        __pyx_t_21 += __pyx_v_sspar.shape[0];
        if (unlikely(__pyx_t_21 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_21 >= __pyx_v_sspar.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_1 < 0) {
        __pyx_t_1 += __pyx_v_sspar.shape[1];
        if (unlikely(__pyx_t_1 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_1 >= __pyx_v_sspar.shape[1])) __pyx_t_12 = 1;
      if (__pyx_t_23 < 0) {
        __pyx_t_23 += __pyx_v_sspar.shape[2];
        if (unlikely(__pyx_t_23 < 0)) __pyx_t_12 = 2;
      } else if (unlikely(__pyx_t_23 >= __pyx_v_sspar.shape[2])) __pyx_t_12 = 2;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1176, __pyx_L1_error)
      }
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_sspar.data + __pyx_t_21 * __pyx_v_sspar.strides[0]) ) + __pyx_t_1 * __pyx_v_sspar.strides[1]) ) + __pyx_t_23 * __pyx_v_sspar.strides[2]) )) = (*((double *) ( /* dim=0 */ (__pyx_v_mr.data + __pyx_t_29 * __pyx_v_mr.strides[0]) )));
+1177:             sspar[2,ff,rr] = rz[z_max]
      if (unlikely(((PyObject *) __pyx_v_rz.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1177, __pyx_L1_error)
      }
      __pyx_t_29 = __pyx_v_z_max;
      __pyx_t_12 = -1;
      if (__pyx_t_29 < 0) {
        __pyx_t_29 += __pyx_v_rz.shape[0];
        if (unlikely(__pyx_t_29 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_29 >= __pyx_v_rz.shape[0])) __pyx_t_12 = 0;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1177, __pyx_L1_error)
      }
      if (unlikely(((PyObject *) __pyx_v_sspar.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1177, __pyx_L1_error)
      }
      __pyx_t_23 = 2;
      __pyx_t_1 = __pyx_v_ff;
      __pyx_t_21 = __pyx_v_rr;
      __pyx_t_12 = -1;
      if (__pyx_t_23 < 0) {
        __pyx_t_23 += __pyx_v_sspar.shape[0];
        if (unlikely(__pyx_t_23 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_23 >= __pyx_v_sspar.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_1 < 0) {
        __pyx_t_1 += __pyx_v_sspar.shape[1];
        if (unlikely(__pyx_t_1 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_1 >= __pyx_v_sspar.shape[1])) __pyx_t_12 = 1;
      if (__pyx_t_21 < 0) {
        __pyx_t_21 += __pyx_v_sspar.shape[2];
        if (unlikely(__pyx_t_21 < 0)) __pyx_t_12 = 2;
      } else if (unlikely(__pyx_t_21 >= __pyx_v_sspar.shape[2])) __pyx_t_12 = 2;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1177, __pyx_L1_error)
      }
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_sspar.data + __pyx_t_23 * __pyx_v_sspar.strides[0]) ) + __pyx_t_1 * __pyx_v_sspar.strides[1]) ) + __pyx_t_21 * __pyx_v_sspar.strides[2]) )) = (*((double *) ( /* dim=0 */ (__pyx_v_rz.data + __pyx_t_29 * __pyx_v_rz.strides[0]) )));
+1178:             if (max==0): # sanity check
      __pyx_t_25 = ((__pyx_v_max == 0.0) != 0);
      if (__pyx_t_25) {
/* … */
      }
    }
  }
+1179:                 print('No sources found at %dth frequency' % ff) # could warn
        __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_ff); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1179, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = PyUnicode_Format(__pyx_kp_u_No_sources_found_at_dth_frequenc, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1179, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_print, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1179, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 1180:     # still need to sqrt and sum! (back in python)
 1181: 
+1182:     return
  goto __pyx_L0;
 1183: 
 1184: 
+1185: def test_sort():
/* Python wrapper */
static PyObject *__pyx_pw_8holodeck_7cyutils_11test_sort(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyMethodDef __pyx_mdef_8holodeck_7cyutils_11test_sort = {"test_sort", (PyCFunction)__pyx_pw_8holodeck_7cyutils_11test_sort, METH_NOARGS, 0};
static PyObject *__pyx_pw_8holodeck_7cyutils_11test_sort(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("test_sort (wrapper)", 0);
  __pyx_r = __pyx_pf_8holodeck_7cyutils_10test_sort(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8holodeck_7cyutils_10test_sort(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("test_sort", 0);
/* … */
  /* function exit code */
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_8holodeck_7cyutils_11test_sort, NULL, __pyx_n_s_holodeck_cyutils); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1185, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test_sort, __pyx_t_3) < 0) __PYX_ERR(0, 1185, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
/* … */
  __pyx_codeobj__34 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_holodeck_cyutils_pyx, __pyx_n_s_test_sort, 1185, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__34)) __PYX_ERR(0, 1185, __pyx_L1_error)
+1186:     _test_sort()
  __pyx_f_8holodeck_7cyutils__test_sort();
+1187:     return None
  __Pyx_XDECREF(__pyx_r);
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
 1188: 
+1189: cdef void _test_sort():
static void __pyx_f_8holodeck_7cyutils__test_sort(void) {
  double __pyx_v_test[4];
  int *__pyx_v_indices;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_test_sort", 0);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_WriteUnraisable("holodeck.cyutils._test_sort", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}
 1190:     cdef double test[4]
+1191:     test[:] = [1.0, -2.3, 7.8, 0.0]
  __pyx_t_1[0] = 1.0;
  __pyx_t_1[1] = -2.3;
  __pyx_t_1[2] = 7.8;
  __pyx_t_1[3] = 0.0;
  memcpy(&(__pyx_v_test[0]), __pyx_t_1, sizeof(__pyx_v_test[0]) * (4));
+1192:     cdef (int *)indices = <int *>malloc(4 * sizeof(int))
  __pyx_v_indices = ((int *)malloc((4 * (sizeof(int)))));
+1193:     print(test)
  __pyx_t_2 = __Pyx_carray_to_py_double(__pyx_v_test, 4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_print, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
 1194: 
+1195:     argsort(test, 4, &indices)
  __pyx_f_8holodeck_7cyutils_argsort(__pyx_v_test, 4, (&__pyx_v_indices));
+1196:     print(test)
  __pyx_t_3 = __Pyx_carray_to_py_double(__pyx_v_test, 4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1196, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_print, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1196, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+1197:     print(test[indices[0]], test[indices[1]], test[indices[2]], test[indices[3]])
  __pyx_t_2 = PyFloat_FromDouble((__pyx_v_test[(__pyx_v_indices[0])])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1197, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyFloat_FromDouble((__pyx_v_test[(__pyx_v_indices[1])])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1197, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyFloat_FromDouble((__pyx_v_test[(__pyx_v_indices[2])])); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1197, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyFloat_FromDouble((__pyx_v_test[(__pyx_v_indices[3])])); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1197, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyTuple_New(4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1197, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_6, 3, __pyx_t_5);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1197, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+1198:     return
  goto __pyx_L0;
 1199: 
+1200: def sort_h2fdf(h2fdf):
/* Python wrapper */
static PyObject *__pyx_pw_8holodeck_7cyutils_13sort_h2fdf(PyObject *__pyx_self, PyObject *__pyx_v_h2fdf); /*proto*/
static char __pyx_doc_8holodeck_7cyutils_12sort_h2fdf[] = " Get indices of sorted h2fdf.\n    Parameters\n    ----------\n    h2fdf : (M,Q,Z) NDarray\n        h_s^2 * f / df of a source in each bin.\n    Returns\n    -------\n    indices : ?\n    ";
static PyMethodDef __pyx_mdef_8holodeck_7cyutils_13sort_h2fdf = {"sort_h2fdf", (PyCFunction)__pyx_pw_8holodeck_7cyutils_13sort_h2fdf, METH_O, __pyx_doc_8holodeck_7cyutils_12sort_h2fdf};
static PyObject *__pyx_pw_8holodeck_7cyutils_13sort_h2fdf(PyObject *__pyx_self, PyObject *__pyx_v_h2fdf) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sort_h2fdf (wrapper)", 0);
  __pyx_r = __pyx_pf_8holodeck_7cyutils_12sort_h2fdf(__pyx_self, ((PyObject *)__pyx_v_h2fdf));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8holodeck_7cyutils_12sort_h2fdf(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_h2fdf) {
  __Pyx_memviewslice __pyx_v_shape = { 0, 0, { 0 }, { 0 }, { 0 } };
  long __pyx_v_size;
  __Pyx_memviewslice __pyx_v_flat_h2fdf = { 0, 0, { 0 }, { 0 }, { 0 } };
  long __pyx_v_ii;
  int *__pyx_v_indices;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sort_h2fdf", 0);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __Pyx_AddTraceback("holodeck.cyutils.sort_h2fdf", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_shape, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_v_flat_h2fdf, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__35 = PyTuple_Pack(6, __pyx_n_s_h2fdf, __pyx_n_s_shape, __pyx_n_s_size, __pyx_n_s_flat_h2fdf, __pyx_n_s_ii, __pyx_n_s_indices); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 1200, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__35);
  __Pyx_GIVEREF(__pyx_tuple__35);
/* … */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_8holodeck_7cyutils_13sort_h2fdf, NULL, __pyx_n_s_holodeck_cyutils); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1200, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sort_h2fdf, __pyx_t_3) < 0) __PYX_ERR(0, 1200, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_codeobj__36 = (PyObject*)__Pyx_PyCode_New(1, 0, 6, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__35, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_holodeck_cyutils_pyx, __pyx_n_s_sort_h2fdf, 1200, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__36)) __PYX_ERR(0, 1200, __pyx_L1_error)
 1201:     """ Get indices of sorted h2fdf.
 1202:     Parameters
 1203:     ----------
 1204:     h2fdf : (M,Q,Z) NDarray
 1205:         h_s^2 * f / df of a source in each bin.
 1206:     Returns
 1207:     -------
 1208:     indices : ?
 1209:     """
+1210:     cdef long[:] shape = np.array(h2fdf.shape)
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_h2fdf, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1210, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 1210, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_shape = __pyx_t_5;
  __pyx_t_5.memview = NULL;
  __pyx_t_5.data = NULL;
+1211:     cdef long size = shape[0] * shape[1] * shape[2]
  __pyx_t_6 = 0;
  __pyx_t_7 = -1;
  if (__pyx_t_6 < 0) {
    __pyx_t_6 += __pyx_v_shape.shape[0];
    if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
  } else if (unlikely(__pyx_t_6 >= __pyx_v_shape.shape[0])) __pyx_t_7 = 0;
  if (unlikely(__pyx_t_7 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_7);
    __PYX_ERR(0, 1211, __pyx_L1_error)
  }
  __pyx_t_8 = 1;
  __pyx_t_7 = -1;
  if (__pyx_t_8 < 0) {
    __pyx_t_8 += __pyx_v_shape.shape[0];
    if (unlikely(__pyx_t_8 < 0)) __pyx_t_7 = 0;
  } else if (unlikely(__pyx_t_8 >= __pyx_v_shape.shape[0])) __pyx_t_7 = 0;
  if (unlikely(__pyx_t_7 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_7);
    __PYX_ERR(0, 1211, __pyx_L1_error)
  }
  __pyx_t_9 = 2;
  __pyx_t_7 = -1;
  if (__pyx_t_9 < 0) {
    __pyx_t_9 += __pyx_v_shape.shape[0];
    if (unlikely(__pyx_t_9 < 0)) __pyx_t_7 = 0;
  } else if (unlikely(__pyx_t_9 >= __pyx_v_shape.shape[0])) __pyx_t_7 = 0;
  if (unlikely(__pyx_t_7 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_7);
    __PYX_ERR(0, 1211, __pyx_L1_error)
  }
  __pyx_v_size = (((*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_6 * __pyx_v_shape.strides[0]) ))) * (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_8 * __pyx_v_shape.strides[0]) )))) * (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_9 * __pyx_v_shape.strides[0]) ))));
 1212: 
+1213:     cdef double[:]flat_h2fdf = h2fdf.flatten()
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_h2fdf, __pyx_n_s_flatten); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1213, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1213, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 1213, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_flat_h2fdf = __pyx_t_10;
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;
 1214: 
+1215:     print('flattened array elements')
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1215, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* … */
  __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_flattened_array_elements); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 1215, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);
+1216:     for ii in range(size):
  __pyx_t_11 = __pyx_v_size;
  __pyx_t_12 = __pyx_t_11;
  for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) {
    __pyx_v_ii = __pyx_t_13;
+1217:         print(flat_h2fdf[ii])
    __pyx_t_9 = __pyx_v_ii;
    __pyx_t_7 = -1;
    if (__pyx_t_9 < 0) {
      __pyx_t_9 += __pyx_v_flat_h2fdf.shape[0];
      if (unlikely(__pyx_t_9 < 0)) __pyx_t_7 = 0;
    } else if (unlikely(__pyx_t_9 >= __pyx_v_flat_h2fdf.shape[0])) __pyx_t_7 = 0;
    if (unlikely(__pyx_t_7 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_7);
      __PYX_ERR(0, 1217, __pyx_L1_error)
    }
    __pyx_t_1 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_flat_h2fdf.data + __pyx_t_9 * __pyx_v_flat_h2fdf.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1217, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_builtin_print, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1217, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
 1218: 
+1219:     indices = _sort_h2fdf(flat_h2fdf, size)
  __pyx_v_indices = __pyx_f_8holodeck_7cyutils__sort_h2fdf(__pyx_v_flat_h2fdf, __pyx_v_size);
 1220: 
+1221:     print('\nsorted array elements')
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1221, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
/* … */
  __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_u_sorted_array_elements); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 1221, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__2);
  __Pyx_GIVEREF(__pyx_tuple__2);
+1222:     for ii in range(size):
  __pyx_t_11 = __pyx_v_size;
  __pyx_t_12 = __pyx_t_11;
  for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) {
    __pyx_v_ii = __pyx_t_13;
+1223:         print(flat_h2fdf[indices[ii]])
    __pyx_t_9 = (__pyx_v_indices[__pyx_v_ii]);
    __pyx_t_7 = -1;
    if (__pyx_t_9 < 0) {
      __pyx_t_9 += __pyx_v_flat_h2fdf.shape[0];
      if (unlikely(__pyx_t_9 < 0)) __pyx_t_7 = 0;
    } else if (unlikely(__pyx_t_9 >= __pyx_v_flat_h2fdf.shape[0])) __pyx_t_7 = 0;
    if (unlikely(__pyx_t_7 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_7);
      __PYX_ERR(0, 1223, __pyx_L1_error)
    }
    __pyx_t_3 = PyFloat_FromDouble((*((double *) ( /* dim=0 */ (__pyx_v_flat_h2fdf.data + __pyx_t_9 * __pyx_v_flat_h2fdf.strides[0]) )))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1223, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_print, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1223, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
 1224: 
+1225:     return
  __Pyx_XDECREF(__pyx_r);
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
 1226: 
+1227: cdef (int *) _sort_h2fdf(double[:] flat_h2fdf, long size):
static int *__pyx_f_8holodeck_7cyutils__sort_h2fdf(__Pyx_memviewslice __pyx_v_flat_h2fdf, long __pyx_v_size) {
  double *__pyx_v_array;
  int *__pyx_v_indices;
  long __pyx_v_ii;
  int *__pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_sort_h2fdf", 0);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("holodeck.cyutils._sort_h2fdf", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 1228: 
+1229:     cdef (double *)array = <double *>malloc(size * sizeof(double))
  __pyx_v_array = ((double *)malloc((__pyx_v_size * (sizeof(double)))));
+1230:     cdef (int *)indices = <int *>malloc(size * sizeof(int))
  __pyx_v_indices = ((int *)malloc((__pyx_v_size * (sizeof(int)))));
 1231: 
+1232:     for ii in range(size):
  __pyx_t_1 = __pyx_v_size;
  __pyx_t_2 = __pyx_t_1;
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
    __pyx_v_ii = __pyx_t_3;
+1233:         array[ii] = flat_h2fdf[ii]
    __pyx_t_4 = __pyx_v_ii;
    __pyx_t_5 = -1;
    if (__pyx_t_4 < 0) {
      __pyx_t_4 += __pyx_v_flat_h2fdf.shape[0];
      if (unlikely(__pyx_t_4 < 0)) __pyx_t_5 = 0;
    } else if (unlikely(__pyx_t_4 >= __pyx_v_flat_h2fdf.shape[0])) __pyx_t_5 = 0;
    if (unlikely(__pyx_t_5 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_5);
      __PYX_ERR(0, 1233, __pyx_L1_error)
    }
    (__pyx_v_array[__pyx_v_ii]) = (*((double *) ( /* dim=0 */ (__pyx_v_flat_h2fdf.data + __pyx_t_4 * __pyx_v_flat_h2fdf.strides[0]) )));
  }
 1234: 
+1235:     argsort(array, size, &indices)
  __pyx_f_8holodeck_7cyutils_argsort(__pyx_v_array, __pyx_v_size, (&__pyx_v_indices));
 1236: 
+1237:     return indices
  __pyx_r = __pyx_v_indices;
  goto __pyx_L0;
 1238: 
 1239: 
+1240: def loudest_hc_from_sorted(number, h2fdf, nreals, nloudest, msort, qsort, zsort, normal_threshold=1e10):
/* Python wrapper */
static PyObject *__pyx_pw_8holodeck_7cyutils_15loudest_hc_from_sorted(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8holodeck_7cyutils_14loudest_hc_from_sorted[] = "\n    Calculates the characteristic strain from loud single sources and a background of all other sources.\n\n    Parameters\n    ------------------------\n    number : [M, Q, Z, F] NDarray\n        number in each bin\n    h2fdf : [M, Q, Z, F] NDarray\n        Strain amplitude squared x frequency / frequency bin width for each bin.\n    nreals\n        Number of realizations.\n    nloudest\n        Number of loudest sources to separate in each frequency bin.\n    msort : (M*Q*Z,) 1Darray\n        M indices of each bin, sorted from largest to smallest h2fdf.\n    qsort : (M*Q*Z,) 1Darray\n        q indices of each bin, sorted from largest to smallest h2fdf.\n    zsort : (M*Q*Z,) 1Darray\n        z indices of each bin, sorted from largest to smallest h2fdf.\n    normal_threshold : float\n        Threshold for approximating poisson sampling as normal.\n\n    Returns\n    --------------------------\n    hc2ss : (F, R, L) Ndarray of scalars\n        Char strain squared of the loudest single sources.\n    hc2bg : (F, R) Ndarray of scalars\n        Char strain squared of the background.\n    ";
static PyMethodDef __pyx_mdef_8holodeck_7cyutils_15loudest_hc_from_sorted = {"loudest_hc_from_sorted", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8holodeck_7cyutils_15loudest_hc_from_sorted, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8holodeck_7cyutils_14loudest_hc_from_sorted};
static PyObject *__pyx_pw_8holodeck_7cyutils_15loudest_hc_from_sorted(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_number = 0;
  PyObject *__pyx_v_h2fdf = 0;
  PyObject *__pyx_v_nreals = 0;
  PyObject *__pyx_v_nloudest = 0;
  PyObject *__pyx_v_msort = 0;
  PyObject *__pyx_v_qsort = 0;
  PyObject *__pyx_v_zsort = 0;
  PyObject *__pyx_v_normal_threshold = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("loudest_hc_from_sorted (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_number,&__pyx_n_s_h2fdf,&__pyx_n_s_nreals,&__pyx_n_s_nloudest,&__pyx_n_s_msort,&__pyx_n_s_qsort,&__pyx_n_s_zsort,&__pyx_n_s_normal_threshold,0};
    PyObject* values[8] = {0,0,0,0,0,0,0,0};
    values[7] = ((PyObject *)__pyx_float_1e10);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_number)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_h2fdf)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_from_sorted", 0, 7, 8, 1); __PYX_ERR(0, 1240, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_nreals)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_from_sorted", 0, 7, 8, 2); __PYX_ERR(0, 1240, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_nloudest)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_from_sorted", 0, 7, 8, 3); __PYX_ERR(0, 1240, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_msort)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_from_sorted", 0, 7, 8, 4); __PYX_ERR(0, 1240, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_qsort)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_from_sorted", 0, 7, 8, 5); __PYX_ERR(0, 1240, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (likely((values[6] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_zsort)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_from_sorted", 0, 7, 8, 6); __PYX_ERR(0, 1240, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  7:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_normal_threshold);
          if (value) { values[7] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "loudest_hc_from_sorted") < 0)) __PYX_ERR(0, 1240, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_number = values[0];
    __pyx_v_h2fdf = values[1];
    __pyx_v_nreals = values[2];
    __pyx_v_nloudest = values[3];
    __pyx_v_msort = values[4];
    __pyx_v_qsort = values[5];
    __pyx_v_zsort = values[6];
    __pyx_v_normal_threshold = values[7];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("loudest_hc_from_sorted", 0, 7, 8, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1240, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("holodeck.cyutils.loudest_hc_from_sorted", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_8holodeck_7cyutils_14loudest_hc_from_sorted(__pyx_self, __pyx_v_number, __pyx_v_h2fdf, __pyx_v_nreals, __pyx_v_nloudest, __pyx_v_msort, __pyx_v_qsort, __pyx_v_zsort, __pyx_v_normal_threshold);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8holodeck_7cyutils_14loudest_hc_from_sorted(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_number, PyObject *__pyx_v_h2fdf, PyObject *__pyx_v_nreals, PyObject *__pyx_v_nloudest, PyObject *__pyx_v_msort, PyObject *__pyx_v_qsort, PyObject *__pyx_v_zsort, PyObject *__pyx_v_normal_threshold) {
  __Pyx_memviewslice __pyx_v_shape = { 0, 0, { 0 }, { 0 }, { 0 } };
  PyObject *__pyx_v_F = NULL;
  PyObject *__pyx_v_R = NULL;
  PyObject *__pyx_v_L = NULL;
  PyArrayObject *__pyx_v_hc2ss = 0;
  PyArrayObject *__pyx_v_hc2bg = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_hc2bg;
  __Pyx_Buffer __pyx_pybuffer_hc2bg;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_hc2ss;
  __Pyx_Buffer __pyx_pybuffer_hc2ss;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("loudest_hc_from_sorted", 0);
  __pyx_pybuffer_hc2ss.pybuffer.buf = NULL;
  __pyx_pybuffer_hc2ss.refcount = 0;
  __pyx_pybuffernd_hc2ss.data = NULL;
  __pyx_pybuffernd_hc2ss.rcbuffer = &__pyx_pybuffer_hc2ss;
  __pyx_pybuffer_hc2bg.pybuffer.buf = NULL;
  __pyx_pybuffer_hc2bg.refcount = 0;
  __pyx_pybuffernd_hc2bg.data = NULL;
  __pyx_pybuffernd_hc2bg.rcbuffer = &__pyx_pybuffer_hc2bg;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_11, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_15, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_16, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_17, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_18, 1);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2bg.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2ss.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("holodeck.cyutils.loudest_hc_from_sorted", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2bg.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2ss.rcbuffer->pybuffer);
  __pyx_L2:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_shape, 1);
  __Pyx_XDECREF(__pyx_v_F);
  __Pyx_XDECREF(__pyx_v_R);
  __Pyx_XDECREF(__pyx_v_L);
  __Pyx_XDECREF((PyObject *)__pyx_v_hc2ss);
  __Pyx_XDECREF((PyObject *)__pyx_v_hc2bg);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__37 = PyTuple_Pack(14, __pyx_n_s_number, __pyx_n_s_h2fdf, __pyx_n_s_nreals, __pyx_n_s_nloudest, __pyx_n_s_msort, __pyx_n_s_qsort, __pyx_n_s_zsort, __pyx_n_s_normal_threshold, __pyx_n_s_shape, __pyx_n_s_F, __pyx_n_s_R, __pyx_n_s_L, __pyx_n_s_hc2ss, __pyx_n_s_hc2bg); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 1240, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__37);
  __Pyx_GIVEREF(__pyx_tuple__37);
/* … */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_8holodeck_7cyutils_15loudest_hc_from_sorted, NULL, __pyx_n_s_holodeck_cyutils); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1240, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_loudest_hc_from_sorted, __pyx_t_3) < 0) __PYX_ERR(0, 1240, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_codeobj__38 = (PyObject*)__Pyx_PyCode_New(8, 0, 14, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__37, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_holodeck_cyutils_pyx, __pyx_n_s_loudest_hc_from_sorted, 1240, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__38)) __PYX_ERR(0, 1240, __pyx_L1_error)
 1241:     """
 1242:     Calculates the characteristic strain from loud single sources and a background of all other sources.
 1243: 
 1244:     Parameters
 1245:     ------------------------
 1246:     number : [M, Q, Z, F] NDarray
 1247:         number in each bin
 1248:     h2fdf : [M, Q, Z, F] NDarray
 1249:         Strain amplitude squared x frequency / frequency bin width for each bin.
 1250:     nreals
 1251:         Number of realizations.
 1252:     nloudest
 1253:         Number of loudest sources to separate in each frequency bin.
 1254:     msort : (M*Q*Z,) 1Darray
 1255:         M indices of each bin, sorted from largest to smallest h2fdf.
 1256:     qsort : (M*Q*Z,) 1Darray
 1257:         q indices of each bin, sorted from largest to smallest h2fdf.
 1258:     zsort : (M*Q*Z,) 1Darray
 1259:         z indices of each bin, sorted from largest to smallest h2fdf.
 1260:     normal_threshold : float
 1261:         Threshold for approximating poisson sampling as normal.
 1262: 
 1263:     Returns
 1264:     --------------------------
 1265:     hc2ss : (F, R, L) Ndarray of scalars
 1266:         Char strain squared of the loudest single sources.
 1267:     hc2bg : (F, R) Ndarray of scalars
 1268:         Char strain squared of the background.
 1269:     """
 1270: 
+1271:     cdef long[:] shape = np.array(number.shape)
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_number, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1271, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 1271, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_shape = __pyx_t_5;
  __pyx_t_5.memview = NULL;
  __pyx_t_5.data = NULL;
+1272:     F = shape[3]
  __pyx_t_6 = 3;
  __pyx_t_7 = -1;
  if (__pyx_t_6 < 0) {
    __pyx_t_6 += __pyx_v_shape.shape[0];
    if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
  } else if (unlikely(__pyx_t_6 >= __pyx_v_shape.shape[0])) __pyx_t_7 = 0;
  if (unlikely(__pyx_t_7 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_7);
    __PYX_ERR(0, 1272, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyInt_From_long((*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_6 * __pyx_v_shape.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1272, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_F = __pyx_t_1;
  __pyx_t_1 = 0;
+1273:     R = nreals
  __Pyx_INCREF(__pyx_v_nreals);
  __pyx_v_R = __pyx_v_nreals;
+1274:     L = nloudest
  __Pyx_INCREF(__pyx_v_nloudest);
  __pyx_v_L = __pyx_v_nloudest;
+1275:     cdef np.ndarray[np.double_t, ndim=3] hc2ss = np.zeros((F,R,L))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1275, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1275, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1275, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_R);
  __Pyx_INCREF(__pyx_v_L);
  __Pyx_GIVEREF(__pyx_v_L);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_L);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1275, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1275, __pyx_L1_error)
  __pyx_t_8 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_hc2ss.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_hc2ss = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 1275, __pyx_L1_error)
    } else {__pyx_pybuffernd_hc2ss.diminfo[0].strides = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_hc2ss.diminfo[0].shape = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_hc2ss.diminfo[1].strides = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_hc2ss.diminfo[1].shape = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_hc2ss.diminfo[2].strides = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_hc2ss.diminfo[2].shape = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_8 = 0;
  __pyx_v_hc2ss = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
+1276:     cdef np.ndarray[np.double_t, ndim=2] hc2bg = np.zeros((F,R))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1276, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1276, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1276, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_R);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1276, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1276, __pyx_L1_error)
  __pyx_t_9 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_hc2bg.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_hc2bg = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 1276, __pyx_L1_error)
    } else {__pyx_pybuffernd_hc2bg.diminfo[0].strides = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_hc2bg.diminfo[0].shape = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_hc2bg.diminfo[1].strides = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_hc2bg.diminfo[1].shape = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_9 = 0;
  __pyx_v_hc2bg = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
+1277:     _loudest_hc_from_sorted(shape, h2fdf, number, nreals, nloudest, normal_threshold,
  __pyx_t_10 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_double(__pyx_v_h2fdf, PyBUF_WRITABLE); if (unlikely(!__pyx_t_10.memview)) __PYX_ERR(0, 1277, __pyx_L1_error)
  __pyx_t_11 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_double(__pyx_v_number, PyBUF_WRITABLE); if (unlikely(!__pyx_t_11.memview)) __PYX_ERR(0, 1277, __pyx_L1_error)
  __pyx_t_12 = __Pyx_PyInt_As_long(__pyx_v_nreals); if (unlikely((__pyx_t_12 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1277, __pyx_L1_error)
  __pyx_t_13 = __Pyx_PyInt_As_long(__pyx_v_nloudest); if (unlikely((__pyx_t_13 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1277, __pyx_L1_error)
  __pyx_t_14 = __Pyx_PyInt_As_long(__pyx_v_normal_threshold); if (unlikely((__pyx_t_14 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1277, __pyx_L1_error)
/* … */
  __pyx_f_8holodeck_7cyutils__loudest_hc_from_sorted(__pyx_v_shape, __pyx_t_10, __pyx_t_11, __pyx_t_12, __pyx_t_13, __pyx_t_14, __pyx_t_5, __pyx_t_15, __pyx_t_16, __pyx_t_17, __pyx_t_18);
  __PYX_XDEC_MEMVIEW(&__pyx_t_10, 1);
  __pyx_t_10.memview = NULL;
  __pyx_t_10.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_11, 1);
  __pyx_t_11.memview = NULL;
  __pyx_t_11.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
  __pyx_t_5.memview = NULL;
  __pyx_t_5.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_15, 1);
  __pyx_t_15.memview = NULL;
  __pyx_t_15.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_16, 1);
  __pyx_t_16.memview = NULL;
  __pyx_t_16.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_17, 1);
  __pyx_t_17.memview = NULL;
  __pyx_t_17.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_18, 1);
  __pyx_t_18.memview = NULL;
  __pyx_t_18.data = NULL;
+1278:                             msort, qsort, zsort,
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(__pyx_v_msort, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 1278, __pyx_L1_error)
  __pyx_t_15 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(__pyx_v_qsort, PyBUF_WRITABLE); if (unlikely(!__pyx_t_15.memview)) __PYX_ERR(0, 1278, __pyx_L1_error)
  __pyx_t_16 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(__pyx_v_zsort, PyBUF_WRITABLE); if (unlikely(!__pyx_t_16.memview)) __PYX_ERR(0, 1278, __pyx_L1_error)
+1279:                             hc2ss, hc2bg)
  __pyx_t_17 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_double(((PyObject *)__pyx_v_hc2ss), PyBUF_WRITABLE); if (unlikely(!__pyx_t_17.memview)) __PYX_ERR(0, 1279, __pyx_L1_error)
  __pyx_t_18 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(((PyObject *)__pyx_v_hc2bg), PyBUF_WRITABLE); if (unlikely(!__pyx_t_18.memview)) __PYX_ERR(0, 1279, __pyx_L1_error)
+1280:     return hc2ss, hc2bg
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1280, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_hc2ss));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_hc2ss));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_hc2ss));
  __Pyx_INCREF(((PyObject *)__pyx_v_hc2bg));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_hc2bg));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_hc2bg));
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;
 1281: 
 1282: @cython.boundscheck(True)
 1283: @cython.wraparound(True)
 1284: @cython.nonecheck(True)
 1285: @cython.cdivision(True)
+1286: cdef void _loudest_hc_from_sorted(long[:] shape, double[:,:,:,:] h2fdf, double[:,:,:,:] number,
static void __pyx_f_8holodeck_7cyutils__loudest_hc_from_sorted(__Pyx_memviewslice __pyx_v_shape, __Pyx_memviewslice __pyx_v_h2fdf, __Pyx_memviewslice __pyx_v_number, long __pyx_v_nreals, long __pyx_v_nloudest, long __pyx_v_thresh, __Pyx_memviewslice __pyx_v_msort, __Pyx_memviewslice __pyx_v_qsort, __Pyx_memviewslice __pyx_v_zsort, __Pyx_memviewslice __pyx_v_hc2ss, __Pyx_memviewslice __pyx_v_hc2bg) {
  int __pyx_v_M;
  int __pyx_v_Q;
  int __pyx_v_Z;
  int __pyx_v_F;
  int __pyx_v_L;
  int __pyx_v_R;
  int __pyx_v_mm;
  int __pyx_v_qq;
  int __pyx_v_zz;
  int __pyx_v_ff;
  int __pyx_v_rr;
  int __pyx_v_ll;
  double __pyx_v_num;
  double __pyx_v_sum;
  bitgen_t *__pyx_v_rng;
  char const *__pyx_v_capsule_name;
  PyObject *__pyx_v_capsule = NULL;
  int __pyx_v_bb;
  double __pyx_v_std;
  PyObject *__pyx_v_cur = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_loudest_hc_from_sorted", 0);
/* … */
  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_WriteUnraisable("holodeck.cyutils._loudest_hc_from_sorted", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_capsule);
  __Pyx_XDECREF(__pyx_v_cur);
  __Pyx_RefNannyFinishContext();
}
 1287:             long nreals, long nloudest, long thresh,
 1288:             long[:] msort, long[:] qsort, long[:] zsort,
 1289:             double[:,:,:] hc2ss, double[:,:] hc2bg):
 1290:     """
 1291:     Calculates the characteristic strain from loud single sources and a background of all other sources.
 1292: 
 1293:     Parameters
 1294:     ----------
 1295:     shape : long[:] array
 1296:         Shape of number, [M, Q, Z, F].
 1297:     number : double[:,:,:,:] array
 1298:         Number per bin.
 1299:     h2fdf : double[:,:,:,:] array
 1300:         Strain amplitude squared * f/Delta f for a single source in each bin.
 1301:     nreals : int
 1302:         Number of realizations.
 1303:     nloudest : int
 1304:         Number of loudest sources at each source.
 1305:     msort : (M*Q*Z,) 1Darray
 1306:         M indices of each bin, sorted from largest to smallest h2fdf.
 1307:     qsort : (M*Q*Z,) 1Darray
 1308:         q indices of each bin, sorted from largest to smallest h2fdf.
 1309:     zsort : (M*Q*Z,) 1Darray
 1310:         z indices of each bin, sorted from largest to smallest h2fdf.
 1311:     hc2ss : double[:,:,:] array
 1312:         (Memory address of) single source characteristic strain squared array.
 1313:     hc2bg : double[:,:] array
 1314:         (Memory address of) background characteristic strain squared array.
 1315: 
 1316:     Returns
 1317:     -------
 1318:     void
 1319:     updated via memory address: hc2ss, hc2bg, ssidx, bg_par
 1320:     """
 1321: 
+1322:     cdef int M = shape[0]
  if (unlikely(((PyObject *) __pyx_v_shape.memview) == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
    __PYX_ERR(0, 1322, __pyx_L1_error)
  }
  __pyx_t_1 = 0;
  __pyx_t_2 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_shape.shape[0];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_shape.shape[0])) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 1322, __pyx_L1_error)
  }
  __pyx_v_M = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+1323:     cdef int Q = shape[1]
  if (unlikely(((PyObject *) __pyx_v_shape.memview) == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
    __PYX_ERR(0, 1323, __pyx_L1_error)
  }
  __pyx_t_1 = 1;
  __pyx_t_2 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_shape.shape[0];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_shape.shape[0])) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 1323, __pyx_L1_error)
  }
  __pyx_v_Q = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+1324:     cdef int Z = shape[2]
  if (unlikely(((PyObject *) __pyx_v_shape.memview) == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
    __PYX_ERR(0, 1324, __pyx_L1_error)
  }
  __pyx_t_1 = 2;
  __pyx_t_2 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_shape.shape[0];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_shape.shape[0])) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 1324, __pyx_L1_error)
  }
  __pyx_v_Z = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+1325:     cdef int F = shape[3]
  if (unlikely(((PyObject *) __pyx_v_shape.memview) == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
    __PYX_ERR(0, 1325, __pyx_L1_error)
  }
  __pyx_t_1 = 3;
  __pyx_t_2 = -1;
  if (__pyx_t_1 < 0) {
    __pyx_t_1 += __pyx_v_shape.shape[0];
    if (unlikely(__pyx_t_1 < 0)) __pyx_t_2 = 0;
  } else if (unlikely(__pyx_t_1 >= __pyx_v_shape.shape[0])) __pyx_t_2 = 0;
  if (unlikely(__pyx_t_2 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_2);
    __PYX_ERR(0, 1325, __pyx_L1_error)
  }
  __pyx_v_F = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+1326:     cdef int L = nloudest
  __pyx_v_L = __pyx_v_nloudest;
+1327:     cdef int R = nreals
  __pyx_v_R = __pyx_v_nreals;
 1328: 
 1329:     cdef int mm, qq, zz, ff, rr, ll
 1330:     cdef double num, sum
 1331: 
 1332:     # Setup random number generator from numpy library
 1333:     cdef bitgen_t *rng
+1334:     cdef const char *capsule_name = "BitGenerator"
  __pyx_v_capsule_name = ((char const *)"BitGenerator");
+1335:     capsule = PCG64().capsule
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_PCG64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1335, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_3 = (__pyx_t_5) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1335, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_capsule); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1335, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_capsule = __pyx_t_4;
  __pyx_t_4 = 0;
 1336:     # Cast the pointer
+1337:     rng = <bitgen_t *> PyCapsule_GetPointer(capsule, capsule_name)
  __pyx_t_6 = PyCapsule_GetPointer(__pyx_v_capsule, __pyx_v_capsule_name); if (unlikely(__pyx_t_6 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 1337, __pyx_L1_error)
  __pyx_v_rng = ((bitgen_t *)__pyx_t_6);
+1338:     for rr in range(R):
  __pyx_t_2 = __pyx_v_R;
  __pyx_t_7 = __pyx_t_2;
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_rr = __pyx_t_8;
+1339:         for ff in range(F):
    __pyx_t_9 = __pyx_v_F;
    __pyx_t_10 = __pyx_t_9;
    for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) {
      __pyx_v_ff = __pyx_t_11;
+1340:             ll = 0 # track which index in the loudest list you're currently storing
      __pyx_v_ll = 0;
 1341:                      # start at 0 for the loudest of all.
+1342:             sum = 0
      __pyx_v_sum = 0.0;
+1343:             for bb in range(M*Q*Z): #iterate through bins, loudest to quietest
      __pyx_t_12 = ((__pyx_v_M * __pyx_v_Q) * __pyx_v_Z);
      __pyx_t_13 = __pyx_t_12;
      for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
        __pyx_v_bb = __pyx_t_14;
+1344:                 mm = msort[bb]
        if (unlikely(((PyObject *) __pyx_v_msort.memview) == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
          __PYX_ERR(0, 1344, __pyx_L1_error)
        }
        __pyx_t_1 = __pyx_v_bb;
        __pyx_t_15 = -1;
        if (__pyx_t_1 < 0) {
          __pyx_t_1 += __pyx_v_msort.shape[0];
          if (unlikely(__pyx_t_1 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_1 >= __pyx_v_msort.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 1344, __pyx_L1_error)
        }
        __pyx_v_mm = (*((long *) ( /* dim=0 */ (__pyx_v_msort.data + __pyx_t_1 * __pyx_v_msort.strides[0]) )));
+1345:                 qq = qsort[bb]
        if (unlikely(((PyObject *) __pyx_v_qsort.memview) == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
          __PYX_ERR(0, 1345, __pyx_L1_error)
        }
        __pyx_t_1 = __pyx_v_bb;
        __pyx_t_15 = -1;
        if (__pyx_t_1 < 0) {
          __pyx_t_1 += __pyx_v_qsort.shape[0];
          if (unlikely(__pyx_t_1 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_1 >= __pyx_v_qsort.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 1345, __pyx_L1_error)
        }
        __pyx_v_qq = (*((long *) ( /* dim=0 */ (__pyx_v_qsort.data + __pyx_t_1 * __pyx_v_qsort.strides[0]) )));
+1346:                 zz = zsort[bb]
        if (unlikely(((PyObject *) __pyx_v_zsort.memview) == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
          __PYX_ERR(0, 1346, __pyx_L1_error)
        }
        __pyx_t_1 = __pyx_v_bb;
        __pyx_t_15 = -1;
        if (__pyx_t_1 < 0) {
          __pyx_t_1 += __pyx_v_zsort.shape[0];
          if (unlikely(__pyx_t_1 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_1 >= __pyx_v_zsort.shape[0])) __pyx_t_15 = 0;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 1346, __pyx_L1_error)
        }
        __pyx_v_zz = (*((long *) ( /* dim=0 */ (__pyx_v_zsort.data + __pyx_t_1 * __pyx_v_zsort.strides[0]) )));
+1347:                 num = number[mm,qq,zz,ff]
        if (unlikely(((PyObject *) __pyx_v_number.memview) == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
          __PYX_ERR(0, 1347, __pyx_L1_error)
        }
        __pyx_t_1 = __pyx_v_mm;
        __pyx_t_16 = __pyx_v_qq;
        __pyx_t_17 = __pyx_v_zz;
        __pyx_t_18 = __pyx_v_ff;
        __pyx_t_15 = -1;
        if (__pyx_t_1 < 0) {
          __pyx_t_1 += __pyx_v_number.shape[0];
          if (unlikely(__pyx_t_1 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_1 >= __pyx_v_number.shape[0])) __pyx_t_15 = 0;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_number.shape[1];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_15 = 1;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_number.shape[1])) __pyx_t_15 = 1;
        if (__pyx_t_17 < 0) {
          __pyx_t_17 += __pyx_v_number.shape[2];
          if (unlikely(__pyx_t_17 < 0)) __pyx_t_15 = 2;
        } else if (unlikely(__pyx_t_17 >= __pyx_v_number.shape[2])) __pyx_t_15 = 2;
        if (__pyx_t_18 < 0) {
          __pyx_t_18 += __pyx_v_number.shape[3];
          if (unlikely(__pyx_t_18 < 0)) __pyx_t_15 = 3;
        } else if (unlikely(__pyx_t_18 >= __pyx_v_number.shape[3])) __pyx_t_15 = 3;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 1347, __pyx_L1_error)
        }
        __pyx_v_num = (*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_number.data + __pyx_t_1 * __pyx_v_number.strides[0]) ) + __pyx_t_16 * __pyx_v_number.strides[1]) ) + __pyx_t_17 * __pyx_v_number.strides[2]) ) + __pyx_t_18 * __pyx_v_number.strides[3]) )));
+1348:                 if (num>thresh): # Gaussian sample
        __pyx_t_19 = ((__pyx_v_num > __pyx_v_thresh) != 0);
        if (__pyx_t_19) {
/* … */
          goto __pyx_L9;
        }
+1349:                     std = sqrt(num)
          __pyx_v_std = sqrt(__pyx_v_num);
+1350:                     num = <double>random_normal(rng, num, std)
          __pyx_v_num = ((double)random_normal(__pyx_v_rng, __pyx_v_num, __pyx_v_std));
 1351:                 else:            # Poisson sample
+1352:                     num = <double>random_poisson(rng, num)
        /*else*/ {
          __pyx_v_num = ((double)random_poisson(__pyx_v_rng, __pyx_v_num));
        }
        __pyx_L9:;
+1353:                 if(num < 1):
        __pyx_t_19 = ((__pyx_v_num < 1.0) != 0);
        if (__pyx_t_19) {
/* … */
        }
+1354:                     continue
          goto __pyx_L7_continue;
+1355:                 cur = h2fdf[mm,qq,zz,ff]
        if (unlikely(((PyObject *) __pyx_v_h2fdf.memview) == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
          __PYX_ERR(0, 1355, __pyx_L1_error)
        }
        __pyx_t_18 = __pyx_v_mm;
        __pyx_t_17 = __pyx_v_qq;
        __pyx_t_16 = __pyx_v_zz;
        __pyx_t_1 = __pyx_v_ff;
        __pyx_t_15 = -1;
        if (__pyx_t_18 < 0) {
          __pyx_t_18 += __pyx_v_h2fdf.shape[0];
          if (unlikely(__pyx_t_18 < 0)) __pyx_t_15 = 0;
        } else if (unlikely(__pyx_t_18 >= __pyx_v_h2fdf.shape[0])) __pyx_t_15 = 0;
        if (__pyx_t_17 < 0) {
          __pyx_t_17 += __pyx_v_h2fdf.shape[1];
          if (unlikely(__pyx_t_17 < 0)) __pyx_t_15 = 1;
        } else if (unlikely(__pyx_t_17 >= __pyx_v_h2fdf.shape[1])) __pyx_t_15 = 1;
        if (__pyx_t_16 < 0) {
          __pyx_t_16 += __pyx_v_h2fdf.shape[2];
          if (unlikely(__pyx_t_16 < 0)) __pyx_t_15 = 2;
        } else if (unlikely(__pyx_t_16 >= __pyx_v_h2fdf.shape[2])) __pyx_t_15 = 2;
        if (__pyx_t_1 < 0) {
          __pyx_t_1 += __pyx_v_h2fdf.shape[3];
          if (unlikely(__pyx_t_1 < 0)) __pyx_t_15 = 3;
        } else if (unlikely(__pyx_t_1 >= __pyx_v_h2fdf.shape[3])) __pyx_t_15 = 3;
        if (unlikely(__pyx_t_15 != -1)) {
          __Pyx_RaiseBufferIndexError(__pyx_t_15);
          __PYX_ERR(0, 1355, __pyx_L1_error)
        }
        __pyx_t_4 = PyFloat_FromDouble((*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_h2fdf.data + __pyx_t_18 * __pyx_v_h2fdf.strides[0]) ) + __pyx_t_17 * __pyx_v_h2fdf.strides[1]) ) + __pyx_t_16 * __pyx_v_h2fdf.strides[2]) ) + __pyx_t_1 * __pyx_v_h2fdf.strides[3]) )))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1355, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_XDECREF_SET(__pyx_v_cur, __pyx_t_4);
        __pyx_t_4 = 0;
+1356:                 if (num<1):
        __pyx_t_19 = ((__pyx_v_num < 1.0) != 0);
        if (__pyx_t_19) {
/* … */
        }
+1357:                     continue # to next loudest bin
          goto __pyx_L7_continue;
+1358:                 while (ll < L) and (num > 0):
        while (1) {
          __pyx_t_20 = ((__pyx_v_ll < __pyx_v_L) != 0);
          if (__pyx_t_20) {
          } else {
            __pyx_t_19 = __pyx_t_20;
            goto __pyx_L14_bool_binop_done;
          }
          __pyx_t_20 = ((__pyx_v_num > 0.0) != 0);
          __pyx_t_19 = __pyx_t_20;
          __pyx_L14_bool_binop_done:;
          if (!__pyx_t_19) break;
+1359:                     hc2ss[ff,rr,ll] = cur
          __pyx_t_21 = __pyx_PyFloat_AsDouble(__pyx_v_cur); if (unlikely((__pyx_t_21 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 1359, __pyx_L1_error)
          if (unlikely(((PyObject *) __pyx_v_hc2ss.memview) == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
            __PYX_ERR(0, 1359, __pyx_L1_error)
          }
          __pyx_t_1 = __pyx_v_ff;
          __pyx_t_16 = __pyx_v_rr;
          __pyx_t_17 = __pyx_v_ll;
          __pyx_t_15 = -1;
          if (__pyx_t_1 < 0) {
            __pyx_t_1 += __pyx_v_hc2ss.shape[0];
            if (unlikely(__pyx_t_1 < 0)) __pyx_t_15 = 0;
          } else if (unlikely(__pyx_t_1 >= __pyx_v_hc2ss.shape[0])) __pyx_t_15 = 0;
          if (__pyx_t_16 < 0) {
            __pyx_t_16 += __pyx_v_hc2ss.shape[1];
            if (unlikely(__pyx_t_16 < 0)) __pyx_t_15 = 1;
          } else if (unlikely(__pyx_t_16 >= __pyx_v_hc2ss.shape[1])) __pyx_t_15 = 1;
          if (__pyx_t_17 < 0) {
            __pyx_t_17 += __pyx_v_hc2ss.shape[2];
            if (unlikely(__pyx_t_17 < 0)) __pyx_t_15 = 2;
          } else if (unlikely(__pyx_t_17 >= __pyx_v_hc2ss.shape[2])) __pyx_t_15 = 2;
          if (unlikely(__pyx_t_15 != -1)) {
            __Pyx_RaiseBufferIndexError(__pyx_t_15);
            __PYX_ERR(0, 1359, __pyx_L1_error)
          }
          *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_hc2ss.data + __pyx_t_1 * __pyx_v_hc2ss.strides[0]) ) + __pyx_t_16 * __pyx_v_hc2ss.strides[1]) ) + __pyx_t_17 * __pyx_v_hc2ss.strides[2]) )) = __pyx_t_21;
+1360:                     num -= 1
          __pyx_v_num = (__pyx_v_num - 1.0);
+1361:                     ll += 1
          __pyx_v_ll = (__pyx_v_ll + 1);
        }
+1362:                 sum += num * cur
        __pyx_t_4 = PyFloat_FromDouble(__pyx_v_sum); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1362, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_3 = PyFloat_FromDouble(__pyx_v_num); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1362, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_5 = PyNumber_Multiply(__pyx_t_3, __pyx_v_cur); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1362, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1362, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_21 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_21 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 1362, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_v_sum = __pyx_t_21;
        __pyx_L7_continue:;
      }
 1363: 
+1364:             hc2bg[ff,rr] = sum
      if (unlikely(((PyObject *) __pyx_v_hc2bg.memview) == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "Cannot index None memoryview slice");
        __PYX_ERR(0, 1364, __pyx_L1_error)
      }
      __pyx_t_17 = __pyx_v_ff;
      __pyx_t_16 = __pyx_v_rr;
      __pyx_t_12 = -1;
      if (__pyx_t_17 < 0) {
        __pyx_t_17 += __pyx_v_hc2bg.shape[0];
        if (unlikely(__pyx_t_17 < 0)) __pyx_t_12 = 0;
      } else if (unlikely(__pyx_t_17 >= __pyx_v_hc2bg.shape[0])) __pyx_t_12 = 0;
      if (__pyx_t_16 < 0) {
        __pyx_t_16 += __pyx_v_hc2bg.shape[1];
        if (unlikely(__pyx_t_16 < 0)) __pyx_t_12 = 1;
      } else if (unlikely(__pyx_t_16 >= __pyx_v_hc2bg.shape[1])) __pyx_t_12 = 1;
      if (unlikely(__pyx_t_12 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_12);
        __PYX_ERR(0, 1364, __pyx_L1_error)
      }
      *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_hc2bg.data + __pyx_t_17 * __pyx_v_hc2bg.strides[0]) ) + __pyx_t_16 * __pyx_v_hc2bg.strides[1]) )) = __pyx_v_sum;
    }
  }
 1365: 
 1366: 
+1367: def loudest_hc_and_par_from_sorted(number, h2fdf, nreals, nloudest, mt, mr, rz, msort, qsort, zsort, normal_threshold=1e10):
/* Python wrapper */
static PyObject *__pyx_pw_8holodeck_7cyutils_17loudest_hc_and_par_from_sorted(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8holodeck_7cyutils_16loudest_hc_and_par_from_sorted[] = "\n    Calculates the characteristic strain from loud single sources and a background of all other sources.\n\n    Parameters\n    ------------------------\n    number : [M, Q, Z, F] NDarray\n        number in each bin\n    h2fdf : [M, Q, Z, F] NDarray\n        Strain amplitude squared x frequency / frequency bin width for each bin.\n    nreals\n        Number of realizations.\n    nloudest\n        Number of loudest sources to separate in each frequency bin.\n    mt : (M,) 1Darray of scalars\n        Total masses, M, of each bin center.\n    mr : (Q,) 1Darray of scalars\n        Mass ratios, q, of each bin center.\n    rz : (Z,) 1Darray of scalars\n        Redshifts, z, of each bin center.\n    msort : (M*Q*Z,) 1Darray\n        M indices of each bin, sorted from largest to smallest h2fdf.\n    qsort : (M*Q*Z,) 1Darray\n        q indices of each bin, sorted from largest to smallest h2fdf.\n    zsort : (M*Q*Z,) 1Darray\n        z indices of each bin, sorted from largest to smallest h2fdf.\n    normal_threshold : float\n        Threshold for approximating poisson sampling as normal.\n\n    Returns\n    --------------------------\n    hc2ss : (F, R, L) Ndarray of scalars\n        Char strain squared of the loudest single sources.\n    hc2bg : (F, R) Ndarray of scalars\n        Char strain squared of the background.\n    lspar : (3, F, R) NDarray of scalars\n        Average effective M, q, z parameters of the loudest L sources.\n    bgpar : (3, F, R) NDarray of scalars\n        Average effective M, q, z parameters of the background.\n    ssidx : (3, F, R, L) NDarray of ints\n        Indices of the loudest single sources.\n    ";
static PyMethodDef __pyx_mdef_8holodeck_7cyutils_17loudest_hc_and_par_from_sorted = {"loudest_hc_and_par_from_sorted", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8holodeck_7cyutils_17loudest_hc_and_par_from_sorted, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8holodeck_7cyutils_16loudest_hc_and_par_from_sorted};
static PyObject *__pyx_pw_8holodeck_7cyutils_17loudest_hc_and_par_from_sorted(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_number = 0;
  PyObject *__pyx_v_h2fdf = 0;
  PyObject *__pyx_v_nreals = 0;
  PyObject *__pyx_v_nloudest = 0;
  PyObject *__pyx_v_mt = 0;
  PyObject *__pyx_v_mr = 0;
  PyObject *__pyx_v_rz = 0;
  PyObject *__pyx_v_msort = 0;
  PyObject *__pyx_v_qsort = 0;
  PyObject *__pyx_v_zsort = 0;
  PyObject *__pyx_v_normal_threshold = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("loudest_hc_and_par_from_sorted (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_number,&__pyx_n_s_h2fdf,&__pyx_n_s_nreals,&__pyx_n_s_nloudest,&__pyx_n_s_mt,&__pyx_n_s_mr,&__pyx_n_s_rz,&__pyx_n_s_msort,&__pyx_n_s_qsort,&__pyx_n_s_zsort,&__pyx_n_s_normal_threshold,0};
    PyObject* values[11] = {0,0,0,0,0,0,0,0,0,0,0};
    values[10] = ((PyObject *)__pyx_float_1e10);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        CYTHON_FALLTHROUGH;
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        CYTHON_FALLTHROUGH;
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        CYTHON_FALLTHROUGH;
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_number)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_h2fdf)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted", 0, 10, 11, 1); __PYX_ERR(0, 1367, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_nreals)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted", 0, 10, 11, 2); __PYX_ERR(0, 1367, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_nloudest)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted", 0, 10, 11, 3); __PYX_ERR(0, 1367, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mt)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted", 0, 10, 11, 4); __PYX_ERR(0, 1367, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mr)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted", 0, 10, 11, 5); __PYX_ERR(0, 1367, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (likely((values[6] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_rz)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted", 0, 10, 11, 6); __PYX_ERR(0, 1367, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  7:
        if (likely((values[7] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_msort)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted", 0, 10, 11, 7); __PYX_ERR(0, 1367, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  8:
        if (likely((values[8] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_qsort)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted", 0, 10, 11, 8); __PYX_ERR(0, 1367, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  9:
        if (likely((values[9] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_zsort)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted", 0, 10, 11, 9); __PYX_ERR(0, 1367, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case 10:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_normal_threshold);
          if (value) { values[10] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "loudest_hc_and_par_from_sorted") < 0)) __PYX_ERR(0, 1367, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        CYTHON_FALLTHROUGH;
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_number = values[0];
    __pyx_v_h2fdf = values[1];
    __pyx_v_nreals = values[2];
    __pyx_v_nloudest = values[3];
    __pyx_v_mt = values[4];
    __pyx_v_mr = values[5];
    __pyx_v_rz = values[6];
    __pyx_v_msort = values[7];
    __pyx_v_qsort = values[8];
    __pyx_v_zsort = values[9];
    __pyx_v_normal_threshold = values[10];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted", 0, 10, 11, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1367, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("holodeck.cyutils.loudest_hc_and_par_from_sorted", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_8holodeck_7cyutils_16loudest_hc_and_par_from_sorted(__pyx_self, __pyx_v_number, __pyx_v_h2fdf, __pyx_v_nreals, __pyx_v_nloudest, __pyx_v_mt, __pyx_v_mr, __pyx_v_rz, __pyx_v_msort, __pyx_v_qsort, __pyx_v_zsort, __pyx_v_normal_threshold);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8holodeck_7cyutils_16loudest_hc_and_par_from_sorted(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_number, PyObject *__pyx_v_h2fdf, PyObject *__pyx_v_nreals, PyObject *__pyx_v_nloudest, PyObject *__pyx_v_mt, PyObject *__pyx_v_mr, PyObject *__pyx_v_rz, PyObject *__pyx_v_msort, PyObject *__pyx_v_qsort, PyObject *__pyx_v_zsort, PyObject *__pyx_v_normal_threshold) {
  __Pyx_memviewslice __pyx_v_shape = { 0, 0, { 0 }, { 0 }, { 0 } };
  PyObject *__pyx_v_F = NULL;
  PyObject *__pyx_v_R = NULL;
  PyObject *__pyx_v_L = NULL;
  PyArrayObject *__pyx_v_hc2ss = 0;
  PyArrayObject *__pyx_v_hc2bg = 0;
  PyArrayObject *__pyx_v_lspar = 0;
  PyArrayObject *__pyx_v_bgpar = 0;
  PyArrayObject *__pyx_v_ssidx = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_bgpar;
  __Pyx_Buffer __pyx_pybuffer_bgpar;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_hc2bg;
  __Pyx_Buffer __pyx_pybuffer_hc2bg;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_hc2ss;
  __Pyx_Buffer __pyx_pybuffer_hc2ss;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_lspar;
  __Pyx_Buffer __pyx_pybuffer_lspar;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ssidx;
  __Pyx_Buffer __pyx_pybuffer_ssidx;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("loudest_hc_and_par_from_sorted", 0);
  __pyx_pybuffer_hc2ss.pybuffer.buf = NULL;
  __pyx_pybuffer_hc2ss.refcount = 0;
  __pyx_pybuffernd_hc2ss.data = NULL;
  __pyx_pybuffernd_hc2ss.rcbuffer = &__pyx_pybuffer_hc2ss;
  __pyx_pybuffer_hc2bg.pybuffer.buf = NULL;
  __pyx_pybuffer_hc2bg.refcount = 0;
  __pyx_pybuffernd_hc2bg.data = NULL;
  __pyx_pybuffernd_hc2bg.rcbuffer = &__pyx_pybuffer_hc2bg;
  __pyx_pybuffer_lspar.pybuffer.buf = NULL;
  __pyx_pybuffer_lspar.refcount = 0;
  __pyx_pybuffernd_lspar.data = NULL;
  __pyx_pybuffernd_lspar.rcbuffer = &__pyx_pybuffer_lspar;
  __pyx_pybuffer_bgpar.pybuffer.buf = NULL;
  __pyx_pybuffer_bgpar.refcount = 0;
  __pyx_pybuffernd_bgpar.data = NULL;
  __pyx_pybuffernd_bgpar.rcbuffer = &__pyx_pybuffer_bgpar;
  __pyx_pybuffer_ssidx.pybuffer.buf = NULL;
  __pyx_pybuffer_ssidx.refcount = 0;
  __pyx_pybuffernd_ssidx.data = NULL;
  __pyx_pybuffernd_ssidx.rcbuffer = &__pyx_pybuffer_ssidx;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_13, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_14, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_18, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_19, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_20, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_21, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_22, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_23, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_24, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_25, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_26, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_27, 1);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bgpar.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2bg.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2ss.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lspar.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ssidx.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("holodeck.cyutils.loudest_hc_and_par_from_sorted", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bgpar.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2bg.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2ss.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lspar.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ssidx.rcbuffer->pybuffer);
  __pyx_L2:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_shape, 1);
  __Pyx_XDECREF(__pyx_v_F);
  __Pyx_XDECREF(__pyx_v_R);
  __Pyx_XDECREF(__pyx_v_L);
  __Pyx_XDECREF((PyObject *)__pyx_v_hc2ss);
  __Pyx_XDECREF((PyObject *)__pyx_v_hc2bg);
  __Pyx_XDECREF((PyObject *)__pyx_v_lspar);
  __Pyx_XDECREF((PyObject *)__pyx_v_bgpar);
  __Pyx_XDECREF((PyObject *)__pyx_v_ssidx);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__39 = PyTuple_Pack(20, __pyx_n_s_number, __pyx_n_s_h2fdf, __pyx_n_s_nreals, __pyx_n_s_nloudest, __pyx_n_s_mt, __pyx_n_s_mr, __pyx_n_s_rz, __pyx_n_s_msort, __pyx_n_s_qsort, __pyx_n_s_zsort, __pyx_n_s_normal_threshold, __pyx_n_s_shape, __pyx_n_s_F, __pyx_n_s_R, __pyx_n_s_L, __pyx_n_s_hc2ss, __pyx_n_s_hc2bg, __pyx_n_s_lspar, __pyx_n_s_bgpar, __pyx_n_s_ssidx); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(0, 1367, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__39);
  __Pyx_GIVEREF(__pyx_tuple__39);
/* … */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_8holodeck_7cyutils_17loudest_hc_and_par_from_sorted, NULL, __pyx_n_s_holodeck_cyutils); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1367, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_loudest_hc_and_par_from_sorted, __pyx_t_3) < 0) __PYX_ERR(0, 1367, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_codeobj__40 = (PyObject*)__Pyx_PyCode_New(11, 0, 20, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__39, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_holodeck_cyutils_pyx, __pyx_n_s_loudest_hc_and_par_from_sorted, 1367, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__40)) __PYX_ERR(0, 1367, __pyx_L1_error)
 1368:     """
 1369:     Calculates the characteristic strain from loud single sources and a background of all other sources.
 1370: 
 1371:     Parameters
 1372:     ------------------------
 1373:     number : [M, Q, Z, F] NDarray
 1374:         number in each bin
 1375:     h2fdf : [M, Q, Z, F] NDarray
 1376:         Strain amplitude squared x frequency / frequency bin width for each bin.
 1377:     nreals
 1378:         Number of realizations.
 1379:     nloudest
 1380:         Number of loudest sources to separate in each frequency bin.
 1381:     mt : (M,) 1Darray of scalars
 1382:         Total masses, M, of each bin center.
 1383:     mr : (Q,) 1Darray of scalars
 1384:         Mass ratios, q, of each bin center.
 1385:     rz : (Z,) 1Darray of scalars
 1386:         Redshifts, z, of each bin center.
 1387:     msort : (M*Q*Z,) 1Darray
 1388:         M indices of each bin, sorted from largest to smallest h2fdf.
 1389:     qsort : (M*Q*Z,) 1Darray
 1390:         q indices of each bin, sorted from largest to smallest h2fdf.
 1391:     zsort : (M*Q*Z,) 1Darray
 1392:         z indices of each bin, sorted from largest to smallest h2fdf.
 1393:     normal_threshold : float
 1394:         Threshold for approximating poisson sampling as normal.
 1395: 
 1396:     Returns
 1397:     --------------------------
 1398:     hc2ss : (F, R, L) Ndarray of scalars
 1399:         Char strain squared of the loudest single sources.
 1400:     hc2bg : (F, R) Ndarray of scalars
 1401:         Char strain squared of the background.
 1402:     lspar : (3, F, R) NDarray of scalars
 1403:         Average effective M, q, z parameters of the loudest L sources.
 1404:     bgpar : (3, F, R) NDarray of scalars
 1405:         Average effective M, q, z parameters of the background.
 1406:     ssidx : (3, F, R, L) NDarray of ints
 1407:         Indices of the loudest single sources.
 1408:     """
 1409: 
+1410:     cdef long[:] shape = np.array(number.shape)
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1410, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1410, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_number, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1410, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1410, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 1410, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_shape = __pyx_t_5;
  __pyx_t_5.memview = NULL;
  __pyx_t_5.data = NULL;
+1411:     F = shape[3]
  __pyx_t_6 = 3;
  __pyx_t_7 = -1;
  if (__pyx_t_6 < 0) {
    __pyx_t_6 += __pyx_v_shape.shape[0];
    if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
  } else if (unlikely(__pyx_t_6 >= __pyx_v_shape.shape[0])) __pyx_t_7 = 0;
  if (unlikely(__pyx_t_7 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_7);
    __PYX_ERR(0, 1411, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyInt_From_long((*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_6 * __pyx_v_shape.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1411, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_F = __pyx_t_1;
  __pyx_t_1 = 0;
+1412:     R = nreals
  __Pyx_INCREF(__pyx_v_nreals);
  __pyx_v_R = __pyx_v_nreals;
+1413:     L = nloudest
  __Pyx_INCREF(__pyx_v_nloudest);
  __pyx_v_L = __pyx_v_nloudest;
+1414:     cdef np.ndarray[np.double_t, ndim=3] hc2ss = np.zeros((F,R,L))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1414, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1414, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1414, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_R);
  __Pyx_INCREF(__pyx_v_L);
  __Pyx_GIVEREF(__pyx_v_L);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_L);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1414, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1414, __pyx_L1_error)
  __pyx_t_8 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_hc2ss.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_hc2ss = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 1414, __pyx_L1_error)
    } else {__pyx_pybuffernd_hc2ss.diminfo[0].strides = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_hc2ss.diminfo[0].shape = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_hc2ss.diminfo[1].strides = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_hc2ss.diminfo[1].shape = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_hc2ss.diminfo[2].strides = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_hc2ss.diminfo[2].shape = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_8 = 0;
  __pyx_v_hc2ss = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
+1415:     cdef np.ndarray[np.double_t, ndim=2] hc2bg = np.zeros((F,R))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1415, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1415, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1415, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_R);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1415, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1415, __pyx_L1_error)
  __pyx_t_9 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_hc2bg.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_hc2bg = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 1415, __pyx_L1_error)
    } else {__pyx_pybuffernd_hc2bg.diminfo[0].strides = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_hc2bg.diminfo[0].shape = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_hc2bg.diminfo[1].strides = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_hc2bg.diminfo[1].shape = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_9 = 0;
  __pyx_v_hc2bg = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
+1416:     cdef np.ndarray[np.double_t, ndim=3] lspar = np.zeros((3,F,R))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_int_3);
  __Pyx_GIVEREF(__pyx_int_3);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_3);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_R);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1416, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1416, __pyx_L1_error)
  __pyx_t_10 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_lspar.rcbuffer->pybuffer, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_lspar = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_lspar.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 1416, __pyx_L1_error)
    } else {__pyx_pybuffernd_lspar.diminfo[0].strides = __pyx_pybuffernd_lspar.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_lspar.diminfo[0].shape = __pyx_pybuffernd_lspar.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_lspar.diminfo[1].strides = __pyx_pybuffernd_lspar.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_lspar.diminfo[1].shape = __pyx_pybuffernd_lspar.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_lspar.diminfo[2].strides = __pyx_pybuffernd_lspar.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_lspar.diminfo[2].shape = __pyx_pybuffernd_lspar.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_10 = 0;
  __pyx_v_lspar = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
+1417:     cdef np.ndarray[np.double_t, ndim=3] bgpar = np.zeros((3,F,R))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1417, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1417, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1417, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_int_3);
  __Pyx_GIVEREF(__pyx_int_3);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_3);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_R);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1417, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1417, __pyx_L1_error)
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_bgpar.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_bgpar = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 1417, __pyx_L1_error)
    } else {__pyx_pybuffernd_bgpar.diminfo[0].strides = __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_bgpar.diminfo[0].shape = __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_bgpar.diminfo[1].strides = __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_bgpar.diminfo[1].shape = __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_bgpar.diminfo[2].strides = __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_bgpar.diminfo[2].shape = __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_11 = 0;
  __pyx_v_bgpar = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
+1418:     cdef np.ndarray[np.longlong_t, ndim=4] ssidx = np.zeros((3,F,R,L), dtype=int)
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1418, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1418, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1418, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_int_3);
  __Pyx_GIVEREF(__pyx_int_3);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_int_3);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_R);
  __Pyx_INCREF(__pyx_v_L);
  __Pyx_GIVEREF(__pyx_v_L);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_L);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1418, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1418, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, ((PyObject *)(&PyInt_Type))) < 0) __PYX_ERR(0, 1418, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1418, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1418, __pyx_L1_error)
  __pyx_t_12 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ssidx.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_longlong_t, PyBUF_FORMAT| PyBUF_STRIDES, 4, 0, __pyx_stack) == -1)) {
      __pyx_v_ssidx = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 1418, __pyx_L1_error)
    } else {__pyx_pybuffernd_ssidx.diminfo[0].strides = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ssidx.diminfo[0].shape = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_ssidx.diminfo[1].strides = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_ssidx.diminfo[1].shape = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_ssidx.diminfo[2].strides = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_ssidx.diminfo[2].shape = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.shape[2]; __pyx_pybuffernd_ssidx.diminfo[3].strides = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.strides[3]; __pyx_pybuffernd_ssidx.diminfo[3].shape = __pyx_pybuffernd_ssidx.rcbuffer->pybuffer.shape[3];
    }
  }
  __pyx_t_12 = 0;
  __pyx_v_ssidx = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;
+1419:     _loudest_hc_and_par_from_sorted(shape, h2fdf, number, nreals, nloudest, normal_threshold,
  __pyx_t_13 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_double(__pyx_v_h2fdf, PyBUF_WRITABLE); if (unlikely(!__pyx_t_13.memview)) __PYX_ERR(0, 1419, __pyx_L1_error)
  __pyx_t_14 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_double(__pyx_v_number, PyBUF_WRITABLE); if (unlikely(!__pyx_t_14.memview)) __PYX_ERR(0, 1419, __pyx_L1_error)
  __pyx_t_15 = __Pyx_PyInt_As_long(__pyx_v_nreals); if (unlikely((__pyx_t_15 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1419, __pyx_L1_error)
  __pyx_t_16 = __Pyx_PyInt_As_long(__pyx_v_nloudest); if (unlikely((__pyx_t_16 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1419, __pyx_L1_error)
  __pyx_t_17 = __Pyx_PyInt_As_long(__pyx_v_normal_threshold); if (unlikely((__pyx_t_17 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1419, __pyx_L1_error)
/* … */
  __pyx_f_8holodeck_7cyutils__loudest_hc_and_par_from_sorted(__pyx_v_shape, __pyx_t_13, __pyx_t_14, __pyx_t_15, __pyx_t_16, __pyx_t_17, __pyx_t_18, __pyx_t_19, __pyx_t_20, __pyx_t_5, __pyx_t_21, __pyx_t_22, __pyx_t_23, __pyx_t_24, __pyx_t_25, __pyx_t_26, __pyx_t_27);
  __PYX_XDEC_MEMVIEW(&__pyx_t_13, 1);
  __pyx_t_13.memview = NULL;
  __pyx_t_13.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_14, 1);
  __pyx_t_14.memview = NULL;
  __pyx_t_14.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_18, 1);
  __pyx_t_18.memview = NULL;
  __pyx_t_18.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_19, 1);
  __pyx_t_19.memview = NULL;
  __pyx_t_19.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_20, 1);
  __pyx_t_20.memview = NULL;
  __pyx_t_20.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
  __pyx_t_5.memview = NULL;
  __pyx_t_5.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_21, 1);
  __pyx_t_21.memview = NULL;
  __pyx_t_21.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_22, 1);
  __pyx_t_22.memview = NULL;
  __pyx_t_22.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_23, 1);
  __pyx_t_23.memview = NULL;
  __pyx_t_23.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_24, 1);
  __pyx_t_24.memview = NULL;
  __pyx_t_24.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_25, 1);
  __pyx_t_25.memview = NULL;
  __pyx_t_25.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_26, 1);
  __pyx_t_26.memview = NULL;
  __pyx_t_26.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_27, 1);
  __pyx_t_27.memview = NULL;
  __pyx_t_27.data = NULL;
+1420:                             mt, mr, rz, msort, qsort, zsort,
  __pyx_t_18 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_mt, PyBUF_WRITABLE); if (unlikely(!__pyx_t_18.memview)) __PYX_ERR(0, 1420, __pyx_L1_error)
  __pyx_t_19 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_mr, PyBUF_WRITABLE); if (unlikely(!__pyx_t_19.memview)) __PYX_ERR(0, 1420, __pyx_L1_error)
  __pyx_t_20 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_rz, PyBUF_WRITABLE); if (unlikely(!__pyx_t_20.memview)) __PYX_ERR(0, 1420, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(__pyx_v_msort, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 1420, __pyx_L1_error)
  __pyx_t_21 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(__pyx_v_qsort, PyBUF_WRITABLE); if (unlikely(!__pyx_t_21.memview)) __PYX_ERR(0, 1420, __pyx_L1_error)
  __pyx_t_22 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(__pyx_v_zsort, PyBUF_WRITABLE); if (unlikely(!__pyx_t_22.memview)) __PYX_ERR(0, 1420, __pyx_L1_error)
+1421:                             hc2ss, hc2bg, lspar, bgpar, ssidx)
  __pyx_t_23 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_double(((PyObject *)__pyx_v_hc2ss), PyBUF_WRITABLE); if (unlikely(!__pyx_t_23.memview)) __PYX_ERR(0, 1421, __pyx_L1_error)
  __pyx_t_24 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(((PyObject *)__pyx_v_hc2bg), PyBUF_WRITABLE); if (unlikely(!__pyx_t_24.memview)) __PYX_ERR(0, 1421, __pyx_L1_error)
  __pyx_t_25 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_double(((PyObject *)__pyx_v_lspar), PyBUF_WRITABLE); if (unlikely(!__pyx_t_25.memview)) __PYX_ERR(0, 1421, __pyx_L1_error)
  __pyx_t_26 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_double(((PyObject *)__pyx_v_bgpar), PyBUF_WRITABLE); if (unlikely(!__pyx_t_26.memview)) __PYX_ERR(0, 1421, __pyx_L1_error)
  __pyx_t_27 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_long(((PyObject *)__pyx_v_ssidx), PyBUF_WRITABLE); if (unlikely(!__pyx_t_27.memview)) __PYX_ERR(0, 1421, __pyx_L1_error)
+1422:     return hc2ss, hc2bg, lspar, bgpar, ssidx
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = PyTuple_New(5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1422, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(((PyObject *)__pyx_v_hc2ss));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_hc2ss));
  PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_v_hc2ss));
  __Pyx_INCREF(((PyObject *)__pyx_v_hc2bg));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_hc2bg));
  PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_hc2bg));
  __Pyx_INCREF(((PyObject *)__pyx_v_lspar));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_lspar));
  PyTuple_SET_ITEM(__pyx_t_4, 2, ((PyObject *)__pyx_v_lspar));
  __Pyx_INCREF(((PyObject *)__pyx_v_bgpar));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_bgpar));
  PyTuple_SET_ITEM(__pyx_t_4, 3, ((PyObject *)__pyx_v_bgpar));
  __Pyx_INCREF(((PyObject *)__pyx_v_ssidx));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_ssidx));
  PyTuple_SET_ITEM(__pyx_t_4, 4, ((PyObject *)__pyx_v_ssidx));
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;
 1423: 
 1424: 
 1425: @cython.boundscheck(False)
 1426: @cython.wraparound(False)
 1427: @cython.nonecheck(False)
 1428: @cython.cdivision(True)
+1429: cdef void _loudest_hc_and_par_from_sorted(long[:] shape, double[:,:,:,:] h2fdf, double[:,:,:,:] number,
static void __pyx_f_8holodeck_7cyutils__loudest_hc_and_par_from_sorted(__Pyx_memviewslice __pyx_v_shape, __Pyx_memviewslice __pyx_v_h2fdf, __Pyx_memviewslice __pyx_v_number, long __pyx_v_nreals, long __pyx_v_nloudest, long __pyx_v_thresh, __Pyx_memviewslice __pyx_v_mt, __Pyx_memviewslice __pyx_v_mr, __Pyx_memviewslice __pyx_v_rz, __Pyx_memviewslice __pyx_v_msort, __Pyx_memviewslice __pyx_v_qsort, __Pyx_memviewslice __pyx_v_zsort, __Pyx_memviewslice __pyx_v_hc2ss, __Pyx_memviewslice __pyx_v_hc2bg, __Pyx_memviewslice __pyx_v_lspar, __Pyx_memviewslice __pyx_v_bgpar, __Pyx_memviewslice __pyx_v_ssidx) {
  int __pyx_v_M;
  int __pyx_v_Q;
  int __pyx_v_Z;
  int __pyx_v_F;
  int __pyx_v_L;
  int __pyx_v_R;
  int __pyx_v_mm;
  int __pyx_v_qq;
  int __pyx_v_zz;
  int __pyx_v_ff;
  int __pyx_v_rr;
  int __pyx_v_ll;
  double __pyx_v_num;
  double __pyx_v_cur;
  double __pyx_v_sum_bg;
  double __pyx_v_sum_ls;
  double __pyx_v_m_bg;
  double __pyx_v_q_bg;
  double __pyx_v_z_bg;
  double __pyx_v_m_ls;
  double __pyx_v_q_ls;
  double __pyx_v_z_ls;
  CYTHON_UNUSED PyArrayObject *__pyx_v_maxes = 0;
  bitgen_t *__pyx_v_rng;
  char const *__pyx_v_capsule_name;
  PyObject *__pyx_v_capsule = NULL;
  int __pyx_v_bb;
  double __pyx_v_std;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_maxes;
  __Pyx_Buffer __pyx_pybuffer_maxes;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_loudest_hc_and_par_from_sorted", 0);
  __pyx_pybuffer_maxes.pybuffer.buf = NULL;
  __pyx_pybuffer_maxes.refcount = 0;
  __pyx_pybuffernd_maxes.data = NULL;
  __pyx_pybuffernd_maxes.rcbuffer = &__pyx_pybuffer_maxes;
/* … */
  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_maxes.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_WriteUnraisable("holodeck.cyutils._loudest_hc_and_par_from_sorted", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_maxes.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_maxes);
  __Pyx_XDECREF(__pyx_v_capsule);
  __Pyx_RefNannyFinishContext();
}
 1430:             long nreals, long nloudest, long thresh,
 1431:             double[:] mt, double[:] mr, double[:] rz,
 1432:             long[:] msort, long[:] qsort, long[:] zsort,
 1433:             double[:,:,:] hc2ss, double[:,:] hc2bg, double[:,:,:] lspar, double[:,:,:] bgpar, long[:,:,:,:] ssidx):
 1434:     """
 1435:     Calculates the characteristic strain from loud single sources and a background of all other sources.
 1436: 
 1437:     Parameters
 1438:     ----------
 1439:     shape : long[:] array
 1440:         Shape of number, [M, Q, Z, F].
 1441:     number : double[:,:,:,:] array
 1442:         Number per bin.
 1443:     h2fdf : double[:,:,:,:] array
 1444:         Strain amplitude squared * f/Delta f for a single source in each bin.
 1445:     nreals : int
 1446:         Number of realizations.
 1447:     nloudest : int
 1448:         Number of loudest sources at each source.
 1449:     mt : (M,) 1Darray of scalars
 1450:         Total masses of each bin center.
 1451:     mr : (Q,) 1Darray of scalars
 1452:         Mass ratios of each bin center.
 1453:     rz : (Z,) 1Darray of scalars
 1454:         Redshifts of each bin center.
 1455:     msort : (M*Q*Z,) 1Darray
 1456:         M indices of each bin, sorted from largest to smallest h2fdf.
 1457:     qsort : (M*Q*Z,) 1Darray
 1458:         q indices of each bin, sorted from largest to smallest h2fdf.
 1459:     zsort : (M*Q*Z,) 1Darray
 1460:         z indices of each bin, sorted from largest to smallest h2fdf.
 1461:     hc2ss : double[:,:,:] array
 1462:         (Memory address of) single source characteristic strain squared array.
 1463:     hc2bg : double[:,:] array
 1464:         (Memory address of) background characteristic strain squared array.
 1465:     lspar : (3, F, R) NDarray of scalars
 1466:         Average effective M, q, z parameters of the loudest L sources.
 1467:     bgpar : (3, F, R) NDarray of scalars
 1468:         Average effective M, q, z parameters of the background.
 1469:     ssidx : (3, F, R, L) NDarray of ints
 1470:         Indices of the loudest sources.
 1471: 
 1472:     Returns
 1473:     -------
 1474:     void
 1475:     updated via memory address: hc2ss, hc2bg, lspar, bgpar, ssidx
 1476:     """
 1477: 
+1478:     cdef int M = shape[0]
  __pyx_t_1 = 0;
  __pyx_v_M = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+1479:     cdef int Q = shape[1]
  __pyx_t_1 = 1;
  __pyx_v_Q = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+1480:     cdef int Z = shape[2]
  __pyx_t_1 = 2;
  __pyx_v_Z = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+1481:     cdef int F = shape[3]
  __pyx_t_1 = 3;
  __pyx_v_F = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+1482:     cdef int L = nloudest
  __pyx_v_L = __pyx_v_nloudest;
+1483:     cdef int R = nreals
  __pyx_v_R = __pyx_v_nreals;
 1484: 
 1485:     cdef int mm, qq, zz, ff, rr, ll
 1486:     cdef double num, cur, sum_bg, sum_ls, m_bg, q_bg, z_bg, m_ls, q_ls, z_ls
+1487:     cdef np.ndarray[np.double_t, ndim=3] maxes = np.zeros((F,R,L))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1487, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_zeros); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1487, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_F); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1487, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_R); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1487, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_L); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1487, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1487, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_6);
  __pyx_t_3 = 0;
  __pyx_t_5 = 0;
  __pyx_t_6 = 0;
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_2 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_6, __pyx_t_7) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_7);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1487, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1487, __pyx_L1_error)
  __pyx_t_8 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_maxes.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_maxes = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_maxes.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 1487, __pyx_L1_error)
    } else {__pyx_pybuffernd_maxes.diminfo[0].strides = __pyx_pybuffernd_maxes.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_maxes.diminfo[0].shape = __pyx_pybuffernd_maxes.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_maxes.diminfo[1].strides = __pyx_pybuffernd_maxes.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_maxes.diminfo[1].shape = __pyx_pybuffernd_maxes.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_maxes.diminfo[2].strides = __pyx_pybuffernd_maxes.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_maxes.diminfo[2].shape = __pyx_pybuffernd_maxes.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_8 = 0;
  __pyx_v_maxes = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;
 1488: 
 1489:     # Setup random number generator from numpy library
 1490:     cdef bitgen_t *rng
+1491:     cdef const char *capsule_name = "BitGenerator"
  __pyx_v_capsule_name = ((char const *)"BitGenerator");
+1492:     capsule = PCG64().capsule
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_PCG64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_7 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_7)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
    }
  }
  __pyx_t_2 = (__pyx_t_7) ? __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_7) : __Pyx_PyObject_CallNoArg(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_capsule); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1492, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_capsule = __pyx_t_4;
  __pyx_t_4 = 0;
 1493:     # Cast the pointer
+1494:     rng = <bitgen_t *> PyCapsule_GetPointer(capsule, capsule_name)
  __pyx_t_9 = PyCapsule_GetPointer(__pyx_v_capsule, __pyx_v_capsule_name); if (unlikely(__pyx_t_9 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 1494, __pyx_L1_error)
  __pyx_v_rng = ((bitgen_t *)__pyx_t_9);
+1495:     for rr in range(R):
  __pyx_t_10 = __pyx_v_R;
  __pyx_t_11 = __pyx_t_10;
  for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {
    __pyx_v_rr = __pyx_t_12;
+1496:         for ff in range(F):
    __pyx_t_13 = __pyx_v_F;
    __pyx_t_14 = __pyx_t_13;
    for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) {
      __pyx_v_ff = __pyx_t_15;
+1497:             ll = 0 # track which index in the loudest list you're currently storing
      __pyx_v_ll = 0;
 1498:                      # start at 0 for the loudest of all.
 1499:             # reset strain sums
+1500:             sum_bg = 0 # sum of bg h2fdf, for parameter averaging and gwb
      __pyx_v_sum_bg = 0.0;
+1501:             sum_ls = 0 # sum of ls h2fdf, for parameter averaging
      __pyx_v_sum_ls = 0.0;
 1502:             # reset parameter averaging sums
+1503:             m_ls = 0
      __pyx_v_m_ls = 0.0;
+1504:             q_ls = 0
      __pyx_v_q_ls = 0.0;
+1505:             z_ls = 0
      __pyx_v_z_ls = 0.0;
+1506:             m_bg = 0
      __pyx_v_m_bg = 0.0;
+1507:             q_bg = 0
      __pyx_v_q_bg = 0.0;
+1508:             z_bg = 0
      __pyx_v_z_bg = 0.0;
+1509:             for bb in range(M*Q*Z): #iterate through bins, loudest to quietest
      __pyx_t_16 = ((__pyx_v_M * __pyx_v_Q) * __pyx_v_Z);
      __pyx_t_17 = __pyx_t_16;
      for (__pyx_t_18 = 0; __pyx_t_18 < __pyx_t_17; __pyx_t_18+=1) {
        __pyx_v_bb = __pyx_t_18;
+1510:                 mm = msort[bb]
        __pyx_t_1 = __pyx_v_bb;
        __pyx_v_mm = (*((long *) ( /* dim=0 */ (__pyx_v_msort.data + __pyx_t_1 * __pyx_v_msort.strides[0]) )));
+1511:                 qq = qsort[bb]
        __pyx_t_1 = __pyx_v_bb;
        __pyx_v_qq = (*((long *) ( /* dim=0 */ (__pyx_v_qsort.data + __pyx_t_1 * __pyx_v_qsort.strides[0]) )));
+1512:                 zz = zsort[bb]
        __pyx_t_1 = __pyx_v_bb;
        __pyx_v_zz = (*((long *) ( /* dim=0 */ (__pyx_v_zsort.data + __pyx_t_1 * __pyx_v_zsort.strides[0]) )));
+1513:                 num = number[mm,qq,zz,ff]
        __pyx_t_1 = __pyx_v_mm;
        __pyx_t_19 = __pyx_v_qq;
        __pyx_t_20 = __pyx_v_zz;
        __pyx_t_21 = __pyx_v_ff;
        __pyx_v_num = (*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_number.data + __pyx_t_1 * __pyx_v_number.strides[0]) ) + __pyx_t_19 * __pyx_v_number.strides[1]) ) + __pyx_t_20 * __pyx_v_number.strides[2]) ) + __pyx_t_21 * __pyx_v_number.strides[3]) )));
+1514:                 if (num>thresh): # Gaussian sample
        __pyx_t_22 = ((__pyx_v_num > __pyx_v_thresh) != 0);
        if (__pyx_t_22) {
/* … */
          goto __pyx_L9;
        }
+1515:                     std = sqrt(num)
          __pyx_v_std = sqrt(__pyx_v_num);
+1516:                     num = <double>random_normal(rng, num, std)
          __pyx_v_num = ((double)random_normal(__pyx_v_rng, __pyx_v_num, __pyx_v_std));
 1517:                 else:            # Poisson sample
+1518:                     num = <double>random_poisson(rng, num)
        /*else*/ {
          __pyx_v_num = ((double)random_poisson(__pyx_v_rng, __pyx_v_num));
        }
        __pyx_L9:;
+1519:                 if(num < 1):
        __pyx_t_22 = ((__pyx_v_num < 1.0) != 0);
        if (__pyx_t_22) {
/* … */
        }
+1520:                     continue
          goto __pyx_L7_continue;
+1521:                 cur = h2fdf[mm,qq,zz,ff] # h^2 * f/df of current bin
        __pyx_t_21 = __pyx_v_mm;
        __pyx_t_20 = __pyx_v_qq;
        __pyx_t_19 = __pyx_v_zz;
        __pyx_t_1 = __pyx_v_ff;
        __pyx_v_cur = (*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_h2fdf.data + __pyx_t_21 * __pyx_v_h2fdf.strides[0]) ) + __pyx_t_20 * __pyx_v_h2fdf.strides[1]) ) + __pyx_t_19 * __pyx_v_h2fdf.strides[2]) ) + __pyx_t_1 * __pyx_v_h2fdf.strides[3]) )));
+1522:                 if (num<1):
        __pyx_t_22 = ((__pyx_v_num < 1.0) != 0);
        if (__pyx_t_22) {
/* … */
        }
+1523:                     continue # to next loudest bin
          goto __pyx_L7_continue;
+1524:                 while (ll < L) and (num > 0):
        while (1) {
          __pyx_t_23 = ((__pyx_v_ll < __pyx_v_L) != 0);
          if (__pyx_t_23) {
          } else {
            __pyx_t_22 = __pyx_t_23;
            goto __pyx_L14_bool_binop_done;
          }
          __pyx_t_23 = ((__pyx_v_num > 0.0) != 0);
          __pyx_t_22 = __pyx_t_23;
          __pyx_L14_bool_binop_done:;
          if (!__pyx_t_22) break;
 1525:                     # store ll loudest source strain
+1526:                     hc2ss[ff,rr,ll] = cur
          __pyx_t_1 = __pyx_v_ff;
          __pyx_t_19 = __pyx_v_rr;
          __pyx_t_20 = __pyx_v_ll;
          *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_hc2ss.data + __pyx_t_1 * __pyx_v_hc2ss.strides[0]) ) + __pyx_t_19 * __pyx_v_hc2ss.strides[1]) ) + __pyx_t_20 * __pyx_v_hc2ss.strides[2]) )) = __pyx_v_cur;
 1527: 
 1528:                     # store indices of ll loudest source
+1529:                     ssidx[0,ff,rr,ll] = mm
          __pyx_t_20 = 0;
          __pyx_t_19 = __pyx_v_ff;
          __pyx_t_1 = __pyx_v_rr;
          __pyx_t_21 = __pyx_v_ll;
          *((long *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_ssidx.data + __pyx_t_20 * __pyx_v_ssidx.strides[0]) ) + __pyx_t_19 * __pyx_v_ssidx.strides[1]) ) + __pyx_t_1 * __pyx_v_ssidx.strides[2]) ) + __pyx_t_21 * __pyx_v_ssidx.strides[3]) )) = __pyx_v_mm;
+1530:                     ssidx[1,ff,rr,ll] = qq
          __pyx_t_21 = 1;
          __pyx_t_1 = __pyx_v_ff;
          __pyx_t_19 = __pyx_v_rr;
          __pyx_t_20 = __pyx_v_ll;
          *((long *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_ssidx.data + __pyx_t_21 * __pyx_v_ssidx.strides[0]) ) + __pyx_t_1 * __pyx_v_ssidx.strides[1]) ) + __pyx_t_19 * __pyx_v_ssidx.strides[2]) ) + __pyx_t_20 * __pyx_v_ssidx.strides[3]) )) = __pyx_v_qq;
+1531:                     ssidx[2,ff,rr,ll] = zz
          __pyx_t_20 = 2;
          __pyx_t_19 = __pyx_v_ff;
          __pyx_t_1 = __pyx_v_rr;
          __pyx_t_21 = __pyx_v_ll;
          *((long *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_ssidx.data + __pyx_t_20 * __pyx_v_ssidx.strides[0]) ) + __pyx_t_19 * __pyx_v_ssidx.strides[1]) ) + __pyx_t_1 * __pyx_v_ssidx.strides[2]) ) + __pyx_t_21 * __pyx_v_ssidx.strides[3]) )) = __pyx_v_zz;
 1532: 
 1533: 
+1534:                     sum_ls += cur # tot ls h2fdf
          __pyx_v_sum_ls = (__pyx_v_sum_ls + __pyx_v_cur);
 1535:                     # add to average parameters of loudest sources
+1536:                     m_ls += cur * mt[mm] # tot weighted ls mass
          __pyx_t_21 = __pyx_v_mm;
          __pyx_v_m_ls = (__pyx_v_m_ls + (__pyx_v_cur * (*((double *) ( /* dim=0 */ (__pyx_v_mt.data + __pyx_t_21 * __pyx_v_mt.strides[0]) )))));
+1537:                     q_ls += cur * mr[qq] # tot weighted ls ratio
          __pyx_t_21 = __pyx_v_qq;
          __pyx_v_q_ls = (__pyx_v_q_ls + (__pyx_v_cur * (*((double *) ( /* dim=0 */ (__pyx_v_mr.data + __pyx_t_21 * __pyx_v_mr.strides[0]) )))));
+1538:                     z_ls += cur * rz[zz] # tot weighted ls redshift
          __pyx_t_21 = __pyx_v_zz;
          __pyx_v_z_ls = (__pyx_v_z_ls + (__pyx_v_cur * (*((double *) ( /* dim=0 */ (__pyx_v_rz.data + __pyx_t_21 * __pyx_v_rz.strides[0]) )))));
 1539: 
 1540:                     # update number and ll index
+1541:                     num -= 1
          __pyx_v_num = (__pyx_v_num - 1.0);
+1542:                     ll += 1
          __pyx_v_ll = (__pyx_v_ll + 1);
        }
 1543: 
+1544:                 sum_bg += num * cur # tot bg h2fdf
        __pyx_v_sum_bg = (__pyx_v_sum_bg + (__pyx_v_num * __pyx_v_cur));
 1545:                 # add to average parameters of background sources
+1546:                 m_bg += num * cur * mt[mm] # tot weight bg mass
        __pyx_t_21 = __pyx_v_mm;
        __pyx_v_m_bg = (__pyx_v_m_bg + ((__pyx_v_num * __pyx_v_cur) * (*((double *) ( /* dim=0 */ (__pyx_v_mt.data + __pyx_t_21 * __pyx_v_mt.strides[0]) )))));
+1547:                 q_bg += num * cur * mr[qq] # tot weighted bg ratio
        __pyx_t_21 = __pyx_v_qq;
        __pyx_v_q_bg = (__pyx_v_q_bg + ((__pyx_v_num * __pyx_v_cur) * (*((double *) ( /* dim=0 */ (__pyx_v_mr.data + __pyx_t_21 * __pyx_v_mr.strides[0]) )))));
+1548:                 z_bg += num * cur * rz[zz] # tot weighted bg redshift
        __pyx_t_21 = __pyx_v_zz;
        __pyx_v_z_bg = (__pyx_v_z_bg + ((__pyx_v_num * __pyx_v_cur) * (*((double *) ( /* dim=0 */ (__pyx_v_rz.data + __pyx_t_21 * __pyx_v_rz.strides[0]) )))));
        __pyx_L7_continue:;
      }
 1549: 
+1550:             hc2bg[ff,rr] = sum_bg # background strain
      __pyx_t_21 = __pyx_v_ff;
      __pyx_t_1 = __pyx_v_rr;
      *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_hc2bg.data + __pyx_t_21 * __pyx_v_hc2bg.strides[0]) ) + __pyx_t_1 * __pyx_v_hc2bg.strides[1]) )) = __pyx_v_sum_bg;
 1551:             # background average parameters
+1552:             bgpar[0,ff,rr] = m_bg/sum_bg # bg avg mass
      __pyx_t_1 = 0;
      __pyx_t_21 = __pyx_v_ff;
      __pyx_t_19 = __pyx_v_rr;
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_bgpar.data + __pyx_t_1 * __pyx_v_bgpar.strides[0]) ) + __pyx_t_21 * __pyx_v_bgpar.strides[1]) ) + __pyx_t_19 * __pyx_v_bgpar.strides[2]) )) = (__pyx_v_m_bg / __pyx_v_sum_bg);
+1553:             bgpar[1,ff,rr] = q_bg/sum_bg # bg avg ratio
      __pyx_t_19 = 1;
      __pyx_t_21 = __pyx_v_ff;
      __pyx_t_1 = __pyx_v_rr;
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_bgpar.data + __pyx_t_19 * __pyx_v_bgpar.strides[0]) ) + __pyx_t_21 * __pyx_v_bgpar.strides[1]) ) + __pyx_t_1 * __pyx_v_bgpar.strides[2]) )) = (__pyx_v_q_bg / __pyx_v_sum_bg);
+1554:             bgpar[2,ff,rr] = z_bg/sum_bg # bg avg redshift
      __pyx_t_1 = 2;
      __pyx_t_21 = __pyx_v_ff;
      __pyx_t_19 = __pyx_v_rr;
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_bgpar.data + __pyx_t_1 * __pyx_v_bgpar.strides[0]) ) + __pyx_t_21 * __pyx_v_bgpar.strides[1]) ) + __pyx_t_19 * __pyx_v_bgpar.strides[2]) )) = (__pyx_v_z_bg / __pyx_v_sum_bg);
 1555:             # loudest source average parameters
+1556:             lspar[0,ff,rr] = m_ls/sum_ls # ls avg mass
      __pyx_t_19 = 0;
      __pyx_t_21 = __pyx_v_ff;
      __pyx_t_1 = __pyx_v_rr;
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_lspar.data + __pyx_t_19 * __pyx_v_lspar.strides[0]) ) + __pyx_t_21 * __pyx_v_lspar.strides[1]) ) + __pyx_t_1 * __pyx_v_lspar.strides[2]) )) = (__pyx_v_m_ls / __pyx_v_sum_ls);
+1557:             lspar[1,ff,rr] = q_ls/sum_ls # ls avg ratio
      __pyx_t_1 = 1;
      __pyx_t_21 = __pyx_v_ff;
      __pyx_t_19 = __pyx_v_rr;
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_lspar.data + __pyx_t_1 * __pyx_v_lspar.strides[0]) ) + __pyx_t_21 * __pyx_v_lspar.strides[1]) ) + __pyx_t_19 * __pyx_v_lspar.strides[2]) )) = (__pyx_v_q_ls / __pyx_v_sum_ls);
+1558:             lspar[2,ff,rr] = z_ls/sum_ls # ls avg redshift
      __pyx_t_19 = 2;
      __pyx_t_21 = __pyx_v_ff;
      __pyx_t_1 = __pyx_v_rr;
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_lspar.data + __pyx_t_19 * __pyx_v_lspar.strides[0]) ) + __pyx_t_21 * __pyx_v_lspar.strides[1]) ) + __pyx_t_1 * __pyx_v_lspar.strides[2]) )) = (__pyx_v_z_ls / __pyx_v_sum_ls);
    }
  }
 1559: 
 1560: 
+1561: def loudest_hc_and_par_from_sorted_redz(
/* Python wrapper */
static PyObject *__pyx_pw_8holodeck_7cyutils_19loudest_hc_and_par_from_sorted_redz(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8holodeck_7cyutils_18loudest_hc_and_par_from_sorted_redz[] = "\n    Calculates the characteristic strain and binary parameters from loud single sources and a\n    background of all other sources.\n\n    Parameters\n    ------------------------\n    number : [M, Q, Z, F] NDarray\n        number in each bin\n    h2fdf : [M, Q, Z, F] NDarray\n        Strain amplitude squared x frequency / frequency bin width for each bin.\n    nreals\n        Number of realizations.\n    nloudest\n        Number of loudest sources to separate in each frequency bin.\n    mt : (M,) 1Darray of scalars\n        Total masses, M, of each bin center.\n    mr : (Q,) 1Darray of scalars\n        Mass ratios, q, of each bin center.\n    rz : (Z,) 1Darray of scalars\n        Redshifts, z, of each bin center.\n    redz_final : (M,Q,Z,F) NDarray of scalars\n        Final redshifts of each bin.\n    dcom_final : (M,Q,Z,F) NDarray of scalars\n        Final comoving distances of each bin.\n    sepa : (M,Q,Z,F) NDarray of scalars\n        Final separations of each mass and frequency combination.\n    angs : (M,Q,Z,F)\n        Final angular separations of each bin.\n    msort : (M*Q*Z,) 1Darray\n        M indices of each bin, sorted from largest to smallest h2fdf.\n    qsort : (M*Q*Z,) 1Darray\n        q indices of each bin, sorted from largest to smallest h2fdf.\n    zsort : (M*Q*Z,) 1Darray\n        z indices of each bin, sorted from largest to smallest h2fdf.\n    normal_threshold : float\n        Threshold for approximating poisson sampling as normal.\n\n    Returns\n    --------------------------\n    hc2ss : (F, R, L) Ndarray of scalars\n        Char strain squared of the loudest single sources.\n    hc2bg : (F, R) Ndarray of scalars\n        Char strain squared of the background.\n    sspar : (4, F, R) NDarray of scalars\n        Effective M, q, z parameters of the loudest L sources.\n        mass, ratio, redshift, redshift_final\n    bgpar : (4, F, R) NDarray of scalars\n        Average effective M, q, z parameters of the background.\n        mass, ratio, r""edshift, redshift_final\n    ";
static PyMethodDef __pyx_mdef_8holodeck_7cyutils_19loudest_hc_and_par_from_sorted_redz = {"loudest_hc_and_par_from_sorted_redz", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8holodeck_7cyutils_19loudest_hc_and_par_from_sorted_redz, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8holodeck_7cyutils_18loudest_hc_and_par_from_sorted_redz};
static PyObject *__pyx_pw_8holodeck_7cyutils_19loudest_hc_and_par_from_sorted_redz(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_number = 0;
  PyObject *__pyx_v_h2fdf = 0;
  PyObject *__pyx_v_nreals = 0;
  PyObject *__pyx_v_nloudest = 0;
  PyObject *__pyx_v_mt = 0;
  PyObject *__pyx_v_mr = 0;
  PyObject *__pyx_v_rz = 0;
  PyObject *__pyx_v_redz_final = 0;
  PyObject *__pyx_v_dcom_final = 0;
  PyObject *__pyx_v_sepa = 0;
  PyObject *__pyx_v_angs = 0;
  PyObject *__pyx_v_msort = 0;
  PyObject *__pyx_v_qsort = 0;
  PyObject *__pyx_v_zsort = 0;
  PyObject *__pyx_v_normal_threshold = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("loudest_hc_and_par_from_sorted_redz (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_number,&__pyx_n_s_h2fdf,&__pyx_n_s_nreals,&__pyx_n_s_nloudest,&__pyx_n_s_mt,&__pyx_n_s_mr,&__pyx_n_s_rz,&__pyx_n_s_redz_final,&__pyx_n_s_dcom_final,&__pyx_n_s_sepa,&__pyx_n_s_angs,&__pyx_n_s_msort,&__pyx_n_s_qsort,&__pyx_n_s_zsort,&__pyx_n_s_normal_threshold,0};
    PyObject* values[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    values[14] = ((PyObject *)__pyx_float_1e10);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14);
        CYTHON_FALLTHROUGH;
        case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13);
        CYTHON_FALLTHROUGH;
        case 13: values[12] = PyTuple_GET_ITEM(__pyx_args, 12);
        CYTHON_FALLTHROUGH;
        case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11);
        CYTHON_FALLTHROUGH;
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        CYTHON_FALLTHROUGH;
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        CYTHON_FALLTHROUGH;
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        CYTHON_FALLTHROUGH;
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        CYTHON_FALLTHROUGH;
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        CYTHON_FALLTHROUGH;
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_number)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_h2fdf)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted_redz", 0, 14, 15, 1); __PYX_ERR(0, 1561, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_nreals)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted_redz", 0, 14, 15, 2); __PYX_ERR(0, 1561, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_nloudest)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted_redz", 0, 14, 15, 3); __PYX_ERR(0, 1561, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mt)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted_redz", 0, 14, 15, 4); __PYX_ERR(0, 1561, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_mr)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted_redz", 0, 14, 15, 5); __PYX_ERR(0, 1561, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  6:
        if (likely((values[6] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_rz)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted_redz", 0, 14, 15, 6); __PYX_ERR(0, 1561, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  7:
        if (likely((values[7] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_redz_final)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted_redz", 0, 14, 15, 7); __PYX_ERR(0, 1561, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  8:
        if (likely((values[8] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_dcom_final)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted_redz", 0, 14, 15, 8); __PYX_ERR(0, 1561, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  9:
        if (likely((values[9] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_sepa)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted_redz", 0, 14, 15, 9); __PYX_ERR(0, 1561, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case 10:
        if (likely((values[10] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_angs)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted_redz", 0, 14, 15, 10); __PYX_ERR(0, 1561, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case 11:
        if (likely((values[11] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_msort)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted_redz", 0, 14, 15, 11); __PYX_ERR(0, 1561, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case 12:
        if (likely((values[12] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_qsort)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted_redz", 0, 14, 15, 12); __PYX_ERR(0, 1561, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case 13:
        if (likely((values[13] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_zsort)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted_redz", 0, 14, 15, 13); __PYX_ERR(0, 1561, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case 14:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_normal_threshold);
          if (value) { values[14] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "loudest_hc_and_par_from_sorted_redz") < 0)) __PYX_ERR(0, 1561, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case 15: values[14] = PyTuple_GET_ITEM(__pyx_args, 14);
        CYTHON_FALLTHROUGH;
        case 14: values[13] = PyTuple_GET_ITEM(__pyx_args, 13);
        values[12] = PyTuple_GET_ITEM(__pyx_args, 12);
        values[11] = PyTuple_GET_ITEM(__pyx_args, 11);
        values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_number = values[0];
    __pyx_v_h2fdf = values[1];
    __pyx_v_nreals = values[2];
    __pyx_v_nloudest = values[3];
    __pyx_v_mt = values[4];
    __pyx_v_mr = values[5];
    __pyx_v_rz = values[6];
    __pyx_v_redz_final = values[7];
    __pyx_v_dcom_final = values[8];
    __pyx_v_sepa = values[9];
    __pyx_v_angs = values[10];
    __pyx_v_msort = values[11];
    __pyx_v_qsort = values[12];
    __pyx_v_zsort = values[13];
    __pyx_v_normal_threshold = values[14];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("loudest_hc_and_par_from_sorted_redz", 0, 14, 15, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1561, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("holodeck.cyutils.loudest_hc_and_par_from_sorted_redz", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_8holodeck_7cyutils_18loudest_hc_and_par_from_sorted_redz(__pyx_self, __pyx_v_number, __pyx_v_h2fdf, __pyx_v_nreals, __pyx_v_nloudest, __pyx_v_mt, __pyx_v_mr, __pyx_v_rz, __pyx_v_redz_final, __pyx_v_dcom_final, __pyx_v_sepa, __pyx_v_angs, __pyx_v_msort, __pyx_v_qsort, __pyx_v_zsort, __pyx_v_normal_threshold);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8holodeck_7cyutils_18loudest_hc_and_par_from_sorted_redz(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_number, PyObject *__pyx_v_h2fdf, PyObject *__pyx_v_nreals, PyObject *__pyx_v_nloudest, PyObject *__pyx_v_mt, PyObject *__pyx_v_mr, PyObject *__pyx_v_rz, PyObject *__pyx_v_redz_final, PyObject *__pyx_v_dcom_final, PyObject *__pyx_v_sepa, PyObject *__pyx_v_angs, PyObject *__pyx_v_msort, PyObject *__pyx_v_qsort, PyObject *__pyx_v_zsort, PyObject *__pyx_v_normal_threshold) {
  __Pyx_memviewslice __pyx_v_shape = { 0, 0, { 0 }, { 0 }, { 0 } };
  PyObject *__pyx_v_F = NULL;
  PyObject *__pyx_v_R = NULL;
  PyObject *__pyx_v_L = NULL;
  PyArrayObject *__pyx_v_hc2ss = 0;
  PyArrayObject *__pyx_v_hc2bg = 0;
  PyArrayObject *__pyx_v_sspar = 0;
  PyArrayObject *__pyx_v_bgpar = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_bgpar;
  __Pyx_Buffer __pyx_pybuffer_bgpar;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_hc2bg;
  __Pyx_Buffer __pyx_pybuffer_hc2bg;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_hc2ss;
  __Pyx_Buffer __pyx_pybuffer_hc2ss;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_sspar;
  __Pyx_Buffer __pyx_pybuffer_sspar;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("loudest_hc_and_par_from_sorted_redz", 0);
  __pyx_pybuffer_hc2ss.pybuffer.buf = NULL;
  __pyx_pybuffer_hc2ss.refcount = 0;
  __pyx_pybuffernd_hc2ss.data = NULL;
  __pyx_pybuffernd_hc2ss.rcbuffer = &__pyx_pybuffer_hc2ss;
  __pyx_pybuffer_hc2bg.pybuffer.buf = NULL;
  __pyx_pybuffer_hc2bg.refcount = 0;
  __pyx_pybuffernd_hc2bg.data = NULL;
  __pyx_pybuffernd_hc2bg.rcbuffer = &__pyx_pybuffer_hc2bg;
  __pyx_pybuffer_sspar.pybuffer.buf = NULL;
  __pyx_pybuffer_sspar.refcount = 0;
  __pyx_pybuffernd_sspar.data = NULL;
  __pyx_pybuffernd_sspar.rcbuffer = &__pyx_pybuffer_sspar;
  __pyx_pybuffer_bgpar.pybuffer.buf = NULL;
  __pyx_pybuffer_bgpar.refcount = 0;
  __pyx_pybuffernd_bgpar.data = NULL;
  __pyx_pybuffernd_bgpar.rcbuffer = &__pyx_pybuffer_bgpar;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_12, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_13, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_17, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_18, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_19, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_20, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_21, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_22, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_23, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_24, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_25, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_26, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_27, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_28, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_29, 1);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bgpar.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2bg.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2ss.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_sspar.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("holodeck.cyutils.loudest_hc_and_par_from_sorted_redz", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_bgpar.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2bg.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hc2ss.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_sspar.rcbuffer->pybuffer);
  __pyx_L2:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_shape, 1);
  __Pyx_XDECREF(__pyx_v_F);
  __Pyx_XDECREF(__pyx_v_R);
  __Pyx_XDECREF(__pyx_v_L);
  __Pyx_XDECREF((PyObject *)__pyx_v_hc2ss);
  __Pyx_XDECREF((PyObject *)__pyx_v_hc2bg);
  __Pyx_XDECREF((PyObject *)__pyx_v_sspar);
  __Pyx_XDECREF((PyObject *)__pyx_v_bgpar);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__41 = PyTuple_Pack(23, __pyx_n_s_number, __pyx_n_s_h2fdf, __pyx_n_s_nreals, __pyx_n_s_nloudest, __pyx_n_s_mt, __pyx_n_s_mr, __pyx_n_s_rz, __pyx_n_s_redz_final, __pyx_n_s_dcom_final, __pyx_n_s_sepa, __pyx_n_s_angs, __pyx_n_s_msort, __pyx_n_s_qsort, __pyx_n_s_zsort, __pyx_n_s_normal_threshold, __pyx_n_s_shape, __pyx_n_s_F, __pyx_n_s_R, __pyx_n_s_L, __pyx_n_s_hc2ss, __pyx_n_s_hc2bg, __pyx_n_s_sspar, __pyx_n_s_bgpar); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(0, 1561, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__41);
  __Pyx_GIVEREF(__pyx_tuple__41);
/* … */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_8holodeck_7cyutils_19loudest_hc_and_par_from_sorted_redz, NULL, __pyx_n_s_holodeck_cyutils); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1561, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_loudest_hc_and_par_from_sorted_r, __pyx_t_3) < 0) __PYX_ERR(0, 1561, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_codeobj__42 = (PyObject*)__Pyx_PyCode_New(15, 0, 23, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__41, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_holodeck_cyutils_pyx, __pyx_n_s_loudest_hc_and_par_from_sorted_r, 1561, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__42)) __PYX_ERR(0, 1561, __pyx_L1_error)
 1562:     number, h2fdf, nreals, nloudest,
 1563:     mt, mr, rz, redz_final, dcom_final, sepa, angs,
 1564:     msort, qsort, zsort, normal_threshold=1e10):
 1565:     """
 1566:     Calculates the characteristic strain and binary parameters from loud single sources and a
 1567:     background of all other sources.
 1568: 
 1569:     Parameters
 1570:     ------------------------
 1571:     number : [M, Q, Z, F] NDarray
 1572:         number in each bin
 1573:     h2fdf : [M, Q, Z, F] NDarray
 1574:         Strain amplitude squared x frequency / frequency bin width for each bin.
 1575:     nreals
 1576:         Number of realizations.
 1577:     nloudest
 1578:         Number of loudest sources to separate in each frequency bin.
 1579:     mt : (M,) 1Darray of scalars
 1580:         Total masses, M, of each bin center.
 1581:     mr : (Q,) 1Darray of scalars
 1582:         Mass ratios, q, of each bin center.
 1583:     rz : (Z,) 1Darray of scalars
 1584:         Redshifts, z, of each bin center.
 1585:     redz_final : (M,Q,Z,F) NDarray of scalars
 1586:         Final redshifts of each bin.
 1587:     dcom_final : (M,Q,Z,F) NDarray of scalars
 1588:         Final comoving distances of each bin.
 1589:     sepa : (M,Q,Z,F) NDarray of scalars
 1590:         Final separations of each mass and frequency combination.
 1591:     angs : (M,Q,Z,F)
 1592:         Final angular separations of each bin.
 1593:     msort : (M*Q*Z,) 1Darray
 1594:         M indices of each bin, sorted from largest to smallest h2fdf.
 1595:     qsort : (M*Q*Z,) 1Darray
 1596:         q indices of each bin, sorted from largest to smallest h2fdf.
 1597:     zsort : (M*Q*Z,) 1Darray
 1598:         z indices of each bin, sorted from largest to smallest h2fdf.
 1599:     normal_threshold : float
 1600:         Threshold for approximating poisson sampling as normal.
 1601: 
 1602:     Returns
 1603:     --------------------------
 1604:     hc2ss : (F, R, L) Ndarray of scalars
 1605:         Char strain squared of the loudest single sources.
 1606:     hc2bg : (F, R) Ndarray of scalars
 1607:         Char strain squared of the background.
 1608:     sspar : (4, F, R) NDarray of scalars
 1609:         Effective M, q, z parameters of the loudest L sources.
 1610:         mass, ratio, redshift, redshift_final
 1611:     bgpar : (4, F, R) NDarray of scalars
 1612:         Average effective M, q, z parameters of the background.
 1613:         mass, ratio, redshift, redshift_final
 1614:     """
 1615: 
+1616:     cdef long[:] shape = np.array(number.shape)
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1616, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_array); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1616, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_number, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1616, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1616, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(__pyx_t_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 1616, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_shape = __pyx_t_5;
  __pyx_t_5.memview = NULL;
  __pyx_t_5.data = NULL;
+1617:     F = shape[3]
  __pyx_t_6 = 3;
  __pyx_t_7 = -1;
  if (__pyx_t_6 < 0) {
    __pyx_t_6 += __pyx_v_shape.shape[0];
    if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 0;
  } else if (unlikely(__pyx_t_6 >= __pyx_v_shape.shape[0])) __pyx_t_7 = 0;
  if (unlikely(__pyx_t_7 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_7);
    __PYX_ERR(0, 1617, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyInt_From_long((*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_6 * __pyx_v_shape.strides[0]) )))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1617, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_F = __pyx_t_1;
  __pyx_t_1 = 0;
+1618:     R = nreals
  __Pyx_INCREF(__pyx_v_nreals);
  __pyx_v_R = __pyx_v_nreals;
+1619:     L = nloudest
  __Pyx_INCREF(__pyx_v_nloudest);
  __pyx_v_L = __pyx_v_nloudest;
+1620:     cdef np.ndarray[np.double_t, ndim=3] hc2ss = np.zeros((F,R,L))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1620, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1620, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1620, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_R);
  __Pyx_INCREF(__pyx_v_L);
  __Pyx_GIVEREF(__pyx_v_L);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_L);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1620, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1620, __pyx_L1_error)
  __pyx_t_8 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_hc2ss.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_hc2ss = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 1620, __pyx_L1_error)
    } else {__pyx_pybuffernd_hc2ss.diminfo[0].strides = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_hc2ss.diminfo[0].shape = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_hc2ss.diminfo[1].strides = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_hc2ss.diminfo[1].shape = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_hc2ss.diminfo[2].strides = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_hc2ss.diminfo[2].shape = __pyx_pybuffernd_hc2ss.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_8 = 0;
  __pyx_v_hc2ss = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
+1621:     cdef np.ndarray[np.double_t, ndim=2] hc2bg = np.zeros((F,R))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1621, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1621, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1621, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_R);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1621, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1621, __pyx_L1_error)
  __pyx_t_9 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_hc2bg.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_hc2bg = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 1621, __pyx_L1_error)
    } else {__pyx_pybuffernd_hc2bg.diminfo[0].strides = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_hc2bg.diminfo[0].shape = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_hc2bg.diminfo[1].strides = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_hc2bg.diminfo[1].shape = __pyx_pybuffernd_hc2bg.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_9 = 0;
  __pyx_v_hc2bg = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
+1622:     cdef np.ndarray[np.double_t, ndim=4] sspar = np.zeros((4,F,R,L))
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_int_4);
  __Pyx_GIVEREF(__pyx_int_4);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_4);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_R);
  __Pyx_INCREF(__pyx_v_L);
  __Pyx_GIVEREF(__pyx_v_L);
  PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_v_L);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_4, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1622, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1622, __pyx_L1_error)
  __pyx_t_10 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_sspar.rcbuffer->pybuffer, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 4, 0, __pyx_stack) == -1)) {
      __pyx_v_sspar = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_sspar.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 1622, __pyx_L1_error)
    } else {__pyx_pybuffernd_sspar.diminfo[0].strides = __pyx_pybuffernd_sspar.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_sspar.diminfo[0].shape = __pyx_pybuffernd_sspar.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_sspar.diminfo[1].strides = __pyx_pybuffernd_sspar.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_sspar.diminfo[1].shape = __pyx_pybuffernd_sspar.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_sspar.diminfo[2].strides = __pyx_pybuffernd_sspar.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_sspar.diminfo[2].shape = __pyx_pybuffernd_sspar.rcbuffer->pybuffer.shape[2]; __pyx_pybuffernd_sspar.diminfo[3].strides = __pyx_pybuffernd_sspar.rcbuffer->pybuffer.strides[3]; __pyx_pybuffernd_sspar.diminfo[3].shape = __pyx_pybuffernd_sspar.rcbuffer->pybuffer.shape[3];
    }
  }
  __pyx_t_10 = 0;
  __pyx_v_sspar = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
+1623:     cdef np.ndarray[np.double_t, ndim=3] bgpar = np.zeros((7,F,R))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_int_7);
  __Pyx_GIVEREF(__pyx_int_7);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_int_7);
  __Pyx_INCREF(__pyx_v_F);
  __Pyx_GIVEREF(__pyx_v_F);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_F);
  __Pyx_INCREF(__pyx_v_R);
  __Pyx_GIVEREF(__pyx_v_R);
  PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_R);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1623, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1623, __pyx_L1_error)
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_bgpar.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 3, 0, __pyx_stack) == -1)) {
      __pyx_v_bgpar = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 1623, __pyx_L1_error)
    } else {__pyx_pybuffernd_bgpar.diminfo[0].strides = __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_bgpar.diminfo[0].shape = __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_bgpar.diminfo[1].strides = __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_bgpar.diminfo[1].shape = __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.shape[1]; __pyx_pybuffernd_bgpar.diminfo[2].strides = __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.strides[2]; __pyx_pybuffernd_bgpar.diminfo[2].shape = __pyx_pybuffernd_bgpar.rcbuffer->pybuffer.shape[2];
    }
  }
  __pyx_t_11 = 0;
  __pyx_v_bgpar = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
+1624:     _loudest_hc_and_par_from_sorted_redz(shape, h2fdf, number, nreals, nloudest, normal_threshold,
  __pyx_t_12 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_double(__pyx_v_h2fdf, PyBUF_WRITABLE); if (unlikely(!__pyx_t_12.memview)) __PYX_ERR(0, 1624, __pyx_L1_error)
  __pyx_t_13 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_double(__pyx_v_number, PyBUF_WRITABLE); if (unlikely(!__pyx_t_13.memview)) __PYX_ERR(0, 1624, __pyx_L1_error)
  __pyx_t_14 = __Pyx_PyInt_As_long(__pyx_v_nreals); if (unlikely((__pyx_t_14 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1624, __pyx_L1_error)
  __pyx_t_15 = __Pyx_PyInt_As_long(__pyx_v_nloudest); if (unlikely((__pyx_t_15 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1624, __pyx_L1_error)
  __pyx_t_16 = __Pyx_PyInt_As_long(__pyx_v_normal_threshold); if (unlikely((__pyx_t_16 == (long)-1) && PyErr_Occurred())) __PYX_ERR(0, 1624, __pyx_L1_error)
/* … */
  __pyx_f_8holodeck_7cyutils__loudest_hc_and_par_from_sorted_redz(__pyx_v_shape, __pyx_t_12, __pyx_t_13, __pyx_t_14, __pyx_t_15, __pyx_t_16, __pyx_t_17, __pyx_t_18, __pyx_t_19, __pyx_t_20, __pyx_t_21, __pyx_t_22, __pyx_t_23, __pyx_t_5, __pyx_t_24, __pyx_t_25, __pyx_t_26, __pyx_t_27, __pyx_t_28, __pyx_t_29);
  __PYX_XDEC_MEMVIEW(&__pyx_t_12, 1);
  __pyx_t_12.memview = NULL;
  __pyx_t_12.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_13, 1);
  __pyx_t_13.memview = NULL;
  __pyx_t_13.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_17, 1);
  __pyx_t_17.memview = NULL;
  __pyx_t_17.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_18, 1);
  __pyx_t_18.memview = NULL;
  __pyx_t_18.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_19, 1);
  __pyx_t_19.memview = NULL;
  __pyx_t_19.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_20, 1);
  __pyx_t_20.memview = NULL;
  __pyx_t_20.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_21, 1);
  __pyx_t_21.memview = NULL;
  __pyx_t_21.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_22, 1);
  __pyx_t_22.memview = NULL;
  __pyx_t_22.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_23, 1);
  __pyx_t_23.memview = NULL;
  __pyx_t_23.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
  __pyx_t_5.memview = NULL;
  __pyx_t_5.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_24, 1);
  __pyx_t_24.memview = NULL;
  __pyx_t_24.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_25, 1);
  __pyx_t_25.memview = NULL;
  __pyx_t_25.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_26, 1);
  __pyx_t_26.memview = NULL;
  __pyx_t_26.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_27, 1);
  __pyx_t_27.memview = NULL;
  __pyx_t_27.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_28, 1);
  __pyx_t_28.memview = NULL;
  __pyx_t_28.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_29, 1);
  __pyx_t_29.memview = NULL;
  __pyx_t_29.data = NULL;
+1625:                             mt, mr, rz, redz_final, dcom_final, sepa, angs,
  __pyx_t_17 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_mt, PyBUF_WRITABLE); if (unlikely(!__pyx_t_17.memview)) __PYX_ERR(0, 1625, __pyx_L1_error)
  __pyx_t_18 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_mr, PyBUF_WRITABLE); if (unlikely(!__pyx_t_18.memview)) __PYX_ERR(0, 1625, __pyx_L1_error)
  __pyx_t_19 = __Pyx_PyObject_to_MemoryviewSlice_ds_double(__pyx_v_rz, PyBUF_WRITABLE); if (unlikely(!__pyx_t_19.memview)) __PYX_ERR(0, 1625, __pyx_L1_error)
  __pyx_t_20 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_double(__pyx_v_redz_final, PyBUF_WRITABLE); if (unlikely(!__pyx_t_20.memview)) __PYX_ERR(0, 1625, __pyx_L1_error)
  __pyx_t_21 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_double(__pyx_v_dcom_final, PyBUF_WRITABLE); if (unlikely(!__pyx_t_21.memview)) __PYX_ERR(0, 1625, __pyx_L1_error)
  __pyx_t_22 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_double(__pyx_v_sepa, PyBUF_WRITABLE); if (unlikely(!__pyx_t_22.memview)) __PYX_ERR(0, 1625, __pyx_L1_error)
  __pyx_t_23 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_double(__pyx_v_angs, PyBUF_WRITABLE); if (unlikely(!__pyx_t_23.memview)) __PYX_ERR(0, 1625, __pyx_L1_error)
+1626:                             msort, qsort, zsort,
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(__pyx_v_msort, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 1626, __pyx_L1_error)
  __pyx_t_24 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(__pyx_v_qsort, PyBUF_WRITABLE); if (unlikely(!__pyx_t_24.memview)) __PYX_ERR(0, 1626, __pyx_L1_error)
  __pyx_t_25 = __Pyx_PyObject_to_MemoryviewSlice_ds_long(__pyx_v_zsort, PyBUF_WRITABLE); if (unlikely(!__pyx_t_25.memview)) __PYX_ERR(0, 1626, __pyx_L1_error)
+1627:                             hc2ss, hc2bg, sspar, bgpar)
  __pyx_t_26 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_double(((PyObject *)__pyx_v_hc2ss), PyBUF_WRITABLE); if (unlikely(!__pyx_t_26.memview)) __PYX_ERR(0, 1627, __pyx_L1_error)
  __pyx_t_27 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(((PyObject *)__pyx_v_hc2bg), PyBUF_WRITABLE); if (unlikely(!__pyx_t_27.memview)) __PYX_ERR(0, 1627, __pyx_L1_error)
  __pyx_t_28 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_double(((PyObject *)__pyx_v_sspar), PyBUF_WRITABLE); if (unlikely(!__pyx_t_28.memview)) __PYX_ERR(0, 1627, __pyx_L1_error)
  __pyx_t_29 = __Pyx_PyObject_to_MemoryviewSlice_dsdsds_double(((PyObject *)__pyx_v_bgpar), PyBUF_WRITABLE); if (unlikely(!__pyx_t_29.memview)) __PYX_ERR(0, 1627, __pyx_L1_error)
+1628:     return hc2ss, hc2bg, sspar, bgpar
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1628, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_hc2ss));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_hc2ss));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_hc2ss));
  __Pyx_INCREF(((PyObject *)__pyx_v_hc2bg));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_hc2bg));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_hc2bg));
  __Pyx_INCREF(((PyObject *)__pyx_v_sspar));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_sspar));
  PyTuple_SET_ITEM(__pyx_t_1, 2, ((PyObject *)__pyx_v_sspar));
  __Pyx_INCREF(((PyObject *)__pyx_v_bgpar));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_bgpar));
  PyTuple_SET_ITEM(__pyx_t_1, 3, ((PyObject *)__pyx_v_bgpar));
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;
 1629: 
 1630: 
 1631: @cython.boundscheck(False)
 1632: @cython.wraparound(False)
 1633: @cython.nonecheck(False)
 1634: @cython.cdivision(True)
+1635: cdef void _loudest_hc_and_par_from_sorted_redz(long[:] shape, double[:,:,:,:] h2fdf, double[:,:,:,:] number,
static void __pyx_f_8holodeck_7cyutils__loudest_hc_and_par_from_sorted_redz(__Pyx_memviewslice __pyx_v_shape, __Pyx_memviewslice __pyx_v_h2fdf, __Pyx_memviewslice __pyx_v_number, long __pyx_v_nreals, long __pyx_v_nloudest, long __pyx_v_thresh, __Pyx_memviewslice __pyx_v_mt, __Pyx_memviewslice __pyx_v_mr, __Pyx_memviewslice __pyx_v_rz, __Pyx_memviewslice __pyx_v_redz_final, __Pyx_memviewslice __pyx_v_dcom_final, __Pyx_memviewslice __pyx_v_sepa, __Pyx_memviewslice __pyx_v_angs, __Pyx_memviewslice __pyx_v_msort, __Pyx_memviewslice __pyx_v_qsort, __Pyx_memviewslice __pyx_v_zsort, __Pyx_memviewslice __pyx_v_hc2ss, __Pyx_memviewslice __pyx_v_hc2bg, __Pyx_memviewslice __pyx_v_sspar, __Pyx_memviewslice __pyx_v_bgpar) {
  int __pyx_v_M;
  int __pyx_v_Q;
  int __pyx_v_Z;
  int __pyx_v_F;
  int __pyx_v_L;
  int __pyx_v_R;
  int __pyx_v_mm;
  int __pyx_v_qq;
  int __pyx_v_zz;
  int __pyx_v_ff;
  int __pyx_v_rr;
  int __pyx_v_ll;
  double __pyx_v_num;
  double __pyx_v_cur;
  double __pyx_v_sum_bg;
  double __pyx_v_m_bg;
  double __pyx_v_q_bg;
  double __pyx_v_z_bg;
  double __pyx_v_zfinal_bg;
  double __pyx_v_dcom_bg;
  double __pyx_v_sepa_bg;
  double __pyx_v_angs_bg;
  bitgen_t *__pyx_v_rng;
  char const *__pyx_v_capsule_name;
  PyObject *__pyx_v_capsule = NULL;
  int __pyx_v_bb;
  double __pyx_v_std;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_loudest_hc_and_par_from_sorted_redz", 0);
/* … */
  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_WriteUnraisable("holodeck.cyutils._loudest_hc_and_par_from_sorted_redz", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_capsule);
  __Pyx_RefNannyFinishContext();
}
 1636:             long nreals, long nloudest, long thresh,
 1637:             double[:] mt, double[:] mr, double[:] rz,
 1638:             double[:,:,:,:] redz_final, double[:,:,:,:] dcom_final, double[:,:,:,:] sepa, double[:,:,:,:] angs,
 1639:             long[:] msort, long[:] qsort, long[:] zsort,
 1640:             double[:,:,:] hc2ss, double[:,:] hc2bg, double[:,:,:,:] sspar, double[:,:,:] bgpar):
 1641:     """
 1642:     Calculates the characteristic strain from loud single sources and a background of all other sources.
 1643: 
 1644:     Parameters
 1645:     ----------
 1646:     shape : long[:] array
 1647:         Shape of number, [M, Q, Z, F].
 1648:     number : double[:,:,:,:] array
 1649:         Number per bin.
 1650:     h2fdf : double[:,:,:,:] array
 1651:         Strain amplitude squared * f/Delta f for a single source in each bin.
 1652:     nreals : int
 1653:         Number of realizations.
 1654:     nloudest : int
 1655:         Number of loudest sources at each source.
 1656:     mt : (M,) 1Darray of scalars
 1657:         Total masses of each bin center.
 1658:     mr : (Q,) 1Darray of scalars
 1659:         Mass ratios of each bin center.
 1660:     rz : (Z,) 1Darray of scalars
 1661:         Redshifts, z, of each bin center.
 1662:     redz_final : (M,Q,Z,F) NDarray of scalars
 1663:         Final redshifts of each bin.
 1664:     dcom_final : (M,Q,Z,F) NDarray of scalars
 1665:         Final comoving distances of each bin.
 1666:     sepa : (M,Q,Z,F) NDarray of scalars
 1667:         Final separations of each bin.
 1668:     angs : (M,Q,Z,F)
 1669:         Final angular separations of each bin.
 1670:     msort : (M*Q*Z,) 1Darray
 1671:         M indices of each bin, sorted from largest to smallest h2fdf.
 1672:     qsort : (M*Q*Z,) 1Darray
 1673:         q indices of each bin, sorted from largest to smallest h2fdf.
 1674:     zsort : (M*Q*Z,) 1Darray
 1675:         z indices of each bin, sorted from largest to smallest h2fdf.
 1676:     hc2ss : double[:,:,:] array
 1677:         (Memory address of) single source characteristic strain squared array.
 1678:     hc2bg : double[:,:] array
 1679:         (Memory address of) background characteristic strain squared array.
 1680:     sspar : (4, F, R) NDarray of scalars
 1681:         Effective M, q, z parameters of the loudest L sources.
 1682:         mass, ratio, redshift, redshift_final
 1683:     bgpar : (4, F, R) NDarray of scalars
 1684:         Average effective M, q, z parameters of the background.
 1685:         mass, ratio, redshift, redshift_final
 1686: 
 1687:     Returns
 1688:     -------
 1689:     void
 1690:     updated via memory address: hc2ss, hc2bg, sspar, bgpar
 1691:     """
 1692: 
+1693:     cdef int M = shape[0]
  __pyx_t_1 = 0;
  __pyx_v_M = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+1694:     cdef int Q = shape[1]
  __pyx_t_1 = 1;
  __pyx_v_Q = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+1695:     cdef int Z = shape[2]
  __pyx_t_1 = 2;
  __pyx_v_Z = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+1696:     cdef int F = shape[3]
  __pyx_t_1 = 3;
  __pyx_v_F = (*((long *) ( /* dim=0 */ (__pyx_v_shape.data + __pyx_t_1 * __pyx_v_shape.strides[0]) )));
+1697:     cdef int L = nloudest
  __pyx_v_L = __pyx_v_nloudest;
+1698:     cdef int R = nreals
  __pyx_v_R = __pyx_v_nreals;
 1699: 
 1700:     cdef int mm, qq, zz, ff, rr, ll
 1701:     cdef double num, cur, sum_bg, m_bg, q_bg, z_bg, zfinal_bg, dcom_bg, sepa_bg, angs_bg
 1702: 
 1703:     # Setup random number generator from numpy library
 1704:     cdef bitgen_t *rng
+1705:     cdef const char *capsule_name = "BitGenerator"
  __pyx_v_capsule_name = ((char const *)"BitGenerator");
+1706:     capsule = PCG64().capsule
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_PCG64); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1706, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1706, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_capsule); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1706, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_capsule = __pyx_t_3;
  __pyx_t_3 = 0;
 1707:     # Cast the pointer
+1708:     rng = <bitgen_t *> PyCapsule_GetPointer(capsule, capsule_name)
  __pyx_t_5 = PyCapsule_GetPointer(__pyx_v_capsule, __pyx_v_capsule_name); if (unlikely(__pyx_t_5 == ((void *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 1708, __pyx_L1_error)
  __pyx_v_rng = ((bitgen_t *)__pyx_t_5);
+1709:     for rr in range(R):
  __pyx_t_6 = __pyx_v_R;
  __pyx_t_7 = __pyx_t_6;
  for (__pyx_t_8 = 0; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_rr = __pyx_t_8;
+1710:         for ff in range(F):
    __pyx_t_9 = __pyx_v_F;
    __pyx_t_10 = __pyx_t_9;
    for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) {
      __pyx_v_ff = __pyx_t_11;
+1711:             ll = 0 # track which index in the loudest list you're currently storing
      __pyx_v_ll = 0;
 1712:                      # start at 0 for the loudest of all.
 1713:             # reset strain sums
+1714:             sum_bg = 0 # sum of bg h2fdf, for parameter averaging and gwb
      __pyx_v_sum_bg = 0.0;
 1715:             # reset parameter averaging sums
+1716:             m_bg = 0
      __pyx_v_m_bg = 0.0;
+1717:             q_bg = 0
      __pyx_v_q_bg = 0.0;
+1718:             z_bg = 0
      __pyx_v_z_bg = 0.0;
+1719:             zfinal_bg = 0
      __pyx_v_zfinal_bg = 0.0;
+1720:             dcom_bg = 0
      __pyx_v_dcom_bg = 0.0;
+1721:             sepa_bg = 0
      __pyx_v_sepa_bg = 0.0;
+1722:             angs_bg = 0
      __pyx_v_angs_bg = 0.0;
+1723:             for bb in range(M*Q*Z): #iterate through bins, loudest to quietest
      __pyx_t_12 = ((__pyx_v_M * __pyx_v_Q) * __pyx_v_Z);
      __pyx_t_13 = __pyx_t_12;
      for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
        __pyx_v_bb = __pyx_t_14;
+1724:                 mm = msort[bb]
        __pyx_t_1 = __pyx_v_bb;
        __pyx_v_mm = (*((long *) ( /* dim=0 */ (__pyx_v_msort.data + __pyx_t_1 * __pyx_v_msort.strides[0]) )));
+1725:                 qq = qsort[bb]
        __pyx_t_1 = __pyx_v_bb;
        __pyx_v_qq = (*((long *) ( /* dim=0 */ (__pyx_v_qsort.data + __pyx_t_1 * __pyx_v_qsort.strides[0]) )));
+1726:                 zz = zsort[bb]
        __pyx_t_1 = __pyx_v_bb;
        __pyx_v_zz = (*((long *) ( /* dim=0 */ (__pyx_v_zsort.data + __pyx_t_1 * __pyx_v_zsort.strides[0]) )));
+1727:                 num = number[mm,qq,zz,ff]
        __pyx_t_1 = __pyx_v_mm;
        __pyx_t_15 = __pyx_v_qq;
        __pyx_t_16 = __pyx_v_zz;
        __pyx_t_17 = __pyx_v_ff;
        __pyx_v_num = (*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_number.data + __pyx_t_1 * __pyx_v_number.strides[0]) ) + __pyx_t_15 * __pyx_v_number.strides[1]) ) + __pyx_t_16 * __pyx_v_number.strides[2]) ) + __pyx_t_17 * __pyx_v_number.strides[3]) )));
+1728:                 if (num>thresh): # Gaussian sample
        __pyx_t_18 = ((__pyx_v_num > __pyx_v_thresh) != 0);
        if (__pyx_t_18) {
/* … */
          goto __pyx_L9;
        }
+1729:                     std = sqrt(num)
          __pyx_v_std = sqrt(__pyx_v_num);
+1730:                     num = <double>random_normal(rng, num, std)
          __pyx_v_num = ((double)random_normal(__pyx_v_rng, __pyx_v_num, __pyx_v_std));
 1731:                 else:            # Poisson sample
+1732:                     num = <double>random_poisson(rng, num)
        /*else*/ {
          __pyx_v_num = ((double)random_poisson(__pyx_v_rng, __pyx_v_num));
        }
        __pyx_L9:;
+1733:                 if(num < 1):
        __pyx_t_18 = ((__pyx_v_num < 1.0) != 0);
        if (__pyx_t_18) {
/* … */
        }
+1734:                     continue
          goto __pyx_L7_continue;
+1735:                 cur = h2fdf[mm,qq,zz,ff] # h^2 * f/df of current bin
        __pyx_t_17 = __pyx_v_mm;
        __pyx_t_16 = __pyx_v_qq;
        __pyx_t_15 = __pyx_v_zz;
        __pyx_t_1 = __pyx_v_ff;
        __pyx_v_cur = (*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_h2fdf.data + __pyx_t_17 * __pyx_v_h2fdf.strides[0]) ) + __pyx_t_16 * __pyx_v_h2fdf.strides[1]) ) + __pyx_t_15 * __pyx_v_h2fdf.strides[2]) ) + __pyx_t_1 * __pyx_v_h2fdf.strides[3]) )));
+1736:                 if (num<1):
        __pyx_t_18 = ((__pyx_v_num < 1.0) != 0);
        if (__pyx_t_18) {
/* … */
        }
+1737:                     continue # to next loudest bin
          goto __pyx_L7_continue;
+1738:                 while (ll < L) and (num > 0):
        while (1) {
          __pyx_t_19 = ((__pyx_v_ll < __pyx_v_L) != 0);
          if (__pyx_t_19) {
          } else {
            __pyx_t_18 = __pyx_t_19;
            goto __pyx_L14_bool_binop_done;
          }
          __pyx_t_19 = ((__pyx_v_num > 0.0) != 0);
          __pyx_t_18 = __pyx_t_19;
          __pyx_L14_bool_binop_done:;
          if (!__pyx_t_18) break;
 1739:                     # store ll loudest source strain
+1740:                     hc2ss[ff,rr,ll] = cur
          __pyx_t_1 = __pyx_v_ff;
          __pyx_t_15 = __pyx_v_rr;
          __pyx_t_16 = __pyx_v_ll;
          *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_hc2ss.data + __pyx_t_1 * __pyx_v_hc2ss.strides[0]) ) + __pyx_t_15 * __pyx_v_hc2ss.strides[1]) ) + __pyx_t_16 * __pyx_v_hc2ss.strides[2]) )) = __pyx_v_cur;
 1741: 
 1742:                     # store indices of ll loudest source
+1743:                     sspar[0,ff,rr,ll] = mt[mm]
          __pyx_t_16 = __pyx_v_mm;
          __pyx_t_15 = 0;
          __pyx_t_1 = __pyx_v_ff;
          __pyx_t_17 = __pyx_v_rr;
          __pyx_t_20 = __pyx_v_ll;
          *((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_sspar.data + __pyx_t_15 * __pyx_v_sspar.strides[0]) ) + __pyx_t_1 * __pyx_v_sspar.strides[1]) ) + __pyx_t_17 * __pyx_v_sspar.strides[2]) ) + __pyx_t_20 * __pyx_v_sspar.strides[3]) )) = (*((double *) ( /* dim=0 */ (__pyx_v_mt.data + __pyx_t_16 * __pyx_v_mt.strides[0]) )));
+1744:                     sspar[1,ff,rr,ll] = mr[qq]
          __pyx_t_16 = __pyx_v_qq;
          __pyx_t_20 = 1;
          __pyx_t_17 = __pyx_v_ff;
          __pyx_t_1 = __pyx_v_rr;
          __pyx_t_15 = __pyx_v_ll;
          *((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_sspar.data + __pyx_t_20 * __pyx_v_sspar.strides[0]) ) + __pyx_t_17 * __pyx_v_sspar.strides[1]) ) + __pyx_t_1 * __pyx_v_sspar.strides[2]) ) + __pyx_t_15 * __pyx_v_sspar.strides[3]) )) = (*((double *) ( /* dim=0 */ (__pyx_v_mr.data + __pyx_t_16 * __pyx_v_mr.strides[0]) )));
+1745:                     sspar[2,ff,rr,ll] = rz[zz]
          __pyx_t_16 = __pyx_v_zz;
          __pyx_t_15 = 2;
          __pyx_t_1 = __pyx_v_ff;
          __pyx_t_17 = __pyx_v_rr;
          __pyx_t_20 = __pyx_v_ll;
          *((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_sspar.data + __pyx_t_15 * __pyx_v_sspar.strides[0]) ) + __pyx_t_1 * __pyx_v_sspar.strides[1]) ) + __pyx_t_17 * __pyx_v_sspar.strides[2]) ) + __pyx_t_20 * __pyx_v_sspar.strides[3]) )) = (*((double *) ( /* dim=0 */ (__pyx_v_rz.data + __pyx_t_16 * __pyx_v_rz.strides[0]) )));
+1746:                     sspar[3,ff,rr,ll] = redz_final[mm,qq,zz,ff]
          __pyx_t_16 = __pyx_v_mm;
          __pyx_t_20 = __pyx_v_qq;
          __pyx_t_17 = __pyx_v_zz;
          __pyx_t_1 = __pyx_v_ff;
          __pyx_t_15 = 3;
          __pyx_t_21 = __pyx_v_ff;
          __pyx_t_22 = __pyx_v_rr;
          __pyx_t_23 = __pyx_v_ll;
          *((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_sspar.data + __pyx_t_15 * __pyx_v_sspar.strides[0]) ) + __pyx_t_21 * __pyx_v_sspar.strides[1]) ) + __pyx_t_22 * __pyx_v_sspar.strides[2]) ) + __pyx_t_23 * __pyx_v_sspar.strides[3]) )) = (*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_redz_final.data + __pyx_t_16 * __pyx_v_redz_final.strides[0]) ) + __pyx_t_20 * __pyx_v_redz_final.strides[1]) ) + __pyx_t_17 * __pyx_v_redz_final.strides[2]) ) + __pyx_t_1 * __pyx_v_redz_final.strides[3]) )));
 1747: 
 1748:                     # update number and ll index
+1749:                     num -= 1
          __pyx_v_num = (__pyx_v_num - 1.0);
+1750:                     ll += 1
          __pyx_v_ll = (__pyx_v_ll + 1);
        }
 1751: 
+1752:                 sum_bg += num * cur # tot bg h2fdf
        __pyx_v_sum_bg = (__pyx_v_sum_bg + (__pyx_v_num * __pyx_v_cur));
 1753:                 # add to average parameters of background sources
+1754:                 m_bg += num * cur * mt[mm] # tot weight bg mass
        __pyx_t_1 = __pyx_v_mm;
        __pyx_v_m_bg = (__pyx_v_m_bg + ((__pyx_v_num * __pyx_v_cur) * (*((double *) ( /* dim=0 */ (__pyx_v_mt.data + __pyx_t_1 * __pyx_v_mt.strides[0]) )))));
+1755:                 q_bg += num * cur * mr[qq] # tot weighted bg ratio
        __pyx_t_1 = __pyx_v_qq;
        __pyx_v_q_bg = (__pyx_v_q_bg + ((__pyx_v_num * __pyx_v_cur) * (*((double *) ( /* dim=0 */ (__pyx_v_mr.data + __pyx_t_1 * __pyx_v_mr.strides[0]) )))));
+1756:                 z_bg += num * cur * rz[zz] # tot weighted bg redshift
        __pyx_t_1 = __pyx_v_zz;
        __pyx_v_z_bg = (__pyx_v_z_bg + ((__pyx_v_num * __pyx_v_cur) * (*((double *) ( /* dim=0 */ (__pyx_v_rz.data + __pyx_t_1 * __pyx_v_rz.strides[0]) )))));
+1757:                 zfinal_bg += num * cur * redz_final[mm,qq,zz,ff] # tot weighted bg redshift after hardening
        __pyx_t_1 = __pyx_v_mm;
        __pyx_t_17 = __pyx_v_qq;
        __pyx_t_20 = __pyx_v_zz;
        __pyx_t_16 = __pyx_v_ff;
        __pyx_v_zfinal_bg = (__pyx_v_zfinal_bg + ((__pyx_v_num * __pyx_v_cur) * (*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_redz_final.data + __pyx_t_1 * __pyx_v_redz_final.strides[0]) ) + __pyx_t_17 * __pyx_v_redz_final.strides[1]) ) + __pyx_t_20 * __pyx_v_redz_final.strides[2]) ) + __pyx_t_16 * __pyx_v_redz_final.strides[3]) )))));
+1758:                 dcom_bg += num * cur * dcom_final[mm,qq,zz,ff] # tot weighted bg com. dist. after hardening
        __pyx_t_16 = __pyx_v_mm;
        __pyx_t_20 = __pyx_v_qq;
        __pyx_t_17 = __pyx_v_zz;
        __pyx_t_1 = __pyx_v_ff;
        __pyx_v_dcom_bg = (__pyx_v_dcom_bg + ((__pyx_v_num * __pyx_v_cur) * (*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_dcom_final.data + __pyx_t_16 * __pyx_v_dcom_final.strides[0]) ) + __pyx_t_20 * __pyx_v_dcom_final.strides[1]) ) + __pyx_t_17 * __pyx_v_dcom_final.strides[2]) ) + __pyx_t_1 * __pyx_v_dcom_final.strides[3]) )))));
+1759:                 sepa_bg += num * cur * sepa[mm,qq,zz,ff] # tot weighted bg separation after hardening
        __pyx_t_1 = __pyx_v_mm;
        __pyx_t_17 = __pyx_v_qq;
        __pyx_t_20 = __pyx_v_zz;
        __pyx_t_16 = __pyx_v_ff;
        __pyx_v_sepa_bg = (__pyx_v_sepa_bg + ((__pyx_v_num * __pyx_v_cur) * (*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_sepa.data + __pyx_t_1 * __pyx_v_sepa.strides[0]) ) + __pyx_t_17 * __pyx_v_sepa.strides[1]) ) + __pyx_t_20 * __pyx_v_sepa.strides[2]) ) + __pyx_t_16 * __pyx_v_sepa.strides[3]) )))));
+1760:                 angs_bg += num * cur * angs[mm,qq,zz,ff] # tot weighted bg angular separation after hardening
        __pyx_t_16 = __pyx_v_mm;
        __pyx_t_20 = __pyx_v_qq;
        __pyx_t_17 = __pyx_v_zz;
        __pyx_t_1 = __pyx_v_ff;
        __pyx_v_angs_bg = (__pyx_v_angs_bg + ((__pyx_v_num * __pyx_v_cur) * (*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_angs.data + __pyx_t_16 * __pyx_v_angs.strides[0]) ) + __pyx_t_20 * __pyx_v_angs.strides[1]) ) + __pyx_t_17 * __pyx_v_angs.strides[2]) ) + __pyx_t_1 * __pyx_v_angs.strides[3]) )))));
        __pyx_L7_continue:;
      }
 1761: 
+1762:             hc2bg[ff,rr] = sum_bg # background strain
      __pyx_t_1 = __pyx_v_ff;
      __pyx_t_17 = __pyx_v_rr;
      *((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_hc2bg.data + __pyx_t_1 * __pyx_v_hc2bg.strides[0]) ) + __pyx_t_17 * __pyx_v_hc2bg.strides[1]) )) = __pyx_v_sum_bg;
 1763:             # background average parameters
+1764:             bgpar[0,ff,rr] = m_bg/sum_bg # bg avg mass
      __pyx_t_17 = 0;
      __pyx_t_1 = __pyx_v_ff;
      __pyx_t_20 = __pyx_v_rr;
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_bgpar.data + __pyx_t_17 * __pyx_v_bgpar.strides[0]) ) + __pyx_t_1 * __pyx_v_bgpar.strides[1]) ) + __pyx_t_20 * __pyx_v_bgpar.strides[2]) )) = (__pyx_v_m_bg / __pyx_v_sum_bg);
+1765:             bgpar[1,ff,rr] = q_bg/sum_bg # bg avg ratio
      __pyx_t_20 = 1;
      __pyx_t_1 = __pyx_v_ff;
      __pyx_t_17 = __pyx_v_rr;
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_bgpar.data + __pyx_t_20 * __pyx_v_bgpar.strides[0]) ) + __pyx_t_1 * __pyx_v_bgpar.strides[1]) ) + __pyx_t_17 * __pyx_v_bgpar.strides[2]) )) = (__pyx_v_q_bg / __pyx_v_sum_bg);
+1766:             bgpar[2,ff,rr] = z_bg/sum_bg # bg avg redshift
      __pyx_t_17 = 2;
      __pyx_t_1 = __pyx_v_ff;
      __pyx_t_20 = __pyx_v_rr;
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_bgpar.data + __pyx_t_17 * __pyx_v_bgpar.strides[0]) ) + __pyx_t_1 * __pyx_v_bgpar.strides[1]) ) + __pyx_t_20 * __pyx_v_bgpar.strides[2]) )) = (__pyx_v_z_bg / __pyx_v_sum_bg);
+1767:             bgpar[3,ff,rr] = zfinal_bg/sum_bg # bg avg redshift after hardening
      __pyx_t_20 = 3;
      __pyx_t_1 = __pyx_v_ff;
      __pyx_t_17 = __pyx_v_rr;
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_bgpar.data + __pyx_t_20 * __pyx_v_bgpar.strides[0]) ) + __pyx_t_1 * __pyx_v_bgpar.strides[1]) ) + __pyx_t_17 * __pyx_v_bgpar.strides[2]) )) = (__pyx_v_zfinal_bg / __pyx_v_sum_bg);
+1768:             bgpar[4,ff,rr] = dcom_bg/sum_bg # bg avg comoving distance after hardening
      __pyx_t_17 = 4;
      __pyx_t_1 = __pyx_v_ff;
      __pyx_t_20 = __pyx_v_rr;
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_bgpar.data + __pyx_t_17 * __pyx_v_bgpar.strides[0]) ) + __pyx_t_1 * __pyx_v_bgpar.strides[1]) ) + __pyx_t_20 * __pyx_v_bgpar.strides[2]) )) = (__pyx_v_dcom_bg / __pyx_v_sum_bg);
+1769:             bgpar[5,ff,rr] = sepa_bg/sum_bg # bg avg binary separation after hardening
      __pyx_t_20 = 5;
      __pyx_t_1 = __pyx_v_ff;
      __pyx_t_17 = __pyx_v_rr;
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_bgpar.data + __pyx_t_20 * __pyx_v_bgpar.strides[0]) ) + __pyx_t_1 * __pyx_v_bgpar.strides[1]) ) + __pyx_t_17 * __pyx_v_bgpar.strides[2]) )) = (__pyx_v_sepa_bg / __pyx_v_sum_bg);
+1770:             bgpar[6,ff,rr] = angs_bg/sum_bg # bg avg binary angular separation after hardening
      __pyx_t_17 = 6;
      __pyx_t_1 = __pyx_v_ff;
      __pyx_t_20 = __pyx_v_rr;
      *((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_bgpar.data + __pyx_t_17 * __pyx_v_bgpar.strides[0]) ) + __pyx_t_1 * __pyx_v_bgpar.strides[1]) ) + __pyx_t_20 * __pyx_v_bgpar.strides[2]) )) = (__pyx_v_angs_bg / __pyx_v_sum_bg);
    }
  }
 1771: 
 1772: 
 1773: 
 1774: 
+1775: def interp_2d(xnew, xold, yold, xlog=False, ylog=False, extrap=False):
/* Python wrapper */
static PyObject *__pyx_pw_8holodeck_7cyutils_21interp_2d(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_8holodeck_7cyutils_21interp_2d = {"interp_2d", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_8holodeck_7cyutils_21interp_2d, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_8holodeck_7cyutils_21interp_2d(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_xnew = 0;
  PyObject *__pyx_v_xold = 0;
  PyObject *__pyx_v_yold = 0;
  PyObject *__pyx_v_xlog = 0;
  PyObject *__pyx_v_ylog = 0;
  PyObject *__pyx_v_extrap = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("interp_2d (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_xnew,&__pyx_n_s_xold,&__pyx_n_s_yold,&__pyx_n_s_xlog,&__pyx_n_s_ylog,&__pyx_n_s_extrap,0};
    PyObject* values[6] = {0,0,0,0,0,0};
    values[3] = ((PyObject *)Py_False);
    values[4] = ((PyObject *)Py_False);
    values[5] = ((PyObject *)Py_False);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_xnew)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_xold)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("interp_2d", 0, 3, 6, 1); __PYX_ERR(0, 1775, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_yold)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("interp_2d", 0, 3, 6, 2); __PYX_ERR(0, 1775, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_xlog);
          if (value) { values[3] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  4:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_ylog);
          if (value) { values[4] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  5:
        if (kw_args > 0) {
          PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_extrap);
          if (value) { values[5] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "interp_2d") < 0)) __PYX_ERR(0, 1775, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        CYTHON_FALLTHROUGH;
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        CYTHON_FALLTHROUGH;
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_xnew = values[0];
    __pyx_v_xold = values[1];
    __pyx_v_yold = values[2];
    __pyx_v_xlog = values[3];
    __pyx_v_ylog = values[4];
    __pyx_v_extrap = values[5];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("interp_2d", 0, 3, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 1775, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("holodeck.cyutils.interp_2d", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_8holodeck_7cyutils_20interp_2d(__pyx_self, __pyx_v_xnew, __pyx_v_xold, __pyx_v_yold, __pyx_v_xlog, __pyx_v_ylog, __pyx_v_extrap);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8holodeck_7cyutils_20interp_2d(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_xnew, PyObject *__pyx_v_xold, PyObject *__pyx_v_yold, PyObject *__pyx_v_xlog, PyObject *__pyx_v_ylog, PyObject *__pyx_v_extrap) {
  long __pyx_v_extrap_flag;
  PyObject *__pyx_v_ynew = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("interp_2d", 0);
  __Pyx_INCREF(__pyx_v_xnew);
  __Pyx_INCREF(__pyx_v_xold);
  __Pyx_INCREF(__pyx_v_yold);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("holodeck.cyutils.interp_2d", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_ynew);
  __Pyx_XDECREF(__pyx_v_xnew);
  __Pyx_XDECREF(__pyx_v_xold);
  __Pyx_XDECREF(__pyx_v_yold);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__43 = PyTuple_Pack(8, __pyx_n_s_xnew, __pyx_n_s_xold, __pyx_n_s_yold, __pyx_n_s_xlog, __pyx_n_s_ylog, __pyx_n_s_extrap, __pyx_n_s_extrap_flag, __pyx_n_s_ynew); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(0, 1775, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__43);
  __Pyx_GIVEREF(__pyx_tuple__43);
/* … */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_8holodeck_7cyutils_21interp_2d, NULL, __pyx_n_s_holodeck_cyutils); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1775, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_interp_2d, __pyx_t_3) < 0) __PYX_ERR(0, 1775, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_codeobj__44 = (PyObject*)__Pyx_PyCode_New(6, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__43, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_holodeck_cyutils_pyx, __pyx_n_s_interp_2d, 1775, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__44)) __PYX_ERR(0, 1775, __pyx_L1_error)
+1776:     if xlog:
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_xlog); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1776, __pyx_L1_error)
  if (__pyx_t_1) {
/* … */
  }
+1777:         xnew = np.log10(xnew)
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1777, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_log10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1777, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_xnew) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_xnew);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1777, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_xnew, __pyx_t_2);
    __pyx_t_2 = 0;
+1778:         xold = np.log10(xold)
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_np); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_log10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_v_xold) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_xold);
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1778, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_xold, __pyx_t_2);
    __pyx_t_2 = 0;
+1779:     if ylog:
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_ylog); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1779, __pyx_L1_error)
  if (__pyx_t_1) {
/* … */
  }
+1780:         yold = np.log10(yold)
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1780, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_log10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1780, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_3, __pyx_v_yold) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_yold);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1780, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_yold, __pyx_t_2);
    __pyx_t_2 = 0;
 1781: 
+1782:     assert xnew.shape[0] == xold.shape[0]
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_xnew, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1782, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1782, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_xold, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1782, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1782, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1782, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1782, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_1)) {
      PyErr_SetNone(PyExc_AssertionError);
      __PYX_ERR(0, 1782, __pyx_L1_error)
    }
  }
  #endif
+1783:     assert xold.shape == yold.shape
  #ifndef CYTHON_WITHOUT_ASSERTIONS
  if (unlikely(!Py_OptimizeFlag)) {
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_xold, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1783, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_yold, __pyx_n_s_shape); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1783, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1783, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1783, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(!__pyx_t_1)) {
      PyErr_SetNone(PyExc_AssertionError);
      __PYX_ERR(0, 1783, __pyx_L1_error)
    }
  }
  #endif
 1784: 
+1785:     extrap_flag = 1 if extrap else 0
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_extrap); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1785, __pyx_L1_error)
  if (__pyx_t_1) {
    __pyx_t_5 = 1;
  } else {
    __pyx_t_5 = 0;
  }
  __pyx_v_extrap_flag = __pyx_t_5;
+1786:     ynew = _interp_2d(xnew, xold, yold, extrap_flag)
  __pyx_t_6 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_v_xnew, PyBUF_WRITABLE); if (unlikely(!__pyx_t_6.memview)) __PYX_ERR(0, 1786, __pyx_L1_error)
  __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_v_xold, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 1786, __pyx_L1_error)
  __pyx_t_8 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(__pyx_v_yold, PyBUF_WRITABLE); if (unlikely(!__pyx_t_8.memview)) __PYX_ERR(0, 1786, __pyx_L1_error)
  __pyx_t_9 = __pyx_f_8holodeck_7cyutils__interp_2d(__pyx_t_6, __pyx_t_7, __pyx_t_8, __pyx_v_extrap_flag); if (unlikely(!__pyx_t_9.memview)) __PYX_ERR(0, 1786, __pyx_L1_error)
  __PYX_XDEC_MEMVIEW(&__pyx_t_6, 1);
  __pyx_t_6.memview = NULL;
  __pyx_t_6.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1);
  __pyx_t_7.memview = NULL;
  __pyx_t_7.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_8, 1);
  __pyx_t_8.memview = NULL;
  __pyx_t_8.data = NULL;
  __pyx_t_4 = __pyx_memoryview_fromslice(__pyx_t_9, 2, (PyObject *(*)(char *)) __pyx_memview_get_double, (int (*)(char *, PyObject *)) __pyx_memview_set_double, 0);; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1786, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __PYX_XDEC_MEMVIEW(&__pyx_t_9, 1);
  __pyx_t_9.memview = NULL;
  __pyx_t_9.data = NULL;
  __pyx_v_ynew = __pyx_t_4;
  __pyx_t_4 = 0;
 1787: 
+1788:     if ylog:
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_ylog); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 1788, __pyx_L1_error)
  if (__pyx_t_1) {
/* … */
  }
+1789:         ynew = np.power(10.0, ynew)
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1789, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_power); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1789, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    __pyx_t_10 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_10 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_float_10_0, __pyx_v_ynew};
      __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1789, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_4);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_float_10_0, __pyx_v_ynew};
      __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1789, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_4);
    } else
    #endif
    {
      __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1789, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      if (__pyx_t_3) {
        __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_3); __pyx_t_3 = NULL;
      }
      __Pyx_INCREF(__pyx_float_10_0);
      __Pyx_GIVEREF(__pyx_float_10_0);
      PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_float_10_0);
      __Pyx_INCREF(__pyx_v_ynew);
      __Pyx_GIVEREF(__pyx_v_ynew);
      PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_v_ynew);
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1789, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF_SET(__pyx_v_ynew, __pyx_t_4);
    __pyx_t_4 = 0;
+1790:     return ynew
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_ynew);
  __pyx_r = __pyx_v_ynew;
  goto __pyx_L0;
 1791: 
 1792: 
 1793: @cython.boundscheck(False)
 1794: @cython.wraparound(False)
 1795: @cython.nonecheck(False)
 1796: @cython.cdivision(True)
+1797: cdef double[:, :] _interp_2d(
static __Pyx_memviewslice __pyx_f_8holodeck_7cyutils__interp_2d(__Pyx_memviewslice __pyx_v_xnew, __Pyx_memviewslice __pyx_v_xold, __Pyx_memviewslice __pyx_v_yold, int __pyx_v_extrap) {
  int __pyx_v_num;
  int __pyx_v_new_size;
  int __pyx_v_old_size;
  int __pyx_v_last;
  int __pyx_v_ii;
  int __pyx_v_nn;
  int __pyx_v_oo;
  double __pyx_v_newval;
  PyArrayObject *__pyx_v_ynew = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ynew;
  __Pyx_Buffer __pyx_pybuffer_ynew;
  __Pyx_memviewslice __pyx_r = { 0, 0, { 0 }, { 0 }, { 0 } };
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_interp_2d", 0);
  __pyx_pybuffer_ynew.pybuffer.buf = NULL;
  __pyx_pybuffer_ynew.refcount = 0;
  __pyx_pybuffernd_ynew.data = NULL;
  __pyx_pybuffernd_ynew.rcbuffer = &__pyx_pybuffer_ynew;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __PYX_XDEC_MEMVIEW(&__pyx_t_25, 1);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ynew.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __pyx_r.data = NULL;
  __pyx_r.memview = NULL;
  __Pyx_AddTraceback("holodeck.cyutils._interp_2d", __pyx_clineno, __pyx_lineno, __pyx_filename);
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ynew.rcbuffer->pybuffer);
  if (unlikely(!__pyx_r.memview)) {
    PyErr_SetString(PyExc_TypeError, "Memoryview return value is not initialized");
  }
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_ynew);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 1798:     double[:, :] xnew, double[:, :] xold, double[:, :] yold, int extrap,
 1799: ):
+1800:     cdef int num = xnew.shape[0]
  __pyx_v_num = (__pyx_v_xnew.shape[0]);
+1801:     cdef int new_size = xnew.shape[1]
  __pyx_v_new_size = (__pyx_v_xnew.shape[1]);
+1802:     cdef int old_size = xold.shape[1]
  __pyx_v_old_size = (__pyx_v_xold.shape[1]);
+1803:     cdef int last = old_size - 1
  __pyx_v_last = (__pyx_v_old_size - 1);
 1804: 
 1805:     cdef int ii, nn, oo
 1806:     cdef double newval
 1807: 
+1808:     cdef np.ndarray[np.double_t, ndim=2] ynew = np.empty((num, new_size))
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_num); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_new_size); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
  __pyx_t_2 = 0;
  __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_4, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_5);
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1808, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 1808, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ynew.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_ynew = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_ynew.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 1808, __pyx_L1_error)
    } else {__pyx_pybuffernd_ynew.diminfo[0].strides = __pyx_pybuffernd_ynew.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ynew.diminfo[0].shape = __pyx_pybuffernd_ynew.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_ynew.diminfo[1].strides = __pyx_pybuffernd_ynew.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_ynew.diminfo[1].shape = __pyx_pybuffernd_ynew.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_6 = 0;
  __pyx_v_ynew = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
+1809:     for ii in range(num):
  __pyx_t_7 = __pyx_v_num;
  __pyx_t_8 = __pyx_t_7;
  for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) {
    __pyx_v_ii = __pyx_t_9;
+1810:         oo = 0
    __pyx_v_oo = 0;
+1811:         for nn in range(new_size):
    __pyx_t_10 = __pyx_v_new_size;
    __pyx_t_11 = __pyx_t_10;
    for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {
      __pyx_v_nn = __pyx_t_12;
+1812:             newval = xnew[ii, nn]
      __pyx_t_13 = __pyx_v_ii;
      __pyx_t_14 = __pyx_v_nn;
      __pyx_v_newval = (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_xnew.data + __pyx_t_13 * __pyx_v_xnew.strides[0]) ) + __pyx_t_14 * __pyx_v_xnew.strides[1]) )));
+1813:             while (xold[ii, oo+1] < newval) and (oo < last-1):
      while (1) {
        __pyx_t_14 = __pyx_v_ii;
        __pyx_t_13 = (__pyx_v_oo + 1);
        __pyx_t_16 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_xold.data + __pyx_t_14 * __pyx_v_xold.strides[0]) ) + __pyx_t_13 * __pyx_v_xold.strides[1]) ))) < __pyx_v_newval) != 0);
        if (__pyx_t_16) {
        } else {
          __pyx_t_15 = __pyx_t_16;
          goto __pyx_L9_bool_binop_done;
        }
        __pyx_t_16 = ((__pyx_v_oo < (__pyx_v_last - 1)) != 0);
        __pyx_t_15 = __pyx_t_16;
        __pyx_L9_bool_binop_done:;
        if (!__pyx_t_15) break;
+1814:                 oo += 1
        __pyx_v_oo = (__pyx_v_oo + 1);
      }
 1815: 
+1816:             if extrap == 1 or ((xold[ii, oo] < newval) and (newval < xold[ii, oo+1])):
      __pyx_t_16 = ((__pyx_v_extrap == 1) != 0);
      if (!__pyx_t_16) {
      } else {
        __pyx_t_15 = __pyx_t_16;
        goto __pyx_L12_bool_binop_done;
      }
      __pyx_t_13 = __pyx_v_ii;
      __pyx_t_14 = __pyx_v_oo;
      __pyx_t_16 = (((*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_xold.data + __pyx_t_13 * __pyx_v_xold.strides[0]) ) + __pyx_t_14 * __pyx_v_xold.strides[1]) ))) < __pyx_v_newval) != 0);
      if (__pyx_t_16) {
      } else {
        __pyx_t_15 = __pyx_t_16;
        goto __pyx_L12_bool_binop_done;
      }
      __pyx_t_14 = __pyx_v_ii;
      __pyx_t_13 = (__pyx_v_oo + 1);
      __pyx_t_16 = ((__pyx_v_newval < (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_xold.data + __pyx_t_14 * __pyx_v_xold.strides[0]) ) + __pyx_t_13 * __pyx_v_xold.strides[1]) )))) != 0);
      __pyx_t_15 = __pyx_t_16;
      __pyx_L12_bool_binop_done:;
      if (__pyx_t_15) {
/* … */
        goto __pyx_L11;
      }
+1817:                 ynew[ii, nn] = _interp_between_vals(newval, xold[ii, oo], xold[ii, oo+1], yold[ii, oo], yold[ii, oo+1])
        __pyx_t_13 = __pyx_v_ii;
        __pyx_t_14 = __pyx_v_oo;
        __pyx_t_17 = __pyx_v_ii;
        __pyx_t_18 = (__pyx_v_oo + 1);
        __pyx_t_19 = __pyx_v_ii;
        __pyx_t_20 = __pyx_v_oo;
        __pyx_t_21 = __pyx_v_ii;
        __pyx_t_22 = (__pyx_v_oo + 1);
        __pyx_t_23 = __pyx_v_ii;
        __pyx_t_24 = __pyx_v_nn;
        *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_ynew.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_ynew.diminfo[0].strides, __pyx_t_24, __pyx_pybuffernd_ynew.diminfo[1].strides) = __pyx_f_8holodeck_7cyutils__interp_between_vals(__pyx_v_newval, (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_xold.data + __pyx_t_13 * __pyx_v_xold.strides[0]) ) + __pyx_t_14 * __pyx_v_xold.strides[1]) ))), (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_xold.data + __pyx_t_17 * __pyx_v_xold.strides[0]) ) + __pyx_t_18 * __pyx_v_xold.strides[1]) ))), (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_yold.data + __pyx_t_19 * __pyx_v_yold.strides[0]) ) + __pyx_t_20 * __pyx_v_yold.strides[1]) ))), (*((double *) ( /* dim=1 */ (( /* dim=0 */ (__pyx_v_yold.data + __pyx_t_21 * __pyx_v_yold.strides[0]) ) + __pyx_t_22 * __pyx_v_yold.strides[1]) ))));
 1818:             else:
+1819:                 ynew[ii, nn] = NAN
      /*else*/ {
        __pyx_t_22 = __pyx_v_ii;
        __pyx_t_21 = __pyx_v_nn;
        *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_ynew.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_ynew.diminfo[0].strides, __pyx_t_21, __pyx_pybuffernd_ynew.diminfo[1].strides) = NAN;
      }
      __pyx_L11:;
    }
  }
 1820: 
+1821:     return ynew
  __pyx_t_25 = __Pyx_PyObject_to_MemoryviewSlice_dsds_double(((PyObject *)__pyx_v_ynew), PyBUF_WRITABLE); if (unlikely(!__pyx_t_25.memview)) __PYX_ERR(0, 1821, __pyx_L1_error)
  __pyx_r = __pyx_t_25;
  __pyx_t_25.memview = NULL;
  __pyx_t_25.data = NULL;
  goto __pyx_L0;