/* Generated by Cython 0.23.2 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000)
    #error Cython requires Python 2.6+ or Python 3.2+.
#else
#define CYTHON_ABI "0_23_2"
#include <stddef.h>
#ifndef offsetof
#define offsetof(type, member) ( (size_t) & ((type*)0) -> member )
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
  #ifndef __fastcall
    #define __fastcall
  #endif
#endif
#ifndef DL_IMPORT
  #define DL_IMPORT(t) t
#endif
#ifndef DL_EXPORT
  #define DL_EXPORT(t) t
#endif
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#ifndef Py_HUGE_VAL
  #define Py_HUGE_VAL HUGE_VAL
#endif
#ifdef PYPY_VERSION
#define CYTHON_COMPILING_IN_PYPY 1
#define CYTHON_COMPILING_IN_CPYTHON 0
#else
#define CYTHON_COMPILING_IN_PYPY 0
#define CYTHON_COMPILING_IN_CPYTHON 1
#endif
#if !defined(CYTHON_USE_PYLONG_INTERNALS) && CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x02070000
#define CYTHON_USE_PYLONG_INTERNALS 1
#endif
#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
#define Py_OptimizeFlag 0
#endif
#define __PYX_BUILD_PY_SSIZE_T "n"
#define CYTHON_FORMAT_SSIZE_T "z"
#if PY_MAJOR_VERSION < 3
  #define __Pyx_BUILTIN_MODULE_NAME "__builtin__"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyClass_Type
#else
  #define __Pyx_BUILTIN_MODULE_NAME "builtins"
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyType_Type
#endif
#ifndef Py_TPFLAGS_CHECKTYPES
  #define Py_TPFLAGS_CHECKTYPES 0
#endif
#ifndef Py_TPFLAGS_HAVE_INDEX
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#ifndef Py_TPFLAGS_HAVE_FINALIZE
  #define Py_TPFLAGS_HAVE_FINALIZE 0
#endif
#if PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND)
  #define CYTHON_PEP393_ENABLED 1
  #define __Pyx_PyUnicode_READY(op)       (likely(PyUnicode_IS_READY(op)) ?\
                                              0 : _PyUnicode_Ready((PyObject *)(op)))
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_LENGTH(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i)
  #define __Pyx_PyUnicode_KIND(u)         PyUnicode_KIND(u)
  #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
#else
  #define CYTHON_PEP393_ENABLED 0
  #define __Pyx_PyUnicode_READY(op)       (0)
  #define __Pyx_PyUnicode_GET_LENGTH(u)   PyUnicode_GET_SIZE(u)
  #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i]))
  #define __Pyx_PyUnicode_KIND(u)         (sizeof(Py_UNICODE))
  #define __Pyx_PyUnicode_DATA(u)         ((void*)PyUnicode_AS_UNICODE(u))
  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
#endif
#if CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
#else
  #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
      PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
  #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
#endif
#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
#else
  #define __Pyx_PyString_Format(a, b)  PyString_Format(a, b)
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBaseString_Type            PyUnicode_Type
  #define PyStringObject               PyUnicodeObject
  #define PyString_Type                PyUnicode_Type
  #define PyString_Check               PyUnicode_Check
  #define PyString_CheckExact          PyUnicode_CheckExact
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
#else
  #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
#endif
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#if PY_MAJOR_VERSION >= 3
  #define PyIntObject                  PyLongObject
  #define PyInt_Type                   PyLong_Type
  #define PyInt_Check(op)              PyLong_Check(op)
  #define PyInt_CheckExact(op)         PyLong_CheckExact(op)
  #define PyInt_FromString             PyLong_FromString
  #define PyInt_FromUnicode            PyLong_FromUnicode
  #define PyInt_FromLong               PyLong_FromLong
  #define PyInt_FromSize_t             PyLong_FromSize_t
  #define PyInt_FromSsize_t            PyLong_FromSsize_t
  #define PyInt_AsLong                 PyLong_AsLong
  #define PyInt_AS_LONG                PyLong_AS_LONG
  #define PyInt_AsSsize_t              PyLong_AsSsize_t
  #define PyInt_AsUnsignedLongMask     PyLong_AsUnsignedLongMask
  #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
  #define PyNumber_Int                 PyNumber_Long
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  #ifndef PyUnicode_InternFromString
    #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  #endif
#endif
#if PY_VERSION_HEX < 0x030200A4
  typedef long Py_hash_t;
  #define __Pyx_PyInt_FromHash_t PyInt_FromLong
  #define __Pyx_PyInt_AsHash_t   PyInt_AsLong
#else
  #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t
  #define __Pyx_PyInt_AsHash_t   PyInt_AsSsize_t
#endif
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#else
  #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif
#if PY_VERSION_HEX >= 0x030500B1
#define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
#define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
#elif CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3
typedef struct {
    unaryfunc am_await;
    unaryfunc am_aiter;
    unaryfunc am_anext;
} __Pyx_PyAsyncMethodsStruct;
#define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
#else
#define __Pyx_PyType_AsAsync(obj) NULL
#endif
#ifndef CYTHON_RESTRICT
  #if defined(__GNUC__)
    #define CYTHON_RESTRICT __restrict__
  #elif defined(_MSC_VER) && _MSC_VER >= 1400
    #define CYTHON_RESTRICT __restrict
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_RESTRICT restrict
  #else
    #define CYTHON_RESTRICT
  #endif
#endif
#define __Pyx_void_to_None(void_result) (void_result, Py_INCREF(Py_None), Py_None)

#ifndef CYTHON_INLINE
  #if defined(__GNUC__)
    #define CYTHON_INLINE __inline__
  #elif defined(_MSC_VER)
    #define CYTHON_INLINE __inline
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_INLINE inline
  #else
    #define CYTHON_INLINE
  #endif
#endif

#if defined(WIN32) || defined(MS_WINDOWS)
  #define _USE_MATH_DEFINES
#endif
#include <math.h>
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
  float value;
  memset(&value, 0xFF, sizeof(value));
  return value;
}
#endif


#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
#endif

#ifndef __PYX_EXTERN_C
  #ifdef __cplusplus
    #define __PYX_EXTERN_C extern "C"
  #else
    #define __PYX_EXTERN_C extern
  #endif
#endif

#define __PYX_HAVE__dipy__tracking__distances
#define __PYX_HAVE_API__dipy__tracking__distances
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
#include "numpy/arrayobject.h"
#include "numpy/ufuncobject.h"
#include "dpy_math.h"
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif

#ifndef CYTHON_UNUSED
# if defined(__GNUC__)
#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
#     define CYTHON_UNUSED __attribute__ ((__unused__))
#   else
#     define CYTHON_UNUSED
#   endif
# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER))
#   define CYTHON_UNUSED __attribute__ ((__unused__))
# else
#   define CYTHON_UNUSED
# endif
#endif
#ifndef CYTHON_NCP_UNUSED
# if CYTHON_COMPILING_IN_CPYTHON
#  define CYTHON_NCP_UNUSED
# else
#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
# endif
#endif
typedef struct {PyObject **p; char *s; const Py_ssize_t n; const char* encoding;
                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;

#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0
#define __PYX_DEFAULT_STRING_ENCODING ""
#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#define __Pyx_uchar_cast(c) ((unsigned char)c)
#define __Pyx_long_cast(x) ((long)x)
#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (\
    (sizeof(type) < sizeof(Py_ssize_t))  ||\
    (sizeof(type) > sizeof(Py_ssize_t) &&\
          likely(v < (type)PY_SSIZE_T_MAX ||\
                 v == (type)PY_SSIZE_T_MAX)  &&\
          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
                                v == (type)PY_SSIZE_T_MIN)))  ||\
    (sizeof(type) == sizeof(Py_ssize_t) &&\
          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
                               v == (type)PY_SSIZE_T_MAX)))  )
#if defined (__cplusplus) && __cplusplus >= 201103L
    #include <cstdlib>
    #define __Pyx_sst_abs(value) std::abs(value)
#elif SIZEOF_INT >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) abs(value)
#elif SIZEOF_LONG >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) labs(value)
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define __Pyx_sst_abs(value) llabs(value)
#elif defined (_MSC_VER) && defined (_M_X64)
    #define __Pyx_sst_abs(value) _abs64(value)
#elif defined (__GNUC__)
    #define __Pyx_sst_abs(value) __builtin_llabs(value)
#else
    #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
#endif
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
#define __Pyx_PyBytes_FromString        PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
#if PY_MAJOR_VERSION < 3
    #define __Pyx_PyStr_FromString        __Pyx_PyBytes_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#else
    #define __Pyx_PyStr_FromString        __Pyx_PyUnicode_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
#endif
#define __Pyx_PyObject_AsSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_FromCString(s)  __Pyx_PyObject_FromString((const char*)s)
#define __Pyx_PyBytes_FromCString(s)   __Pyx_PyBytes_FromString((const char*)s)
#define __Pyx_PyByteArray_FromCString(s)   __Pyx_PyByteArray_FromString((const char*)s)
#define __Pyx_PyStr_FromCString(s)     __Pyx_PyStr_FromString((const char*)s)
#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
#if PY_MAJOR_VERSION < 3
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
{
    const Py_UNICODE *u_end = u;
    while (*u_end++) ;
    return (size_t)(u_end - u - 1);
}
#else
#define __Pyx_Py_UNICODE_strlen Py_UNICODE_strlen
#endif
#define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
#define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
#define __Pyx_PyBool_FromLong(b) ((b) ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x);
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
#if CYTHON_COMPILING_IN_CPYTHON
#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x))
#else
#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x)
#endif
#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x))
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
static int __Pyx_sys_getdefaultencoding_not_ascii;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    PyObject* ascii_chars_u = NULL;
    PyObject* ascii_chars_b = NULL;
    const char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    if (strcmp(default_encoding_c, "ascii") == 0) {
        __Pyx_sys_getdefaultencoding_not_ascii = 0;
    } else {
        char ascii_chars[128];
        int c;
        for (c = 0; c < 128; c++) {
            ascii_chars[c] = c;
        }
        __Pyx_sys_getdefaultencoding_not_ascii = 1;
        ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
        if (!ascii_chars_u) goto bad;
        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
        if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
            PyErr_Format(
                PyExc_ValueError,
                "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
                default_encoding_c);
            goto bad;
        }
        Py_DECREF(ascii_chars_u);
        Py_DECREF(ascii_chars_b);
    }
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    Py_XDECREF(ascii_chars_u);
    Py_XDECREF(ascii_chars_b);
    return -1;
}
#endif
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
#else
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
static char* __PYX_DEFAULT_STRING_ENCODING;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c));
    if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
    strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    return -1;
}
#endif
#endif


/* Test for GCC > 2.95 */
#if defined(__GNUC__)     && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
  #define likely(x)   __builtin_expect(!!(x), 1)
  #define unlikely(x) __builtin_expect(!!(x), 0)
#else /* !__GNUC__ or GCC < 2.95 */
  #define likely(x)   (x)
  #define unlikely(x) (x)
#endif /* __GNUC__ */

static PyObject *__pyx_m;
static PyObject *__pyx_d;
static PyObject *__pyx_b;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;

#if !defined(CYTHON_CCOMPLEX)
  #if defined(__cplusplus)
    #define CYTHON_CCOMPLEX 1
  #elif defined(_Complex_I)
    #define CYTHON_CCOMPLEX 1
  #else
    #define CYTHON_CCOMPLEX 0
  #endif
#endif
#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    #include <complex>
  #else
    #include <complex.h>
  #endif
#endif
#if CYTHON_CCOMPLEX && !defined(__cplusplus) && defined(__sun__) && defined(__GNUC__)
  #undef _Complex_I
  #define _Complex_I 1.0fj
#endif


static const char *__pyx_f[] = {
  "dipy/tracking/distances.pyx",
  "__init__.pxd",
  "type.pxd",
};
#define IS_UNSIGNED(type) (((type) -1) > 0)
struct __Pyx_StructField_;
#define __PYX_BUF_FLAGS_PACKED_STRUCT (1 << 0)
typedef struct {
  const char* name;
  struct __Pyx_StructField_* fields;
  size_t size;
  size_t arraysize[8];
  int ndim;
  char typegroup;
  char is_unsigned;
  int flags;
} __Pyx_TypeInfo;
typedef struct __Pyx_StructField_ {
  __Pyx_TypeInfo* type;
  const char* name;
  size_t offset;
} __Pyx_StructField;
typedef struct {
  __Pyx_StructField* field;
  size_t parent_offset;
} __Pyx_BufFmt_StackElem;
typedef struct {
  __Pyx_StructField root;
  __Pyx_BufFmt_StackElem* head;
  size_t fmt_offset;
  size_t new_count, enc_count;
  size_t struct_alignment;
  int is_complex;
  char enc_type;
  char new_packmode;
  char enc_packmode;
  char is_valid_array;
} __Pyx_BufFmt_Context;


/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":725
 * # in Cython to enable them only on the right systems.
 * 
 * ctypedef npy_int8       int8_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t
 */
typedef npy_int8 __pyx_t_5numpy_int8_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":726
 * 
 * ctypedef npy_int8       int8_t
 * ctypedef npy_int16      int16_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int32      int32_t
 * ctypedef npy_int64      int64_t
 */
typedef npy_int16 __pyx_t_5numpy_int16_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":727
 * ctypedef npy_int8       int8_t
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_int64      int64_t
 * #ctypedef npy_int96      int96_t
 */
typedef npy_int32 __pyx_t_5numpy_int32_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":728
 * ctypedef npy_int16      int16_t
 * ctypedef npy_int32      int32_t
 * ctypedef npy_int64      int64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_int96      int96_t
 * #ctypedef npy_int128     int128_t
 */
typedef npy_int64 __pyx_t_5numpy_int64_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":732
 * #ctypedef npy_int128     int128_t
 * 
 * ctypedef npy_uint8      uint8_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t
 */
typedef npy_uint8 __pyx_t_5numpy_uint8_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":733
 * 
 * ctypedef npy_uint8      uint8_t
 * ctypedef npy_uint16     uint16_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint32     uint32_t
 * ctypedef npy_uint64     uint64_t
 */
typedef npy_uint16 __pyx_t_5numpy_uint16_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":734
 * ctypedef npy_uint8      uint8_t
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uint64     uint64_t
 * #ctypedef npy_uint96     uint96_t
 */
typedef npy_uint32 __pyx_t_5numpy_uint32_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":735
 * ctypedef npy_uint16     uint16_t
 * ctypedef npy_uint32     uint32_t
 * ctypedef npy_uint64     uint64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_uint96     uint96_t
 * #ctypedef npy_uint128    uint128_t
 */
typedef npy_uint64 __pyx_t_5numpy_uint64_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":739
 * #ctypedef npy_uint128    uint128_t
 * 
 * ctypedef npy_float32    float32_t             # <<<<<<<<<<<<<<
 * ctypedef npy_float64    float64_t
 * #ctypedef npy_float80    float80_t
 */
typedef npy_float32 __pyx_t_5numpy_float32_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":740
 * 
 * ctypedef npy_float32    float32_t
 * ctypedef npy_float64    float64_t             # <<<<<<<<<<<<<<
 * #ctypedef npy_float80    float80_t
 * #ctypedef npy_float128   float128_t
 */
typedef npy_float64 __pyx_t_5numpy_float64_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":749
 * # The int types are mapped a bit surprising --
 * # numpy.int corresponds to 'l' and numpy.long to 'q'
 * ctypedef npy_long       int_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longlong   long_t
 * ctypedef npy_longlong   longlong_t
 */
typedef npy_long __pyx_t_5numpy_int_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":750
 * # numpy.int corresponds to 'l' and numpy.long to 'q'
 * ctypedef npy_long       int_t
 * ctypedef npy_longlong   long_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longlong   longlong_t
 * 
 */
typedef npy_longlong __pyx_t_5numpy_long_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":751
 * ctypedef npy_long       int_t
 * ctypedef npy_longlong   long_t
 * ctypedef npy_longlong   longlong_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_ulong      uint_t
 */
typedef npy_longlong __pyx_t_5numpy_longlong_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":753
 * ctypedef npy_longlong   longlong_t
 * 
 * ctypedef npy_ulong      uint_t             # <<<<<<<<<<<<<<
 * ctypedef npy_ulonglong  ulong_t
 * ctypedef npy_ulonglong  ulonglong_t
 */
typedef npy_ulong __pyx_t_5numpy_uint_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":754
 * 
 * ctypedef npy_ulong      uint_t
 * ctypedef npy_ulonglong  ulong_t             # <<<<<<<<<<<<<<
 * ctypedef npy_ulonglong  ulonglong_t
 * 
 */
typedef npy_ulonglong __pyx_t_5numpy_ulong_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":755
 * ctypedef npy_ulong      uint_t
 * ctypedef npy_ulonglong  ulong_t
 * ctypedef npy_ulonglong  ulonglong_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_intp       intp_t
 */
typedef npy_ulonglong __pyx_t_5numpy_ulonglong_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":757
 * ctypedef npy_ulonglong  ulonglong_t
 * 
 * ctypedef npy_intp       intp_t             # <<<<<<<<<<<<<<
 * ctypedef npy_uintp      uintp_t
 * 
 */
typedef npy_intp __pyx_t_5numpy_intp_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":758
 * 
 * ctypedef npy_intp       intp_t
 * ctypedef npy_uintp      uintp_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_double     float_t
 */
typedef npy_uintp __pyx_t_5numpy_uintp_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":760
 * ctypedef npy_uintp      uintp_t
 * 
 * ctypedef npy_double     float_t             # <<<<<<<<<<<<<<
 * ctypedef npy_double     double_t
 * ctypedef npy_longdouble longdouble_t
 */
typedef npy_double __pyx_t_5numpy_float_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":761
 * 
 * ctypedef npy_double     float_t
 * ctypedef npy_double     double_t             # <<<<<<<<<<<<<<
 * ctypedef npy_longdouble longdouble_t
 * 
 */
typedef npy_double __pyx_t_5numpy_double_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":762
 * ctypedef npy_double     float_t
 * ctypedef npy_double     double_t
 * ctypedef npy_longdouble longdouble_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_cfloat      cfloat_t
 */
typedef npy_longdouble __pyx_t_5numpy_longdouble_t;
#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    typedef ::std::complex< float > __pyx_t_float_complex;
  #else
    typedef float _Complex __pyx_t_float_complex;
  #endif
#else
    typedef struct { float real, imag; } __pyx_t_float_complex;
#endif

#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    typedef ::std::complex< double > __pyx_t_double_complex;
  #else
    typedef double _Complex __pyx_t_double_complex;
  #endif
#else
    typedef struct { double real, imag; } __pyx_t_double_complex;
#endif


/*--- Type declarations ---*/

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":764
 * ctypedef npy_longdouble longdouble_t
 * 
 * ctypedef npy_cfloat      cfloat_t             # <<<<<<<<<<<<<<
 * ctypedef npy_cdouble     cdouble_t
 * ctypedef npy_clongdouble clongdouble_t
 */
typedef npy_cfloat __pyx_t_5numpy_cfloat_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":765
 * 
 * ctypedef npy_cfloat      cfloat_t
 * ctypedef npy_cdouble     cdouble_t             # <<<<<<<<<<<<<<
 * ctypedef npy_clongdouble clongdouble_t
 * 
 */
typedef npy_cdouble __pyx_t_5numpy_cdouble_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":766
 * ctypedef npy_cfloat      cfloat_t
 * ctypedef npy_cdouble     cdouble_t
 * ctypedef npy_clongdouble clongdouble_t             # <<<<<<<<<<<<<<
 * 
 * ctypedef npy_cdouble     complex_t
 */
typedef npy_clongdouble __pyx_t_5numpy_clongdouble_t;

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":768
 * ctypedef npy_clongdouble clongdouble_t
 * 
 * ctypedef npy_cdouble     complex_t             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew1(a):
 */
typedef npy_cdouble __pyx_t_5numpy_complex_t;
struct __pyx_t_4dipy_8tracking_9distances_LSC_Cluster;
typedef struct __pyx_t_4dipy_8tracking_9distances_LSC_Cluster __pyx_t_4dipy_8tracking_9distances_LSC_Cluster;

/* "dipy/tracking/distances.pyx":1460
 * 
 * 
 * ctypedef struct LSC_Cluster:             # <<<<<<<<<<<<<<
 *     long *indices
 *     float *hidden
 */
struct __pyx_t_4dipy_8tracking_9distances_LSC_Cluster {
  long *indices;
  float *hidden;
  long N;
};

/* --- Runtime support code (head) --- */
#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif
#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
  #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#ifdef WITH_THREAD
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          if (acquire_gil) {\
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
              PyGILState_Release(__pyx_gilstate_save);\
          } else {\
              __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__);\
          }
#else
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), __LINE__, __FILE__)
#endif
  #define __Pyx_RefNannyFinishContext()\
          __Pyx_RefNanny->FinishContext(&__pyx_refnanny)
  #define __Pyx_INCREF(r)  __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_DECREF(r)  __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GOTREF(r)  __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), __LINE__)
  #define __Pyx_XINCREF(r)  do { if((r) != NULL) {__Pyx_INCREF(r); }} while(0)
  #define __Pyx_XDECREF(r)  do { if((r) != NULL) {__Pyx_DECREF(r); }} while(0)
  #define __Pyx_XGOTREF(r)  do { if((r) != NULL) {__Pyx_GOTREF(r); }} while(0)
  #define __Pyx_XGIVEREF(r) do { if((r) != NULL) {__Pyx_GIVEREF(r);}} while(0)
#else
  #define __Pyx_RefNannyDeclarations
  #define __Pyx_RefNannySetupContext(name, acquire_gil)
  #define __Pyx_RefNannyFinishContext()
  #define __Pyx_INCREF(r) Py_INCREF(r)
  #define __Pyx_DECREF(r) Py_DECREF(r)
  #define __Pyx_GOTREF(r)
  #define __Pyx_GIVEREF(r)
  #define __Pyx_XINCREF(r) Py_XINCREF(r)
  #define __Pyx_XDECREF(r) Py_XDECREF(r)
  #define __Pyx_XGOTREF(r)
  #define __Pyx_XGIVEREF(r)
#endif
#define __Pyx_XDECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_XDECREF(tmp);\
    } while (0)
#define __Pyx_DECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_DECREF(tmp);\
    } while (0)
#define __Pyx_CLEAR(r)    do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0)
#define __Pyx_XCLEAR(r)   do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0)

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro))
        return tp->tp_getattro(obj, attr_name);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_getattr))
        return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
#endif
    return PyObject_GetAttr(obj, attr_name);
}
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif

static PyObject *__Pyx_GetBuiltinName(PyObject *name);

static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name);

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
#else
#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
#endif

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
#endif

static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);

static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type);

static CYTHON_INLINE int  __Pyx_GetBufferAndValidate(Py_buffer* buf, PyObject* obj,
    __Pyx_TypeInfo* dtype, int flags, int nd, int cast, __Pyx_BufFmt_StackElem* stack);
static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info);

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb);
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb);

static void __Pyx_WriteUnraisable(const char *name, int clineno,
                                  int lineno, const char *filename,
                                  int full_traceback, int nogil);

static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
    Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found);

static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);

static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
    const char* function_name);

static void __Pyx_RaiseBufferFallbackError(void);

#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\
    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\
               __Pyx_GetItemInt_Generic(o, to_py_func(i))))
#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
                                                     int is_list, int wraparound, int boundscheck);

static void __Pyx_RaiseBufferIndexError(int axis);

#define __Pyx_BufPtrStrided1d(type, buf, i0, s0) (type)((char*)buf + i0 * s0)
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
    PyListObject* L = (PyListObject*) list;
    Py_ssize_t len = Py_SIZE(list);
    if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) {
        Py_INCREF(x);
        PyList_SET_ITEM(list, len, x);
        Py_SIZE(list) = len+1;
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
#endif

static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg);

static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x);

#define __Pyx_SetItemInt(o, i, v, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_SetItemInt_Fast(o, (Py_ssize_t)i, v, is_list, wraparound, boundscheck) :\
    (is_list ? (PyErr_SetString(PyExc_IndexError, "list assignment index out of range"), -1) :\
               __Pyx_SetItemInt_Generic(o, to_py_func(i), v)))
static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v);
static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v,
                                               int is_list, int wraparound, int boundscheck);

static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(
        PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
        int has_cstart, int has_cstop, int wraparound);

#include <string.h>

static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals);

static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals);

#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals
#else
#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals
#endif

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);

#define __Pyx_BufPtrStrided2d(type, buf, i0, s0, i1, s1) (type)((char*)buf + i0 * s0 + i1 * s1)
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
    PyObject *value;
    value = PyDict_GetItemWithError(d, key);
    if (unlikely(!value)) {
        if (!PyErr_Occurred()) {
            PyObject* args = PyTuple_Pack(1, key);
            if (likely(args))
                PyErr_SetObject(PyExc_KeyError, args);
            Py_XDECREF(args);
        }
        return NULL;
    }
    Py_INCREF(value);
    return value;
}
#else
    #define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
#endif

#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o,n,NULL)
static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_setattro))
        return tp->tp_setattro(obj, attr_name, value);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_setattr))
        return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value);
#endif
    return PyObject_SetAttr(obj, attr_name, value);
}
#else
#define __Pyx_PyObject_DelAttrStr(o,n)   PyObject_DelAttr(o,n)
#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v)
#endif

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
#else
#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
#endif

static CYTHON_INLINE PyObject* __Pyx_PyDict_Keys(PyObject* d);

typedef struct {
    PyObject *type;
    PyObject **method_name;
    PyCFunction func;
    PyObject *method;
    int flag;
} __Pyx_CachedCFunction;

static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self);
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_CallUnboundCMethod0(cfunc, self)\
    ((likely((cfunc)->func)) ?\
        (likely((cfunc)->flag == METH_NOARGS) ?  (*((cfunc)->func))(self, NULL) :\
         (likely((cfunc)->flag == (METH_VARARGS | METH_KEYWORDS)) ?  ((*(PyCFunctionWithKeywords)(cfunc)->func)(self, __pyx_empty_tuple, NULL)) :\
             ((cfunc)->flag == METH_VARARGS ?  (*((cfunc)->func))(self, __pyx_empty_tuple) : __Pyx__CallUnboundCMethod0(cfunc, self)))) :\
        __Pyx__CallUnboundCMethod0(cfunc, self))
#else
#define __Pyx_CallUnboundCMethod0(cfunc, self)  __Pyx__CallUnboundCMethod0(cfunc, self)
#endif

#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_EqObjC(op1, op2, intval, inplace)\
    PyObject_RichCompare(op1, op2, Py_EQ)
    #endif

#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

#define __Pyx_DelItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_DelItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound) :\
    (is_list ? (PyErr_SetString(PyExc_IndexError, "list assignment index out of range"), -1) :\
               __Pyx_DelItem_Generic(o, to_py_func(i))))
static CYTHON_INLINE int __Pyx_DelItem_Generic(PyObject *o, PyObject *j);
static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i,
                                               int is_list, int wraparound);

static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact);

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);

typedef struct {
    int code_line;
    PyCodeObject* code_object;
} __Pyx_CodeObjectCacheEntry;
struct __Pyx_CodeObjectCache {
    int count;
    int max_count;
    __Pyx_CodeObjectCacheEntry* entries;
};
static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL};
static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line);
static PyCodeObject *__pyx_find_code_object(int code_line);
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object);

static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename);

typedef struct {
  Py_ssize_t shape, strides, suboffsets;
} __Pyx_Buf_DimInfo;
typedef struct {
  size_t refcount;
  Py_buffer pybuffer;
} __Pyx_Buffer;
typedef struct {
  __Pyx_Buffer *rcbuffer;
  char *data;
  __Pyx_Buf_DimInfo diminfo[8];
} __Pyx_LocalBuf_ND;

#if PY_MAJOR_VERSION < 3
    static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags);
    static void __Pyx_ReleaseBuffer(Py_buffer *view);
#else
    #define __Pyx_GetBuffer PyObject_GetBuffer
    #define __Pyx_ReleaseBuffer PyBuffer_Release
#endif


static Py_ssize_t __Pyx_zeros[] = {0, 0, 0, 0, 0, 0, 0, 0};
static Py_ssize_t __Pyx_minusones[] = {-1, -1, -1, -1, -1, -1, -1, -1};

static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);

static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);

static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);

#ifndef __PYX_FORCE_INIT_THREADS
  #define __PYX_FORCE_INIT_THREADS 0
#endif

#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    #define __Pyx_CREAL(z) ((z).real())
    #define __Pyx_CIMAG(z) ((z).imag())
  #else
    #define __Pyx_CREAL(z) (__real__(z))
    #define __Pyx_CIMAG(z) (__imag__(z))
  #endif
#else
    #define __Pyx_CREAL(z) ((z).real)
    #define __Pyx_CIMAG(z) ((z).imag)
#endif
#if (defined(_WIN32) || defined(__clang__)) && defined(__cplusplus) && CYTHON_CCOMPLEX
    #define __Pyx_SET_CREAL(z,x) ((z).real(x))
    #define __Pyx_SET_CIMAG(z,y) ((z).imag(y))
#else
    #define __Pyx_SET_CREAL(z,x) __Pyx_CREAL(z) = (x)
    #define __Pyx_SET_CIMAG(z,y) __Pyx_CIMAG(z) = (y)
#endif

static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float, float);

#if CYTHON_CCOMPLEX
    #define __Pyx_c_eqf(a, b)   ((a)==(b))
    #define __Pyx_c_sumf(a, b)  ((a)+(b))
    #define __Pyx_c_difff(a, b) ((a)-(b))
    #define __Pyx_c_prodf(a, b) ((a)*(b))
    #define __Pyx_c_quotf(a, b) ((a)/(b))
    #define __Pyx_c_negf(a)     (-(a))
  #ifdef __cplusplus
    #define __Pyx_c_is_zerof(z) ((z)==(float)0)
    #define __Pyx_c_conjf(z)    (::std::conj(z))
    #if 1
        #define __Pyx_c_absf(z)     (::std::abs(z))
        #define __Pyx_c_powf(a, b)  (::std::pow(a, b))
    #endif
  #else
    #define __Pyx_c_is_zerof(z) ((z)==0)
    #define __Pyx_c_conjf(z)    (conjf(z))
    #if 1
        #define __Pyx_c_absf(z)     (cabsf(z))
        #define __Pyx_c_powf(a, b)  (cpowf(a, b))
    #endif
 #endif
#else
    static CYTHON_INLINE int __Pyx_c_eqf(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_complex, __pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_complex);
    static CYTHON_INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex);
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_complex);
    #if 1
        static CYTHON_INLINE float __Pyx_c_absf(__pyx_t_float_complex);
        static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_powf(__pyx_t_float_complex, __pyx_t_float_complex);
    #endif
#endif

static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double, double);

#if CYTHON_CCOMPLEX
    #define __Pyx_c_eq(a, b)   ((a)==(b))
    #define __Pyx_c_sum(a, b)  ((a)+(b))
    #define __Pyx_c_diff(a, b) ((a)-(b))
    #define __Pyx_c_prod(a, b) ((a)*(b))
    #define __Pyx_c_quot(a, b) ((a)/(b))
    #define __Pyx_c_neg(a)     (-(a))
  #ifdef __cplusplus
    #define __Pyx_c_is_zero(z) ((z)==(double)0)
    #define __Pyx_c_conj(z)    (::std::conj(z))
    #if 1
        #define __Pyx_c_abs(z)     (::std::abs(z))
        #define __Pyx_c_pow(a, b)  (::std::pow(a, b))
    #endif
  #else
    #define __Pyx_c_is_zero(z) ((z)==0)
    #define __Pyx_c_conj(z)    (conj(z))
    #if 1
        #define __Pyx_c_abs(z)     (cabs(z))
        #define __Pyx_c_pow(a, b)  (cpow(a, b))
    #endif
 #endif
#else
    static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex, __pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex);
    static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex);
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex);
    #if 1
        static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex);
        static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow(__pyx_t_double_complex, __pyx_t_double_complex);
    #endif
#endif

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum__NPY_TYPES(enum NPY_TYPES value);

static int __Pyx_check_binary_version(void);

#if !defined(__Pyx_PyIdentifier_FromString)
#if PY_MAJOR_VERSION < 3
  #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
#else
  #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
#endif
#endif

static PyObject *__Pyx_ImportModule(const char *name);

static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict);

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);


/* Module declarations from 'cython' */

/* Module declarations from 'cpython.buffer' */

/* Module declarations from 'libc.string' */

/* Module declarations from 'libc.stdio' */

/* Module declarations from '__builtin__' */

/* Module declarations from 'cpython.type' */
static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0;

/* Module declarations from 'cpython' */

/* Module declarations from 'cpython.object' */

/* Module declarations from 'cpython.ref' */

/* Module declarations from 'libc.stdlib' */

/* Module declarations from 'numpy' */

/* Module declarations from 'numpy' */
static PyTypeObject *__pyx_ptype_5numpy_dtype = 0;
static PyTypeObject *__pyx_ptype_5numpy_flatiter = 0;
static PyTypeObject *__pyx_ptype_5numpy_broadcast = 0;
static PyTypeObject *__pyx_ptype_5numpy_ndarray = 0;
static PyTypeObject *__pyx_ptype_5numpy_ufunc = 0;
static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *, char *, char *, int *); /*proto*/

/* Module declarations from 'dipy.tracking.distances' */
static PyArray_Descr *__pyx_v_4dipy_8tracking_9distances_f32_dt = 0;
static __pyx_t_5numpy_float32_t __pyx_v_4dipy_8tracking_9distances_inf;
static CYTHON_INLINE PyArrayObject *__pyx_f_4dipy_8tracking_9distances_as_float_3vec(PyObject *); /*proto*/
static CYTHON_INLINE float *__pyx_f_4dipy_8tracking_9distances_asfp(PyArrayObject *); /*proto*/
static CYTHON_INLINE float __pyx_f_4dipy_8tracking_9distances_cnorm_3vec(float *); /*proto*/
static CYTHON_INLINE void __pyx_f_4dipy_8tracking_9distances_cnormalized_3vec(float *, float *); /*proto*/
static CYTHON_INLINE float __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(float *, float *); /*proto*/
static CYTHON_INLINE void __pyx_f_4dipy_8tracking_9distances_csub_3vecs(float *, float *, float *); /*proto*/
static CYTHON_INLINE void __pyx_f_4dipy_8tracking_9distances_cadd_3vecs(float *, float *, float *); /*proto*/
static CYTHON_INLINE void __pyx_f_4dipy_8tracking_9distances_cmul_3vecs(float *, float *, float *); /*proto*/
static CYTHON_INLINE void __pyx_f_4dipy_8tracking_9distances_cmul_3vec(float, float *, float *); /*proto*/
static CYTHON_INLINE __pyx_t_5numpy_float32_t __pyx_f_4dipy_8tracking_9distances_czhang(size_t, __pyx_t_5numpy_float32_t *, size_t, __pyx_t_5numpy_float32_t *, __pyx_t_5numpy_float32_t *, int); /*proto*/
static CYTHON_INLINE void __pyx_f_4dipy_8tracking_9distances_min_distances(size_t, __pyx_t_5numpy_float32_t *, size_t, __pyx_t_5numpy_float32_t *, __pyx_t_5numpy_float32_t *, __pyx_t_5numpy_float32_t *); /*proto*/
static float __pyx_f_4dipy_8tracking_9distances_clee_perpendicular_distance(float *, float *, float *, float *); /*proto*/
static float __pyx_f_4dipy_8tracking_9distances_clee_angle_distance(float *, float *, float *, float *); /*proto*/
static float __pyx_f_4dipy_8tracking_9distances_cintersect_segment_cylinder(float *, float *, float *, float *, float, float *); /*proto*/
static CYTHON_INLINE float __pyx_f_4dipy_8tracking_9distances_cpoint_segment_sq_dist(float *, float *, float *); /*proto*/
static void __pyx_f_4dipy_8tracking_9distances_track_direct_flip_dist(float *, float *, long, float *); /*proto*/
static CYTHON_INLINE void __pyx_f_4dipy_8tracking_9distances_track_direct_flip_3dist(float *, float *, float *, float *, float *, float *, float *); /*proto*/
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t = { "float32_t", NULL, sizeof(__pyx_t_5numpy_float32_t), { 0 }, 0, 'R', 0, 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_uint64_t = { "uint64_t", NULL, sizeof(__pyx_t_5numpy_uint64_t), { 0 }, 0, IS_UNSIGNED(__pyx_t_5numpy_uint64_t) ? 'U' : 'I', IS_UNSIGNED(__pyx_t_5numpy_uint64_t), 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_object = { "Python object", NULL, sizeof(PyObject *), { 0 }, 0, 'O', 0, 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_nn___pyx_t_5numpy_double_t = { "double_t", NULL, sizeof(__pyx_t_5numpy_double_t), { 0 }, 0, 'R', 0, 0 };
static __Pyx_TypeInfo __Pyx_TypeInfo_float = { "float", NULL, sizeof(float), { 0 }, 0, 'R', 0, 0 };
#define __Pyx_MODULE_NAME "dipy.tracking.distances"
int __pyx_module_is_main_dipy__tracking__distances = 0;

/* Implementation of 'dipy.tracking.distances' */
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_object;
static PyObject *__pyx_builtin_RuntimeError;
static char __pyx_k_B[] = "B";
static char __pyx_k_C[] = "C";
static char __pyx_k_H[] = "H";
static char __pyx_k_I[] = "I";
static char __pyx_k_L[] = "L";
static char __pyx_k_N[] = "N";
static char __pyx_k_O[] = "O";
static char __pyx_k_Q[] = "Q";
static char __pyx_k_a[] = "a";
static char __pyx_k_b[] = "b";
static char __pyx_k_c[] = "c";
static char __pyx_k_d[] = "d";
static char __pyx_k_f[] = "f";
static char __pyx_k_g[] = "g";
static char __pyx_k_h[] = "h";
static char __pyx_k_i[] = "i";
static char __pyx_k_j[] = "j";
static char __pyx_k_k[] = "k";
static char __pyx_k_l[] = "l";
static char __pyx_k_p[] = "p";
static char __pyx_k_q[] = "q";
static char __pyx_k_r[] = "r";
static char __pyx_k_t[] = "t";
static char __pyx_k_C2[] = "C2";
static char __pyx_k_DM[] = "DM";
static char __pyx_k_Zd[] = "Zd";
static char __pyx_k_Zf[] = "Zf";
static char __pyx_k_Zg[] = "Zg";
static char __pyx_k_ca[] = "ca";
static char __pyx_k_cb[] = "cb";
static char __pyx_k_cc[] = "cc";
static char __pyx_k_ch[] = "ch";
static char __pyx_k_cp[] = "cp";
static char __pyx_k_cq[] = "cq";
static char __pyx_k_cr[] = "cr";
static char __pyx_k_ct[] = "ct";
static char __pyx_k_it[] = "it";
static char __pyx_k_ld[] = "ld";
static char __pyx_k_mn[] = "mn";
static char __pyx_k_np[] = "np";
static char __pyx_k_sa[] = "sa";
static char __pyx_k_sb[] = "sb";
static char __pyx_k_si[] = "si";
static char __pyx_k_t1[] = "t1";
static char __pyx_k_t2[] = "t2";
static char __pyx_k_ts[] = "ts";
static char __pyx_k_Hit[] = "Hit";
static char __pyx_k_all[] = "all";
static char __pyx_k_avg[] = "avg";
static char __pyx_k_cit[] = "cit";
static char __pyx_k_csa[] = "csa";
static char __pyx_k_csb[] = "csb";
static char __pyx_k_dim[] = "dim";
static char __pyx_k_hid[] = "hid";
static char __pyx_k_hit[] = "hit";
static char __pyx_k_i_k[] = "i_k";
static char __pyx_k_inf[] = "inf";
static char __pyx_k_lhp[] = "lhp";
static char __pyx_k_lrq[] = "lrq";
static char __pyx_k_m_d[] = "m_d";
static char __pyx_k_m_k[] = "m_k";
static char __pyx_k_max[] = "max";
static char __pyx_k_min[] = "min";
static char __pyx_k_pMq[] = "pMq";
static char __pyx_k_ptr[] = "ptr";
static char __pyx_k_qMp[] = "qMp";
static char __pyx_k_rMp[] = "rMp";
static char __pyx_k_rMq[] = "rMq";
static char __pyx_k_rcd[] = "rcd";
static char __pyx_k_ref[] = "ref";
static char __pyx_k_roi[] = "roi";
static char __pyx_k_thr[] = "thr";
static char __pyx_k_tmp[] = "tmp";
static char __pyx_k_vec[] = "vec";
static char __pyx_k_xyz[] = "xyz";
static char __pyx_k_alld[] = "alld";
static char __pyx_k_beta[] = "beta";
static char __pyx_k_copy[] = "copy";
static char __pyx_k_curr[] = "curr";
static char __pyx_k_dist[] = "dist";
static char __pyx_k_end0[] = "end0";
static char __pyx_k_end1[] = "end1";
static char __pyx_k_flip[] = "flip";
static char __pyx_k_fvec[] = "fvec";
static char __pyx_k_hits[] = "hits";
static char __pyx_k_keys[] = "keys";
static char __pyx_k_klen[] = "klen";
static char __pyx_k_lenC[] = "lenC";
static char __pyx_k_lent[] = "lent";
static char __pyx_k_main[] = "__main__";
static char __pyx_k_p_no[] = "p_no";
static char __pyx_k_q_no[] = "q_no";
static char __pyx_k_rep3[] = "rep3";
static char __pyx_k_rlen[] = "rlen";
static char __pyx_k_rows[] = "rows";
static char __pyx_k_t_no[] = "t_no";
static char __pyx_k_test[] = "__test__";
static char __pyx_k_time[] = "time";
static char __pyx_k_tlen[] = "tlen";
static char __pyx_k_vec0[] = "vec0";
static char __pyx_k_vec1[] = "vec1";
static char __pyx_k_vec2[] = "vec2";
static char __pyx_k_xyz1[] = "xyz1";
static char __pyx_k_xyz2[] = "xyz2";
static char __pyx_k_N_ref[] = "N_ref";
static char __pyx_k_along[] = "along";
static char __pyx_k_alpha[] = "alpha";
static char __pyx_k_angle[] = "angle";
static char __pyx_k_array[] = "array";
static char __pyx_k_currp[] = "currp";
static char __pyx_k_d_thr[] = "d_thr";
static char __pyx_k_delta[] = "delta";
static char __pyx_k_dtype[] = "dtype";
static char __pyx_k_empty[] = "empty";
static char __pyx_k_fvec0[] = "fvec0";
static char __pyx_k_fvec1[] = "fvec1";
static char __pyx_k_fvec2[] = "fvec2";
static char __pyx_k_fvec3[] = "fvec3";
static char __pyx_k_fvec4[] = "fvec4";
static char __pyx_k_hitMp[] = "hitMp";
static char __pyx_k_int64[] = "int64";
static char __pyx_k_lentA[] = "lentA";
static char __pyx_k_lentB[] = "lentB";
static char __pyx_k_numpy[] = "numpy";
static char __pyx_k_point[] = "point";
static char __pyx_k_range[] = "range";
static char __pyx_k_ref32[] = "ref32";
static char __pyx_k_shape[] = "shape";
static char __pyx_k_t1_pi[] = "t1_pi";
static char __pyx_k_t2_pi[] = "t2_pi";
static char __pyx_k_t_len[] = "t_len";
static char __pyx_k_track[] = "track";
static char __pyx_k_zeros[] = "zeros";
static char __pyx_k_alphac[] = "alphac";
static char __pyx_k_append[] = "append";
static char __pyx_k_argmin[] = "argmin";
static char __pyx_k_cd_thr[] = "cd_thr";
static char __pyx_k_double[] = "double";
static char __pyx_k_hidden[] = "hidden";
static char __pyx_k_hit_no[] = "hit_no";
static char __pyx_k_import[] = "__import__";
static char __pyx_k_krange[] = "krange";
static char __pyx_k_length[] = "length";
static char __pyx_k_metric[] = "metric";
static char __pyx_k_n_hits[] = "n_hits";
static char __pyx_k_normal[] = "normal";
static char __pyx_k_object[] = "object";
static char __pyx_k_points[] = "points";
static char __pyx_k_start0[] = "start0";
static char __pyx_k_start1[] = "start1";
static char __pyx_k_t1_len[] = "t1_len";
static char __pyx_k_t1_ptr[] = "t1_ptr";
static char __pyx_k_t2_len[] = "t2_len";
static char __pyx_k_t2_ptr[] = "t2_ptr";
static char __pyx_k_track1[] = "track1";
static char __pyx_k_track2[] = "track2";
static char __pyx_k_tracka[] = "tracka";
static char __pyx_k_trackb[] = "trackb";
static char __pyx_k_tracks[] = "tracks";
static char __pyx_k_uint64[] = "uint64";
static char __pyx_k_vec_in[] = "vec_in";
static char __pyx_k_N_track[] = "N_track";
static char __pyx_k_asarray[] = "asarray";
static char __pyx_k_cluster[] = "cluster";
static char __pyx_k_float32[] = "float32";
static char __pyx_k_hit_arr[] = "hit_arr";
static char __pyx_k_hit_ptr[] = "hit_ptr";
static char __pyx_k_indices[] = "indices";
static char __pyx_k_itrange[] = "itrange";
static char __pyx_k_one_hit[] = "one_hit";
static char __pyx_k_squeeze[] = "squeeze";
static char __pyx_k_tracksA[] = "tracksA";
static char __pyx_k_tracksB[] = "tracksB";
static char __pyx_k_vec_out[] = "vec_out";
static char __pyx_k_N_tracks[] = "N_tracks";
static char __pyx_k_cost_par[] = "cost_par";
static char __pyx_k_distance[] = "distance";
static char __pyx_k_min_t1t2[] = "min_t1t2";
static char __pyx_k_min_t2t1[] = "min_t2t1";
static char __pyx_k_mul_3vec[] = "mul_3vec";
static char __pyx_k_tracks32[] = "tracks32";
static char __pyx_k_add_3vecs[] = "add_3vecs";
static char __pyx_k_cut_plane[] = "cut_plane";
static char __pyx_k_mean_t1t2[] = "mean_t1t2";
static char __pyx_k_mean_t2t1[] = "mean_t2t1";
static char __pyx_k_mid_index[] = "mid_index";
static char __pyx_k_mul_3vecs[] = "mul_3vecs";
static char __pyx_k_norm_3vec[] = "norm_3vec";
static char __pyx_k_sub_3vecs[] = "sub_3vecs";
static char __pyx_k_track_len[] = "track_len";
static char __pyx_k_tracksA32[] = "tracksA32";
static char __pyx_k_tracksB32[] = "tracksB32";
static char __pyx_k_ValueError[] = "ValueError";
static char __pyx_k_cost_nopar[] = "cost_nopar";
static char __pyx_k_intersects[] = "intersects";
static char __pyx_k_min_buffer[] = "min_buffer";
static char __pyx_k_next_ref_p[] = "next_ref_p";
static char __pyx_k_next_trk_p[] = "next_trk_p";
static char __pyx_k_this_ref_p[] = "this_ref_p";
static char __pyx_k_this_trk_p[] = "this_trk_p";
static char __pyx_k_inner_3vecs[] = "inner_3vecs";
static char __pyx_k_max_hit_len[] = "max_hit_len";
static char __pyx_k_metric_type[] = "metric_type";
static char __pyx_k_sq_dist_thr[] = "sq_dist_thr";
static char __pyx_k_start_index[] = "start_index";
static char __pyx_k_RuntimeError[] = "RuntimeError";
static char __pyx_k_larch_3merge[] = "larch_3merge";
static char __pyx_k_larch_3split[] = "larch_3split";
static char __pyx_k_min_min_t1t2[] = "min_min_t1t2";
static char __pyx_k_min_min_t2t1[] = "min_min_t2t1";
static char __pyx_k_track2others[] = "track2others";
static char __pyx_k_current_index[] = "current_index";
static char __pyx_k_mam_distances[] = "mam_distances";
static char __pyx_k_track_lengths[] = "track_lengths";
static char __pyx_k_normalized_3vec[] = "normalized_3vec";
static char __pyx_k_track_dist_3pts[] = "track_dist_3pts";
static char __pyx_k_distances_buffer[] = "distances_buffer";
static char __pyx_k_sum_track2others[] = "sum_track2others";
static char __pyx_k_ascontiguousarray[] = "ascontiguousarray";
static char __pyx_k_longest_track_len[] = "longest_track_len";
static char __pyx_k_cut_plane_line_190[] = "cut_plane (line 190)";
static char __pyx_k_lee_angle_distance[] = "lee_angle_distance";
static char __pyx_k_longest_track_lenA[] = "longest_track_lenA";
static char __pyx_k_longest_track_lenB[] = "longest_track_lenB";
static char __pyx_k_approx_polygon_track[] = "approx_polygon_track";
static char __pyx_k_bundles_distances_mam[] = "bundles_distances_mam";
static char __pyx_k_bundles_distances_mdf[] = "bundles_distances_mdf";
static char __pyx_k_characteristic_points[] = "characteristic_points";
static char __pyx_k_larch_3split_line_1786[] = "larch_3split (line 1786)";
static char __pyx_k_most_similar_track_mam[] = "most_similar_track_mam";
static char __pyx_k_dipy_tracking_distances[] = "dipy.tracking.distances";
static char __pyx_k_minimum_closest_distance[] = "minimum_closest_distance";
static char __pyx_k_Wrong_argument_for_metric[] = "Wrong argument for metric";
static char __pyx_k_local_skeleton_clustering[] = "local_skeleton_clustering";
static char __pyx_k_point_segment_sq_distance[] = "point_segment_sq_distance";
static char __pyx_k_track_dist_3pts_line_1324[] = "track_dist_3pts (line 1324)";
static char __pyx_k_approximate_mdl_trajectory[] = "approximate_mdl_trajectory";
static char __pyx_k_intersect_segment_cylinder[] = "intersect_segment_cylinder";
static char __pyx_k_lee_perpendicular_distance[] = "lee_perpendicular_distance";
static char __pyx_k_lee_angle_distance_line_941[] = "lee_angle_distance (line 941)";
static char __pyx_k_ndarray_is_not_C_contiguous[] = "ndarray is not C contiguous";
static char __pyx_k_track_roi_intersection_check[] = "track_roi_intersection_check";
static char __pyx_k_point_track_sq_distance_check[] = "point_track_sq_distance_check";
static char __pyx_k_Calculate_the_squared_distance[] = " Calculate the squared distance from a point c to a finite line segment ab.\n\n    Examples\n    --------\n    >>> a=np.array([0,0,0], dtype=np.float32)\n    >>> b=np.array([1,0,0], dtype=np.float32)\n    >>> c=np.array([0,1,0], dtype=np.float32)\n    >>> point_segment_sq_distance(a, b, c)\n    1.0\n    >>> c = np.array([0,3,0], dtype=np.float32)\n    >>> point_segment_sq_distance(a,b,c)\n    9.0\n    >>> c = np.array([-1,1,0], dtype=np.float32)\n    >>> point_segment_sq_distance(a, b, c)\n    2.0\n    ";
static char __pyx_k_Extract_divergence_vectors_and[] = " Extract divergence vectors and points of intersection\n    between planes normal to the reference fiber and other tracks\n\n    Parameters\n    ----------\n    tracks : sequence\n        of tracks as arrays, shape (N1,3) .. (Nm,3)\n    ref : array, shape (N,3)\n        reference track\n\n    Returns\n    -------\n    hits : sequence\n       list of points and rcds (radial coefficient of divergence)\n\n    Notes\n    -----\n    The orthogonality relationship\n    ``np.inner(hits[p][q][0:3]-ref[p+1],ref[p+2]-ref[r][p+1])`` will hold\n    throughout for every point q in the hits plane at point (p+1) on the\n    reference track.\n\n    Examples\n    --------\n    >>> refx = np.array([[0,0,0],[1,0,0],[2,0,0],[3,0,0]],dtype='float32')\n    >>> bundlex = [np.array([[0.5,1,0],[1.5,2,0],[2.5,3,0]],dtype='float32')]\n    >>> res = cut_plane(bundlex,refx)\n    >>> len(res)\n    2\n    >>> print(res[0])\n    [[ 1.          1.5         0.          0.70710683  0.        ]]\n    >>> print(res[1])\n    [[ 2.          2.5         0.          0.70710677  0.        ]]\n    ";
static char __pyx_k_approx_polygon_track_line_1007[] = "approx_polygon_track (line 1007)";
static char __pyx_k_local_skeleton_clustering_3pts[] = "local_skeleton_clustering_3pts";
static char __pyx_k_Calculate_the_euclidean_distanc[] = " Calculate the euclidean distance between two 3pt tracks\n\n    Both direct and flip distances are calculated but only the smallest is returned\n\n    Parameters\n    ----------\n    a : array, shape (3,3)\n    a three point track\n    b : array, shape (3,3)\n    a three point track\n\n    Returns\n    -------\n    dist :float\n\n    Examples\n    --------\n    >>> a = np.array([[0,0,0],[1,0,0,],[2,0,0]])\n    >>> b = np.array([[3,0,0],[3.5,1,0],[4,2,0]])\n    >>> c = track_dist_3pts(a, b)\n    >>> print('%.6f' % c)\n    2.721573\n    ";
static char __pyx_k_Calculates_angle_distance_metri[] = " Calculates angle distance metric for the distance between two line segments\n\n    Based on Lee , Han & Whang SIGMOD07.\n\n    This function assumes that norm(end0-start0)>norm(end1-start1) i.e. that the\n    first segment will be bigger than the second one.\n\n    Parameters\n    ----------\n    start0 : float array(3,)\n    end0 : float array(3,)\n    start1 : float array(3,)\n    end1 : float array(3,)\n\n    Returns\n    -------\n    angle_distance : float\n\n    Notes\n    -----\n    l_0 = np.inner(end0-start0,end0-start0)\n    l_1 = np.inner(end1-start1,end1-start1)\n\n    cos_theta_squared = np.inner(end0-start0,end1-start1)**2/ (l_0*l_1)\n    return np.sqrt((1-cos_theta_squared)*l_1)\n\n    Examples\n    --------\n    >>> lee_angle_distance([0,0,0],[1,0,0],[3,4,5],[5,4,3])\n    2.0\n    ";
static char __pyx_k_Calculates_perpendicular_distan[] = " Calculates perpendicular distance metric for the distance between two line segments\n\n    Based on Lee , Han & Whang SIGMOD07.\n\n    This function assumes that norm(end0-start0)>norm(end1-start1) i.e. that the\n    first segment will be bigger than the second one.\n\n    Parameters\n    ----------\n    start0 : float array(3,)\n    end0 : float array(3,)\n    start1 : float array(3,)\n    end1 : float array(3,)\n\n    Returns\n    -------\n    perpendicular_distance: float\n\n    Notes\n    -----\n    l0 = np.inner(end0-start0,end0-start0)\n    l1 = np.inner(end1-start1,end1-start1)\n\n    k0=end0-start0\n\n    u1 = np.inner(start1-start0,k0)/l0\n    u2 = np.inner(end1-start0,k0)/l0\n\n    ps = start0+u1*k0\n    pe = start0+u2*k0\n\n    lperp1 = np.sqrt(np.inner(ps-start1,ps-start1))\n    lperp2 = np.sqrt(np.inner(pe-end1,pe-end1))\n\n    if lperp1+lperp2 > 0.:\n        return (lperp1**2+lperp2**2)/(lperp1+lperp2)\n    else:\n        return 0.\n\n    Examples\n    --------\n    >>> d = lee_perpendicular_distance([0,0,0],[1,0,0],[3,4,5],[5,4,3])\n    >>> print('%.6f' % d)\n    5.787888\n    ";
static char __pyx_k_Check_if_a_track_is_intersectin[] = " Check if a track is intersecting a region of interest\n\n    Parameters\n    ----------\n    track: array,float32, shape (N,3)\n    roi: array,float32, shape (M,3)\n    sq_dist_thr: double, threshold, check squared euclidean distance from every roi point\n\n    Returns\n    -------\n    bool: True, if sq_distance <= sq_dist_thr, otherwise False.\n\n    Examples\n    --------\n    >>> roi=np.array([[0,0,0],[1,0,0],[2,0,0]],dtype='f4')\n    >>> t=np.array([[0,0,0],[1,1,1],[2,2,2]],dtype='f4')\n    >>> track_roi_intersection_check(t,roi,1)\n    True\n    >>> track_roi_intersection_check(t,np.array([[10,0,0]],dtype='f4'),1)\n    False\n    ";
static char __pyx_k_Check_if_square_distance_of_tra[] = " Check if square distance of track from point is smaller than threshold\n\n    Parameters\n    ----------\n    track: array,float32, shape (N,3)\n    point: array,float32, shape (3,)\n    sq_dist_thr: double, threshold\n\n    Returns\n    -------\n    bool: True, if sq_distance <= sq_dist_thr, otherwise False.\n\n    Examples\n    --------\n    >>> t=np.random.rand(10,3).astype(np.float32)\n    >>> p=np.array([0.5,0.5,0.5],dtype=np.float32)\n    >>> point_track_sq_distance_check(t,p,2**2)\n    True\n    >>> t=np.array([[0,0,0],[1,1,1],[2,2,2]],dtype='f4')\n    >>> p=np.array([-1,-1.,-1],dtype='f4')\n    >>> point_track_sq_distance_check(t,p,.2**2)\n    False\n    >>> point_track_sq_distance_check(t,p,2**2)\n    True\n    ";
static char __pyx_k_Does_a_first_pass_clustering_Ev[] = " Does a first pass clustering\n\n    Every track can only have 3 pts neither less or more.\n    Use `dipy.tracking.metrics.downsample` to restrict the number of points\n\n    Parameters\n    ----------\n    tracks : sequence\n        of tracks as arrays, shape (N,3) .. (N,3) where N=3\n    d_thr : float\n        Average euclidean distance threshold\n\n    Returns\n    -------\n    C : dict\n       Clusters.\n\n    Examples\n    --------\n    >>> tracks=[np.array([[0,0,0],[1,0,0,],[2,0,0]]),\n    ...         np.array([[3,0,0],[3.5,1,0],[4,2,0]]),\n    ...         np.array([[3.2,0,0],[3.7,1,0],[4.4,2,0]]),\n    ...         np.array([[3.4,0,0],[3.9,1,0],[4.6,2,0]]),\n    ...         np.array([[0,0.2,0],[1,0.2,0],[2,0.2,0]]),\n    ...         np.array([[2,0.2,0],[1,0.2,0],[0,0.2,0]]),\n    ...         np.array([[0,0,0],[0,1,0],[0,2,0]])]\n    >>> C=local_skeleton_clustering_3pts(tracks,d_thr=0.5)\n\n    Notes\n    -----\n    It is possible to visualize the clustering C from the example\n    above using the fvtk module::\n\n        r=fvtk.ren()\n        for c in C:\n            color=np.random.rand(3)\n            for i in C[c]['indices']:\n                fvtk.add(r,fos.line(tracks[i],color))\n        fvtk.show(r)\n\n    ";
static char __pyx_k_Fast_and_simple_trajectory_appr[] = " Fast and simple trajectory approximation algorithm by Eleftherios and Ian\n\n    It will reduce the number of points of the track by keeping\n    intact the start and endpoints of the track and trying to remove\n    as many points as possible without distorting much the shape of\n    the track\n\n    Parameters\n    ----------\n    xyz : array(N,3)\n        initial trajectory\n    alpha : float\n        smoothing parameter (<0.392 smoother, >0.392 rougher) if the\n        trajectory was a smooth circle then with alpha =0.393\n        ~=pi/8. the circle would be approximated with an decahexagon if\n        alpha = 0.7853 ~=pi/4. with an octagon.\n\n    Returns\n    -------\n    characteristic_points: list of M array(3,) points\n\n    Examples\n    --------\n\n    Approximating a helix:\n\n    >>> t=np.linspace(0,1.75*2*np.pi,100)\n    >>> x = np.sin(t)\n    >>> y = np.cos(t)\n    >>> z = t\n    >>> xyz=np.vstack((x,y,z)).T\n    >>> xyza = approx_polygon_track(xyz)\n    >>> len(xyza) < len(xyz)\n    True\n\n    Notes\n    -----\n    Assuming that a good approximation for a circle is an octagon then\n    that means that the points of the octagon will have angle alpha =\n    2*pi/8 = pi/4 . We calculate the angle between every two neighbour\n    segments of a trajectory and if the angle is higher than pi/4 we\n    choose that point as a characteristic point otherwise we move at the\n    next point.\n    ";
static char __pyx_k_Intersect_Segment_S_t_sa_t_sb_s[] = " Intersect Segment S(t) = sa +t(sb-sa), 0 <=t<= 1 against cylinder specified by p,q and r\n\n    See p.197 from Real Time Collision Detection by C. Ericson\n\n    Examples\n    --------\n    Define cylinder using a segment defined by\n\n    >>> p=np.array([0,0,0],dtype=np.float32)\n    >>> q=np.array([1,0,0],dtype=np.float32)\n    >>> r=0.5\n\n    Define segment\n\n    >>> sa=np.array([0.5,1 ,0],dtype=np.float32)\n    >>> sb=np.array([0.5,-1,0],dtype=np.float32)\n\n    Intersection\n\n    >>> intersect_segment_cylinder(sa, sb, p, q, r)\n    (1.0, 0.25, 0.75)\n    ";
static char __pyx_k_Metric_should_be_one_of_avg_min[] = "Metric should be one of avg, min, max";
static char __pyx_k_Optimized_track_distances_simil[] = " Optimized track distances, similarities and distanch clustering algorithms\n";
static char __pyx_k_home_yoh_deb_gits_pkg_exppsy_di[] = "/home/yoh/deb/gits/pkg-exppsy/dipy/dipy/tracking/distances.pyx";
static char __pyx_k_intersect_segment_cylinder_line[] = "intersect_segment_cylinder (line 1158)";
static char __pyx_k_lee_perpendicular_distance_line[] = "lee_perpendicular_distance (line 838)";
static char __pyx_k_unknown_dtype_code_in_numpy_pxd[] = "unknown dtype code in numpy.pxd (%d)";
static char __pyx_k_Efficient_tractography_clusterin[] = "Efficient tractography clustering\n\n    Every track can needs to have the same number of points.\n    Use `dipy.tracking.metrics.downsample` to restrict the number of points\n\n    Parameters\n    ----------\n    tracks : sequence\n        of tracks as arrays, shape (N,3) .. (N,3) where N=points\n    d_thr : float\n        average euclidean distance threshold\n\n    Returns\n    -------\n    C : dict\n        Clusters.\n\n    Examples\n    --------\n    >>> tracks=[np.array([[0,0,0],[1,0,0,],[2,0,0]]),\n    ...         np.array([[3,0,0],[3.5,1,0],[4,2,0]]),\n    ...         np.array([[3.2,0,0],[3.7,1,0],[4.4,2,0]]),\n    ...         np.array([[3.4,0,0],[3.9,1,0],[4.6,2,0]]),\n    ...         np.array([[0,0.2,0],[1,0.2,0],[2,0.2,0]]),\n    ...         np.array([[2,0.2,0],[1,0.2,0],[0,0.2,0]]),\n    ...         np.array([[0,0,0],[0,1,0],[0,2,0]])]\n    >>> C = local_skeleton_clustering(tracks, d_thr=0.5)\n\n    Notes\n    -----\n    The distance calculated between two tracks::\n\n        t_1       t_2\n\n        0*   a    *0\n          \\       |\n           \\      |\n           1*     |\n            |  b  *1\n            |      \\\n            2*      \\\n                c    *2\n\n    is equal to $(a+b+c)/3$ where $a$ the euclidean distance between ``t_1[0]``\n    and ``t_2[0]``, $b$ between ``t_1[1]`` and ``t_2[1]`` and $c$ between\n    ``t_1[2]`` and ``t_2[2]``. Also the same with t2 flipped (so ``t_1[0]``\n    compared to ``t_2[2]`` etc).\n\n    Visualization:\n\n    It is possible to visualize the clustering C from the example\n    above using the fvtk module::\n\n        from dipy.viz import fvtk\n        r=fvtk.ren()\n        for c in C:\n            color=np.random.rand(3)\n            for i in C[c]['indices']:\n                fvtk.add(r,fvtk.line(tracks[i],color))\n        fvtk.show(r)\n\n    See Also\n    --------\n    dipy.tracking.metrics.downsample\n    ";
static char __pyx_k_Format_string_allocated_too_shor[] = "Format string allocated too short, see comment in numpy.pxd";
static char __pyx_k_Generate_a_first_pass_clustering[] = "Generate a first pass clustering using 3 points on the tracks only.\n\n    Parameters\n    ----------\n    tracks : sequence\n        of tracks as arrays, shape ``(N1,3) .. (Nm,3)``, where 3 points are\n        (first, mid and last)\n    indices : None or sequence, optional\n        Sequence of integer indices of tracks\n    trh : float, optional\n        squared euclidean distance threshold\n\n    Returns\n    -------\n    C : dict\n        A tree graph containing the clusters.\n\n    Notes\n    -----\n    If a 3 point track (3track) is far away from all clusters then add a new\n    cluster and assign this 3track as the rep(representative) track for the new\n    cluster. Otherwise the rep 3track of each cluster is the average track of\n    the cluster.\n\n    Examples\n    --------\n    >>> tracks=[np.array([[0,0,0],[1,0,0,],[2,0,0]],dtype=np.float32),\n    ...         np.array([[3,0,0],[3.5,1,0],[4,2,0]],dtype=np.float32),\n    ...         np.array([[3.2,0,0],[3.7,1,0],[4.4,2,0]],dtype=np.float32),\n    ...         np.array([[3.4,0,0],[3.9,1,0],[4.6,2,0]],dtype=np.float32),\n    ...         np.array([[0,0.2,0],[1,0.2,0],[2,0.2,0]],dtype=np.float32),\n    ...         np.array([[2,0.2,0],[1,0.2,0],[0,0.2,0]],dtype=np.float32),\n    ...         np.array([[0,0,0],[0,1,0],[0,2,0]],dtype=np.float32),\n    ...         np.array([[0.2,0,0],[0.2,1,0],[0.2,2,0]],dtype=np.float32),\n    ...         np.array([[-0.2,0,0],[-0.2,1,0],[-0.2,2,0]],dtype=np.float32)]\n    >>> C = larch_3split(tracks, None, 0.5)\n\n    Here is an example of how to visualize the clustering above::\n\n        from dipy.viz import fvtk\n        r=fvtk.ren()\n        fvtk.add(r,fvtk.line(tracks,fvtk.red))\n        fvtk.show(r)\n        for c in C:\n            color=np.random.rand(3)\n            for i in C[c]['indices']:\n                fos.add(r,fvtk.line(tracks[i],color))\n        fvtk.show(r)\n        for c in C:\n            fvtk.add(r,fos.line(C[c]['rep3']/C[c]['N'],fos.white))\n        fvtk.show(""r)\n    ";
static char __pyx_k_Non_native_byte_order_not_suppor[] = "Non-native byte order not supported";
static char __pyx_k_local_skeleton_clustering_3pts_l[] = "local_skeleton_clustering_3pts (line 1656)";
static char __pyx_k_local_skeleton_clustering_line_1[] = "local_skeleton_clustering (line 1471)";
static char __pyx_k_ndarray_is_not_Fortran_contiguou[] = "ndarray is not Fortran contiguous";
static char __pyx_k_point_segment_sq_distance_line_1[] = "point_segment_sq_distance (line 1271)";
static char __pyx_k_point_track_sq_distance_check_li[] = "point_track_sq_distance_check (line 1953)";
static char __pyx_k_track_roi_intersection_check_lin[] = "track_roi_intersection_check (line 2011)";
static char __pyx_k_Format_string_allocated_too_shor_2[] = "Format string allocated too short.";
static PyObject *__pyx_n_s_C;
static PyObject *__pyx_n_s_C2;
static PyObject *__pyx_kp_u_Calculate_the_euclidean_distanc;
static PyObject *__pyx_kp_u_Calculate_the_squared_distance;
static PyObject *__pyx_kp_u_Calculates_angle_distance_metri;
static PyObject *__pyx_kp_u_Calculates_perpendicular_distan;
static PyObject *__pyx_kp_u_Check_if_a_track_is_intersectin;
static PyObject *__pyx_kp_u_Check_if_square_distance_of_tra;
static PyObject *__pyx_n_s_DM;
static PyObject *__pyx_kp_u_Does_a_first_pass_clustering_Ev;
static PyObject *__pyx_kp_u_Efficient_tractography_clusterin;
static PyObject *__pyx_kp_u_Extract_divergence_vectors_and;
static PyObject *__pyx_kp_u_Fast_and_simple_trajectory_appr;
static PyObject *__pyx_kp_u_Format_string_allocated_too_shor;
static PyObject *__pyx_kp_u_Format_string_allocated_too_shor_2;
static PyObject *__pyx_kp_u_Generate_a_first_pass_clustering;
static PyObject *__pyx_n_s_Hit;
static PyObject *__pyx_kp_u_Intersect_Segment_S_t_sa_t_sb_s;
static PyObject *__pyx_kp_s_Metric_should_be_one_of_avg_min;
static PyObject *__pyx_n_s_N;
static PyObject *__pyx_n_s_N_ref;
static PyObject *__pyx_n_s_N_track;
static PyObject *__pyx_n_s_N_tracks;
static PyObject *__pyx_kp_u_Non_native_byte_order_not_suppor;
static PyObject *__pyx_n_s_RuntimeError;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_kp_s_Wrong_argument_for_metric;
static PyObject *__pyx_n_s_a;
static PyObject *__pyx_n_s_add_3vecs;
static PyObject *__pyx_n_s_all;
static PyObject *__pyx_n_s_alld;
static PyObject *__pyx_n_s_along;
static PyObject *__pyx_n_s_alpha;
static PyObject *__pyx_n_s_alphac;
static PyObject *__pyx_n_s_angle;
static PyObject *__pyx_n_s_append;
static PyObject *__pyx_n_s_approx_polygon_track;
static PyObject *__pyx_kp_u_approx_polygon_track_line_1007;
static PyObject *__pyx_n_s_approximate_mdl_trajectory;
static PyObject *__pyx_n_s_argmin;
static PyObject *__pyx_n_s_array;
static PyObject *__pyx_n_s_asarray;
static PyObject *__pyx_n_s_ascontiguousarray;
static PyObject *__pyx_n_s_avg;
static PyObject *__pyx_n_s_b;
static PyObject *__pyx_n_s_beta;
static PyObject *__pyx_n_s_bundles_distances_mam;
static PyObject *__pyx_n_s_bundles_distances_mdf;
static PyObject *__pyx_n_s_c;
static PyObject *__pyx_n_s_ca;
static PyObject *__pyx_n_s_cb;
static PyObject *__pyx_n_s_cc;
static PyObject *__pyx_n_s_cd_thr;
static PyObject *__pyx_n_s_ch;
static PyObject *__pyx_n_s_characteristic_points;
static PyObject *__pyx_n_s_cit;
static PyObject *__pyx_n_s_cluster;
static PyObject *__pyx_n_s_copy;
static PyObject *__pyx_n_s_cost_nopar;
static PyObject *__pyx_n_s_cost_par;
static PyObject *__pyx_n_s_cp;
static PyObject *__pyx_n_s_cq;
static PyObject *__pyx_n_s_cr;
static PyObject *__pyx_n_s_csa;
static PyObject *__pyx_n_s_csb;
static PyObject *__pyx_n_s_ct;
static PyObject *__pyx_n_s_curr;
static PyObject *__pyx_n_s_current_index;
static PyObject *__pyx_n_s_currp;
static PyObject *__pyx_n_s_cut_plane;
static PyObject *__pyx_kp_u_cut_plane_line_190;
static PyObject *__pyx_n_s_d;
static PyObject *__pyx_n_s_d_thr;
static PyObject *__pyx_n_s_delta;
static PyObject *__pyx_n_s_dim;
static PyObject *__pyx_n_s_dipy_tracking_distances;
static PyObject *__pyx_n_s_dist;
static PyObject *__pyx_n_s_distance;
static PyObject *__pyx_n_s_distances_buffer;
static PyObject *__pyx_n_s_double;
static PyObject *__pyx_n_s_dtype;
static PyObject *__pyx_n_s_empty;
static PyObject *__pyx_n_s_end0;
static PyObject *__pyx_n_s_end1;
static PyObject *__pyx_n_s_flip;
static PyObject *__pyx_n_s_float32;
static PyObject *__pyx_n_s_fvec;
static PyObject *__pyx_n_s_fvec0;
static PyObject *__pyx_n_s_fvec1;
static PyObject *__pyx_n_s_fvec2;
static PyObject *__pyx_n_s_fvec3;
static PyObject *__pyx_n_s_fvec4;
static PyObject *__pyx_n_s_h;
static PyObject *__pyx_n_s_hid;
static PyObject *__pyx_n_s_hidden;
static PyObject *__pyx_n_s_hit;
static PyObject *__pyx_n_s_hitMp;
static PyObject *__pyx_n_s_hit_arr;
static PyObject *__pyx_n_s_hit_no;
static PyObject *__pyx_n_s_hit_ptr;
static PyObject *__pyx_n_s_hits;
static PyObject *__pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di;
static PyObject *__pyx_n_s_i;
static PyObject *__pyx_n_s_i_k;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_indices;
static PyObject *__pyx_n_s_inf;
static PyObject *__pyx_n_s_inner_3vecs;
static PyObject *__pyx_n_s_int64;
static PyObject *__pyx_n_s_intersect_segment_cylinder;
static PyObject *__pyx_kp_u_intersect_segment_cylinder_line;
static PyObject *__pyx_n_s_intersects;
static PyObject *__pyx_n_s_it;
static PyObject *__pyx_n_s_itrange;
static PyObject *__pyx_n_s_j;
static PyObject *__pyx_n_s_k;
static PyObject *__pyx_n_s_keys;
static PyObject *__pyx_n_s_klen;
static PyObject *__pyx_n_s_krange;
static PyObject *__pyx_n_s_larch_3merge;
static PyObject *__pyx_n_s_larch_3split;
static PyObject *__pyx_kp_u_larch_3split_line_1786;
static PyObject *__pyx_n_s_ld;
static PyObject *__pyx_n_s_lee_angle_distance;
static PyObject *__pyx_kp_u_lee_angle_distance_line_941;
static PyObject *__pyx_n_s_lee_perpendicular_distance;
static PyObject *__pyx_kp_u_lee_perpendicular_distance_line;
static PyObject *__pyx_n_s_lenC;
static PyObject *__pyx_n_s_length;
static PyObject *__pyx_n_s_lent;
static PyObject *__pyx_n_s_lentA;
static PyObject *__pyx_n_s_lentB;
static PyObject *__pyx_n_s_lhp;
static PyObject *__pyx_n_s_local_skeleton_clustering;
static PyObject *__pyx_n_s_local_skeleton_clustering_3pts;
static PyObject *__pyx_kp_u_local_skeleton_clustering_3pts_l;
static PyObject *__pyx_kp_u_local_skeleton_clustering_line_1;
static PyObject *__pyx_n_s_longest_track_len;
static PyObject *__pyx_n_s_longest_track_lenA;
static PyObject *__pyx_n_s_longest_track_lenB;
static PyObject *__pyx_n_s_lrq;
static PyObject *__pyx_n_s_m_d;
static PyObject *__pyx_n_s_m_k;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_mam_distances;
static PyObject *__pyx_n_s_max;
static PyObject *__pyx_n_s_max_hit_len;
static PyObject *__pyx_n_s_mean_t1t2;
static PyObject *__pyx_n_s_mean_t2t1;
static PyObject *__pyx_n_s_metric;
static PyObject *__pyx_n_s_metric_type;
static PyObject *__pyx_n_s_mid_index;
static PyObject *__pyx_n_s_min;
static PyObject *__pyx_n_s_min_buffer;
static PyObject *__pyx_n_s_min_min_t1t2;
static PyObject *__pyx_n_s_min_min_t2t1;
static PyObject *__pyx_n_s_min_t1t2;
static PyObject *__pyx_n_s_min_t2t1;
static PyObject *__pyx_n_s_minimum_closest_distance;
static PyObject *__pyx_n_s_mn;
static PyObject *__pyx_n_s_most_similar_track_mam;
static PyObject *__pyx_n_s_mul_3vec;
static PyObject *__pyx_n_s_mul_3vecs;
static PyObject *__pyx_n_s_n_hits;
static PyObject *__pyx_kp_u_ndarray_is_not_C_contiguous;
static PyObject *__pyx_kp_u_ndarray_is_not_Fortran_contiguou;
static PyObject *__pyx_n_s_next_ref_p;
static PyObject *__pyx_n_s_next_trk_p;
static PyObject *__pyx_n_s_norm_3vec;
static PyObject *__pyx_n_s_normal;
static PyObject *__pyx_n_s_normalized_3vec;
static PyObject *__pyx_n_s_np;
static PyObject *__pyx_n_s_numpy;
static PyObject *__pyx_n_s_object;
static PyObject *__pyx_n_s_one_hit;
static PyObject *__pyx_n_s_p;
static PyObject *__pyx_n_s_pMq;
static PyObject *__pyx_n_s_p_no;
static PyObject *__pyx_n_s_point;
static PyObject *__pyx_n_s_point_segment_sq_distance;
static PyObject *__pyx_kp_u_point_segment_sq_distance_line_1;
static PyObject *__pyx_n_s_point_track_sq_distance_check;
static PyObject *__pyx_kp_u_point_track_sq_distance_check_li;
static PyObject *__pyx_n_s_points;
static PyObject *__pyx_n_s_ptr;
static PyObject *__pyx_n_s_q;
static PyObject *__pyx_n_s_qMp;
static PyObject *__pyx_n_s_q_no;
static PyObject *__pyx_n_s_r;
static PyObject *__pyx_n_s_rMp;
static PyObject *__pyx_n_s_rMq;
static PyObject *__pyx_n_s_range;
static PyObject *__pyx_n_s_rcd;
static PyObject *__pyx_n_s_ref;
static PyObject *__pyx_n_s_ref32;
static PyObject *__pyx_n_s_rep3;
static PyObject *__pyx_n_s_rlen;
static PyObject *__pyx_n_s_roi;
static PyObject *__pyx_n_s_rows;
static PyObject *__pyx_n_s_sa;
static PyObject *__pyx_n_s_sb;
static PyObject *__pyx_n_s_shape;
static PyObject *__pyx_n_s_si;
static PyObject *__pyx_n_s_sq_dist_thr;
static PyObject *__pyx_n_s_squeeze;
static PyObject *__pyx_n_s_start0;
static PyObject *__pyx_n_s_start1;
static PyObject *__pyx_n_s_start_index;
static PyObject *__pyx_n_s_sub_3vecs;
static PyObject *__pyx_n_s_sum_track2others;
static PyObject *__pyx_n_s_t;
static PyObject *__pyx_n_s_t1;
static PyObject *__pyx_n_s_t1_len;
static PyObject *__pyx_n_s_t1_pi;
static PyObject *__pyx_n_s_t1_ptr;
static PyObject *__pyx_n_s_t2;
static PyObject *__pyx_n_s_t2_len;
static PyObject *__pyx_n_s_t2_pi;
static PyObject *__pyx_n_s_t2_ptr;
static PyObject *__pyx_n_s_t_len;
static PyObject *__pyx_n_s_t_no;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_this_ref_p;
static PyObject *__pyx_n_s_this_trk_p;
static PyObject *__pyx_n_s_thr;
static PyObject *__pyx_n_s_time;
static PyObject *__pyx_n_s_tlen;
static PyObject *__pyx_n_s_tmp;
static PyObject *__pyx_n_s_track;
static PyObject *__pyx_n_s_track1;
static PyObject *__pyx_n_s_track2;
static PyObject *__pyx_n_s_track2others;
static PyObject *__pyx_n_s_track_dist_3pts;
static PyObject *__pyx_kp_u_track_dist_3pts_line_1324;
static PyObject *__pyx_n_s_track_len;
static PyObject *__pyx_n_s_track_lengths;
static PyObject *__pyx_n_s_track_roi_intersection_check;
static PyObject *__pyx_kp_u_track_roi_intersection_check_lin;
static PyObject *__pyx_n_s_tracka;
static PyObject *__pyx_n_s_trackb;
static PyObject *__pyx_n_s_tracks;
static PyObject *__pyx_n_s_tracks32;
static PyObject *__pyx_n_s_tracksA;
static PyObject *__pyx_n_s_tracksA32;
static PyObject *__pyx_n_s_tracksB;
static PyObject *__pyx_n_s_tracksB32;
static PyObject *__pyx_n_s_ts;
static PyObject *__pyx_n_s_uint64;
static PyObject *__pyx_kp_u_unknown_dtype_code_in_numpy_pxd;
static PyObject *__pyx_n_s_vec;
static PyObject *__pyx_n_s_vec0;
static PyObject *__pyx_n_s_vec1;
static PyObject *__pyx_n_s_vec2;
static PyObject *__pyx_n_s_vec_in;
static PyObject *__pyx_n_s_vec_out;
static PyObject *__pyx_n_s_xyz;
static PyObject *__pyx_n_s_xyz1;
static PyObject *__pyx_n_s_xyz2;
static PyObject *__pyx_n_s_zeros;
static PyObject *__pyx_pf_4dipy_8tracking_9distances_normalized_3vec(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_vec); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_2norm_3vec(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_vec); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_4inner_3vecs(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_vec1, PyObject *__pyx_v_vec2); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_6sub_3vecs(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_vec1, PyObject *__pyx_v_vec2); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_8add_3vecs(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_vec1, PyObject *__pyx_v_vec2); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_10mul_3vecs(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_vec1, PyObject *__pyx_v_vec2); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_12mul_3vec(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_a, PyObject *__pyx_v_vec); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_14cut_plane(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tracks, PyObject *__pyx_v_ref); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_16most_similar_track_mam(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tracks, PyObject *__pyx_v_metric); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_18bundles_distances_mam(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tracksA, PyObject *__pyx_v_tracksB, PyObject *__pyx_v_metric); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_20bundles_distances_mdf(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tracksA, PyObject *__pyx_v_tracksB); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_22mam_distances(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_xyz1, PyObject *__pyx_v_xyz2, PyObject *__pyx_v_metric); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_24minimum_closest_distance(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_xyz1, PyObject *__pyx_v_xyz2); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_26lee_perpendicular_distance(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_start0, PyObject *__pyx_v_end0, PyObject *__pyx_v_start1, PyObject *__pyx_v_end1); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_28lee_angle_distance(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_start0, PyObject *__pyx_v_end0, PyObject *__pyx_v_start1, PyObject *__pyx_v_end1); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_30approx_polygon_track(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_xyz, PyObject *__pyx_v_alpha); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_32approximate_mdl_trajectory(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_xyz, PyObject *__pyx_v_alpha); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_34intersect_segment_cylinder(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sa, PyObject *__pyx_v_sb, PyObject *__pyx_v_p, PyObject *__pyx_v_q, PyObject *__pyx_v_r); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_36point_segment_sq_distance(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_38track_dist_3pts(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tracka, PyObject *__pyx_v_trackb); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_40local_skeleton_clustering(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tracks, PyObject *__pyx_v_d_thr); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_42local_skeleton_clustering_3pts(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tracks, PyObject *__pyx_v_d_thr); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_44larch_3split(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tracks, PyObject *__pyx_v_indices, PyObject *__pyx_v_thr); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_46larch_3merge(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_C, PyObject *__pyx_v_thr); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_48point_track_sq_distance_check(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_track, PyArrayObject *__pyx_v_point, double __pyx_v_sq_dist_thr); /* proto */
static PyObject *__pyx_pf_4dipy_8tracking_9distances_50track_roi_intersection_check(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_track, PyArrayObject *__pyx_v_roi, double __pyx_v_sq_dist_thr); /* proto */
static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */
static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */
static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_keys = {0, &__pyx_n_s_keys, 0, 0, 0};
static PyObject *__pyx_float_1_;
static PyObject *__pyx_float_10_;
static PyObject *__pyx_float_0_392;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_3;
static PyObject *__pyx_int_5;
static PyObject *__pyx_int_10;
static PyObject *__pyx_tuple_;
static PyObject *__pyx_slice__8;
static PyObject *__pyx_tuple__2;
static PyObject *__pyx_tuple__3;
static PyObject *__pyx_tuple__4;
static PyObject *__pyx_tuple__5;
static PyObject *__pyx_tuple__6;
static PyObject *__pyx_tuple__7;
static PyObject *__pyx_tuple__9;
static PyObject *__pyx_slice__14;
static PyObject *__pyx_tuple__10;
static PyObject *__pyx_tuple__11;
static PyObject *__pyx_tuple__12;
static PyObject *__pyx_tuple__13;
static PyObject *__pyx_tuple__15;
static PyObject *__pyx_tuple__16;
static PyObject *__pyx_tuple__17;
static PyObject *__pyx_tuple__18;
static PyObject *__pyx_tuple__19;
static PyObject *__pyx_tuple__20;
static PyObject *__pyx_tuple__21;
static PyObject *__pyx_tuple__22;
static PyObject *__pyx_tuple__23;
static PyObject *__pyx_tuple__24;
static PyObject *__pyx_tuple__25;
static PyObject *__pyx_tuple__26;
static PyObject *__pyx_tuple__27;
static PyObject *__pyx_tuple__28;
static PyObject *__pyx_tuple__29;
static PyObject *__pyx_tuple__31;
static PyObject *__pyx_tuple__33;
static PyObject *__pyx_tuple__35;
static PyObject *__pyx_tuple__37;
static PyObject *__pyx_tuple__39;
static PyObject *__pyx_tuple__41;
static PyObject *__pyx_tuple__43;
static PyObject *__pyx_tuple__45;
static PyObject *__pyx_tuple__47;
static PyObject *__pyx_tuple__49;
static PyObject *__pyx_tuple__51;
static PyObject *__pyx_tuple__53;
static PyObject *__pyx_tuple__55;
static PyObject *__pyx_tuple__57;
static PyObject *__pyx_tuple__59;
static PyObject *__pyx_tuple__61;
static PyObject *__pyx_tuple__63;
static PyObject *__pyx_tuple__65;
static PyObject *__pyx_tuple__67;
static PyObject *__pyx_tuple__69;
static PyObject *__pyx_tuple__71;
static PyObject *__pyx_tuple__73;
static PyObject *__pyx_tuple__75;
static PyObject *__pyx_tuple__77;
static PyObject *__pyx_tuple__79;
static PyObject *__pyx_codeobj__30;
static PyObject *__pyx_codeobj__32;
static PyObject *__pyx_codeobj__34;
static PyObject *__pyx_codeobj__36;
static PyObject *__pyx_codeobj__38;
static PyObject *__pyx_codeobj__40;
static PyObject *__pyx_codeobj__42;
static PyObject *__pyx_codeobj__44;
static PyObject *__pyx_codeobj__46;
static PyObject *__pyx_codeobj__48;
static PyObject *__pyx_codeobj__50;
static PyObject *__pyx_codeobj__52;
static PyObject *__pyx_codeobj__54;
static PyObject *__pyx_codeobj__56;
static PyObject *__pyx_codeobj__58;
static PyObject *__pyx_codeobj__60;
static PyObject *__pyx_codeobj__62;
static PyObject *__pyx_codeobj__64;
static PyObject *__pyx_codeobj__66;
static PyObject *__pyx_codeobj__68;
static PyObject *__pyx_codeobj__70;
static PyObject *__pyx_codeobj__72;
static PyObject *__pyx_codeobj__74;
static PyObject *__pyx_codeobj__76;
static PyObject *__pyx_codeobj__78;
static PyObject *__pyx_codeobj__80;

/* "dipy/tracking/distances.pyx":40
 * DEF biggest_float = 3.4028235e+38 #np.finfo('f4').max
 * 
 * cdef inline cnp.ndarray[cnp.float32_t, ndim=1] as_float_3vec(object vec):             # <<<<<<<<<<<<<<
 *     ''' Utility function to convert object to 3D float vector '''
 *     return np.squeeze(np.asarray(vec, dtype=np.float32))
 */

static CYTHON_INLINE PyArrayObject *__pyx_f_4dipy_8tracking_9distances_as_float_3vec(PyObject *__pyx_v_vec) {
  PyArrayObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("as_float_3vec", 0);

  /* "dipy/tracking/distances.pyx":42
 * cdef inline cnp.ndarray[cnp.float32_t, ndim=1] as_float_3vec(object vec):
 *     ''' Utility function to convert object to 3D float vector '''
 *     return np.squeeze(np.asarray(vec, dtype=np.float32))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_squeeze); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_asarray); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_vec);
  __Pyx_GIVEREF(__pyx_v_vec);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_vec);
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_float32); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __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;
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_7); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __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 = NULL;
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __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;
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":40
 * DEF biggest_float = 3.4028235e+38 #np.finfo('f4').max
 * 
 * cdef inline cnp.ndarray[cnp.float32_t, ndim=1] as_float_3vec(object vec):             # <<<<<<<<<<<<<<
 *     ''' Utility function to convert object to 3D float vector '''
 *     return np.squeeze(np.asarray(vec, dtype=np.float32))
 */

  /* 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_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("dipy.tracking.distances.as_float_3vec", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":45
 * 
 * 
 * cdef inline float* asfp(cnp.ndarray pt):             # <<<<<<<<<<<<<<
 *     return <float *>pt.data
 * 
 */

static CYTHON_INLINE float *__pyx_f_4dipy_8tracking_9distances_asfp(PyArrayObject *__pyx_v_pt) {
  float *__pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("asfp", 0);

  /* "dipy/tracking/distances.pyx":46
 * 
 * cdef inline float* asfp(cnp.ndarray pt):
 *     return <float *>pt.data             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = ((float *)__pyx_v_pt->data);
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":45
 * 
 * 
 * cdef inline float* asfp(cnp.ndarray pt):             # <<<<<<<<<<<<<<
 *     return <float *>pt.data
 * 
 */

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

/* "dipy/tracking/distances.pyx":49
 * 
 * 
 * def normalized_3vec(vec):             # <<<<<<<<<<<<<<
 *     ''' Return normalized 3D vector
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_1normalized_3vec(PyObject *__pyx_self, PyObject *__pyx_v_vec); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_normalized_3vec[] = " Return normalized 3D vector\n\n    Vector divided by Euclidean (L2) norm\n\n    Parameters\n    ----------\n    vec : array-like shape (3,)\n\n    Returns\n    -------\n    vec_out : array shape (3,)\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_1normalized_3vec = {"normalized_3vec", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_1normalized_3vec, METH_O, __pyx_doc_4dipy_8tracking_9distances_normalized_3vec};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_1normalized_3vec(PyObject *__pyx_self, PyObject *__pyx_v_vec) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("normalized_3vec (wrapper)", 0);
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_normalized_3vec(__pyx_self, ((PyObject *)__pyx_v_vec));

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_normalized_3vec(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_vec) {
  PyArrayObject *__pyx_v_vec_in = 0;
  PyArrayObject *__pyx_v_vec_out = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vec_in;
  __Pyx_Buffer __pyx_pybuffer_vec_in;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vec_out;
  __Pyx_Buffer __pyx_pybuffer_vec_out;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("normalized_3vec", 0);
  __pyx_pybuffer_vec_in.pybuffer.buf = NULL;
  __pyx_pybuffer_vec_in.refcount = 0;
  __pyx_pybuffernd_vec_in.data = NULL;
  __pyx_pybuffernd_vec_in.rcbuffer = &__pyx_pybuffer_vec_in;
  __pyx_pybuffer_vec_out.pybuffer.buf = NULL;
  __pyx_pybuffer_vec_out.refcount = 0;
  __pyx_pybuffernd_vec_out.data = NULL;
  __pyx_pybuffernd_vec_out.rcbuffer = &__pyx_pybuffer_vec_out;

  /* "dipy/tracking/distances.pyx":62
 *     vec_out : array shape (3,)
 *     '''
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_in = as_float_3vec(vec)             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 *     cnormalized_3vec(<float *>vec_in.data, <float*>vec_out.data)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_vec)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vec_in.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_vec_in = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_vec_in.rcbuffer->pybuffer.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_pybuffernd_vec_in.diminfo[0].strides = __pyx_pybuffernd_vec_in.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vec_in.diminfo[0].shape = __pyx_pybuffernd_vec_in.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_vec_in = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":63
 *     '''
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_in = as_float_3vec(vec)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)             # <<<<<<<<<<<<<<
 *     cnormalized_3vec(<float *>vec_in.data, <float*>vec_out.data)
 *     return vec_out
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_5 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(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_5 = 1;
    }
  }
  __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (__pyx_t_2) {
    __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); __pyx_t_2 = NULL;
  }
  __Pyx_INCREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);
  PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_tuple_);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __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_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vec_out.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_vec_out = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_vec_out.rcbuffer->pybuffer.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_pybuffernd_vec_out.diminfo[0].strides = __pyx_pybuffernd_vec_out.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vec_out.diminfo[0].shape = __pyx_pybuffernd_vec_out.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_7 = 0;
  __pyx_v_vec_out = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":64
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_in = as_float_3vec(vec)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 *     cnormalized_3vec(<float *>vec_in.data, <float*>vec_out.data)             # <<<<<<<<<<<<<<
 *     return vec_out
 * 
 */
  __pyx_f_4dipy_8tracking_9distances_cnormalized_3vec(((float *)__pyx_v_vec_in->data), ((float *)__pyx_v_vec_out->data));

  /* "dipy/tracking/distances.pyx":65
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 *     cnormalized_3vec(<float *>vec_in.data, <float*>vec_out.data)
 *     return vec_out             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_vec_out));
  __pyx_r = ((PyObject *)__pyx_v_vec_out);
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":49
 * 
 * 
 * def normalized_3vec(vec):             # <<<<<<<<<<<<<<
 *     ''' Return normalized 3D vector
 * 
 */

  /* 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_6);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vec_in.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vec_out.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.normalized_3vec", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vec_in.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vec_out.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vec_in);
  __Pyx_XDECREF((PyObject *)__pyx_v_vec_out);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":68
 * 
 * 
 * def norm_3vec(vec):             # <<<<<<<<<<<<<<
 *     ''' Euclidean (L2) norm of length 3 vector
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_3norm_3vec(PyObject *__pyx_self, PyObject *__pyx_v_vec); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_2norm_3vec[] = " Euclidean (L2) norm of length 3 vector\n\n    Parameters\n    ----------\n    vec : array-like shape (3,)\n\n    Returns\n    -------\n    norm : float\n       Euclidean norm\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_3norm_3vec = {"norm_3vec", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_3norm_3vec, METH_O, __pyx_doc_4dipy_8tracking_9distances_2norm_3vec};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_3norm_3vec(PyObject *__pyx_self, PyObject *__pyx_v_vec) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("norm_3vec (wrapper)", 0);
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_2norm_3vec(__pyx_self, ((PyObject *)__pyx_v_vec));

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_2norm_3vec(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_vec) {
  PyArrayObject *__pyx_v_vec_in = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vec_in;
  __Pyx_Buffer __pyx_pybuffer_vec_in;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("norm_3vec", 0);
  __pyx_pybuffer_vec_in.pybuffer.buf = NULL;
  __pyx_pybuffer_vec_in.refcount = 0;
  __pyx_pybuffernd_vec_in.data = NULL;
  __pyx_pybuffernd_vec_in.rcbuffer = &__pyx_pybuffer_vec_in;

  /* "dipy/tracking/distances.pyx":80
 *        Euclidean norm
 *     '''
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_in = as_float_3vec(vec)             # <<<<<<<<<<<<<<
 *     return cnorm_3vec(<float *>vec_in.data)
 * 
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_vec)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vec_in.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_vec_in = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_vec_in.rcbuffer->pybuffer.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_pybuffernd_vec_in.diminfo[0].strides = __pyx_pybuffernd_vec_in.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vec_in.diminfo[0].shape = __pyx_pybuffernd_vec_in.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_vec_in = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":81
 *     '''
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_in = as_float_3vec(vec)
 *     return cnorm_3vec(<float *>vec_in.data)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyFloat_FromDouble(__pyx_f_4dipy_8tracking_9distances_cnorm_3vec(((float *)__pyx_v_vec_in->data))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":68
 * 
 * 
 * def norm_3vec(vec):             # <<<<<<<<<<<<<<
 *     ''' Euclidean (L2) norm of length 3 vector
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vec_in.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.norm_3vec", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vec_in.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_vec_in);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":84
 * 
 * 
 * cdef inline float cnorm_3vec(float *vec):             # <<<<<<<<<<<<<<
 *     ''' Calculate Euclidean norm of input vector
 * 
 */

static CYTHON_INLINE float __pyx_f_4dipy_8tracking_9distances_cnorm_3vec(float *__pyx_v_vec) {
  float __pyx_v_v0;
  float __pyx_v_v1;
  float __pyx_v_v2;
  float __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("cnorm_3vec", 0);

  /* "dipy/tracking/distances.pyx":98
 *     '''
 *     cdef float v0, v1, v2
 *     v0 = vec[0]             # <<<<<<<<<<<<<<
 *     v1 = vec[1]
 *     v2 = vec[2]
 */
  __pyx_v_v0 = (__pyx_v_vec[0]);

  /* "dipy/tracking/distances.pyx":99
 *     cdef float v0, v1, v2
 *     v0 = vec[0]
 *     v1 = vec[1]             # <<<<<<<<<<<<<<
 *     v2 = vec[2]
 *     return sqrt(v0 * v0 + v1*v1 + v2*v2)
 */
  __pyx_v_v1 = (__pyx_v_vec[1]);

  /* "dipy/tracking/distances.pyx":100
 *     v0 = vec[0]
 *     v1 = vec[1]
 *     v2 = vec[2]             # <<<<<<<<<<<<<<
 *     return sqrt(v0 * v0 + v1*v1 + v2*v2)
 * 
 */
  __pyx_v_v2 = (__pyx_v_vec[2]);

  /* "dipy/tracking/distances.pyx":101
 *     v1 = vec[1]
 *     v2 = vec[2]
 *     return sqrt(v0 * v0 + v1*v1 + v2*v2)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = sqrt((((__pyx_v_v0 * __pyx_v_v0) + (__pyx_v_v1 * __pyx_v_v1)) + (__pyx_v_v2 * __pyx_v_v2)));
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":84
 * 
 * 
 * cdef inline float cnorm_3vec(float *vec):             # <<<<<<<<<<<<<<
 *     ''' Calculate Euclidean norm of input vector
 * 
 */

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

/* "dipy/tracking/distances.pyx":104
 * 
 * 
 * cdef inline void cnormalized_3vec(float *vec_in, float *vec_out):             # <<<<<<<<<<<<<<
 *     ''' Calculate and fill normalized 3D vector
 * 
 */

static CYTHON_INLINE void __pyx_f_4dipy_8tracking_9distances_cnormalized_3vec(float *__pyx_v_vec_in, float *__pyx_v_vec_out) {
  float __pyx_v_norm;
  int __pyx_v_i;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("cnormalized_3vec", 0);

  /* "dipy/tracking/distances.pyx":115
 * 
 *     '''
 *     cdef float norm = cnorm_3vec(vec_in)             # <<<<<<<<<<<<<<
 *     cdef int i
 *     for i in range(3):
 */
  __pyx_v_norm = __pyx_f_4dipy_8tracking_9distances_cnorm_3vec(__pyx_v_vec_in);

  /* "dipy/tracking/distances.pyx":117
 *     cdef float norm = cnorm_3vec(vec_in)
 *     cdef int i
 *     for i in range(3):             # <<<<<<<<<<<<<<
 *         vec_out[i] = vec_in[i] / norm
 * 
 */
  for (__pyx_t_1 = 0; __pyx_t_1 < 3; __pyx_t_1+=1) {
    __pyx_v_i = __pyx_t_1;

    /* "dipy/tracking/distances.pyx":118
 *     cdef int i
 *     for i in range(3):
 *         vec_out[i] = vec_in[i] / norm             # <<<<<<<<<<<<<<
 * 
 * 
 */
    if (unlikely(__pyx_v_norm == 0)) {
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    (__pyx_v_vec_out[__pyx_v_i]) = ((__pyx_v_vec_in[__pyx_v_i]) / __pyx_v_norm);
  }

  /* "dipy/tracking/distances.pyx":104
 * 
 * 
 * cdef inline void cnormalized_3vec(float *vec_in, float *vec_out):             # <<<<<<<<<<<<<<
 *     ''' Calculate and fill normalized 3D vector
 * 
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("dipy.tracking.distances.cnormalized_3vec", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
}

/* "dipy/tracking/distances.pyx":121
 * 
 * 
 * def inner_3vecs(vec1, vec2):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_5inner_3vecs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_5inner_3vecs = {"inner_3vecs", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_5inner_3vecs, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_5inner_3vecs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_vec1 = 0;
  PyObject *__pyx_v_vec2 = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("inner_3vecs (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_vec1,&__pyx_n_s_vec2,0};
    PyObject* values[2] = {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  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_vec1)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_vec2)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("inner_3vecs", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "inner_3vecs") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_vec1 = values[0];
    __pyx_v_vec2 = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("inner_3vecs", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.inner_3vecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_4inner_3vecs(__pyx_self, __pyx_v_vec1, __pyx_v_vec2);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_4inner_3vecs(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_vec1, PyObject *__pyx_v_vec2) {
  PyArrayObject *__pyx_v_fvec1 = 0;
  PyArrayObject *__pyx_v_fvec2 = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec1;
  __Pyx_Buffer __pyx_pybuffer_fvec1;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec2;
  __Pyx_Buffer __pyx_pybuffer_fvec2;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("inner_3vecs", 0);
  __pyx_pybuffer_fvec1.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec1.refcount = 0;
  __pyx_pybuffernd_fvec1.data = NULL;
  __pyx_pybuffernd_fvec1.rcbuffer = &__pyx_pybuffer_fvec1;
  __pyx_pybuffer_fvec2.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec2.refcount = 0;
  __pyx_pybuffernd_fvec2.data = NULL;
  __pyx_pybuffernd_fvec2.rcbuffer = &__pyx_pybuffer_fvec2;

  /* "dipy/tracking/distances.pyx":122
 * 
 * def inner_3vecs(vec1, vec2):
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 *     return cinner_3vecs(<float *>fvec1.data, <float*>fvec2.data)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_vec1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_fvec1 = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_fvec1.rcbuffer->pybuffer.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_pybuffernd_fvec1.diminfo[0].strides = __pyx_pybuffernd_fvec1.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec1.diminfo[0].shape = __pyx_pybuffernd_fvec1.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_fvec1 = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":123
 * def inner_3vecs(vec1, vec2):
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)             # <<<<<<<<<<<<<<
 *     return cinner_3vecs(<float *>fvec1.data, <float*>fvec2.data)
 * 
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_vec2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_fvec2 = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_fvec2.rcbuffer->pybuffer.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_pybuffernd_fvec2.diminfo[0].strides = __pyx_pybuffernd_fvec2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec2.diminfo[0].shape = __pyx_pybuffernd_fvec2.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_fvec2 = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":124
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 *     return cinner_3vecs(<float *>fvec1.data, <float*>fvec2.data)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyFloat_FromDouble(__pyx_f_4dipy_8tracking_9distances_cinner_3vecs(((float *)__pyx_v_fvec1->data), ((float *)__pyx_v_fvec2->data))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":121
 * 
 * 
 * def inner_3vecs(vec1, vec2):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.inner_3vecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec1);
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec2);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":127
 * 
 * 
 * cdef inline float cinner_3vecs(float *vec1, float *vec2) nogil:             # <<<<<<<<<<<<<<
 *     cdef int i
 *     cdef float ip = 0
 */

static CYTHON_INLINE float __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(float *__pyx_v_vec1, float *__pyx_v_vec2) {
  int __pyx_v_i;
  float __pyx_v_ip;
  float __pyx_r;

  /* "dipy/tracking/distances.pyx":129
 * cdef inline float cinner_3vecs(float *vec1, float *vec2) nogil:
 *     cdef int i
 *     cdef float ip = 0             # <<<<<<<<<<<<<<
 *     for i from 0<=i<3:
 *         ip += vec1[i]*vec2[i]
 */
  __pyx_v_ip = 0.0;

  /* "dipy/tracking/distances.pyx":130
 *     cdef int i
 *     cdef float ip = 0
 *     for i from 0<=i<3:             # <<<<<<<<<<<<<<
 *         ip += vec1[i]*vec2[i]
 *     return ip
 */
  for (__pyx_v_i = 0; __pyx_v_i < 3; __pyx_v_i++) {

    /* "dipy/tracking/distances.pyx":131
 *     cdef float ip = 0
 *     for i from 0<=i<3:
 *         ip += vec1[i]*vec2[i]             # <<<<<<<<<<<<<<
 *     return ip
 * 
 */
    __pyx_v_ip = (__pyx_v_ip + ((__pyx_v_vec1[__pyx_v_i]) * (__pyx_v_vec2[__pyx_v_i])));
  }

  /* "dipy/tracking/distances.pyx":132
 *     for i from 0<=i<3:
 *         ip += vec1[i]*vec2[i]
 *     return ip             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_ip;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":127
 * 
 * 
 * cdef inline float cinner_3vecs(float *vec1, float *vec2) nogil:             # <<<<<<<<<<<<<<
 *     cdef int i
 *     cdef float ip = 0
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":135
 * 
 * 
 * def sub_3vecs(vec1, vec2):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_7sub_3vecs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_7sub_3vecs = {"sub_3vecs", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_7sub_3vecs, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_7sub_3vecs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_vec1 = 0;
  PyObject *__pyx_v_vec2 = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("sub_3vecs (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_vec1,&__pyx_n_s_vec2,0};
    PyObject* values[2] = {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  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_vec1)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_vec2)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("sub_3vecs", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "sub_3vecs") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_vec1 = values[0];
    __pyx_v_vec2 = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("sub_3vecs", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.sub_3vecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_6sub_3vecs(__pyx_self, __pyx_v_vec1, __pyx_v_vec2);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_6sub_3vecs(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_vec1, PyObject *__pyx_v_vec2) {
  PyArrayObject *__pyx_v_fvec1 = 0;
  PyArrayObject *__pyx_v_fvec2 = 0;
  PyArrayObject *__pyx_v_vec_out = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec1;
  __Pyx_Buffer __pyx_pybuffer_fvec1;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec2;
  __Pyx_Buffer __pyx_pybuffer_fvec2;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vec_out;
  __Pyx_Buffer __pyx_pybuffer_vec_out;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("sub_3vecs", 0);
  __pyx_pybuffer_fvec1.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec1.refcount = 0;
  __pyx_pybuffernd_fvec1.data = NULL;
  __pyx_pybuffernd_fvec1.rcbuffer = &__pyx_pybuffer_fvec1;
  __pyx_pybuffer_fvec2.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec2.refcount = 0;
  __pyx_pybuffernd_fvec2.data = NULL;
  __pyx_pybuffernd_fvec2.rcbuffer = &__pyx_pybuffer_fvec2;
  __pyx_pybuffer_vec_out.pybuffer.buf = NULL;
  __pyx_pybuffer_vec_out.refcount = 0;
  __pyx_pybuffernd_vec_out.data = NULL;
  __pyx_pybuffernd_vec_out.rcbuffer = &__pyx_pybuffer_vec_out;

  /* "dipy/tracking/distances.pyx":136
 * 
 * def sub_3vecs(vec1, vec2):
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_vec1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_fvec1 = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_fvec1.rcbuffer->pybuffer.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 136; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_pybuffernd_fvec1.diminfo[0].strides = __pyx_pybuffernd_fvec1.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec1.diminfo[0].shape = __pyx_pybuffernd_fvec1.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_fvec1 = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":137
 * def sub_3vecs(vec1, vec2):
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 *     csub_3vecs(<float *>fvec1.data, <float*>fvec2.data, <float *>vec_out.data)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_vec2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_fvec2 = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_fvec2.rcbuffer->pybuffer.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 137; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_pybuffernd_fvec2.diminfo[0].strides = __pyx_pybuffernd_fvec2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec2.diminfo[0].shape = __pyx_pybuffernd_fvec2.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_fvec2 = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":138
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)             # <<<<<<<<<<<<<<
 *     csub_3vecs(<float *>fvec1.data, <float*>fvec2.data, <float *>vec_out.data)
 *     return vec_out
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_5 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(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_5 = 1;
    }
  }
  __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (__pyx_t_2) {
    __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); __pyx_t_2 = NULL;
  }
  __Pyx_INCREF(__pyx_tuple__2);
  __Pyx_GIVEREF(__pyx_tuple__2);
  PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_tuple__2);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __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_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vec_out.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_vec_out = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_vec_out.rcbuffer->pybuffer.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_pybuffernd_vec_out.diminfo[0].strides = __pyx_pybuffernd_vec_out.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vec_out.diminfo[0].shape = __pyx_pybuffernd_vec_out.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_7 = 0;
  __pyx_v_vec_out = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":139
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 *     csub_3vecs(<float *>fvec1.data, <float*>fvec2.data, <float *>vec_out.data)             # <<<<<<<<<<<<<<
 *     return vec_out
 * 
 */
  __pyx_f_4dipy_8tracking_9distances_csub_3vecs(((float *)__pyx_v_fvec1->data), ((float *)__pyx_v_fvec2->data), ((float *)__pyx_v_vec_out->data));

  /* "dipy/tracking/distances.pyx":140
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 *     csub_3vecs(<float *>fvec1.data, <float*>fvec2.data, <float *>vec_out.data)
 *     return vec_out             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_vec_out));
  __pyx_r = ((PyObject *)__pyx_v_vec_out);
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":135
 * 
 * 
 * def sub_3vecs(vec1, vec2):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 */

  /* 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_6);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vec_out.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.sub_3vecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vec_out.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec1);
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec2);
  __Pyx_XDECREF((PyObject *)__pyx_v_vec_out);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":143
 * 
 * 
 * cdef inline void csub_3vecs(float *vec1, float *vec2, float *vec_out) nogil:             # <<<<<<<<<<<<<<
 *     cdef int i
 *     for i from 0<=i<3:
 */

static CYTHON_INLINE void __pyx_f_4dipy_8tracking_9distances_csub_3vecs(float *__pyx_v_vec1, float *__pyx_v_vec2, float *__pyx_v_vec_out) {
  int __pyx_v_i;

  /* "dipy/tracking/distances.pyx":145
 * cdef inline void csub_3vecs(float *vec1, float *vec2, float *vec_out) nogil:
 *     cdef int i
 *     for i from 0<=i<3:             # <<<<<<<<<<<<<<
 *         vec_out[i] = vec1[i]-vec2[i]
 * 
 */
  for (__pyx_v_i = 0; __pyx_v_i < 3; __pyx_v_i++) {

    /* "dipy/tracking/distances.pyx":146
 *     cdef int i
 *     for i from 0<=i<3:
 *         vec_out[i] = vec1[i]-vec2[i]             # <<<<<<<<<<<<<<
 * 
 * 
 */
    (__pyx_v_vec_out[__pyx_v_i]) = ((__pyx_v_vec1[__pyx_v_i]) - (__pyx_v_vec2[__pyx_v_i]));
  }

  /* "dipy/tracking/distances.pyx":143
 * 
 * 
 * cdef inline void csub_3vecs(float *vec1, float *vec2, float *vec_out) nogil:             # <<<<<<<<<<<<<<
 *     cdef int i
 *     for i from 0<=i<3:
 */

  /* function exit code */
}

/* "dipy/tracking/distances.pyx":149
 * 
 * 
 * def add_3vecs(vec1, vec2):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_9add_3vecs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_9add_3vecs = {"add_3vecs", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_9add_3vecs, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_9add_3vecs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_vec1 = 0;
  PyObject *__pyx_v_vec2 = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("add_3vecs (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_vec1,&__pyx_n_s_vec2,0};
    PyObject* values[2] = {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  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_vec1)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_vec2)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("add_3vecs", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_3vecs") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_vec1 = values[0];
    __pyx_v_vec2 = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("add_3vecs", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.add_3vecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_8add_3vecs(__pyx_self, __pyx_v_vec1, __pyx_v_vec2);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_8add_3vecs(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_vec1, PyObject *__pyx_v_vec2) {
  PyArrayObject *__pyx_v_fvec1 = 0;
  PyArrayObject *__pyx_v_fvec2 = 0;
  PyArrayObject *__pyx_v_vec_out = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec1;
  __Pyx_Buffer __pyx_pybuffer_fvec1;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec2;
  __Pyx_Buffer __pyx_pybuffer_fvec2;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vec_out;
  __Pyx_Buffer __pyx_pybuffer_vec_out;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("add_3vecs", 0);
  __pyx_pybuffer_fvec1.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec1.refcount = 0;
  __pyx_pybuffernd_fvec1.data = NULL;
  __pyx_pybuffernd_fvec1.rcbuffer = &__pyx_pybuffer_fvec1;
  __pyx_pybuffer_fvec2.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec2.refcount = 0;
  __pyx_pybuffernd_fvec2.data = NULL;
  __pyx_pybuffernd_fvec2.rcbuffer = &__pyx_pybuffer_fvec2;
  __pyx_pybuffer_vec_out.pybuffer.buf = NULL;
  __pyx_pybuffer_vec_out.refcount = 0;
  __pyx_pybuffernd_vec_out.data = NULL;
  __pyx_pybuffernd_vec_out.rcbuffer = &__pyx_pybuffer_vec_out;

  /* "dipy/tracking/distances.pyx":150
 * 
 * def add_3vecs(vec1, vec2):
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_vec1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_fvec1 = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_fvec1.rcbuffer->pybuffer.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_pybuffernd_fvec1.diminfo[0].strides = __pyx_pybuffernd_fvec1.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec1.diminfo[0].shape = __pyx_pybuffernd_fvec1.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_fvec1 = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":151
 * def add_3vecs(vec1, vec2):
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 *     cadd_3vecs(<float *>fvec1.data, <float*>fvec2.data, <float *>vec_out.data)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_vec2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_fvec2 = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_fvec2.rcbuffer->pybuffer.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 151; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_pybuffernd_fvec2.diminfo[0].strides = __pyx_pybuffernd_fvec2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec2.diminfo[0].shape = __pyx_pybuffernd_fvec2.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_fvec2 = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":152
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)             # <<<<<<<<<<<<<<
 *     cadd_3vecs(<float *>fvec1.data, <float*>fvec2.data, <float *>vec_out.data)
 *     return vec_out
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_5 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(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_5 = 1;
    }
  }
  __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (__pyx_t_2) {
    __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); __pyx_t_2 = NULL;
  }
  __Pyx_INCREF(__pyx_tuple__3);
  __Pyx_GIVEREF(__pyx_tuple__3);
  PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_tuple__3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __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_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vec_out.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_vec_out = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_vec_out.rcbuffer->pybuffer.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_pybuffernd_vec_out.diminfo[0].strides = __pyx_pybuffernd_vec_out.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vec_out.diminfo[0].shape = __pyx_pybuffernd_vec_out.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_7 = 0;
  __pyx_v_vec_out = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":153
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 *     cadd_3vecs(<float *>fvec1.data, <float*>fvec2.data, <float *>vec_out.data)             # <<<<<<<<<<<<<<
 *     return vec_out
 * 
 */
  __pyx_f_4dipy_8tracking_9distances_cadd_3vecs(((float *)__pyx_v_fvec1->data), ((float *)__pyx_v_fvec2->data), ((float *)__pyx_v_vec_out->data));

  /* "dipy/tracking/distances.pyx":154
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 *     cadd_3vecs(<float *>fvec1.data, <float*>fvec2.data, <float *>vec_out.data)
 *     return vec_out             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_vec_out));
  __pyx_r = ((PyObject *)__pyx_v_vec_out);
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":149
 * 
 * 
 * def add_3vecs(vec1, vec2):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 */

  /* 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_6);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vec_out.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.add_3vecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vec_out.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec1);
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec2);
  __Pyx_XDECREF((PyObject *)__pyx_v_vec_out);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":157
 * 
 * 
 * cdef inline void cadd_3vecs(float *vec1, float *vec2, float *vec_out) nogil:             # <<<<<<<<<<<<<<
 *     cdef int i
 *     for i from 0<=i<3:
 */

static CYTHON_INLINE void __pyx_f_4dipy_8tracking_9distances_cadd_3vecs(float *__pyx_v_vec1, float *__pyx_v_vec2, float *__pyx_v_vec_out) {
  int __pyx_v_i;

  /* "dipy/tracking/distances.pyx":159
 * cdef inline void cadd_3vecs(float *vec1, float *vec2, float *vec_out) nogil:
 *     cdef int i
 *     for i from 0<=i<3:             # <<<<<<<<<<<<<<
 *         vec_out[i] = vec1[i]+vec2[i]
 * 
 */
  for (__pyx_v_i = 0; __pyx_v_i < 3; __pyx_v_i++) {

    /* "dipy/tracking/distances.pyx":160
 *     cdef int i
 *     for i from 0<=i<3:
 *         vec_out[i] = vec1[i]+vec2[i]             # <<<<<<<<<<<<<<
 * 
 * def mul_3vecs(vec1, vec2):
 */
    (__pyx_v_vec_out[__pyx_v_i]) = ((__pyx_v_vec1[__pyx_v_i]) + (__pyx_v_vec2[__pyx_v_i]));
  }

  /* "dipy/tracking/distances.pyx":157
 * 
 * 
 * cdef inline void cadd_3vecs(float *vec1, float *vec2, float *vec_out) nogil:             # <<<<<<<<<<<<<<
 *     cdef int i
 *     for i from 0<=i<3:
 */

  /* function exit code */
}

/* "dipy/tracking/distances.pyx":162
 *         vec_out[i] = vec1[i]+vec2[i]
 * 
 * def mul_3vecs(vec1, vec2):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_11mul_3vecs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_11mul_3vecs = {"mul_3vecs", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_11mul_3vecs, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_11mul_3vecs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_vec1 = 0;
  PyObject *__pyx_v_vec2 = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("mul_3vecs (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_vec1,&__pyx_n_s_vec2,0};
    PyObject* values[2] = {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  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_vec1)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_vec2)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("mul_3vecs", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "mul_3vecs") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_vec1 = values[0];
    __pyx_v_vec2 = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("mul_3vecs", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.mul_3vecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_10mul_3vecs(__pyx_self, __pyx_v_vec1, __pyx_v_vec2);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_10mul_3vecs(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_vec1, PyObject *__pyx_v_vec2) {
  PyArrayObject *__pyx_v_fvec1 = 0;
  PyArrayObject *__pyx_v_fvec2 = 0;
  PyArrayObject *__pyx_v_vec_out = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec1;
  __Pyx_Buffer __pyx_pybuffer_fvec1;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec2;
  __Pyx_Buffer __pyx_pybuffer_fvec2;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vec_out;
  __Pyx_Buffer __pyx_pybuffer_vec_out;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("mul_3vecs", 0);
  __pyx_pybuffer_fvec1.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec1.refcount = 0;
  __pyx_pybuffernd_fvec1.data = NULL;
  __pyx_pybuffernd_fvec1.rcbuffer = &__pyx_pybuffer_fvec1;
  __pyx_pybuffer_fvec2.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec2.refcount = 0;
  __pyx_pybuffernd_fvec2.data = NULL;
  __pyx_pybuffernd_fvec2.rcbuffer = &__pyx_pybuffer_fvec2;
  __pyx_pybuffer_vec_out.pybuffer.buf = NULL;
  __pyx_pybuffer_vec_out.refcount = 0;
  __pyx_pybuffernd_vec_out.data = NULL;
  __pyx_pybuffernd_vec_out.rcbuffer = &__pyx_pybuffer_vec_out;

  /* "dipy/tracking/distances.pyx":163
 * 
 * def mul_3vecs(vec1, vec2):
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_vec1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_fvec1 = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_fvec1.rcbuffer->pybuffer.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 163; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_pybuffernd_fvec1.diminfo[0].strides = __pyx_pybuffernd_fvec1.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec1.diminfo[0].shape = __pyx_pybuffernd_fvec1.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_fvec1 = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":164
 * def mul_3vecs(vec1, vec2):
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 *     cmul_3vecs(<float *>fvec1.data, <float*>fvec2.data, <float *>vec_out.data)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_vec2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_fvec2 = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_fvec2.rcbuffer->pybuffer.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 164; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_pybuffernd_fvec2.diminfo[0].strides = __pyx_pybuffernd_fvec2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec2.diminfo[0].shape = __pyx_pybuffernd_fvec2.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_fvec2 = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":165
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)             # <<<<<<<<<<<<<<
 *     cmul_3vecs(<float *>fvec1.data, <float*>fvec2.data, <float *>vec_out.data)
 *     return vec_out
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_5 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(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_5 = 1;
    }
  }
  __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (__pyx_t_2) {
    __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); __pyx_t_2 = NULL;
  }
  __Pyx_INCREF(__pyx_tuple__4);
  __Pyx_GIVEREF(__pyx_tuple__4);
  PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_tuple__4);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __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_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vec_out.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_vec_out = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_vec_out.rcbuffer->pybuffer.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_pybuffernd_vec_out.diminfo[0].strides = __pyx_pybuffernd_vec_out.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vec_out.diminfo[0].shape = __pyx_pybuffernd_vec_out.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_7 = 0;
  __pyx_v_vec_out = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":166
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 *     cmul_3vecs(<float *>fvec1.data, <float*>fvec2.data, <float *>vec_out.data)             # <<<<<<<<<<<<<<
 *     return vec_out
 * 
 */
  __pyx_f_4dipy_8tracking_9distances_cmul_3vecs(((float *)__pyx_v_fvec1->data), ((float *)__pyx_v_fvec2->data), ((float *)__pyx_v_vec_out->data));

  /* "dipy/tracking/distances.pyx":167
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 *     cmul_3vecs(<float *>fvec1.data, <float*>fvec2.data, <float *>vec_out.data)
 *     return vec_out             # <<<<<<<<<<<<<<
 * 
 * cdef inline void cmul_3vecs(float *vec1, float *vec2, float *vec_out) nogil:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_vec_out));
  __pyx_r = ((PyObject *)__pyx_v_vec_out);
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":162
 *         vec_out[i] = vec1[i]+vec2[i]
 * 
 * def mul_3vecs(vec1, vec2):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 */

  /* 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_6);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vec_out.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.mul_3vecs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vec_out.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec1);
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec2);
  __Pyx_XDECREF((PyObject *)__pyx_v_vec_out);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":169
 *     return vec_out
 * 
 * cdef inline void cmul_3vecs(float *vec1, float *vec2, float *vec_out) nogil:             # <<<<<<<<<<<<<<
 *     cdef int i
 *     for i from 0<=i<3:
 */

static CYTHON_INLINE void __pyx_f_4dipy_8tracking_9distances_cmul_3vecs(float *__pyx_v_vec1, float *__pyx_v_vec2, float *__pyx_v_vec_out) {
  int __pyx_v_i;

  /* "dipy/tracking/distances.pyx":171
 * cdef inline void cmul_3vecs(float *vec1, float *vec2, float *vec_out) nogil:
 *     cdef int i
 *     for i from 0<=i<3:             # <<<<<<<<<<<<<<
 *         vec_out[i] = vec1[i]*vec2[i]
 * 
 */
  for (__pyx_v_i = 0; __pyx_v_i < 3; __pyx_v_i++) {

    /* "dipy/tracking/distances.pyx":172
 *     cdef int i
 *     for i from 0<=i<3:
 *         vec_out[i] = vec1[i]*vec2[i]             # <<<<<<<<<<<<<<
 * 
 * def mul_3vec(a, vec):
 */
    (__pyx_v_vec_out[__pyx_v_i]) = ((__pyx_v_vec1[__pyx_v_i]) * (__pyx_v_vec2[__pyx_v_i]));
  }

  /* "dipy/tracking/distances.pyx":169
 *     return vec_out
 * 
 * cdef inline void cmul_3vecs(float *vec1, float *vec2, float *vec_out) nogil:             # <<<<<<<<<<<<<<
 *     cdef int i
 *     for i from 0<=i<3:
 */

  /* function exit code */
}

/* "dipy/tracking/distances.pyx":174
 *         vec_out[i] = vec1[i]*vec2[i]
 * 
 * def mul_3vec(a, vec):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec = as_float_3vec(vec)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_13mul_3vec(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_13mul_3vec = {"mul_3vec", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_13mul_3vec, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_13mul_3vec(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_a = 0;
  PyObject *__pyx_v_vec = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("mul_3vec (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_a,&__pyx_n_s_vec,0};
    PyObject* values[2] = {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  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_a)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_vec)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("mul_3vec", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "mul_3vec") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_a = values[0];
    __pyx_v_vec = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("mul_3vec", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.mul_3vec", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_12mul_3vec(__pyx_self, __pyx_v_a, __pyx_v_vec);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_12mul_3vec(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_a, PyObject *__pyx_v_vec) {
  PyArrayObject *__pyx_v_fvec = 0;
  PyArrayObject *__pyx_v_vec_out = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec;
  __Pyx_Buffer __pyx_pybuffer_fvec;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_vec_out;
  __Pyx_Buffer __pyx_pybuffer_vec_out;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  float __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("mul_3vec", 0);
  __pyx_pybuffer_fvec.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec.refcount = 0;
  __pyx_pybuffernd_fvec.data = NULL;
  __pyx_pybuffernd_fvec.rcbuffer = &__pyx_pybuffer_fvec;
  __pyx_pybuffer_vec_out.pybuffer.buf = NULL;
  __pyx_pybuffer_vec_out.refcount = 0;
  __pyx_pybuffernd_vec_out.data = NULL;
  __pyx_pybuffernd_vec_out.rcbuffer = &__pyx_pybuffer_vec_out;

  /* "dipy/tracking/distances.pyx":175
 * 
 * def mul_3vec(a, vec):
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec = as_float_3vec(vec)             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 *     cmul_3vec(a,<float *>fvec.data, <float *>vec_out.data)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_vec)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_fvec = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_fvec.rcbuffer->pybuffer.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 175; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_pybuffernd_fvec.diminfo[0].strides = __pyx_pybuffernd_fvec.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec.diminfo[0].shape = __pyx_pybuffernd_fvec.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_v_fvec = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":176
 * def mul_3vec(a, vec):
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec = as_float_3vec(vec)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)             # <<<<<<<<<<<<<<
 *     cmul_3vec(a,<float *>fvec.data, <float *>vec_out.data)
 *     return vec_out
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_5 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(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_5 = 1;
    }
  }
  __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  if (__pyx_t_2) {
    __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); __pyx_t_2 = NULL;
  }
  __Pyx_INCREF(__pyx_tuple__5);
  __Pyx_GIVEREF(__pyx_tuple__5);
  PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_tuple__5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __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_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_vec_out.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
      __pyx_v_vec_out = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_vec_out.rcbuffer->pybuffer.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_pybuffernd_vec_out.diminfo[0].strides = __pyx_pybuffernd_vec_out.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_vec_out.diminfo[0].shape = __pyx_pybuffernd_vec_out.rcbuffer->pybuffer.shape[0];
    }
  }
  __pyx_t_7 = 0;
  __pyx_v_vec_out = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":177
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec = as_float_3vec(vec)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 *     cmul_3vec(a,<float *>fvec.data, <float *>vec_out.data)             # <<<<<<<<<<<<<<
 *     return vec_out
 * 
 */
  __pyx_t_8 = __pyx_PyFloat_AsFloat(__pyx_v_a); if (unlikely((__pyx_t_8 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 177; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_f_4dipy_8tracking_9distances_cmul_3vec(__pyx_t_8, ((float *)__pyx_v_fvec->data), ((float *)__pyx_v_vec_out->data));

  /* "dipy/tracking/distances.pyx":178
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 *     cmul_3vec(a,<float *>fvec.data, <float *>vec_out.data)
 *     return vec_out             # <<<<<<<<<<<<<<
 * 
 * cdef inline void cmul_3vec(float a, float *vec, float *vec_out) nogil:
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_vec_out));
  __pyx_r = ((PyObject *)__pyx_v_vec_out);
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":174
 *         vec_out[i] = vec1[i]*vec2[i]
 * 
 * def mul_3vec(a, vec):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec = as_float_3vec(vec)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 */

  /* 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_6);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vec_out.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.mul_3vec", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_vec_out.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec);
  __Pyx_XDECREF((PyObject *)__pyx_v_vec_out);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":180
 *     return vec_out
 * 
 * cdef inline void cmul_3vec(float a, float *vec, float *vec_out) nogil:             # <<<<<<<<<<<<<<
 *     cdef int i
 *     for i from 0<=i<3:
 */

static CYTHON_INLINE void __pyx_f_4dipy_8tracking_9distances_cmul_3vec(float __pyx_v_a, float *__pyx_v_vec, float *__pyx_v_vec_out) {
  int __pyx_v_i;

  /* "dipy/tracking/distances.pyx":182
 * cdef inline void cmul_3vec(float a, float *vec, float *vec_out) nogil:
 *     cdef int i
 *     for i from 0<=i<3:             # <<<<<<<<<<<<<<
 *         vec_out[i] = a*vec[i]
 * 
 */
  for (__pyx_v_i = 0; __pyx_v_i < 3; __pyx_v_i++) {

    /* "dipy/tracking/distances.pyx":183
 *     cdef int i
 *     for i from 0<=i<3:
 *         vec_out[i] = a*vec[i]             # <<<<<<<<<<<<<<
 * 
 * 
 */
    (__pyx_v_vec_out[__pyx_v_i]) = (__pyx_v_a * (__pyx_v_vec[__pyx_v_i]));
  }

  /* "dipy/tracking/distances.pyx":180
 *     return vec_out
 * 
 * cdef inline void cmul_3vec(float a, float *vec, float *vec_out) nogil:             # <<<<<<<<<<<<<<
 *     cdef int i
 *     for i from 0<=i<3:
 */

  /* function exit code */
}

/* "dipy/tracking/distances.pyx":190
 * 
 * 
 * def cut_plane(tracks, ref):             # <<<<<<<<<<<<<<
 *     ''' Extract divergence vectors and points of intersection
 *     between planes normal to the reference fiber and other tracks
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_15cut_plane(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_14cut_plane[] = " Extract divergence vectors and points of intersection\n    between planes normal to the reference fiber and other tracks\n\n    Parameters\n    ----------\n    tracks : sequence\n        of tracks as arrays, shape (N1,3) .. (Nm,3)\n    ref : array, shape (N,3)\n        reference track\n\n    Returns\n    -------\n    hits : sequence\n       list of points and rcds (radial coefficient of divergence)\n\n    Notes\n    -----\n    The orthogonality relationship\n    ``np.inner(hits[p][q][0:3]-ref[p+1],ref[p+2]-ref[r][p+1])`` will hold\n    throughout for every point q in the hits plane at point (p+1) on the\n    reference track.\n\n    Examples\n    --------\n    >>> refx = np.array([[0,0,0],[1,0,0],[2,0,0],[3,0,0]],dtype='float32')\n    >>> bundlex = [np.array([[0.5,1,0],[1.5,2,0],[2.5,3,0]],dtype='float32')]\n    >>> res = cut_plane(bundlex,refx)\n    >>> len(res)\n    2\n    >>> print(res[0])\n    [[ 1.          1.5         0.          0.70710683  0.        ]]\n    >>> print(res[1])\n    [[ 2.          2.5         0.          0.70710677  0.        ]]\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_15cut_plane = {"cut_plane", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_15cut_plane, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_14cut_plane};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_15cut_plane(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_tracks = 0;
  PyObject *__pyx_v_ref = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("cut_plane (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tracks,&__pyx_n_s_ref,0};
    PyObject* values[2] = {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  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tracks)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_ref)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("cut_plane", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "cut_plane") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_tracks = values[0];
    __pyx_v_ref = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("cut_plane", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.cut_plane", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_14cut_plane(__pyx_self, __pyx_v_tracks, __pyx_v_ref);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_14cut_plane(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tracks, PyObject *__pyx_v_ref) {
  size_t __pyx_v_n_hits;
  size_t __pyx_v_hit_no;
  size_t __pyx_v_max_hit_len;
  float __pyx_v_alpha;
  float __pyx_v_beta;
  float __pyx_v_rcd;
  float __pyx_v_lhp;
  float __pyx_v_ld;
  PyArrayObject *__pyx_v_ref32 = 0;
  PyArrayObject *__pyx_v_track = 0;
  PyObject *__pyx_v_hits = 0;
  PyArrayObject *__pyx_v_one_hit = 0;
  float *__pyx_v_hit_ptr;
  PyArrayObject *__pyx_v_hit_arr = 0;
  PyObject *__pyx_v_Hit = 0;
  size_t __pyx_v_N_tracks;
  PyArrayObject *__pyx_v_track_lengths = 0;
  size_t __pyx_v_t_no;
  size_t __pyx_v_N_track;
  PyObject *__pyx_v_tracks32 = 0;
  size_t __pyx_v_N_ref;
  size_t __pyx_v_p_no;
  size_t __pyx_v_q_no;
  float *__pyx_v_this_ref_p;
  float *__pyx_v_next_ref_p;
  float *__pyx_v_this_trk_p;
  float *__pyx_v_next_trk_p;
  float __pyx_v_along[3];
  float __pyx_v_normal[3];
  float __pyx_v_qMp[3];
  float __pyx_v_rMp[3];
  float __pyx_v_rMq[3];
  float __pyx_v_pMq[3];
  float __pyx_v_hit[3];
  float __pyx_v_hitMp[3];
  float *__pyx_v_delta;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_hit_arr;
  __Pyx_Buffer __pyx_pybuffer_hit_arr;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_one_hit;
  __Pyx_Buffer __pyx_pybuffer_one_hit;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ref32;
  __Pyx_Buffer __pyx_pybuffer_ref32;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_track;
  __Pyx_Buffer __pyx_pybuffer_track;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_track_lengths;
  __Pyx_Buffer __pyx_pybuffer_track_lengths;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyArrayObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyArrayObject *__pyx_t_12 = NULL;
  size_t __pyx_t_13;
  size_t __pyx_t_14;
  PyArrayObject *__pyx_t_15 = NULL;
  size_t __pyx_t_16;
  int __pyx_t_17;
  size_t __pyx_t_18;
  size_t __pyx_t_19;
  size_t __pyx_t_20;
  size_t __pyx_t_21;
  size_t __pyx_t_22;
  size_t __pyx_t_23;
  int __pyx_t_24;
  float __pyx_t_25;
  float __pyx_t_26;
  PyArrayObject *__pyx_t_27 = NULL;
  PyArrayObject *__pyx_t_28 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("cut_plane", 0);
  __pyx_pybuffer_ref32.pybuffer.buf = NULL;
  __pyx_pybuffer_ref32.refcount = 0;
  __pyx_pybuffernd_ref32.data = NULL;
  __pyx_pybuffernd_ref32.rcbuffer = &__pyx_pybuffer_ref32;
  __pyx_pybuffer_track.pybuffer.buf = NULL;
  __pyx_pybuffer_track.refcount = 0;
  __pyx_pybuffernd_track.data = NULL;
  __pyx_pybuffernd_track.rcbuffer = &__pyx_pybuffer_track;
  __pyx_pybuffer_one_hit.pybuffer.buf = NULL;
  __pyx_pybuffer_one_hit.refcount = 0;
  __pyx_pybuffernd_one_hit.data = NULL;
  __pyx_pybuffernd_one_hit.rcbuffer = &__pyx_pybuffer_one_hit;
  __pyx_pybuffer_hit_arr.pybuffer.buf = NULL;
  __pyx_pybuffer_hit_arr.refcount = 0;
  __pyx_pybuffernd_hit_arr.data = NULL;
  __pyx_pybuffernd_hit_arr.rcbuffer = &__pyx_pybuffer_hit_arr;
  __pyx_pybuffer_track_lengths.pybuffer.buf = NULL;
  __pyx_pybuffer_track_lengths.refcount = 0;
  __pyx_pybuffernd_track_lengths.data = NULL;
  __pyx_pybuffernd_track_lengths.rcbuffer = &__pyx_pybuffer_track_lengths;

  /* "dipy/tracking/distances.pyx":234
 *         float *hit_ptr
 *         cnp.ndarray[cnp.float32_t, ndim=2] hit_arr
 *         object Hit=[]             # <<<<<<<<<<<<<<
 *     # make reference fiber usable type
 *     ref32 = np.ascontiguousarray(ref, f32_dt)
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_Hit = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":236
 *         object Hit=[]
 *     # make reference fiber usable type
 *     ref32 = np.ascontiguousarray(ref, f32_dt)             # <<<<<<<<<<<<<<
 *     # convert all the tracks to something we can work with.  Get track
 *     # lengths
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_4 = 0;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(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_4 = 1;
    }
  }
  __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (__pyx_t_2) {
    __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL;
  }
  __Pyx_INCREF(__pyx_v_ref);
  __Pyx_GIVEREF(__pyx_v_ref);
  PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_ref);
  __Pyx_INCREF(((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt));
  PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt));
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __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_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ref32.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ref32.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ref32.rcbuffer->pybuffer, (PyObject*)__pyx_v_ref32, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
    }
    __pyx_pybuffernd_ref32.diminfo[0].strides = __pyx_pybuffernd_ref32.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ref32.diminfo[0].shape = __pyx_pybuffernd_ref32.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_ref32.diminfo[1].strides = __pyx_pybuffernd_ref32.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_ref32.diminfo[1].shape = __pyx_pybuffernd_ref32.rcbuffer->pybuffer.shape[1];
    if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_ref32 = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":240
 *     # lengths
 *     cdef:
 *         size_t N_tracks=len(tracks)             # <<<<<<<<<<<<<<
 *         cnp.ndarray[cnp.uint64_t, ndim=1] track_lengths
 *         size_t t_no, N_track
 */
  __pyx_t_4 = PyObject_Length(__pyx_v_tracks); if (unlikely(__pyx_t_4 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 240; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_N_tracks = __pyx_t_4;

  /* "dipy/tracking/distances.pyx":243
 *         cnp.ndarray[cnp.uint64_t, ndim=1] track_lengths
 *         size_t t_no, N_track
 *     cdef object tracks32 = []             # <<<<<<<<<<<<<<
 *     track_lengths = np.empty((N_tracks,), dtype=np.uint64)
 *     for t_no in range(N_tracks):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 243; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_tracks32 = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":244
 *         size_t t_no, N_track
 *     cdef object tracks32 = []
 *     track_lengths = np.empty((N_tracks,), dtype=np.uint64)             # <<<<<<<<<<<<<<
 *     for t_no in range(N_tracks):
 *         track = np.ascontiguousarray(tracks[t_no], f32_dt)
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyInt_FromSize_t(__pyx_v_N_tracks); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_uint64); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_11) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_12 = ((PyArrayObject *)__pyx_t_11);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track_lengths.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track_lengths.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track_lengths.rcbuffer->pybuffer, (PyObject*)__pyx_v_track_lengths, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint64_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
    }
    __pyx_pybuffernd_track_lengths.diminfo[0].strides = __pyx_pybuffernd_track_lengths.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_track_lengths.diminfo[0].shape = __pyx_pybuffernd_track_lengths.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_12 = 0;
  __pyx_v_track_lengths = ((PyArrayObject *)__pyx_t_11);
  __pyx_t_11 = 0;

  /* "dipy/tracking/distances.pyx":245
 *     cdef object tracks32 = []
 *     track_lengths = np.empty((N_tracks,), dtype=np.uint64)
 *     for t_no in range(N_tracks):             # <<<<<<<<<<<<<<
 *         track = np.ascontiguousarray(tracks[t_no], f32_dt)
 *         track_lengths[t_no] = track.shape[0]
 */
  __pyx_t_13 = __pyx_v_N_tracks;
  for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
    __pyx_v_t_no = __pyx_t_14;

    /* "dipy/tracking/distances.pyx":246
 *     track_lengths = np.empty((N_tracks,), dtype=np.uint64)
 *     for t_no in range(N_tracks):
 *         track = np.ascontiguousarray(tracks[t_no], f32_dt)             # <<<<<<<<<<<<<<
 *         track_lengths[t_no] = track.shape[0]
 *         tracks32.append(track)
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_tracks, __pyx_v_t_no, size_t, 0, __Pyx_PyInt_FromSize_t, 0, 0, 1); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = NULL;
    __pyx_t_4 = 0;
    if (CYTHON_COMPILING_IN_CPYTHON && 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 = 1;
      }
    }
    __pyx_t_2 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    if (__pyx_t_3) {
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __pyx_t_3 = NULL;
    }
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_4, __pyx_t_5);
    __Pyx_INCREF(((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt));
    PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_4, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt));
    __pyx_t_5 = 0;
    __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_15 = ((PyArrayObject *)__pyx_t_11);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
      __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track.rcbuffer->pybuffer, (PyObject*)__pyx_t_15, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_7 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track.rcbuffer->pybuffer, (PyObject*)__pyx_v_track, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
      }
      __pyx_pybuffernd_track.diminfo[0].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_track.diminfo[0].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_track.diminfo[1].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_track.diminfo[1].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 246; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_15 = 0;
    __Pyx_XDECREF_SET(__pyx_v_track, ((PyArrayObject *)__pyx_t_11));
    __pyx_t_11 = 0;

    /* "dipy/tracking/distances.pyx":247
 *     for t_no in range(N_tracks):
 *         track = np.ascontiguousarray(tracks[t_no], f32_dt)
 *         track_lengths[t_no] = track.shape[0]             # <<<<<<<<<<<<<<
 *         tracks32.append(track)
 *     # set up loop across reference fiber points
 */
    __pyx_t_16 = __pyx_v_t_no;
    __pyx_t_7 = -1;
    if (unlikely(__pyx_t_16 >= (size_t)__pyx_pybuffernd_track_lengths.diminfo[0].shape)) __pyx_t_7 = 0;
    if (unlikely(__pyx_t_7 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_7);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 247; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint64_t *, __pyx_pybuffernd_track_lengths.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_track_lengths.diminfo[0].strides) = (__pyx_v_track->dimensions[0]);

    /* "dipy/tracking/distances.pyx":248
 *         track = np.ascontiguousarray(tracks[t_no], f32_dt)
 *         track_lengths[t_no] = track.shape[0]
 *         tracks32.append(track)             # <<<<<<<<<<<<<<
 *     # set up loop across reference fiber points
 *     cdef:
 */
    __pyx_t_17 = __Pyx_PyObject_Append(__pyx_v_tracks32, ((PyObject *)__pyx_v_track)); if (unlikely(__pyx_t_17 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "dipy/tracking/distances.pyx":251
 *     # set up loop across reference fiber points
 *     cdef:
 *         size_t N_ref = ref32.shape[0]             # <<<<<<<<<<<<<<
 *         size_t p_no, q_no
 *         float *this_ref_p, *next_ref_p, *this_trk_p, *next_trk_p
 */
  __pyx_v_N_ref = (__pyx_v_ref32->dimensions[0]);

  /* "dipy/tracking/distances.pyx":260
 *     # small numpy arrays, and reuse them over the reference track point
 *     # loops.
 *     max_hit_len = 0             # <<<<<<<<<<<<<<
 *     hits = []
 *     # for every point along the reference track
 */
  __pyx_v_max_hit_len = 0;

  /* "dipy/tracking/distances.pyx":261
 *     # loops.
 *     max_hit_len = 0
 *     hits = []             # <<<<<<<<<<<<<<
 *     # for every point along the reference track
 *     next_ref_p = asfp(ref32[0])
 */
  __pyx_t_11 = PyList_New(0); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 261; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_v_hits = __pyx_t_11;
  __pyx_t_11 = 0;

  /* "dipy/tracking/distances.pyx":263
 *     hits = []
 *     # for every point along the reference track
 *     next_ref_p = asfp(ref32[0])             # <<<<<<<<<<<<<<
 *     for p_no in range(N_ref-1):
 *         # extract point to point vector into `along`
 */
  __pyx_t_11 = __Pyx_GetItemInt(((PyObject *)__pyx_v_ref32), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_11 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_11);
  if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_next_ref_p = __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_11));
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

  /* "dipy/tracking/distances.pyx":264
 *     # for every point along the reference track
 *     next_ref_p = asfp(ref32[0])
 *     for p_no in range(N_ref-1):             # <<<<<<<<<<<<<<
 *         # extract point to point vector into `along`
 *         this_ref_p = next_ref_p
 */
  __pyx_t_13 = (__pyx_v_N_ref - 1);
  for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
    __pyx_v_p_no = __pyx_t_14;

    /* "dipy/tracking/distances.pyx":266
 *     for p_no in range(N_ref-1):
 *         # extract point to point vector into `along`
 *         this_ref_p = next_ref_p             # <<<<<<<<<<<<<<
 *         next_ref_p = asfp(ref32[p_no+1])
 *         csub_3vecs(next_ref_p, this_ref_p, along)
 */
    __pyx_v_this_ref_p = __pyx_v_next_ref_p;

    /* "dipy/tracking/distances.pyx":267
 *         # extract point to point vector into `along`
 *         this_ref_p = next_ref_p
 *         next_ref_p = asfp(ref32[p_no+1])             # <<<<<<<<<<<<<<
 *         csub_3vecs(next_ref_p, this_ref_p, along)
 *         # normalize
 */
    __pyx_t_18 = (__pyx_v_p_no + 1);
    __pyx_t_11 = __Pyx_GetItemInt(((PyObject *)__pyx_v_ref32), __pyx_t_18, size_t, 0, __Pyx_PyInt_FromSize_t, 0, 0, 1); if (unlikely(__pyx_t_11 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_11);
    if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_next_ref_p = __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_11));
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

    /* "dipy/tracking/distances.pyx":268
 *         this_ref_p = next_ref_p
 *         next_ref_p = asfp(ref32[p_no+1])
 *         csub_3vecs(next_ref_p, this_ref_p, along)             # <<<<<<<<<<<<<<
 *         # normalize
 *         cnormalized_3vec(along, normal)
 */
    __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_next_ref_p, __pyx_v_this_ref_p, __pyx_v_along);

    /* "dipy/tracking/distances.pyx":270
 *         csub_3vecs(next_ref_p, this_ref_p, along)
 *         # normalize
 *         cnormalized_3vec(along, normal)             # <<<<<<<<<<<<<<
 *         # initialize index for hits
 *         hit_no = 0
 */
    __pyx_f_4dipy_8tracking_9distances_cnormalized_3vec(__pyx_v_along, __pyx_v_normal);

    /* "dipy/tracking/distances.pyx":272
 *         cnormalized_3vec(along, normal)
 *         # initialize index for hits
 *         hit_no = 0             # <<<<<<<<<<<<<<
 *         # for every track
 *         for t_no in range(N_tracks):
 */
    __pyx_v_hit_no = 0;

    /* "dipy/tracking/distances.pyx":274
 *         hit_no = 0
 *         # for every track
 *         for t_no in range(N_tracks):             # <<<<<<<<<<<<<<
 *             track=tracks32[t_no]
 *             N_track = track_lengths[t_no]
 */
    __pyx_t_18 = __pyx_v_N_tracks;
    for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_18; __pyx_t_19+=1) {
      __pyx_v_t_no = __pyx_t_19;

      /* "dipy/tracking/distances.pyx":275
 *         # for every track
 *         for t_no in range(N_tracks):
 *             track=tracks32[t_no]             # <<<<<<<<<<<<<<
 *             N_track = track_lengths[t_no]
 *             # for every point on the track
 */
      __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_tracks32, __pyx_v_t_no, size_t, 0, __Pyx_PyInt_FromSize_t, 0, 0, 1); if (unlikely(__pyx_t_11 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_11);
      if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_15 = ((PyArrayObject *)__pyx_t_11);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
        __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track.rcbuffer->pybuffer, (PyObject*)__pyx_t_15, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_7 < 0)) {
          PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track.rcbuffer->pybuffer, (PyObject*)__pyx_v_track, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
          }
        }
        __pyx_pybuffernd_track.diminfo[0].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_track.diminfo[0].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_track.diminfo[1].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_track.diminfo[1].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 275; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_15 = 0;
      __Pyx_XDECREF_SET(__pyx_v_track, ((PyArrayObject *)__pyx_t_11));
      __pyx_t_11 = 0;

      /* "dipy/tracking/distances.pyx":276
 *         for t_no in range(N_tracks):
 *             track=tracks32[t_no]
 *             N_track = track_lengths[t_no]             # <<<<<<<<<<<<<<
 *             # for every point on the track
 *             next_trk_p = asfp(track[0])
 */
      __pyx_t_20 = __pyx_v_t_no;
      __pyx_t_7 = -1;
      if (unlikely(__pyx_t_20 >= (size_t)__pyx_pybuffernd_track_lengths.diminfo[0].shape)) __pyx_t_7 = 0;
      if (unlikely(__pyx_t_7 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_7);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 276; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_v_N_track = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint64_t *, __pyx_pybuffernd_track_lengths.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_track_lengths.diminfo[0].strides));

      /* "dipy/tracking/distances.pyx":278
 *             N_track = track_lengths[t_no]
 *             # for every point on the track
 *             next_trk_p = asfp(track[0])             # <<<<<<<<<<<<<<
 *             for q_no in range(N_track-1):
 *                 # p = ref32[p_no]
 */
      __pyx_t_11 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_11 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_11);
      if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_next_trk_p = __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_11));
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

      /* "dipy/tracking/distances.pyx":279
 *             # for every point on the track
 *             next_trk_p = asfp(track[0])
 *             for q_no in range(N_track-1):             # <<<<<<<<<<<<<<
 *                 # p = ref32[p_no]
 *                 # q = track[q_no]
 */
      __pyx_t_21 = (__pyx_v_N_track - 1);
      for (__pyx_t_22 = 0; __pyx_t_22 < __pyx_t_21; __pyx_t_22+=1) {
        __pyx_v_q_no = __pyx_t_22;

        /* "dipy/tracking/distances.pyx":284
 *                 # r = track[q_no+1]
 *                 # float* versions of above: p == this_ref_p
 *                 this_trk_p = next_trk_p # q             # <<<<<<<<<<<<<<
 *                 next_trk_p = asfp(track[q_no+1]) # r
 *                 #if np.inner(normal,q-p)*np.inner(normal,r-p) <= 0:
 */
        __pyx_v_this_trk_p = __pyx_v_next_trk_p;

        /* "dipy/tracking/distances.pyx":285
 *                 # float* versions of above: p == this_ref_p
 *                 this_trk_p = next_trk_p # q
 *                 next_trk_p = asfp(track[q_no+1]) # r             # <<<<<<<<<<<<<<
 *                 #if np.inner(normal,q-p)*np.inner(normal,r-p) <= 0:
 *                 csub_3vecs(this_trk_p, this_ref_p, qMp) # q-p
 */
        __pyx_t_23 = (__pyx_v_q_no + 1);
        __pyx_t_11 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), __pyx_t_23, size_t, 0, __Pyx_PyInt_FromSize_t, 0, 0, 1); if (unlikely(__pyx_t_11 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_11);
        if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __pyx_v_next_trk_p = __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_11));
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

        /* "dipy/tracking/distances.pyx":287
 *                 next_trk_p = asfp(track[q_no+1]) # r
 *                 #if np.inner(normal,q-p)*np.inner(normal,r-p) <= 0:
 *                 csub_3vecs(this_trk_p, this_ref_p, qMp) # q-p             # <<<<<<<<<<<<<<
 *                 csub_3vecs(next_trk_p, this_ref_p, rMp) # r-p
 *                 if (cinner_3vecs(normal, qMp) * cinner_3vecs(normal, rMp)) <=0:
 */
        __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_this_trk_p, __pyx_v_this_ref_p, __pyx_v_qMp);

        /* "dipy/tracking/distances.pyx":288
 *                 #if np.inner(normal,q-p)*np.inner(normal,r-p) <= 0:
 *                 csub_3vecs(this_trk_p, this_ref_p, qMp) # q-p
 *                 csub_3vecs(next_trk_p, this_ref_p, rMp) # r-p             # <<<<<<<<<<<<<<
 *                 if (cinner_3vecs(normal, qMp) * cinner_3vecs(normal, rMp)) <=0:
 *                     #if np.inner((r-q),normal) != 0:
 */
        __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_next_trk_p, __pyx_v_this_ref_p, __pyx_v_rMp);

        /* "dipy/tracking/distances.pyx":289
 *                 csub_3vecs(this_trk_p, this_ref_p, qMp) # q-p
 *                 csub_3vecs(next_trk_p, this_ref_p, rMp) # r-p
 *                 if (cinner_3vecs(normal, qMp) * cinner_3vecs(normal, rMp)) <=0:             # <<<<<<<<<<<<<<
 *                     #if np.inner((r-q),normal) != 0:
 *                     csub_3vecs(next_trk_p, this_trk_p, rMq)
 */
        __pyx_t_24 = (((__pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_normal, __pyx_v_qMp) * __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_normal, __pyx_v_rMp)) <= 0.0) != 0);
        if (__pyx_t_24) {

          /* "dipy/tracking/distances.pyx":291
 *                 if (cinner_3vecs(normal, qMp) * cinner_3vecs(normal, rMp)) <=0:
 *                     #if np.inner((r-q),normal) != 0:
 *                     csub_3vecs(next_trk_p, this_trk_p, rMq)             # <<<<<<<<<<<<<<
 *                     beta = cinner_3vecs(rMq, normal)
 *                     if beta !=0:
 */
          __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_next_trk_p, __pyx_v_this_trk_p, __pyx_v_rMq);

          /* "dipy/tracking/distances.pyx":292
 *                     #if np.inner((r-q),normal) != 0:
 *                     csub_3vecs(next_trk_p, this_trk_p, rMq)
 *                     beta = cinner_3vecs(rMq, normal)             # <<<<<<<<<<<<<<
 *                     if beta !=0:
 *                         #alpha = np.inner((p-q),normal)/np.inner((r-q),normal)
 */
          __pyx_v_beta = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_rMq, __pyx_v_normal);

          /* "dipy/tracking/distances.pyx":293
 *                     csub_3vecs(next_trk_p, this_trk_p, rMq)
 *                     beta = cinner_3vecs(rMq, normal)
 *                     if beta !=0:             # <<<<<<<<<<<<<<
 *                         #alpha = np.inner((p-q),normal)/np.inner((r-q),normal)
 *                         csub_3vecs(this_ref_p, this_trk_p, pMq)
 */
          __pyx_t_24 = ((__pyx_v_beta != 0.0) != 0);
          if (__pyx_t_24) {

            /* "dipy/tracking/distances.pyx":295
 *                     if beta !=0:
 *                         #alpha = np.inner((p-q),normal)/np.inner((r-q),normal)
 *                         csub_3vecs(this_ref_p, this_trk_p, pMq)             # <<<<<<<<<<<<<<
 *                         alpha = (cinner_3vecs(pMq, normal) /
 *                                   cinner_3vecs(rMq, normal))
 */
            __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_this_ref_p, __pyx_v_this_trk_p, __pyx_v_pMq);

            /* "dipy/tracking/distances.pyx":296
 *                         #alpha = np.inner((p-q),normal)/np.inner((r-q),normal)
 *                         csub_3vecs(this_ref_p, this_trk_p, pMq)
 *                         alpha = (cinner_3vecs(pMq, normal) /             # <<<<<<<<<<<<<<
 *                                   cinner_3vecs(rMq, normal))
 *                         if alpha < 1:
 */
            __pyx_t_25 = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_pMq, __pyx_v_normal);

            /* "dipy/tracking/distances.pyx":297
 *                         csub_3vecs(this_ref_p, this_trk_p, pMq)
 *                         alpha = (cinner_3vecs(pMq, normal) /
 *                                   cinner_3vecs(rMq, normal))             # <<<<<<<<<<<<<<
 *                         if alpha < 1:
 *                             # hit = q+alpha*(r-q)
 */
            __pyx_t_26 = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_rMq, __pyx_v_normal);

            /* "dipy/tracking/distances.pyx":296
 *                         #alpha = np.inner((p-q),normal)/np.inner((r-q),normal)
 *                         csub_3vecs(this_ref_p, this_trk_p, pMq)
 *                         alpha = (cinner_3vecs(pMq, normal) /             # <<<<<<<<<<<<<<
 *                                   cinner_3vecs(rMq, normal))
 *                         if alpha < 1:
 */
            if (unlikely(__pyx_t_26 == 0)) {
              PyErr_SetString(PyExc_ZeroDivisionError, "float division");
              {__pyx_filename = __pyx_f[0]; __pyx_lineno = 296; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
            }
            __pyx_v_alpha = (__pyx_t_25 / __pyx_t_26);

            /* "dipy/tracking/distances.pyx":298
 *                         alpha = (cinner_3vecs(pMq, normal) /
 *                                   cinner_3vecs(rMq, normal))
 *                         if alpha < 1:             # <<<<<<<<<<<<<<
 *                             # hit = q+alpha*(r-q)
 *                             hit[0] = this_trk_p[0]+alpha*rMq[0]
 */
            __pyx_t_24 = ((__pyx_v_alpha < 1.0) != 0);
            if (__pyx_t_24) {

              /* "dipy/tracking/distances.pyx":300
 *                         if alpha < 1:
 *                             # hit = q+alpha*(r-q)
 *                             hit[0] = this_trk_p[0]+alpha*rMq[0]             # <<<<<<<<<<<<<<
 *                             hit[1] = this_trk_p[1]+alpha*rMq[1]
 *                             hit[2] = this_trk_p[2]+alpha*rMq[2]
 */
              (__pyx_v_hit[0]) = ((__pyx_v_this_trk_p[0]) + (__pyx_v_alpha * (__pyx_v_rMq[0])));

              /* "dipy/tracking/distances.pyx":301
 *                             # hit = q+alpha*(r-q)
 *                             hit[0] = this_trk_p[0]+alpha*rMq[0]
 *                             hit[1] = this_trk_p[1]+alpha*rMq[1]             # <<<<<<<<<<<<<<
 *                             hit[2] = this_trk_p[2]+alpha*rMq[2]
 *                             # h-p
 */
              (__pyx_v_hit[1]) = ((__pyx_v_this_trk_p[1]) + (__pyx_v_alpha * (__pyx_v_rMq[1])));

              /* "dipy/tracking/distances.pyx":302
 *                             hit[0] = this_trk_p[0]+alpha*rMq[0]
 *                             hit[1] = this_trk_p[1]+alpha*rMq[1]
 *                             hit[2] = this_trk_p[2]+alpha*rMq[2]             # <<<<<<<<<<<<<<
 *                             # h-p
 *                             csub_3vecs(hit, this_ref_p, hitMp)
 */
              (__pyx_v_hit[2]) = ((__pyx_v_this_trk_p[2]) + (__pyx_v_alpha * (__pyx_v_rMq[2])));

              /* "dipy/tracking/distances.pyx":304
 *                             hit[2] = this_trk_p[2]+alpha*rMq[2]
 *                             # h-p
 *                             csub_3vecs(hit, this_ref_p, hitMp)             # <<<<<<<<<<<<<<
 *                             # |h-p|
 *                             lhp = cnorm_3vec(hitMp)
 */
              __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_hit, __pyx_v_this_ref_p, __pyx_v_hitMp);

              /* "dipy/tracking/distances.pyx":306
 *                             csub_3vecs(hit, this_ref_p, hitMp)
 *                             # |h-p|
 *                             lhp = cnorm_3vec(hitMp)             # <<<<<<<<<<<<<<
 *                             delta = rMq # just renaming
 *                             # |r-q| == |delta|
 */
              __pyx_v_lhp = __pyx_f_4dipy_8tracking_9distances_cnorm_3vec(__pyx_v_hitMp);

              /* "dipy/tracking/distances.pyx":307
 *                             # |h-p|
 *                             lhp = cnorm_3vec(hitMp)
 *                             delta = rMq # just renaming             # <<<<<<<<<<<<<<
 *                             # |r-q| == |delta|
 *                             ld = cnorm_3vec(delta)
 */
              __pyx_v_delta = __pyx_v_rMq;

              /* "dipy/tracking/distances.pyx":309
 *                             delta = rMq # just renaming
 *                             # |r-q| == |delta|
 *                             ld = cnorm_3vec(delta)             # <<<<<<<<<<<<<<
 *                             ''' # Summary of stuff in comments
 *                             # divergence =((r-q)-inner(r-q,normal)*normal)/|r-q|
 */
              __pyx_v_ld = __pyx_f_4dipy_8tracking_9distances_cnorm_3vec(__pyx_v_delta);

              /* "dipy/tracking/distances.pyx":319
 *                             # radial divergence
 *                             # np.inner(delta, (hit-p)) / (ld * lhp)
 *                             if lhp > 0:             # <<<<<<<<<<<<<<
 *                                 rcd = fabs(cinner_3vecs(delta, hitMp)
 *                                            / (ld*lhp))
 */
              __pyx_t_24 = ((__pyx_v_lhp > 0.0) != 0);
              if (__pyx_t_24) {

                /* "dipy/tracking/distances.pyx":320
 *                             # np.inner(delta, (hit-p)) / (ld * lhp)
 *                             if lhp > 0:
 *                                 rcd = fabs(cinner_3vecs(delta, hitMp)             # <<<<<<<<<<<<<<
 *                                            / (ld*lhp))
 *                             else:
 */
                __pyx_t_26 = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_delta, __pyx_v_hitMp);

                /* "dipy/tracking/distances.pyx":321
 *                             if lhp > 0:
 *                                 rcd = fabs(cinner_3vecs(delta, hitMp)
 *                                            / (ld*lhp))             # <<<<<<<<<<<<<<
 *                             else:
 *                                 rcd=0
 */
                __pyx_t_25 = (__pyx_v_ld * __pyx_v_lhp);
                if (unlikely(__pyx_t_25 == 0)) {
                  PyErr_SetString(PyExc_ZeroDivisionError, "float division");
                  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
                }

                /* "dipy/tracking/distances.pyx":320
 *                             # np.inner(delta, (hit-p)) / (ld * lhp)
 *                             if lhp > 0:
 *                                 rcd = fabs(cinner_3vecs(delta, hitMp)             # <<<<<<<<<<<<<<
 *                                            / (ld*lhp))
 *                             else:
 */
                __pyx_v_rcd = fabs((__pyx_t_26 / __pyx_t_25));

                /* "dipy/tracking/distances.pyx":319
 *                             # radial divergence
 *                             # np.inner(delta, (hit-p)) / (ld * lhp)
 *                             if lhp > 0:             # <<<<<<<<<<<<<<
 *                                 rcd = fabs(cinner_3vecs(delta, hitMp)
 *                                            / (ld*lhp))
 */
                goto __pyx_L14;
              }

              /* "dipy/tracking/distances.pyx":323
 *                                            / (ld*lhp))
 *                             else:
 *                                 rcd=0             # <<<<<<<<<<<<<<
 *                             # hit data into array
 *                             if hit_no >= max_hit_len:
 */
              /*else*/ {
                __pyx_v_rcd = 0.0;
              }
              __pyx_L14:;

              /* "dipy/tracking/distances.pyx":325
 *                                 rcd=0
 *                             # hit data into array
 *                             if hit_no >= max_hit_len:             # <<<<<<<<<<<<<<
 *                                 one_hit = np.empty((5,), dtype=f32_dt)
 *                                 hits.append(one_hit)
 */
              __pyx_t_24 = ((__pyx_v_hit_no >= __pyx_v_max_hit_len) != 0);
              if (__pyx_t_24) {

                /* "dipy/tracking/distances.pyx":326
 *                             # hit data into array
 *                             if hit_no >= max_hit_len:
 *                                 one_hit = np.empty((5,), dtype=f32_dt)             # <<<<<<<<<<<<<<
 *                                 hits.append(one_hit)
 *                             else:
 */
                __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
                __Pyx_GOTREF(__pyx_t_11);
                __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_empty); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
                __Pyx_GOTREF(__pyx_t_1);
                __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
                __pyx_t_11 = PyDict_New(); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
                __Pyx_GOTREF(__pyx_t_11);
                if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
                __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__7, __pyx_t_11); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
                __Pyx_GOTREF(__pyx_t_2);
                __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
                __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
                if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
                __pyx_t_27 = ((PyArrayObject *)__pyx_t_2);
                {
                  __Pyx_BufFmt_StackElem __pyx_stack[1];
                  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_one_hit.rcbuffer->pybuffer);
                  __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_one_hit.rcbuffer->pybuffer, (PyObject*)__pyx_t_27, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
                  if (unlikely(__pyx_t_7 < 0)) {
                    PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
                    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_one_hit.rcbuffer->pybuffer, (PyObject*)__pyx_v_one_hit, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
                      Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
                      __Pyx_RaiseBufferFallbackError();
                    } else {
                      PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
                    }
                  }
                  __pyx_pybuffernd_one_hit.diminfo[0].strides = __pyx_pybuffernd_one_hit.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_one_hit.diminfo[0].shape = __pyx_pybuffernd_one_hit.rcbuffer->pybuffer.shape[0];
                  if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
                }
                __pyx_t_27 = 0;
                __Pyx_XDECREF_SET(__pyx_v_one_hit, ((PyArrayObject *)__pyx_t_2));
                __pyx_t_2 = 0;

                /* "dipy/tracking/distances.pyx":327
 *                             if hit_no >= max_hit_len:
 *                                 one_hit = np.empty((5,), dtype=f32_dt)
 *                                 hits.append(one_hit)             # <<<<<<<<<<<<<<
 *                             else:
 *                                 one_hit = hits[hit_no]
 */
                __pyx_t_17 = __Pyx_PyObject_Append(__pyx_v_hits, ((PyObject *)__pyx_v_one_hit)); if (unlikely(__pyx_t_17 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

                /* "dipy/tracking/distances.pyx":325
 *                                 rcd=0
 *                             # hit data into array
 *                             if hit_no >= max_hit_len:             # <<<<<<<<<<<<<<
 *                                 one_hit = np.empty((5,), dtype=f32_dt)
 *                                 hits.append(one_hit)
 */
                goto __pyx_L15;
              }

              /* "dipy/tracking/distances.pyx":329
 *                                 hits.append(one_hit)
 *                             else:
 *                                 one_hit = hits[hit_no]             # <<<<<<<<<<<<<<
 *                             hit_ptr = <float *>one_hit.data
 *                             hit_ptr[0] = hit[0]
 */
              /*else*/ {
                __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_hits, __pyx_v_hit_no, size_t, 0, __Pyx_PyInt_FromSize_t, 0, 0, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
                __Pyx_GOTREF(__pyx_t_2);
                if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
                __pyx_t_27 = ((PyArrayObject *)__pyx_t_2);
                {
                  __Pyx_BufFmt_StackElem __pyx_stack[1];
                  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_one_hit.rcbuffer->pybuffer);
                  __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_one_hit.rcbuffer->pybuffer, (PyObject*)__pyx_t_27, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
                  if (unlikely(__pyx_t_7 < 0)) {
                    PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
                    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_one_hit.rcbuffer->pybuffer, (PyObject*)__pyx_v_one_hit, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
                      Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
                      __Pyx_RaiseBufferFallbackError();
                    } else {
                      PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
                    }
                  }
                  __pyx_pybuffernd_one_hit.diminfo[0].strides = __pyx_pybuffernd_one_hit.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_one_hit.diminfo[0].shape = __pyx_pybuffernd_one_hit.rcbuffer->pybuffer.shape[0];
                  if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 329; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
                }
                __pyx_t_27 = 0;
                __Pyx_XDECREF_SET(__pyx_v_one_hit, ((PyArrayObject *)__pyx_t_2));
                __pyx_t_2 = 0;
              }
              __pyx_L15:;

              /* "dipy/tracking/distances.pyx":330
 *                             else:
 *                                 one_hit = hits[hit_no]
 *                             hit_ptr = <float *>one_hit.data             # <<<<<<<<<<<<<<
 *                             hit_ptr[0] = hit[0]
 *                             hit_ptr[1] = hit[1]
 */
              __pyx_v_hit_ptr = ((float *)__pyx_v_one_hit->data);

              /* "dipy/tracking/distances.pyx":331
 *                                 one_hit = hits[hit_no]
 *                             hit_ptr = <float *>one_hit.data
 *                             hit_ptr[0] = hit[0]             # <<<<<<<<<<<<<<
 *                             hit_ptr[1] = hit[1]
 *                             hit_ptr[2] = hit[2]
 */
              (__pyx_v_hit_ptr[0]) = (__pyx_v_hit[0]);

              /* "dipy/tracking/distances.pyx":332
 *                             hit_ptr = <float *>one_hit.data
 *                             hit_ptr[0] = hit[0]
 *                             hit_ptr[1] = hit[1]             # <<<<<<<<<<<<<<
 *                             hit_ptr[2] = hit[2]
 *                             hit_ptr[3] = rcd
 */
              (__pyx_v_hit_ptr[1]) = (__pyx_v_hit[1]);

              /* "dipy/tracking/distances.pyx":333
 *                             hit_ptr[0] = hit[0]
 *                             hit_ptr[1] = hit[1]
 *                             hit_ptr[2] = hit[2]             # <<<<<<<<<<<<<<
 *                             hit_ptr[3] = rcd
 *                             hit_ptr[4] = t_no
 */
              (__pyx_v_hit_ptr[2]) = (__pyx_v_hit[2]);

              /* "dipy/tracking/distances.pyx":334
 *                             hit_ptr[1] = hit[1]
 *                             hit_ptr[2] = hit[2]
 *                             hit_ptr[3] = rcd             # <<<<<<<<<<<<<<
 *                             hit_ptr[4] = t_no
 *                             hit_no += 1
 */
              (__pyx_v_hit_ptr[3]) = __pyx_v_rcd;

              /* "dipy/tracking/distances.pyx":335
 *                             hit_ptr[2] = hit[2]
 *                             hit_ptr[3] = rcd
 *                             hit_ptr[4] = t_no             # <<<<<<<<<<<<<<
 *                             hit_no += 1
 *         # convert hits list to hits array
 */
              (__pyx_v_hit_ptr[4]) = __pyx_v_t_no;

              /* "dipy/tracking/distances.pyx":336
 *                             hit_ptr[3] = rcd
 *                             hit_ptr[4] = t_no
 *                             hit_no += 1             # <<<<<<<<<<<<<<
 *         # convert hits list to hits array
 *         n_hits = hit_no
 */
              __pyx_v_hit_no = (__pyx_v_hit_no + 1);

              /* "dipy/tracking/distances.pyx":298
 *                         alpha = (cinner_3vecs(pMq, normal) /
 *                                   cinner_3vecs(rMq, normal))
 *                         if alpha < 1:             # <<<<<<<<<<<<<<
 *                             # hit = q+alpha*(r-q)
 *                             hit[0] = this_trk_p[0]+alpha*rMq[0]
 */
            }

            /* "dipy/tracking/distances.pyx":293
 *                     csub_3vecs(next_trk_p, this_trk_p, rMq)
 *                     beta = cinner_3vecs(rMq, normal)
 *                     if beta !=0:             # <<<<<<<<<<<<<<
 *                         #alpha = np.inner((p-q),normal)/np.inner((r-q),normal)
 *                         csub_3vecs(this_ref_p, this_trk_p, pMq)
 */
          }

          /* "dipy/tracking/distances.pyx":289
 *                 csub_3vecs(this_trk_p, this_ref_p, qMp) # q-p
 *                 csub_3vecs(next_trk_p, this_ref_p, rMp) # r-p
 *                 if (cinner_3vecs(normal, qMp) * cinner_3vecs(normal, rMp)) <=0:             # <<<<<<<<<<<<<<
 *                     #if np.inner((r-q),normal) != 0:
 *                     csub_3vecs(next_trk_p, this_trk_p, rMq)
 */
        }
      }
    }

    /* "dipy/tracking/distances.pyx":338
 *                             hit_no += 1
 *         # convert hits list to hits array
 *         n_hits = hit_no             # <<<<<<<<<<<<<<
 *         if n_hits > max_hit_len:
 *             max_hit_len = n_hits
 */
    __pyx_v_n_hits = __pyx_v_hit_no;

    /* "dipy/tracking/distances.pyx":339
 *         # convert hits list to hits array
 *         n_hits = hit_no
 *         if n_hits > max_hit_len:             # <<<<<<<<<<<<<<
 *             max_hit_len = n_hits
 *         hit_arr = np.empty((n_hits,5), dtype=f32_dt)
 */
    __pyx_t_24 = ((__pyx_v_n_hits > __pyx_v_max_hit_len) != 0);
    if (__pyx_t_24) {

      /* "dipy/tracking/distances.pyx":340
 *         n_hits = hit_no
 *         if n_hits > max_hit_len:
 *             max_hit_len = n_hits             # <<<<<<<<<<<<<<
 *         hit_arr = np.empty((n_hits,5), dtype=f32_dt)
 *         for hit_no in range(n_hits):
 */
      __pyx_v_max_hit_len = __pyx_v_n_hits;

      /* "dipy/tracking/distances.pyx":339
 *         # convert hits list to hits array
 *         n_hits = hit_no
 *         if n_hits > max_hit_len:             # <<<<<<<<<<<<<<
 *             max_hit_len = n_hits
 *         hit_arr = np.empty((n_hits,5), dtype=f32_dt)
 */
    }

    /* "dipy/tracking/distances.pyx":341
 *         if n_hits > max_hit_len:
 *             max_hit_len = n_hits
 *         hit_arr = np.empty((n_hits,5), dtype=f32_dt)             # <<<<<<<<<<<<<<
 *         for hit_no in range(n_hits):
 *             hit_arr[hit_no] = hits[hit_no]
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_empty); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_n_hits); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
    __Pyx_INCREF(__pyx_int_5);
    __Pyx_GIVEREF(__pyx_int_5);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_5);
    __pyx_t_2 = 0;
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __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 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_28 = ((PyArrayObject *)__pyx_t_5);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hit_arr.rcbuffer->pybuffer);
      __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_hit_arr.rcbuffer->pybuffer, (PyObject*)__pyx_t_28, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_7 < 0)) {
        PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_hit_arr.rcbuffer->pybuffer, (PyObject*)__pyx_v_hit_arr, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
        }
      }
      __pyx_pybuffernd_hit_arr.diminfo[0].strides = __pyx_pybuffernd_hit_arr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_hit_arr.diminfo[0].shape = __pyx_pybuffernd_hit_arr.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_hit_arr.diminfo[1].strides = __pyx_pybuffernd_hit_arr.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_hit_arr.diminfo[1].shape = __pyx_pybuffernd_hit_arr.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 341; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_28 = 0;
    __Pyx_XDECREF_SET(__pyx_v_hit_arr, ((PyArrayObject *)__pyx_t_5));
    __pyx_t_5 = 0;

    /* "dipy/tracking/distances.pyx":342
 *             max_hit_len = n_hits
 *         hit_arr = np.empty((n_hits,5), dtype=f32_dt)
 *         for hit_no in range(n_hits):             # <<<<<<<<<<<<<<
 *             hit_arr[hit_no] = hits[hit_no]
 *         Hit.append(hit_arr)
 */
    __pyx_t_18 = __pyx_v_n_hits;
    for (__pyx_t_19 = 0; __pyx_t_19 < __pyx_t_18; __pyx_t_19+=1) {
      __pyx_v_hit_no = __pyx_t_19;

      /* "dipy/tracking/distances.pyx":343
 *         hit_arr = np.empty((n_hits,5), dtype=f32_dt)
 *         for hit_no in range(n_hits):
 *             hit_arr[hit_no] = hits[hit_no]             # <<<<<<<<<<<<<<
 *         Hit.append(hit_arr)
 *         #Div.append(divs[1:])
 */
      __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_hits, __pyx_v_hit_no, size_t, 0, __Pyx_PyInt_FromSize_t, 0, 0, 1); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_5);
      if (unlikely(__Pyx_SetItemInt(((PyObject *)__pyx_v_hit_arr), __pyx_v_hit_no, __pyx_t_5, size_t, 0, __Pyx_PyInt_FromSize_t, 0, 0, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 343; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }

    /* "dipy/tracking/distances.pyx":344
 *         for hit_no in range(n_hits):
 *             hit_arr[hit_no] = hits[hit_no]
 *         Hit.append(hit_arr)             # <<<<<<<<<<<<<<
 *         #Div.append(divs[1:])
 *     return Hit[1:]
 */
    __pyx_t_17 = __Pyx_PyObject_Append(__pyx_v_Hit, ((PyObject *)__pyx_v_hit_arr)); if (unlikely(__pyx_t_17 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 344; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }

  /* "dipy/tracking/distances.pyx":346
 *         Hit.append(hit_arr)
 *         #Div.append(divs[1:])
 *     return Hit[1:]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = __Pyx_PyObject_GetSlice(__pyx_v_Hit, 1, 0, NULL, NULL, &__pyx_slice__8, 1, 0, 1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":190
 * 
 * 
 * def cut_plane(tracks, ref):             # <<<<<<<<<<<<<<
 *     ''' Extract divergence vectors and points of intersection
 *     between planes normal to the reference fiber and other tracks
 */

  /* 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_5);
  __Pyx_XDECREF(__pyx_t_11);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hit_arr.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_one_hit.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ref32.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track_lengths.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.cut_plane", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_hit_arr.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_one_hit.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ref32.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track_lengths.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_ref32);
  __Pyx_XDECREF((PyObject *)__pyx_v_track);
  __Pyx_XDECREF(__pyx_v_hits);
  __Pyx_XDECREF((PyObject *)__pyx_v_one_hit);
  __Pyx_XDECREF((PyObject *)__pyx_v_hit_arr);
  __Pyx_XDECREF(__pyx_v_Hit);
  __Pyx_XDECREF((PyObject *)__pyx_v_track_lengths);
  __Pyx_XDECREF(__pyx_v_tracks32);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":352
 * 
 * 
 * def most_similar_track_mam(tracks,metric='avg'):             # <<<<<<<<<<<<<<
 *     ''' Find the most similar track in a bundle
 *     using distances calculated from Zhang et. al 2008.
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_17most_similar_track_mam(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_16most_similar_track_mam[] = " Find the most similar track in a bundle\n    using distances calculated from Zhang et. al 2008.\n\n    Parameters\n    ----------\n    tracks : sequence\n       of tracks as arrays, shape (N1,3) .. (Nm,3)\n    metric : str\n       'avg', 'min', 'max'\n\n    Returns\n    -------\n    si : int\n       index of the most similar track in tracks. This can be used as a\n       reference track for a bundle.\n    s : array, shape (len(tracks),)\n        similarities between tracks[si] and the rest of the tracks in\n        the bundle\n\n    Notes\n    -----\n    A vague description of this function is given below:\n\n    for (i,j) in tracks_combinations_of_2:\n\n        calculate the mean_closest_distance from i to j  (mcd_i)\n        calculate the mean_closest_distance from j to i  (mcd_j)\n\n        if 'avg':\n            s holds the average similarities\n        if 'min':\n            s holds the minimum similarities\n        if 'max':\n            s holds the maximum similarities\n\n    si holds the index of the track with min {avg,min,max} average metric\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_17most_similar_track_mam = {"most_similar_track_mam", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_17most_similar_track_mam, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_16most_similar_track_mam};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_17most_similar_track_mam(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_tracks = 0;
  PyObject *__pyx_v_metric = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("most_similar_track_mam (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tracks,&__pyx_n_s_metric,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)__pyx_n_s_avg);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tracks)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_metric);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "most_similar_track_mam") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_tracks = values[0];
    __pyx_v_metric = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("most_similar_track_mam", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.most_similar_track_mam", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_16most_similar_track_mam(__pyx_self, __pyx_v_tracks, __pyx_v_metric);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_16most_similar_track_mam(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tracks, PyObject *__pyx_v_metric) {
  size_t __pyx_v_i;
  size_t __pyx_v_j;
  size_t __pyx_v_lent;
  int __pyx_v_metric_type;
  size_t __pyx_v_longest_track_len;
  size_t __pyx_v_track_len;
  PyArrayObject *__pyx_v_tracks32 = 0;
  PyArrayObject *__pyx_v_track2others = 0;
  __pyx_t_5numpy_double_t *__pyx_v_sum_track2others;
  PyArrayObject *__pyx_v_distances_buffer = 0;
  __pyx_t_5numpy_float32_t *__pyx_v_t1_ptr;
  __pyx_t_5numpy_float32_t *__pyx_v_t2_ptr;
  __pyx_t_5numpy_float32_t *__pyx_v_min_buffer;
  __pyx_t_5numpy_float32_t __pyx_v_distance;
  PyArrayObject *__pyx_v_t1 = 0;
  PyArrayObject *__pyx_v_t2 = 0;
  size_t __pyx_v_t1_len;
  size_t __pyx_v_t2_len;
  double __pyx_v_mn;
  size_t __pyx_v_si;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_distances_buffer;
  __Pyx_Buffer __pyx_pybuffer_distances_buffer;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_t1;
  __Pyx_Buffer __pyx_pybuffer_t1;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_t2;
  __Pyx_Buffer __pyx_pybuffer_t2;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_track2others;
  __Pyx_Buffer __pyx_pybuffer_track2others;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_tracks32;
  __Pyx_Buffer __pyx_pybuffer_tracks32;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  size_t __pyx_t_12;
  size_t __pyx_t_13;
  size_t __pyx_t_14;
  PyObject **__pyx_t_15;
  size_t __pyx_t_16;
  size_t __pyx_t_17;
  PyObject *__pyx_t_18 = NULL;
  PyArrayObject *__pyx_t_19 = NULL;
  PyArrayObject *__pyx_t_20 = NULL;
  PyArrayObject *__pyx_t_21 = NULL;
  size_t __pyx_t_22;
  size_t __pyx_t_23;
  size_t __pyx_t_24;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("most_similar_track_mam", 0);
  __pyx_pybuffer_tracks32.pybuffer.buf = NULL;
  __pyx_pybuffer_tracks32.refcount = 0;
  __pyx_pybuffernd_tracks32.data = NULL;
  __pyx_pybuffernd_tracks32.rcbuffer = &__pyx_pybuffer_tracks32;
  __pyx_pybuffer_track2others.pybuffer.buf = NULL;
  __pyx_pybuffer_track2others.refcount = 0;
  __pyx_pybuffernd_track2others.data = NULL;
  __pyx_pybuffernd_track2others.rcbuffer = &__pyx_pybuffer_track2others;
  __pyx_pybuffer_distances_buffer.pybuffer.buf = NULL;
  __pyx_pybuffer_distances_buffer.refcount = 0;
  __pyx_pybuffernd_distances_buffer.data = NULL;
  __pyx_pybuffernd_distances_buffer.rcbuffer = &__pyx_pybuffer_distances_buffer;
  __pyx_pybuffer_t1.pybuffer.buf = NULL;
  __pyx_pybuffer_t1.refcount = 0;
  __pyx_pybuffernd_t1.data = NULL;
  __pyx_pybuffernd_t1.rcbuffer = &__pyx_pybuffer_t1;
  __pyx_pybuffer_t2.pybuffer.buf = NULL;
  __pyx_pybuffer_t2.refcount = 0;
  __pyx_pybuffernd_t2.data = NULL;
  __pyx_pybuffernd_t2.rcbuffer = &__pyx_pybuffer_t2;

  /* "dipy/tracking/distances.pyx":393
 *         size_t i, j, lent
 *         int metric_type
 *     if metric=='avg':             # <<<<<<<<<<<<<<
 *         metric_type = 0
 *     elif metric == 'min':
 */
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_metric, __pyx_n_s_avg, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 393; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "dipy/tracking/distances.pyx":394
 *         int metric_type
 *     if metric=='avg':
 *         metric_type = 0             # <<<<<<<<<<<<<<
 *     elif metric == 'min':
 *         metric_type = 1
 */
    __pyx_v_metric_type = 0;

    /* "dipy/tracking/distances.pyx":393
 *         size_t i, j, lent
 *         int metric_type
 *     if metric=='avg':             # <<<<<<<<<<<<<<
 *         metric_type = 0
 *     elif metric == 'min':
 */
    goto __pyx_L3;
  }

  /* "dipy/tracking/distances.pyx":395
 *     if metric=='avg':
 *         metric_type = 0
 *     elif metric == 'min':             # <<<<<<<<<<<<<<
 *         metric_type = 1
 *     elif metric == 'max':
 */
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_metric, __pyx_n_s_min, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 395; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "dipy/tracking/distances.pyx":396
 *         metric_type = 0
 *     elif metric == 'min':
 *         metric_type = 1             # <<<<<<<<<<<<<<
 *     elif metric == 'max':
 *         metric_type = 2
 */
    __pyx_v_metric_type = 1;

    /* "dipy/tracking/distances.pyx":395
 *     if metric=='avg':
 *         metric_type = 0
 *     elif metric == 'min':             # <<<<<<<<<<<<<<
 *         metric_type = 1
 *     elif metric == 'max':
 */
    goto __pyx_L3;
  }

  /* "dipy/tracking/distances.pyx":397
 *     elif metric == 'min':
 *         metric_type = 1
 *     elif metric == 'max':             # <<<<<<<<<<<<<<
 *         metric_type = 2
 *     else:
 */
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_metric, __pyx_n_s_max, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 397; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "dipy/tracking/distances.pyx":398
 *         metric_type = 1
 *     elif metric == 'max':
 *         metric_type = 2             # <<<<<<<<<<<<<<
 *     else:
 *         raise ValueError('Metric should be one of avg, min, max')
 */
    __pyx_v_metric_type = 2;

    /* "dipy/tracking/distances.pyx":397
 *     elif metric == 'min':
 *         metric_type = 1
 *     elif metric == 'max':             # <<<<<<<<<<<<<<
 *         metric_type = 2
 *     else:
 */
    goto __pyx_L3;
  }

  /* "dipy/tracking/distances.pyx":400
 *         metric_type = 2
 *     else:
 *         raise ValueError('Metric should be one of avg, min, max')             # <<<<<<<<<<<<<<
 *     # preprocess tracks
 *     cdef:
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__9, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_L3:;

  /* "dipy/tracking/distances.pyx":403
 *     # preprocess tracks
 *     cdef:
 *         size_t longest_track_len = 0, track_len             # <<<<<<<<<<<<<<
 *         cnp.ndarray[object, ndim=1] tracks32
 *     lent = len(tracks)
 */
  __pyx_v_longest_track_len = 0;

  /* "dipy/tracking/distances.pyx":405
 *         size_t longest_track_len = 0, track_len
 *         cnp.ndarray[object, ndim=1] tracks32
 *     lent = len(tracks)             # <<<<<<<<<<<<<<
 *     tracks32 = np.zeros((lent,), dtype=object)
 *     # process tracks to predictable memory layout, find longest track
 */
  __pyx_t_3 = PyObject_Length(__pyx_v_tracks); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 405; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_lent = __pyx_t_3;

  /* "dipy/tracking/distances.pyx":406
 *         cnp.ndarray[object, ndim=1] tracks32
 *     lent = len(tracks)
 *     tracks32 = np.zeros((lent,), dtype=object)             # <<<<<<<<<<<<<<
 *     # process tracks to predictable memory layout, find longest track
 *     for i in range(lent):
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_lent); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __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 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_builtin_object) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __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_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tracks32.rcbuffer->pybuffer);
    __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_tracks32.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_object, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_8 < 0)) {
      PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_tracks32.rcbuffer->pybuffer, (PyObject*)__pyx_v_tracks32, &__Pyx_TypeInfo_object, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
      }
    }
    __pyx_pybuffernd_tracks32.diminfo[0].strides = __pyx_pybuffernd_tracks32.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_tracks32.diminfo[0].shape = __pyx_pybuffernd_tracks32.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_7 = 0;
  __pyx_v_tracks32 = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "dipy/tracking/distances.pyx":408
 *     tracks32 = np.zeros((lent,), dtype=object)
 *     # process tracks to predictable memory layout, find longest track
 *     for i in range(lent):             # <<<<<<<<<<<<<<
 *         tracks32[i] = np.ascontiguousarray(tracks[i], dtype=f32_dt)
 *         track_len = tracks32[i].shape[0]
 */
  __pyx_t_12 = __pyx_v_lent;
  for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) {
    __pyx_v_i = __pyx_t_13;

    /* "dipy/tracking/distances.pyx":409
 *     # process tracks to predictable memory layout, find longest track
 *     for i in range(lent):
 *         tracks32[i] = np.ascontiguousarray(tracks[i], dtype=f32_dt)             # <<<<<<<<<<<<<<
 *         track_len = tracks32[i].shape[0]
 *         if track_len > longest_track_len:
 */
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_tracks, __pyx_v_i, size_t, 0, __Pyx_PyInt_FromSize_t, 0, 0, 1); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6);
    __pyx_t_6 = 0;
    __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_14 = __pyx_v_i;
    __pyx_t_8 = -1;
    if (unlikely(__pyx_t_14 >= (size_t)__pyx_pybuffernd_tracks32.diminfo[0].shape)) __pyx_t_8 = 0;
    if (unlikely(__pyx_t_8 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_8);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 409; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_15 = __Pyx_BufPtrStrided1d(PyObject **, __pyx_pybuffernd_tracks32.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_tracks32.diminfo[0].strides);
    __Pyx_GOTREF(*__pyx_t_15);
    __Pyx_INCREF(__pyx_t_4); __Pyx_DECREF(*__pyx_t_15);
    *__pyx_t_15 = __pyx_t_4;
    __Pyx_GIVEREF(*__pyx_t_15);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "dipy/tracking/distances.pyx":410
 *     for i in range(lent):
 *         tracks32[i] = np.ascontiguousarray(tracks[i], dtype=f32_dt)
 *         track_len = tracks32[i].shape[0]             # <<<<<<<<<<<<<<
 *         if track_len > longest_track_len:
 *             longest_track_len = track_len
 */
    __pyx_t_16 = __pyx_v_i;
    __pyx_t_8 = -1;
    if (unlikely(__pyx_t_16 >= (size_t)__pyx_pybuffernd_tracks32.diminfo[0].shape)) __pyx_t_8 = 0;
    if (unlikely(__pyx_t_8 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_8);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_4 = (PyObject *) *__Pyx_BufPtrStrided1d(PyObject **, __pyx_pybuffernd_tracks32.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_tracks32.diminfo[0].strides);
    __Pyx_INCREF((PyObject*)__pyx_t_4);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_shape); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_6, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_17 = __Pyx_PyInt_As_size_t(__pyx_t_4); if (unlikely((__pyx_t_17 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 410; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_track_len = __pyx_t_17;

    /* "dipy/tracking/distances.pyx":411
 *         tracks32[i] = np.ascontiguousarray(tracks[i], dtype=f32_dt)
 *         track_len = tracks32[i].shape[0]
 *         if track_len > longest_track_len:             # <<<<<<<<<<<<<<
 *             longest_track_len = track_len
 *     # buffer for distances of found track to other tracks
 */
    __pyx_t_1 = ((__pyx_v_track_len > __pyx_v_longest_track_len) != 0);
    if (__pyx_t_1) {

      /* "dipy/tracking/distances.pyx":412
 *         track_len = tracks32[i].shape[0]
 *         if track_len > longest_track_len:
 *             longest_track_len = track_len             # <<<<<<<<<<<<<<
 *     # buffer for distances of found track to other tracks
 *     cdef:
 */
      __pyx_v_longest_track_len = __pyx_v_track_len;

      /* "dipy/tracking/distances.pyx":411
 *         tracks32[i] = np.ascontiguousarray(tracks[i], dtype=f32_dt)
 *         track_len = tracks32[i].shape[0]
 *         if track_len > longest_track_len:             # <<<<<<<<<<<<<<
 *             longest_track_len = track_len
 *     # buffer for distances of found track to other tracks
 */
    }
  }

  /* "dipy/tracking/distances.pyx":416
 *     cdef:
 *         cnp.ndarray[cnp.double_t, ndim=1] track2others
 *     track2others = np.zeros((lent,), dtype=np.double)             # <<<<<<<<<<<<<<
 *     # use this buffer also for working space containing summed distances
 *     # of candidate track to all other tracks
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_zeros); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyInt_FromSize_t(__pyx_v_lent); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __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 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_double); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_18) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
  __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_18) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_18, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_19 = ((PyArrayObject *)__pyx_t_18);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track2others.rcbuffer->pybuffer);
    __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track2others.rcbuffer->pybuffer, (PyObject*)__pyx_t_19, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_8 < 0)) {
      PyErr_Fetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track2others.rcbuffer->pybuffer, (PyObject*)__pyx_v_track2others, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_11, __pyx_t_10, __pyx_t_9);
      }
    }
    __pyx_pybuffernd_track2others.diminfo[0].strides = __pyx_pybuffernd_track2others.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_track2others.diminfo[0].shape = __pyx_pybuffernd_track2others.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 416; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_19 = 0;
  __pyx_v_track2others = ((PyArrayObject *)__pyx_t_18);
  __pyx_t_18 = 0;

  /* "dipy/tracking/distances.pyx":419
 *     # use this buffer also for working space containing summed distances
 *     # of candidate track to all other tracks
 *     cdef cnp.double_t *sum_track2others = <cnp.double_t *>track2others.data             # <<<<<<<<<<<<<<
 *     # preallocate buffer array for track distance calculations
 *     cdef:
 */
  __pyx_v_sum_track2others = ((__pyx_t_5numpy_double_t *)__pyx_v_track2others->data);

  /* "dipy/tracking/distances.pyx":424
 *         cnp.ndarray [cnp.float32_t, ndim=1] distances_buffer
 *         cnp.float32_t *t1_ptr, *t2_ptr, *min_buffer, distance
 *     distances_buffer = np.zeros((longest_track_len*2,), dtype=np.float32)             # <<<<<<<<<<<<<<
 *     min_buffer = <cnp.float32_t *> distances_buffer.data
 *     # cycle over tracks
 */
  __pyx_t_18 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_18);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_18, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
  __pyx_t_18 = __Pyx_PyInt_FromSize_t((__pyx_v_longest_track_len * 2)); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_18);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_18);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_18);
  __pyx_t_18 = 0;
  __pyx_t_18 = PyTuple_New(1); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_18);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_float32); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_18, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 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_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_20 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer);
    __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer, (PyObject*)__pyx_t_20, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_8 < 0)) {
      PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer, (PyObject*)__pyx_v_distances_buffer, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
      }
    }
    __pyx_pybuffernd_distances_buffer.diminfo[0].strides = __pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_distances_buffer.diminfo[0].shape = __pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 424; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_20 = 0;
  __pyx_v_distances_buffer = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "dipy/tracking/distances.pyx":425
 *         cnp.float32_t *t1_ptr, *t2_ptr, *min_buffer, distance
 *     distances_buffer = np.zeros((longest_track_len*2,), dtype=np.float32)
 *     min_buffer = <cnp.float32_t *> distances_buffer.data             # <<<<<<<<<<<<<<
 *     # cycle over tracks
 *     cdef:
 */
  __pyx_v_min_buffer = ((__pyx_t_5numpy_float32_t *)__pyx_v_distances_buffer->data);

  /* "dipy/tracking/distances.pyx":430
 *         cnp.ndarray [cnp.float32_t, ndim=2] t1, t2
 *         size_t t1_len, t2_len
 *     for i from 0 <= i < lent-1:             # <<<<<<<<<<<<<<
 *         t1 = tracks32[i]
 *         t1_len = t1.shape[0]
 */
  __pyx_t_12 = (__pyx_v_lent - 1);
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_12; __pyx_v_i++) {

    /* "dipy/tracking/distances.pyx":431
 *         size_t t1_len, t2_len
 *     for i from 0 <= i < lent-1:
 *         t1 = tracks32[i]             # <<<<<<<<<<<<<<
 *         t1_len = t1.shape[0]
 *         t1_ptr = <cnp.float32_t *>t1.data
 */
    __pyx_t_13 = __pyx_v_i;
    __pyx_t_8 = -1;
    if (unlikely(__pyx_t_13 >= (size_t)__pyx_pybuffernd_tracks32.diminfo[0].shape)) __pyx_t_8 = 0;
    if (unlikely(__pyx_t_8 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_8);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_5 = (PyObject *) *__Pyx_BufPtrStrided1d(PyObject **, __pyx_pybuffernd_tracks32.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_tracks32.diminfo[0].strides);
    __Pyx_INCREF((PyObject*)__pyx_t_5);
    if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_21 = ((PyArrayObject *)__pyx_t_5);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t1.rcbuffer->pybuffer);
      __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t1.rcbuffer->pybuffer, (PyObject*)__pyx_t_21, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_8 < 0)) {
        PyErr_Fetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t1.rcbuffer->pybuffer, (PyObject*)__pyx_v_t1, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_11, __pyx_t_10, __pyx_t_9);
        }
      }
      __pyx_pybuffernd_t1.diminfo[0].strides = __pyx_pybuffernd_t1.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_t1.diminfo[0].shape = __pyx_pybuffernd_t1.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_t1.diminfo[1].strides = __pyx_pybuffernd_t1.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_t1.diminfo[1].shape = __pyx_pybuffernd_t1.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 431; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_21 = 0;
    __Pyx_XDECREF_SET(__pyx_v_t1, ((PyArrayObject *)__pyx_t_5));
    __pyx_t_5 = 0;

    /* "dipy/tracking/distances.pyx":432
 *     for i from 0 <= i < lent-1:
 *         t1 = tracks32[i]
 *         t1_len = t1.shape[0]             # <<<<<<<<<<<<<<
 *         t1_ptr = <cnp.float32_t *>t1.data
 *         for j from i+1 <= j < lent:
 */
    __pyx_v_t1_len = (__pyx_v_t1->dimensions[0]);

    /* "dipy/tracking/distances.pyx":433
 *         t1 = tracks32[i]
 *         t1_len = t1.shape[0]
 *         t1_ptr = <cnp.float32_t *>t1.data             # <<<<<<<<<<<<<<
 *         for j from i+1 <= j < lent:
 *             t2 = tracks32[j]
 */
    __pyx_v_t1_ptr = ((__pyx_t_5numpy_float32_t *)__pyx_v_t1->data);

    /* "dipy/tracking/distances.pyx":434
 *         t1_len = t1.shape[0]
 *         t1_ptr = <cnp.float32_t *>t1.data
 *         for j from i+1 <= j < lent:             # <<<<<<<<<<<<<<
 *             t2 = tracks32[j]
 *             t2_len = t2.shape[0]
 */
    __pyx_t_17 = __pyx_v_lent;
    for (__pyx_v_j = (__pyx_v_i + 1); __pyx_v_j < __pyx_t_17; __pyx_v_j++) {

      /* "dipy/tracking/distances.pyx":435
 *         t1_ptr = <cnp.float32_t *>t1.data
 *         for j from i+1 <= j < lent:
 *             t2 = tracks32[j]             # <<<<<<<<<<<<<<
 *             t2_len = t2.shape[0]
 *             t2_ptr = <cnp.float32_t *>t2.data
 */
      __pyx_t_22 = __pyx_v_j;
      __pyx_t_8 = -1;
      if (unlikely(__pyx_t_22 >= (size_t)__pyx_pybuffernd_tracks32.diminfo[0].shape)) __pyx_t_8 = 0;
      if (unlikely(__pyx_t_8 != -1)) {
        __Pyx_RaiseBufferIndexError(__pyx_t_8);
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_5 = (PyObject *) *__Pyx_BufPtrStrided1d(PyObject **, __pyx_pybuffernd_tracks32.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_tracks32.diminfo[0].strides);
      __Pyx_INCREF((PyObject*)__pyx_t_5);
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_21 = ((PyArrayObject *)__pyx_t_5);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t2.rcbuffer->pybuffer);
        __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t2.rcbuffer->pybuffer, (PyObject*)__pyx_t_21, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_8 < 0)) {
          PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t2.rcbuffer->pybuffer, (PyObject*)__pyx_v_t2, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
          }
        }
        __pyx_pybuffernd_t2.diminfo[0].strides = __pyx_pybuffernd_t2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_t2.diminfo[0].shape = __pyx_pybuffernd_t2.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_t2.diminfo[1].strides = __pyx_pybuffernd_t2.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_t2.diminfo[1].shape = __pyx_pybuffernd_t2.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 435; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_21 = 0;
      __Pyx_XDECREF_SET(__pyx_v_t2, ((PyArrayObject *)__pyx_t_5));
      __pyx_t_5 = 0;

      /* "dipy/tracking/distances.pyx":436
 *         for j from i+1 <= j < lent:
 *             t2 = tracks32[j]
 *             t2_len = t2.shape[0]             # <<<<<<<<<<<<<<
 *             t2_ptr = <cnp.float32_t *>t2.data
 *             distance = czhang(t1_len, t1_ptr, t2_len, t2_ptr, min_buffer, metric_type)
 */
      __pyx_v_t2_len = (__pyx_v_t2->dimensions[0]);

      /* "dipy/tracking/distances.pyx":437
 *             t2 = tracks32[j]
 *             t2_len = t2.shape[0]
 *             t2_ptr = <cnp.float32_t *>t2.data             # <<<<<<<<<<<<<<
 *             distance = czhang(t1_len, t1_ptr, t2_len, t2_ptr, min_buffer, metric_type)
 *             # get metric
 */
      __pyx_v_t2_ptr = ((__pyx_t_5numpy_float32_t *)__pyx_v_t2->data);

      /* "dipy/tracking/distances.pyx":438
 *             t2_len = t2.shape[0]
 *             t2_ptr = <cnp.float32_t *>t2.data
 *             distance = czhang(t1_len, t1_ptr, t2_len, t2_ptr, min_buffer, metric_type)             # <<<<<<<<<<<<<<
 *             # get metric
 *             sum_track2others[i]+=distance
 */
      __pyx_v_distance = __pyx_f_4dipy_8tracking_9distances_czhang(__pyx_v_t1_len, __pyx_v_t1_ptr, __pyx_v_t2_len, __pyx_v_t2_ptr, __pyx_v_min_buffer, __pyx_v_metric_type);

      /* "dipy/tracking/distances.pyx":440
 *             distance = czhang(t1_len, t1_ptr, t2_len, t2_ptr, min_buffer, metric_type)
 *             # get metric
 *             sum_track2others[i]+=distance             # <<<<<<<<<<<<<<
 *             sum_track2others[j]+=distance
 *     # find track with smallest summed metric with other tracks
 */
      __pyx_t_23 = __pyx_v_i;
      (__pyx_v_sum_track2others[__pyx_t_23]) = ((__pyx_v_sum_track2others[__pyx_t_23]) + __pyx_v_distance);

      /* "dipy/tracking/distances.pyx":441
 *             # get metric
 *             sum_track2others[i]+=distance
 *             sum_track2others[j]+=distance             # <<<<<<<<<<<<<<
 *     # find track with smallest summed metric with other tracks
 *     cdef double mn = sum_track2others[0]
 */
      __pyx_t_23 = __pyx_v_j;
      (__pyx_v_sum_track2others[__pyx_t_23]) = ((__pyx_v_sum_track2others[__pyx_t_23]) + __pyx_v_distance);
    }
  }

  /* "dipy/tracking/distances.pyx":443
 *             sum_track2others[j]+=distance
 *     # find track with smallest summed metric with other tracks
 *     cdef double mn = sum_track2others[0]             # <<<<<<<<<<<<<<
 *     cdef size_t si = 0
 *     for i in range(lent):
 */
  __pyx_v_mn = (__pyx_v_sum_track2others[0]);

  /* "dipy/tracking/distances.pyx":444
 *     # find track with smallest summed metric with other tracks
 *     cdef double mn = sum_track2others[0]
 *     cdef size_t si = 0             # <<<<<<<<<<<<<<
 *     for i in range(lent):
 *         if sum_track2others[i] < mn:
 */
  __pyx_v_si = 0;

  /* "dipy/tracking/distances.pyx":445
 *     cdef double mn = sum_track2others[0]
 *     cdef size_t si = 0
 *     for i in range(lent):             # <<<<<<<<<<<<<<
 *         if sum_track2others[i] < mn:
 *             si = i
 */
  __pyx_t_12 = __pyx_v_lent;
  for (__pyx_t_17 = 0; __pyx_t_17 < __pyx_t_12; __pyx_t_17+=1) {
    __pyx_v_i = __pyx_t_17;

    /* "dipy/tracking/distances.pyx":446
 *     cdef size_t si = 0
 *     for i in range(lent):
 *         if sum_track2others[i] < mn:             # <<<<<<<<<<<<<<
 *             si = i
 *             mn = sum_track2others[i]
 */
    __pyx_t_1 = (((__pyx_v_sum_track2others[__pyx_v_i]) < __pyx_v_mn) != 0);
    if (__pyx_t_1) {

      /* "dipy/tracking/distances.pyx":447
 *     for i in range(lent):
 *         if sum_track2others[i] < mn:
 *             si = i             # <<<<<<<<<<<<<<
 *             mn = sum_track2others[i]
 *     # recalculate distance of this track from the others
 */
      __pyx_v_si = __pyx_v_i;

      /* "dipy/tracking/distances.pyx":448
 *         if sum_track2others[i] < mn:
 *             si = i
 *             mn = sum_track2others[i]             # <<<<<<<<<<<<<<
 *     # recalculate distance of this track from the others
 *     t1 = tracks32[si]
 */
      __pyx_v_mn = (__pyx_v_sum_track2others[__pyx_v_i]);

      /* "dipy/tracking/distances.pyx":446
 *     cdef size_t si = 0
 *     for i in range(lent):
 *         if sum_track2others[i] < mn:             # <<<<<<<<<<<<<<
 *             si = i
 *             mn = sum_track2others[i]
 */
    }
  }

  /* "dipy/tracking/distances.pyx":450
 *             mn = sum_track2others[i]
 *     # recalculate distance of this track from the others
 *     t1 = tracks32[si]             # <<<<<<<<<<<<<<
 *     t1_len = t1.shape[0]
 *     t1_ptr = <cnp.float32_t *>t1.data
 */
  __pyx_t_12 = __pyx_v_si;
  __pyx_t_8 = -1;
  if (unlikely(__pyx_t_12 >= (size_t)__pyx_pybuffernd_tracks32.diminfo[0].shape)) __pyx_t_8 = 0;
  if (unlikely(__pyx_t_8 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_8);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_5 = (PyObject *) *__Pyx_BufPtrStrided1d(PyObject **, __pyx_pybuffernd_tracks32.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_tracks32.diminfo[0].strides);
  __Pyx_INCREF((PyObject*)__pyx_t_5);
  if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_21 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t1.rcbuffer->pybuffer);
    __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t1.rcbuffer->pybuffer, (PyObject*)__pyx_t_21, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_8 < 0)) {
      PyErr_Fetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t1.rcbuffer->pybuffer, (PyObject*)__pyx_v_t1, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_11, __pyx_t_10, __pyx_t_9);
      }
    }
    __pyx_pybuffernd_t1.diminfo[0].strides = __pyx_pybuffernd_t1.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_t1.diminfo[0].shape = __pyx_pybuffernd_t1.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_t1.diminfo[1].strides = __pyx_pybuffernd_t1.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_t1.diminfo[1].shape = __pyx_pybuffernd_t1.rcbuffer->pybuffer.shape[1];
    if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 450; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_21 = 0;
  __Pyx_XDECREF_SET(__pyx_v_t1, ((PyArrayObject *)__pyx_t_5));
  __pyx_t_5 = 0;

  /* "dipy/tracking/distances.pyx":451
 *     # recalculate distance of this track from the others
 *     t1 = tracks32[si]
 *     t1_len = t1.shape[0]             # <<<<<<<<<<<<<<
 *     t1_ptr = <cnp.float32_t *>t1.data
 *     for j from 0 <= j < lent:
 */
  __pyx_v_t1_len = (__pyx_v_t1->dimensions[0]);

  /* "dipy/tracking/distances.pyx":452
 *     t1 = tracks32[si]
 *     t1_len = t1.shape[0]
 *     t1_ptr = <cnp.float32_t *>t1.data             # <<<<<<<<<<<<<<
 *     for j from 0 <= j < lent:
 *         t2 = tracks32[j]
 */
  __pyx_v_t1_ptr = ((__pyx_t_5numpy_float32_t *)__pyx_v_t1->data);

  /* "dipy/tracking/distances.pyx":453
 *     t1_len = t1.shape[0]
 *     t1_ptr = <cnp.float32_t *>t1.data
 *     for j from 0 <= j < lent:             # <<<<<<<<<<<<<<
 *         t2 = tracks32[j]
 *         t2_len = t2.shape[0]
 */
  __pyx_t_17 = __pyx_v_lent;
  for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_17; __pyx_v_j++) {

    /* "dipy/tracking/distances.pyx":454
 *     t1_ptr = <cnp.float32_t *>t1.data
 *     for j from 0 <= j < lent:
 *         t2 = tracks32[j]             # <<<<<<<<<<<<<<
 *         t2_len = t2.shape[0]
 *         t2_ptr = <cnp.float32_t *>t2.data
 */
    __pyx_t_23 = __pyx_v_j;
    __pyx_t_8 = -1;
    if (unlikely(__pyx_t_23 >= (size_t)__pyx_pybuffernd_tracks32.diminfo[0].shape)) __pyx_t_8 = 0;
    if (unlikely(__pyx_t_8 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_8);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_5 = (PyObject *) *__Pyx_BufPtrStrided1d(PyObject **, __pyx_pybuffernd_tracks32.rcbuffer->pybuffer.buf, __pyx_t_23, __pyx_pybuffernd_tracks32.diminfo[0].strides);
    __Pyx_INCREF((PyObject*)__pyx_t_5);
    if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_21 = ((PyArrayObject *)__pyx_t_5);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t2.rcbuffer->pybuffer);
      __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t2.rcbuffer->pybuffer, (PyObject*)__pyx_t_21, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_8 < 0)) {
        PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t2.rcbuffer->pybuffer, (PyObject*)__pyx_v_t2, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
        }
      }
      __pyx_pybuffernd_t2.diminfo[0].strides = __pyx_pybuffernd_t2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_t2.diminfo[0].shape = __pyx_pybuffernd_t2.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_t2.diminfo[1].strides = __pyx_pybuffernd_t2.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_t2.diminfo[1].shape = __pyx_pybuffernd_t2.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 454; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_21 = 0;
    __Pyx_XDECREF_SET(__pyx_v_t2, ((PyArrayObject *)__pyx_t_5));
    __pyx_t_5 = 0;

    /* "dipy/tracking/distances.pyx":455
 *     for j from 0 <= j < lent:
 *         t2 = tracks32[j]
 *         t2_len = t2.shape[0]             # <<<<<<<<<<<<<<
 *         t2_ptr = <cnp.float32_t *>t2.data
 *         track2others[j] = czhang(t1_len, t1_ptr, t2_len, t2_ptr, min_buffer, metric_type)
 */
    __pyx_v_t2_len = (__pyx_v_t2->dimensions[0]);

    /* "dipy/tracking/distances.pyx":456
 *         t2 = tracks32[j]
 *         t2_len = t2.shape[0]
 *         t2_ptr = <cnp.float32_t *>t2.data             # <<<<<<<<<<<<<<
 *         track2others[j] = czhang(t1_len, t1_ptr, t2_len, t2_ptr, min_buffer, metric_type)
 *     return si, track2others
 */
    __pyx_v_t2_ptr = ((__pyx_t_5numpy_float32_t *)__pyx_v_t2->data);

    /* "dipy/tracking/distances.pyx":457
 *         t2_len = t2.shape[0]
 *         t2_ptr = <cnp.float32_t *>t2.data
 *         track2others[j] = czhang(t1_len, t1_ptr, t2_len, t2_ptr, min_buffer, metric_type)             # <<<<<<<<<<<<<<
 *     return si, track2others
 * 
 */
    __pyx_t_24 = __pyx_v_j;
    __pyx_t_8 = -1;
    if (unlikely(__pyx_t_24 >= (size_t)__pyx_pybuffernd_track2others.diminfo[0].shape)) __pyx_t_8 = 0;
    if (unlikely(__pyx_t_8 != -1)) {
      __Pyx_RaiseBufferIndexError(__pyx_t_8);
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 457; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_track2others.rcbuffer->pybuffer.buf, __pyx_t_24, __pyx_pybuffernd_track2others.diminfo[0].strides) = __pyx_f_4dipy_8tracking_9distances_czhang(__pyx_v_t1_len, __pyx_v_t1_ptr, __pyx_v_t2_len, __pyx_v_t2_ptr, __pyx_v_min_buffer, __pyx_v_metric_type);
  }

  /* "dipy/tracking/distances.pyx":458
 *         t2_ptr = <cnp.float32_t *>t2.data
 *         track2others[j] = czhang(t1_len, t1_ptr, t2_len, t2_ptr, min_buffer, metric_type)
 *     return si, track2others             # <<<<<<<<<<<<<<
 * 
 * @cython.boundscheck(False)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = __Pyx_PyInt_FromSize_t(__pyx_v_si); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 458; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __Pyx_INCREF(((PyObject *)__pyx_v_track2others));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_track2others));
  PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_track2others));
  __pyx_t_5 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":352
 * 
 * 
 * def most_similar_track_mam(tracks,metric='avg'):             # <<<<<<<<<<<<<<
 *     ''' Find the most similar track in a bundle
 *     using distances calculated from Zhang et. al 2008.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_18);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t1.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t2.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track2others.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tracks32.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.most_similar_track_mam", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t1.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t2.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track2others.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tracks32.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_tracks32);
  __Pyx_XDECREF((PyObject *)__pyx_v_track2others);
  __Pyx_XDECREF((PyObject *)__pyx_v_distances_buffer);
  __Pyx_XDECREF((PyObject *)__pyx_v_t1);
  __Pyx_XDECREF((PyObject *)__pyx_v_t2);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":462
 * @cython.boundscheck(False)
 * @cython.wraparound(False)
 * def bundles_distances_mam(tracksA, tracksB, metric='avg'):             # <<<<<<<<<<<<<<
 *     ''' Calculate distances between list of tracks A and list of tracks B
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_19bundles_distances_mam(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_18bundles_distances_mam[] = " Calculate distances between list of tracks A and list of tracks B\n\n    Parameters\n    ----------\n    tracksA : sequence\n       of tracks as arrays, shape (N1,3) .. (Nm,3)\n    tracksB : sequence\n       of tracks as arrays, shape (N1,3) .. (Nm,3)\n    metric : str\n       'avg', 'min', 'max'\n\n    Returns\n    -------\n    DM : array, shape (len(tracksA), len(tracksB))\n        distances between tracksA and tracksB according to metric\n\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_19bundles_distances_mam = {"bundles_distances_mam", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_19bundles_distances_mam, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_18bundles_distances_mam};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_19bundles_distances_mam(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_tracksA = 0;
  PyObject *__pyx_v_tracksB = 0;
  PyObject *__pyx_v_metric = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("bundles_distances_mam (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tracksA,&__pyx_n_s_tracksB,&__pyx_n_s_metric,0};
    PyObject* values[3] = {0,0,0};
    values[2] = ((PyObject *)__pyx_n_s_avg);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tracksA)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tracksB)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("bundles_distances_mam", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_metric);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "bundles_distances_mam") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  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_tracksA = values[0];
    __pyx_v_tracksB = values[1];
    __pyx_v_metric = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("bundles_distances_mam", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.bundles_distances_mam", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_18bundles_distances_mam(__pyx_self, __pyx_v_tracksA, __pyx_v_tracksB, __pyx_v_metric);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_18bundles_distances_mam(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tracksA, PyObject *__pyx_v_tracksB, PyObject *__pyx_v_metric) {
  size_t __pyx_v_i;
  size_t __pyx_v_j;
  size_t __pyx_v_lentA;
  size_t __pyx_v_lentB;
  int __pyx_v_metric_type;
  CYTHON_UNUSED size_t __pyx_v_longest_track_len;
  size_t __pyx_v_track_len;
  size_t __pyx_v_longest_track_lenA;
  size_t __pyx_v_longest_track_lenB;
  PyArrayObject *__pyx_v_tracksA32 = 0;
  PyArrayObject *__pyx_v_tracksB32 = 0;
  PyArrayObject *__pyx_v_DM = 0;
  PyArrayObject *__pyx_v_distances_buffer = 0;
  __pyx_t_5numpy_float32_t *__pyx_v_t1_ptr;
  __pyx_t_5numpy_float32_t *__pyx_v_t2_ptr;
  __pyx_t_5numpy_float32_t *__pyx_v_min_buffer;
  PyArrayObject *__pyx_v_t1 = 0;
  PyArrayObject *__pyx_v_t2 = 0;
  size_t __pyx_v_t1_len;
  size_t __pyx_v_t2_len;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_DM;
  __Pyx_Buffer __pyx_pybuffer_DM;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_distances_buffer;
  __Pyx_Buffer __pyx_pybuffer_distances_buffer;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_t1;
  __Pyx_Buffer __pyx_pybuffer_t1;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_t2;
  __Pyx_Buffer __pyx_pybuffer_t2;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_tracksA32;
  __Pyx_Buffer __pyx_pybuffer_tracksA32;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_tracksB32;
  __Pyx_Buffer __pyx_pybuffer_tracksB32;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyArrayObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyArrayObject *__pyx_t_14 = NULL;
  size_t __pyx_t_15;
  size_t __pyx_t_16;
  size_t __pyx_t_17;
  PyObject **__pyx_t_18;
  size_t __pyx_t_19;
  size_t __pyx_t_20;
  size_t __pyx_t_21;
  size_t __pyx_t_22;
  PyArrayObject *__pyx_t_23 = NULL;
  PyArrayObject *__pyx_t_24 = NULL;
  size_t __pyx_t_25;
  size_t __pyx_t_26;
  size_t __pyx_t_27;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("bundles_distances_mam", 0);
  __pyx_pybuffer_tracksA32.pybuffer.buf = NULL;
  __pyx_pybuffer_tracksA32.refcount = 0;
  __pyx_pybuffernd_tracksA32.data = NULL;
  __pyx_pybuffernd_tracksA32.rcbuffer = &__pyx_pybuffer_tracksA32;
  __pyx_pybuffer_tracksB32.pybuffer.buf = NULL;
  __pyx_pybuffer_tracksB32.refcount = 0;
  __pyx_pybuffernd_tracksB32.data = NULL;
  __pyx_pybuffernd_tracksB32.rcbuffer = &__pyx_pybuffer_tracksB32;
  __pyx_pybuffer_DM.pybuffer.buf = NULL;
  __pyx_pybuffer_DM.refcount = 0;
  __pyx_pybuffernd_DM.data = NULL;
  __pyx_pybuffernd_DM.rcbuffer = &__pyx_pybuffer_DM;
  __pyx_pybuffer_distances_buffer.pybuffer.buf = NULL;
  __pyx_pybuffer_distances_buffer.refcount = 0;
  __pyx_pybuffernd_distances_buffer.data = NULL;
  __pyx_pybuffernd_distances_buffer.rcbuffer = &__pyx_pybuffer_distances_buffer;
  __pyx_pybuffer_t1.pybuffer.buf = NULL;
  __pyx_pybuffer_t1.refcount = 0;
  __pyx_pybuffernd_t1.data = NULL;
  __pyx_pybuffernd_t1.rcbuffer = &__pyx_pybuffer_t1;
  __pyx_pybuffer_t2.pybuffer.buf = NULL;
  __pyx_pybuffer_t2.refcount = 0;
  __pyx_pybuffernd_t2.data = NULL;
  __pyx_pybuffernd_t2.rcbuffer = &__pyx_pybuffer_t2;

  /* "dipy/tracking/distances.pyx":483
 *         size_t i, j, lentA, lentB
 *         int metric_type
 *     if metric=='avg':             # <<<<<<<<<<<<<<
 *         metric_type = 0
 *     elif metric == 'min':
 */
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_metric, __pyx_n_s_avg, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 483; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "dipy/tracking/distances.pyx":484
 *         int metric_type
 *     if metric=='avg':
 *         metric_type = 0             # <<<<<<<<<<<<<<
 *     elif metric == 'min':
 *         metric_type = 1
 */
    __pyx_v_metric_type = 0;

    /* "dipy/tracking/distances.pyx":483
 *         size_t i, j, lentA, lentB
 *         int metric_type
 *     if metric=='avg':             # <<<<<<<<<<<<<<
 *         metric_type = 0
 *     elif metric == 'min':
 */
    goto __pyx_L3;
  }

  /* "dipy/tracking/distances.pyx":485
 *     if metric=='avg':
 *         metric_type = 0
 *     elif metric == 'min':             # <<<<<<<<<<<<<<
 *         metric_type = 1
 *     elif metric == 'max':
 */
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_metric, __pyx_n_s_min, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "dipy/tracking/distances.pyx":486
 *         metric_type = 0
 *     elif metric == 'min':
 *         metric_type = 1             # <<<<<<<<<<<<<<
 *     elif metric == 'max':
 *         metric_type = 2
 */
    __pyx_v_metric_type = 1;

    /* "dipy/tracking/distances.pyx":485
 *     if metric=='avg':
 *         metric_type = 0
 *     elif metric == 'min':             # <<<<<<<<<<<<<<
 *         metric_type = 1
 *     elif metric == 'max':
 */
    goto __pyx_L3;
  }

  /* "dipy/tracking/distances.pyx":487
 *     elif metric == 'min':
 *         metric_type = 1
 *     elif metric == 'max':             # <<<<<<<<<<<<<<
 *         metric_type = 2
 *     else:
 */
  __pyx_t_1 = (__Pyx_PyString_Equals(__pyx_v_metric, __pyx_n_s_max, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 487; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_1) {

    /* "dipy/tracking/distances.pyx":488
 *         metric_type = 1
 *     elif metric == 'max':
 *         metric_type = 2             # <<<<<<<<<<<<<<
 *     else:
 *         raise ValueError('Metric should be one of avg, min, max')
 */
    __pyx_v_metric_type = 2;

    /* "dipy/tracking/distances.pyx":487
 *     elif metric == 'min':
 *         metric_type = 1
 *     elif metric == 'max':             # <<<<<<<<<<<<<<
 *         metric_type = 2
 *     else:
 */
    goto __pyx_L3;
  }

  /* "dipy/tracking/distances.pyx":490
 *         metric_type = 2
 *     else:
 *         raise ValueError('Metric should be one of avg, min, max')             # <<<<<<<<<<<<<<
 *     # preprocess tracks
 *     cdef:
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_L3:;

  /* "dipy/tracking/distances.pyx":493
 *     # preprocess tracks
 *     cdef:
 *         size_t longest_track_len = 0, track_len             # <<<<<<<<<<<<<<
 *         size_t longest_track_lenA = 0, longest_track_lenB = 0
 *         cnp.ndarray[object, ndim=1] tracksA32
 */
  __pyx_v_longest_track_len = 0;

  /* "dipy/tracking/distances.pyx":494
 *     cdef:
 *         size_t longest_track_len = 0, track_len
 *         size_t longest_track_lenA = 0, longest_track_lenB = 0             # <<<<<<<<<<<<<<
 *         cnp.ndarray[object, ndim=1] tracksA32
 *         cnp.ndarray[object, ndim=1] tracksB32
 */
  __pyx_v_longest_track_lenA = 0;
  __pyx_v_longest_track_lenB = 0;

  /* "dipy/tracking/distances.pyx":498
 *         cnp.ndarray[object, ndim=1] tracksB32
 *         cnp.ndarray[cnp.double_t, ndim=2] DM
 *     lentA = len(tracksA)             # <<<<<<<<<<<<<<
 *     lentB = len(tracksB)
 *     tracksA32 = np.zeros((lentA,), dtype=object)
 */
  __pyx_t_3 = PyObject_Length(__pyx_v_tracksA); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 498; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_lentA = __pyx_t_3;

  /* "dipy/tracking/distances.pyx":499
 *         cnp.ndarray[cnp.double_t, ndim=2] DM
 *     lentA = len(tracksA)
 *     lentB = len(tracksB)             # <<<<<<<<<<<<<<
 *     tracksA32 = np.zeros((lentA,), dtype=object)
 *     tracksB32 = np.zeros((lentB,), dtype=object)
 */
  __pyx_t_3 = PyObject_Length(__pyx_v_tracksB); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 499; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_lentB = __pyx_t_3;

  /* "dipy/tracking/distances.pyx":500
 *     lentA = len(tracksA)
 *     lentB = len(tracksB)
 *     tracksA32 = np.zeros((lentA,), dtype=object)             # <<<<<<<<<<<<<<
 *     tracksB32 = np.zeros((lentB,), dtype=object)
 *     DM = np.zeros((lentA,lentB), dtype=np.double)
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_lentA); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __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 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_builtin_object) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __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_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tracksA32.rcbuffer->pybuffer);
    __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_tracksA32.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_object, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_8 < 0)) {
      PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_tracksA32.rcbuffer->pybuffer, (PyObject*)__pyx_v_tracksA32, &__Pyx_TypeInfo_object, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
      }
    }
    __pyx_pybuffernd_tracksA32.diminfo[0].strides = __pyx_pybuffernd_tracksA32.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_tracksA32.diminfo[0].shape = __pyx_pybuffernd_tracksA32.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 500; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_7 = 0;
  __pyx_v_tracksA32 = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "dipy/tracking/distances.pyx":501
 *     lentB = len(tracksB)
 *     tracksA32 = np.zeros((lentA,), dtype=object)
 *     tracksB32 = np.zeros((lentB,), dtype=object)             # <<<<<<<<<<<<<<
 *     DM = np.zeros((lentA,lentB), dtype=np.double)
 *     # process tracks to predictable memory layout, find longest track
 */
  __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_zeros); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyInt_FromSize_t(__pyx_v_lentB); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_builtin_object) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __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_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_12 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tracksB32.rcbuffer->pybuffer);
    __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_tracksB32.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_object, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_8 < 0)) {
      PyErr_Fetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_tracksB32.rcbuffer->pybuffer, (PyObject*)__pyx_v_tracksB32, &__Pyx_TypeInfo_object, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_11, __pyx_t_10, __pyx_t_9);
      }
    }
    __pyx_pybuffernd_tracksB32.diminfo[0].strides = __pyx_pybuffernd_tracksB32.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_tracksB32.diminfo[0].shape = __pyx_pybuffernd_tracksB32.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 501; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_12 = 0;
  __pyx_v_tracksB32 = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "dipy/tracking/distances.pyx":502
 *     tracksA32 = np.zeros((lentA,), dtype=object)
 *     tracksB32 = np.zeros((lentB,), dtype=object)
 *     DM = np.zeros((lentA,lentB), dtype=np.double)             # <<<<<<<<<<<<<<
 *     # process tracks to predictable memory layout, find longest track
 *     for i in range(lentA):
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyInt_FromSize_t(__pyx_v_lentA); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyInt_FromSize_t(__pyx_v_lentB); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6);
  __pyx_t_4 = 0;
  __pyx_t_6 = 0;
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_double); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_13);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_t_13) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_13);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (!(likely(((__pyx_t_13) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_13, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_14 = ((PyArrayObject *)__pyx_t_13);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_DM.rcbuffer->pybuffer);
    __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_DM.rcbuffer->pybuffer, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_8 < 0)) {
      PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_DM.rcbuffer->pybuffer, (PyObject*)__pyx_v_DM, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
      }
    }
    __pyx_pybuffernd_DM.diminfo[0].strides = __pyx_pybuffernd_DM.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_DM.diminfo[0].shape = __pyx_pybuffernd_DM.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_DM.diminfo[1].strides = __pyx_pybuffernd_DM.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_DM.diminfo[1].shape = __pyx_pybuffernd_DM.rcbuffer->pybuffer.shape[1];
    if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 502; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_14 = 0;
  __pyx_v_DM = ((PyArrayObject *)__pyx_t_13);
  __pyx_t_13 = 0;

  /* "dipy/tracking/distances.pyx":504
 *     DM = np.zeros((lentA,lentB), dtype=np.double)
 *     # process tracks to predictable memory layout, find longest track
 *     for i in range(lentA):             # <<<<<<<<<<<<<<
 *         tracksA32[i] = np.ascontiguousarray(tracksA[i], dtype=f32_dt)
 *         track_len = tracksA32[i].shape[0]
 */
  __pyx_t_15 = __pyx_v_lentA;
  for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
    __pyx_v_i = __pyx_t_16;

    /* "dipy/tracking/distances.pyx":505
 *     # process tracks to predictable memory layout, find longest track
 *     for i in range(lentA):
 *         tracksA32[i] = np.ascontiguousarray(tracksA[i], dtype=f32_dt)             # <<<<<<<<<<<<<<
 *         track_len = tracksA32[i].shape[0]
 *         if track_len > longest_track_lenA:
 */
    __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __pyx_t_13 = __Pyx_GetItemInt(__pyx_v_tracksA, __pyx_v_i, size_t, 0, __Pyx_PyInt_FromSize_t, 0, 0, 0); if (unlikely(__pyx_t_13 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_13);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_13);
    __pyx_t_13 = 0;
    __pyx_t_13 = PyDict_New(); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_13);
    if (PyDict_SetItem(__pyx_t_13, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_6, __pyx_t_13); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __pyx_t_17 = __pyx_v_i;
    __pyx_t_18 = __Pyx_BufPtrStrided1d(PyObject **, __pyx_pybuffernd_tracksA32.rcbuffer->pybuffer.buf, __pyx_t_17, __pyx_pybuffernd_tracksA32.diminfo[0].strides);
    __Pyx_GOTREF(*__pyx_t_18);
    __Pyx_INCREF(__pyx_t_2); __Pyx_DECREF(*__pyx_t_18);
    *__pyx_t_18 = __pyx_t_2;
    __Pyx_GIVEREF(*__pyx_t_18);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "dipy/tracking/distances.pyx":506
 *     for i in range(lentA):
 *         tracksA32[i] = np.ascontiguousarray(tracksA[i], dtype=f32_dt)
 *         track_len = tracksA32[i].shape[0]             # <<<<<<<<<<<<<<
 *         if track_len > longest_track_lenA:
 *             longest_track_lenA = track_len
 */
    __pyx_t_19 = __pyx_v_i;
    __pyx_t_2 = (PyObject *) *__Pyx_BufPtrStrided1d(PyObject **, __pyx_pybuffernd_tracksA32.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_tracksA32.diminfo[0].strides);
    __Pyx_INCREF((PyObject*)__pyx_t_2);
    __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_shape); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_13);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_13, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 506; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __pyx_t_20 = __Pyx_PyInt_As_size_t(__pyx_t_2); if (unlikely((__pyx_t_20 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 506; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_track_len = __pyx_t_20;

    /* "dipy/tracking/distances.pyx":507
 *         tracksA32[i] = np.ascontiguousarray(tracksA[i], dtype=f32_dt)
 *         track_len = tracksA32[i].shape[0]
 *         if track_len > longest_track_lenA:             # <<<<<<<<<<<<<<
 *             longest_track_lenA = track_len
 *     for i in range(lentB):
 */
    __pyx_t_1 = ((__pyx_v_track_len > __pyx_v_longest_track_lenA) != 0);
    if (__pyx_t_1) {

      /* "dipy/tracking/distances.pyx":508
 *         track_len = tracksA32[i].shape[0]
 *         if track_len > longest_track_lenA:
 *             longest_track_lenA = track_len             # <<<<<<<<<<<<<<
 *     for i in range(lentB):
 *         tracksB32[i] = np.ascontiguousarray(tracksB[i], dtype=f32_dt)
 */
      __pyx_v_longest_track_lenA = __pyx_v_track_len;

      /* "dipy/tracking/distances.pyx":507
 *         tracksA32[i] = np.ascontiguousarray(tracksA[i], dtype=f32_dt)
 *         track_len = tracksA32[i].shape[0]
 *         if track_len > longest_track_lenA:             # <<<<<<<<<<<<<<
 *             longest_track_lenA = track_len
 *     for i in range(lentB):
 */
    }
  }

  /* "dipy/tracking/distances.pyx":509
 *         if track_len > longest_track_lenA:
 *             longest_track_lenA = track_len
 *     for i in range(lentB):             # <<<<<<<<<<<<<<
 *         tracksB32[i] = np.ascontiguousarray(tracksB[i], dtype=f32_dt)
 *         track_len = tracksB32[i].shape[0]
 */
  __pyx_t_15 = __pyx_v_lentB;
  for (__pyx_t_16 = 0; __pyx_t_16 < __pyx_t_15; __pyx_t_16+=1) {
    __pyx_v_i = __pyx_t_16;

    /* "dipy/tracking/distances.pyx":510
 *             longest_track_lenA = track_len
 *     for i in range(lentB):
 *         tracksB32[i] = np.ascontiguousarray(tracksB[i], dtype=f32_dt)             # <<<<<<<<<<<<<<
 *         track_len = tracksB32[i].shape[0]
 *         if track_len > longest_track_lenB:
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_13);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_tracksB, __pyx_v_i, size_t, 0, __Pyx_PyInt_FromSize_t, 0, 0, 0); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 510; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_20 = __pyx_v_i;
    __pyx_t_18 = __Pyx_BufPtrStrided1d(PyObject **, __pyx_pybuffernd_tracksB32.rcbuffer->pybuffer.buf, __pyx_t_20, __pyx_pybuffernd_tracksB32.diminfo[0].strides);
    __Pyx_GOTREF(*__pyx_t_18);
    __Pyx_INCREF(__pyx_t_5); __Pyx_DECREF(*__pyx_t_18);
    *__pyx_t_18 = __pyx_t_5;
    __Pyx_GIVEREF(*__pyx_t_18);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "dipy/tracking/distances.pyx":511
 *     for i in range(lentB):
 *         tracksB32[i] = np.ascontiguousarray(tracksB[i], dtype=f32_dt)
 *         track_len = tracksB32[i].shape[0]             # <<<<<<<<<<<<<<
 *         if track_len > longest_track_lenB:
 *             longest_track_lenB = track_len
 */
    __pyx_t_21 = __pyx_v_i;
    __pyx_t_5 = (PyObject *) *__Pyx_BufPtrStrided1d(PyObject **, __pyx_pybuffernd_tracksB32.rcbuffer->pybuffer.buf, __pyx_t_21, __pyx_pybuffernd_tracksB32.diminfo[0].strides);
    __Pyx_INCREF((PyObject*)__pyx_t_5);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_22 = __Pyx_PyInt_As_size_t(__pyx_t_5); if (unlikely((__pyx_t_22 == (size_t)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 511; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_track_len = __pyx_t_22;

    /* "dipy/tracking/distances.pyx":512
 *         tracksB32[i] = np.ascontiguousarray(tracksB[i], dtype=f32_dt)
 *         track_len = tracksB32[i].shape[0]
 *         if track_len > longest_track_lenB:             # <<<<<<<<<<<<<<
 *             longest_track_lenB = track_len
 *     if longest_track_lenB > longest_track_lenA:
 */
    __pyx_t_1 = ((__pyx_v_track_len > __pyx_v_longest_track_lenB) != 0);
    if (__pyx_t_1) {

      /* "dipy/tracking/distances.pyx":513
 *         track_len = tracksB32[i].shape[0]
 *         if track_len > longest_track_lenB:
 *             longest_track_lenB = track_len             # <<<<<<<<<<<<<<
 *     if longest_track_lenB > longest_track_lenA:
 *         longest_track_lenA = longest_track_lenB
 */
      __pyx_v_longest_track_lenB = __pyx_v_track_len;

      /* "dipy/tracking/distances.pyx":512
 *         tracksB32[i] = np.ascontiguousarray(tracksB[i], dtype=f32_dt)
 *         track_len = tracksB32[i].shape[0]
 *         if track_len > longest_track_lenB:             # <<<<<<<<<<<<<<
 *             longest_track_lenB = track_len
 *     if longest_track_lenB > longest_track_lenA:
 */
    }
  }

  /* "dipy/tracking/distances.pyx":514
 *         if track_len > longest_track_lenB:
 *             longest_track_lenB = track_len
 *     if longest_track_lenB > longest_track_lenA:             # <<<<<<<<<<<<<<
 *         longest_track_lenA = longest_track_lenB
 *     # preallocate buffer array for track distance calculations
 */
  __pyx_t_1 = ((__pyx_v_longest_track_lenB > __pyx_v_longest_track_lenA) != 0);
  if (__pyx_t_1) {

    /* "dipy/tracking/distances.pyx":515
 *             longest_track_lenB = track_len
 *     if longest_track_lenB > longest_track_lenA:
 *         longest_track_lenA = longest_track_lenB             # <<<<<<<<<<<<<<
 *     # preallocate buffer array for track distance calculations
 *     cdef:
 */
    __pyx_v_longest_track_lenA = __pyx_v_longest_track_lenB;

    /* "dipy/tracking/distances.pyx":514
 *         if track_len > longest_track_lenB:
 *             longest_track_lenB = track_len
 *     if longest_track_lenB > longest_track_lenA:             # <<<<<<<<<<<<<<
 *         longest_track_lenA = longest_track_lenB
 *     # preallocate buffer array for track distance calculations
 */
  }

  /* "dipy/tracking/distances.pyx":520
 *         cnp.ndarray [cnp.float32_t, ndim=1] distances_buffer
 *         cnp.float32_t *t1_ptr, *t2_ptr, *min_buffer
 *     distances_buffer = np.zeros((longest_track_lenA*2,), dtype=np.float32)             # <<<<<<<<<<<<<<
 *     min_buffer = <cnp.float32_t *> distances_buffer.data
 *     # cycle over tracks
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_FromSize_t((__pyx_v_longest_track_lenA * 2)); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_13 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_13);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_23 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer);
    __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer, (PyObject*)__pyx_t_23, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_8 < 0)) {
      PyErr_Fetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer, (PyObject*)__pyx_v_distances_buffer, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_11, __pyx_t_10, __pyx_t_9);
      }
    }
    __pyx_pybuffernd_distances_buffer.diminfo[0].strides = __pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_distances_buffer.diminfo[0].shape = __pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 520; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_23 = 0;
  __pyx_v_distances_buffer = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "dipy/tracking/distances.pyx":521
 *         cnp.float32_t *t1_ptr, *t2_ptr, *min_buffer
 *     distances_buffer = np.zeros((longest_track_lenA*2,), dtype=np.float32)
 *     min_buffer = <cnp.float32_t *> distances_buffer.data             # <<<<<<<<<<<<<<
 *     # cycle over tracks
 *     cdef:
 */
  __pyx_v_min_buffer = ((__pyx_t_5numpy_float32_t *)__pyx_v_distances_buffer->data);

  /* "dipy/tracking/distances.pyx":526
 *         cnp.ndarray [cnp.float32_t, ndim=2] t1, t2
 *         size_t t1_len, t2_len
 *     for i from 0 <= i < lentA:             # <<<<<<<<<<<<<<
 *         t1 = tracksA32[i]
 *         t1_len = t1.shape[0]
 */
  __pyx_t_15 = __pyx_v_lentA;
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_15; __pyx_v_i++) {

    /* "dipy/tracking/distances.pyx":527
 *         size_t t1_len, t2_len
 *     for i from 0 <= i < lentA:
 *         t1 = tracksA32[i]             # <<<<<<<<<<<<<<
 *         t1_len = t1.shape[0]
 *         t1_ptr = <cnp.float32_t *>t1.data
 */
    __pyx_t_16 = __pyx_v_i;
    __pyx_t_4 = (PyObject *) *__Pyx_BufPtrStrided1d(PyObject **, __pyx_pybuffernd_tracksA32.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_tracksA32.diminfo[0].strides);
    __Pyx_INCREF((PyObject*)__pyx_t_4);
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_24 = ((PyArrayObject *)__pyx_t_4);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t1.rcbuffer->pybuffer);
      __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t1.rcbuffer->pybuffer, (PyObject*)__pyx_t_24, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_8 < 0)) {
        PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t1.rcbuffer->pybuffer, (PyObject*)__pyx_v_t1, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
        }
      }
      __pyx_pybuffernd_t1.diminfo[0].strides = __pyx_pybuffernd_t1.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_t1.diminfo[0].shape = __pyx_pybuffernd_t1.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_t1.diminfo[1].strides = __pyx_pybuffernd_t1.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_t1.diminfo[1].shape = __pyx_pybuffernd_t1.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 527; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_24 = 0;
    __Pyx_XDECREF_SET(__pyx_v_t1, ((PyArrayObject *)__pyx_t_4));
    __pyx_t_4 = 0;

    /* "dipy/tracking/distances.pyx":528
 *     for i from 0 <= i < lentA:
 *         t1 = tracksA32[i]
 *         t1_len = t1.shape[0]             # <<<<<<<<<<<<<<
 *         t1_ptr = <cnp.float32_t *>t1.data
 *         for j from 0 <= j < lentB:
 */
    __pyx_v_t1_len = (__pyx_v_t1->dimensions[0]);

    /* "dipy/tracking/distances.pyx":529
 *         t1 = tracksA32[i]
 *         t1_len = t1.shape[0]
 *         t1_ptr = <cnp.float32_t *>t1.data             # <<<<<<<<<<<<<<
 *         for j from 0 <= j < lentB:
 *             t2 = tracksB32[j]
 */
    __pyx_v_t1_ptr = ((__pyx_t_5numpy_float32_t *)__pyx_v_t1->data);

    /* "dipy/tracking/distances.pyx":530
 *         t1_len = t1.shape[0]
 *         t1_ptr = <cnp.float32_t *>t1.data
 *         for j from 0 <= j < lentB:             # <<<<<<<<<<<<<<
 *             t2 = tracksB32[j]
 *             t2_len = t2.shape[0]
 */
    __pyx_t_22 = __pyx_v_lentB;
    for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_22; __pyx_v_j++) {

      /* "dipy/tracking/distances.pyx":531
 *         t1_ptr = <cnp.float32_t *>t1.data
 *         for j from 0 <= j < lentB:
 *             t2 = tracksB32[j]             # <<<<<<<<<<<<<<
 *             t2_len = t2.shape[0]
 *             t2_ptr = <cnp.float32_t *>t2.data
 */
      __pyx_t_25 = __pyx_v_j;
      __pyx_t_4 = (PyObject *) *__Pyx_BufPtrStrided1d(PyObject **, __pyx_pybuffernd_tracksB32.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_tracksB32.diminfo[0].strides);
      __Pyx_INCREF((PyObject*)__pyx_t_4);
      if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_24 = ((PyArrayObject *)__pyx_t_4);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t2.rcbuffer->pybuffer);
        __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t2.rcbuffer->pybuffer, (PyObject*)__pyx_t_24, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_8 < 0)) {
          PyErr_Fetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t2.rcbuffer->pybuffer, (PyObject*)__pyx_v_t2, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_11, __pyx_t_10, __pyx_t_9);
          }
        }
        __pyx_pybuffernd_t2.diminfo[0].strides = __pyx_pybuffernd_t2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_t2.diminfo[0].shape = __pyx_pybuffernd_t2.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_t2.diminfo[1].strides = __pyx_pybuffernd_t2.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_t2.diminfo[1].shape = __pyx_pybuffernd_t2.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 531; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_24 = 0;
      __Pyx_XDECREF_SET(__pyx_v_t2, ((PyArrayObject *)__pyx_t_4));
      __pyx_t_4 = 0;

      /* "dipy/tracking/distances.pyx":532
 *         for j from 0 <= j < lentB:
 *             t2 = tracksB32[j]
 *             t2_len = t2.shape[0]             # <<<<<<<<<<<<<<
 *             t2_ptr = <cnp.float32_t *>t2.data
 *             DM[i,j] = czhang(t1_len, t1_ptr, t2_len, t2_ptr, min_buffer, metric_type)
 */
      __pyx_v_t2_len = (__pyx_v_t2->dimensions[0]);

      /* "dipy/tracking/distances.pyx":533
 *             t2 = tracksB32[j]
 *             t2_len = t2.shape[0]
 *             t2_ptr = <cnp.float32_t *>t2.data             # <<<<<<<<<<<<<<
 *             DM[i,j] = czhang(t1_len, t1_ptr, t2_len, t2_ptr, min_buffer, metric_type)
 * 
 */
      __pyx_v_t2_ptr = ((__pyx_t_5numpy_float32_t *)__pyx_v_t2->data);

      /* "dipy/tracking/distances.pyx":534
 *             t2_len = t2.shape[0]
 *             t2_ptr = <cnp.float32_t *>t2.data
 *             DM[i,j] = czhang(t1_len, t1_ptr, t2_len, t2_ptr, min_buffer, metric_type)             # <<<<<<<<<<<<<<
 * 
 *     return DM
 */
      __pyx_t_26 = __pyx_v_i;
      __pyx_t_27 = __pyx_v_j;
      *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_DM.rcbuffer->pybuffer.buf, __pyx_t_26, __pyx_pybuffernd_DM.diminfo[0].strides, __pyx_t_27, __pyx_pybuffernd_DM.diminfo[1].strides) = __pyx_f_4dipy_8tracking_9distances_czhang(__pyx_v_t1_len, __pyx_v_t1_ptr, __pyx_v_t2_len, __pyx_v_t2_ptr, __pyx_v_min_buffer, __pyx_v_metric_type);
    }
  }

  /* "dipy/tracking/distances.pyx":536
 *             DM[i,j] = czhang(t1_len, t1_ptr, t2_len, t2_ptr, min_buffer, metric_type)
 * 
 *     return DM             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_DM));
  __pyx_r = ((PyObject *)__pyx_v_DM);
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":462
 * @cython.boundscheck(False)
 * @cython.wraparound(False)
 * def bundles_distances_mam(tracksA, tracksB, metric='avg'):             # <<<<<<<<<<<<<<
 *     ''' Calculate distances between list of tracks A and list of tracks B
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_13);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_DM.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t1.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t2.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tracksA32.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tracksB32.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.bundles_distances_mam", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_DM.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t1.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t2.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tracksA32.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tracksB32.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_tracksA32);
  __Pyx_XDECREF((PyObject *)__pyx_v_tracksB32);
  __Pyx_XDECREF((PyObject *)__pyx_v_DM);
  __Pyx_XDECREF((PyObject *)__pyx_v_distances_buffer);
  __Pyx_XDECREF((PyObject *)__pyx_v_t1);
  __Pyx_XDECREF((PyObject *)__pyx_v_t2);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":541
 * @cython.boundscheck(False)
 * @cython.wraparound(False)
 * def bundles_distances_mdf(tracksA, tracksB):             # <<<<<<<<<<<<<<
 *     ''' Calculate distances between list of tracks A and list of tracks B
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_21bundles_distances_mdf(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_20bundles_distances_mdf[] = " Calculate distances between list of tracks A and list of tracks B\n\n    All tracks need to have the same number of points\n\n    Parameters\n    ----------\n    tracksA : sequence\n       of tracks as arrays, [(N,3) .. (N,3)]\n    tracksB : sequence\n       of tracks as arrays, [(N,3) .. (N,3)]\n\n    Returns\n    -------\n    DM : array, shape (len(tracksA), len(tracksB))\n        distances between tracksA and tracksB according to metric\n\n    See Also\n    ---------\n    dipy.metrics.downsample\n\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_21bundles_distances_mdf = {"bundles_distances_mdf", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_21bundles_distances_mdf, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_20bundles_distances_mdf};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_21bundles_distances_mdf(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_tracksA = 0;
  PyObject *__pyx_v_tracksB = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("bundles_distances_mdf (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tracksA,&__pyx_n_s_tracksB,0};
    PyObject* values[2] = {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  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tracksA)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tracksB)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("bundles_distances_mdf", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 541; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "bundles_distances_mdf") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 541; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_tracksA = values[0];
    __pyx_v_tracksB = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("bundles_distances_mdf", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 541; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.bundles_distances_mdf", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_20bundles_distances_mdf(__pyx_self, __pyx_v_tracksA, __pyx_v_tracksB);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_20bundles_distances_mdf(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tracksA, PyObject *__pyx_v_tracksB) {
  size_t __pyx_v_i;
  size_t __pyx_v_j;
  size_t __pyx_v_lentA;
  size_t __pyx_v_lentB;
  CYTHON_UNUSED size_t __pyx_v_longest_track_len;
  PyArrayObject *__pyx_v_tracksA32 = 0;
  PyArrayObject *__pyx_v_tracksB32 = 0;
  PyArrayObject *__pyx_v_DM = 0;
  __pyx_t_5numpy_float32_t *__pyx_v_t1_ptr;
  __pyx_t_5numpy_float32_t *__pyx_v_t2_ptr;
  PyArrayObject *__pyx_v_t1 = 0;
  PyArrayObject *__pyx_v_t2 = 0;
  float __pyx_v_d[2];
  PyObject *__pyx_v_t_len = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_DM;
  __Pyx_Buffer __pyx_pybuffer_DM;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_t1;
  __Pyx_Buffer __pyx_pybuffer_t1;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_t2;
  __Pyx_Buffer __pyx_pybuffer_t2;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_tracksA32;
  __Pyx_Buffer __pyx_pybuffer_tracksA32;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_tracksB32;
  __Pyx_Buffer __pyx_pybuffer_tracksB32;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyArrayObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyArrayObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyArrayObject *__pyx_t_13 = NULL;
  size_t __pyx_t_14;
  size_t __pyx_t_15;
  size_t __pyx_t_16;
  PyObject **__pyx_t_17;
  size_t __pyx_t_18;
  Py_ssize_t __pyx_t_19;
  PyArrayObject *__pyx_t_20 = NULL;
  size_t __pyx_t_21;
  size_t __pyx_t_22;
  long __pyx_t_23;
  int __pyx_t_24;
  size_t __pyx_t_25;
  size_t __pyx_t_26;
  size_t __pyx_t_27;
  size_t __pyx_t_28;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("bundles_distances_mdf", 0);
  __pyx_pybuffer_tracksA32.pybuffer.buf = NULL;
  __pyx_pybuffer_tracksA32.refcount = 0;
  __pyx_pybuffernd_tracksA32.data = NULL;
  __pyx_pybuffernd_tracksA32.rcbuffer = &__pyx_pybuffer_tracksA32;
  __pyx_pybuffer_tracksB32.pybuffer.buf = NULL;
  __pyx_pybuffer_tracksB32.refcount = 0;
  __pyx_pybuffernd_tracksB32.data = NULL;
  __pyx_pybuffernd_tracksB32.rcbuffer = &__pyx_pybuffer_tracksB32;
  __pyx_pybuffer_DM.pybuffer.buf = NULL;
  __pyx_pybuffer_DM.refcount = 0;
  __pyx_pybuffernd_DM.data = NULL;
  __pyx_pybuffernd_DM.rcbuffer = &__pyx_pybuffer_DM;
  __pyx_pybuffer_t1.pybuffer.buf = NULL;
  __pyx_pybuffer_t1.refcount = 0;
  __pyx_pybuffernd_t1.data = NULL;
  __pyx_pybuffernd_t1.rcbuffer = &__pyx_pybuffer_t1;
  __pyx_pybuffer_t2.pybuffer.buf = NULL;
  __pyx_pybuffer_t2.refcount = 0;
  __pyx_pybuffernd_t2.data = NULL;
  __pyx_pybuffernd_t2.rcbuffer = &__pyx_pybuffer_t2;

  /* "dipy/tracking/distances.pyx":567
 *     # preprocess tracks
 *     cdef:
 *         size_t longest_track_len = 0, track_len             # <<<<<<<<<<<<<<
 *         longest_track_lenA, longest_track_lenB
 *         cnp.ndarray[object, ndim=1] tracksA32
 */
  __pyx_v_longest_track_len = 0;

  /* "dipy/tracking/distances.pyx":572
 *         cnp.ndarray[object, ndim=1] tracksB32
 *         cnp.ndarray[cnp.double_t, ndim=2] DM
 *     lentA = len(tracksA)             # <<<<<<<<<<<<<<
 *     lentB = len(tracksB)
 *     tracksA32 = np.zeros((lentA,), dtype=object)
 */
  __pyx_t_1 = PyObject_Length(__pyx_v_tracksA); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 572; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_lentA = __pyx_t_1;

  /* "dipy/tracking/distances.pyx":573
 *         cnp.ndarray[cnp.double_t, ndim=2] DM
 *     lentA = len(tracksA)
 *     lentB = len(tracksB)             # <<<<<<<<<<<<<<
 *     tracksA32 = np.zeros((lentA,), dtype=object)
 *     tracksB32 = np.zeros((lentB,), dtype=object)
 */
  __pyx_t_1 = PyObject_Length(__pyx_v_tracksB); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 573; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_lentB = __pyx_t_1;

  /* "dipy/tracking/distances.pyx":574
 *     lentA = len(tracksA)
 *     lentB = len(tracksB)
 *     tracksA32 = np.zeros((lentA,), dtype=object)             # <<<<<<<<<<<<<<
 *     tracksB32 = np.zeros((lentB,), dtype=object)
 *     DM = np.zeros((lentA,lentB), dtype=np.double)
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_lentA); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __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 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_builtin_object) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tracksA32.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_tracksA32.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_object, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_tracksA32.rcbuffer->pybuffer, (PyObject*)__pyx_v_tracksA32, &__Pyx_TypeInfo_object, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
    }
    __pyx_pybuffernd_tracksA32.diminfo[0].strides = __pyx_pybuffernd_tracksA32.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_tracksA32.diminfo[0].shape = __pyx_pybuffernd_tracksA32.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_tracksA32 = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "dipy/tracking/distances.pyx":575
 *     lentB = len(tracksB)
 *     tracksA32 = np.zeros((lentA,), dtype=object)
 *     tracksB32 = np.zeros((lentB,), dtype=object)             # <<<<<<<<<<<<<<
 *     DM = np.zeros((lentA,lentB), dtype=np.double)
 *     # process tracks to predictable memory layout
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyInt_FromSize_t(__pyx_v_lentB); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __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 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_builtin_object) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __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_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_11 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tracksB32.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_tracksB32.rcbuffer->pybuffer, (PyObject*)__pyx_t_11, &__Pyx_TypeInfo_object, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_tracksB32.rcbuffer->pybuffer, (PyObject*)__pyx_v_tracksB32, &__Pyx_TypeInfo_object, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
      }
    }
    __pyx_pybuffernd_tracksB32.diminfo[0].strides = __pyx_pybuffernd_tracksB32.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_tracksB32.diminfo[0].shape = __pyx_pybuffernd_tracksB32.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 575; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_11 = 0;
  __pyx_v_tracksB32 = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":576
 *     tracksA32 = np.zeros((lentA,), dtype=object)
 *     tracksB32 = np.zeros((lentB,), dtype=object)
 *     DM = np.zeros((lentA,lentB), dtype=np.double)             # <<<<<<<<<<<<<<
 *     # process tracks to predictable memory layout
 *     for i in range(lentA):
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_v_lentA); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyInt_FromSize_t(__pyx_v_lentB); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
  __pyx_t_3 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_double); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_12) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_12) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_12, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_13 = ((PyArrayObject *)__pyx_t_12);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_DM.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_DM.rcbuffer->pybuffer, (PyObject*)__pyx_t_13, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_DM.rcbuffer->pybuffer, (PyObject*)__pyx_v_DM, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
    }
    __pyx_pybuffernd_DM.diminfo[0].strides = __pyx_pybuffernd_DM.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_DM.diminfo[0].shape = __pyx_pybuffernd_DM.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_DM.diminfo[1].strides = __pyx_pybuffernd_DM.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_DM.diminfo[1].shape = __pyx_pybuffernd_DM.rcbuffer->pybuffer.shape[1];
    if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 576; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_13 = 0;
  __pyx_v_DM = ((PyArrayObject *)__pyx_t_12);
  __pyx_t_12 = 0;

  /* "dipy/tracking/distances.pyx":578
 *     DM = np.zeros((lentA,lentB), dtype=np.double)
 *     # process tracks to predictable memory layout
 *     for i in range(lentA):             # <<<<<<<<<<<<<<
 *         tracksA32[i] = np.ascontiguousarray(tracksA[i], dtype=f32_dt)
 *     for i in range(lentB):
 */
  __pyx_t_14 = __pyx_v_lentA;
  for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) {
    __pyx_v_i = __pyx_t_15;

    /* "dipy/tracking/distances.pyx":579
 *     # process tracks to predictable memory layout
 *     for i in range(lentA):
 *         tracksA32[i] = np.ascontiguousarray(tracksA[i], dtype=f32_dt)             # <<<<<<<<<<<<<<
 *     for i in range(lentB):
 *         tracksB32[i] = np.ascontiguousarray(tracksB[i], dtype=f32_dt)
 */
    __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_12 = __Pyx_GetItemInt(__pyx_v_tracksA, __pyx_v_i, size_t, 0, __Pyx_PyInt_FromSize_t, 0, 0, 0); if (unlikely(__pyx_t_12 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_12);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_12);
    __pyx_t_12 = 0;
    __pyx_t_12 = PyDict_New(); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_12);
    if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_12); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 579; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_16 = __pyx_v_i;
    __pyx_t_17 = __Pyx_BufPtrStrided1d(PyObject **, __pyx_pybuffernd_tracksA32.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_tracksA32.diminfo[0].strides);
    __Pyx_GOTREF(*__pyx_t_17);
    __Pyx_INCREF(__pyx_t_2); __Pyx_DECREF(*__pyx_t_17);
    *__pyx_t_17 = __pyx_t_2;
    __Pyx_GIVEREF(*__pyx_t_17);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }

  /* "dipy/tracking/distances.pyx":580
 *     for i in range(lentA):
 *         tracksA32[i] = np.ascontiguousarray(tracksA[i], dtype=f32_dt)
 *     for i in range(lentB):             # <<<<<<<<<<<<<<
 *         tracksB32[i] = np.ascontiguousarray(tracksB[i], dtype=f32_dt)
 *     # preallocate buffer array for track distance calculations
 */
  __pyx_t_14 = __pyx_v_lentB;
  for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) {
    __pyx_v_i = __pyx_t_15;

    /* "dipy/tracking/distances.pyx":581
 *         tracksA32[i] = np.ascontiguousarray(tracksA[i], dtype=f32_dt)
 *     for i in range(lentB):
 *         tracksB32[i] = np.ascontiguousarray(tracksB[i], dtype=f32_dt)             # <<<<<<<<<<<<<<
 *     # preallocate buffer array for track distance calculations
 *     cdef:
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_tracksB, __pyx_v_i, size_t, 0, __Pyx_PyInt_FromSize_t, 0, 0, 0); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_18 = __pyx_v_i;
    __pyx_t_17 = __Pyx_BufPtrStrided1d(PyObject **, __pyx_pybuffernd_tracksB32.rcbuffer->pybuffer.buf, __pyx_t_18, __pyx_pybuffernd_tracksB32.diminfo[0].strides);
    __Pyx_GOTREF(*__pyx_t_17);
    __Pyx_INCREF(__pyx_t_4); __Pyx_DECREF(*__pyx_t_17);
    *__pyx_t_17 = __pyx_t_4;
    __Pyx_GIVEREF(*__pyx_t_17);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }

  /* "dipy/tracking/distances.pyx":590
 *         size_t t1_len, t2_len
 *         float d[2]
 *     t_len = tracksA32[0].shape[0]             # <<<<<<<<<<<<<<
 * 
 *     for i from 0 <= i < lentA:
 */
  __pyx_t_19 = 0;
  __pyx_t_4 = (PyObject *) *__Pyx_BufPtrStrided1d(PyObject **, __pyx_pybuffernd_tracksA32.rcbuffer->pybuffer.buf, __pyx_t_19, __pyx_pybuffernd_tracksA32.diminfo[0].strides);
  __Pyx_INCREF((PyObject*)__pyx_t_4);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 590; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_2, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 590; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_t_len = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "dipy/tracking/distances.pyx":592
 *     t_len = tracksA32[0].shape[0]
 * 
 *     for i from 0 <= i < lentA:             # <<<<<<<<<<<<<<
 *         t1 = tracksA32[i]
 *         #t1_len = t1.shape[0]
 */
  __pyx_t_14 = __pyx_v_lentA;
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_14; __pyx_v_i++) {

    /* "dipy/tracking/distances.pyx":593
 * 
 *     for i from 0 <= i < lentA:
 *         t1 = tracksA32[i]             # <<<<<<<<<<<<<<
 *         #t1_len = t1.shape[0]
 *         t1_ptr = <cnp.float32_t *>t1.data
 */
    __pyx_t_15 = __pyx_v_i;
    __pyx_t_4 = (PyObject *) *__Pyx_BufPtrStrided1d(PyObject **, __pyx_pybuffernd_tracksA32.rcbuffer->pybuffer.buf, __pyx_t_15, __pyx_pybuffernd_tracksA32.diminfo[0].strides);
    __Pyx_INCREF((PyObject*)__pyx_t_4);
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_20 = ((PyArrayObject *)__pyx_t_4);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t1.rcbuffer->pybuffer);
      __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t1.rcbuffer->pybuffer, (PyObject*)__pyx_t_20, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_7 < 0)) {
        PyErr_Fetch(&__pyx_t_10, &__pyx_t_9, &__pyx_t_8);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t1.rcbuffer->pybuffer, (PyObject*)__pyx_v_t1, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_10, __pyx_t_9, __pyx_t_8);
        }
      }
      __pyx_pybuffernd_t1.diminfo[0].strides = __pyx_pybuffernd_t1.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_t1.diminfo[0].shape = __pyx_pybuffernd_t1.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_t1.diminfo[1].strides = __pyx_pybuffernd_t1.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_t1.diminfo[1].shape = __pyx_pybuffernd_t1.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 593; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_20 = 0;
    __Pyx_XDECREF_SET(__pyx_v_t1, ((PyArrayObject *)__pyx_t_4));
    __pyx_t_4 = 0;

    /* "dipy/tracking/distances.pyx":595
 *         t1 = tracksA32[i]
 *         #t1_len = t1.shape[0]
 *         t1_ptr = <cnp.float32_t *>t1.data             # <<<<<<<<<<<<<<
 *         for j from 0 <= j < lentB:
 *             t2 = tracksB32[j]
 */
    __pyx_v_t1_ptr = ((__pyx_t_5numpy_float32_t *)__pyx_v_t1->data);

    /* "dipy/tracking/distances.pyx":596
 *         #t1_len = t1.shape[0]
 *         t1_ptr = <cnp.float32_t *>t1.data
 *         for j from 0 <= j < lentB:             # <<<<<<<<<<<<<<
 *             t2 = tracksB32[j]
 *             #t2_len = t2.shape[0]
 */
    __pyx_t_21 = __pyx_v_lentB;
    for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_21; __pyx_v_j++) {

      /* "dipy/tracking/distances.pyx":597
 *         t1_ptr = <cnp.float32_t *>t1.data
 *         for j from 0 <= j < lentB:
 *             t2 = tracksB32[j]             # <<<<<<<<<<<<<<
 *             #t2_len = t2.shape[0]
 *             t2_ptr = <cnp.float32_t *>t2.data
 */
      __pyx_t_22 = __pyx_v_j;
      __pyx_t_4 = (PyObject *) *__Pyx_BufPtrStrided1d(PyObject **, __pyx_pybuffernd_tracksB32.rcbuffer->pybuffer.buf, __pyx_t_22, __pyx_pybuffernd_tracksB32.diminfo[0].strides);
      __Pyx_INCREF((PyObject*)__pyx_t_4);
      if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_20 = ((PyArrayObject *)__pyx_t_4);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t2.rcbuffer->pybuffer);
        __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t2.rcbuffer->pybuffer, (PyObject*)__pyx_t_20, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_7 < 0)) {
          PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_t2.rcbuffer->pybuffer, (PyObject*)__pyx_v_t2, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
          }
        }
        __pyx_pybuffernd_t2.diminfo[0].strides = __pyx_pybuffernd_t2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_t2.diminfo[0].shape = __pyx_pybuffernd_t2.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_t2.diminfo[1].strides = __pyx_pybuffernd_t2.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_t2.diminfo[1].shape = __pyx_pybuffernd_t2.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 597; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_20 = 0;
      __Pyx_XDECREF_SET(__pyx_v_t2, ((PyArrayObject *)__pyx_t_4));
      __pyx_t_4 = 0;

      /* "dipy/tracking/distances.pyx":599
 *             t2 = tracksB32[j]
 *             #t2_len = t2.shape[0]
 *             t2_ptr = <cnp.float32_t *>t2.data             # <<<<<<<<<<<<<<
 *             #DM[i,j] = czhang(t1_len, t1_ptr, t2_len, t2_ptr, min_buffer, metric_type)
 *             track_direct_flip_dist(t1_ptr, t2_ptr,t_len,<float *>d)
 */
      __pyx_v_t2_ptr = ((__pyx_t_5numpy_float32_t *)__pyx_v_t2->data);

      /* "dipy/tracking/distances.pyx":601
 *             t2_ptr = <cnp.float32_t *>t2.data
 *             #DM[i,j] = czhang(t1_len, t1_ptr, t2_len, t2_ptr, min_buffer, metric_type)
 *             track_direct_flip_dist(t1_ptr, t2_ptr,t_len,<float *>d)             # <<<<<<<<<<<<<<
 *             if d[0]<d[1]:
 *                 DM[i,j]=d[0]
 */
      __pyx_t_23 = __Pyx_PyInt_As_long(__pyx_v_t_len); if (unlikely((__pyx_t_23 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 601; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_f_4dipy_8tracking_9distances_track_direct_flip_dist(__pyx_v_t1_ptr, __pyx_v_t2_ptr, __pyx_t_23, ((float *)__pyx_v_d));

      /* "dipy/tracking/distances.pyx":602
 *             #DM[i,j] = czhang(t1_len, t1_ptr, t2_len, t2_ptr, min_buffer, metric_type)
 *             track_direct_flip_dist(t1_ptr, t2_ptr,t_len,<float *>d)
 *             if d[0]<d[1]:             # <<<<<<<<<<<<<<
 *                 DM[i,j]=d[0]
 *             else:
 */
      __pyx_t_24 = (((__pyx_v_d[0]) < (__pyx_v_d[1])) != 0);
      if (__pyx_t_24) {

        /* "dipy/tracking/distances.pyx":603
 *             track_direct_flip_dist(t1_ptr, t2_ptr,t_len,<float *>d)
 *             if d[0]<d[1]:
 *                 DM[i,j]=d[0]             # <<<<<<<<<<<<<<
 *             else:
 *                 DM[i,j]=d[1]
 */
        __pyx_t_25 = __pyx_v_i;
        __pyx_t_26 = __pyx_v_j;
        *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_DM.rcbuffer->pybuffer.buf, __pyx_t_25, __pyx_pybuffernd_DM.diminfo[0].strides, __pyx_t_26, __pyx_pybuffernd_DM.diminfo[1].strides) = (__pyx_v_d[0]);

        /* "dipy/tracking/distances.pyx":602
 *             #DM[i,j] = czhang(t1_len, t1_ptr, t2_len, t2_ptr, min_buffer, metric_type)
 *             track_direct_flip_dist(t1_ptr, t2_ptr,t_len,<float *>d)
 *             if d[0]<d[1]:             # <<<<<<<<<<<<<<
 *                 DM[i,j]=d[0]
 *             else:
 */
        goto __pyx_L11;
      }

      /* "dipy/tracking/distances.pyx":605
 *                 DM[i,j]=d[0]
 *             else:
 *                 DM[i,j]=d[1]             # <<<<<<<<<<<<<<
 *     return DM
 * 
 */
      /*else*/ {
        __pyx_t_27 = __pyx_v_i;
        __pyx_t_28 = __pyx_v_j;
        *__Pyx_BufPtrStrided2d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_DM.rcbuffer->pybuffer.buf, __pyx_t_27, __pyx_pybuffernd_DM.diminfo[0].strides, __pyx_t_28, __pyx_pybuffernd_DM.diminfo[1].strides) = (__pyx_v_d[1]);
      }
      __pyx_L11:;
    }
  }

  /* "dipy/tracking/distances.pyx":606
 *             else:
 *                 DM[i,j]=d[1]
 *     return DM             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_DM));
  __pyx_r = ((PyObject *)__pyx_v_DM);
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":541
 * @cython.boundscheck(False)
 * @cython.wraparound(False)
 * def bundles_distances_mdf(tracksA, tracksB):             # <<<<<<<<<<<<<<
 *     ''' Calculate distances between list of tracks A and list of tracks B
 * 
 */

  /* 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_12);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_DM.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t1.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t2.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tracksA32.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tracksB32.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.bundles_distances_mdf", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_DM.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t1.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_t2.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tracksA32.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_tracksB32.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_tracksA32);
  __Pyx_XDECREF((PyObject *)__pyx_v_tracksB32);
  __Pyx_XDECREF((PyObject *)__pyx_v_DM);
  __Pyx_XDECREF((PyObject *)__pyx_v_t1);
  __Pyx_XDECREF((PyObject *)__pyx_v_t2);
  __Pyx_XDECREF(__pyx_v_t_len);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":614
 * 
 * @cython.cdivision(True)
 * cdef inline cnp.float32_t czhang(size_t t1_len,             # <<<<<<<<<<<<<<
 *                                  cnp.float32_t *track1_ptr,
 *                                  size_t t2_len,
 */

static CYTHON_INLINE __pyx_t_5numpy_float32_t __pyx_f_4dipy_8tracking_9distances_czhang(size_t __pyx_v_t1_len, __pyx_t_5numpy_float32_t *__pyx_v_track1_ptr, size_t __pyx_v_t2_len, __pyx_t_5numpy_float32_t *__pyx_v_track2_ptr, __pyx_t_5numpy_float32_t *__pyx_v_min_buffer, int __pyx_v_metric_type) {
  __pyx_t_5numpy_float32_t *__pyx_v_min_t2t1;
  __pyx_t_5numpy_float32_t *__pyx_v_min_t1t2;
  size_t __pyx_v_t1_pi;
  size_t __pyx_v_t2_pi;
  __pyx_t_5numpy_float32_t __pyx_v_mean_t2t1;
  __pyx_t_5numpy_float32_t __pyx_v_mean_t1t2;
  __pyx_t_5numpy_float32_t __pyx_v_dist_val;
  __pyx_t_5numpy_float32_t __pyx_r;
  size_t __pyx_t_1;
  int __pyx_t_2;

  /* "dipy/tracking/distances.pyx":623
 *     cdef:
 *         cnp.float32_t *min_t2t1, *min_t1t2
 *     min_t2t1 = min_buffer             # <<<<<<<<<<<<<<
 *     min_t1t2 = min_buffer + t2_len
 *     min_distances(t1_len, track1_ptr,
 */
  __pyx_v_min_t2t1 = __pyx_v_min_buffer;

  /* "dipy/tracking/distances.pyx":624
 *         cnp.float32_t *min_t2t1, *min_t1t2
 *     min_t2t1 = min_buffer
 *     min_t1t2 = min_buffer + t2_len             # <<<<<<<<<<<<<<
 *     min_distances(t1_len, track1_ptr,
 *                   t2_len, track2_ptr,
 */
  __pyx_v_min_t1t2 = (__pyx_v_min_buffer + __pyx_v_t2_len);

  /* "dipy/tracking/distances.pyx":625
 *     min_t2t1 = min_buffer
 *     min_t1t2 = min_buffer + t2_len
 *     min_distances(t1_len, track1_ptr,             # <<<<<<<<<<<<<<
 *                   t2_len, track2_ptr,
 *                   min_t2t1,
 */
  __pyx_f_4dipy_8tracking_9distances_min_distances(__pyx_v_t1_len, __pyx_v_track1_ptr, __pyx_v_t2_len, __pyx_v_track2_ptr, __pyx_v_min_t2t1, __pyx_v_min_t1t2);

  /* "dipy/tracking/distances.pyx":631
 *     cdef:
 *         size_t t1_pi, t2_pi
 *         cnp.float32_t mean_t2t1 = 0, mean_t1t2 = 0, dist_val             # <<<<<<<<<<<<<<
 *     for t1_pi from 0<= t1_pi < t1_len:
 *         mean_t1t2+=min_t1t2[t1_pi]
 */
  __pyx_v_mean_t2t1 = 0.0;
  __pyx_v_mean_t1t2 = 0.0;

  /* "dipy/tracking/distances.pyx":632
 *         size_t t1_pi, t2_pi
 *         cnp.float32_t mean_t2t1 = 0, mean_t1t2 = 0, dist_val
 *     for t1_pi from 0<= t1_pi < t1_len:             # <<<<<<<<<<<<<<
 *         mean_t1t2+=min_t1t2[t1_pi]
 *     mean_t1t2=mean_t1t2/t1_len
 */
  __pyx_t_1 = __pyx_v_t1_len;
  for (__pyx_v_t1_pi = 0; __pyx_v_t1_pi < __pyx_t_1; __pyx_v_t1_pi++) {

    /* "dipy/tracking/distances.pyx":633
 *         cnp.float32_t mean_t2t1 = 0, mean_t1t2 = 0, dist_val
 *     for t1_pi from 0<= t1_pi < t1_len:
 *         mean_t1t2+=min_t1t2[t1_pi]             # <<<<<<<<<<<<<<
 *     mean_t1t2=mean_t1t2/t1_len
 *     for t2_pi from 0<= t2_pi < t2_len:
 */
    __pyx_v_mean_t1t2 = (__pyx_v_mean_t1t2 + (__pyx_v_min_t1t2[__pyx_v_t1_pi]));
  }

  /* "dipy/tracking/distances.pyx":634
 *     for t1_pi from 0<= t1_pi < t1_len:
 *         mean_t1t2+=min_t1t2[t1_pi]
 *     mean_t1t2=mean_t1t2/t1_len             # <<<<<<<<<<<<<<
 *     for t2_pi from 0<= t2_pi < t2_len:
 *         mean_t2t1+=min_t2t1[t2_pi]
 */
  __pyx_v_mean_t1t2 = (__pyx_v_mean_t1t2 / __pyx_v_t1_len);

  /* "dipy/tracking/distances.pyx":635
 *         mean_t1t2+=min_t1t2[t1_pi]
 *     mean_t1t2=mean_t1t2/t1_len
 *     for t2_pi from 0<= t2_pi < t2_len:             # <<<<<<<<<<<<<<
 *         mean_t2t1+=min_t2t1[t2_pi]
 *     mean_t2t1=mean_t2t1/t2_len
 */
  __pyx_t_1 = __pyx_v_t2_len;
  for (__pyx_v_t2_pi = 0; __pyx_v_t2_pi < __pyx_t_1; __pyx_v_t2_pi++) {

    /* "dipy/tracking/distances.pyx":636
 *     mean_t1t2=mean_t1t2/t1_len
 *     for t2_pi from 0<= t2_pi < t2_len:
 *         mean_t2t1+=min_t2t1[t2_pi]             # <<<<<<<<<<<<<<
 *     mean_t2t1=mean_t2t1/t2_len
 *     if metric_type == 0:
 */
    __pyx_v_mean_t2t1 = (__pyx_v_mean_t2t1 + (__pyx_v_min_t2t1[__pyx_v_t2_pi]));
  }

  /* "dipy/tracking/distances.pyx":637
 *     for t2_pi from 0<= t2_pi < t2_len:
 *         mean_t2t1+=min_t2t1[t2_pi]
 *     mean_t2t1=mean_t2t1/t2_len             # <<<<<<<<<<<<<<
 *     if metric_type == 0:
 *         dist_val=(mean_t2t1+mean_t1t2)/2.0
 */
  __pyx_v_mean_t2t1 = (__pyx_v_mean_t2t1 / __pyx_v_t2_len);

  /* "dipy/tracking/distances.pyx":638
 *         mean_t2t1+=min_t2t1[t2_pi]
 *     mean_t2t1=mean_t2t1/t2_len
 *     if metric_type == 0:             # <<<<<<<<<<<<<<
 *         dist_val=(mean_t2t1+mean_t1t2)/2.0
 *     elif metric_type == 1:
 */
  switch (__pyx_v_metric_type) {
    case 0:

    /* "dipy/tracking/distances.pyx":639
 *     mean_t2t1=mean_t2t1/t2_len
 *     if metric_type == 0:
 *         dist_val=(mean_t2t1+mean_t1t2)/2.0             # <<<<<<<<<<<<<<
 *     elif metric_type == 1:
 *         if mean_t2t1 < mean_t1t2:
 */
    __pyx_v_dist_val = ((__pyx_v_mean_t2t1 + __pyx_v_mean_t1t2) / 2.0);

    /* "dipy/tracking/distances.pyx":638
 *         mean_t2t1+=min_t2t1[t2_pi]
 *     mean_t2t1=mean_t2t1/t2_len
 *     if metric_type == 0:             # <<<<<<<<<<<<<<
 *         dist_val=(mean_t2t1+mean_t1t2)/2.0
 *     elif metric_type == 1:
 */
    break;

    /* "dipy/tracking/distances.pyx":640
 *     if metric_type == 0:
 *         dist_val=(mean_t2t1+mean_t1t2)/2.0
 *     elif metric_type == 1:             # <<<<<<<<<<<<<<
 *         if mean_t2t1 < mean_t1t2:
 *             dist_val=mean_t2t1
 */
    case 1:

    /* "dipy/tracking/distances.pyx":641
 *         dist_val=(mean_t2t1+mean_t1t2)/2.0
 *     elif metric_type == 1:
 *         if mean_t2t1 < mean_t1t2:             # <<<<<<<<<<<<<<
 *             dist_val=mean_t2t1
 *         else:
 */
    __pyx_t_2 = ((__pyx_v_mean_t2t1 < __pyx_v_mean_t1t2) != 0);
    if (__pyx_t_2) {

      /* "dipy/tracking/distances.pyx":642
 *     elif metric_type == 1:
 *         if mean_t2t1 < mean_t1t2:
 *             dist_val=mean_t2t1             # <<<<<<<<<<<<<<
 *         else:
 *             dist_val=mean_t1t2
 */
      __pyx_v_dist_val = __pyx_v_mean_t2t1;

      /* "dipy/tracking/distances.pyx":641
 *         dist_val=(mean_t2t1+mean_t1t2)/2.0
 *     elif metric_type == 1:
 *         if mean_t2t1 < mean_t1t2:             # <<<<<<<<<<<<<<
 *             dist_val=mean_t2t1
 *         else:
 */
      goto __pyx_L7;
    }

    /* "dipy/tracking/distances.pyx":644
 *             dist_val=mean_t2t1
 *         else:
 *             dist_val=mean_t1t2             # <<<<<<<<<<<<<<
 *     elif metric_type == 2:
 *         if mean_t2t1 > mean_t1t2:
 */
    /*else*/ {
      __pyx_v_dist_val = __pyx_v_mean_t1t2;
    }
    __pyx_L7:;

    /* "dipy/tracking/distances.pyx":640
 *     if metric_type == 0:
 *         dist_val=(mean_t2t1+mean_t1t2)/2.0
 *     elif metric_type == 1:             # <<<<<<<<<<<<<<
 *         if mean_t2t1 < mean_t1t2:
 *             dist_val=mean_t2t1
 */
    break;

    /* "dipy/tracking/distances.pyx":645
 *         else:
 *             dist_val=mean_t1t2
 *     elif metric_type == 2:             # <<<<<<<<<<<<<<
 *         if mean_t2t1 > mean_t1t2:
 *             dist_val=mean_t2t1
 */
    case 2:

    /* "dipy/tracking/distances.pyx":646
 *             dist_val=mean_t1t2
 *     elif metric_type == 2:
 *         if mean_t2t1 > mean_t1t2:             # <<<<<<<<<<<<<<
 *             dist_val=mean_t2t1
 *         else:
 */
    __pyx_t_2 = ((__pyx_v_mean_t2t1 > __pyx_v_mean_t1t2) != 0);
    if (__pyx_t_2) {

      /* "dipy/tracking/distances.pyx":647
 *     elif metric_type == 2:
 *         if mean_t2t1 > mean_t1t2:
 *             dist_val=mean_t2t1             # <<<<<<<<<<<<<<
 *         else:
 *             dist_val=mean_t1t2
 */
      __pyx_v_dist_val = __pyx_v_mean_t2t1;

      /* "dipy/tracking/distances.pyx":646
 *             dist_val=mean_t1t2
 *     elif metric_type == 2:
 *         if mean_t2t1 > mean_t1t2:             # <<<<<<<<<<<<<<
 *             dist_val=mean_t2t1
 *         else:
 */
      goto __pyx_L8;
    }

    /* "dipy/tracking/distances.pyx":649
 *             dist_val=mean_t2t1
 *         else:
 *             dist_val=mean_t1t2             # <<<<<<<<<<<<<<
 *     return dist_val
 * 
 */
    /*else*/ {
      __pyx_v_dist_val = __pyx_v_mean_t1t2;
    }
    __pyx_L8:;

    /* "dipy/tracking/distances.pyx":645
 *         else:
 *             dist_val=mean_t1t2
 *     elif metric_type == 2:             # <<<<<<<<<<<<<<
 *         if mean_t2t1 > mean_t1t2:
 *             dist_val=mean_t2t1
 */
    break;
    default: break;
  }

  /* "dipy/tracking/distances.pyx":650
 *         else:
 *             dist_val=mean_t1t2
 *     return dist_val             # <<<<<<<<<<<<<<
 * 
 * @cython.cdivision(True)
 */
  __pyx_r = __pyx_v_dist_val;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":614
 * 
 * @cython.cdivision(True)
 * cdef inline cnp.float32_t czhang(size_t t1_len,             # <<<<<<<<<<<<<<
 *                                  cnp.float32_t *track1_ptr,
 *                                  size_t t2_len,
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":653
 * 
 * @cython.cdivision(True)
 * cdef inline void min_distances(size_t t1_len,             # <<<<<<<<<<<<<<
 *                                cnp.float32_t *track1_ptr,
 *                                size_t t2_len,
 */

static CYTHON_INLINE void __pyx_f_4dipy_8tracking_9distances_min_distances(size_t __pyx_v_t1_len, __pyx_t_5numpy_float32_t *__pyx_v_track1_ptr, size_t __pyx_v_t2_len, __pyx_t_5numpy_float32_t *__pyx_v_track2_ptr, __pyx_t_5numpy_float32_t *__pyx_v_min_t2t1, __pyx_t_5numpy_float32_t *__pyx_v_min_t1t2) {
  __pyx_t_5numpy_float32_t *__pyx_v_t1_pt;
  __pyx_t_5numpy_float32_t *__pyx_v_t2_pt;
  __pyx_t_5numpy_float32_t __pyx_v_d0;
  __pyx_t_5numpy_float32_t __pyx_v_d1;
  __pyx_t_5numpy_float32_t __pyx_v_d2;
  __pyx_t_5numpy_float32_t __pyx_v_delta2;
  int __pyx_v_t1_pi;
  int __pyx_v_t2_pi;
  size_t __pyx_t_1;
  size_t __pyx_t_2;
  int __pyx_t_3;

  /* "dipy/tracking/distances.pyx":663
 *         cnp.float32_t delta2
 *         int t1_pi, t2_pi
 *     for t2_pi from 0<= t2_pi < t2_len:             # <<<<<<<<<<<<<<
 *         min_t2t1[t2_pi] = inf
 *     for t1_pi from 0<= t1_pi < t1_len:
 */
  __pyx_t_1 = __pyx_v_t2_len;
  for (__pyx_v_t2_pi = 0; __pyx_v_t2_pi < __pyx_t_1; __pyx_v_t2_pi++) {

    /* "dipy/tracking/distances.pyx":664
 *         int t1_pi, t2_pi
 *     for t2_pi from 0<= t2_pi < t2_len:
 *         min_t2t1[t2_pi] = inf             # <<<<<<<<<<<<<<
 *     for t1_pi from 0<= t1_pi < t1_len:
 *         min_t1t2[t1_pi] = inf
 */
    (__pyx_v_min_t2t1[__pyx_v_t2_pi]) = __pyx_v_4dipy_8tracking_9distances_inf;
  }

  /* "dipy/tracking/distances.pyx":665
 *     for t2_pi from 0<= t2_pi < t2_len:
 *         min_t2t1[t2_pi] = inf
 *     for t1_pi from 0<= t1_pi < t1_len:             # <<<<<<<<<<<<<<
 *         min_t1t2[t1_pi] = inf
 *     # pointer to current point in track 1
 */
  __pyx_t_1 = __pyx_v_t1_len;
  for (__pyx_v_t1_pi = 0; __pyx_v_t1_pi < __pyx_t_1; __pyx_v_t1_pi++) {

    /* "dipy/tracking/distances.pyx":666
 *         min_t2t1[t2_pi] = inf
 *     for t1_pi from 0<= t1_pi < t1_len:
 *         min_t1t2[t1_pi] = inf             # <<<<<<<<<<<<<<
 *     # pointer to current point in track 1
 *     t1_pt = track1_ptr
 */
    (__pyx_v_min_t1t2[__pyx_v_t1_pi]) = __pyx_v_4dipy_8tracking_9distances_inf;
  }

  /* "dipy/tracking/distances.pyx":668
 *         min_t1t2[t1_pi] = inf
 *     # pointer to current point in track 1
 *     t1_pt = track1_ptr             # <<<<<<<<<<<<<<
 *     # calculate min squared distance between each point in the two
 *     # lines.  Squared distance to delay doing the sqrt until after this
 */
  __pyx_v_t1_pt = __pyx_v_track1_ptr;

  /* "dipy/tracking/distances.pyx":672
 *     # lines.  Squared distance to delay doing the sqrt until after this
 *     # speed-critical loop
 *     for t1_pi from 0<= t1_pi < t1_len:             # <<<<<<<<<<<<<<
 *         # pointer to current point in track 2
 *         t2_pt = track2_ptr
 */
  __pyx_t_1 = __pyx_v_t1_len;
  for (__pyx_v_t1_pi = 0; __pyx_v_t1_pi < __pyx_t_1; __pyx_v_t1_pi++) {

    /* "dipy/tracking/distances.pyx":674
 *     for t1_pi from 0<= t1_pi < t1_len:
 *         # pointer to current point in track 2
 *         t2_pt = track2_ptr             # <<<<<<<<<<<<<<
 *         for t2_pi from 0<= t2_pi < t2_len:
 *             d0 = t1_pt[0] - t2_pt[0]
 */
    __pyx_v_t2_pt = __pyx_v_track2_ptr;

    /* "dipy/tracking/distances.pyx":675
 *         # pointer to current point in track 2
 *         t2_pt = track2_ptr
 *         for t2_pi from 0<= t2_pi < t2_len:             # <<<<<<<<<<<<<<
 *             d0 = t1_pt[0] - t2_pt[0]
 *             d1 = t1_pt[1] - t2_pt[1]
 */
    __pyx_t_2 = __pyx_v_t2_len;
    for (__pyx_v_t2_pi = 0; __pyx_v_t2_pi < __pyx_t_2; __pyx_v_t2_pi++) {

      /* "dipy/tracking/distances.pyx":676
 *         t2_pt = track2_ptr
 *         for t2_pi from 0<= t2_pi < t2_len:
 *             d0 = t1_pt[0] - t2_pt[0]             # <<<<<<<<<<<<<<
 *             d1 = t1_pt[1] - t2_pt[1]
 *             d2 = t1_pt[2] - t2_pt[2]
 */
      __pyx_v_d0 = ((__pyx_v_t1_pt[0]) - (__pyx_v_t2_pt[0]));

      /* "dipy/tracking/distances.pyx":677
 *         for t2_pi from 0<= t2_pi < t2_len:
 *             d0 = t1_pt[0] - t2_pt[0]
 *             d1 = t1_pt[1] - t2_pt[1]             # <<<<<<<<<<<<<<
 *             d2 = t1_pt[2] - t2_pt[2]
 *             delta2 = d0*d0 + d1*d1 + d2*d2
 */
      __pyx_v_d1 = ((__pyx_v_t1_pt[1]) - (__pyx_v_t2_pt[1]));

      /* "dipy/tracking/distances.pyx":678
 *             d0 = t1_pt[0] - t2_pt[0]
 *             d1 = t1_pt[1] - t2_pt[1]
 *             d2 = t1_pt[2] - t2_pt[2]             # <<<<<<<<<<<<<<
 *             delta2 = d0*d0 + d1*d1 + d2*d2
 *             if delta2 < min_t2t1[t2_pi]:
 */
      __pyx_v_d2 = ((__pyx_v_t1_pt[2]) - (__pyx_v_t2_pt[2]));

      /* "dipy/tracking/distances.pyx":679
 *             d1 = t1_pt[1] - t2_pt[1]
 *             d2 = t1_pt[2] - t2_pt[2]
 *             delta2 = d0*d0 + d1*d1 + d2*d2             # <<<<<<<<<<<<<<
 *             if delta2 < min_t2t1[t2_pi]:
 *                 min_t2t1[t2_pi]=delta2
 */
      __pyx_v_delta2 = (((__pyx_v_d0 * __pyx_v_d0) + (__pyx_v_d1 * __pyx_v_d1)) + (__pyx_v_d2 * __pyx_v_d2));

      /* "dipy/tracking/distances.pyx":680
 *             d2 = t1_pt[2] - t2_pt[2]
 *             delta2 = d0*d0 + d1*d1 + d2*d2
 *             if delta2 < min_t2t1[t2_pi]:             # <<<<<<<<<<<<<<
 *                 min_t2t1[t2_pi]=delta2
 *             if delta2 < min_t1t2[t1_pi]:
 */
      __pyx_t_3 = ((__pyx_v_delta2 < (__pyx_v_min_t2t1[__pyx_v_t2_pi])) != 0);
      if (__pyx_t_3) {

        /* "dipy/tracking/distances.pyx":681
 *             delta2 = d0*d0 + d1*d1 + d2*d2
 *             if delta2 < min_t2t1[t2_pi]:
 *                 min_t2t1[t2_pi]=delta2             # <<<<<<<<<<<<<<
 *             if delta2 < min_t1t2[t1_pi]:
 *                 min_t1t2[t1_pi]=delta2
 */
        (__pyx_v_min_t2t1[__pyx_v_t2_pi]) = __pyx_v_delta2;

        /* "dipy/tracking/distances.pyx":680
 *             d2 = t1_pt[2] - t2_pt[2]
 *             delta2 = d0*d0 + d1*d1 + d2*d2
 *             if delta2 < min_t2t1[t2_pi]:             # <<<<<<<<<<<<<<
 *                 min_t2t1[t2_pi]=delta2
 *             if delta2 < min_t1t2[t1_pi]:
 */
      }

      /* "dipy/tracking/distances.pyx":682
 *             if delta2 < min_t2t1[t2_pi]:
 *                 min_t2t1[t2_pi]=delta2
 *             if delta2 < min_t1t2[t1_pi]:             # <<<<<<<<<<<<<<
 *                 min_t1t2[t1_pi]=delta2
 *             t2_pt += 3 # to next point in track 2
 */
      __pyx_t_3 = ((__pyx_v_delta2 < (__pyx_v_min_t1t2[__pyx_v_t1_pi])) != 0);
      if (__pyx_t_3) {

        /* "dipy/tracking/distances.pyx":683
 *                 min_t2t1[t2_pi]=delta2
 *             if delta2 < min_t1t2[t1_pi]:
 *                 min_t1t2[t1_pi]=delta2             # <<<<<<<<<<<<<<
 *             t2_pt += 3 # to next point in track 2
 *         t1_pt += 3 # to next point in track 1
 */
        (__pyx_v_min_t1t2[__pyx_v_t1_pi]) = __pyx_v_delta2;

        /* "dipy/tracking/distances.pyx":682
 *             if delta2 < min_t2t1[t2_pi]:
 *                 min_t2t1[t2_pi]=delta2
 *             if delta2 < min_t1t2[t1_pi]:             # <<<<<<<<<<<<<<
 *                 min_t1t2[t1_pi]=delta2
 *             t2_pt += 3 # to next point in track 2
 */
      }

      /* "dipy/tracking/distances.pyx":684
 *             if delta2 < min_t1t2[t1_pi]:
 *                 min_t1t2[t1_pi]=delta2
 *             t2_pt += 3 # to next point in track 2             # <<<<<<<<<<<<<<
 *         t1_pt += 3 # to next point in track 1
 *     # sqrt to get Euclidean distance from squared distance
 */
      __pyx_v_t2_pt = (__pyx_v_t2_pt + 3);
    }

    /* "dipy/tracking/distances.pyx":685
 *                 min_t1t2[t1_pi]=delta2
 *             t2_pt += 3 # to next point in track 2
 *         t1_pt += 3 # to next point in track 1             # <<<<<<<<<<<<<<
 *     # sqrt to get Euclidean distance from squared distance
 *     for t1_pi from 0<= t1_pi < t1_len:
 */
    __pyx_v_t1_pt = (__pyx_v_t1_pt + 3);
  }

  /* "dipy/tracking/distances.pyx":687
 *         t1_pt += 3 # to next point in track 1
 *     # sqrt to get Euclidean distance from squared distance
 *     for t1_pi from 0<= t1_pi < t1_len:             # <<<<<<<<<<<<<<
 *         min_t1t2[t1_pi]=sqrt(min_t1t2[t1_pi])
 *     for t2_pi from 0<= t2_pi < t2_len:
 */
  __pyx_t_1 = __pyx_v_t1_len;
  for (__pyx_v_t1_pi = 0; __pyx_v_t1_pi < __pyx_t_1; __pyx_v_t1_pi++) {

    /* "dipy/tracking/distances.pyx":688
 *     # sqrt to get Euclidean distance from squared distance
 *     for t1_pi from 0<= t1_pi < t1_len:
 *         min_t1t2[t1_pi]=sqrt(min_t1t2[t1_pi])             # <<<<<<<<<<<<<<
 *     for t2_pi from 0<= t2_pi < t2_len:
 *         min_t2t1[t2_pi]=sqrt(min_t2t1[t2_pi])
 */
    (__pyx_v_min_t1t2[__pyx_v_t1_pi]) = sqrt((__pyx_v_min_t1t2[__pyx_v_t1_pi]));
  }

  /* "dipy/tracking/distances.pyx":689
 *     for t1_pi from 0<= t1_pi < t1_len:
 *         min_t1t2[t1_pi]=sqrt(min_t1t2[t1_pi])
 *     for t2_pi from 0<= t2_pi < t2_len:             # <<<<<<<<<<<<<<
 *         min_t2t1[t2_pi]=sqrt(min_t2t1[t2_pi])
 * 
 */
  __pyx_t_1 = __pyx_v_t2_len;
  for (__pyx_v_t2_pi = 0; __pyx_v_t2_pi < __pyx_t_1; __pyx_v_t2_pi++) {

    /* "dipy/tracking/distances.pyx":690
 *         min_t1t2[t1_pi]=sqrt(min_t1t2[t1_pi])
 *     for t2_pi from 0<= t2_pi < t2_len:
 *         min_t2t1[t2_pi]=sqrt(min_t2t1[t2_pi])             # <<<<<<<<<<<<<<
 * 
 * 
 */
    (__pyx_v_min_t2t1[__pyx_v_t2_pi]) = sqrt((__pyx_v_min_t2t1[__pyx_v_t2_pi]));
  }

  /* "dipy/tracking/distances.pyx":653
 * 
 * @cython.cdivision(True)
 * cdef inline void min_distances(size_t t1_len,             # <<<<<<<<<<<<<<
 *                                cnp.float32_t *track1_ptr,
 *                                size_t t2_len,
 */

  /* function exit code */
}

/* "dipy/tracking/distances.pyx":694
 * 
 * 
 * def mam_distances(xyz1,xyz2,metric='all'):             # <<<<<<<<<<<<<<
 *     ''' Min/Max/Mean Average Minimum Distance between tracks xyz1 and xyz2
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_23mam_distances(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_22mam_distances[] = " Min/Max/Mean Average Minimum Distance between tracks xyz1 and xyz2\n\n    Based on the metrics in Zhang, Correia, Laidlaw 2008\n    http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=4479455\n    which in turn are based on those of Corouge et al. 2004\n\n    Parameters\n    ----------\n    xyz1 : array, shape (N1,3), dtype float32\n    xyz2 : array, shape (N2,3), dtype float32\n       arrays representing x,y,z of the N1 and N2 points of two tracks\n    metrics : {'avg','min','max','all'}\n       Metric to calculate.  {'avg','min','max'} return a scalar. 'all'\n       returns a tuple\n\n    Returns\n    -------\n    avg_mcd : float\n       average_mean_closest_distance\n    min_mcd : float\n       minimum_mean_closest_distance\n    max_mcd : float\n       maximum_mean_closest_distance\n\n    Notes\n    -----\n    Algorithmic description\n\n    Lets say we have curves A and B.\n\n    For every point in A calculate the minimum distance from every point\n    in B stored in minAB\n\n    For every point in B calculate the minimum distance from every point\n    in A stored in minBA\n\n    find average of minAB stored as avg_minAB\n    find average of minBA stored as avg_minBA\n\n    if metric is 'avg' then return (avg_minAB + avg_minBA)/2.0\n    if metric is 'min' then return min(avg_minAB,avg_minBA)\n    if metric is 'max' then return max(avg_minAB,avg_minBA)\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_23mam_distances = {"mam_distances", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_23mam_distances, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_22mam_distances};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_23mam_distances(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_xyz1 = 0;
  PyObject *__pyx_v_xyz2 = 0;
  PyObject *__pyx_v_metric = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("mam_distances (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_xyz1,&__pyx_n_s_xyz2,&__pyx_n_s_metric,0};
    PyObject* values[3] = {0,0,0};
    values[2] = ((PyObject *)__pyx_n_s_all);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_xyz1)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_xyz2)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("mam_distances", 0, 2, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_metric);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "mam_distances") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  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_xyz1 = values[0];
    __pyx_v_xyz2 = values[1];
    __pyx_v_metric = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("mam_distances", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.mam_distances", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_22mam_distances(__pyx_self, __pyx_v_xyz1, __pyx_v_xyz2, __pyx_v_metric);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_22mam_distances(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_xyz1, PyObject *__pyx_v_xyz2, PyObject *__pyx_v_metric) {
  PyArrayObject *__pyx_v_track1 = 0;
  PyArrayObject *__pyx_v_track2 = 0;
  size_t __pyx_v_t1_len;
  size_t __pyx_v_t2_len;
  __pyx_t_5numpy_float32_t *__pyx_v_min_t2t1;
  __pyx_t_5numpy_float32_t *__pyx_v_min_t1t2;
  PyArrayObject *__pyx_v_distances_buffer = 0;
  size_t __pyx_v_t1_pi;
  size_t __pyx_v_t2_pi;
  __pyx_t_5numpy_float32_t __pyx_v_mean_t2t1;
  __pyx_t_5numpy_float32_t __pyx_v_mean_t1t2;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_distances_buffer;
  __Pyx_Buffer __pyx_pybuffer_distances_buffer;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_track1;
  __Pyx_Buffer __pyx_pybuffer_track1;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_track2;
  __Pyx_Buffer __pyx_pybuffer_track2;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyArrayObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyArrayObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyArrayObject *__pyx_t_12 = NULL;
  size_t __pyx_t_13;
  int __pyx_t_14;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("mam_distances", 0);
  __pyx_pybuffer_track1.pybuffer.buf = NULL;
  __pyx_pybuffer_track1.refcount = 0;
  __pyx_pybuffernd_track1.data = NULL;
  __pyx_pybuffernd_track1.rcbuffer = &__pyx_pybuffer_track1;
  __pyx_pybuffer_track2.pybuffer.buf = NULL;
  __pyx_pybuffer_track2.refcount = 0;
  __pyx_pybuffernd_track2.data = NULL;
  __pyx_pybuffernd_track2.rcbuffer = &__pyx_pybuffer_track2;
  __pyx_pybuffer_distances_buffer.pybuffer.buf = NULL;
  __pyx_pybuffer_distances_buffer.refcount = 0;
  __pyx_pybuffernd_distances_buffer.data = NULL;
  __pyx_pybuffernd_distances_buffer.rcbuffer = &__pyx_pybuffer_distances_buffer;

  /* "dipy/tracking/distances.pyx":742
 *         cnp.ndarray[cnp.float32_t, ndim=2] track2
 *         size_t t1_len, t2_len
 *     track1 = np.ascontiguousarray(xyz1, dtype=f32_dt)             # <<<<<<<<<<<<<<
 *     t1_len = track1.shape[0]
 *     track2 = np.ascontiguousarray(xyz2, dtype=f32_dt)
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_xyz1);
  __Pyx_GIVEREF(__pyx_v_xyz1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_xyz1);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track1.rcbuffer->pybuffer);
    __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track1.rcbuffer->pybuffer, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_6 < 0)) {
      PyErr_Fetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track1.rcbuffer->pybuffer, (PyObject*)__pyx_v_track1, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_7, __pyx_t_8, __pyx_t_9);
      }
    }
    __pyx_pybuffernd_track1.diminfo[0].strides = __pyx_pybuffernd_track1.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_track1.diminfo[0].shape = __pyx_pybuffernd_track1.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_track1.diminfo[1].strides = __pyx_pybuffernd_track1.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_track1.diminfo[1].shape = __pyx_pybuffernd_track1.rcbuffer->pybuffer.shape[1];
    if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 742; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_5 = 0;
  __pyx_v_track1 = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "dipy/tracking/distances.pyx":743
 *         size_t t1_len, t2_len
 *     track1 = np.ascontiguousarray(xyz1, dtype=f32_dt)
 *     t1_len = track1.shape[0]             # <<<<<<<<<<<<<<
 *     track2 = np.ascontiguousarray(xyz2, dtype=f32_dt)
 *     t2_len = track2.shape[0]
 */
  __pyx_v_t1_len = (__pyx_v_track1->dimensions[0]);

  /* "dipy/tracking/distances.pyx":744
 *     track1 = np.ascontiguousarray(xyz1, dtype=f32_dt)
 *     t1_len = track1.shape[0]
 *     track2 = np.ascontiguousarray(xyz2, dtype=f32_dt)             # <<<<<<<<<<<<<<
 *     t2_len = track2.shape[0]
 *     # preallocate buffer array for track distance calculations
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_xyz2);
  __Pyx_GIVEREF(__pyx_v_xyz2);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_xyz2);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_10 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track2.rcbuffer->pybuffer);
    __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track2.rcbuffer->pybuffer, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_6 < 0)) {
      PyErr_Fetch(&__pyx_t_9, &__pyx_t_8, &__pyx_t_7);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track2.rcbuffer->pybuffer, (PyObject*)__pyx_v_track2, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_9, __pyx_t_8, __pyx_t_7);
      }
    }
    __pyx_pybuffernd_track2.diminfo[0].strides = __pyx_pybuffernd_track2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_track2.diminfo[0].shape = __pyx_pybuffernd_track2.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_track2.diminfo[1].strides = __pyx_pybuffernd_track2.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_track2.diminfo[1].shape = __pyx_pybuffernd_track2.rcbuffer->pybuffer.shape[1];
    if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_10 = 0;
  __pyx_v_track2 = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "dipy/tracking/distances.pyx":745
 *     t1_len = track1.shape[0]
 *     track2 = np.ascontiguousarray(xyz2, dtype=f32_dt)
 *     t2_len = track2.shape[0]             # <<<<<<<<<<<<<<
 *     # preallocate buffer array for track distance calculations
 *     cdef:
 */
  __pyx_v_t2_len = (__pyx_v_track2->dimensions[0]);

  /* "dipy/tracking/distances.pyx":750
 *         cnp.float32_t *min_t2t1, *min_t1t2
 *         cnp.ndarray [cnp.float32_t, ndim=1] distances_buffer
 *     distances_buffer = np.zeros((t1_len + t2_len,), dtype=np.float32)             # <<<<<<<<<<<<<<
 *     min_t2t1 = <cnp.float32_t *> distances_buffer.data
 *     min_t1t2 = min_t2t1 + t2_len
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_FromSize_t((__pyx_v_t1_len + __pyx_v_t2_len)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __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 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float32); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_11) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_12 = ((PyArrayObject *)__pyx_t_11);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer);
    __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_6 < 0)) {
      PyErr_Fetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer, (PyObject*)__pyx_v_distances_buffer, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_7, __pyx_t_8, __pyx_t_9);
      }
    }
    __pyx_pybuffernd_distances_buffer.diminfo[0].strides = __pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_distances_buffer.diminfo[0].shape = __pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_12 = 0;
  __pyx_v_distances_buffer = ((PyArrayObject *)__pyx_t_11);
  __pyx_t_11 = 0;

  /* "dipy/tracking/distances.pyx":751
 *         cnp.ndarray [cnp.float32_t, ndim=1] distances_buffer
 *     distances_buffer = np.zeros((t1_len + t2_len,), dtype=np.float32)
 *     min_t2t1 = <cnp.float32_t *> distances_buffer.data             # <<<<<<<<<<<<<<
 *     min_t1t2 = min_t2t1 + t2_len
 *     min_distances(t1_len, <cnp.float32_t *>track1.data,
 */
  __pyx_v_min_t2t1 = ((__pyx_t_5numpy_float32_t *)__pyx_v_distances_buffer->data);

  /* "dipy/tracking/distances.pyx":752
 *     distances_buffer = np.zeros((t1_len + t2_len,), dtype=np.float32)
 *     min_t2t1 = <cnp.float32_t *> distances_buffer.data
 *     min_t1t2 = min_t2t1 + t2_len             # <<<<<<<<<<<<<<
 *     min_distances(t1_len, <cnp.float32_t *>track1.data,
 *                   t2_len, <cnp.float32_t *>track2.data,
 */
  __pyx_v_min_t1t2 = (__pyx_v_min_t2t1 + __pyx_v_t2_len);

  /* "dipy/tracking/distances.pyx":753
 *     min_t2t1 = <cnp.float32_t *> distances_buffer.data
 *     min_t1t2 = min_t2t1 + t2_len
 *     min_distances(t1_len, <cnp.float32_t *>track1.data,             # <<<<<<<<<<<<<<
 *                   t2_len, <cnp.float32_t *>track2.data,
 *                   min_t2t1,
 */
  __pyx_f_4dipy_8tracking_9distances_min_distances(__pyx_v_t1_len, ((__pyx_t_5numpy_float32_t *)__pyx_v_track1->data), __pyx_v_t2_len, ((__pyx_t_5numpy_float32_t *)__pyx_v_track2->data), __pyx_v_min_t2t1, __pyx_v_min_t1t2);

  /* "dipy/tracking/distances.pyx":759
 *     cdef:
 *         size_t t1_pi, t2_pi
 *         cnp.float32_t mean_t2t1 = 0, mean_t1t2 = 0             # <<<<<<<<<<<<<<
 *     for t1_pi from 0<= t1_pi < t1_len:
 *         mean_t1t2+=min_t1t2[t1_pi]
 */
  __pyx_v_mean_t2t1 = 0.0;
  __pyx_v_mean_t1t2 = 0.0;

  /* "dipy/tracking/distances.pyx":760
 *         size_t t1_pi, t2_pi
 *         cnp.float32_t mean_t2t1 = 0, mean_t1t2 = 0
 *     for t1_pi from 0<= t1_pi < t1_len:             # <<<<<<<<<<<<<<
 *         mean_t1t2+=min_t1t2[t1_pi]
 *     mean_t1t2=mean_t1t2/t1_len
 */
  __pyx_t_13 = __pyx_v_t1_len;
  for (__pyx_v_t1_pi = 0; __pyx_v_t1_pi < __pyx_t_13; __pyx_v_t1_pi++) {

    /* "dipy/tracking/distances.pyx":761
 *         cnp.float32_t mean_t2t1 = 0, mean_t1t2 = 0
 *     for t1_pi from 0<= t1_pi < t1_len:
 *         mean_t1t2+=min_t1t2[t1_pi]             # <<<<<<<<<<<<<<
 *     mean_t1t2=mean_t1t2/t1_len
 *     for t2_pi from 0<= t2_pi < t2_len:
 */
    __pyx_v_mean_t1t2 = (__pyx_v_mean_t1t2 + (__pyx_v_min_t1t2[__pyx_v_t1_pi]));
  }

  /* "dipy/tracking/distances.pyx":762
 *     for t1_pi from 0<= t1_pi < t1_len:
 *         mean_t1t2+=min_t1t2[t1_pi]
 *     mean_t1t2=mean_t1t2/t1_len             # <<<<<<<<<<<<<<
 *     for t2_pi from 0<= t2_pi < t2_len:
 *         mean_t2t1+=min_t2t1[t2_pi]
 */
  if (unlikely(__pyx_v_t1_len == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 762; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_v_mean_t1t2 = (__pyx_v_mean_t1t2 / __pyx_v_t1_len);

  /* "dipy/tracking/distances.pyx":763
 *         mean_t1t2+=min_t1t2[t1_pi]
 *     mean_t1t2=mean_t1t2/t1_len
 *     for t2_pi from 0<= t2_pi < t2_len:             # <<<<<<<<<<<<<<
 *         mean_t2t1+=min_t2t1[t2_pi]
 *     mean_t2t1=mean_t2t1/t2_len
 */
  __pyx_t_13 = __pyx_v_t2_len;
  for (__pyx_v_t2_pi = 0; __pyx_v_t2_pi < __pyx_t_13; __pyx_v_t2_pi++) {

    /* "dipy/tracking/distances.pyx":764
 *     mean_t1t2=mean_t1t2/t1_len
 *     for t2_pi from 0<= t2_pi < t2_len:
 *         mean_t2t1+=min_t2t1[t2_pi]             # <<<<<<<<<<<<<<
 *     mean_t2t1=mean_t2t1/t2_len
 *     if metric=='all':
 */
    __pyx_v_mean_t2t1 = (__pyx_v_mean_t2t1 + (__pyx_v_min_t2t1[__pyx_v_t2_pi]));
  }

  /* "dipy/tracking/distances.pyx":765
 *     for t2_pi from 0<= t2_pi < t2_len:
 *         mean_t2t1+=min_t2t1[t2_pi]
 *     mean_t2t1=mean_t2t1/t2_len             # <<<<<<<<<<<<<<
 *     if metric=='all':
 *         return ((mean_t2t1+mean_t1t2)/2.0,
 */
  if (unlikely(__pyx_v_t2_len == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 765; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_v_mean_t2t1 = (__pyx_v_mean_t2t1 / __pyx_v_t2_len);

  /* "dipy/tracking/distances.pyx":766
 *         mean_t2t1+=min_t2t1[t2_pi]
 *     mean_t2t1=mean_t2t1/t2_len
 *     if metric=='all':             # <<<<<<<<<<<<<<
 *         return ((mean_t2t1+mean_t1t2)/2.0,
 *                 np.min((mean_t2t1,mean_t1t2)),
 */
  __pyx_t_14 = (__Pyx_PyString_Equals(__pyx_v_metric, __pyx_n_s_all, Py_EQ)); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 766; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_14) {

    /* "dipy/tracking/distances.pyx":767
 *     mean_t2t1=mean_t2t1/t2_len
 *     if metric=='all':
 *         return ((mean_t2t1+mean_t1t2)/2.0,             # <<<<<<<<<<<<<<
 *                 np.min((mean_t2t1,mean_t1t2)),
 *                 np.max((mean_t2t1,mean_t1t2)))
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_11 = PyFloat_FromDouble(((__pyx_v_mean_t2t1 + __pyx_v_mean_t1t2) / 2.0)); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 767; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);

    /* "dipy/tracking/distances.pyx":768
 *     if metric=='all':
 *         return ((mean_t2t1+mean_t1t2)/2.0,
 *                 np.min((mean_t2t1,mean_t1t2)),             # <<<<<<<<<<<<<<
 *                 np.max((mean_t2t1,mean_t1t2)))
 *     elif metric=='avg':
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_min); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyFloat_FromDouble(__pyx_v_mean_t2t1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyFloat_FromDouble(__pyx_v_mean_t1t2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_15 = PyTuple_New(2); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_3);
    __pyx_t_2 = 0;
    __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && 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);
      }
    }
    if (!__pyx_t_3) {
      __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_15); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_GOTREF(__pyx_t_4);
    } else {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_GIVEREF(__pyx_t_15);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_15);
      __pyx_t_15 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 768; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "dipy/tracking/distances.pyx":769
 *         return ((mean_t2t1+mean_t1t2)/2.0,
 *                 np.min((mean_t2t1,mean_t1t2)),
 *                 np.max((mean_t2t1,mean_t1t2)))             # <<<<<<<<<<<<<<
 *     elif metric=='avg':
 *         return (mean_t2t1+mean_t1t2)/2.0
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_max); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyFloat_FromDouble(__pyx_v_mean_t2t1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyFloat_FromDouble(__pyx_v_mean_t1t2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_16 = PyTuple_New(2); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_t_3);
    __pyx_t_2 = 0;
    __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_15))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_15);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_15, function);
      }
    }
    if (!__pyx_t_3) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_16); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_GIVEREF(__pyx_t_16);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_16);
      __pyx_t_16 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;

    /* "dipy/tracking/distances.pyx":767
 *     mean_t2t1=mean_t2t1/t2_len
 *     if metric=='all':
 *         return ((mean_t2t1+mean_t1t2)/2.0,             # <<<<<<<<<<<<<<
 *                 np.min((mean_t2t1,mean_t1t2)),
 *                 np.max((mean_t2t1,mean_t1t2)))
 */
    __pyx_t_15 = PyTuple_New(3); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 767; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_15, 1, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_15, 2, __pyx_t_1);
    __pyx_t_11 = 0;
    __pyx_t_4 = 0;
    __pyx_t_1 = 0;
    __pyx_r = __pyx_t_15;
    __pyx_t_15 = 0;
    goto __pyx_L0;

    /* "dipy/tracking/distances.pyx":766
 *         mean_t2t1+=min_t2t1[t2_pi]
 *     mean_t2t1=mean_t2t1/t2_len
 *     if metric=='all':             # <<<<<<<<<<<<<<
 *         return ((mean_t2t1+mean_t1t2)/2.0,
 *                 np.min((mean_t2t1,mean_t1t2)),
 */
  }

  /* "dipy/tracking/distances.pyx":770
 *                 np.min((mean_t2t1,mean_t1t2)),
 *                 np.max((mean_t2t1,mean_t1t2)))
 *     elif metric=='avg':             # <<<<<<<<<<<<<<
 *         return (mean_t2t1+mean_t1t2)/2.0
 *     elif metric=='min':
 */
  __pyx_t_14 = (__Pyx_PyString_Equals(__pyx_v_metric, __pyx_n_s_avg, Py_EQ)); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 770; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_14) {

    /* "dipy/tracking/distances.pyx":771
 *                 np.max((mean_t2t1,mean_t1t2)))
 *     elif metric=='avg':
 *         return (mean_t2t1+mean_t1t2)/2.0             # <<<<<<<<<<<<<<
 *     elif metric=='min':
 *         return np.min((mean_t2t1,mean_t1t2))
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_15 = PyFloat_FromDouble(((__pyx_v_mean_t2t1 + __pyx_v_mean_t1t2) / 2.0)); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_r = __pyx_t_15;
    __pyx_t_15 = 0;
    goto __pyx_L0;

    /* "dipy/tracking/distances.pyx":770
 *                 np.min((mean_t2t1,mean_t1t2)),
 *                 np.max((mean_t2t1,mean_t1t2)))
 *     elif metric=='avg':             # <<<<<<<<<<<<<<
 *         return (mean_t2t1+mean_t1t2)/2.0
 *     elif metric=='min':
 */
  }

  /* "dipy/tracking/distances.pyx":772
 *     elif metric=='avg':
 *         return (mean_t2t1+mean_t1t2)/2.0
 *     elif metric=='min':             # <<<<<<<<<<<<<<
 *         return np.min((mean_t2t1,mean_t1t2))
 *     elif metric =='max':
 */
  __pyx_t_14 = (__Pyx_PyString_Equals(__pyx_v_metric, __pyx_n_s_min, Py_EQ)); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 772; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_14) {

    /* "dipy/tracking/distances.pyx":773
 *         return (mean_t2t1+mean_t1t2)/2.0
 *     elif metric=='min':
 *         return np.min((mean_t2t1,mean_t1t2))             # <<<<<<<<<<<<<<
 *     elif metric =='max':
 *         return np.max((mean_t2t1,mean_t1t2))
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_min); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyFloat_FromDouble(__pyx_v_mean_t2t1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_11 = PyFloat_FromDouble(__pyx_v_mean_t1t2); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_11);
    __pyx_t_1 = 0;
    __pyx_t_11 = 0;
    __pyx_t_11 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_11)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_11);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_11) {
      __pyx_t_15 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_15);
    } else {
      __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_11); __pyx_t_11 = NULL;
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_15;
    __pyx_t_15 = 0;
    goto __pyx_L0;

    /* "dipy/tracking/distances.pyx":772
 *     elif metric=='avg':
 *         return (mean_t2t1+mean_t1t2)/2.0
 *     elif metric=='min':             # <<<<<<<<<<<<<<
 *         return np.min((mean_t2t1,mean_t1t2))
 *     elif metric =='max':
 */
  }

  /* "dipy/tracking/distances.pyx":774
 *     elif metric=='min':
 *         return np.min((mean_t2t1,mean_t1t2))
 *     elif metric =='max':             # <<<<<<<<<<<<<<
 *         return np.max((mean_t2t1,mean_t1t2))
 *     else :
 */
  __pyx_t_14 = (__Pyx_PyString_Equals(__pyx_v_metric, __pyx_n_s_max, Py_EQ)); if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 774; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (__pyx_t_14) {

    /* "dipy/tracking/distances.pyx":775
 *         return np.min((mean_t2t1,mean_t1t2))
 *     elif metric =='max':
 *         return np.max((mean_t2t1,mean_t1t2))             # <<<<<<<<<<<<<<
 *     else :
 *         ValueError('Wrong argument for metric')
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_max); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyFloat_FromDouble(__pyx_v_mean_t2t1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = PyFloat_FromDouble(__pyx_v_mean_t1t2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_2);
    __pyx_t_4 = 0;
    __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    if (!__pyx_t_2) {
      __pyx_t_15 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_11); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_GOTREF(__pyx_t_15);
    } else {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL;
      __Pyx_GIVEREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_11);
      __pyx_t_11 = 0;
      __pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 775; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_r = __pyx_t_15;
    __pyx_t_15 = 0;
    goto __pyx_L0;

    /* "dipy/tracking/distances.pyx":774
 *     elif metric=='min':
 *         return np.min((mean_t2t1,mean_t1t2))
 *     elif metric =='max':             # <<<<<<<<<<<<<<
 *         return np.max((mean_t2t1,mean_t1t2))
 *     else :
 */
  }

  /* "dipy/tracking/distances.pyx":777
 *         return np.max((mean_t2t1,mean_t1t2))
 *     else :
 *         ValueError('Wrong argument for metric')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __pyx_t_15 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  }

  /* "dipy/tracking/distances.pyx":694
 * 
 * 
 * def mam_distances(xyz1,xyz2,metric='all'):             # <<<<<<<<<<<<<<
 *     ''' Min/Max/Mean Average Minimum Distance between tracks xyz1 and xyz2
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __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_11);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_16);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track1.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track2.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.mam_distances", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track1.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track2.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_track1);
  __Pyx_XDECREF((PyObject *)__pyx_v_track2);
  __Pyx_XDECREF((PyObject *)__pyx_v_distances_buffer);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":780
 * 
 * 
 * def minimum_closest_distance(xyz1,xyz2):             # <<<<<<<<<<<<<<
 *     ''' Find the minimum distance between two curves xyz1, xyz2
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_25minimum_closest_distance(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_24minimum_closest_distance[] = " Find the minimum distance between two curves xyz1, xyz2\n\n    Parameters\n    ----------\n    xyz1 : array, shape (N1,3), dtype float32\n    xyz2 : array, shape (N2,3), dtype float32\n        arrays representing x,y,z of the N1 and N2 points  of two tracks\n\n    Returns\n    -------\n    md : minimum distance\n\n    Notes\n    -----\n    Algorithmic description\n\n    Lets say we have curves A and B\n\n    for every point in A calculate the minimum distance from every point in B stored in minAB\n    for every point in B calculate the minimum distance from every point in A stored in minBA\n    find min of minAB stored in min_minAB\n    find min of minBA stored in min_minBA\n\n    Then return (min_minAB + min_minBA)/2.0\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_25minimum_closest_distance = {"minimum_closest_distance", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_25minimum_closest_distance, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_24minimum_closest_distance};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_25minimum_closest_distance(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_xyz1 = 0;
  PyObject *__pyx_v_xyz2 = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("minimum_closest_distance (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_xyz1,&__pyx_n_s_xyz2,0};
    PyObject* values[2] = {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  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_xyz1)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_xyz2)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("minimum_closest_distance", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 780; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "minimum_closest_distance") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 780; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_xyz1 = values[0];
    __pyx_v_xyz2 = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("minimum_closest_distance", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 780; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.minimum_closest_distance", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_24minimum_closest_distance(__pyx_self, __pyx_v_xyz1, __pyx_v_xyz2);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_24minimum_closest_distance(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_xyz1, PyObject *__pyx_v_xyz2) {
  PyArrayObject *__pyx_v_track1 = 0;
  PyArrayObject *__pyx_v_track2 = 0;
  size_t __pyx_v_t1_len;
  size_t __pyx_v_t2_len;
  __pyx_t_5numpy_float32_t *__pyx_v_min_t2t1;
  __pyx_t_5numpy_float32_t *__pyx_v_min_t1t2;
  PyArrayObject *__pyx_v_distances_buffer = 0;
  size_t __pyx_v_t1_pi;
  size_t __pyx_v_t2_pi;
  double __pyx_v_min_min_t2t1;
  double __pyx_v_min_min_t1t2;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_distances_buffer;
  __Pyx_Buffer __pyx_pybuffer_distances_buffer;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_track1;
  __Pyx_Buffer __pyx_pybuffer_track1;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_track2;
  __Pyx_Buffer __pyx_pybuffer_track2;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyArrayObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyArrayObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyArrayObject *__pyx_t_12 = NULL;
  size_t __pyx_t_13;
  size_t __pyx_t_14;
  int __pyx_t_15;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("minimum_closest_distance", 0);
  __pyx_pybuffer_track1.pybuffer.buf = NULL;
  __pyx_pybuffer_track1.refcount = 0;
  __pyx_pybuffernd_track1.data = NULL;
  __pyx_pybuffernd_track1.rcbuffer = &__pyx_pybuffer_track1;
  __pyx_pybuffer_track2.pybuffer.buf = NULL;
  __pyx_pybuffer_track2.refcount = 0;
  __pyx_pybuffernd_track2.data = NULL;
  __pyx_pybuffernd_track2.rcbuffer = &__pyx_pybuffer_track2;
  __pyx_pybuffer_distances_buffer.pybuffer.buf = NULL;
  __pyx_pybuffer_distances_buffer.refcount = 0;
  __pyx_pybuffernd_distances_buffer.data = NULL;
  __pyx_pybuffernd_distances_buffer.rcbuffer = &__pyx_pybuffer_distances_buffer;

  /* "dipy/tracking/distances.pyx":810
 *         cnp.ndarray[cnp.float32_t, ndim=2] track2
 *         size_t t1_len, t2_len
 *     track1 = np.ascontiguousarray(xyz1, dtype=f32_dt)             # <<<<<<<<<<<<<<
 *     t1_len = track1.shape[0]
 *     track2 = np.ascontiguousarray(xyz2, dtype=f32_dt)
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_xyz1);
  __Pyx_GIVEREF(__pyx_v_xyz1);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_xyz1);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track1.rcbuffer->pybuffer);
    __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track1.rcbuffer->pybuffer, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_6 < 0)) {
      PyErr_Fetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track1.rcbuffer->pybuffer, (PyObject*)__pyx_v_track1, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_7, __pyx_t_8, __pyx_t_9);
      }
    }
    __pyx_pybuffernd_track1.diminfo[0].strides = __pyx_pybuffernd_track1.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_track1.diminfo[0].shape = __pyx_pybuffernd_track1.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_track1.diminfo[1].strides = __pyx_pybuffernd_track1.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_track1.diminfo[1].shape = __pyx_pybuffernd_track1.rcbuffer->pybuffer.shape[1];
    if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 810; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_5 = 0;
  __pyx_v_track1 = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "dipy/tracking/distances.pyx":811
 *         size_t t1_len, t2_len
 *     track1 = np.ascontiguousarray(xyz1, dtype=f32_dt)
 *     t1_len = track1.shape[0]             # <<<<<<<<<<<<<<
 *     track2 = np.ascontiguousarray(xyz2, dtype=f32_dt)
 *     t2_len = track2.shape[0]
 */
  __pyx_v_t1_len = (__pyx_v_track1->dimensions[0]);

  /* "dipy/tracking/distances.pyx":812
 *     track1 = np.ascontiguousarray(xyz1, dtype=f32_dt)
 *     t1_len = track1.shape[0]
 *     track2 = np.ascontiguousarray(xyz2, dtype=f32_dt)             # <<<<<<<<<<<<<<
 *     t2_len = track2.shape[0]
 *     # preallocate buffer array for track distance calculations
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_xyz2);
  __Pyx_GIVEREF(__pyx_v_xyz2);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_xyz2);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_10 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track2.rcbuffer->pybuffer);
    __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track2.rcbuffer->pybuffer, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_6 < 0)) {
      PyErr_Fetch(&__pyx_t_9, &__pyx_t_8, &__pyx_t_7);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track2.rcbuffer->pybuffer, (PyObject*)__pyx_v_track2, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_9, __pyx_t_8, __pyx_t_7);
      }
    }
    __pyx_pybuffernd_track2.diminfo[0].strides = __pyx_pybuffernd_track2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_track2.diminfo[0].shape = __pyx_pybuffernd_track2.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_track2.diminfo[1].strides = __pyx_pybuffernd_track2.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_track2.diminfo[1].shape = __pyx_pybuffernd_track2.rcbuffer->pybuffer.shape[1];
    if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 812; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_10 = 0;
  __pyx_v_track2 = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "dipy/tracking/distances.pyx":813
 *     t1_len = track1.shape[0]
 *     track2 = np.ascontiguousarray(xyz2, dtype=f32_dt)
 *     t2_len = track2.shape[0]             # <<<<<<<<<<<<<<
 *     # preallocate buffer array for track distance calculations
 *     cdef:
 */
  __pyx_v_t2_len = (__pyx_v_track2->dimensions[0]);

  /* "dipy/tracking/distances.pyx":818
 *         cnp.float32_t *min_t2t1, *min_t1t2
 *         cnp.ndarray [cnp.float32_t, ndim=1] distances_buffer
 *     distances_buffer = np.zeros((t1_len + t2_len,), dtype=np.float32)             # <<<<<<<<<<<<<<
 *     min_t2t1 = <cnp.float32_t *> distances_buffer.data
 *     min_t1t2 = min_t2t1 + t2_len
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyInt_FromSize_t((__pyx_v_t1_len + __pyx_v_t2_len)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __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 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float32); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_11) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_12 = ((PyArrayObject *)__pyx_t_11);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer);
    __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer, (PyObject*)__pyx_t_12, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_6 < 0)) {
      PyErr_Fetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer, (PyObject*)__pyx_v_distances_buffer, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_7, __pyx_t_8, __pyx_t_9);
      }
    }
    __pyx_pybuffernd_distances_buffer.diminfo[0].strides = __pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_distances_buffer.diminfo[0].shape = __pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 818; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_12 = 0;
  __pyx_v_distances_buffer = ((PyArrayObject *)__pyx_t_11);
  __pyx_t_11 = 0;

  /* "dipy/tracking/distances.pyx":819
 *         cnp.ndarray [cnp.float32_t, ndim=1] distances_buffer
 *     distances_buffer = np.zeros((t1_len + t2_len,), dtype=np.float32)
 *     min_t2t1 = <cnp.float32_t *> distances_buffer.data             # <<<<<<<<<<<<<<
 *     min_t1t2 = min_t2t1 + t2_len
 *     min_distances(t1_len, <cnp.float32_t *>track1.data,
 */
  __pyx_v_min_t2t1 = ((__pyx_t_5numpy_float32_t *)__pyx_v_distances_buffer->data);

  /* "dipy/tracking/distances.pyx":820
 *     distances_buffer = np.zeros((t1_len + t2_len,), dtype=np.float32)
 *     min_t2t1 = <cnp.float32_t *> distances_buffer.data
 *     min_t1t2 = min_t2t1 + t2_len             # <<<<<<<<<<<<<<
 *     min_distances(t1_len, <cnp.float32_t *>track1.data,
 *                   t2_len, <cnp.float32_t *>track2.data,
 */
  __pyx_v_min_t1t2 = (__pyx_v_min_t2t1 + __pyx_v_t2_len);

  /* "dipy/tracking/distances.pyx":821
 *     min_t2t1 = <cnp.float32_t *> distances_buffer.data
 *     min_t1t2 = min_t2t1 + t2_len
 *     min_distances(t1_len, <cnp.float32_t *>track1.data,             # <<<<<<<<<<<<<<
 *                   t2_len, <cnp.float32_t *>track2.data,
 *                   min_t2t1,
 */
  __pyx_f_4dipy_8tracking_9distances_min_distances(__pyx_v_t1_len, ((__pyx_t_5numpy_float32_t *)__pyx_v_track1->data), __pyx_v_t2_len, ((__pyx_t_5numpy_float32_t *)__pyx_v_track2->data), __pyx_v_min_t2t1, __pyx_v_min_t1t2);

  /* "dipy/tracking/distances.pyx":827
 *     cdef:
 *         size_t t1_pi, t2_pi
 *         double min_min_t2t1 = inf             # <<<<<<<<<<<<<<
 *         double min_min_t1t2 = inf
 *     for t1_pi in range(t1_len):
 */
  __pyx_v_min_min_t2t1 = __pyx_v_4dipy_8tracking_9distances_inf;

  /* "dipy/tracking/distances.pyx":828
 *         size_t t1_pi, t2_pi
 *         double min_min_t2t1 = inf
 *         double min_min_t1t2 = inf             # <<<<<<<<<<<<<<
 *     for t1_pi in range(t1_len):
 *         if min_min_t1t2 > min_t1t2[t1_pi]:
 */
  __pyx_v_min_min_t1t2 = __pyx_v_4dipy_8tracking_9distances_inf;

  /* "dipy/tracking/distances.pyx":829
 *         double min_min_t2t1 = inf
 *         double min_min_t1t2 = inf
 *     for t1_pi in range(t1_len):             # <<<<<<<<<<<<<<
 *         if min_min_t1t2 > min_t1t2[t1_pi]:
 *             min_min_t1t2 = min_t1t2[t1_pi]
 */
  __pyx_t_13 = __pyx_v_t1_len;
  for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
    __pyx_v_t1_pi = __pyx_t_14;

    /* "dipy/tracking/distances.pyx":830
 *         double min_min_t1t2 = inf
 *     for t1_pi in range(t1_len):
 *         if min_min_t1t2 > min_t1t2[t1_pi]:             # <<<<<<<<<<<<<<
 *             min_min_t1t2 = min_t1t2[t1_pi]
 *     for t2_pi in range(t2_len):
 */
    __pyx_t_15 = ((__pyx_v_min_min_t1t2 > (__pyx_v_min_t1t2[__pyx_v_t1_pi])) != 0);
    if (__pyx_t_15) {

      /* "dipy/tracking/distances.pyx":831
 *     for t1_pi in range(t1_len):
 *         if min_min_t1t2 > min_t1t2[t1_pi]:
 *             min_min_t1t2 = min_t1t2[t1_pi]             # <<<<<<<<<<<<<<
 *     for t2_pi in range(t2_len):
 *         if min_min_t2t1 > min_t2t1[t2_pi]:
 */
      __pyx_v_min_min_t1t2 = (__pyx_v_min_t1t2[__pyx_v_t1_pi]);

      /* "dipy/tracking/distances.pyx":830
 *         double min_min_t1t2 = inf
 *     for t1_pi in range(t1_len):
 *         if min_min_t1t2 > min_t1t2[t1_pi]:             # <<<<<<<<<<<<<<
 *             min_min_t1t2 = min_t1t2[t1_pi]
 *     for t2_pi in range(t2_len):
 */
    }
  }

  /* "dipy/tracking/distances.pyx":832
 *         if min_min_t1t2 > min_t1t2[t1_pi]:
 *             min_min_t1t2 = min_t1t2[t1_pi]
 *     for t2_pi in range(t2_len):             # <<<<<<<<<<<<<<
 *         if min_min_t2t1 > min_t2t1[t2_pi]:
 *             min_min_t2t1 = min_t2t1[t2_pi]
 */
  __pyx_t_13 = __pyx_v_t2_len;
  for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
    __pyx_v_t2_pi = __pyx_t_14;

    /* "dipy/tracking/distances.pyx":833
 *             min_min_t1t2 = min_t1t2[t1_pi]
 *     for t2_pi in range(t2_len):
 *         if min_min_t2t1 > min_t2t1[t2_pi]:             # <<<<<<<<<<<<<<
 *             min_min_t2t1 = min_t2t1[t2_pi]
 *     return (min_min_t1t2+min_min_t2t1)/2.0
 */
    __pyx_t_15 = ((__pyx_v_min_min_t2t1 > (__pyx_v_min_t2t1[__pyx_v_t2_pi])) != 0);
    if (__pyx_t_15) {

      /* "dipy/tracking/distances.pyx":834
 *     for t2_pi in range(t2_len):
 *         if min_min_t2t1 > min_t2t1[t2_pi]:
 *             min_min_t2t1 = min_t2t1[t2_pi]             # <<<<<<<<<<<<<<
 *     return (min_min_t1t2+min_min_t2t1)/2.0
 * 
 */
      __pyx_v_min_min_t2t1 = (__pyx_v_min_t2t1[__pyx_v_t2_pi]);

      /* "dipy/tracking/distances.pyx":833
 *             min_min_t1t2 = min_t1t2[t1_pi]
 *     for t2_pi in range(t2_len):
 *         if min_min_t2t1 > min_t2t1[t2_pi]:             # <<<<<<<<<<<<<<
 *             min_min_t2t1 = min_t2t1[t2_pi]
 *     return (min_min_t1t2+min_min_t2t1)/2.0
 */
    }
  }

  /* "dipy/tracking/distances.pyx":835
 *         if min_min_t2t1 > min_t2t1[t2_pi]:
 *             min_min_t2t1 = min_t2t1[t2_pi]
 *     return (min_min_t1t2+min_min_t2t1)/2.0             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_11 = PyFloat_FromDouble(((__pyx_v_min_min_t1t2 + __pyx_v_min_min_t2t1) / 2.0)); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_r = __pyx_t_11;
  __pyx_t_11 = 0;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":780
 * 
 * 
 * def minimum_closest_distance(xyz1,xyz2):             # <<<<<<<<<<<<<<
 *     ''' Find the minimum distance between two curves xyz1, xyz2
 * 
 */

  /* 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_11);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track1.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track2.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.minimum_closest_distance", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_distances_buffer.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track1.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track2.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_track1);
  __Pyx_XDECREF((PyObject *)__pyx_v_track2);
  __Pyx_XDECREF((PyObject *)__pyx_v_distances_buffer);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":838
 * 
 * 
 * def lee_perpendicular_distance(start0, end0, start1, end1):             # <<<<<<<<<<<<<<
 *     ''' Calculates perpendicular distance metric for the distance between two line segments
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_27lee_perpendicular_distance(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_26lee_perpendicular_distance[] = " Calculates perpendicular distance metric for the distance between two line segments\n\n    Based on Lee , Han & Whang SIGMOD07.\n\n    This function assumes that norm(end0-start0)>norm(end1-start1) i.e. that the\n    first segment will be bigger than the second one.\n\n    Parameters\n    ----------\n    start0 : float array(3,)\n    end0 : float array(3,)\n    start1 : float array(3,)\n    end1 : float array(3,)\n\n    Returns\n    -------\n    perpendicular_distance: float\n\n    Notes\n    -----\n    l0 = np.inner(end0-start0,end0-start0)\n    l1 = np.inner(end1-start1,end1-start1)\n\n    k0=end0-start0\n\n    u1 = np.inner(start1-start0,k0)/l0\n    u2 = np.inner(end1-start0,k0)/l0\n\n    ps = start0+u1*k0\n    pe = start0+u2*k0\n\n    lperp1 = np.sqrt(np.inner(ps-start1,ps-start1))\n    lperp2 = np.sqrt(np.inner(pe-end1,pe-end1))\n\n    if lperp1+lperp2 > 0.:\n        return (lperp1**2+lperp2**2)/(lperp1+lperp2)\n    else:\n        return 0.\n\n    Examples\n    --------\n    >>> d = lee_perpendicular_distance([0,0,0],[1,0,0],[3,4,5],[5,4,3])\n    >>> print('%.6f' % d)\n    5.787888\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_27lee_perpendicular_distance = {"lee_perpendicular_distance", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_27lee_perpendicular_distance, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_26lee_perpendicular_distance};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_27lee_perpendicular_distance(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_start0 = 0;
  PyObject *__pyx_v_end0 = 0;
  PyObject *__pyx_v_start1 = 0;
  PyObject *__pyx_v_end1 = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("lee_perpendicular_distance (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_start0,&__pyx_n_s_end0,&__pyx_n_s_start1,&__pyx_n_s_end1,0};
    PyObject* values[4] = {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  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start0)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end0)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("lee_perpendicular_distance", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start1)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("lee_perpendicular_distance", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end1)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("lee_perpendicular_distance", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "lee_perpendicular_distance") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
      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);
    }
    __pyx_v_start0 = values[0];
    __pyx_v_end0 = values[1];
    __pyx_v_start1 = values[2];
    __pyx_v_end1 = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("lee_perpendicular_distance", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.lee_perpendicular_distance", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_26lee_perpendicular_distance(__pyx_self, __pyx_v_start0, __pyx_v_end0, __pyx_v_start1, __pyx_v_end1);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_26lee_perpendicular_distance(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_start0, PyObject *__pyx_v_end0, PyObject *__pyx_v_start1, PyObject *__pyx_v_end1) {
  PyArrayObject *__pyx_v_fvec1 = 0;
  PyArrayObject *__pyx_v_fvec2 = 0;
  PyArrayObject *__pyx_v_fvec3 = 0;
  PyArrayObject *__pyx_v_fvec4 = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec1;
  __Pyx_Buffer __pyx_pybuffer_fvec1;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec2;
  __Pyx_Buffer __pyx_pybuffer_fvec2;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec3;
  __Pyx_Buffer __pyx_pybuffer_fvec3;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec4;
  __Pyx_Buffer __pyx_pybuffer_fvec4;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("lee_perpendicular_distance", 0);
  __pyx_pybuffer_fvec1.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec1.refcount = 0;
  __pyx_pybuffernd_fvec1.data = NULL;
  __pyx_pybuffernd_fvec1.rcbuffer = &__pyx_pybuffer_fvec1;
  __pyx_pybuffer_fvec2.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec2.refcount = 0;
  __pyx_pybuffernd_fvec2.data = NULL;
  __pyx_pybuffernd_fvec2.rcbuffer = &__pyx_pybuffer_fvec2;
  __pyx_pybuffer_fvec3.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec3.refcount = 0;
  __pyx_pybuffernd_fvec3.data = NULL;
  __pyx_pybuffernd_fvec3.rcbuffer = &__pyx_pybuffer_fvec3;
  __pyx_pybuffer_fvec4.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec4.refcount = 0;
  __pyx_pybuffernd_fvec4.data = NULL;
  __pyx_pybuffernd_fvec4.rcbuffer = &__pyx_pybuffer_fvec4;

  /* "dipy/tracking/distances.pyx":887
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1,fvec2,fvec3,fvec4
 * 
 *     fvec1 = as_float_3vec(start0)             # <<<<<<<<<<<<<<
 *     fvec2 = as_float_3vec(end0)
 *     fvec3 = as_float_3vec(start1)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_start0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer);
    __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_2 < 0)) {
      PyErr_Fetch(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer, (PyObject*)__pyx_v_fvec1, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_3); Py_XDECREF(__pyx_t_4); Py_XDECREF(__pyx_t_5);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_3, __pyx_t_4, __pyx_t_5);
      }
    }
    __pyx_pybuffernd_fvec1.diminfo[0].strides = __pyx_pybuffernd_fvec1.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec1.diminfo[0].shape = __pyx_pybuffernd_fvec1.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 887; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_v_fvec1 = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":888
 * 
 *     fvec1 = as_float_3vec(start0)
 *     fvec2 = as_float_3vec(end0)             # <<<<<<<<<<<<<<
 *     fvec3 = as_float_3vec(start1)
 *     fvec4 = as_float_3vec(end1)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_end0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer);
    __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_2 < 0)) {
      PyErr_Fetch(&__pyx_t_5, &__pyx_t_4, &__pyx_t_3);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer, (PyObject*)__pyx_v_fvec2, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_5); Py_XDECREF(__pyx_t_4); Py_XDECREF(__pyx_t_3);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_5, __pyx_t_4, __pyx_t_3);
      }
    }
    __pyx_pybuffernd_fvec2.diminfo[0].strides = __pyx_pybuffernd_fvec2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec2.diminfo[0].shape = __pyx_pybuffernd_fvec2.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 888; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_v_fvec2 = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":889
 *     fvec1 = as_float_3vec(start0)
 *     fvec2 = as_float_3vec(end0)
 *     fvec3 = as_float_3vec(start1)             # <<<<<<<<<<<<<<
 *     fvec4 = as_float_3vec(end1)
 * 
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_start1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec3.rcbuffer->pybuffer);
    __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec3.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_2 < 0)) {
      PyErr_Fetch(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec3.rcbuffer->pybuffer, (PyObject*)__pyx_v_fvec3, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_3); Py_XDECREF(__pyx_t_4); Py_XDECREF(__pyx_t_5);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_3, __pyx_t_4, __pyx_t_5);
      }
    }
    __pyx_pybuffernd_fvec3.diminfo[0].strides = __pyx_pybuffernd_fvec3.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec3.diminfo[0].shape = __pyx_pybuffernd_fvec3.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_v_fvec3 = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":890
 *     fvec2 = as_float_3vec(end0)
 *     fvec3 = as_float_3vec(start1)
 *     fvec4 = as_float_3vec(end1)             # <<<<<<<<<<<<<<
 * 
 *     return clee_perpendicular_distance(<float *>fvec1.data,<float *>fvec2.data,<float *>fvec3.data,<float *>fvec4.data)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_end1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec4.rcbuffer->pybuffer);
    __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec4.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_2 < 0)) {
      PyErr_Fetch(&__pyx_t_5, &__pyx_t_4, &__pyx_t_3);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec4.rcbuffer->pybuffer, (PyObject*)__pyx_v_fvec4, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_5); Py_XDECREF(__pyx_t_4); Py_XDECREF(__pyx_t_3);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_5, __pyx_t_4, __pyx_t_3);
      }
    }
    __pyx_pybuffernd_fvec4.diminfo[0].strides = __pyx_pybuffernd_fvec4.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec4.diminfo[0].shape = __pyx_pybuffernd_fvec4.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 890; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_v_fvec4 = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":892
 *     fvec4 = as_float_3vec(end1)
 * 
 *     return clee_perpendicular_distance(<float *>fvec1.data,<float *>fvec2.data,<float *>fvec3.data,<float *>fvec4.data)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyFloat_FromDouble(__pyx_f_4dipy_8tracking_9distances_clee_perpendicular_distance(((float *)__pyx_v_fvec1->data), ((float *)__pyx_v_fvec2->data), ((float *)__pyx_v_fvec3->data), ((float *)__pyx_v_fvec4->data))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":838
 * 
 * 
 * def lee_perpendicular_distance(start0, end0, start1, end1):             # <<<<<<<<<<<<<<
 *     ''' Calculates perpendicular distance metric for the distance between two line segments
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec3.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec4.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.lee_perpendicular_distance", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec3.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec4.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec1);
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec2);
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec3);
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec4);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":895
 * 
 * 
 * cdef float clee_perpendicular_distance(float *start0, float *end0,float *start1, float *end1):             # <<<<<<<<<<<<<<
 *     ''' This function assumes that norm(end0-start0)>norm(end1-start1)
 *     '''
 */

static float __pyx_f_4dipy_8tracking_9distances_clee_perpendicular_distance(float *__pyx_v_start0, float *__pyx_v_end0, float *__pyx_v_start1, float *__pyx_v_end1) {
  float __pyx_v_l0;
  CYTHON_UNUSED float __pyx_v_l1;
  float __pyx_v_u1;
  float __pyx_v_u2;
  float __pyx_v_lperp1;
  float __pyx_v_lperp2;
  float __pyx_v_k0[3];
  float __pyx_v_ps[3];
  float __pyx_v_pe[3];
  float __pyx_v_ps1[3];
  float __pyx_v_pe1[3];
  float __pyx_v_tmp[3];
  float __pyx_r;
  __Pyx_RefNannyDeclarations
  float __pyx_t_1;
  int __pyx_t_2;
  float __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("clee_perpendicular_distance", 0);

  /* "dipy/tracking/distances.pyx":903
 *         float *s_tmp,*e_tmp,k0[3],ps[3],pe[3],ps1[3],pe1[3],tmp[3]
 * 
 *     csub_3vecs(end0,start0,k0)             # <<<<<<<<<<<<<<
 *     l0 = cinner_3vecs(k0,k0)
 * 
 */
  __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_end0, __pyx_v_start0, __pyx_v_k0);

  /* "dipy/tracking/distances.pyx":904
 * 
 *     csub_3vecs(end0,start0,k0)
 *     l0 = cinner_3vecs(k0,k0)             # <<<<<<<<<<<<<<
 * 
 *     csub_3vecs(end1,start1,tmp)
 */
  __pyx_v_l0 = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_k0, __pyx_v_k0);

  /* "dipy/tracking/distances.pyx":906
 *     l0 = cinner_3vecs(k0,k0)
 * 
 *     csub_3vecs(end1,start1,tmp)             # <<<<<<<<<<<<<<
 *     l1 = cinner_3vecs(tmp, tmp)
 * 
 */
  __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_end1, __pyx_v_start1, __pyx_v_tmp);

  /* "dipy/tracking/distances.pyx":907
 * 
 *     csub_3vecs(end1,start1,tmp)
 *     l1 = cinner_3vecs(tmp, tmp)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_v_l1 = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_tmp, __pyx_v_tmp);

  /* "dipy/tracking/distances.pyx":914
 *     #u1 = np.inner(start1-start0,k0)/l0
 *     #u2 = np.inner(end1-start0,k0)/l0
 *     csub_3vecs(start1,start0,tmp)             # <<<<<<<<<<<<<<
 *     u1 = cinner_3vecs(tmp,k0)/l0
 * 
 */
  __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_start1, __pyx_v_start0, __pyx_v_tmp);

  /* "dipy/tracking/distances.pyx":915
 *     #u2 = np.inner(end1-start0,k0)/l0
 *     csub_3vecs(start1,start0,tmp)
 *     u1 = cinner_3vecs(tmp,k0)/l0             # <<<<<<<<<<<<<<
 * 
 *     csub_3vecs(end1,start0,tmp)
 */
  __pyx_t_1 = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_tmp, __pyx_v_k0);
  if (unlikely(__pyx_v_l0 == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 915; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_v_u1 = (__pyx_t_1 / __pyx_v_l0);

  /* "dipy/tracking/distances.pyx":917
 *     u1 = cinner_3vecs(tmp,k0)/l0
 * 
 *     csub_3vecs(end1,start0,tmp)             # <<<<<<<<<<<<<<
 *     u2 = cinner_3vecs(tmp,k0)/l0
 * 
 */
  __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_end1, __pyx_v_start0, __pyx_v_tmp);

  /* "dipy/tracking/distances.pyx":918
 * 
 *     csub_3vecs(end1,start0,tmp)
 *     u2 = cinner_3vecs(tmp,k0)/l0             # <<<<<<<<<<<<<<
 * 
 *     cmul_3vec(u1,k0,tmp)
 */
  __pyx_t_1 = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_tmp, __pyx_v_k0);
  if (unlikely(__pyx_v_l0 == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 918; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_v_u2 = (__pyx_t_1 / __pyx_v_l0);

  /* "dipy/tracking/distances.pyx":920
 *     u2 = cinner_3vecs(tmp,k0)/l0
 * 
 *     cmul_3vec(u1,k0,tmp)             # <<<<<<<<<<<<<<
 *     cadd_3vecs(start0,tmp,ps)
 * 
 */
  __pyx_f_4dipy_8tracking_9distances_cmul_3vec(__pyx_v_u1, __pyx_v_k0, __pyx_v_tmp);

  /* "dipy/tracking/distances.pyx":921
 * 
 *     cmul_3vec(u1,k0,tmp)
 *     cadd_3vecs(start0,tmp,ps)             # <<<<<<<<<<<<<<
 * 
 *     cmul_3vec(u2,k0,tmp)
 */
  __pyx_f_4dipy_8tracking_9distances_cadd_3vecs(__pyx_v_start0, __pyx_v_tmp, __pyx_v_ps);

  /* "dipy/tracking/distances.pyx":923
 *     cadd_3vecs(start0,tmp,ps)
 * 
 *     cmul_3vec(u2,k0,tmp)             # <<<<<<<<<<<<<<
 *     cadd_3vecs(start0,tmp,pe)
 * 
 */
  __pyx_f_4dipy_8tracking_9distances_cmul_3vec(__pyx_v_u2, __pyx_v_k0, __pyx_v_tmp);

  /* "dipy/tracking/distances.pyx":924
 * 
 *     cmul_3vec(u2,k0,tmp)
 *     cadd_3vecs(start0,tmp,pe)             # <<<<<<<<<<<<<<
 * 
 *     #lperp1 = np.sqrt(np.inner(ps-start1,ps-start1))
 */
  __pyx_f_4dipy_8tracking_9distances_cadd_3vecs(__pyx_v_start0, __pyx_v_tmp, __pyx_v_pe);

  /* "dipy/tracking/distances.pyx":929
 *     #lperp2 = np.sqrt(np.inner(pe-end1,pe-end1))
 * 
 *     csub_3vecs(ps,start1,ps1)             # <<<<<<<<<<<<<<
 *     csub_3vecs(pe,end1,pe1)
 * 
 */
  __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_ps, __pyx_v_start1, __pyx_v_ps1);

  /* "dipy/tracking/distances.pyx":930
 * 
 *     csub_3vecs(ps,start1,ps1)
 *     csub_3vecs(pe,end1,pe1)             # <<<<<<<<<<<<<<
 * 
 *     lperp1 = sqrt(cinner_3vecs(ps1,ps1))
 */
  __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_pe, __pyx_v_end1, __pyx_v_pe1);

  /* "dipy/tracking/distances.pyx":932
 *     csub_3vecs(pe,end1,pe1)
 * 
 *     lperp1 = sqrt(cinner_3vecs(ps1,ps1))             # <<<<<<<<<<<<<<
 *     lperp2 = sqrt(cinner_3vecs(pe1,pe1))
 * 
 */
  __pyx_v_lperp1 = sqrt(__pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_ps1, __pyx_v_ps1));

  /* "dipy/tracking/distances.pyx":933
 * 
 *     lperp1 = sqrt(cinner_3vecs(ps1,ps1))
 *     lperp2 = sqrt(cinner_3vecs(pe1,pe1))             # <<<<<<<<<<<<<<
 * 
 *     if lperp1+lperp2 > 0.:
 */
  __pyx_v_lperp2 = sqrt(__pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_pe1, __pyx_v_pe1));

  /* "dipy/tracking/distances.pyx":935
 *     lperp2 = sqrt(cinner_3vecs(pe1,pe1))
 * 
 *     if lperp1+lperp2 > 0.:             # <<<<<<<<<<<<<<
 *         return (lperp1*lperp1+lperp2*lperp2)/(lperp1+lperp2)
 *     else:
 */
  __pyx_t_2 = (((__pyx_v_lperp1 + __pyx_v_lperp2) > 0.) != 0);
  if (__pyx_t_2) {

    /* "dipy/tracking/distances.pyx":936
 * 
 *     if lperp1+lperp2 > 0.:
 *         return (lperp1*lperp1+lperp2*lperp2)/(lperp1+lperp2)             # <<<<<<<<<<<<<<
 *     else:
 *         return 0.
 */
    __pyx_t_1 = ((__pyx_v_lperp1 * __pyx_v_lperp1) + (__pyx_v_lperp2 * __pyx_v_lperp2));
    __pyx_t_3 = (__pyx_v_lperp1 + __pyx_v_lperp2);
    if (unlikely(__pyx_t_3 == 0)) {
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 936; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_r = (__pyx_t_1 / __pyx_t_3);
    goto __pyx_L0;

    /* "dipy/tracking/distances.pyx":935
 *     lperp2 = sqrt(cinner_3vecs(pe1,pe1))
 * 
 *     if lperp1+lperp2 > 0.:             # <<<<<<<<<<<<<<
 *         return (lperp1*lperp1+lperp2*lperp2)/(lperp1+lperp2)
 *     else:
 */
  }

  /* "dipy/tracking/distances.pyx":938
 *         return (lperp1*lperp1+lperp2*lperp2)/(lperp1+lperp2)
 *     else:
 *         return 0.             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __pyx_r = 0.;
    goto __pyx_L0;
  }

  /* "dipy/tracking/distances.pyx":895
 * 
 * 
 * cdef float clee_perpendicular_distance(float *start0, float *end0,float *start1, float *end1):             # <<<<<<<<<<<<<<
 *     ''' This function assumes that norm(end0-start0)>norm(end1-start1)
 *     '''
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("dipy.tracking.distances.clee_perpendicular_distance", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":941
 * 
 * 
 * def lee_angle_distance(start0, end0, start1, end1):             # <<<<<<<<<<<<<<
 *     ''' Calculates angle distance metric for the distance between two line segments
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_29lee_angle_distance(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_28lee_angle_distance[] = " Calculates angle distance metric for the distance between two line segments\n\n    Based on Lee , Han & Whang SIGMOD07.\n\n    This function assumes that norm(end0-start0)>norm(end1-start1) i.e. that the\n    first segment will be bigger than the second one.\n\n    Parameters\n    ----------\n    start0 : float array(3,)\n    end0 : float array(3,)\n    start1 : float array(3,)\n    end1 : float array(3,)\n\n    Returns\n    -------\n    angle_distance : float\n\n    Notes\n    -----\n    l_0 = np.inner(end0-start0,end0-start0)\n    l_1 = np.inner(end1-start1,end1-start1)\n\n    cos_theta_squared = np.inner(end0-start0,end1-start1)**2/ (l_0*l_1)\n    return np.sqrt((1-cos_theta_squared)*l_1)\n\n    Examples\n    --------\n    >>> lee_angle_distance([0,0,0],[1,0,0],[3,4,5],[5,4,3])\n    2.0\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_29lee_angle_distance = {"lee_angle_distance", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_29lee_angle_distance, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_28lee_angle_distance};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_29lee_angle_distance(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_start0 = 0;
  PyObject *__pyx_v_end0 = 0;
  PyObject *__pyx_v_start1 = 0;
  PyObject *__pyx_v_end1 = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("lee_angle_distance (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_start0,&__pyx_n_s_end0,&__pyx_n_s_start1,&__pyx_n_s_end1,0};
    PyObject* values[4] = {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  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start0)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end0)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("lee_angle_distance", 1, 4, 4, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_start1)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("lee_angle_distance", 1, 4, 4, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_end1)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("lee_angle_distance", 1, 4, 4, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "lee_angle_distance") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 4) {
      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);
    }
    __pyx_v_start0 = values[0];
    __pyx_v_end0 = values[1];
    __pyx_v_start1 = values[2];
    __pyx_v_end1 = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("lee_angle_distance", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.lee_angle_distance", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_28lee_angle_distance(__pyx_self, __pyx_v_start0, __pyx_v_end0, __pyx_v_start1, __pyx_v_end1);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_28lee_angle_distance(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_start0, PyObject *__pyx_v_end0, PyObject *__pyx_v_start1, PyObject *__pyx_v_end1) {
  PyArrayObject *__pyx_v_fvec1 = 0;
  PyArrayObject *__pyx_v_fvec2 = 0;
  PyArrayObject *__pyx_v_fvec3 = 0;
  PyArrayObject *__pyx_v_fvec4 = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec1;
  __Pyx_Buffer __pyx_pybuffer_fvec1;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec2;
  __Pyx_Buffer __pyx_pybuffer_fvec2;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec3;
  __Pyx_Buffer __pyx_pybuffer_fvec3;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec4;
  __Pyx_Buffer __pyx_pybuffer_fvec4;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("lee_angle_distance", 0);
  __pyx_pybuffer_fvec1.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec1.refcount = 0;
  __pyx_pybuffernd_fvec1.data = NULL;
  __pyx_pybuffernd_fvec1.rcbuffer = &__pyx_pybuffer_fvec1;
  __pyx_pybuffer_fvec2.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec2.refcount = 0;
  __pyx_pybuffernd_fvec2.data = NULL;
  __pyx_pybuffernd_fvec2.rcbuffer = &__pyx_pybuffer_fvec2;
  __pyx_pybuffer_fvec3.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec3.refcount = 0;
  __pyx_pybuffernd_fvec3.data = NULL;
  __pyx_pybuffernd_fvec3.rcbuffer = &__pyx_pybuffer_fvec3;
  __pyx_pybuffer_fvec4.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec4.refcount = 0;
  __pyx_pybuffernd_fvec4.data = NULL;
  __pyx_pybuffernd_fvec4.rcbuffer = &__pyx_pybuffer_fvec4;

  /* "dipy/tracking/distances.pyx":976
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1,fvec2,fvec3,fvec4
 * 
 *     fvec1 = as_float_3vec(start0)             # <<<<<<<<<<<<<<
 *     fvec2 = as_float_3vec(end0)
 *     fvec3 = as_float_3vec(start1)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_start0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 976; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer);
    __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_2 < 0)) {
      PyErr_Fetch(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer, (PyObject*)__pyx_v_fvec1, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_3); Py_XDECREF(__pyx_t_4); Py_XDECREF(__pyx_t_5);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_3, __pyx_t_4, __pyx_t_5);
      }
    }
    __pyx_pybuffernd_fvec1.diminfo[0].strides = __pyx_pybuffernd_fvec1.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec1.diminfo[0].shape = __pyx_pybuffernd_fvec1.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 976; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_v_fvec1 = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":977
 * 
 *     fvec1 = as_float_3vec(start0)
 *     fvec2 = as_float_3vec(end0)             # <<<<<<<<<<<<<<
 *     fvec3 = as_float_3vec(start1)
 *     fvec4 = as_float_3vec(end1)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_end0)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer);
    __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_2 < 0)) {
      PyErr_Fetch(&__pyx_t_5, &__pyx_t_4, &__pyx_t_3);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer, (PyObject*)__pyx_v_fvec2, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_5); Py_XDECREF(__pyx_t_4); Py_XDECREF(__pyx_t_3);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_5, __pyx_t_4, __pyx_t_3);
      }
    }
    __pyx_pybuffernd_fvec2.diminfo[0].strides = __pyx_pybuffernd_fvec2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec2.diminfo[0].shape = __pyx_pybuffernd_fvec2.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 977; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_v_fvec2 = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":978
 *     fvec1 = as_float_3vec(start0)
 *     fvec2 = as_float_3vec(end0)
 *     fvec3 = as_float_3vec(start1)             # <<<<<<<<<<<<<<
 *     fvec4 = as_float_3vec(end1)
 * 
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_start1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec3.rcbuffer->pybuffer);
    __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec3.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_2 < 0)) {
      PyErr_Fetch(&__pyx_t_3, &__pyx_t_4, &__pyx_t_5);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec3.rcbuffer->pybuffer, (PyObject*)__pyx_v_fvec3, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_3); Py_XDECREF(__pyx_t_4); Py_XDECREF(__pyx_t_5);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_3, __pyx_t_4, __pyx_t_5);
      }
    }
    __pyx_pybuffernd_fvec3.diminfo[0].strides = __pyx_pybuffernd_fvec3.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec3.diminfo[0].shape = __pyx_pybuffernd_fvec3.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 978; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_v_fvec3 = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":979
 *     fvec2 = as_float_3vec(end0)
 *     fvec3 = as_float_3vec(start1)
 *     fvec4 = as_float_3vec(end1)             # <<<<<<<<<<<<<<
 * 
 *     return clee_angle_distance(<float *>fvec1.data,<float *>fvec2.data,<float *>fvec3.data,<float *>fvec4.data)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_v_end1)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec4.rcbuffer->pybuffer);
    __pyx_t_2 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec4.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_1), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_2 < 0)) {
      PyErr_Fetch(&__pyx_t_5, &__pyx_t_4, &__pyx_t_3);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec4.rcbuffer->pybuffer, (PyObject*)__pyx_v_fvec4, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_5); Py_XDECREF(__pyx_t_4); Py_XDECREF(__pyx_t_3);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_5, __pyx_t_4, __pyx_t_3);
      }
    }
    __pyx_pybuffernd_fvec4.diminfo[0].strides = __pyx_pybuffernd_fvec4.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec4.diminfo[0].shape = __pyx_pybuffernd_fvec4.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 979; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_v_fvec4 = ((PyArrayObject *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":981
 *     fvec4 = as_float_3vec(end1)
 * 
 *     return clee_angle_distance(<float *>fvec1.data,<float *>fvec2.data,<float *>fvec3.data,<float *>fvec4.data)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyFloat_FromDouble(__pyx_f_4dipy_8tracking_9distances_clee_angle_distance(((float *)__pyx_v_fvec1->data), ((float *)__pyx_v_fvec2->data), ((float *)__pyx_v_fvec3->data), ((float *)__pyx_v_fvec4->data))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 981; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":941
 * 
 * 
 * def lee_angle_distance(start0, end0, start1, end1):             # <<<<<<<<<<<<<<
 *     ''' Calculates angle distance metric for the distance between two line segments
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec3.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec4.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.lee_angle_distance", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec3.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec4.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec1);
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec2);
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec3);
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec4);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":984
 * 
 * 
 * cdef float clee_angle_distance(float *start0, float *end0,float *start1, float *end1):             # <<<<<<<<<<<<<<
 *     ''' This function assumes that norm(end0-start0)>norm(end1-start1)
 *     '''
 */

static float __pyx_f_4dipy_8tracking_9distances_clee_angle_distance(float *__pyx_v_start0, float *__pyx_v_end0, float *__pyx_v_start1, float *__pyx_v_end1) {
  float __pyx_v_l0;
  float __pyx_v_l1;
  float __pyx_v_ltmp;
  float __pyx_v_cos_theta_squared;
  float __pyx_v_k0[3];
  float __pyx_v_k1[3];
  float __pyx_r;
  __Pyx_RefNannyDeclarations
  float __pyx_t_1;
  float __pyx_t_2;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("clee_angle_distance", 0);

  /* "dipy/tracking/distances.pyx":992
 *         float *s_tmp,*e_tmp,k0[3],k1[3],tmp[3]
 * 
 *     csub_3vecs(end0,start0,k0)             # <<<<<<<<<<<<<<
 *     l0 = cinner_3vecs(k0,k0)
 *     #print l0
 */
  __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_end0, __pyx_v_start0, __pyx_v_k0);

  /* "dipy/tracking/distances.pyx":993
 * 
 *     csub_3vecs(end0,start0,k0)
 *     l0 = cinner_3vecs(k0,k0)             # <<<<<<<<<<<<<<
 *     #print l0
 * 
 */
  __pyx_v_l0 = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_k0, __pyx_v_k0);

  /* "dipy/tracking/distances.pyx":996
 *     #print l0
 * 
 *     csub_3vecs(end1,start1,k1)             # <<<<<<<<<<<<<<
 *     l1 = cinner_3vecs(k1, k1)
 *     #print l1
 */
  __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_end1, __pyx_v_start1, __pyx_v_k1);

  /* "dipy/tracking/distances.pyx":997
 * 
 *     csub_3vecs(end1,start1,k1)
 *     l1 = cinner_3vecs(k1, k1)             # <<<<<<<<<<<<<<
 *     #print l1
 * 
 */
  __pyx_v_l1 = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_k1, __pyx_v_k1);

  /* "dipy/tracking/distances.pyx":1000
 *     #print l1
 * 
 *     ltmp=cinner_3vecs(k0,k1)             # <<<<<<<<<<<<<<
 * 
 *     cos_theta_squared = (ltmp*ltmp)/ (l0*l1)
 */
  __pyx_v_ltmp = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_k0, __pyx_v_k1);

  /* "dipy/tracking/distances.pyx":1002
 *     ltmp=cinner_3vecs(k0,k1)
 * 
 *     cos_theta_squared = (ltmp*ltmp)/ (l0*l1)             # <<<<<<<<<<<<<<
 *     #print cos_theta_squared
 *     return sqrt((1-cos_theta_squared)*l1)
 */
  __pyx_t_1 = (__pyx_v_ltmp * __pyx_v_ltmp);
  __pyx_t_2 = (__pyx_v_l0 * __pyx_v_l1);
  if (unlikely(__pyx_t_2 == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1002; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_v_cos_theta_squared = (__pyx_t_1 / __pyx_t_2);

  /* "dipy/tracking/distances.pyx":1004
 *     cos_theta_squared = (ltmp*ltmp)/ (l0*l1)
 *     #print cos_theta_squared
 *     return sqrt((1-cos_theta_squared)*l1)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = sqrt(((1.0 - __pyx_v_cos_theta_squared) * __pyx_v_l1));
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":984
 * 
 * 
 * cdef float clee_angle_distance(float *start0, float *end0,float *start1, float *end1):             # <<<<<<<<<<<<<<
 *     ''' This function assumes that norm(end0-start0)>norm(end1-start1)
 *     '''
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("dipy.tracking.distances.clee_angle_distance", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":1007
 * 
 * 
 * def approx_polygon_track(xyz,alpha=0.392):             # <<<<<<<<<<<<<<
 *     ''' Fast and simple trajectory approximation algorithm by Eleftherios and Ian
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_31approx_polygon_track(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_30approx_polygon_track[] = " Fast and simple trajectory approximation algorithm by Eleftherios and Ian\n\n    It will reduce the number of points of the track by keeping\n    intact the start and endpoints of the track and trying to remove\n    as many points as possible without distorting much the shape of\n    the track\n\n    Parameters\n    ----------\n    xyz : array(N,3)\n        initial trajectory\n    alpha : float\n        smoothing parameter (<0.392 smoother, >0.392 rougher) if the\n        trajectory was a smooth circle then with alpha =0.393\n        ~=pi/8. the circle would be approximated with an decahexagon if\n        alpha = 0.7853 ~=pi/4. with an octagon.\n\n    Returns\n    -------\n    characteristic_points: list of M array(3,) points\n\n    Examples\n    --------\n\n    Approximating a helix:\n\n    >>> t=np.linspace(0,1.75*2*np.pi,100)\n    >>> x = np.sin(t)\n    >>> y = np.cos(t)\n    >>> z = t\n    >>> xyz=np.vstack((x,y,z)).T\n    >>> xyza = approx_polygon_track(xyz)\n    >>> len(xyza) < len(xyz)\n    True\n\n    Notes\n    -----\n    Assuming that a good approximation for a circle is an octagon then\n    that means that the points of the octagon will have angle alpha =\n    2*pi/8 = pi/4 . We calculate the angle between every two neighbour\n    segments of a trajectory and if the angle is higher than pi/4 we\n    choose that point as a characteristic point otherwise we move at the\n    next point.\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_31approx_polygon_track = {"approx_polygon_track", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_31approx_polygon_track, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_30approx_polygon_track};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_31approx_polygon_track(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_xyz = 0;
  PyObject *__pyx_v_alpha = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("approx_polygon_track (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_xyz,&__pyx_n_s_alpha,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)__pyx_float_0_392);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_xyz)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alpha);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "approx_polygon_track") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1007; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_xyz = values[0];
    __pyx_v_alpha = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("approx_polygon_track", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1007; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.approx_polygon_track", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_30approx_polygon_track(__pyx_self, __pyx_v_xyz, __pyx_v_alpha);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_30approx_polygon_track(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_xyz, PyObject *__pyx_v_alpha) {
  int __pyx_v_mid_index;
  PyArrayObject *__pyx_v_track = 0;
  float *__pyx_v_fvec0;
  float *__pyx_v_fvec1;
  float *__pyx_v_fvec2;
  PyObject *__pyx_v_characteristic_points = 0;
  size_t __pyx_v_t_len;
  double __pyx_v_angle;
  double __pyx_v_tmp;
  float __pyx_v_vec0[3];
  float __pyx_v_vec1[3];
  __Pyx_LocalBuf_ND __pyx_pybuffernd_track;
  __Pyx_Buffer __pyx_pybuffer_track;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  double __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyArrayObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  Py_ssize_t __pyx_t_11;
  int __pyx_t_12;
  long __pyx_t_13;
  float __pyx_t_14;
  float __pyx_t_15;
  int __pyx_t_16;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("approx_polygon_track", 0);
  __pyx_pybuffer_track.pybuffer.buf = NULL;
  __pyx_pybuffer_track.refcount = 0;
  __pyx_pybuffernd_track.data = NULL;
  __pyx_pybuffernd_track.rcbuffer = &__pyx_pybuffer_track;

  /* "dipy/tracking/distances.pyx":1061
 *         float vec0[3],vec1[3]
 * 
 *     angle=alpha             # <<<<<<<<<<<<<<
 *     track = np.ascontiguousarray(xyz, dtype=f32_dt)
 *     t_len=len(track)
 */
  __pyx_t_1 = __pyx_PyFloat_AsDouble(__pyx_v_alpha); if (unlikely((__pyx_t_1 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1061; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_angle = __pyx_t_1;

  /* "dipy/tracking/distances.pyx":1062
 * 
 *     angle=alpha
 *     track = np.ascontiguousarray(xyz, dtype=f32_dt)             # <<<<<<<<<<<<<<
 *     t_len=len(track)
 *     characteristic_points=[track[0]]
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_xyz);
  __Pyx_GIVEREF(__pyx_v_xyz);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_xyz);
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1062; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_5);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
    __pyx_t_7 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_7 < 0)) {
      PyErr_Fetch(&__pyx_t_8, &__pyx_t_9, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track.rcbuffer->pybuffer, (PyObject*)__pyx_v_track, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_8, __pyx_t_9, __pyx_t_10);
      }
    }
    __pyx_pybuffernd_track.diminfo[0].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_track.diminfo[0].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_track.diminfo[1].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_track.diminfo[1].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[1];
    if (unlikely(__pyx_t_7 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1062; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_6 = 0;
  __pyx_v_track = ((PyArrayObject *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "dipy/tracking/distances.pyx":1063
 *     angle=alpha
 *     track = np.ascontiguousarray(xyz, dtype=f32_dt)
 *     t_len=len(track)             # <<<<<<<<<<<<<<
 *     characteristic_points=[track[0]]
 *     mid_index = 1
 */
  __pyx_t_11 = PyObject_Length(((PyObject *)__pyx_v_track)); if (unlikely(__pyx_t_11 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1063; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_t_len = __pyx_t_11;

  /* "dipy/tracking/distances.pyx":1064
 *     track = np.ascontiguousarray(xyz, dtype=f32_dt)
 *     t_len=len(track)
 *     characteristic_points=[track[0]]             # <<<<<<<<<<<<<<
 *     mid_index = 1
 *     angle=0
 */
  __pyx_t_5 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1064; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_5);
  PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_5);
  __pyx_t_5 = 0;
  __pyx_v_characteristic_points = __pyx_t_4;
  __pyx_t_4 = 0;

  /* "dipy/tracking/distances.pyx":1065
 *     t_len=len(track)
 *     characteristic_points=[track[0]]
 *     mid_index = 1             # <<<<<<<<<<<<<<
 *     angle=0
 * 
 */
  __pyx_v_mid_index = 1;

  /* "dipy/tracking/distances.pyx":1066
 *     characteristic_points=[track[0]]
 *     mid_index = 1
 *     angle=0             # <<<<<<<<<<<<<<
 * 
 *     while mid_index < t_len-1:
 */
  __pyx_v_angle = 0.0;

  /* "dipy/tracking/distances.pyx":1068
 *     angle=0
 * 
 *     while mid_index < t_len-1:             # <<<<<<<<<<<<<<
 *         #fvec0 = as_float_3vec(track[mid_index-1])
 *         #<float *>track[0].data
 */
  while (1) {
    __pyx_t_12 = ((__pyx_v_mid_index < (__pyx_v_t_len - 1)) != 0);
    if (!__pyx_t_12) break;

    /* "dipy/tracking/distances.pyx":1071
 *         #fvec0 = as_float_3vec(track[mid_index-1])
 *         #<float *>track[0].data
 *         fvec0 = asfp(track[mid_index-1])             # <<<<<<<<<<<<<<
 *         fvec1 = asfp(track[mid_index])
 *         fvec2 = asfp(track[mid_index+1])
 */
    __pyx_t_13 = (__pyx_v_mid_index - 1);
    __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), __pyx_t_13, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_4);
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1071; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_fvec0 = __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_4));
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "dipy/tracking/distances.pyx":1072
 *         #<float *>track[0].data
 *         fvec0 = asfp(track[mid_index-1])
 *         fvec1 = asfp(track[mid_index])             # <<<<<<<<<<<<<<
 *         fvec2 = asfp(track[mid_index+1])
 *         #csub_3vecs(<float *>fvec1.data,<float *>fvec0.data,vec0)
 */
    __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), __pyx_v_mid_index, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1072; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_4);
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1072; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_fvec1 = __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_4));
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "dipy/tracking/distances.pyx":1073
 *         fvec0 = asfp(track[mid_index-1])
 *         fvec1 = asfp(track[mid_index])
 *         fvec2 = asfp(track[mid_index+1])             # <<<<<<<<<<<<<<
 *         #csub_3vecs(<float *>fvec1.data,<float *>fvec0.data,vec0)
 *         csub_3vecs(fvec1,fvec0,vec0)
 */
    __pyx_t_13 = (__pyx_v_mid_index + 1);
    __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), __pyx_t_13, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1073; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_4);
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1073; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_fvec2 = __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_4));
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "dipy/tracking/distances.pyx":1075
 *         fvec2 = asfp(track[mid_index+1])
 *         #csub_3vecs(<float *>fvec1.data,<float *>fvec0.data,vec0)
 *         csub_3vecs(fvec1,fvec0,vec0)             # <<<<<<<<<<<<<<
 *         csub_3vecs(fvec2,fvec1,vec1)
 *         tmp=<double>fabs(acos(cinner_3vecs(vec0,vec1)/(cnorm_3vec(vec0)*cnorm_3vec(vec1))))
 */
    __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_fvec1, __pyx_v_fvec0, __pyx_v_vec0);

    /* "dipy/tracking/distances.pyx":1076
 *         #csub_3vecs(<float *>fvec1.data,<float *>fvec0.data,vec0)
 *         csub_3vecs(fvec1,fvec0,vec0)
 *         csub_3vecs(fvec2,fvec1,vec1)             # <<<<<<<<<<<<<<
 *         tmp=<double>fabs(acos(cinner_3vecs(vec0,vec1)/(cnorm_3vec(vec0)*cnorm_3vec(vec1))))
 *         if dpy_isnan(tmp) :
 */
    __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_fvec2, __pyx_v_fvec1, __pyx_v_vec1);

    /* "dipy/tracking/distances.pyx":1077
 *         csub_3vecs(fvec1,fvec0,vec0)
 *         csub_3vecs(fvec2,fvec1,vec1)
 *         tmp=<double>fabs(acos(cinner_3vecs(vec0,vec1)/(cnorm_3vec(vec0)*cnorm_3vec(vec1))))             # <<<<<<<<<<<<<<
 *         if dpy_isnan(tmp) :
 *             angle+=0.
 */
    __pyx_t_14 = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_vec0, __pyx_v_vec1);
    __pyx_t_15 = (__pyx_f_4dipy_8tracking_9distances_cnorm_3vec(__pyx_v_vec0) * __pyx_f_4dipy_8tracking_9distances_cnorm_3vec(__pyx_v_vec1));
    if (unlikely(__pyx_t_15 == 0)) {
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1077; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_v_tmp = ((double)fabs(acos((__pyx_t_14 / __pyx_t_15))));

    /* "dipy/tracking/distances.pyx":1078
 *         csub_3vecs(fvec2,fvec1,vec1)
 *         tmp=<double>fabs(acos(cinner_3vecs(vec0,vec1)/(cnorm_3vec(vec0)*cnorm_3vec(vec1))))
 *         if dpy_isnan(tmp) :             # <<<<<<<<<<<<<<
 *             angle+=0.
 *         else:
 */
    __pyx_t_12 = (dpy_isnan(__pyx_v_tmp) != 0);
    if (__pyx_t_12) {

      /* "dipy/tracking/distances.pyx":1079
 *         tmp=<double>fabs(acos(cinner_3vecs(vec0,vec1)/(cnorm_3vec(vec0)*cnorm_3vec(vec1))))
 *         if dpy_isnan(tmp) :
 *             angle+=0.             # <<<<<<<<<<<<<<
 *         else:
 *             angle+=tmp
 */
      __pyx_v_angle = (__pyx_v_angle + 0.);

      /* "dipy/tracking/distances.pyx":1078
 *         csub_3vecs(fvec2,fvec1,vec1)
 *         tmp=<double>fabs(acos(cinner_3vecs(vec0,vec1)/(cnorm_3vec(vec0)*cnorm_3vec(vec1))))
 *         if dpy_isnan(tmp) :             # <<<<<<<<<<<<<<
 *             angle+=0.
 *         else:
 */
      goto __pyx_L5;
    }

    /* "dipy/tracking/distances.pyx":1081
 *             angle+=0.
 *         else:
 *             angle+=tmp             # <<<<<<<<<<<<<<
 *         if  angle > alpha:
 *             characteristic_points.append(track[mid_index])
 */
    /*else*/ {
      __pyx_v_angle = (__pyx_v_angle + __pyx_v_tmp);
    }
    __pyx_L5:;

    /* "dipy/tracking/distances.pyx":1082
 *         else:
 *             angle+=tmp
 *         if  angle > alpha:             # <<<<<<<<<<<<<<
 *             characteristic_points.append(track[mid_index])
 *             angle=0
 */
    __pyx_t_4 = PyFloat_FromDouble(__pyx_v_angle); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_4, __pyx_v_alpha, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_12 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1082; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_12) {

      /* "dipy/tracking/distances.pyx":1083
 *             angle+=tmp
 *         if  angle > alpha:
 *             characteristic_points.append(track[mid_index])             # <<<<<<<<<<<<<<
 *             angle=0
 *         mid_index+=1
 */
      __pyx_t_5 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), __pyx_v_mid_index, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_16 = __Pyx_PyObject_Append(__pyx_v_characteristic_points, __pyx_t_5); if (unlikely(__pyx_t_16 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1083; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "dipy/tracking/distances.pyx":1084
 *         if  angle > alpha:
 *             characteristic_points.append(track[mid_index])
 *             angle=0             # <<<<<<<<<<<<<<
 *         mid_index+=1
 * 
 */
      __pyx_v_angle = 0.0;

      /* "dipy/tracking/distances.pyx":1082
 *         else:
 *             angle+=tmp
 *         if  angle > alpha:             # <<<<<<<<<<<<<<
 *             characteristic_points.append(track[mid_index])
 *             angle=0
 */
    }

    /* "dipy/tracking/distances.pyx":1085
 *             characteristic_points.append(track[mid_index])
 *             angle=0
 *         mid_index+=1             # <<<<<<<<<<<<<<
 * 
 *     characteristic_points.append(track[-1])
 */
    __pyx_v_mid_index = (__pyx_v_mid_index + 1);
  }

  /* "dipy/tracking/distances.pyx":1087
 *         mid_index+=1
 * 
 *     characteristic_points.append(track[-1])             # <<<<<<<<<<<<<<
 *     return np.array(characteristic_points)
 * 
 */
  __pyx_t_5 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_16 = __Pyx_PyObject_Append(__pyx_v_characteristic_points, __pyx_t_5); if (unlikely(__pyx_t_16 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1087; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "dipy/tracking/distances.pyx":1088
 * 
 *     characteristic_points.append(track[-1])
 *     return np.array(characteristic_points)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1088; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_array); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1088; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && 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);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_characteristic_points); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1088; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
  } else {
    __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1088; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL;
    __Pyx_INCREF(__pyx_v_characteristic_points);
    __Pyx_GIVEREF(__pyx_v_characteristic_points);
    PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_v_characteristic_points);
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1088; __pyx_clineno = __LINE__; goto __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_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":1007
 * 
 * 
 * def approx_polygon_track(xyz,alpha=0.392):             # <<<<<<<<<<<<<<
 *     ''' Fast and simple trajectory approximation algorithm by Eleftherios and Ian
 * 
 */

  /* 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);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.approx_polygon_track", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_track);
  __Pyx_XDECREF(__pyx_v_characteristic_points);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":1091
 * 
 * 
 * def approximate_mdl_trajectory(xyz, alpha=1.):             # <<<<<<<<<<<<<<
 *     ''' Implementation of Lee et al Approximate Trajectory
 *     Partitioning Algorithm
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_33approximate_mdl_trajectory(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_32approximate_mdl_trajectory[] = " Implementation of Lee et al Approximate Trajectory\n    Partitioning Algorithm\n\n    This is base on the minimum description length principle\n\n    Parameters\n    ----------\n    xyz : array(N,3)\n        initial trajectory\n    alpha : float\n        smoothing parameter (>1 smoother, <1  rougher)\n\n    Returns\n    -------\n    characteristic_points : list of M array(3,) points\n\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_33approximate_mdl_trajectory = {"approximate_mdl_trajectory", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_33approximate_mdl_trajectory, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_32approximate_mdl_trajectory};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_33approximate_mdl_trajectory(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_xyz = 0;
  PyObject *__pyx_v_alpha = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("approximate_mdl_trajectory (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_xyz,&__pyx_n_s_alpha,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)__pyx_float_1_);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_xyz)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_alpha);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "approximate_mdl_trajectory") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1091; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_xyz = values[0];
    __pyx_v_alpha = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("approximate_mdl_trajectory", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1091; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.approximate_mdl_trajectory", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_32approximate_mdl_trajectory(__pyx_self, __pyx_v_xyz, __pyx_v_alpha);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_32approximate_mdl_trajectory(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_xyz, PyObject *__pyx_v_alpha) {
  int __pyx_v_start_index;
  int __pyx_v_length;
  int __pyx_v_current_index;
  int __pyx_v_i;
  double __pyx_v_cost_par;
  double __pyx_v_cost_nopar;
  double __pyx_v_alphac;
  PyObject *__pyx_v_characteristic_points = 0;
  size_t __pyx_v_t_len;
  PyArrayObject *__pyx_v_track = 0;
  float __pyx_v_tmp[3];
  PyArrayObject *__pyx_v_fvec1 = 0;
  PyArrayObject *__pyx_v_fvec2 = 0;
  PyArrayObject *__pyx_v_fvec3 = 0;
  PyArrayObject *__pyx_v_fvec4 = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec1;
  __Pyx_Buffer __pyx_pybuffer_fvec1;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec2;
  __Pyx_Buffer __pyx_pybuffer_fvec2;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec3;
  __Pyx_Buffer __pyx_pybuffer_fvec3;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_fvec4;
  __Pyx_Buffer __pyx_pybuffer_fvec4;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_track;
  __Pyx_Buffer __pyx_pybuffer_track;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyArrayObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  Py_ssize_t __pyx_t_10;
  double __pyx_t_11;
  int __pyx_t_12;
  long __pyx_t_13;
  int __pyx_t_14;
  long __pyx_t_15;
  int __pyx_t_16;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("approximate_mdl_trajectory", 0);
  __pyx_pybuffer_track.pybuffer.buf = NULL;
  __pyx_pybuffer_track.refcount = 0;
  __pyx_pybuffernd_track.data = NULL;
  __pyx_pybuffernd_track.rcbuffer = &__pyx_pybuffer_track;
  __pyx_pybuffer_fvec1.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec1.refcount = 0;
  __pyx_pybuffernd_fvec1.data = NULL;
  __pyx_pybuffernd_fvec1.rcbuffer = &__pyx_pybuffer_fvec1;
  __pyx_pybuffer_fvec2.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec2.refcount = 0;
  __pyx_pybuffernd_fvec2.data = NULL;
  __pyx_pybuffernd_fvec2.rcbuffer = &__pyx_pybuffer_fvec2;
  __pyx_pybuffer_fvec3.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec3.refcount = 0;
  __pyx_pybuffernd_fvec3.data = NULL;
  __pyx_pybuffernd_fvec3.rcbuffer = &__pyx_pybuffer_fvec3;
  __pyx_pybuffer_fvec4.pybuffer.buf = NULL;
  __pyx_pybuffer_fvec4.refcount = 0;
  __pyx_pybuffernd_fvec4.data = NULL;
  __pyx_pybuffernd_fvec4.rcbuffer = &__pyx_pybuffer_fvec4;

  /* "dipy/tracking/distances.pyx":1118
 *         cnp.ndarray[cnp.float32_t, ndim=1] fvec1,fvec2,fvec3,fvec4
 * 
 *     track = np.ascontiguousarray(xyz, dtype=f32_dt)             # <<<<<<<<<<<<<<
 *     t_len=len(track)
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_xyz);
  __Pyx_GIVEREF(__pyx_v_xyz);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_xyz);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
    __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track.rcbuffer->pybuffer, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_6 < 0)) {
      PyErr_Fetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track.rcbuffer->pybuffer, (PyObject*)__pyx_v_track, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_7, __pyx_t_8, __pyx_t_9);
      }
    }
    __pyx_pybuffernd_track.diminfo[0].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_track.diminfo[0].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_track.diminfo[1].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_track.diminfo[1].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[1];
    if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1118; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_5 = 0;
  __pyx_v_track = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "dipy/tracking/distances.pyx":1119
 * 
 *     track = np.ascontiguousarray(xyz, dtype=f32_dt)
 *     t_len=len(track)             # <<<<<<<<<<<<<<
 * 
 *     alphac=alpha
 */
  __pyx_t_10 = PyObject_Length(((PyObject *)__pyx_v_track)); if (unlikely(__pyx_t_10 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1119; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_t_len = __pyx_t_10;

  /* "dipy/tracking/distances.pyx":1121
 *     t_len=len(track)
 * 
 *     alphac=alpha             # <<<<<<<<<<<<<<
 *     characteristic_points=[xyz[0]]
 *     start_index = 0
 */
  __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_v_alpha); if (unlikely((__pyx_t_11 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_alphac = __pyx_t_11;

  /* "dipy/tracking/distances.pyx":1122
 * 
 *     alphac=alpha
 *     characteristic_points=[xyz[0]]             # <<<<<<<<<<<<<<
 *     start_index = 0
 *     length = 2
 */
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_xyz, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1122; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyList_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __pyx_t_4 = 0;
  __pyx_v_characteristic_points = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":1123
 *     alphac=alpha
 *     characteristic_points=[xyz[0]]
 *     start_index = 0             # <<<<<<<<<<<<<<
 *     length = 2
 *     #print t_len
 */
  __pyx_v_start_index = 0;

  /* "dipy/tracking/distances.pyx":1124
 *     characteristic_points=[xyz[0]]
 *     start_index = 0
 *     length = 2             # <<<<<<<<<<<<<<
 *     #print t_len
 * 
 */
  __pyx_v_length = 2;

  /* "dipy/tracking/distances.pyx":1127
 *     #print t_len
 * 
 *     while start_index+length < <int>t_len-1:             # <<<<<<<<<<<<<<
 *         current_index = start_index+length
 *         fvec1 = as_float_3vec(track[start_index])
 */
  while (1) {
    __pyx_t_12 = (((__pyx_v_start_index + __pyx_v_length) < (((int)__pyx_v_t_len) - 1)) != 0);
    if (!__pyx_t_12) break;

    /* "dipy/tracking/distances.pyx":1128
 * 
 *     while start_index+length < <int>t_len-1:
 *         current_index = start_index+length             # <<<<<<<<<<<<<<
 *         fvec1 = as_float_3vec(track[start_index])
 *         fvec2 = as_float_3vec(track[current_index])
 */
    __pyx_v_current_index = (__pyx_v_start_index + __pyx_v_length);

    /* "dipy/tracking/distances.pyx":1129
 *     while start_index+length < <int>t_len-1:
 *         current_index = start_index+length
 *         fvec1 = as_float_3vec(track[start_index])             # <<<<<<<<<<<<<<
 *         fvec2 = as_float_3vec(track[current_index])
 *         # L(H)
 */
    __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), __pyx_v_start_index, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1129; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer);
      __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_4), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_6 < 0)) {
        PyErr_Fetch(&__pyx_t_9, &__pyx_t_8, &__pyx_t_7);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer, (PyObject*)__pyx_v_fvec1, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_9, __pyx_t_8, __pyx_t_7);
        }
      }
      __pyx_pybuffernd_fvec1.diminfo[0].strides = __pyx_pybuffernd_fvec1.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec1.diminfo[0].shape = __pyx_pybuffernd_fvec1.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1129; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_XDECREF_SET(__pyx_v_fvec1, ((PyArrayObject *)__pyx_t_4));
    __pyx_t_4 = 0;

    /* "dipy/tracking/distances.pyx":1130
 *         current_index = start_index+length
 *         fvec1 = as_float_3vec(track[start_index])
 *         fvec2 = as_float_3vec(track[current_index])             # <<<<<<<<<<<<<<
 *         # L(H)
 *         csub_3vecs(<float *>fvec2.data,<float *>fvec1.data,tmp)
 */
    __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), __pyx_v_current_index, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1130; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer);
      __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_3), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
      if (unlikely(__pyx_t_6 < 0)) {
        PyErr_Fetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer, (PyObject*)__pyx_v_fvec2, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_7, __pyx_t_8, __pyx_t_9);
        }
      }
      __pyx_pybuffernd_fvec2.diminfo[0].strides = __pyx_pybuffernd_fvec2.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec2.diminfo[0].shape = __pyx_pybuffernd_fvec2.rcbuffer->pybuffer.shape[0];
      if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1130; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_XDECREF_SET(__pyx_v_fvec2, ((PyArrayObject *)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "dipy/tracking/distances.pyx":1132
 *         fvec2 = as_float_3vec(track[current_index])
 *         # L(H)
 *         csub_3vecs(<float *>fvec2.data,<float *>fvec1.data,tmp)             # <<<<<<<<<<<<<<
 *         cost_par=dpy_log2(sqrt(cinner_3vecs(tmp,tmp)))
 *         cost_nopar=0
 */
    __pyx_f_4dipy_8tracking_9distances_csub_3vecs(((float *)__pyx_v_fvec2->data), ((float *)__pyx_v_fvec1->data), __pyx_v_tmp);

    /* "dipy/tracking/distances.pyx":1133
 *         # L(H)
 *         csub_3vecs(<float *>fvec2.data,<float *>fvec1.data,tmp)
 *         cost_par=dpy_log2(sqrt(cinner_3vecs(tmp,tmp)))             # <<<<<<<<<<<<<<
 *         cost_nopar=0
 *         #print start_index,current_index
 */
    __pyx_v_cost_par = dpy_log2(sqrt(__pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_tmp, __pyx_v_tmp)));

    /* "dipy/tracking/distances.pyx":1134
 *         csub_3vecs(<float *>fvec2.data,<float *>fvec1.data,tmp)
 *         cost_par=dpy_log2(sqrt(cinner_3vecs(tmp,tmp)))
 *         cost_nopar=0             # <<<<<<<<<<<<<<
 *         #print start_index,current_index
 *         # L(D|H)
 */
    __pyx_v_cost_nopar = 0.0;

    /* "dipy/tracking/distances.pyx":1138
 *         # L(D|H)
 *         #for i in range(start_index+1,current_index):#+1):
 *         for i in range(start_index,current_index+1):             # <<<<<<<<<<<<<<
 *             #print i
 *             fvec3 = as_float_3vec(track[i])
 */
    __pyx_t_13 = (__pyx_v_current_index + 1);
    for (__pyx_t_6 = __pyx_v_start_index; __pyx_t_6 < __pyx_t_13; __pyx_t_6+=1) {
      __pyx_v_i = __pyx_t_6;

      /* "dipy/tracking/distances.pyx":1140
 *         for i in range(start_index,current_index+1):
 *             #print i
 *             fvec3 = as_float_3vec(track[i])             # <<<<<<<<<<<<<<
 *             fvec4 = as_float_3vec(track[i+1])
 *             cost_par += dpy_log2(clee_perpendicular_distance(<float *>fvec3.data,<float *>fvec4.data,<float *>fvec1.data,<float *>fvec2.data))
 */
      __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1140; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_t_3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec3.rcbuffer->pybuffer);
        __pyx_t_14 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec3.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_4), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_14 < 0)) {
          PyErr_Fetch(&__pyx_t_9, &__pyx_t_8, &__pyx_t_7);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec3.rcbuffer->pybuffer, (PyObject*)__pyx_v_fvec3, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_9, __pyx_t_8, __pyx_t_7);
          }
        }
        __pyx_pybuffernd_fvec3.diminfo[0].strides = __pyx_pybuffernd_fvec3.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec3.diminfo[0].shape = __pyx_pybuffernd_fvec3.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1140; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_XDECREF_SET(__pyx_v_fvec3, ((PyArrayObject *)__pyx_t_4));
      __pyx_t_4 = 0;

      /* "dipy/tracking/distances.pyx":1141
 *             #print i
 *             fvec3 = as_float_3vec(track[i])
 *             fvec4 = as_float_3vec(track[i+1])             # <<<<<<<<<<<<<<
 *             cost_par += dpy_log2(clee_perpendicular_distance(<float *>fvec3.data,<float *>fvec4.data,<float *>fvec1.data,<float *>fvec2.data))
 *             cost_par += dpy_log2(clee_angle_distance(<float *>fvec3.data,<float *>fvec4.data,<float *>fvec1.data,<float *>fvec2.data))
 */
      __pyx_t_15 = (__pyx_v_i + 1);
      __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), __pyx_t_15, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1141; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = ((PyObject *)__pyx_f_4dipy_8tracking_9distances_as_float_3vec(__pyx_t_4)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec4.rcbuffer->pybuffer);
        __pyx_t_14 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec4.rcbuffer->pybuffer, (PyObject*)((PyArrayObject *)__pyx_t_3), &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_14 < 0)) {
          PyErr_Fetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_fvec4.rcbuffer->pybuffer, (PyObject*)__pyx_v_fvec4, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_7, __pyx_t_8, __pyx_t_9);
          }
        }
        __pyx_pybuffernd_fvec4.diminfo[0].strides = __pyx_pybuffernd_fvec4.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_fvec4.diminfo[0].shape = __pyx_pybuffernd_fvec4.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1141; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_XDECREF_SET(__pyx_v_fvec4, ((PyArrayObject *)__pyx_t_3));
      __pyx_t_3 = 0;

      /* "dipy/tracking/distances.pyx":1142
 *             fvec3 = as_float_3vec(track[i])
 *             fvec4 = as_float_3vec(track[i+1])
 *             cost_par += dpy_log2(clee_perpendicular_distance(<float *>fvec3.data,<float *>fvec4.data,<float *>fvec1.data,<float *>fvec2.data))             # <<<<<<<<<<<<<<
 *             cost_par += dpy_log2(clee_angle_distance(<float *>fvec3.data,<float *>fvec4.data,<float *>fvec1.data,<float *>fvec2.data))
 *             csub_3vecs(<float *>fvec4.data,<float *>fvec3.data,tmp)
 */
      __pyx_v_cost_par = (__pyx_v_cost_par + dpy_log2(__pyx_f_4dipy_8tracking_9distances_clee_perpendicular_distance(((float *)__pyx_v_fvec3->data), ((float *)__pyx_v_fvec4->data), ((float *)__pyx_v_fvec1->data), ((float *)__pyx_v_fvec2->data))));

      /* "dipy/tracking/distances.pyx":1143
 *             fvec4 = as_float_3vec(track[i+1])
 *             cost_par += dpy_log2(clee_perpendicular_distance(<float *>fvec3.data,<float *>fvec4.data,<float *>fvec1.data,<float *>fvec2.data))
 *             cost_par += dpy_log2(clee_angle_distance(<float *>fvec3.data,<float *>fvec4.data,<float *>fvec1.data,<float *>fvec2.data))             # <<<<<<<<<<<<<<
 *             csub_3vecs(<float *>fvec4.data,<float *>fvec3.data,tmp)
 *             cost_nopar += dpy_log2(cinner_3vecs(tmp,tmp))
 */
      __pyx_v_cost_par = (__pyx_v_cost_par + dpy_log2(__pyx_f_4dipy_8tracking_9distances_clee_angle_distance(((float *)__pyx_v_fvec3->data), ((float *)__pyx_v_fvec4->data), ((float *)__pyx_v_fvec1->data), ((float *)__pyx_v_fvec2->data))));

      /* "dipy/tracking/distances.pyx":1144
 *             cost_par += dpy_log2(clee_perpendicular_distance(<float *>fvec3.data,<float *>fvec4.data,<float *>fvec1.data,<float *>fvec2.data))
 *             cost_par += dpy_log2(clee_angle_distance(<float *>fvec3.data,<float *>fvec4.data,<float *>fvec1.data,<float *>fvec2.data))
 *             csub_3vecs(<float *>fvec4.data,<float *>fvec3.data,tmp)             # <<<<<<<<<<<<<<
 *             cost_nopar += dpy_log2(cinner_3vecs(tmp,tmp))
 *         cost_nopar /= 2
 */
      __pyx_f_4dipy_8tracking_9distances_csub_3vecs(((float *)__pyx_v_fvec4->data), ((float *)__pyx_v_fvec3->data), __pyx_v_tmp);

      /* "dipy/tracking/distances.pyx":1145
 *             cost_par += dpy_log2(clee_angle_distance(<float *>fvec3.data,<float *>fvec4.data,<float *>fvec1.data,<float *>fvec2.data))
 *             csub_3vecs(<float *>fvec4.data,<float *>fvec3.data,tmp)
 *             cost_nopar += dpy_log2(cinner_3vecs(tmp,tmp))             # <<<<<<<<<<<<<<
 *         cost_nopar /= 2
 *         #print cost_par, cost_nopar, start_index,length
 */
      __pyx_v_cost_nopar = (__pyx_v_cost_nopar + dpy_log2(__pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_tmp, __pyx_v_tmp)));
    }

    /* "dipy/tracking/distances.pyx":1146
 *             csub_3vecs(<float *>fvec4.data,<float *>fvec3.data,tmp)
 *             cost_nopar += dpy_log2(cinner_3vecs(tmp,tmp))
 *         cost_nopar /= 2             # <<<<<<<<<<<<<<
 *         #print cost_par, cost_nopar, start_index,length
 *         if alphac*cost_par>cost_nopar:
 */
    __pyx_v_cost_nopar = (__pyx_v_cost_nopar / 2.0);

    /* "dipy/tracking/distances.pyx":1148
 *         cost_nopar /= 2
 *         #print cost_par, cost_nopar, start_index,length
 *         if alphac*cost_par>cost_nopar:             # <<<<<<<<<<<<<<
 *             characteristic_points.append(track[current_index-1])
 *             start_index = current_index-1
 */
    __pyx_t_12 = (((__pyx_v_alphac * __pyx_v_cost_par) > __pyx_v_cost_nopar) != 0);
    if (__pyx_t_12) {

      /* "dipy/tracking/distances.pyx":1149
 *         #print cost_par, cost_nopar, start_index,length
 *         if alphac*cost_par>cost_nopar:
 *             characteristic_points.append(track[current_index-1])             # <<<<<<<<<<<<<<
 *             start_index = current_index-1
 *             length = 2
 */
      __pyx_t_13 = (__pyx_v_current_index - 1);
      __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), __pyx_t_13, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1149; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_16 = __Pyx_PyObject_Append(__pyx_v_characteristic_points, __pyx_t_3); if (unlikely(__pyx_t_16 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "dipy/tracking/distances.pyx":1150
 *         if alphac*cost_par>cost_nopar:
 *             characteristic_points.append(track[current_index-1])
 *             start_index = current_index-1             # <<<<<<<<<<<<<<
 *             length = 2
 *         else:
 */
      __pyx_v_start_index = (__pyx_v_current_index - 1);

      /* "dipy/tracking/distances.pyx":1151
 *             characteristic_points.append(track[current_index-1])
 *             start_index = current_index-1
 *             length = 2             # <<<<<<<<<<<<<<
 *         else:
 *             length+=1
 */
      __pyx_v_length = 2;

      /* "dipy/tracking/distances.pyx":1148
 *         cost_nopar /= 2
 *         #print cost_par, cost_nopar, start_index,length
 *         if alphac*cost_par>cost_nopar:             # <<<<<<<<<<<<<<
 *             characteristic_points.append(track[current_index-1])
 *             start_index = current_index-1
 */
      goto __pyx_L7;
    }

    /* "dipy/tracking/distances.pyx":1153
 *             length = 2
 *         else:
 *             length+=1             # <<<<<<<<<<<<<<
 *     characteristic_points.append(track[-1])
 *     return np.array(characteristic_points)
 */
    /*else*/ {
      __pyx_v_length = (__pyx_v_length + 1);
    }
    __pyx_L7:;
  }

  /* "dipy/tracking/distances.pyx":1154
 *         else:
 *             length+=1
 *     characteristic_points.append(track[-1])             # <<<<<<<<<<<<<<
 *     return np.array(characteristic_points)
 * 
 */
  __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1154; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_16 = __Pyx_PyObject_Append(__pyx_v_characteristic_points, __pyx_t_3); if (unlikely(__pyx_t_16 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1154; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":1155
 *             length+=1
 *     characteristic_points.append(track[-1])
 *     return np.array(characteristic_points)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_array); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (!__pyx_t_4) {
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_characteristic_points); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
  } else {
    __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __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 = NULL;
    __Pyx_INCREF(__pyx_v_characteristic_points);
    __Pyx_GIVEREF(__pyx_v_characteristic_points);
    PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_characteristic_points);
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":1091
 * 
 * 
 * def approximate_mdl_trajectory(xyz, alpha=1.):             # <<<<<<<<<<<<<<
 *     ''' Implementation of Lee et al Approximate Trajectory
 *     Partitioning Algorithm
 */

  /* 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);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec3.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec4.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.approximate_mdl_trajectory", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec1.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec2.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec3.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_fvec4.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_characteristic_points);
  __Pyx_XDECREF((PyObject *)__pyx_v_track);
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec1);
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec2);
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec3);
  __Pyx_XDECREF((PyObject *)__pyx_v_fvec4);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":1158
 * 
 * 
 * def intersect_segment_cylinder(sa,sb,p,q,r):             # <<<<<<<<<<<<<<
 *     ''' Intersect Segment S(t) = sa +t(sb-sa), 0 <=t<= 1 against cylinder specified by p,q and r
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_35intersect_segment_cylinder(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_34intersect_segment_cylinder[] = " Intersect Segment S(t) = sa +t(sb-sa), 0 <=t<= 1 against cylinder specified by p,q and r\n\n    See p.197 from Real Time Collision Detection by C. Ericson\n\n    Examples\n    --------\n    Define cylinder using a segment defined by\n\n    >>> p=np.array([0,0,0],dtype=np.float32)\n    >>> q=np.array([1,0,0],dtype=np.float32)\n    >>> r=0.5\n\n    Define segment\n\n    >>> sa=np.array([0.5,1 ,0],dtype=np.float32)\n    >>> sb=np.array([0.5,-1,0],dtype=np.float32)\n\n    Intersection\n\n    >>> intersect_segment_cylinder(sa, sb, p, q, r)\n    (1.0, 0.25, 0.75)\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_35intersect_segment_cylinder = {"intersect_segment_cylinder", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_35intersect_segment_cylinder, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_34intersect_segment_cylinder};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_35intersect_segment_cylinder(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_sa = 0;
  PyObject *__pyx_v_sb = 0;
  PyObject *__pyx_v_p = 0;
  PyObject *__pyx_v_q = 0;
  PyObject *__pyx_v_r = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("intersect_segment_cylinder (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_sa,&__pyx_n_s_sb,&__pyx_n_s_p,&__pyx_n_s_q,&__pyx_n_s_r,0};
    PyObject* values[5] = {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  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sa)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sb)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("intersect_segment_cylinder", 1, 5, 5, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1158; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_p)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("intersect_segment_cylinder", 1, 5, 5, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1158; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_q)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("intersect_segment_cylinder", 1, 5, 5, 3); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1158; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  4:
        if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_r)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("intersect_segment_cylinder", 1, 5, 5, 4); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1158; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "intersect_segment_cylinder") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1158; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 5) {
      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);
    }
    __pyx_v_sa = values[0];
    __pyx_v_sb = values[1];
    __pyx_v_p = values[2];
    __pyx_v_q = values[3];
    __pyx_v_r = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("intersect_segment_cylinder", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1158; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.intersect_segment_cylinder", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_34intersect_segment_cylinder(__pyx_self, __pyx_v_sa, __pyx_v_sb, __pyx_v_p, __pyx_v_q, __pyx_v_r);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_34intersect_segment_cylinder(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_sa, PyObject *__pyx_v_sb, PyObject *__pyx_v_p, PyObject *__pyx_v_q, PyObject *__pyx_v_r) {
  float *__pyx_v_csa;
  float *__pyx_v_csb;
  float *__pyx_v_cp;
  float *__pyx_v_cq;
  float __pyx_v_cr;
  float __pyx_v_ct[2];
  PyObject *__pyx_v_tmp = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  float __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("intersect_segment_cylinder", 0);

  /* "dipy/tracking/distances.pyx":1186
 *         float ct[2]
 * 
 *     csa = asfp(sa)             # <<<<<<<<<<<<<<
 *     csb = asfp(sb)
 *     cp = asfp(p)
 */
  if (!(likely(((__pyx_v_sa) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_sa, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1186; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_csa = __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_v_sa));

  /* "dipy/tracking/distances.pyx":1187
 * 
 *     csa = asfp(sa)
 *     csb = asfp(sb)             # <<<<<<<<<<<<<<
 *     cp = asfp(p)
 *     cq = asfp(q)
 */
  if (!(likely(((__pyx_v_sb) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_sb, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_csb = __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_v_sb));

  /* "dipy/tracking/distances.pyx":1188
 *     csa = asfp(sa)
 *     csb = asfp(sb)
 *     cp = asfp(p)             # <<<<<<<<<<<<<<
 *     cq = asfp(q)
 *     cr=r
 */
  if (!(likely(((__pyx_v_p) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_p, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1188; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_cp = __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_v_p));

  /* "dipy/tracking/distances.pyx":1189
 *     csb = asfp(sb)
 *     cp = asfp(p)
 *     cq = asfp(q)             # <<<<<<<<<<<<<<
 *     cr=r
 *     ct[0]=-100
 */
  if (!(likely(((__pyx_v_q) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_q, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1189; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_cq = __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_v_q));

  /* "dipy/tracking/distances.pyx":1190
 *     cp = asfp(p)
 *     cq = asfp(q)
 *     cr=r             # <<<<<<<<<<<<<<
 *     ct[0]=-100
 *     ct[1]=-100
 */
  __pyx_t_1 = __pyx_PyFloat_AsFloat(__pyx_v_r); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_cr = __pyx_t_1;

  /* "dipy/tracking/distances.pyx":1191
 *     cq = asfp(q)
 *     cr=r
 *     ct[0]=-100             # <<<<<<<<<<<<<<
 *     ct[1]=-100
 * 
 */
  (__pyx_v_ct[0]) = -100.0;

  /* "dipy/tracking/distances.pyx":1192
 *     cr=r
 *     ct[0]=-100
 *     ct[1]=-100             # <<<<<<<<<<<<<<
 * 
 *     tmp = cintersect_segment_cylinder(csa,csb,cp, cq, cr, ct)
 */
  (__pyx_v_ct[1]) = -100.0;

  /* "dipy/tracking/distances.pyx":1194
 *     ct[1]=-100
 * 
 *     tmp = cintersect_segment_cylinder(csa,csb,cp, cq, cr, ct)             # <<<<<<<<<<<<<<
 * 
 *     return tmp, ct[0], ct[1]
 */
  __pyx_t_2 = PyFloat_FromDouble(__pyx_f_4dipy_8tracking_9distances_cintersect_segment_cylinder(__pyx_v_csa, __pyx_v_csb, __pyx_v_cp, __pyx_v_cq, __pyx_v_cr, __pyx_v_ct)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1194; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_tmp = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "dipy/tracking/distances.pyx":1196
 *     tmp = cintersect_segment_cylinder(csa,csb,cp, cq, cr, ct)
 * 
 *     return tmp, ct[0], ct[1]             # <<<<<<<<<<<<<<
 * 
 * cdef float cintersect_segment_cylinder(float *sa,float *sb,float *p, float *q, float r, float *t):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyFloat_FromDouble((__pyx_v_ct[0])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyFloat_FromDouble((__pyx_v_ct[1])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1196; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_tmp);
  __Pyx_GIVEREF(__pyx_v_tmp);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_tmp);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3);
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  __pyx_r = __pyx_t_4;
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":1158
 * 
 * 
 * def intersect_segment_cylinder(sa,sb,p,q,r):             # <<<<<<<<<<<<<<
 *     ''' Intersect Segment S(t) = sa +t(sb-sa), 0 <=t<= 1 against cylinder specified by p,q and r
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("dipy.tracking.distances.intersect_segment_cylinder", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_tmp);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":1198
 *     return tmp, ct[0], ct[1]
 * 
 * cdef float cintersect_segment_cylinder(float *sa,float *sb,float *p, float *q, float r, float *t):             # <<<<<<<<<<<<<<
 *     ''' Intersect Segment S(t) = sa +t(sb-sa), 0 <=t<= 1 against cylinder specified by p,q and r
 * 
 */

static float __pyx_f_4dipy_8tracking_9distances_cintersect_segment_cylinder(float *__pyx_v_sa, float *__pyx_v_sb, float *__pyx_v_p, float *__pyx_v_q, float __pyx_v_r, float *__pyx_v_t) {
  float __pyx_v_d[3];
  float __pyx_v_m[3];
  float __pyx_v_n[3];
  float __pyx_v_md;
  float __pyx_v_nd;
  float __pyx_v_dd;
  float __pyx_v_nn;
  float __pyx_v_mn;
  float __pyx_v_a;
  float __pyx_v_k;
  float __pyx_v_c;
  float __pyx_v_b;
  float __pyx_v_discr;
  float __pyx_v_epsilon_float;
  float __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  float __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("cintersect_segment_cylinder", 0);

  /* "dipy/tracking/distances.pyx":1213
 *         float md,nd,dd, nn, mn, a, k, c,b, discr
 * 
 *         float epsilon_float=5.96e-08             # <<<<<<<<<<<<<<
 * 
 *     csub_3vecs(q,p,d)
 */
  __pyx_v_epsilon_float = 5.96e-08;

  /* "dipy/tracking/distances.pyx":1215
 *         float epsilon_float=5.96e-08
 * 
 *     csub_3vecs(q,p,d)             # <<<<<<<<<<<<<<
 *     csub_3vecs(sa,p,m)
 *     csub_3vecs(sb,sa,n)
 */
  __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_q, __pyx_v_p, __pyx_v_d);

  /* "dipy/tracking/distances.pyx":1216
 * 
 *     csub_3vecs(q,p,d)
 *     csub_3vecs(sa,p,m)             # <<<<<<<<<<<<<<
 *     csub_3vecs(sb,sa,n)
 * 
 */
  __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_sa, __pyx_v_p, __pyx_v_m);

  /* "dipy/tracking/distances.pyx":1217
 *     csub_3vecs(q,p,d)
 *     csub_3vecs(sa,p,m)
 *     csub_3vecs(sb,sa,n)             # <<<<<<<<<<<<<<
 * 
 *     md=cinner_3vecs(m,d)
 */
  __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_sb, __pyx_v_sa, __pyx_v_n);

  /* "dipy/tracking/distances.pyx":1219
 *     csub_3vecs(sb,sa,n)
 * 
 *     md=cinner_3vecs(m,d)             # <<<<<<<<<<<<<<
 *     nd=cinner_3vecs(n,d)
 *     dd=cinner_3vecs(d,d)
 */
  __pyx_v_md = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_m, __pyx_v_d);

  /* "dipy/tracking/distances.pyx":1220
 * 
 *     md=cinner_3vecs(m,d)
 *     nd=cinner_3vecs(n,d)             # <<<<<<<<<<<<<<
 *     dd=cinner_3vecs(d,d)
 * 
 */
  __pyx_v_nd = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_n, __pyx_v_d);

  /* "dipy/tracking/distances.pyx":1221
 *     md=cinner_3vecs(m,d)
 *     nd=cinner_3vecs(n,d)
 *     dd=cinner_3vecs(d,d)             # <<<<<<<<<<<<<<
 * 
 *     #test if segment fully outside either endcap of cylinder
 */
  __pyx_v_dd = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_d, __pyx_v_d);

  /* "dipy/tracking/distances.pyx":1224
 * 
 *     #test if segment fully outside either endcap of cylinder
 *     if md < 0. and md + nd < 0.:  return 0 #segment outside p side             # <<<<<<<<<<<<<<
 *     if md > dd and md + nd > dd:  return 0 #segment outside q side
 * 
 */
  __pyx_t_2 = ((__pyx_v_md < 0.) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_2 = (((__pyx_v_md + __pyx_v_nd) < 0.) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_1) {
    __pyx_r = 0.0;
    goto __pyx_L0;
  }

  /* "dipy/tracking/distances.pyx":1225
 *     #test if segment fully outside either endcap of cylinder
 *     if md < 0. and md + nd < 0.:  return 0 #segment outside p side
 *     if md > dd and md + nd > dd:  return 0 #segment outside q side             # <<<<<<<<<<<<<<
 * 
 *     nn=cinner_3vecs(n,n)
 */
  __pyx_t_2 = ((__pyx_v_md > __pyx_v_dd) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L7_bool_binop_done;
  }
  __pyx_t_2 = (((__pyx_v_md + __pyx_v_nd) > __pyx_v_dd) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L7_bool_binop_done:;
  if (__pyx_t_1) {
    __pyx_r = 0.0;
    goto __pyx_L0;
  }

  /* "dipy/tracking/distances.pyx":1227
 *     if md > dd and md + nd > dd:  return 0 #segment outside q side
 * 
 *     nn=cinner_3vecs(n,n)             # <<<<<<<<<<<<<<
 *     mn=cinner_3vecs(m,n)
 *     a=dd*nn-nd*nd
 */
  __pyx_v_nn = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_n, __pyx_v_n);

  /* "dipy/tracking/distances.pyx":1228
 * 
 *     nn=cinner_3vecs(n,n)
 *     mn=cinner_3vecs(m,n)             # <<<<<<<<<<<<<<
 *     a=dd*nn-nd*nd
 *     k=cinner_3vecs(m,m) -r*r
 */
  __pyx_v_mn = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_m, __pyx_v_n);

  /* "dipy/tracking/distances.pyx":1229
 *     nn=cinner_3vecs(n,n)
 *     mn=cinner_3vecs(m,n)
 *     a=dd*nn-nd*nd             # <<<<<<<<<<<<<<
 *     k=cinner_3vecs(m,m) -r*r
 *     c=dd*k-md*md
 */
  __pyx_v_a = ((__pyx_v_dd * __pyx_v_nn) - (__pyx_v_nd * __pyx_v_nd));

  /* "dipy/tracking/distances.pyx":1230
 *     mn=cinner_3vecs(m,n)
 *     a=dd*nn-nd*nd
 *     k=cinner_3vecs(m,m) -r*r             # <<<<<<<<<<<<<<
 *     c=dd*k-md*md
 * 
 */
  __pyx_v_k = (__pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_m, __pyx_v_m) - (__pyx_v_r * __pyx_v_r));

  /* "dipy/tracking/distances.pyx":1231
 *     a=dd*nn-nd*nd
 *     k=cinner_3vecs(m,m) -r*r
 *     c=dd*k-md*md             # <<<<<<<<<<<<<<
 * 
 *     if fabs(a) < epsilon_float:
 */
  __pyx_v_c = ((__pyx_v_dd * __pyx_v_k) - (__pyx_v_md * __pyx_v_md));

  /* "dipy/tracking/distances.pyx":1233
 *     c=dd*k-md*md
 * 
 *     if fabs(a) < epsilon_float:             # <<<<<<<<<<<<<<
 *         #segment runs parallel to cylinder axis
 *         if c>0.:  return 0. # segment lies outside cylinder
 */
  __pyx_t_1 = ((fabs(__pyx_v_a) < __pyx_v_epsilon_float) != 0);
  if (__pyx_t_1) {

    /* "dipy/tracking/distances.pyx":1235
 *     if fabs(a) < epsilon_float:
 *         #segment runs parallel to cylinder axis
 *         if c>0.:  return 0. # segment lies outside cylinder             # <<<<<<<<<<<<<<
 *         if md < 0.:
 *             t[0]=-mn/nn # intersect against p endcap
 */
    __pyx_t_1 = ((__pyx_v_c > 0.) != 0);
    if (__pyx_t_1) {
      __pyx_r = 0.;
      goto __pyx_L0;
    }

    /* "dipy/tracking/distances.pyx":1236
 *         #segment runs parallel to cylinder axis
 *         if c>0.:  return 0. # segment lies outside cylinder
 *         if md < 0.:             # <<<<<<<<<<<<<<
 *             t[0]=-mn/nn # intersect against p endcap
 *         elif md > dd :
 */
    __pyx_t_1 = ((__pyx_v_md < 0.) != 0);
    if (__pyx_t_1) {

      /* "dipy/tracking/distances.pyx":1237
 *         if c>0.:  return 0. # segment lies outside cylinder
 *         if md < 0.:
 *             t[0]=-mn/nn # intersect against p endcap             # <<<<<<<<<<<<<<
 *         elif md > dd :
 *             t[0]=(nd-mn)/nn # intersect against q endcap
 */
      __pyx_t_3 = (-__pyx_v_mn);
      if (unlikely(__pyx_v_nn == 0)) {
        PyErr_SetString(PyExc_ZeroDivisionError, "float division");
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1237; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      (__pyx_v_t[0]) = (__pyx_t_3 / __pyx_v_nn);

      /* "dipy/tracking/distances.pyx":1236
 *         #segment runs parallel to cylinder axis
 *         if c>0.:  return 0. # segment lies outside cylinder
 *         if md < 0.:             # <<<<<<<<<<<<<<
 *             t[0]=-mn/nn # intersect against p endcap
 *         elif md > dd :
 */
      goto __pyx_L11;
    }

    /* "dipy/tracking/distances.pyx":1238
 *         if md < 0.:
 *             t[0]=-mn/nn # intersect against p endcap
 *         elif md > dd :             # <<<<<<<<<<<<<<
 *             t[0]=(nd-mn)/nn # intersect against q endcap
 *         else:
 */
    __pyx_t_1 = ((__pyx_v_md > __pyx_v_dd) != 0);
    if (__pyx_t_1) {

      /* "dipy/tracking/distances.pyx":1239
 *             t[0]=-mn/nn # intersect against p endcap
 *         elif md > dd :
 *             t[0]=(nd-mn)/nn # intersect against q endcap             # <<<<<<<<<<<<<<
 *         else:
 *             t[0]=0. # lies inside cylinder
 */
      __pyx_t_3 = (__pyx_v_nd - __pyx_v_mn);
      if (unlikely(__pyx_v_nn == 0)) {
        PyErr_SetString(PyExc_ZeroDivisionError, "float division");
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1239; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      (__pyx_v_t[0]) = (__pyx_t_3 / __pyx_v_nn);

      /* "dipy/tracking/distances.pyx":1238
 *         if md < 0.:
 *             t[0]=-mn/nn # intersect against p endcap
 *         elif md > dd :             # <<<<<<<<<<<<<<
 *             t[0]=(nd-mn)/nn # intersect against q endcap
 *         else:
 */
      goto __pyx_L11;
    }

    /* "dipy/tracking/distances.pyx":1241
 *             t[0]=(nd-mn)/nn # intersect against q endcap
 *         else:
 *             t[0]=0. # lies inside cylinder             # <<<<<<<<<<<<<<
 *         return 1
 * 
 */
    /*else*/ {
      (__pyx_v_t[0]) = 0.;
    }
    __pyx_L11:;

    /* "dipy/tracking/distances.pyx":1242
 *         else:
 *             t[0]=0. # lies inside cylinder
 *         return 1             # <<<<<<<<<<<<<<
 * 
 *     b=dd*mn -nd*md
 */
    __pyx_r = 1.0;
    goto __pyx_L0;

    /* "dipy/tracking/distances.pyx":1233
 *     c=dd*k-md*md
 * 
 *     if fabs(a) < epsilon_float:             # <<<<<<<<<<<<<<
 *         #segment runs parallel to cylinder axis
 *         if c>0.:  return 0. # segment lies outside cylinder
 */
  }

  /* "dipy/tracking/distances.pyx":1244
 *         return 1
 * 
 *     b=dd*mn -nd*md             # <<<<<<<<<<<<<<
 *     discr=b*b-a*c
 *     if discr < 0.: return 0. # no real roots ; no intersection
 */
  __pyx_v_b = ((__pyx_v_dd * __pyx_v_mn) - (__pyx_v_nd * __pyx_v_md));

  /* "dipy/tracking/distances.pyx":1245
 * 
 *     b=dd*mn -nd*md
 *     discr=b*b-a*c             # <<<<<<<<<<<<<<
 *     if discr < 0.: return 0. # no real roots ; no intersection
 * 
 */
  __pyx_v_discr = ((__pyx_v_b * __pyx_v_b) - (__pyx_v_a * __pyx_v_c));

  /* "dipy/tracking/distances.pyx":1246
 *     b=dd*mn -nd*md
 *     discr=b*b-a*c
 *     if discr < 0.: return 0. # no real roots ; no intersection             # <<<<<<<<<<<<<<
 * 
 *     t[0]=(-b-sqrt(discr))/a
 */
  __pyx_t_1 = ((__pyx_v_discr < 0.) != 0);
  if (__pyx_t_1) {
    __pyx_r = 0.;
    goto __pyx_L0;
  }

  /* "dipy/tracking/distances.pyx":1248
 *     if discr < 0.: return 0. # no real roots ; no intersection
 * 
 *     t[0]=(-b-sqrt(discr))/a             # <<<<<<<<<<<<<<
 *     t[1]=(-b+sqrt(discr))/a
 *     if t[0]<0. or t[0] > 1. : return 0. # intersection lies outside segment
 */
  __pyx_t_3 = ((-__pyx_v_b) - sqrt(__pyx_v_discr));
  if (unlikely(__pyx_v_a == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1248; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  (__pyx_v_t[0]) = (__pyx_t_3 / __pyx_v_a);

  /* "dipy/tracking/distances.pyx":1249
 * 
 *     t[0]=(-b-sqrt(discr))/a
 *     t[1]=(-b+sqrt(discr))/a             # <<<<<<<<<<<<<<
 *     if t[0]<0. or t[0] > 1. : return 0. # intersection lies outside segment
 * 
 */
  __pyx_t_3 = ((-__pyx_v_b) + sqrt(__pyx_v_discr));
  if (unlikely(__pyx_v_a == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "float division");
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1249; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  (__pyx_v_t[1]) = (__pyx_t_3 / __pyx_v_a);

  /* "dipy/tracking/distances.pyx":1250
 *     t[0]=(-b-sqrt(discr))/a
 *     t[1]=(-b+sqrt(discr))/a
 *     if t[0]<0. or t[0] > 1. : return 0. # intersection lies outside segment             # <<<<<<<<<<<<<<
 * 
 *     if md + t[0]* nd < 0.:
 */
  __pyx_t_2 = (((__pyx_v_t[0]) < 0.) != 0);
  if (!__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L14_bool_binop_done;
  }
  __pyx_t_2 = (((__pyx_v_t[0]) > 1.) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L14_bool_binop_done:;
  if (__pyx_t_1) {
    __pyx_r = 0.;
    goto __pyx_L0;
  }

  /* "dipy/tracking/distances.pyx":1252
 *     if t[0]<0. or t[0] > 1. : return 0. # intersection lies outside segment
 * 
 *     if md + t[0]* nd < 0.:             # <<<<<<<<<<<<<<
 *         #intersection outside cylinder on 'p' side
 *         if nd <= 0. : return 0. # segment pointing away from endcap
 */
  __pyx_t_1 = (((__pyx_v_md + ((__pyx_v_t[0]) * __pyx_v_nd)) < 0.) != 0);
  if (__pyx_t_1) {

    /* "dipy/tracking/distances.pyx":1254
 *     if md + t[0]* nd < 0.:
 *         #intersection outside cylinder on 'p' side
 *         if nd <= 0. : return 0. # segment pointing away from endcap             # <<<<<<<<<<<<<<
 *         t[0]=-md/nd
 *         #keep intersection if Dot(S(t)-p,S(t)-p) <= r^2
 */
    __pyx_t_1 = ((__pyx_v_nd <= 0.) != 0);
    if (__pyx_t_1) {
      __pyx_r = 0.;
      goto __pyx_L0;
    }

    /* "dipy/tracking/distances.pyx":1255
 *         #intersection outside cylinder on 'p' side
 *         if nd <= 0. : return 0. # segment pointing away from endcap
 *         t[0]=-md/nd             # <<<<<<<<<<<<<<
 *         #keep intersection if Dot(S(t)-p,S(t)-p) <= r^2
 *         if k+2*t[0]*(mn+t[0]*nn) <=0.:
 */
    __pyx_t_3 = (-__pyx_v_md);
    if (unlikely(__pyx_v_nd == 0)) {
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1255; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    (__pyx_v_t[0]) = (__pyx_t_3 / __pyx_v_nd);

    /* "dipy/tracking/distances.pyx":1257
 *         t[0]=-md/nd
 *         #keep intersection if Dot(S(t)-p,S(t)-p) <= r^2
 *         if k+2*t[0]*(mn+t[0]*nn) <=0.:             # <<<<<<<<<<<<<<
 *             return 1.
 * 
 */
    __pyx_t_1 = (((__pyx_v_k + ((2.0 * (__pyx_v_t[0])) * (__pyx_v_mn + ((__pyx_v_t[0]) * __pyx_v_nn)))) <= 0.) != 0);
    if (__pyx_t_1) {

      /* "dipy/tracking/distances.pyx":1258
 *         #keep intersection if Dot(S(t)-p,S(t)-p) <= r^2
 *         if k+2*t[0]*(mn+t[0]*nn) <=0.:
 *             return 1.             # <<<<<<<<<<<<<<
 * 
 *     elif md+t[0]*nd > dd :
 */
      __pyx_r = 1.;
      goto __pyx_L0;

      /* "dipy/tracking/distances.pyx":1257
 *         t[0]=-md/nd
 *         #keep intersection if Dot(S(t)-p,S(t)-p) <= r^2
 *         if k+2*t[0]*(mn+t[0]*nn) <=0.:             # <<<<<<<<<<<<<<
 *             return 1.
 * 
 */
    }

    /* "dipy/tracking/distances.pyx":1252
 *     if t[0]<0. or t[0] > 1. : return 0. # intersection lies outside segment
 * 
 *     if md + t[0]* nd < 0.:             # <<<<<<<<<<<<<<
 *         #intersection outside cylinder on 'p' side
 *         if nd <= 0. : return 0. # segment pointing away from endcap
 */
    goto __pyx_L16;
  }

  /* "dipy/tracking/distances.pyx":1260
 *             return 1.
 * 
 *     elif md+t[0]*nd > dd :             # <<<<<<<<<<<<<<
 *         #intersection outside cylinder on 'q' side
 *         if nd >= 0.: return 0. # segment pointing away from endcap
 */
  __pyx_t_1 = (((__pyx_v_md + ((__pyx_v_t[0]) * __pyx_v_nd)) > __pyx_v_dd) != 0);
  if (__pyx_t_1) {

    /* "dipy/tracking/distances.pyx":1262
 *     elif md+t[0]*nd > dd :
 *         #intersection outside cylinder on 'q' side
 *         if nd >= 0.: return 0. # segment pointing away from endcap             # <<<<<<<<<<<<<<
 *         t[0]= (dd-md)/nd
 *         #keep intersection if Dot(S(t)-q,S(t)-q) <= r^2
 */
    __pyx_t_1 = ((__pyx_v_nd >= 0.) != 0);
    if (__pyx_t_1) {
      __pyx_r = 0.;
      goto __pyx_L0;
    }

    /* "dipy/tracking/distances.pyx":1263
 *         #intersection outside cylinder on 'q' side
 *         if nd >= 0.: return 0. # segment pointing away from endcap
 *         t[0]= (dd-md)/nd             # <<<<<<<<<<<<<<
 *         #keep intersection if Dot(S(t)-q,S(t)-q) <= r^2
 *         if k+dd-2*md+t[0]*(2*(mn-nd)+t[0]*nn) <= 0.:
 */
    __pyx_t_3 = (__pyx_v_dd - __pyx_v_md);
    if (unlikely(__pyx_v_nd == 0)) {
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1263; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    (__pyx_v_t[0]) = (__pyx_t_3 / __pyx_v_nd);

    /* "dipy/tracking/distances.pyx":1265
 *         t[0]= (dd-md)/nd
 *         #keep intersection if Dot(S(t)-q,S(t)-q) <= r^2
 *         if k+dd-2*md+t[0]*(2*(mn-nd)+t[0]*nn) <= 0.:             # <<<<<<<<<<<<<<
 *             return 1.
 *     # segment intersects cylinder between the endcaps; t is correct
 */
    __pyx_t_1 = (((((__pyx_v_k + __pyx_v_dd) - (2.0 * __pyx_v_md)) + ((__pyx_v_t[0]) * ((2.0 * (__pyx_v_mn - __pyx_v_nd)) + ((__pyx_v_t[0]) * __pyx_v_nn)))) <= 0.) != 0);
    if (__pyx_t_1) {

      /* "dipy/tracking/distances.pyx":1266
 *         #keep intersection if Dot(S(t)-q,S(t)-q) <= r^2
 *         if k+dd-2*md+t[0]*(2*(mn-nd)+t[0]*nn) <= 0.:
 *             return 1.             # <<<<<<<<<<<<<<
 *     # segment intersects cylinder between the endcaps; t is correct
 *     return 1.
 */
      __pyx_r = 1.;
      goto __pyx_L0;

      /* "dipy/tracking/distances.pyx":1265
 *         t[0]= (dd-md)/nd
 *         #keep intersection if Dot(S(t)-q,S(t)-q) <= r^2
 *         if k+dd-2*md+t[0]*(2*(mn-nd)+t[0]*nn) <= 0.:             # <<<<<<<<<<<<<<
 *             return 1.
 *     # segment intersects cylinder between the endcaps; t is correct
 */
    }

    /* "dipy/tracking/distances.pyx":1260
 *             return 1.
 * 
 *     elif md+t[0]*nd > dd :             # <<<<<<<<<<<<<<
 *         #intersection outside cylinder on 'q' side
 *         if nd >= 0.: return 0. # segment pointing away from endcap
 */
  }
  __pyx_L16:;

  /* "dipy/tracking/distances.pyx":1268
 *             return 1.
 *     # segment intersects cylinder between the endcaps; t is correct
 *     return 1.             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = 1.;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":1198
 *     return tmp, ct[0], ct[1]
 * 
 * cdef float cintersect_segment_cylinder(float *sa,float *sb,float *p, float *q, float r, float *t):             # <<<<<<<<<<<<<<
 *     ''' Intersect Segment S(t) = sa +t(sb-sa), 0 <=t<= 1 against cylinder specified by p,q and r
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("dipy.tracking.distances.cintersect_segment_cylinder", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":1271
 * 
 * 
 * def point_segment_sq_distance(a, b, c):             # <<<<<<<<<<<<<<
 *     ''' Calculate the squared distance from a point c to a finite line segment ab.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_37point_segment_sq_distance(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_36point_segment_sq_distance[] = " Calculate the squared distance from a point c to a finite line segment ab.\n\n    Examples\n    --------\n    >>> a=np.array([0,0,0], dtype=np.float32)\n    >>> b=np.array([1,0,0], dtype=np.float32)\n    >>> c=np.array([0,1,0], dtype=np.float32)\n    >>> point_segment_sq_distance(a, b, c)\n    1.0\n    >>> c = np.array([0,3,0], dtype=np.float32)\n    >>> point_segment_sq_distance(a,b,c)\n    9.0\n    >>> c = np.array([-1,1,0], dtype=np.float32)\n    >>> point_segment_sq_distance(a, b, c)\n    2.0\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_37point_segment_sq_distance = {"point_segment_sq_distance", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_37point_segment_sq_distance, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_36point_segment_sq_distance};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_37point_segment_sq_distance(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_a = 0;
  PyObject *__pyx_v_b = 0;
  PyObject *__pyx_v_c = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("point_segment_sq_distance (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_a,&__pyx_n_s_b,&__pyx_n_s_c,0};
    PyObject* values[3] = {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  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_a)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_b)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("point_segment_sq_distance", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1271; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_c)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("point_segment_sq_distance", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1271; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "point_segment_sq_distance") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1271; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      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);
    }
    __pyx_v_a = values[0];
    __pyx_v_b = values[1];
    __pyx_v_c = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("point_segment_sq_distance", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1271; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.point_segment_sq_distance", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_36point_segment_sq_distance(__pyx_self, __pyx_v_a, __pyx_v_b, __pyx_v_c);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_36point_segment_sq_distance(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c) {
  float *__pyx_v_ca;
  float *__pyx_v_cb;
  float *__pyx_v_cc;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("point_segment_sq_distance", 0);

  /* "dipy/tracking/distances.pyx":1293
 *         float ct[2]
 * 
 *     ca = asfp(a)             # <<<<<<<<<<<<<<
 *     cb = asfp(b)
 *     cc = asfp(c)
 */
  if (!(likely(((__pyx_v_a) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_a, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1293; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_ca = __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_v_a));

  /* "dipy/tracking/distances.pyx":1294
 * 
 *     ca = asfp(a)
 *     cb = asfp(b)             # <<<<<<<<<<<<<<
 *     cc = asfp(c)
 * 
 */
  if (!(likely(((__pyx_v_b) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_b, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1294; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_cb = __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_v_b));

  /* "dipy/tracking/distances.pyx":1295
 *     ca = asfp(a)
 *     cb = asfp(b)
 *     cc = asfp(c)             # <<<<<<<<<<<<<<
 * 
 *     return cpoint_segment_sq_dist(ca, cb, cc)
 */
  if (!(likely(((__pyx_v_c) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_c, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1295; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_cc = __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_v_c));

  /* "dipy/tracking/distances.pyx":1297
 *     cc = asfp(c)
 * 
 *     return cpoint_segment_sq_dist(ca, cb, cc)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyFloat_FromDouble(__pyx_f_4dipy_8tracking_9distances_cpoint_segment_sq_dist(__pyx_v_ca, __pyx_v_cb, __pyx_v_cc)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1297; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":1271
 * 
 * 
 * def point_segment_sq_distance(a, b, c):             # <<<<<<<<<<<<<<
 *     ''' Calculate the squared distance from a point c to a finite line segment ab.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("dipy.tracking.distances.point_segment_sq_distance", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":1301
 * 
 * @cython.cdivision(True)
 * cdef inline float cpoint_segment_sq_dist(float * a, float * b, float * c) nogil:             # <<<<<<<<<<<<<<
 *     ''' Calculate the squared distance from a point c to a line segment ab.
 * 
 */

static CYTHON_INLINE float __pyx_f_4dipy_8tracking_9distances_cpoint_segment_sq_dist(float *__pyx_v_a, float *__pyx_v_b, float *__pyx_v_c) {
  float __pyx_v_ab[3];
  float __pyx_v_ac[3];
  float __pyx_v_bc[3];
  float __pyx_v_e;
  float __pyx_v_f;
  float __pyx_r;
  int __pyx_t_1;

  /* "dipy/tracking/distances.pyx":1309
 *         float e,f
 * 
 *     csub_3vecs(b,a,ab)             # <<<<<<<<<<<<<<
 *     csub_3vecs(c,a,ac)
 *     csub_3vecs(c,b,bc)
 */
  __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_b, __pyx_v_a, __pyx_v_ab);

  /* "dipy/tracking/distances.pyx":1310
 * 
 *     csub_3vecs(b,a,ab)
 *     csub_3vecs(c,a,ac)             # <<<<<<<<<<<<<<
 *     csub_3vecs(c,b,bc)
 * 
 */
  __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_c, __pyx_v_a, __pyx_v_ac);

  /* "dipy/tracking/distances.pyx":1311
 *     csub_3vecs(b,a,ab)
 *     csub_3vecs(c,a,ac)
 *     csub_3vecs(c,b,bc)             # <<<<<<<<<<<<<<
 * 
 *     e = cinner_3vecs(ac, ab)
 */
  __pyx_f_4dipy_8tracking_9distances_csub_3vecs(__pyx_v_c, __pyx_v_b, __pyx_v_bc);

  /* "dipy/tracking/distances.pyx":1313
 *     csub_3vecs(c,b,bc)
 * 
 *     e = cinner_3vecs(ac, ab)             # <<<<<<<<<<<<<<
 *     #Handle cases where c projects outside ab
 *     if e <= 0.:
 */
  __pyx_v_e = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_ac, __pyx_v_ab);

  /* "dipy/tracking/distances.pyx":1315
 *     e = cinner_3vecs(ac, ab)
 *     #Handle cases where c projects outside ab
 *     if e <= 0.:             # <<<<<<<<<<<<<<
 *         return cinner_3vecs(ac, ac)
 *     f = cinner_3vecs(ab, ab)
 */
  __pyx_t_1 = ((__pyx_v_e <= 0.) != 0);
  if (__pyx_t_1) {

    /* "dipy/tracking/distances.pyx":1316
 *     #Handle cases where c projects outside ab
 *     if e <= 0.:
 *         return cinner_3vecs(ac, ac)             # <<<<<<<<<<<<<<
 *     f = cinner_3vecs(ab, ab)
 *     if e >= f :
 */
    __pyx_r = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_ac, __pyx_v_ac);
    goto __pyx_L0;

    /* "dipy/tracking/distances.pyx":1315
 *     e = cinner_3vecs(ac, ab)
 *     #Handle cases where c projects outside ab
 *     if e <= 0.:             # <<<<<<<<<<<<<<
 *         return cinner_3vecs(ac, ac)
 *     f = cinner_3vecs(ab, ab)
 */
  }

  /* "dipy/tracking/distances.pyx":1317
 *     if e <= 0.:
 *         return cinner_3vecs(ac, ac)
 *     f = cinner_3vecs(ab, ab)             # <<<<<<<<<<<<<<
 *     if e >= f :
 *         return cinner_3vecs(bc, bc)
 */
  __pyx_v_f = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_ab, __pyx_v_ab);

  /* "dipy/tracking/distances.pyx":1318
 *         return cinner_3vecs(ac, ac)
 *     f = cinner_3vecs(ab, ab)
 *     if e >= f :             # <<<<<<<<<<<<<<
 *         return cinner_3vecs(bc, bc)
 *     #Handle case where c projects onto ab
 */
  __pyx_t_1 = ((__pyx_v_e >= __pyx_v_f) != 0);
  if (__pyx_t_1) {

    /* "dipy/tracking/distances.pyx":1319
 *     f = cinner_3vecs(ab, ab)
 *     if e >= f :
 *         return cinner_3vecs(bc, bc)             # <<<<<<<<<<<<<<
 *     #Handle case where c projects onto ab
 *     return cinner_3vecs(ac, ac) - e * e / f
 */
    __pyx_r = __pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_bc, __pyx_v_bc);
    goto __pyx_L0;

    /* "dipy/tracking/distances.pyx":1318
 *         return cinner_3vecs(ac, ac)
 *     f = cinner_3vecs(ab, ab)
 *     if e >= f :             # <<<<<<<<<<<<<<
 *         return cinner_3vecs(bc, bc)
 *     #Handle case where c projects onto ab
 */
  }

  /* "dipy/tracking/distances.pyx":1321
 *         return cinner_3vecs(bc, bc)
 *     #Handle case where c projects onto ab
 *     return cinner_3vecs(ac, ac) - e * e / f             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = (__pyx_f_4dipy_8tracking_9distances_cinner_3vecs(__pyx_v_ac, __pyx_v_ac) - ((__pyx_v_e * __pyx_v_e) / __pyx_v_f));
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":1301
 * 
 * @cython.cdivision(True)
 * cdef inline float cpoint_segment_sq_dist(float * a, float * b, float * c) nogil:             # <<<<<<<<<<<<<<
 *     ''' Calculate the squared distance from a point c to a line segment ab.
 * 
 */

  /* function exit code */
  __pyx_L0:;
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":1324
 * 
 * 
 * def track_dist_3pts(tracka,trackb):             # <<<<<<<<<<<<<<
 *     ''' Calculate the euclidean distance between two 3pt tracks
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_39track_dist_3pts(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_38track_dist_3pts[] = " Calculate the euclidean distance between two 3pt tracks\n\n    Both direct and flip distances are calculated but only the smallest is returned\n\n    Parameters\n    ----------\n    a : array, shape (3,3)\n    a three point track\n    b : array, shape (3,3)\n    a three point track\n\n    Returns\n    -------\n    dist :float\n\n    Examples\n    --------\n    >>> a = np.array([[0,0,0],[1,0,0,],[2,0,0]])\n    >>> b = np.array([[3,0,0],[3.5,1,0],[4,2,0]])\n    >>> c = track_dist_3pts(a, b)\n    >>> print('%.6f' % c)\n    2.721573\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_39track_dist_3pts = {"track_dist_3pts", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_39track_dist_3pts, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_38track_dist_3pts};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_39track_dist_3pts(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_tracka = 0;
  PyObject *__pyx_v_trackb = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("track_dist_3pts (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tracka,&__pyx_n_s_trackb,0};
    PyObject* values[2] = {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  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tracka)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_trackb)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("track_dist_3pts", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "track_dist_3pts") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_tracka = values[0];
    __pyx_v_trackb = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("track_dist_3pts", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.track_dist_3pts", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_38track_dist_3pts(__pyx_self, __pyx_v_tracka, __pyx_v_trackb);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_38track_dist_3pts(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tracka, PyObject *__pyx_v_trackb) {
  PyArrayObject *__pyx_v_a = 0;
  PyArrayObject *__pyx_v_b = 0;
  float __pyx_v_d[2];
  __Pyx_LocalBuf_ND __pyx_pybuffernd_a;
  __Pyx_Buffer __pyx_pybuffer_a;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_b;
  __Pyx_Buffer __pyx_pybuffer_b;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyArrayObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("track_dist_3pts", 0);
  __pyx_pybuffer_a.pybuffer.buf = NULL;
  __pyx_pybuffer_a.refcount = 0;
  __pyx_pybuffernd_a.data = NULL;
  __pyx_pybuffernd_a.rcbuffer = &__pyx_pybuffer_a;
  __pyx_pybuffer_b.pybuffer.buf = NULL;
  __pyx_pybuffer_b.refcount = 0;
  __pyx_pybuffernd_b.data = NULL;
  __pyx_pybuffernd_b.rcbuffer = &__pyx_pybuffer_b;

  /* "dipy/tracking/distances.pyx":1352
 *     cdef float d[2]
 * 
 *     a=np.ascontiguousarray(tracka,dtype=f32_dt)             # <<<<<<<<<<<<<<
 *     b=np.ascontiguousarray(trackb,dtype=f32_dt)
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_tracka);
  __Pyx_GIVEREF(__pyx_v_tracka);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_tracka);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_a.rcbuffer->pybuffer);
    __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_a.rcbuffer->pybuffer, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_6 < 0)) {
      PyErr_Fetch(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_a.rcbuffer->pybuffer, (PyObject*)__pyx_v_a, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_7); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_9);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_7, __pyx_t_8, __pyx_t_9);
      }
    }
    __pyx_pybuffernd_a.diminfo[0].strides = __pyx_pybuffernd_a.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_a.diminfo[0].shape = __pyx_pybuffernd_a.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_a.diminfo[1].strides = __pyx_pybuffernd_a.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_a.diminfo[1].shape = __pyx_pybuffernd_a.rcbuffer->pybuffer.shape[1];
    if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_5 = 0;
  __pyx_v_a = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "dipy/tracking/distances.pyx":1353
 * 
 *     a=np.ascontiguousarray(tracka,dtype=f32_dt)
 *     b=np.ascontiguousarray(trackb,dtype=f32_dt)             # <<<<<<<<<<<<<<
 * 
 *     track_direct_flip_3dist(asfp(a[0]),asfp(a[1]),asfp(a[2]),
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_trackb);
  __Pyx_GIVEREF(__pyx_v_trackb);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_trackb);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_b.rcbuffer->pybuffer);
    __pyx_t_6 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_b.rcbuffer->pybuffer, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_6 < 0)) {
      PyErr_Fetch(&__pyx_t_9, &__pyx_t_8, &__pyx_t_7);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_b.rcbuffer->pybuffer, (PyObject*)__pyx_v_b, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_8); Py_XDECREF(__pyx_t_7);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_9, __pyx_t_8, __pyx_t_7);
      }
    }
    __pyx_pybuffernd_b.diminfo[0].strides = __pyx_pybuffernd_b.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_b.diminfo[0].shape = __pyx_pybuffernd_b.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_b.diminfo[1].strides = __pyx_pybuffernd_b.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_b.diminfo[1].shape = __pyx_pybuffernd_b.rcbuffer->pybuffer.shape[1];
    if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1353; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_5 = 0;
  __pyx_v_b = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "dipy/tracking/distances.pyx":1355
 *     b=np.ascontiguousarray(trackb,dtype=f32_dt)
 * 
 *     track_direct_flip_3dist(asfp(a[0]),asfp(a[1]),asfp(a[2]),             # <<<<<<<<<<<<<<
 *                             asfp(b[0]),asfp(b[1]),asfp(b[2]),d)
 * 
 */
  __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_a), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1355; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_2);
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_1 = __Pyx_GetItemInt(((PyObject *)__pyx_v_a), 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1355; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_a), 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1355; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_4);
  if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1355; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":1356
 * 
 *     track_direct_flip_3dist(asfp(a[0]),asfp(a[1]),asfp(a[2]),
 *                             asfp(b[0]),asfp(b[1]),asfp(b[2]),d)             # <<<<<<<<<<<<<<
 * 
 *     if d[0]<d[1]:
 */
  __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_v_b), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_3);
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_10 = __Pyx_GetItemInt(((PyObject *)__pyx_v_b), 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_10 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_10);
  if (!(likely(((__pyx_t_10) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_10, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_11 = __Pyx_GetItemInt(((PyObject *)__pyx_v_b), 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_11 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_11);
  if (!(likely(((__pyx_t_11) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_11, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1356; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":1355
 *     b=np.ascontiguousarray(trackb,dtype=f32_dt)
 * 
 *     track_direct_flip_3dist(asfp(a[0]),asfp(a[1]),asfp(a[2]),             # <<<<<<<<<<<<<<
 *                             asfp(b[0]),asfp(b[1]),asfp(b[2]),d)
 * 
 */
  __pyx_f_4dipy_8tracking_9distances_track_direct_flip_3dist(__pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_2)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_1)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_4)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_3)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_10)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_11)), __pyx_v_d);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

  /* "dipy/tracking/distances.pyx":1358
 *                             asfp(b[0]),asfp(b[1]),asfp(b[2]),d)
 * 
 *     if d[0]<d[1]:             # <<<<<<<<<<<<<<
 *         return d[0]
 *     else:
 */
  __pyx_t_12 = (((__pyx_v_d[0]) < (__pyx_v_d[1])) != 0);
  if (__pyx_t_12) {

    /* "dipy/tracking/distances.pyx":1359
 * 
 *     if d[0]<d[1]:
 *         return d[0]             # <<<<<<<<<<<<<<
 *     else:
 *         return d[1]
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_11 = PyFloat_FromDouble((__pyx_v_d[0])); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1359; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_r = __pyx_t_11;
    __pyx_t_11 = 0;
    goto __pyx_L0;

    /* "dipy/tracking/distances.pyx":1358
 *                             asfp(b[0]),asfp(b[1]),asfp(b[2]),d)
 * 
 *     if d[0]<d[1]:             # <<<<<<<<<<<<<<
 *         return d[0]
 *     else:
 */
  }

  /* "dipy/tracking/distances.pyx":1361
 *         return d[0]
 *     else:
 *         return d[1]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_11 = PyFloat_FromDouble((__pyx_v_d[1])); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1361; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_r = __pyx_t_11;
    __pyx_t_11 = 0;
    goto __pyx_L0;
  }

  /* "dipy/tracking/distances.pyx":1324
 * 
 * 
 * def track_dist_3pts(tracka,trackb):             # <<<<<<<<<<<<<<
 *     ''' Calculate the euclidean distance between two 3pt tracks
 * 
 */

  /* 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_10);
  __Pyx_XDECREF(__pyx_t_11);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_a.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_b.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.track_dist_3pts", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_a.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_b.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_a);
  __Pyx_XDECREF((PyObject *)__pyx_v_b);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":1367
 * @cython.wraparound(False)
 * @cython.cdivision(True)
 * cdef void track_direct_flip_dist(float *a,float *b,long rows,float *out) nogil:             # <<<<<<<<<<<<<<
 *     r''' Direct and flip average distance between two tracks
 * 
 */

static void __pyx_f_4dipy_8tracking_9distances_track_direct_flip_dist(float *__pyx_v_a, float *__pyx_v_b, long __pyx_v_rows, float *__pyx_v_out) {
  long __pyx_v_i;
  long __pyx_v_j;
  float __pyx_v_sub;
  float __pyx_v_subf;
  float __pyx_v_distf;
  float __pyx_v_dist;
  float __pyx_v_tmprow;
  float __pyx_v_tmprowf;
  long __pyx_t_1;

  /* "dipy/tracking/distances.pyx":1405
 *     '''
 *     cdef:
 *         long i=0,j=0             # <<<<<<<<<<<<<<
 *         float sub=0,subf=0,distf=0,dist=0,tmprow=0, tmprowf=0
 * 
 */
  __pyx_v_i = 0;
  __pyx_v_j = 0;

  /* "dipy/tracking/distances.pyx":1406
 *     cdef:
 *         long i=0,j=0
 *         float sub=0,subf=0,distf=0,dist=0,tmprow=0, tmprowf=0             # <<<<<<<<<<<<<<
 * 
 *     for i from 0<=i<rows:
 */
  __pyx_v_sub = 0.0;
  __pyx_v_subf = 0.0;
  __pyx_v_distf = 0.0;
  __pyx_v_dist = 0.0;
  __pyx_v_tmprow = 0.0;
  __pyx_v_tmprowf = 0.0;

  /* "dipy/tracking/distances.pyx":1408
 *         float sub=0,subf=0,distf=0,dist=0,tmprow=0, tmprowf=0
 * 
 *     for i from 0<=i<rows:             # <<<<<<<<<<<<<<
 *         tmprow=0
 *         tmprowf=0
 */
  __pyx_t_1 = __pyx_v_rows;
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_1; __pyx_v_i++) {

    /* "dipy/tracking/distances.pyx":1409
 * 
 *     for i from 0<=i<rows:
 *         tmprow=0             # <<<<<<<<<<<<<<
 *         tmprowf=0
 *         for j from 0<=j<3:
 */
    __pyx_v_tmprow = 0.0;

    /* "dipy/tracking/distances.pyx":1410
 *     for i from 0<=i<rows:
 *         tmprow=0
 *         tmprowf=0             # <<<<<<<<<<<<<<
 *         for j from 0<=j<3:
 *             sub=a[i*3+j]-b[i*3+j]
 */
    __pyx_v_tmprowf = 0.0;

    /* "dipy/tracking/distances.pyx":1411
 *         tmprow=0
 *         tmprowf=0
 *         for j from 0<=j<3:             # <<<<<<<<<<<<<<
 *             sub=a[i*3+j]-b[i*3+j]
 *             subf=a[i*3+j]-b[(rows-1-i)*3+j]
 */
    for (__pyx_v_j = 0; __pyx_v_j < 3; __pyx_v_j++) {

      /* "dipy/tracking/distances.pyx":1412
 *         tmprowf=0
 *         for j from 0<=j<3:
 *             sub=a[i*3+j]-b[i*3+j]             # <<<<<<<<<<<<<<
 *             subf=a[i*3+j]-b[(rows-1-i)*3+j]
 *             tmprow+=sub*sub
 */
      __pyx_v_sub = ((__pyx_v_a[((__pyx_v_i * 3) + __pyx_v_j)]) - (__pyx_v_b[((__pyx_v_i * 3) + __pyx_v_j)]));

      /* "dipy/tracking/distances.pyx":1413
 *         for j from 0<=j<3:
 *             sub=a[i*3+j]-b[i*3+j]
 *             subf=a[i*3+j]-b[(rows-1-i)*3+j]             # <<<<<<<<<<<<<<
 *             tmprow+=sub*sub
 *             tmprowf+=subf*subf
 */
      __pyx_v_subf = ((__pyx_v_a[((__pyx_v_i * 3) + __pyx_v_j)]) - (__pyx_v_b[((((__pyx_v_rows - 1) - __pyx_v_i) * 3) + __pyx_v_j)]));

      /* "dipy/tracking/distances.pyx":1414
 *             sub=a[i*3+j]-b[i*3+j]
 *             subf=a[i*3+j]-b[(rows-1-i)*3+j]
 *             tmprow+=sub*sub             # <<<<<<<<<<<<<<
 *             tmprowf+=subf*subf
 *         dist+=sqrt(tmprow)
 */
      __pyx_v_tmprow = (__pyx_v_tmprow + (__pyx_v_sub * __pyx_v_sub));

      /* "dipy/tracking/distances.pyx":1415
 *             subf=a[i*3+j]-b[(rows-1-i)*3+j]
 *             tmprow+=sub*sub
 *             tmprowf+=subf*subf             # <<<<<<<<<<<<<<
 *         dist+=sqrt(tmprow)
 *         distf+=sqrt(tmprowf)
 */
      __pyx_v_tmprowf = (__pyx_v_tmprowf + (__pyx_v_subf * __pyx_v_subf));
    }

    /* "dipy/tracking/distances.pyx":1416
 *             tmprow+=sub*sub
 *             tmprowf+=subf*subf
 *         dist+=sqrt(tmprow)             # <<<<<<<<<<<<<<
 *         distf+=sqrt(tmprowf)
 * 
 */
    __pyx_v_dist = (__pyx_v_dist + sqrt(__pyx_v_tmprow));

    /* "dipy/tracking/distances.pyx":1417
 *             tmprowf+=subf*subf
 *         dist+=sqrt(tmprow)
 *         distf+=sqrt(tmprowf)             # <<<<<<<<<<<<<<
 * 
 *     out[0]=dist/<float>rows
 */
    __pyx_v_distf = (__pyx_v_distf + sqrt(__pyx_v_tmprowf));
  }

  /* "dipy/tracking/distances.pyx":1419
 *         distf+=sqrt(tmprowf)
 * 
 *     out[0]=dist/<float>rows             # <<<<<<<<<<<<<<
 *     out[1]=distf/<float>rows
 * 
 */
  (__pyx_v_out[0]) = (__pyx_v_dist / ((float)__pyx_v_rows));

  /* "dipy/tracking/distances.pyx":1420
 * 
 *     out[0]=dist/<float>rows
 *     out[1]=distf/<float>rows             # <<<<<<<<<<<<<<
 * 
 * 
 */
  (__pyx_v_out[1]) = (__pyx_v_distf / ((float)__pyx_v_rows));

  /* "dipy/tracking/distances.pyx":1367
 * @cython.wraparound(False)
 * @cython.cdivision(True)
 * cdef void track_direct_flip_dist(float *a,float *b,long rows,float *out) nogil:             # <<<<<<<<<<<<<<
 *     r''' Direct and flip average distance between two tracks
 * 
 */

  /* function exit code */
}

/* "dipy/tracking/distances.pyx":1424
 * 
 * @cython.cdivision(True)
 * cdef inline void track_direct_flip_3dist(float *a1, float *b1,float  *c1,float *a2, float *b2, float *c2, float *out) nogil:             # <<<<<<<<<<<<<<
 *     ''' Calculate the euclidean distance between two 3pt tracks
 *     both direct and flip are given as output
 */

static CYTHON_INLINE void __pyx_f_4dipy_8tracking_9distances_track_direct_flip_3dist(float *__pyx_v_a1, float *__pyx_v_b1, float *__pyx_v_c1, float *__pyx_v_a2, float *__pyx_v_b2, float *__pyx_v_c2, float *__pyx_v_out) {
  int __pyx_v_i;
  float __pyx_v_tmp1;
  float __pyx_v_tmp2;
  float __pyx_v_tmp3;
  float __pyx_v_tmp1f;
  float __pyx_v_tmp3f;

  /* "dipy/tracking/distances.pyx":1441
 *     cdef:
 *         int i
 *         float tmp1=0,tmp2=0,tmp3=0,tmp1f=0,tmp3f=0             # <<<<<<<<<<<<<<
 * 
 *     #for i in range(3):
 */
  __pyx_v_tmp1 = 0.0;
  __pyx_v_tmp2 = 0.0;
  __pyx_v_tmp3 = 0.0;
  __pyx_v_tmp1f = 0.0;
  __pyx_v_tmp3f = 0.0;

  /* "dipy/tracking/distances.pyx":1444
 * 
 *     #for i in range(3):
 *     for i from 0<=i<3:             # <<<<<<<<<<<<<<
 *         tmp1=tmp1+(a1[i]-a2[i])*(a1[i]-a2[i])
 *         tmp2=tmp2+(b1[i]-b2[i])*(b1[i]-b2[i])
 */
  for (__pyx_v_i = 0; __pyx_v_i < 3; __pyx_v_i++) {

    /* "dipy/tracking/distances.pyx":1445
 *     #for i in range(3):
 *     for i from 0<=i<3:
 *         tmp1=tmp1+(a1[i]-a2[i])*(a1[i]-a2[i])             # <<<<<<<<<<<<<<
 *         tmp2=tmp2+(b1[i]-b2[i])*(b1[i]-b2[i])
 *         tmp3=tmp3+(c1[i]-c2[i])*(c1[i]-c2[i])
 */
    __pyx_v_tmp1 = (__pyx_v_tmp1 + (((__pyx_v_a1[__pyx_v_i]) - (__pyx_v_a2[__pyx_v_i])) * ((__pyx_v_a1[__pyx_v_i]) - (__pyx_v_a2[__pyx_v_i]))));

    /* "dipy/tracking/distances.pyx":1446
 *     for i from 0<=i<3:
 *         tmp1=tmp1+(a1[i]-a2[i])*(a1[i]-a2[i])
 *         tmp2=tmp2+(b1[i]-b2[i])*(b1[i]-b2[i])             # <<<<<<<<<<<<<<
 *         tmp3=tmp3+(c1[i]-c2[i])*(c1[i]-c2[i])
 *         tmp1f=tmp1f+(a1[i]-c2[i])*(a1[i]-c2[i])
 */
    __pyx_v_tmp2 = (__pyx_v_tmp2 + (((__pyx_v_b1[__pyx_v_i]) - (__pyx_v_b2[__pyx_v_i])) * ((__pyx_v_b1[__pyx_v_i]) - (__pyx_v_b2[__pyx_v_i]))));

    /* "dipy/tracking/distances.pyx":1447
 *         tmp1=tmp1+(a1[i]-a2[i])*(a1[i]-a2[i])
 *         tmp2=tmp2+(b1[i]-b2[i])*(b1[i]-b2[i])
 *         tmp3=tmp3+(c1[i]-c2[i])*(c1[i]-c2[i])             # <<<<<<<<<<<<<<
 *         tmp1f=tmp1f+(a1[i]-c2[i])*(a1[i]-c2[i])
 *         tmp3f=tmp3f+(c1[i]-a2[i])*(c1[i]-a2[i])
 */
    __pyx_v_tmp3 = (__pyx_v_tmp3 + (((__pyx_v_c1[__pyx_v_i]) - (__pyx_v_c2[__pyx_v_i])) * ((__pyx_v_c1[__pyx_v_i]) - (__pyx_v_c2[__pyx_v_i]))));

    /* "dipy/tracking/distances.pyx":1448
 *         tmp2=tmp2+(b1[i]-b2[i])*(b1[i]-b2[i])
 *         tmp3=tmp3+(c1[i]-c2[i])*(c1[i]-c2[i])
 *         tmp1f=tmp1f+(a1[i]-c2[i])*(a1[i]-c2[i])             # <<<<<<<<<<<<<<
 *         tmp3f=tmp3f+(c1[i]-a2[i])*(c1[i]-a2[i])
 * 
 */
    __pyx_v_tmp1f = (__pyx_v_tmp1f + (((__pyx_v_a1[__pyx_v_i]) - (__pyx_v_c2[__pyx_v_i])) * ((__pyx_v_a1[__pyx_v_i]) - (__pyx_v_c2[__pyx_v_i]))));

    /* "dipy/tracking/distances.pyx":1449
 *         tmp3=tmp3+(c1[i]-c2[i])*(c1[i]-c2[i])
 *         tmp1f=tmp1f+(a1[i]-c2[i])*(a1[i]-c2[i])
 *         tmp3f=tmp3f+(c1[i]-a2[i])*(c1[i]-a2[i])             # <<<<<<<<<<<<<<
 * 
 *     out[0]=(sqrt(tmp1)+sqrt(tmp2)+sqrt(tmp3))/3.0
 */
    __pyx_v_tmp3f = (__pyx_v_tmp3f + (((__pyx_v_c1[__pyx_v_i]) - (__pyx_v_a2[__pyx_v_i])) * ((__pyx_v_c1[__pyx_v_i]) - (__pyx_v_a2[__pyx_v_i]))));
  }

  /* "dipy/tracking/distances.pyx":1451
 *         tmp3f=tmp3f+(c1[i]-a2[i])*(c1[i]-a2[i])
 * 
 *     out[0]=(sqrt(tmp1)+sqrt(tmp2)+sqrt(tmp3))/3.0             # <<<<<<<<<<<<<<
 *     out[1]=(sqrt(tmp1f)+sqrt(tmp2)+sqrt(tmp3f))/3.0
 * 
 */
  (__pyx_v_out[0]) = (((sqrt(__pyx_v_tmp1) + sqrt(__pyx_v_tmp2)) + sqrt(__pyx_v_tmp3)) / 3.0);

  /* "dipy/tracking/distances.pyx":1452
 * 
 *     out[0]=(sqrt(tmp1)+sqrt(tmp2)+sqrt(tmp3))/3.0
 *     out[1]=(sqrt(tmp1f)+sqrt(tmp2)+sqrt(tmp3f))/3.0             # <<<<<<<<<<<<<<
 * 
 *     #out[0]=(tmp1+tmp2+tmp3)/3.0
 */
  (__pyx_v_out[1]) = (((sqrt(__pyx_v_tmp1f) + sqrt(__pyx_v_tmp2)) + sqrt(__pyx_v_tmp3f)) / 3.0);

  /* "dipy/tracking/distances.pyx":1424
 * 
 * @cython.cdivision(True)
 * cdef inline void track_direct_flip_3dist(float *a1, float *b1,float  *c1,float *a2, float *b2, float *c2, float *out) nogil:             # <<<<<<<<<<<<<<
 *     ''' Calculate the euclidean distance between two 3pt tracks
 *     both direct and flip are given as output
 */

  /* function exit code */
}

/* "dipy/tracking/distances.pyx":1471
 * @cython.wraparound(False)
 * @cython.cdivision(True)
 * def local_skeleton_clustering(tracks, d_thr=10):             # <<<<<<<<<<<<<<
 *     r"""Efficient tractography clustering
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_41local_skeleton_clustering(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_40local_skeleton_clustering[] = "Efficient tractography clustering\n\n    Every track can needs to have the same number of points.\n    Use `dipy.tracking.metrics.downsample` to restrict the number of points\n\n    Parameters\n    ----------\n    tracks : sequence\n        of tracks as arrays, shape (N,3) .. (N,3) where N=points\n    d_thr : float\n        average euclidean distance threshold\n\n    Returns\n    -------\n    C : dict\n        Clusters.\n\n    Examples\n    --------\n    >>> tracks=[np.array([[0,0,0],[1,0,0,],[2,0,0]]),\n    ...         np.array([[3,0,0],[3.5,1,0],[4,2,0]]),\n    ...         np.array([[3.2,0,0],[3.7,1,0],[4.4,2,0]]),\n    ...         np.array([[3.4,0,0],[3.9,1,0],[4.6,2,0]]),\n    ...         np.array([[0,0.2,0],[1,0.2,0],[2,0.2,0]]),\n    ...         np.array([[2,0.2,0],[1,0.2,0],[0,0.2,0]]),\n    ...         np.array([[0,0,0],[0,1,0],[0,2,0]])]\n    >>> C = local_skeleton_clustering(tracks, d_thr=0.5)\n\n    Notes\n    -----\n    The distance calculated between two tracks::\n\n        t_1       t_2\n\n        0*   a    *0\n          \\       |\n           \\      |\n           1*     |\n            |  b  *1\n            |      \\\n            2*      \\\n                c    *2\n\n    is equal to $(a+b+c)/3$ where $a$ the euclidean distance between ``t_1[0]``\n    and ``t_2[0]``, $b$ between ``t_1[1]`` and ``t_2[1]`` and $c$ between\n    ``t_1[2]`` and ``t_2[2]``. Also the same with t2 flipped (so ``t_1[0]``\n    compared to ``t_2[2]`` etc).\n\n    Visualization:\n\n    It is possible to visualize the clustering C from the example\n    above using the fvtk module::\n\n        from dipy.viz import fvtk\n        r=fvtk.ren()\n        for c in C:\n            color=np.random.rand(3)\n            for i in C[c]['indices']:\n                fvtk.add(r,fvtk.line(tracks[i],color))\n        fvtk.show(r)\n\n    See Also\n    --------\n    dipy.tracking.metrics.downsample\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_41local_skeleton_clustering = {"local_skeleton_clustering", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_41local_skeleton_clustering, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_40local_skeleton_clustering};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_41local_skeleton_clustering(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_tracks = 0;
  PyObject *__pyx_v_d_thr = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("local_skeleton_clustering (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tracks,&__pyx_n_s_d_thr,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)__pyx_int_10);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tracks)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_d_thr);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "local_skeleton_clustering") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1471; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_tracks = values[0];
    __pyx_v_d_thr = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("local_skeleton_clustering", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1471; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.local_skeleton_clustering", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_40local_skeleton_clustering(__pyx_self, __pyx_v_tracks, __pyx_v_d_thr);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_40local_skeleton_clustering(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tracks, PyObject *__pyx_v_d_thr) {
  PyArrayObject *__pyx_v_track = 0;
  __pyx_t_4dipy_8tracking_9distances_LSC_Cluster *__pyx_v_cluster;
  long __pyx_v_lent;
  long __pyx_v_lenC;
  long __pyx_v_dim;
  long __pyx_v_points;
  long __pyx_v_i;
  long __pyx_v_j;
  CYTHON_UNUSED long __pyx_v_c;
  long __pyx_v_i_k;
  long __pyx_v_rows;
  long __pyx_v_cit;
  float *__pyx_v_ptr;
  float *__pyx_v_hid;
  float *__pyx_v_alld;
  float __pyx_v_d[2];
  float __pyx_v_m_d;
  float __pyx_v_cd_thr;
  long *__pyx_v_flip;
  long __pyx_v_it;
  long __pyx_v_k;
  PyObject *__pyx_v_C = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_track;
  __Pyx_Buffer __pyx_pybuffer_track;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  float __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyArrayObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  long __pyx_t_12;
  long __pyx_t_13;
  long __pyx_t_14;
  long __pyx_t_15;
  int __pyx_t_16;
  long __pyx_t_17;
  PyObject *__pyx_t_18 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("local_skeleton_clustering", 0);
  __pyx_pybuffer_track.pybuffer.buf = NULL;
  __pyx_pybuffer_track.refcount = 0;
  __pyx_pybuffernd_track.data = NULL;
  __pyx_pybuffernd_track.rcbuffer = &__pyx_pybuffer_track;

  /* "dipy/tracking/distances.pyx":1540
 *         cnp.ndarray[cnp.float32_t, ndim=2] track
 *         LSC_Cluster *cluster
 *         long lent = 0,lenC = 0, dim = 0, points=0             # <<<<<<<<<<<<<<
 *         long i=0, j=0, c=0, i_k=0, rows=0 ,cit=0
 *         float *ptr, *hid, *alld
 */
  __pyx_v_lent = 0;
  __pyx_v_lenC = 0;
  __pyx_v_dim = 0;
  __pyx_v_points = 0;

  /* "dipy/tracking/distances.pyx":1541
 *         LSC_Cluster *cluster
 *         long lent = 0,lenC = 0, dim = 0, points=0
 *         long i=0, j=0, c=0, i_k=0, rows=0 ,cit=0             # <<<<<<<<<<<<<<
 *         float *ptr, *hid, *alld
 *         float d[2],m_d,cd_thr
 */
  __pyx_v_i = 0;
  __pyx_v_j = 0;
  __pyx_v_c = 0;
  __pyx_v_i_k = 0;
  __pyx_v_rows = 0;
  __pyx_v_cit = 0;

  /* "dipy/tracking/distances.pyx":1546
 *         long *flip
 * 
 *     points=len(tracks[0])             # <<<<<<<<<<<<<<
 *     dim = points*3
 *     rows = points
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_tracks, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1546; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyObject_Length(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1546; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_points = __pyx_t_2;

  /* "dipy/tracking/distances.pyx":1547
 * 
 *     points=len(tracks[0])
 *     dim = points*3             # <<<<<<<<<<<<<<
 *     rows = points
 *     cd_thr = d_thr
 */
  __pyx_v_dim = (__pyx_v_points * 3);

  /* "dipy/tracking/distances.pyx":1548
 *     points=len(tracks[0])
 *     dim = points*3
 *     rows = points             # <<<<<<<<<<<<<<
 *     cd_thr = d_thr
 * 
 */
  __pyx_v_rows = __pyx_v_points;

  /* "dipy/tracking/distances.pyx":1549
 *     dim = points*3
 *     rows = points
 *     cd_thr = d_thr             # <<<<<<<<<<<<<<
 * 
 *     #Allocate and copy memory for first cluster
 */
  __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_d_thr); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1549; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_cd_thr = __pyx_t_3;

  /* "dipy/tracking/distances.pyx":1552
 * 
 *     #Allocate and copy memory for first cluster
 *     cluster=<LSC_Cluster *>realloc(NULL,sizeof(LSC_Cluster))             # <<<<<<<<<<<<<<
 *     cluster[0].indices=<long *>realloc(NULL,sizeof(long))
 *     cluster[0].hidden=<float *>realloc(NULL,dim*sizeof(float))
 */
  __pyx_v_cluster = ((__pyx_t_4dipy_8tracking_9distances_LSC_Cluster *)realloc(NULL, (sizeof(__pyx_t_4dipy_8tracking_9distances_LSC_Cluster))));

  /* "dipy/tracking/distances.pyx":1553
 *     #Allocate and copy memory for first cluster
 *     cluster=<LSC_Cluster *>realloc(NULL,sizeof(LSC_Cluster))
 *     cluster[0].indices=<long *>realloc(NULL,sizeof(long))             # <<<<<<<<<<<<<<
 *     cluster[0].hidden=<float *>realloc(NULL,dim*sizeof(float))
 *     cluster[0].indices[0]=0
 */
  (__pyx_v_cluster[0]).indices = ((long *)realloc(NULL, (sizeof(long))));

  /* "dipy/tracking/distances.pyx":1554
 *     cluster=<LSC_Cluster *>realloc(NULL,sizeof(LSC_Cluster))
 *     cluster[0].indices=<long *>realloc(NULL,sizeof(long))
 *     cluster[0].hidden=<float *>realloc(NULL,dim*sizeof(float))             # <<<<<<<<<<<<<<
 *     cluster[0].indices[0]=0
 *     track=np.ascontiguousarray(tracks[0],dtype=f32_dt)
 */
  (__pyx_v_cluster[0]).hidden = ((float *)realloc(NULL, (__pyx_v_dim * (sizeof(float)))));

  /* "dipy/tracking/distances.pyx":1555
 *     cluster[0].indices=<long *>realloc(NULL,sizeof(long))
 *     cluster[0].hidden=<float *>realloc(NULL,dim*sizeof(float))
 *     cluster[0].indices[0]=0             # <<<<<<<<<<<<<<
 *     track=np.ascontiguousarray(tracks[0],dtype=f32_dt)
 *     ptr=<float *>track.data
 */
  ((__pyx_v_cluster[0]).indices[0]) = 0;

  /* "dipy/tracking/distances.pyx":1556
 *     cluster[0].hidden=<float *>realloc(NULL,dim*sizeof(float))
 *     cluster[0].indices[0]=0
 *     track=np.ascontiguousarray(tracks[0],dtype=f32_dt)             # <<<<<<<<<<<<<<
 *     ptr=<float *>track.data
 *     for i from 0<=i<dim:
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_tracks, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1556; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
    __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
    if (unlikely(__pyx_t_8 < 0)) {
      PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track.rcbuffer->pybuffer, (PyObject*)__pyx_v_track, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
      }
    }
    __pyx_pybuffernd_track.diminfo[0].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_track.diminfo[0].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_track.diminfo[1].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_track.diminfo[1].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[1];
    if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1556; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_7 = 0;
  __pyx_v_track = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "dipy/tracking/distances.pyx":1557
 *     cluster[0].indices[0]=0
 *     track=np.ascontiguousarray(tracks[0],dtype=f32_dt)
 *     ptr=<float *>track.data             # <<<<<<<<<<<<<<
 *     for i from 0<=i<dim:
 *         cluster[0].hidden[i]=ptr[i]
 */
  __pyx_v_ptr = ((float *)__pyx_v_track->data);

  /* "dipy/tracking/distances.pyx":1558
 *     track=np.ascontiguousarray(tracks[0],dtype=f32_dt)
 *     ptr=<float *>track.data
 *     for i from 0<=i<dim:             # <<<<<<<<<<<<<<
 *         cluster[0].hidden[i]=ptr[i]
 *     cluster[0].N=1
 */
  __pyx_t_12 = __pyx_v_dim;
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_12; __pyx_v_i++) {

    /* "dipy/tracking/distances.pyx":1559
 *     ptr=<float *>track.data
 *     for i from 0<=i<dim:
 *         cluster[0].hidden[i]=ptr[i]             # <<<<<<<<<<<<<<
 *     cluster[0].N=1
 * 
 */
    ((__pyx_v_cluster[0]).hidden[__pyx_v_i]) = (__pyx_v_ptr[__pyx_v_i]);
  }

  /* "dipy/tracking/distances.pyx":1560
 *     for i from 0<=i<dim:
 *         cluster[0].hidden[i]=ptr[i]
 *     cluster[0].N=1             # <<<<<<<<<<<<<<
 * 
 *     #holds number of clusters
 */
  (__pyx_v_cluster[0]).N = 1;

  /* "dipy/tracking/distances.pyx":1563
 * 
 *     #holds number of clusters
 *     lenC = 1             # <<<<<<<<<<<<<<
 * 
 *     #store memmory for the hid variable
 */
  __pyx_v_lenC = 1;

  /* "dipy/tracking/distances.pyx":1566
 * 
 *     #store memmory for the hid variable
 *     hid=<float *>realloc(NULL,dim*sizeof(float))             # <<<<<<<<<<<<<<
 * 
 *     #Work with the rest of the tracks
 */
  __pyx_v_hid = ((float *)realloc(NULL, (__pyx_v_dim * (sizeof(float)))));

  /* "dipy/tracking/distances.pyx":1569
 * 
 *     #Work with the rest of the tracks
 *     lent=len(tracks)             # <<<<<<<<<<<<<<
 *     for it in range(1,lent):
 *         track=np.ascontiguousarray(tracks[it],dtype=f32_dt)
 */
  __pyx_t_2 = PyObject_Length(__pyx_v_tracks); if (unlikely(__pyx_t_2 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1569; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_lent = __pyx_t_2;

  /* "dipy/tracking/distances.pyx":1570
 *     #Work with the rest of the tracks
 *     lent=len(tracks)
 *     for it in range(1,lent):             # <<<<<<<<<<<<<<
 *         track=np.ascontiguousarray(tracks[it],dtype=f32_dt)
 *         ptr=<float *>track.data
 */
  __pyx_t_12 = __pyx_v_lent;
  for (__pyx_t_13 = 1; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) {
    __pyx_v_it = __pyx_t_13;

    /* "dipy/tracking/distances.pyx":1571
 *     lent=len(tracks)
 *     for it in range(1,lent):
 *         track=np.ascontiguousarray(tracks[it],dtype=f32_dt)             # <<<<<<<<<<<<<<
 *         ptr=<float *>track.data
 *         cit=it
 */
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1571; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1571; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_tracks, __pyx_v_it, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1571; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1571; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
    __pyx_t_6 = 0;
    __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1571; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1571; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1571; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1571; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_7 = ((PyArrayObject *)__pyx_t_4);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
      __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_8 < 0)) {
        PyErr_Fetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track.rcbuffer->pybuffer, (PyObject*)__pyx_v_track, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_9);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_11, __pyx_t_10, __pyx_t_9);
        }
      }
      __pyx_pybuffernd_track.diminfo[0].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_track.diminfo[0].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_track.diminfo[1].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_track.diminfo[1].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_8 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1571; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_7 = 0;
    __Pyx_DECREF_SET(__pyx_v_track, ((PyArrayObject *)__pyx_t_4));
    __pyx_t_4 = 0;

    /* "dipy/tracking/distances.pyx":1572
 *     for it in range(1,lent):
 *         track=np.ascontiguousarray(tracks[it],dtype=f32_dt)
 *         ptr=<float *>track.data             # <<<<<<<<<<<<<<
 *         cit=it
 * 
 */
    __pyx_v_ptr = ((float *)__pyx_v_track->data);

    /* "dipy/tracking/distances.pyx":1573
 *         track=np.ascontiguousarray(tracks[it],dtype=f32_dt)
 *         ptr=<float *>track.data
 *         cit=it             # <<<<<<<<<<<<<<
 * 
 *         with nogil:
 */
    __pyx_v_cit = __pyx_v_it;

    /* "dipy/tracking/distances.pyx":1575
 *         cit=it
 * 
 *         with nogil:             # <<<<<<<<<<<<<<
 * 
 *             alld=<float *>calloc(lenC,sizeof(float))
 */
    {
        #ifdef WITH_THREAD
        PyThreadState *_save;
        Py_UNBLOCK_THREADS
        #endif
        /*try:*/ {

          /* "dipy/tracking/distances.pyx":1577
 *         with nogil:
 * 
 *             alld=<float *>calloc(lenC,sizeof(float))             # <<<<<<<<<<<<<<
 *             flip=<long *>calloc(lenC,sizeof(long))
 *             for k from 0<=k<lenC:
 */
          __pyx_v_alld = ((float *)calloc(__pyx_v_lenC, (sizeof(float))));

          /* "dipy/tracking/distances.pyx":1578
 * 
 *             alld=<float *>calloc(lenC,sizeof(float))
 *             flip=<long *>calloc(lenC,sizeof(long))             # <<<<<<<<<<<<<<
 *             for k from 0<=k<lenC:
 *                 for i from 0<=i<dim:
 */
          __pyx_v_flip = ((long *)calloc(__pyx_v_lenC, (sizeof(long))));

          /* "dipy/tracking/distances.pyx":1579
 *             alld=<float *>calloc(lenC,sizeof(float))
 *             flip=<long *>calloc(lenC,sizeof(long))
 *             for k from 0<=k<lenC:             # <<<<<<<<<<<<<<
 *                 for i from 0<=i<dim:
 *                     hid[i]=cluster[k].hidden[i]/<float>cluster[k].N
 */
          __pyx_t_14 = __pyx_v_lenC;
          for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_14; __pyx_v_k++) {

            /* "dipy/tracking/distances.pyx":1580
 *             flip=<long *>calloc(lenC,sizeof(long))
 *             for k from 0<=k<lenC:
 *                 for i from 0<=i<dim:             # <<<<<<<<<<<<<<
 *                     hid[i]=cluster[k].hidden[i]/<float>cluster[k].N
 * 
 */
            __pyx_t_15 = __pyx_v_dim;
            for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_15; __pyx_v_i++) {

              /* "dipy/tracking/distances.pyx":1581
 *             for k from 0<=k<lenC:
 *                 for i from 0<=i<dim:
 *                     hid[i]=cluster[k].hidden[i]/<float>cluster[k].N             # <<<<<<<<<<<<<<
 * 
 *                 #track_direct_flip_3dist(&ptr[0],&ptr[3],&ptr[6],&hid[0],&hid[3],&hid[6],d)
 */
              (__pyx_v_hid[__pyx_v_i]) = (((__pyx_v_cluster[__pyx_v_k]).hidden[__pyx_v_i]) / ((float)(__pyx_v_cluster[__pyx_v_k]).N));
            }

            /* "dipy/tracking/distances.pyx":1585
 *                 #track_direct_flip_3dist(&ptr[0],&ptr[3],&ptr[6],&hid[0],&hid[3],&hid[6],d)
 *                 #track_direct_flip_3dist(ptr,ptr+3,ptr+6,hid,hid+3,hid+6,<float *>d)
 *                 track_direct_flip_dist(ptr, hid,rows,<float *>d)             # <<<<<<<<<<<<<<
 * 
 *                 if d[1]<d[0]:
 */
            __pyx_f_4dipy_8tracking_9distances_track_direct_flip_dist(__pyx_v_ptr, __pyx_v_hid, __pyx_v_rows, ((float *)__pyx_v_d));

            /* "dipy/tracking/distances.pyx":1587
 *                 track_direct_flip_dist(ptr, hid,rows,<float *>d)
 * 
 *                 if d[1]<d[0]:             # <<<<<<<<<<<<<<
 *                     d[0]=d[1]
 *                     flip[k]=1
 */
            __pyx_t_16 = (((__pyx_v_d[1]) < (__pyx_v_d[0])) != 0);
            if (__pyx_t_16) {

              /* "dipy/tracking/distances.pyx":1588
 * 
 *                 if d[1]<d[0]:
 *                     d[0]=d[1]             # <<<<<<<<<<<<<<
 *                     flip[k]=1
 *                 alld[k]=d[0]
 */
              (__pyx_v_d[0]) = (__pyx_v_d[1]);

              /* "dipy/tracking/distances.pyx":1589
 *                 if d[1]<d[0]:
 *                     d[0]=d[1]
 *                     flip[k]=1             # <<<<<<<<<<<<<<
 *                 alld[k]=d[0]
 * 
 */
              (__pyx_v_flip[__pyx_v_k]) = 1;

              /* "dipy/tracking/distances.pyx":1587
 *                 track_direct_flip_dist(ptr, hid,rows,<float *>d)
 * 
 *                 if d[1]<d[0]:             # <<<<<<<<<<<<<<
 *                     d[0]=d[1]
 *                     flip[k]=1
 */
            }

            /* "dipy/tracking/distances.pyx":1590
 *                     d[0]=d[1]
 *                     flip[k]=1
 *                 alld[k]=d[0]             # <<<<<<<<<<<<<<
 * 
 *             m_d = biggest_float
 */
            (__pyx_v_alld[__pyx_v_k]) = (__pyx_v_d[0]);
          }

          /* "dipy/tracking/distances.pyx":1592
 *                 alld[k]=d[0]
 * 
 *             m_d = biggest_float             # <<<<<<<<<<<<<<
 *             #find minimum distance and index
 *             for k from 0<=k<lenC:
 */
          __pyx_v_m_d = 3.4028235e+38;

          /* "dipy/tracking/distances.pyx":1594
 *             m_d = biggest_float
 *             #find minimum distance and index
 *             for k from 0<=k<lenC:             # <<<<<<<<<<<<<<
 *                 if alld[k] < m_d:
 *                     m_d=alld[k]
 */
          __pyx_t_14 = __pyx_v_lenC;
          for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_14; __pyx_v_k++) {

            /* "dipy/tracking/distances.pyx":1595
 *             #find minimum distance and index
 *             for k from 0<=k<lenC:
 *                 if alld[k] < m_d:             # <<<<<<<<<<<<<<
 *                     m_d=alld[k]
 *                     i_k=k
 */
            __pyx_t_16 = (((__pyx_v_alld[__pyx_v_k]) < __pyx_v_m_d) != 0);
            if (__pyx_t_16) {

              /* "dipy/tracking/distances.pyx":1596
 *             for k from 0<=k<lenC:
 *                 if alld[k] < m_d:
 *                     m_d=alld[k]             # <<<<<<<<<<<<<<
 *                     i_k=k
 * 
 */
              __pyx_v_m_d = (__pyx_v_alld[__pyx_v_k]);

              /* "dipy/tracking/distances.pyx":1597
 *                 if alld[k] < m_d:
 *                     m_d=alld[k]
 *                     i_k=k             # <<<<<<<<<<<<<<
 * 
 *             if m_d < cd_thr:
 */
              __pyx_v_i_k = __pyx_v_k;

              /* "dipy/tracking/distances.pyx":1595
 *             #find minimum distance and index
 *             for k from 0<=k<lenC:
 *                 if alld[k] < m_d:             # <<<<<<<<<<<<<<
 *                     m_d=alld[k]
 *                     i_k=k
 */
            }
          }

          /* "dipy/tracking/distances.pyx":1599
 *                     i_k=k
 * 
 *             if m_d < cd_thr:             # <<<<<<<<<<<<<<
 *                 if flip[i_k]==1:#correct if flipping is needed
 *                     for i from 0<=i<rows:
 */
          __pyx_t_16 = ((__pyx_v_m_d < __pyx_v_cd_thr) != 0);
          if (__pyx_t_16) {

            /* "dipy/tracking/distances.pyx":1600
 * 
 *             if m_d < cd_thr:
 *                 if flip[i_k]==1:#correct if flipping is needed             # <<<<<<<<<<<<<<
 *                     for i from 0<=i<rows:
 *                         for j from 0<=j<3:
 */
            __pyx_t_16 = (((__pyx_v_flip[__pyx_v_i_k]) == 1) != 0);
            if (__pyx_t_16) {

              /* "dipy/tracking/distances.pyx":1601
 *             if m_d < cd_thr:
 *                 if flip[i_k]==1:#correct if flipping is needed
 *                     for i from 0<=i<rows:             # <<<<<<<<<<<<<<
 *                         for j from 0<=j<3:
 *                             cluster[i_k].hidden[i*3+j]+=ptr[(rows-1-i)*3+j]
 */
              __pyx_t_14 = __pyx_v_rows;
              for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_14; __pyx_v_i++) {

                /* "dipy/tracking/distances.pyx":1602
 *                 if flip[i_k]==1:#correct if flipping is needed
 *                     for i from 0<=i<rows:
 *                         for j from 0<=j<3:             # <<<<<<<<<<<<<<
 *                             cluster[i_k].hidden[i*3+j]+=ptr[(rows-1-i)*3+j]
 *                 else:
 */
                for (__pyx_v_j = 0; __pyx_v_j < 3; __pyx_v_j++) {

                  /* "dipy/tracking/distances.pyx":1603
 *                     for i from 0<=i<rows:
 *                         for j from 0<=j<3:
 *                             cluster[i_k].hidden[i*3+j]+=ptr[(rows-1-i)*3+j]             # <<<<<<<<<<<<<<
 *                 else:
 *                      for i from 0<=i<rows:
 */
                  __pyx_t_15 = __pyx_v_i_k;
                  __pyx_t_17 = ((__pyx_v_i * 3) + __pyx_v_j);
                  ((__pyx_v_cluster[__pyx_t_15]).hidden[__pyx_t_17]) = (((__pyx_v_cluster[__pyx_t_15]).hidden[__pyx_t_17]) + (__pyx_v_ptr[((((__pyx_v_rows - 1) - __pyx_v_i) * 3) + __pyx_v_j)]));
                }
              }

              /* "dipy/tracking/distances.pyx":1600
 * 
 *             if m_d < cd_thr:
 *                 if flip[i_k]==1:#correct if flipping is needed             # <<<<<<<<<<<<<<
 *                     for i from 0<=i<rows:
 *                         for j from 0<=j<3:
 */
              goto __pyx_L21;
            }

            /* "dipy/tracking/distances.pyx":1605
 *                             cluster[i_k].hidden[i*3+j]+=ptr[(rows-1-i)*3+j]
 *                 else:
 *                      for i from 0<=i<rows:             # <<<<<<<<<<<<<<
 *                         for j from 0<=j<3:
 *                             cluster[i_k].hidden[i*3+j]+=ptr[i*3+j]
 */
            /*else*/ {
              __pyx_t_14 = __pyx_v_rows;
              for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_14; __pyx_v_i++) {

                /* "dipy/tracking/distances.pyx":1606
 *                 else:
 *                      for i from 0<=i<rows:
 *                         for j from 0<=j<3:             # <<<<<<<<<<<<<<
 *                             cluster[i_k].hidden[i*3+j]+=ptr[i*3+j]
 *                 cluster[i_k].N+=1
 */
                for (__pyx_v_j = 0; __pyx_v_j < 3; __pyx_v_j++) {

                  /* "dipy/tracking/distances.pyx":1607
 *                      for i from 0<=i<rows:
 *                         for j from 0<=j<3:
 *                             cluster[i_k].hidden[i*3+j]+=ptr[i*3+j]             # <<<<<<<<<<<<<<
 *                 cluster[i_k].N+=1
 *                 cluster[i_k].indices=<long *>realloc(cluster[i_k].indices,cluster[i_k].N*sizeof(long))
 */
                  __pyx_t_15 = __pyx_v_i_k;
                  __pyx_t_17 = ((__pyx_v_i * 3) + __pyx_v_j);
                  ((__pyx_v_cluster[__pyx_t_15]).hidden[__pyx_t_17]) = (((__pyx_v_cluster[__pyx_t_15]).hidden[__pyx_t_17]) + (__pyx_v_ptr[((__pyx_v_i * 3) + __pyx_v_j)]));
                }
              }
            }
            __pyx_L21:;

            /* "dipy/tracking/distances.pyx":1608
 *                         for j from 0<=j<3:
 *                             cluster[i_k].hidden[i*3+j]+=ptr[i*3+j]
 *                 cluster[i_k].N+=1             # <<<<<<<<<<<<<<
 *                 cluster[i_k].indices=<long *>realloc(cluster[i_k].indices,cluster[i_k].N*sizeof(long))
 *                 cluster[i_k].indices[cluster[i_k].N-1]=cit
 */
            __pyx_t_14 = __pyx_v_i_k;
            (__pyx_v_cluster[__pyx_t_14]).N = ((__pyx_v_cluster[__pyx_t_14]).N + 1);

            /* "dipy/tracking/distances.pyx":1609
 *                             cluster[i_k].hidden[i*3+j]+=ptr[i*3+j]
 *                 cluster[i_k].N+=1
 *                 cluster[i_k].indices=<long *>realloc(cluster[i_k].indices,cluster[i_k].N*sizeof(long))             # <<<<<<<<<<<<<<
 *                 cluster[i_k].indices[cluster[i_k].N-1]=cit
 * 
 */
            (__pyx_v_cluster[__pyx_v_i_k]).indices = ((long *)realloc((__pyx_v_cluster[__pyx_v_i_k]).indices, ((__pyx_v_cluster[__pyx_v_i_k]).N * (sizeof(long)))));

            /* "dipy/tracking/distances.pyx":1610
 *                 cluster[i_k].N+=1
 *                 cluster[i_k].indices=<long *>realloc(cluster[i_k].indices,cluster[i_k].N*sizeof(long))
 *                 cluster[i_k].indices[cluster[i_k].N-1]=cit             # <<<<<<<<<<<<<<
 * 
 *             else:#New cluster added
 */
            ((__pyx_v_cluster[__pyx_v_i_k]).indices[((__pyx_v_cluster[__pyx_v_i_k]).N - 1)]) = __pyx_v_cit;

            /* "dipy/tracking/distances.pyx":1599
 *                     i_k=k
 * 
 *             if m_d < cd_thr:             # <<<<<<<<<<<<<<
 *                 if flip[i_k]==1:#correct if flipping is needed
 *                     for i from 0<=i<rows:
 */
            goto __pyx_L20;
          }

          /* "dipy/tracking/distances.pyx":1613
 * 
 *             else:#New cluster added
 *                 lenC+=1             # <<<<<<<<<<<<<<
 *                 cluster=<LSC_Cluster *>realloc(cluster,lenC*sizeof(LSC_Cluster))
 *                 cluster[lenC-1].indices=<long *>realloc(NULL,sizeof(long))
 */
          /*else*/ {
            __pyx_v_lenC = (__pyx_v_lenC + 1);

            /* "dipy/tracking/distances.pyx":1614
 *             else:#New cluster added
 *                 lenC+=1
 *                 cluster=<LSC_Cluster *>realloc(cluster,lenC*sizeof(LSC_Cluster))             # <<<<<<<<<<<<<<
 *                 cluster[lenC-1].indices=<long *>realloc(NULL,sizeof(long))
 *                 cluster[lenC-1].hidden=<float *>realloc(NULL,dim*sizeof(float))
 */
            __pyx_v_cluster = ((__pyx_t_4dipy_8tracking_9distances_LSC_Cluster *)realloc(__pyx_v_cluster, (__pyx_v_lenC * (sizeof(__pyx_t_4dipy_8tracking_9distances_LSC_Cluster)))));

            /* "dipy/tracking/distances.pyx":1615
 *                 lenC+=1
 *                 cluster=<LSC_Cluster *>realloc(cluster,lenC*sizeof(LSC_Cluster))
 *                 cluster[lenC-1].indices=<long *>realloc(NULL,sizeof(long))             # <<<<<<<<<<<<<<
 *                 cluster[lenC-1].hidden=<float *>realloc(NULL,dim*sizeof(float))
 *                 cluster[lenC-1].indices[0]=cit
 */
            (__pyx_v_cluster[(__pyx_v_lenC - 1)]).indices = ((long *)realloc(NULL, (sizeof(long))));

            /* "dipy/tracking/distances.pyx":1616
 *                 cluster=<LSC_Cluster *>realloc(cluster,lenC*sizeof(LSC_Cluster))
 *                 cluster[lenC-1].indices=<long *>realloc(NULL,sizeof(long))
 *                 cluster[lenC-1].hidden=<float *>realloc(NULL,dim*sizeof(float))             # <<<<<<<<<<<<<<
 *                 cluster[lenC-1].indices[0]=cit
 *                 for i from 0<=i<dim:
 */
            (__pyx_v_cluster[(__pyx_v_lenC - 1)]).hidden = ((float *)realloc(NULL, (__pyx_v_dim * (sizeof(float)))));

            /* "dipy/tracking/distances.pyx":1617
 *                 cluster[lenC-1].indices=<long *>realloc(NULL,sizeof(long))
 *                 cluster[lenC-1].hidden=<float *>realloc(NULL,dim*sizeof(float))
 *                 cluster[lenC-1].indices[0]=cit             # <<<<<<<<<<<<<<
 *                 for i from 0<=i<dim:
 *                     cluster[lenC-1].hidden[i]=ptr[i]
 */
            ((__pyx_v_cluster[(__pyx_v_lenC - 1)]).indices[0]) = __pyx_v_cit;

            /* "dipy/tracking/distances.pyx":1618
 *                 cluster[lenC-1].hidden=<float *>realloc(NULL,dim*sizeof(float))
 *                 cluster[lenC-1].indices[0]=cit
 *                 for i from 0<=i<dim:             # <<<<<<<<<<<<<<
 *                     cluster[lenC-1].hidden[i]=ptr[i]
 *                 cluster[lenC-1].N=1
 */
            __pyx_t_14 = __pyx_v_dim;
            for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_14; __pyx_v_i++) {

              /* "dipy/tracking/distances.pyx":1619
 *                 cluster[lenC-1].indices[0]=cit
 *                 for i from 0<=i<dim:
 *                     cluster[lenC-1].hidden[i]=ptr[i]             # <<<<<<<<<<<<<<
 *                 cluster[lenC-1].N=1
 * 
 */
              ((__pyx_v_cluster[(__pyx_v_lenC - 1)]).hidden[__pyx_v_i]) = (__pyx_v_ptr[__pyx_v_i]);
            }

            /* "dipy/tracking/distances.pyx":1620
 *                 for i from 0<=i<dim:
 *                     cluster[lenC-1].hidden[i]=ptr[i]
 *                 cluster[lenC-1].N=1             # <<<<<<<<<<<<<<
 * 
 *             free(alld)
 */
            (__pyx_v_cluster[(__pyx_v_lenC - 1)]).N = 1;
          }
          __pyx_L20:;

          /* "dipy/tracking/distances.pyx":1622
 *                 cluster[lenC-1].N=1
 * 
 *             free(alld)             # <<<<<<<<<<<<<<
 *             free(flip)
 * 
 */
          free(__pyx_v_alld);

          /* "dipy/tracking/distances.pyx":1623
 * 
 *             free(alld)
 *             free(flip)             # <<<<<<<<<<<<<<
 * 
 * 
 */
          free(__pyx_v_flip);
        }

        /* "dipy/tracking/distances.pyx":1575
 *         cit=it
 * 
 *         with nogil:             # <<<<<<<<<<<<<<
 * 
 *             alld=<float *>calloc(lenC,sizeof(float))
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            Py_BLOCK_THREADS
            #endif
            goto __pyx_L11;
          }
          __pyx_L11:;
        }
    }
  }

  /* "dipy/tracking/distances.pyx":1628
 *     #Copy results to a dictionary
 * 
 *     C={}             # <<<<<<<<<<<<<<
 *     for k in range(lenC):
 * 
 */
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1628; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_C = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "dipy/tracking/distances.pyx":1629
 * 
 *     C={}
 *     for k in range(lenC):             # <<<<<<<<<<<<<<
 * 
 *         C[k]={}
 */
  __pyx_t_12 = __pyx_v_lenC;
  for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) {
    __pyx_v_k = __pyx_t_13;

    /* "dipy/tracking/distances.pyx":1631
 *     for k in range(lenC):
 * 
 *         C[k]={}             # <<<<<<<<<<<<<<
 *         C[k]['hidden']=np.zeros(points*3,dtype=np.float32)
 * 
 */
    __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyInt_From_long(__pyx_v_k); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    if (unlikely(PyDict_SetItem(__pyx_v_C, __pyx_t_6, __pyx_t_4) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1631; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "dipy/tracking/distances.pyx":1632
 * 
 *         C[k]={}
 *         C[k]['hidden']=np.zeros(points*3,dtype=np.float32)             # <<<<<<<<<<<<<<
 * 
 *         for j in range(points*3):
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_zeros); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyInt_From_long((__pyx_v_points * 3)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_18);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_18) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
    __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_18);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyInt_From_long(__pyx_v_k); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_t_4); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1632; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(PyObject_SetItem(__pyx_t_5, __pyx_n_s_hidden, __pyx_t_18) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1632; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;

    /* "dipy/tracking/distances.pyx":1634
 *         C[k]['hidden']=np.zeros(points*3,dtype=np.float32)
 * 
 *         for j in range(points*3):             # <<<<<<<<<<<<<<
 *             C[k]['hidden'][j]=cluster[k].hidden[j]
 *         C[k]['hidden'].shape=(points,3)
 */
    __pyx_t_14 = (__pyx_v_points * 3);
    for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) {
      __pyx_v_j = __pyx_t_15;

      /* "dipy/tracking/distances.pyx":1635
 * 
 *         for j in range(points*3):
 *             C[k]['hidden'][j]=cluster[k].hidden[j]             # <<<<<<<<<<<<<<
 *         C[k]['hidden'].shape=(points,3)
 * 
 */
      __pyx_t_18 = PyFloat_FromDouble(((__pyx_v_cluster[__pyx_v_k]).hidden[__pyx_v_j])); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_18);
      __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_k); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_t_5); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1635; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyObject_GetItem(__pyx_t_4, __pyx_n_s_hidden); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1635; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(__Pyx_SetItemInt(__pyx_t_5, __pyx_v_j, __pyx_t_18, long, 1, __Pyx_PyInt_From_long, 0, 0, 0) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1635; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
    }

    /* "dipy/tracking/distances.pyx":1636
 *         for j in range(points*3):
 *             C[k]['hidden'][j]=cluster[k].hidden[j]
 *         C[k]['hidden'].shape=(points,3)             # <<<<<<<<<<<<<<
 * 
 *         C[k]['N']=cluster[k].N
 */
    __pyx_t_18 = __Pyx_PyInt_From_long(__pyx_v_points); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_18);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_18);
    __Pyx_INCREF(__pyx_int_3);
    __Pyx_GIVEREF(__pyx_int_3);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_int_3);
    __pyx_t_18 = 0;
    __pyx_t_18 = __Pyx_PyInt_From_long(__pyx_v_k); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_t_18); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1636; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
    __pyx_t_18 = PyObject_GetItem(__pyx_t_4, __pyx_n_s_hidden); if (unlikely(__pyx_t_18 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1636; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_18);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__Pyx_PyObject_SetAttrStr(__pyx_t_18, __pyx_n_s_shape, __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1636; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;

    /* "dipy/tracking/distances.pyx":1638
 *         C[k]['hidden'].shape=(points,3)
 * 
 *         C[k]['N']=cluster[k].N             # <<<<<<<<<<<<<<
 *         C[k]['indices']=np.zeros(cluster[k].N,dtype=np.int64)
 * 
 */
    __pyx_t_18 = __Pyx_PyInt_From_long((__pyx_v_cluster[__pyx_v_k]).N); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_k); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_t_5); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1638; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(PyObject_SetItem(__pyx_t_4, __pyx_n_s_N, __pyx_t_18) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1638; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;

    /* "dipy/tracking/distances.pyx":1639
 * 
 *         C[k]['N']=cluster[k].N
 *         C[k]['indices']=np.zeros(cluster[k].N,dtype=np.int64)             # <<<<<<<<<<<<<<
 * 
 *         for i in range(cluster[k].N):
 */
    __pyx_t_18 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_18, __pyx_n_s_zeros); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
    __pyx_t_18 = __Pyx_PyInt_From_long((__pyx_v_cluster[__pyx_v_k]).N); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_18);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_18);
    __pyx_t_18 = 0;
    __pyx_t_18 = PyDict_New(); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_int64); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (PyDict_SetItem(__pyx_t_18, __pyx_n_s_dtype, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, __pyx_t_18); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
    __pyx_t_18 = __Pyx_PyInt_From_long(__pyx_v_k); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_5 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_t_18); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
    if (unlikely(PyObject_SetItem(__pyx_t_5, __pyx_n_s_indices, __pyx_t_1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1639; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "dipy/tracking/distances.pyx":1641
 *         C[k]['indices']=np.zeros(cluster[k].N,dtype=np.int64)
 * 
 *         for i in range(cluster[k].N):             # <<<<<<<<<<<<<<
 *             C[k]['indices'][i]=cluster[k].indices[i]
 * 
 */
    __pyx_t_14 = (__pyx_v_cluster[__pyx_v_k]).N;
    for (__pyx_t_15 = 0; __pyx_t_15 < __pyx_t_14; __pyx_t_15+=1) {
      __pyx_v_i = __pyx_t_15;

      /* "dipy/tracking/distances.pyx":1642
 * 
 *         for i in range(cluster[k].N):
 *             C[k]['indices'][i]=cluster[k].indices[i]             # <<<<<<<<<<<<<<
 * 
 *         C[k]['indices']=list(C[k]['indices'])
 */
      __pyx_t_1 = __Pyx_PyInt_From_long(((__pyx_v_cluster[__pyx_v_k]).indices[__pyx_v_i])); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_5 = __Pyx_PyInt_From_long(__pyx_v_k); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_18 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_t_5); if (unlikely(__pyx_t_18 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1642; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_18);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyObject_GetItem(__pyx_t_18, __pyx_n_s_indices); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1642; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      if (unlikely(__Pyx_SetItemInt(__pyx_t_5, __pyx_v_i, __pyx_t_1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1642; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }

    /* "dipy/tracking/distances.pyx":1644
 *             C[k]['indices'][i]=cluster[k].indices[i]
 * 
 *         C[k]['indices']=list(C[k]['indices'])             # <<<<<<<<<<<<<<
 * 
 *     #Free memory
 */
    __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_k); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_t_1); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1644; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyObject_GetItem(__pyx_t_5, __pyx_n_s_indices); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1644; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v_k); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_18 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_t_1); if (unlikely(__pyx_t_18 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1644; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_18);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(PyObject_SetItem(__pyx_t_18, __pyx_n_s_indices, __pyx_t_5) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1644; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }

  /* "dipy/tracking/distances.pyx":1647
 * 
 *     #Free memory
 *     with nogil:             # <<<<<<<<<<<<<<
 * 
 *         for k from 0<=k<lenC:
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      #endif
      /*try:*/ {

        /* "dipy/tracking/distances.pyx":1649
 *     with nogil:
 * 
 *         for k from 0<=k<lenC:             # <<<<<<<<<<<<<<
 *             free(cluster[k].indices)
 *             free(cluster[k].hidden)
 */
        __pyx_t_12 = __pyx_v_lenC;
        for (__pyx_v_k = 0; __pyx_v_k < __pyx_t_12; __pyx_v_k++) {

          /* "dipy/tracking/distances.pyx":1650
 * 
 *         for k from 0<=k<lenC:
 *             free(cluster[k].indices)             # <<<<<<<<<<<<<<
 *             free(cluster[k].hidden)
 *         free(cluster)
 */
          free((__pyx_v_cluster[__pyx_v_k]).indices);

          /* "dipy/tracking/distances.pyx":1651
 *         for k from 0<=k<lenC:
 *             free(cluster[k].indices)
 *             free(cluster[k].hidden)             # <<<<<<<<<<<<<<
 *         free(cluster)
 * 
 */
          free((__pyx_v_cluster[__pyx_v_k]).hidden);
        }

        /* "dipy/tracking/distances.pyx":1652
 *             free(cluster[k].indices)
 *             free(cluster[k].hidden)
 *         free(cluster)             # <<<<<<<<<<<<<<
 * 
 *     return C
 */
        free(__pyx_v_cluster);
      }

      /* "dipy/tracking/distances.pyx":1647
 * 
 *     #Free memory
 *     with nogil:             # <<<<<<<<<<<<<<
 * 
 *         for k from 0<=k<lenC:
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L40;
        }
        __pyx_L40:;
      }
  }

  /* "dipy/tracking/distances.pyx":1654
 *         free(cluster)
 * 
 *     return C             # <<<<<<<<<<<<<<
 * 
 * def local_skeleton_clustering_3pts(tracks, d_thr=10):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_C);
  __pyx_r = __pyx_v_C;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":1471
 * @cython.wraparound(False)
 * @cython.cdivision(True)
 * def local_skeleton_clustering(tracks, d_thr=10):             # <<<<<<<<<<<<<<
 *     r"""Efficient tractography clustering
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_18);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.local_skeleton_clustering", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_track);
  __Pyx_XDECREF(__pyx_v_C);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":1656
 *     return C
 * 
 * def local_skeleton_clustering_3pts(tracks, d_thr=10):             # <<<<<<<<<<<<<<
 *     ''' Does a first pass clustering
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_43local_skeleton_clustering_3pts(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_42local_skeleton_clustering_3pts[] = " Does a first pass clustering\n\n    Every track can only have 3 pts neither less or more.\n    Use `dipy.tracking.metrics.downsample` to restrict the number of points\n\n    Parameters\n    ----------\n    tracks : sequence\n        of tracks as arrays, shape (N,3) .. (N,3) where N=3\n    d_thr : float\n        Average euclidean distance threshold\n\n    Returns\n    -------\n    C : dict\n       Clusters.\n\n    Examples\n    --------\n    >>> tracks=[np.array([[0,0,0],[1,0,0,],[2,0,0]]),\n    ...         np.array([[3,0,0],[3.5,1,0],[4,2,0]]),\n    ...         np.array([[3.2,0,0],[3.7,1,0],[4.4,2,0]]),\n    ...         np.array([[3.4,0,0],[3.9,1,0],[4.6,2,0]]),\n    ...         np.array([[0,0.2,0],[1,0.2,0],[2,0.2,0]]),\n    ...         np.array([[2,0.2,0],[1,0.2,0],[0,0.2,0]]),\n    ...         np.array([[0,0,0],[0,1,0],[0,2,0]])]\n    >>> C=local_skeleton_clustering_3pts(tracks,d_thr=0.5)\n\n    Notes\n    -----\n    It is possible to visualize the clustering C from the example\n    above using the fvtk module::\n\n        r=fvtk.ren()\n        for c in C:\n            color=np.random.rand(3)\n            for i in C[c]['indices']:\n                fvtk.add(r,fos.line(tracks[i],color))\n        fvtk.show(r)\n\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_43local_skeleton_clustering_3pts = {"local_skeleton_clustering_3pts", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_43local_skeleton_clustering_3pts, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_42local_skeleton_clustering_3pts};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_43local_skeleton_clustering_3pts(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_tracks = 0;
  PyObject *__pyx_v_d_thr = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("local_skeleton_clustering_3pts (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tracks,&__pyx_n_s_d_thr,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)__pyx_int_10);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tracks)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_d_thr);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "local_skeleton_clustering_3pts") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1656; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_tracks = values[0];
    __pyx_v_d_thr = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("local_skeleton_clustering_3pts", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1656; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.local_skeleton_clustering_3pts", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_42local_skeleton_clustering_3pts(__pyx_self, __pyx_v_tracks, __pyx_v_d_thr);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_42local_skeleton_clustering_3pts(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tracks, PyObject *__pyx_v_d_thr) {
  PyArrayObject *__pyx_v_track = 0;
  PyArrayObject *__pyx_v_h = 0;
  int __pyx_v_lent;
  int __pyx_v_k;
  int __pyx_v_it;
  float __pyx_v_d[2];
  PyObject *__pyx_v_C = NULL;
  PyObject *__pyx_v_ts = NULL;
  Py_ssize_t __pyx_v_lenC;
  PyObject *__pyx_v_alld = NULL;
  PyObject *__pyx_v_flip = NULL;
  PyObject *__pyx_v_m_k = NULL;
  PyObject *__pyx_v_i_k = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_h;
  __Pyx_Buffer __pyx_pybuffer_h;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_track;
  __Pyx_Buffer __pyx_pybuffer_track;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  int __pyx_t_8;
  PyArrayObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyArrayObject *__pyx_t_14 = NULL;
  int __pyx_t_15;
  PyObject *__pyx_t_16 = NULL;
  int __pyx_t_17;
  int __pyx_t_18;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("local_skeleton_clustering_3pts", 0);
  __pyx_pybuffer_track.pybuffer.buf = NULL;
  __pyx_pybuffer_track.refcount = 0;
  __pyx_pybuffernd_track.data = NULL;
  __pyx_pybuffernd_track.rcbuffer = &__pyx_pybuffer_track;
  __pyx_pybuffer_h.pybuffer.buf = NULL;
  __pyx_pybuffer_h.refcount = 0;
  __pyx_pybuffernd_h.data = NULL;
  __pyx_pybuffernd_h.rcbuffer = &__pyx_pybuffer_h;

  /* "dipy/tracking/distances.pyx":1705
 *         #float d_sq=d_thr**2
 * 
 *     lent=len(tracks)             # <<<<<<<<<<<<<<
 * 
 *     #Network C
 */
  __pyx_t_1 = PyObject_Length(__pyx_v_tracks); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1705; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_lent = __pyx_t_1;

  /* "dipy/tracking/distances.pyx":1708
 * 
 *     #Network C
 *     C={0:{'indices':[0],'hidden':tracks[0].copy(),'N':1}}             # <<<<<<<<<<<<<<
 *     ts=np.zeros((3,3),dtype=np.float32)
 * 
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyList_SET_ITEM(__pyx_t_4, 0, __pyx_int_0);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_indices, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_tracks, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_copy); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_6))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_6, function);
    }
  }
  if (__pyx_t_5) {
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_hidden, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_N, __pyx_int_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_2, __pyx_int_0, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1708; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_C = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "dipy/tracking/distances.pyx":1709
 *     #Network C
 *     C={0:{'indices':[0],'hidden':tracks[0].copy(),'N':1}}
 *     ts=np.zeros((3,3),dtype=np.float32)             # <<<<<<<<<<<<<<
 * 
 *     #for (it,t) in enumerate(tracks[1:]):
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_float32); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_6) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__13, __pyx_t_2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_ts = __pyx_t_6;
  __pyx_t_6 = 0;

  /* "dipy/tracking/distances.pyx":1712
 * 
 *     #for (it,t) in enumerate(tracks[1:]):
 *     for it in range(1,lent):             # <<<<<<<<<<<<<<
 *         track=np.ascontiguousarray(tracks[it],dtype=f32_dt)
 *         lenC=len(C.keys())
 */
  __pyx_t_7 = __pyx_v_lent;
  for (__pyx_t_8 = 1; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) {
    __pyx_v_it = __pyx_t_8;

    /* "dipy/tracking/distances.pyx":1713
 *     #for (it,t) in enumerate(tracks[1:]):
 *     for it in range(1,lent):
 *         track=np.ascontiguousarray(tracks[it],dtype=f32_dt)             # <<<<<<<<<<<<<<
 *         lenC=len(C.keys())
 *         #if it%1000==0:
 */
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_tracks, __pyx_v_it, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1713; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
    __pyx_t_6 = 0;
    __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_9 = ((PyArrayObject *)__pyx_t_4);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
      __pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track.rcbuffer->pybuffer, (PyObject*)__pyx_t_9, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_10 < 0)) {
        PyErr_Fetch(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track.rcbuffer->pybuffer, (PyObject*)__pyx_v_track, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_13);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_11, __pyx_t_12, __pyx_t_13);
        }
      }
      __pyx_pybuffernd_track.diminfo[0].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_track.diminfo[0].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_track.diminfo[1].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_track.diminfo[1].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1713; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_9 = 0;
    __Pyx_XDECREF_SET(__pyx_v_track, ((PyArrayObject *)__pyx_t_4));
    __pyx_t_4 = 0;

    /* "dipy/tracking/distances.pyx":1714
 *     for it in range(1,lent):
 *         track=np.ascontiguousarray(tracks[it],dtype=f32_dt)
 *         lenC=len(C.keys())             # <<<<<<<<<<<<<<
 *         #if it%1000==0:
 *         #    print it,lenC
 */
    __pyx_t_4 = __Pyx_PyDict_Keys(__pyx_v_C); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1714; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_lenC = __pyx_t_1;

    /* "dipy/tracking/distances.pyx":1717
 *         #if it%1000==0:
 *         #    print it,lenC
 *         alld=np.zeros(lenC)             # <<<<<<<<<<<<<<
 *         flip=np.zeros(lenC)
 *         for k in range(lenC):
 */
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_lenC); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_2 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(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);
      }
    }
    if (!__pyx_t_2) {
      __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_4);
    } else {
      __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1717; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL;
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1717; __pyx_clineno = __LINE__; goto __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_XDECREF_SET(__pyx_v_alld, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "dipy/tracking/distances.pyx":1718
 *         #    print it,lenC
 *         alld=np.zeros(lenC)
 *         flip=np.zeros(lenC)             # <<<<<<<<<<<<<<
 *         for k in range(lenC):
 *             h=np.ascontiguousarray(C[k]['hidden']/C[k]['N'],dtype=f32_dt)
 */
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_zeros); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_lenC); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_4);
    } else {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1718; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF_SET(__pyx_v_flip, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "dipy/tracking/distances.pyx":1719
 *         alld=np.zeros(lenC)
 *         flip=np.zeros(lenC)
 *         for k in range(lenC):             # <<<<<<<<<<<<<<
 *             h=np.ascontiguousarray(C[k]['hidden']/C[k]['N'],dtype=f32_dt)
 *             #print track
 */
    __pyx_t_1 = __pyx_v_lenC;
    for (__pyx_t_10 = 0; __pyx_t_10 < __pyx_t_1; __pyx_t_10+=1) {
      __pyx_v_k = __pyx_t_10;

      /* "dipy/tracking/distances.pyx":1720
 *         flip=np.zeros(lenC)
 *         for k in range(lenC):
 *             h=np.ascontiguousarray(C[k]['hidden']/C[k]['N'],dtype=f32_dt)             # <<<<<<<<<<<<<<
 *             #print track
 *             #print h
 */
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_k); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_t_4); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_GetItem(__pyx_t_2, __pyx_n_s_hidden); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __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_k); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_t_2); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_GetItem(__pyx_t_3, __pyx_n_s_N); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
      __pyx_t_3 = 0;
      __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_14 = ((PyArrayObject *)__pyx_t_4);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_h.rcbuffer->pybuffer);
        __pyx_t_15 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_h.rcbuffer->pybuffer, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_15 < 0)) {
          PyErr_Fetch(&__pyx_t_13, &__pyx_t_12, &__pyx_t_11);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_h.rcbuffer->pybuffer, (PyObject*)__pyx_v_h, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_13); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_11);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_13, __pyx_t_12, __pyx_t_11);
          }
        }
        __pyx_pybuffernd_h.diminfo[0].strides = __pyx_pybuffernd_h.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_h.diminfo[0].shape = __pyx_pybuffernd_h.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_h.diminfo[1].strides = __pyx_pybuffernd_h.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_h.diminfo[1].shape = __pyx_pybuffernd_h.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_15 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1720; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_14 = 0;
      __Pyx_XDECREF_SET(__pyx_v_h, ((PyArrayObject *)__pyx_t_4));
      __pyx_t_4 = 0;

      /* "dipy/tracking/distances.pyx":1724
 *             #print h
 *             track_direct_flip_3dist(
 *                 asfp(track[0]),asfp(track[1]),asfp(track[2]),             # <<<<<<<<<<<<<<
 *                 asfp(h[0]), asfp(h[1]),asfp(h[2]),<float *>d)
 *             #d=np.sum(np.sqrt(np.sum((t-h)**2,axis=1)))/3.0
 */
      __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1724; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_4);
      if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1724; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_3);
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1724; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_2);
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1724; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "dipy/tracking/distances.pyx":1725
 *             track_direct_flip_3dist(
 *                 asfp(track[0]),asfp(track[1]),asfp(track[2]),
 *                 asfp(h[0]), asfp(h[1]),asfp(h[2]),<float *>d)             # <<<<<<<<<<<<<<
 *             #d=np.sum(np.sqrt(np.sum((t-h)**2,axis=1)))/3.0
 *             #ts[0]=t[-1];ts[1]=t[1];ts[-1]=t[0]
 */
      __pyx_t_5 = __Pyx_GetItemInt(((PyObject *)__pyx_v_h), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1725; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_5);
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_6 = __Pyx_GetItemInt(((PyObject *)__pyx_v_h), 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1725; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_6);
      if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_16 = __Pyx_GetItemInt(((PyObject *)__pyx_v_h), 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_16 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1725; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_16);
      if (!(likely(((__pyx_t_16) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_16, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1725; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "dipy/tracking/distances.pyx":1723
 *             #print track
 *             #print h
 *             track_direct_flip_3dist(             # <<<<<<<<<<<<<<
 *                 asfp(track[0]),asfp(track[1]),asfp(track[2]),
 *                 asfp(h[0]), asfp(h[1]),asfp(h[2]),<float *>d)
 */
      __pyx_f_4dipy_8tracking_9distances_track_direct_flip_3dist(__pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_4)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_3)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_2)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_5)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_6)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_16)), ((float *)__pyx_v_d));
      __Pyx_DECREF(__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;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;

      /* "dipy/tracking/distances.pyx":1730
 *             #ds=np.sum(np.sqrt(np.sum((ts-h)**2,axis=1)))/3.0
 *             #print d[0],d[1]
 *             if d[1]<d[0]:             # <<<<<<<<<<<<<<
 *                 d[0]=d[1]
 *                 flip[k]=1
 */
      __pyx_t_17 = (((__pyx_v_d[1]) < (__pyx_v_d[0])) != 0);
      if (__pyx_t_17) {

        /* "dipy/tracking/distances.pyx":1731
 *             #print d[0],d[1]
 *             if d[1]<d[0]:
 *                 d[0]=d[1]             # <<<<<<<<<<<<<<
 *                 flip[k]=1
 *             alld[k]=d[0]
 */
        (__pyx_v_d[0]) = (__pyx_v_d[1]);

        /* "dipy/tracking/distances.pyx":1732
 *             if d[1]<d[0]:
 *                 d[0]=d[1]
 *                 flip[k]=1             # <<<<<<<<<<<<<<
 *             alld[k]=d[0]
 *         m_k=np.min(alld)
 */
        if (unlikely(__Pyx_SetItemInt(__pyx_v_flip, __pyx_v_k, __pyx_int_1, int, 1, __Pyx_PyInt_From_int, 0, 1, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1732; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

        /* "dipy/tracking/distances.pyx":1730
 *             #ds=np.sum(np.sqrt(np.sum((ts-h)**2,axis=1)))/3.0
 *             #print d[0],d[1]
 *             if d[1]<d[0]:             # <<<<<<<<<<<<<<
 *                 d[0]=d[1]
 *                 flip[k]=1
 */
      }

      /* "dipy/tracking/distances.pyx":1733
 *                 d[0]=d[1]
 *                 flip[k]=1
 *             alld[k]=d[0]             # <<<<<<<<<<<<<<
 *         m_k=np.min(alld)
 *         i_k=np.argmin(alld)
 */
      __pyx_t_16 = PyFloat_FromDouble((__pyx_v_d[0])); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_16);
      if (unlikely(__Pyx_SetItemInt(__pyx_v_alld, __pyx_v_k, __pyx_t_16, int, 1, __Pyx_PyInt_From_int, 0, 1, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1733; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    }

    /* "dipy/tracking/distances.pyx":1734
 *                 flip[k]=1
 *             alld[k]=d[0]
 *         m_k=np.min(alld)             # <<<<<<<<<<<<<<
 *         i_k=np.argmin(alld)
 *         if m_k<d_thr:
 */
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_min); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_16 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_alld); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_16);
    } else {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_6); __pyx_t_6 = NULL;
      __Pyx_INCREF(__pyx_v_alld);
      __Pyx_GIVEREF(__pyx_v_alld);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_alld);
      __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1734; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_16);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF_SET(__pyx_v_m_k, __pyx_t_16);
    __pyx_t_16 = 0;

    /* "dipy/tracking/distances.pyx":1735
 *             alld[k]=d[0]
 *         m_k=np.min(alld)
 *         i_k=np.argmin(alld)             # <<<<<<<<<<<<<<
 *         if m_k<d_thr:
 *             if flip[i_k]==1:
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_argmin); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    if (!__pyx_t_5) {
      __pyx_t_16 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_alld); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_16);
    } else {
      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
      __Pyx_INCREF(__pyx_v_alld);
      __Pyx_GIVEREF(__pyx_v_alld);
      PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_alld);
      __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1735; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_16);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF_SET(__pyx_v_i_k, __pyx_t_16);
    __pyx_t_16 = 0;

    /* "dipy/tracking/distances.pyx":1736
 *         m_k=np.min(alld)
 *         i_k=np.argmin(alld)
 *         if m_k<d_thr:             # <<<<<<<<<<<<<<
 *             if flip[i_k]==1:
 *                 ts[0]=track[-1];ts[1]=track[1];ts[-1]=track[0]
 */
    __pyx_t_16 = PyObject_RichCompare(__pyx_v_m_k, __pyx_v_d_thr, Py_LT); __Pyx_XGOTREF(__pyx_t_16); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_16); if (unlikely(__pyx_t_17 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1736; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    if (__pyx_t_17) {

      /* "dipy/tracking/distances.pyx":1737
 *         i_k=np.argmin(alld)
 *         if m_k<d_thr:
 *             if flip[i_k]==1:             # <<<<<<<<<<<<<<
 *                 ts[0]=track[-1];ts[1]=track[1];ts[-1]=track[0]
 *                 C[i_k]['hidden'] = C[i_k]['hidden'] + ts
 */
      __pyx_t_16 = PyObject_GetItem(__pyx_v_flip, __pyx_v_i_k); if (unlikely(__pyx_t_16 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_16);
      __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_16, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __pyx_t_17 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_17 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1737; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__pyx_t_17) {

        /* "dipy/tracking/distances.pyx":1738
 *         if m_k<d_thr:
 *             if flip[i_k]==1:
 *                 ts[0]=track[-1];ts[1]=track[1];ts[-1]=track[0]             # <<<<<<<<<<<<<<
 *                 C[i_k]['hidden'] = C[i_k]['hidden'] + ts
 *             else:
 */
        __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_2);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_ts, 0, __pyx_t_2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_2);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_ts, 1, __pyx_t_2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_2);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_ts, -1L, __pyx_t_2, long, 1, __Pyx_PyInt_From_long, 0, 1, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1738; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "dipy/tracking/distances.pyx":1739
 *             if flip[i_k]==1:
 *                 ts[0]=track[-1];ts[1]=track[1];ts[-1]=track[0]
 *                 C[i_k]['hidden'] = C[i_k]['hidden'] + ts             # <<<<<<<<<<<<<<
 *             else:
 *                 #print(track.shape)
 */
        __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_v_i_k); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1739; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_16 = PyObject_GetItem(__pyx_t_2, __pyx_n_s_hidden); if (unlikely(__pyx_t_16 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1739; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_16);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyNumber_Add(__pyx_t_16, __pyx_v_ts); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        __pyx_t_16 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_v_i_k); if (unlikely(__pyx_t_16 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1739; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_16);
        if (unlikely(PyObject_SetItem(__pyx_t_16, __pyx_n_s_hidden, __pyx_t_2) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1739; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "dipy/tracking/distances.pyx":1737
 *         i_k=np.argmin(alld)
 *         if m_k<d_thr:
 *             if flip[i_k]==1:             # <<<<<<<<<<<<<<
 *                 ts[0]=track[-1];ts[1]=track[1];ts[-1]=track[0]
 *                 C[i_k]['hidden'] = C[i_k]['hidden'] + ts
 */
        goto __pyx_L9;
      }

      /* "dipy/tracking/distances.pyx":1743
 *                 #print(track.shape)
 *                 #print(track.dtype)
 *                 C[i_k]['hidden'] = C[i_k]['hidden'] + track             # <<<<<<<<<<<<<<
 *             C[i_k]['N'] = C[i_k]['N'] + 1
 *             C[i_k]['indices'].append(it)
 */
      /*else*/ {
        __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_v_i_k); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1743; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_16 = PyObject_GetItem(__pyx_t_2, __pyx_n_s_hidden); if (unlikely(__pyx_t_16 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1743; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_16);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = PyNumber_Add(__pyx_t_16, ((PyObject *)__pyx_v_track)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        __pyx_t_16 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_v_i_k); if (unlikely(__pyx_t_16 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1743; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_16);
        if (unlikely(PyObject_SetItem(__pyx_t_16, __pyx_n_s_hidden, __pyx_t_2) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1743; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __pyx_L9:;

      /* "dipy/tracking/distances.pyx":1744
 *                 #print(track.dtype)
 *                 C[i_k]['hidden'] = C[i_k]['hidden'] + track
 *             C[i_k]['N'] = C[i_k]['N'] + 1             # <<<<<<<<<<<<<<
 *             C[i_k]['indices'].append(it)
 *         else:
 */
      __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_v_i_k); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1744; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_16 = PyObject_GetItem(__pyx_t_2, __pyx_n_s_N); if (unlikely(__pyx_t_16 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1744; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_16);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_16, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __pyx_t_16 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_v_i_k); if (unlikely(__pyx_t_16 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1744; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_16);
      if (unlikely(PyObject_SetItem(__pyx_t_16, __pyx_n_s_N, __pyx_t_2) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1744; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "dipy/tracking/distances.pyx":1745
 *                 C[i_k]['hidden'] = C[i_k]['hidden'] + track
 *             C[i_k]['N'] = C[i_k]['N'] + 1
 *             C[i_k]['indices'].append(it)             # <<<<<<<<<<<<<<
 *         else:
 *             C[lenC]={}
 */
      __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_v_i_k); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1745; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_16 = PyObject_GetItem(__pyx_t_2, __pyx_n_s_indices); if (unlikely(__pyx_t_16 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1745; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_16);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_it); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_18 = __Pyx_PyObject_Append(__pyx_t_16, __pyx_t_2); if (unlikely(__pyx_t_18 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1745; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "dipy/tracking/distances.pyx":1736
 *         m_k=np.min(alld)
 *         i_k=np.argmin(alld)
 *         if m_k<d_thr:             # <<<<<<<<<<<<<<
 *             if flip[i_k]==1:
 *                 ts[0]=track[-1];ts[1]=track[1];ts[-1]=track[0]
 */
      goto __pyx_L8;
    }

    /* "dipy/tracking/distances.pyx":1747
 *             C[i_k]['indices'].append(it)
 *         else:
 *             C[lenC]={}             # <<<<<<<<<<<<<<
 *             C[lenC]['hidden']=track.copy()
 *             C[lenC]['N']=1
 */
    /*else*/ {
      __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_16 = PyInt_FromSsize_t(__pyx_v_lenC); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_16);
      if (unlikely(PyDict_SetItem(__pyx_v_C, __pyx_t_16, __pyx_t_2) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1747; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "dipy/tracking/distances.pyx":1748
 *         else:
 *             C[lenC]={}
 *             C[lenC]['hidden']=track.copy()             # <<<<<<<<<<<<<<
 *             C[lenC]['N']=1
 *             C[lenC]['indices']=[it]
 */
      __pyx_t_16 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_track), __pyx_n_s_copy); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_16);
      __pyx_t_6 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_16))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_16);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_16, function);
        }
      }
      if (__pyx_t_6) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_6); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else {
        __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_16); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __pyx_t_16 = PyInt_FromSsize_t(__pyx_v_lenC); if (unlikely(!__pyx_t_16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_16);
      __pyx_t_6 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_t_16); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1748; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      if (unlikely(PyObject_SetItem(__pyx_t_6, __pyx_n_s_hidden, __pyx_t_2) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1748; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "dipy/tracking/distances.pyx":1749
 *             C[lenC]={}
 *             C[lenC]['hidden']=track.copy()
 *             C[lenC]['N']=1             # <<<<<<<<<<<<<<
 *             C[lenC]['indices']=[it]
 *     return C
 */
      __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_lenC); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_t_2); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1749; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(PyObject_SetItem(__pyx_t_6, __pyx_n_s_N, __pyx_int_1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1749; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "dipy/tracking/distances.pyx":1750
 *             C[lenC]['hidden']=track.copy()
 *             C[lenC]['N']=1
 *             C[lenC]['indices']=[it]             # <<<<<<<<<<<<<<
 *     return C
 * 
 */
      __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_it); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_6);
      PyList_SET_ITEM(__pyx_t_2, 0, __pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_lenC); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_16 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_t_6); if (unlikely(__pyx_t_16 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1750; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_16);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(PyObject_SetItem(__pyx_t_16, __pyx_n_s_indices, __pyx_t_2) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1750; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __pyx_L8:;
  }

  /* "dipy/tracking/distances.pyx":1751
 *             C[lenC]['N']=1
 *             C[lenC]['indices']=[it]
 *     return C             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_C);
  __pyx_r = __pyx_v_C;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":1656
 *     return C
 * 
 * def local_skeleton_clustering_3pts(tracks, d_thr=10):             # <<<<<<<<<<<<<<
 *     ''' Does a first pass clustering
 * 
 */

  /* 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_XDECREF(__pyx_t_16);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_h.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.local_skeleton_clustering_3pts", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_h.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_track);
  __Pyx_XDECREF((PyObject *)__pyx_v_h);
  __Pyx_XDECREF(__pyx_v_C);
  __Pyx_XDECREF(__pyx_v_ts);
  __Pyx_XDECREF(__pyx_v_alld);
  __Pyx_XDECREF(__pyx_v_flip);
  __Pyx_XDECREF(__pyx_v_m_k);
  __Pyx_XDECREF(__pyx_v_i_k);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":1754
 * 
 * 
 * cdef inline void track_direct_flip_3sq_dist(float *a1, float *b1,float  *c1,float *a2, float *b2, float *c2, float *out):             # <<<<<<<<<<<<<<
 *     ''' Calculate the average squared euclidean distance between two 3pt tracks
 *     both direct and flip are given as output
 */

static CYTHON_INLINE void __pyx_f_4dipy_8tracking_9distances_track_direct_flip_3sq_dist(float *__pyx_v_a1, float *__pyx_v_b1, float *__pyx_v_c1, float *__pyx_v_a2, float *__pyx_v_b2, float *__pyx_v_c2, float *__pyx_v_out) {
  int __pyx_v_i;
  float __pyx_v_tmp1;
  float __pyx_v_tmp2;
  float __pyx_v_tmp3;
  float __pyx_v_tmp1f;
  float __pyx_v_tmp3f;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("track_direct_flip_3sq_dist", 0);

  /* "dipy/tracking/distances.pyx":1773
 *     cdef:
 *         int i
 *         float tmp1=0,tmp2=0,tmp3=0,tmp1f=0,tmp3f=0             # <<<<<<<<<<<<<<
 *     #for i in range(3):
 *     for i from 0<=i<3:
 */
  __pyx_v_tmp1 = 0.0;
  __pyx_v_tmp2 = 0.0;
  __pyx_v_tmp3 = 0.0;
  __pyx_v_tmp1f = 0.0;
  __pyx_v_tmp3f = 0.0;

  /* "dipy/tracking/distances.pyx":1775
 *         float tmp1=0,tmp2=0,tmp3=0,tmp1f=0,tmp3f=0
 *     #for i in range(3):
 *     for i from 0<=i<3:             # <<<<<<<<<<<<<<
 *         tmp1=tmp1+(a1[i]-a2[i])*(a1[i]-a2[i])
 *         tmp2=tmp2+(b1[i]-b2[i])*(b1[i]-b2[i])
 */
  for (__pyx_v_i = 0; __pyx_v_i < 3; __pyx_v_i++) {

    /* "dipy/tracking/distances.pyx":1776
 *     #for i in range(3):
 *     for i from 0<=i<3:
 *         tmp1=tmp1+(a1[i]-a2[i])*(a1[i]-a2[i])             # <<<<<<<<<<<<<<
 *         tmp2=tmp2+(b1[i]-b2[i])*(b1[i]-b2[i])
 *         tmp3=tmp3+(c1[i]-c2[i])*(c1[i]-c2[i])
 */
    __pyx_v_tmp1 = (__pyx_v_tmp1 + (((__pyx_v_a1[__pyx_v_i]) - (__pyx_v_a2[__pyx_v_i])) * ((__pyx_v_a1[__pyx_v_i]) - (__pyx_v_a2[__pyx_v_i]))));

    /* "dipy/tracking/distances.pyx":1777
 *     for i from 0<=i<3:
 *         tmp1=tmp1+(a1[i]-a2[i])*(a1[i]-a2[i])
 *         tmp2=tmp2+(b1[i]-b2[i])*(b1[i]-b2[i])             # <<<<<<<<<<<<<<
 *         tmp3=tmp3+(c1[i]-c2[i])*(c1[i]-c2[i])
 *         tmp1f=tmp1f+(a1[i]-c2[i])*(a1[i]-c2[i])
 */
    __pyx_v_tmp2 = (__pyx_v_tmp2 + (((__pyx_v_b1[__pyx_v_i]) - (__pyx_v_b2[__pyx_v_i])) * ((__pyx_v_b1[__pyx_v_i]) - (__pyx_v_b2[__pyx_v_i]))));

    /* "dipy/tracking/distances.pyx":1778
 *         tmp1=tmp1+(a1[i]-a2[i])*(a1[i]-a2[i])
 *         tmp2=tmp2+(b1[i]-b2[i])*(b1[i]-b2[i])
 *         tmp3=tmp3+(c1[i]-c2[i])*(c1[i]-c2[i])             # <<<<<<<<<<<<<<
 *         tmp1f=tmp1f+(a1[i]-c2[i])*(a1[i]-c2[i])
 *         tmp3f=tmp3f+(c1[i]-a2[i])*(c1[i]-a2[i])
 */
    __pyx_v_tmp3 = (__pyx_v_tmp3 + (((__pyx_v_c1[__pyx_v_i]) - (__pyx_v_c2[__pyx_v_i])) * ((__pyx_v_c1[__pyx_v_i]) - (__pyx_v_c2[__pyx_v_i]))));

    /* "dipy/tracking/distances.pyx":1779
 *         tmp2=tmp2+(b1[i]-b2[i])*(b1[i]-b2[i])
 *         tmp3=tmp3+(c1[i]-c2[i])*(c1[i]-c2[i])
 *         tmp1f=tmp1f+(a1[i]-c2[i])*(a1[i]-c2[i])             # <<<<<<<<<<<<<<
 *         tmp3f=tmp3f+(c1[i]-a2[i])*(c1[i]-a2[i])
 * 
 */
    __pyx_v_tmp1f = (__pyx_v_tmp1f + (((__pyx_v_a1[__pyx_v_i]) - (__pyx_v_c2[__pyx_v_i])) * ((__pyx_v_a1[__pyx_v_i]) - (__pyx_v_c2[__pyx_v_i]))));

    /* "dipy/tracking/distances.pyx":1780
 *         tmp3=tmp3+(c1[i]-c2[i])*(c1[i]-c2[i])
 *         tmp1f=tmp1f+(a1[i]-c2[i])*(a1[i]-c2[i])
 *         tmp3f=tmp3f+(c1[i]-a2[i])*(c1[i]-a2[i])             # <<<<<<<<<<<<<<
 * 
 *     out[0]=(tmp1+tmp2+tmp3)/3.0
 */
    __pyx_v_tmp3f = (__pyx_v_tmp3f + (((__pyx_v_c1[__pyx_v_i]) - (__pyx_v_a2[__pyx_v_i])) * ((__pyx_v_c1[__pyx_v_i]) - (__pyx_v_a2[__pyx_v_i]))));
  }

  /* "dipy/tracking/distances.pyx":1782
 *         tmp3f=tmp3f+(c1[i]-a2[i])*(c1[i]-a2[i])
 * 
 *     out[0]=(tmp1+tmp2+tmp3)/3.0             # <<<<<<<<<<<<<<
 *     out[1]=(tmp1f+tmp2+tmp3f)/3.0
 * 
 */
  (__pyx_v_out[0]) = (((__pyx_v_tmp1 + __pyx_v_tmp2) + __pyx_v_tmp3) / 3.0);

  /* "dipy/tracking/distances.pyx":1783
 * 
 *     out[0]=(tmp1+tmp2+tmp3)/3.0
 *     out[1]=(tmp1f+tmp2+tmp3f)/3.0             # <<<<<<<<<<<<<<
 * 
 * 
 */
  (__pyx_v_out[1]) = (((__pyx_v_tmp1f + __pyx_v_tmp2) + __pyx_v_tmp3f) / 3.0);

  /* "dipy/tracking/distances.pyx":1754
 * 
 * 
 * cdef inline void track_direct_flip_3sq_dist(float *a1, float *b1,float  *c1,float *a2, float *b2, float *c2, float *out):             # <<<<<<<<<<<<<<
 *     ''' Calculate the average squared euclidean distance between two 3pt tracks
 *     both direct and flip are given as output
 */

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

/* "dipy/tracking/distances.pyx":1786
 * 
 * 
 * def larch_3split(tracks, indices=None, thr=10.):             # <<<<<<<<<<<<<<
 *     '''Generate a first pass clustering using 3 points on the tracks only.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_45larch_3split(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_44larch_3split[] = "Generate a first pass clustering using 3 points on the tracks only.\n\n    Parameters\n    ----------\n    tracks : sequence\n        of tracks as arrays, shape ``(N1,3) .. (Nm,3)``, where 3 points are\n        (first, mid and last)\n    indices : None or sequence, optional\n        Sequence of integer indices of tracks\n    trh : float, optional\n        squared euclidean distance threshold\n\n    Returns\n    -------\n    C : dict\n        A tree graph containing the clusters.\n\n    Notes\n    -----\n    If a 3 point track (3track) is far away from all clusters then add a new\n    cluster and assign this 3track as the rep(representative) track for the new\n    cluster. Otherwise the rep 3track of each cluster is the average track of\n    the cluster.\n\n    Examples\n    --------\n    >>> tracks=[np.array([[0,0,0],[1,0,0,],[2,0,0]],dtype=np.float32),\n    ...         np.array([[3,0,0],[3.5,1,0],[4,2,0]],dtype=np.float32),\n    ...         np.array([[3.2,0,0],[3.7,1,0],[4.4,2,0]],dtype=np.float32),\n    ...         np.array([[3.4,0,0],[3.9,1,0],[4.6,2,0]],dtype=np.float32),\n    ...         np.array([[0,0.2,0],[1,0.2,0],[2,0.2,0]],dtype=np.float32),\n    ...         np.array([[2,0.2,0],[1,0.2,0],[0,0.2,0]],dtype=np.float32),\n    ...         np.array([[0,0,0],[0,1,0],[0,2,0]],dtype=np.float32),\n    ...         np.array([[0.2,0,0],[0.2,1,0],[0.2,2,0]],dtype=np.float32),\n    ...         np.array([[-0.2,0,0],[-0.2,1,0],[-0.2,2,0]],dtype=np.float32)]\n    >>> C = larch_3split(tracks, None, 0.5)\n\n    Here is an example of how to visualize the clustering above::\n\n        from dipy.viz import fvtk\n        r=fvtk.ren()\n        fvtk.add(r,fvtk.line(tracks,fvtk.red))\n        fvtk.show(r)\n        for c in C:\n            color=np.random.rand(3)\n            for i in C[c]['indices']:\n                fos.add(r,fvtk.line(tracks[i],color))\n        fvtk.show(r)\n        for c in C:\n            fvtk.add(r,fos.line(C[c]['rep3']/C[c]['N'],fos.white))\n        fvtk.show(""r)\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_45larch_3split = {"larch_3split", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_45larch_3split, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_44larch_3split};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_45larch_3split(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_tracks = 0;
  PyObject *__pyx_v_indices = 0;
  PyObject *__pyx_v_thr = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("larch_3split (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tracks,&__pyx_n_s_indices,&__pyx_n_s_thr,0};
    PyObject* values[3] = {0,0,0};
    values[1] = ((PyObject *)Py_None);
    values[2] = ((PyObject *)__pyx_float_10_);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tracks)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_indices);
          if (value) { values[1] = value; kw_args--; }
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_thr);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "larch_3split") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1786; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_tracks = values[0];
    __pyx_v_indices = values[1];
    __pyx_v_thr = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("larch_3split", 0, 1, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1786; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.larch_3split", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_44larch_3split(__pyx_self, __pyx_v_tracks, __pyx_v_indices, __pyx_v_thr);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_44larch_3split(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tracks, PyObject *__pyx_v_indices, PyObject *__pyx_v_thr) {
  PyArrayObject *__pyx_v_track = 0;
  PyArrayObject *__pyx_v_h = 0;
  int __pyx_v_lent;
  int __pyx_v_k;
  int __pyx_v_it;
  float __pyx_v_d[2];
  PyObject *__pyx_v_C = NULL;
  PyObject *__pyx_v_itrange = NULL;
  PyObject *__pyx_v_ts = NULL;
  Py_ssize_t __pyx_v_lenC;
  PyObject *__pyx_v_alld = NULL;
  PyObject *__pyx_v_flip = NULL;
  PyObject *__pyx_v_m_k = NULL;
  PyObject *__pyx_v_i_k = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_h;
  __Pyx_Buffer __pyx_pybuffer_h;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_track;
  __Pyx_Buffer __pyx_pybuffer_track;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *(*__pyx_t_8)(PyObject *);
  int __pyx_t_9;
  PyArrayObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  Py_ssize_t __pyx_t_14;
  PyObject *__pyx_t_15 = NULL;
  PyArrayObject *__pyx_t_16 = NULL;
  int __pyx_t_17;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  int __pyx_t_20;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("larch_3split", 0);
  __pyx_pybuffer_track.pybuffer.buf = NULL;
  __pyx_pybuffer_track.refcount = 0;
  __pyx_pybuffernd_track.data = NULL;
  __pyx_pybuffernd_track.rcbuffer = &__pyx_pybuffer_track;
  __pyx_pybuffer_h.pybuffer.buf = NULL;
  __pyx_pybuffer_h.refcount = 0;
  __pyx_pybuffernd_h.data = NULL;
  __pyx_pybuffernd_h.rcbuffer = &__pyx_pybuffer_h;

  /* "dipy/tracking/distances.pyx":1846
 *         float d[2]
 * 
 *     lent=len(tracks)             # <<<<<<<<<<<<<<
 *     if indices==None:
 *         C={0:{'indices':[0],'rep3':tracks[0].copy(),'N':1}}
 */
  __pyx_t_1 = PyObject_Length(__pyx_v_tracks); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1846; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_lent = __pyx_t_1;

  /* "dipy/tracking/distances.pyx":1847
 * 
 *     lent=len(tracks)
 *     if indices==None:             # <<<<<<<<<<<<<<
 *         C={0:{'indices':[0],'rep3':tracks[0].copy(),'N':1}}
 *         itrange=range(1,lent)
 */
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_indices, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1847; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1847; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "dipy/tracking/distances.pyx":1848
 *     lent=len(tracks)
 *     if indices==None:
 *         C={0:{'indices':[0],'rep3':tracks[0].copy(),'N':1}}             # <<<<<<<<<<<<<<
 *         itrange=range(1,lent)
 *     else:
 */
    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyList_New(1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_int_0);
    __Pyx_GIVEREF(__pyx_int_0);
    PyList_SET_ITEM(__pyx_t_5, 0, __pyx_int_0);
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_indices, __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_tracks, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_copy); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    if (__pyx_t_6) {
      __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else {
      __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_rep3, __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_N, __pyx_int_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (PyDict_SetItem(__pyx_t_2, __pyx_int_0, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1848; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_C = ((PyObject*)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "dipy/tracking/distances.pyx":1849
 *     if indices==None:
 *         C={0:{'indices':[0],'rep3':tracks[0].copy(),'N':1}}
 *         itrange=range(1,lent)             # <<<<<<<<<<<<<<
 *     else:
 *         C={0:{'indices':[indices[0]],'rep3':tracks[indices[0]].copy(),'N':1}}
 */
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_lent); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_int_1);
    __Pyx_GIVEREF(__pyx_int_1);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_1);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_itrange = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "dipy/tracking/distances.pyx":1847
 * 
 *     lent=len(tracks)
 *     if indices==None:             # <<<<<<<<<<<<<<
 *         C={0:{'indices':[0],'rep3':tracks[0].copy(),'N':1}}
 *         itrange=range(1,lent)
 */
    goto __pyx_L3;
  }

  /* "dipy/tracking/distances.pyx":1851
 *         itrange=range(1,lent)
 *     else:
 *         C={0:{'indices':[indices[0]],'rep3':tracks[indices[0]].copy(),'N':1}}             # <<<<<<<<<<<<<<
 *         itrange=indices[1:]
 * 
 */
  /*else*/ {
    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_indices, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_5);
    PyList_SET_ITEM(__pyx_t_7, 0, __pyx_t_5);
    __pyx_t_5 = 0;
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_indices, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_indices, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_5 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PyObject_GetItem(__pyx_v_tracks, __pyx_t_5); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_copy); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    if (__pyx_t_6) {
      __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else {
      __pyx_t_7 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_rep3, __pyx_t_7) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_N, __pyx_int_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (PyDict_SetItem(__pyx_t_2, __pyx_int_0, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1851; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_C = ((PyObject*)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "dipy/tracking/distances.pyx":1852
 *     else:
 *         C={0:{'indices':[indices[0]],'rep3':tracks[indices[0]].copy(),'N':1}}
 *         itrange=indices[1:]             # <<<<<<<<<<<<<<
 * 
 *     ts=np.zeros((3,3),dtype=np.float32)
 */
    __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_indices, 1, 0, NULL, NULL, &__pyx_slice__14, 1, 0, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_itrange = __pyx_t_2;
    __pyx_t_2 = 0;
  }
  __pyx_L3:;

  /* "dipy/tracking/distances.pyx":1854
 *         itrange=indices[1:]
 * 
 *     ts=np.zeros((3,3),dtype=np.float32)             # <<<<<<<<<<<<<<
 *     for it in itrange:
 *         track=np.ascontiguousarray(tracks[it],dtype=f32_dt)
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1854; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_float32); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_t_5) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__16, __pyx_t_2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_ts = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "dipy/tracking/distances.pyx":1855
 * 
 *     ts=np.zeros((3,3),dtype=np.float32)
 *     for it in itrange:             # <<<<<<<<<<<<<<
 *         track=np.ascontiguousarray(tracks[it],dtype=f32_dt)
 *         lenC=len(C.keys())
 */
  if (likely(PyList_CheckExact(__pyx_v_itrange)) || PyTuple_CheckExact(__pyx_v_itrange)) {
    __pyx_t_5 = __pyx_v_itrange; __Pyx_INCREF(__pyx_t_5); __pyx_t_1 = 0;
    __pyx_t_8 = NULL;
  } else {
    __pyx_t_1 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_itrange); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_8 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  for (;;) {
    if (likely(!__pyx_t_8)) {
      if (likely(PyList_CheckExact(__pyx_t_5))) {
        if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_2 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_5, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      } else {
        if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_COMPILING_IN_CPYTHON
        __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        #else
        __pyx_t_2 = PySequence_ITEM(__pyx_t_5, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        #endif
      }
    } else {
      __pyx_t_2 = __pyx_t_8(__pyx_t_5);
      if (unlikely(!__pyx_t_2)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_2);
    }
    __pyx_t_9 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_9 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1855; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_it = __pyx_t_9;

    /* "dipy/tracking/distances.pyx":1856
 *     ts=np.zeros((3,3),dtype=np.float32)
 *     for it in itrange:
 *         track=np.ascontiguousarray(tracks[it],dtype=f32_dt)             # <<<<<<<<<<<<<<
 *         lenC=len(C.keys())
 *         alld=np.zeros(lenC)
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_tracks, __pyx_v_it, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1856; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_10 = ((PyArrayObject *)__pyx_t_6);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
      __pyx_t_9 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track.rcbuffer->pybuffer, (PyObject*)__pyx_t_10, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_9 < 0)) {
        PyErr_Fetch(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track.rcbuffer->pybuffer, (PyObject*)__pyx_v_track, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_13);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_11, __pyx_t_12, __pyx_t_13);
        }
      }
      __pyx_pybuffernd_track.diminfo[0].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_track.diminfo[0].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_track.diminfo[1].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_track.diminfo[1].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_9 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1856; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_10 = 0;
    __Pyx_XDECREF_SET(__pyx_v_track, ((PyArrayObject *)__pyx_t_6));
    __pyx_t_6 = 0;

    /* "dipy/tracking/distances.pyx":1857
 *     for it in itrange:
 *         track=np.ascontiguousarray(tracks[it],dtype=f32_dt)
 *         lenC=len(C.keys())             # <<<<<<<<<<<<<<
 *         alld=np.zeros(lenC)
 *         flip=np.zeros(lenC)
 */
    __pyx_t_6 = __Pyx_PyDict_Keys(__pyx_v_C); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_14 = PyObject_Length(__pyx_t_6); if (unlikely(__pyx_t_14 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1857; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_lenC = __pyx_t_14;

    /* "dipy/tracking/distances.pyx":1858
 *         track=np.ascontiguousarray(tracks[it],dtype=f32_dt)
 *         lenC=len(C.keys())
 *         alld=np.zeros(lenC)             # <<<<<<<<<<<<<<
 *         flip=np.zeros(lenC)
 * 
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_lenC); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    if (!__pyx_t_4) {
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_6);
    } else {
      __pyx_t_15 = PyTuple_New(1+1); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_4); __pyx_t_4 = NULL;
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_15, 0+1, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_15, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1858; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_XDECREF_SET(__pyx_v_alld, __pyx_t_6);
    __pyx_t_6 = 0;

    /* "dipy/tracking/distances.pyx":1859
 *         lenC=len(C.keys())
 *         alld=np.zeros(lenC)
 *         flip=np.zeros(lenC)             # <<<<<<<<<<<<<<
 * 
 *         for k in range(lenC):
 */
    __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_zeros); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyInt_FromSsize_t(__pyx_v_lenC); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_2 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_15))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_15);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_15, function);
      }
    }
    if (!__pyx_t_2) {
      __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_t_7); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_6);
    } else {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL;
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_4, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1859; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_XDECREF_SET(__pyx_v_flip, __pyx_t_6);
    __pyx_t_6 = 0;

    /* "dipy/tracking/distances.pyx":1861
 *         flip=np.zeros(lenC)
 * 
 *         for k in range(lenC):             # <<<<<<<<<<<<<<
 *             h=np.ascontiguousarray(C[k]['rep3']/C[k]['N'],dtype=f32_dt)
 *             track_direct_flip_3dist(asfp(track[0]),asfp(track[1]),asfp(track[2]),
 */
    __pyx_t_14 = __pyx_v_lenC;
    for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_14; __pyx_t_9+=1) {
      __pyx_v_k = __pyx_t_9;

      /* "dipy/tracking/distances.pyx":1862
 * 
 *         for k in range(lenC):
 *             h=np.ascontiguousarray(C[k]['rep3']/C[k]['N'],dtype=f32_dt)             # <<<<<<<<<<<<<<
 *             track_direct_flip_3dist(asfp(track[0]),asfp(track[1]),asfp(track[2]),
 *                                     asfp(h[0]), asfp(h[1]), asfp(h[2]),d)
 */
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_15);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_k); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_t_6); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1862; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyObject_GetItem(__pyx_t_4, __pyx_n_s_rep3); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1862; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_k); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_t_4); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1862; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_GetItem(__pyx_t_7, __pyx_n_s_N); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1862; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_7 = __Pyx_PyNumber_Divide(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_7);
      if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_4, __pyx_t_7); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_16 = ((PyArrayObject *)__pyx_t_6);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_h.rcbuffer->pybuffer);
        __pyx_t_17 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_h.rcbuffer->pybuffer, (PyObject*)__pyx_t_16, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_17 < 0)) {
          PyErr_Fetch(&__pyx_t_13, &__pyx_t_12, &__pyx_t_11);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_h.rcbuffer->pybuffer, (PyObject*)__pyx_v_h, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_13); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_11);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_13, __pyx_t_12, __pyx_t_11);
          }
        }
        __pyx_pybuffernd_h.diminfo[0].strides = __pyx_pybuffernd_h.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_h.diminfo[0].shape = __pyx_pybuffernd_h.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_h.diminfo[1].strides = __pyx_pybuffernd_h.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_h.diminfo[1].shape = __pyx_pybuffernd_h.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_17 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1862; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_16 = 0;
      __Pyx_XDECREF_SET(__pyx_v_h, ((PyArrayObject *)__pyx_t_6));
      __pyx_t_6 = 0;

      /* "dipy/tracking/distances.pyx":1863
 *         for k in range(lenC):
 *             h=np.ascontiguousarray(C[k]['rep3']/C[k]['N'],dtype=f32_dt)
 *             track_direct_flip_3dist(asfp(track[0]),asfp(track[1]),asfp(track[2]),             # <<<<<<<<<<<<<<
 *                                     asfp(h[0]), asfp(h[1]), asfp(h[2]),d)
 *             if d[1]<d[0]:
 */
      __pyx_t_6 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_6 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1863; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_6);
      if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_7 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1863; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_7);
      if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1863; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_4);
      if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1863; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "dipy/tracking/distances.pyx":1864
 *             h=np.ascontiguousarray(C[k]['rep3']/C[k]['N'],dtype=f32_dt)
 *             track_direct_flip_3dist(asfp(track[0]),asfp(track[1]),asfp(track[2]),
 *                                     asfp(h[0]), asfp(h[1]), asfp(h[2]),d)             # <<<<<<<<<<<<<<
 *             if d[1]<d[0]:
 *                 d[0]=d[1];flip[k]=1
 */
      __pyx_t_15 = __Pyx_GetItemInt(((PyObject *)__pyx_v_h), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_15 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1864; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_15);
      if (!(likely(((__pyx_t_15) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_15, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1864; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_h), 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1864; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_2);
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1864; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_18 = __Pyx_GetItemInt(((PyObject *)__pyx_v_h), 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_18 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1864; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_18);
      if (!(likely(((__pyx_t_18) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_18, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1864; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "dipy/tracking/distances.pyx":1863
 *         for k in range(lenC):
 *             h=np.ascontiguousarray(C[k]['rep3']/C[k]['N'],dtype=f32_dt)
 *             track_direct_flip_3dist(asfp(track[0]),asfp(track[1]),asfp(track[2]),             # <<<<<<<<<<<<<<
 *                                     asfp(h[0]), asfp(h[1]), asfp(h[2]),d)
 *             if d[1]<d[0]:
 */
      __pyx_f_4dipy_8tracking_9distances_track_direct_flip_3dist(__pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_6)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_7)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_4)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_15)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_2)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_18)), __pyx_v_d);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;

      /* "dipy/tracking/distances.pyx":1865
 *             track_direct_flip_3dist(asfp(track[0]),asfp(track[1]),asfp(track[2]),
 *                                     asfp(h[0]), asfp(h[1]), asfp(h[2]),d)
 *             if d[1]<d[0]:             # <<<<<<<<<<<<<<
 *                 d[0]=d[1];flip[k]=1
 *             alld[k]=d[0]
 */
      __pyx_t_3 = (((__pyx_v_d[1]) < (__pyx_v_d[0])) != 0);
      if (__pyx_t_3) {

        /* "dipy/tracking/distances.pyx":1866
 *                                     asfp(h[0]), asfp(h[1]), asfp(h[2]),d)
 *             if d[1]<d[0]:
 *                 d[0]=d[1];flip[k]=1             # <<<<<<<<<<<<<<
 *             alld[k]=d[0]
 *         m_k=np.min(alld)
 */
        (__pyx_v_d[0]) = (__pyx_v_d[1]);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_flip, __pyx_v_k, __pyx_int_1, int, 1, __Pyx_PyInt_From_int, 0, 1, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1866; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

        /* "dipy/tracking/distances.pyx":1865
 *             track_direct_flip_3dist(asfp(track[0]),asfp(track[1]),asfp(track[2]),
 *                                     asfp(h[0]), asfp(h[1]), asfp(h[2]),d)
 *             if d[1]<d[0]:             # <<<<<<<<<<<<<<
 *                 d[0]=d[1];flip[k]=1
 *             alld[k]=d[0]
 */
      }

      /* "dipy/tracking/distances.pyx":1867
 *             if d[1]<d[0]:
 *                 d[0]=d[1];flip[k]=1
 *             alld[k]=d[0]             # <<<<<<<<<<<<<<
 *         m_k=np.min(alld)
 *         i_k=np.argmin(alld)
 */
      __pyx_t_18 = PyFloat_FromDouble((__pyx_v_d[0])); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_18);
      if (unlikely(__Pyx_SetItemInt(__pyx_v_alld, __pyx_v_k, __pyx_t_18, int, 1, __Pyx_PyInt_From_int, 0, 1, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1867; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
    }

    /* "dipy/tracking/distances.pyx":1868
 *                 d[0]=d[1];flip[k]=1
 *             alld[k]=d[0]
 *         m_k=np.min(alld)             # <<<<<<<<<<<<<<
 *         i_k=np.argmin(alld)
 *         if m_k<thr:
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_min); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_15))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_15);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_15, function);
      }
    }
    if (!__pyx_t_2) {
      __pyx_t_18 = __Pyx_PyObject_CallOneArg(__pyx_t_15, __pyx_v_alld); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_18);
    } else {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL;
      __Pyx_INCREF(__pyx_v_alld);
      __Pyx_GIVEREF(__pyx_v_alld);
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_alld);
      __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_4, NULL); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1868; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_18);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_XDECREF_SET(__pyx_v_m_k, __pyx_t_18);
    __pyx_t_18 = 0;

    /* "dipy/tracking/distances.pyx":1869
 *             alld[k]=d[0]
 *         m_k=np.min(alld)
 *         i_k=np.argmin(alld)             # <<<<<<<<<<<<<<
 *         if m_k<thr:
 *             if flip[i_k]==1:
 */
    __pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1869; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_argmin); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1869; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __pyx_t_15 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_15)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_15);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_15) {
      __pyx_t_18 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_alld); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1869; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_18);
    } else {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1869; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_15); __pyx_t_15 = NULL;
      __Pyx_INCREF(__pyx_v_alld);
      __Pyx_GIVEREF(__pyx_v_alld);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_alld);
      __pyx_t_18 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1869; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_18);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF_SET(__pyx_v_i_k, __pyx_t_18);
    __pyx_t_18 = 0;

    /* "dipy/tracking/distances.pyx":1870
 *         m_k=np.min(alld)
 *         i_k=np.argmin(alld)
 *         if m_k<thr:             # <<<<<<<<<<<<<<
 *             if flip[i_k]==1:
 *                 ts[0]=track[-1];ts[1]=track[1];ts[-1]=track[0]
 */
    __pyx_t_18 = PyObject_RichCompare(__pyx_v_m_k, __pyx_v_thr, Py_LT); __Pyx_XGOTREF(__pyx_t_18); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_18); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1870; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
    if (__pyx_t_3) {

      /* "dipy/tracking/distances.pyx":1871
 *         i_k=np.argmin(alld)
 *         if m_k<thr:
 *             if flip[i_k]==1:             # <<<<<<<<<<<<<<
 *                 ts[0]=track[-1];ts[1]=track[1];ts[-1]=track[0]
 *                 C[i_k]['rep3']+=ts
 */
      __pyx_t_18 = PyObject_GetItem(__pyx_v_flip, __pyx_v_i_k); if (unlikely(__pyx_t_18 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1871; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_18);
      __pyx_t_4 = __Pyx_PyInt_EqObjC(__pyx_t_18, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_3 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1871; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_3) {

        /* "dipy/tracking/distances.pyx":1872
 *         if m_k<thr:
 *             if flip[i_k]==1:
 *                 ts[0]=track[-1];ts[1]=track[1];ts[-1]=track[0]             # <<<<<<<<<<<<<<
 *                 C[i_k]['rep3']+=ts
 *             else:
 */
        __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_4);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_ts, 0, __pyx_t_4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_4);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_ts, 1, __pyx_t_4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_track), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_4);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_ts, -1L, __pyx_t_4, long, 1, __Pyx_PyInt_From_long, 0, 1, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1872; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

        /* "dipy/tracking/distances.pyx":1873
 *             if flip[i_k]==1:
 *                 ts[0]=track[-1];ts[1]=track[1];ts[-1]=track[0]
 *                 C[i_k]['rep3']+=ts             # <<<<<<<<<<<<<<
 *             else:
 *                 C[i_k]['rep3']+=track
 */
        __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_v_i_k); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1873; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_INCREF(__pyx_n_s_rep3);
        __pyx_t_19 = __pyx_n_s_rep3;
        __pyx_t_18 = PyObject_GetItem(__pyx_t_4, __pyx_t_19); if (unlikely(__pyx_t_18 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1873; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_18);
        __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_t_18, __pyx_v_ts); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1873; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
        if (unlikely(PyObject_SetItem(__pyx_t_4, __pyx_t_19, __pyx_t_2) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1873; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

        /* "dipy/tracking/distances.pyx":1871
 *         i_k=np.argmin(alld)
 *         if m_k<thr:
 *             if flip[i_k]==1:             # <<<<<<<<<<<<<<
 *                 ts[0]=track[-1];ts[1]=track[1];ts[-1]=track[0]
 *                 C[i_k]['rep3']+=ts
 */
        goto __pyx_L10;
      }

      /* "dipy/tracking/distances.pyx":1875
 *                 C[i_k]['rep3']+=ts
 *             else:
 *                 C[i_k]['rep3']+=track             # <<<<<<<<<<<<<<
 *             C[i_k]['N']+=1
 *             C[i_k]['indices'].append(it)
 */
      /*else*/ {
        __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_v_i_k); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_INCREF(__pyx_n_s_rep3);
        __pyx_t_19 = __pyx_n_s_rep3;
        __pyx_t_2 = PyObject_GetItem(__pyx_t_4, __pyx_t_19); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_18 = PyNumber_InPlaceAdd(__pyx_t_2, ((PyObject *)__pyx_v_track)); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_18);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        if (unlikely(PyObject_SetItem(__pyx_t_4, __pyx_t_19, __pyx_t_18) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1875; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
      __pyx_L10:;

      /* "dipy/tracking/distances.pyx":1876
 *             else:
 *                 C[i_k]['rep3']+=track
 *             C[i_k]['N']+=1             # <<<<<<<<<<<<<<
 *             C[i_k]['indices'].append(it)
 * 
 */
      __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_v_i_k); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1876; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_n_s_N);
      __pyx_t_19 = __pyx_n_s_N;
      __pyx_t_18 = PyObject_GetItem(__pyx_t_4, __pyx_t_19); if (unlikely(__pyx_t_18 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1876; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_18);
      __pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_18, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      if (unlikely(PyObject_SetItem(__pyx_t_4, __pyx_t_19, __pyx_t_2) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1876; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "dipy/tracking/distances.pyx":1877
 *                 C[i_k]['rep3']+=track
 *             C[i_k]['N']+=1
 *             C[i_k]['indices'].append(it)             # <<<<<<<<<<<<<<
 * 
 *         else:
 */
      __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_v_i_k); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1877; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = PyObject_GetItem(__pyx_t_4, __pyx_n_s_indices); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1877; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_it); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_20 = __Pyx_PyObject_Append(__pyx_t_2, __pyx_t_4); if (unlikely(__pyx_t_20 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1877; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "dipy/tracking/distances.pyx":1870
 *         m_k=np.min(alld)
 *         i_k=np.argmin(alld)
 *         if m_k<thr:             # <<<<<<<<<<<<<<
 *             if flip[i_k]==1:
 *                 ts[0]=track[-1];ts[1]=track[1];ts[-1]=track[0]
 */
      goto __pyx_L9;
    }

    /* "dipy/tracking/distances.pyx":1880
 * 
 *         else:
 *             C[lenC]={}             # <<<<<<<<<<<<<<
 *             C[lenC]['rep3']=track.copy()
 *             C[lenC]['N']=1
 */
    /*else*/ {
      __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_lenC); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      if (unlikely(PyDict_SetItem(__pyx_v_C, __pyx_t_2, __pyx_t_4) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1880; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "dipy/tracking/distances.pyx":1881
 *         else:
 *             C[lenC]={}
 *             C[lenC]['rep3']=track.copy()             # <<<<<<<<<<<<<<
 *             C[lenC]['N']=1
 *             C[lenC]['indices']=[it]
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_track), __pyx_n_s_copy); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_18 = NULL;
      if (CYTHON_COMPILING_IN_CPYTHON && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_18 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_18)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_18);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      if (__pyx_t_18) {
        __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_18); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      } else {
        __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_lenC); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_18 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_t_2); if (unlikely(__pyx_t_18 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1881; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_18);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (unlikely(PyObject_SetItem(__pyx_t_18, __pyx_n_s_rep3, __pyx_t_4) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1881; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "dipy/tracking/distances.pyx":1882
 *             C[lenC]={}
 *             C[lenC]['rep3']=track.copy()
 *             C[lenC]['N']=1             # <<<<<<<<<<<<<<
 *             C[lenC]['indices']=[it]
 * 
 */
      __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_lenC); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_18 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_t_4); if (unlikely(__pyx_t_18 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1882; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_18);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (unlikely(PyObject_SetItem(__pyx_t_18, __pyx_n_s_N, __pyx_int_1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1882; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;

      /* "dipy/tracking/distances.pyx":1883
 *             C[lenC]['rep3']=track.copy()
 *             C[lenC]['N']=1
 *             C[lenC]['indices']=[it]             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_t_18 = __Pyx_PyInt_From_int(__pyx_v_it); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_18);
      __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_18);
      PyList_SET_ITEM(__pyx_t_4, 0, __pyx_t_18);
      __pyx_t_18 = 0;
      __pyx_t_18 = PyInt_FromSsize_t(__pyx_v_lenC); if (unlikely(!__pyx_t_18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_18);
      __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_C, __pyx_t_18); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1883; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      if (unlikely(PyObject_SetItem(__pyx_t_2, __pyx_n_s_indices, __pyx_t_4) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1883; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __pyx_L9:;

    /* "dipy/tracking/distances.pyx":1855
 * 
 *     ts=np.zeros((3,3),dtype=np.float32)
 *     for it in itrange:             # <<<<<<<<<<<<<<
 *         track=np.ascontiguousarray(tracks[it],dtype=f32_dt)
 *         lenC=len(C.keys())
 */
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "dipy/tracking/distances.pyx":1886
 * 
 * 
 *     return C             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_C);
  __pyx_r = __pyx_v_C;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":1786
 * 
 * 
 * def larch_3split(tracks, indices=None, thr=10.):             # <<<<<<<<<<<<<<
 *     '''Generate a first pass clustering using 3 points on the tracks only.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_XDECREF(__pyx_t_19);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_h.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.larch_3split", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_h.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_track);
  __Pyx_XDECREF((PyObject *)__pyx_v_h);
  __Pyx_XDECREF(__pyx_v_C);
  __Pyx_XDECREF(__pyx_v_itrange);
  __Pyx_XDECREF(__pyx_v_ts);
  __Pyx_XDECREF(__pyx_v_alld);
  __Pyx_XDECREF(__pyx_v_flip);
  __Pyx_XDECREF(__pyx_v_m_k);
  __Pyx_XDECREF(__pyx_v_i_k);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":1889
 * 
 * 
 * def larch_3merge(C,thr=10.):             # <<<<<<<<<<<<<<
 *     '''
 *     Reassign tracks to existing clusters by merging clusters that their
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_47larch_3merge(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_46larch_3merge[] = "\n    Reassign tracks to existing clusters by merging clusters that their\n    representative tracks are not very distant i.e. less than sqd_thr. Using\n    tracks consisting of 3 points (first, mid and last). This is necessary\n    after running larch_fast_split after multiple split in different levels\n    (squared thresholds) as some of them have created independent clusters.\n\n    Parameters\n    ----------\n    C : graph with clusters\n        of indices 3tracks (tracks consisting of 3 points only)\n    sqd_trh: float\n        squared euclidean distance threshold\n\n    Returns\n    -------\n    C : dict\n       a tree graph containing the clusters\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_47larch_3merge = {"larch_3merge", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_47larch_3merge, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_46larch_3merge};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_47larch_3merge(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_C = 0;
  PyObject *__pyx_v_thr = 0;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("larch_3merge (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_C,&__pyx_n_s_thr,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)__pyx_float_10_);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_C)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_thr);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "larch_3merge") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1889; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_C = values[0];
    __pyx_v_thr = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("larch_3merge", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1889; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.larch_3merge", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_46larch_3merge(__pyx_self, __pyx_v_C, __pyx_v_thr);

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

static PyObject *__pyx_pf_4dipy_8tracking_9distances_46larch_3merge(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_C, PyObject *__pyx_v_thr) {
  PyArrayObject *__pyx_v_h = 0;
  PyArrayObject *__pyx_v_ch = 0;
  int __pyx_v_lenC;
  int __pyx_v_k;
  int __pyx_v_c;
  float __pyx_v_d[2];
  PyObject *__pyx_v_ts = NULL;
  PyObject *__pyx_v_C2 = NULL;
  PyObject *__pyx_v_krange = NULL;
  Py_ssize_t __pyx_v_klen;
  PyObject *__pyx_v_alld = NULL;
  PyObject *__pyx_v_flip = NULL;
  PyObject *__pyx_v_m_k = NULL;
  PyObject *__pyx_v_i_k = NULL;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_ch;
  __Pyx_Buffer __pyx_pybuffer_ch;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_h;
  __Pyx_Buffer __pyx_pybuffer_h;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyArrayObject *__pyx_t_5 = NULL;
  PyArrayObject *__pyx_t_6 = NULL;
  Py_ssize_t __pyx_t_7;
  long __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  int __pyx_t_15;
  int __pyx_t_16;
  PyObject *__pyx_t_17 = NULL;
  int __pyx_t_18;
  long __pyx_t_19;
  PyObject *__pyx_t_20 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("larch_3merge", 0);
  __pyx_pybuffer_h.pybuffer.buf = NULL;
  __pyx_pybuffer_h.refcount = 0;
  __pyx_pybuffernd_h.data = NULL;
  __pyx_pybuffernd_h.rcbuffer = &__pyx_pybuffer_h;
  __pyx_pybuffer_ch.pybuffer.buf = NULL;
  __pyx_pybuffer_ch.refcount = 0;
  __pyx_pybuffernd_ch.data = NULL;
  __pyx_pybuffernd_ch.rcbuffer = &__pyx_pybuffer_ch;

  /* "dipy/tracking/distances.pyx":1910
 *     '''
 * 
 *     cdef cnp.ndarray[cnp.float32_t, ndim=2] h=np.zeros((3,3),dtype=np.float32)             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=2] ch=np.zeros((3,3),dtype=np.float32)
 *     cdef int lenC,k,c
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1910; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1910; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1910; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1910; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1910; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_4) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1910; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__18, __pyx_t_1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1910; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __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_filename = __pyx_f[0]; __pyx_lineno = 1910; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_5 = ((PyArrayObject *)__pyx_t_4);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_h.rcbuffer->pybuffer, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_h = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_h.rcbuffer->pybuffer.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1910; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_pybuffernd_h.diminfo[0].strides = __pyx_pybuffernd_h.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_h.diminfo[0].shape = __pyx_pybuffernd_h.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_h.diminfo[1].strides = __pyx_pybuffernd_h.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_h.diminfo[1].shape = __pyx_pybuffernd_h.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_5 = 0;
  __pyx_v_h = ((PyArrayObject *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "dipy/tracking/distances.pyx":1911
 * 
 *     cdef cnp.ndarray[cnp.float32_t, ndim=2] h=np.zeros((3,3),dtype=np.float32)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=2] ch=np.zeros((3,3),dtype=np.float32)             # <<<<<<<<<<<<<<
 *     cdef int lenC,k,c
 *     cdef float d[2]
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_zeros); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__20, __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __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_filename = __pyx_f[0]; __pyx_lineno = 1911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_t_6 = ((PyArrayObject *)__pyx_t_3);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ch.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
      __pyx_v_ch = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_pybuffernd_ch.rcbuffer->pybuffer.buf = NULL;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    } else {__pyx_pybuffernd_ch.diminfo[0].strides = __pyx_pybuffernd_ch.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ch.diminfo[0].shape = __pyx_pybuffernd_ch.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_ch.diminfo[1].strides = __pyx_pybuffernd_ch.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_ch.diminfo[1].shape = __pyx_pybuffernd_ch.rcbuffer->pybuffer.shape[1];
    }
  }
  __pyx_t_6 = 0;
  __pyx_v_ch = ((PyArrayObject *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":1915
 *     cdef float d[2]
 * 
 *     ts=np.zeros((3,3),dtype=np.float32)             # <<<<<<<<<<<<<<
 * 
 *     lenC=len(C)
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1915; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[0]; __pyx_lineno = 1915; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1915; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1915; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_float32); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1915; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1915; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__22, __pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1915; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_ts = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "dipy/tracking/distances.pyx":1917
 *     ts=np.zeros((3,3),dtype=np.float32)
 * 
 *     lenC=len(C)             # <<<<<<<<<<<<<<
 *     C2=C.copy()
 * 
 */
  __pyx_t_7 = PyObject_Length(__pyx_v_C); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1917; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_lenC = __pyx_t_7;

  /* "dipy/tracking/distances.pyx":1918
 * 
 *     lenC=len(C)
 *     C2=C.copy()             # <<<<<<<<<<<<<<
 * 
 *     for c in range(0,lenC-1):
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_C, __pyx_n_s_copy); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1918; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && likely(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);
    }
  }
  if (__pyx_t_4) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1918; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1918; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_C2 = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "dipy/tracking/distances.pyx":1920
 *     C2=C.copy()
 * 
 *     for c in range(0,lenC-1):             # <<<<<<<<<<<<<<
 *         ch=np.ascontiguousarray(C[c]['rep3']/C[c]['N'],dtype=f32_dt)
 *         krange=range(c+1,lenC)
 */
  __pyx_t_8 = (__pyx_v_lenC - 1);
  for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) {
    __pyx_v_c = __pyx_t_9;

    /* "dipy/tracking/distances.pyx":1921
 * 
 *     for c in range(0,lenC-1):
 *         ch=np.ascontiguousarray(C[c]['rep3']/C[c]['N'],dtype=f32_dt)             # <<<<<<<<<<<<<<
 *         krange=range(c+1,lenC)
 *         klen=len(krange)
 */
    __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_C, __pyx_v_c, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = PyObject_GetItem(__pyx_t_2, __pyx_n_s_rep3); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_C, __pyx_v_c, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyObject_GetItem(__pyx_t_2, __pyx_n_s_N); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __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_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_6 = ((PyArrayObject *)__pyx_t_4);
    {
      __Pyx_BufFmt_StackElem __pyx_stack[1];
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ch.rcbuffer->pybuffer);
      __pyx_t_10 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ch.rcbuffer->pybuffer, (PyObject*)__pyx_t_6, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
      if (unlikely(__pyx_t_10 < 0)) {
        PyErr_Fetch(&__pyx_t_11, &__pyx_t_12, &__pyx_t_13);
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_ch.rcbuffer->pybuffer, (PyObject*)__pyx_v_ch, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
          Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_13);
          __Pyx_RaiseBufferFallbackError();
        } else {
          PyErr_Restore(__pyx_t_11, __pyx_t_12, __pyx_t_13);
        }
      }
      __pyx_pybuffernd_ch.diminfo[0].strides = __pyx_pybuffernd_ch.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_ch.diminfo[0].shape = __pyx_pybuffernd_ch.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_ch.diminfo[1].strides = __pyx_pybuffernd_ch.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_ch.diminfo[1].shape = __pyx_pybuffernd_ch.rcbuffer->pybuffer.shape[1];
      if (unlikely(__pyx_t_10 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1921; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_6 = 0;
    __Pyx_DECREF_SET(__pyx_v_ch, ((PyArrayObject *)__pyx_t_4));
    __pyx_t_4 = 0;

    /* "dipy/tracking/distances.pyx":1922
 *     for c in range(0,lenC-1):
 *         ch=np.ascontiguousarray(C[c]['rep3']/C[c]['N'],dtype=f32_dt)
 *         krange=range(c+1,lenC)             # <<<<<<<<<<<<<<
 *         klen=len(krange)
 *         alld=np.zeros(klen)
 */
    __pyx_t_4 = __Pyx_PyInt_From_long((__pyx_v_c + 1)); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_lenC); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
    __pyx_t_4 = 0;
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1922; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF_SET(__pyx_v_krange, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "dipy/tracking/distances.pyx":1923
 *         ch=np.ascontiguousarray(C[c]['rep3']/C[c]['N'],dtype=f32_dt)
 *         krange=range(c+1,lenC)
 *         klen=len(krange)             # <<<<<<<<<<<<<<
 *         alld=np.zeros(klen)
 *         flip=np.zeros(klen)
 */
    __pyx_t_7 = PyObject_Length(__pyx_v_krange); if (unlikely(__pyx_t_7 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1923; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_klen = __pyx_t_7;

    /* "dipy/tracking/distances.pyx":1924
 *         krange=range(c+1,lenC)
 *         klen=len(krange)
 *         alld=np.zeros(klen)             # <<<<<<<<<<<<<<
 *         flip=np.zeros(klen)
 *         for k in range(c+1,lenC):
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_klen); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && 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);
      }
    }
    if (!__pyx_t_3) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else {
      __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_14, 0+1, __pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_14, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1924; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF_SET(__pyx_v_alld, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "dipy/tracking/distances.pyx":1925
 *         klen=len(krange)
 *         alld=np.zeros(klen)
 *         flip=np.zeros(klen)             # <<<<<<<<<<<<<<
 *         for k in range(c+1,lenC):
 *             h=np.ascontiguousarray(C[k]['rep3']/C[k]['N'],dtype=f32_dt)
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_zeros); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_14);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyInt_FromSsize_t(__pyx_v_klen); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_14))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_14);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_14, function);
      }
    }
    if (!__pyx_t_1) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else {
      __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __pyx_t_1 = NULL;
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1925; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __Pyx_XDECREF_SET(__pyx_v_flip, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "dipy/tracking/distances.pyx":1926
 *         alld=np.zeros(klen)
 *         flip=np.zeros(klen)
 *         for k in range(c+1,lenC):             # <<<<<<<<<<<<<<
 *             h=np.ascontiguousarray(C[k]['rep3']/C[k]['N'],dtype=f32_dt)
 *             track_direct_flip_3dist(
 */
    __pyx_t_10 = __pyx_v_lenC;
    for (__pyx_t_15 = (__pyx_v_c + 1); __pyx_t_15 < __pyx_t_10; __pyx_t_15+=1) {
      __pyx_v_k = __pyx_t_15;

      /* "dipy/tracking/distances.pyx":1927
 *         flip=np.zeros(klen)
 *         for k in range(c+1,lenC):
 *             h=np.ascontiguousarray(C[k]['rep3']/C[k]['N'],dtype=f32_dt)             # <<<<<<<<<<<<<<
 *             track_direct_flip_3dist(
 *                 asfp(ch[0]),asfp(ch[1]),asfp(ch[2]),
 */
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_ascontiguousarray); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_C, __pyx_v_k, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1927; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = PyObject_GetItem(__pyx_t_2, __pyx_n_s_rep3); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1927; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_C, __pyx_v_k, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1927; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = PyObject_GetItem(__pyx_t_2, __pyx_n_s_N); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1927; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_2);
      if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, ((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt)) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_5 = ((PyArrayObject *)__pyx_t_3);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_h.rcbuffer->pybuffer);
        __pyx_t_16 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_h.rcbuffer->pybuffer, (PyObject*)__pyx_t_5, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack);
        if (unlikely(__pyx_t_16 < 0)) {
          PyErr_Fetch(&__pyx_t_13, &__pyx_t_12, &__pyx_t_11);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_h.rcbuffer->pybuffer, (PyObject*)__pyx_v_h, &__Pyx_TypeInfo_nn___pyx_t_5numpy_float32_t, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_13); Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_11);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_13, __pyx_t_12, __pyx_t_11);
          }
        }
        __pyx_pybuffernd_h.diminfo[0].strides = __pyx_pybuffernd_h.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_h.diminfo[0].shape = __pyx_pybuffernd_h.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_h.diminfo[1].strides = __pyx_pybuffernd_h.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_h.diminfo[1].shape = __pyx_pybuffernd_h.rcbuffer->pybuffer.shape[1];
        if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1927; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_t_5 = 0;
      __Pyx_DECREF_SET(__pyx_v_h, ((PyArrayObject *)__pyx_t_3));
      __pyx_t_3 = 0;

      /* "dipy/tracking/distances.pyx":1929
 *             h=np.ascontiguousarray(C[k]['rep3']/C[k]['N'],dtype=f32_dt)
 *             track_direct_flip_3dist(
 *                 asfp(ch[0]),asfp(ch[1]),asfp(ch[2]),             # <<<<<<<<<<<<<<
 *                 asfp(h[0]), asfp(h[1]), asfp(h[2]),d)
 * 
 */
      __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_v_ch), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1929; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_3);
      if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1929; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_ch), 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_2 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1929; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_2);
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1929; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_ch), 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1929; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_4);
      if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1929; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "dipy/tracking/distances.pyx":1930
 *             track_direct_flip_3dist(
 *                 asfp(ch[0]),asfp(ch[1]),asfp(ch[2]),
 *                 asfp(h[0]), asfp(h[1]), asfp(h[2]),d)             # <<<<<<<<<<<<<<
 * 
 *             if d[1]<d[0]:
 */
      __pyx_t_14 = __Pyx_GetItemInt(((PyObject *)__pyx_v_h), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_14 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1930; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_14);
      if (!(likely(((__pyx_t_14) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_14, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1930; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_1 = __Pyx_GetItemInt(((PyObject *)__pyx_v_h), 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1930; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_1);
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1930; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_t_17 = __Pyx_GetItemInt(((PyObject *)__pyx_v_h), 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_17 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1930; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_17);
      if (!(likely(((__pyx_t_17) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_17, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1930; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "dipy/tracking/distances.pyx":1928
 *         for k in range(c+1,lenC):
 *             h=np.ascontiguousarray(C[k]['rep3']/C[k]['N'],dtype=f32_dt)
 *             track_direct_flip_3dist(             # <<<<<<<<<<<<<<
 *                 asfp(ch[0]),asfp(ch[1]),asfp(ch[2]),
 *                 asfp(h[0]), asfp(h[1]), asfp(h[2]),d)
 */
      __pyx_f_4dipy_8tracking_9distances_track_direct_flip_3dist(__pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_3)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_2)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_4)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_14)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_1)), __pyx_f_4dipy_8tracking_9distances_asfp(((PyArrayObject *)__pyx_t_17)), __pyx_v_d);
      __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;
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;

      /* "dipy/tracking/distances.pyx":1932
 *                 asfp(h[0]), asfp(h[1]), asfp(h[2]),d)
 * 
 *             if d[1]<d[0]:             # <<<<<<<<<<<<<<
 *                 d[0]=d[1]
 *                 flip[k-c-1]=1
 */
      __pyx_t_18 = (((__pyx_v_d[1]) < (__pyx_v_d[0])) != 0);
      if (__pyx_t_18) {

        /* "dipy/tracking/distances.pyx":1933
 * 
 *             if d[1]<d[0]:
 *                 d[0]=d[1]             # <<<<<<<<<<<<<<
 *                 flip[k-c-1]=1
 *             alld[k-c-1]=d[0]
 */
        (__pyx_v_d[0]) = (__pyx_v_d[1]);

        /* "dipy/tracking/distances.pyx":1934
 *             if d[1]<d[0]:
 *                 d[0]=d[1]
 *                 flip[k-c-1]=1             # <<<<<<<<<<<<<<
 *             alld[k-c-1]=d[0]
 * 
 */
        __pyx_t_19 = ((__pyx_v_k - __pyx_v_c) - 1);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_flip, __pyx_t_19, __pyx_int_1, long, 1, __Pyx_PyInt_From_long, 0, 1, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1934; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

        /* "dipy/tracking/distances.pyx":1932
 *                 asfp(h[0]), asfp(h[1]), asfp(h[2]),d)
 * 
 *             if d[1]<d[0]:             # <<<<<<<<<<<<<<
 *                 d[0]=d[1]
 *                 flip[k-c-1]=1
 */
      }

      /* "dipy/tracking/distances.pyx":1935
 *                 d[0]=d[1]
 *                 flip[k-c-1]=1
 *             alld[k-c-1]=d[0]             # <<<<<<<<<<<<<<
 * 
 *         m_k=np.min(alld)
 */
      __pyx_t_17 = PyFloat_FromDouble((__pyx_v_d[0])); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1935; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_17);
      __pyx_t_19 = ((__pyx_v_k - __pyx_v_c) - 1);
      if (unlikely(__Pyx_SetItemInt(__pyx_v_alld, __pyx_t_19, __pyx_t_17, long, 1, __Pyx_PyInt_From_long, 0, 1, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1935; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
    }

    /* "dipy/tracking/distances.pyx":1937
 *             alld[k-c-1]=d[0]
 * 
 *         m_k=np.min(alld)             # <<<<<<<<<<<<<<
 *         i_k=np.argmin(alld)
 *         if m_k<thr:
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_min); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_14);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_14))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_14);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_14, function);
      }
    }
    if (!__pyx_t_1) {
      __pyx_t_17 = __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_v_alld); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_17);
    } else {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __pyx_t_1 = NULL;
      __Pyx_INCREF(__pyx_v_alld);
      __Pyx_GIVEREF(__pyx_v_alld);
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_alld);
      __pyx_t_17 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_4, NULL); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1937; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_17);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __Pyx_XDECREF_SET(__pyx_v_m_k, __pyx_t_17);
    __pyx_t_17 = 0;

    /* "dipy/tracking/distances.pyx":1938
 * 
 *         m_k=np.min(alld)
 *         i_k=np.argmin(alld)             # <<<<<<<<<<<<<<
 *         if m_k<thr:
 *             if flip[i_k]==1:
 */
    __pyx_t_14 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_14);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_argmin); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __pyx_t_14 = NULL;
    if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_14)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_14);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_14) {
      __pyx_t_17 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_alld); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_17);
    } else {
      __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_14); __pyx_t_14 = NULL;
      __Pyx_INCREF(__pyx_v_alld);
      __Pyx_GIVEREF(__pyx_v_alld);
      PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_v_alld);
      __pyx_t_17 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, NULL); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1938; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_17);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF_SET(__pyx_v_i_k, __pyx_t_17);
    __pyx_t_17 = 0;

    /* "dipy/tracking/distances.pyx":1939
 *         m_k=np.min(alld)
 *         i_k=np.argmin(alld)
 *         if m_k<thr:             # <<<<<<<<<<<<<<
 *             if flip[i_k]==1:
 *                 ts[0]=ch[-1];ts[1]=ch[1];ts[-1]=ch[0]
 */
    __pyx_t_17 = PyObject_RichCompare(__pyx_v_m_k, __pyx_v_thr, Py_LT); __Pyx_XGOTREF(__pyx_t_17); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_17); if (unlikely(__pyx_t_18 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1939; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
    if (__pyx_t_18) {

      /* "dipy/tracking/distances.pyx":1940
 *         i_k=np.argmin(alld)
 *         if m_k<thr:
 *             if flip[i_k]==1:             # <<<<<<<<<<<<<<
 *                 ts[0]=ch[-1];ts[1]=ch[1];ts[-1]=ch[0]
 *                 C2[i_k+c]['rep3']+=ts
 */
      __pyx_t_17 = PyObject_GetItem(__pyx_v_flip, __pyx_v_i_k); if (unlikely(__pyx_t_17 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1940; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_17);
      __pyx_t_4 = __Pyx_PyInt_EqObjC(__pyx_t_17, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1940; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_18 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1940; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_18) {

        /* "dipy/tracking/distances.pyx":1941
 *         if m_k<thr:
 *             if flip[i_k]==1:
 *                 ts[0]=ch[-1];ts[1]=ch[1];ts[-1]=ch[0]             # <<<<<<<<<<<<<<
 *                 C2[i_k+c]['rep3']+=ts
 *             else:
 */
        __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_ch), -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_4);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_ts, 0, __pyx_t_4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_ch), 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_4);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_ts, 1, __pyx_t_4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_ch), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_4);
        if (unlikely(__Pyx_SetItemInt(__pyx_v_ts, -1L, __pyx_t_4, long, 1, __Pyx_PyInt_From_long, 0, 1, 1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

        /* "dipy/tracking/distances.pyx":1942
 *             if flip[i_k]==1:
 *                 ts[0]=ch[-1];ts[1]=ch[1];ts[-1]=ch[0]
 *                 C2[i_k+c]['rep3']+=ts             # <<<<<<<<<<<<<<
 *             else:
 *                 C2[i_k+c]['rep3']+=ch
 */
        __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_c); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_17 = PyNumber_Add(__pyx_v_i_k, __pyx_t_4); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_17);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = PyObject_GetItem(__pyx_v_C2, __pyx_t_17); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1942; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
        __Pyx_INCREF(__pyx_n_s_rep3);
        __pyx_t_20 = __pyx_n_s_rep3;
        __pyx_t_17 = PyObject_GetItem(__pyx_t_4, __pyx_t_20); if (unlikely(__pyx_t_17 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1942; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_17);
        __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_t_17, __pyx_v_ts); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
        if (unlikely(PyObject_SetItem(__pyx_t_4, __pyx_t_20, __pyx_t_1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1942; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

        /* "dipy/tracking/distances.pyx":1940
 *         i_k=np.argmin(alld)
 *         if m_k<thr:
 *             if flip[i_k]==1:             # <<<<<<<<<<<<<<
 *                 ts[0]=ch[-1];ts[1]=ch[1];ts[-1]=ch[0]
 *                 C2[i_k+c]['rep3']+=ts
 */
        goto __pyx_L9;
      }

      /* "dipy/tracking/distances.pyx":1944
 *                 C2[i_k+c]['rep3']+=ts
 *             else:
 *                 C2[i_k+c]['rep3']+=ch             # <<<<<<<<<<<<<<
 *             C2[i_k+c]['N']+=C2[c]['N']
 *             C2[i_k+c]['indices']+=C2[c]['indices']
 */
      /*else*/ {
        __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_c); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_1 = PyNumber_Add(__pyx_v_i_k, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = PyObject_GetItem(__pyx_v_C2, __pyx_t_1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_INCREF(__pyx_n_s_rep3);
        __pyx_t_20 = __pyx_n_s_rep3;
        __pyx_t_1 = PyObject_GetItem(__pyx_t_4, __pyx_t_20); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_17 = PyNumber_InPlaceAdd(__pyx_t_1, ((PyObject *)__pyx_v_ch)); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_17);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (unlikely(PyObject_SetItem(__pyx_t_4, __pyx_t_20, __pyx_t_17) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1944; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
      __pyx_L9:;

      /* "dipy/tracking/distances.pyx":1945
 *             else:
 *                 C2[i_k+c]['rep3']+=ch
 *             C2[i_k+c]['N']+=C2[c]['N']             # <<<<<<<<<<<<<<
 *             C2[i_k+c]['indices']+=C2[c]['indices']
 *             del C2[c]
 */
      __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_c); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_17 = PyNumber_Add(__pyx_v_i_k, __pyx_t_4); if (unlikely(!__pyx_t_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_17);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_GetItem(__pyx_v_C2, __pyx_t_17); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1945; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      __Pyx_INCREF(__pyx_n_s_N);
      __pyx_t_20 = __pyx_n_s_N;
      __pyx_t_17 = PyObject_GetItem(__pyx_t_4, __pyx_t_20); if (unlikely(__pyx_t_17 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1945; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_17);
      __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_C2, __pyx_v_c, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1945; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_14 = PyObject_GetItem(__pyx_t_1, __pyx_n_s_N); if (unlikely(__pyx_t_14 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1945; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_t_17, __pyx_t_14); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      if (unlikely(PyObject_SetItem(__pyx_t_4, __pyx_t_20, __pyx_t_1) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1945; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "dipy/tracking/distances.pyx":1946
 *                 C2[i_k+c]['rep3']+=ch
 *             C2[i_k+c]['N']+=C2[c]['N']
 *             C2[i_k+c]['indices']+=C2[c]['indices']             # <<<<<<<<<<<<<<
 *             del C2[c]
 * 
 */
      __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_c); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_1 = PyNumber_Add(__pyx_v_i_k, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_GetItem(__pyx_v_C2, __pyx_t_1); if (unlikely(__pyx_t_4 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_INCREF(__pyx_n_s_indices);
      __pyx_t_20 = __pyx_n_s_indices;
      __pyx_t_1 = PyObject_GetItem(__pyx_t_4, __pyx_t_20); if (unlikely(__pyx_t_1 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_14 = __Pyx_GetItemInt(__pyx_v_C2, __pyx_v_c, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(__pyx_t_14 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_14);
      __pyx_t_17 = PyObject_GetItem(__pyx_t_14, __pyx_n_s_indices); if (unlikely(__pyx_t_17 == NULL)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
      __Pyx_GOTREF(__pyx_t_17);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_14 = PyNumber_InPlaceAdd(__pyx_t_1, __pyx_t_17); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      if (unlikely(PyObject_SetItem(__pyx_t_4, __pyx_t_20, __pyx_t_14) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1946; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "dipy/tracking/distances.pyx":1947
 *             C2[i_k+c]['N']+=C2[c]['N']
 *             C2[i_k+c]['indices']+=C2[c]['indices']
 *             del C2[c]             # <<<<<<<<<<<<<<
 * 
 *     return C2
 */
      if (__Pyx_DelItemInt(__pyx_v_C2, __pyx_v_c, int, 1, __Pyx_PyInt_From_int, 0, 1, 1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1947; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "dipy/tracking/distances.pyx":1939
 *         m_k=np.min(alld)
 *         i_k=np.argmin(alld)
 *         if m_k<thr:             # <<<<<<<<<<<<<<
 *             if flip[i_k]==1:
 *                 ts[0]=ch[-1];ts[1]=ch[1];ts[-1]=ch[0]
 */
    }
  }

  /* "dipy/tracking/distances.pyx":1949
 *             del C2[c]
 * 
 *     return C2             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_C2);
  __pyx_r = __pyx_v_C2;
  goto __pyx_L0;

  /* "dipy/tracking/distances.pyx":1889
 * 
 * 
 * def larch_3merge(C,thr=10.):             # <<<<<<<<<<<<<<
 *     '''
 *     Reassign tracks to existing clusters by merging clusters that their
 */

  /* 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_14);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_XDECREF(__pyx_t_20);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ch.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_h.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.larch_3merge", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_ch.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_h.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_h);
  __Pyx_XDECREF((PyObject *)__pyx_v_ch);
  __Pyx_XDECREF(__pyx_v_ts);
  __Pyx_XDECREF(__pyx_v_C2);
  __Pyx_XDECREF(__pyx_v_krange);
  __Pyx_XDECREF(__pyx_v_alld);
  __Pyx_XDECREF(__pyx_v_flip);
  __Pyx_XDECREF(__pyx_v_m_k);
  __Pyx_XDECREF(__pyx_v_i_k);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":1953
 * 
 * 
 * def point_track_sq_distance_check(cnp.ndarray[float,ndim=2] track,             # <<<<<<<<<<<<<<
 *                                   cnp.ndarray[float,ndim=1] point,
 *                                   double sq_dist_thr):
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_49point_track_sq_distance_check(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_48point_track_sq_distance_check[] = " Check if square distance of track from point is smaller than threshold\n\n    Parameters\n    ----------\n    track: array,float32, shape (N,3)\n    point: array,float32, shape (3,)\n    sq_dist_thr: double, threshold\n\n    Returns\n    -------\n    bool: True, if sq_distance <= sq_dist_thr, otherwise False.\n\n    Examples\n    --------\n    >>> t=np.random.rand(10,3).astype(np.float32)\n    >>> p=np.array([0.5,0.5,0.5],dtype=np.float32)\n    >>> point_track_sq_distance_check(t,p,2**2)\n    True\n    >>> t=np.array([[0,0,0],[1,1,1],[2,2,2]],dtype='f4')\n    >>> p=np.array([-1,-1.,-1],dtype='f4')\n    >>> point_track_sq_distance_check(t,p,.2**2)\n    False\n    >>> point_track_sq_distance_check(t,p,2**2)\n    True\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_49point_track_sq_distance_check = {"point_track_sq_distance_check", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_49point_track_sq_distance_check, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_48point_track_sq_distance_check};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_49point_track_sq_distance_check(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_track = 0;
  PyArrayObject *__pyx_v_point = 0;
  double __pyx_v_sq_dist_thr;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("point_track_sq_distance_check (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_track,&__pyx_n_s_point,&__pyx_n_s_sq_dist_thr,0};
    PyObject* values[3] = {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  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_track)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_point)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("point_track_sq_distance_check", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1953; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sq_dist_thr)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("point_track_sq_distance_check", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1953; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "point_track_sq_distance_check") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1953; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      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);
    }
    __pyx_v_track = ((PyArrayObject *)values[0]);
    __pyx_v_point = ((PyArrayObject *)values[1]);
    __pyx_v_sq_dist_thr = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_sq_dist_thr == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1955; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("point_track_sq_distance_check", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1953; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.point_track_sq_distance_check", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_track), __pyx_ptype_5numpy_ndarray, 1, "track", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_point), __pyx_ptype_5numpy_ndarray, 1, "point", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1954; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_48point_track_sq_distance_check(__pyx_self, __pyx_v_track, __pyx_v_point, __pyx_v_sq_dist_thr);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_4dipy_8tracking_9distances_48point_track_sq_distance_check(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_track, PyArrayObject *__pyx_v_point, double __pyx_v_sq_dist_thr) {
  float *__pyx_v_t;
  float *__pyx_v_p;
  float __pyx_v_a[3];
  float __pyx_v_b[3];
  int __pyx_v_tlen;
  int __pyx_v_curr;
  float __pyx_v_dist;
  int __pyx_v_i;
  int __pyx_v_intersects;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_point;
  __Pyx_Buffer __pyx_pybuffer_point;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_track;
  __Pyx_Buffer __pyx_pybuffer_track;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  long __pyx_t_2;
  int __pyx_t_3;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("point_track_sq_distance_check", 0);
  __pyx_pybuffer_track.pybuffer.buf = NULL;
  __pyx_pybuffer_track.refcount = 0;
  __pyx_pybuffernd_track.data = NULL;
  __pyx_pybuffernd_track.rcbuffer = &__pyx_pybuffer_track;
  __pyx_pybuffer_point.pybuffer.buf = NULL;
  __pyx_pybuffer_point.refcount = 0;
  __pyx_pybuffernd_point.data = NULL;
  __pyx_pybuffernd_point.rcbuffer = &__pyx_pybuffer_point;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track.rcbuffer->pybuffer, (PyObject*)__pyx_v_track, &__Pyx_TypeInfo_float, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_pybuffernd_track.diminfo[0].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_track.diminfo[0].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_track.diminfo[1].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_track.diminfo[1].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_point.rcbuffer->pybuffer, (PyObject*)__pyx_v_point, &__Pyx_TypeInfo_float, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_pybuffernd_point.diminfo[0].strides = __pyx_pybuffernd_point.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_point.diminfo[0].shape = __pyx_pybuffernd_point.rcbuffer->pybuffer.shape[0];

  /* "dipy/tracking/distances.pyx":1983
 * 
 *     cdef:
 *         float *t=<float *>track.data             # <<<<<<<<<<<<<<
 *         float *p=<float *>point.data
 *         float a[3],b[3]
 */
  __pyx_v_t = ((float *)__pyx_v_track->data);

  /* "dipy/tracking/distances.pyx":1984
 *     cdef:
 *         float *t=<float *>track.data
 *         float *p=<float *>point.data             # <<<<<<<<<<<<<<
 *         float a[3],b[3]
 *         int tlen = len(track)
 */
  __pyx_v_p = ((float *)__pyx_v_point->data);

  /* "dipy/tracking/distances.pyx":1986
 *         float *p=<float *>point.data
 *         float a[3],b[3]
 *         int tlen = len(track)             # <<<<<<<<<<<<<<
 *         int curr = 0
 *         float dist = 0
 */
  __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_v_track)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1986; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_tlen = __pyx_t_1;

  /* "dipy/tracking/distances.pyx":1987
 *         float a[3],b[3]
 *         int tlen = len(track)
 *         int curr = 0             # <<<<<<<<<<<<<<
 *         float dist = 0
 *         int i
 */
  __pyx_v_curr = 0;

  /* "dipy/tracking/distances.pyx":1988
 *         int tlen = len(track)
 *         int curr = 0
 *         float dist = 0             # <<<<<<<<<<<<<<
 *         int i
 *         int intersects = 0
 */
  __pyx_v_dist = 0.0;

  /* "dipy/tracking/distances.pyx":1990
 *         float dist = 0
 *         int i
 *         int intersects = 0             # <<<<<<<<<<<<<<
 * 
 *     with nogil:
 */
  __pyx_v_intersects = 0;

  /* "dipy/tracking/distances.pyx":1992
 *         int intersects = 0
 * 
 *     with nogil:             # <<<<<<<<<<<<<<
 *         for i from 0<=i<tlen-1:
 *             curr=i*3
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      #endif
      /*try:*/ {

        /* "dipy/tracking/distances.pyx":1993
 * 
 *     with nogil:
 *         for i from 0<=i<tlen-1:             # <<<<<<<<<<<<<<
 *             curr=i*3
 *             a[0]=t[curr]
 */
        __pyx_t_2 = (__pyx_v_tlen - 1);
        for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) {

          /* "dipy/tracking/distances.pyx":1994
 *     with nogil:
 *         for i from 0<=i<tlen-1:
 *             curr=i*3             # <<<<<<<<<<<<<<
 *             a[0]=t[curr]
 *             a[1]=t[curr+1]
 */
          __pyx_v_curr = (__pyx_v_i * 3);

          /* "dipy/tracking/distances.pyx":1995
 *         for i from 0<=i<tlen-1:
 *             curr=i*3
 *             a[0]=t[curr]             # <<<<<<<<<<<<<<
 *             a[1]=t[curr+1]
 *             a[2]=t[curr+2]
 */
          (__pyx_v_a[0]) = (__pyx_v_t[__pyx_v_curr]);

          /* "dipy/tracking/distances.pyx":1996
 *             curr=i*3
 *             a[0]=t[curr]
 *             a[1]=t[curr+1]             # <<<<<<<<<<<<<<
 *             a[2]=t[curr+2]
 *             b[0]=t[curr+3]
 */
          (__pyx_v_a[1]) = (__pyx_v_t[(__pyx_v_curr + 1)]);

          /* "dipy/tracking/distances.pyx":1997
 *             a[0]=t[curr]
 *             a[1]=t[curr+1]
 *             a[2]=t[curr+2]             # <<<<<<<<<<<<<<
 *             b[0]=t[curr+3]
 *             b[1]=t[curr+4]
 */
          (__pyx_v_a[2]) = (__pyx_v_t[(__pyx_v_curr + 2)]);

          /* "dipy/tracking/distances.pyx":1998
 *             a[1]=t[curr+1]
 *             a[2]=t[curr+2]
 *             b[0]=t[curr+3]             # <<<<<<<<<<<<<<
 *             b[1]=t[curr+4]
 *             b[2]=t[curr+5]
 */
          (__pyx_v_b[0]) = (__pyx_v_t[(__pyx_v_curr + 3)]);

          /* "dipy/tracking/distances.pyx":1999
 *             a[2]=t[curr+2]
 *             b[0]=t[curr+3]
 *             b[1]=t[curr+4]             # <<<<<<<<<<<<<<
 *             b[2]=t[curr+5]
 *             dist=cpoint_segment_sq_dist(<float *>a,<float *>b,p)
 */
          (__pyx_v_b[1]) = (__pyx_v_t[(__pyx_v_curr + 4)]);

          /* "dipy/tracking/distances.pyx":2000
 *             b[0]=t[curr+3]
 *             b[1]=t[curr+4]
 *             b[2]=t[curr+5]             # <<<<<<<<<<<<<<
 *             dist=cpoint_segment_sq_dist(<float *>a,<float *>b,p)
 *             if dist<=sq_dist_thr:
 */
          (__pyx_v_b[2]) = (__pyx_v_t[(__pyx_v_curr + 5)]);

          /* "dipy/tracking/distances.pyx":2001
 *             b[1]=t[curr+4]
 *             b[2]=t[curr+5]
 *             dist=cpoint_segment_sq_dist(<float *>a,<float *>b,p)             # <<<<<<<<<<<<<<
 *             if dist<=sq_dist_thr:
 *                 intersects=1
 */
          __pyx_v_dist = __pyx_f_4dipy_8tracking_9distances_cpoint_segment_sq_dist(((float *)__pyx_v_a), ((float *)__pyx_v_b), __pyx_v_p);

          /* "dipy/tracking/distances.pyx":2002
 *             b[2]=t[curr+5]
 *             dist=cpoint_segment_sq_dist(<float *>a,<float *>b,p)
 *             if dist<=sq_dist_thr:             # <<<<<<<<<<<<<<
 *                 intersects=1
 *                 break
 */
          __pyx_t_3 = ((__pyx_v_dist <= __pyx_v_sq_dist_thr) != 0);
          if (__pyx_t_3) {

            /* "dipy/tracking/distances.pyx":2003
 *             dist=cpoint_segment_sq_dist(<float *>a,<float *>b,p)
 *             if dist<=sq_dist_thr:
 *                 intersects=1             # <<<<<<<<<<<<<<
 *                 break
 * 
 */
            __pyx_v_intersects = 1;

            /* "dipy/tracking/distances.pyx":2004
 *             if dist<=sq_dist_thr:
 *                 intersects=1
 *                 break             # <<<<<<<<<<<<<<
 * 
 *     if intersects==1:
 */
            goto __pyx_L7_break;

            /* "dipy/tracking/distances.pyx":2002
 *             b[2]=t[curr+5]
 *             dist=cpoint_segment_sq_dist(<float *>a,<float *>b,p)
 *             if dist<=sq_dist_thr:             # <<<<<<<<<<<<<<
 *                 intersects=1
 *                 break
 */
          }
        }
        __pyx_L7_break:;
      }

      /* "dipy/tracking/distances.pyx":1992
 *         int intersects = 0
 * 
 *     with nogil:             # <<<<<<<<<<<<<<
 *         for i from 0<=i<tlen-1:
 *             curr=i*3
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "dipy/tracking/distances.pyx":2006
 *                 break
 * 
 *     if intersects==1:             # <<<<<<<<<<<<<<
 *         return True
 *     else:
 */
  __pyx_t_3 = ((__pyx_v_intersects == 1) != 0);
  if (__pyx_t_3) {

    /* "dipy/tracking/distances.pyx":2007
 * 
 *     if intersects==1:
 *         return True             # <<<<<<<<<<<<<<
 *     else:
 *         return False
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_True);
    __pyx_r = Py_True;
    goto __pyx_L0;

    /* "dipy/tracking/distances.pyx":2006
 *                 break
 * 
 *     if intersects==1:             # <<<<<<<<<<<<<<
 *         return True
 *     else:
 */
  }

  /* "dipy/tracking/distances.pyx":2009
 *         return True
 *     else:
 *         return False             # <<<<<<<<<<<<<<
 * 
 * def track_roi_intersection_check(cnp.ndarray[float,ndim=2] track, cnp.ndarray[float,ndim=2] roi, double sq_dist_thr):
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_False);
    __pyx_r = Py_False;
    goto __pyx_L0;
  }

  /* "dipy/tracking/distances.pyx":1953
 * 
 * 
 * def point_track_sq_distance_check(cnp.ndarray[float,ndim=2] track,             # <<<<<<<<<<<<<<
 *                                   cnp.ndarray[float,ndim=1] point,
 *                                   double sq_dist_thr):
 */

  /* function exit code */
  __pyx_L1_error:;
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_point.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.point_track_sq_distance_check", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_point.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "dipy/tracking/distances.pyx":2011
 *         return False
 * 
 * def track_roi_intersection_check(cnp.ndarray[float,ndim=2] track, cnp.ndarray[float,ndim=2] roi, double sq_dist_thr):             # <<<<<<<<<<<<<<
 *     ''' Check if a track is intersecting a region of interest
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_4dipy_8tracking_9distances_51track_roi_intersection_check(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4dipy_8tracking_9distances_50track_roi_intersection_check[] = " Check if a track is intersecting a region of interest\n\n    Parameters\n    ----------\n    track: array,float32, shape (N,3)\n    roi: array,float32, shape (M,3)\n    sq_dist_thr: double, threshold, check squared euclidean distance from every roi point\n\n    Returns\n    -------\n    bool: True, if sq_distance <= sq_dist_thr, otherwise False.\n\n    Examples\n    --------\n    >>> roi=np.array([[0,0,0],[1,0,0],[2,0,0]],dtype='f4')\n    >>> t=np.array([[0,0,0],[1,1,1],[2,2,2]],dtype='f4')\n    >>> track_roi_intersection_check(t,roi,1)\n    True\n    >>> track_roi_intersection_check(t,np.array([[10,0,0]],dtype='f4'),1)\n    False\n    ";
static PyMethodDef __pyx_mdef_4dipy_8tracking_9distances_51track_roi_intersection_check = {"track_roi_intersection_check", (PyCFunction)__pyx_pw_4dipy_8tracking_9distances_51track_roi_intersection_check, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4dipy_8tracking_9distances_50track_roi_intersection_check};
static PyObject *__pyx_pw_4dipy_8tracking_9distances_51track_roi_intersection_check(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyArrayObject *__pyx_v_track = 0;
  PyArrayObject *__pyx_v_roi = 0;
  double __pyx_v_sq_dist_thr;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("track_roi_intersection_check (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_track,&__pyx_n_s_roi,&__pyx_n_s_sq_dist_thr,0};
    PyObject* values[3] = {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  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_track)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_roi)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("track_roi_intersection_check", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sq_dist_thr)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("track_roi_intersection_check", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "track_roi_intersection_check") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      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);
    }
    __pyx_v_track = ((PyArrayObject *)values[0]);
    __pyx_v_roi = ((PyArrayObject *)values[1]);
    __pyx_v_sq_dist_thr = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_sq_dist_thr == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("track_roi_intersection_check", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L3_error;}
  __pyx_L3_error:;
  __Pyx_AddTraceback("dipy.tracking.distances.track_roi_intersection_check", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_track), __pyx_ptype_5numpy_ndarray, 1, "track", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_roi), __pyx_ptype_5numpy_ndarray, 1, "roi", 0))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_r = __pyx_pf_4dipy_8tracking_9distances_50track_roi_intersection_check(__pyx_self, __pyx_v_track, __pyx_v_roi, __pyx_v_sq_dist_thr);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_4dipy_8tracking_9distances_50track_roi_intersection_check(CYTHON_UNUSED PyObject *__pyx_self, PyArrayObject *__pyx_v_track, PyArrayObject *__pyx_v_roi, double __pyx_v_sq_dist_thr) {
  float *__pyx_v_t;
  float *__pyx_v_r;
  float __pyx_v_a[3];
  float __pyx_v_b[3];
  float __pyx_v_p[3];
  int __pyx_v_tlen;
  int __pyx_v_rlen;
  int __pyx_v_curr;
  int __pyx_v_currp;
  float __pyx_v_dist;
  int __pyx_v_i;
  int __pyx_v_j;
  int __pyx_v_intersects;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_roi;
  __Pyx_Buffer __pyx_pybuffer_roi;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_track;
  __Pyx_Buffer __pyx_pybuffer_track;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  long __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("track_roi_intersection_check", 0);
  __pyx_pybuffer_track.pybuffer.buf = NULL;
  __pyx_pybuffer_track.refcount = 0;
  __pyx_pybuffernd_track.data = NULL;
  __pyx_pybuffernd_track.rcbuffer = &__pyx_pybuffer_track;
  __pyx_pybuffer_roi.pybuffer.buf = NULL;
  __pyx_pybuffer_roi.refcount = 0;
  __pyx_pybuffernd_roi.data = NULL;
  __pyx_pybuffernd_roi.rcbuffer = &__pyx_pybuffer_roi;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_track.rcbuffer->pybuffer, (PyObject*)__pyx_v_track, &__Pyx_TypeInfo_float, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_pybuffernd_track.diminfo[0].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_track.diminfo[0].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_track.diminfo[1].strides = __pyx_pybuffernd_track.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_track.diminfo[1].shape = __pyx_pybuffernd_track.rcbuffer->pybuffer.shape[1];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_roi.rcbuffer->pybuffer, (PyObject*)__pyx_v_roi, &__Pyx_TypeInfo_float, PyBUF_FORMAT| PyBUF_STRIDES, 2, 0, __pyx_stack) == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_pybuffernd_roi.diminfo[0].strides = __pyx_pybuffernd_roi.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_roi.diminfo[0].shape = __pyx_pybuffernd_roi.rcbuffer->pybuffer.shape[0]; __pyx_pybuffernd_roi.diminfo[1].strides = __pyx_pybuffernd_roi.rcbuffer->pybuffer.strides[1]; __pyx_pybuffernd_roi.diminfo[1].shape = __pyx_pybuffernd_roi.rcbuffer->pybuffer.shape[1];

  /* "dipy/tracking/distances.pyx":2035
 * 
 *     cdef:
 *         float *t=<float *>track.data             # <<<<<<<<<<<<<<
 *         float *r=<float *>roi.data
 *         float a[3],b[3],p[3]
 */
  __pyx_v_t = ((float *)__pyx_v_track->data);

  /* "dipy/tracking/distances.pyx":2036
 *     cdef:
 *         float *t=<float *>track.data
 *         float *r=<float *>roi.data             # <<<<<<<<<<<<<<
 *         float a[3],b[3],p[3]
 *         int tlen = len(track)
 */
  __pyx_v_r = ((float *)__pyx_v_roi->data);

  /* "dipy/tracking/distances.pyx":2038
 *         float *r=<float *>roi.data
 *         float a[3],b[3],p[3]
 *         int tlen = len(track)             # <<<<<<<<<<<<<<
 *         int rlen = len(roi)
 *         int curr = 0
 */
  __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_v_track)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2038; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_tlen = __pyx_t_1;

  /* "dipy/tracking/distances.pyx":2039
 *         float a[3],b[3],p[3]
 *         int tlen = len(track)
 *         int rlen = len(roi)             # <<<<<<<<<<<<<<
 *         int curr = 0
 *         int currp = 0
 */
  __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_v_roi)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2039; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_v_rlen = __pyx_t_1;

  /* "dipy/tracking/distances.pyx":2040
 *         int tlen = len(track)
 *         int rlen = len(roi)
 *         int curr = 0             # <<<<<<<<<<<<<<
 *         int currp = 0
 *         float dist = 0
 */
  __pyx_v_curr = 0;

  /* "dipy/tracking/distances.pyx":2041
 *         int rlen = len(roi)
 *         int curr = 0
 *         int currp = 0             # <<<<<<<<<<<<<<
 *         float dist = 0
 *         int i,j
 */
  __pyx_v_currp = 0;

  /* "dipy/tracking/distances.pyx":2042
 *         int curr = 0
 *         int currp = 0
 *         float dist = 0             # <<<<<<<<<<<<<<
 *         int i,j
 *         int intersects=0
 */
  __pyx_v_dist = 0.0;

  /* "dipy/tracking/distances.pyx":2044
 *         float dist = 0
 *         int i,j
 *         int intersects=0             # <<<<<<<<<<<<<<
 * 
 *     with nogil:
 */
  __pyx_v_intersects = 0;

  /* "dipy/tracking/distances.pyx":2046
 *         int intersects=0
 * 
 *     with nogil:             # <<<<<<<<<<<<<<
 *         for i from 0<=i<tlen-1:
 *             curr=i*3
 */
  {
      #ifdef WITH_THREAD
      PyThreadState *_save;
      Py_UNBLOCK_THREADS
      #endif
      /*try:*/ {

        /* "dipy/tracking/distances.pyx":2047
 * 
 *     with nogil:
 *         for i from 0<=i<tlen-1:             # <<<<<<<<<<<<<<
 *             curr=i*3
 *             a[0]=t[curr]
 */
        __pyx_t_2 = (__pyx_v_tlen - 1);
        for (__pyx_v_i = 0; __pyx_v_i < __pyx_t_2; __pyx_v_i++) {

          /* "dipy/tracking/distances.pyx":2048
 *     with nogil:
 *         for i from 0<=i<tlen-1:
 *             curr=i*3             # <<<<<<<<<<<<<<
 *             a[0]=t[curr]
 *             a[1]=t[curr+1]
 */
          __pyx_v_curr = (__pyx_v_i * 3);

          /* "dipy/tracking/distances.pyx":2049
 *         for i from 0<=i<tlen-1:
 *             curr=i*3
 *             a[0]=t[curr]             # <<<<<<<<<<<<<<
 *             a[1]=t[curr+1]
 *             a[2]=t[curr+2]
 */
          (__pyx_v_a[0]) = (__pyx_v_t[__pyx_v_curr]);

          /* "dipy/tracking/distances.pyx":2050
 *             curr=i*3
 *             a[0]=t[curr]
 *             a[1]=t[curr+1]             # <<<<<<<<<<<<<<
 *             a[2]=t[curr+2]
 *             b[0]=t[curr+3]
 */
          (__pyx_v_a[1]) = (__pyx_v_t[(__pyx_v_curr + 1)]);

          /* "dipy/tracking/distances.pyx":2051
 *             a[0]=t[curr]
 *             a[1]=t[curr+1]
 *             a[2]=t[curr+2]             # <<<<<<<<<<<<<<
 *             b[0]=t[curr+3]
 *             b[1]=t[curr+4]
 */
          (__pyx_v_a[2]) = (__pyx_v_t[(__pyx_v_curr + 2)]);

          /* "dipy/tracking/distances.pyx":2052
 *             a[1]=t[curr+1]
 *             a[2]=t[curr+2]
 *             b[0]=t[curr+3]             # <<<<<<<<<<<<<<
 *             b[1]=t[curr+4]
 *             b[2]=t[curr+5]
 */
          (__pyx_v_b[0]) = (__pyx_v_t[(__pyx_v_curr + 3)]);

          /* "dipy/tracking/distances.pyx":2053
 *             a[2]=t[curr+2]
 *             b[0]=t[curr+3]
 *             b[1]=t[curr+4]             # <<<<<<<<<<<<<<
 *             b[2]=t[curr+5]
 *             for j from 0<=j<rlen:
 */
          (__pyx_v_b[1]) = (__pyx_v_t[(__pyx_v_curr + 4)]);

          /* "dipy/tracking/distances.pyx":2054
 *             b[0]=t[curr+3]
 *             b[1]=t[curr+4]
 *             b[2]=t[curr+5]             # <<<<<<<<<<<<<<
 *             for j from 0<=j<rlen:
 *                 currp=j*3
 */
          (__pyx_v_b[2]) = (__pyx_v_t[(__pyx_v_curr + 5)]);

          /* "dipy/tracking/distances.pyx":2055
 *             b[1]=t[curr+4]
 *             b[2]=t[curr+5]
 *             for j from 0<=j<rlen:             # <<<<<<<<<<<<<<
 *                 currp=j*3
 *                 p[0]=r[currp]
 */
          __pyx_t_3 = __pyx_v_rlen;
          for (__pyx_v_j = 0; __pyx_v_j < __pyx_t_3; __pyx_v_j++) {

            /* "dipy/tracking/distances.pyx":2056
 *             b[2]=t[curr+5]
 *             for j from 0<=j<rlen:
 *                 currp=j*3             # <<<<<<<<<<<<<<
 *                 p[0]=r[currp]
 *                 p[1]=r[currp+1]
 */
            __pyx_v_currp = (__pyx_v_j * 3);

            /* "dipy/tracking/distances.pyx":2057
 *             for j from 0<=j<rlen:
 *                 currp=j*3
 *                 p[0]=r[currp]             # <<<<<<<<<<<<<<
 *                 p[1]=r[currp+1]
 *                 p[2]=r[currp+2]
 */
            (__pyx_v_p[0]) = (__pyx_v_r[__pyx_v_currp]);

            /* "dipy/tracking/distances.pyx":2058
 *                 currp=j*3
 *                 p[0]=r[currp]
 *                 p[1]=r[currp+1]             # <<<<<<<<<<<<<<
 *                 p[2]=r[currp+2]
 *                 dist=cpoint_segment_sq_dist(<float *>a,<float *>b,<float *>p)
 */
            (__pyx_v_p[1]) = (__pyx_v_r[(__pyx_v_currp + 1)]);

            /* "dipy/tracking/distances.pyx":2059
 *                 p[0]=r[currp]
 *                 p[1]=r[currp+1]
 *                 p[2]=r[currp+2]             # <<<<<<<<<<<<<<
 *                 dist=cpoint_segment_sq_dist(<float *>a,<float *>b,<float *>p)
 *                 if dist<=sq_dist_thr:
 */
            (__pyx_v_p[2]) = (__pyx_v_r[(__pyx_v_currp + 2)]);

            /* "dipy/tracking/distances.pyx":2060
 *                 p[1]=r[currp+1]
 *                 p[2]=r[currp+2]
 *                 dist=cpoint_segment_sq_dist(<float *>a,<float *>b,<float *>p)             # <<<<<<<<<<<<<<
 *                 if dist<=sq_dist_thr:
 *                     intersects=1
 */
            __pyx_v_dist = __pyx_f_4dipy_8tracking_9distances_cpoint_segment_sq_dist(((float *)__pyx_v_a), ((float *)__pyx_v_b), ((float *)__pyx_v_p));

            /* "dipy/tracking/distances.pyx":2061
 *                 p[2]=r[currp+2]
 *                 dist=cpoint_segment_sq_dist(<float *>a,<float *>b,<float *>p)
 *                 if dist<=sq_dist_thr:             # <<<<<<<<<<<<<<
 *                     intersects=1
 *                     break
 */
            __pyx_t_4 = ((__pyx_v_dist <= __pyx_v_sq_dist_thr) != 0);
            if (__pyx_t_4) {

              /* "dipy/tracking/distances.pyx":2062
 *                 dist=cpoint_segment_sq_dist(<float *>a,<float *>b,<float *>p)
 *                 if dist<=sq_dist_thr:
 *                     intersects=1             # <<<<<<<<<<<<<<
 *                     break
 *             if intersects==1:
 */
              __pyx_v_intersects = 1;

              /* "dipy/tracking/distances.pyx":2063
 *                 if dist<=sq_dist_thr:
 *                     intersects=1
 *                     break             # <<<<<<<<<<<<<<
 *             if intersects==1:
 *                 break
 */
              goto __pyx_L9_break;

              /* "dipy/tracking/distances.pyx":2061
 *                 p[2]=r[currp+2]
 *                 dist=cpoint_segment_sq_dist(<float *>a,<float *>b,<float *>p)
 *                 if dist<=sq_dist_thr:             # <<<<<<<<<<<<<<
 *                     intersects=1
 *                     break
 */
            }
          }
          __pyx_L9_break:;

          /* "dipy/tracking/distances.pyx":2064
 *                     intersects=1
 *                     break
 *             if intersects==1:             # <<<<<<<<<<<<<<
 *                 break
 *     if intersects==1:
 */
          __pyx_t_4 = ((__pyx_v_intersects == 1) != 0);
          if (__pyx_t_4) {

            /* "dipy/tracking/distances.pyx":2065
 *                     break
 *             if intersects==1:
 *                 break             # <<<<<<<<<<<<<<
 *     if intersects==1:
 *         return True
 */
            goto __pyx_L7_break;

            /* "dipy/tracking/distances.pyx":2064
 *                     intersects=1
 *                     break
 *             if intersects==1:             # <<<<<<<<<<<<<<
 *                 break
 *     if intersects==1:
 */
          }
        }
        __pyx_L7_break:;
      }

      /* "dipy/tracking/distances.pyx":2046
 *         int intersects=0
 * 
 *     with nogil:             # <<<<<<<<<<<<<<
 *         for i from 0<=i<tlen-1:
 *             curr=i*3
 */
      /*finally:*/ {
        /*normal exit:*/{
          #ifdef WITH_THREAD
          Py_BLOCK_THREADS
          #endif
          goto __pyx_L5;
        }
        __pyx_L5:;
      }
  }

  /* "dipy/tracking/distances.pyx":2066
 *             if intersects==1:
 *                 break
 *     if intersects==1:             # <<<<<<<<<<<<<<
 *         return True
 *     else:
 */
  __pyx_t_4 = ((__pyx_v_intersects == 1) != 0);
  if (__pyx_t_4) {

    /* "dipy/tracking/distances.pyx":2067
 *                 break
 *     if intersects==1:
 *         return True             # <<<<<<<<<<<<<<
 *     else:
 *         return False
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_True);
    __pyx_r = Py_True;
    goto __pyx_L0;

    /* "dipy/tracking/distances.pyx":2066
 *             if intersects==1:
 *                 break
 *     if intersects==1:             # <<<<<<<<<<<<<<
 *         return True
 *     else:
 */
  }

  /* "dipy/tracking/distances.pyx":2069
 *         return True
 *     else:
 *         return False             # <<<<<<<<<<<<<<
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_False);
    __pyx_r = Py_False;
    goto __pyx_L0;
  }

  /* "dipy/tracking/distances.pyx":2011
 *         return False
 * 
 * def track_roi_intersection_check(cnp.ndarray[float,ndim=2] track, cnp.ndarray[float,ndim=2] roi, double sq_dist_thr):             # <<<<<<<<<<<<<<
 *     ''' Check if a track is intersecting a region of interest
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_roi.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("dipy.tracking.distances.track_roi_intersection_check", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_roi.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_track.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":197
 *         # experimental exception made for __getbuffer__ and __releasebuffer__
 *         # -- the details of this may change.
 *         def __getbuffer__(ndarray self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fullfill the PEP.
 */

/* Python wrapper */
static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
static CYTHON_UNUSED int __pyx_pw_5numpy_7ndarray_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
  __pyx_r = __pyx_pf_5numpy_7ndarray___getbuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));

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

static int __pyx_pf_5numpy_7ndarray___getbuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
  int __pyx_v_copy_shape;
  int __pyx_v_i;
  int __pyx_v_ndim;
  int __pyx_v_endian_detector;
  int __pyx_v_little_endian;
  int __pyx_v_t;
  char *__pyx_v_f;
  PyArray_Descr *__pyx_v_descr = 0;
  int __pyx_v_offset;
  int __pyx_v_hasfields;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  char *__pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__getbuffer__", 0);
  if (__pyx_v_info != NULL) {
    __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(__pyx_v_info->obj);
  }

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":203
 *             # of flags
 * 
 *             if info == NULL: return             # <<<<<<<<<<<<<<
 * 
 *             cdef int copy_shape, i, ndim
 */
  __pyx_t_1 = ((__pyx_v_info == NULL) != 0);
  if (__pyx_t_1) {
    __pyx_r = 0;
    goto __pyx_L0;
  }

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":206
 * 
 *             cdef int copy_shape, i, ndim
 *             cdef int endian_detector = 1             # <<<<<<<<<<<<<<
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 * 
 */
  __pyx_v_endian_detector = 1;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":207
 *             cdef int copy_shape, i, ndim
 *             cdef int endian_detector = 1
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)             # <<<<<<<<<<<<<<
 * 
 *             ndim = PyArray_NDIM(self)
 */
  __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":209
 *             cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 * 
 *             ndim = PyArray_NDIM(self)             # <<<<<<<<<<<<<<
 * 
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 */
  __pyx_v_ndim = PyArray_NDIM(__pyx_v_self);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":211
 *             ndim = PyArray_NDIM(self)
 * 
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 copy_shape = 1
 *             else:
 */
  __pyx_t_1 = (((sizeof(npy_intp)) != (sizeof(Py_ssize_t))) != 0);
  if (__pyx_t_1) {

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":212
 * 
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 copy_shape = 1             # <<<<<<<<<<<<<<
 *             else:
 *                 copy_shape = 0
 */
    __pyx_v_copy_shape = 1;

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":211
 *             ndim = PyArray_NDIM(self)
 * 
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 copy_shape = 1
 *             else:
 */
    goto __pyx_L4;
  }

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":214
 *                 copy_shape = 1
 *             else:
 *                 copy_shape = 0             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 */
  /*else*/ {
    __pyx_v_copy_shape = 0;
  }
  __pyx_L4:;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":216
 *                 copy_shape = 0
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")
 */
  __pyx_t_2 = (((__pyx_v_flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L6_bool_binop_done;
  }

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":217
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):             # <<<<<<<<<<<<<<
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 */
  __pyx_t_2 = ((!(PyArray_CHKFLAGS(__pyx_v_self, NPY_C_CONTIGUOUS) != 0)) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L6_bool_binop_done:;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":216
 *                 copy_shape = 0
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")
 */
  if (__pyx_t_1) {

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":218
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[1]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":216
 *                 copy_shape = 0
 * 
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")
 */
  }

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":220
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 */
  __pyx_t_2 = (((__pyx_v_flags & PyBUF_F_CONTIGUOUS) == PyBUF_F_CONTIGUOUS) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L9_bool_binop_done;
  }

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":221
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):             # <<<<<<<<<<<<<<
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 * 
 */
  __pyx_t_2 = ((!(PyArray_CHKFLAGS(__pyx_v_self, NPY_F_CONTIGUOUS) != 0)) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L9_bool_binop_done:;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":220
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 */
  if (__pyx_t_1) {

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":222
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")             # <<<<<<<<<<<<<<
 * 
 *             info.buf = PyArray_DATA(self)
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    {__pyx_filename = __pyx_f[1]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":220
 *                 raise ValueError(u"ndarray is not C contiguous")
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)             # <<<<<<<<<<<<<<
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 */
  }

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":224
 *                 raise ValueError(u"ndarray is not Fortran contiguous")
 * 
 *             info.buf = PyArray_DATA(self)             # <<<<<<<<<<<<<<
 *             info.ndim = ndim
 *             if copy_shape:
 */
  __pyx_v_info->buf = PyArray_DATA(__pyx_v_self);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":225
 * 
 *             info.buf = PyArray_DATA(self)
 *             info.ndim = ndim             # <<<<<<<<<<<<<<
 *             if copy_shape:
 *                 # Allocate new buffer for strides and shape info.
 */
  __pyx_v_info->ndim = __pyx_v_ndim;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":226
 *             info.buf = PyArray_DATA(self)
 *             info.ndim = ndim
 *             if copy_shape:             # <<<<<<<<<<<<<<
 *                 # Allocate new buffer for strides and shape info.
 *                 # This is allocated as one block, strides first.
 */
  __pyx_t_1 = (__pyx_v_copy_shape != 0);
  if (__pyx_t_1) {

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":229
 *                 # Allocate new buffer for strides and shape info.
 *                 # This is allocated as one block, strides first.
 *                 info.strides = <Py_ssize_t*>stdlib.malloc(sizeof(Py_ssize_t) * <size_t>ndim * 2)             # <<<<<<<<<<<<<<
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):
 */
    __pyx_v_info->strides = ((Py_ssize_t *)malloc((((sizeof(Py_ssize_t)) * ((size_t)__pyx_v_ndim)) * 2)));

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":230
 *                 # This is allocated as one block, strides first.
 *                 info.strides = <Py_ssize_t*>stdlib.malloc(sizeof(Py_ssize_t) * <size_t>ndim * 2)
 *                 info.shape = info.strides + ndim             # <<<<<<<<<<<<<<
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 */
    __pyx_v_info->shape = (__pyx_v_info->strides + __pyx_v_ndim);

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":231
 *                 info.strides = <Py_ssize_t*>stdlib.malloc(sizeof(Py_ssize_t) * <size_t>ndim * 2)
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):             # <<<<<<<<<<<<<<
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 *                     info.shape[i] = PyArray_DIMS(self)[i]
 */
    __pyx_t_4 = __pyx_v_ndim;
    for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
      __pyx_v_i = __pyx_t_5;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":232
 *                 info.shape = info.strides + ndim
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]             # <<<<<<<<<<<<<<
 *                     info.shape[i] = PyArray_DIMS(self)[i]
 *             else:
 */
      (__pyx_v_info->strides[__pyx_v_i]) = (PyArray_STRIDES(__pyx_v_self)[__pyx_v_i]);

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":233
 *                 for i in range(ndim):
 *                     info.strides[i] = PyArray_STRIDES(self)[i]
 *                     info.shape[i] = PyArray_DIMS(self)[i]             # <<<<<<<<<<<<<<
 *             else:
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 */
      (__pyx_v_info->shape[__pyx_v_i]) = (PyArray_DIMS(__pyx_v_self)[__pyx_v_i]);
    }

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":226
 *             info.buf = PyArray_DATA(self)
 *             info.ndim = ndim
 *             if copy_shape:             # <<<<<<<<<<<<<<
 *                 # Allocate new buffer for strides and shape info.
 *                 # This is allocated as one block, strides first.
 */
    goto __pyx_L11;
  }

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":235
 *                     info.shape[i] = PyArray_DIMS(self)[i]
 *             else:
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)             # <<<<<<<<<<<<<<
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL
 */
  /*else*/ {
    __pyx_v_info->strides = ((Py_ssize_t *)PyArray_STRIDES(__pyx_v_self));

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":236
 *             else:
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)             # <<<<<<<<<<<<<<
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)
 */
    __pyx_v_info->shape = ((Py_ssize_t *)PyArray_DIMS(__pyx_v_self));
  }
  __pyx_L11:;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":237
 *                 info.strides = <Py_ssize_t*>PyArray_STRIDES(self)
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL             # <<<<<<<<<<<<<<
 *             info.itemsize = PyArray_ITEMSIZE(self)
 *             info.readonly = not PyArray_ISWRITEABLE(self)
 */
  __pyx_v_info->suboffsets = NULL;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":238
 *                 info.shape = <Py_ssize_t*>PyArray_DIMS(self)
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)             # <<<<<<<<<<<<<<
 *             info.readonly = not PyArray_ISWRITEABLE(self)
 * 
 */
  __pyx_v_info->itemsize = PyArray_ITEMSIZE(__pyx_v_self);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":239
 *             info.suboffsets = NULL
 *             info.itemsize = PyArray_ITEMSIZE(self)
 *             info.readonly = not PyArray_ISWRITEABLE(self)             # <<<<<<<<<<<<<<
 * 
 *             cdef int t
 */
  __pyx_v_info->readonly = (!(PyArray_ISWRITEABLE(__pyx_v_self) != 0));

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":242
 * 
 *             cdef int t
 *             cdef char* f = NULL             # <<<<<<<<<<<<<<
 *             cdef dtype descr = self.descr
 *             cdef int offset
 */
  __pyx_v_f = NULL;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":243
 *             cdef int t
 *             cdef char* f = NULL
 *             cdef dtype descr = self.descr             # <<<<<<<<<<<<<<
 *             cdef int offset
 * 
 */
  __pyx_t_3 = ((PyObject *)__pyx_v_self->descr);
  __Pyx_INCREF(__pyx_t_3);
  __pyx_v_descr = ((PyArray_Descr *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":246
 *             cdef int offset
 * 
 *             cdef bint hasfields = PyDataType_HASFIELDS(descr)             # <<<<<<<<<<<<<<
 * 
 *             if not hasfields and not copy_shape:
 */
  __pyx_v_hasfields = PyDataType_HASFIELDS(__pyx_v_descr);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":248
 *             cdef bint hasfields = PyDataType_HASFIELDS(descr)
 * 
 *             if not hasfields and not copy_shape:             # <<<<<<<<<<<<<<
 *                 # do not call releasebuffer
 *                 info.obj = None
 */
  __pyx_t_2 = ((!(__pyx_v_hasfields != 0)) != 0);
  if (__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L15_bool_binop_done;
  }
  __pyx_t_2 = ((!(__pyx_v_copy_shape != 0)) != 0);
  __pyx_t_1 = __pyx_t_2;
  __pyx_L15_bool_binop_done:;
  if (__pyx_t_1) {

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":250
 *             if not hasfields and not copy_shape:
 *                 # do not call releasebuffer
 *                 info.obj = None             # <<<<<<<<<<<<<<
 *             else:
 *                 # need to call releasebuffer
 */
    __Pyx_INCREF(Py_None);
    __Pyx_GIVEREF(Py_None);
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj);
    __pyx_v_info->obj = Py_None;

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":248
 *             cdef bint hasfields = PyDataType_HASFIELDS(descr)
 * 
 *             if not hasfields and not copy_shape:             # <<<<<<<<<<<<<<
 *                 # do not call releasebuffer
 *                 info.obj = None
 */
    goto __pyx_L14;
  }

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":253
 *             else:
 *                 # need to call releasebuffer
 *                 info.obj = self             # <<<<<<<<<<<<<<
 * 
 *             if not hasfields:
 */
  /*else*/ {
    __Pyx_INCREF(((PyObject *)__pyx_v_self));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj);
    __pyx_v_info->obj = ((PyObject *)__pyx_v_self);
  }
  __pyx_L14:;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":255
 *                 info.obj = self
 * 
 *             if not hasfields:             # <<<<<<<<<<<<<<
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or
 */
  __pyx_t_1 = ((!(__pyx_v_hasfields != 0)) != 0);
  if (__pyx_t_1) {

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":256
 * 
 *             if not hasfields:
 *                 t = descr.type_num             # <<<<<<<<<<<<<<
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):
 */
    __pyx_t_4 = __pyx_v_descr->type_num;
    __pyx_v_t = __pyx_t_4;

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":257
 *             if not hasfields:
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 */
    __pyx_t_2 = ((__pyx_v_descr->byteorder == '>') != 0);
    if (!__pyx_t_2) {
      goto __pyx_L20_next_or;
    } else {
    }
    __pyx_t_2 = (__pyx_v_little_endian != 0);
    if (!__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L19_bool_binop_done;
    }
    __pyx_L20_next_or:;

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":258
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):             # <<<<<<<<<<<<<<
 *                     raise ValueError(u"Non-native byte order not supported")
 *                 if   t == NPY_BYTE:        f = "b"
 */
    __pyx_t_2 = ((__pyx_v_descr->byteorder == '<') != 0);
    if (__pyx_t_2) {
    } else {
      __pyx_t_1 = __pyx_t_2;
      goto __pyx_L19_bool_binop_done;
    }
    __pyx_t_2 = ((!(__pyx_v_little_endian != 0)) != 0);
    __pyx_t_1 = __pyx_t_2;
    __pyx_L19_bool_binop_done:;

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":257
 *             if not hasfields:
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 */
    if (__pyx_t_1) {

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":259
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"
 */
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[1]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":257
 *             if not hasfields:
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 */
    }

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":260
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")
 *                 if   t == NPY_BYTE:        f = "b"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_UBYTE:       f = "B"
 *                 elif t == NPY_SHORT:       f = "h"
 */
    switch (__pyx_v_t) {
      case NPY_BYTE:
      __pyx_v_f = __pyx_k_b;
      break;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":261
 *                     raise ValueError(u"Non-native byte order not supported")
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_SHORT:       f = "h"
 *                 elif t == NPY_USHORT:      f = "H"
 */
      case NPY_UBYTE:
      __pyx_v_f = __pyx_k_B;
      break;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":262
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"
 *                 elif t == NPY_SHORT:       f = "h"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_USHORT:      f = "H"
 *                 elif t == NPY_INT:         f = "i"
 */
      case NPY_SHORT:
      __pyx_v_f = __pyx_k_h;
      break;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":263
 *                 elif t == NPY_UBYTE:       f = "B"
 *                 elif t == NPY_SHORT:       f = "h"
 *                 elif t == NPY_USHORT:      f = "H"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_INT:         f = "i"
 *                 elif t == NPY_UINT:        f = "I"
 */
      case NPY_USHORT:
      __pyx_v_f = __pyx_k_H;
      break;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":264
 *                 elif t == NPY_SHORT:       f = "h"
 *                 elif t == NPY_USHORT:      f = "H"
 *                 elif t == NPY_INT:         f = "i"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_UINT:        f = "I"
 *                 elif t == NPY_LONG:        f = "l"
 */
      case NPY_INT:
      __pyx_v_f = __pyx_k_i;
      break;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":265
 *                 elif t == NPY_USHORT:      f = "H"
 *                 elif t == NPY_INT:         f = "i"
 *                 elif t == NPY_UINT:        f = "I"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_LONG:        f = "l"
 *                 elif t == NPY_ULONG:       f = "L"
 */
      case NPY_UINT:
      __pyx_v_f = __pyx_k_I;
      break;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":266
 *                 elif t == NPY_INT:         f = "i"
 *                 elif t == NPY_UINT:        f = "I"
 *                 elif t == NPY_LONG:        f = "l"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_ULONG:       f = "L"
 *                 elif t == NPY_LONGLONG:    f = "q"
 */
      case NPY_LONG:
      __pyx_v_f = __pyx_k_l;
      break;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":267
 *                 elif t == NPY_UINT:        f = "I"
 *                 elif t == NPY_LONG:        f = "l"
 *                 elif t == NPY_ULONG:       f = "L"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_LONGLONG:    f = "q"
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 */
      case NPY_ULONG:
      __pyx_v_f = __pyx_k_L;
      break;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":268
 *                 elif t == NPY_LONG:        f = "l"
 *                 elif t == NPY_ULONG:       f = "L"
 *                 elif t == NPY_LONGLONG:    f = "q"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 *                 elif t == NPY_FLOAT:       f = "f"
 */
      case NPY_LONGLONG:
      __pyx_v_f = __pyx_k_q;
      break;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":269
 *                 elif t == NPY_ULONG:       f = "L"
 *                 elif t == NPY_LONGLONG:    f = "q"
 *                 elif t == NPY_ULONGLONG:   f = "Q"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_FLOAT:       f = "f"
 *                 elif t == NPY_DOUBLE:      f = "d"
 */
      case NPY_ULONGLONG:
      __pyx_v_f = __pyx_k_Q;
      break;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":270
 *                 elif t == NPY_LONGLONG:    f = "q"
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 *                 elif t == NPY_FLOAT:       f = "f"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_DOUBLE:      f = "d"
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 */
      case NPY_FLOAT:
      __pyx_v_f = __pyx_k_f;
      break;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":271
 *                 elif t == NPY_ULONGLONG:   f = "Q"
 *                 elif t == NPY_FLOAT:       f = "f"
 *                 elif t == NPY_DOUBLE:      f = "d"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 */
      case NPY_DOUBLE:
      __pyx_v_f = __pyx_k_d;
      break;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":272
 *                 elif t == NPY_FLOAT:       f = "f"
 *                 elif t == NPY_DOUBLE:      f = "d"
 *                 elif t == NPY_LONGDOUBLE:  f = "g"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 */
      case NPY_LONGDOUBLE:
      __pyx_v_f = __pyx_k_g;
      break;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":273
 *                 elif t == NPY_DOUBLE:      f = "d"
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 *                 elif t == NPY_CFLOAT:      f = "Zf"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"
 */
      case NPY_CFLOAT:
      __pyx_v_f = __pyx_k_Zf;
      break;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":274
 *                 elif t == NPY_LONGDOUBLE:  f = "g"
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 *                 elif t == NPY_CDOUBLE:     f = "Zd"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"
 *                 elif t == NPY_OBJECT:      f = "O"
 */
      case NPY_CDOUBLE:
      __pyx_v_f = __pyx_k_Zd;
      break;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":275
 *                 elif t == NPY_CFLOAT:      f = "Zf"
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"             # <<<<<<<<<<<<<<
 *                 elif t == NPY_OBJECT:      f = "O"
 *                 else:
 */
      case NPY_CLONGDOUBLE:
      __pyx_v_f = __pyx_k_Zg;
      break;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":276
 *                 elif t == NPY_CDOUBLE:     f = "Zd"
 *                 elif t == NPY_CLONGDOUBLE: f = "Zg"
 *                 elif t == NPY_OBJECT:      f = "O"             # <<<<<<<<<<<<<<
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 */
      case NPY_OBJECT:
      __pyx_v_f = __pyx_k_O;
      break;
      default:

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":278
 *                 elif t == NPY_OBJECT:      f = "O"
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)             # <<<<<<<<<<<<<<
 *                 info.format = f
 *                 return
 */
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_t); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = PyUnicode_Format(__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_t_3); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_Raise(__pyx_t_6, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      {__pyx_filename = __pyx_f[1]; __pyx_lineno = 278; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      break;
    }

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":279
 *                 else:
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *                 info.format = f             # <<<<<<<<<<<<<<
 *                 return
 *             else:
 */
    __pyx_v_info->format = __pyx_v_f;

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":280
 *                     raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *                 info.format = f
 *                 return             # <<<<<<<<<<<<<<
 *             else:
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":255
 *                 info.obj = self
 * 
 *             if not hasfields:             # <<<<<<<<<<<<<<
 *                 t = descr.type_num
 *                 if ((descr.byteorder == c'>' and little_endian) or
 */
  }

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":282
 *                 return
 *             else:
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)             # <<<<<<<<<<<<<<
 *                 info.format[0] = c'^' # Native data types, manual alignment
 *                 offset = 0
 */
  /*else*/ {
    __pyx_v_info->format = ((char *)malloc(0xFF));

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":283
 *             else:
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)
 *                 info.format[0] = c'^' # Native data types, manual alignment             # <<<<<<<<<<<<<<
 *                 offset = 0
 *                 f = _util_dtypestring(descr, info.format + 1,
 */
    (__pyx_v_info->format[0]) = '^';

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":284
 *                 info.format = <char*>stdlib.malloc(_buffer_format_string_len)
 *                 info.format[0] = c'^' # Native data types, manual alignment
 *                 offset = 0             # <<<<<<<<<<<<<<
 *                 f = _util_dtypestring(descr, info.format + 1,
 *                                       info.format + _buffer_format_string_len,
 */
    __pyx_v_offset = 0;

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":285
 *                 info.format[0] = c'^' # Native data types, manual alignment
 *                 offset = 0
 *                 f = _util_dtypestring(descr, info.format + 1,             # <<<<<<<<<<<<<<
 *                                       info.format + _buffer_format_string_len,
 *                                       &offset)
 */
    __pyx_t_7 = __pyx_f_5numpy__util_dtypestring(__pyx_v_descr, (__pyx_v_info->format + 1), (__pyx_v_info->format + 0xFF), (&__pyx_v_offset)); if (unlikely(__pyx_t_7 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 285; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __pyx_v_f = __pyx_t_7;

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":288
 *                                       info.format + _buffer_format_string_len,
 *                                       &offset)
 *                 f[0] = c'\0' # Terminate format string             # <<<<<<<<<<<<<<
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 */
    (__pyx_v_f[0]) = '\x00';
  }

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":197
 *         # experimental exception made for __getbuffer__ and __releasebuffer__
 *         # -- the details of this may change.
 *         def __getbuffer__(ndarray self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fullfill the PEP.
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("numpy.ndarray.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  if (__pyx_v_info != NULL && __pyx_v_info->obj != NULL) {
    __Pyx_GOTREF(__pyx_v_info->obj);
    __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = NULL;
  }
  goto __pyx_L2;
  __pyx_L0:;
  if (__pyx_v_info != NULL && __pyx_v_info->obj == Py_None) {
    __Pyx_GOTREF(Py_None);
    __Pyx_DECREF(Py_None); __pyx_v_info->obj = NULL;
  }
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_descr);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":290
 *                 f[0] = c'\0' # Terminate format string
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)
 */

/* Python wrapper */
static CYTHON_UNUSED void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/
static CYTHON_UNUSED void __pyx_pw_5numpy_7ndarray_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0);
  __pyx_pf_5numpy_7ndarray_2__releasebuffer__(((PyArrayObject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info));

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

static void __pyx_pf_5numpy_7ndarray_2__releasebuffer__(PyArrayObject *__pyx_v_self, Py_buffer *__pyx_v_info) {
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("__releasebuffer__", 0);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":291
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 *             if PyArray_HASFIELDS(self):             # <<<<<<<<<<<<<<
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 */
  __pyx_t_1 = (PyArray_HASFIELDS(__pyx_v_self) != 0);
  if (__pyx_t_1) {

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":292
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)             # <<<<<<<<<<<<<<
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 stdlib.free(info.strides)
 */
    free(__pyx_v_info->format);

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":291
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):
 *             if PyArray_HASFIELDS(self):             # <<<<<<<<<<<<<<
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 */
  }

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":293
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 stdlib.free(info.strides)
 *                 # info.shape was stored after info.strides in the same block
 */
  __pyx_t_1 = (((sizeof(npy_intp)) != (sizeof(Py_ssize_t))) != 0);
  if (__pyx_t_1) {

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":294
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):
 *                 stdlib.free(info.strides)             # <<<<<<<<<<<<<<
 *                 # info.shape was stored after info.strides in the same block
 * 
 */
    free(__pyx_v_info->strides);

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":293
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)
 *             if sizeof(npy_intp) != sizeof(Py_ssize_t):             # <<<<<<<<<<<<<<
 *                 stdlib.free(info.strides)
 *                 # info.shape was stored after info.strides in the same block
 */
  }

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":290
 *                 f[0] = c'\0' # Terminate format string
 * 
 *         def __releasebuffer__(ndarray self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             if PyArray_HASFIELDS(self):
 *                 stdlib.free(info.format)
 */

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

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":770
 * ctypedef npy_cdouble     complex_t
 * 
 * cdef inline object PyArray_MultiIterNew1(a):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew1(PyObject *__pyx_v_a) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew1", 0);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":771
 * 
 * cdef inline object PyArray_MultiIterNew1(a):
 *     return PyArray_MultiIterNew(1, <void*>a)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(1, ((void *)__pyx_v_a)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 771; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":770
 * ctypedef npy_cdouble     complex_t
 * 
 * cdef inline object PyArray_MultiIterNew1(a):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew1", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":773
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew2(PyObject *__pyx_v_a, PyObject *__pyx_v_b) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew2", 0);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":774
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(2, ((void *)__pyx_v_a), ((void *)__pyx_v_b)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 774; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":773
 *     return PyArray_MultiIterNew(1, <void*>a)
 * 
 * cdef inline object PyArray_MultiIterNew2(a, b):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew2", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":776
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew3(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew3", 0);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":777
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(3, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":776
 *     return PyArray_MultiIterNew(2, <void*>a, <void*>b)
 * 
 * cdef inline object PyArray_MultiIterNew3(a, b, c):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew3", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":779
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew4(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew4", 0);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":780
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)             # <<<<<<<<<<<<<<
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(4, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 780; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":779
 *     return PyArray_MultiIterNew(3, <void*>a, <void*>b, <void*> c)
 * 
 * cdef inline object PyArray_MultiIterNew4(a, b, c, d):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew4", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":782
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_PyArray_MultiIterNew5(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_c, PyObject *__pyx_v_d, PyObject *__pyx_v_e) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("PyArray_MultiIterNew5", 0);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":783
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)             # <<<<<<<<<<<<<<
 * 
 * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyArray_MultiIterNew(5, ((void *)__pyx_v_a), ((void *)__pyx_v_b), ((void *)__pyx_v_c), ((void *)__pyx_v_d), ((void *)__pyx_v_e)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 783; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":782
 *     return PyArray_MultiIterNew(4, <void*>a, <void*>b, <void*>c, <void*> d)
 * 
 * cdef inline object PyArray_MultiIterNew5(a, b, c, d, e):             # <<<<<<<<<<<<<<
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("numpy.PyArray_MultiIterNew5", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":785
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:             # <<<<<<<<<<<<<<
 *     # Recursive utility function used in __getbuffer__ to get format
 *     # string. The new location in the format string is returned.
 */

static CYTHON_INLINE char *__pyx_f_5numpy__util_dtypestring(PyArray_Descr *__pyx_v_descr, char *__pyx_v_f, char *__pyx_v_end, int *__pyx_v_offset) {
  PyArray_Descr *__pyx_v_child = 0;
  int __pyx_v_endian_detector;
  int __pyx_v_little_endian;
  PyObject *__pyx_v_fields = 0;
  PyObject *__pyx_v_childname = NULL;
  PyObject *__pyx_v_new_offset = NULL;
  PyObject *__pyx_v_t = NULL;
  char *__pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  long __pyx_t_8;
  char *__pyx_t_9;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_util_dtypestring", 0);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":790
 * 
 *     cdef dtype child
 *     cdef int endian_detector = 1             # <<<<<<<<<<<<<<
 *     cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)
 *     cdef tuple fields
 */
  __pyx_v_endian_detector = 1;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":791
 *     cdef dtype child
 *     cdef int endian_detector = 1
 *     cdef bint little_endian = ((<char*>&endian_detector)[0] != 0)             # <<<<<<<<<<<<<<
 *     cdef tuple fields
 * 
 */
  __pyx_v_little_endian = ((((char *)(&__pyx_v_endian_detector))[0]) != 0);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":794
 *     cdef tuple fields
 * 
 *     for childname in descr.names:             # <<<<<<<<<<<<<<
 *         fields = descr.fields[childname]
 *         child, new_offset = fields
 */
  if (unlikely(__pyx_v_descr->names == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    {__pyx_filename = __pyx_f[1]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  __pyx_t_1 = __pyx_v_descr->names; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
  for (;;) {
    if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_COMPILING_IN_CPYTHON
    __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 794; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_childname, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":795
 * 
 *     for childname in descr.names:
 *         fields = descr.fields[childname]             # <<<<<<<<<<<<<<
 *         child, new_offset = fields
 * 
 */
    if (unlikely(__pyx_v_descr->fields == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_descr->fields, __pyx_v_childname); if (unlikely(__pyx_t_3 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
    __Pyx_GOTREF(__pyx_t_3);
    if (!(likely(PyTuple_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 795; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_XDECREF_SET(__pyx_v_fields, ((PyObject*)__pyx_t_3));
    __pyx_t_3 = 0;

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":796
 *     for childname in descr.names:
 *         fields = descr.fields[childname]
 *         child, new_offset = fields             # <<<<<<<<<<<<<<
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:
 */
    if (likely(__pyx_v_fields != Py_None)) {
      PyObject* sequence = __pyx_v_fields;
      #if CYTHON_COMPILING_IN_CPYTHON
      Py_ssize_t size = Py_SIZE(sequence);
      #else
      Py_ssize_t size = PySequence_Size(sequence);
      #endif
      if (unlikely(size != 2)) {
        if (size > 2) __Pyx_RaiseTooManyValuesError(2);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      #if CYTHON_COMPILING_IN_CPYTHON
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); 
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_4);
      #else
      __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      #endif
    } else {
      __Pyx_RaiseNoneNotIterableError(); {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_5numpy_dtype))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 796; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_XDECREF_SET(__pyx_v_child, ((PyArray_Descr *)__pyx_t_3));
    __pyx_t_3 = 0;
    __Pyx_XDECREF_SET(__pyx_v_new_offset, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":798
 *         child, new_offset = fields
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:             # <<<<<<<<<<<<<<
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 */
    __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_v_offset[0])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyNumber_Subtract(__pyx_v_new_offset, __pyx_t_4); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 798; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_6 = ((((__pyx_v_end - __pyx_v_f) - ((int)__pyx_t_5)) < 15) != 0);
    if (__pyx_t_6) {

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":799
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")             # <<<<<<<<<<<<<<
 * 
 *         if ((child.byteorder == c'>' and little_endian) or
 */
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":798
 *         child, new_offset = fields
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:             # <<<<<<<<<<<<<<
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 */
    }

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":801
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 *         if ((child.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")
 */
    __pyx_t_7 = ((__pyx_v_child->byteorder == '>') != 0);
    if (!__pyx_t_7) {
      goto __pyx_L8_next_or;
    } else {
    }
    __pyx_t_7 = (__pyx_v_little_endian != 0);
    if (!__pyx_t_7) {
    } else {
      __pyx_t_6 = __pyx_t_7;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_L8_next_or:;

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":802
 * 
 *         if ((child.byteorder == c'>' and little_endian) or
 *             (child.byteorder == c'<' and not little_endian)):             # <<<<<<<<<<<<<<
 *             raise ValueError(u"Non-native byte order not supported")
 *             # One could encode it in the format string and have Cython
 */
    __pyx_t_7 = ((__pyx_v_child->byteorder == '<') != 0);
    if (__pyx_t_7) {
    } else {
      __pyx_t_6 = __pyx_t_7;
      goto __pyx_L7_bool_binop_done;
    }
    __pyx_t_7 = ((!(__pyx_v_little_endian != 0)) != 0);
    __pyx_t_6 = __pyx_t_7;
    __pyx_L7_bool_binop_done:;

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":801
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 *         if ((child.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")
 */
    if (__pyx_t_6) {

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":803
 *         if ((child.byteorder == c'>' and little_endian) or
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *             # One could encode it in the format string and have Cython
 *             # complain instead, BUT: < and > in format strings also imply
 */
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__27, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":801
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")
 * 
 *         if ((child.byteorder == c'>' and little_endian) or             # <<<<<<<<<<<<<<
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")
 */
    }

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":813
 * 
 *         # Output padding bytes
 *         while offset[0] < new_offset:             # <<<<<<<<<<<<<<
 *             f[0] = 120 # "x"; pad byte
 *             f += 1
 */
    while (1) {
      __pyx_t_3 = __Pyx_PyInt_From_int((__pyx_v_offset[0])); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_v_new_offset, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 813; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (!__pyx_t_6) break;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":814
 *         # Output padding bytes
 *         while offset[0] < new_offset:
 *             f[0] = 120 # "x"; pad byte             # <<<<<<<<<<<<<<
 *             f += 1
 *             offset[0] += 1
 */
      (__pyx_v_f[0]) = 0x78;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":815
 *         while offset[0] < new_offset:
 *             f[0] = 120 # "x"; pad byte
 *             f += 1             # <<<<<<<<<<<<<<
 *             offset[0] += 1
 * 
 */
      __pyx_v_f = (__pyx_v_f + 1);

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":816
 *             f[0] = 120 # "x"; pad byte
 *             f += 1
 *             offset[0] += 1             # <<<<<<<<<<<<<<
 * 
 *         offset[0] += child.itemsize
 */
      __pyx_t_8 = 0;
      (__pyx_v_offset[__pyx_t_8]) = ((__pyx_v_offset[__pyx_t_8]) + 1);
    }

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":818
 *             offset[0] += 1
 * 
 *         offset[0] += child.itemsize             # <<<<<<<<<<<<<<
 * 
 *         if not PyDataType_HASFIELDS(child):
 */
    __pyx_t_8 = 0;
    (__pyx_v_offset[__pyx_t_8]) = ((__pyx_v_offset[__pyx_t_8]) + __pyx_v_child->elsize);

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":820
 *         offset[0] += child.itemsize
 * 
 *         if not PyDataType_HASFIELDS(child):             # <<<<<<<<<<<<<<
 *             t = child.type_num
 *             if end - f < 5:
 */
    __pyx_t_6 = ((!(PyDataType_HASFIELDS(__pyx_v_child) != 0)) != 0);
    if (__pyx_t_6) {

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":821
 * 
 *         if not PyDataType_HASFIELDS(child):
 *             t = child.type_num             # <<<<<<<<<<<<<<
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")
 */
      __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_child->type_num); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 821; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":822
 *         if not PyDataType_HASFIELDS(child):
 *             t = child.type_num
 *             if end - f < 5:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError(u"Format string allocated too short.")
 * 
 */
      __pyx_t_6 = (((__pyx_v_end - __pyx_v_f) < 5) != 0);
      if (__pyx_t_6) {

        /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":823
 *             t = child.type_num
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")             # <<<<<<<<<<<<<<
 * 
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 */
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_RuntimeError, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_Raise(__pyx_t_4, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

        /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":822
 *         if not PyDataType_HASFIELDS(child):
 *             t = child.type_num
 *             if end - f < 5:             # <<<<<<<<<<<<<<
 *                 raise RuntimeError(u"Format string allocated too short.")
 * 
 */
      }

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":826
 * 
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 *             if   t == NPY_BYTE:        f[0] =  98 #"b"             # <<<<<<<<<<<<<<
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_BYTE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 826; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 98;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":827
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 *             if   t == NPY_BYTE:        f[0] =  98 #"b"
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"             # <<<<<<<<<<<<<<
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_UBYTE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 827; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 66;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":828
 *             if   t == NPY_BYTE:        f[0] =  98 #"b"
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"             # <<<<<<<<<<<<<<
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_SHORT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 828; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x68;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":829
 *             elif t == NPY_UBYTE:       f[0] =  66 #"B"
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"             # <<<<<<<<<<<<<<
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_USHORT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 829; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 72;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":830
 *             elif t == NPY_SHORT:       f[0] = 104 #"h"
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 *             elif t == NPY_INT:         f[0] = 105 #"i"             # <<<<<<<<<<<<<<
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_INT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 830; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x69;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":831
 *             elif t == NPY_USHORT:      f[0] =  72 #"H"
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 *             elif t == NPY_UINT:        f[0] =  73 #"I"             # <<<<<<<<<<<<<<
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_UINT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 831; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 73;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":832
 *             elif t == NPY_INT:         f[0] = 105 #"i"
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 *             elif t == NPY_LONG:        f[0] = 108 #"l"             # <<<<<<<<<<<<<<
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_LONG); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 832; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x6C;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":833
 *             elif t == NPY_UINT:        f[0] =  73 #"I"
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"             # <<<<<<<<<<<<<<
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_ULONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 833; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 76;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":834
 *             elif t == NPY_LONG:        f[0] = 108 #"l"
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"             # <<<<<<<<<<<<<<
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_LONGLONG); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 834; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x71;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":835
 *             elif t == NPY_ULONG:       f[0] = 76  #"L"
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"             # <<<<<<<<<<<<<<
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_ULONGLONG); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 835; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 81;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":836
 *             elif t == NPY_LONGLONG:    f[0] = 113 #"q"
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"             # <<<<<<<<<<<<<<
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_FLOAT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 836; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x66;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":837
 *             elif t == NPY_ULONGLONG:   f[0] = 81  #"Q"
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"             # <<<<<<<<<<<<<<
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_DOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 837; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x64;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":838
 *             elif t == NPY_FLOAT:       f[0] = 102 #"f"
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"             # <<<<<<<<<<<<<<
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_LONGDOUBLE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 0x67;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":839
 *             elif t == NPY_DOUBLE:      f[0] = 100 #"d"
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf             # <<<<<<<<<<<<<<
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_CFLOAT); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 839; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 0x66;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":840
 *             elif t == NPY_LONGDOUBLE:  f[0] = 103 #"g"
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd             # <<<<<<<<<<<<<<
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_CDOUBLE); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 840; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 0x64;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":841
 *             elif t == NPY_CFLOAT:      f[0] = 90; f[1] = 102; f += 1 # Zf
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg             # <<<<<<<<<<<<<<
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 *             else:
 */
      __pyx_t_3 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_CLONGDOUBLE); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_t, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 841; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 90;
        (__pyx_v_f[1]) = 0x67;
        __pyx_v_f = (__pyx_v_f + 1);
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":842
 *             elif t == NPY_CDOUBLE:     f[0] = 90; f[1] = 100; f += 1 # Zd
 *             elif t == NPY_CLONGDOUBLE: f[0] = 90; f[1] = 103; f += 1 # Zg
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"             # <<<<<<<<<<<<<<
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 */
      __pyx_t_4 = __Pyx_PyInt_From_enum__NPY_TYPES(NPY_OBJECT); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = PyObject_RichCompare(__pyx_v_t, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 842; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (__pyx_t_6) {
        (__pyx_v_f[0]) = 79;
        goto __pyx_L15;
      }

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":844
 *             elif t == NPY_OBJECT:      f[0] = 79 #"O"
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)             # <<<<<<<<<<<<<<
 *             f += 1
 *         else:
 */
      /*else*/ {
        __pyx_t_3 = PyUnicode_Format(__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_v_t); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
        __pyx_t_3 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_Raise(__pyx_t_3, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        {__pyx_filename = __pyx_f[1]; __pyx_lineno = 844; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      }
      __pyx_L15:;

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":845
 *             else:
 *                 raise ValueError(u"unknown dtype code in numpy.pxd (%d)" % t)
 *             f += 1             # <<<<<<<<<<<<<<
 *         else:
 *             # Cython ignores struct boundary information ("T{...}"),
 */
      __pyx_v_f = (__pyx_v_f + 1);

      /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":820
 *         offset[0] += child.itemsize
 * 
 *         if not PyDataType_HASFIELDS(child):             # <<<<<<<<<<<<<<
 *             t = child.type_num
 *             if end - f < 5:
 */
      goto __pyx_L13;
    }

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":849
 *             # Cython ignores struct boundary information ("T{...}"),
 *             # so don't output it
 *             f = _util_dtypestring(child, f, end, offset)             # <<<<<<<<<<<<<<
 *     return f
 * 
 */
    /*else*/ {
      __pyx_t_9 = __pyx_f_5numpy__util_dtypestring(__pyx_v_child, __pyx_v_f, __pyx_v_end, __pyx_v_offset); if (unlikely(__pyx_t_9 == NULL)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 849; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
      __pyx_v_f = __pyx_t_9;
    }
    __pyx_L13:;

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":794
 *     cdef tuple fields
 * 
 *     for childname in descr.names:             # <<<<<<<<<<<<<<
 *         fields = descr.fields[childname]
 *         child, new_offset = fields
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":850
 *             # so don't output it
 *             f = _util_dtypestring(child, f, end, offset)
 *     return f             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_f;
  goto __pyx_L0;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":785
 *     return PyArray_MultiIterNew(5, <void*>a, <void*>b, <void*>c, <void*> d, <void*> e)
 * 
 * cdef inline char* _util_dtypestring(dtype descr, char* f, char* end, int* offset) except NULL:             # <<<<<<<<<<<<<<
 *     # Recursive utility function used in __getbuffer__ to get format
 *     # string. The new location in the format string is returned.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("numpy._util_dtypestring", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_child);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XDECREF(__pyx_v_childname);
  __Pyx_XDECREF(__pyx_v_new_offset);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":966
 * 
 * 
 * cdef inline void set_array_base(ndarray arr, object base):             # <<<<<<<<<<<<<<
 *      cdef PyObject* baseptr
 *      if base is None:
 */

static CYTHON_INLINE void __pyx_f_5numpy_set_array_base(PyArrayObject *__pyx_v_arr, PyObject *__pyx_v_base) {
  PyObject *__pyx_v_baseptr;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  __Pyx_RefNannySetupContext("set_array_base", 0);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":968
 * cdef inline void set_array_base(ndarray arr, object base):
 *      cdef PyObject* baseptr
 *      if base is None:             # <<<<<<<<<<<<<<
 *          baseptr = NULL
 *      else:
 */
  __pyx_t_1 = (__pyx_v_base == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":969
 *      cdef PyObject* baseptr
 *      if base is None:
 *          baseptr = NULL             # <<<<<<<<<<<<<<
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!
 */
    __pyx_v_baseptr = NULL;

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":968
 * cdef inline void set_array_base(ndarray arr, object base):
 *      cdef PyObject* baseptr
 *      if base is None:             # <<<<<<<<<<<<<<
 *          baseptr = NULL
 *      else:
 */
    goto __pyx_L3;
  }

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":971
 *          baseptr = NULL
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!             # <<<<<<<<<<<<<<
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)
 */
  /*else*/ {
    Py_INCREF(__pyx_v_base);

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":972
 *      else:
 *          Py_INCREF(base) # important to do this before decref below!
 *          baseptr = <PyObject*>base             # <<<<<<<<<<<<<<
 *      Py_XDECREF(arr.base)
 *      arr.base = baseptr
 */
    __pyx_v_baseptr = ((PyObject *)__pyx_v_base);
  }
  __pyx_L3:;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":973
 *          Py_INCREF(base) # important to do this before decref below!
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)             # <<<<<<<<<<<<<<
 *      arr.base = baseptr
 * 
 */
  Py_XDECREF(__pyx_v_arr->base);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":974
 *          baseptr = <PyObject*>base
 *      Py_XDECREF(arr.base)
 *      arr.base = baseptr             # <<<<<<<<<<<<<<
 * 
 * cdef inline object get_array_base(ndarray arr):
 */
  __pyx_v_arr->base = __pyx_v_baseptr;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":966
 * 
 * 
 * cdef inline void set_array_base(ndarray arr, object base):             # <<<<<<<<<<<<<<
 *      cdef PyObject* baseptr
 *      if base is None:
 */

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

/* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":976
 *      arr.base = baseptr
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     if arr.base is NULL:
 *         return None
 */

static CYTHON_INLINE PyObject *__pyx_f_5numpy_get_array_base(PyArrayObject *__pyx_v_arr) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  __Pyx_RefNannySetupContext("get_array_base", 0);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":977
 * 
 * cdef inline object get_array_base(ndarray arr):
 *     if arr.base is NULL:             # <<<<<<<<<<<<<<
 *         return None
 *     else:
 */
  __pyx_t_1 = ((__pyx_v_arr->base == NULL) != 0);
  if (__pyx_t_1) {

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":978
 * cdef inline object get_array_base(ndarray arr):
 *     if arr.base is NULL:
 *         return None             # <<<<<<<<<<<<<<
 *     else:
 *         return <object>arr.base
 */
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(Py_None);
    __pyx_r = Py_None;
    goto __pyx_L0;

    /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":977
 * 
 * cdef inline object get_array_base(ndarray arr):
 *     if arr.base is NULL:             # <<<<<<<<<<<<<<
 *         return None
 *     else:
 */
  }

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":980
 *         return None
 *     else:
 *         return <object>arr.base             # <<<<<<<<<<<<<<
 */
  /*else*/ {
    __Pyx_XDECREF(__pyx_r);
    __Pyx_INCREF(((PyObject *)__pyx_v_arr->base));
    __pyx_r = ((PyObject *)__pyx_v_arr->base);
    goto __pyx_L0;
  }

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":976
 *      arr.base = baseptr
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     if arr.base is NULL:
 *         return None
 */

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

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
  #if PY_VERSION_HEX < 0x03020000
    { PyObject_HEAD_INIT(NULL) NULL, 0, NULL },
  #else
    PyModuleDef_HEAD_INIT,
  #endif
    "distances",
    __pyx_k_Optimized_track_distances_simil, /* m_doc */
    -1, /* m_size */
    __pyx_methods /* m_methods */,
    NULL, /* m_reload */
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_n_s_C, __pyx_k_C, sizeof(__pyx_k_C), 0, 0, 1, 1},
  {&__pyx_n_s_C2, __pyx_k_C2, sizeof(__pyx_k_C2), 0, 0, 1, 1},
  {&__pyx_kp_u_Calculate_the_euclidean_distanc, __pyx_k_Calculate_the_euclidean_distanc, sizeof(__pyx_k_Calculate_the_euclidean_distanc), 0, 1, 0, 0},
  {&__pyx_kp_u_Calculate_the_squared_distance, __pyx_k_Calculate_the_squared_distance, sizeof(__pyx_k_Calculate_the_squared_distance), 0, 1, 0, 0},
  {&__pyx_kp_u_Calculates_angle_distance_metri, __pyx_k_Calculates_angle_distance_metri, sizeof(__pyx_k_Calculates_angle_distance_metri), 0, 1, 0, 0},
  {&__pyx_kp_u_Calculates_perpendicular_distan, __pyx_k_Calculates_perpendicular_distan, sizeof(__pyx_k_Calculates_perpendicular_distan), 0, 1, 0, 0},
  {&__pyx_kp_u_Check_if_a_track_is_intersectin, __pyx_k_Check_if_a_track_is_intersectin, sizeof(__pyx_k_Check_if_a_track_is_intersectin), 0, 1, 0, 0},
  {&__pyx_kp_u_Check_if_square_distance_of_tra, __pyx_k_Check_if_square_distance_of_tra, sizeof(__pyx_k_Check_if_square_distance_of_tra), 0, 1, 0, 0},
  {&__pyx_n_s_DM, __pyx_k_DM, sizeof(__pyx_k_DM), 0, 0, 1, 1},
  {&__pyx_kp_u_Does_a_first_pass_clustering_Ev, __pyx_k_Does_a_first_pass_clustering_Ev, sizeof(__pyx_k_Does_a_first_pass_clustering_Ev), 0, 1, 0, 0},
  {&__pyx_kp_u_Efficient_tractography_clusterin, __pyx_k_Efficient_tractography_clusterin, sizeof(__pyx_k_Efficient_tractography_clusterin), 0, 1, 0, 0},
  {&__pyx_kp_u_Extract_divergence_vectors_and, __pyx_k_Extract_divergence_vectors_and, sizeof(__pyx_k_Extract_divergence_vectors_and), 0, 1, 0, 0},
  {&__pyx_kp_u_Fast_and_simple_trajectory_appr, __pyx_k_Fast_and_simple_trajectory_appr, sizeof(__pyx_k_Fast_and_simple_trajectory_appr), 0, 1, 0, 0},
  {&__pyx_kp_u_Format_string_allocated_too_shor, __pyx_k_Format_string_allocated_too_shor, sizeof(__pyx_k_Format_string_allocated_too_shor), 0, 1, 0, 0},
  {&__pyx_kp_u_Format_string_allocated_too_shor_2, __pyx_k_Format_string_allocated_too_shor_2, sizeof(__pyx_k_Format_string_allocated_too_shor_2), 0, 1, 0, 0},
  {&__pyx_kp_u_Generate_a_first_pass_clustering, __pyx_k_Generate_a_first_pass_clustering, sizeof(__pyx_k_Generate_a_first_pass_clustering), 0, 1, 0, 0},
  {&__pyx_n_s_Hit, __pyx_k_Hit, sizeof(__pyx_k_Hit), 0, 0, 1, 1},
  {&__pyx_kp_u_Intersect_Segment_S_t_sa_t_sb_s, __pyx_k_Intersect_Segment_S_t_sa_t_sb_s, sizeof(__pyx_k_Intersect_Segment_S_t_sa_t_sb_s), 0, 1, 0, 0},
  {&__pyx_kp_s_Metric_should_be_one_of_avg_min, __pyx_k_Metric_should_be_one_of_avg_min, sizeof(__pyx_k_Metric_should_be_one_of_avg_min), 0, 0, 1, 0},
  {&__pyx_n_s_N, __pyx_k_N, sizeof(__pyx_k_N), 0, 0, 1, 1},
  {&__pyx_n_s_N_ref, __pyx_k_N_ref, sizeof(__pyx_k_N_ref), 0, 0, 1, 1},
  {&__pyx_n_s_N_track, __pyx_k_N_track, sizeof(__pyx_k_N_track), 0, 0, 1, 1},
  {&__pyx_n_s_N_tracks, __pyx_k_N_tracks, sizeof(__pyx_k_N_tracks), 0, 0, 1, 1},
  {&__pyx_kp_u_Non_native_byte_order_not_suppor, __pyx_k_Non_native_byte_order_not_suppor, sizeof(__pyx_k_Non_native_byte_order_not_suppor), 0, 1, 0, 0},
  {&__pyx_n_s_RuntimeError, __pyx_k_RuntimeError, sizeof(__pyx_k_RuntimeError), 0, 0, 1, 1},
  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  {&__pyx_kp_s_Wrong_argument_for_metric, __pyx_k_Wrong_argument_for_metric, sizeof(__pyx_k_Wrong_argument_for_metric), 0, 0, 1, 0},
  {&__pyx_n_s_a, __pyx_k_a, sizeof(__pyx_k_a), 0, 0, 1, 1},
  {&__pyx_n_s_add_3vecs, __pyx_k_add_3vecs, sizeof(__pyx_k_add_3vecs), 0, 0, 1, 1},
  {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1},
  {&__pyx_n_s_alld, __pyx_k_alld, sizeof(__pyx_k_alld), 0, 0, 1, 1},
  {&__pyx_n_s_along, __pyx_k_along, sizeof(__pyx_k_along), 0, 0, 1, 1},
  {&__pyx_n_s_alpha, __pyx_k_alpha, sizeof(__pyx_k_alpha), 0, 0, 1, 1},
  {&__pyx_n_s_alphac, __pyx_k_alphac, sizeof(__pyx_k_alphac), 0, 0, 1, 1},
  {&__pyx_n_s_angle, __pyx_k_angle, sizeof(__pyx_k_angle), 0, 0, 1, 1},
  {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1},
  {&__pyx_n_s_approx_polygon_track, __pyx_k_approx_polygon_track, sizeof(__pyx_k_approx_polygon_track), 0, 0, 1, 1},
  {&__pyx_kp_u_approx_polygon_track_line_1007, __pyx_k_approx_polygon_track_line_1007, sizeof(__pyx_k_approx_polygon_track_line_1007), 0, 1, 0, 0},
  {&__pyx_n_s_approximate_mdl_trajectory, __pyx_k_approximate_mdl_trajectory, sizeof(__pyx_k_approximate_mdl_trajectory), 0, 0, 1, 1},
  {&__pyx_n_s_argmin, __pyx_k_argmin, sizeof(__pyx_k_argmin), 0, 0, 1, 1},
  {&__pyx_n_s_array, __pyx_k_array, sizeof(__pyx_k_array), 0, 0, 1, 1},
  {&__pyx_n_s_asarray, __pyx_k_asarray, sizeof(__pyx_k_asarray), 0, 0, 1, 1},
  {&__pyx_n_s_ascontiguousarray, __pyx_k_ascontiguousarray, sizeof(__pyx_k_ascontiguousarray), 0, 0, 1, 1},
  {&__pyx_n_s_avg, __pyx_k_avg, sizeof(__pyx_k_avg), 0, 0, 1, 1},
  {&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1},
  {&__pyx_n_s_beta, __pyx_k_beta, sizeof(__pyx_k_beta), 0, 0, 1, 1},
  {&__pyx_n_s_bundles_distances_mam, __pyx_k_bundles_distances_mam, sizeof(__pyx_k_bundles_distances_mam), 0, 0, 1, 1},
  {&__pyx_n_s_bundles_distances_mdf, __pyx_k_bundles_distances_mdf, sizeof(__pyx_k_bundles_distances_mdf), 0, 0, 1, 1},
  {&__pyx_n_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 1},
  {&__pyx_n_s_ca, __pyx_k_ca, sizeof(__pyx_k_ca), 0, 0, 1, 1},
  {&__pyx_n_s_cb, __pyx_k_cb, sizeof(__pyx_k_cb), 0, 0, 1, 1},
  {&__pyx_n_s_cc, __pyx_k_cc, sizeof(__pyx_k_cc), 0, 0, 1, 1},
  {&__pyx_n_s_cd_thr, __pyx_k_cd_thr, sizeof(__pyx_k_cd_thr), 0, 0, 1, 1},
  {&__pyx_n_s_ch, __pyx_k_ch, sizeof(__pyx_k_ch), 0, 0, 1, 1},
  {&__pyx_n_s_characteristic_points, __pyx_k_characteristic_points, sizeof(__pyx_k_characteristic_points), 0, 0, 1, 1},
  {&__pyx_n_s_cit, __pyx_k_cit, sizeof(__pyx_k_cit), 0, 0, 1, 1},
  {&__pyx_n_s_cluster, __pyx_k_cluster, sizeof(__pyx_k_cluster), 0, 0, 1, 1},
  {&__pyx_n_s_copy, __pyx_k_copy, sizeof(__pyx_k_copy), 0, 0, 1, 1},
  {&__pyx_n_s_cost_nopar, __pyx_k_cost_nopar, sizeof(__pyx_k_cost_nopar), 0, 0, 1, 1},
  {&__pyx_n_s_cost_par, __pyx_k_cost_par, sizeof(__pyx_k_cost_par), 0, 0, 1, 1},
  {&__pyx_n_s_cp, __pyx_k_cp, sizeof(__pyx_k_cp), 0, 0, 1, 1},
  {&__pyx_n_s_cq, __pyx_k_cq, sizeof(__pyx_k_cq), 0, 0, 1, 1},
  {&__pyx_n_s_cr, __pyx_k_cr, sizeof(__pyx_k_cr), 0, 0, 1, 1},
  {&__pyx_n_s_csa, __pyx_k_csa, sizeof(__pyx_k_csa), 0, 0, 1, 1},
  {&__pyx_n_s_csb, __pyx_k_csb, sizeof(__pyx_k_csb), 0, 0, 1, 1},
  {&__pyx_n_s_ct, __pyx_k_ct, sizeof(__pyx_k_ct), 0, 0, 1, 1},
  {&__pyx_n_s_curr, __pyx_k_curr, sizeof(__pyx_k_curr), 0, 0, 1, 1},
  {&__pyx_n_s_current_index, __pyx_k_current_index, sizeof(__pyx_k_current_index), 0, 0, 1, 1},
  {&__pyx_n_s_currp, __pyx_k_currp, sizeof(__pyx_k_currp), 0, 0, 1, 1},
  {&__pyx_n_s_cut_plane, __pyx_k_cut_plane, sizeof(__pyx_k_cut_plane), 0, 0, 1, 1},
  {&__pyx_kp_u_cut_plane_line_190, __pyx_k_cut_plane_line_190, sizeof(__pyx_k_cut_plane_line_190), 0, 1, 0, 0},
  {&__pyx_n_s_d, __pyx_k_d, sizeof(__pyx_k_d), 0, 0, 1, 1},
  {&__pyx_n_s_d_thr, __pyx_k_d_thr, sizeof(__pyx_k_d_thr), 0, 0, 1, 1},
  {&__pyx_n_s_delta, __pyx_k_delta, sizeof(__pyx_k_delta), 0, 0, 1, 1},
  {&__pyx_n_s_dim, __pyx_k_dim, sizeof(__pyx_k_dim), 0, 0, 1, 1},
  {&__pyx_n_s_dipy_tracking_distances, __pyx_k_dipy_tracking_distances, sizeof(__pyx_k_dipy_tracking_distances), 0, 0, 1, 1},
  {&__pyx_n_s_dist, __pyx_k_dist, sizeof(__pyx_k_dist), 0, 0, 1, 1},
  {&__pyx_n_s_distance, __pyx_k_distance, sizeof(__pyx_k_distance), 0, 0, 1, 1},
  {&__pyx_n_s_distances_buffer, __pyx_k_distances_buffer, sizeof(__pyx_k_distances_buffer), 0, 0, 1, 1},
  {&__pyx_n_s_double, __pyx_k_double, sizeof(__pyx_k_double), 0, 0, 1, 1},
  {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1},
  {&__pyx_n_s_empty, __pyx_k_empty, sizeof(__pyx_k_empty), 0, 0, 1, 1},
  {&__pyx_n_s_end0, __pyx_k_end0, sizeof(__pyx_k_end0), 0, 0, 1, 1},
  {&__pyx_n_s_end1, __pyx_k_end1, sizeof(__pyx_k_end1), 0, 0, 1, 1},
  {&__pyx_n_s_flip, __pyx_k_flip, sizeof(__pyx_k_flip), 0, 0, 1, 1},
  {&__pyx_n_s_float32, __pyx_k_float32, sizeof(__pyx_k_float32), 0, 0, 1, 1},
  {&__pyx_n_s_fvec, __pyx_k_fvec, sizeof(__pyx_k_fvec), 0, 0, 1, 1},
  {&__pyx_n_s_fvec0, __pyx_k_fvec0, sizeof(__pyx_k_fvec0), 0, 0, 1, 1},
  {&__pyx_n_s_fvec1, __pyx_k_fvec1, sizeof(__pyx_k_fvec1), 0, 0, 1, 1},
  {&__pyx_n_s_fvec2, __pyx_k_fvec2, sizeof(__pyx_k_fvec2), 0, 0, 1, 1},
  {&__pyx_n_s_fvec3, __pyx_k_fvec3, sizeof(__pyx_k_fvec3), 0, 0, 1, 1},
  {&__pyx_n_s_fvec4, __pyx_k_fvec4, sizeof(__pyx_k_fvec4), 0, 0, 1, 1},
  {&__pyx_n_s_h, __pyx_k_h, sizeof(__pyx_k_h), 0, 0, 1, 1},
  {&__pyx_n_s_hid, __pyx_k_hid, sizeof(__pyx_k_hid), 0, 0, 1, 1},
  {&__pyx_n_s_hidden, __pyx_k_hidden, sizeof(__pyx_k_hidden), 0, 0, 1, 1},
  {&__pyx_n_s_hit, __pyx_k_hit, sizeof(__pyx_k_hit), 0, 0, 1, 1},
  {&__pyx_n_s_hitMp, __pyx_k_hitMp, sizeof(__pyx_k_hitMp), 0, 0, 1, 1},
  {&__pyx_n_s_hit_arr, __pyx_k_hit_arr, sizeof(__pyx_k_hit_arr), 0, 0, 1, 1},
  {&__pyx_n_s_hit_no, __pyx_k_hit_no, sizeof(__pyx_k_hit_no), 0, 0, 1, 1},
  {&__pyx_n_s_hit_ptr, __pyx_k_hit_ptr, sizeof(__pyx_k_hit_ptr), 0, 0, 1, 1},
  {&__pyx_n_s_hits, __pyx_k_hits, sizeof(__pyx_k_hits), 0, 0, 1, 1},
  {&__pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_k_home_yoh_deb_gits_pkg_exppsy_di, sizeof(__pyx_k_home_yoh_deb_gits_pkg_exppsy_di), 0, 0, 1, 0},
  {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
  {&__pyx_n_s_i_k, __pyx_k_i_k, sizeof(__pyx_k_i_k), 0, 0, 1, 1},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_n_s_indices, __pyx_k_indices, sizeof(__pyx_k_indices), 0, 0, 1, 1},
  {&__pyx_n_s_inf, __pyx_k_inf, sizeof(__pyx_k_inf), 0, 0, 1, 1},
  {&__pyx_n_s_inner_3vecs, __pyx_k_inner_3vecs, sizeof(__pyx_k_inner_3vecs), 0, 0, 1, 1},
  {&__pyx_n_s_int64, __pyx_k_int64, sizeof(__pyx_k_int64), 0, 0, 1, 1},
  {&__pyx_n_s_intersect_segment_cylinder, __pyx_k_intersect_segment_cylinder, sizeof(__pyx_k_intersect_segment_cylinder), 0, 0, 1, 1},
  {&__pyx_kp_u_intersect_segment_cylinder_line, __pyx_k_intersect_segment_cylinder_line, sizeof(__pyx_k_intersect_segment_cylinder_line), 0, 1, 0, 0},
  {&__pyx_n_s_intersects, __pyx_k_intersects, sizeof(__pyx_k_intersects), 0, 0, 1, 1},
  {&__pyx_n_s_it, __pyx_k_it, sizeof(__pyx_k_it), 0, 0, 1, 1},
  {&__pyx_n_s_itrange, __pyx_k_itrange, sizeof(__pyx_k_itrange), 0, 0, 1, 1},
  {&__pyx_n_s_j, __pyx_k_j, sizeof(__pyx_k_j), 0, 0, 1, 1},
  {&__pyx_n_s_k, __pyx_k_k, sizeof(__pyx_k_k), 0, 0, 1, 1},
  {&__pyx_n_s_keys, __pyx_k_keys, sizeof(__pyx_k_keys), 0, 0, 1, 1},
  {&__pyx_n_s_klen, __pyx_k_klen, sizeof(__pyx_k_klen), 0, 0, 1, 1},
  {&__pyx_n_s_krange, __pyx_k_krange, sizeof(__pyx_k_krange), 0, 0, 1, 1},
  {&__pyx_n_s_larch_3merge, __pyx_k_larch_3merge, sizeof(__pyx_k_larch_3merge), 0, 0, 1, 1},
  {&__pyx_n_s_larch_3split, __pyx_k_larch_3split, sizeof(__pyx_k_larch_3split), 0, 0, 1, 1},
  {&__pyx_kp_u_larch_3split_line_1786, __pyx_k_larch_3split_line_1786, sizeof(__pyx_k_larch_3split_line_1786), 0, 1, 0, 0},
  {&__pyx_n_s_ld, __pyx_k_ld, sizeof(__pyx_k_ld), 0, 0, 1, 1},
  {&__pyx_n_s_lee_angle_distance, __pyx_k_lee_angle_distance, sizeof(__pyx_k_lee_angle_distance), 0, 0, 1, 1},
  {&__pyx_kp_u_lee_angle_distance_line_941, __pyx_k_lee_angle_distance_line_941, sizeof(__pyx_k_lee_angle_distance_line_941), 0, 1, 0, 0},
  {&__pyx_n_s_lee_perpendicular_distance, __pyx_k_lee_perpendicular_distance, sizeof(__pyx_k_lee_perpendicular_distance), 0, 0, 1, 1},
  {&__pyx_kp_u_lee_perpendicular_distance_line, __pyx_k_lee_perpendicular_distance_line, sizeof(__pyx_k_lee_perpendicular_distance_line), 0, 1, 0, 0},
  {&__pyx_n_s_lenC, __pyx_k_lenC, sizeof(__pyx_k_lenC), 0, 0, 1, 1},
  {&__pyx_n_s_length, __pyx_k_length, sizeof(__pyx_k_length), 0, 0, 1, 1},
  {&__pyx_n_s_lent, __pyx_k_lent, sizeof(__pyx_k_lent), 0, 0, 1, 1},
  {&__pyx_n_s_lentA, __pyx_k_lentA, sizeof(__pyx_k_lentA), 0, 0, 1, 1},
  {&__pyx_n_s_lentB, __pyx_k_lentB, sizeof(__pyx_k_lentB), 0, 0, 1, 1},
  {&__pyx_n_s_lhp, __pyx_k_lhp, sizeof(__pyx_k_lhp), 0, 0, 1, 1},
  {&__pyx_n_s_local_skeleton_clustering, __pyx_k_local_skeleton_clustering, sizeof(__pyx_k_local_skeleton_clustering), 0, 0, 1, 1},
  {&__pyx_n_s_local_skeleton_clustering_3pts, __pyx_k_local_skeleton_clustering_3pts, sizeof(__pyx_k_local_skeleton_clustering_3pts), 0, 0, 1, 1},
  {&__pyx_kp_u_local_skeleton_clustering_3pts_l, __pyx_k_local_skeleton_clustering_3pts_l, sizeof(__pyx_k_local_skeleton_clustering_3pts_l), 0, 1, 0, 0},
  {&__pyx_kp_u_local_skeleton_clustering_line_1, __pyx_k_local_skeleton_clustering_line_1, sizeof(__pyx_k_local_skeleton_clustering_line_1), 0, 1, 0, 0},
  {&__pyx_n_s_longest_track_len, __pyx_k_longest_track_len, sizeof(__pyx_k_longest_track_len), 0, 0, 1, 1},
  {&__pyx_n_s_longest_track_lenA, __pyx_k_longest_track_lenA, sizeof(__pyx_k_longest_track_lenA), 0, 0, 1, 1},
  {&__pyx_n_s_longest_track_lenB, __pyx_k_longest_track_lenB, sizeof(__pyx_k_longest_track_lenB), 0, 0, 1, 1},
  {&__pyx_n_s_lrq, __pyx_k_lrq, sizeof(__pyx_k_lrq), 0, 0, 1, 1},
  {&__pyx_n_s_m_d, __pyx_k_m_d, sizeof(__pyx_k_m_d), 0, 0, 1, 1},
  {&__pyx_n_s_m_k, __pyx_k_m_k, sizeof(__pyx_k_m_k), 0, 0, 1, 1},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_n_s_mam_distances, __pyx_k_mam_distances, sizeof(__pyx_k_mam_distances), 0, 0, 1, 1},
  {&__pyx_n_s_max, __pyx_k_max, sizeof(__pyx_k_max), 0, 0, 1, 1},
  {&__pyx_n_s_max_hit_len, __pyx_k_max_hit_len, sizeof(__pyx_k_max_hit_len), 0, 0, 1, 1},
  {&__pyx_n_s_mean_t1t2, __pyx_k_mean_t1t2, sizeof(__pyx_k_mean_t1t2), 0, 0, 1, 1},
  {&__pyx_n_s_mean_t2t1, __pyx_k_mean_t2t1, sizeof(__pyx_k_mean_t2t1), 0, 0, 1, 1},
  {&__pyx_n_s_metric, __pyx_k_metric, sizeof(__pyx_k_metric), 0, 0, 1, 1},
  {&__pyx_n_s_metric_type, __pyx_k_metric_type, sizeof(__pyx_k_metric_type), 0, 0, 1, 1},
  {&__pyx_n_s_mid_index, __pyx_k_mid_index, sizeof(__pyx_k_mid_index), 0, 0, 1, 1},
  {&__pyx_n_s_min, __pyx_k_min, sizeof(__pyx_k_min), 0, 0, 1, 1},
  {&__pyx_n_s_min_buffer, __pyx_k_min_buffer, sizeof(__pyx_k_min_buffer), 0, 0, 1, 1},
  {&__pyx_n_s_min_min_t1t2, __pyx_k_min_min_t1t2, sizeof(__pyx_k_min_min_t1t2), 0, 0, 1, 1},
  {&__pyx_n_s_min_min_t2t1, __pyx_k_min_min_t2t1, sizeof(__pyx_k_min_min_t2t1), 0, 0, 1, 1},
  {&__pyx_n_s_min_t1t2, __pyx_k_min_t1t2, sizeof(__pyx_k_min_t1t2), 0, 0, 1, 1},
  {&__pyx_n_s_min_t2t1, __pyx_k_min_t2t1, sizeof(__pyx_k_min_t2t1), 0, 0, 1, 1},
  {&__pyx_n_s_minimum_closest_distance, __pyx_k_minimum_closest_distance, sizeof(__pyx_k_minimum_closest_distance), 0, 0, 1, 1},
  {&__pyx_n_s_mn, __pyx_k_mn, sizeof(__pyx_k_mn), 0, 0, 1, 1},
  {&__pyx_n_s_most_similar_track_mam, __pyx_k_most_similar_track_mam, sizeof(__pyx_k_most_similar_track_mam), 0, 0, 1, 1},
  {&__pyx_n_s_mul_3vec, __pyx_k_mul_3vec, sizeof(__pyx_k_mul_3vec), 0, 0, 1, 1},
  {&__pyx_n_s_mul_3vecs, __pyx_k_mul_3vecs, sizeof(__pyx_k_mul_3vecs), 0, 0, 1, 1},
  {&__pyx_n_s_n_hits, __pyx_k_n_hits, sizeof(__pyx_k_n_hits), 0, 0, 1, 1},
  {&__pyx_kp_u_ndarray_is_not_C_contiguous, __pyx_k_ndarray_is_not_C_contiguous, sizeof(__pyx_k_ndarray_is_not_C_contiguous), 0, 1, 0, 0},
  {&__pyx_kp_u_ndarray_is_not_Fortran_contiguou, __pyx_k_ndarray_is_not_Fortran_contiguou, sizeof(__pyx_k_ndarray_is_not_Fortran_contiguou), 0, 1, 0, 0},
  {&__pyx_n_s_next_ref_p, __pyx_k_next_ref_p, sizeof(__pyx_k_next_ref_p), 0, 0, 1, 1},
  {&__pyx_n_s_next_trk_p, __pyx_k_next_trk_p, sizeof(__pyx_k_next_trk_p), 0, 0, 1, 1},
  {&__pyx_n_s_norm_3vec, __pyx_k_norm_3vec, sizeof(__pyx_k_norm_3vec), 0, 0, 1, 1},
  {&__pyx_n_s_normal, __pyx_k_normal, sizeof(__pyx_k_normal), 0, 0, 1, 1},
  {&__pyx_n_s_normalized_3vec, __pyx_k_normalized_3vec, sizeof(__pyx_k_normalized_3vec), 0, 0, 1, 1},
  {&__pyx_n_s_np, __pyx_k_np, sizeof(__pyx_k_np), 0, 0, 1, 1},
  {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1},
  {&__pyx_n_s_object, __pyx_k_object, sizeof(__pyx_k_object), 0, 0, 1, 1},
  {&__pyx_n_s_one_hit, __pyx_k_one_hit, sizeof(__pyx_k_one_hit), 0, 0, 1, 1},
  {&__pyx_n_s_p, __pyx_k_p, sizeof(__pyx_k_p), 0, 0, 1, 1},
  {&__pyx_n_s_pMq, __pyx_k_pMq, sizeof(__pyx_k_pMq), 0, 0, 1, 1},
  {&__pyx_n_s_p_no, __pyx_k_p_no, sizeof(__pyx_k_p_no), 0, 0, 1, 1},
  {&__pyx_n_s_point, __pyx_k_point, sizeof(__pyx_k_point), 0, 0, 1, 1},
  {&__pyx_n_s_point_segment_sq_distance, __pyx_k_point_segment_sq_distance, sizeof(__pyx_k_point_segment_sq_distance), 0, 0, 1, 1},
  {&__pyx_kp_u_point_segment_sq_distance_line_1, __pyx_k_point_segment_sq_distance_line_1, sizeof(__pyx_k_point_segment_sq_distance_line_1), 0, 1, 0, 0},
  {&__pyx_n_s_point_track_sq_distance_check, __pyx_k_point_track_sq_distance_check, sizeof(__pyx_k_point_track_sq_distance_check), 0, 0, 1, 1},
  {&__pyx_kp_u_point_track_sq_distance_check_li, __pyx_k_point_track_sq_distance_check_li, sizeof(__pyx_k_point_track_sq_distance_check_li), 0, 1, 0, 0},
  {&__pyx_n_s_points, __pyx_k_points, sizeof(__pyx_k_points), 0, 0, 1, 1},
  {&__pyx_n_s_ptr, __pyx_k_ptr, sizeof(__pyx_k_ptr), 0, 0, 1, 1},
  {&__pyx_n_s_q, __pyx_k_q, sizeof(__pyx_k_q), 0, 0, 1, 1},
  {&__pyx_n_s_qMp, __pyx_k_qMp, sizeof(__pyx_k_qMp), 0, 0, 1, 1},
  {&__pyx_n_s_q_no, __pyx_k_q_no, sizeof(__pyx_k_q_no), 0, 0, 1, 1},
  {&__pyx_n_s_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 0, 1, 1},
  {&__pyx_n_s_rMp, __pyx_k_rMp, sizeof(__pyx_k_rMp), 0, 0, 1, 1},
  {&__pyx_n_s_rMq, __pyx_k_rMq, sizeof(__pyx_k_rMq), 0, 0, 1, 1},
  {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
  {&__pyx_n_s_rcd, __pyx_k_rcd, sizeof(__pyx_k_rcd), 0, 0, 1, 1},
  {&__pyx_n_s_ref, __pyx_k_ref, sizeof(__pyx_k_ref), 0, 0, 1, 1},
  {&__pyx_n_s_ref32, __pyx_k_ref32, sizeof(__pyx_k_ref32), 0, 0, 1, 1},
  {&__pyx_n_s_rep3, __pyx_k_rep3, sizeof(__pyx_k_rep3), 0, 0, 1, 1},
  {&__pyx_n_s_rlen, __pyx_k_rlen, sizeof(__pyx_k_rlen), 0, 0, 1, 1},
  {&__pyx_n_s_roi, __pyx_k_roi, sizeof(__pyx_k_roi), 0, 0, 1, 1},
  {&__pyx_n_s_rows, __pyx_k_rows, sizeof(__pyx_k_rows), 0, 0, 1, 1},
  {&__pyx_n_s_sa, __pyx_k_sa, sizeof(__pyx_k_sa), 0, 0, 1, 1},
  {&__pyx_n_s_sb, __pyx_k_sb, sizeof(__pyx_k_sb), 0, 0, 1, 1},
  {&__pyx_n_s_shape, __pyx_k_shape, sizeof(__pyx_k_shape), 0, 0, 1, 1},
  {&__pyx_n_s_si, __pyx_k_si, sizeof(__pyx_k_si), 0, 0, 1, 1},
  {&__pyx_n_s_sq_dist_thr, __pyx_k_sq_dist_thr, sizeof(__pyx_k_sq_dist_thr), 0, 0, 1, 1},
  {&__pyx_n_s_squeeze, __pyx_k_squeeze, sizeof(__pyx_k_squeeze), 0, 0, 1, 1},
  {&__pyx_n_s_start0, __pyx_k_start0, sizeof(__pyx_k_start0), 0, 0, 1, 1},
  {&__pyx_n_s_start1, __pyx_k_start1, sizeof(__pyx_k_start1), 0, 0, 1, 1},
  {&__pyx_n_s_start_index, __pyx_k_start_index, sizeof(__pyx_k_start_index), 0, 0, 1, 1},
  {&__pyx_n_s_sub_3vecs, __pyx_k_sub_3vecs, sizeof(__pyx_k_sub_3vecs), 0, 0, 1, 1},
  {&__pyx_n_s_sum_track2others, __pyx_k_sum_track2others, sizeof(__pyx_k_sum_track2others), 0, 0, 1, 1},
  {&__pyx_n_s_t, __pyx_k_t, sizeof(__pyx_k_t), 0, 0, 1, 1},
  {&__pyx_n_s_t1, __pyx_k_t1, sizeof(__pyx_k_t1), 0, 0, 1, 1},
  {&__pyx_n_s_t1_len, __pyx_k_t1_len, sizeof(__pyx_k_t1_len), 0, 0, 1, 1},
  {&__pyx_n_s_t1_pi, __pyx_k_t1_pi, sizeof(__pyx_k_t1_pi), 0, 0, 1, 1},
  {&__pyx_n_s_t1_ptr, __pyx_k_t1_ptr, sizeof(__pyx_k_t1_ptr), 0, 0, 1, 1},
  {&__pyx_n_s_t2, __pyx_k_t2, sizeof(__pyx_k_t2), 0, 0, 1, 1},
  {&__pyx_n_s_t2_len, __pyx_k_t2_len, sizeof(__pyx_k_t2_len), 0, 0, 1, 1},
  {&__pyx_n_s_t2_pi, __pyx_k_t2_pi, sizeof(__pyx_k_t2_pi), 0, 0, 1, 1},
  {&__pyx_n_s_t2_ptr, __pyx_k_t2_ptr, sizeof(__pyx_k_t2_ptr), 0, 0, 1, 1},
  {&__pyx_n_s_t_len, __pyx_k_t_len, sizeof(__pyx_k_t_len), 0, 0, 1, 1},
  {&__pyx_n_s_t_no, __pyx_k_t_no, sizeof(__pyx_k_t_no), 0, 0, 1, 1},
  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  {&__pyx_n_s_this_ref_p, __pyx_k_this_ref_p, sizeof(__pyx_k_this_ref_p), 0, 0, 1, 1},
  {&__pyx_n_s_this_trk_p, __pyx_k_this_trk_p, sizeof(__pyx_k_this_trk_p), 0, 0, 1, 1},
  {&__pyx_n_s_thr, __pyx_k_thr, sizeof(__pyx_k_thr), 0, 0, 1, 1},
  {&__pyx_n_s_time, __pyx_k_time, sizeof(__pyx_k_time), 0, 0, 1, 1},
  {&__pyx_n_s_tlen, __pyx_k_tlen, sizeof(__pyx_k_tlen), 0, 0, 1, 1},
  {&__pyx_n_s_tmp, __pyx_k_tmp, sizeof(__pyx_k_tmp), 0, 0, 1, 1},
  {&__pyx_n_s_track, __pyx_k_track, sizeof(__pyx_k_track), 0, 0, 1, 1},
  {&__pyx_n_s_track1, __pyx_k_track1, sizeof(__pyx_k_track1), 0, 0, 1, 1},
  {&__pyx_n_s_track2, __pyx_k_track2, sizeof(__pyx_k_track2), 0, 0, 1, 1},
  {&__pyx_n_s_track2others, __pyx_k_track2others, sizeof(__pyx_k_track2others), 0, 0, 1, 1},
  {&__pyx_n_s_track_dist_3pts, __pyx_k_track_dist_3pts, sizeof(__pyx_k_track_dist_3pts), 0, 0, 1, 1},
  {&__pyx_kp_u_track_dist_3pts_line_1324, __pyx_k_track_dist_3pts_line_1324, sizeof(__pyx_k_track_dist_3pts_line_1324), 0, 1, 0, 0},
  {&__pyx_n_s_track_len, __pyx_k_track_len, sizeof(__pyx_k_track_len), 0, 0, 1, 1},
  {&__pyx_n_s_track_lengths, __pyx_k_track_lengths, sizeof(__pyx_k_track_lengths), 0, 0, 1, 1},
  {&__pyx_n_s_track_roi_intersection_check, __pyx_k_track_roi_intersection_check, sizeof(__pyx_k_track_roi_intersection_check), 0, 0, 1, 1},
  {&__pyx_kp_u_track_roi_intersection_check_lin, __pyx_k_track_roi_intersection_check_lin, sizeof(__pyx_k_track_roi_intersection_check_lin), 0, 1, 0, 0},
  {&__pyx_n_s_tracka, __pyx_k_tracka, sizeof(__pyx_k_tracka), 0, 0, 1, 1},
  {&__pyx_n_s_trackb, __pyx_k_trackb, sizeof(__pyx_k_trackb), 0, 0, 1, 1},
  {&__pyx_n_s_tracks, __pyx_k_tracks, sizeof(__pyx_k_tracks), 0, 0, 1, 1},
  {&__pyx_n_s_tracks32, __pyx_k_tracks32, sizeof(__pyx_k_tracks32), 0, 0, 1, 1},
  {&__pyx_n_s_tracksA, __pyx_k_tracksA, sizeof(__pyx_k_tracksA), 0, 0, 1, 1},
  {&__pyx_n_s_tracksA32, __pyx_k_tracksA32, sizeof(__pyx_k_tracksA32), 0, 0, 1, 1},
  {&__pyx_n_s_tracksB, __pyx_k_tracksB, sizeof(__pyx_k_tracksB), 0, 0, 1, 1},
  {&__pyx_n_s_tracksB32, __pyx_k_tracksB32, sizeof(__pyx_k_tracksB32), 0, 0, 1, 1},
  {&__pyx_n_s_ts, __pyx_k_ts, sizeof(__pyx_k_ts), 0, 0, 1, 1},
  {&__pyx_n_s_uint64, __pyx_k_uint64, sizeof(__pyx_k_uint64), 0, 0, 1, 1},
  {&__pyx_kp_u_unknown_dtype_code_in_numpy_pxd, __pyx_k_unknown_dtype_code_in_numpy_pxd, sizeof(__pyx_k_unknown_dtype_code_in_numpy_pxd), 0, 1, 0, 0},
  {&__pyx_n_s_vec, __pyx_k_vec, sizeof(__pyx_k_vec), 0, 0, 1, 1},
  {&__pyx_n_s_vec0, __pyx_k_vec0, sizeof(__pyx_k_vec0), 0, 0, 1, 1},
  {&__pyx_n_s_vec1, __pyx_k_vec1, sizeof(__pyx_k_vec1), 0, 0, 1, 1},
  {&__pyx_n_s_vec2, __pyx_k_vec2, sizeof(__pyx_k_vec2), 0, 0, 1, 1},
  {&__pyx_n_s_vec_in, __pyx_k_vec_in, sizeof(__pyx_k_vec_in), 0, 0, 1, 1},
  {&__pyx_n_s_vec_out, __pyx_k_vec_out, sizeof(__pyx_k_vec_out), 0, 0, 1, 1},
  {&__pyx_n_s_xyz, __pyx_k_xyz, sizeof(__pyx_k_xyz), 0, 0, 1, 1},
  {&__pyx_n_s_xyz1, __pyx_k_xyz1, sizeof(__pyx_k_xyz1), 0, 0, 1, 1},
  {&__pyx_n_s_xyz2, __pyx_k_xyz2, sizeof(__pyx_k_xyz2), 0, 0, 1, 1},
  {&__pyx_n_s_zeros, __pyx_k_zeros, sizeof(__pyx_k_zeros), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_object = __Pyx_GetBuiltinName(__pyx_n_s_object); if (!__pyx_builtin_object) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 406; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_builtin_RuntimeError = __Pyx_GetBuiltinName(__pyx_n_s_RuntimeError); if (!__pyx_builtin_RuntimeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "dipy/tracking/distances.pyx":63
 *     '''
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_in = as_float_3vec(vec)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)             # <<<<<<<<<<<<<<
 *     cnormalized_3vec(<float *>vec_in.data, <float*>vec_out.data)
 *     return vec_out
 */
  __pyx_tuple_ = PyTuple_Pack(1, __pyx_int_3); if (unlikely(!__pyx_tuple_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);

  /* "dipy/tracking/distances.pyx":138
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)             # <<<<<<<<<<<<<<
 *     csub_3vecs(<float *>fvec1.data, <float*>fvec2.data, <float *>vec_out.data)
 *     return vec_out
 */
  __pyx_tuple__2 = PyTuple_Pack(1, __pyx_int_3); if (unlikely(!__pyx_tuple__2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__2);
  __Pyx_GIVEREF(__pyx_tuple__2);

  /* "dipy/tracking/distances.pyx":152
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)             # <<<<<<<<<<<<<<
 *     cadd_3vecs(<float *>fvec1.data, <float*>fvec2.data, <float *>vec_out.data)
 *     return vec_out
 */
  __pyx_tuple__3 = PyTuple_Pack(1, __pyx_int_3); if (unlikely(!__pyx_tuple__3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__3);
  __Pyx_GIVEREF(__pyx_tuple__3);

  /* "dipy/tracking/distances.pyx":165
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)             # <<<<<<<<<<<<<<
 *     cmul_3vecs(<float *>fvec1.data, <float*>fvec2.data, <float *>vec_out.data)
 *     return vec_out
 */
  __pyx_tuple__4 = PyTuple_Pack(1, __pyx_int_3); if (unlikely(!__pyx_tuple__4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__4);
  __Pyx_GIVEREF(__pyx_tuple__4);

  /* "dipy/tracking/distances.pyx":176
 * def mul_3vec(a, vec):
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec = as_float_3vec(vec)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)             # <<<<<<<<<<<<<<
 *     cmul_3vec(a,<float *>fvec.data, <float *>vec_out.data)
 *     return vec_out
 */
  __pyx_tuple__5 = PyTuple_Pack(1, __pyx_int_3); if (unlikely(!__pyx_tuple__5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 176; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__5);
  __Pyx_GIVEREF(__pyx_tuple__5);

  /* "dipy/tracking/distances.pyx":326
 *                             # hit data into array
 *                             if hit_no >= max_hit_len:
 *                                 one_hit = np.empty((5,), dtype=f32_dt)             # <<<<<<<<<<<<<<
 *                                 hits.append(one_hit)
 *                             else:
 */
  __pyx_tuple__6 = PyTuple_Pack(1, __pyx_int_5); if (unlikely(!__pyx_tuple__6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__6);
  __Pyx_GIVEREF(__pyx_tuple__6);
  __pyx_tuple__7 = PyTuple_Pack(1, __pyx_tuple__6); if (unlikely(!__pyx_tuple__7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__7);
  __Pyx_GIVEREF(__pyx_tuple__7);

  /* "dipy/tracking/distances.pyx":346
 *         Hit.append(hit_arr)
 *         #Div.append(divs[1:])
 *     return Hit[1:]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_slice__8 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 346; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__8);
  __Pyx_GIVEREF(__pyx_slice__8);

  /* "dipy/tracking/distances.pyx":400
 *         metric_type = 2
 *     else:
 *         raise ValueError('Metric should be one of avg, min, max')             # <<<<<<<<<<<<<<
 *     # preprocess tracks
 *     cdef:
 */
  __pyx_tuple__9 = PyTuple_Pack(1, __pyx_kp_s_Metric_should_be_one_of_avg_min); if (unlikely(!__pyx_tuple__9)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 400; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__9);
  __Pyx_GIVEREF(__pyx_tuple__9);

  /* "dipy/tracking/distances.pyx":490
 *         metric_type = 2
 *     else:
 *         raise ValueError('Metric should be one of avg, min, max')             # <<<<<<<<<<<<<<
 *     # preprocess tracks
 *     cdef:
 */
  __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s_Metric_should_be_one_of_avg_min); if (unlikely(!__pyx_tuple__10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 490; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__10);
  __Pyx_GIVEREF(__pyx_tuple__10);

  /* "dipy/tracking/distances.pyx":777
 *         return np.max((mean_t2t1,mean_t1t2))
 *     else :
 *         ValueError('Wrong argument for metric')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_s_Wrong_argument_for_metric); if (unlikely(!__pyx_tuple__11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__11);
  __Pyx_GIVEREF(__pyx_tuple__11);

  /* "dipy/tracking/distances.pyx":1709
 *     #Network C
 *     C={0:{'indices':[0],'hidden':tracks[0].copy(),'N':1}}
 *     ts=np.zeros((3,3),dtype=np.float32)             # <<<<<<<<<<<<<<
 * 
 *     #for (it,t) in enumerate(tracks[1:]):
 */
  __pyx_tuple__12 = PyTuple_Pack(2, __pyx_int_3, __pyx_int_3); if (unlikely(!__pyx_tuple__12)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);
  __pyx_tuple__13 = PyTuple_Pack(1, __pyx_tuple__12); if (unlikely(!__pyx_tuple__13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1709; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__13);
  __Pyx_GIVEREF(__pyx_tuple__13);

  /* "dipy/tracking/distances.pyx":1852
 *     else:
 *         C={0:{'indices':[indices[0]],'rep3':tracks[indices[0]].copy(),'N':1}}
 *         itrange=indices[1:]             # <<<<<<<<<<<<<<
 * 
 *     ts=np.zeros((3,3),dtype=np.float32)
 */
  __pyx_slice__14 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1852; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_slice__14);
  __Pyx_GIVEREF(__pyx_slice__14);

  /* "dipy/tracking/distances.pyx":1854
 *         itrange=indices[1:]
 * 
 *     ts=np.zeros((3,3),dtype=np.float32)             # <<<<<<<<<<<<<<
 *     for it in itrange:
 *         track=np.ascontiguousarray(tracks[it],dtype=f32_dt)
 */
  __pyx_tuple__15 = PyTuple_Pack(2, __pyx_int_3, __pyx_int_3); if (unlikely(!__pyx_tuple__15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__15);
  __Pyx_GIVEREF(__pyx_tuple__15);
  __pyx_tuple__16 = PyTuple_Pack(1, __pyx_tuple__15); if (unlikely(!__pyx_tuple__16)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1854; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__16);
  __Pyx_GIVEREF(__pyx_tuple__16);

  /* "dipy/tracking/distances.pyx":1910
 *     '''
 * 
 *     cdef cnp.ndarray[cnp.float32_t, ndim=2] h=np.zeros((3,3),dtype=np.float32)             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=2] ch=np.zeros((3,3),dtype=np.float32)
 *     cdef int lenC,k,c
 */
  __pyx_tuple__17 = PyTuple_Pack(2, __pyx_int_3, __pyx_int_3); if (unlikely(!__pyx_tuple__17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1910; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__17);
  __Pyx_GIVEREF(__pyx_tuple__17);
  __pyx_tuple__18 = PyTuple_Pack(1, __pyx_tuple__17); if (unlikely(!__pyx_tuple__18)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1910; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__18);
  __Pyx_GIVEREF(__pyx_tuple__18);

  /* "dipy/tracking/distances.pyx":1911
 * 
 *     cdef cnp.ndarray[cnp.float32_t, ndim=2] h=np.zeros((3,3),dtype=np.float32)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=2] ch=np.zeros((3,3),dtype=np.float32)             # <<<<<<<<<<<<<<
 *     cdef int lenC,k,c
 *     cdef float d[2]
 */
  __pyx_tuple__19 = PyTuple_Pack(2, __pyx_int_3, __pyx_int_3); if (unlikely(!__pyx_tuple__19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__19);
  __Pyx_GIVEREF(__pyx_tuple__19);
  __pyx_tuple__20 = PyTuple_Pack(1, __pyx_tuple__19); if (unlikely(!__pyx_tuple__20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1911; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__20);
  __Pyx_GIVEREF(__pyx_tuple__20);

  /* "dipy/tracking/distances.pyx":1915
 *     cdef float d[2]
 * 
 *     ts=np.zeros((3,3),dtype=np.float32)             # <<<<<<<<<<<<<<
 * 
 *     lenC=len(C)
 */
  __pyx_tuple__21 = PyTuple_Pack(2, __pyx_int_3, __pyx_int_3); if (unlikely(!__pyx_tuple__21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1915; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__21);
  __Pyx_GIVEREF(__pyx_tuple__21);
  __pyx_tuple__22 = PyTuple_Pack(1, __pyx_tuple__21); if (unlikely(!__pyx_tuple__22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1915; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__22);
  __Pyx_GIVEREF(__pyx_tuple__22);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":218
 *             if ((flags & pybuf.PyBUF_C_CONTIGUOUS == pybuf.PyBUF_C_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not C contiguous")             # <<<<<<<<<<<<<<
 * 
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 */
  __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_u_ndarray_is_not_C_contiguous); if (unlikely(!__pyx_tuple__23)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__23);
  __Pyx_GIVEREF(__pyx_tuple__23);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":222
 *             if ((flags & pybuf.PyBUF_F_CONTIGUOUS == pybuf.PyBUF_F_CONTIGUOUS)
 *                 and not PyArray_CHKFLAGS(self, NPY_F_CONTIGUOUS)):
 *                 raise ValueError(u"ndarray is not Fortran contiguous")             # <<<<<<<<<<<<<<
 * 
 *             info.buf = PyArray_DATA(self)
 */
  __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_u_ndarray_is_not_Fortran_contiguou); if (unlikely(!__pyx_tuple__24)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__24);
  __Pyx_GIVEREF(__pyx_tuple__24);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":259
 *                 if ((descr.byteorder == c'>' and little_endian) or
 *                     (descr.byteorder == c'<' and not little_endian)):
 *                     raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *                 if   t == NPY_BYTE:        f = "b"
 *                 elif t == NPY_UBYTE:       f = "B"
 */
  __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_u_Non_native_byte_order_not_suppor); if (unlikely(!__pyx_tuple__25)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 259; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__25);
  __Pyx_GIVEREF(__pyx_tuple__25);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":799
 * 
 *         if (end - f) - <int>(new_offset - offset[0]) < 15:
 *             raise RuntimeError(u"Format string allocated too short, see comment in numpy.pxd")             # <<<<<<<<<<<<<<
 * 
 *         if ((child.byteorder == c'>' and little_endian) or
 */
  __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_u_Format_string_allocated_too_shor); if (unlikely(!__pyx_tuple__26)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 799; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__26);
  __Pyx_GIVEREF(__pyx_tuple__26);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":803
 *         if ((child.byteorder == c'>' and little_endian) or
 *             (child.byteorder == c'<' and not little_endian)):
 *             raise ValueError(u"Non-native byte order not supported")             # <<<<<<<<<<<<<<
 *             # One could encode it in the format string and have Cython
 *             # complain instead, BUT: < and > in format strings also imply
 */
  __pyx_tuple__27 = PyTuple_Pack(1, __pyx_kp_u_Non_native_byte_order_not_suppor); if (unlikely(!__pyx_tuple__27)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 803; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__27);
  __Pyx_GIVEREF(__pyx_tuple__27);

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":823
 *             t = child.type_num
 *             if end - f < 5:
 *                 raise RuntimeError(u"Format string allocated too short.")             # <<<<<<<<<<<<<<
 * 
 *             # Until ticket #99 is fixed, use integers to avoid warnings
 */
  __pyx_tuple__28 = PyTuple_Pack(1, __pyx_kp_u_Format_string_allocated_too_shor_2); if (unlikely(!__pyx_tuple__28)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 823; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__28);
  __Pyx_GIVEREF(__pyx_tuple__28);

  /* "dipy/tracking/distances.pyx":49
 * 
 * 
 * def normalized_3vec(vec):             # <<<<<<<<<<<<<<
 *     ''' Return normalized 3D vector
 * 
 */
  __pyx_tuple__29 = PyTuple_Pack(3, __pyx_n_s_vec, __pyx_n_s_vec_in, __pyx_n_s_vec_out); if (unlikely(!__pyx_tuple__29)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__29);
  __Pyx_GIVEREF(__pyx_tuple__29);
  __pyx_codeobj__30 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__29, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_normalized_3vec, 49, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__30)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":68
 * 
 * 
 * def norm_3vec(vec):             # <<<<<<<<<<<<<<
 *     ''' Euclidean (L2) norm of length 3 vector
 * 
 */
  __pyx_tuple__31 = PyTuple_Pack(2, __pyx_n_s_vec, __pyx_n_s_vec_in); if (unlikely(!__pyx_tuple__31)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__31);
  __Pyx_GIVEREF(__pyx_tuple__31);
  __pyx_codeobj__32 = (PyObject*)__Pyx_PyCode_New(1, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__31, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_norm_3vec, 68, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__32)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":121
 * 
 * 
 * def inner_3vecs(vec1, vec2):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 */
  __pyx_tuple__33 = PyTuple_Pack(4, __pyx_n_s_vec1, __pyx_n_s_vec2, __pyx_n_s_fvec1, __pyx_n_s_fvec2); if (unlikely(!__pyx_tuple__33)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__33);
  __Pyx_GIVEREF(__pyx_tuple__33);
  __pyx_codeobj__34 = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__33, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_inner_3vecs, 121, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__34)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":135
 * 
 * 
 * def sub_3vecs(vec1, vec2):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 */
  __pyx_tuple__35 = PyTuple_Pack(5, __pyx_n_s_vec1, __pyx_n_s_vec2, __pyx_n_s_fvec1, __pyx_n_s_fvec2, __pyx_n_s_vec_out); if (unlikely(!__pyx_tuple__35)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__35);
  __Pyx_GIVEREF(__pyx_tuple__35);
  __pyx_codeobj__36 = (PyObject*)__Pyx_PyCode_New(2, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__35, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_sub_3vecs, 135, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__36)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":149
 * 
 * 
 * def add_3vecs(vec1, vec2):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 */
  __pyx_tuple__37 = PyTuple_Pack(5, __pyx_n_s_vec1, __pyx_n_s_vec2, __pyx_n_s_fvec1, __pyx_n_s_fvec2, __pyx_n_s_vec_out); if (unlikely(!__pyx_tuple__37)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__37);
  __Pyx_GIVEREF(__pyx_tuple__37);
  __pyx_codeobj__38 = (PyObject*)__Pyx_PyCode_New(2, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__37, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_add_3vecs, 149, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__38)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":162
 *         vec_out[i] = vec1[i]+vec2[i]
 * 
 * def mul_3vecs(vec1, vec2):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 */
  __pyx_tuple__39 = PyTuple_Pack(5, __pyx_n_s_vec1, __pyx_n_s_vec2, __pyx_n_s_fvec1, __pyx_n_s_fvec2, __pyx_n_s_vec_out); if (unlikely(!__pyx_tuple__39)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__39);
  __Pyx_GIVEREF(__pyx_tuple__39);
  __pyx_codeobj__40 = (PyObject*)__Pyx_PyCode_New(2, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__39, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_mul_3vecs, 162, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__40)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":174
 *         vec_out[i] = vec1[i]*vec2[i]
 * 
 * def mul_3vec(a, vec):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec = as_float_3vec(vec)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 */
  __pyx_tuple__41 = PyTuple_Pack(4, __pyx_n_s_a, __pyx_n_s_vec, __pyx_n_s_fvec, __pyx_n_s_vec_out); if (unlikely(!__pyx_tuple__41)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__41);
  __Pyx_GIVEREF(__pyx_tuple__41);
  __pyx_codeobj__42 = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__41, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_mul_3vec, 174, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__42)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":190
 * 
 * 
 * def cut_plane(tracks, ref):             # <<<<<<<<<<<<<<
 *     ''' Extract divergence vectors and points of intersection
 *     between planes normal to the reference fiber and other tracks
 */
  __pyx_tuple__43 = PyTuple_Pack(39, __pyx_n_s_tracks, __pyx_n_s_ref, __pyx_n_s_n_hits, __pyx_n_s_hit_no, __pyx_n_s_max_hit_len, __pyx_n_s_alpha, __pyx_n_s_beta, __pyx_n_s_lrq, __pyx_n_s_rcd, __pyx_n_s_lhp, __pyx_n_s_ld, __pyx_n_s_ref32, __pyx_n_s_track, __pyx_n_s_hits, __pyx_n_s_one_hit, __pyx_n_s_hit_ptr, __pyx_n_s_hit_arr, __pyx_n_s_Hit, __pyx_n_s_N_tracks, __pyx_n_s_track_lengths, __pyx_n_s_t_no, __pyx_n_s_N_track, __pyx_n_s_tracks32, __pyx_n_s_N_ref, __pyx_n_s_p_no, __pyx_n_s_q_no, __pyx_n_s_this_ref_p, __pyx_n_s_next_ref_p, __pyx_n_s_this_trk_p, __pyx_n_s_next_trk_p, __pyx_n_s_along, __pyx_n_s_normal, __pyx_n_s_qMp, __pyx_n_s_rMp, __pyx_n_s_rMq, __pyx_n_s_pMq, __pyx_n_s_hit, __pyx_n_s_hitMp, __pyx_n_s_delta); if (unlikely(!__pyx_tuple__43)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__43);
  __Pyx_GIVEREF(__pyx_tuple__43);
  __pyx_codeobj__44 = (PyObject*)__Pyx_PyCode_New(2, 0, 39, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__43, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_cut_plane, 190, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__44)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":352
 * 
 * 
 * def most_similar_track_mam(tracks,metric='avg'):             # <<<<<<<<<<<<<<
 *     ''' Find the most similar track in a bundle
 *     using distances calculated from Zhang et. al 2008.
 */
  __pyx_tuple__45 = PyTuple_Pack(22, __pyx_n_s_tracks, __pyx_n_s_metric, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_lent, __pyx_n_s_metric_type, __pyx_n_s_longest_track_len, __pyx_n_s_track_len, __pyx_n_s_tracks32, __pyx_n_s_track2others, __pyx_n_s_sum_track2others, __pyx_n_s_distances_buffer, __pyx_n_s_t1_ptr, __pyx_n_s_t2_ptr, __pyx_n_s_min_buffer, __pyx_n_s_distance, __pyx_n_s_t1, __pyx_n_s_t2, __pyx_n_s_t1_len, __pyx_n_s_t2_len, __pyx_n_s_mn, __pyx_n_s_si); if (unlikely(!__pyx_tuple__45)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__45);
  __Pyx_GIVEREF(__pyx_tuple__45);
  __pyx_codeobj__46 = (PyObject*)__Pyx_PyCode_New(2, 0, 22, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__45, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_most_similar_track_mam, 352, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__46)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":462
 * @cython.boundscheck(False)
 * @cython.wraparound(False)
 * def bundles_distances_mam(tracksA, tracksB, metric='avg'):             # <<<<<<<<<<<<<<
 *     ''' Calculate distances between list of tracks A and list of tracks B
 * 
 */
  __pyx_tuple__47 = PyTuple_Pack(23, __pyx_n_s_tracksA, __pyx_n_s_tracksB, __pyx_n_s_metric, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_lentA, __pyx_n_s_lentB, __pyx_n_s_metric_type, __pyx_n_s_longest_track_len, __pyx_n_s_track_len, __pyx_n_s_longest_track_lenA, __pyx_n_s_longest_track_lenB, __pyx_n_s_tracksA32, __pyx_n_s_tracksB32, __pyx_n_s_DM, __pyx_n_s_distances_buffer, __pyx_n_s_t1_ptr, __pyx_n_s_t2_ptr, __pyx_n_s_min_buffer, __pyx_n_s_t1, __pyx_n_s_t2, __pyx_n_s_t1_len, __pyx_n_s_t2_len); if (unlikely(!__pyx_tuple__47)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__47);
  __Pyx_GIVEREF(__pyx_tuple__47);
  __pyx_codeobj__48 = (PyObject*)__Pyx_PyCode_New(3, 0, 23, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__47, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_bundles_distances_mam, 462, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__48)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":541
 * @cython.boundscheck(False)
 * @cython.wraparound(False)
 * def bundles_distances_mdf(tracksA, tracksB):             # <<<<<<<<<<<<<<
 *     ''' Calculate distances between list of tracks A and list of tracks B
 * 
 */
  __pyx_tuple__49 = PyTuple_Pack(22, __pyx_n_s_tracksA, __pyx_n_s_tracksB, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_lentA, __pyx_n_s_lentB, __pyx_n_s_longest_track_len, __pyx_n_s_track_len, __pyx_n_s_longest_track_lenA, __pyx_n_s_longest_track_lenB, __pyx_n_s_tracksA32, __pyx_n_s_tracksB32, __pyx_n_s_DM, __pyx_n_s_t1_ptr, __pyx_n_s_t2_ptr, __pyx_n_s_min_buffer, __pyx_n_s_t1, __pyx_n_s_t2, __pyx_n_s_t1_len, __pyx_n_s_t2_len, __pyx_n_s_d, __pyx_n_s_t_len); if (unlikely(!__pyx_tuple__49)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 541; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__49);
  __Pyx_GIVEREF(__pyx_tuple__49);
  __pyx_codeobj__50 = (PyObject*)__Pyx_PyCode_New(2, 0, 22, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__49, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_bundles_distances_mdf, 541, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__50)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 541; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":694
 * 
 * 
 * def mam_distances(xyz1,xyz2,metric='all'):             # <<<<<<<<<<<<<<
 *     ''' Min/Max/Mean Average Minimum Distance between tracks xyz1 and xyz2
 * 
 */
  __pyx_tuple__51 = PyTuple_Pack(14, __pyx_n_s_xyz1, __pyx_n_s_xyz2, __pyx_n_s_metric, __pyx_n_s_track1, __pyx_n_s_track2, __pyx_n_s_t1_len, __pyx_n_s_t2_len, __pyx_n_s_min_t2t1, __pyx_n_s_min_t1t2, __pyx_n_s_distances_buffer, __pyx_n_s_t1_pi, __pyx_n_s_t2_pi, __pyx_n_s_mean_t2t1, __pyx_n_s_mean_t1t2); if (unlikely(!__pyx_tuple__51)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__51);
  __Pyx_GIVEREF(__pyx_tuple__51);
  __pyx_codeobj__52 = (PyObject*)__Pyx_PyCode_New(3, 0, 14, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__51, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_mam_distances, 694, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__52)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":780
 * 
 * 
 * def minimum_closest_distance(xyz1,xyz2):             # <<<<<<<<<<<<<<
 *     ''' Find the minimum distance between two curves xyz1, xyz2
 * 
 */
  __pyx_tuple__53 = PyTuple_Pack(13, __pyx_n_s_xyz1, __pyx_n_s_xyz2, __pyx_n_s_track1, __pyx_n_s_track2, __pyx_n_s_t1_len, __pyx_n_s_t2_len, __pyx_n_s_min_t2t1, __pyx_n_s_min_t1t2, __pyx_n_s_distances_buffer, __pyx_n_s_t1_pi, __pyx_n_s_t2_pi, __pyx_n_s_min_min_t2t1, __pyx_n_s_min_min_t1t2); if (unlikely(!__pyx_tuple__53)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 780; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__53);
  __Pyx_GIVEREF(__pyx_tuple__53);
  __pyx_codeobj__54 = (PyObject*)__Pyx_PyCode_New(2, 0, 13, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__53, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_minimum_closest_distance, 780, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__54)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 780; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":838
 * 
 * 
 * def lee_perpendicular_distance(start0, end0, start1, end1):             # <<<<<<<<<<<<<<
 *     ''' Calculates perpendicular distance metric for the distance between two line segments
 * 
 */
  __pyx_tuple__55 = PyTuple_Pack(8, __pyx_n_s_start0, __pyx_n_s_end0, __pyx_n_s_start1, __pyx_n_s_end1, __pyx_n_s_fvec1, __pyx_n_s_fvec2, __pyx_n_s_fvec3, __pyx_n_s_fvec4); if (unlikely(!__pyx_tuple__55)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__55);
  __Pyx_GIVEREF(__pyx_tuple__55);
  __pyx_codeobj__56 = (PyObject*)__Pyx_PyCode_New(4, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__55, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_lee_perpendicular_distance, 838, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__56)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":941
 * 
 * 
 * def lee_angle_distance(start0, end0, start1, end1):             # <<<<<<<<<<<<<<
 *     ''' Calculates angle distance metric for the distance between two line segments
 * 
 */
  __pyx_tuple__57 = PyTuple_Pack(8, __pyx_n_s_start0, __pyx_n_s_end0, __pyx_n_s_start1, __pyx_n_s_end1, __pyx_n_s_fvec1, __pyx_n_s_fvec2, __pyx_n_s_fvec3, __pyx_n_s_fvec4); if (unlikely(!__pyx_tuple__57)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__57);
  __Pyx_GIVEREF(__pyx_tuple__57);
  __pyx_codeobj__58 = (PyObject*)__Pyx_PyCode_New(4, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__57, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_lee_angle_distance, 941, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__58)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":1007
 * 
 * 
 * def approx_polygon_track(xyz,alpha=0.392):             # <<<<<<<<<<<<<<
 *     ''' Fast and simple trajectory approximation algorithm by Eleftherios and Ian
 * 
 */
  __pyx_tuple__59 = PyTuple_Pack(13, __pyx_n_s_xyz, __pyx_n_s_alpha, __pyx_n_s_mid_index, __pyx_n_s_track, __pyx_n_s_fvec0, __pyx_n_s_fvec1, __pyx_n_s_fvec2, __pyx_n_s_characteristic_points, __pyx_n_s_t_len, __pyx_n_s_angle, __pyx_n_s_tmp, __pyx_n_s_vec0, __pyx_n_s_vec1); if (unlikely(!__pyx_tuple__59)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__59);
  __Pyx_GIVEREF(__pyx_tuple__59);
  __pyx_codeobj__60 = (PyObject*)__Pyx_PyCode_New(2, 0, 13, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__59, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_approx_polygon_track, 1007, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__60)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":1091
 * 
 * 
 * def approximate_mdl_trajectory(xyz, alpha=1.):             # <<<<<<<<<<<<<<
 *     ''' Implementation of Lee et al Approximate Trajectory
 *     Partitioning Algorithm
 */
  __pyx_tuple__61 = PyTuple_Pack(17, __pyx_n_s_xyz, __pyx_n_s_alpha, __pyx_n_s_start_index, __pyx_n_s_length, __pyx_n_s_current_index, __pyx_n_s_i, __pyx_n_s_cost_par, __pyx_n_s_cost_nopar, __pyx_n_s_alphac, __pyx_n_s_characteristic_points, __pyx_n_s_t_len, __pyx_n_s_track, __pyx_n_s_tmp, __pyx_n_s_fvec1, __pyx_n_s_fvec2, __pyx_n_s_fvec3, __pyx_n_s_fvec4); if (unlikely(!__pyx_tuple__61)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1091; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__61);
  __Pyx_GIVEREF(__pyx_tuple__61);
  __pyx_codeobj__62 = (PyObject*)__Pyx_PyCode_New(2, 0, 17, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__61, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_approximate_mdl_trajectory, 1091, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__62)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1091; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":1158
 * 
 * 
 * def intersect_segment_cylinder(sa,sb,p,q,r):             # <<<<<<<<<<<<<<
 *     ''' Intersect Segment S(t) = sa +t(sb-sa), 0 <=t<= 1 against cylinder specified by p,q and r
 * 
 */
  __pyx_tuple__63 = PyTuple_Pack(12, __pyx_n_s_sa, __pyx_n_s_sb, __pyx_n_s_p, __pyx_n_s_q, __pyx_n_s_r, __pyx_n_s_csa, __pyx_n_s_csb, __pyx_n_s_cp, __pyx_n_s_cq, __pyx_n_s_cr, __pyx_n_s_ct, __pyx_n_s_tmp); if (unlikely(!__pyx_tuple__63)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__63);
  __Pyx_GIVEREF(__pyx_tuple__63);
  __pyx_codeobj__64 = (PyObject*)__Pyx_PyCode_New(5, 0, 12, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__63, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_intersect_segment_cylinder, 1158, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__64)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":1271
 * 
 * 
 * def point_segment_sq_distance(a, b, c):             # <<<<<<<<<<<<<<
 *     ''' Calculate the squared distance from a point c to a finite line segment ab.
 * 
 */
  __pyx_tuple__65 = PyTuple_Pack(8, __pyx_n_s_a, __pyx_n_s_b, __pyx_n_s_c, __pyx_n_s_ca, __pyx_n_s_cb, __pyx_n_s_cc, __pyx_n_s_cr, __pyx_n_s_ct); if (unlikely(!__pyx_tuple__65)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__65);
  __Pyx_GIVEREF(__pyx_tuple__65);
  __pyx_codeobj__66 = (PyObject*)__Pyx_PyCode_New(3, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__65, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_point_segment_sq_distance, 1271, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__66)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":1324
 * 
 * 
 * def track_dist_3pts(tracka,trackb):             # <<<<<<<<<<<<<<
 *     ''' Calculate the euclidean distance between two 3pt tracks
 * 
 */
  __pyx_tuple__67 = PyTuple_Pack(5, __pyx_n_s_tracka, __pyx_n_s_trackb, __pyx_n_s_a, __pyx_n_s_b, __pyx_n_s_d); if (unlikely(!__pyx_tuple__67)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__67);
  __Pyx_GIVEREF(__pyx_tuple__67);
  __pyx_codeobj__68 = (PyObject*)__Pyx_PyCode_New(2, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__67, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_track_dist_3pts, 1324, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__68)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":1471
 * @cython.wraparound(False)
 * @cython.cdivision(True)
 * def local_skeleton_clustering(tracks, d_thr=10):             # <<<<<<<<<<<<<<
 *     r"""Efficient tractography clustering
 * 
 */
  __pyx_tuple__69 = PyTuple_Pack(24, __pyx_n_s_tracks, __pyx_n_s_d_thr, __pyx_n_s_track, __pyx_n_s_cluster, __pyx_n_s_lent, __pyx_n_s_lenC, __pyx_n_s_dim, __pyx_n_s_points, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_c, __pyx_n_s_i_k, __pyx_n_s_rows, __pyx_n_s_cit, __pyx_n_s_ptr, __pyx_n_s_hid, __pyx_n_s_alld, __pyx_n_s_d, __pyx_n_s_m_d, __pyx_n_s_cd_thr, __pyx_n_s_flip, __pyx_n_s_it, __pyx_n_s_k, __pyx_n_s_C); if (unlikely(!__pyx_tuple__69)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__69);
  __Pyx_GIVEREF(__pyx_tuple__69);
  __pyx_codeobj__70 = (PyObject*)__Pyx_PyCode_New(2, 0, 24, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__69, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_local_skeleton_clustering, 1471, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__70)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":1656
 *     return C
 * 
 * def local_skeleton_clustering_3pts(tracks, d_thr=10):             # <<<<<<<<<<<<<<
 *     ''' Does a first pass clustering
 * 
 */
  __pyx_tuple__71 = PyTuple_Pack(15, __pyx_n_s_tracks, __pyx_n_s_d_thr, __pyx_n_s_track, __pyx_n_s_h, __pyx_n_s_lent, __pyx_n_s_k, __pyx_n_s_it, __pyx_n_s_d, __pyx_n_s_C, __pyx_n_s_ts, __pyx_n_s_lenC, __pyx_n_s_alld, __pyx_n_s_flip, __pyx_n_s_m_k, __pyx_n_s_i_k); if (unlikely(!__pyx_tuple__71)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__71);
  __Pyx_GIVEREF(__pyx_tuple__71);
  __pyx_codeobj__72 = (PyObject*)__Pyx_PyCode_New(2, 0, 15, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__71, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_local_skeleton_clustering_3pts, 1656, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__72)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":1786
 * 
 * 
 * def larch_3split(tracks, indices=None, thr=10.):             # <<<<<<<<<<<<<<
 *     '''Generate a first pass clustering using 3 points on the tracks only.
 * 
 */
  __pyx_tuple__73 = PyTuple_Pack(17, __pyx_n_s_tracks, __pyx_n_s_indices, __pyx_n_s_thr, __pyx_n_s_track, __pyx_n_s_h, __pyx_n_s_lent, __pyx_n_s_k, __pyx_n_s_it, __pyx_n_s_d, __pyx_n_s_C, __pyx_n_s_itrange, __pyx_n_s_ts, __pyx_n_s_lenC, __pyx_n_s_alld, __pyx_n_s_flip, __pyx_n_s_m_k, __pyx_n_s_i_k); if (unlikely(!__pyx_tuple__73)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1786; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__73);
  __Pyx_GIVEREF(__pyx_tuple__73);
  __pyx_codeobj__74 = (PyObject*)__Pyx_PyCode_New(3, 0, 17, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__73, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_larch_3split, 1786, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__74)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1786; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":1889
 * 
 * 
 * def larch_3merge(C,thr=10.):             # <<<<<<<<<<<<<<
 *     '''
 *     Reassign tracks to existing clusters by merging clusters that their
 */
  __pyx_tuple__75 = PyTuple_Pack(16, __pyx_n_s_C, __pyx_n_s_thr, __pyx_n_s_h, __pyx_n_s_ch, __pyx_n_s_lenC, __pyx_n_s_k, __pyx_n_s_c, __pyx_n_s_d, __pyx_n_s_ts, __pyx_n_s_C2, __pyx_n_s_krange, __pyx_n_s_klen, __pyx_n_s_alld, __pyx_n_s_flip, __pyx_n_s_m_k, __pyx_n_s_i_k); if (unlikely(!__pyx_tuple__75)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__75);
  __Pyx_GIVEREF(__pyx_tuple__75);
  __pyx_codeobj__76 = (PyObject*)__Pyx_PyCode_New(2, 0, 16, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__75, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_larch_3merge, 1889, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__76)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":1953
 * 
 * 
 * def point_track_sq_distance_check(cnp.ndarray[float,ndim=2] track,             # <<<<<<<<<<<<<<
 *                                   cnp.ndarray[float,ndim=1] point,
 *                                   double sq_dist_thr):
 */
  __pyx_tuple__77 = PyTuple_Pack(12, __pyx_n_s_track, __pyx_n_s_point, __pyx_n_s_sq_dist_thr, __pyx_n_s_t, __pyx_n_s_p, __pyx_n_s_a, __pyx_n_s_b, __pyx_n_s_tlen, __pyx_n_s_curr, __pyx_n_s_dist, __pyx_n_s_i, __pyx_n_s_intersects); if (unlikely(!__pyx_tuple__77)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__77);
  __Pyx_GIVEREF(__pyx_tuple__77);
  __pyx_codeobj__78 = (PyObject*)__Pyx_PyCode_New(3, 0, 12, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__77, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_point_track_sq_distance_check, 1953, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__78)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}

  /* "dipy/tracking/distances.pyx":2011
 *         return False
 * 
 * def track_roi_intersection_check(cnp.ndarray[float,ndim=2] track, cnp.ndarray[float,ndim=2] roi, double sq_dist_thr):             # <<<<<<<<<<<<<<
 *     ''' Check if a track is intersecting a region of interest
 * 
 */
  __pyx_tuple__79 = PyTuple_Pack(16, __pyx_n_s_track, __pyx_n_s_roi, __pyx_n_s_sq_dist_thr, __pyx_n_s_t, __pyx_n_s_r, __pyx_n_s_a, __pyx_n_s_b, __pyx_n_s_p, __pyx_n_s_tlen, __pyx_n_s_rlen, __pyx_n_s_curr, __pyx_n_s_currp, __pyx_n_s_dist, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_intersects); if (unlikely(!__pyx_tuple__79)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_tuple__79);
  __Pyx_GIVEREF(__pyx_tuple__79);
  __pyx_codeobj__80 = (PyObject*)__Pyx_PyCode_New(3, 0, 16, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__79, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_yoh_deb_gits_pkg_exppsy_di, __pyx_n_s_track_roi_intersection_check, 2011, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__80)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_InitGlobals(void) {
  __pyx_umethod_PyDict_Type_keys.type = (PyObject*)&PyDict_Type;
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  __pyx_float_1_ = PyFloat_FromDouble(1.); if (unlikely(!__pyx_float_1_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_float_10_ = PyFloat_FromDouble(10.); if (unlikely(!__pyx_float_10_)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_float_0_392 = PyFloat_FromDouble(0.392); if (unlikely(!__pyx_float_0_392)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_5 = PyInt_FromLong(5); if (unlikely(!__pyx_int_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_int_10 = PyInt_FromLong(10); if (unlikely(!__pyx_int_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initdistances(void); /*proto*/
PyMODINIT_FUNC initdistances(void)
#else
PyMODINIT_FUNC PyInit_distances(void); /*proto*/
PyMODINIT_FUNC PyInit_distances(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  __pyx_t_5numpy_float32_t __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  #if CYTHON_REFNANNY
  __Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny");
  if (!__Pyx_RefNanny) {
      PyErr_Clear();
      __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny");
      if (!__Pyx_RefNanny)
          Py_FatalError("failed to import 'refnanny' module");
  }
  #endif
  __Pyx_RefNannySetupContext("PyMODINIT_FUNC PyInit_distances(void)", 0);
  if (__Pyx_check_binary_version() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #ifdef __Pyx_CyFunction_USED
  if (__pyx_CyFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_Coroutine_USED
  if (__pyx_Coroutine_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  #ifdef __Pyx_StopAsyncIteration_USED
  if (__pyx_StopAsyncIteration_init() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  /*--- Library function declarations ---*/
  /*--- Threads initialization code ---*/
  #if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS
  #ifdef WITH_THREAD /* Python build with threading support? */
  PyEval_InitThreads();
  #endif
  #endif
  /*--- Module creation code ---*/
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4("distances", __pyx_methods, __pyx_k_Optimized_track_distances_simil, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if CYTHON_COMPILING_IN_PYPY
  Py_INCREF(__pyx_b);
  #endif
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;};
  /*--- Initialize various global constants etc. ---*/
  if (__Pyx_InitGlobals() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  if (__Pyx_init_sys_getdefaultencoding_params() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif
  if (__pyx_module_is_main_dipy__tracking__distances) {
    if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    if (!PyDict_GetItemString(modules, "dipy.tracking.distances")) {
      if (unlikely(PyDict_SetItemString(modules, "dipy.tracking.distances", __pyx_m) < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (__Pyx_InitCachedBuiltins() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Constants init code ---*/
  if (__Pyx_InitCachedConstants() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Global init code ---*/
  __pyx_v_4dipy_8tracking_9distances_f32_dt = ((PyArray_Descr *)Py_None); Py_INCREF(Py_None);
  /*--- Variable export code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  /*--- Type import code ---*/
  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", 
  #if CYTHON_COMPILING_IN_PYPY
  sizeof(PyTypeObject),
  #else
  sizeof(PyHeapTypeObject),
  #endif
  0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_dtype = __Pyx_ImportType("numpy", "dtype", sizeof(PyArray_Descr), 0); if (unlikely(!__pyx_ptype_5numpy_dtype)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 155; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_flatiter = __Pyx_ImportType("numpy", "flatiter", sizeof(PyArrayIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_flatiter)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 168; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_broadcast = __Pyx_ImportType("numpy", "broadcast", sizeof(PyArrayMultiIterObject), 0); if (unlikely(!__pyx_ptype_5numpy_broadcast)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_ndarray = __Pyx_ImportType("numpy", "ndarray", sizeof(PyArrayObject), 0); if (unlikely(!__pyx_ptype_5numpy_ndarray)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 181; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __pyx_ptype_5numpy_ufunc = __Pyx_ImportType("numpy", "ufunc", sizeof(PyUFuncObject), 0); if (unlikely(!__pyx_ptype_5numpy_ufunc)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 861; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  /*--- Variable import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/
  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  if (__Pyx_patch_abc() < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  #endif

  /* "dipy/tracking/distances.pyx":10
 * cimport cython
 * 
 * import time             # <<<<<<<<<<<<<<
 * import numpy as np
 * cimport numpy as cnp
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_time, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_time, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":11
 * 
 * import time
 * import numpy as np             # <<<<<<<<<<<<<<
 * cimport numpy as cnp
 * 
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":49
 * 
 * 
 * def normalized_3vec(vec):             # <<<<<<<<<<<<<<
 *     ''' Return normalized 3D vector
 * 
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_1normalized_3vec, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_normalized_3vec, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":68
 * 
 * 
 * def norm_3vec(vec):             # <<<<<<<<<<<<<<
 *     ''' Euclidean (L2) norm of length 3 vector
 * 
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_3norm_3vec, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_norm_3vec, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":121
 * 
 * 
 * def inner_3vecs(vec1, vec2):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_5inner_3vecs, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_inner_3vecs, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":135
 * 
 * 
 * def sub_3vecs(vec1, vec2):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_7sub_3vecs, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sub_3vecs, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 135; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":149
 * 
 * 
 * def add_3vecs(vec1, vec2):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_9add_3vecs, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_add_3vecs, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 149; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":162
 *         vec_out[i] = vec1[i]+vec2[i]
 * 
 * def mul_3vecs(vec1, vec2):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec1 = as_float_3vec(vec1)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec2 = as_float_3vec(vec2)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_11mul_3vecs, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_mul_3vecs, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 162; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":174
 *         vec_out[i] = vec1[i]*vec2[i]
 * 
 * def mul_3vec(a, vec):             # <<<<<<<<<<<<<<
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] fvec = as_float_3vec(vec)
 *     cdef cnp.ndarray[cnp.float32_t, ndim=1] vec_out = np.zeros((3,), np.float32)
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_13mul_3vec, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_mul_3vec, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 174; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":187
 * 
 * # float 32 dtype for casting
 * cdef cnp.dtype f32_dt = np.dtype(np.float32)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_dtype); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_float32); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_COMPILING_IN_CPYTHON && unlikely(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);
    }
  }
  if (!__pyx_t_2) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL;
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __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_dtype))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 187; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_XGOTREF(((PyObject *)__pyx_v_4dipy_8tracking_9distances_f32_dt));
  __Pyx_DECREF_SET(__pyx_v_4dipy_8tracking_9distances_f32_dt, ((PyArray_Descr *)__pyx_t_1));
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":190
 * 
 * 
 * def cut_plane(tracks, ref):             # <<<<<<<<<<<<<<
 *     ''' Extract divergence vectors and points of intersection
 *     between planes normal to the reference fiber and other tracks
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_15cut_plane, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_cut_plane, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 190; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":352
 * 
 * 
 * def most_similar_track_mam(tracks,metric='avg'):             # <<<<<<<<<<<<<<
 *     ''' Find the most similar track in a bundle
 *     using distances calculated from Zhang et. al 2008.
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_17most_similar_track_mam, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_most_similar_track_mam, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 352; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":462
 * @cython.boundscheck(False)
 * @cython.wraparound(False)
 * def bundles_distances_mam(tracksA, tracksB, metric='avg'):             # <<<<<<<<<<<<<<
 *     ''' Calculate distances between list of tracks A and list of tracks B
 * 
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_19bundles_distances_mam, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_bundles_distances_mam, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":541
 * @cython.boundscheck(False)
 * @cython.wraparound(False)
 * def bundles_distances_mdf(tracksA, tracksB):             # <<<<<<<<<<<<<<
 *     ''' Calculate distances between list of tracks A and list of tracks B
 * 
 */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_21bundles_distances_mdf, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 541; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_bundles_distances_mdf, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 541; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "dipy/tracking/distances.pyx":611
 * 
 * 
 * cdef cnp.float32_t inf = np.inf             # <<<<<<<<<<<<<<
 * 
 * @cython.cdivision(True)
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_inf); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __pyx_PyFloat_AsFloat(__pyx_t_3); if (unlikely((__pyx_t_6 == (npy_float32)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 611; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_4dipy_8tracking_9distances_inf = __pyx_t_6;

  /* "dipy/tracking/distances.pyx":694
 * 
 * 
 * def mam_distances(xyz1,xyz2,metric='all'):             # <<<<<<<<<<<<<<
 *     ''' Min/Max/Mean Average Minimum Distance between tracks xyz1 and xyz2
 * 
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_23mam_distances, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_mam_distances, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":780
 * 
 * 
 * def minimum_closest_distance(xyz1,xyz2):             # <<<<<<<<<<<<<<
 *     ''' Find the minimum distance between two curves xyz1, xyz2
 * 
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_25minimum_closest_distance, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 780; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_minimum_closest_distance, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 780; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":838
 * 
 * 
 * def lee_perpendicular_distance(start0, end0, start1, end1):             # <<<<<<<<<<<<<<
 *     ''' Calculates perpendicular distance metric for the distance between two line segments
 * 
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_27lee_perpendicular_distance, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_lee_perpendicular_distance, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":941
 * 
 * 
 * def lee_angle_distance(start0, end0, start1, end1):             # <<<<<<<<<<<<<<
 *     ''' Calculates angle distance metric for the distance between two line segments
 * 
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_29lee_angle_distance, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_lee_angle_distance, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 941; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":1007
 * 
 * 
 * def approx_polygon_track(xyz,alpha=0.392):             # <<<<<<<<<<<<<<
 *     ''' Fast and simple trajectory approximation algorithm by Eleftherios and Ian
 * 
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_31approx_polygon_track, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_approx_polygon_track, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1007; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":1091
 * 
 * 
 * def approximate_mdl_trajectory(xyz, alpha=1.):             # <<<<<<<<<<<<<<
 *     ''' Implementation of Lee et al Approximate Trajectory
 *     Partitioning Algorithm
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_33approximate_mdl_trajectory, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1091; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_approximate_mdl_trajectory, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1091; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":1158
 * 
 * 
 * def intersect_segment_cylinder(sa,sb,p,q,r):             # <<<<<<<<<<<<<<
 *     ''' Intersect Segment S(t) = sa +t(sb-sa), 0 <=t<= 1 against cylinder specified by p,q and r
 * 
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_35intersect_segment_cylinder, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_intersect_segment_cylinder, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1158; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":1271
 * 
 * 
 * def point_segment_sq_distance(a, b, c):             # <<<<<<<<<<<<<<
 *     ''' Calculate the squared distance from a point c to a finite line segment ab.
 * 
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_37point_segment_sq_distance, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_point_segment_sq_distance, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1271; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":1324
 * 
 * 
 * def track_dist_3pts(tracka,trackb):             # <<<<<<<<<<<<<<
 *     ''' Calculate the euclidean distance between two 3pt tracks
 * 
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_39track_dist_3pts, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_track_dist_3pts, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1324; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":1471
 * @cython.wraparound(False)
 * @cython.cdivision(True)
 * def local_skeleton_clustering(tracks, d_thr=10):             # <<<<<<<<<<<<<<
 *     r"""Efficient tractography clustering
 * 
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_41local_skeleton_clustering, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_local_skeleton_clustering, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1471; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":1656
 *     return C
 * 
 * def local_skeleton_clustering_3pts(tracks, d_thr=10):             # <<<<<<<<<<<<<<
 *     ''' Does a first pass clustering
 * 
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_43local_skeleton_clustering_3pts, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_local_skeleton_clustering_3pts, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1656; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":1786
 * 
 * 
 * def larch_3split(tracks, indices=None, thr=10.):             # <<<<<<<<<<<<<<
 *     '''Generate a first pass clustering using 3 points on the tracks only.
 * 
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_45larch_3split, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1786; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_larch_3split, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1786; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":1889
 * 
 * 
 * def larch_3merge(C,thr=10.):             # <<<<<<<<<<<<<<
 *     '''
 *     Reassign tracks to existing clusters by merging clusters that their
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_47larch_3merge, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_larch_3merge, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1889; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":1953
 * 
 * 
 * def point_track_sq_distance_check(cnp.ndarray[float,ndim=2] track,             # <<<<<<<<<<<<<<
 *                                   cnp.ndarray[float,ndim=1] point,
 *                                   double sq_dist_thr):
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_49point_track_sq_distance_check, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_point_track_sq_distance_check, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1953; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":2011
 *         return False
 * 
 * def track_roi_intersection_check(cnp.ndarray[float,ndim=2] track, cnp.ndarray[float,ndim=2] roi, double sq_dist_thr):             # <<<<<<<<<<<<<<
 *     ''' Check if a track is intersecting a region of interest
 * 
 */
  __pyx_t_3 = PyCFunction_NewEx(&__pyx_mdef_4dipy_8tracking_9distances_51track_roi_intersection_check, NULL, __pyx_n_s_dipy_tracking_distances); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_track_roi_intersection_check, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2011; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "dipy/tracking/distances.pyx":2
 *  # A type of -*- python -*- file
 * """ Optimized track distances, similarities and distanch clustering algorithms             # <<<<<<<<<<<<<<
 * """
 * 
 */
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_kp_u_cut_plane_line_190, __pyx_kp_u_Extract_divergence_vectors_and) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_kp_u_lee_perpendicular_distance_line, __pyx_kp_u_Calculates_perpendicular_distan) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_kp_u_lee_angle_distance_line_941, __pyx_kp_u_Calculates_angle_distance_metri) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_kp_u_approx_polygon_track_line_1007, __pyx_kp_u_Fast_and_simple_trajectory_appr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_kp_u_intersect_segment_cylinder_line, __pyx_kp_u_Intersect_Segment_S_t_sa_t_sb_s) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_kp_u_point_segment_sq_distance_line_1, __pyx_kp_u_Calculate_the_squared_distance) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_kp_u_track_dist_3pts_line_1324, __pyx_kp_u_Calculate_the_euclidean_distanc) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_kp_u_local_skeleton_clustering_line_1, __pyx_kp_u_Efficient_tractography_clusterin) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_kp_u_local_skeleton_clustering_3pts_l, __pyx_kp_u_Does_a_first_pass_clustering_Ev) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_kp_u_larch_3split_line_1786, __pyx_kp_u_Generate_a_first_pass_clustering) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_kp_u_point_track_sq_distance_check_li, __pyx_kp_u_Check_if_square_distance_of_tra) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_t_3, __pyx_kp_u_track_roi_intersection_check_lin, __pyx_kp_u_Check_if_a_track_is_intersectin) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 2; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "../../../../../../usr/lib/python2.7/dist-packages/Cython/Includes/numpy/__init__.pxd":976
 *      arr.base = baseptr
 * 
 * cdef inline object get_array_base(ndarray arr):             # <<<<<<<<<<<<<<
 *     if arr.base is NULL:
 *         return None
 */

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __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);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init dipy.tracking.distances", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init dipy.tracking.distances");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* --- Runtime support code --- */
#if CYTHON_REFNANNY
static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) {
    PyObject *m = NULL, *p = NULL;
    void *r = NULL;
    m = PyImport_ImportModule((char *)modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, (char *)"RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif

static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
    PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
    if (unlikely(!result)) {
        PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
            "name '%U' is not defined", name);
#else
            "name '%.200s' is not defined", PyString_AS_STRING(name));
#endif
    }
    return result;
}

static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
    PyObject *result;
#if CYTHON_COMPILING_IN_CPYTHON
    result = PyDict_GetItem(__pyx_d, name);
    if (likely(result)) {
        Py_INCREF(result);
    } else {
#else
    result = PyObject_GetItem(__pyx_d, name);
    if (!result) {
        PyErr_Clear();
#endif
        result = __Pyx_GetBuiltinName(name);
    }
    return result;
}

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = func->ob_type->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = (*call)(func, arg, kw);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
    PyObject *self, *result;
    PyCFunction cfunc;
    cfunc = PyCFunction_GET_FUNCTION(func);
    self = PyCFunction_GET_SELF(func);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = cfunc(self, arg);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_New(1);
    if (unlikely(!args)) return NULL;
    Py_INCREF(arg);
    PyTuple_SET_ITEM(args, 0, arg);
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
    if (likely(PyCFunction_Check(func))) {
#endif
        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
            return __Pyx_PyObject_CallMethO(func, arg);
        }
    }
    return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject* args = PyTuple_Pack(1, arg);
    return (likely(args)) ? __Pyx_PyObject_Call(func, args, NULL) : NULL;
}
#endif

static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(PyObject_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

static CYTHON_INLINE int __Pyx_IsLittleEndian(void) {
  unsigned int n = 1;
  return *(unsigned char*)(&n) != 0;
}
static void __Pyx_BufFmt_Init(__Pyx_BufFmt_Context* ctx,
                              __Pyx_BufFmt_StackElem* stack,
                              __Pyx_TypeInfo* type) {
  stack[0].field = &ctx->root;
  stack[0].parent_offset = 0;
  ctx->root.type = type;
  ctx->root.name = "buffer dtype";
  ctx->root.offset = 0;
  ctx->head = stack;
  ctx->head->field = &ctx->root;
  ctx->fmt_offset = 0;
  ctx->head->parent_offset = 0;
  ctx->new_packmode = '@';
  ctx->enc_packmode = '@';
  ctx->new_count = 1;
  ctx->enc_count = 0;
  ctx->enc_type = 0;
  ctx->is_complex = 0;
  ctx->is_valid_array = 0;
  ctx->struct_alignment = 0;
  while (type->typegroup == 'S') {
    ++ctx->head;
    ctx->head->field = type->fields;
    ctx->head->parent_offset = 0;
    type = type->fields->type;
  }
}
static int __Pyx_BufFmt_ParseNumber(const char** ts) {
    int count;
    const char* t = *ts;
    if (*t < '0' || *t > '9') {
      return -1;
    } else {
        count = *t++ - '0';
        while (*t >= '0' && *t < '9') {
            count *= 10;
            count += *t++ - '0';
        }
    }
    *ts = t;
    return count;
}
static int __Pyx_BufFmt_ExpectNumber(const char **ts) {
    int number = __Pyx_BufFmt_ParseNumber(ts);
    if (number == -1)
        PyErr_Format(PyExc_ValueError,\
                     "Does not understand character buffer dtype format string ('%c')", **ts);
    return number;
}
static void __Pyx_BufFmt_RaiseUnexpectedChar(char ch) {
  PyErr_Format(PyExc_ValueError,
               "Unexpected format string character: '%c'", ch);
}
static const char* __Pyx_BufFmt_DescribeTypeChar(char ch, int is_complex) {
  switch (ch) {
    case 'c': return "'char'";
    case 'b': return "'signed char'";
    case 'B': return "'unsigned char'";
    case 'h': return "'short'";
    case 'H': return "'unsigned short'";
    case 'i': return "'int'";
    case 'I': return "'unsigned int'";
    case 'l': return "'long'";
    case 'L': return "'unsigned long'";
    case 'q': return "'long long'";
    case 'Q': return "'unsigned long long'";
    case 'f': return (is_complex ? "'complex float'" : "'float'");
    case 'd': return (is_complex ? "'complex double'" : "'double'");
    case 'g': return (is_complex ? "'complex long double'" : "'long double'");
    case 'T': return "a struct";
    case 'O': return "Python object";
    case 'P': return "a pointer";
    case 's': case 'p': return "a string";
    case 0: return "end";
    default: return "unparseable format string";
  }
}
static size_t __Pyx_BufFmt_TypeCharToStandardSize(char ch, int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return 2;
    case 'i': case 'I': case 'l': case 'L': return 4;
    case 'q': case 'Q': return 8;
    case 'f': return (is_complex ? 8 : 4);
    case 'd': return (is_complex ? 16 : 8);
    case 'g': {
      PyErr_SetString(PyExc_ValueError, "Python does not define a standard format string size for long double ('g')..");
      return 0;
    }
    case 'O': case 'P': return sizeof(void*);
    default:
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
}
static size_t __Pyx_BufFmt_TypeCharToNativeSize(char ch, int is_complex) {
  switch (ch) {
    case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return sizeof(short);
    case 'i': case 'I': return sizeof(int);
    case 'l': case 'L': return sizeof(long);
    #ifdef HAVE_LONG_LONG
    case 'q': case 'Q': return sizeof(PY_LONG_LONG);
    #endif
    case 'f': return sizeof(float) * (is_complex ? 2 : 1);
    case 'd': return sizeof(double) * (is_complex ? 2 : 1);
    case 'g': return sizeof(long double) * (is_complex ? 2 : 1);
    case 'O': case 'P': return sizeof(void*);
    default: {
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
  }
}
typedef struct { char c; short x; } __Pyx_st_short;
typedef struct { char c; int x; } __Pyx_st_int;
typedef struct { char c; long x; } __Pyx_st_long;
typedef struct { char c; float x; } __Pyx_st_float;
typedef struct { char c; double x; } __Pyx_st_double;
typedef struct { char c; long double x; } __Pyx_st_longdouble;
typedef struct { char c; void *x; } __Pyx_st_void_p;
#ifdef HAVE_LONG_LONG
typedef struct { char c; PY_LONG_LONG x; } __Pyx_st_longlong;
#endif
static size_t __Pyx_BufFmt_TypeCharToAlignment(char ch, CYTHON_UNUSED int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return sizeof(__Pyx_st_short) - sizeof(short);
    case 'i': case 'I': return sizeof(__Pyx_st_int) - sizeof(int);
    case 'l': case 'L': return sizeof(__Pyx_st_long) - sizeof(long);
#ifdef HAVE_LONG_LONG
    case 'q': case 'Q': return sizeof(__Pyx_st_longlong) - sizeof(PY_LONG_LONG);
#endif
    case 'f': return sizeof(__Pyx_st_float) - sizeof(float);
    case 'd': return sizeof(__Pyx_st_double) - sizeof(double);
    case 'g': return sizeof(__Pyx_st_longdouble) - sizeof(long double);
    case 'P': case 'O': return sizeof(__Pyx_st_void_p) - sizeof(void*);
    default:
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
}
/* These are for computing the padding at the end of the struct to align
   on the first member of the struct. This will probably the same as above,
   but we don't have any guarantees.
 */
typedef struct { short x; char c; } __Pyx_pad_short;
typedef struct { int x; char c; } __Pyx_pad_int;
typedef struct { long x; char c; } __Pyx_pad_long;
typedef struct { float x; char c; } __Pyx_pad_float;
typedef struct { double x; char c; } __Pyx_pad_double;
typedef struct { long double x; char c; } __Pyx_pad_longdouble;
typedef struct { void *x; char c; } __Pyx_pad_void_p;
#ifdef HAVE_LONG_LONG
typedef struct { PY_LONG_LONG x; char c; } __Pyx_pad_longlong;
#endif
static size_t __Pyx_BufFmt_TypeCharToPadding(char ch, CYTHON_UNUSED int is_complex) {
  switch (ch) {
    case '?': case 'c': case 'b': case 'B': case 's': case 'p': return 1;
    case 'h': case 'H': return sizeof(__Pyx_pad_short) - sizeof(short);
    case 'i': case 'I': return sizeof(__Pyx_pad_int) - sizeof(int);
    case 'l': case 'L': return sizeof(__Pyx_pad_long) - sizeof(long);
#ifdef HAVE_LONG_LONG
    case 'q': case 'Q': return sizeof(__Pyx_pad_longlong) - sizeof(PY_LONG_LONG);
#endif
    case 'f': return sizeof(__Pyx_pad_float) - sizeof(float);
    case 'd': return sizeof(__Pyx_pad_double) - sizeof(double);
    case 'g': return sizeof(__Pyx_pad_longdouble) - sizeof(long double);
    case 'P': case 'O': return sizeof(__Pyx_pad_void_p) - sizeof(void*);
    default:
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
}
static char __Pyx_BufFmt_TypeCharToGroup(char ch, int is_complex) {
  switch (ch) {
    case 'c':
        return 'H';
    case 'b': case 'h': case 'i':
    case 'l': case 'q': case 's': case 'p':
        return 'I';
    case 'B': case 'H': case 'I': case 'L': case 'Q':
        return 'U';
    case 'f': case 'd': case 'g':
        return (is_complex ? 'C' : 'R');
    case 'O':
        return 'O';
    case 'P':
        return 'P';
    default: {
      __Pyx_BufFmt_RaiseUnexpectedChar(ch);
      return 0;
    }
  }
}
static void __Pyx_BufFmt_RaiseExpected(__Pyx_BufFmt_Context* ctx) {
  if (ctx->head == NULL || ctx->head->field == &ctx->root) {
    const char* expected;
    const char* quote;
    if (ctx->head == NULL) {
      expected = "end";
      quote = "";
    } else {
      expected = ctx->head->field->type->name;
      quote = "'";
    }
    PyErr_Format(PyExc_ValueError,
                 "Buffer dtype mismatch, expected %s%s%s but got %s",
                 quote, expected, quote,
                 __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex));
  } else {
    __Pyx_StructField* field = ctx->head->field;
    __Pyx_StructField* parent = (ctx->head - 1)->field;
    PyErr_Format(PyExc_ValueError,
                 "Buffer dtype mismatch, expected '%s' but got %s in '%s.%s'",
                 field->type->name, __Pyx_BufFmt_DescribeTypeChar(ctx->enc_type, ctx->is_complex),
                 parent->type->name, field->name);
  }
}
static int __Pyx_BufFmt_ProcessTypeChunk(__Pyx_BufFmt_Context* ctx) {
  char group;
  size_t size, offset, arraysize = 1;
  if (ctx->enc_type == 0) return 0;
  if (ctx->head->field->type->arraysize[0]) {
    int i, ndim = 0;
    if (ctx->enc_type == 's' || ctx->enc_type == 'p') {
        ctx->is_valid_array = ctx->head->field->type->ndim == 1;
        ndim = 1;
        if (ctx->enc_count != ctx->head->field->type->arraysize[0]) {
            PyErr_Format(PyExc_ValueError,
                         "Expected a dimension of size %zu, got %zu",
                         ctx->head->field->type->arraysize[0], ctx->enc_count);
            return -1;
        }
    }
    if (!ctx->is_valid_array) {
      PyErr_Format(PyExc_ValueError, "Expected %d dimensions, got %d",
                   ctx->head->field->type->ndim, ndim);
      return -1;
    }
    for (i = 0; i < ctx->head->field->type->ndim; i++) {
      arraysize *= ctx->head->field->type->arraysize[i];
    }
    ctx->is_valid_array = 0;
    ctx->enc_count = 1;
  }
  group = __Pyx_BufFmt_TypeCharToGroup(ctx->enc_type, ctx->is_complex);
  do {
    __Pyx_StructField* field = ctx->head->field;
    __Pyx_TypeInfo* type = field->type;
    if (ctx->enc_packmode == '@' || ctx->enc_packmode == '^') {
      size = __Pyx_BufFmt_TypeCharToNativeSize(ctx->enc_type, ctx->is_complex);
    } else {
      size = __Pyx_BufFmt_TypeCharToStandardSize(ctx->enc_type, ctx->is_complex);
    }
    if (ctx->enc_packmode == '@') {
      size_t align_at = __Pyx_BufFmt_TypeCharToAlignment(ctx->enc_type, ctx->is_complex);
      size_t align_mod_offset;
      if (align_at == 0) return -1;
      align_mod_offset = ctx->fmt_offset % align_at;
      if (align_mod_offset > 0) ctx->fmt_offset += align_at - align_mod_offset;
      if (ctx->struct_alignment == 0)
          ctx->struct_alignment = __Pyx_BufFmt_TypeCharToPadding(ctx->enc_type,
                                                                 ctx->is_complex);
    }
    if (type->size != size || type->typegroup != group) {
      if (type->typegroup == 'C' && type->fields != NULL) {
        size_t parent_offset = ctx->head->parent_offset + field->offset;
        ++ctx->head;
        ctx->head->field = type->fields;
        ctx->head->parent_offset = parent_offset;
        continue;
      }
      if ((type->typegroup == 'H' || group == 'H') && type->size == size) {
      } else {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return -1;
      }
    }
    offset = ctx->head->parent_offset + field->offset;
    if (ctx->fmt_offset != offset) {
      PyErr_Format(PyExc_ValueError,
                   "Buffer dtype mismatch; next field is at offset %" CYTHON_FORMAT_SSIZE_T "d but %" CYTHON_FORMAT_SSIZE_T "d expected",
                   (Py_ssize_t)ctx->fmt_offset, (Py_ssize_t)offset);
      return -1;
    }
    ctx->fmt_offset += size;
    if (arraysize)
      ctx->fmt_offset += (arraysize - 1) * size;
    --ctx->enc_count;
    while (1) {
      if (field == &ctx->root) {
        ctx->head = NULL;
        if (ctx->enc_count != 0) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return -1;
        }
        break;
      }
      ctx->head->field = ++field;
      if (field->type == NULL) {
        --ctx->head;
        field = ctx->head->field;
        continue;
      } else if (field->type->typegroup == 'S') {
        size_t parent_offset = ctx->head->parent_offset + field->offset;
        if (field->type->fields->type == NULL) continue;
        field = field->type->fields;
        ++ctx->head;
        ctx->head->field = field;
        ctx->head->parent_offset = parent_offset;
        break;
      } else {
        break;
      }
    }
  } while (ctx->enc_count);
  ctx->enc_type = 0;
  ctx->is_complex = 0;
  return 0;
}
static CYTHON_INLINE PyObject *
__pyx_buffmt_parse_array(__Pyx_BufFmt_Context* ctx, const char** tsp)
{
    const char *ts = *tsp;
    int i = 0, number;
    int ndim = ctx->head->field->type->ndim;
;
    ++ts;
    if (ctx->new_count != 1) {
        PyErr_SetString(PyExc_ValueError,
                        "Cannot handle repeated arrays in format string");
        return NULL;
    }
    if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
    while (*ts && *ts != ')') {
        switch (*ts) {
            case ' ': case '\f': case '\r': case '\n': case '\t': case '\v':  continue;
            default:  break;
        }
        number = __Pyx_BufFmt_ExpectNumber(&ts);
        if (number == -1) return NULL;
        if (i < ndim && (size_t) number != ctx->head->field->type->arraysize[i])
            return PyErr_Format(PyExc_ValueError,
                        "Expected a dimension of size %zu, got %d",
                        ctx->head->field->type->arraysize[i], number);
        if (*ts != ',' && *ts != ')')
            return PyErr_Format(PyExc_ValueError,
                                "Expected a comma in format string, got '%c'", *ts);
        if (*ts == ',') ts++;
        i++;
    }
    if (i != ndim)
        return PyErr_Format(PyExc_ValueError, "Expected %d dimension(s), got %d",
                            ctx->head->field->type->ndim, i);
    if (!*ts) {
        PyErr_SetString(PyExc_ValueError,
                        "Unexpected end of format string, expected ')'");
        return NULL;
    }
    ctx->is_valid_array = 1;
    ctx->new_count = 1;
    *tsp = ++ts;
    return Py_None;
}
static const char* __Pyx_BufFmt_CheckString(__Pyx_BufFmt_Context* ctx, const char* ts) {
  int got_Z = 0;
  while (1) {
    switch(*ts) {
      case 0:
        if (ctx->enc_type != 0 && ctx->head == NULL) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return NULL;
        }
        if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
        if (ctx->head != NULL) {
          __Pyx_BufFmt_RaiseExpected(ctx);
          return NULL;
        }
        return ts;
      case ' ':
      case '\r':
      case '\n':
        ++ts;
        break;
      case '<':
        if (!__Pyx_IsLittleEndian()) {
          PyErr_SetString(PyExc_ValueError, "Little-endian buffer not supported on big-endian compiler");
          return NULL;
        }
        ctx->new_packmode = '=';
        ++ts;
        break;
      case '>':
      case '!':
        if (__Pyx_IsLittleEndian()) {
          PyErr_SetString(PyExc_ValueError, "Big-endian buffer not supported on little-endian compiler");
          return NULL;
        }
        ctx->new_packmode = '=';
        ++ts;
        break;
      case '=':
      case '@':
      case '^':
        ctx->new_packmode = *ts++;
        break;
      case 'T':
        {
          const char* ts_after_sub;
          size_t i, struct_count = ctx->new_count;
          size_t struct_alignment = ctx->struct_alignment;
          ctx->new_count = 1;
          ++ts;
          if (*ts != '{') {
            PyErr_SetString(PyExc_ValueError, "Buffer acquisition: Expected '{' after 'T'");
            return NULL;
          }
          if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
          ctx->enc_type = 0;
          ctx->enc_count = 0;
          ctx->struct_alignment = 0;
          ++ts;
          ts_after_sub = ts;
          for (i = 0; i != struct_count; ++i) {
            ts_after_sub = __Pyx_BufFmt_CheckString(ctx, ts);
            if (!ts_after_sub) return NULL;
          }
          ts = ts_after_sub;
          if (struct_alignment) ctx->struct_alignment = struct_alignment;
        }
        break;
      case '}':
        {
          size_t alignment = ctx->struct_alignment;
          ++ts;
          if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
          ctx->enc_type = 0;
          if (alignment && ctx->fmt_offset % alignment) {
            ctx->fmt_offset += alignment - (ctx->fmt_offset % alignment);
          }
        }
        return ts;
      case 'x':
        if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
        ctx->fmt_offset += ctx->new_count;
        ctx->new_count = 1;
        ctx->enc_count = 0;
        ctx->enc_type = 0;
        ctx->enc_packmode = ctx->new_packmode;
        ++ts;
        break;
      case 'Z':
        got_Z = 1;
        ++ts;
        if (*ts != 'f' && *ts != 'd' && *ts != 'g') {
          __Pyx_BufFmt_RaiseUnexpectedChar('Z');
          return NULL;
        }
      case 'c': case 'b': case 'B': case 'h': case 'H': case 'i': case 'I':
      case 'l': case 'L': case 'q': case 'Q':
      case 'f': case 'd': case 'g':
      case 'O': case 'p':
        if (ctx->enc_type == *ts && got_Z == ctx->is_complex &&
            ctx->enc_packmode == ctx->new_packmode) {
          ctx->enc_count += ctx->new_count;
          ctx->new_count = 1;
          got_Z = 0;
          ++ts;
          break;
        }
      case 's':
        if (__Pyx_BufFmt_ProcessTypeChunk(ctx) == -1) return NULL;
        ctx->enc_count = ctx->new_count;
        ctx->enc_packmode = ctx->new_packmode;
        ctx->enc_type = *ts;
        ctx->is_complex = got_Z;
        ++ts;
        ctx->new_count = 1;
        got_Z = 0;
        break;
      case ':':
        ++ts;
        while(*ts != ':') ++ts;
        ++ts;
        break;
      case '(':
        if (!__pyx_buffmt_parse_array(ctx, &ts)) return NULL;
        break;
      default:
        {
          int number = __Pyx_BufFmt_ExpectNumber(&ts);
          if (number == -1) return NULL;
          ctx->new_count = (size_t)number;
        }
    }
  }
}
static CYTHON_INLINE void __Pyx_ZeroBuffer(Py_buffer* buf) {
  buf->buf = NULL;
  buf->obj = NULL;
  buf->strides = __Pyx_zeros;
  buf->shape = __Pyx_zeros;
  buf->suboffsets = __Pyx_minusones;
}
static CYTHON_INLINE int __Pyx_GetBufferAndValidate(
        Py_buffer* buf, PyObject* obj,  __Pyx_TypeInfo* dtype, int flags,
        int nd, int cast, __Pyx_BufFmt_StackElem* stack)
{
  if (obj == Py_None || obj == NULL) {
    __Pyx_ZeroBuffer(buf);
    return 0;
  }
  buf->buf = NULL;
  if (__Pyx_GetBuffer(obj, buf, flags) == -1) goto fail;
  if (buf->ndim != nd) {
    PyErr_Format(PyExc_ValueError,
                 "Buffer has wrong number of dimensions (expected %d, got %d)",
                 nd, buf->ndim);
    goto fail;
  }
  if (!cast) {
    __Pyx_BufFmt_Context ctx;
    __Pyx_BufFmt_Init(&ctx, stack, dtype);
    if (!__Pyx_BufFmt_CheckString(&ctx, buf->format)) goto fail;
  }
  if ((unsigned)buf->itemsize != dtype->size) {
    PyErr_Format(PyExc_ValueError,
      "Item size of buffer (%" CYTHON_FORMAT_SSIZE_T "d byte%s) does not match size of '%s' (%" CYTHON_FORMAT_SSIZE_T "d byte%s)",
      buf->itemsize, (buf->itemsize > 1) ? "s" : "",
      dtype->name, (Py_ssize_t)dtype->size, (dtype->size > 1) ? "s" : "");
    goto fail;
  }
  if (buf->suboffsets == NULL) buf->suboffsets = __Pyx_minusones;
  return 0;
fail:;
  __Pyx_ZeroBuffer(buf);
  return -1;
}
static CYTHON_INLINE void __Pyx_SafeReleaseBuffer(Py_buffer* info) {
  if (info->buf == NULL) return;
  if (info->suboffsets == __Pyx_minusones) info->suboffsets = NULL;
  __Pyx_ReleaseBuffer(info);
}

static CYTHON_INLINE void __Pyx_ErrRestore(PyObject *type, PyObject *value, PyObject *tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyThreadState *tstate = PyThreadState_GET();
    tmp_type = tstate->curexc_type;
    tmp_value = tstate->curexc_value;
    tmp_tb = tstate->curexc_traceback;
    tstate->curexc_type = type;
    tstate->curexc_value = value;
    tstate->curexc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_Restore(type, value, tb);
#endif
}
static CYTHON_INLINE void __Pyx_ErrFetch(PyObject **type, PyObject **value, PyObject **tb) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyThreadState *tstate = PyThreadState_GET();
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(type, value, tb);
#endif
}

static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
                                  int full_traceback, CYTHON_UNUSED int nogil) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
#ifdef WITH_THREAD
    PyGILState_STATE state;
    if (nogil)
        state = PyGILState_Ensure();
#endif
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    if (full_traceback) {
        Py_XINCREF(old_exc);
        Py_XINCREF(old_val);
        Py_XINCREF(old_tb);
        __Pyx_ErrRestore(old_exc, old_val, old_tb);
        PyErr_PrintEx(1);
    }
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
#ifdef WITH_THREAD
    if (nogil)
        PyGILState_Release(state);
#endif
}

static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *more_or_less;
    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    PyErr_Format(PyExc_TypeError,
                 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AsString(kw_name));
        #endif
}

static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;
    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
            continue;
        }
        name = first_kw_arg;
        #if PY_MAJOR_VERSION < 3
        if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
            while (*name) {
                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
                        && _PyString_Eq(**name, key)) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    if ((**argname == key) || (
                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
                             && _PyString_Eq(**argname, key))) {
                        goto arg_passed_twice;
                    }
                    argname++;
                }
            }
        } else
        #endif
        if (likely(PyUnicode_Check(key))) {
            while (*name) {
                int cmp = (**name == key) ? 0 :
                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                    (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
                #endif
                    PyUnicode_Compare(**name, key);
                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                if (cmp == 0) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    int cmp = (**argname == key) ? 0 :
                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                        (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
                    #endif
                        PyUnicode_Compare(**argname, key);
                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                    if (cmp == 0) goto arg_passed_twice;
                    argname++;
                }
            }
        } else
            goto invalid_keyword_type;
        if (kwds2) {
            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
        } else {
            goto invalid_keyword;
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, key);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

static void __Pyx_RaiseBufferFallbackError(void) {
  PyErr_SetString(PyExc_ValueError,
     "Buffer acquisition failed on assignment; and then reacquiring the old buffer failed too!");
}

static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
                                                     CYTHON_NCP_UNUSED int wraparound,
                                                     CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) {
            PyObject *r = PyList_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (PyTuple_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (PyErr_ExceptionMatches(PyExc_OverflowError))
                        PyErr_Clear();
                    else
                        return NULL;
                }
            }
            return m->sq_item(o, i);
        }
    }
#else
    if (is_list || PySequence_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

static void __Pyx_RaiseBufferIndexError(int axis) {
  PyErr_Format(PyExc_IndexError,
     "Out of bounds on buffer access (axis %d)", axis);
}

static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
    PyObject *method, *result = NULL;
    method = __Pyx_PyObject_GetAttrStr(obj, method_name);
    if (unlikely(!method)) goto bad;
#if CYTHON_COMPILING_IN_CPYTHON
    if (likely(PyMethod_Check(method))) {
        PyObject *self = PyMethod_GET_SELF(method);
        if (likely(self)) {
            PyObject *args;
            PyObject *function = PyMethod_GET_FUNCTION(method);
            args = PyTuple_New(2);
            if (unlikely(!args)) goto bad;
            Py_INCREF(self);
            PyTuple_SET_ITEM(args, 0, self);
            Py_INCREF(arg);
            PyTuple_SET_ITEM(args, 1, arg);
            Py_INCREF(function);
            Py_DECREF(method); method = NULL;
            result = __Pyx_PyObject_Call(function, args, NULL);
            Py_DECREF(args);
            Py_DECREF(function);
            return result;
        }
    }
#endif
    result = __Pyx_PyObject_CallOneArg(method, arg);
bad:
    Py_XDECREF(method);
    return result;
}

static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
    if (likely(PyList_CheckExact(L))) {
        if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1;
    } else {
        PyObject* retval = __Pyx_PyObject_CallMethod1(L, __pyx_n_s_append, x);
        if (unlikely(!retval))
            return -1;
        Py_DECREF(retval);
    }
    return 0;
}

static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) {
    int r;
    if (!j) return -1;
    r = PyObject_SetItem(o, j, v);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v, int is_list,
                                               CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_COMPILING_IN_CPYTHON
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = (!wraparound) ? i : ((likely(i >= 0)) ? i : i + PyList_GET_SIZE(o));
        if ((!boundscheck) || likely((n >= 0) & (n < PyList_GET_SIZE(o)))) {
            PyObject* old = PyList_GET_ITEM(o, n);
            Py_INCREF(v);
            PyList_SET_ITEM(o, n, v);
            Py_DECREF(old);
            return 1;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_ass_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (PyErr_ExceptionMatches(PyExc_OverflowError))
                        PyErr_Clear();
                    else
                        return -1;
                }
            }
            return m->sq_ass_item(o, i, v);
        }
    }
#else
#if CYTHON_COMPILING_IN_PYPY
    if (is_list || (PySequence_Check(o) && !PyDict_Check(o))) {
#else
    if (is_list || PySequence_Check(o)) {
#endif
        return PySequence_SetItem(o, i, v);
    }
#endif
    return __Pyx_SetItemInt_Generic(o, PyInt_FromSsize_t(i), v);
}

static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj,
        Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
        int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyMappingMethods* mp;
#if PY_MAJOR_VERSION < 3
    PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence;
    if (likely(ms && ms->sq_slice)) {
        if (!has_cstart) {
            if (_py_start && (*_py_start != Py_None)) {
                cstart = __Pyx_PyIndex_AsSsize_t(*_py_start);
                if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstart = 0;
        }
        if (!has_cstop) {
            if (_py_stop && (*_py_stop != Py_None)) {
                cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop);
                if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstop = PY_SSIZE_T_MAX;
        }
        if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) {
            Py_ssize_t l = ms->sq_length(obj);
            if (likely(l >= 0)) {
                if (cstop < 0) {
                    cstop += l;
                    if (cstop < 0) cstop = 0;
                }
                if (cstart < 0) {
                    cstart += l;
                    if (cstart < 0) cstart = 0;
                }
            } else {
                if (PyErr_ExceptionMatches(PyExc_OverflowError))
                    PyErr_Clear();
                else
                    goto bad;
            }
        }
        return ms->sq_slice(obj, cstart, cstop);
    }
#endif
    mp = Py_TYPE(obj)->tp_as_mapping;
    if (likely(mp && mp->mp_subscript))
#endif
    {
        PyObject* result;
        PyObject *py_slice, *py_start, *py_stop;
        if (_py_slice) {
            py_slice = *_py_slice;
        } else {
            PyObject* owned_start = NULL;
            PyObject* owned_stop = NULL;
            if (_py_start) {
                py_start = *_py_start;
            } else {
                if (has_cstart) {
                    owned_start = py_start = PyInt_FromSsize_t(cstart);
                    if (unlikely(!py_start)) goto bad;
                } else
                    py_start = Py_None;
            }
            if (_py_stop) {
                py_stop = *_py_stop;
            } else {
                if (has_cstop) {
                    owned_stop = py_stop = PyInt_FromSsize_t(cstop);
                    if (unlikely(!py_stop)) {
                        Py_XDECREF(owned_start);
                        goto bad;
                    }
                } else
                    py_stop = Py_None;
            }
            py_slice = PySlice_New(py_start, py_stop, Py_None);
            Py_XDECREF(owned_start);
            Py_XDECREF(owned_stop);
            if (unlikely(!py_slice)) goto bad;
        }
#if CYTHON_COMPILING_IN_CPYTHON
        result = mp->mp_subscript(obj, py_slice);
#else
        result = PyObject_GetItem(obj, py_slice);
#endif
        if (!_py_slice) {
            Py_DECREF(py_slice);
        }
        return result;
    }
    PyErr_Format(PyExc_TypeError,
        "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name);
bad:
    return NULL;
}

static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
    if (s1 == s2) {
        return (equals == Py_EQ);
    } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
        const char *ps1, *ps2;
        Py_ssize_t length = PyBytes_GET_SIZE(s1);
        if (length != PyBytes_GET_SIZE(s2))
            return (equals == Py_NE);
        ps1 = PyBytes_AS_STRING(s1);
        ps2 = PyBytes_AS_STRING(s2);
        if (ps1[0] != ps2[0]) {
            return (equals == Py_NE);
        } else if (length == 1) {
            return (equals == Py_EQ);
        } else {
            int result = memcmp(ps1, ps2, (size_t)length);
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
        return (equals == Py_NE);
    } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
        return (equals == Py_NE);
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
#endif
}

static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
#if PY_MAJOR_VERSION < 3
    PyObject* owned_ref = NULL;
#endif
    int s1_is_unicode, s2_is_unicode;
    if (s1 == s2) {
        goto return_eq;
    }
    s1_is_unicode = PyUnicode_CheckExact(s1);
    s2_is_unicode = PyUnicode_CheckExact(s2);
#if PY_MAJOR_VERSION < 3
    if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) {
        owned_ref = PyUnicode_FromObject(s2);
        if (unlikely(!owned_ref))
            return -1;
        s2 = owned_ref;
        s2_is_unicode = 1;
    } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) {
        owned_ref = PyUnicode_FromObject(s1);
        if (unlikely(!owned_ref))
            return -1;
        s1 = owned_ref;
        s1_is_unicode = 1;
    } else if (((!s2_is_unicode) & (!s1_is_unicode))) {
        return __Pyx_PyBytes_Equals(s1, s2, equals);
    }
#endif
    if (s1_is_unicode & s2_is_unicode) {
        Py_ssize_t length;
        int kind;
        void *data1, *data2;
        if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0))
            return -1;
        length = __Pyx_PyUnicode_GET_LENGTH(s1);
        if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) {
            goto return_ne;
        }
        kind = __Pyx_PyUnicode_KIND(s1);
        if (kind != __Pyx_PyUnicode_KIND(s2)) {
            goto return_ne;
        }
        data1 = __Pyx_PyUnicode_DATA(s1);
        data2 = __Pyx_PyUnicode_DATA(s2);
        if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) {
            goto return_ne;
        } else if (length == 1) {
            goto return_eq;
        } else {
            int result = memcmp(data1, data2, (size_t)(length * kind));
            #if PY_MAJOR_VERSION < 3
            Py_XDECREF(owned_ref);
            #endif
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & s2_is_unicode) {
        goto return_ne;
    } else if ((s2 == Py_None) & s1_is_unicode) {
        goto return_ne;
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
return_eq:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_EQ);
return_ne:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_NE);
#endif
}

#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    if (PyType_Check(type)) {
#if CYTHON_COMPILING_IN_PYPY
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);
    } else {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        value = type;
        type = (PyObject*) Py_TYPE(type);
        Py_INCREF(type);
        if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: exception class must be a subclass of BaseException");
            goto raise_error;
        }
    }
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    PyObject* owned_instance = NULL;
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;
    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (PyExceptionClass_Check(type)) {
        PyObject *instance_class = NULL;
        if (value && PyExceptionInstance_Check(value)) {
            instance_class = (PyObject*) Py_TYPE(value);
            if (instance_class != type) {
                int is_subclass = PyObject_IsSubclass(instance_class, type);
                if (!is_subclass) {
                    instance_class = NULL;
                } else if (unlikely(is_subclass == -1)) {
                    goto bad;
                } else {
                    type = instance_class;
                }
            }
        }
        if (!instance_class) {
            PyObject *args;
            if (!value)
                args = PyTuple_New(0);
            else if (PyTuple_Check(value)) {
                Py_INCREF(value);
                args = value;
            } else
                args = PyTuple_Pack(1, value);
            if (!args)
                goto bad;
            owned_instance = PyObject_Call(type, args, NULL);
            Py_DECREF(args);
            if (!owned_instance)
                goto bad;
            value = owned_instance;
            if (!PyExceptionInstance_Check(value)) {
                PyErr_Format(PyExc_TypeError,
                             "calling %R should have returned an instance of "
                             "BaseException, not %R",
                             type, Py_TYPE(value));
                goto bad;
            }
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
#if PY_VERSION_HEX >= 0x03030000
    if (cause) {
#else
    if (cause && cause != Py_None) {
#endif
        PyObject *fixed_cause;
        if (cause == Py_None) {
            fixed_cause = NULL;
        } else if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        } else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        } else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        PyException_SetCause(value, fixed_cause);
    }
    PyErr_SetObject(type, value);
    if (tb) {
#if CYTHON_COMPILING_IN_PYPY
        PyObject *tmp_type, *tmp_value, *tmp_tb;
        PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
        Py_INCREF(tb);
        PyErr_Restore(tmp_type, tmp_value, tb);
        Py_XDECREF(tmp_tb);
#else
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
#endif
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
    if (likely(PyCFunction_Check(func))) {
#endif
        if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
            return __Pyx_PyObject_CallMethO(func, NULL);
        }
    }
    return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
}
#endif

static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
    PyObject *method;
    method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name);
    if (unlikely(!method))
        return -1;
    target->method = method;
#if CYTHON_COMPILING_IN_CPYTHON
    #if PY_MAJOR_VERSION >= 3
    if (likely(PyObject_TypeCheck(method, &PyMethodDescr_Type)))
    #endif
    {
        PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
        target->func = descr->d_method->ml_meth;
        target->flag = descr->d_method->ml_flags & (METH_VARARGS | METH_KEYWORDS | METH_O | METH_NOARGS);
    }
#endif
    return 0;
}

static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) {
    PyObject *args, *result = NULL;
    if (unlikely(!cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
#if CYTHON_COMPILING_IN_CPYTHON
    args = PyTuple_New(1);
    if (unlikely(!args)) goto bad;
    Py_INCREF(self);
    PyTuple_SET_ITEM(args, 0, self);
#else
    args = PyTuple_Pack(1, self);
    if (unlikely(!args)) goto bad;
#endif
    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
    Py_DECREF(args);
bad:
    return result;
}

static CYTHON_INLINE PyObject* __Pyx_PyDict_Keys(PyObject* d) {
    if (PY_MAJOR_VERSION >= 3)
        return __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyDict_Type_keys, d);
    else
        return PyDict_Keys(d);
}

#if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
#endif

#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    if (op1 == op2) {
        Py_RETURN_TRUE;
    }
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
        if (a == b) {
            Py_RETURN_TRUE;
        } else {
            Py_RETURN_FALSE;
        }
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS && PY_MAJOR_VERSION >= 3
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a;
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                #if PyLong_SHIFT < 30 && PyLong_SHIFT != 15
                default: return PyLong_Type.tp_richcompare(op1, op2, Py_EQ);
                #else
                default: Py_RETURN_FALSE;
                #endif
            }
        }
            if (a == b) {
                Py_RETURN_TRUE;
            } else {
                Py_RETURN_FALSE;
            }
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            if ((double)a == (double)b) {
                Py_RETURN_TRUE;
            } else {
                Py_RETURN_FALSE;
            }
    }
    return PyObject_RichCompare(op1, op2, Py_EQ);
}
#endif

#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = (long)((unsigned long)a + b);
            if (likely((x^a) >= 0 || (x^b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_add(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS && PY_MAJOR_VERSION >= 3
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
                    }
                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
            }
        }
                x = a + b;
            return PyLong_FromLong(x);
        long_long:
                llx = lla + llb;
            return PyLong_FromLongLong(llx);
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            PyFPE_START_PROTECT("add", return NULL)
            result = ((double)a) + (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
}
#endif

static CYTHON_INLINE int __Pyx_DelItem_Generic(PyObject *o, PyObject *j) {
    int r;
    if (!j) return -1;
    r = PyObject_DelItem(o, j);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i,
                                               CYTHON_UNUSED int is_list, CYTHON_NCP_UNUSED int wraparound) {
#if CYTHON_COMPILING_IN_PYPY
    if (is_list || PySequence_Check(o)) {
        return PySequence_DelItem(o, i);
    }
#else
    PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
    if (likely(m && m->sq_ass_item)) {
        if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
            Py_ssize_t l = m->sq_length(o);
            if (likely(l >= 0)) {
                i += l;
            } else {
                if (PyErr_ExceptionMatches(PyExc_OverflowError))
                    PyErr_Clear();
                else
                    return -1;
            }
        }
        return m->sq_ass_item(o, i, (PyObject *)NULL);
    }
#endif
    return __Pyx_DelItem_Generic(o, PyInt_FromSsize_t(i));
}

static void __Pyx_RaiseArgumentTypeInvalid(const char* name, PyObject *obj, PyTypeObject *type) {
    PyErr_Format(PyExc_TypeError,
        "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
}
static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact)
{
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (none_allowed && obj == Py_None) return 1;
    else if (exact) {
        if (likely(Py_TYPE(obj) == type)) return 1;
        #if PY_MAJOR_VERSION == 2
        else if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
        #endif
    }
    else {
        if (likely(PyObject_TypeCheck(obj, type))) return 1;
    }
    __Pyx_RaiseArgumentTypeInvalid(name, obj, type);
    return 0;
}

static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
    PyErr_Format(PyExc_ValueError,
                 "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
}

static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
                 index, (index == 1) ? "" : "s");
}

static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    #if PY_VERSION_HEX < 0x03030000
    PyObject *py_import;
    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
    if (!py_import)
        goto bad;
    #endif
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if (strchr(__Pyx_MODULE_NAME, '.')) {
                #if PY_VERSION_HEX < 0x03030000
                PyObject *py_level = PyInt_FromLong(1);
                if (!py_level)
                    goto bad;
                module = PyObject_CallFunctionObjArgs(py_import,
                    name, global_dict, empty_dict, list, py_level, NULL);
                Py_DECREF(py_level);
                #else
                module = PyImport_ImportModuleLevelObject(
                    name, global_dict, empty_dict, list, 1);
                #endif
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0;
        }
        #endif
        if (!module) {
            #if PY_VERSION_HEX < 0x03030000
            PyObject *py_level = PyInt_FromLong(level);
            if (!py_level)
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, global_dict, empty_dict, list, py_level, NULL);
            Py_DECREF(py_level);
            #else
            module = PyImport_ImportModuleLevelObject(
                name, global_dict, empty_dict, list, level);
            #endif
        }
    }
bad:
    #if PY_VERSION_HEX < 0x03030000
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) {
    int start = 0, mid = 0, end = count - 1;
    if (end >= 0 && code_line > entries[end].code_line) {
        return count;
    }
    while (start < end) {
        mid = start + (end - start) / 2;
        if (code_line < entries[mid].code_line) {
            end = mid;
        } else if (code_line > entries[mid].code_line) {
             start = mid + 1;
        } else {
            return mid;
        }
    }
    if (code_line <= entries[mid].code_line) {
        return mid;
    } else {
        return mid + 1;
    }
}
static PyCodeObject *__pyx_find_code_object(int code_line) {
    PyCodeObject* code_object;
    int pos;
    if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) {
        return NULL;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) {
        return NULL;
    }
    code_object = __pyx_code_cache.entries[pos].code_object;
    Py_INCREF(code_object);
    return code_object;
}
static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) {
    int pos, i;
    __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries;
    if (unlikely(!code_line)) {
        return;
    }
    if (unlikely(!entries)) {
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry));
        if (likely(entries)) {
            __pyx_code_cache.entries = entries;
            __pyx_code_cache.max_count = 64;
            __pyx_code_cache.count = 1;
            entries[0].code_line = code_line;
            entries[0].code_object = code_object;
            Py_INCREF(code_object);
        }
        return;
    }
    pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line);
    if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) {
        PyCodeObject* tmp = entries[pos].code_object;
        entries[pos].code_object = code_object;
        Py_DECREF(tmp);
        return;
    }
    if (__pyx_code_cache.count == __pyx_code_cache.max_count) {
        int new_max = __pyx_code_cache.max_count + 64;
        entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc(
            __pyx_code_cache.entries, (size_t)new_max*sizeof(__Pyx_CodeObjectCacheEntry));
        if (unlikely(!entries)) {
            return;
        }
        __pyx_code_cache.entries = entries;
        __pyx_code_cache.max_count = new_max;
    }
    for (i=__pyx_code_cache.count; i>pos; i--) {
        entries[i] = entries[i-1];
    }
    entries[pos].code_line = code_line;
    entries[pos].code_object = code_object;
    __pyx_code_cache.count++;
    Py_INCREF(code_object);
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"
static PyCodeObject* __Pyx_CreateCodeObjectForTraceback(
            const char *funcname, int c_line,
            int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    #if PY_MAJOR_VERSION < 3
    py_srcfile = PyString_FromString(filename);
    #else
    py_srcfile = PyUnicode_FromString(filename);
    #endif
    if (!py_srcfile) goto bad;
    if (c_line) {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #else
        py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line);
        #endif
    }
    else {
        #if PY_MAJOR_VERSION < 3
        py_funcname = PyString_FromString(funcname);
        #else
        py_funcname = PyUnicode_FromString(funcname);
        #endif
    }
    if (!py_funcname) goto bad;
    py_code = __Pyx_PyCode_New(
        0,
        0,
        0,
        0,
        0,
        __pyx_empty_bytes, /*PyObject *code,*/
        __pyx_empty_tuple, /*PyObject *consts,*/
        __pyx_empty_tuple, /*PyObject *names,*/
        __pyx_empty_tuple, /*PyObject *varnames,*/
        __pyx_empty_tuple, /*PyObject *freevars,*/
        __pyx_empty_tuple, /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        py_line,
        __pyx_empty_bytes  /*PyObject *lnotab*/
    );
    Py_DECREF(py_srcfile);
    Py_DECREF(py_funcname);
    return py_code;
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    return NULL;
}
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename) {
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    py_code = __pyx_find_code_object(c_line ? c_line : py_line);
    if (!py_code) {
        py_code = __Pyx_CreateCodeObjectForTraceback(
            funcname, c_line, py_line, filename);
        if (!py_code) goto bad;
        __pyx_insert_code_object(c_line ? c_line : py_line, py_code);
    }
    py_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        __pyx_d,      /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = py_line;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

#if PY_MAJOR_VERSION < 3
static int __Pyx_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
    if (PyObject_CheckBuffer(obj)) return PyObject_GetBuffer(obj, view, flags);
        if (PyObject_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) return __pyx_pw_5numpy_7ndarray_1__getbuffer__(obj, view, flags);
    PyErr_Format(PyExc_TypeError, "'%.200s' does not have the buffer interface", Py_TYPE(obj)->tp_name);
    return -1;
}
static void __Pyx_ReleaseBuffer(Py_buffer *view) {
    PyObject *obj = view->obj;
    if (!obj) return;
    if (PyObject_CheckBuffer(obj)) {
        PyBuffer_Release(view);
        return;
    }
        if (PyObject_TypeCheck(obj, __pyx_ptype_5numpy_ndarray)) { __pyx_pw_5numpy_7ndarray_3__releasebuffer__(obj, view); return; }
    Py_DECREF(obj);
    view->obj = NULL;
}
#endif


            #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
    {\
        func_type value = func_value;\
        if (sizeof(target_type) < sizeof(func_type)) {\
            if (unlikely(value != (func_type) (target_type) value)) {\
                func_type zero = 0;\
                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
                    return (target_type) -1;\
                if (is_unsigned && unlikely(value < zero))\
                    goto raise_neg_overflow;\
                else\
                    goto raise_overflow;\
            }\
        }\
        return (target_type) value;\
    }

static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (int) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(int) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, -(sdigit) digits[0])
                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) -(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) -(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) -(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(int) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
            } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (int) -1;
        }
    } else {
        int val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int");
    return (int) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int");
    return (int) -1;
}

static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) {
    const size_t neg_one = (size_t) -1, const_zero = (size_t) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(size_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(size_t, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (size_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (size_t) 0;
                case  1: __PYX_VERIFY_RETURN_INT(size_t, digit, digits[0])
                case 2:
                    if (8 * sizeof(size_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) >= 2 * PyLong_SHIFT) {
                            return (size_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(size_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) >= 3 * PyLong_SHIFT) {
                            return (size_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(size_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) >= 4 * PyLong_SHIFT) {
                            return (size_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (size_t) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(size_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(size_t) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (size_t) 0;
                case -1: __PYX_VERIFY_RETURN_INT(size_t, sdigit, -(sdigit) digits[0])
                case  1: __PYX_VERIFY_RETURN_INT(size_t,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(size_t) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
                            return (size_t) -(((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(size_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
                            return (size_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
                            return (size_t) -(((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(size_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
                            return (size_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 4 * PyLong_SHIFT) {
                            return (size_t) -(((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(size_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 4 * PyLong_SHIFT) {
                            return (size_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(size_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, long, PyLong_AsLong(x))
            } else if (sizeof(size_t) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            size_t val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (size_t) -1;
        }
    } else {
        size_t val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (size_t) -1;
        val = __Pyx_PyInt_As_size_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to size_t");
    return (size_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to size_t");
    return (size_t) -1;
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(long) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
    }
}

static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(long) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (long) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (long) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(long) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
            } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, -(sdigit) digits[0])
                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) -(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) -(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) -(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(long) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
            } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            long val;
            PyObject *v = __Pyx_PyNumber_Int(x);
 #if PY_MAJOR_VERSION < 3
            if (likely(v) && !PyLong_Check(v)) {
                PyObject *tmp = v;
                v = PyNumber_Long(tmp);
                Py_DECREF(tmp);
            }
 #endif
            if (likely(v)) {
                int one = 1; int is_little = (int)*(unsigned char *)&one;
                unsigned char *bytes = (unsigned char *)&val;
                int ret = _PyLong_AsByteArray((PyLongObject *)v,
                                              bytes, sizeof(val),
                                              is_little, !is_unsigned);
                Py_DECREF(v);
                if (likely(!ret))
                    return val;
            }
#endif
            return (long) -1;
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_Int(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyInt_As_long(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to long");
    return (long) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to long");
    return (long) -1;
}

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
    }
}

#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      return ::std::complex< float >(x, y);
    }
  #else
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      return x + y*(__pyx_t_float_complex)_Complex_I;
    }
  #endif
#else
    static CYTHON_INLINE __pyx_t_float_complex __pyx_t_float_complex_from_parts(float x, float y) {
      __pyx_t_float_complex z;
      z.real = x;
      z.imag = y;
      return z;
    }
#endif

#if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eqf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
       return (a.real == b.real) && (a.imag == b.imag);
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_sumf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real + b.real;
        z.imag = a.imag + b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_difff(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real - b.real;
        z.imag = a.imag - b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_prodf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        z.real = a.real * b.real - a.imag * b.imag;
        z.imag = a.real * b.imag + a.imag * b.real;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_quotf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
        __pyx_t_float_complex z;
        float denom = b.real * b.real + b.imag * b.imag;
        z.real = (a.real * b.real + a.imag * b.imag) / denom;
        z.imag = (a.imag * b.real - a.real * b.imag) / denom;
        return z;
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_negf(__pyx_t_float_complex a) {
        __pyx_t_float_complex z;
        z.real = -a.real;
        z.imag = -a.imag;
        return z;
    }
    static CYTHON_INLINE int __Pyx_c_is_zerof(__pyx_t_float_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_conjf(__pyx_t_float_complex a) {
        __pyx_t_float_complex z;
        z.real =  a.real;
        z.imag = -a.imag;
        return z;
    }
    #if 1
        static CYTHON_INLINE float __Pyx_c_absf(__pyx_t_float_complex z) {
          #if !defined(HAVE_HYPOT) || defined(_MSC_VER)
            return sqrtf(z.real*z.real + z.imag*z.imag);
          #else
            return hypotf(z.real, z.imag);
          #endif
        }
        static CYTHON_INLINE __pyx_t_float_complex __Pyx_c_powf(__pyx_t_float_complex a, __pyx_t_float_complex b) {
            __pyx_t_float_complex z;
            float r, lnr, theta, z_r, z_theta;
            if (b.imag == 0 && b.real == (int)b.real) {
                if (b.real < 0) {
                    float denom = a.real * a.real + a.imag * a.imag;
                    a.real = a.real / denom;
                    a.imag = -a.imag / denom;
                    b.real = -b.real;
                }
                switch ((int)b.real) {
                    case 0:
                        z.real = 1;
                        z.imag = 0;
                        return z;
                    case 1:
                        return a;
                    case 2:
                        z = __Pyx_c_prodf(a, a);
                        return __Pyx_c_prodf(a, a);
                    case 3:
                        z = __Pyx_c_prodf(a, a);
                        return __Pyx_c_prodf(z, a);
                    case 4:
                        z = __Pyx_c_prodf(a, a);
                        return __Pyx_c_prodf(z, z);
                }
            }
            if (a.imag == 0) {
                if (a.real == 0) {
                    return a;
                }
                r = a.real;
                theta = 0;
            } else {
                r = __Pyx_c_absf(a);
                theta = atan2f(a.imag, a.real);
            }
            lnr = logf(r);
            z_r = expf(lnr * b.real - theta * b.imag);
            z_theta = theta * b.real + lnr * b.imag;
            z.real = z_r * cosf(z_theta);
            z.imag = z_r * sinf(z_theta);
            return z;
        }
    #endif
#endif

#if CYTHON_CCOMPLEX
  #ifdef __cplusplus
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      return ::std::complex< double >(x, y);
    }
  #else
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      return x + y*(__pyx_t_double_complex)_Complex_I;
    }
  #endif
#else
    static CYTHON_INLINE __pyx_t_double_complex __pyx_t_double_complex_from_parts(double x, double y) {
      __pyx_t_double_complex z;
      z.real = x;
      z.imag = y;
      return z;
    }
#endif

#if CYTHON_CCOMPLEX
#else
    static CYTHON_INLINE int __Pyx_c_eq(__pyx_t_double_complex a, __pyx_t_double_complex b) {
       return (a.real == b.real) && (a.imag == b.imag);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_sum(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real + b.real;
        z.imag = a.imag + b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_diff(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real - b.real;
        z.imag = a.imag - b.imag;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_prod(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        z.real = a.real * b.real - a.imag * b.imag;
        z.imag = a.real * b.imag + a.imag * b.real;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_quot(__pyx_t_double_complex a, __pyx_t_double_complex b) {
        __pyx_t_double_complex z;
        double denom = b.real * b.real + b.imag * b.imag;
        z.real = (a.real * b.real + a.imag * b.imag) / denom;
        z.imag = (a.imag * b.real - a.real * b.imag) / denom;
        return z;
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_neg(__pyx_t_double_complex a) {
        __pyx_t_double_complex z;
        z.real = -a.real;
        z.imag = -a.imag;
        return z;
    }
    static CYTHON_INLINE int __Pyx_c_is_zero(__pyx_t_double_complex a) {
       return (a.real == 0) && (a.imag == 0);
    }
    static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_conj(__pyx_t_double_complex a) {
        __pyx_t_double_complex z;
        z.real =  a.real;
        z.imag = -a.imag;
        return z;
    }
    #if 1
        static CYTHON_INLINE double __Pyx_c_abs(__pyx_t_double_complex z) {
          #if !defined(HAVE_HYPOT) || defined(_MSC_VER)
            return sqrt(z.real*z.real + z.imag*z.imag);
          #else
            return hypot(z.real, z.imag);
          #endif
        }
        static CYTHON_INLINE __pyx_t_double_complex __Pyx_c_pow(__pyx_t_double_complex a, __pyx_t_double_complex b) {
            __pyx_t_double_complex z;
            double r, lnr, theta, z_r, z_theta;
            if (b.imag == 0 && b.real == (int)b.real) {
                if (b.real < 0) {
                    double denom = a.real * a.real + a.imag * a.imag;
                    a.real = a.real / denom;
                    a.imag = -a.imag / denom;
                    b.real = -b.real;
                }
                switch ((int)b.real) {
                    case 0:
                        z.real = 1;
                        z.imag = 0;
                        return z;
                    case 1:
                        return a;
                    case 2:
                        z = __Pyx_c_prod(a, a);
                        return __Pyx_c_prod(a, a);
                    case 3:
                        z = __Pyx_c_prod(a, a);
                        return __Pyx_c_prod(z, a);
                    case 4:
                        z = __Pyx_c_prod(a, a);
                        return __Pyx_c_prod(z, z);
                }
            }
            if (a.imag == 0) {
                if (a.real == 0) {
                    return a;
                }
                r = a.real;
                theta = 0;
            } else {
                r = __Pyx_c_abs(a);
                theta = atan2(a.imag, a.real);
            }
            lnr = log(r);
            z_r = exp(lnr * b.real - theta * b.imag);
            z_theta = theta * b.real + lnr * b.imag;
            z.real = z_r * cos(z_theta);
            z.imag = z_r * sin(z_theta);
            return z;
        }
    #endif
#endif

static CYTHON_INLINE PyObject* __Pyx_PyInt_From_enum__NPY_TYPES(enum NPY_TYPES value) {
    const enum NPY_TYPES neg_one = (enum NPY_TYPES) -1, const_zero = (enum NPY_TYPES) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(enum NPY_TYPES) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(enum NPY_TYPES) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
        } else if (sizeof(enum NPY_TYPES) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
        }
    } else {
        if (sizeof(enum NPY_TYPES) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(enum NPY_TYPES) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(enum NPY_TYPES),
                                     little, !is_unsigned);
    }
}

static int __Pyx_check_binary_version(void) {
    char ctversion[4], rtversion[4];
    PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION);
    PyOS_snprintf(rtversion, 4, "%s", Py_GetVersion());
    if (ctversion[0] != rtversion[0] || ctversion[2] != rtversion[2]) {
        char message[200];
        PyOS_snprintf(message, sizeof(message),
                      "compiletime version %s of module '%.100s' "
                      "does not match runtime version %s",
                      ctversion, __Pyx_MODULE_NAME, rtversion);
        return PyErr_WarnEx(NULL, message, 1);
    }
    return 0;
}

#ifndef __PYX_HAVE_RT_ImportModule
#define __PYX_HAVE_RT_ImportModule
static PyObject *__Pyx_ImportModule(const char *name) {
    PyObject *py_name = 0;
    PyObject *py_module = 0;
    py_name = __Pyx_PyIdentifier_FromString(name);
    if (!py_name)
        goto bad;
    py_module = PyImport_Import(py_name);
    Py_DECREF(py_name);
    return py_module;
bad:
    Py_XDECREF(py_name);
    return 0;
}
#endif

#ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
    size_t size, int strict)
{
    PyObject *py_module = 0;
    PyObject *result = 0;
    PyObject *py_name = 0;
    char warning[200];
    Py_ssize_t basicsize;
#ifdef Py_LIMITED_API
    PyObject *py_basicsize;
#endif
    py_module = __Pyx_ImportModule(module_name);
    if (!py_module)
        goto bad;
    py_name = __Pyx_PyIdentifier_FromString(class_name);
    if (!py_name)
        goto bad;
    result = PyObject_GetAttr(py_module, py_name);
    Py_DECREF(py_name);
    py_name = 0;
    Py_DECREF(py_module);
    py_module = 0;
    if (!result)
        goto bad;
    if (!PyType_Check(result)) {
        PyErr_Format(PyExc_TypeError,
            "%.200s.%.200s is not a type object",
            module_name, class_name);
        goto bad;
    }
#ifndef Py_LIMITED_API
    basicsize = ((PyTypeObject *)result)->tp_basicsize;
#else
    py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
    if (!py_basicsize)
        goto bad;
    basicsize = PyLong_AsSsize_t(py_basicsize);
    Py_DECREF(py_basicsize);
    py_basicsize = 0;
    if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
        goto bad;
#endif
    if (!strict && (size_t)basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility",
            module_name, class_name);
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
    }
    else if ((size_t)basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s has the wrong size, try recompiling",
            module_name, class_name);
        goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(py_module);
    Py_XDECREF(result);
    return NULL;
}
#endif

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        #if PY_MAJOR_VERSION < 3
        if (t->is_unicode) {
            *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL);
        } else if (t->intern) {
            *t->p = PyString_InternFromString(t->s);
        } else {
            *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        }
        #else
        if (t->is_unicode | t->is_str) {
            if (t->intern) {
                *t->p = PyUnicode_InternFromString(t->s);
            } else if (t->encoding) {
                *t->p = PyUnicode_Decode(t->s, t->n - 1, t->encoding, NULL);
            } else {
                *t->p = PyUnicode_FromStringAndSize(t->s, t->n - 1);
            }
        } else {
            *t->p = PyBytes_FromStringAndSize(t->s, t->n - 1);
        }
        #endif
        if (!*t->p)
            return -1;
        ++t;
    }
    return 0;
}

static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
    return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
}
static CYTHON_INLINE char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
static CYTHON_INLINE char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
    if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
            __Pyx_sys_getdefaultencoding_not_ascii &&
#endif
            PyUnicode_Check(o)) {
#if PY_VERSION_HEX < 0x03030000
        char* defenc_c;
        PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
        if (!defenc) return NULL;
        defenc_c = PyBytes_AS_STRING(defenc);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        {
            char* end = defenc_c + PyBytes_GET_SIZE(defenc);
            char* c;
            for (c = defenc_c; c < end; c++) {
                if ((unsigned char) (*c) >= 128) {
                    PyUnicode_AsASCIIString(o);
                    return NULL;
                }
            }
        }
#endif
        *length = PyBytes_GET_SIZE(defenc);
        return defenc_c;
#else
        if (__Pyx_PyUnicode_READY(o) == -1) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        if (PyUnicode_IS_ASCII(o)) {
            *length = PyUnicode_GET_LENGTH(o);
            return PyUnicode_AsUTF8(o);
        } else {
            PyUnicode_AsASCIIString(o);
            return NULL;
        }
#else
        return PyUnicode_AsUTF8AndSize(o, length);
#endif
#endif
    } else
#endif
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
    if (PyByteArray_Check(o)) {
        *length = PyByteArray_GET_SIZE(o);
        return PyByteArray_AS_STRING(o);
    } else
#endif
    {
        char* result;
        int r = PyBytes_AsStringAndSize(o, &result, length);
        if (unlikely(r < 0)) {
            return NULL;
        } else {
            return result;
        }
    }
}
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) {
   int is_true = x == Py_True;
   if (is_true | (x == Py_False) | (x == Py_None)) return is_true;
   else return PyObject_IsTrue(x);
}
static CYTHON_INLINE PyObject* __Pyx_PyNumber_Int(PyObject* x) {
  PyNumberMethods *m;
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return __Pyx_NewRef(x);
  m = Py_TYPE(x)->tp_as_number;
#if PY_MAJOR_VERSION < 3
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = PyNumber_Long(x);
  }
#else
  if (m && m->nb_int) {
    name = "int";
    res = PyNumber_Long(x);
  }
#endif
  if (res) {
#if PY_MAJOR_VERSION < 3
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%.4s__ returned non-%.4s (type %.200s)",
                   name, name, Py_TYPE(res)->tp_name);
      Py_DECREF(res);
      return NULL;
    }
  }
  else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_TypeError,
                    "an integer is required");
  }
  return res;
}
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) {
  Py_ssize_t ival;
  PyObject *x;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_CheckExact(b))) {
    if (sizeof(Py_ssize_t) >= sizeof(long))
        return PyInt_AS_LONG(b);
    else
        return PyInt_AsSsize_t(x);
  }
#endif
  if (likely(PyLong_CheckExact(b))) {
    #if CYTHON_USE_PYLONG_INTERNALS
    const digit* digits = ((PyLongObject*)b)->ob_digit;
    const Py_ssize_t size = Py_SIZE(b);
    if (likely(__Pyx_sst_abs(size) <= 1)) {
        ival = likely(size) ? digits[0] : 0;
        if (size == -1) ival = -ival;
        return ival;
    } else {
      switch (size) {
         case 2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
      }
    }
    #endif
    return PyLong_AsSsize_t(b);
  }
  x = PyNumber_Index(b);
  if (!x) return -1;
  ival = PyInt_AsSsize_t(x);
  Py_DECREF(x);
  return ival;
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
    return PyInt_FromSize_t(ival);
}


#endif /* Py_PYTHON_H */
