Generated by Cython 0.29.33

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: nj.c

+001: import numpy as np
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* … */
  __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 002: cimport numpy as np
 003: cimport cython
 004: """
 005: Original code from https://github.com/mattapow/dodonaphy/blob/b0e7e27ce2b46c74c15cc4f964c72be535784b8e/dodonaphy/cython/Cpeeler.pyx
 006: """
 007: 
+008: cdef np.double_t infty = np.finfo(np.double).max
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_finfo); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_double); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_max); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_4 = __pyx_PyFloat_AsDouble(__pyx_t_3); if (unlikely((__pyx_t_4 == ((npy_double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_6geophy_8tree_dec_2nj_infty = __pyx_t_4;
+009: cdef np.double_t eps = np.finfo(np.double).eps
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_finfo); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_double); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_eps); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_4 == ((npy_double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_6geophy_8tree_dec_2nj_eps = __pyx_t_4;
 010: 
+011: cdef class Node:
struct __pyx_obj_6geophy_8tree_dec_2nj_Node {
  PyObject_HEAD
  int taxon;
  PyObject *_nj_distances;
  double _nj_xsub;
};

 012:     cdef int taxon
 013:     cdef dict _nj_distances
 014:     cdef double _nj_xsub
 015: 
+016:     def __init__(self, int taxon):
/* Python wrapper */
static int __pyx_pw_6geophy_8tree_dec_2nj_4Node_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_6geophy_8tree_dec_2nj_4Node_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_taxon;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_taxon,0};
    PyObject* values[1] = {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  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_taxon)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 16, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 1) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    }
    __pyx_v_taxon = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_taxon == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 16, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 16, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("geophy.tree_dec.nj.Node.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return -1;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6geophy_8tree_dec_2nj_4Node___init__(((struct __pyx_obj_6geophy_8tree_dec_2nj_Node *)__pyx_v_self), __pyx_v_taxon);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

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

static int __pyx_pf_6geophy_8tree_dec_2nj_4Node___init__(struct __pyx_obj_6geophy_8tree_dec_2nj_Node *__pyx_v_self, int __pyx_v_taxon) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__", 0);
/* … */
  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("geophy.tree_dec.nj.Node.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
+017:         self.taxon = taxon
  __pyx_v_self->taxon = __pyx_v_taxon;
+018:         self._nj_distances = {}
  __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 18, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_self->_nj_distances);
  __Pyx_DECREF(__pyx_v_self->_nj_distances);
  __pyx_v_self->_nj_distances = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
+019:         self._nj_xsub = 0.0
  __pyx_v_self->_nj_xsub = 0.0;
 020: 
 021: @cython.boundscheck(False)
 022: @cython.wraparound(False)
+023: cpdef nj(double[:, ::1] pdm):
static PyObject *__pyx_pw_6geophy_8tree_dec_2nj_1nj(PyObject *__pyx_self, PyObject *__pyx_arg_pdm); /*proto*/
static PyObject *__pyx_f_6geophy_8tree_dec_2nj_nj(__Pyx_memviewslice __pyx_v_pdm, CYTHON_UNUSED int __pyx_skip_dispatch) {
  int __pyx_v_n_pool;
  int __pyx_v_n_taxa;
  int __pyx_v_n_ints;
  int __pyx_v_node_count;
  PyArrayObject *__pyx_v_peel = 0;
  PyArrayObject *__pyx_v_blens = 0;
  PyObject *__pyx_v_node_pool = NULL;
  __pyx_t_5numpy_double_t __pyx_v_dist;
  __pyx_t_5numpy_double_t __pyx_v_v1;
  __pyx_t_5numpy_double_t __pyx_v_v3;
  __pyx_t_5numpy_double_t __pyx_v_v4;
  __pyx_t_5numpy_double_t __pyx_v_qvalue;
  __pyx_t_5numpy_double_t __pyx_v_min_q;
  int __pyx_v_int_i;
  int __pyx_v_parent;
  __pyx_t_5numpy_double_t __pyx_v_delta_f;
  __pyx_t_5numpy_double_t __pyx_v_delta_g;
  __pyx_t_5numpy_double_t __pyx_v_two;
  struct __pyx_obj_6geophy_8tree_dec_2nj_Node *__pyx_v_nd = 0;
  struct __pyx_obj_6geophy_8tree_dec_2nj_Node *__pyx_v_nd1 = 0;
  struct __pyx_obj_6geophy_8tree_dec_2nj_Node *__pyx_v_nd2 = 0;
  struct __pyx_obj_6geophy_8tree_dec_2nj_Node *__pyx_v_node_to_join1 = 0;
  struct __pyx_obj_6geophy_8tree_dec_2nj_Node *__pyx_v_node_to_join2 = 0;
  PyObject *__pyx_v_idx1 = NULL;
  CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
  struct __pyx_obj_6geophy_8tree_dec_2nj_Node *__pyx_v_new_node = NULL;
  int __pyx_7genexpr__pyx_v_taxon;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_blens;
  __Pyx_Buffer __pyx_pybuffer_blens;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_peel;
  __Pyx_Buffer __pyx_pybuffer_peel;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("nj", 0);
  __pyx_pybuffer_peel.pybuffer.buf = NULL;
  __pyx_pybuffer_peel.refcount = 0;
  __pyx_pybuffernd_peel.data = NULL;
  __pyx_pybuffernd_peel.rcbuffer = &__pyx_pybuffer_peel;
  __pyx_pybuffer_blens.pybuffer.buf = NULL;
  __pyx_pybuffer_blens.refcount = 0;
  __pyx_pybuffernd_blens.data = NULL;
  __pyx_pybuffernd_blens.rcbuffer = &__pyx_pybuffer_blens;
/* … */
  /* 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_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_blens.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_peel.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("geophy.tree_dec.nj.nj", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_blens.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_peel.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_peel);
  __Pyx_XDECREF((PyObject *)__pyx_v_blens);
  __Pyx_XDECREF(__pyx_v_node_pool);
  __Pyx_XDECREF((PyObject *)__pyx_v_nd);
  __Pyx_XDECREF((PyObject *)__pyx_v_nd1);
  __Pyx_XDECREF((PyObject *)__pyx_v_nd2);
  __Pyx_XDECREF((PyObject *)__pyx_v_node_to_join1);
  __Pyx_XDECREF((PyObject *)__pyx_v_node_to_join2);
  __Pyx_XDECREF(__pyx_v_idx1);
  __Pyx_XDECREF(__pyx_v__);
  __Pyx_XDECREF((PyObject *)__pyx_v_new_node);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_6geophy_8tree_dec_2nj_1nj(PyObject *__pyx_self, PyObject *__pyx_arg_pdm); /*proto*/
static char __pyx_doc_6geophy_8tree_dec_2nj_nj[] = " Calculate neighbour joining tree.\n    Credit to Dendropy for python implentation.\n\n    Args:\n        pdm (ndarray): Pairwise distance matrix\n    ";
static PyObject *__pyx_pw_6geophy_8tree_dec_2nj_1nj(PyObject *__pyx_self, PyObject *__pyx_arg_pdm) {
  __Pyx_memviewslice __pyx_v_pdm = { 0, 0, { 0 }, { 0 }, { 0 } };
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("nj (wrapper)", 0);
  assert(__pyx_arg_pdm); {
    __pyx_v_pdm = __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(__pyx_arg_pdm, PyBUF_WRITABLE); if (unlikely(!__pyx_v_pdm.memview)) __PYX_ERR(0, 23, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L3_error:;
  __Pyx_AddTraceback("geophy.tree_dec.nj.nj", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_6geophy_8tree_dec_2nj_nj(__pyx_self, __pyx_v_pdm);
  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_6geophy_8tree_dec_2nj_nj(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_pdm) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("nj", 0);
  __Pyx_XDECREF(__pyx_r);
  if (unlikely(!__pyx_v_pdm.memview)) { __Pyx_RaiseUnboundLocalError("pdm"); __PYX_ERR(0, 23, __pyx_L1_error) }
  __pyx_t_1 = __pyx_f_6geophy_8tree_dec_2nj_nj(__pyx_v_pdm, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("geophy.tree_dec.nj.nj", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __PYX_XDEC_MEMVIEW(&__pyx_v_pdm, 1);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 024:     """ Calculate neighbour joining tree.
 025:     Credit to Dendropy for python implentation.
 026: 
 027:     Args:
 028:         pdm (ndarray): Pairwise distance matrix
 029:     """
 030: 
+031:     cdef int n_pool = len(pdm)
  __pyx_t_1 = __Pyx_MemoryView_Len(__pyx_v_pdm); 
  __pyx_v_n_pool = __pyx_t_1;
+032:     cdef int n_taxa = len(pdm)
  __pyx_t_1 = __Pyx_MemoryView_Len(__pyx_v_pdm); 
  __pyx_v_n_taxa = __pyx_t_1;
+033:     cdef int n_ints = n_taxa - 1
  __pyx_v_n_ints = (__pyx_v_n_taxa - 1);
+034:     cdef int node_count = 2 * n_taxa - 2
  __pyx_v_node_count = ((2 * __pyx_v_n_taxa) - 2);
 035: 
+036:     cdef np.ndarray[long, ndim=2] peel = np.zeros((n_ints, 3), dtype=long)
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 36, __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, 36, __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_n_ints); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __Pyx_INCREF(__pyx_int_3);
  __Pyx_GIVEREF(__pyx_int_3);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_int_3);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, ((PyObject *)(&PyLong_Type))) < 0) __PYX_ERR(0, 36, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 36, __pyx_L1_error)
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_peel.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_peel = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_peel.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 36, __pyx_L1_error)
    } else {__pyx_pybuffernd_peel.diminfo[0].strides = __pyx_pybuffernd_peel.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_peel.diminfo[0].shape = __pyx_pybuffernd_peel.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_peel.diminfo[1].strides = __pyx_pybuffernd_peel.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_peel.diminfo[1].shape = __pyx_pybuffernd_peel.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_6 = 0;
  __pyx_v_peel = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;
+037:     cdef np.ndarray[np.double_t, ndim=1] blens = np.zeros(node_count, dtype=np.double)
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_zeros); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_node_count); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_double); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_7) < 0) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 37, __pyx_L1_error)
  __pyx_t_8 = ((PyArrayObject *)__pyx_t_7);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_blens.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_blens = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_blens.rcbuffer->pybuffer.buf = NULL;
      __PYX_ERR(0, 37, __pyx_L1_error)
    } else {__pyx_pybuffernd_blens.diminfo[0].strides = __pyx_pybuffernd_blens.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_blens.diminfo[0].shape = __pyx_pybuffernd_blens.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_8 = 0;
  __pyx_v_blens = ((PyArrayObject *)__pyx_t_7);
  __pyx_t_7 = 0;
 038: 
 039:     # initialise node pool
+040:     node_pool = [Node(taxon=taxon) for taxon in range(n_pool)]
  { /* enter inner scope */
    __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 40, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = __pyx_v_n_pool;
    __pyx_t_10 = __pyx_t_9;
    for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) {
      __pyx_7genexpr__pyx_v_taxon = __pyx_t_11;
      __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 40, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_7genexpr__pyx_v_taxon); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 40, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_taxon, __pyx_t_2) < 0) __PYX_ERR(0, 40, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_6geophy_8tree_dec_2nj_Node), __pyx_empty_tuple, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 40, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_7, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 40, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
  } /* exit inner scope */
  __pyx_v_node_pool = ((PyObject*)__pyx_t_7);
  __pyx_t_7 = 0;
 041: 
 042:     cdef np.double_t dist
 043:     cdef np.double_t v1
 044:     cdef np.double_t v3
 045:     cdef np.double_t v4
 046:     cdef np.double_t qvalue
 047:     cdef np.double_t min_q
 048:     cdef int int_i
 049:     cdef int parent
 050:     cdef np.double_t delta_f
 051:     cdef np.double_t delta_g
