/* Generated by Cython 0.25.2 */

/* BEGIN: Cython Metadata
{
    "distutils": {
        "depends": [], 
        "extra_compile_args": [
            "-O2"
        ]
    }, 
    "module_name": "wlsqm.fitter.infra"
}
END: Cython Metadata */

#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_25_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 HAVE_LONG_LONG
  #if PY_VERSION_HEX >= 0x03030000 || (PY_MAJOR_VERSION == 2 && PY_VERSION_HEX >= 0x02070000)
    #define HAVE_LONG_LONG
  #endif
#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_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #undef CYTHON_USE_TYPE_SLOTS
  #define CYTHON_USE_TYPE_SLOTS 0
  #undef CYTHON_USE_ASYNC_SLOTS
  #define CYTHON_USE_ASYNC_SLOTS 0
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #undef CYTHON_USE_UNICODE_INTERNALS
  #define CYTHON_USE_UNICODE_INTERNALS 0
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #undef CYTHON_AVOID_BORROWED_REFS
  #define CYTHON_AVOID_BORROWED_REFS 1
  #undef CYTHON_ASSUME_SAFE_MACROS
  #define CYTHON_ASSUME_SAFE_MACROS 0
  #undef CYTHON_UNPACK_METHODS
  #define CYTHON_UNPACK_METHODS 0
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
#elif defined(PYSTON_VERSION)
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 1
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #undef CYTHON_USE_ASYNC_SLOTS
  #define CYTHON_USE_ASYNC_SLOTS 0
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
#else
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 1
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #if PY_MAJOR_VERSION < 3
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #if PY_VERSION_HEX < 0x02070000
    #undef CYTHON_USE_PYLONG_INTERNALS
    #define CYTHON_USE_PYLONG_INTERNALS 0
  #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
    #define CYTHON_USE_PYLONG_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_PYLIST_INTERNALS
    #define CYTHON_USE_PYLIST_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #if PY_VERSION_HEX < 0x030300F0
    #undef CYTHON_USE_UNICODE_WRITER
    #define CYTHON_USE_UNICODE_WRITER 0
  #elif !defined(CYTHON_USE_UNICODE_WRITER)
    #define CYTHON_USE_UNICODE_WRITER 1
  #endif
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #ifndef CYTHON_FAST_THREAD_STATE
    #define CYTHON_FAST_THREAD_STATE 1
  #endif
  #ifndef CYTHON_FAST_PYCALL
    #define CYTHON_FAST_PYCALL 1
  #endif
#endif
#if !defined(CYTHON_FAST_PYCCALL)
#define CYTHON_FAST_PYCCALL  (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
#endif
#if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
  #undef SHIFT
  #undef BASE
  #undef MASK
#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
#ifndef METH_FASTCALL
  #define METH_FASTCALL 0x80
  typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject **args,
                                              Py_ssize_t nargs, PyObject *kwnames);
#else
  #define __Pyx_PyCFunctionFast _PyCFunctionFast
#endif
#if CYTHON_FAST_PYCCALL
#define __Pyx_PyFastCFunction_Check(func)\
    ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)))))
#else
#define __Pyx_PyFastCFunction_Check(func) 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_MAX_CHAR_VALUE(u)   PyUnicode_MAX_CHAR_VALUE(u)
  #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)
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  PyUnicode_WRITE(k, d, i, ch)
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
#else
  #define CYTHON_PEP393_ENABLED 0
  #define PyUnicode_1BYTE_KIND  1
  #define PyUnicode_2BYTE_KIND  2
  #define PyUnicode_4BYTE_KIND  4
  #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_MAX_CHAR_VALUE(u)   ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
  #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]))
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_SIZE(u))
#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
#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
  #define PyByteArray_Check(obj)  PyObject_TypeCheck(obj, &PyByteArray_Type)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
  #define PyObject_Format(obj, fmt)  PyObject_CallMethod(obj, "__format__", "O", fmt)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
  #define PyObject_Malloc(s)   PyMem_Malloc(s)
  #define PyObject_Free(p)     PyMem_Free(p)
  #define PyObject_Realloc(p)  PyMem_Realloc(p)
#endif
#if CYTHON_COMPILING_IN_PYSTON
  #define __Pyx_PyCode_HasFreeVars(co)  PyCode_HasFreeVars(co)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
#else
  #define __Pyx_PyCode_HasFreeVars(co)  (PyCode_GetNumFree(co) > 0)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno)  (frame)->f_lineno = (lineno)
#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 && !defined(PyObject_ASCII)
  #define PyObject_ASCII(o)            PyObject_Repr(o)
#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)
#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
#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 CYTHON_USE_ASYNC_SLOTS
  #if PY_VERSION_HEX >= 0x030500B1
    #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
    #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
  #else
    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))
  #endif
#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
#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_MAYBE_UNUSED_VAR
#  if defined(__cplusplus)
     template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
#  else
#    define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
#  endif
#endif
#ifndef CYTHON_NCP_UNUSED
# if CYTHON_COMPILING_IN_CPYTHON
#  define CYTHON_NCP_UNUSED
# else
#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
# endif
#endif
#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)

#ifndef CYTHON_INLINE
  #if defined(__clang__)
    #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  #elif 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 defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
#define __Pyx_truncl trunc
#else
#define __Pyx_truncl truncl
#endif


#define __PYX_ERR(f_index, lineno, Ln_error) \
{ \
  __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \
}

#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_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(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__wlsqm__fitter__infra
#define __PYX_HAVE_API__wlsqm__fitter__infra
#include <string.h>
#include <stdlib.h>
#include <math.h>
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif

typedef struct {PyObject **p; const 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 (_MSC_VER) && defined (_M_X64)
    #define __Pyx_sst_abs(value) _abs64(value)
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define __Pyx_sst_abs(value) llabs(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_IntOrLong(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_ASSUME_SAFE_MACROS
#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
#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
#else
#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
#endif
#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(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 PyObject *__pyx_empty_unicode;
static int __pyx_lineno;
static int __pyx_clineno = 0;
static const char * __pyx_cfilenm= __FILE__;
static const char *__pyx_filename;


static const char *__pyx_f[] = {
  "wlsqm/fitter/infra.pyx",
};

/*--- Type declarations ---*/
struct __pyx_t_5wlsqm_6fitter_5infra_Allocator;
struct __pyx_t_5wlsqm_6fitter_5infra_BufferSizes;
struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager;
struct __pyx_t_5wlsqm_6fitter_5infra_Case;

/* "wlsqm/fitter/infra.pxd":27
 * cdef int ALLOC_MODE_ONEBIGBUFFER  # pre-allocate one big buffer to fit everything in
 * 
 * cdef struct Allocator:             # <<<<<<<<<<<<<<
 *     int mode       # operation mode, see constants ALLOC_MODE_*
 *     void* buffer   # start address of all storage
 */
struct __pyx_t_5wlsqm_6fitter_5infra_Allocator {
  int mode;
  void *buffer;
  int size_total;
  void *p;
  int size_used;
};

/* "wlsqm/fitter/infra.pxd":48
 * # This is really just a struct; no methods.
 * #
 * cdef struct BufferSizes:             # <<<<<<<<<<<<<<
 *     int o2r        # DOF mapping original --> reduced
 *     int r2o        # DOF mapping reduced  --> original
 */
struct __pyx_t_5wlsqm_6fitter_5infra_BufferSizes {
  int o2r;
  int r2o;
  int c;
  int w;
  int A;
  int row_scale;
  int col_scale;
  int ipiv;
  int fi;
  int fi2;
  int wrk;
  int fk_tmp;
  int fi_tmp;
  int total;
};

/* "wlsqm/fitter/infra.pxd":77
 * # This class is only intended to be used from a Python thread.
 * #
 * cdef struct CaseManager:             # <<<<<<<<<<<<<<
 *     # parallel processing
 *     #
 */
struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager {
  int ntasks;
  double **wrks;
  double **fk_tmps;
  double **fi_tmps;
  struct __pyx_t_5wlsqm_6fitter_5infra_Case **cases;
  int max_cases;
  int ncases;
  int bytes_needed;
  struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *mal;
  int dimension;
  int do_sens;
  int iterative;
};

/* "wlsqm/fitter/infra.pxd":123
 * # TODO: could also store the point xi and other relevant stuff. (OTOH, currently no actual use case that needs them)
 * #
 * cdef struct Case:             # <<<<<<<<<<<<<<
 *     # infra
 *     int have_manager  # 1 = has a CaseManager, using its allocator
 */
struct __pyx_t_5wlsqm_6fitter_5infra_Case {
  int have_manager;
  struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *manager;
  struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *mal;
  int dimension;
  int order;
  PY_LONG_LONG knowns;
  int weighting_method;
  int no;
  int nr;
  int nk;
  int do_sens;
  int iterative;
  double xi;
  double yi;
  double zi;
  int geometry_owned;
  int *o2r;
  int *r2o;
  double *c;
  double *w;
  double *A;
  double *row_scale;
  double *col_scale;
  int *ipiv;
  double cond_orig;
  double cond_scaled;
  double *fi;
  double *fi2;
  double *wrk;
  double *fk_tmp;
  double *fi_tmp;
};

/* --- Runtime support code (head) --- */
/* Refnanny.proto */
#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)

/* PyObjectGetAttrStr.proto */
#if CYTHON_USE_TYPE_SLOTS
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

/* GetBuiltinName.proto */
static PyObject *__Pyx_GetBuiltinName(PyObject *name);

/* ForceInitThreads.proto */
#ifndef __PYX_FORCE_INIT_THREADS
  #define __PYX_FORCE_INIT_THREADS 0
#endif

/* PyObjectCall.proto */
#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

/* PyThreadStateGet.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyThreadState_declare  PyThreadState *__pyx_tstate;
#define __Pyx_PyThreadState_assign  __pyx_tstate = PyThreadState_GET();
#else
#define __Pyx_PyThreadState_declare
#define __Pyx_PyThreadState_assign
#endif

/* PyErrFetchRestore.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_ErrRestoreWithState(type, value, tb)  __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)    __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)    __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
#define __Pyx_ErrRestoreWithState(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)  PyErr_Fetch(type, value, tb)
#endif

/* RaiseException.proto */
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);

/* SaveResetException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_ExceptionSave(type, value, tb)  __Pyx__ExceptionSave(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#define __Pyx_ExceptionReset(type, value, tb)  __Pyx__ExceptionReset(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
#else
#define __Pyx_ExceptionSave(type, value, tb)   PyErr_GetExcInfo(type, value, tb)
#define __Pyx_ExceptionReset(type, value, tb)  PyErr_SetExcInfo(type, value, tb)
#endif

/* GetException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_GetException(type, value, tb)  __Pyx__GetException(__pyx_tstate, type, value, tb)
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
#endif

/* CodeObjectCache.proto */
typedef struct {
    PyCodeObject* code_object;
    int code_line;
} __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);

/* AddTraceback.proto */
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);

/* CIntFromPy.proto */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);

/* CIntFromPy.proto */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);

/* CheckBinaryVersion.proto */
static int __Pyx_check_binary_version(void);

/* PyObjectSetAttrStr.proto */
#if CYTHON_USE_TYPE_SLOTS
#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

/* VoidPtrExport.proto */
static int __Pyx_ExportVoidPtr(PyObject *name, void *p, const char *sig);

/* FunctionExport.proto */
static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig);

/* PyIdentifierFromString.proto */
#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

/* ModuleImport.proto */
static PyObject *__Pyx_ImportModule(const char *name);

/* VoidPtrImport.proto */
static int __Pyx_ImportVoidPtr(PyObject *module, const char *name, void **p, const char *sig);

/* InitStrings.proto */
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);


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

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

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

