Cython: cg_ext.pyx

Generated by Cython 0.29.28

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

Raw output: cg_ext.c

    +01: #cython: wraparound=False, boundscheck=False, cdivision=True, profile=False, nonecheck=False, overflowcheck=False, cdivision_warnings=False, unraisable_tracebacks=False

      __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     02: import cython

     03:

     04: # import both numpy and the Cython declarations for numpy

    +05: import numpy as np

      __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(0, 5, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     06: cimport numpy as np

     07:

     08: # declare the interface to the C code

     09: cdef extern from "cg.c":

     10:     int _jacobi_precon_c(double* data, long* colind, long* row_ptr, double* precon, int M)

     11:     int _cg_solve_c(double* data, long* colind, long* row_ptr, double* b, double* x, int imax, double tol, double a_tol, int M)

     12:     int _cg_solve_c_precon(double* data, long* colind, long* row_ptr, double* b, double* x, int imax, double tol, double a_tol, int M, double* precon)

     13:

    +14: def jacobi_precon_c(object csr_sparse, np.ndarray[double, ndim=1, mode="c"] precon not None):

    /* Python wrapper */
    static PyObject *__pyx_pw_5anuga_9utilities_6cg_ext_1jacobi_precon_c(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static PyMethodDef __pyx_mdef_5anuga_9utilities_6cg_ext_1jacobi_precon_c = {"jacobi_precon_c", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5anuga_9utilities_6cg_ext_1jacobi_precon_c, METH_VARARGS|METH_KEYWORDS, 0};
    static PyObject *__pyx_pw_5anuga_9utilities_6cg_ext_1jacobi_precon_c(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyObject *__pyx_v_csr_sparse = 0;
      PyArrayObject *__pyx_v_precon = 0;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("jacobi_precon_c (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_csr_sparse,&__pyx_n_s_precon,0};
        PyObject* values[2] = {0,0};
        if (unlikely(__pyx_kwds)) {
          Py_ssize_t kw_args;
          const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
          switch (pos_args) {
            case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
            CYTHON_FALLTHROUGH;
            case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = PyDict_Size(__pyx_kwds);
          switch (pos_args) {
            case  0:
            if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_csr_sparse)) != 0)) kw_args--;
            else goto __pyx_L5_argtuple_error;
            CYTHON_FALLTHROUGH;
            case  1:
            if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_precon)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("jacobi_precon_c", 1, 2, 2, 1); __PYX_ERR(0, 14, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "jacobi_precon_c") < 0)) __PYX_ERR(0, 14, __pyx_L3_error)
          }
        } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
          goto __pyx_L5_argtuple_error;
        } else {
          values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
          values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        }
        __pyx_v_csr_sparse = values[0];
        __pyx_v_precon = ((PyArrayObject *)values[1]);
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("jacobi_precon_c", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 14, __pyx_L3_error)
      __pyx_L3_error:;
      __Pyx_AddTraceback("anuga.utilities.cg_ext.jacobi_precon_c", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return NULL;
      __pyx_L4_argument_unpacking_done:;
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_precon), __pyx_ptype_5numpy_ndarray, 0, "precon", 0))) __PYX_ERR(0, 14, __pyx_L1_error)
      __pyx_r = __pyx_pf_5anuga_9utilities_6cg_ext_jacobi_precon_c(__pyx_self, __pyx_v_csr_sparse, __pyx_v_precon);
      int __pyx_lineno = 0;
      const char *__pyx_filename = NULL;
      int __pyx_clineno = 0;

      /* function exit code */
      goto __pyx_L0;
      __pyx_L1_error:;
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_5anuga_9utilities_6cg_ext_jacobi_precon_c(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_csr_sparse, PyArrayObject *__pyx_v_precon) {
      int __pyx_v_M;
      CYTHON_UNUSED int __pyx_v_err;
      PyArrayObject *__pyx_v_data = 0;
      PyArrayObject *__pyx_v_colind = 0;
      PyArrayObject *__pyx_v_row_ptr = 0;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_colind;
      __Pyx_Buffer __pyx_pybuffer_colind;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_data;
      __Pyx_Buffer __pyx_pybuffer_data;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_precon;
      __Pyx_Buffer __pyx_pybuffer_precon;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_row_ptr;
      __Pyx_Buffer __pyx_pybuffer_row_ptr;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("jacobi_precon_c", 0);
      __pyx_pybuffer_data.pybuffer.buf = NULL;
      __pyx_pybuffer_data.refcount = 0;
      __pyx_pybuffernd_data.data = NULL;
      __pyx_pybuffernd_data.rcbuffer = &__pyx_pybuffer_data;
      __pyx_pybuffer_colind.pybuffer.buf = NULL;
      __pyx_pybuffer_colind.refcount = 0;
      __pyx_pybuffernd_colind.data = NULL;
      __pyx_pybuffernd_colind.rcbuffer = &__pyx_pybuffer_colind;
      __pyx_pybuffer_row_ptr.pybuffer.buf = NULL;
      __pyx_pybuffer_row_ptr.refcount = 0;
      __pyx_pybuffernd_row_ptr.data = NULL;
      __pyx_pybuffernd_row_ptr.rcbuffer = &__pyx_pybuffer_row_ptr;
      __pyx_pybuffer_precon.pybuffer.buf = NULL;
      __pyx_pybuffer_precon.refcount = 0;
      __pyx_pybuffernd_precon.data = NULL;
      __pyx_pybuffernd_precon.rcbuffer = &__pyx_pybuffer_precon;
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_precon.rcbuffer->pybuffer, (PyObject*)__pyx_v_precon, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 14, __pyx_L1_error)
      }
      __pyx_pybuffernd_precon.diminfo[0].strides = __pyx_pybuffernd_precon.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_precon.diminfo[0].shape = __pyx_pybuffernd_precon.rcbuffer->pybuffer.shape[0];
    /* … */
      /* function exit code */
      __pyx_r = Py_None; __Pyx_INCREF(Py_None);
      goto __pyx_L0;
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_colind.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_precon.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_row_ptr.rcbuffer->pybuffer);
      __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
      __Pyx_AddTraceback("anuga.utilities.cg_ext.jacobi_precon_c", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      goto __pyx_L2;
      __pyx_L0:;
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_colind.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_precon.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_row_ptr.rcbuffer->pybuffer);
      __pyx_L2:;
      __Pyx_XDECREF((PyObject *)__pyx_v_data);
      __Pyx_XDECREF((PyObject *)__pyx_v_colind);
      __Pyx_XDECREF((PyObject *)__pyx_v_row_ptr);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_tuple__3 = PyTuple_Pack(7, __pyx_n_s_csr_sparse, __pyx_n_s_precon, __pyx_n_s_M, __pyx_n_s_err, __pyx_n_s_data, __pyx_n_s_colind, __pyx_n_s_row_ptr); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 14, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__3);
      __Pyx_GIVEREF(__pyx_tuple__3);
    /* … */
      __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5anuga_9utilities_6cg_ext_1jacobi_precon_c, NULL, __pyx_n_s_anuga_utilities_cg_ext); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 14, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_jacobi_precon_c, __pyx_t_1) < 0) __PYX_ERR(0, 14, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_codeobj__4 = (PyObject*)__Pyx_PyCode_New(2, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__3, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_anuga_utilities_cg_ext_pyx, __pyx_n_s_jacobi_precon_c, 14, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__4)) __PYX_ERR(0, 14, __pyx_L1_error)

     15:

     16:     cdef int M, err

     17:     cdef np.ndarray[double, ndim=1, mode="c"] data

     18:     cdef np.ndarray[long, ndim=1, mode="c"] colind

     19:     cdef np.ndarray[long, ndim=1, mode="c"] row_ptr

     20:

    +21:     data = csr_sparse.data

      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_csr_sparse, __pyx_n_s_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 21, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 21, __pyx_L1_error)
      __pyx_t_2 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
        __pyx_t_3 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)__pyx_t_2, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_3 < 0)) {
          PyErr_Fetch(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)__pyx_v_data, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_4); Py_XDECREF(__pyx_t_5); Py_XDECREF(__pyx_t_6);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_4, __pyx_t_5, __pyx_t_6);
          }
          __pyx_t_4 = __pyx_t_5 = __pyx_t_6 = 0;
        }
        __pyx_pybuffernd_data.diminfo[0].strides = __pyx_pybuffernd_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_data.diminfo[0].shape = __pyx_pybuffernd_data.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 21, __pyx_L1_error)
      }
      __pyx_t_2 = 0;
      __pyx_v_data = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;

    +22:     colind = csr_sparse.colind

      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_csr_sparse, __pyx_n_s_colind); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 22, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 22, __pyx_L1_error)
      __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_colind.rcbuffer->pybuffer);
        __pyx_t_3 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_colind.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_3 < 0)) {
          PyErr_Fetch(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_colind.rcbuffer->pybuffer, (PyObject*)__pyx_v_colind, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_6); Py_XDECREF(__pyx_t_5); Py_XDECREF(__pyx_t_4);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_6, __pyx_t_5, __pyx_t_4);
          }
          __pyx_t_6 = __pyx_t_5 = __pyx_t_4 = 0;
        }
        __pyx_pybuffernd_colind.diminfo[0].strides = __pyx_pybuffernd_colind.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_colind.diminfo[0].shape = __pyx_pybuffernd_colind.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 22, __pyx_L1_error)
      }
      __pyx_t_7 = 0;
      __pyx_v_colind = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;

    +23:     row_ptr = csr_sparse.row_ptr

      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_csr_sparse, __pyx_n_s_row_ptr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 23, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 23, __pyx_L1_error)
      __pyx_t_8 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_row_ptr.rcbuffer->pybuffer);
        __pyx_t_3 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_row_ptr.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_3 < 0)) {
          PyErr_Fetch(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_row_ptr.rcbuffer->pybuffer, (PyObject*)__pyx_v_row_ptr, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_4); Py_XDECREF(__pyx_t_5); Py_XDECREF(__pyx_t_6);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_4, __pyx_t_5, __pyx_t_6);
          }
          __pyx_t_4 = __pyx_t_5 = __pyx_t_6 = 0;
        }
        __pyx_pybuffernd_row_ptr.diminfo[0].strides = __pyx_pybuffernd_row_ptr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_row_ptr.diminfo[0].shape = __pyx_pybuffernd_row_ptr.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 23, __pyx_L1_error)
      }
      __pyx_t_8 = 0;
      __pyx_v_row_ptr = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;

     24:

    +25:     M = row_ptr.shape[0] - 1

      __pyx_v_M = ((__pyx_v_row_ptr->dimensions[0]) - 1);

     26:

    +27:     err = _jacobi_precon_c(&data[0], &colind[0], &row_ptr[0], &precon[0], M)

      __pyx_t_9 = 0;
      __pyx_t_10 = 0;
      __pyx_t_11 = 0;
      __pyx_t_12 = 0;
      __pyx_v_err = _jacobi_precon_c((&(*__Pyx_BufPtrCContig1d(double *, __pyx_pybuffernd_data.rcbuffer->pybuffer.buf, __pyx_t_9, __pyx_pybuffernd_data.diminfo[0].strides))), (&(*__Pyx_BufPtrCContig1d(long *, __pyx_pybuffernd_colind.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_colind.diminfo[0].strides))), (&(*__Pyx_BufPtrCContig1d(long *, __pyx_pybuffernd_row_ptr.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_row_ptr.diminfo[0].strides))), (&(*__Pyx_BufPtrCContig1d(double *, __pyx_pybuffernd_precon.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_precon.diminfo[0].strides))), __pyx_v_M);

     28:

    +29: def cg_solve_c(object csr_sparse,\

    /* Python wrapper */
    static PyObject *__pyx_pw_5anuga_9utilities_6cg_ext_3cg_solve_c(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static PyMethodDef __pyx_mdef_5anuga_9utilities_6cg_ext_3cg_solve_c = {"cg_solve_c", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5anuga_9utilities_6cg_ext_3cg_solve_c, METH_VARARGS|METH_KEYWORDS, 0};
    static PyObject *__pyx_pw_5anuga_9utilities_6cg_ext_3cg_solve_c(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyObject *__pyx_v_csr_sparse = 0;
      PyArrayObject *__pyx_v_x0 = 0;
      PyArrayObject *__pyx_v_b = 0;
      int __pyx_v_imax;
      double __pyx_v_tol;
      double __pyx_v_a_tol;
      CYTHON_UNUSED int __pyx_v_bcols;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("cg_solve_c (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_csr_sparse,&__pyx_n_s_x0,&__pyx_n_s_b,&__pyx_n_s_imax,&__pyx_n_s_tol,&__pyx_n_s_a_tol,&__pyx_n_s_bcols,0};
        PyObject* values[7] = {0,0,0,0,0,0,0};
        if (unlikely(__pyx_kwds)) {
          Py_ssize_t kw_args;
          const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
          switch (pos_args) {
            case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
            CYTHON_FALLTHROUGH;
            case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
            CYTHON_FALLTHROUGH;
            case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
            CYTHON_FALLTHROUGH;
            case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
            CYTHON_FALLTHROUGH;
            case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
            CYTHON_FALLTHROUGH;
            case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
            CYTHON_FALLTHROUGH;
            case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = PyDict_Size(__pyx_kwds);
          switch (pos_args) {
            case  0:
            if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_csr_sparse)) != 0)) kw_args--;
            else goto __pyx_L5_argtuple_error;
            CYTHON_FALLTHROUGH;
            case  1:
            if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_x0)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("cg_solve_c", 1, 7, 7, 1); __PYX_ERR(0, 29, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  2:
            if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_b)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("cg_solve_c", 1, 7, 7, 2); __PYX_ERR(0, 29, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  3:
            if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_imax)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("cg_solve_c", 1, 7, 7, 3); __PYX_ERR(0, 29, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  4:
            if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tol)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("cg_solve_c", 1, 7, 7, 4); __PYX_ERR(0, 29, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  5:
            if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_a_tol)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("cg_solve_c", 1, 7, 7, 5); __PYX_ERR(0, 29, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  6:
            if (likely((values[6] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bcols)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("cg_solve_c", 1, 7, 7, 6); __PYX_ERR(0, 29, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "cg_solve_c") < 0)) __PYX_ERR(0, 29, __pyx_L3_error)
          }
        } else if (PyTuple_GET_SIZE(__pyx_args) != 7) {
          goto __pyx_L5_argtuple_error;
        } else {
          values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
          values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
          values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
          values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
          values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
          values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
          values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        }
        __pyx_v_csr_sparse = values[0];
        __pyx_v_x0 = ((PyArrayObject *)values[1]);
        __pyx_v_b = ((PyArrayObject *)values[2]);
        __pyx_v_imax = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_imax == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 32, __pyx_L3_error)
        __pyx_v_tol = __pyx_PyFloat_AsDouble(values[4]); if (unlikely((__pyx_v_tol == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 33, __pyx_L3_error)
        __pyx_v_a_tol = __pyx_PyFloat_AsDouble(values[5]); if (unlikely((__pyx_v_a_tol == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 34, __pyx_L3_error)
        __pyx_v_bcols = __Pyx_PyInt_As_int(values[6]); if (unlikely((__pyx_v_bcols == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 35, __pyx_L3_error)
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("cg_solve_c", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 29, __pyx_L3_error)
      __pyx_L3_error:;
      __Pyx_AddTraceback("anuga.utilities.cg_ext.cg_solve_c", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return NULL;
      __pyx_L4_argument_unpacking_done:;
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x0), __pyx_ptype_5numpy_ndarray, 0, "x0", 0))) __PYX_ERR(0, 30, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_b), __pyx_ptype_5numpy_ndarray, 0, "b", 0))) __PYX_ERR(0, 31, __pyx_L1_error)
      __pyx_r = __pyx_pf_5anuga_9utilities_6cg_ext_2cg_solve_c(__pyx_self, __pyx_v_csr_sparse, __pyx_v_x0, __pyx_v_b, __pyx_v_imax, __pyx_v_tol, __pyx_v_a_tol, __pyx_v_bcols);
      int __pyx_lineno = 0;
      const char *__pyx_filename = NULL;
      int __pyx_clineno = 0;

      /* function exit code */
      goto __pyx_L0;
      __pyx_L1_error:;
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_5anuga_9utilities_6cg_ext_2cg_solve_c(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_csr_sparse, PyArrayObject *__pyx_v_x0, PyArrayObject *__pyx_v_b, int __pyx_v_imax, double __pyx_v_tol, double __pyx_v_a_tol, CYTHON_UNUSED int __pyx_v_bcols) {
      int __pyx_v_M;
      int __pyx_v_err;
      PyArrayObject *__pyx_v_data = 0;
      PyArrayObject *__pyx_v_colind = 0;
      PyArrayObject *__pyx_v_row_ptr = 0;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_b;
      __Pyx_Buffer __pyx_pybuffer_b;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_colind;
      __Pyx_Buffer __pyx_pybuffer_colind;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_data;
      __Pyx_Buffer __pyx_pybuffer_data;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_row_ptr;
      __Pyx_Buffer __pyx_pybuffer_row_ptr;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_x0;
      __Pyx_Buffer __pyx_pybuffer_x0;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("cg_solve_c", 0);
      __pyx_pybuffer_data.pybuffer.buf = NULL;
      __pyx_pybuffer_data.refcount = 0;
      __pyx_pybuffernd_data.data = NULL;
      __pyx_pybuffernd_data.rcbuffer = &__pyx_pybuffer_data;
      __pyx_pybuffer_colind.pybuffer.buf = NULL;
      __pyx_pybuffer_colind.refcount = 0;
      __pyx_pybuffernd_colind.data = NULL;
      __pyx_pybuffernd_colind.rcbuffer = &__pyx_pybuffer_colind;
      __pyx_pybuffer_row_ptr.pybuffer.buf = NULL;
      __pyx_pybuffer_row_ptr.refcount = 0;
      __pyx_pybuffernd_row_ptr.data = NULL;
      __pyx_pybuffernd_row_ptr.rcbuffer = &__pyx_pybuffer_row_ptr;
      __pyx_pybuffer_x0.pybuffer.buf = NULL;
      __pyx_pybuffer_x0.refcount = 0;
      __pyx_pybuffernd_x0.data = NULL;
      __pyx_pybuffernd_x0.rcbuffer = &__pyx_pybuffer_x0;
      __pyx_pybuffer_b.pybuffer.buf = NULL;
      __pyx_pybuffer_b.refcount = 0;
      __pyx_pybuffernd_b.data = NULL;
      __pyx_pybuffernd_b.rcbuffer = &__pyx_pybuffer_b;
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_x0.rcbuffer->pybuffer, (PyObject*)__pyx_v_x0, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 29, __pyx_L1_error)
      }
      __pyx_pybuffernd_x0.diminfo[0].strides = __pyx_pybuffernd_x0.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_x0.diminfo[0].shape = __pyx_pybuffernd_x0.rcbuffer->pybuffer.shape[0];
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_b.rcbuffer->pybuffer, (PyObject*)__pyx_v_b, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 29, __pyx_L1_error)
      }
      __pyx_pybuffernd_b.diminfo[0].strides = __pyx_pybuffernd_b.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_b.diminfo[0].shape = __pyx_pybuffernd_b.rcbuffer->pybuffer.shape[0];
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_b.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_colind.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_row_ptr.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x0.rcbuffer->pybuffer);
      __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
      __Pyx_AddTraceback("anuga.utilities.cg_ext.cg_solve_c", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      goto __pyx_L2;
      __pyx_L0:;
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_b.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_colind.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_row_ptr.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x0.rcbuffer->pybuffer);
      __pyx_L2:;
      __Pyx_XDECREF((PyObject *)__pyx_v_data);
      __Pyx_XDECREF((PyObject *)__pyx_v_colind);
      __Pyx_XDECREF((PyObject *)__pyx_v_row_ptr);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_tuple__5 = PyTuple_Pack(12, __pyx_n_s_csr_sparse, __pyx_n_s_x0, __pyx_n_s_b, __pyx_n_s_imax, __pyx_n_s_tol, __pyx_n_s_a_tol, __pyx_n_s_bcols, __pyx_n_s_M, __pyx_n_s_err, __pyx_n_s_data, __pyx_n_s_colind, __pyx_n_s_row_ptr); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 29, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__5);
      __Pyx_GIVEREF(__pyx_tuple__5);
    /* … */
      __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5anuga_9utilities_6cg_ext_3cg_solve_c, NULL, __pyx_n_s_anuga_utilities_cg_ext); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 29, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_cg_solve_c, __pyx_t_1) < 0) __PYX_ERR(0, 29, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_codeobj__6 = (PyObject*)__Pyx_PyCode_New(7, 0, 12, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__5, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_anuga_utilities_cg_ext_pyx, __pyx_n_s_cg_solve_c, 29, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__6)) __PYX_ERR(0, 29, __pyx_L1_error)

     30:                 np.ndarray[double, ndim=1, mode="c"] x0 not None,\

     31:                 np.ndarray[double, ndim=1, mode="c"] b not None,\

     32:                 int imax,\

     33:                 double tol,\

     34:                 double a_tol,\

     35:                 int bcols):

     36:

     37:     cdef int M, err

     38:     cdef np.ndarray[double, ndim=1, mode="c"] data

     39:     cdef np.ndarray[long, ndim=1, mode="c"] colind

     40:     cdef np.ndarray[long, ndim=1, mode="c"] row_ptr

     41:

    +42:     data = csr_sparse.data

      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_csr_sparse, __pyx_n_s_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 42, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 42, __pyx_L1_error)
      __pyx_t_2 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
        __pyx_t_3 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)__pyx_t_2, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_3 < 0)) {
          PyErr_Fetch(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)__pyx_v_data, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_4); Py_XDECREF(__pyx_t_5); Py_XDECREF(__pyx_t_6);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_4, __pyx_t_5, __pyx_t_6);
          }
          __pyx_t_4 = __pyx_t_5 = __pyx_t_6 = 0;
        }
        __pyx_pybuffernd_data.diminfo[0].strides = __pyx_pybuffernd_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_data.diminfo[0].shape = __pyx_pybuffernd_data.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 42, __pyx_L1_error)
      }
      __pyx_t_2 = 0;
      __pyx_v_data = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;

    +43:     colind = csr_sparse.colind

      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_csr_sparse, __pyx_n_s_colind); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 43, __pyx_L1_error)
      __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_colind.rcbuffer->pybuffer);
        __pyx_t_3 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_colind.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_3 < 0)) {
          PyErr_Fetch(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_colind.rcbuffer->pybuffer, (PyObject*)__pyx_v_colind, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_6); Py_XDECREF(__pyx_t_5); Py_XDECREF(__pyx_t_4);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_6, __pyx_t_5, __pyx_t_4);
          }
          __pyx_t_6 = __pyx_t_5 = __pyx_t_4 = 0;
        }
        __pyx_pybuffernd_colind.diminfo[0].strides = __pyx_pybuffernd_colind.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_colind.diminfo[0].shape = __pyx_pybuffernd_colind.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 43, __pyx_L1_error)
      }
      __pyx_t_7 = 0;
      __pyx_v_colind = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;

    +44:     row_ptr = csr_sparse.row_ptr

      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_csr_sparse, __pyx_n_s_row_ptr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 44, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 44, __pyx_L1_error)
      __pyx_t_8 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_row_ptr.rcbuffer->pybuffer);
        __pyx_t_3 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_row_ptr.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_3 < 0)) {
          PyErr_Fetch(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_row_ptr.rcbuffer->pybuffer, (PyObject*)__pyx_v_row_ptr, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_4); Py_XDECREF(__pyx_t_5); Py_XDECREF(__pyx_t_6);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_4, __pyx_t_5, __pyx_t_6);
          }
          __pyx_t_4 = __pyx_t_5 = __pyx_t_6 = 0;
        }
        __pyx_pybuffernd_row_ptr.diminfo[0].strides = __pyx_pybuffernd_row_ptr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_row_ptr.diminfo[0].shape = __pyx_pybuffernd_row_ptr.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 44, __pyx_L1_error)
      }
      __pyx_t_8 = 0;
      __pyx_v_row_ptr = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;

     45:

    +46:     M = row_ptr.shape[0] - 1

      __pyx_v_M = ((__pyx_v_row_ptr->dimensions[0]) - 1);

     47:

    +48:     err = _cg_solve_c(&data[0],\

      __pyx_t_9 = 0;
    /* … */
      __pyx_v_err = _cg_solve_c((&(*__Pyx_BufPtrCContig1d(double *, __pyx_pybuffernd_data.rcbuffer->pybuffer.buf, __pyx_t_9, __pyx_pybuffernd_data.diminfo[0].strides))), (&(*__Pyx_BufPtrCContig1d(long *, __pyx_pybuffernd_colind.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_colind.diminfo[0].strides))), (&(*__Pyx_BufPtrCContig1d(long *, __pyx_pybuffernd_row_ptr.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_row_ptr.diminfo[0].strides))), (&(*__Pyx_BufPtrCContig1d(double *, __pyx_pybuffernd_b.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_b.diminfo[0].strides))), (&(*__Pyx_BufPtrCContig1d(double *, __pyx_pybuffernd_x0.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_x0.diminfo[0].strides))), __pyx_v_imax, __pyx_v_tol, __pyx_v_a_tol, __pyx_v_M);

    +49:                     &colind[0],\

      __pyx_t_10 = 0;

    +50:                     &row_ptr[0],\

      __pyx_t_11 = 0;

    +51:                     &b[0],\

      __pyx_t_12 = 0;

    +52:                     &x0[0],\

      __pyx_t_13 = 0;

     53:                     imax,\

     54:                     tol,\

     55:                     a_tol,\

     56:                     M)

     57:

    +58:     return err

      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_err); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 58, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;

     59:

    +60: def cg_solve_c_precon(object csr_sparse,\

    /* Python wrapper */
    static PyObject *__pyx_pw_5anuga_9utilities_6cg_ext_5cg_solve_c_precon(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static PyMethodDef __pyx_mdef_5anuga_9utilities_6cg_ext_5cg_solve_c_precon = {"cg_solve_c_precon", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5anuga_9utilities_6cg_ext_5cg_solve_c_precon, METH_VARARGS|METH_KEYWORDS, 0};
    static PyObject *__pyx_pw_5anuga_9utilities_6cg_ext_5cg_solve_c_precon(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyObject *__pyx_v_csr_sparse = 0;
      PyArrayObject *__pyx_v_x0 = 0;
      PyArrayObject *__pyx_v_b = 0;
      int __pyx_v_imax;
      double __pyx_v_tol;
      double __pyx_v_a_tol;
      CYTHON_UNUSED int __pyx_v_bcols;
      PyArrayObject *__pyx_v_precon = 0;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("cg_solve_c_precon (wrapper)", 0);
      {
        static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_csr_sparse,&__pyx_n_s_x0,&__pyx_n_s_b,&__pyx_n_s_imax,&__pyx_n_s_tol,&__pyx_n_s_a_tol,&__pyx_n_s_bcols,&__pyx_n_s_precon,0};
        PyObject* values[8] = {0,0,0,0,0,0,0,0};
        if (unlikely(__pyx_kwds)) {
          Py_ssize_t kw_args;
          const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
          switch (pos_args) {
            case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
            CYTHON_FALLTHROUGH;
            case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
            CYTHON_FALLTHROUGH;
            case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
            CYTHON_FALLTHROUGH;
            case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
            CYTHON_FALLTHROUGH;
            case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
            CYTHON_FALLTHROUGH;
            case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
            CYTHON_FALLTHROUGH;
            case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
            CYTHON_FALLTHROUGH;
            case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = PyDict_Size(__pyx_kwds);
          switch (pos_args) {
            case  0:
            if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_csr_sparse)) != 0)) kw_args--;
            else goto __pyx_L5_argtuple_error;
            CYTHON_FALLTHROUGH;
            case  1:
            if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_x0)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("cg_solve_c_precon", 1, 8, 8, 1); __PYX_ERR(0, 60, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  2:
            if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_b)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("cg_solve_c_precon", 1, 8, 8, 2); __PYX_ERR(0, 60, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  3:
            if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_imax)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("cg_solve_c_precon", 1, 8, 8, 3); __PYX_ERR(0, 60, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  4:
            if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tol)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("cg_solve_c_precon", 1, 8, 8, 4); __PYX_ERR(0, 60, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  5:
            if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_a_tol)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("cg_solve_c_precon", 1, 8, 8, 5); __PYX_ERR(0, 60, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  6:
            if (likely((values[6] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bcols)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("cg_solve_c_precon", 1, 8, 8, 6); __PYX_ERR(0, 60, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  7:
            if (likely((values[7] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_precon)) != 0)) kw_args--;
            else {
              __Pyx_RaiseArgtupleInvalid("cg_solve_c_precon", 1, 8, 8, 7); __PYX_ERR(0, 60, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "cg_solve_c_precon") < 0)) __PYX_ERR(0, 60, __pyx_L3_error)
          }
        } else if (PyTuple_GET_SIZE(__pyx_args) != 8) {
          goto __pyx_L5_argtuple_error;
        } else {
          values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
          values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
          values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
          values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
          values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
          values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
          values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
          values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        }
        __pyx_v_csr_sparse = values[0];
        __pyx_v_x0 = ((PyArrayObject *)values[1]);
        __pyx_v_b = ((PyArrayObject *)values[2]);
        __pyx_v_imax = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_imax == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 63, __pyx_L3_error)
        __pyx_v_tol = __pyx_PyFloat_AsDouble(values[4]); if (unlikely((__pyx_v_tol == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 64, __pyx_L3_error)
        __pyx_v_a_tol = __pyx_PyFloat_AsDouble(values[5]); if (unlikely((__pyx_v_a_tol == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 65, __pyx_L3_error)
        __pyx_v_bcols = __Pyx_PyInt_As_int(values[6]); if (unlikely((__pyx_v_bcols == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 66, __pyx_L3_error)
        __pyx_v_precon = ((PyArrayObject *)values[7]);
      }
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("cg_solve_c_precon", 1, 8, 8, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 60, __pyx_L3_error)
      __pyx_L3_error:;
      __Pyx_AddTraceback("anuga.utilities.cg_ext.cg_solve_c_precon", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return NULL;
      __pyx_L4_argument_unpacking_done:;
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x0), __pyx_ptype_5numpy_ndarray, 0, "x0", 0))) __PYX_ERR(0, 61, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_b), __pyx_ptype_5numpy_ndarray, 0, "b", 0))) __PYX_ERR(0, 62, __pyx_L1_error)
      if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_precon), __pyx_ptype_5numpy_ndarray, 0, "precon", 0))) __PYX_ERR(0, 67, __pyx_L1_error)
      __pyx_r = __pyx_pf_5anuga_9utilities_6cg_ext_4cg_solve_c_precon(__pyx_self, __pyx_v_csr_sparse, __pyx_v_x0, __pyx_v_b, __pyx_v_imax, __pyx_v_tol, __pyx_v_a_tol, __pyx_v_bcols, __pyx_v_precon);
      int __pyx_lineno = 0;
      const char *__pyx_filename = NULL;
      int __pyx_clineno = 0;

      /* function exit code */
      goto __pyx_L0;
      __pyx_L1_error:;
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_5anuga_9utilities_6cg_ext_4cg_solve_c_precon(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_csr_sparse, PyArrayObject *__pyx_v_x0, PyArrayObject *__pyx_v_b, int __pyx_v_imax, double __pyx_v_tol, double __pyx_v_a_tol, CYTHON_UNUSED int __pyx_v_bcols, PyArrayObject *__pyx_v_precon) {
      int __pyx_v_M;
      int __pyx_v_err;
      PyArrayObject *__pyx_v_data = 0;
      PyArrayObject *__pyx_v_colind = 0;
      PyArrayObject *__pyx_v_row_ptr = 0;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_b;
      __Pyx_Buffer __pyx_pybuffer_b;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_colind;
      __Pyx_Buffer __pyx_pybuffer_colind;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_data;
      __Pyx_Buffer __pyx_pybuffer_data;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_precon;
      __Pyx_Buffer __pyx_pybuffer_precon;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_row_ptr;
      __Pyx_Buffer __pyx_pybuffer_row_ptr;
      __Pyx_LocalBuf_ND __pyx_pybuffernd_x0;
      __Pyx_Buffer __pyx_pybuffer_x0;
      PyObject *__pyx_r = NULL;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("cg_solve_c_precon", 0);
      __pyx_pybuffer_data.pybuffer.buf = NULL;
      __pyx_pybuffer_data.refcount = 0;
      __pyx_pybuffernd_data.data = NULL;
      __pyx_pybuffernd_data.rcbuffer = &__pyx_pybuffer_data;
      __pyx_pybuffer_colind.pybuffer.buf = NULL;
      __pyx_pybuffer_colind.refcount = 0;
      __pyx_pybuffernd_colind.data = NULL;
      __pyx_pybuffernd_colind.rcbuffer = &__pyx_pybuffer_colind;
      __pyx_pybuffer_row_ptr.pybuffer.buf = NULL;
      __pyx_pybuffer_row_ptr.refcount = 0;
      __pyx_pybuffernd_row_ptr.data = NULL;
      __pyx_pybuffernd_row_ptr.rcbuffer = &__pyx_pybuffer_row_ptr;
      __pyx_pybuffer_x0.pybuffer.buf = NULL;
      __pyx_pybuffer_x0.refcount = 0;
      __pyx_pybuffernd_x0.data = NULL;
      __pyx_pybuffernd_x0.rcbuffer = &__pyx_pybuffer_x0;
      __pyx_pybuffer_b.pybuffer.buf = NULL;
      __pyx_pybuffer_b.refcount = 0;
      __pyx_pybuffernd_b.data = NULL;
      __pyx_pybuffernd_b.rcbuffer = &__pyx_pybuffer_b;
      __pyx_pybuffer_precon.pybuffer.buf = NULL;
      __pyx_pybuffer_precon.refcount = 0;
      __pyx_pybuffernd_precon.data = NULL;
      __pyx_pybuffernd_precon.rcbuffer = &__pyx_pybuffer_precon;
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_x0.rcbuffer->pybuffer, (PyObject*)__pyx_v_x0, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 60, __pyx_L1_error)
      }
      __pyx_pybuffernd_x0.diminfo[0].strides = __pyx_pybuffernd_x0.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_x0.diminfo[0].shape = __pyx_pybuffernd_x0.rcbuffer->pybuffer.shape[0];
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_b.rcbuffer->pybuffer, (PyObject*)__pyx_v_b, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 60, __pyx_L1_error)
      }
      __pyx_pybuffernd_b.diminfo[0].strides = __pyx_pybuffernd_b.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_b.diminfo[0].shape = __pyx_pybuffernd_b.rcbuffer->pybuffer.shape[0];
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_precon.rcbuffer->pybuffer, (PyObject*)__pyx_v_precon, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 60, __pyx_L1_error)
      }
      __pyx_pybuffernd_precon.diminfo[0].strides = __pyx_pybuffernd_precon.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_precon.diminfo[0].shape = __pyx_pybuffernd_precon.rcbuffer->pybuffer.shape[0];
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_b.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_colind.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_precon.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_row_ptr.rcbuffer->pybuffer);
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x0.rcbuffer->pybuffer);
      __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
      __Pyx_AddTraceback("anuga.utilities.cg_ext.cg_solve_c_precon", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      goto __pyx_L2;
      __pyx_L0:;
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_b.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_colind.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_precon.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_row_ptr.rcbuffer->pybuffer);
      __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_x0.rcbuffer->pybuffer);
      __pyx_L2:;
      __Pyx_XDECREF((PyObject *)__pyx_v_data);
      __Pyx_XDECREF((PyObject *)__pyx_v_colind);
      __Pyx_XDECREF((PyObject *)__pyx_v_row_ptr);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_tuple__7 = PyTuple_Pack(13, __pyx_n_s_csr_sparse, __pyx_n_s_x0, __pyx_n_s_b, __pyx_n_s_imax, __pyx_n_s_tol, __pyx_n_s_a_tol, __pyx_n_s_bcols, __pyx_n_s_precon, __pyx_n_s_M, __pyx_n_s_err, __pyx_n_s_data, __pyx_n_s_colind, __pyx_n_s_row_ptr); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 60, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__7);
      __Pyx_GIVEREF(__pyx_tuple__7);
    /* … */
      __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5anuga_9utilities_6cg_ext_5cg_solve_c_precon, NULL, __pyx_n_s_anuga_utilities_cg_ext); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 60, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_cg_solve_c_precon, __pyx_t_1) < 0) __PYX_ERR(0, 60, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

     61:                     np.ndarray[double, ndim=1, mode="c"] x0 not None,\

     62:                     np.ndarray[double, ndim=1, mode="c"] b not None,\

     63:                     int imax,\

     64:                     double tol,\

     65:                     double a_tol,\

     66:                     int bcols,\

     67:                     np.ndarray[double, ndim=1, mode="c"] precon not None):

     68:

     69:     cdef int M, err

     70:     cdef np.ndarray[double, ndim=1, mode="c"] data

     71:     cdef np.ndarray[long, ndim=1, mode="c"] colind

     72:     cdef np.ndarray[long, ndim=1, mode="c"] row_ptr

     73:

    +74:     data = csr_sparse.data

      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_csr_sparse, __pyx_n_s_data); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 74, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 74, __pyx_L1_error)
      __pyx_t_2 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_data.rcbuffer->pybuffer);
        __pyx_t_3 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)__pyx_t_2, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_3 < 0)) {
          PyErr_Fetch(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_data.rcbuffer->pybuffer, (PyObject*)__pyx_v_data, &__Pyx_TypeInfo_double, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_4); Py_XDECREF(__pyx_t_5); Py_XDECREF(__pyx_t_6);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_4, __pyx_t_5, __pyx_t_6);
          }
          __pyx_t_4 = __pyx_t_5 = __pyx_t_6 = 0;
        }
        __pyx_pybuffernd_data.diminfo[0].strides = __pyx_pybuffernd_data.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_data.diminfo[0].shape = __pyx_pybuffernd_data.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 74, __pyx_L1_error)
      }
      __pyx_t_2 = 0;
      __pyx_v_data = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;

    +75:     colind = csr_sparse.colind

      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_csr_sparse, __pyx_n_s_colind); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 75, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 75, __pyx_L1_error)
      __pyx_t_7 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_colind.rcbuffer->pybuffer);
        __pyx_t_3 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_colind.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_3 < 0)) {
          PyErr_Fetch(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_colind.rcbuffer->pybuffer, (PyObject*)__pyx_v_colind, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_6); Py_XDECREF(__pyx_t_5); Py_XDECREF(__pyx_t_4);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_6, __pyx_t_5, __pyx_t_4);
          }
          __pyx_t_6 = __pyx_t_5 = __pyx_t_4 = 0;
        }
        __pyx_pybuffernd_colind.diminfo[0].strides = __pyx_pybuffernd_colind.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_colind.diminfo[0].shape = __pyx_pybuffernd_colind.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 75, __pyx_L1_error)
      }
      __pyx_t_7 = 0;
      __pyx_v_colind = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;

    +76:     row_ptr = csr_sparse.row_ptr

      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_csr_sparse, __pyx_n_s_row_ptr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 76, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 76, __pyx_L1_error)
      __pyx_t_8 = ((PyArrayObject *)__pyx_t_1);
      {
        __Pyx_BufFmt_StackElem __pyx_stack[1];
        __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_row_ptr.rcbuffer->pybuffer);
        __pyx_t_3 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_row_ptr.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack);
        if (unlikely(__pyx_t_3 < 0)) {
          PyErr_Fetch(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6);
          if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_row_ptr.rcbuffer->pybuffer, (PyObject*)__pyx_v_row_ptr, &__Pyx_TypeInfo_long, PyBUF_FORMAT| PyBUF_C_CONTIGUOUS, 1, 0, __pyx_stack) == -1)) {
            Py_XDECREF(__pyx_t_4); Py_XDECREF(__pyx_t_5); Py_XDECREF(__pyx_t_6);
            __Pyx_RaiseBufferFallbackError();
          } else {
            PyErr_Restore(__pyx_t_4, __pyx_t_5, __pyx_t_6);
          }
          __pyx_t_4 = __pyx_t_5 = __pyx_t_6 = 0;
        }
        __pyx_pybuffernd_row_ptr.diminfo[0].strides = __pyx_pybuffernd_row_ptr.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_row_ptr.diminfo[0].shape = __pyx_pybuffernd_row_ptr.rcbuffer->pybuffer.shape[0];
        if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 76, __pyx_L1_error)
      }
      __pyx_t_8 = 0;
      __pyx_v_row_ptr = ((PyArrayObject *)__pyx_t_1);
      __pyx_t_1 = 0;

     77:

    +78:     M = row_ptr.shape[0] - 1

      __pyx_v_M = ((__pyx_v_row_ptr->dimensions[0]) - 1);

     79:

    +80:     err = _cg_solve_c_precon(&data[0],\

      __pyx_t_9 = 0;
    /* … */
      __pyx_v_err = _cg_solve_c_precon((&(*__Pyx_BufPtrCContig1d(double *, __pyx_pybuffernd_data.rcbuffer->pybuffer.buf, __pyx_t_9, __pyx_pybuffernd_data.diminfo[0].strides))), (&(*__Pyx_BufPtrCContig1d(long *, __pyx_pybuffernd_colind.rcbuffer->pybuffer.buf, __pyx_t_10, __pyx_pybuffernd_colind.diminfo[0].strides))), (&(*__Pyx_BufPtrCContig1d(long *, __pyx_pybuffernd_row_ptr.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_row_ptr.diminfo[0].strides))), (&(*__Pyx_BufPtrCContig1d(double *, __pyx_pybuffernd_b.rcbuffer->pybuffer.buf, __pyx_t_12, __pyx_pybuffernd_b.diminfo[0].strides))), (&(*__Pyx_BufPtrCContig1d(double *, __pyx_pybuffernd_x0.rcbuffer->pybuffer.buf, __pyx_t_13, __pyx_pybuffernd_x0.diminfo[0].strides))), __pyx_v_imax, __pyx_v_tol, __pyx_v_a_tol, __pyx_v_M, (&(*__Pyx_BufPtrCContig1d(double *, __pyx_pybuffernd_precon.rcbuffer->pybuffer.buf, __pyx_t_14, __pyx_pybuffernd_precon.diminfo[0].strides))));

    +81:                             &colind[0],\

      __pyx_t_10 = 0;

    +82:                             &row_ptr[0],\

      __pyx_t_11 = 0;

    +83:                             &b[0],\

      __pyx_t_12 = 0;

    +84:                             &x0[0],\

      __pyx_t_13 = 0;

     85:                             imax,\

     86:                             tol,\

     87:                             a_tol,\

     88:                             M,\

    +89:                             &precon[0])

      __pyx_t_14 = 0;

     90:

    +91:     return err

      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_err); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 91, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;