+052:     cdef np.double_t two = 2.
  __pyx_v_two = 2.;
 053: 
 054:     # More hints to use Node
 055:     cdef Node nd
 056:     cdef Node nd1
 057:     cdef Node nd2
 058:     cdef Node node_to_join1
 059:     cdef Node node_to_join2
 060: 
 061:     # cache calculations
+062:     for nd1 in node_pool:
  __pyx_t_7 = __pyx_v_node_pool; __Pyx_INCREF(__pyx_t_7); __pyx_t_12 = 0;
  for (;;) {
    if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_7)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_2 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_12); __Pyx_INCREF(__pyx_t_2); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 62, __pyx_L1_error)
    #else
    __pyx_t_2 = PySequence_ITEM(__pyx_t_7, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 62, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    #endif
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_6geophy_8tree_dec_2nj_Node))))) __PYX_ERR(0, 62, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_nd1, ((struct __pyx_obj_6geophy_8tree_dec_2nj_Node *)__pyx_t_2));
    __pyx_t_2 = 0;
/* … */
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+063:         nd1._nj_xsub = <np.double_t>0.0
    __pyx_v_nd1->_nj_xsub = ((__pyx_t_5numpy_double_t)0.0);
+064:         for nd2 in node_pool:
    __pyx_t_2 = __pyx_v_node_pool; __Pyx_INCREF(__pyx_t_2); __pyx_t_13 = 0;
    for (;;) {
      if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_2)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_13); __Pyx_INCREF(__pyx_t_5); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 64, __pyx_L1_error)
      #else
      __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 64, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      #endif
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_6geophy_8tree_dec_2nj_Node))))) __PYX_ERR(0, 64, __pyx_L1_error)
      __Pyx_XDECREF_SET(__pyx_v_nd2, ((struct __pyx_obj_6geophy_8tree_dec_2nj_Node *)__pyx_t_5));
      __pyx_t_5 = 0;