/* Module declarations from 'wlsqm.fitter.defs' */
static int *__pyx_vp_5wlsqm_6fitter_4defs_ALGO_BASIC_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_ALGO_BASIC_c (*__pyx_vp_5wlsqm_6fitter_4defs_ALGO_BASIC_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_ALGO_ITERATIVE_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_ALGO_ITERATIVE_c (*__pyx_vp_5wlsqm_6fitter_4defs_ALGO_ITERATIVE_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_WEIGHT_UNIFORM_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_WEIGHT_UNIFORM_c (*__pyx_vp_5wlsqm_6fitter_4defs_WEIGHT_UNIFORM_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_WEIGHT_CENTER_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_WEIGHT_CENTER_c (*__pyx_vp_5wlsqm_6fitter_4defs_WEIGHT_CENTER_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i1_F_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i1_F_c (*__pyx_vp_5wlsqm_6fitter_4defs_i1_F_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i1_X_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i1_X_c (*__pyx_vp_5wlsqm_6fitter_4defs_i1_X_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i1_X2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i1_X2_c (*__pyx_vp_5wlsqm_6fitter_4defs_i1_X2_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i1_X3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i1_X3_c (*__pyx_vp_5wlsqm_6fitter_4defs_i1_X3_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i1_X4_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i1_X4_c (*__pyx_vp_5wlsqm_6fitter_4defs_i1_X4_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i1_0th_end_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i1_0th_end_c (*__pyx_vp_5wlsqm_6fitter_4defs_i1_0th_end_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i1_1st_end_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i1_1st_end_c (*__pyx_vp_5wlsqm_6fitter_4defs_i1_1st_end_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i1_2nd_end_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i1_2nd_end_c (*__pyx_vp_5wlsqm_6fitter_4defs_i1_2nd_end_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i1_3rd_end_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i1_3rd_end_c (*__pyx_vp_5wlsqm_6fitter_4defs_i1_3rd_end_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i1_4th_end_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i1_4th_end_c (*__pyx_vp_5wlsqm_6fitter_4defs_i1_4th_end_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_SIZE1_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_SIZE1_c (*__pyx_vp_5wlsqm_6fitter_4defs_SIZE1_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_F_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_F_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_F_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_X_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_X_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_X_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_Y_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_Y_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_Y_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_X2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_X2_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_X2_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_XY_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_XY_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_XY_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_Y2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_Y2_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_Y2_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_X3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_X3_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_X3_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_X2Y_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_X2Y_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_X2Y_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_XY2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_XY2_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_XY2_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_Y3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_Y3_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_Y3_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_X4_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_X4_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_X4_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_X3Y_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_X3Y_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_X3Y_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_X2Y2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_X2Y2_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_X2Y2_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_XY3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_XY3_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_XY3_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_Y4_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_Y4_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_Y4_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_0th_end_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_0th_end_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_0th_end_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_1st_end_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_1st_end_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_1st_end_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_2nd_end_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_2nd_end_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_2nd_end_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_3rd_end_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_3rd_end_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_3rd_end_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i2_4th_end_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i2_4th_end_c (*__pyx_vp_5wlsqm_6fitter_4defs_i2_4th_end_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_SIZE2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_SIZE2_c (*__pyx_vp_5wlsqm_6fitter_4defs_SIZE2_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_F_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_F_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_F_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_X_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_X_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_X_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_Y_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_Y_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_Y_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_Z_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_Z_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_Z_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_X2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_X2_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_X2_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_XY_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_XY_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_XY_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_Y2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_Y2_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_Y2_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_YZ_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_YZ_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_YZ_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_Z2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_Z2_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_Z2_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_XZ_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_XZ_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_XZ_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_X3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_X3_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_X3_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_X2Y_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_X2Y_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_X2Y_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_XY2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_XY2_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_XY2_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_Y3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_Y3_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_Y3_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_Y2Z_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_Y2Z_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_Y2Z_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_YZ2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_YZ2_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_YZ2_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_Z3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_Z3_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_Z3_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_XZ2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_XZ2_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_XZ2_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_X2Z_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_X2Z_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_X2Z_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_XYZ_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_XYZ_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_XYZ_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_X4_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_X4_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_X4_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_X3Y_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_X3Y_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_X3Y_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_X2Y2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_X2Y2_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_X2Y2_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_XY3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_XY3_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_XY3_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_Y4_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_Y4_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_Y4_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_Y3Z_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_Y3Z_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_Y3Z_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_Y2Z2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_Y2Z2_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_Y2Z2_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_YZ3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_YZ3_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_YZ3_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_Z4_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_Z4_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_Z4_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_XZ3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_XZ3_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_XZ3_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_X2Z2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_X2Z2_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_X2Z2_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_X3Z_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_X3Z_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_X3Z_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_X2YZ_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_X2YZ_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_X2YZ_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_XY2Z_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_XY2Z_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_XY2Z_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_XYZ2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_XYZ2_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_XYZ2_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_0th_end_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_0th_end_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_0th_end_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_1st_end_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_1st_end_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_1st_end_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_2nd_end_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_2nd_end_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_2nd_end_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_3rd_end_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_3rd_end_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_3rd_end_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_i3_4th_end_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_i3_4th_end_c (*__pyx_vp_5wlsqm_6fitter_4defs_i3_4th_end_c)
static int *__pyx_vp_5wlsqm_6fitter_4defs_SIZE3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_SIZE3_c (*__pyx_vp_5wlsqm_6fitter_4defs_SIZE3_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b1_F_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b1_F_c (*__pyx_vp_5wlsqm_6fitter_4defs_b1_F_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b1_X_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b1_X_c (*__pyx_vp_5wlsqm_6fitter_4defs_b1_X_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b1_X2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b1_X2_c (*__pyx_vp_5wlsqm_6fitter_4defs_b1_X2_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b1_X3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b1_X3_c (*__pyx_vp_5wlsqm_6fitter_4defs_b1_X3_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b1_X4_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b1_X4_c (*__pyx_vp_5wlsqm_6fitter_4defs_b1_X4_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b2_F_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b2_F_c (*__pyx_vp_5wlsqm_6fitter_4defs_b2_F_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b2_X_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b2_X_c (*__pyx_vp_5wlsqm_6fitter_4defs_b2_X_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b2_Y_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b2_Y_c (*__pyx_vp_5wlsqm_6fitter_4defs_b2_Y_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b2_X2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b2_X2_c (*__pyx_vp_5wlsqm_6fitter_4defs_b2_X2_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b2_XY_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b2_XY_c (*__pyx_vp_5wlsqm_6fitter_4defs_b2_XY_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b2_Y2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b2_Y2_c (*__pyx_vp_5wlsqm_6fitter_4defs_b2_Y2_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b2_X3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b2_X3_c (*__pyx_vp_5wlsqm_6fitter_4defs_b2_X3_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b2_X2Y_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b2_X2Y_c (*__pyx_vp_5wlsqm_6fitter_4defs_b2_X2Y_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b2_XY2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b2_XY2_c (*__pyx_vp_5wlsqm_6fitter_4defs_b2_XY2_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b2_Y3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b2_Y3_c (*__pyx_vp_5wlsqm_6fitter_4defs_b2_Y3_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b2_X4_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b2_X4_c (*__pyx_vp_5wlsqm_6fitter_4defs_b2_X4_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b2_X3Y_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b2_X3Y_c (*__pyx_vp_5wlsqm_6fitter_4defs_b2_X3Y_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b2_X2Y2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b2_X2Y2_c (*__pyx_vp_5wlsqm_6fitter_4defs_b2_X2Y2_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b2_XY3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b2_XY3_c (*__pyx_vp_5wlsqm_6fitter_4defs_b2_XY3_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b2_Y4_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b2_Y4_c (*__pyx_vp_5wlsqm_6fitter_4defs_b2_Y4_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_F_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_F_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_F_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_X_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_X_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_X_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_Y_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_Y_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_Y_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_Z_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_Z_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_Z_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_X2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_X2_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_X2_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_XY_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_XY_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_XY_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_Y2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_Y2_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_Y2_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_YZ_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_YZ_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_YZ_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_Z2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_Z2_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_Z2_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_XZ_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_XZ_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_XZ_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_X3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_X3_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_X3_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_X2Y_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_X2Y_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_X2Y_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_XY2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_XY2_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_XY2_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_Y3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_Y3_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_Y3_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_Y2Z_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_Y2Z_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_Y2Z_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_YZ2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_YZ2_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_YZ2_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_Z3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_Z3_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_Z3_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_XZ2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_XZ2_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_XZ2_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_X2Z_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_X2Z_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_X2Z_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_XYZ_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_XYZ_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_XYZ_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_X4_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_X4_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_X4_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_X3Y_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_X3Y_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_X3Y_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_X2Y2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_X2Y2_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_X2Y2_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_XY3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_XY3_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_XY3_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_Y4_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_Y4_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_Y4_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_Y3Z_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_Y3Z_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_Y3Z_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_Y2Z2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_Y2Z2_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_Y2Z2_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_YZ3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_YZ3_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_YZ3_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_Z4_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_Z4_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_Z4_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_XZ3_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_XZ3_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_XZ3_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_X2Z2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_X2Z2_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_X2Z2_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_X3Z_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_X3Z_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_X3Z_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_X2YZ_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_X2YZ_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_X2YZ_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_XY2Z_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_XY2Z_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_XY2Z_c)
static PY_LONG_LONG *__pyx_vp_5wlsqm_6fitter_4defs_b3_XYZ2_c = 0;
#define __pyx_v_5wlsqm_6fitter_4defs_b3_XYZ2_c (*__pyx_vp_5wlsqm_6fitter_4defs_b3_XYZ2_c)

/* Module declarations from 'wlsqm.fitter.infra' */
static int __pyx_v_5wlsqm_6fitter_5infra_ALLOC_MODE_PASSTHROUGH;
static int __pyx_v_5wlsqm_6fitter_5infra_ALLOC_MODE_ONEBIGBUFFER;
static int __pyx_f_5wlsqm_6fitter_5infra_number_of_dofs(int, int); /*proto*/
static int __pyx_f_5wlsqm_6fitter_5infra_number_of_reduced_dofs(int, PY_LONG_LONG); /*proto*/
static int __pyx_f_5wlsqm_6fitter_5infra_remap(int *, int *, int, PY_LONG_LONG); /*proto*/
static struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *__pyx_f_5wlsqm_6fitter_5infra_Allocator_new(int, int); /*proto*/
static void *__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc(struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *, int); /*proto*/
static void __pyx_f_5wlsqm_6fitter_5infra_Allocator_free(struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *, void *); /*proto*/
static int __pyx_f_5wlsqm_6fitter_5infra_Allocator_size_remaining(struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *); /*proto*/
static void __pyx_f_5wlsqm_6fitter_5infra_Allocator_del(struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *); /*proto*/
static int __pyx_f_5wlsqm_6fitter_5infra_CaseManager_add(struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *, struct __pyx_t_5wlsqm_6fitter_5infra_Case *); /*proto*/
static void __pyx_f_5wlsqm_6fitter_5infra_Case_del(struct __pyx_t_5wlsqm_6fitter_5infra_Case *); /*proto*/
__PYX_EXTERN_C DL_IMPORT(int) __builtin_popcountll(unsigned PY_LONG_LONG); /*proto*/
static int __pyx_f_5wlsqm_6fitter_5infra_CaseManager_allocate(struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *); /*proto*/
static void __pyx_f_5wlsqm_6fitter_5infra_CaseManager_deallocate(struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *); /*proto*/
static void __pyx_f_5wlsqm_6fitter_5infra_Case_determine_sizes(struct __pyx_t_5wlsqm_6fitter_5infra_Case *, struct __pyx_t_5wlsqm_6fitter_5infra_BufferSizes *); /*proto*/
static int __pyx_f_5wlsqm_6fitter_5infra_Case_allocate(struct __pyx_t_5wlsqm_6fitter_5infra_Case *); /*proto*/
static void __pyx_f_5wlsqm_6fitter_5infra_Case_deallocate(struct __pyx_t_5wlsqm_6fitter_5infra_Case *); /*proto*/
#define __Pyx_MODULE_NAME "wlsqm.fitter.infra"
int __pyx_module_is_main_wlsqm__fitter__infra = 0;

/* Implementation of 'wlsqm.fitter.infra' */
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_MemoryError;
static PyObject *__pyx_builtin_ValueError;
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_range[] = "range";
static const char __pyx_k_pyx_capi[] = "__pyx_capi__";
static const char __pyx_k_ValueError[] = "ValueError";
static const char __pyx_k_MemoryError[] = "MemoryError";
static const char __pyx_k_ALLOC_MODE_PASSTHROUGH[] = "ALLOC_MODE_PASSTHROUGH";
static const char __pyx_k_ALLOC_MODE_ONEBIGBUFFER[] = "ALLOC_MODE_ONEBIGBUFFER";
static const char __pyx_k_d_bytes_of_memory_needed_but_th[] = "%d bytes of memory needed, but the given allocator has only %d bytes remaining.";
static const char __pyx_k_Cannot_add_case_with_different_d[] = "Cannot add case with different dimension = %d; this manager has dimension = %d";
static const char __pyx_k_Cannot_add_case_with_different_s[] = "Cannot add case with different setting for do_sens = %d; this manager has do_sens = %d";
static const char __pyx_k_Case_pointer_buffer_full_max_cas[] = "Case pointer buffer full, max_cases = %d reached";
static const char __pyx_k_Must_specify_max_cases_0_when_cr[] = "Must specify max_cases > 0 when creating a CaseManager.";
static const char __pyx_k_No_cases_add_some_before_allocat[] = "No cases; add some before allocating";
static const char __pyx_k_Out_of_memory_trying_to_allocate[] = "Out of memory trying to allocate an Allocator object";
static const char __pyx_k_Cannot_add_case_with_different_s_2[] = "Cannot add case with different setting for iterative = %d; this manager has iterative = %d";
static const char __pyx_k_Out_of_memory_trying_to_allocate_2[] = "Out of memory trying to allocate a buffer of %d bytes";
static const char __pyx_k_Out_of_memory_trying_to_allocate_3[] = "Out of memory trying to allocate an CaseManager object";
static const char __pyx_k_Out_of_memory_trying_to_allocate_4[] = "Out of memory trying to allocate a Case object";
static PyObject *__pyx_n_s_ALLOC_MODE_ONEBIGBUFFER;
static PyObject *__pyx_n_s_ALLOC_MODE_PASSTHROUGH;
static PyObject *__pyx_kp_s_Cannot_add_case_with_different_d;
static PyObject *__pyx_kp_s_Cannot_add_case_with_different_s;
static PyObject *__pyx_kp_s_Cannot_add_case_with_different_s_2;
static PyObject *__pyx_kp_s_Case_pointer_buffer_full_max_cas;
static PyObject *__pyx_n_s_MemoryError;
static PyObject *__pyx_kp_s_Must_specify_max_cases_0_when_cr;
static PyObject *__pyx_kp_s_No_cases_add_some_before_allocat;
static PyObject *__pyx_kp_s_Out_of_memory_trying_to_allocate;
static PyObject *__pyx_kp_s_Out_of_memory_trying_to_allocate_2;
static PyObject *__pyx_kp_s_Out_of_memory_trying_to_allocate_3;
static PyObject *__pyx_kp_s_Out_of_memory_trying_to_allocate_4;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_kp_s_d_bytes_of_memory_needed_but_th;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_pyx_capi;
static PyObject *__pyx_n_s_range;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_tuple_;
static PyObject *__pyx_tuple__2;
static PyObject *__pyx_tuple__3;
static PyObject *__pyx_tuple__4;
static PyObject *__pyx_tuple__5;

/* "wlsqm/fitter/infra.pyx":62
 * # order     : in, the order of the polynomial to be fitted
 * #
 * cdef int number_of_dofs( int dimension, int order ) nogil:             # <<<<<<<<<<<<<<
 *     if dimension not in [1,2,3]:
 *         return -1
 */

static int __pyx_f_5wlsqm_6fitter_5infra_number_of_dofs(int __pyx_v_dimension, int __pyx_v_order) {
  int __pyx_v_no;
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;

  /* "wlsqm/fitter/infra.pyx":63
 * #
 * cdef int number_of_dofs( int dimension, int order ) nogil:
 *     if dimension not in [1,2,3]:             # <<<<<<<<<<<<<<
 *         return -1
 * #        with gil:
 */
  switch (__pyx_v_dimension) {
    case 1:
    case 2:
    case 3:
    __pyx_t_1 = 0;
    break;
    default:
    __pyx_t_1 = 1;
    break;
  }
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "wlsqm/fitter/infra.pyx":64
 * cdef int number_of_dofs( int dimension, int order ) nogil:
 *     if dimension not in [1,2,3]:
 *         return -1             # <<<<<<<<<<<<<<
 * #        with gil:
 * #            raise ValueError( "dimension must be 1, 2 or 3; got %d" % dimension )
 */
    __pyx_r = -1;
    goto __pyx_L0;

    /* "wlsqm/fitter/infra.pyx":63
 * #
 * cdef int number_of_dofs( int dimension, int order ) nogil:
 *     if dimension not in [1,2,3]:             # <<<<<<<<<<<<<<
 *         return -1
 * #        with gil:
 */
  }

  /* "wlsqm/fitter/infra.pyx":67
 * #        with gil:
 * #            raise ValueError( "dimension must be 1, 2 or 3; got %d" % dimension )
 *     if order not in [0,1,2,3,4]:             # <<<<<<<<<<<<<<
 *         return -2
 * #        with gil:
 */
  switch (__pyx_v_order) {
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
    __pyx_t_2 = 0;
    break;
    default:
    __pyx_t_2 = 1;
    break;
  }
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (__pyx_t_1) {

    /* "wlsqm/fitter/infra.pyx":68
 * #            raise ValueError( "dimension must be 1, 2 or 3; got %d" % dimension )
 *     if order not in [0,1,2,3,4]:
 *         return -2             # <<<<<<<<<<<<<<
 * #        with gil:
 * #            raise ValueError( "order must be 0, 1, 2, 3 or 4; got %d" % order )
 */
    __pyx_r = -2;
    goto __pyx_L0;

    /* "wlsqm/fitter/infra.pyx":67
 * #        with gil:
 * #            raise ValueError( "dimension must be 1, 2 or 3; got %d" % dimension )
 *     if order not in [0,1,2,3,4]:             # <<<<<<<<<<<<<<
 *         return -2
 * #        with gil:
 */
  }

  /* "wlsqm/fitter/infra.pyx":73
 * 
 *     cdef int no
 *     if dimension == 3:             # <<<<<<<<<<<<<<
 *         if order == 4:
 *             no = defs.i3_4th_end_c
 */
  switch (__pyx_v_dimension) {
    case 3:

    /* "wlsqm/fitter/infra.pyx":74
 *     cdef int no
 *     if dimension == 3:
 *         if order == 4:             # <<<<<<<<<<<<<<
 *             no = defs.i3_4th_end_c
 *         elif order == 3:
 */
    __pyx_t_1 = ((__pyx_v_order == 4) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":75
 *     if dimension == 3:
 *         if order == 4:
 *             no = defs.i3_4th_end_c             # <<<<<<<<<<<<<<
 *         elif order == 3:
 *             no = defs.i3_3rd_end_c
 */
      __pyx_v_no = __pyx_v_5wlsqm_6fitter_4defs_i3_4th_end_c;

      /* "wlsqm/fitter/infra.pyx":74
 *     cdef int no
 *     if dimension == 3:
 *         if order == 4:             # <<<<<<<<<<<<<<
 *             no = defs.i3_4th_end_c
 *         elif order == 3:
 */
      goto __pyx_L5;
    }

    /* "wlsqm/fitter/infra.pyx":76
 *         if order == 4:
 *             no = defs.i3_4th_end_c
 *         elif order == 3:             # <<<<<<<<<<<<<<
 *             no = defs.i3_3rd_end_c
 *         elif order == 2:
 */
    __pyx_t_1 = ((__pyx_v_order == 3) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":77
 *             no = defs.i3_4th_end_c
 *         elif order == 3:
 *             no = defs.i3_3rd_end_c             # <<<<<<<<<<<<<<
 *         elif order == 2:
 *             no = defs.i3_2nd_end_c
 */
      __pyx_v_no = __pyx_v_5wlsqm_6fitter_4defs_i3_3rd_end_c;

      /* "wlsqm/fitter/infra.pyx":76
 *         if order == 4:
 *             no = defs.i3_4th_end_c
 *         elif order == 3:             # <<<<<<<<<<<<<<
 *             no = defs.i3_3rd_end_c
 *         elif order == 2:
 */
      goto __pyx_L5;
    }

    /* "wlsqm/fitter/infra.pyx":78
 *         elif order == 3:
 *             no = defs.i3_3rd_end_c
 *         elif order == 2:             # <<<<<<<<<<<<<<
 *             no = defs.i3_2nd_end_c
 *         elif order == 1:
 */
    __pyx_t_1 = ((__pyx_v_order == 2) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":79
 *             no = defs.i3_3rd_end_c
 *         elif order == 2:
 *             no = defs.i3_2nd_end_c             # <<<<<<<<<<<<<<
 *         elif order == 1:
 *             no = defs.i3_1st_end_c
 */
      __pyx_v_no = __pyx_v_5wlsqm_6fitter_4defs_i3_2nd_end_c;

      /* "wlsqm/fitter/infra.pyx":78
 *         elif order == 3:
 *             no = defs.i3_3rd_end_c
 *         elif order == 2:             # <<<<<<<<<<<<<<
 *             no = defs.i3_2nd_end_c
 *         elif order == 1:
 */
      goto __pyx_L5;
    }

    /* "wlsqm/fitter/infra.pyx":80
 *         elif order == 2:
 *             no = defs.i3_2nd_end_c
 *         elif order == 1:             # <<<<<<<<<<<<<<
 *             no = defs.i3_1st_end_c
 *         else: # order == 0:
 */
    __pyx_t_1 = ((__pyx_v_order == 1) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":81
 *             no = defs.i3_2nd_end_c
 *         elif order == 1:
 *             no = defs.i3_1st_end_c             # <<<<<<<<<<<<<<
 *         else: # order == 0:
 *             no = defs.i3_0th_end_c
 */
      __pyx_v_no = __pyx_v_5wlsqm_6fitter_4defs_i3_1st_end_c;

      /* "wlsqm/fitter/infra.pyx":80
 *         elif order == 2:
 *             no = defs.i3_2nd_end_c
 *         elif order == 1:             # <<<<<<<<<<<<<<
 *             no = defs.i3_1st_end_c
 *         else: # order == 0:
 */
      goto __pyx_L5;
    }

    /* "wlsqm/fitter/infra.pyx":83
 *             no = defs.i3_1st_end_c
 *         else: # order == 0:
 *             no = defs.i3_0th_end_c             # <<<<<<<<<<<<<<
 *     elif dimension == 2:
 *         if order == 4:
 */
    /*else*/ {
      __pyx_v_no = __pyx_v_5wlsqm_6fitter_4defs_i3_0th_end_c;
    }
    __pyx_L5:;

    /* "wlsqm/fitter/infra.pyx":73
 * 
 *     cdef int no
 *     if dimension == 3:             # <<<<<<<<<<<<<<
 *         if order == 4:
 *             no = defs.i3_4th_end_c
 */
    break;

    /* "wlsqm/fitter/infra.pyx":84
 *         else: # order == 0:
 *             no = defs.i3_0th_end_c
 *     elif dimension == 2:             # <<<<<<<<<<<<<<
 *         if order == 4:
 *             no = defs.i2_4th_end_c
 */
    case 2:

    /* "wlsqm/fitter/infra.pyx":85
 *             no = defs.i3_0th_end_c
 *     elif dimension == 2:
 *         if order == 4:             # <<<<<<<<<<<<<<
 *             no = defs.i2_4th_end_c
 *         elif order == 3:
 */
    __pyx_t_1 = ((__pyx_v_order == 4) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":86
 *     elif dimension == 2:
 *         if order == 4:
 *             no = defs.i2_4th_end_c             # <<<<<<<<<<<<<<
 *         elif order == 3:
 *             no = defs.i2_3rd_end_c
 */
      __pyx_v_no = __pyx_v_5wlsqm_6fitter_4defs_i2_4th_end_c;

      /* "wlsqm/fitter/infra.pyx":85
 *             no = defs.i3_0th_end_c
 *     elif dimension == 2:
 *         if order == 4:             # <<<<<<<<<<<<<<
 *             no = defs.i2_4th_end_c
 *         elif order == 3:
 */
      goto __pyx_L6;
    }

    /* "wlsqm/fitter/infra.pyx":87
 *         if order == 4:
 *             no = defs.i2_4th_end_c
 *         elif order == 3:             # <<<<<<<<<<<<<<
 *             no = defs.i2_3rd_end_c
 *         elif order == 2:
 */
    __pyx_t_1 = ((__pyx_v_order == 3) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":88
 *             no = defs.i2_4th_end_c
 *         elif order == 3:
 *             no = defs.i2_3rd_end_c             # <<<<<<<<<<<<<<
 *         elif order == 2:
 *             no = defs.i2_2nd_end_c
 */
      __pyx_v_no = __pyx_v_5wlsqm_6fitter_4defs_i2_3rd_end_c;

      /* "wlsqm/fitter/infra.pyx":87
 *         if order == 4:
 *             no = defs.i2_4th_end_c
 *         elif order == 3:             # <<<<<<<<<<<<<<
 *             no = defs.i2_3rd_end_c
 *         elif order == 2:
 */
      goto __pyx_L6;
    }

    /* "wlsqm/fitter/infra.pyx":89
 *         elif order == 3:
 *             no = defs.i2_3rd_end_c
 *         elif order == 2:             # <<<<<<<<<<<<<<
 *             no = defs.i2_2nd_end_c
 *         elif order == 1:
 */
    __pyx_t_1 = ((__pyx_v_order == 2) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":90
 *             no = defs.i2_3rd_end_c
 *         elif order == 2:
 *             no = defs.i2_2nd_end_c             # <<<<<<<<<<<<<<
 *         elif order == 1:
 *             no = defs.i2_1st_end_c
 */
      __pyx_v_no = __pyx_v_5wlsqm_6fitter_4defs_i2_2nd_end_c;

      /* "wlsqm/fitter/infra.pyx":89
 *         elif order == 3:
 *             no = defs.i2_3rd_end_c
 *         elif order == 2:             # <<<<<<<<<<<<<<
 *             no = defs.i2_2nd_end_c
 *         elif order == 1:
 */
      goto __pyx_L6;
    }

    /* "wlsqm/fitter/infra.pyx":91
 *         elif order == 2:
 *             no = defs.i2_2nd_end_c
 *         elif order == 1:             # <<<<<<<<<<<<<<
 *             no = defs.i2_1st_end_c
 *         else: # order == 0:
 */
    __pyx_t_1 = ((__pyx_v_order == 1) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":92
 *             no = defs.i2_2nd_end_c
 *         elif order == 1:
 *             no = defs.i2_1st_end_c             # <<<<<<<<<<<<<<
 *         else: # order == 0:
 *             no = defs.i2_0th_end_c
 */
      __pyx_v_no = __pyx_v_5wlsqm_6fitter_4defs_i2_1st_end_c;

      /* "wlsqm/fitter/infra.pyx":91
 *         elif order == 2:
 *             no = defs.i2_2nd_end_c
 *         elif order == 1:             # <<<<<<<<<<<<<<
 *             no = defs.i2_1st_end_c
 *         else: # order == 0:
 */
      goto __pyx_L6;
    }

    /* "wlsqm/fitter/infra.pyx":94
 *             no = defs.i2_1st_end_c
 *         else: # order == 0:
 *             no = defs.i2_0th_end_c             # <<<<<<<<<<<<<<
 *     else: # dimension == 1:
 *         if order == 4:
 */
    /*else*/ {
      __pyx_v_no = __pyx_v_5wlsqm_6fitter_4defs_i2_0th_end_c;
    }
    __pyx_L6:;

    /* "wlsqm/fitter/infra.pyx":84
 *         else: # order == 0:
 *             no = defs.i3_0th_end_c
 *     elif dimension == 2:             # <<<<<<<<<<<<<<
 *         if order == 4:
 *             no = defs.i2_4th_end_c
 */
    break;
    default:

    /* "wlsqm/fitter/infra.pyx":96
 *             no = defs.i2_0th_end_c
 *     else: # dimension == 1:
 *         if order == 4:             # <<<<<<<<<<<<<<
 *             no = defs.i1_4th_end_c
 *         elif order == 3:
 */
    __pyx_t_1 = ((__pyx_v_order == 4) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":97
 *     else: # dimension == 1:
 *         if order == 4:
 *             no = defs.i1_4th_end_c             # <<<<<<<<<<<<<<
 *         elif order == 3:
 *             no = defs.i1_3rd_end_c
 */
      __pyx_v_no = __pyx_v_5wlsqm_6fitter_4defs_i1_4th_end_c;

      /* "wlsqm/fitter/infra.pyx":96
 *             no = defs.i2_0th_end_c
 *     else: # dimension == 1:
 *         if order == 4:             # <<<<<<<<<<<<<<
 *             no = defs.i1_4th_end_c
 *         elif order == 3:
 */
      goto __pyx_L7;
    }

    /* "wlsqm/fitter/infra.pyx":98
 *         if order == 4:
 *             no = defs.i1_4th_end_c
 *         elif order == 3:             # <<<<<<<<<<<<<<
 *             no = defs.i1_3rd_end_c
 *         elif order == 2:
 */
    __pyx_t_1 = ((__pyx_v_order == 3) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":99
 *             no = defs.i1_4th_end_c
 *         elif order == 3:
 *             no = defs.i1_3rd_end_c             # <<<<<<<<<<<<<<
 *         elif order == 2:
 *             no = defs.i1_2nd_end_c
 */
      __pyx_v_no = __pyx_v_5wlsqm_6fitter_4defs_i1_3rd_end_c;

      /* "wlsqm/fitter/infra.pyx":98
 *         if order == 4:
 *             no = defs.i1_4th_end_c
 *         elif order == 3:             # <<<<<<<<<<<<<<
 *             no = defs.i1_3rd_end_c
 *         elif order == 2:
 */
      goto __pyx_L7;
    }

    /* "wlsqm/fitter/infra.pyx":100
 *         elif order == 3:
 *             no = defs.i1_3rd_end_c
 *         elif order == 2:             # <<<<<<<<<<<<<<
 *             no = defs.i1_2nd_end_c
 *         elif order == 1:
 */
    __pyx_t_1 = ((__pyx_v_order == 2) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":101
 *             no = defs.i1_3rd_end_c
 *         elif order == 2:
 *             no = defs.i1_2nd_end_c             # <<<<<<<<<<<<<<
 *         elif order == 1:
 *             no = defs.i1_1st_end_c
 */
      __pyx_v_no = __pyx_v_5wlsqm_6fitter_4defs_i1_2nd_end_c;

      /* "wlsqm/fitter/infra.pyx":100
 *         elif order == 3:
 *             no = defs.i1_3rd_end_c
 *         elif order == 2:             # <<<<<<<<<<<<<<
 *             no = defs.i1_2nd_end_c
 *         elif order == 1:
 */
      goto __pyx_L7;
    }

    /* "wlsqm/fitter/infra.pyx":102
 *         elif order == 2:
 *             no = defs.i1_2nd_end_c
 *         elif order == 1:             # <<<<<<<<<<<<<<
 *             no = defs.i1_1st_end_c
 *         else: # order == 0:
 */
    __pyx_t_1 = ((__pyx_v_order == 1) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":103
 *             no = defs.i1_2nd_end_c
 *         elif order == 1:
 *             no = defs.i1_1st_end_c             # <<<<<<<<<<<<<<
 *         else: # order == 0:
 *             no = defs.i1_0th_end_c
 */
      __pyx_v_no = __pyx_v_5wlsqm_6fitter_4defs_i1_1st_end_c;

      /* "wlsqm/fitter/infra.pyx":102
 *         elif order == 2:
 *             no = defs.i1_2nd_end_c
 *         elif order == 1:             # <<<<<<<<<<<<<<
 *             no = defs.i1_1st_end_c
 *         else: # order == 0:
 */
      goto __pyx_L7;
    }

    /* "wlsqm/fitter/infra.pyx":105
 *             no = defs.i1_1st_end_c
 *         else: # order == 0:
 *             no = defs.i1_0th_end_c             # <<<<<<<<<<<<<<
 * 
 *     return no
 */
    /*else*/ {
      __pyx_v_no = __pyx_v_5wlsqm_6fitter_4defs_i1_0th_end_c;
    }
    __pyx_L7:;
    break;
  }

  /* "wlsqm/fitter/infra.pyx":107
 *             no = defs.i1_0th_end_c
 * 
 *     return no             # <<<<<<<<<<<<<<
 * 
 * # Return the number of DOFs in the reduced system, corresponding to an original (unreduced) number of DOFs  n  and a knowns mask.
 */
  __pyx_r = __pyx_v_no;
  goto __pyx_L0;

  /* "wlsqm/fitter/infra.pyx":62
 * # order     : in, the order of the polynomial to be fitted
 * #
 * cdef int number_of_dofs( int dimension, int order ) nogil:             # <<<<<<<<<<<<<<
 *     if dimension not in [1,2,3]:
 *         return -1
 */

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

/* "wlsqm/fitter/infra.pyx":114
 * # mask : in, bitmask of knowns
 * #
 * cdef int number_of_reduced_dofs( int n, long long mask ) nogil:             # <<<<<<<<<<<<<<
 *     cdef int ne = __builtin_popcountll(mask)  # number of eliminated DOFs = number of bits set in mask
 *     return n - ne  # remaining DOFs
 */

static int __pyx_f_5wlsqm_6fitter_5infra_number_of_reduced_dofs(int __pyx_v_n, PY_LONG_LONG __pyx_v_mask) {
  int __pyx_v_ne;
  int __pyx_r;

  /* "wlsqm/fitter/infra.pyx":115
 * #
 * cdef int number_of_reduced_dofs( int n, long long mask ) nogil:
 *     cdef int ne = __builtin_popcountll(mask)  # number of eliminated DOFs = number of bits set in mask             # <<<<<<<<<<<<<<
 *     return n - ne  # remaining DOFs
 * 
 */
  __pyx_v_ne = __builtin_popcountll(__pyx_v_mask);

  /* "wlsqm/fitter/infra.pyx":116
 * cdef int number_of_reduced_dofs( int n, long long mask ) nogil:
 *     cdef int ne = __builtin_popcountll(mask)  # number of eliminated DOFs = number of bits set in mask
 *     return n - ne  # remaining DOFs             # <<<<<<<<<<<<<<
 * 
 * # Reduce the system size by removing the rows/columns for knowns from the DOF numbering.
 */
  __pyx_r = (__pyx_v_n - __pyx_v_ne);
  goto __pyx_L0;

  /* "wlsqm/fitter/infra.pyx":114
 * # mask : in, bitmask of knowns
 * #
 * cdef int number_of_reduced_dofs( int n, long long mask ) nogil:             # <<<<<<<<<<<<<<
 *     cdef int ne = __builtin_popcountll(mask)  # number of eliminated DOFs = number of bits set in mask
 *     return n - ne  # remaining DOFs
 */

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

/* "wlsqm/fitter/infra.pyx":140
 * # where  n_reduced = (n - n_eliminated),  since the reduced system has only n_reduced DOFs in total.
 * #
 * cdef int remap( int* o2r, int* r2o, int n, long long mask ) nogil:  # o = original, r = reduced             # <<<<<<<<<<<<<<
 *     # We always start the elimination with a full range(n) of DOFs.
 *     #
 */

static int __pyx_f_5wlsqm_6fitter_5infra_remap(int *__pyx_v_o2r, int *__pyx_v_r2o, int __pyx_v_n, PY_LONG_LONG __pyx_v_mask) {
  int __pyx_v_j;
  int __pyx_v_k;
  int __pyx_r;
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;

  /* "wlsqm/fitter/infra.pyx":172
 *     # We first generate orig -> reduced.
 *     #
 *     cdef int j, k=0  # k = first currently available DOF number (0-based) in the reduced system             # <<<<<<<<<<<<<<
 *     for j in range(n):
 *         if mask & (1LL << j):  # eliminate this DOF?
 */
  __pyx_v_k = 0;

  /* "wlsqm/fitter/infra.pyx":173
 *     #
 *     cdef int j, k=0  # k = first currently available DOF number (0-based) in the reduced system
 *     for j in range(n):             # <<<<<<<<<<<<<<
 *         if mask & (1LL << j):  # eliminate this DOF?
 *             o2r[j] = -1
 */
  __pyx_t_1 = __pyx_v_n;
  for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
    __pyx_v_j = __pyx_t_2;

    /* "wlsqm/fitter/infra.pyx":174
 *     cdef int j, k=0  # k = first currently available DOF number (0-based) in the reduced system
 *     for j in range(n):
 *         if mask & (1LL << j):  # eliminate this DOF?             # <<<<<<<<<<<<<<
 *             o2r[j] = -1
 *         else:
 */
    __pyx_t_3 = ((__pyx_v_mask & (1LL << __pyx_v_j)) != 0);
    if (__pyx_t_3) {

      /* "wlsqm/fitter/infra.pyx":175
 *     for j in range(n):
 *         if mask & (1LL << j):  # eliminate this DOF?
 *             o2r[j] = -1             # <<<<<<<<<<<<<<
 *         else:
 *             o2r[j] = k
 */
      (__pyx_v_o2r[__pyx_v_j]) = -1;

      /* "wlsqm/fitter/infra.pyx":174
 *     cdef int j, k=0  # k = first currently available DOF number (0-based) in the reduced system
 *     for j in range(n):
 *         if mask & (1LL << j):  # eliminate this DOF?             # <<<<<<<<<<<<<<
 *             o2r[j] = -1
 *         else:
 */
      goto __pyx_L5;
    }

    /* "wlsqm/fitter/infra.pyx":177
 *             o2r[j] = -1
 *         else:
 *             o2r[j] = k             # <<<<<<<<<<<<<<
 *             k += 1  # a DOF was introduced into the reduced system
 * 
 */
    /*else*/ {
      (__pyx_v_o2r[__pyx_v_j]) = __pyx_v_k;

      /* "wlsqm/fitter/infra.pyx":178
 *         else:
 *             o2r[j] = k
 *             k += 1  # a DOF was introduced into the reduced system             # <<<<<<<<<<<<<<
 * 
 *     # k is now the number of DOFs in the reduced system
 */
      __pyx_v_k = (__pyx_v_k + 1);
    }
    __pyx_L5:;
  }

  /* "wlsqm/fitter/infra.pyx":184
 *     # Construct the inverse to obtain reduced -> orig. See the example above.
 *     #
 *     for j in range(n):             # <<<<<<<<<<<<<<
 *         if o2r[j] == -1:
 *             continue
 */
  __pyx_t_1 = __pyx_v_n;
  for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
    __pyx_v_j = __pyx_t_2;

    /* "wlsqm/fitter/infra.pyx":185
 *     #
 *     for j in range(n):
 *         if o2r[j] == -1:             # <<<<<<<<<<<<<<
 *             continue
 *         r2o[ o2r[j] ] = j
 */
    __pyx_t_3 = (((__pyx_v_o2r[__pyx_v_j]) == -1L) != 0);
    if (__pyx_t_3) {

      /* "wlsqm/fitter/infra.pyx":186
 *     for j in range(n):
 *         if o2r[j] == -1:
 *             continue             # <<<<<<<<<<<<<<
 *         r2o[ o2r[j] ] = j
 * 
 */
      goto __pyx_L6_continue;

      /* "wlsqm/fitter/infra.pyx":185
 *     #
 *     for j in range(n):
 *         if o2r[j] == -1:             # <<<<<<<<<<<<<<
 *             continue
 *         r2o[ o2r[j] ] = j
 */
    }

    /* "wlsqm/fitter/infra.pyx":187
 *         if o2r[j] == -1:
 *             continue
 *         r2o[ o2r[j] ] = j             # <<<<<<<<<<<<<<
 * 
 *     # In the reduced -> orig mapping, set the rest to -1, since the reduced system
 */
    (__pyx_v_r2o[(__pyx_v_o2r[__pyx_v_j])]) = __pyx_v_j;
    __pyx_L6_continue:;
  }

  /* "wlsqm/fitter/infra.pyx":192
 *     # has less DOFs than the original one.
 *     #
 *     for j in range(k, n):             # <<<<<<<<<<<<<<
 *         r2o[j] = -1
 * 
 */
  __pyx_t_1 = __pyx_v_n;
  for (__pyx_t_2 = __pyx_v_k; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
    __pyx_v_j = __pyx_t_2;

    /* "wlsqm/fitter/infra.pyx":193
 *     #
 *     for j in range(k, n):
 *         r2o[j] = -1             # <<<<<<<<<<<<<<
 * 
 *     return k
 */
    (__pyx_v_r2o[__pyx_v_j]) = -1;
  }

  /* "wlsqm/fitter/infra.pyx":195
 *         r2o[j] = -1
 * 
 *     return k             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_k;
  goto __pyx_L0;

  /* "wlsqm/fitter/infra.pyx":140
 * # where  n_reduced = (n - n_eliminated),  since the reduced system has only n_reduced DOFs in total.
 * #
 * cdef int remap( int* o2r, int* r2o, int n, long long mask ) nogil:  # o = original, r = reduced             # <<<<<<<<<<<<<<
 *     # We always start the elimination with a full range(n) of DOFs.
 *     #
 */

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

/* "wlsqm/fitter/infra.pyx":228
 * # and Cython's "int total_size_bytes=*" syntax (in the .pxd file) does not support nogil functions.
 * #
 * cdef Allocator* Allocator_new( int mode, int total_size_bytes ) nogil except <Allocator*>0:             # <<<<<<<<<<<<<<
 *     cdef Allocator* self = <Allocator*>malloc( sizeof(Allocator) )
 *     if self == <Allocator*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 */

static struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *__pyx_f_5wlsqm_6fitter_5infra_Allocator_new(int __pyx_v_mode, int __pyx_v_total_size_bytes) {
  struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *__pyx_v_self;
  struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *__pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  void *__pyx_t_5;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save;
  #endif
  __Pyx_RefNannySetupContext("Allocator_new", 1);

  /* "wlsqm/fitter/infra.pyx":229
 * #
 * cdef Allocator* Allocator_new( int mode, int total_size_bytes ) nogil except <Allocator*>0:
 *     cdef Allocator* self = <Allocator*>malloc( sizeof(Allocator) )             # <<<<<<<<<<<<<<
 *     if self == <Allocator*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 *         with gil:
 */
  /*try:*/ {
    __pyx_v_self = ((struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *)malloc((sizeof(struct __pyx_t_5wlsqm_6fitter_5infra_Allocator))));

    /* "wlsqm/fitter/infra.pyx":230
 * cdef Allocator* Allocator_new( int mode, int total_size_bytes ) nogil except <Allocator*>0:
 *     cdef Allocator* self = <Allocator*>malloc( sizeof(Allocator) )
 *     if self == <Allocator*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails             # <<<<<<<<<<<<<<
 *         with gil:
 *             raise MemoryError("Out of memory trying to allocate an Allocator object")
 */
    __pyx_t_1 = ((__pyx_v_self == ((struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *)0)) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":231
 *     cdef Allocator* self = <Allocator*>malloc( sizeof(Allocator) )
 *     if self == <Allocator*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 *         with gil:             # <<<<<<<<<<<<<<
 *             raise MemoryError("Out of memory trying to allocate an Allocator object")
 * 
 */
      {
          #ifdef WITH_THREAD
          PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
          #endif
          /*try:*/ {

            /* "wlsqm/fitter/infra.pyx":232
 *     if self == <Allocator*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 *         with gil:
 *             raise MemoryError("Out of memory trying to allocate an Allocator object")             # <<<<<<<<<<<<<<
 * 
 *     if mode == ALLOC_MODE_ONEBIGBUFFER  and  total_size_bytes > 0:
 */
            __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 232, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_Raise(__pyx_t_2, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __PYX_ERR(0, 232, __pyx_L8_error)
          }

          /* "wlsqm/fitter/infra.pyx":231
 *     cdef Allocator* self = <Allocator*>malloc( sizeof(Allocator) )
 *     if self == <Allocator*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 *         with gil:             # <<<<<<<<<<<<<<
 *             raise MemoryError("Out of memory trying to allocate an Allocator object")
 * 
 */
          /*finally:*/ {
            __pyx_L8_error: {
              #ifdef WITH_THREAD
              PyGILState_Release(__pyx_gilstate_save);
              #endif
              goto __pyx_L4_error;
            }
          }
      }

      /* "wlsqm/fitter/infra.pyx":230
 * cdef Allocator* Allocator_new( int mode, int total_size_bytes ) nogil except <Allocator*>0:
 *     cdef Allocator* self = <Allocator*>malloc( sizeof(Allocator) )
 *     if self == <Allocator*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails             # <<<<<<<<<<<<<<
 *         with gil:
 *             raise MemoryError("Out of memory trying to allocate an Allocator object")
 */
    }

    /* "wlsqm/fitter/infra.pyx":234
 *             raise MemoryError("Out of memory trying to allocate an Allocator object")
 * 
 *     if mode == ALLOC_MODE_ONEBIGBUFFER  and  total_size_bytes > 0:             # <<<<<<<<<<<<<<
 *         self.buffer = malloc( total_size_bytes )
 *         if self.buffer == <void*>0:
 */
    __pyx_t_3 = ((__pyx_v_mode == __pyx_v_5wlsqm_6fitter_5infra_ALLOC_MODE_ONEBIGBUFFER) != 0);
    if (__pyx_t_3) {
    } else {
      __pyx_t_1 = __pyx_t_3;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_t_3 = ((__pyx_v_total_size_bytes > 0) != 0);
    __pyx_t_1 = __pyx_t_3;
    __pyx_L11_bool_binop_done:;
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":235
 * 
 *     if mode == ALLOC_MODE_ONEBIGBUFFER  and  total_size_bytes > 0:
 *         self.buffer = malloc( total_size_bytes )             # <<<<<<<<<<<<<<
 *         if self.buffer == <void*>0:
 *             with gil:
 */
      __pyx_v_self->buffer = malloc(__pyx_v_total_size_bytes);

      /* "wlsqm/fitter/infra.pyx":236
 *     if mode == ALLOC_MODE_ONEBIGBUFFER  and  total_size_bytes > 0:
 *         self.buffer = malloc( total_size_bytes )
 *         if self.buffer == <void*>0:             # <<<<<<<<<<<<<<
 *             with gil:
 *                 raise MemoryError("Out of memory trying to allocate a buffer of %d bytes" % (total_size_bytes))
 */
      __pyx_t_1 = ((__pyx_v_self->buffer == ((void *)0)) != 0);
      if (__pyx_t_1) {

        /* "wlsqm/fitter/infra.pyx":237
 *         self.buffer = malloc( total_size_bytes )
 *         if self.buffer == <void*>0:
 *             with gil:             # <<<<<<<<<<<<<<
 *                 raise MemoryError("Out of memory trying to allocate a buffer of %d bytes" % (total_size_bytes))
 *     else:
 */
        {
            #ifdef WITH_THREAD
            PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
            #endif
            /*try:*/ {

              /* "wlsqm/fitter/infra.pyx":238
 *         if self.buffer == <void*>0:
 *             with gil:
 *                 raise MemoryError("Out of memory trying to allocate a buffer of %d bytes" % (total_size_bytes))             # <<<<<<<<<<<<<<
 *     else:
 *         self.buffer = <void*>0
 */
              __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_total_size_bytes); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 238, __pyx_L15_error)
              __Pyx_GOTREF(__pyx_t_2);
              __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Out_of_memory_trying_to_allocate_2, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 238, __pyx_L15_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_ERR(0, 238, __pyx_L15_error)
              __Pyx_GOTREF(__pyx_t_2);
              __Pyx_GIVEREF(__pyx_t_4);
              PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
              __pyx_t_4 = 0;
              __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 238, __pyx_L15_error)
              __Pyx_GOTREF(__pyx_t_4);
              __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
              __Pyx_Raise(__pyx_t_4, 0, 0, 0);
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
              __PYX_ERR(0, 238, __pyx_L15_error)
            }

            /* "wlsqm/fitter/infra.pyx":237
 *         self.buffer = malloc( total_size_bytes )
 *         if self.buffer == <void*>0:
 *             with gil:             # <<<<<<<<<<<<<<
 *                 raise MemoryError("Out of memory trying to allocate a buffer of %d bytes" % (total_size_bytes))
 *     else:
 */
            /*finally:*/ {
              __pyx_L15_error: {
                #ifdef WITH_THREAD
                PyGILState_Release(__pyx_gilstate_save);
                #endif
                goto __pyx_L4_error;
              }
            }
        }

        /* "wlsqm/fitter/infra.pyx":236
 *     if mode == ALLOC_MODE_ONEBIGBUFFER  and  total_size_bytes > 0:
 *         self.buffer = malloc( total_size_bytes )
 *         if self.buffer == <void*>0:             # <<<<<<<<<<<<<<
 *             with gil:
 *                 raise MemoryError("Out of memory trying to allocate a buffer of %d bytes" % (total_size_bytes))
 */
      }

      /* "wlsqm/fitter/infra.pyx":234
 *             raise MemoryError("Out of memory trying to allocate an Allocator object")
 * 
 *     if mode == ALLOC_MODE_ONEBIGBUFFER  and  total_size_bytes > 0:             # <<<<<<<<<<<<<<
 *         self.buffer = malloc( total_size_bytes )
 *         if self.buffer == <void*>0:
 */
      goto __pyx_L10;
    }

    /* "wlsqm/fitter/infra.pyx":240
 *                 raise MemoryError("Out of memory trying to allocate a buffer of %d bytes" % (total_size_bytes))
 *     else:
 *         self.buffer = <void*>0             # <<<<<<<<<<<<<<
 * 
 *     self.mode       = mode
 */
    /*else*/ {
      __pyx_v_self->buffer = ((void *)0);
    }
    __pyx_L10:;

    /* "wlsqm/fitter/infra.pyx":242
 *         self.buffer = <void*>0
 * 
 *     self.mode       = mode             # <<<<<<<<<<<<<<
 *     self.size_total = total_size_bytes
 *     self.p          = self.buffer
 */
    __pyx_v_self->mode = __pyx_v_mode;

    /* "wlsqm/fitter/infra.pyx":243
 * 
 *     self.mode       = mode
 *     self.size_total = total_size_bytes             # <<<<<<<<<<<<<<
 *     self.p          = self.buffer
 *     self.size_used  = 0
 */
    __pyx_v_self->size_total = __pyx_v_total_size_bytes;

    /* "wlsqm/fitter/infra.pyx":244
 *     self.mode       = mode
 *     self.size_total = total_size_bytes
 *     self.p          = self.buffer             # <<<<<<<<<<<<<<
 *     self.size_used  = 0
 * 
 */
    __pyx_t_5 = __pyx_v_self->buffer;
    __pyx_v_self->p = __pyx_t_5;

    /* "wlsqm/fitter/infra.pyx":245
 *     self.size_total = total_size_bytes
 *     self.p          = self.buffer
 *     self.size_used  = 0             # <<<<<<<<<<<<<<
 * 
 *     return self
 */
    __pyx_v_self->size_used = 0;

    /* "wlsqm/fitter/infra.pyx":247
 *     self.size_used  = 0
 * 
 *     return self             # <<<<<<<<<<<<<<
 * 
 * cdef void* Allocator_malloc( Allocator* self, int size_bytes ) nogil:
 */
    __pyx_r = __pyx_v_self;
    goto __pyx_L3_return;
  }

  /* "wlsqm/fitter/infra.pyx":229
 * #
 * cdef Allocator* Allocator_new( int mode, int total_size_bytes ) nogil except <Allocator*>0:
 *     cdef Allocator* self = <Allocator*>malloc( sizeof(Allocator) )             # <<<<<<<<<<<<<<
 *     if self == <Allocator*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 *         with gil:
 */
  /*finally:*/ {
    __pyx_L3_return: {
      #ifdef WITH_THREAD
      __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      goto __pyx_L0;
    }
    __pyx_L4_error: {
      #ifdef WITH_THREAD
      __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      goto __pyx_L1_error;
    }
  }

  /* "wlsqm/fitter/infra.pyx":228
 * # and Cython's "int total_size_bytes=*" syntax (in the .pxd file) does not support nogil functions.
 * #
 * cdef Allocator* Allocator_new( int mode, int total_size_bytes ) nogil except <Allocator*>0:             # <<<<<<<<<<<<<<
 *     cdef Allocator* self = <Allocator*>malloc( sizeof(Allocator) )
 *     if self == <Allocator*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("wlsqm.fitter.infra.Allocator_new", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = ((struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *)0);
  __pyx_L0:;
  #ifdef WITH_THREAD
  PyGILState_Release(__pyx_gilstate_save);
  #endif
  return __pyx_r;
}

/* "wlsqm/fitter/infra.pyx":249
 *     return self
 * 
 * cdef void* Allocator_malloc( Allocator* self, int size_bytes ) nogil:             # <<<<<<<<<<<<<<
 *     if self.mode == ALLOC_MODE_PASSTHROUGH:
 * #        with gil:
 */

static void *__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc(struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *__pyx_v_self, int __pyx_v_size_bytes) {
  int __pyx_v_size_remaining;
  void *__pyx_v_p;
  void *__pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  void *__pyx_t_2;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save;
  #endif
  __Pyx_RefNannySetupContext("Allocator_malloc", 1);

  /* "wlsqm/fitter/infra.pyx":250
 * 
 * cdef void* Allocator_malloc( Allocator* self, int size_bytes ) nogil:
 *     if self.mode == ALLOC_MODE_PASSTHROUGH:             # <<<<<<<<<<<<<<
 * #        with gil:
 * #            print "directly allocating %d bytes" % (size_bytes)
 */
  /*try:*/ {
    __pyx_t_1 = ((__pyx_v_self->mode == __pyx_v_5wlsqm_6fitter_5infra_ALLOC_MODE_PASSTHROUGH) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":253
 * #        with gil:
 * #            print "directly allocating %d bytes" % (size_bytes)
 *         return malloc( size_bytes )             # <<<<<<<<<<<<<<
 * 
 *     # else...
 */
      __pyx_r = malloc(__pyx_v_size_bytes);
      goto __pyx_L3_return;

      /* "wlsqm/fitter/infra.pyx":250
 * 
 * cdef void* Allocator_malloc( Allocator* self, int size_bytes ) nogil:
 *     if self.mode == ALLOC_MODE_PASSTHROUGH:             # <<<<<<<<<<<<<<
 * #        with gil:
 * #            print "directly allocating %d bytes" % (size_bytes)
 */
    }

    /* "wlsqm/fitter/infra.pyx":258
 * 
 *     # pathological case: no buffer, can't allocate
 *     if self.buffer == <void*>0:             # <<<<<<<<<<<<<<
 *         return <void*>0
 * 
 */
    __pyx_t_1 = ((__pyx_v_self->buffer == ((void *)0)) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":259
 *     # pathological case: no buffer, can't allocate
 *     if self.buffer == <void*>0:
 *         return <void*>0             # <<<<<<<<<<<<<<
 * 
 *     # check that there is enough space remaining in the buffer
 */
      __pyx_r = ((void *)0);
      goto __pyx_L3_return;

      /* "wlsqm/fitter/infra.pyx":258
 * 
 *     # pathological case: no buffer, can't allocate
 *     if self.buffer == <void*>0:             # <<<<<<<<<<<<<<
 *         return <void*>0
 * 
 */
    }

    /* "wlsqm/fitter/infra.pyx":262
 * 
 *     # check that there is enough space remaining in the buffer
 *     cdef int size_remaining = self.size_total - self.size_used             # <<<<<<<<<<<<<<
 *     if size_bytes > size_remaining:
 * #        with gil:
 */
    __pyx_v_size_remaining = (__pyx_v_self->size_total - __pyx_v_self->size_used);

    /* "wlsqm/fitter/infra.pyx":263
 *     # check that there is enough space remaining in the buffer
 *     cdef int size_remaining = self.size_total - self.size_used
 *     if size_bytes > size_remaining:             # <<<<<<<<<<<<<<
 * #        with gil:
 * #            print "buffer full, cannot allocate %d bytes" % (size_bytes)  # DEBUG
 */
    __pyx_t_1 = ((__pyx_v_size_bytes > __pyx_v_size_remaining) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":266
 * #        with gil:
 * #            print "buffer full, cannot allocate %d bytes" % (size_bytes)  # DEBUG
 *         return <void*>0             # <<<<<<<<<<<<<<
 * 
 *     cdef void* p
 */
      __pyx_r = ((void *)0);
      goto __pyx_L3_return;

      /* "wlsqm/fitter/infra.pyx":263
 *     # check that there is enough space remaining in the buffer
 *     cdef int size_remaining = self.size_total - self.size_used
 *     if size_bytes > size_remaining:             # <<<<<<<<<<<<<<
 * #        with gil:
 * #            print "buffer full, cannot allocate %d bytes" % (size_bytes)  # DEBUG
 */
    }

    /* "wlsqm/fitter/infra.pyx":269
 * 
 *     cdef void* p
 *     with gil:  # since we are called from Python threads only, we can use the GIL to make the operation thread-safe. (TODO/FIXME: well, not exactly, see e.g. http://www.slideshare.net/dabeaz/an-introduction-to-python-concurrency )             # <<<<<<<<<<<<<<
 * #        print "reserving %d bytes from buffer of size %d; after alloc, %d bytes remaining" % (size_bytes, self.size_total, size_remaining - size_bytes)  # DEBUG
 *         p = self.p
 */
    {
        #ifdef WITH_THREAD
        PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
        #endif
        /*try:*/ {

          /* "wlsqm/fitter/infra.pyx":271
 *     with gil:  # since we are called from Python threads only, we can use the GIL to make the operation thread-safe. (TODO/FIXME: well, not exactly, see e.g. http://www.slideshare.net/dabeaz/an-introduction-to-python-concurrency )
 * #        print "reserving %d bytes from buffer of size %d; after alloc, %d bytes remaining" % (size_bytes, self.size_total, size_remaining - size_bytes)  # DEBUG
 *         p = self.p             # <<<<<<<<<<<<<<
 *         self.p = <void*>( (<char*>p) + size_bytes )
 *         self.size_used += size_bytes
 */
          __pyx_t_2 = __pyx_v_self->p;
          __pyx_v_p = __pyx_t_2;

          /* "wlsqm/fitter/infra.pyx":272
 * #        print "reserving %d bytes from buffer of size %d; after alloc, %d bytes remaining" % (size_bytes, self.size_total, size_remaining - size_bytes)  # DEBUG
 *         p = self.p
 *         self.p = <void*>( (<char*>p) + size_bytes )             # <<<<<<<<<<<<<<
 *         self.size_used += size_bytes
 * 
 */
          __pyx_v_self->p = ((void *)(((char *)__pyx_v_p) + __pyx_v_size_bytes));

          /* "wlsqm/fitter/infra.pyx":273
 *         p = self.p
 *         self.p = <void*>( (<char*>p) + size_bytes )
 *         self.size_used += size_bytes             # <<<<<<<<<<<<<<
 * 
 *     return p
 */
          __pyx_v_self->size_used = (__pyx_v_self->size_used + __pyx_v_size_bytes);
        }

        /* "wlsqm/fitter/infra.pyx":269
 * 
 *     cdef void* p
 *     with gil:  # since we are called from Python threads only, we can use the GIL to make the operation thread-safe. (TODO/FIXME: well, not exactly, see e.g. http://www.slideshare.net/dabeaz/an-introduction-to-python-concurrency )             # <<<<<<<<<<<<<<
 * #        print "reserving %d bytes from buffer of size %d; after alloc, %d bytes remaining" % (size_bytes, self.size_total, size_remaining - size_bytes)  # DEBUG
 *         p = self.p
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            PyGILState_Release(__pyx_gilstate_save);
            #endif
            goto __pyx_L11;
          }
          __pyx_L11:;
        }
    }

    /* "wlsqm/fitter/infra.pyx":275
 *         self.size_used += size_bytes
 * 
 *     return p             # <<<<<<<<<<<<<<
 * 
 * cdef void Allocator_free( Allocator* self, void* p ) nogil:
 */
    __pyx_r = __pyx_v_p;
    goto __pyx_L3_return;
  }

  /* "wlsqm/fitter/infra.pyx":250
 * 
 * cdef void* Allocator_malloc( Allocator* self, int size_bytes ) nogil:
 *     if self.mode == ALLOC_MODE_PASSTHROUGH:             # <<<<<<<<<<<<<<
 * #        with gil:
 * #            print "directly allocating %d bytes" % (size_bytes)
 */
  /*finally:*/ {
    __pyx_L3_return: {
      #ifdef WITH_THREAD
      __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      goto __pyx_L0;
    }
  }

  /* "wlsqm/fitter/infra.pyx":249
 *     return self
 * 
 * cdef void* Allocator_malloc( Allocator* self, int size_bytes ) nogil:             # <<<<<<<<<<<<<<
 *     if self.mode == ALLOC_MODE_PASSTHROUGH:
 * #        with gil:
 */

  /* function exit code */
  __pyx_r = 0;
  __pyx_L0:;
  #ifdef WITH_THREAD
  PyGILState_Release(__pyx_gilstate_save);
  #endif
  return __pyx_r;
}

/* "wlsqm/fitter/infra.pyx":277
 *     return p
 * 
 * cdef void Allocator_free( Allocator* self, void* p ) nogil:             # <<<<<<<<<<<<<<
 *     if self.mode == ALLOC_MODE_PASSTHROUGH:
 *         free( p )
 */

static void __pyx_f_5wlsqm_6fitter_5infra_Allocator_free(struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *__pyx_v_self, void *__pyx_v_p) {
  int __pyx_t_1;

  /* "wlsqm/fitter/infra.pyx":278
 * 
 * cdef void Allocator_free( Allocator* self, void* p ) nogil:
 *     if self.mode == ALLOC_MODE_PASSTHROUGH:             # <<<<<<<<<<<<<<
 *         free( p )
 *     # else do nothing; this simplistic allocator doesn't reuse blocks once they are allocated
 */
  __pyx_t_1 = ((__pyx_v_self->mode == __pyx_v_5wlsqm_6fitter_5infra_ALLOC_MODE_PASSTHROUGH) != 0);
  if (__pyx_t_1) {

    /* "wlsqm/fitter/infra.pyx":279
 * cdef void Allocator_free( Allocator* self, void* p ) nogil:
 *     if self.mode == ALLOC_MODE_PASSTHROUGH:
 *         free( p )             # <<<<<<<<<<<<<<
 *     # else do nothing; this simplistic allocator doesn't reuse blocks once they are allocated
 * 
 */
    free(__pyx_v_p);

    /* "wlsqm/fitter/infra.pyx":278
 * 
 * cdef void Allocator_free( Allocator* self, void* p ) nogil:
 *     if self.mode == ALLOC_MODE_PASSTHROUGH:             # <<<<<<<<<<<<<<
 *         free( p )
 *     # else do nothing; this simplistic allocator doesn't reuse blocks once they are allocated
 */
  }

  /* "wlsqm/fitter/infra.pyx":277
 *     return p
 * 
 * cdef void Allocator_free( Allocator* self, void* p ) nogil:             # <<<<<<<<<<<<<<
 *     if self.mode == ALLOC_MODE_PASSTHROUGH:
 *         free( p )
 */

  /* function exit code */
}

/* "wlsqm/fitter/infra.pyx":282
 *     # else do nothing; this simplistic allocator doesn't reuse blocks once they are allocated
 * 
 * cdef int Allocator_size_remaining( Allocator* self ) nogil:             # <<<<<<<<<<<<<<
 *     return self.size_total - self.size_used
 * 
 */

static int __pyx_f_5wlsqm_6fitter_5infra_Allocator_size_remaining(struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *__pyx_v_self) {
  int __pyx_r;

  /* "wlsqm/fitter/infra.pyx":283
 * 
 * cdef int Allocator_size_remaining( Allocator* self ) nogil:
 *     return self.size_total - self.size_used             # <<<<<<<<<<<<<<
 * 
 * # Destructor.
 */
  __pyx_r = (__pyx_v_self->size_total - __pyx_v_self->size_used);
  goto __pyx_L0;

  /* "wlsqm/fitter/infra.pyx":282
 *     # else do nothing; this simplistic allocator doesn't reuse blocks once they are allocated
 * 
 * cdef int Allocator_size_remaining( Allocator* self ) nogil:             # <<<<<<<<<<<<<<
 *     return self.size_total - self.size_used
 * 
 */

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

/* "wlsqm/fitter/infra.pyx":286
 * 
 * # Destructor.
 * cdef void Allocator_del( Allocator* self ) nogil:             # <<<<<<<<<<<<<<
 *     if self != <Allocator*>0:
 *         free( self.buffer )
 */

static void __pyx_f_5wlsqm_6fitter_5infra_Allocator_del(struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *__pyx_v_self) {
  int __pyx_t_1;

  /* "wlsqm/fitter/infra.pyx":287
 * # Destructor.
 * cdef void Allocator_del( Allocator* self ) nogil:
 *     if self != <Allocator*>0:             # <<<<<<<<<<<<<<
 *         free( self.buffer )
 *         free( self )
 */
  __pyx_t_1 = ((__pyx_v_self != ((struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *)0)) != 0);
  if (__pyx_t_1) {

    /* "wlsqm/fitter/infra.pyx":288
 * cdef void Allocator_del( Allocator* self ) nogil:
 *     if self != <Allocator*>0:
 *         free( self.buffer )             # <<<<<<<<<<<<<<
 *         free( self )
 * 
 */
    free(__pyx_v_self->buffer);

    /* "wlsqm/fitter/infra.pyx":289
 *     if self != <Allocator*>0:
 *         free( self.buffer )
 *         free( self )             # <<<<<<<<<<<<<<
 * 
 * 
 */
    free(__pyx_v_self);

    /* "wlsqm/fitter/infra.pyx":287
 * # Destructor.
 * cdef void Allocator_del( Allocator* self ) nogil:
 *     if self != <Allocator*>0:             # <<<<<<<<<<<<<<
 *         free( self.buffer )
 *         free( self )
 */
  }

  /* "wlsqm/fitter/infra.pyx":286
 * 
 * # Destructor.
 * cdef void Allocator_del( Allocator* self ) nogil:             # <<<<<<<<<<<<<<
 *     if self != <Allocator*>0:
 *         free( self.buffer )
 */

  /* function exit code */
}

/* "wlsqm/fitter/infra.pyx":303
 * # When processing serially, use the value 1.
 * #
 * cdef CaseManager* CaseManager_new( int dimension, int do_sens, int iterative, int max_cases, int ntasks ) nogil except <CaseManager*>0:             # <<<<<<<<<<<<<<
 *     # Generally speaking, fixing the array size at instantiation time is stupid (an automatically expanding buffer would be better),
 *     # but considering that this class has only one actual user, where we do know max_cases in advance, it is fine for our purposes.
 */

static struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *__pyx_f_5wlsqm_6fitter_5infra_CaseManager_new(int __pyx_v_dimension, int __pyx_v_do_sens, int __pyx_v_iterative, int __pyx_v_max_cases, int __pyx_v_ntasks) {
  struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *__pyx_v_self;
  int __pyx_v_j;
  struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *__pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save;
  #endif
  __Pyx_RefNannySetupContext("CaseManager_new", 1);

  /* "wlsqm/fitter/infra.pyx":306
 *     # Generally speaking, fixing the array size at instantiation time is stupid (an automatically expanding buffer would be better),
 *     # but considering that this class has only one actual user, where we do know max_cases in advance, it is fine for our purposes.
 *     if max_cases < 1:             # <<<<<<<<<<<<<<
 *         with gil:
 *             raise ValueError("Must specify max_cases > 0 when creating a CaseManager.")
 */
  /*try:*/ {
    __pyx_t_1 = ((__pyx_v_max_cases < 1) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":307
 *     # but considering that this class has only one actual user, where we do know max_cases in advance, it is fine for our purposes.
 *     if max_cases < 1:
 *         with gil:             # <<<<<<<<<<<<<<
 *             raise ValueError("Must specify max_cases > 0 when creating a CaseManager.")
 * 
 */
      {
          #ifdef WITH_THREAD
          PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
          #endif
          /*try:*/ {

            /* "wlsqm/fitter/infra.pyx":308
 *     if max_cases < 1:
 *         with gil:
 *             raise ValueError("Must specify max_cases > 0 when creating a CaseManager.")             # <<<<<<<<<<<<<<
 * 
 *     cdef CaseManager* self = <CaseManager*>malloc( sizeof(CaseManager) )
 */
            __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 308, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_Raise(__pyx_t_2, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __PYX_ERR(0, 308, __pyx_L8_error)
          }

          /* "wlsqm/fitter/infra.pyx":307
 *     # but considering that this class has only one actual user, where we do know max_cases in advance, it is fine for our purposes.
 *     if max_cases < 1:
 *         with gil:             # <<<<<<<<<<<<<<
 *             raise ValueError("Must specify max_cases > 0 when creating a CaseManager.")
 * 
 */
          /*finally:*/ {
            __pyx_L8_error: {
              #ifdef WITH_THREAD
              PyGILState_Release(__pyx_gilstate_save);
              #endif
              goto __pyx_L4_error;
            }
          }
      }

      /* "wlsqm/fitter/infra.pyx":306
 *     # Generally speaking, fixing the array size at instantiation time is stupid (an automatically expanding buffer would be better),
 *     # but considering that this class has only one actual user, where we do know max_cases in advance, it is fine for our purposes.
 *     if max_cases < 1:             # <<<<<<<<<<<<<<
 *         with gil:
 *             raise ValueError("Must specify max_cases > 0 when creating a CaseManager.")
 */
    }

    /* "wlsqm/fitter/infra.pyx":310
 *             raise ValueError("Must specify max_cases > 0 when creating a CaseManager.")
 * 
 *     cdef CaseManager* self = <CaseManager*>malloc( sizeof(CaseManager) )             # <<<<<<<<<<<<<<
 *     if self == <CaseManager*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 *         with gil:
 */
    __pyx_v_self = ((struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *)malloc((sizeof(struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager))));

    /* "wlsqm/fitter/infra.pyx":311
 * 
 *     cdef CaseManager* self = <CaseManager*>malloc( sizeof(CaseManager) )
 *     if self == <CaseManager*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails             # <<<<<<<<<<<<<<
 *         with gil:
 *             raise MemoryError("Out of memory trying to allocate an CaseManager object")
 */
    __pyx_t_1 = ((__pyx_v_self == ((struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *)0)) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":312
 *     cdef CaseManager* self = <CaseManager*>malloc( sizeof(CaseManager) )
 *     if self == <CaseManager*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 *         with gil:             # <<<<<<<<<<<<<<
 *             raise MemoryError("Out of memory trying to allocate an CaseManager object")
 * 
 */
      {
          #ifdef WITH_THREAD
          PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
          #endif
          /*try:*/ {

            /* "wlsqm/fitter/infra.pyx":313
 *     if self == <CaseManager*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 *         with gil:
 *             raise MemoryError("Out of memory trying to allocate an CaseManager object")             # <<<<<<<<<<<<<<
 * 
 *     # init parallel proc
 */
            __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 313, __pyx_L12_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_Raise(__pyx_t_2, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __PYX_ERR(0, 313, __pyx_L12_error)
          }

          /* "wlsqm/fitter/infra.pyx":312
 *     cdef CaseManager* self = <CaseManager*>malloc( sizeof(CaseManager) )
 *     if self == <CaseManager*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 *         with gil:             # <<<<<<<<<<<<<<
 *             raise MemoryError("Out of memory trying to allocate an CaseManager object")
 * 
 */
          /*finally:*/ {
            __pyx_L12_error: {
              #ifdef WITH_THREAD
              PyGILState_Release(__pyx_gilstate_save);
              #endif
              goto __pyx_L4_error;
            }
          }
      }

      /* "wlsqm/fitter/infra.pyx":311
 * 
 *     cdef CaseManager* self = <CaseManager*>malloc( sizeof(CaseManager) )
 *     if self == <CaseManager*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails             # <<<<<<<<<<<<<<
 *         with gil:
 *             raise MemoryError("Out of memory trying to allocate an CaseManager object")
 */
    }

    /* "wlsqm/fitter/infra.pyx":317
 *     # init parallel proc
 *     #
 *     self.ntasks  = ntasks             # <<<<<<<<<<<<<<
 *     self.wrks    = <double**>malloc( ntasks*sizeof(double*) )
 *     self.fk_tmps = <double**>malloc( ntasks*sizeof(double*) )
 */
    __pyx_v_self->ntasks = __pyx_v_ntasks;

    /* "wlsqm/fitter/infra.pyx":318
 *     #
 *     self.ntasks  = ntasks
 *     self.wrks    = <double**>malloc( ntasks*sizeof(double*) )             # <<<<<<<<<<<<<<
 *     self.fk_tmps = <double**>malloc( ntasks*sizeof(double*) )
 *     self.fi_tmps = <double**>malloc( ntasks*sizeof(double*) )
 */
    __pyx_v_self->wrks = ((double **)malloc((__pyx_v_ntasks * (sizeof(double *)))));

    /* "wlsqm/fitter/infra.pyx":319
 *     self.ntasks  = ntasks
 *     self.wrks    = <double**>malloc( ntasks*sizeof(double*) )
 *     self.fk_tmps = <double**>malloc( ntasks*sizeof(double*) )             # <<<<<<<<<<<<<<
 *     self.fi_tmps = <double**>malloc( ntasks*sizeof(double*) )
 *     for j in range(ntasks):  # init to NULL needed to gracefully handle errors in CaseManager_allocate()
 */
    __pyx_v_self->fk_tmps = ((double **)malloc((__pyx_v_ntasks * (sizeof(double *)))));

    /* "wlsqm/fitter/infra.pyx":320
 *     self.wrks    = <double**>malloc( ntasks*sizeof(double*) )
 *     self.fk_tmps = <double**>malloc( ntasks*sizeof(double*) )
 *     self.fi_tmps = <double**>malloc( ntasks*sizeof(double*) )             # <<<<<<<<<<<<<<
 *     for j in range(ntasks):  # init to NULL needed to gracefully handle errors in CaseManager_allocate()
 *         self.wrks[j]    = <double*>0
 */
    __pyx_v_self->fi_tmps = ((double **)malloc((__pyx_v_ntasks * (sizeof(double *)))));

    /* "wlsqm/fitter/infra.pyx":321
 *     self.fk_tmps = <double**>malloc( ntasks*sizeof(double*) )
 *     self.fi_tmps = <double**>malloc( ntasks*sizeof(double*) )
 *     for j in range(ntasks):  # init to NULL needed to gracefully handle errors in CaseManager_allocate()             # <<<<<<<<<<<<<<
 *         self.wrks[j]    = <double*>0
 *         self.fk_tmps[j] = <double*>0
 */
    __pyx_t_3 = __pyx_v_ntasks;
    for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
      __pyx_v_j = __pyx_t_4;

      /* "wlsqm/fitter/infra.pyx":322
 *     self.fi_tmps = <double**>malloc( ntasks*sizeof(double*) )
 *     for j in range(ntasks):  # init to NULL needed to gracefully handle errors in CaseManager_allocate()
 *         self.wrks[j]    = <double*>0             # <<<<<<<<<<<<<<
 *         self.fk_tmps[j] = <double*>0
 *         self.fi_tmps[j] = <double*>0
 */
      (__pyx_v_self->wrks[__pyx_v_j]) = ((double *)0);

      /* "wlsqm/fitter/infra.pyx":323
 *     for j in range(ntasks):  # init to NULL needed to gracefully handle errors in CaseManager_allocate()
 *         self.wrks[j]    = <double*>0
 *         self.fk_tmps[j] = <double*>0             # <<<<<<<<<<<<<<
 *         self.fi_tmps[j] = <double*>0
 * 
 */
      (__pyx_v_self->fk_tmps[__pyx_v_j]) = ((double *)0);

      /* "wlsqm/fitter/infra.pyx":324
 *         self.wrks[j]    = <double*>0
 *         self.fk_tmps[j] = <double*>0
 *         self.fi_tmps[j] = <double*>0             # <<<<<<<<<<<<<<
 * 
 *     # init storage for Case pointers
 */
      (__pyx_v_self->fi_tmps[__pyx_v_j]) = ((double *)0);
    }

    /* "wlsqm/fitter/infra.pyx":328
 *     # init storage for Case pointers
 *     #
 *     self.cases = <Case**>malloc( max_cases*sizeof(Case*) )             # <<<<<<<<<<<<<<
 *     self.max_cases = max_cases
 *     self.ncases = 0
 */
    __pyx_v_self->cases = ((struct __pyx_t_5wlsqm_6fitter_5infra_Case **)malloc((__pyx_v_max_cases * (sizeof(struct __pyx_t_5wlsqm_6fitter_5infra_Case *)))));

    /* "wlsqm/fitter/infra.pyx":329
 *     #
 *     self.cases = <Case**>malloc( max_cases*sizeof(Case*) )
 *     self.max_cases = max_cases             # <<<<<<<<<<<<<<
 *     self.ncases = 0
 * 
 */
    __pyx_v_self->max_cases = __pyx_v_max_cases;

    /* "wlsqm/fitter/infra.pyx":330
 *     self.cases = <Case**>malloc( max_cases*sizeof(Case*) )
 *     self.max_cases = max_cases
 *     self.ncases = 0             # <<<<<<<<<<<<<<
 * 
 *     # save metadata
 */
    __pyx_v_self->ncases = 0;

    /* "wlsqm/fitter/infra.pyx":334
 *     # save metadata
 *     #
 *     self.dimension = dimension             # <<<<<<<<<<<<<<
 *     self.do_sens   = do_sens
 *     self.iterative = iterative
 */
    __pyx_v_self->dimension = __pyx_v_dimension;

    /* "wlsqm/fitter/infra.pyx":335
 *     #
 *     self.dimension = dimension
 *     self.do_sens   = do_sens             # <<<<<<<<<<<<<<
 *     self.iterative = iterative
 * 
 */
    __pyx_v_self->do_sens = __pyx_v_do_sens;

    /* "wlsqm/fitter/infra.pyx":336
 *     self.dimension = dimension
 *     self.do_sens   = do_sens
 *     self.iterative = iterative             # <<<<<<<<<<<<<<
 * 
 *     # these will be set up at allocate time
 */
    __pyx_v_self->iterative = __pyx_v_iterative;

    /* "wlsqm/fitter/infra.pyx":340
 *     # these will be set up at allocate time
 *     #
 *     self.mal          = <Allocator*>0             # <<<<<<<<<<<<<<
 *     self.bytes_needed = 0
 * 
 */
    __pyx_v_self->mal = ((struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *)0);

    /* "wlsqm/fitter/infra.pyx":341
 *     #
 *     self.mal          = <Allocator*>0
 *     self.bytes_needed = 0             # <<<<<<<<<<<<<<
 * 
 *     return self
 */
    __pyx_v_self->bytes_needed = 0;

    /* "wlsqm/fitter/infra.pyx":343
 *     self.bytes_needed = 0
 * 
 *     return self             # <<<<<<<<<<<<<<
 * 
 * # Add a case to this manager.
 */
    __pyx_r = __pyx_v_self;
    goto __pyx_L3_return;
  }

  /* "wlsqm/fitter/infra.pyx":306
 *     # Generally speaking, fixing the array size at instantiation time is stupid (an automatically expanding buffer would be better),
 *     # but considering that this class has only one actual user, where we do know max_cases in advance, it is fine for our purposes.
 *     if max_cases < 1:             # <<<<<<<<<<<<<<
 *         with gil:
 *             raise ValueError("Must specify max_cases > 0 when creating a CaseManager.")
 */
  /*finally:*/ {
    __pyx_L3_return: {
      #ifdef WITH_THREAD
      __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      goto __pyx_L0;
    }
    __pyx_L4_error: {
      #ifdef WITH_THREAD
      __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      goto __pyx_L1_error;
    }
  }

  /* "wlsqm/fitter/infra.pyx":303
 * # When processing serially, use the value 1.
 * #
 * cdef CaseManager* CaseManager_new( int dimension, int do_sens, int iterative, int max_cases, int ntasks ) nogil except <CaseManager*>0:             # <<<<<<<<<<<<<<
 *     # Generally speaking, fixing the array size at instantiation time is stupid (an automatically expanding buffer would be better),
 *     # but considering that this class has only one actual user, where we do know max_cases in advance, it is fine for our purposes.
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_AddTraceback("wlsqm.fitter.infra.CaseManager_new", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = ((struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *)0);
  __pyx_L0:;
  #ifdef WITH_THREAD
  PyGILState_Release(__pyx_gilstate_save);
  #endif
  return __pyx_r;
}

/* "wlsqm/fitter/infra.pyx":354
 * # Case_new() will call this automatically, if a manager is specified.
 * #
 * cdef int CaseManager_add( CaseManager* self, Case* case ) nogil except -1:             # <<<<<<<<<<<<<<
 *     # sanity check remaining space
 *     if self.ncases == self.max_cases:
 */

static int __pyx_f_5wlsqm_6fitter_5infra_CaseManager_add(struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *__pyx_v_self, struct __pyx_t_5wlsqm_6fitter_5infra_Case *__pyx_v_case) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save;
  #endif
  __Pyx_RefNannySetupContext("CaseManager_add", 1);

  /* "wlsqm/fitter/infra.pyx":356
 * cdef int CaseManager_add( CaseManager* self, Case* case ) nogil except -1:
 *     # sanity check remaining space
 *     if self.ncases == self.max_cases:             # <<<<<<<<<<<<<<
 *         with gil:
 *             raise MemoryError("Case pointer buffer full, max_cases = %d reached" % self.max_cases)
 */
  /*try:*/ {
    __pyx_t_1 = ((__pyx_v_self->ncases == __pyx_v_self->max_cases) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":357
 *     # sanity check remaining space
 *     if self.ncases == self.max_cases:
 *         with gil:             # <<<<<<<<<<<<<<
 *             raise MemoryError("Case pointer buffer full, max_cases = %d reached" % self.max_cases)
 * 
 */
      {
          #ifdef WITH_THREAD
          PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
          #endif
          /*try:*/ {

            /* "wlsqm/fitter/infra.pyx":358
 *     if self.ncases == self.max_cases:
 *         with gil:
 *             raise MemoryError("Case pointer buffer full, max_cases = %d reached" % self.max_cases)             # <<<<<<<<<<<<<<
 * 
 *     # sanity check Case metadata for compatibility with this CaseManager instance
 */
            __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->max_cases); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 358, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_Case_pointer_buffer_full_max_cas, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 358, __pyx_L8_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_ERR(0, 358, __pyx_L8_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 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 358, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_Raise(__pyx_t_3, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __PYX_ERR(0, 358, __pyx_L8_error)
          }

          /* "wlsqm/fitter/infra.pyx":357
 *     # sanity check remaining space
 *     if self.ncases == self.max_cases:
 *         with gil:             # <<<<<<<<<<<<<<
 *             raise MemoryError("Case pointer buffer full, max_cases = %d reached" % self.max_cases)
 * 
 */
          /*finally:*/ {
            __pyx_L8_error: {
              #ifdef WITH_THREAD
              PyGILState_Release(__pyx_gilstate_save);
              #endif
              goto __pyx_L4_error;
            }
          }
      }

      /* "wlsqm/fitter/infra.pyx":356
 * cdef int CaseManager_add( CaseManager* self, Case* case ) nogil except -1:
 *     # sanity check remaining space
 *     if self.ncases == self.max_cases:             # <<<<<<<<<<<<<<
 *         with gil:
 *             raise MemoryError("Case pointer buffer full, max_cases = %d reached" % self.max_cases)
 */
    }

    /* "wlsqm/fitter/infra.pyx":361
 * 
 *     # sanity check Case metadata for compatibility with this CaseManager instance
 *     if case.dimension != self.dimension:             # <<<<<<<<<<<<<<
 *         with gil:
 *             raise ValueError("Cannot add case with different dimension = %d; this manager has dimension = %d" % (case.dimension, self.dimension))
 */
    __pyx_t_1 = ((__pyx_v_case->dimension != __pyx_v_self->dimension) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":362
 *     # sanity check Case metadata for compatibility with this CaseManager instance
 *     if case.dimension != self.dimension:
 *         with gil:             # <<<<<<<<<<<<<<
 *             raise ValueError("Cannot add case with different dimension = %d; this manager has dimension = %d" % (case.dimension, self.dimension))
 *     if case.do_sens != self.do_sens:
 */
      {
          #ifdef WITH_THREAD
          PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
          #endif
          /*try:*/ {

            /* "wlsqm/fitter/infra.pyx":363
 *     if case.dimension != self.dimension:
 *         with gil:
 *             raise ValueError("Cannot add case with different dimension = %d; this manager has dimension = %d" % (case.dimension, self.dimension))             # <<<<<<<<<<<<<<
 *     if case.do_sens != self.do_sens:
 *         with gil:
 */
            __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_case->dimension); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 363, __pyx_L12_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->dimension); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 363, __pyx_L12_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 363, __pyx_L12_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_2);
            PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
            __pyx_t_3 = 0;
            __pyx_t_2 = 0;
            __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_Cannot_add_case_with_different_d, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 363, __pyx_L12_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 363, __pyx_L12_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 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 363, __pyx_L12_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_Raise(__pyx_t_2, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __PYX_ERR(0, 363, __pyx_L12_error)
          }

          /* "wlsqm/fitter/infra.pyx":362
 *     # sanity check Case metadata for compatibility with this CaseManager instance
 *     if case.dimension != self.dimension:
 *         with gil:             # <<<<<<<<<<<<<<
 *             raise ValueError("Cannot add case with different dimension = %d; this manager has dimension = %d" % (case.dimension, self.dimension))
 *     if case.do_sens != self.do_sens:
 */
          /*finally:*/ {
            __pyx_L12_error: {
              #ifdef WITH_THREAD
              PyGILState_Release(__pyx_gilstate_save);
              #endif
              goto __pyx_L4_error;
            }
          }
      }

      /* "wlsqm/fitter/infra.pyx":361
 * 
 *     # sanity check Case metadata for compatibility with this CaseManager instance
 *     if case.dimension != self.dimension:             # <<<<<<<<<<<<<<
 *         with gil:
 *             raise ValueError("Cannot add case with different dimension = %d; this manager has dimension = %d" % (case.dimension, self.dimension))
 */
    }

    /* "wlsqm/fitter/infra.pyx":364
 *         with gil:
 *             raise ValueError("Cannot add case with different dimension = %d; this manager has dimension = %d" % (case.dimension, self.dimension))
 *     if case.do_sens != self.do_sens:             # <<<<<<<<<<<<<<
 *         with gil:
 *             raise ValueError("Cannot add case with different setting for do_sens = %d; this manager has do_sens = %d" % (case.do_sens, self.do_sens))
 */
    __pyx_t_1 = ((__pyx_v_case->do_sens != __pyx_v_self->do_sens) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":365
 *             raise ValueError("Cannot add case with different dimension = %d; this manager has dimension = %d" % (case.dimension, self.dimension))
 *     if case.do_sens != self.do_sens:
 *         with gil:             # <<<<<<<<<<<<<<
 *             raise ValueError("Cannot add case with different setting for do_sens = %d; this manager has do_sens = %d" % (case.do_sens, self.do_sens))
 *     if case.iterative != self.iterative:
 */
      {
          #ifdef WITH_THREAD
          PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
          #endif
          /*try:*/ {

            /* "wlsqm/fitter/infra.pyx":366
 *     if case.do_sens != self.do_sens:
 *         with gil:
 *             raise ValueError("Cannot add case with different setting for do_sens = %d; this manager has do_sens = %d" % (case.do_sens, self.do_sens))             # <<<<<<<<<<<<<<
 *     if case.iterative != self.iterative:
 *         with gil:
 */
            __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_case->do_sens); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 366, __pyx_L16_error)
            __Pyx_GOTREF(__pyx_t_2);
            __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_self->do_sens); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 366, __pyx_L16_error)
            __Pyx_GOTREF(__pyx_t_4);
            __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 366, __pyx_L16_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_GIVEREF(__pyx_t_2);
            PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
            __Pyx_GIVEREF(__pyx_t_4);
            PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_4);
            __pyx_t_2 = 0;
            __pyx_t_4 = 0;
            __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_Cannot_add_case_with_different_s, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 366, __pyx_L16_error)
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 366, __pyx_L16_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_GIVEREF(__pyx_t_4);
            PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
            __pyx_t_4 = 0;
            __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 366, __pyx_L16_error)
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __Pyx_Raise(__pyx_t_4, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            __PYX_ERR(0, 366, __pyx_L16_error)
          }

          /* "wlsqm/fitter/infra.pyx":365
 *             raise ValueError("Cannot add case with different dimension = %d; this manager has dimension = %d" % (case.dimension, self.dimension))
 *     if case.do_sens != self.do_sens:
 *         with gil:             # <<<<<<<<<<<<<<
 *             raise ValueError("Cannot add case with different setting for do_sens = %d; this manager has do_sens = %d" % (case.do_sens, self.do_sens))
 *     if case.iterative != self.iterative:
 */
          /*finally:*/ {
            __pyx_L16_error: {
              #ifdef WITH_THREAD
              PyGILState_Release(__pyx_gilstate_save);
              #endif
              goto __pyx_L4_error;
            }
          }
      }

      /* "wlsqm/fitter/infra.pyx":364
 *         with gil:
 *             raise ValueError("Cannot add case with different dimension = %d; this manager has dimension = %d" % (case.dimension, self.dimension))
 *     if case.do_sens != self.do_sens:             # <<<<<<<<<<<<<<
 *         with gil:
 *             raise ValueError("Cannot add case with different setting for do_sens = %d; this manager has do_sens = %d" % (case.do_sens, self.do_sens))
 */
    }

    /* "wlsqm/fitter/infra.pyx":367
 *         with gil:
 *             raise ValueError("Cannot add case with different setting for do_sens = %d; this manager has do_sens = %d" % (case.do_sens, self.do_sens))
 *     if case.iterative != self.iterative:             # <<<<<<<<<<<<<<
 *         with gil:
 *             raise ValueError("Cannot add case with different setting for iterative = %d; this manager has iterative = %d" % (case.iterative, self.iterative))
 */
    __pyx_t_1 = ((__pyx_v_case->iterative != __pyx_v_self->iterative) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":368
 *             raise ValueError("Cannot add case with different setting for do_sens = %d; this manager has do_sens = %d" % (case.do_sens, self.do_sens))
 *     if case.iterative != self.iterative:
 *         with gil:             # <<<<<<<<<<<<<<
 *             raise ValueError("Cannot add case with different setting for iterative = %d; this manager has iterative = %d" % (case.iterative, self.iterative))
 * 
 */
      {
          #ifdef WITH_THREAD
          PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
          #endif
          /*try:*/ {

            /* "wlsqm/fitter/infra.pyx":369
 *     if case.iterative != self.iterative:
 *         with gil:
 *             raise ValueError("Cannot add case with different setting for iterative = %d; this manager has iterative = %d" % (case.iterative, self.iterative))             # <<<<<<<<<<<<<<
 * 
 *     # add the Case to the managed cases.
 */
            __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_case->iterative); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 369, __pyx_L20_error)
            __Pyx_GOTREF(__pyx_t_4);
            __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->iterative); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 369, __pyx_L20_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 369, __pyx_L20_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_GIVEREF(__pyx_t_4);
            PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
            __Pyx_GIVEREF(__pyx_t_3);
            PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_3);
            __pyx_t_4 = 0;
            __pyx_t_3 = 0;
            __pyx_t_3 = __Pyx_PyString_Format(__pyx_kp_s_Cannot_add_case_with_different_s_2, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 369, __pyx_L20_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_ERR(0, 369, __pyx_L20_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 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 369, __pyx_L20_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_Raise(__pyx_t_3, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __PYX_ERR(0, 369, __pyx_L20_error)
          }

          /* "wlsqm/fitter/infra.pyx":368
 *             raise ValueError("Cannot add case with different setting for do_sens = %d; this manager has do_sens = %d" % (case.do_sens, self.do_sens))
 *     if case.iterative != self.iterative:
 *         with gil:             # <<<<<<<<<<<<<<
 *             raise ValueError("Cannot add case with different setting for iterative = %d; this manager has iterative = %d" % (case.iterative, self.iterative))
 * 
 */
          /*finally:*/ {
            __pyx_L20_error: {
              #ifdef WITH_THREAD
              PyGILState_Release(__pyx_gilstate_save);
              #endif
              goto __pyx_L4_error;
            }
          }
      }

      /* "wlsqm/fitter/infra.pyx":367
 *         with gil:
 *             raise ValueError("Cannot add case with different setting for do_sens = %d; this manager has do_sens = %d" % (case.do_sens, self.do_sens))
 *     if case.iterative != self.iterative:             # <<<<<<<<<<<<<<
 *         with gil:
 *             raise ValueError("Cannot add case with different setting for iterative = %d; this manager has iterative = %d" % (case.iterative, self.iterative))
 */
    }

    /* "wlsqm/fitter/infra.pyx":372
 * 
 *     # add the Case to the managed cases.
 *     self.cases[self.ncases] = case             # <<<<<<<<<<<<<<
 *     self.ncases += 1
 * 
 */
    (__pyx_v_self->cases[__pyx_v_self->ncases]) = __pyx_v_case;

    /* "wlsqm/fitter/infra.pyx":373
 *     # add the Case to the managed cases.
 *     self.cases[self.ncases] = case
 *     self.ncases += 1             # <<<<<<<<<<<<<<
 * 
 *     return 0
 */
    __pyx_v_self->ncases = (__pyx_v_self->ncases + 1);

    /* "wlsqm/fitter/infra.pyx":375
 *     self.ncases += 1
 * 
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * # Finish adding Case objects. Prepare the manaager for solving.
 */
    __pyx_r = 0;
    goto __pyx_L3_return;
  }

  /* "wlsqm/fitter/infra.pyx":356
 * cdef int CaseManager_add( CaseManager* self, Case* case ) nogil except -1:
 *     # sanity check remaining space
 *     if self.ncases == self.max_cases:             # <<<<<<<<<<<<<<
 *         with gil:
 *             raise MemoryError("Case pointer buffer full, max_cases = %d reached" % self.max_cases)
 */
  /*finally:*/ {
    __pyx_L3_return: {
      #ifdef WITH_THREAD
      __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      goto __pyx_L0;
    }
    __pyx_L4_error: {
      #ifdef WITH_THREAD
      __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      goto __pyx_L1_error;
    }
  }

  /* "wlsqm/fitter/infra.pyx":354
 * # Case_new() will call this automatically, if a manager is specified.
 * #
 * cdef int CaseManager_add( CaseManager* self, Case* case ) nogil except -1:             # <<<<<<<<<<<<<<
 *     # sanity check remaining space
 *     if self.ncases == self.max_cases:
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("wlsqm.fitter.infra.CaseManager_add", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  #ifdef WITH_THREAD
  PyGILState_Release(__pyx_gilstate_save);
  #endif
  return __pyx_r;
}

/* "wlsqm/fitter/infra.pyx":381
 * # This should be called exactly once (per instance of CaseManager), after all cases have been CaseManager_add()'d.
 * #
 * cdef int CaseManager_commit( CaseManager* self ) nogil except -1:             # <<<<<<<<<<<<<<
 *     return CaseManager_allocate( self )
 * 
 */

static int __pyx_f_5wlsqm_6fitter_5infra_CaseManager_commit(struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *__pyx_v_self) {
  int __pyx_r;
  int __pyx_t_1;

  /* "wlsqm/fitter/infra.pyx":382
 * #
 * cdef int CaseManager_commit( CaseManager* self ) nogil except -1:
 *     return CaseManager_allocate( self )             # <<<<<<<<<<<<<<
 * 
 * # Create the memory buffer that will contain the data arrays for all cases.
 */
  __pyx_t_1 = __pyx_f_5wlsqm_6fitter_5infra_CaseManager_allocate(__pyx_v_self); if (unlikely(__pyx_t_1 == -1)) __PYX_ERR(0, 382, __pyx_L1_error)
  __pyx_r = __pyx_t_1;
  goto __pyx_L0;

  /* "wlsqm/fitter/infra.pyx":381
 * # This should be called exactly once (per instance of CaseManager), after all cases have been CaseManager_add()'d.
 * #
 * cdef int CaseManager_commit( CaseManager* self ) nogil except -1:             # <<<<<<<<<<<<<<
 *     return CaseManager_allocate( self )
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  {
    #ifdef WITH_THREAD
    PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
    #endif
    __Pyx_AddTraceback("wlsqm.fitter.infra.CaseManager_commit", __pyx_clineno, __pyx_lineno, __pyx_filename);
    #ifdef WITH_THREAD
    PyGILState_Release(__pyx_gilstate_save);
    #endif
  }
  __pyx_r = -1;
  __pyx_L0:;
  return __pyx_r;
}

/* "wlsqm/fitter/infra.pyx":386
 * # Create the memory buffer that will contain the data arrays for all cases.
 * #
 * cdef int CaseManager_allocate( CaseManager* self ) nogil except -1:             # <<<<<<<<<<<<<<
 *     cdef int j, problem_instance_bytes=0, task_bytes=0
 *     cdef int max_nk=0, max_no=0, max_nr=0
 */

static int __pyx_f_5wlsqm_6fitter_5infra_CaseManager_allocate(struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *__pyx_v_self) {
  int __pyx_v_j;
  int __pyx_v_problem_instance_bytes;
  int __pyx_v_task_bytes;
  int __pyx_v_max_nk;
  int __pyx_v_max_no;
  int __pyx_v_max_nr;
  int __pyx_v_size_wrk;
  int __pyx_v_size_fk_tmp;
  int __pyx_v_size_fi_tmp;
  struct __pyx_t_5wlsqm_6fitter_5infra_BufferSizes __pyx_v_sizes;
  struct __pyx_t_5wlsqm_6fitter_5infra_Case *__pyx_v_case;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_t_8;
  struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *__pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save;
  #endif
  __Pyx_RefNannySetupContext("CaseManager_allocate", 1);

  /* "wlsqm/fitter/infra.pyx":387
 * #
 * cdef int CaseManager_allocate( CaseManager* self ) nogil except -1:
 *     cdef int j, problem_instance_bytes=0, task_bytes=0             # <<<<<<<<<<<<<<
 *     cdef int max_nk=0, max_no=0, max_nr=0
 *     cdef int size_wrk=0, size_fk_tmp=0, size_fi_tmp=0
 */
  /*try:*/ {
    __pyx_v_problem_instance_bytes = 0;
    __pyx_v_task_bytes = 0;

    /* "wlsqm/fitter/infra.pyx":388
 * cdef int CaseManager_allocate( CaseManager* self ) nogil except -1:
 *     cdef int j, problem_instance_bytes=0, task_bytes=0
 *     cdef int max_nk=0, max_no=0, max_nr=0             # <<<<<<<<<<<<<<
 *     cdef int size_wrk=0, size_fk_tmp=0, size_fi_tmp=0
 *     cdef BufferSizes sizes
 */
    __pyx_v_max_nk = 0;
    __pyx_v_max_no = 0;
    __pyx_v_max_nr = 0;

    /* "wlsqm/fitter/infra.pyx":389
 *     cdef int j, problem_instance_bytes=0, task_bytes=0
 *     cdef int max_nk=0, max_no=0, max_nr=0
 *     cdef int size_wrk=0, size_fk_tmp=0, size_fi_tmp=0             # <<<<<<<<<<<<<<
 *     cdef BufferSizes sizes
 *     cdef Case* case
 */
    __pyx_v_size_wrk = 0;
    __pyx_v_size_fk_tmp = 0;
    __pyx_v_size_fi_tmp = 0;

    /* "wlsqm/fitter/infra.pyx":392
 *     cdef BufferSizes sizes
 *     cdef Case* case
 *     with gil:             # <<<<<<<<<<<<<<
 *         try:
 *             if self.ncases == 0:
 */
    {
        #ifdef WITH_THREAD
        PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
        #endif
        /*try:*/ {

          /* "wlsqm/fitter/infra.pyx":393
 *     cdef Case* case
 *     with gil:
 *         try:             # <<<<<<<<<<<<<<
 *             if self.ncases == 0:
 *                 raise ValueError("No cases; add some before allocating")
 */
          {
            __Pyx_PyThreadState_declare
            __Pyx_PyThreadState_assign
            __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
            __Pyx_XGOTREF(__pyx_t_1);
            __Pyx_XGOTREF(__pyx_t_2);
            __Pyx_XGOTREF(__pyx_t_3);
            /*try:*/ {

              /* "wlsqm/fitter/infra.pyx":394
 *     with gil:
 *         try:
 *             if self.ncases == 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("No cases; add some before allocating")
 * 
 */
              __pyx_t_4 = ((__pyx_v_self->ncases == 0) != 0);
              if (__pyx_t_4) {

                /* "wlsqm/fitter/infra.pyx":395
 *         try:
 *             if self.ncases == 0:
 *                 raise ValueError("No cases; add some before allocating")             # <<<<<<<<<<<<<<
 * 
 *             # Determine total amount of memory needed by the per-problem-instance arrays.
 */
                __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 395, __pyx_L9_error)
                __Pyx_GOTREF(__pyx_t_5);
                __Pyx_Raise(__pyx_t_5, 0, 0, 0);
                __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                __PYX_ERR(0, 395, __pyx_L9_error)

                /* "wlsqm/fitter/infra.pyx":394
 *     with gil:
 *         try:
 *             if self.ncases == 0:             # <<<<<<<<<<<<<<
 *                 raise ValueError("No cases; add some before allocating")
 * 
 */
              }

              /* "wlsqm/fitter/infra.pyx":401
 *             # Also, find max_nk for allocation of per-task arrays. (nk may vary across cases)
 *             #
 *             for j in range(self.ncases):             # <<<<<<<<<<<<<<
 *                 case = self.cases[j]
 *                 Case_determine_sizes( case, &sizes )
 */
              __pyx_t_6 = __pyx_v_self->ncases;
              for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) {
                __pyx_v_j = __pyx_t_7;

                /* "wlsqm/fitter/infra.pyx":402
 *             #
 *             for j in range(self.ncases):
 *                 case = self.cases[j]             # <<<<<<<<<<<<<<
 *                 Case_determine_sizes( case, &sizes )
 * 
 */
                __pyx_v_case = (__pyx_v_self->cases[__pyx_v_j]);

                /* "wlsqm/fitter/infra.pyx":403
 *             for j in range(self.ncases):
 *                 case = self.cases[j]
 *                 Case_determine_sizes( case, &sizes )             # <<<<<<<<<<<<<<
 * 
 *                 problem_instance_bytes += sizes.total
 */
                __pyx_f_5wlsqm_6fitter_5infra_Case_determine_sizes(__pyx_v_case, (&__pyx_v_sizes));

                /* "wlsqm/fitter/infra.pyx":405
 *                 Case_determine_sizes( case, &sizes )
 * 
 *                 problem_instance_bytes += sizes.total             # <<<<<<<<<<<<<<
 * 
 *                 if case.nk > max_nk:
 */
                __pyx_v_problem_instance_bytes = (__pyx_v_problem_instance_bytes + __pyx_v_sizes.total);

                /* "wlsqm/fitter/infra.pyx":407
 *                 problem_instance_bytes += sizes.total
 * 
 *                 if case.nk > max_nk:             # <<<<<<<<<<<<<<
 *                     max_nk = case.nk
 *                 if case.no > max_no:
 */
                __pyx_t_4 = ((__pyx_v_case->nk > __pyx_v_max_nk) != 0);
                if (__pyx_t_4) {

                  /* "wlsqm/fitter/infra.pyx":408
 * 
 *                 if case.nk > max_nk:
 *                     max_nk = case.nk             # <<<<<<<<<<<<<<
 *                 if case.no > max_no:
 *                     max_no = case.no
 */
                  __pyx_t_8 = __pyx_v_case->nk;
                  __pyx_v_max_nk = __pyx_t_8;

                  /* "wlsqm/fitter/infra.pyx":407
 *                 problem_instance_bytes += sizes.total
 * 
 *                 if case.nk > max_nk:             # <<<<<<<<<<<<<<
 *                     max_nk = case.nk
 *                 if case.no > max_no:
 */
                }

                /* "wlsqm/fitter/infra.pyx":409
 *                 if case.nk > max_nk:
 *                     max_nk = case.nk
 *                 if case.no > max_no:             # <<<<<<<<<<<<<<
 *                     max_no = case.no
 *                 if case.nr > max_nr:
 */
                __pyx_t_4 = ((__pyx_v_case->no > __pyx_v_max_no) != 0);
                if (__pyx_t_4) {

                  /* "wlsqm/fitter/infra.pyx":410
 *                     max_nk = case.nk
 *                 if case.no > max_no:
 *                     max_no = case.no             # <<<<<<<<<<<<<<
 *                 if case.nr > max_nr:
 *                     max_nr = case.nr
 */
                  __pyx_t_8 = __pyx_v_case->no;
                  __pyx_v_max_no = __pyx_t_8;

                  /* "wlsqm/fitter/infra.pyx":409
 *                 if case.nk > max_nk:
 *                     max_nk = case.nk
 *                 if case.no > max_no:             # <<<<<<<<<<<<<<
 *                     max_no = case.no
 *                 if case.nr > max_nr:
 */
                }

                /* "wlsqm/fitter/infra.pyx":411
 *                 if case.no > max_no:
 *                     max_no = case.no
 *                 if case.nr > max_nr:             # <<<<<<<<<<<<<<
 *                     max_nr = case.nr
 * 
 */
                __pyx_t_4 = ((__pyx_v_case->nr > __pyx_v_max_nr) != 0);
                if (__pyx_t_4) {

                  /* "wlsqm/fitter/infra.pyx":412
 *                     max_no = case.no
 *                 if case.nr > max_nr:
 *                     max_nr = case.nr             # <<<<<<<<<<<<<<
 * 
 *             # Determine maximum needed size for one instance of the per-task arrays,
 */
                  __pyx_t_8 = __pyx_v_case->nr;
                  __pyx_v_max_nr = __pyx_t_8;

                  /* "wlsqm/fitter/infra.pyx":411
 *                 if case.no > max_no:
 *                     max_no = case.no
 *                 if case.nr > max_nr:             # <<<<<<<<<<<<<<
 *                     max_nr = case.nr
 * 
 */
                }
              }

              /* "wlsqm/fitter/infra.pyx":417
 *             # when working on this set of cases.
 *             #
 *             if self.do_sens:             # <<<<<<<<<<<<<<
 *                 size_wrk = max_nr*(max_nk + 1)*sizeof(double)
 *             else:
 */
              __pyx_t_4 = (__pyx_v_self->do_sens != 0);
              if (__pyx_t_4) {

                /* "wlsqm/fitter/infra.pyx":418
 *             #
 *             if self.do_sens:
 *                 size_wrk = max_nr*(max_nk + 1)*sizeof(double)             # <<<<<<<<<<<<<<
 *             else:
 *                 size_wrk = max_nr*sizeof(double)
 */
                __pyx_v_size_wrk = ((__pyx_v_max_nr * (__pyx_v_max_nk + 1)) * (sizeof(double)));

                /* "wlsqm/fitter/infra.pyx":417
 *             # when working on this set of cases.
 *             #
 *             if self.do_sens:             # <<<<<<<<<<<<<<
 *                 size_wrk = max_nr*(max_nk + 1)*sizeof(double)
 *             else:
 */
                goto __pyx_L23;
              }

              /* "wlsqm/fitter/infra.pyx":420
 *                 size_wrk = max_nr*(max_nk + 1)*sizeof(double)
 *             else:
 *                 size_wrk = max_nr*sizeof(double)             # <<<<<<<<<<<<<<
 * 
 *             if self.iterative:
 */
              /*else*/ {
                __pyx_v_size_wrk = (__pyx_v_max_nr * (sizeof(double)));
              }
              __pyx_L23:;

              /* "wlsqm/fitter/infra.pyx":422
 *                 size_wrk = max_nr*sizeof(double)
 * 
 *             if self.iterative:             # <<<<<<<<<<<<<<
 *                 size_fk_tmp = max_nk*sizeof(double)
 *                 size_fi_tmp = max_no*sizeof(double)
 */
              __pyx_t_4 = (__pyx_v_self->iterative != 0);
              if (__pyx_t_4) {

                /* "wlsqm/fitter/infra.pyx":423
 * 
 *             if self.iterative:
 *                 size_fk_tmp = max_nk*sizeof(double)             # <<<<<<<<<<<<<<
 *                 size_fi_tmp = max_no*sizeof(double)
 *             else:
 */
                __pyx_v_size_fk_tmp = (__pyx_v_max_nk * (sizeof(double)));

                /* "wlsqm/fitter/infra.pyx":424
 *             if self.iterative:
 *                 size_fk_tmp = max_nk*sizeof(double)
 *                 size_fi_tmp = max_no*sizeof(double)             # <<<<<<<<<<<<<<
 *             else:
 *                 size_fk_tmp = 0
 */
                __pyx_v_size_fi_tmp = (__pyx_v_max_no * (sizeof(double)));

                /* "wlsqm/fitter/infra.pyx":422
 *                 size_wrk = max_nr*sizeof(double)
 * 
 *             if self.iterative:             # <<<<<<<<<<<<<<
 *                 size_fk_tmp = max_nk*sizeof(double)
 *                 size_fi_tmp = max_no*sizeof(double)
 */
                goto __pyx_L24;
              }

              /* "wlsqm/fitter/infra.pyx":426
 *                 size_fi_tmp = max_no*sizeof(double)
 *             else:
 *                 size_fk_tmp = 0             # <<<<<<<<<<<<<<
 *                 size_fi_tmp = 0
 * 
 */
              /*else*/ {
                __pyx_v_size_fk_tmp = 0;

                /* "wlsqm/fitter/infra.pyx":427
 *             else:
 *                 size_fk_tmp = 0
 *                 size_fi_tmp = 0             # <<<<<<<<<<<<<<
 * 
 *             # The total for the per-task arrays is then just ntasks copies:
 */
                __pyx_v_size_fi_tmp = 0;
              }
              __pyx_L24:;

              /* "wlsqm/fitter/infra.pyx":431
 *             # The total for the per-task arrays is then just ntasks copies:
 *             #
 *             task_bytes = self.ntasks*(size_wrk + size_fk_tmp + size_fi_tmp)             # <<<<<<<<<<<<<<
 * 
 *             # Final total of memory needed is thus:
 */
              __pyx_v_task_bytes = (__pyx_v_self->ntasks * ((__pyx_v_size_wrk + __pyx_v_size_fk_tmp) + __pyx_v_size_fi_tmp));

              /* "wlsqm/fitter/infra.pyx":435
 *             # Final total of memory needed is thus:
 *             #
 *             self.bytes_needed = task_bytes + problem_instance_bytes             # <<<<<<<<<<<<<<
 * 
 *             # NOTE: this may be big (e.g. ~5.5kB per problem instance for dimension=2, order=4, nk=25,
 */
              __pyx_v_self->bytes_needed = (__pyx_v_task_bytes + __pyx_v_problem_instance_bytes);

              /* "wlsqm/fitter/infra.pyx":443
 *             # we can simply let the buffer be - there is no need to re-create it for each run.
 *             #
 *             self.mal = Allocator_new( mode=ALLOC_MODE_ONEBIGBUFFER, total_size_bytes=self.bytes_needed )             # <<<<<<<<<<<<<<
 * 
 *             # Allocate the per-task arrays.
 */
              __pyx_t_9 = __pyx_f_5wlsqm_6fitter_5infra_Allocator_new(__pyx_v_5wlsqm_6fitter_5infra_ALLOC_MODE_ONEBIGBUFFER, __pyx_v_self->bytes_needed); if (unlikely(__pyx_t_9 == ((struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *)0))) __PYX_ERR(0, 443, __pyx_L9_error)
              __pyx_v_self->mal = __pyx_t_9;

              /* "wlsqm/fitter/infra.pyx":447
 *             # Allocate the per-task arrays.
 *             #
 *             for j in range(self.ntasks):             # <<<<<<<<<<<<<<
 *                 self.wrks[j]    = <double*>Allocator_malloc( self.mal, size_wrk )
 *                 self.fk_tmps[j] = <double*>Allocator_malloc( self.mal, size_fk_tmp )
 */
              __pyx_t_6 = __pyx_v_self->ntasks;
              for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) {
                __pyx_v_j = __pyx_t_7;

                /* "wlsqm/fitter/infra.pyx":448
 *             #
 *             for j in range(self.ntasks):
 *                 self.wrks[j]    = <double*>Allocator_malloc( self.mal, size_wrk )             # <<<<<<<<<<<<<<
 *                 self.fk_tmps[j] = <double*>Allocator_malloc( self.mal, size_fk_tmp )
 *                 self.fi_tmps[j] = <double*>Allocator_malloc( self.mal, size_fi_tmp )
 */
                (__pyx_v_self->wrks[__pyx_v_j]) = ((double *)__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc(__pyx_v_self->mal, __pyx_v_size_wrk));

                /* "wlsqm/fitter/infra.pyx":449
 *             for j in range(self.ntasks):
 *                 self.wrks[j]    = <double*>Allocator_malloc( self.mal, size_wrk )
 *                 self.fk_tmps[j] = <double*>Allocator_malloc( self.mal, size_fk_tmp )             # <<<<<<<<<<<<<<
 *                 self.fi_tmps[j] = <double*>Allocator_malloc( self.mal, size_fi_tmp )
 * 
 */
                (__pyx_v_self->fk_tmps[__pyx_v_j]) = ((double *)__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc(__pyx_v_self->mal, __pyx_v_size_fk_tmp));

                /* "wlsqm/fitter/infra.pyx":450
 *                 self.wrks[j]    = <double*>Allocator_malloc( self.mal, size_wrk )
 *                 self.fk_tmps[j] = <double*>Allocator_malloc( self.mal, size_fk_tmp )
 *                 self.fi_tmps[j] = <double*>Allocator_malloc( self.mal, size_fi_tmp )             # <<<<<<<<<<<<<<
 * 
 *             # Finally, tell the Case objects to allocate their memory.
 */
                (__pyx_v_self->fi_tmps[__pyx_v_j]) = ((double *)__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc(__pyx_v_self->mal, __pyx_v_size_fi_tmp));
              }

              /* "wlsqm/fitter/infra.pyx":456
 *             # They will automatically grab our allocator, since they are in managed mode.
 *             #
 *             for j in range(self.ncases):             # <<<<<<<<<<<<<<
 *                 Case_allocate( self.cases[j] )
 * 
 */
              __pyx_t_6 = __pyx_v_self->ncases;
              for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) {
                __pyx_v_j = __pyx_t_7;

                /* "wlsqm/fitter/infra.pyx":457
 *             #
 *             for j in range(self.ncases):
 *                 Case_allocate( self.cases[j] )             # <<<<<<<<<<<<<<
 * 
 *         except:
 */
                __pyx_t_8 = __pyx_f_5wlsqm_6fitter_5infra_Case_allocate((__pyx_v_self->cases[__pyx_v_j])); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 457, __pyx_L9_error)
              }

              /* "wlsqm/fitter/infra.pyx":393
 *     cdef Case* case
 *     with gil:
 *         try:             # <<<<<<<<<<<<<<
 *             if self.ncases == 0:
 *                 raise ValueError("No cases; add some before allocating")
 */
            }
            __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
            goto __pyx_L16_try_end;
            __pyx_L9_error:;
            __Pyx_PyThreadState_assign
            __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;

            /* "wlsqm/fitter/infra.pyx":459
 *                 Case_allocate( self.cases[j] )
 * 
 *         except:             # <<<<<<<<<<<<<<
 *             # on error, leave the CaseManager in the state it was in before this method was called.
 *             CaseManager_deallocate( self )
 */
            /*except:*/ {
              __Pyx_AddTraceback("wlsqm.fitter.infra.CaseManager_allocate", __pyx_clineno, __pyx_lineno, __pyx_filename);
              if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_10, &__pyx_t_11) < 0) __PYX_ERR(0, 459, __pyx_L11_except_error)
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_GOTREF(__pyx_t_11);

              /* "wlsqm/fitter/infra.pyx":461
 *         except:
 *             # on error, leave the CaseManager in the state it was in before this method was called.
 *             CaseManager_deallocate( self )             # <<<<<<<<<<<<<<
 *             raise
 * 
 */
              __pyx_f_5wlsqm_6fitter_5infra_CaseManager_deallocate(__pyx_v_self);

              /* "wlsqm/fitter/infra.pyx":462
 *             # on error, leave the CaseManager in the state it was in before this method was called.
 *             CaseManager_deallocate( self )
 *             raise             # <<<<<<<<<<<<<<
 * 
 *     return 0
 */
              __Pyx_GIVEREF(__pyx_t_5);
              __Pyx_GIVEREF(__pyx_t_10);
              __Pyx_XGIVEREF(__pyx_t_11);
              __Pyx_ErrRestoreWithState(__pyx_t_5, __pyx_t_10, __pyx_t_11);
              __pyx_t_5 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; 
              __PYX_ERR(0, 462, __pyx_L11_except_error)
            }
            __pyx_L11_except_error:;

            /* "wlsqm/fitter/infra.pyx":393
 *     cdef Case* case
 *     with gil:
 *         try:             # <<<<<<<<<<<<<<
 *             if self.ncases == 0:
 *                 raise ValueError("No cases; add some before allocating")
 */
            __Pyx_PyThreadState_assign
            __Pyx_XGIVEREF(__pyx_t_1);
            __Pyx_XGIVEREF(__pyx_t_2);
            __Pyx_XGIVEREF(__pyx_t_3);
            __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
            goto __pyx_L7_error;
            __pyx_L16_try_end:;
          }
        }

        /* "wlsqm/fitter/infra.pyx":392
 *     cdef BufferSizes sizes
 *     cdef Case* case
 *     with gil:             # <<<<<<<<<<<<<<
 *         try:
 *             if self.ncases == 0:
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            PyGILState_Release(__pyx_gilstate_save);
            #endif
            goto __pyx_L8;
          }
          __pyx_L7_error: {
            #ifdef WITH_THREAD
            PyGILState_Release(__pyx_gilstate_save);
            #endif
            goto __pyx_L4_error;
          }
          __pyx_L8:;
        }
    }

    /* "wlsqm/fitter/infra.pyx":464
 *             raise
 * 
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * # The opposite of CaseManager_allocate().
 */
    __pyx_r = 0;
    goto __pyx_L3_return;
  }

  /* "wlsqm/fitter/infra.pyx":387
 * #
 * cdef int CaseManager_allocate( CaseManager* self ) nogil except -1:
 *     cdef int j, problem_instance_bytes=0, task_bytes=0             # <<<<<<<<<<<<<<
 *     cdef int max_nk=0, max_no=0, max_nr=0
 *     cdef int size_wrk=0, size_fk_tmp=0, size_fi_tmp=0
 */
  /*finally:*/ {
    __pyx_L3_return: {
      #ifdef WITH_THREAD
      __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      goto __pyx_L0;
    }
    __pyx_L4_error: {
      #ifdef WITH_THREAD
      __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      goto __pyx_L1_error;
    }
  }

  /* "wlsqm/fitter/infra.pyx":386
 * # Create the memory buffer that will contain the data arrays for all cases.
 * #
 * cdef int CaseManager_allocate( CaseManager* self ) nogil except -1:             # <<<<<<<<<<<<<<
 *     cdef int j, problem_instance_bytes=0, task_bytes=0
 *     cdef int max_nk=0, max_no=0, max_nr=0
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("wlsqm.fitter.infra.CaseManager_allocate", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  #ifdef WITH_THREAD
  PyGILState_Release(__pyx_gilstate_save);
  #endif
  return __pyx_r;
}

/* "wlsqm/fitter/infra.pyx":468
 * # The opposite of CaseManager_allocate().
 * #
 * cdef void CaseManager_deallocate( CaseManager* self ) nogil:             # <<<<<<<<<<<<<<
 *     if self != <CaseManager*>0:
 *         self.bytes_needed = 0
 */

static void __pyx_f_5wlsqm_6fitter_5infra_CaseManager_deallocate(struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *__pyx_v_self) {
  int __pyx_v_j;
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;

  /* "wlsqm/fitter/infra.pyx":469
 * #
 * cdef void CaseManager_deallocate( CaseManager* self ) nogil:
 *     if self != <CaseManager*>0:             # <<<<<<<<<<<<<<
 *         self.bytes_needed = 0
 * 
 */
  __pyx_t_1 = ((__pyx_v_self != ((struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *)0)) != 0);
  if (__pyx_t_1) {

    /* "wlsqm/fitter/infra.pyx":470
 * cdef void CaseManager_deallocate( CaseManager* self ) nogil:
 *     if self != <CaseManager*>0:
 *         self.bytes_needed = 0             # <<<<<<<<<<<<<<
 * 
 *         if self.mal != <Allocator*>0:  # the allocator instantiation may have failed, so make sure we have an allocator before attempting this
 */
    __pyx_v_self->bytes_needed = 0;

    /* "wlsqm/fitter/infra.pyx":472
 *         self.bytes_needed = 0
 * 
 *         if self.mal != <Allocator*>0:  # the allocator instantiation may have failed, so make sure we have an allocator before attempting this             # <<<<<<<<<<<<<<
 *             # the managed Case objects also use our allocator
 *             for j in range(self.ncases):
 */
    __pyx_t_1 = ((__pyx_v_self->mal != ((struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *)0)) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":474
 *         if self.mal != <Allocator*>0:  # the allocator instantiation may have failed, so make sure we have an allocator before attempting this
 *             # the managed Case objects also use our allocator
 *             for j in range(self.ncases):             # <<<<<<<<<<<<<<
 *                 Case_deallocate( self.cases[j] )  # it is safe to Case_deallocate() also a Case that has not yet been Case_allocate()'d.
 * 
 */
      __pyx_t_2 = __pyx_v_self->ncases;
      for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
        __pyx_v_j = __pyx_t_3;

        /* "wlsqm/fitter/infra.pyx":475
 *             # the managed Case objects also use our allocator
 *             for j in range(self.ncases):
 *                 Case_deallocate( self.cases[j] )  # it is safe to Case_deallocate() also a Case that has not yet been Case_allocate()'d.             # <<<<<<<<<<<<<<
 * 
 *             for j in range(self.ntasks):
 */
        __pyx_f_5wlsqm_6fitter_5infra_Case_deallocate((__pyx_v_self->cases[__pyx_v_j]));
      }

      /* "wlsqm/fitter/infra.pyx":477
 *                 Case_deallocate( self.cases[j] )  # it is safe to Case_deallocate() also a Case that has not yet been Case_allocate()'d.
 * 
 *             for j in range(self.ntasks):             # <<<<<<<<<<<<<<
 *                 Allocator_free( self.mal, self.fi_tmps[j] )
 *                 self.fi_tmps[j] = <double*>0
 */
      __pyx_t_2 = __pyx_v_self->ntasks;
      for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
        __pyx_v_j = __pyx_t_3;

        /* "wlsqm/fitter/infra.pyx":478
 * 
 *             for j in range(self.ntasks):
 *                 Allocator_free( self.mal, self.fi_tmps[j] )             # <<<<<<<<<<<<<<
 *                 self.fi_tmps[j] = <double*>0
 *                 Allocator_free( self.mal, self.fk_tmps[j] )
 */
        __pyx_f_5wlsqm_6fitter_5infra_Allocator_free(__pyx_v_self->mal, (__pyx_v_self->fi_tmps[__pyx_v_j]));

        /* "wlsqm/fitter/infra.pyx":479
 *             for j in range(self.ntasks):
 *                 Allocator_free( self.mal, self.fi_tmps[j] )
 *                 self.fi_tmps[j] = <double*>0             # <<<<<<<<<<<<<<
 *                 Allocator_free( self.mal, self.fk_tmps[j] )
 *                 self.fk_tmps[j] = <double*>0
 */
        (__pyx_v_self->fi_tmps[__pyx_v_j]) = ((double *)0);

        /* "wlsqm/fitter/infra.pyx":480
 *                 Allocator_free( self.mal, self.fi_tmps[j] )
 *                 self.fi_tmps[j] = <double*>0
 *                 Allocator_free( self.mal, self.fk_tmps[j] )             # <<<<<<<<<<<<<<
 *                 self.fk_tmps[j] = <double*>0
 *                 Allocator_free( self.mal, self.wrks[j] )
 */
        __pyx_f_5wlsqm_6fitter_5infra_Allocator_free(__pyx_v_self->mal, (__pyx_v_self->fk_tmps[__pyx_v_j]));

        /* "wlsqm/fitter/infra.pyx":481
 *                 self.fi_tmps[j] = <double*>0
 *                 Allocator_free( self.mal, self.fk_tmps[j] )
 *                 self.fk_tmps[j] = <double*>0             # <<<<<<<<<<<<<<
 *                 Allocator_free( self.mal, self.wrks[j] )
 *                 self.wrks[j]    = <double*>0
 */
        (__pyx_v_self->fk_tmps[__pyx_v_j]) = ((double *)0);

        /* "wlsqm/fitter/infra.pyx":482
 *                 Allocator_free( self.mal, self.fk_tmps[j] )
 *                 self.fk_tmps[j] = <double*>0
 *                 Allocator_free( self.mal, self.wrks[j] )             # <<<<<<<<<<<<<<
 *                 self.wrks[j]    = <double*>0
 * 
 */
        __pyx_f_5wlsqm_6fitter_5infra_Allocator_free(__pyx_v_self->mal, (__pyx_v_self->wrks[__pyx_v_j]));

        /* "wlsqm/fitter/infra.pyx":483
 *                 self.fk_tmps[j] = <double*>0
 *                 Allocator_free( self.mal, self.wrks[j] )
 *                 self.wrks[j]    = <double*>0             # <<<<<<<<<<<<<<
 * 
 *             Allocator_del( self.mal )
 */
        (__pyx_v_self->wrks[__pyx_v_j]) = ((double *)0);
      }

      /* "wlsqm/fitter/infra.pyx":485
 *                 self.wrks[j]    = <double*>0
 * 
 *             Allocator_del( self.mal )             # <<<<<<<<<<<<<<
 *             self.mal = <Allocator*>0
 * 
 */
      __pyx_f_5wlsqm_6fitter_5infra_Allocator_del(__pyx_v_self->mal);

      /* "wlsqm/fitter/infra.pyx":486
 * 
 *             Allocator_del( self.mal )
 *             self.mal = <Allocator*>0             # <<<<<<<<<<<<<<
 * 
 * # Destructor. Destroys also the managed Case objects.
 */
      __pyx_v_self->mal = ((struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *)0);

      /* "wlsqm/fitter/infra.pyx":472
 *         self.bytes_needed = 0
 * 
 *         if self.mal != <Allocator*>0:  # the allocator instantiation may have failed, so make sure we have an allocator before attempting this             # <<<<<<<<<<<<<<
 *             # the managed Case objects also use our allocator
 *             for j in range(self.ncases):
 */
    }

    /* "wlsqm/fitter/infra.pyx":469
 * #
 * cdef void CaseManager_deallocate( CaseManager* self ) nogil:
 *     if self != <CaseManager*>0:             # <<<<<<<<<<<<<<
 *         self.bytes_needed = 0
 * 
 */
  }

  /* "wlsqm/fitter/infra.pyx":468
 * # The opposite of CaseManager_allocate().
 * #
 * cdef void CaseManager_deallocate( CaseManager* self ) nogil:             # <<<<<<<<<<<<<<
 *     if self != <CaseManager*>0:
 *         self.bytes_needed = 0
 */

  /* function exit code */
}

/* "wlsqm/fitter/infra.pyx":490
 * # Destructor. Destroys also the managed Case objects.
 * #
 * cdef void CaseManager_del( CaseManager* self ) nogil:             # <<<<<<<<<<<<<<
 *     cdef int j
 *     if self != <CaseManager*>0:
 */

static void __pyx_f_5wlsqm_6fitter_5infra_CaseManager_del(struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *__pyx_v_self) {
  int __pyx_v_j;
  int __pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;

  /* "wlsqm/fitter/infra.pyx":492
 * cdef void CaseManager_del( CaseManager* self ) nogil:
 *     cdef int j
 *     if self != <CaseManager*>0:             # <<<<<<<<<<<<<<
 *         CaseManager_deallocate( self )
 * 
 */
  __pyx_t_1 = ((__pyx_v_self != ((struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *)0)) != 0);
  if (__pyx_t_1) {

    /* "wlsqm/fitter/infra.pyx":493
 *     cdef int j
 *     if self != <CaseManager*>0:
 *         CaseManager_deallocate( self )             # <<<<<<<<<<<<<<
 * 
 *         # destroy the managed Case objects
 */
    __pyx_f_5wlsqm_6fitter_5infra_CaseManager_deallocate(__pyx_v_self);

    /* "wlsqm/fitter/infra.pyx":496
 * 
 *         # destroy the managed Case objects
 *         for j in range(self.ncases):             # <<<<<<<<<<<<<<
 *             Case_del( self.cases[j] )
 * 
 */
    __pyx_t_2 = __pyx_v_self->ncases;
    for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
      __pyx_v_j = __pyx_t_3;

      /* "wlsqm/fitter/infra.pyx":497
 *         # destroy the managed Case objects
 *         for j in range(self.ncases):
 *             Case_del( self.cases[j] )             # <<<<<<<<<<<<<<
 * 
 *         # free manually allocated storage
 */
      __pyx_f_5wlsqm_6fitter_5infra_Case_del((__pyx_v_self->cases[__pyx_v_j]));
    }

    /* "wlsqm/fitter/infra.pyx":500
 * 
 *         # free manually allocated storage
 *         free( self.cases )             # <<<<<<<<<<<<<<
 *         free( self.fi_tmps )
 *         free( self.fk_tmps )
 */
    free(__pyx_v_self->cases);

    /* "wlsqm/fitter/infra.pyx":501
 *         # free manually allocated storage
 *         free( self.cases )
 *         free( self.fi_tmps )             # <<<<<<<<<<<<<<
 *         free( self.fk_tmps )
 *         free( self.wrks )
 */
    free(__pyx_v_self->fi_tmps);

    /* "wlsqm/fitter/infra.pyx":502
 *         free( self.cases )
 *         free( self.fi_tmps )
 *         free( self.fk_tmps )             # <<<<<<<<<<<<<<
 *         free( self.wrks )
 * 
 */
    free(__pyx_v_self->fk_tmps);

    /* "wlsqm/fitter/infra.pyx":503
 *         free( self.fi_tmps )
 *         free( self.fk_tmps )
 *         free( self.wrks )             # <<<<<<<<<<<<<<
 * 
 *         free( self )
 */
    free(__pyx_v_self->wrks);

    /* "wlsqm/fitter/infra.pyx":505
 *         free( self.wrks )
 * 
 *         free( self )             # <<<<<<<<<<<<<<
 * 
 * 
 */
    free(__pyx_v_self);

    /* "wlsqm/fitter/infra.pyx":492
 * cdef void CaseManager_del( CaseManager* self ) nogil:
 *     cdef int j
 *     if self != <CaseManager*>0:             # <<<<<<<<<<<<<<
 *         CaseManager_deallocate( self )
 * 
 */
  }

  /* "wlsqm/fitter/infra.pyx":490
 * # Destructor. Destroys also the managed Case objects.
 * #
 * cdef void CaseManager_del( CaseManager* self ) nogil:             # <<<<<<<<<<<<<<
 *     cdef int j
 *     if self != <CaseManager*>0:
 */

  /* function exit code */
}

/* "wlsqm/fitter/infra.pyx":538
 * #          If null, the geometry data will be allocated locally.
 * #
 * cdef Case* Case_new( int dimension, int order, double xi, double yi, double zi, int nk, long long knowns, int weighting_method, int do_sens, int iterative, CaseManager* manager, Case* host ) nogil except <Case*>0:             # <<<<<<<<<<<<<<
 *     cdef Case* self = <Case*>malloc( sizeof(Case) )
 *     if self == <Case*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 */

static struct __pyx_t_5wlsqm_6fitter_5infra_Case *__pyx_f_5wlsqm_6fitter_5infra_Case_new(int __pyx_v_dimension, int __pyx_v_order, double __pyx_v_xi, double __pyx_v_yi, double __pyx_v_zi, int __pyx_v_nk, PY_LONG_LONG __pyx_v_knowns, int __pyx_v_weighting_method, int __pyx_v_do_sens, int __pyx_v_iterative, struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *__pyx_v_manager, struct __pyx_t_5wlsqm_6fitter_5infra_Case *__pyx_v_host) {
  struct __pyx_t_5wlsqm_6fitter_5infra_Case *__pyx_v_self;
  double __pyx_v_nan;
  int __pyx_v_no;
  int __pyx_v_nr;
  struct __pyx_t_5wlsqm_6fitter_5infra_Case *__pyx_r;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  double __pyx_t_3;
  int *__pyx_t_4;
  double *__pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save;
  #endif
  __Pyx_RefNannySetupContext("Case_new", 1);

  /* "wlsqm/fitter/infra.pyx":539
 * #
 * cdef Case* Case_new( int dimension, int order, double xi, double yi, double zi, int nk, long long knowns, int weighting_method, int do_sens, int iterative, CaseManager* manager, Case* host ) nogil except <Case*>0:
 *     cdef Case* self = <Case*>malloc( sizeof(Case) )             # <<<<<<<<<<<<<<
 *     if self == <Case*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 *         with gil:
 */
  /*try:*/ {
    __pyx_v_self = ((struct __pyx_t_5wlsqm_6fitter_5infra_Case *)malloc((sizeof(struct __pyx_t_5wlsqm_6fitter_5infra_Case))));

    /* "wlsqm/fitter/infra.pyx":540
 * cdef Case* Case_new( int dimension, int order, double xi, double yi, double zi, int nk, long long knowns, int weighting_method, int do_sens, int iterative, CaseManager* manager, Case* host ) nogil except <Case*>0:
 *     cdef Case* self = <Case*>malloc( sizeof(Case) )
 *     if self == <Case*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails             # <<<<<<<<<<<<<<
 *         with gil:
 *             raise MemoryError("Out of memory trying to allocate a Case object")
 */
    __pyx_t_1 = ((__pyx_v_self == ((struct __pyx_t_5wlsqm_6fitter_5infra_Case *)0)) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":541
 *     cdef Case* self = <Case*>malloc( sizeof(Case) )
 *     if self == <Case*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 *         with gil:             # <<<<<<<<<<<<<<
 *             raise MemoryError("Out of memory trying to allocate a Case object")
 * 
 */
      {
          #ifdef WITH_THREAD
          PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
          #endif
          /*try:*/ {

            /* "wlsqm/fitter/infra.pyx":542
 *     if self == <Case*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 *         with gil:
 *             raise MemoryError("Out of memory trying to allocate a Case object")             # <<<<<<<<<<<<<<
 * 
 *     # tag unused components as NaN
 */
            __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 542, __pyx_L8_error)
            __Pyx_GOTREF(__pyx_t_2);
            __Pyx_Raise(__pyx_t_2, 0, 0, 0);
            __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
            __PYX_ERR(0, 542, __pyx_L8_error)
          }

          /* "wlsqm/fitter/infra.pyx":541
 *     cdef Case* self = <Case*>malloc( sizeof(Case) )
 *     if self == <Case*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 *         with gil:             # <<<<<<<<<<<<<<
 *             raise MemoryError("Out of memory trying to allocate a Case object")
 * 
 */
          /*finally:*/ {
            __pyx_L8_error: {
              #ifdef WITH_THREAD
              PyGILState_Release(__pyx_gilstate_save);
              #endif
              goto __pyx_L4_error;
            }
          }
      }

      /* "wlsqm/fitter/infra.pyx":540
 * cdef Case* Case_new( int dimension, int order, double xi, double yi, double zi, int nk, long long knowns, int weighting_method, int do_sens, int iterative, CaseManager* manager, Case* host ) nogil except <Case*>0:
 *     cdef Case* self = <Case*>malloc( sizeof(Case) )
 *     if self == <Case*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails             # <<<<<<<<<<<<<<
 *         with gil:
 *             raise MemoryError("Out of memory trying to allocate a Case object")
 */
    }

    /* "wlsqm/fitter/infra.pyx":545
 * 
 *     # tag unused components as NaN
 *     cdef double nan = 0./0.  # NaN as per IEEE-754             # <<<<<<<<<<<<<<
 *     self.xi = xi
 *     self.yi = yi  if dimension >= 2  else  nan
 */
    __pyx_v_nan = (0. / 0.);

    /* "wlsqm/fitter/infra.pyx":546
 *     # tag unused components as NaN
 *     cdef double nan = 0./0.  # NaN as per IEEE-754
 *     self.xi = xi             # <<<<<<<<<<<<<<
 *     self.yi = yi  if dimension >= 2  else  nan
 *     self.zi = zi  if dimension == 3  else  nan
 */
    __pyx_v_self->xi = __pyx_v_xi;

    /* "wlsqm/fitter/infra.pyx":547
 *     cdef double nan = 0./0.  # NaN as per IEEE-754
 *     self.xi = xi
 *     self.yi = yi  if dimension >= 2  else  nan             # <<<<<<<<<<<<<<
 *     self.zi = zi  if dimension == 3  else  nan
 * 
 */
    if (((__pyx_v_dimension >= 2) != 0)) {
      __pyx_t_3 = __pyx_v_yi;
    } else {
      __pyx_t_3 = __pyx_v_nan;
    }
    __pyx_v_self->yi = __pyx_t_3;

    /* "wlsqm/fitter/infra.pyx":548
 *     self.xi = xi
 *     self.yi = yi  if dimension >= 2  else  nan
 *     self.zi = zi  if dimension == 3  else  nan             # <<<<<<<<<<<<<<
 * 
 *     # init data pointers to NULL to make it safe to dealloc partially initialized Case (when something goes wrong)
 */
    if (((__pyx_v_dimension == 3) != 0)) {
      __pyx_t_3 = __pyx_v_zi;
    } else {
      __pyx_t_3 = __pyx_v_nan;
    }
    __pyx_v_self->zi = __pyx_t_3;

    /* "wlsqm/fitter/infra.pyx":551
 * 
 *     # init data pointers to NULL to make it safe to dealloc partially initialized Case (when something goes wrong)
 *     self.o2r       = <int*>0             # <<<<<<<<<<<<<<
 *     self.r2o       = <int*>0
 *     self.c         = <double*>0
 */
    __pyx_v_self->o2r = ((int *)0);

    /* "wlsqm/fitter/infra.pyx":552
 *     # init data pointers to NULL to make it safe to dealloc partially initialized Case (when something goes wrong)
 *     self.o2r       = <int*>0
 *     self.r2o       = <int*>0             # <<<<<<<<<<<<<<
 *     self.c         = <double*>0
 *     self.w         = <double*>0
 */
    __pyx_v_self->r2o = ((int *)0);

    /* "wlsqm/fitter/infra.pyx":553
 *     self.o2r       = <int*>0
 *     self.r2o       = <int*>0
 *     self.c         = <double*>0             # <<<<<<<<<<<<<<
 *     self.w         = <double*>0
 *     self.A         = <double*>0
 */
    __pyx_v_self->c = ((double *)0);

    /* "wlsqm/fitter/infra.pyx":554
 *     self.r2o       = <int*>0
 *     self.c         = <double*>0
 *     self.w         = <double*>0             # <<<<<<<<<<<<<<
 *     self.A         = <double*>0
 *     self.row_scale = <double*>0
 */
    __pyx_v_self->w = ((double *)0);

    /* "wlsqm/fitter/infra.pyx":555
 *     self.c         = <double*>0
 *     self.w         = <double*>0
 *     self.A         = <double*>0             # <<<<<<<<<<<<<<
 *     self.row_scale = <double*>0
 *     self.col_scale = <double*>0
 */
    __pyx_v_self->A = ((double *)0);

    /* "wlsqm/fitter/infra.pyx":556
 *     self.w         = <double*>0
 *     self.A         = <double*>0
 *     self.row_scale = <double*>0             # <<<<<<<<<<<<<<
 *     self.col_scale = <double*>0
 *     self.ipiv      = <int*>0
 */
    __pyx_v_self->row_scale = ((double *)0);

    /* "wlsqm/fitter/infra.pyx":557
 *     self.A         = <double*>0
 *     self.row_scale = <double*>0
 *     self.col_scale = <double*>0             # <<<<<<<<<<<<<<
 *     self.ipiv      = <int*>0
 *     self.fi        = <double*>0
 */
    __pyx_v_self->col_scale = ((double *)0);

    /* "wlsqm/fitter/infra.pyx":558
 *     self.row_scale = <double*>0
 *     self.col_scale = <double*>0
 *     self.ipiv      = <int*>0             # <<<<<<<<<<<<<<
 *     self.fi        = <double*>0
 *     self.fi2       = <double*>0
 */
    __pyx_v_self->ipiv = ((int *)0);

    /* "wlsqm/fitter/infra.pyx":559
 *     self.col_scale = <double*>0
 *     self.ipiv      = <int*>0
 *     self.fi        = <double*>0             # <<<<<<<<<<<<<<
 *     self.fi2       = <double*>0
 *     self.wrk       = <double*>0
 */
    __pyx_v_self->fi = ((double *)0);

    /* "wlsqm/fitter/infra.pyx":560
 *     self.ipiv      = <int*>0
 *     self.fi        = <double*>0
 *     self.fi2       = <double*>0             # <<<<<<<<<<<<<<
 *     self.wrk       = <double*>0
 *     self.fk_tmp    = <double*>0
 */
    __pyx_v_self->fi2 = ((double *)0);

    /* "wlsqm/fitter/infra.pyx":561
 *     self.fi        = <double*>0
 *     self.fi2       = <double*>0
 *     self.wrk       = <double*>0             # <<<<<<<<<<<<<<
 *     self.fk_tmp    = <double*>0
 *     self.fi_tmp    = <double*>0
 */
    __pyx_v_self->wrk = ((double *)0);

    /* "wlsqm/fitter/infra.pyx":562
 *     self.fi2       = <double*>0
 *     self.wrk       = <double*>0
 *     self.fk_tmp    = <double*>0             # <<<<<<<<<<<<<<
 *     self.fi_tmp    = <double*>0
 * 
 */
    __pyx_v_self->fk_tmp = ((double *)0);

    /* "wlsqm/fitter/infra.pyx":563
 *     self.wrk       = <double*>0
 *     self.fk_tmp    = <double*>0
 *     self.fi_tmp    = <double*>0             # <<<<<<<<<<<<<<
 * 
 *     if host == <Case*>0:
 */
    __pyx_v_self->fi_tmp = ((double *)0);

    /* "wlsqm/fitter/infra.pyx":565
 *     self.fi_tmp    = <double*>0
 * 
 *     if host == <Case*>0:             # <<<<<<<<<<<<<<
 *         self.geometry_owned = 1
 * 
 */
    __pyx_t_1 = ((__pyx_v_host == ((struct __pyx_t_5wlsqm_6fitter_5infra_Case *)0)) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":566
 * 
 *     if host == <Case*>0:
 *         self.geometry_owned = 1             # <<<<<<<<<<<<<<
 * 
 *         # set condition numbers to nan until computed (only computed if wlsqm.fitter.impl.prepare() is called with the debug flag set!)
 */
      __pyx_v_self->geometry_owned = 1;

      /* "wlsqm/fitter/infra.pyx":569
 * 
 *         # set condition numbers to nan until computed (only computed if wlsqm.fitter.impl.prepare() is called with the debug flag set!)
 *         self.cond_orig   = nan             # <<<<<<<<<<<<<<
 *         self.cond_scaled = nan
 * 
 */
      __pyx_v_self->cond_orig = __pyx_v_nan;

      /* "wlsqm/fitter/infra.pyx":570
 *         # set condition numbers to nan until computed (only computed if wlsqm.fitter.impl.prepare() is called with the debug flag set!)
 *         self.cond_orig   = nan
 *         self.cond_scaled = nan             # <<<<<<<<<<<<<<
 * 
 *     else:
 */
      __pyx_v_self->cond_scaled = __pyx_v_nan;

      /* "wlsqm/fitter/infra.pyx":565
 *     self.fi_tmp    = <double*>0
 * 
 *     if host == <Case*>0:             # <<<<<<<<<<<<<<
 *         self.geometry_owned = 1
 * 
 */
      goto __pyx_L10;
    }

    /* "wlsqm/fitter/infra.pyx":573
 * 
 *     else:
 *         self.geometry_owned = 0             # <<<<<<<<<<<<<<
 *         self.o2r            = host.o2r
 *         self.r2o            = host.r2o
 */
    /*else*/ {
      __pyx_v_self->geometry_owned = 0;

      /* "wlsqm/fitter/infra.pyx":574
 *     else:
 *         self.geometry_owned = 0
 *         self.o2r            = host.o2r             # <<<<<<<<<<<<<<
 *         self.r2o            = host.r2o
 *         self.c              = host.c
 */
      __pyx_t_4 = __pyx_v_host->o2r;
      __pyx_v_self->o2r = __pyx_t_4;

      /* "wlsqm/fitter/infra.pyx":575
 *         self.geometry_owned = 0
 *         self.o2r            = host.o2r
 *         self.r2o            = host.r2o             # <<<<<<<<<<<<<<
 *         self.c              = host.c
 *         self.w              = host.w
 */
      __pyx_t_4 = __pyx_v_host->r2o;
      __pyx_v_self->r2o = __pyx_t_4;

      /* "wlsqm/fitter/infra.pyx":576
 *         self.o2r            = host.o2r
 *         self.r2o            = host.r2o
 *         self.c              = host.c             # <<<<<<<<<<<<<<
 *         self.w              = host.w
 *         self.A              = host.A
 */
      __pyx_t_5 = __pyx_v_host->c;
      __pyx_v_self->c = __pyx_t_5;

      /* "wlsqm/fitter/infra.pyx":577
 *         self.r2o            = host.r2o
 *         self.c              = host.c
 *         self.w              = host.w             # <<<<<<<<<<<<<<
 *         self.A              = host.A
 *         self.row_scale      = host.row_scale
 */
      __pyx_t_5 = __pyx_v_host->w;
      __pyx_v_self->w = __pyx_t_5;

      /* "wlsqm/fitter/infra.pyx":578
 *         self.c              = host.c
 *         self.w              = host.w
 *         self.A              = host.A             # <<<<<<<<<<<<<<
 *         self.row_scale      = host.row_scale
 *         self.col_scale      = host.col_scale
 */
      __pyx_t_5 = __pyx_v_host->A;
      __pyx_v_self->A = __pyx_t_5;

      /* "wlsqm/fitter/infra.pyx":579
 *         self.w              = host.w
 *         self.A              = host.A
 *         self.row_scale      = host.row_scale             # <<<<<<<<<<<<<<
 *         self.col_scale      = host.col_scale
 *         self.ipiv           = host.ipiv
 */
      __pyx_t_5 = __pyx_v_host->row_scale;
      __pyx_v_self->row_scale = __pyx_t_5;

      /* "wlsqm/fitter/infra.pyx":580
 *         self.A              = host.A
 *         self.row_scale      = host.row_scale
 *         self.col_scale      = host.col_scale             # <<<<<<<<<<<<<<
 *         self.ipiv           = host.ipiv
 * 
 */
      __pyx_t_5 = __pyx_v_host->col_scale;
      __pyx_v_self->col_scale = __pyx_t_5;

      /* "wlsqm/fitter/infra.pyx":581
 *         self.row_scale      = host.row_scale
 *         self.col_scale      = host.col_scale
 *         self.ipiv           = host.ipiv             # <<<<<<<<<<<<<<
 * 
 *         # these may have been computed by host (this only works if the host has had preprocess_A() called on it already, but this is the best we can do)
 */
      __pyx_t_4 = __pyx_v_host->ipiv;
      __pyx_v_self->ipiv = __pyx_t_4;

      /* "wlsqm/fitter/infra.pyx":584
 * 
 *         # these may have been computed by host (this only works if the host has had preprocess_A() called on it already, but this is the best we can do)
 *         self.cond_orig      = host.cond_orig             # <<<<<<<<<<<<<<
 *         self.cond_scaled    = host.cond_scaled
 * 
 */
      __pyx_t_3 = __pyx_v_host->cond_orig;
      __pyx_v_self->cond_orig = __pyx_t_3;

      /* "wlsqm/fitter/infra.pyx":585
 *         # these may have been computed by host (this only works if the host has had preprocess_A() called on it already, but this is the best we can do)
 *         self.cond_orig      = host.cond_orig
 *         self.cond_scaled    = host.cond_scaled             # <<<<<<<<<<<<<<
 * 
 *     # Use the data from CaseManager if given
 */
      __pyx_t_3 = __pyx_v_host->cond_scaled;
      __pyx_v_self->cond_scaled = __pyx_t_3;
    }
    __pyx_L10:;

    /* "wlsqm/fitter/infra.pyx":588
 * 
 *     # Use the data from CaseManager if given
 *     self.have_manager = (manager != <CaseManager*>0)             # <<<<<<<<<<<<<<
 *     self.manager      = manager        # (copies the pointer also if NULL)
 *     self.mal          = <Allocator*>0  # this will be filled at allocate time
 */
    __pyx_v_self->have_manager = (__pyx_v_manager != ((struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *)0));

    /* "wlsqm/fitter/infra.pyx":589
 *     # Use the data from CaseManager if given
 *     self.have_manager = (manager != <CaseManager*>0)
 *     self.manager      = manager        # (copies the pointer also if NULL)             # <<<<<<<<<<<<<<
 *     self.mal          = <Allocator*>0  # this will be filled at allocate time
 * 
 */
    __pyx_v_self->manager = __pyx_v_manager;

    /* "wlsqm/fitter/infra.pyx":590
 *     self.have_manager = (manager != <CaseManager*>0)
 *     self.manager      = manager        # (copies the pointer also if NULL)
 *     self.mal          = <Allocator*>0  # this will be filled at allocate time             # <<<<<<<<<<<<<<
 * 
 *     # determine number of DOFs in the original (unreduced) and reduced systems (needed to determine array sizes)
 */
    __pyx_v_self->mal = ((struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *)0);

    /* "wlsqm/fitter/infra.pyx":593
 * 
 *     # determine number of DOFs in the original (unreduced) and reduced systems (needed to determine array sizes)
 *     cdef int no = number_of_dofs( dimension, order )             # <<<<<<<<<<<<<<
 *     cdef int nr = number_of_reduced_dofs( no, knowns )
 * 
 */
    __pyx_v_no = __pyx_f_5wlsqm_6fitter_5infra_number_of_dofs(__pyx_v_dimension, __pyx_v_order);

    /* "wlsqm/fitter/infra.pyx":594
 *     # determine number of DOFs in the original (unreduced) and reduced systems (needed to determine array sizes)
 *     cdef int no = number_of_dofs( dimension, order )
 *     cdef int nr = number_of_reduced_dofs( no, knowns )             # <<<<<<<<<<<<<<
 * 
 *     # save metadata
 */
    __pyx_v_nr = __pyx_f_5wlsqm_6fitter_5infra_number_of_reduced_dofs(__pyx_v_no, __pyx_v_knowns);

    /* "wlsqm/fitter/infra.pyx":597
 * 
 *     # save metadata
 *     self.dimension        = dimension             # <<<<<<<<<<<<<<
 *     self.order            = order
 *     self.knowns           = knowns
 */
    __pyx_v_self->dimension = __pyx_v_dimension;

    /* "wlsqm/fitter/infra.pyx":598
 *     # save metadata
 *     self.dimension        = dimension
 *     self.order            = order             # <<<<<<<<<<<<<<
 *     self.knowns           = knowns
 *     self.weighting_method = weighting_method
 */
    __pyx_v_self->order = __pyx_v_order;

    /* "wlsqm/fitter/infra.pyx":599
 *     self.dimension        = dimension
 *     self.order            = order
 *     self.knowns           = knowns             # <<<<<<<<<<<<<<
 *     self.weighting_method = weighting_method
 *     self.no               = no
 */
    __pyx_v_self->knowns = __pyx_v_knowns;

    /* "wlsqm/fitter/infra.pyx":600
 *     self.order            = order
 *     self.knowns           = knowns
 *     self.weighting_method = weighting_method             # <<<<<<<<<<<<<<
 *     self.no               = no
 *     self.nr               = nr
 */
    __pyx_v_self->weighting_method = __pyx_v_weighting_method;

    /* "wlsqm/fitter/infra.pyx":601
 *     self.knowns           = knowns
 *     self.weighting_method = weighting_method
 *     self.no               = no             # <<<<<<<<<<<<<<
 *     self.nr               = nr
 *     self.nk               = nk
 */
    __pyx_v_self->no = __pyx_v_no;

    /* "wlsqm/fitter/infra.pyx":602
 *     self.weighting_method = weighting_method
 *     self.no               = no
 *     self.nr               = nr             # <<<<<<<<<<<<<<
 *     self.nk               = nk
 *     self.do_sens          = do_sens
 */
    __pyx_v_self->nr = __pyx_v_nr;

    /* "wlsqm/fitter/infra.pyx":603
 *     self.no               = no
 *     self.nr               = nr
 *     self.nk               = nk             # <<<<<<<<<<<<<<
 *     self.do_sens          = do_sens
 *     self.iterative        = iterative
 */
    __pyx_v_self->nk = __pyx_v_nk;

    /* "wlsqm/fitter/infra.pyx":604
 *     self.nr               = nr
 *     self.nk               = nk
 *     self.do_sens          = do_sens             # <<<<<<<<<<<<<<
 *     self.iterative        = iterative
 * 
 */
    __pyx_v_self->do_sens = __pyx_v_do_sens;

    /* "wlsqm/fitter/infra.pyx":605
 *     self.nk               = nk
 *     self.do_sens          = do_sens
 *     self.iterative        = iterative             # <<<<<<<<<<<<<<
 * 
 *     # Now the Case is in a half-initialized state, with metadata available, but no memory allocated yet.
 */
    __pyx_v_self->iterative = __pyx_v_iterative;

    /* "wlsqm/fitter/infra.pyx":609
 *     # Now the Case is in a half-initialized state, with metadata available, but no memory allocated yet.
 * 
 *     if self.have_manager:             # <<<<<<<<<<<<<<
 *         # In managed mode, cases automatically add themselves to the manager.
 *         with gil:
 */
    __pyx_t_1 = (__pyx_v_self->have_manager != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":611
 *     if self.have_manager:
 *         # In managed mode, cases automatically add themselves to the manager.
 *         with gil:             # <<<<<<<<<<<<<<
 *             try:
 *                 CaseManager_add( self.manager, self )  # this may raise if the buffer is full
 */
      {
          #ifdef WITH_THREAD
          PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
          #endif
          /*try:*/ {

            /* "wlsqm/fitter/infra.pyx":612
 *         # In managed mode, cases automatically add themselves to the manager.
 *         with gil:
 *             try:             # <<<<<<<<<<<<<<
 *                 CaseManager_add( self.manager, self )  # this may raise if the buffer is full
 *             except:
 */
            {
              __Pyx_PyThreadState_declare
              __Pyx_PyThreadState_assign
              __Pyx_ExceptionSave(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8);
              __Pyx_XGOTREF(__pyx_t_6);
              __Pyx_XGOTREF(__pyx_t_7);
              __Pyx_XGOTREF(__pyx_t_8);
              /*try:*/ {

                /* "wlsqm/fitter/infra.pyx":613
 *         with gil:
 *             try:
 *                 CaseManager_add( self.manager, self )  # this may raise if the buffer is full             # <<<<<<<<<<<<<<
 *             except:
 *                 free( self )
 */
                __pyx_t_9 = __pyx_f_5wlsqm_6fitter_5infra_CaseManager_add(__pyx_v_self->manager, __pyx_v_self); if (unlikely(__pyx_t_9 == -1)) __PYX_ERR(0, 613, __pyx_L15_error)

                /* "wlsqm/fitter/infra.pyx":612
 *         # In managed mode, cases automatically add themselves to the manager.
 *         with gil:
 *             try:             # <<<<<<<<<<<<<<
 *                 CaseManager_add( self.manager, self )  # this may raise if the buffer is full
 *             except:
 */
              }
              __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
              __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
              __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
              goto __pyx_L22_try_end;
              __pyx_L15_error:;
              __Pyx_PyThreadState_assign
              __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;

              /* "wlsqm/fitter/infra.pyx":614
 *             try:
 *                 CaseManager_add( self.manager, self )  # this may raise if the buffer is full
 *             except:             # <<<<<<<<<<<<<<
 *                 free( self )
 *                 raise
 */
              /*except:*/ {
                __Pyx_AddTraceback("wlsqm.fitter.infra.Case_new", __pyx_clineno, __pyx_lineno, __pyx_filename);
                if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_10, &__pyx_t_11) < 0) __PYX_ERR(0, 614, __pyx_L17_except_error)
                __Pyx_GOTREF(__pyx_t_2);
                __Pyx_GOTREF(__pyx_t_10);
                __Pyx_GOTREF(__pyx_t_11);

                /* "wlsqm/fitter/infra.pyx":615
 *                 CaseManager_add( self.manager, self )  # this may raise if the buffer is full
 *             except:
 *                 free( self )             # <<<<<<<<<<<<<<
 *                 raise
 *     else:
 */
                free(__pyx_v_self);

                /* "wlsqm/fitter/infra.pyx":616
 *             except:
 *                 free( self )
 *                 raise             # <<<<<<<<<<<<<<
 *     else:
 *         # In unmanaged mode, for caller convenience, cases fully initialize themselves, since there is no separate allocate step
 */
                __Pyx_GIVEREF(__pyx_t_2);
                __Pyx_GIVEREF(__pyx_t_10);
                __Pyx_XGIVEREF(__pyx_t_11);
                __Pyx_ErrRestoreWithState(__pyx_t_2, __pyx_t_10, __pyx_t_11);
                __pyx_t_2 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; 
                __PYX_ERR(0, 616, __pyx_L17_except_error)
              }
              __pyx_L17_except_error:;

              /* "wlsqm/fitter/infra.pyx":612
 *         # In managed mode, cases automatically add themselves to the manager.
 *         with gil:
 *             try:             # <<<<<<<<<<<<<<
 *                 CaseManager_add( self.manager, self )  # this may raise if the buffer is full
 *             except:
 */
              __Pyx_PyThreadState_assign
              __Pyx_XGIVEREF(__pyx_t_6);
              __Pyx_XGIVEREF(__pyx_t_7);
              __Pyx_XGIVEREF(__pyx_t_8);
              __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
              goto __pyx_L13_error;
              __pyx_L22_try_end:;
            }
          }

          /* "wlsqm/fitter/infra.pyx":611
 *     if self.have_manager:
 *         # In managed mode, cases automatically add themselves to the manager.
 *         with gil:             # <<<<<<<<<<<<<<
 *             try:
 *                 CaseManager_add( self.manager, self )  # this may raise if the buffer is full
 */
          /*finally:*/ {
            /*normal exit:*/{
              #ifdef WITH_THREAD
              PyGILState_Release(__pyx_gilstate_save);
              #endif
              goto __pyx_L14;
            }
            __pyx_L13_error: {
              #ifdef WITH_THREAD
              PyGILState_Release(__pyx_gilstate_save);
              #endif
              goto __pyx_L4_error;
            }
            __pyx_L14:;
          }
      }

      /* "wlsqm/fitter/infra.pyx":609
 *     # Now the Case is in a half-initialized state, with metadata available, but no memory allocated yet.
 * 
 *     if self.have_manager:             # <<<<<<<<<<<<<<
 *         # In managed mode, cases automatically add themselves to the manager.
 *         with gil:
 */
      goto __pyx_L11;
    }

    /* "wlsqm/fitter/infra.pyx":620
 *         # In unmanaged mode, for caller convenience, cases fully initialize themselves, since there is no separate allocate step
 *         # that depends on having all the cases available (to compute the final buffer size).
 *         Case_allocate( self )             # <<<<<<<<<<<<<<
 * 
 *     return self
 */
    /*else*/ {
      __pyx_t_9 = __pyx_f_5wlsqm_6fitter_5infra_Case_allocate(__pyx_v_self); if (unlikely(__pyx_t_9 == -1)) __PYX_ERR(0, 620, __pyx_L4_error)
    }
    __pyx_L11:;

    /* "wlsqm/fitter/infra.pyx":622
 *         Case_allocate( self )
 * 
 *     return self             # <<<<<<<<<<<<<<
 * 
 * # Getters for work space pointers for parallel task "taskid" (0, 1, ..., ntasks-1).
 */
    __pyx_r = __pyx_v_self;
    goto __pyx_L3_return;
  }

  /* "wlsqm/fitter/infra.pyx":539
 * #
 * cdef Case* Case_new( int dimension, int order, double xi, double yi, double zi, int nk, long long knowns, int weighting_method, int do_sens, int iterative, CaseManager* manager, Case* host ) nogil except <Case*>0:
 *     cdef Case* self = <Case*>malloc( sizeof(Case) )             # <<<<<<<<<<<<<<
 *     if self == <Case*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 *         with gil:
 */
  /*finally:*/ {
    __pyx_L3_return: {
      #ifdef WITH_THREAD
      __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      goto __pyx_L0;
    }
    __pyx_L4_error: {
      #ifdef WITH_THREAD
      __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      goto __pyx_L1_error;
    }
  }

  /* "wlsqm/fitter/infra.pyx":538
 * #          If null, the geometry data will be allocated locally.
 * #
 * cdef Case* Case_new( int dimension, int order, double xi, double yi, double zi, int nk, long long knowns, int weighting_method, int do_sens, int iterative, CaseManager* manager, Case* host ) nogil except <Case*>0:             # <<<<<<<<<<<<<<
 *     cdef Case* self = <Case*>malloc( sizeof(Case) )
 *     if self == <Case*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("wlsqm.fitter.infra.Case_new", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = ((struct __pyx_t_5wlsqm_6fitter_5infra_Case *)0);
  __pyx_L0:;
  #ifdef WITH_THREAD
  PyGILState_Release(__pyx_gilstate_save);
  #endif
  return __pyx_r;
}

/* "wlsqm/fitter/infra.pyx":630
 * # In unmanaged mode, each Case has its own work space.
 * #
 * cdef double* Case_get_wrk( Case* self, int taskid ) nogil:             # <<<<<<<<<<<<<<
 *     if self.have_manager:
 *         return self.manager.wrks[taskid]
 */

static double *__pyx_f_5wlsqm_6fitter_5infra_Case_get_wrk(struct __pyx_t_5wlsqm_6fitter_5infra_Case *__pyx_v_self, int __pyx_v_taskid) {
  double *__pyx_r;
  int __pyx_t_1;

  /* "wlsqm/fitter/infra.pyx":631
 * #
 * cdef double* Case_get_wrk( Case* self, int taskid ) nogil:
 *     if self.have_manager:             # <<<<<<<<<<<<<<
 *         return self.manager.wrks[taskid]
 *     else:
 */
  __pyx_t_1 = (__pyx_v_self->have_manager != 0);
  if (__pyx_t_1) {

    /* "wlsqm/fitter/infra.pyx":632
 * cdef double* Case_get_wrk( Case* self, int taskid ) nogil:
 *     if self.have_manager:
 *         return self.manager.wrks[taskid]             # <<<<<<<<<<<<<<
 *     else:
 *         return self.wrk
 */
    __pyx_r = (__pyx_v_self->manager->wrks[__pyx_v_taskid]);
    goto __pyx_L0;

    /* "wlsqm/fitter/infra.pyx":631
 * #
 * cdef double* Case_get_wrk( Case* self, int taskid ) nogil:
 *     if self.have_manager:             # <<<<<<<<<<<<<<
 *         return self.manager.wrks[taskid]
 *     else:
 */
  }

  /* "wlsqm/fitter/infra.pyx":634
 *         return self.manager.wrks[taskid]
 *     else:
 *         return self.wrk             # <<<<<<<<<<<<<<
 * 
 * cdef double* Case_get_fk_tmp( Case* self, int taskid ) nogil:
 */
  /*else*/ {
    __pyx_r = __pyx_v_self->wrk;
    goto __pyx_L0;
  }

  /* "wlsqm/fitter/infra.pyx":630
 * # In unmanaged mode, each Case has its own work space.
 * #
 * cdef double* Case_get_wrk( Case* self, int taskid ) nogil:             # <<<<<<<<<<<<<<
 *     if self.have_manager:
 *         return self.manager.wrks[taskid]
 */

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

/* "wlsqm/fitter/infra.pyx":636
 *         return self.wrk
 * 
 * cdef double* Case_get_fk_tmp( Case* self, int taskid ) nogil:             # <<<<<<<<<<<<<<
 *     if self.have_manager:
 *         return self.manager.fk_tmps[taskid]
 */

static double *__pyx_f_5wlsqm_6fitter_5infra_Case_get_fk_tmp(struct __pyx_t_5wlsqm_6fitter_5infra_Case *__pyx_v_self, int __pyx_v_taskid) {
  double *__pyx_r;
  int __pyx_t_1;

  /* "wlsqm/fitter/infra.pyx":637
 * 
 * cdef double* Case_get_fk_tmp( Case* self, int taskid ) nogil:
 *     if self.have_manager:             # <<<<<<<<<<<<<<
 *         return self.manager.fk_tmps[taskid]
 *     else:
 */
  __pyx_t_1 = (__pyx_v_self->have_manager != 0);
  if (__pyx_t_1) {

    /* "wlsqm/fitter/infra.pyx":638
 * cdef double* Case_get_fk_tmp( Case* self, int taskid ) nogil:
 *     if self.have_manager:
 *         return self.manager.fk_tmps[taskid]             # <<<<<<<<<<<<<<
 *     else:
 *         return self.fk_tmp
 */
    __pyx_r = (__pyx_v_self->manager->fk_tmps[__pyx_v_taskid]);
    goto __pyx_L0;

    /* "wlsqm/fitter/infra.pyx":637
 * 
 * cdef double* Case_get_fk_tmp( Case* self, int taskid ) nogil:
 *     if self.have_manager:             # <<<<<<<<<<<<<<
 *         return self.manager.fk_tmps[taskid]
 *     else:
 */
  }

  /* "wlsqm/fitter/infra.pyx":640
 *         return self.manager.fk_tmps[taskid]
 *     else:
 *         return self.fk_tmp             # <<<<<<<<<<<<<<
 * 
 * cdef double* Case_get_fi_tmp( Case* self, int taskid ) nogil:
 */
  /*else*/ {
    __pyx_r = __pyx_v_self->fk_tmp;
    goto __pyx_L0;
  }

  /* "wlsqm/fitter/infra.pyx":636
 *         return self.wrk
 * 
 * cdef double* Case_get_fk_tmp( Case* self, int taskid ) nogil:             # <<<<<<<<<<<<<<
 *     if self.have_manager:
 *         return self.manager.fk_tmps[taskid]
 */

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

/* "wlsqm/fitter/infra.pyx":642
 *         return self.fk_tmp
 * 
 * cdef double* Case_get_fi_tmp( Case* self, int taskid ) nogil:             # <<<<<<<<<<<<<<
 *     if self.have_manager:
 *         return self.manager.fi_tmps[taskid]
 */

static double *__pyx_f_5wlsqm_6fitter_5infra_Case_get_fi_tmp(struct __pyx_t_5wlsqm_6fitter_5infra_Case *__pyx_v_self, int __pyx_v_taskid) {
  double *__pyx_r;
  int __pyx_t_1;

  /* "wlsqm/fitter/infra.pyx":643
 * 
 * cdef double* Case_get_fi_tmp( Case* self, int taskid ) nogil:
 *     if self.have_manager:             # <<<<<<<<<<<<<<
 *         return self.manager.fi_tmps[taskid]
 *     else:
 */
  __pyx_t_1 = (__pyx_v_self->have_manager != 0);
  if (__pyx_t_1) {

    /* "wlsqm/fitter/infra.pyx":644
 * cdef double* Case_get_fi_tmp( Case* self, int taskid ) nogil:
 *     if self.have_manager:
 *         return self.manager.fi_tmps[taskid]             # <<<<<<<<<<<<<<
 *     else:
 *         return self.fi_tmp
 */
    __pyx_r = (__pyx_v_self->manager->fi_tmps[__pyx_v_taskid]);
    goto __pyx_L0;

    /* "wlsqm/fitter/infra.pyx":643
 * 
 * cdef double* Case_get_fi_tmp( Case* self, int taskid ) nogil:
 *     if self.have_manager:             # <<<<<<<<<<<<<<
 *         return self.manager.fi_tmps[taskid]
 *     else:
 */
  }

  /* "wlsqm/fitter/infra.pyx":646
 *         return self.manager.fi_tmps[taskid]
 *     else:
 *         return self.fi_tmp             # <<<<<<<<<<<<<<
 * 
 * # Helper: convert an (nk,) array of squared distances to corresponding weights.
 */
  /*else*/ {
    __pyx_r = __pyx_v_self->fi_tmp;
    goto __pyx_L0;
  }

  /* "wlsqm/fitter/infra.pyx":642
 *         return self.fk_tmp
 * 
 * cdef double* Case_get_fi_tmp( Case* self, int taskid ) nogil:             # <<<<<<<<<<<<<<
 *     if self.have_manager:
 *         return self.manager.fi_tmps[taskid]
 */

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

/* "wlsqm/fitter/infra.pyx":658
 * #                    different weightings are good for different use cases of WLSQM.
 * #
 * cdef void Case_make_weights( Case* self, double max_d2 ) nogil:             # <<<<<<<<<<<<<<
 *     cdef double* w = self.w
 *     cdef int nk    = self.nk
 */

static void __pyx_f_5wlsqm_6fitter_5infra_Case_make_weights(struct __pyx_t_5wlsqm_6fitter_5infra_Case *__pyx_v_self, double __pyx_v_max_d2) {
  double *__pyx_v_w;
  int __pyx_v_nk;
  int __pyx_v_weighting_method;
  int __pyx_v_k;
  double __pyx_v_d2;
  double __pyx_v_tmp;
  double *__pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;

  /* "wlsqm/fitter/infra.pyx":659
 * #
 * cdef void Case_make_weights( Case* self, double max_d2 ) nogil:
 *     cdef double* w = self.w             # <<<<<<<<<<<<<<
 *     cdef int nk    = self.nk
 *     cdef int weighting_method = self.weighting_method
 */
  __pyx_t_1 = __pyx_v_self->w;
  __pyx_v_w = __pyx_t_1;

  /* "wlsqm/fitter/infra.pyx":660
 * cdef void Case_make_weights( Case* self, double max_d2 ) nogil:
 *     cdef double* w = self.w
 *     cdef int nk    = self.nk             # <<<<<<<<<<<<<<
 *     cdef int weighting_method = self.weighting_method
 * 
 */
  __pyx_t_2 = __pyx_v_self->nk;
  __pyx_v_nk = __pyx_t_2;

  /* "wlsqm/fitter/infra.pyx":661
 *     cdef double* w = self.w
 *     cdef int nk    = self.nk
 *     cdef int weighting_method = self.weighting_method             # <<<<<<<<<<<<<<
 * 
 *     # no-op in guest mode (weights already computed in the host Case instance)
 */
  __pyx_t_2 = __pyx_v_self->weighting_method;
  __pyx_v_weighting_method = __pyx_t_2;

  /* "wlsqm/fitter/infra.pyx":664
 * 
 *     # no-op in guest mode (weights already computed in the host Case instance)
 *     if not self.geometry_owned:             # <<<<<<<<<<<<<<
 *         return
 * 
 */
  __pyx_t_3 = ((!(__pyx_v_self->geometry_owned != 0)) != 0);
  if (__pyx_t_3) {

    /* "wlsqm/fitter/infra.pyx":665
 *     # no-op in guest mode (weights already computed in the host Case instance)
 *     if not self.geometry_owned:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     cdef int k
 */
    goto __pyx_L0;

    /* "wlsqm/fitter/infra.pyx":664
 * 
 *     # no-op in guest mode (weights already computed in the host Case instance)
 *     if not self.geometry_owned:             # <<<<<<<<<<<<<<
 *         return
 * 
 */
  }

  /* "wlsqm/fitter/infra.pyx":669
 *     cdef int k
 *     cdef double d2, tmp
 *     if weighting_method == defs.WEIGHT_UNIFORM_c:             # <<<<<<<<<<<<<<
 *         # Trivial weighting. Don't use distance information, treat all points as equally important.
 *         #
 */
  __pyx_t_3 = ((__pyx_v_weighting_method == __pyx_v_5wlsqm_6fitter_4defs_WEIGHT_UNIFORM_c) != 0);
  if (__pyx_t_3) {

    /* "wlsqm/fitter/infra.pyx":678
 *         #  from far-away points corrupts them.)
 *         #
 *         for k in range(nk):             # <<<<<<<<<<<<<<
 *             w[k] = 1.
 * 
 */
    __pyx_t_2 = __pyx_v_nk;
    for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_2; __pyx_t_4+=1) {
      __pyx_v_k = __pyx_t_4;

      /* "wlsqm/fitter/infra.pyx":679
 *         #
 *         for k in range(nk):
 *             w[k] = 1.             # <<<<<<<<<<<<<<
 * 
 *     else: # weighting_method == defs.WEIGHT_CENTER_c:
 */
      (__pyx_v_w[__pyx_v_k]) = 1.;
    }

    /* "wlsqm/fitter/infra.pyx":669
 *     cdef int k
 *     cdef double d2, tmp
 *     if weighting_method == defs.WEIGHT_UNIFORM_c:             # <<<<<<<<<<<<<<
 *         # Trivial weighting. Don't use distance information, treat all points as equally important.
 *         #
 */
    goto __pyx_L4;
  }

  /* "wlsqm/fitter/infra.pyx":687
 *         # of function values at points xk that are (relatively speaking) distant from xi.
 *         #
 *         for k in range(nk):             # <<<<<<<<<<<<<<
 *             d2 = w[k]  # the array w originally contains squared distances (without normalization)
 * 
 */
  /*else*/ {
    __pyx_t_2 = __pyx_v_nk;
    for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_2; __pyx_t_4+=1) {
      __pyx_v_k = __pyx_t_4;

      /* "wlsqm/fitter/infra.pyx":688
 *         #
 *         for k in range(nk):
 *             d2 = w[k]  # the array w originally contains squared distances (without normalization)             # <<<<<<<<<<<<<<
 * 
 *             # distance squared, flipped on the distance axis (fast falloff near origin)
 */
      __pyx_v_d2 = (__pyx_v_w[__pyx_v_k]);

      /* "wlsqm/fitter/infra.pyx":693
 *             DEF alpha = 1e-4  # weight remaining at maximum distance
 *             DEF beta  = 1. - alpha
 *             tmp = 1. - sqrt(d2 / max_d2)             # <<<<<<<<<<<<<<
 *             w[k] = alpha + beta * tmp*tmp
 * 
 */
      __pyx_v_tmp = (1. - sqrt((__pyx_v_d2 / __pyx_v_max_d2)));

      /* "wlsqm/fitter/infra.pyx":694
 *             DEF beta  = 1. - alpha
 *             tmp = 1. - sqrt(d2 / max_d2)
 *             w[k] = alpha + beta * tmp*tmp             # <<<<<<<<<<<<<<
 * 
 * # Determine how many bytes of memory this Case will need for storing its arrays.
 */
      (__pyx_v_w[__pyx_v_k]) = (0.0001 + ((0.9999 * __pyx_v_tmp) * __pyx_v_tmp));
    }
  }
  __pyx_L4:;

  /* "wlsqm/fitter/infra.pyx":658
 * #                    different weightings are good for different use cases of WLSQM.
 * #
 * cdef void Case_make_weights( Case* self, double max_d2 ) nogil:             # <<<<<<<<<<<<<<
 *     cdef double* w = self.w
 *     cdef int nk    = self.nk
 */

  /* function exit code */
  __pyx_L0:;
}

/* "wlsqm/fitter/infra.pyx":700
 * # Write the result into the given BufferSizes struct.
 * #
 * cdef void Case_determine_sizes( Case* self, BufferSizes* sizes ) nogil:             # <<<<<<<<<<<<<<
 *     cdef int no        = self.no
 *     cdef int nr        = self.nr
 */

static void __pyx_f_5wlsqm_6fitter_5infra_Case_determine_sizes(struct __pyx_t_5wlsqm_6fitter_5infra_Case *__pyx_v_self, struct __pyx_t_5wlsqm_6fitter_5infra_BufferSizes *__pyx_v_sizes) {
  int __pyx_v_no;
  int __pyx_v_nr;
  int __pyx_v_nk;
  int __pyx_v_do_sens;
  int __pyx_v_iterative;
  int __pyx_v_no2;
  int __pyx_t_1;
  int __pyx_t_2;

  /* "wlsqm/fitter/infra.pyx":701
 * #
 * cdef void Case_determine_sizes( Case* self, BufferSizes* sizes ) nogil:
 *     cdef int no        = self.no             # <<<<<<<<<<<<<<
 *     cdef int nr        = self.nr
 *     cdef int nk        = self.nk
 */
  __pyx_t_1 = __pyx_v_self->no;
  __pyx_v_no = __pyx_t_1;

  /* "wlsqm/fitter/infra.pyx":702
 * cdef void Case_determine_sizes( Case* self, BufferSizes* sizes ) nogil:
 *     cdef int no        = self.no
 *     cdef int nr        = self.nr             # <<<<<<<<<<<<<<
 *     cdef int nk        = self.nk
 *     cdef int do_sens   = self.do_sens
 */
  __pyx_t_1 = __pyx_v_self->nr;
  __pyx_v_nr = __pyx_t_1;

  /* "wlsqm/fitter/infra.pyx":703
 *     cdef int no        = self.no
 *     cdef int nr        = self.nr
 *     cdef int nk        = self.nk             # <<<<<<<<<<<<<<
 *     cdef int do_sens   = self.do_sens
 *     cdef int iterative = self.iterative
 */
  __pyx_t_1 = __pyx_v_self->nk;
  __pyx_v_nk = __pyx_t_1;

  /* "wlsqm/fitter/infra.pyx":704
 *     cdef int nr        = self.nr
 *     cdef int nk        = self.nk
 *     cdef int do_sens   = self.do_sens             # <<<<<<<<<<<<<<
 *     cdef int iterative = self.iterative
 * 
 */
  __pyx_t_1 = __pyx_v_self->do_sens;
  __pyx_v_do_sens = __pyx_t_1;

  /* "wlsqm/fitter/infra.pyx":705
 *     cdef int nk        = self.nk
 *     cdef int do_sens   = self.do_sens
 *     cdef int iterative = self.iterative             # <<<<<<<<<<<<<<
 * 
 *     if self.geometry_owned:
 */
  __pyx_t_1 = __pyx_v_self->iterative;
  __pyx_v_iterative = __pyx_t_1;

  /* "wlsqm/fitter/infra.pyx":707
 *     cdef int iterative = self.iterative
 * 
 *     if self.geometry_owned:             # <<<<<<<<<<<<<<
 *         sizes.o2r       = no*sizeof(int)        # (no,)
 *         sizes.r2o       = no*sizeof(int)        # (no,)
 */
  __pyx_t_2 = (__pyx_v_self->geometry_owned != 0);
  if (__pyx_t_2) {

    /* "wlsqm/fitter/infra.pyx":708
 * 
 *     if self.geometry_owned:
 *         sizes.o2r       = no*sizeof(int)        # (no,)             # <<<<<<<<<<<<<<
 *         sizes.r2o       = no*sizeof(int)        # (no,)
 *         sizes.c         = nk*no*sizeof(double)  # (nk,no), C-contiguous
 */
    __pyx_v_sizes->o2r = (__pyx_v_no * (sizeof(int)));

    /* "wlsqm/fitter/infra.pyx":709
 *     if self.geometry_owned:
 *         sizes.o2r       = no*sizeof(int)        # (no,)
 *         sizes.r2o       = no*sizeof(int)        # (no,)             # <<<<<<<<<<<<<<
 *         sizes.c         = nk*no*sizeof(double)  # (nk,no), C-contiguous
 *         sizes.w         = nk*sizeof(double)     # (nk,)
 */
    __pyx_v_sizes->r2o = (__pyx_v_no * (sizeof(int)));

    /* "wlsqm/fitter/infra.pyx":710
 *         sizes.o2r       = no*sizeof(int)        # (no,)
 *         sizes.r2o       = no*sizeof(int)        # (no,)
 *         sizes.c         = nk*no*sizeof(double)  # (nk,no), C-contiguous             # <<<<<<<<<<<<<<
 *         sizes.w         = nk*sizeof(double)     # (nk,)
 *         sizes.A         = nr*nr*sizeof(double)  # (nr, nr), Fortran-contiguous
 */
    __pyx_v_sizes->c = ((__pyx_v_nk * __pyx_v_no) * (sizeof(double)));

    /* "wlsqm/fitter/infra.pyx":711
 *         sizes.r2o       = no*sizeof(int)        # (no,)
 *         sizes.c         = nk*no*sizeof(double)  # (nk,no), C-contiguous
 *         sizes.w         = nk*sizeof(double)     # (nk,)             # <<<<<<<<<<<<<<
 *         sizes.A         = nr*nr*sizeof(double)  # (nr, nr), Fortran-contiguous
 *         sizes.row_scale = nr*sizeof(double)     # (nr,)
 */
    __pyx_v_sizes->w = (__pyx_v_nk * (sizeof(double)));

    /* "wlsqm/fitter/infra.pyx":712
 *         sizes.c         = nk*no*sizeof(double)  # (nk,no), C-contiguous
 *         sizes.w         = nk*sizeof(double)     # (nk,)
 *         sizes.A         = nr*nr*sizeof(double)  # (nr, nr), Fortran-contiguous             # <<<<<<<<<<<<<<
 *         sizes.row_scale = nr*sizeof(double)     # (nr,)
 *         sizes.col_scale = nr*sizeof(double)     # (nr,)
 */
    __pyx_v_sizes->A = ((__pyx_v_nr * __pyx_v_nr) * (sizeof(double)));

    /* "wlsqm/fitter/infra.pyx":713
 *         sizes.w         = nk*sizeof(double)     # (nk,)
 *         sizes.A         = nr*nr*sizeof(double)  # (nr, nr), Fortran-contiguous
 *         sizes.row_scale = nr*sizeof(double)     # (nr,)             # <<<<<<<<<<<<<<
 *         sizes.col_scale = nr*sizeof(double)     # (nr,)
 *         sizes.ipiv      = nr*sizeof(int)        # (nr,)
 */
    __pyx_v_sizes->row_scale = (__pyx_v_nr * (sizeof(double)));

    /* "wlsqm/fitter/infra.pyx":714
 *         sizes.A         = nr*nr*sizeof(double)  # (nr, nr), Fortran-contiguous
 *         sizes.row_scale = nr*sizeof(double)     # (nr,)
 *         sizes.col_scale = nr*sizeof(double)     # (nr,)             # <<<<<<<<<<<<<<
 *         sizes.ipiv      = nr*sizeof(int)        # (nr,)
 *     else:
 */
    __pyx_v_sizes->col_scale = (__pyx_v_nr * (sizeof(double)));

    /* "wlsqm/fitter/infra.pyx":715
 *         sizes.row_scale = nr*sizeof(double)     # (nr,)
 *         sizes.col_scale = nr*sizeof(double)     # (nr,)
 *         sizes.ipiv      = nr*sizeof(int)        # (nr,)             # <<<<<<<<<<<<<<
 *     else:
 *         # This function computes only bytes needed, so in guest mode we can put zeroes here.
 */
    __pyx_v_sizes->ipiv = (__pyx_v_nr * (sizeof(int)));

    /* "wlsqm/fitter/infra.pyx":707
 *     cdef int iterative = self.iterative
 * 
 *     if self.geometry_owned:             # <<<<<<<<<<<<<<
 *         sizes.o2r       = no*sizeof(int)        # (no,)
 *         sizes.r2o       = no*sizeof(int)        # (no,)
 */
    goto __pyx_L3;
  }

  /* "wlsqm/fitter/infra.pyx":719
 *         # This function computes only bytes needed, so in guest mode we can put zeroes here.
 *         # This function is not used for determining the number of elements in anything.
 *         sizes.o2r       = 0             # <<<<<<<<<<<<<<
 *         sizes.r2o       = 0
 *         sizes.c         = 0
 */
  /*else*/ {
    __pyx_v_sizes->o2r = 0;

    /* "wlsqm/fitter/infra.pyx":720
 *         # This function is not used for determining the number of elements in anything.
 *         sizes.o2r       = 0
 *         sizes.r2o       = 0             # <<<<<<<<<<<<<<
 *         sizes.c         = 0
 *         sizes.w         = 0
 */
    __pyx_v_sizes->r2o = 0;

    /* "wlsqm/fitter/infra.pyx":721
 *         sizes.o2r       = 0
 *         sizes.r2o       = 0
 *         sizes.c         = 0             # <<<<<<<<<<<<<<
 *         sizes.w         = 0
 *         sizes.A         = 0
 */
    __pyx_v_sizes->c = 0;

    /* "wlsqm/fitter/infra.pyx":722
 *         sizes.r2o       = 0
 *         sizes.c         = 0
 *         sizes.w         = 0             # <<<<<<<<<<<<<<
 *         sizes.A         = 0
 *         sizes.row_scale = 0
 */
    __pyx_v_sizes->w = 0;

    /* "wlsqm/fitter/infra.pyx":723
 *         sizes.c         = 0
 *         sizes.w         = 0
 *         sizes.A         = 0             # <<<<<<<<<<<<<<
 *         sizes.row_scale = 0
 *         sizes.col_scale = 0
 */
    __pyx_v_sizes->A = 0;

    /* "wlsqm/fitter/infra.pyx":724
 *         sizes.w         = 0
 *         sizes.A         = 0
 *         sizes.row_scale = 0             # <<<<<<<<<<<<<<
 *         sizes.col_scale = 0
 *         sizes.ipiv      = 0
 */
    __pyx_v_sizes->row_scale = 0;

    /* "wlsqm/fitter/infra.pyx":725
 *         sizes.A         = 0
 *         sizes.row_scale = 0
 *         sizes.col_scale = 0             # <<<<<<<<<<<<<<
 *         sizes.ipiv      = 0
 * 
 */
    __pyx_v_sizes->col_scale = 0;

    /* "wlsqm/fitter/infra.pyx":726
 *         sizes.row_scale = 0
 *         sizes.col_scale = 0
 *         sizes.ipiv      = 0             # <<<<<<<<<<<<<<
 * 
 *     # The coefficient array is always needed.
 */
    __pyx_v_sizes->ipiv = 0;
  }
  __pyx_L3:;

  /* "wlsqm/fitter/infra.pyx":730
 *     # The coefficient array is always needed.
 *     #
 *     sizes.fi        = no*sizeof(double)     # (no,)             # <<<<<<<<<<<<<<
 * 
 *     # For any polynomial of degree  d >= 1,  its (non-zero) derivatives are a polynomial of degree  d - 1.
 */
  __pyx_v_sizes->fi = (__pyx_v_no * (sizeof(double)));

  /* "wlsqm/fitter/infra.pyx":734
 *     # For any polynomial of degree  d >= 1,  its (non-zero) derivatives are a polynomial of degree  d - 1.
 *     # In the zeroth order case, the derivative is everywhere zero.
 *     cdef int no2    = number_of_dofs( self.dimension, self.order - 1 )  if self.order >= 1  else  0             # <<<<<<<<<<<<<<
 *     sizes.fi2       = no2*sizeof(double)    # (no2,)
 * 
 */
  if (((__pyx_v_self->order >= 1) != 0)) {
    __pyx_t_1 = __pyx_f_5wlsqm_6fitter_5infra_number_of_dofs(__pyx_v_self->dimension, (__pyx_v_self->order - 1));
  } else {
    __pyx_t_1 = 0;
  }
  __pyx_v_no2 = __pyx_t_1;

  /* "wlsqm/fitter/infra.pyx":735
 *     # In the zeroth order case, the derivative is everywhere zero.
 *     cdef int no2    = number_of_dofs( self.dimension, self.order - 1 )  if self.order >= 1  else  0
 *     sizes.fi2       = no2*sizeof(double)    # (no2,)             # <<<<<<<<<<<<<<
 * 
 *     # per-task work space arrays
 */
  __pyx_v_sizes->fi2 = (__pyx_v_no2 * (sizeof(double)));

  /* "wlsqm/fitter/infra.pyx":739
 *     # per-task work space arrays
 *     #
 *     if self.have_manager:             # <<<<<<<<<<<<<<
 *         # in managed mode, CaseManager will allocate one copy of the per-task (not per-problem-instance) arrays
 *         sizes.wrk    = 0
 */
  __pyx_t_2 = (__pyx_v_self->have_manager != 0);
  if (__pyx_t_2) {

    /* "wlsqm/fitter/infra.pyx":741
 *     if self.have_manager:
 *         # in managed mode, CaseManager will allocate one copy of the per-task (not per-problem-instance) arrays
 *         sizes.wrk    = 0             # <<<<<<<<<<<<<<
 *         sizes.fk_tmp = 0
 *         sizes.fi_tmp = 0
 */
    __pyx_v_sizes->wrk = 0;

    /* "wlsqm/fitter/infra.pyx":742
 *         # in managed mode, CaseManager will allocate one copy of the per-task (not per-problem-instance) arrays
 *         sizes.wrk    = 0
 *         sizes.fk_tmp = 0             # <<<<<<<<<<<<<<
 *         sizes.fi_tmp = 0
 *     else:
 */
    __pyx_v_sizes->fk_tmp = 0;

    /* "wlsqm/fitter/infra.pyx":743
 *         sizes.wrk    = 0
 *         sizes.fk_tmp = 0
 *         sizes.fi_tmp = 0             # <<<<<<<<<<<<<<
 *     else:
 *         # unmanaged mode - allocate also the per-task arrays locally.
 */
    __pyx_v_sizes->fi_tmp = 0;

    /* "wlsqm/fitter/infra.pyx":739
 *     # per-task work space arrays
 *     #
 *     if self.have_manager:             # <<<<<<<<<<<<<<
 *         # in managed mode, CaseManager will allocate one copy of the per-task (not per-problem-instance) arrays
 *         sizes.wrk    = 0
 */
    goto __pyx_L4;
  }

  /* "wlsqm/fitter/infra.pyx":747
 *         # unmanaged mode - allocate also the per-task arrays locally.
 *         # see the header comment of solve() for the solver work space sizes
 *         if do_sens:             # <<<<<<<<<<<<<<
 *             sizes.wrk = nr*(nk + 1)*sizeof(double)
 *         else:
 */
  /*else*/ {
    __pyx_t_2 = (__pyx_v_do_sens != 0);
    if (__pyx_t_2) {

      /* "wlsqm/fitter/infra.pyx":748
 *         # see the header comment of solve() for the solver work space sizes
 *         if do_sens:
 *             sizes.wrk = nr*(nk + 1)*sizeof(double)             # <<<<<<<<<<<<<<
 *         else:
 *             sizes.wrk = nr*sizeof(double)
 */
      __pyx_v_sizes->wrk = ((__pyx_v_nr * (__pyx_v_nk + 1)) * (sizeof(double)));

      /* "wlsqm/fitter/infra.pyx":747
 *         # unmanaged mode - allocate also the per-task arrays locally.
 *         # see the header comment of solve() for the solver work space sizes
 *         if do_sens:             # <<<<<<<<<<<<<<
 *             sizes.wrk = nr*(nk + 1)*sizeof(double)
 *         else:
 */
      goto __pyx_L5;
    }

    /* "wlsqm/fitter/infra.pyx":750
 *             sizes.wrk = nr*(nk + 1)*sizeof(double)
 *         else:
 *             sizes.wrk = nr*sizeof(double)             # <<<<<<<<<<<<<<
 * 
 *         if iterative:
 */
    /*else*/ {
      __pyx_v_sizes->wrk = (__pyx_v_nr * (sizeof(double)));
    }
    __pyx_L5:;

    /* "wlsqm/fitter/infra.pyx":752
 *             sizes.wrk = nr*sizeof(double)
 * 
 *         if iterative:             # <<<<<<<<<<<<<<
 *             sizes.fk_tmp = nk*sizeof(double)
 *             sizes.fi_tmp = no*sizeof(double)
 */
    __pyx_t_2 = (__pyx_v_iterative != 0);
    if (__pyx_t_2) {

      /* "wlsqm/fitter/infra.pyx":753
 * 
 *         if iterative:
 *             sizes.fk_tmp = nk*sizeof(double)             # <<<<<<<<<<<<<<
 *             sizes.fi_tmp = no*sizeof(double)
 *         else:
 */
      __pyx_v_sizes->fk_tmp = (__pyx_v_nk * (sizeof(double)));

      /* "wlsqm/fitter/infra.pyx":754
 *         if iterative:
 *             sizes.fk_tmp = nk*sizeof(double)
 *             sizes.fi_tmp = no*sizeof(double)             # <<<<<<<<<<<<<<
 *         else:
 *             sizes.fk_tmp = 0
 */
      __pyx_v_sizes->fi_tmp = (__pyx_v_no * (sizeof(double)));

      /* "wlsqm/fitter/infra.pyx":752
 *             sizes.wrk = nr*sizeof(double)
 * 
 *         if iterative:             # <<<<<<<<<<<<<<
 *             sizes.fk_tmp = nk*sizeof(double)
 *             sizes.fi_tmp = no*sizeof(double)
 */
      goto __pyx_L6;
    }

    /* "wlsqm/fitter/infra.pyx":756
 *             sizes.fi_tmp = no*sizeof(double)
 *         else:
 *             sizes.fk_tmp = 0             # <<<<<<<<<<<<<<
 *             sizes.fi_tmp = 0
 * 
 */
    /*else*/ {
      __pyx_v_sizes->fk_tmp = 0;

      /* "wlsqm/fitter/infra.pyx":757
 *         else:
 *             sizes.fk_tmp = 0
 *             sizes.fi_tmp = 0             # <<<<<<<<<<<<<<
 * 
 *     sizes.total = sizes.o2r + sizes.r2o \
 */
      __pyx_v_sizes->fi_tmp = 0;
    }
    __pyx_L6:;
  }
  __pyx_L4:;

  /* "wlsqm/fitter/infra.pyx":759
 *             sizes.fi_tmp = 0
 * 
 *     sizes.total = sizes.o2r + sizes.r2o \             # <<<<<<<<<<<<<<
 *                 + sizes.c + sizes.w \
 *                 + sizes.A + sizes.row_scale + sizes.col_scale + sizes.ipiv \
 */
  __pyx_v_sizes->total = ((((((((((((__pyx_v_sizes->o2r + __pyx_v_sizes->r2o) + __pyx_v_sizes->c) + __pyx_v_sizes->w) + __pyx_v_sizes->A) + __pyx_v_sizes->row_scale) + __pyx_v_sizes->col_scale) + __pyx_v_sizes->ipiv) + __pyx_v_sizes->fi) + __pyx_v_sizes->fi2) + __pyx_v_sizes->wrk) + __pyx_v_sizes->fk_tmp) + __pyx_v_sizes->fi_tmp);

  /* "wlsqm/fitter/infra.pyx":700
 * # Write the result into the given BufferSizes struct.
 * #
 * cdef void Case_determine_sizes( Case* self, BufferSizes* sizes ) nogil:             # <<<<<<<<<<<<<<
 *     cdef int no        = self.no
 *     cdef int nr        = self.nr
 */

  /* function exit code */
}

/* "wlsqm/fitter/infra.pyx":772
 * # This can be used to populate knowns.
 * #
 * cdef void Case_set_fi( Case* self, double* fi ) nogil:             # <<<<<<<<<<<<<<
 *     cdef double* my_fi = self.fi
 *     cdef int no        = self.no
 */

static void __pyx_f_5wlsqm_6fitter_5infra_Case_set_fi(struct __pyx_t_5wlsqm_6fitter_5infra_Case *__pyx_v_self, double *__pyx_v_fi) {
  double *__pyx_v_my_fi;
  int __pyx_v_no;
  int __pyx_v_om;
  double *__pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;

  /* "wlsqm/fitter/infra.pyx":773
 * #
 * cdef void Case_set_fi( Case* self, double* fi ) nogil:
 *     cdef double* my_fi = self.fi             # <<<<<<<<<<<<<<
 *     cdef int no        = self.no
 *     cdef int om
 */
  __pyx_t_1 = __pyx_v_self->fi;
  __pyx_v_my_fi = __pyx_t_1;

  /* "wlsqm/fitter/infra.pyx":774
 * cdef void Case_set_fi( Case* self, double* fi ) nogil:
 *     cdef double* my_fi = self.fi
 *     cdef int no        = self.no             # <<<<<<<<<<<<<<
 *     cdef int om
 *     for om in range(no):
 */
  __pyx_t_2 = __pyx_v_self->no;
  __pyx_v_no = __pyx_t_2;

  /* "wlsqm/fitter/infra.pyx":776
 *     cdef int no        = self.no
 *     cdef int om
 *     for om in range(no):             # <<<<<<<<<<<<<<
 *         my_fi[om] = fi[om]
 * 
 */
  __pyx_t_2 = __pyx_v_no;
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
    __pyx_v_om = __pyx_t_3;

    /* "wlsqm/fitter/infra.pyx":777
 *     cdef int om
 *     for om in range(no):
 *         my_fi[om] = fi[om]             # <<<<<<<<<<<<<<
 * 
 * # Populate user-given array of length self.no
 */
    (__pyx_v_my_fi[__pyx_v_om]) = (__pyx_v_fi[__pyx_v_om]);
  }

  /* "wlsqm/fitter/infra.pyx":772
 * # This can be used to populate knowns.
 * #
 * cdef void Case_set_fi( Case* self, double* fi ) nogil:             # <<<<<<<<<<<<<<
 *     cdef double* my_fi = self.fi
 *     cdef int no        = self.no
 */

  /* function exit code */
}

/* "wlsqm/fitter/infra.pyx":782
 * # with the solution data (coefficients self.fi).
 * #
 * cdef void Case_get_fi( Case* self, double* out ) nogil:             # <<<<<<<<<<<<<<
 *     cdef double* my_fi = self.fi
 *     cdef int no        = self.no
 */

static void __pyx_f_5wlsqm_6fitter_5infra_Case_get_fi(struct __pyx_t_5wlsqm_6fitter_5infra_Case *__pyx_v_self, double *__pyx_v_out) {
  double *__pyx_v_my_fi;
  int __pyx_v_no;
  int __pyx_v_om;
  double *__pyx_t_1;
  int __pyx_t_2;
  int __pyx_t_3;

  /* "wlsqm/fitter/infra.pyx":783
 * #
 * cdef void Case_get_fi( Case* self, double* out ) nogil:
 *     cdef double* my_fi = self.fi             # <<<<<<<<<<<<<<
 *     cdef int no        = self.no
 *     cdef int om
 */
  __pyx_t_1 = __pyx_v_self->fi;
  __pyx_v_my_fi = __pyx_t_1;

  /* "wlsqm/fitter/infra.pyx":784
 * cdef void Case_get_fi( Case* self, double* out ) nogil:
 *     cdef double* my_fi = self.fi
 *     cdef int no        = self.no             # <<<<<<<<<<<<<<
 *     cdef int om
 *     for om in range(no):
 */
  __pyx_t_2 = __pyx_v_self->no;
  __pyx_v_no = __pyx_t_2;

  /* "wlsqm/fitter/infra.pyx":786
 *     cdef int no        = self.no
 *     cdef int om
 *     for om in range(no):             # <<<<<<<<<<<<<<
 *         out[om] = my_fi[om]
 * 
 */
  __pyx_t_2 = __pyx_v_no;
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
    __pyx_v_om = __pyx_t_3;

    /* "wlsqm/fitter/infra.pyx":787
 *     cdef int om
 *     for om in range(no):
 *         out[om] = my_fi[om]             # <<<<<<<<<<<<<<
 * 
 * # Perform memory allocation.
 */
    (__pyx_v_out[__pyx_v_om]) = (__pyx_v_my_fi[__pyx_v_om]);
  }

  /* "wlsqm/fitter/infra.pyx":782
 * # with the solution data (coefficients self.fi).
 * #
 * cdef void Case_get_fi( Case* self, double* out ) nogil:             # <<<<<<<<<<<<<<
 *     cdef double* my_fi = self.fi
 *     cdef int no        = self.no
 */

  /* function exit code */
}

/* "wlsqm/fitter/infra.pyx":791
 * # Perform memory allocation.
 * #
 * cdef int Case_allocate( Case* self ) nogil except -1:             # <<<<<<<<<<<<<<
 *     # At this point, the constructor has finished, so we have no, nr, nk and the flags (do_sens, iterative).
 *     #
 */

static int __pyx_f_5wlsqm_6fitter_5infra_Case_allocate(struct __pyx_t_5wlsqm_6fitter_5infra_Case *__pyx_v_self) {
  struct __pyx_t_5wlsqm_6fitter_5infra_BufferSizes __pyx_v_sizes;
  int __pyx_v_size_remaining;
  struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *__pyx_v_mal;
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *__pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  #ifdef WITH_THREAD
  PyGILState_STATE __pyx_gilstate_save;
  #endif
  __Pyx_RefNannySetupContext("Case_allocate", 1);

  /* "wlsqm/fitter/infra.pyx":798
 *     # (This also calculates the various individual sizes, which we will use to actually allocate the memory.)
 *     #
 *     cdef BufferSizes sizes             # <<<<<<<<<<<<<<
 *     Case_determine_sizes( self, &sizes )
 * 
 */
  /*try:*/ {

    /* "wlsqm/fitter/infra.pyx":799
 *     #
 *     cdef BufferSizes sizes
 *     Case_determine_sizes( self, &sizes )             # <<<<<<<<<<<<<<
 * 
 *     # Acquire or create the custom memory allocator to allocate storage for actual data.
 */
    __pyx_f_5wlsqm_6fitter_5infra_Case_determine_sizes(__pyx_v_self, (&__pyx_v_sizes));

    /* "wlsqm/fitter/infra.pyx":803
 *     # Acquire or create the custom memory allocator to allocate storage for actual data.
 *     #
 *     cdef int size_remaining=-1             # <<<<<<<<<<<<<<
 *     cdef Allocator* mal
 *     with gil:
 */
    __pyx_v_size_remaining = -1;

    /* "wlsqm/fitter/infra.pyx":805
 *     cdef int size_remaining=-1
 *     cdef Allocator* mal
 *     with gil:             # <<<<<<<<<<<<<<
 *         try:
 *             if self.have_manager:  # managed mode - external allocator given; check that it has enough space for us.
 */
    {
        #ifdef WITH_THREAD
        PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();
        #endif
        /*try:*/ {

          /* "wlsqm/fitter/infra.pyx":806
 *     cdef Allocator* mal
 *     with gil:
 *         try:             # <<<<<<<<<<<<<<
 *             if self.have_manager:  # managed mode - external allocator given; check that it has enough space for us.
 *                 mal = self.manager.mal
 */
          {
            __Pyx_PyThreadState_declare
            __Pyx_PyThreadState_assign
            __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
            __Pyx_XGOTREF(__pyx_t_1);
            __Pyx_XGOTREF(__pyx_t_2);
            __Pyx_XGOTREF(__pyx_t_3);
            /*try:*/ {

              /* "wlsqm/fitter/infra.pyx":807
 *     with gil:
 *         try:
 *             if self.have_manager:  # managed mode - external allocator given; check that it has enough space for us.             # <<<<<<<<<<<<<<
 *                 mal = self.manager.mal
 *                 size_remaining = Allocator_size_remaining( mal )
 */
              __pyx_t_4 = (__pyx_v_self->have_manager != 0);
              if (__pyx_t_4) {

                /* "wlsqm/fitter/infra.pyx":808
 *         try:
 *             if self.have_manager:  # managed mode - external allocator given; check that it has enough space for us.
 *                 mal = self.manager.mal             # <<<<<<<<<<<<<<
 *                 size_remaining = Allocator_size_remaining( mal )
 *                 if size_remaining < sizes.total:
 */
                __pyx_t_5 = __pyx_v_self->manager->mal;
                __pyx_v_mal = __pyx_t_5;

                /* "wlsqm/fitter/infra.pyx":809
 *             if self.have_manager:  # managed mode - external allocator given; check that it has enough space for us.
 *                 mal = self.manager.mal
 *                 size_remaining = Allocator_size_remaining( mal )             # <<<<<<<<<<<<<<
 *                 if size_remaining < sizes.total:
 *                     raise MemoryError("%d bytes of memory needed, but the given allocator has only %d bytes remaining." % (sizes.total, size_remaining))
 */
                __pyx_v_size_remaining = __pyx_f_5wlsqm_6fitter_5infra_Allocator_size_remaining(__pyx_v_mal);

                /* "wlsqm/fitter/infra.pyx":810
 *                 mal = self.manager.mal
 *                 size_remaining = Allocator_size_remaining( mal )
 *                 if size_remaining < sizes.total:             # <<<<<<<<<<<<<<
 *                     raise MemoryError("%d bytes of memory needed, but the given allocator has only %d bytes remaining." % (sizes.total, size_remaining))
 * 
 */
                __pyx_t_4 = ((__pyx_v_size_remaining < __pyx_v_sizes.total) != 0);
                if (__pyx_t_4) {

                  /* "wlsqm/fitter/infra.pyx":811
 *                 size_remaining = Allocator_size_remaining( mal )
 *                 if size_remaining < sizes.total:
 *                     raise MemoryError("%d bytes of memory needed, but the given allocator has only %d bytes remaining." % (sizes.total, size_remaining))             # <<<<<<<<<<<<<<
 * 
 *             else:  # unmanaged mode - instantiate our own Allocator. The Allocator constructor will raise MemoryError if it runs out of memory.
 */
                  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_sizes.total); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 811, __pyx_L9_error)
                  __Pyx_GOTREF(__pyx_t_6);
                  __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_size_remaining); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 811, __pyx_L9_error)
                  __Pyx_GOTREF(__pyx_t_7);
                  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 811, __pyx_L9_error)
                  __Pyx_GOTREF(__pyx_t_8);
                  __Pyx_GIVEREF(__pyx_t_6);
                  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_6);
                  __Pyx_GIVEREF(__pyx_t_7);
                  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
                  __pyx_t_6 = 0;
                  __pyx_t_7 = 0;
                  __pyx_t_7 = __Pyx_PyString_Format(__pyx_kp_s_d_bytes_of_memory_needed_but_th, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 811, __pyx_L9_error)
                  __Pyx_GOTREF(__pyx_t_7);
                  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
                  __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 811, __pyx_L9_error)
                  __Pyx_GOTREF(__pyx_t_8);
                  __Pyx_GIVEREF(__pyx_t_7);
                  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7);
                  __pyx_t_7 = 0;
                  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_t_8, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 811, __pyx_L9_error)
                  __Pyx_GOTREF(__pyx_t_7);
                  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
                  __Pyx_Raise(__pyx_t_7, 0, 0, 0);
                  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
                  __PYX_ERR(0, 811, __pyx_L9_error)

                  /* "wlsqm/fitter/infra.pyx":810
 *                 mal = self.manager.mal
 *                 size_remaining = Allocator_size_remaining( mal )
 *                 if size_remaining < sizes.total:             # <<<<<<<<<<<<<<
 *                     raise MemoryError("%d bytes of memory needed, but the given allocator has only %d bytes remaining." % (sizes.total, size_remaining))
 * 
 */
                }

                /* "wlsqm/fitter/infra.pyx":807
 *     with gil:
 *         try:
 *             if self.have_manager:  # managed mode - external allocator given; check that it has enough space for us.             # <<<<<<<<<<<<<<
 *                 mal = self.manager.mal
 *                 size_remaining = Allocator_size_remaining( mal )
 */
                goto __pyx_L17;
              }

              /* "wlsqm/fitter/infra.pyx":814
 * 
 *             else:  # unmanaged mode - instantiate our own Allocator. The Allocator constructor will raise MemoryError if it runs out of memory.
 *                 mal = Allocator_new( mode=ALLOC_MODE_ONEBIGBUFFER, total_size_bytes=sizes.total )             # <<<<<<<<<<<<<<
 *         except:
 *             free( self )
 */
              /*else*/ {
                __pyx_t_5 = __pyx_f_5wlsqm_6fitter_5infra_Allocator_new(__pyx_v_5wlsqm_6fitter_5infra_ALLOC_MODE_ONEBIGBUFFER, __pyx_v_sizes.total); if (unlikely(__pyx_t_5 == ((struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *)0))) __PYX_ERR(0, 814, __pyx_L9_error)
                __pyx_v_mal = __pyx_t_5;
              }
              __pyx_L17:;

              /* "wlsqm/fitter/infra.pyx":806
 *     cdef Allocator* mal
 *     with gil:
 *         try:             # <<<<<<<<<<<<<<
 *             if self.have_manager:  # managed mode - external allocator given; check that it has enough space for us.
 *                 mal = self.manager.mal
 */
            }
            __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
            __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
            goto __pyx_L16_try_end;
            __pyx_L9_error:;
            __Pyx_PyThreadState_assign
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
            __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;

            /* "wlsqm/fitter/infra.pyx":815
 *             else:  # unmanaged mode - instantiate our own Allocator. The Allocator constructor will raise MemoryError if it runs out of memory.
 *                 mal = Allocator_new( mode=ALLOC_MODE_ONEBIGBUFFER, total_size_bytes=sizes.total )
 *         except:             # <<<<<<<<<<<<<<
 *             free( self )
 *             raise
 */
            /*except:*/ {
              __Pyx_AddTraceback("wlsqm.fitter.infra.Case_allocate", __pyx_clineno, __pyx_lineno, __pyx_filename);
              if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_8, &__pyx_t_6) < 0) __PYX_ERR(0, 815, __pyx_L11_except_error)
              __Pyx_GOTREF(__pyx_t_7);
              __Pyx_GOTREF(__pyx_t_8);
              __Pyx_GOTREF(__pyx_t_6);

              /* "wlsqm/fitter/infra.pyx":816
 *                 mal = Allocator_new( mode=ALLOC_MODE_ONEBIGBUFFER, total_size_bytes=sizes.total )
 *         except:
 *             free( self )             # <<<<<<<<<<<<<<
 *             raise
 *     self.mal = mal
 */
              free(__pyx_v_self);

              /* "wlsqm/fitter/infra.pyx":817
 *         except:
 *             free( self )
 *             raise             # <<<<<<<<<<<<<<
 *     self.mal = mal
 * 
 */
              __Pyx_GIVEREF(__pyx_t_7);
              __Pyx_GIVEREF(__pyx_t_8);
              __Pyx_XGIVEREF(__pyx_t_6);
              __Pyx_ErrRestoreWithState(__pyx_t_7, __pyx_t_8, __pyx_t_6);
              __pyx_t_7 = 0; __pyx_t_8 = 0; __pyx_t_6 = 0; 
              __PYX_ERR(0, 817, __pyx_L11_except_error)
            }
            __pyx_L11_except_error:;

            /* "wlsqm/fitter/infra.pyx":806
 *     cdef Allocator* mal
 *     with gil:
 *         try:             # <<<<<<<<<<<<<<
 *             if self.have_manager:  # managed mode - external allocator given; check that it has enough space for us.
 *                 mal = self.manager.mal
 */
            __Pyx_PyThreadState_assign
            __Pyx_XGIVEREF(__pyx_t_1);
            __Pyx_XGIVEREF(__pyx_t_2);
            __Pyx_XGIVEREF(__pyx_t_3);
            __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
            goto __pyx_L7_error;
            __pyx_L16_try_end:;
          }
        }

        /* "wlsqm/fitter/infra.pyx":805
 *     cdef int size_remaining=-1
 *     cdef Allocator* mal
 *     with gil:             # <<<<<<<<<<<<<<
 *         try:
 *             if self.have_manager:  # managed mode - external allocator given; check that it has enough space for us.
 */
        /*finally:*/ {
          /*normal exit:*/{
            #ifdef WITH_THREAD
            PyGILState_Release(__pyx_gilstate_save);
            #endif
            goto __pyx_L8;
          }
          __pyx_L7_error: {
            #ifdef WITH_THREAD
            PyGILState_Release(__pyx_gilstate_save);
            #endif
            goto __pyx_L4_error;
          }
          __pyx_L8:;
        }
    }

    /* "wlsqm/fitter/infra.pyx":818
 *             free( self )
 *             raise
 *     self.mal = mal             # <<<<<<<<<<<<<<
 * 
 *     # Allocate the storage, using the custom allocator.
 */
    __pyx_v_self->mal = __pyx_v_mal;

    /* "wlsqm/fitter/infra.pyx":822
 *     # Allocate the storage, using the custom allocator.
 *     #
 *     if self.geometry_owned:             # <<<<<<<<<<<<<<
 *         self.o2r       = <int*>   Allocator_malloc( mal, sizes.o2r )
 *         self.r2o       = <int*>   Allocator_malloc( mal, sizes.r2o )
 */
    __pyx_t_4 = (__pyx_v_self->geometry_owned != 0);
    if (__pyx_t_4) {

      /* "wlsqm/fitter/infra.pyx":823
 *     #
 *     if self.geometry_owned:
 *         self.o2r       = <int*>   Allocator_malloc( mal, sizes.o2r )             # <<<<<<<<<<<<<<
 *         self.r2o       = <int*>   Allocator_malloc( mal, sizes.r2o )
 * 
 */
      __pyx_v_self->o2r = ((int *)__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc(__pyx_v_mal, __pyx_v_sizes.o2r));

      /* "wlsqm/fitter/infra.pyx":824
 *     if self.geometry_owned:
 *         self.o2r       = <int*>   Allocator_malloc( mal, sizes.o2r )
 *         self.r2o       = <int*>   Allocator_malloc( mal, sizes.r2o )             # <<<<<<<<<<<<<<
 * 
 *         self.c         = <double*>Allocator_malloc( mal, sizes.c )
 */
      __pyx_v_self->r2o = ((int *)__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc(__pyx_v_mal, __pyx_v_sizes.r2o));

      /* "wlsqm/fitter/infra.pyx":826
 *         self.r2o       = <int*>   Allocator_malloc( mal, sizes.r2o )
 * 
 *         self.c         = <double*>Allocator_malloc( mal, sizes.c )             # <<<<<<<<<<<<<<
 *         self.w         = <double*>Allocator_malloc( mal, sizes.w )
 * 
 */
      __pyx_v_self->c = ((double *)__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc(__pyx_v_mal, __pyx_v_sizes.c));

      /* "wlsqm/fitter/infra.pyx":827
 * 
 *         self.c         = <double*>Allocator_malloc( mal, sizes.c )
 *         self.w         = <double*>Allocator_malloc( mal, sizes.w )             # <<<<<<<<<<<<<<
 * 
 *         self.A         = <double*>Allocator_malloc( mal, sizes.A )
 */
      __pyx_v_self->w = ((double *)__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc(__pyx_v_mal, __pyx_v_sizes.w));

      /* "wlsqm/fitter/infra.pyx":829
 *         self.w         = <double*>Allocator_malloc( mal, sizes.w )
 * 
 *         self.A         = <double*>Allocator_malloc( mal, sizes.A )             # <<<<<<<<<<<<<<
 *         self.row_scale = <double*>Allocator_malloc( mal, sizes.row_scale )
 *         self.col_scale = <double*>Allocator_malloc( mal, sizes.col_scale )
 */
      __pyx_v_self->A = ((double *)__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc(__pyx_v_mal, __pyx_v_sizes.A));

      /* "wlsqm/fitter/infra.pyx":830
 * 
 *         self.A         = <double*>Allocator_malloc( mal, sizes.A )
 *         self.row_scale = <double*>Allocator_malloc( mal, sizes.row_scale )             # <<<<<<<<<<<<<<
 *         self.col_scale = <double*>Allocator_malloc( mal, sizes.col_scale )
 *         self.ipiv      = <int*>   Allocator_malloc( mal, sizes.ipiv )
 */
      __pyx_v_self->row_scale = ((double *)__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc(__pyx_v_mal, __pyx_v_sizes.row_scale));

      /* "wlsqm/fitter/infra.pyx":831
 *         self.A         = <double*>Allocator_malloc( mal, sizes.A )
 *         self.row_scale = <double*>Allocator_malloc( mal, sizes.row_scale )
 *         self.col_scale = <double*>Allocator_malloc( mal, sizes.col_scale )             # <<<<<<<<<<<<<<
 *         self.ipiv      = <int*>   Allocator_malloc( mal, sizes.ipiv )
 * 
 */
      __pyx_v_self->col_scale = ((double *)__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc(__pyx_v_mal, __pyx_v_sizes.col_scale));

      /* "wlsqm/fitter/infra.pyx":832
 *         self.row_scale = <double*>Allocator_malloc( mal, sizes.row_scale )
 *         self.col_scale = <double*>Allocator_malloc( mal, sizes.col_scale )
 *         self.ipiv      = <int*>   Allocator_malloc( mal, sizes.ipiv )             # <<<<<<<<<<<<<<
 * 
 *     self.fi        = <double*>Allocator_malloc( mal, sizes.fi )
 */
      __pyx_v_self->ipiv = ((int *)__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc(__pyx_v_mal, __pyx_v_sizes.ipiv));

      /* "wlsqm/fitter/infra.pyx":822
 *     # Allocate the storage, using the custom allocator.
 *     #
 *     if self.geometry_owned:             # <<<<<<<<<<<<<<
 *         self.o2r       = <int*>   Allocator_malloc( mal, sizes.o2r )
 *         self.r2o       = <int*>   Allocator_malloc( mal, sizes.r2o )
 */
    }

    /* "wlsqm/fitter/infra.pyx":834
 *         self.ipiv      = <int*>   Allocator_malloc( mal, sizes.ipiv )
 * 
 *     self.fi        = <double*>Allocator_malloc( mal, sizes.fi )             # <<<<<<<<<<<<<<
 * 
 *     if sizes.fi2:
 */
    __pyx_v_self->fi = ((double *)__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc(__pyx_v_mal, __pyx_v_sizes.fi));

    /* "wlsqm/fitter/infra.pyx":836
 *     self.fi        = <double*>Allocator_malloc( mal, sizes.fi )
 * 
 *     if sizes.fi2:             # <<<<<<<<<<<<<<
 *         self.fi2   = <double*>Allocator_malloc( mal, sizes.fi2 )
 *     else:
 */
    __pyx_t_4 = (__pyx_v_sizes.fi2 != 0);
    if (__pyx_t_4) {

      /* "wlsqm/fitter/infra.pyx":837
 * 
 *     if sizes.fi2:
 *         self.fi2   = <double*>Allocator_malloc( mal, sizes.fi2 )             # <<<<<<<<<<<<<<
 *     else:
 *         self.fi2   = <double*>0
 */
      __pyx_v_self->fi2 = ((double *)__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc(__pyx_v_mal, __pyx_v_sizes.fi2));

      /* "wlsqm/fitter/infra.pyx":836
 *     self.fi        = <double*>Allocator_malloc( mal, sizes.fi )
 * 
 *     if sizes.fi2:             # <<<<<<<<<<<<<<
 *         self.fi2   = <double*>Allocator_malloc( mal, sizes.fi2 )
 *     else:
 */
      goto __pyx_L22;
    }

    /* "wlsqm/fitter/infra.pyx":839
 *         self.fi2   = <double*>Allocator_malloc( mal, sizes.fi2 )
 *     else:
 *         self.fi2   = <double*>0             # <<<<<<<<<<<<<<
 * 
 *     if self.have_manager:
 */
    /*else*/ {
      __pyx_v_self->fi2 = ((double *)0);
    }
    __pyx_L22:;

    /* "wlsqm/fitter/infra.pyx":841
 *         self.fi2   = <double*>0
 * 
 *     if self.have_manager:             # <<<<<<<<<<<<<<
 *         # in managed mode, CaseManager will allocate one copy of the per-task (not per-problem-instance) arrays
 *         self.wrk    = <double*>0
 */
    __pyx_t_4 = (__pyx_v_self->have_manager != 0);
    if (__pyx_t_4) {

      /* "wlsqm/fitter/infra.pyx":843
 *     if self.have_manager:
 *         # in managed mode, CaseManager will allocate one copy of the per-task (not per-problem-instance) arrays
 *         self.wrk    = <double*>0             # <<<<<<<<<<<<<<
 *         self.fk_tmp = <double*>0
 *         self.fi_tmp = <double*>0
 */
      __pyx_v_self->wrk = ((double *)0);

      /* "wlsqm/fitter/infra.pyx":844
 *         # in managed mode, CaseManager will allocate one copy of the per-task (not per-problem-instance) arrays
 *         self.wrk    = <double*>0
 *         self.fk_tmp = <double*>0             # <<<<<<<<<<<<<<
 *         self.fi_tmp = <double*>0
 * 
 */
      __pyx_v_self->fk_tmp = ((double *)0);

      /* "wlsqm/fitter/infra.pyx":845
 *         self.wrk    = <double*>0
 *         self.fk_tmp = <double*>0
 *         self.fi_tmp = <double*>0             # <<<<<<<<<<<<<<
 * 
 *     else:
 */
      __pyx_v_self->fi_tmp = ((double *)0);

      /* "wlsqm/fitter/infra.pyx":841
 *         self.fi2   = <double*>0
 * 
 *     if self.have_manager:             # <<<<<<<<<<<<<<
 *         # in managed mode, CaseManager will allocate one copy of the per-task (not per-problem-instance) arrays
 *         self.wrk    = <double*>0
 */
      goto __pyx_L23;
    }

    /* "wlsqm/fitter/infra.pyx":849
 *     else:
 *         # unmanaged mode - allocate the per-task arrays locally.
 *         self.wrk        = <double*>Allocator_malloc( mal, sizes.wrk )             # <<<<<<<<<<<<<<
 * 
 *         if self.iterative:
 */
    /*else*/ {
      __pyx_v_self->wrk = ((double *)__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc(__pyx_v_mal, __pyx_v_sizes.wrk));

      /* "wlsqm/fitter/infra.pyx":851
 *         self.wrk        = <double*>Allocator_malloc( mal, sizes.wrk )
 * 
 *         if self.iterative:             # <<<<<<<<<<<<<<
 *             self.fk_tmp = <double*>Allocator_malloc( mal, sizes.fk_tmp )
 *             self.fi_tmp = <double*>Allocator_malloc( mal, sizes.fi_tmp )
 */
      __pyx_t_4 = (__pyx_v_self->iterative != 0);
      if (__pyx_t_4) {

        /* "wlsqm/fitter/infra.pyx":852
 * 
 *         if self.iterative:
 *             self.fk_tmp = <double*>Allocator_malloc( mal, sizes.fk_tmp )             # <<<<<<<<<<<<<<
 *             self.fi_tmp = <double*>Allocator_malloc( mal, sizes.fi_tmp )
 *         else:
 */
        __pyx_v_self->fk_tmp = ((double *)__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc(__pyx_v_mal, __pyx_v_sizes.fk_tmp));

        /* "wlsqm/fitter/infra.pyx":853
 *         if self.iterative:
 *             self.fk_tmp = <double*>Allocator_malloc( mal, sizes.fk_tmp )
 *             self.fi_tmp = <double*>Allocator_malloc( mal, sizes.fi_tmp )             # <<<<<<<<<<<<<<
 *         else:
 *             self.fk_tmp = <double*>0
 */
        __pyx_v_self->fi_tmp = ((double *)__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc(__pyx_v_mal, __pyx_v_sizes.fi_tmp));

        /* "wlsqm/fitter/infra.pyx":851
 *         self.wrk        = <double*>Allocator_malloc( mal, sizes.wrk )
 * 
 *         if self.iterative:             # <<<<<<<<<<<<<<
 *             self.fk_tmp = <double*>Allocator_malloc( mal, sizes.fk_tmp )
 *             self.fi_tmp = <double*>Allocator_malloc( mal, sizes.fi_tmp )
 */
        goto __pyx_L24;
      }

      /* "wlsqm/fitter/infra.pyx":855
 *             self.fi_tmp = <double*>Allocator_malloc( mal, sizes.fi_tmp )
 *         else:
 *             self.fk_tmp = <double*>0             # <<<<<<<<<<<<<<
 *             self.fi_tmp = <double*>0
 * 
 */
      /*else*/ {
        __pyx_v_self->fk_tmp = ((double *)0);

        /* "wlsqm/fitter/infra.pyx":856
 *         else:
 *             self.fk_tmp = <double*>0
 *             self.fi_tmp = <double*>0             # <<<<<<<<<<<<<<
 * 
 *     # memory allocated; populate o2r and r2o
 */
        __pyx_v_self->fi_tmp = ((double *)0);
      }
      __pyx_L24:;
    }
    __pyx_L23:;

    /* "wlsqm/fitter/infra.pyx":862
 *     # (in guest mode, this has already been done in the host Case instance)
 *     #
 *     if self.geometry_owned:             # <<<<<<<<<<<<<<
 *         remap( self.o2r, self.r2o, self.no, self.knowns )
 * 
 */
    __pyx_t_4 = (__pyx_v_self->geometry_owned != 0);
    if (__pyx_t_4) {

      /* "wlsqm/fitter/infra.pyx":863
 *     #
 *     if self.geometry_owned:
 *         remap( self.o2r, self.r2o, self.no, self.knowns )             # <<<<<<<<<<<<<<
 * 
 *     return 0
 */
      __pyx_f_5wlsqm_6fitter_5infra_remap(__pyx_v_self->o2r, __pyx_v_self->r2o, __pyx_v_self->no, __pyx_v_self->knowns);

      /* "wlsqm/fitter/infra.pyx":862
 *     # (in guest mode, this has already been done in the host Case instance)
 *     #
 *     if self.geometry_owned:             # <<<<<<<<<<<<<<
 *         remap( self.o2r, self.r2o, self.no, self.knowns )
 * 
 */
    }

    /* "wlsqm/fitter/infra.pyx":865
 *         remap( self.o2r, self.r2o, self.no, self.knowns )
 * 
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * # The opposite of Case_allocate().
 */
    __pyx_r = 0;
    goto __pyx_L3_return;
  }

  /* "wlsqm/fitter/infra.pyx":798
 *     # (This also calculates the various individual sizes, which we will use to actually allocate the memory.)
 *     #
 *     cdef BufferSizes sizes             # <<<<<<<<<<<<<<
 *     Case_determine_sizes( self, &sizes )
 * 
 */
  /*finally:*/ {
    __pyx_L3_return: {
      #ifdef WITH_THREAD
      __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      goto __pyx_L0;
    }
    __pyx_L4_error: {
      #ifdef WITH_THREAD
      __pyx_gilstate_save = PyGILState_Ensure();
      #endif
      goto __pyx_L1_error;
    }
  }

  /* "wlsqm/fitter/infra.pyx":791
 * # Perform memory allocation.
 * #
 * cdef int Case_allocate( Case* self ) nogil except -1:             # <<<<<<<<<<<<<<
 *     # At this point, the constructor has finished, so we have no, nr, nk and the flags (do_sens, iterative).
 *     #
 */

  /* function exit code */
  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("wlsqm.fitter.infra.Case_allocate", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  #ifdef WITH_THREAD
  PyGILState_Release(__pyx_gilstate_save);
  #endif
  return __pyx_r;
}

/* "wlsqm/fitter/infra.pyx":869
 * # The opposite of Case_allocate().
 * #
 * cdef void Case_deallocate( Case* self ) nogil:             # <<<<<<<<<<<<<<
 *     if self != <Case*>0:
 *         # No guarantee that we'll be called only from the destructor;
 */

static void __pyx_f_5wlsqm_6fitter_5infra_Case_deallocate(struct __pyx_t_5wlsqm_6fitter_5infra_Case *__pyx_v_self) {
  int __pyx_t_1;

  /* "wlsqm/fitter/infra.pyx":870
 * #
 * cdef void Case_deallocate( Case* self ) nogil:
 *     if self != <Case*>0:             # <<<<<<<<<<<<<<
 *         # No guarantee that we'll be called only from the destructor;
 *         # we must set any deallocated pointers to NULL.
 */
  __pyx_t_1 = ((__pyx_v_self != ((struct __pyx_t_5wlsqm_6fitter_5infra_Case *)0)) != 0);
  if (__pyx_t_1) {

    /* "wlsqm/fitter/infra.pyx":873
 *         # No guarantee that we'll be called only from the destructor;
 *         # we must set any deallocated pointers to NULL.
 *         Allocator_free( self.mal, self.fi_tmp )             # <<<<<<<<<<<<<<
 *         self.fi_tmp = <double*>0
 *         Allocator_free( self.mal, self.fk_tmp )
 */
    __pyx_f_5wlsqm_6fitter_5infra_Allocator_free(__pyx_v_self->mal, __pyx_v_self->fi_tmp);

    /* "wlsqm/fitter/infra.pyx":874
 *         # we must set any deallocated pointers to NULL.
 *         Allocator_free( self.mal, self.fi_tmp )
 *         self.fi_tmp = <double*>0             # <<<<<<<<<<<<<<
 *         Allocator_free( self.mal, self.fk_tmp )
 *         self.fk_tmp = <double*>0
 */
    __pyx_v_self->fi_tmp = ((double *)0);

    /* "wlsqm/fitter/infra.pyx":875
 *         Allocator_free( self.mal, self.fi_tmp )
 *         self.fi_tmp = <double*>0
 *         Allocator_free( self.mal, self.fk_tmp )             # <<<<<<<<<<<<<<
 *         self.fk_tmp = <double*>0
 * 
 */
    __pyx_f_5wlsqm_6fitter_5infra_Allocator_free(__pyx_v_self->mal, __pyx_v_self->fk_tmp);

    /* "wlsqm/fitter/infra.pyx":876
 *         self.fi_tmp = <double*>0
 *         Allocator_free( self.mal, self.fk_tmp )
 *         self.fk_tmp = <double*>0             # <<<<<<<<<<<<<<
 * 
 *         Allocator_free( self.mal, self.wrk )
 */
    __pyx_v_self->fk_tmp = ((double *)0);

    /* "wlsqm/fitter/infra.pyx":878
 *         self.fk_tmp = <double*>0
 * 
 *         Allocator_free( self.mal, self.wrk )             # <<<<<<<<<<<<<<
 *         self.wrk = <double*>0
 * 
 */
    __pyx_f_5wlsqm_6fitter_5infra_Allocator_free(__pyx_v_self->mal, __pyx_v_self->wrk);

    /* "wlsqm/fitter/infra.pyx":879
 * 
 *         Allocator_free( self.mal, self.wrk )
 *         self.wrk = <double*>0             # <<<<<<<<<<<<<<
 * 
 *         Allocator_free( self.mal, self.fi2 )
 */
    __pyx_v_self->wrk = ((double *)0);

    /* "wlsqm/fitter/infra.pyx":881
 *         self.wrk = <double*>0
 * 
 *         Allocator_free( self.mal, self.fi2 )             # <<<<<<<<<<<<<<
 *         self.fi2 = <double*>0
 *         Allocator_free( self.mal, self.fi )
 */
    __pyx_f_5wlsqm_6fitter_5infra_Allocator_free(__pyx_v_self->mal, __pyx_v_self->fi2);

    /* "wlsqm/fitter/infra.pyx":882
 * 
 *         Allocator_free( self.mal, self.fi2 )
 *         self.fi2 = <double*>0             # <<<<<<<<<<<<<<
 *         Allocator_free( self.mal, self.fi )
 *         self.fi = <double*>0
 */
    __pyx_v_self->fi2 = ((double *)0);

    /* "wlsqm/fitter/infra.pyx":883
 *         Allocator_free( self.mal, self.fi2 )
 *         self.fi2 = <double*>0
 *         Allocator_free( self.mal, self.fi )             # <<<<<<<<<<<<<<
 *         self.fi = <double*>0
 * 
 */
    __pyx_f_5wlsqm_6fitter_5infra_Allocator_free(__pyx_v_self->mal, __pyx_v_self->fi);

    /* "wlsqm/fitter/infra.pyx":884
 *         self.fi2 = <double*>0
 *         Allocator_free( self.mal, self.fi )
 *         self.fi = <double*>0             # <<<<<<<<<<<<<<
 * 
 *         if self.geometry_owned:
 */
    __pyx_v_self->fi = ((double *)0);

    /* "wlsqm/fitter/infra.pyx":886
 *         self.fi = <double*>0
 * 
 *         if self.geometry_owned:             # <<<<<<<<<<<<<<
 *             Allocator_free( self.mal, self.ipiv )
 *             self.ipiv = <int*>0
 */
    __pyx_t_1 = (__pyx_v_self->geometry_owned != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":887
 * 
 *         if self.geometry_owned:
 *             Allocator_free( self.mal, self.ipiv )             # <<<<<<<<<<<<<<
 *             self.ipiv = <int*>0
 *             Allocator_free( self.mal, self.col_scale )
 */
      __pyx_f_5wlsqm_6fitter_5infra_Allocator_free(__pyx_v_self->mal, __pyx_v_self->ipiv);

      /* "wlsqm/fitter/infra.pyx":888
 *         if self.geometry_owned:
 *             Allocator_free( self.mal, self.ipiv )
 *             self.ipiv = <int*>0             # <<<<<<<<<<<<<<
 *             Allocator_free( self.mal, self.col_scale )
 *             self.col_scale = <double*>0
 */
      __pyx_v_self->ipiv = ((int *)0);

      /* "wlsqm/fitter/infra.pyx":889
 *             Allocator_free( self.mal, self.ipiv )
 *             self.ipiv = <int*>0
 *             Allocator_free( self.mal, self.col_scale )             # <<<<<<<<<<<<<<
 *             self.col_scale = <double*>0
 *             Allocator_free( self.mal, self.row_scale )
 */
      __pyx_f_5wlsqm_6fitter_5infra_Allocator_free(__pyx_v_self->mal, __pyx_v_self->col_scale);

      /* "wlsqm/fitter/infra.pyx":890
 *             self.ipiv = <int*>0
 *             Allocator_free( self.mal, self.col_scale )
 *             self.col_scale = <double*>0             # <<<<<<<<<<<<<<
 *             Allocator_free( self.mal, self.row_scale )
 *             self.row_scale = <double*>0
 */
      __pyx_v_self->col_scale = ((double *)0);

      /* "wlsqm/fitter/infra.pyx":891
 *             Allocator_free( self.mal, self.col_scale )
 *             self.col_scale = <double*>0
 *             Allocator_free( self.mal, self.row_scale )             # <<<<<<<<<<<<<<
 *             self.row_scale = <double*>0
 *             Allocator_free( self.mal, self.A )
 */
      __pyx_f_5wlsqm_6fitter_5infra_Allocator_free(__pyx_v_self->mal, __pyx_v_self->row_scale);

      /* "wlsqm/fitter/infra.pyx":892
 *             self.col_scale = <double*>0
 *             Allocator_free( self.mal, self.row_scale )
 *             self.row_scale = <double*>0             # <<<<<<<<<<<<<<
 *             Allocator_free( self.mal, self.A )
 *             self.A = <double*>0
 */
      __pyx_v_self->row_scale = ((double *)0);

      /* "wlsqm/fitter/infra.pyx":893
 *             Allocator_free( self.mal, self.row_scale )
 *             self.row_scale = <double*>0
 *             Allocator_free( self.mal, self.A )             # <<<<<<<<<<<<<<
 *             self.A = <double*>0
 * 
 */
      __pyx_f_5wlsqm_6fitter_5infra_Allocator_free(__pyx_v_self->mal, __pyx_v_self->A);

      /* "wlsqm/fitter/infra.pyx":894
 *             self.row_scale = <double*>0
 *             Allocator_free( self.mal, self.A )
 *             self.A = <double*>0             # <<<<<<<<<<<<<<
 * 
 *             Allocator_free( self.mal, self.w )
 */
      __pyx_v_self->A = ((double *)0);

      /* "wlsqm/fitter/infra.pyx":896
 *             self.A = <double*>0
 * 
 *             Allocator_free( self.mal, self.w )             # <<<<<<<<<<<<<<
 *             self.w = <double*>0
 *             Allocator_free( self.mal, self.c )
 */
      __pyx_f_5wlsqm_6fitter_5infra_Allocator_free(__pyx_v_self->mal, __pyx_v_self->w);

      /* "wlsqm/fitter/infra.pyx":897
 * 
 *             Allocator_free( self.mal, self.w )
 *             self.w = <double*>0             # <<<<<<<<<<<<<<
 *             Allocator_free( self.mal, self.c )
 *             self.c = <double*>0
 */
      __pyx_v_self->w = ((double *)0);

      /* "wlsqm/fitter/infra.pyx":898
 *             Allocator_free( self.mal, self.w )
 *             self.w = <double*>0
 *             Allocator_free( self.mal, self.c )             # <<<<<<<<<<<<<<
 *             self.c = <double*>0
 * 
 */
      __pyx_f_5wlsqm_6fitter_5infra_Allocator_free(__pyx_v_self->mal, __pyx_v_self->c);

      /* "wlsqm/fitter/infra.pyx":899
 *             self.w = <double*>0
 *             Allocator_free( self.mal, self.c )
 *             self.c = <double*>0             # <<<<<<<<<<<<<<
 * 
 *             Allocator_free( self.mal, self.r2o )
 */
      __pyx_v_self->c = ((double *)0);

      /* "wlsqm/fitter/infra.pyx":901
 *             self.c = <double*>0
 * 
 *             Allocator_free( self.mal, self.r2o )             # <<<<<<<<<<<<<<
 *             self.r2o = <int*>0
 *             Allocator_free( self.mal, self.o2r )
 */
      __pyx_f_5wlsqm_6fitter_5infra_Allocator_free(__pyx_v_self->mal, __pyx_v_self->r2o);

      /* "wlsqm/fitter/infra.pyx":902
 * 
 *             Allocator_free( self.mal, self.r2o )
 *             self.r2o = <int*>0             # <<<<<<<<<<<<<<
 *             Allocator_free( self.mal, self.o2r )
 *             self.o2r = <int*>0
 */
      __pyx_v_self->r2o = ((int *)0);

      /* "wlsqm/fitter/infra.pyx":903
 *             Allocator_free( self.mal, self.r2o )
 *             self.r2o = <int*>0
 *             Allocator_free( self.mal, self.o2r )             # <<<<<<<<<<<<<<
 *             self.o2r = <int*>0
 *         else:
 */
      __pyx_f_5wlsqm_6fitter_5infra_Allocator_free(__pyx_v_self->mal, __pyx_v_self->o2r);

      /* "wlsqm/fitter/infra.pyx":904
 *             self.r2o = <int*>0
 *             Allocator_free( self.mal, self.o2r )
 *             self.o2r = <int*>0             # <<<<<<<<<<<<<<
 *         else:
 *             # In guest mode, the allocation of these arrays is managed by the host Case instance.
 */
      __pyx_v_self->o2r = ((int *)0);

      /* "wlsqm/fitter/infra.pyx":886
 *         self.fi = <double*>0
 * 
 *         if self.geometry_owned:             # <<<<<<<<<<<<<<
 *             Allocator_free( self.mal, self.ipiv )
 *             self.ipiv = <int*>0
 */
      goto __pyx_L4;
    }

    /* "wlsqm/fitter/infra.pyx":907
 *         else:
 *             # In guest mode, the allocation of these arrays is managed by the host Case instance.
 *             self.ipiv      = <int*>0             # <<<<<<<<<<<<<<
 *             self.col_scale = <double*>0
 *             self.row_scale = <double*>0
 */
    /*else*/ {
      __pyx_v_self->ipiv = ((int *)0);

      /* "wlsqm/fitter/infra.pyx":908
 *             # In guest mode, the allocation of these arrays is managed by the host Case instance.
 *             self.ipiv      = <int*>0
 *             self.col_scale = <double*>0             # <<<<<<<<<<<<<<
 *             self.row_scale = <double*>0
 *             self.A         = <double*>0
 */
      __pyx_v_self->col_scale = ((double *)0);

      /* "wlsqm/fitter/infra.pyx":909
 *             self.ipiv      = <int*>0
 *             self.col_scale = <double*>0
 *             self.row_scale = <double*>0             # <<<<<<<<<<<<<<
 *             self.A         = <double*>0
 *             self.w         = <double*>0
 */
      __pyx_v_self->row_scale = ((double *)0);

      /* "wlsqm/fitter/infra.pyx":910
 *             self.col_scale = <double*>0
 *             self.row_scale = <double*>0
 *             self.A         = <double*>0             # <<<<<<<<<<<<<<
 *             self.w         = <double*>0
 *             self.c         = <double*>0
 */
      __pyx_v_self->A = ((double *)0);

      /* "wlsqm/fitter/infra.pyx":911
 *             self.row_scale = <double*>0
 *             self.A         = <double*>0
 *             self.w         = <double*>0             # <<<<<<<<<<<<<<
 *             self.c         = <double*>0
 *             self.r2o       = <int*>0
 */
      __pyx_v_self->w = ((double *)0);

      /* "wlsqm/fitter/infra.pyx":912
 *             self.A         = <double*>0
 *             self.w         = <double*>0
 *             self.c         = <double*>0             # <<<<<<<<<<<<<<
 *             self.r2o       = <int*>0
 *             self.o2r       = <int*>0
 */
      __pyx_v_self->c = ((double *)0);

      /* "wlsqm/fitter/infra.pyx":913
 *             self.w         = <double*>0
 *             self.c         = <double*>0
 *             self.r2o       = <int*>0             # <<<<<<<<<<<<<<
 *             self.o2r       = <int*>0
 * 
 */
      __pyx_v_self->r2o = ((int *)0);

      /* "wlsqm/fitter/infra.pyx":914
 *             self.c         = <double*>0
 *             self.r2o       = <int*>0
 *             self.o2r       = <int*>0             # <<<<<<<<<<<<<<
 * 
 * # Destructor.
 */
      __pyx_v_self->o2r = ((int *)0);
    }
    __pyx_L4:;

    /* "wlsqm/fitter/infra.pyx":870
 * #
 * cdef void Case_deallocate( Case* self ) nogil:
 *     if self != <Case*>0:             # <<<<<<<<<<<<<<
 *         # No guarantee that we'll be called only from the destructor;
 *         # we must set any deallocated pointers to NULL.
 */
  }

  /* "wlsqm/fitter/infra.pyx":869
 * # The opposite of Case_allocate().
 * #
 * cdef void Case_deallocate( Case* self ) nogil:             # <<<<<<<<<<<<<<
 *     if self != <Case*>0:
 *         # No guarantee that we'll be called only from the destructor;
 */

  /* function exit code */
}

/* "wlsqm/fitter/infra.pyx":918
 * # Destructor.
 * #
 * cdef void Case_del( Case* self ) nogil:             # <<<<<<<<<<<<<<
 *     if self != <Case*>0:
 *         Case_deallocate( self )
 */

static void __pyx_f_5wlsqm_6fitter_5infra_Case_del(struct __pyx_t_5wlsqm_6fitter_5infra_Case *__pyx_v_self) {
  int __pyx_t_1;

  /* "wlsqm/fitter/infra.pyx":919
 * #
 * cdef void Case_del( Case* self ) nogil:
 *     if self != <Case*>0:             # <<<<<<<<<<<<<<
 *         Case_deallocate( self )
 * 
 */
  __pyx_t_1 = ((__pyx_v_self != ((struct __pyx_t_5wlsqm_6fitter_5infra_Case *)0)) != 0);
  if (__pyx_t_1) {

    /* "wlsqm/fitter/infra.pyx":920
 * cdef void Case_del( Case* self ) nogil:
 *     if self != <Case*>0:
 *         Case_deallocate( self )             # <<<<<<<<<<<<<<
 * 
 *         if not self.have_manager:
 */
    __pyx_f_5wlsqm_6fitter_5infra_Case_deallocate(__pyx_v_self);

    /* "wlsqm/fitter/infra.pyx":922
 *         Case_deallocate( self )
 * 
 *         if not self.have_manager:             # <<<<<<<<<<<<<<
 *             Allocator_del( self.mal )
 * 
 */
    __pyx_t_1 = ((!(__pyx_v_self->have_manager != 0)) != 0);
    if (__pyx_t_1) {

      /* "wlsqm/fitter/infra.pyx":923
 * 
 *         if not self.have_manager:
 *             Allocator_del( self.mal )             # <<<<<<<<<<<<<<
 * 
 *         free( self )
 */
      __pyx_f_5wlsqm_6fitter_5infra_Allocator_del(__pyx_v_self->mal);

      /* "wlsqm/fitter/infra.pyx":922
 *         Case_deallocate( self )
 * 
 *         if not self.have_manager:             # <<<<<<<<<<<<<<
 *             Allocator_del( self.mal )
 * 
 */
    }

    /* "wlsqm/fitter/infra.pyx":925
 *             Allocator_del( self.mal )
 * 
 *         free( self )             # <<<<<<<<<<<<<<
 * 
 */
    free(__pyx_v_self);

    /* "wlsqm/fitter/infra.pyx":919
 * #
 * cdef void Case_del( Case* self ) nogil:
 *     if self != <Case*>0:             # <<<<<<<<<<<<<<
 *         Case_deallocate( self )
 * 
 */
  }

  /* "wlsqm/fitter/infra.pyx":918
 * # Destructor.
 * #
 * cdef void Case_del( Case* self ) nogil:             # <<<<<<<<<<<<<<
 *     if self != <Case*>0:
 *         Case_deallocate( self )
 */

  /* function exit code */
}

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
    "infra",
    0, /* 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_ALLOC_MODE_ONEBIGBUFFER, __pyx_k_ALLOC_MODE_ONEBIGBUFFER, sizeof(__pyx_k_ALLOC_MODE_ONEBIGBUFFER), 0, 0, 1, 1},
  {&__pyx_n_s_ALLOC_MODE_PASSTHROUGH, __pyx_k_ALLOC_MODE_PASSTHROUGH, sizeof(__pyx_k_ALLOC_MODE_PASSTHROUGH), 0, 0, 1, 1},
  {&__pyx_kp_s_Cannot_add_case_with_different_d, __pyx_k_Cannot_add_case_with_different_d, sizeof(__pyx_k_Cannot_add_case_with_different_d), 0, 0, 1, 0},
  {&__pyx_kp_s_Cannot_add_case_with_different_s, __pyx_k_Cannot_add_case_with_different_s, sizeof(__pyx_k_Cannot_add_case_with_different_s), 0, 0, 1, 0},
  {&__pyx_kp_s_Cannot_add_case_with_different_s_2, __pyx_k_Cannot_add_case_with_different_s_2, sizeof(__pyx_k_Cannot_add_case_with_different_s_2), 0, 0, 1, 0},
  {&__pyx_kp_s_Case_pointer_buffer_full_max_cas, __pyx_k_Case_pointer_buffer_full_max_cas, sizeof(__pyx_k_Case_pointer_buffer_full_max_cas), 0, 0, 1, 0},
  {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1},
  {&__pyx_kp_s_Must_specify_max_cases_0_when_cr, __pyx_k_Must_specify_max_cases_0_when_cr, sizeof(__pyx_k_Must_specify_max_cases_0_when_cr), 0, 0, 1, 0},
  {&__pyx_kp_s_No_cases_add_some_before_allocat, __pyx_k_No_cases_add_some_before_allocat, sizeof(__pyx_k_No_cases_add_some_before_allocat), 0, 0, 1, 0},
  {&__pyx_kp_s_Out_of_memory_trying_to_allocate, __pyx_k_Out_of_memory_trying_to_allocate, sizeof(__pyx_k_Out_of_memory_trying_to_allocate), 0, 0, 1, 0},
  {&__pyx_kp_s_Out_of_memory_trying_to_allocate_2, __pyx_k_Out_of_memory_trying_to_allocate_2, sizeof(__pyx_k_Out_of_memory_trying_to_allocate_2), 0, 0, 1, 0},
  {&__pyx_kp_s_Out_of_memory_trying_to_allocate_3, __pyx_k_Out_of_memory_trying_to_allocate_3, sizeof(__pyx_k_Out_of_memory_trying_to_allocate_3), 0, 0, 1, 0},
  {&__pyx_kp_s_Out_of_memory_trying_to_allocate_4, __pyx_k_Out_of_memory_trying_to_allocate_4, sizeof(__pyx_k_Out_of_memory_trying_to_allocate_4), 0, 0, 1, 0},
  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  {&__pyx_kp_s_d_bytes_of_memory_needed_but_th, __pyx_k_d_bytes_of_memory_needed_but_th, sizeof(__pyx_k_d_bytes_of_memory_needed_but_th), 0, 0, 1, 0},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_capi, __pyx_k_pyx_capi, sizeof(__pyx_k_pyx_capi), 0, 0, 1, 1},
  {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 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_ERR(0, 173, __pyx_L1_error)
  __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(0, 232, __pyx_L1_error)
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 308, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "wlsqm/fitter/infra.pyx":232
 *     if self == <Allocator*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 *         with gil:
 *             raise MemoryError("Out of memory trying to allocate an Allocator object")             # <<<<<<<<<<<<<<
 * 
 *     if mode == ALLOC_MODE_ONEBIGBUFFER  and  total_size_bytes > 0:
 */
  __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_Out_of_memory_trying_to_allocate); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 232, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);

  /* "wlsqm/fitter/infra.pyx":308
 *     if max_cases < 1:
 *         with gil:
 *             raise ValueError("Must specify max_cases > 0 when creating a CaseManager.")             # <<<<<<<<<<<<<<
 * 
 *     cdef CaseManager* self = <CaseManager*>malloc( sizeof(CaseManager) )
 */
  __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_Must_specify_max_cases_0_when_cr); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 308, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__2);
  __Pyx_GIVEREF(__pyx_tuple__2);

  /* "wlsqm/fitter/infra.pyx":313
 *     if self == <CaseManager*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 *         with gil:
 *             raise MemoryError("Out of memory trying to allocate an CaseManager object")             # <<<<<<<<<<<<<<
 * 
 *     # init parallel proc
 */
  __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_Out_of_memory_trying_to_allocate_3); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 313, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__3);
  __Pyx_GIVEREF(__pyx_tuple__3);

  /* "wlsqm/fitter/infra.pyx":395
 *         try:
 *             if self.ncases == 0:
 *                 raise ValueError("No cases; add some before allocating")             # <<<<<<<<<<<<<<
 * 
 *             # Determine total amount of memory needed by the per-problem-instance arrays.
 */
  __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_No_cases_add_some_before_allocat); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 395, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__4);
  __Pyx_GIVEREF(__pyx_tuple__4);

  /* "wlsqm/fitter/infra.pyx":542
 *     if self == <Case*>0:  # we promised Cython not to return NULL, so we must raise if the malloc fails
 *         with gil:
 *             raise MemoryError("Out of memory trying to allocate a Case object")             # <<<<<<<<<<<<<<
 * 
 *     # tag unused components as NaN
 */
  __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_s_Out_of_memory_trying_to_allocate_4); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 542, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__5);
  __Pyx_GIVEREF(__pyx_tuple__5);
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_InitGlobals(void) {
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC initinfra(void); /*proto*/
PyMODINIT_FUNC initinfra(void)
#else
PyMODINIT_FUNC PyInit_infra(void); /*proto*/
PyMODINIT_FUNC PyInit_infra(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  __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_infra(void)", 0);
  if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pyx_CyFunction_USED
  if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Coroutine_USED
  if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_StopAsyncIteration_USED
  if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __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("infra", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
  #if CYTHON_COMPILING_IN_PYPY
  Py_INCREF(__pyx_b);
  #endif
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  /*--- Initialize various global constants etc. ---*/
  if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __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_ERR(0, 1, __pyx_L1_error)
  #endif
  if (__pyx_module_is_main_wlsqm__fitter__infra) {
    if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
    if (!PyDict_GetItemString(modules, "wlsqm.fitter.infra")) {
      if (unlikely(PyDict_SetItemString(modules, "wlsqm.fitter.infra", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Constants init code ---*/
  if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Global init code ---*/
  /*--- Variable export code ---*/
  if (__Pyx_ExportVoidPtr(__pyx_n_s_ALLOC_MODE_PASSTHROUGH, (void *)&__pyx_v_5wlsqm_6fitter_5infra_ALLOC_MODE_PASSTHROUGH, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportVoidPtr(__pyx_n_s_ALLOC_MODE_ONEBIGBUFFER, (void *)&__pyx_v_5wlsqm_6fitter_5infra_ALLOC_MODE_ONEBIGBUFFER, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Function export code ---*/
  if (__Pyx_ExportFunction("number_of_dofs", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_number_of_dofs, "int (int, int)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("number_of_reduced_dofs", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_number_of_reduced_dofs, "int (int, PY_LONG_LONG)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("remap", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_remap, "int (int *, int *, int, PY_LONG_LONG)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("Allocator_new", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_Allocator_new, "struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *(int, int)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("Allocator_malloc", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_Allocator_malloc, "void *(struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *, int)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("Allocator_free", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_Allocator_free, "void (struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *, void *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("Allocator_size_remaining", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_Allocator_size_remaining, "int (struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("Allocator_del", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_Allocator_del, "void (struct __pyx_t_5wlsqm_6fitter_5infra_Allocator *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("CaseManager_new", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_CaseManager_new, "struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *(int, int, int, int, int)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("CaseManager_add", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_CaseManager_add, "int (struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *, struct __pyx_t_5wlsqm_6fitter_5infra_Case *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("CaseManager_commit", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_CaseManager_commit, "int (struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("CaseManager_del", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_CaseManager_del, "void (struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("Case_new", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_Case_new, "struct __pyx_t_5wlsqm_6fitter_5infra_Case *(int, int, double, double, double, int, PY_LONG_LONG, int, int, int, struct __pyx_t_5wlsqm_6fitter_5infra_CaseManager *, struct __pyx_t_5wlsqm_6fitter_5infra_Case *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("Case_get_wrk", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_Case_get_wrk, "double *(struct __pyx_t_5wlsqm_6fitter_5infra_Case *, int)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("Case_get_fk_tmp", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_Case_get_fk_tmp, "double *(struct __pyx_t_5wlsqm_6fitter_5infra_Case *, int)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("Case_get_fi_tmp", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_Case_get_fi_tmp, "double *(struct __pyx_t_5wlsqm_6fitter_5infra_Case *, int)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("Case_make_weights", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_Case_make_weights, "void (struct __pyx_t_5wlsqm_6fitter_5infra_Case *, double)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("Case_set_fi", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_Case_set_fi, "void (struct __pyx_t_5wlsqm_6fitter_5infra_Case *, double *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("Case_get_fi", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_Case_get_fi, "void (struct __pyx_t_5wlsqm_6fitter_5infra_Case *, double *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("Case_del", (void (*)(void))__pyx_f_5wlsqm_6fitter_5infra_Case_del, "void (struct __pyx_t_5wlsqm_6fitter_5infra_Case *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Type init code ---*/
  /*--- Type import code ---*/
  /*--- Variable import code ---*/
  __pyx_t_1 = __Pyx_ImportModule("wlsqm.fitter.defs"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "ALGO_BASIC_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_ALGO_BASIC_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "ALGO_ITERATIVE_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_ALGO_ITERATIVE_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "WEIGHT_UNIFORM_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_WEIGHT_UNIFORM_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "WEIGHT_CENTER_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_WEIGHT_CENTER_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i1_F_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i1_F_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i1_X_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i1_X_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i1_X2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i1_X2_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i1_X3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i1_X3_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i1_X4_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i1_X4_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i1_0th_end_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i1_0th_end_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i1_1st_end_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i1_1st_end_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i1_2nd_end_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i1_2nd_end_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i1_3rd_end_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i1_3rd_end_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i1_4th_end_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i1_4th_end_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "SIZE1_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_SIZE1_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_F_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_F_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_X_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_X_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_Y_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_Y_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_X2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_X2_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_XY_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_XY_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_Y2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_Y2_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_X3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_X3_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_X2Y_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_X2Y_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_XY2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_XY2_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_Y3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_Y3_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_X4_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_X4_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_X3Y_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_X3Y_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_X2Y2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_X2Y2_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_XY3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_XY3_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_Y4_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_Y4_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_0th_end_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_0th_end_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_1st_end_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_1st_end_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_2nd_end_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_2nd_end_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_3rd_end_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_3rd_end_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i2_4th_end_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i2_4th_end_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "SIZE2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_SIZE2_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_F_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_F_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_X_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_X_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_Y_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_Y_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_Z_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_Z_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_X2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_X2_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_XY_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_XY_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_Y2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_Y2_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_YZ_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_YZ_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_Z2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_Z2_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_XZ_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_XZ_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_X3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_X3_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_X2Y_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_X2Y_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_XY2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_XY2_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_Y3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_Y3_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_Y2Z_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_Y2Z_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_YZ2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_YZ2_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_Z3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_Z3_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_XZ2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_XZ2_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_X2Z_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_X2Z_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_XYZ_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_XYZ_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_X4_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_X4_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_X3Y_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_X3Y_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_X2Y2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_X2Y2_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_XY3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_XY3_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_Y4_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_Y4_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_Y3Z_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_Y3Z_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_Y2Z2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_Y2Z2_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_YZ3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_YZ3_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_Z4_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_Z4_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_XZ3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_XZ3_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_X2Z2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_X2Z2_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_X3Z_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_X3Z_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_X2YZ_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_X2YZ_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_XY2Z_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_XY2Z_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_XYZ2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_XYZ2_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_0th_end_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_0th_end_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_1st_end_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_1st_end_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_2nd_end_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_2nd_end_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_3rd_end_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_3rd_end_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "i3_4th_end_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_i3_4th_end_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "SIZE3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_SIZE3_c, "int") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b1_F_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b1_F_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b1_X_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b1_X_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b1_X2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b1_X2_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b1_X3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b1_X3_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b1_X4_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b1_X4_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b2_F_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b2_F_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b2_X_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b2_X_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b2_Y_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b2_Y_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b2_X2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b2_X2_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b2_XY_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b2_XY_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b2_Y2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b2_Y2_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b2_X3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b2_X3_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b2_X2Y_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b2_X2Y_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b2_XY2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b2_XY2_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b2_Y3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b2_Y3_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b2_X4_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b2_X4_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b2_X3Y_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b2_X3Y_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b2_X2Y2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b2_X2Y2_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b2_XY3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b2_XY3_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b2_Y4_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b2_Y4_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_F_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_F_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_X_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_X_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_Y_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_Y_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_Z_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_Z_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_X2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_X2_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_XY_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_XY_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_Y2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_Y2_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_YZ_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_YZ_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_Z2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_Z2_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_XZ_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_XZ_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_X3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_X3_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_X2Y_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_X2Y_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_XY2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_XY2_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_Y3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_Y3_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_Y2Z_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_Y2Z_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_YZ2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_YZ2_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_Z3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_Z3_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_XZ2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_XZ2_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_X2Z_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_X2Z_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_XYZ_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_XYZ_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_X4_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_X4_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_X3Y_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_X3Y_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_X2Y2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_X2Y2_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_XY3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_XY3_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_Y4_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_Y4_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_Y3Z_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_Y3Z_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_Y2Z2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_Y2Z2_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_YZ3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_YZ3_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_Z4_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_Z4_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_XZ3_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_XZ3_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_X2Z2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_X2Z2_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_X3Z_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_X3Z_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_X2YZ_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_X2YZ_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_XY2Z_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_XY2Z_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "b3_XYZ2_c", (void **)&__pyx_vp_5wlsqm_6fitter_4defs_b3_XYZ2_c, "PY_LONG_LONG") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  /*--- Function import code ---*/
  /*--- Execution code ---*/
  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif

  /* "wlsqm/fitter/infra.pyx":218
 * 
 * # Object-oriented programming, C style.
 * cdef int ALLOC_MODE_PASSTHROUGH  = 1  # pass each call through to C malloc/free             # <<<<<<<<<<<<<<
 * cdef int ALLOC_MODE_ONEBIGBUFFER = 2  # pre-allocate one big buffer to fit everything in
 * 
 */
  __pyx_v_5wlsqm_6fitter_5infra_ALLOC_MODE_PASSTHROUGH = 1;

  /* "wlsqm/fitter/infra.pyx":219
 * # Object-oriented programming, C style.
 * cdef int ALLOC_MODE_PASSTHROUGH  = 1  # pass each call through to C malloc/free
 * cdef int ALLOC_MODE_ONEBIGBUFFER = 2  # pre-allocate one big buffer to fit everything in             # <<<<<<<<<<<<<<
 * 
 * # Constructor.
 */
  __pyx_v_5wlsqm_6fitter_5infra_ALLOC_MODE_ONEBIGBUFFER = 2;

  /* "wlsqm/fitter/infra.pyx":1
 * # -*- coding: utf-8 -*-             # <<<<<<<<<<<<<<
 * #
 * # WLSQM (Weighted Least SQuares Meshless): a fast and accurate meshless least-squares interpolator for Python, for scalar-valued data defined as point values on 1D, 2D and 3D point clouds.
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init wlsqm.fitter.infra", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init wlsqm.fitter.infra");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* --- Runtime support code --- */
/* Refnanny */
#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

/* GetBuiltinName */
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;
}

/* PyObjectCall */
#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

/* PyErrFetchRestore */
#if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    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);
}
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}
#endif

/* RaiseException */
#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    __Pyx_PyThreadState_declare
    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_PyThreadState_assign
    __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

/* SaveResetException */
  #if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
}
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = type;
    tstate->exc_value = value;
    tstate->exc_traceback = tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
}
#endif

/* GetException */
  #if CYTHON_FAST_THREAD_STATE
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
#endif
    PyObject *local_type, *local_value, *local_tb;
#if CYTHON_FAST_THREAD_STATE
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    local_type = tstate->curexc_type;
    local_value = tstate->curexc_value;
    local_tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
#else
    PyErr_Fetch(&local_type, &local_value, &local_tb);
#endif
    PyErr_NormalizeException(&local_type, &local_value, &local_tb);
#if CYTHON_FAST_THREAD_STATE
    if (unlikely(tstate->curexc_type))
#else
    if (unlikely(PyErr_Occurred()))
#endif
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (local_tb) {
        if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
            goto bad;
    }
    #endif
    Py_XINCREF(local_tb);
    Py_XINCREF(local_type);
    Py_XINCREF(local_value);
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
#if CYTHON_FAST_THREAD_STATE
    tmp_type = tstate->exc_type;
    tmp_value = tstate->exc_value;
    tmp_tb = tstate->exc_traceback;
    tstate->exc_type = local_type;
    tstate->exc_value = local_value;
    tstate->exc_traceback = local_tb;
    Py_XDECREF(tmp_type);
    Py_XDECREF(tmp_value);
    Py_XDECREF(tmp_tb);
#else
    PyErr_SetExcInfo(local_type, local_value, local_tb);
#endif
    return 0;
bad:
    *type = 0;
    *value = 0;
    *tb = 0;
    Py_XDECREF(local_type);
    Py_XDECREF(local_value);
    Py_XDECREF(local_tb);
    return -1;
}

/* CodeObjectCache */
    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);
}

/* AddTraceback */
    #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;
    __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

/* CIntToPy */
    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);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(int),
                                     little, !is_unsigned);
    }
}

/* CIntFromPyVerify */
    #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;\
    }

/* CIntFromPy */
    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))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } 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) (-(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)-1)*(((((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)-1)*(((((((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)-1)*(((((((((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))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#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_IntOrLong(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_IntOrLong(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;
}

/* CIntToPy */
    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);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
    }
}

/* CIntFromPy */
    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))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } 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) (-(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)-1)*(((((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)-1)*(((((((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)-1)*(((((((((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))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#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_IntOrLong(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_IntOrLong(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;
}

/* CheckBinaryVersion */
    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;
}

/* VoidPtrExport */
    static int __Pyx_ExportVoidPtr(PyObject *name, void *p, const char *sig) {
    PyObject *d;
    PyObject *cobj = 0;
    d = PyDict_GetItem(__pyx_d, __pyx_n_s_pyx_capi);
    Py_XINCREF(d);
    if (!d) {
        d = PyDict_New();
        if (!d)
            goto bad;
        if (__Pyx_PyObject_SetAttrStr(__pyx_m, __pyx_n_s_pyx_capi, d) < 0)
            goto bad;
    }
#if PY_VERSION_HEX >= 0x02070000
    cobj = PyCapsule_New(p, sig, 0);
#else
    cobj = PyCObject_FromVoidPtrAndDesc(p, (void *)sig, 0);
#endif
    if (!cobj)
        goto bad;
    if (PyDict_SetItem(d, name, cobj) < 0)
        goto bad;
    Py_DECREF(cobj);
    Py_DECREF(d);
    return 0;
bad:
    Py_XDECREF(cobj);
    Py_XDECREF(d);
    return -1;
}

/* FunctionExport */
    static int __Pyx_ExportFunction(const char *name, void (*f)(void), const char *sig) {
    PyObject *d = 0;
    PyObject *cobj = 0;
    union {
        void (*fp)(void);
        void *p;
    } tmp;
    d = PyObject_GetAttrString(__pyx_m, (char *)"__pyx_capi__");
    if (!d) {
        PyErr_Clear();
        d = PyDict_New();
        if (!d)
            goto bad;
        Py_INCREF(d);
        if (PyModule_AddObject(__pyx_m, (char *)"__pyx_capi__", d) < 0)
            goto bad;
    }
    tmp.fp = f;
#if PY_VERSION_HEX >= 0x02070000
    cobj = PyCapsule_New(tmp.p, sig, 0);
#else
    cobj = PyCObject_FromVoidPtrAndDesc(tmp.p, (void *)sig, 0);
#endif
    if (!cobj)
        goto bad;
    if (PyDict_SetItemString(d, name, cobj) < 0)
        goto bad;
    Py_DECREF(cobj);
    Py_DECREF(d);
    return 0;
bad:
    Py_XDECREF(cobj);
    Py_XDECREF(d);
    return -1;
}

/* ModuleImport */
    #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

/* VoidPtrImport */
    #ifndef __PYX_HAVE_RT_ImportVoidPtr
#define __PYX_HAVE_RT_ImportVoidPtr
static int __Pyx_ImportVoidPtr(PyObject *module, const char *name, void **p, const char *sig) {
    PyObject *d = 0;
    PyObject *cobj = 0;
    d = PyObject_GetAttrString(module, (char *)"__pyx_capi__");
    if (!d)
        goto bad;
    cobj = PyDict_GetItemString(d, name);
    if (!cobj) {
        PyErr_Format(PyExc_ImportError,
            "%.200s does not export expected C variable %.200s",
                PyModule_GetName(module), name);
        goto bad;
    }
#if PY_VERSION_HEX >= 0x02070000
    if (!PyCapsule_IsValid(cobj, sig)) {
        PyErr_Format(PyExc_TypeError,
            "C variable %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
             PyModule_GetName(module), name, sig, PyCapsule_GetName(cobj));
        goto bad;
    }
    *p = PyCapsule_GetPointer(cobj, sig);
#else
    {const char *desc, *s1, *s2;
    desc = (const char *)PyCObject_GetDesc(cobj);
    if (!desc)
        goto bad;
    s1 = desc; s2 = sig;
    while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
    if (*s1 != *s2) {
        PyErr_Format(PyExc_TypeError,
            "C variable %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
             PyModule_GetName(module), name, sig, desc);
        goto bad;
    }
    *p = PyCObject_AsVoidPtr(cobj);}
#endif
    if (!(*p))
        goto bad;
    Py_DECREF(d);
    return 0;
bad:
    Py_XDECREF(d);
    return -1;
}
#endif

/* InitStrings */
    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_IntOrLong(PyObject* x) {
#if CYTHON_USE_TYPE_SLOTS
  PyNumberMethods *m;
#endif
  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);
#if CYTHON_USE_TYPE_SLOTS
  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
#else
  res = PyNumber_Int(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 */