/* … */
      __pyx_L7_continue:;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+065:             if nd1 is nd2:
      __pyx_t_14 = (__pyx_v_nd1 == __pyx_v_nd2);
      __pyx_t_15 = (__pyx_t_14 != 0);
      if (__pyx_t_15) {
/* … */
      }
+066:                 continue
        goto __pyx_L7_continue;
+067:             dist = pdm[nd1.taxon, nd2.taxon]
      __pyx_t_16 = __pyx_v_nd1->taxon;
      __pyx_t_17 = __pyx_v_nd2->taxon;
      __pyx_v_dist = (*((double *) ( /* dim=1 */ ((char *) (((double *) ( /* dim=0 */ (__pyx_v_pdm.data + __pyx_t_16 * __pyx_v_pdm.strides[0]) )) + __pyx_t_17)) )));
+068:             nd1._nj_distances[nd2] = dist
      __pyx_t_5 = PyFloat_FromDouble(__pyx_v_dist); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 68, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (unlikely(__pyx_v_nd1->_nj_distances == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 68, __pyx_L1_error)
      }
      if (unlikely(PyDict_SetItem(__pyx_v_nd1->_nj_distances, ((PyObject *)__pyx_v_nd2), __pyx_t_5) < 0)) __PYX_ERR(0, 68, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+069:             nd1._nj_xsub += dist
      __pyx_v_nd1->_nj_xsub = (__pyx_v_nd1->_nj_xsub + __pyx_v_dist);
 070: 
+071:     while n_pool > 1:
  while (1) {
    __pyx_t_15 = ((__pyx_v_n_pool > 1) != 0);
    if (!__pyx_t_15) break;
 072:         # calculate argmin of Q-matrix
+073:         min_q = infty
    __pyx_v_min_q = __pyx_v_6geophy_8tree_dec_2nj_infty;
+074:         n_pool = len(node_pool)
    __pyx_t_12 = PyList_GET_SIZE(__pyx_v_node_pool); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 74, __pyx_L1_error)
    __pyx_v_n_pool = __pyx_t_12;
+075:         for idx1, nd1 in enumerate(node_pool[:-1]):
    __Pyx_INCREF(__pyx_int_0);
    __pyx_t_7 = __pyx_int_0;
    __pyx_t_2 = __Pyx_PyList_GetSlice(__pyx_v_node_pool, 0, -1L); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 75, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __pyx_t_2; __Pyx_INCREF(__pyx_t_5); __pyx_t_12 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    for (;;) {
      if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_5)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_2 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_12); __Pyx_INCREF(__pyx_t_2); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 75, __pyx_L1_error)
      #else
      __pyx_t_2 = PySequence_ITEM(__pyx_t_5, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 75, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      #endif
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_6geophy_8tree_dec_2nj_Node))))) __PYX_ERR(0, 75, __pyx_L1_error)
      __Pyx_XDECREF_SET(__pyx_v_nd1, ((struct __pyx_obj_6geophy_8tree_dec_2nj_Node *)__pyx_t_2));
      __pyx_t_2 = 0;
      __Pyx_INCREF(__pyx_t_7);
      __Pyx_XDECREF_SET(__pyx_v_idx1, __pyx_t_7);
      __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_7, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 75, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_7);
      __pyx_t_7 = __pyx_t_2;
      __pyx_t_2 = 0;
/* … */
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+076:             for _, nd2 in enumerate(node_pool[idx1 + 1 :]):
      __Pyx_INCREF(__pyx_int_0);
      __pyx_t_2 = __pyx_int_0;
      __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_v_idx1, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 76, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_15 = (__pyx_t_4 == Py_None);
      if (__pyx_t_15) {
        __pyx_t_13 = 0;
      } else {
        __pyx_t_18 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_18 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 76, __pyx_L1_error)
        __pyx_t_13 = __pyx_t_18;
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyList_GetSlice(__pyx_v_node_pool, __pyx_t_13, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 76, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = __pyx_t_4; __Pyx_INCREF(__pyx_t_3); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      for (;;) {
        if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_13); __Pyx_INCREF(__pyx_t_4); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 76, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 76, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
        if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_6geophy_8tree_dec_2nj_Node))))) __PYX_ERR(0, 76, __pyx_L1_error)
        __Pyx_XDECREF_SET(__pyx_v_nd2, ((struct __pyx_obj_6geophy_8tree_dec_2nj_Node *)__pyx_t_4));
        __pyx_t_4 = 0;
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_2);
        __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 76, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_2);
        __pyx_t_2 = __pyx_t_4;
        __pyx_t_4 = 0;
/* … */
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+077:                 v1 = (<np.double_t>(n_pool) - two) * <np.double_t>(nd1._nj_distances[nd2])
        if (unlikely(__pyx_v_nd1->_nj_distances == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 77, __pyx_L1_error)
        }
        __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_nd1->_nj_distances, ((PyObject *)__pyx_v_nd2)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 77, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_19 == ((npy_double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 77, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_v_v1 = ((((__pyx_t_5numpy_double_t)__pyx_v_n_pool) - __pyx_v_two) * ((__pyx_t_5numpy_double_t)__pyx_t_19));
+078:                 qvalue = v1 - <np.double_t>nd1._nj_xsub - <np.double_t>nd2._nj_xsub
        __pyx_v_qvalue = ((__pyx_v_v1 - ((__pyx_t_5numpy_double_t)__pyx_v_nd1->_nj_xsub)) - ((__pyx_t_5numpy_double_t)__pyx_v_nd2->_nj_xsub));
+079:                 if qvalue < min_q:
        __pyx_t_15 = ((__pyx_v_qvalue < __pyx_v_min_q) != 0);
        if (__pyx_t_15) {
/* … */
        }
+080:                     min_q = qvalue
          __pyx_v_min_q = __pyx_v_qvalue;
 081:                     #nodes_to_join = (nd1, nd2)
+082:                     node_to_join1 = nd1
          __Pyx_INCREF(((PyObject *)__pyx_v_nd1));
          __Pyx_XDECREF_SET(__pyx_v_node_to_join1, __pyx_v_nd1);
+083:                     node_to_join2 = nd2
          __Pyx_INCREF(((PyObject *)__pyx_v_nd2));
          __Pyx_XDECREF_SET(__pyx_v_node_to_join2, __pyx_v_nd2);
 084: 
 085:         # create the new node
+086:         int_i = n_taxa - n_pool
    __pyx_v_int_i = (__pyx_v_n_taxa - __pyx_v_n_pool);
+087:         parent = int_i + n_taxa
    __pyx_v_parent = (__pyx_v_int_i + __pyx_v_n_taxa);
+088:         new_node = Node(parent)
    __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_parent); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 88, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_6geophy_8tree_dec_2nj_Node), __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 88, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_XDECREF_SET(__pyx_v_new_node, ((struct __pyx_obj_6geophy_8tree_dec_2nj_Node *)__pyx_t_5));
    __pyx_t_5 = 0;
+089:         peel[int_i, 2] = parent
    __pyx_t_17 = __pyx_v_int_i;
    __pyx_t_16 = 2;
    *__Pyx_BufPtrStrided2d(long *, __pyx_pybuffernd_peel.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_peel.diminfo[0].strides, __pyx_t_16, __pyx_pybuffernd_peel.diminfo[1].strides) = __pyx_v_parent;
 090: 
 091:         # attach it to the tree
 092:         #peel[int_i, 0] = nodes_to_join[0].taxon
 093:         #peel[int_i, 1] = nodes_to_join[1].taxon
 094:         #node_pool.remove(nodes_to_join[0])
 095:         #node_pool.remove(nodes_to_join[1])
+096:         peel[int_i, 0] = node_to_join1.taxon
    if (unlikely(!__pyx_v_node_to_join1)) { __Pyx_RaiseUnboundLocalError("node_to_join1"); __PYX_ERR(0, 96, __pyx_L1_error) }
    __pyx_t_9 = __pyx_v_node_to_join1->taxon;
    __pyx_t_16 = __pyx_v_int_i;
    __pyx_t_17 = 0;
    *__Pyx_BufPtrStrided2d(long *, __pyx_pybuffernd_peel.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_peel.diminfo[0].strides, __pyx_t_17, __pyx_pybuffernd_peel.diminfo[1].strides) = __pyx_t_9;
+097:         peel[int_i, 1] = node_to_join2.taxon
    if (unlikely(!__pyx_v_node_to_join2)) { __Pyx_RaiseUnboundLocalError("node_to_join2"); __PYX_ERR(0, 97, __pyx_L1_error) }
    __pyx_t_9 = __pyx_v_node_to_join2->taxon;
    __pyx_t_17 = __pyx_v_int_i;
    __pyx_t_16 = 1;
    *__Pyx_BufPtrStrided2d(long *, __pyx_pybuffernd_peel.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_peel.diminfo[0].strides, __pyx_t_16, __pyx_pybuffernd_peel.diminfo[1].strides) = __pyx_t_9;
+098:         node_pool.remove(node_to_join1)
    if (unlikely(!__pyx_v_node_to_join1)) { __Pyx_RaiseUnboundLocalError("node_to_join1"); __PYX_ERR(0, 98, __pyx_L1_error) }
    __pyx_t_5 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyList_Type_remove, __pyx_v_node_pool, ((PyObject *)__pyx_v_node_to_join1)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 98, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+099:         node_pool.remove(node_to_join2)
    if (unlikely(!__pyx_v_node_to_join2)) { __Pyx_RaiseUnboundLocalError("node_to_join2"); __PYX_ERR(0, 99, __pyx_L1_error) }
    __pyx_t_5 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyList_Type_remove, __pyx_v_node_pool, ((PyObject *)__pyx_v_node_to_join2)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 99, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
 100: 
 101:         # calculate the distances for the new node
+102:         for nd in node_pool:
    __pyx_t_5 = __pyx_v_node_pool; __Pyx_INCREF(__pyx_t_5); __pyx_t_12 = 0;
    for (;;) {
      if (__pyx_t_12 >= PyList_GET_SIZE(__pyx_t_5)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_7 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_12); __Pyx_INCREF(__pyx_t_7); __pyx_t_12++; if (unlikely(0 < 0)) __PYX_ERR(0, 102, __pyx_L1_error)
      #else
      __pyx_t_7 = PySequence_ITEM(__pyx_t_5, __pyx_t_12); __pyx_t_12++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 102, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      #endif
      if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_6geophy_8tree_dec_2nj_Node))))) __PYX_ERR(0, 102, __pyx_L1_error)
      __Pyx_XDECREF_SET(__pyx_v_nd, ((struct __pyx_obj_6geophy_8tree_dec_2nj_Node *)__pyx_t_7));
      __pyx_t_7 = 0;
/* … */
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
 103:             # actual node-to-node distances
+104:             v1 = 0.0
      __pyx_v_v1 = 0.0;
 105:             #for node_to_join in nodes_to_join:
 106:             #    v1 += <np.double_t>nd._nj_distances[node_to_join]
 107:             #v3 = nodes_to_join[0]._nj_distances[nodes_to_join[1]]
+108:             v1 += <np.double_t>nd._nj_distances[node_to_join1]
      if (unlikely(__pyx_v_nd->_nj_distances == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 108, __pyx_L1_error)
      }
      if (unlikely(!__pyx_v_node_to_join1)) { __Pyx_RaiseUnboundLocalError("node_to_join1"); __PYX_ERR(0, 108, __pyx_L1_error) }
      __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_nd->_nj_distances, ((PyObject *)__pyx_v_node_to_join1)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 108, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_7); if (unlikely((__pyx_t_19 == ((npy_double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 108, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_v_v1 = (__pyx_v_v1 + ((__pyx_t_5numpy_double_t)__pyx_t_19));
+109:             v1 += <np.double_t>nd._nj_distances[node_to_join2]
      if (unlikely(__pyx_v_nd->_nj_distances == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 109, __pyx_L1_error)
      }
      if (unlikely(!__pyx_v_node_to_join2)) { __Pyx_RaiseUnboundLocalError("node_to_join2"); __PYX_ERR(0, 109, __pyx_L1_error) }
      __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_nd->_nj_distances, ((PyObject *)__pyx_v_node_to_join2)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 109, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_7); if (unlikely((__pyx_t_19 == ((npy_double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 109, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_v_v1 = (__pyx_v_v1 + ((__pyx_t_5numpy_double_t)__pyx_t_19));
+110:             v3 = node_to_join1._nj_distances[node_to_join2]
      if (unlikely(!__pyx_v_node_to_join1)) { __Pyx_RaiseUnboundLocalError("node_to_join1"); __PYX_ERR(0, 110, __pyx_L1_error) }
      if (unlikely(__pyx_v_node_to_join1->_nj_distances == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 110, __pyx_L1_error)
      }
      if (unlikely(!__pyx_v_node_to_join2)) { __Pyx_RaiseUnboundLocalError("node_to_join2"); __PYX_ERR(0, 110, __pyx_L1_error) }
      __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_node_to_join1->_nj_distances, ((PyObject *)__pyx_v_node_to_join2)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 110, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_7); if (unlikely((__pyx_t_19 == ((npy_double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 110, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_v_v3 = __pyx_t_19;
+111:             dist = 0.5 * (v1 - v3)
      __pyx_v_dist = (0.5 * (__pyx_v_v1 - __pyx_v_v3));
+112:             new_node._nj_distances[nd] = dist
      __pyx_t_7 = PyFloat_FromDouble(__pyx_v_dist); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 112, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      if (unlikely(__pyx_v_new_node->_nj_distances == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 112, __pyx_L1_error)
      }
      if (unlikely(PyDict_SetItem(__pyx_v_new_node->_nj_distances, ((PyObject *)__pyx_v_nd), __pyx_t_7) < 0)) __PYX_ERR(0, 112, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+113:             nd._nj_distances[new_node] = dist
      __pyx_t_7 = PyFloat_FromDouble(__pyx_v_dist); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 113, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      if (unlikely(__pyx_v_nd->_nj_distances == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 113, __pyx_L1_error)
      }
      if (unlikely(PyDict_SetItem(__pyx_v_nd->_nj_distances, ((PyObject *)__pyx_v_new_node), __pyx_t_7) < 0)) __PYX_ERR(0, 113, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
 114: 
 115:             # Adjust/recalculate the values needed for the Q-matrix calculation
+116:             new_node._nj_xsub += dist
      __pyx_v_new_node->_nj_xsub = (__pyx_v_new_node->_nj_xsub + __pyx_v_dist);
+117:             nd._nj_xsub += dist
      __pyx_v_nd->_nj_xsub = (__pyx_v_nd->_nj_xsub + __pyx_v_dist);
 118:             #for node_to_join in nodes_to_join:
 119:             #    nd._nj_xsub -= <np.double_t>node_to_join._nj_distances[nd]
+120:             nd._nj_xsub -= <np.double_t>node_to_join1._nj_distances[nd]
      if (unlikely(!__pyx_v_node_to_join1)) { __Pyx_RaiseUnboundLocalError("node_to_join1"); __PYX_ERR(0, 120, __pyx_L1_error) }
      if (unlikely(__pyx_v_node_to_join1->_nj_distances == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 120, __pyx_L1_error)
      }
      __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_node_to_join1->_nj_distances, ((PyObject *)__pyx_v_nd)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 120, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_7); if (unlikely((__pyx_t_19 == ((npy_double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 120, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_v_nd->_nj_xsub = (__pyx_v_nd->_nj_xsub - ((__pyx_t_5numpy_double_t)__pyx_t_19));
+121:             nd._nj_xsub -= <np.double_t>node_to_join2._nj_distances[nd]
      if (unlikely(!__pyx_v_node_to_join2)) { __Pyx_RaiseUnboundLocalError("node_to_join2"); __PYX_ERR(0, 121, __pyx_L1_error) }
      if (unlikely(__pyx_v_node_to_join2->_nj_distances == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 121, __pyx_L1_error)
      }
      __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_node_to_join2->_nj_distances, ((PyObject *)__pyx_v_nd)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 121, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_7); if (unlikely((__pyx_t_19 == ((npy_double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 121, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_v_nd->_nj_xsub = (__pyx_v_nd->_nj_xsub - ((__pyx_t_5numpy_double_t)__pyx_t_19));
 122: 
 123:         # calculate the branch lengths
+124:         if n_pool > 2:
    __pyx_t_15 = ((__pyx_v_n_pool > 2) != 0);
    if (__pyx_t_15) {
/* … */
      goto __pyx_L19;
    }
 125:             #v1 = 0.5 * nodes_to_join[0]._nj_distances[nodes_to_join[1]]
+126:             v1 = 0.5 * node_to_join1._nj_distances[node_to_join2]
      if (unlikely(!__pyx_v_node_to_join1)) { __Pyx_RaiseUnboundLocalError("node_to_join1"); __PYX_ERR(0, 126, __pyx_L1_error) }
      if (unlikely(__pyx_v_node_to_join1->_nj_distances == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 126, __pyx_L1_error)
      }
      if (unlikely(!__pyx_v_node_to_join2)) { __Pyx_RaiseUnboundLocalError("node_to_join2"); __PYX_ERR(0, 126, __pyx_L1_error) }
      __pyx_t_5 = __Pyx_PyDict_GetItem(__pyx_v_node_to_join1->_nj_distances, ((PyObject *)__pyx_v_node_to_join2)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 126, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_7 = PyNumber_Multiply(__pyx_float_0_5, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 126, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_7); if (unlikely((__pyx_t_19 == ((npy_double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 126, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_v_v1 = __pyx_t_19;
 127:             v4 = (
 128:                 1.0
+129:                 / (two * (<np.double_t>n_pool - two))
      __pyx_t_19 = (__pyx_v_two * (((__pyx_t_5numpy_double_t)__pyx_v_n_pool) - __pyx_v_two));
      if (unlikely(__pyx_t_19 == 0)) {
        PyErr_SetString(PyExc_ZeroDivisionError, "float division");
        __PYX_ERR(0, 129, __pyx_L1_error)
      }
 130:                 #* (nodes_to_join[0]._nj_xsub - nodes_to_join[1]._nj_xsub)
+131:                 * (node_to_join1._nj_xsub - node_to_join2._nj_xsub)
      if (unlikely(!__pyx_v_node_to_join1)) { __Pyx_RaiseUnboundLocalError("node_to_join1"); __PYX_ERR(0, 131, __pyx_L1_error) }
      if (unlikely(!__pyx_v_node_to_join2)) { __Pyx_RaiseUnboundLocalError("node_to_join2"); __PYX_ERR(0, 131, __pyx_L1_error) }
      __pyx_v_v4 = ((((__pyx_t_5numpy_double_t)1.0) / __pyx_t_19) * (__pyx_v_node_to_join1->_nj_xsub - __pyx_v_node_to_join2->_nj_xsub));
 132:             )
+133:             delta_f = v1 + v4
      __pyx_v_delta_f = (__pyx_v_v1 + __pyx_v_v4);
 134:             #delta_g = <np.double_t>nodes_to_join[0]._nj_distances[nodes_to_join[1]] - delta_f
 135:             #blens[nodes_to_join[0].taxon] = delta_f
 136:             #blens[nodes_to_join[1].taxon] = delta_g
+137:             delta_g = <np.double_t>node_to_join1._nj_distances[node_to_join2] - delta_f
      if (unlikely(!__pyx_v_node_to_join1)) { __Pyx_RaiseUnboundLocalError("node_to_join1"); __PYX_ERR(0, 137, __pyx_L1_error) }
      if (unlikely(__pyx_v_node_to_join1->_nj_distances == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 137, __pyx_L1_error)
      }
      if (unlikely(!__pyx_v_node_to_join2)) { __Pyx_RaiseUnboundLocalError("node_to_join2"); __PYX_ERR(0, 137, __pyx_L1_error) }
      __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_node_to_join1->_nj_distances, ((PyObject *)__pyx_v_node_to_join2)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 137, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_7); if (unlikely((__pyx_t_19 == ((npy_double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 137, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_v_delta_g = (((__pyx_t_5numpy_double_t)__pyx_t_19) - __pyx_v_delta_f);
+138:             blens[node_to_join1.taxon] = delta_f
      if (unlikely(!__pyx_v_node_to_join1)) { __Pyx_RaiseUnboundLocalError("node_to_join1"); __PYX_ERR(0, 138, __pyx_L1_error) }
      __pyx_t_16 = __pyx_v_node_to_join1->taxon;
      *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_blens.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_blens.diminfo[0].strides) = __pyx_v_delta_f;
+139:             blens[node_to_join2.taxon] = delta_g
      if (unlikely(!__pyx_v_node_to_join2)) { __Pyx_RaiseUnboundLocalError("node_to_join2"); __PYX_ERR(0, 139, __pyx_L1_error) }
      __pyx_t_16 = __pyx_v_node_to_join2->taxon;
      *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_blens.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_blens.diminfo[0].strides) = __pyx_v_delta_g;
 140:         else:
 141:             #dist = nodes_to_join[0]._nj_distances[nodes_to_join[1]]
 142:             #blens[nodes_to_join[0].taxon] = dist / two
 143:             #blens[nodes_to_join[1].taxon] = dist / two
+144:             dist = node_to_join1._nj_distances[node_to_join2]
    /*else*/ {
      if (unlikely(!__pyx_v_node_to_join1)) { __Pyx_RaiseUnboundLocalError("node_to_join1"); __PYX_ERR(0, 144, __pyx_L1_error) }
      if (unlikely(__pyx_v_node_to_join1->_nj_distances == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 144, __pyx_L1_error)
      }
      if (unlikely(!__pyx_v_node_to_join2)) { __Pyx_RaiseUnboundLocalError("node_to_join2"); __PYX_ERR(0, 144, __pyx_L1_error) }
      __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_node_to_join1->_nj_distances, ((PyObject *)__pyx_v_node_to_join2)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 144, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_19 = __pyx_PyFloat_AsDouble(__pyx_t_7); if (unlikely((__pyx_t_19 == ((npy_double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 144, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_v_dist = __pyx_t_19;
+145:             blens[node_to_join1.taxon] = dist / two
      if (unlikely(__pyx_v_two == 0)) {
        PyErr_SetString(PyExc_ZeroDivisionError, "float division");
        __PYX_ERR(0, 145, __pyx_L1_error)
      }
      if (unlikely(!__pyx_v_node_to_join1)) { __Pyx_RaiseUnboundLocalError("node_to_join1"); __PYX_ERR(0, 145, __pyx_L1_error) }
      __pyx_t_16 = __pyx_v_node_to_join1->taxon;
      *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_blens.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_blens.diminfo[0].strides) = (__pyx_v_dist / __pyx_v_two);
+146:             blens[node_to_join2.taxon] = dist / two
      if (unlikely(__pyx_v_two == 0)) {
        PyErr_SetString(PyExc_ZeroDivisionError, "float division");
        __PYX_ERR(0, 146, __pyx_L1_error)
      }
      if (unlikely(!__pyx_v_node_to_join2)) { __Pyx_RaiseUnboundLocalError("node_to_join2"); __PYX_ERR(0, 146, __pyx_L1_error) }
      __pyx_t_16 = __pyx_v_node_to_join2->taxon;
      *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_blens.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_blens.diminfo[0].strides) = (__pyx_v_dist / __pyx_v_two);
    }
    __pyx_L19:;
 147: 
 148:         # clean up
 149:         #for node_to_join in nodes_to_join:
 150:         #    node_to_join._nj_distances = {}
 151:         #    node_to_join._nj_xsub = 0.0
+152:         node_to_join1._nj_distances = {}
    __pyx_t_7 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 152, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (unlikely(!__pyx_v_node_to_join1)) { __Pyx_RaiseUnboundLocalError("node_to_join1"); __PYX_ERR(0, 152, __pyx_L1_error) }
    __Pyx_GIVEREF(__pyx_t_7);
    __Pyx_GOTREF(__pyx_v_node_to_join1->_nj_distances);
    __Pyx_DECREF(__pyx_v_node_to_join1->_nj_distances);
    __pyx_v_node_to_join1->_nj_distances = ((PyObject*)__pyx_t_7);
    __pyx_t_7 = 0;
+153:         node_to_join1._nj_xsub = 0.0
    if (unlikely(!__pyx_v_node_to_join1)) { __Pyx_RaiseUnboundLocalError("node_to_join1"); __PYX_ERR(0, 153, __pyx_L1_error) }
    __pyx_v_node_to_join1->_nj_xsub = 0.0;
+154:         node_to_join2._nj_distances = {}
    __pyx_t_7 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 154, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (unlikely(!__pyx_v_node_to_join2)) { __Pyx_RaiseUnboundLocalError("node_to_join2"); __PYX_ERR(0, 154, __pyx_L1_error) }
    __Pyx_GIVEREF(__pyx_t_7);
    __Pyx_GOTREF(__pyx_v_node_to_join2->_nj_distances);
    __Pyx_DECREF(__pyx_v_node_to_join2->_nj_distances);
    __pyx_v_node_to_join2->_nj_distances = ((PyObject*)__pyx_t_7);
    __pyx_t_7 = 0;
+155:         node_to_join2._nj_xsub = 0.0
    if (unlikely(!__pyx_v_node_to_join2)) { __Pyx_RaiseUnboundLocalError("node_to_join2"); __PYX_ERR(0, 155, __pyx_L1_error) }
    __pyx_v_node_to_join2->_nj_xsub = 0.0;
 156: 
 157:         # add the new node to the pool of nodes
+158:         node_pool.append(new_node)
    __pyx_t_20 = __Pyx_PyList_Append(__pyx_v_node_pool, ((PyObject *)__pyx_v_new_node)); if (unlikely(__pyx_t_20 == ((int)-1))) __PYX_ERR(0, 158, __pyx_L1_error)
 159: 
 160:         # adjust count
+161:         n_pool -= 1
    __pyx_v_n_pool = (__pyx_v_n_pool - 1);
  }
+162:     blens = np.maximum(blens, eps)
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_maximum); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyFloat_FromDouble(__pyx_v_6geophy_8tree_dec_2nj_eps); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_3 = NULL;
  __pyx_t_9 = 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_9 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_blens), __pyx_t_5};
    __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 162, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, ((PyObject *)__pyx_v_blens), __pyx_t_5};
    __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 162, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else
  #endif
  {
    __pyx_t_4 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 162, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (__pyx_t_3) {
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL;
    }
    __Pyx_INCREF(((PyObject *)__pyx_v_blens));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_blens));
    PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_9, ((PyObject *)__pyx_v_blens));
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_9, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 162, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 162, __pyx_L1_error)
  __pyx_t_8 = ((PyArrayObject *)__pyx_t_7);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_blens.rcbuffer->pybuffer);
    __pyx_t_9 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_blens.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_9 < 0)) {
      PyErr_Fetch(&__pyx_t_21, &__pyx_t_22, &__pyx_t_23);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_blens.rcbuffer->pybuffer, (PyObject*)__pyx_v_blens, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_21); Py_XDECREF(__pyx_t_22); Py_XDECREF(__pyx_t_23);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_21, __pyx_t_22, __pyx_t_23);
      }
      __pyx_t_21 = __pyx_t_22 = __pyx_t_23 = 0;
    }
    __pyx_pybuffernd_blens.diminfo[0].strides = __pyx_pybuffernd_blens.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_blens.diminfo[0].shape = __pyx_pybuffernd_blens.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 162, __pyx_L1_error)
  }
  __pyx_t_8 = 0;
  __Pyx_DECREF_SET(__pyx_v_blens, ((PyArrayObject *)__pyx_t_7));
  __pyx_t_7 = 0;
+163:     return peel, blens
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(((PyObject *)__pyx_v_peel));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_peel));
  PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_peel));
  __Pyx_INCREF(((PyObject *)__pyx_v_blens));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_blens));
  PyTuple_SET_ITEM(__pyx_t_7, 1, ((PyObject *)__pyx_v_blens));
  __pyx_r = __pyx_t_7;
  __pyx_t_7 = 0;
  goto __pyx_L0;