/* Generated by Cython 0.29.21 */

/* BEGIN: Cython Metadata
{
    "distutils": {
        "define_macros": [
            [
                "_FORCE_INLINES",
                "1"
            ],
            [
                "CUPY_NO_CUDA",
                "1"
            ]
        ],
        "depends": [],
        "extra_link_args": [
            "-Wl,--disable-new-dtags,-rpath,/usr/local/cuda/lib64"
        ],
        "include_dirs": [
            "/usr/local/cuda/include"
        ],
        "language": "c++",
        "library_dirs": [
            "/usr/local/cuda/lib64"
        ],
        "name": "cupy.core._routines_indexing",
        "sources": [
            "cupy/core/_routines_indexing.pyx"
        ]
    },
    "module_name": "cupy.core._routines_indexing"
}
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 < 0x03030000)
    #error Cython requires Python 2.6+ or Python 3.3+.
#else
#define CYTHON_ABI "0_29_21"
#define CYTHON_HEX_VERSION 0x001D15F0
#define CYTHON_FUTURE_DIVISION 1
#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
#define __PYX_COMMA ,
#ifndef HAVE_LONG_LONG
  #if 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_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #if PY_VERSION_HEX < 0x03050000
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #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
  #undef CYTHON_PEP489_MULTI_PHASE_INIT
  #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #undef CYTHON_USE_TP_FINALIZE
  #define CYTHON_USE_TP_FINALIZE 0
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 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_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #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
  #undef CYTHON_PEP489_MULTI_PHASE_INIT
  #define CYTHON_PEP489_MULTI_PHASE_INIT 0
  #undef CYTHON_USE_TP_FINALIZE
  #define CYTHON_USE_TP_FINALIZE 0
  #undef CYTHON_USE_DICT_VERSIONS
  #define CYTHON_USE_DICT_VERSIONS 0
  #undef CYTHON_USE_EXC_INFO_STACK
  #define CYTHON_USE_EXC_INFO_STACK 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_VERSION_HEX < 0x02070000
    #undef CYTHON_USE_PYTYPE_LOOKUP
    #define CYTHON_USE_PYTYPE_LOOKUP 0
  #elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
    #define CYTHON_USE_PYTYPE_LOOKUP 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
  #ifndef CYTHON_PEP489_MULTI_PHASE_INIT
    #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000)
  #endif
  #ifndef CYTHON_USE_TP_FINALIZE
    #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1)
  #endif
  #ifndef CYTHON_USE_DICT_VERSIONS
    #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1)
  #endif
  #ifndef CYTHON_USE_EXC_INFO_STACK
    #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3)
  #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
  #ifdef SIZEOF_VOID_P
    enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) };
  #endif
#endif
#ifndef __has_attribute
  #define __has_attribute(x) 0
#endif
#ifndef __has_cpp_attribute
  #define __has_cpp_attribute(x) 0
#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)
#ifdef _MSC_VER
    #ifndef _MSC_STDINT_H_
        #if _MSC_VER < 1300
           typedef unsigned char     uint8_t;
           typedef unsigned int      uint32_t;
        #else
           typedef unsigned __int8   uint8_t;
           typedef unsigned __int32  uint32_t;
        #endif
    #endif
#else
   #include <stdint.h>
#endif
#ifndef CYTHON_FALLTHROUGH
  #if defined(__cplusplus) && __cplusplus >= 201103L
    #if __has_cpp_attribute(fallthrough)
      #define CYTHON_FALLTHROUGH [[fallthrough]]
    #elif __has_cpp_attribute(clang::fallthrough)
      #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
    #elif __has_cpp_attribute(gnu::fallthrough)
      #define CYTHON_FALLTHROUGH [[gnu::fallthrough]]
    #endif
  #endif
  #ifndef CYTHON_FALLTHROUGH
    #if __has_attribute(fallthrough)
      #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
    #else
      #define CYTHON_FALLTHROUGH
    #endif
  #endif
  #if defined(__clang__ ) && defined(__apple_build_version__)
    #if __apple_build_version__ < 7000000
      #undef  CYTHON_FALLTHROUGH
      #define CYTHON_FALLTHROUGH
    #endif
  #endif
#endif

#ifndef __cplusplus
  #error "Cython files generated with the C++ option must be compiled with a C++ compiler."
#endif
#ifndef CYTHON_INLINE
  #if defined(__clang__)
    #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  #else
    #define CYTHON_INLINE inline
  #endif
#endif
template<typename T>
void __Pyx_call_destructor(T& x) {
    x.~T();
}
template<typename T>
class __Pyx_FakeReference {
  public:
    __Pyx_FakeReference() : ptr(NULL) { }
    __Pyx_FakeReference(const T& ref) : ptr(const_cast<T*>(&ref)) { }
    T *operator->() { return ptr; }
    T *operator&() { return ptr; }
    operator T&() { return *ptr; }
    template<typename U> bool operator ==(U other) { return *ptr == other; }
    template<typename U> bool operator !=(U other) { return *ptr != other; }
  private:
    T *ptr;
};

#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"
#if PY_VERSION_HEX >= 0x030800A4 && PY_VERSION_HEX < 0x030800B2
  #define __Pyx_PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\
          PyCode_New(a, 0, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
#else
  #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)
#endif
  #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_STACKLESS
  #define METH_STACKLESS 0
#endif
#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL)
  #ifndef METH_FASTCALL
     #define METH_FASTCALL 0x80
  #endif
  typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs);
  typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args,
                                                          Py_ssize_t nargs, PyObject *kwnames);
#else
  #define __Pyx_PyCFunctionFast _PyCFunctionFast
  #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
#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 | METH_KEYWORDS | METH_STACKLESS)))))
#else
#define __Pyx_PyFastCFunction_Check(func) 0
#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_CPYTHON && PY_VERSION_HEX < 0x030400A1
  #define PyMem_RawMalloc(n)           PyMem_Malloc(n)
  #define PyMem_RawRealloc(p, n)       PyMem_Realloc(p, n)
  #define PyMem_RawFree(p)             PyMem_Free(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
#if !CYTHON_FAST_THREAD_STATE || PY_VERSION_HEX < 0x02070000
  #define __Pyx_PyThreadState_Current PyThreadState_GET()
#elif PY_VERSION_HEX >= 0x03060000
  #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
#elif PY_VERSION_HEX >= 0x03000000
  #define __Pyx_PyThreadState_Current PyThreadState_GET()
#else
  #define __Pyx_PyThreadState_Current _PyThreadState_Current
#endif
#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT)
#include "pythread.h"
#define Py_tss_NEEDS_INIT 0
typedef int Py_tss_t;
static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) {
  *key = PyThread_create_key();
  return 0;
}
static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) {
  Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t));
  *key = Py_tss_NEEDS_INIT;
  return key;
}
static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) {
  PyObject_Free(key);
}
static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) {
  return *key != Py_tss_NEEDS_INIT;
}
static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) {
  PyThread_delete_key(*key);
  *key = Py_tss_NEEDS_INIT;
}
static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) {
  return PyThread_set_key_value(*key, value);
}
static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
  return PyThread_get_key_value(*key);
}
#endif
#if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized)
#define __Pyx_PyDict_NewPresized(n)  ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n))
#else
#define __Pyx_PyDict_NewPresized(n)  PyDict_New()
#endif
#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(x,y)
#else
  #define __Pyx_PyNumber_Divide(x,y)         PyNumber_Divide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceDivide(x,y)
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
#define __Pyx_PyDict_GetItemStr(dict, name)  _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
#else
#define __Pyx_PyDict_GetItemStr(dict, name)  PyDict_GetItem(dict, name)
#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)
  #if defined(PyUnicode_IS_READY) && defined(PyUnicode_GET_SIZE)
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
  #else
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_LENGTH(u))
  #endif
#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
#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? 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
#ifndef PyObject_Unicode
  #define PyObject_Unicode             PyObject_Str
#endif
#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
#if PY_VERSION_HEX >= 0x030900A4
  #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt)
  #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size)
#else
  #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt)
  #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size)
#endif
#if CYTHON_ASSUME_SAFE_MACROS
  #define __Pyx_PySequence_SIZE(seq)  Py_SIZE(seq)
#else
  #define __Pyx_PySequence_SIZE(seq)  PySequence_Size(seq)
#endif
#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) ? ((void)(klass), PyMethod_New(func, self)) : __Pyx_NewRef(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
    #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
  #endif
#else
  #define __Pyx_PyType_AsAsync(obj) NULL
#endif
#ifndef __Pyx_PyAsyncMethodsStruct
    typedef struct {
        unaryfunc am_await;
        unaryfunc am_aiter;
        unaryfunc am_anext;
    } __Pyx_PyAsyncMethodsStruct;
#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_MARK_ERR_POS(f_index, lineno) \
    { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; }
#define __PYX_ERR(f_index, lineno, Ln_error) \
    { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; }

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

#define __PYX_HAVE__cupy__core___routines_indexing
#define __PYX_HAVE_API__cupy__core___routines_indexing
/* Early includes */
#include "ios"
#include "new"
#include "stdexcept"
#include "typeinfo"
#include <vector>
#include <stdint.h>
#include <utility>

    #if __cplusplus > 199711L
    #include <type_traits>

    namespace cython_std {
    template <typename T> typename std::remove_reference<T>::type&& move(T& t) noexcept { return std::move(t); }
    template <typename T> typename std::remove_reference<T>::type&& move(T&& t) noexcept { return std::move(t); }
    }

    #endif
    
#include <map>
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_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_UTF8 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8)
#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)))  )
static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) {
    return (size_t) i < (size_t) limit;
}
#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)
    #define __Pyx_sst_abs(value) ((Py_ssize_t)_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 const char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE const 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_PyBytes_AsWritableString(s)     ((char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableSString(s)    ((signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsWritableUString(s)    ((unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsString(s)     ((const char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsSString(s)    ((const signed char*) PyBytes_AS_STRING(s))
#define __Pyx_PyBytes_AsUString(s)    ((const unsigned char*) PyBytes_AS_STRING(s))
#define __Pyx_PyObject_AsWritableString(s)    ((char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsSString(s)    ((const signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s)    ((const 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)
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);
}
#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)
static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b);
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
#define __Pyx_PySequence_Tuple(obj)\
    (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj))
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) + 1);
    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 CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }

static PyObject *__pyx_m = NULL;
static PyObject *__pyx_d;
static PyObject *__pyx_b;
static PyObject *__pyx_cython_runtime = NULL;
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[] = {
  "cupy/core/_routines_indexing.pyx",
  "stringsource",
  "cupy/cuda/device.pxd",
  "cupy/cuda/memory.pxd",
  "cupy/cuda/function.pxd",
  "cupy/core/core.pxd",
  "cupy/core/_routines_manipulation.pxd",
};

/* "internal.pxd":43
 * cpdef size_t clp2(size_t x)
 * 
 * ctypedef unsigned short _float16             # <<<<<<<<<<<<<<
 * 
 * cpdef uint16_t to_float16(float f)
 */
typedef unsigned short __pyx_t_4cupy_4core_8internal__float16;

/*--- Type declarations ---*/
struct __pyx_obj_4cupy_4cuda_6device_Handle;
struct __pyx_obj_4cupy_4cuda_6device_Device;
struct __pyx_obj_4cupy_4cuda_6memory_BaseMemory;
struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer;
struct __pyx_obj_4cupy_4cuda_6memory_MemoryPool;
struct __pyx_obj_4cupy_4cuda_6memory_CFunctionAllocatorMemory;
struct __pyx_obj_4cupy_4cuda_6memory_CFunctionAllocator;
struct __pyx_obj_4cupy_4cuda_8function_CPointer;
struct __pyx_obj_4cupy_4cuda_8function_Function;
struct __pyx_obj_4cupy_4cuda_8function_Module;
struct __pyx_obj_4cupy_4cuda_8function_LinkState;
struct __pyx_obj_4cupy_4core_4core_ndarray;
struct __pyx_obj_4cupy_4core_4core_Indexer;
struct __pyx_obj_4cupy_4core_22_routines_manipulation_broadcast;
struct __pyx_opt_args_4cupy_4cuda_6memory_13MemoryPointer_copy_from_device_async;
struct __pyx_opt_args_4cupy_4cuda_6memory_13MemoryPointer_copy_from_host_async;
struct __pyx_opt_args_4cupy_4cuda_6memory_13MemoryPointer_copy_from_async;
struct __pyx_opt_args_4cupy_4cuda_6memory_13MemoryPointer_copy_to_host_async;
struct __pyx_opt_args_4cupy_4cuda_6memory_13MemoryPointer_memset_async;
struct __pyx_opt_args_4cupy_4cuda_6memory_set_allocator;
struct __pyx_opt_args_4cupy_4cuda_6memory_10MemoryPool_free_all_blocks;
struct __pyx_opt_args_4cupy_4cuda_6memory_10MemoryPool_set_limit;

/* "memory.pxd":30
 * 
 *     cpdef copy_from_device(self, MemoryPointer src, size_t size)
 *     cpdef copy_from_device_async(self, MemoryPointer src, size_t size,             # <<<<<<<<<<<<<<
 *                                  stream=?)
 *     cpdef copy_from_host(self, mem, size_t size)
 */
struct __pyx_opt_args_4cupy_4cuda_6memory_13MemoryPointer_copy_from_device_async {
  int __pyx_n;
  PyObject *stream;
};

/* "memory.pxd":33
 *                                  stream=?)
 *     cpdef copy_from_host(self, mem, size_t size)
 *     cpdef copy_from_host_async(self, mem, size_t size, stream=?)             # <<<<<<<<<<<<<<
 *     cpdef copy_from(self, mem, size_t size)
 *     cpdef copy_from_async(self, mem, size_t size, stream=?)
 */
struct __pyx_opt_args_4cupy_4cuda_6memory_13MemoryPointer_copy_from_host_async {
  int __pyx_n;
  PyObject *stream;
};

/* "memory.pxd":35
 *     cpdef copy_from_host_async(self, mem, size_t size, stream=?)
 *     cpdef copy_from(self, mem, size_t size)
 *     cpdef copy_from_async(self, mem, size_t size, stream=?)             # <<<<<<<<<<<<<<
 *     cpdef copy_to_host(self, mem, size_t size)
 *     cpdef copy_to_host_async(self, mem, size_t size, stream=?)
 */
struct __pyx_opt_args_4cupy_4cuda_6memory_13MemoryPointer_copy_from_async {
  int __pyx_n;
  PyObject *stream;
};

/* "memory.pxd":37
 *     cpdef copy_from_async(self, mem, size_t size, stream=?)
 *     cpdef copy_to_host(self, mem, size_t size)
 *     cpdef copy_to_host_async(self, mem, size_t size, stream=?)             # <<<<<<<<<<<<<<
 *     cpdef memset(self, int value, size_t size)
 *     cpdef memset_async(self, int value, size_t size, stream=?)
 */
struct __pyx_opt_args_4cupy_4cuda_6memory_13MemoryPointer_copy_to_host_async {
  int __pyx_n;
  PyObject *stream;
};

/* "memory.pxd":39
 *     cpdef copy_to_host_async(self, mem, size_t size, stream=?)
 *     cpdef memset(self, int value, size_t size)
 *     cpdef memset_async(self, int value, size_t size, stream=?)             # <<<<<<<<<<<<<<
 * 
 * 
 */
struct __pyx_opt_args_4cupy_4cuda_6memory_13MemoryPointer_memset_async {
  int __pyx_n;
  PyObject *stream;
};

/* "memory.pxd":45
 * 
 * 
 * cpdef set_allocator(allocator=*)             # <<<<<<<<<<<<<<
 * cpdef get_allocator()
 * 
 */
struct __pyx_opt_args_4cupy_4cuda_6memory_set_allocator {
  int __pyx_n;
  PyObject *allocator;
};

/* "memory.pxd":55
 * 
 *     cpdef MemoryPointer malloc(self, size_t size)
 *     cpdef free_all_blocks(self, stream=?)             # <<<<<<<<<<<<<<
 *     cpdef free_all_free(self)
 *     cpdef size_t n_free_blocks(self)
 */
struct __pyx_opt_args_4cupy_4cuda_6memory_10MemoryPool_free_all_blocks {
  int __pyx_n;
  PyObject *stream;
};

/* "memory.pxd":61
 *     cpdef size_t free_bytes(self)
 *     cpdef size_t total_bytes(self)
 *     cpdef set_limit(self, size=?, fraction=?)             # <<<<<<<<<<<<<<
 *     cpdef size_t get_limit(self)
 * 
 */
struct __pyx_opt_args_4cupy_4cuda_6memory_10MemoryPool_set_limit {
  int __pyx_n;
  PyObject *size;
  PyObject *fraction;
};
struct __pyx_opt_args_4cupy_4cuda_8function_8Function_linear_launch;

/* "cupy/cuda/function.pxd":14
 *         public intptr_t ptr
 * 
 *     cpdef linear_launch(self, size_t size, args, size_t shared_mem=*,             # <<<<<<<<<<<<<<
 *                         size_t block_max_size=*, stream=*)
 * 
 */
struct __pyx_opt_args_4cupy_4cuda_8function_8Function_linear_launch {
  int __pyx_n;
  size_t shared_mem;
  size_t block_max_size;
  PyObject *stream;
};
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_tobytes;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_tofile;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_astype;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_copy;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_view;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_ravel;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_squeeze;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_take;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_put;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_repeat;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_choose;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_sort;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_argsort;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_partition;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_argpartition;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_diagonal;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_max;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_argmax;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_min;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_argmin;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_clip;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_round;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_trace;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_sum;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_cumsum;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_mean;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_var;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_std;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_prod;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_cumprod;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_all;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_any;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_get;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_set;
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_reduced_view;
struct __pyx_opt_args_4cupy_4core_4core_ascontiguousarray;
struct __pyx_opt_args_4cupy_4core_4core_asfortranarray;
struct __pyx_opt_args_4cupy_4core_4core_compile_with_cache;
struct __pyx_opt_args_4cupy_4core_4core_array;

/* "cupy/core/core.pxd":25
 *     cpdef item(self)
 *     cpdef tolist(self)
 *     cpdef bytes tobytes(self, order=*)             # <<<<<<<<<<<<<<
 *     cpdef tofile(self, fid, sep=*, format=*)
 *     cpdef dump(self, file)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_tobytes {
  int __pyx_n;
  PyObject *order;
};

/* "cupy/core/core.pxd":26
 *     cpdef tolist(self)
 *     cpdef bytes tobytes(self, order=*)
 *     cpdef tofile(self, fid, sep=*, format=*)             # <<<<<<<<<<<<<<
 *     cpdef dump(self, file)
 *     cpdef bytes dumps(self)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_tofile {
  int __pyx_n;
  PyObject *sep;
  PyObject *format;
};

/* "cupy/core/core.pxd":29
 *     cpdef dump(self, file)
 *     cpdef bytes dumps(self)
 *     cpdef ndarray astype(self, dtype, order=*, casting=*, subok=*, copy=*)             # <<<<<<<<<<<<<<
 *     cpdef ndarray copy(self, order=*)
 *     cpdef ndarray view(self, dtype=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_astype {
  int __pyx_n;
  PyObject *order;
  PyObject *casting;
  PyObject *subok;
  PyObject *copy;
};

/* "cupy/core/core.pxd":30
 *     cpdef bytes dumps(self)
 *     cpdef ndarray astype(self, dtype, order=*, casting=*, subok=*, copy=*)
 *     cpdef ndarray copy(self, order=*)             # <<<<<<<<<<<<<<
 *     cpdef ndarray view(self, dtype=*)
 *     cpdef fill(self, value)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_copy {
  int __pyx_n;
  PyObject *order;
};

/* "cupy/core/core.pxd":31
 *     cpdef ndarray astype(self, dtype, order=*, casting=*, subok=*, copy=*)
 *     cpdef ndarray copy(self, order=*)
 *     cpdef ndarray view(self, dtype=*)             # <<<<<<<<<<<<<<
 *     cpdef fill(self, value)
 *     cpdef ndarray swapaxes(self, Py_ssize_t axis1, Py_ssize_t axis2)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_view {
  int __pyx_n;
  PyObject *dtype;
};

/* "cupy/core/core.pxd":35
 *     cpdef ndarray swapaxes(self, Py_ssize_t axis1, Py_ssize_t axis2)
 *     cpdef ndarray flatten(self)
 *     cpdef ndarray ravel(self, order=*)             # <<<<<<<<<<<<<<
 *     cpdef ndarray squeeze(self, axis=*)
 *     cpdef ndarray take(self, indices, axis=*, out=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_ravel {
  int __pyx_n;
  PyObject *order;
};

/* "cupy/core/core.pxd":36
 *     cpdef ndarray flatten(self)
 *     cpdef ndarray ravel(self, order=*)
 *     cpdef ndarray squeeze(self, axis=*)             # <<<<<<<<<<<<<<
 *     cpdef ndarray take(self, indices, axis=*, out=*)
 *     cpdef put(self, indices, values, mode=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_squeeze {
  int __pyx_n;
  PyObject *axis;
};

/* "cupy/core/core.pxd":37
 *     cpdef ndarray ravel(self, order=*)
 *     cpdef ndarray squeeze(self, axis=*)
 *     cpdef ndarray take(self, indices, axis=*, out=*)             # <<<<<<<<<<<<<<
 *     cpdef put(self, indices, values, mode=*)
 *     cpdef repeat(self, repeats, axis=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_take {
  int __pyx_n;
  PyObject *axis;
  PyObject *out;
};

/* "cupy/core/core.pxd":38
 *     cpdef ndarray squeeze(self, axis=*)
 *     cpdef ndarray take(self, indices, axis=*, out=*)
 *     cpdef put(self, indices, values, mode=*)             # <<<<<<<<<<<<<<
 *     cpdef repeat(self, repeats, axis=*)
 *     cpdef choose(self, choices, out=*, mode=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_put {
  int __pyx_n;
  PyObject *mode;
};

/* "cupy/core/core.pxd":39
 *     cpdef ndarray take(self, indices, axis=*, out=*)
 *     cpdef put(self, indices, values, mode=*)
 *     cpdef repeat(self, repeats, axis=*)             # <<<<<<<<<<<<<<
 *     cpdef choose(self, choices, out=*, mode=*)
 *     cpdef sort(self, int axis=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_repeat {
  int __pyx_n;
  PyObject *axis;
};

/* "cupy/core/core.pxd":40
 *     cpdef put(self, indices, values, mode=*)
 *     cpdef repeat(self, repeats, axis=*)
 *     cpdef choose(self, choices, out=*, mode=*)             # <<<<<<<<<<<<<<
 *     cpdef sort(self, int axis=*)
 *     cpdef ndarray argsort(self, axis=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_choose {
  int __pyx_n;
  PyObject *out;
  PyObject *mode;
};

/* "cupy/core/core.pxd":41
 *     cpdef repeat(self, repeats, axis=*)
 *     cpdef choose(self, choices, out=*, mode=*)
 *     cpdef sort(self, int axis=*)             # <<<<<<<<<<<<<<
 *     cpdef ndarray argsort(self, axis=*)
 *     cpdef partition(self, kth, int axis=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_sort {
  int __pyx_n;
  int axis;
};

/* "cupy/core/core.pxd":42
 *     cpdef choose(self, choices, out=*, mode=*)
 *     cpdef sort(self, int axis=*)
 *     cpdef ndarray argsort(self, axis=*)             # <<<<<<<<<<<<<<
 *     cpdef partition(self, kth, int axis=*)
 *     cpdef ndarray argpartition(self, kth, axis=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_argsort {
  int __pyx_n;
  PyObject *axis;
};

/* "cupy/core/core.pxd":43
 *     cpdef sort(self, int axis=*)
 *     cpdef ndarray argsort(self, axis=*)
 *     cpdef partition(self, kth, int axis=*)             # <<<<<<<<<<<<<<
 *     cpdef ndarray argpartition(self, kth, axis=*)
 *     cpdef tuple nonzero(self)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_partition {
  int __pyx_n;
  int axis;
};

/* "cupy/core/core.pxd":44
 *     cpdef ndarray argsort(self, axis=*)
 *     cpdef partition(self, kth, int axis=*)
 *     cpdef ndarray argpartition(self, kth, axis=*)             # <<<<<<<<<<<<<<
 *     cpdef tuple nonzero(self)
 *     cpdef ndarray diagonal(self, offset=*, axis1=*, axis2=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_argpartition {
  int __pyx_n;
  PyObject *axis;
};

/* "cupy/core/core.pxd":46
 *     cpdef ndarray argpartition(self, kth, axis=*)
 *     cpdef tuple nonzero(self)
 *     cpdef ndarray diagonal(self, offset=*, axis1=*, axis2=*)             # <<<<<<<<<<<<<<
 *     cpdef ndarray max(self, axis=*, out=*, dtype=*, keepdims=*)
 *     cpdef ndarray argmax(self, axis=*, out=*, dtype=*,
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_diagonal {
  int __pyx_n;
  PyObject *offset;
  PyObject *axis1;
  PyObject *axis2;
};

/* "cupy/core/core.pxd":47
 *     cpdef tuple nonzero(self)
 *     cpdef ndarray diagonal(self, offset=*, axis1=*, axis2=*)
 *     cpdef ndarray max(self, axis=*, out=*, dtype=*, keepdims=*)             # <<<<<<<<<<<<<<
 *     cpdef ndarray argmax(self, axis=*, out=*, dtype=*,
 *                          keepdims=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_max {
  int __pyx_n;
  PyObject *axis;
  PyObject *out;
  PyObject *dtype;
  PyObject *keepdims;
};

/* "cupy/core/core.pxd":48
 *     cpdef ndarray diagonal(self, offset=*, axis1=*, axis2=*)
 *     cpdef ndarray max(self, axis=*, out=*, dtype=*, keepdims=*)
 *     cpdef ndarray argmax(self, axis=*, out=*, dtype=*,             # <<<<<<<<<<<<<<
 *                          keepdims=*)
 *     cpdef ndarray min(self, axis=*, out=*, dtype=*, keepdims=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_argmax {
  int __pyx_n;
  PyObject *axis;
  PyObject *out;
  PyObject *dtype;
  PyObject *keepdims;
};

/* "cupy/core/core.pxd":50
 *     cpdef ndarray argmax(self, axis=*, out=*, dtype=*,
 *                          keepdims=*)
 *     cpdef ndarray min(self, axis=*, out=*, dtype=*, keepdims=*)             # <<<<<<<<<<<<<<
 *     cpdef ndarray argmin(self, axis=*, out=*, dtype=*,
 *                          keepdims=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_min {
  int __pyx_n;
  PyObject *axis;
  PyObject *out;
  PyObject *dtype;
  PyObject *keepdims;
};

/* "cupy/core/core.pxd":51
 *                          keepdims=*)
 *     cpdef ndarray min(self, axis=*, out=*, dtype=*, keepdims=*)
 *     cpdef ndarray argmin(self, axis=*, out=*, dtype=*,             # <<<<<<<<<<<<<<
 *                          keepdims=*)
 *     cpdef ndarray clip(self, a_min=*, a_max=*, out=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_argmin {
  int __pyx_n;
  PyObject *axis;
  PyObject *out;
  PyObject *dtype;
  PyObject *keepdims;
};

/* "cupy/core/core.pxd":53
 *     cpdef ndarray argmin(self, axis=*, out=*, dtype=*,
 *                          keepdims=*)
 *     cpdef ndarray clip(self, a_min=*, a_max=*, out=*)             # <<<<<<<<<<<<<<
 *     cpdef ndarray round(self, decimals=*, out=*)
 * 
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_clip {
  int __pyx_n;
  PyObject *a_min;
  PyObject *a_max;
  PyObject *out;
};

/* "cupy/core/core.pxd":54
 *                          keepdims=*)
 *     cpdef ndarray clip(self, a_min=*, a_max=*, out=*)
 *     cpdef ndarray round(self, decimals=*, out=*)             # <<<<<<<<<<<<<<
 * 
 *     cpdef ndarray trace(self, offset=*, axis1=*, axis2=*, dtype=*,
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_round {
  int __pyx_n;
  PyObject *decimals;
  PyObject *out;
};

/* "cupy/core/core.pxd":56
 *     cpdef ndarray round(self, decimals=*, out=*)
 * 
 *     cpdef ndarray trace(self, offset=*, axis1=*, axis2=*, dtype=*,             # <<<<<<<<<<<<<<
 *                         out=*)
 *     cpdef ndarray sum(self, axis=*, dtype=*, out=*, keepdims=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_trace {
  int __pyx_n;
  PyObject *offset;
  PyObject *axis1;
  PyObject *axis2;
  PyObject *dtype;
  PyObject *out;
};

/* "cupy/core/core.pxd":58
 *     cpdef ndarray trace(self, offset=*, axis1=*, axis2=*, dtype=*,
 *                         out=*)
 *     cpdef ndarray sum(self, axis=*, dtype=*, out=*, keepdims=*)             # <<<<<<<<<<<<<<
 *     cpdef ndarray cumsum(self, axis=*, dtype=*, out=*)
 *     cpdef ndarray mean(self, axis=*, dtype=*, out=*, keepdims=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_sum {
  int __pyx_n;
  PyObject *axis;
  PyObject *dtype;
  PyObject *out;
  PyObject *keepdims;
};

/* "cupy/core/core.pxd":59
 *                         out=*)
 *     cpdef ndarray sum(self, axis=*, dtype=*, out=*, keepdims=*)
 *     cpdef ndarray cumsum(self, axis=*, dtype=*, out=*)             # <<<<<<<<<<<<<<
 *     cpdef ndarray mean(self, axis=*, dtype=*, out=*, keepdims=*)
 *     cpdef ndarray var(self, axis=*, dtype=*, out=*, ddof=*,
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_cumsum {
  int __pyx_n;
  PyObject *axis;
  PyObject *dtype;
  PyObject *out;
};

/* "cupy/core/core.pxd":60
 *     cpdef ndarray sum(self, axis=*, dtype=*, out=*, keepdims=*)
 *     cpdef ndarray cumsum(self, axis=*, dtype=*, out=*)
 *     cpdef ndarray mean(self, axis=*, dtype=*, out=*, keepdims=*)             # <<<<<<<<<<<<<<
 *     cpdef ndarray var(self, axis=*, dtype=*, out=*, ddof=*,
 *                       keepdims=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_mean {
  int __pyx_n;
  PyObject *axis;
  PyObject *dtype;
  PyObject *out;
  PyObject *keepdims;
};

/* "cupy/core/core.pxd":61
 *     cpdef ndarray cumsum(self, axis=*, dtype=*, out=*)
 *     cpdef ndarray mean(self, axis=*, dtype=*, out=*, keepdims=*)
 *     cpdef ndarray var(self, axis=*, dtype=*, out=*, ddof=*,             # <<<<<<<<<<<<<<
 *                       keepdims=*)
 *     cpdef ndarray std(self, axis=*, dtype=*, out=*, ddof=*,
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_var {
  int __pyx_n;
  PyObject *axis;
  PyObject *dtype;
  PyObject *out;
  PyObject *ddof;
  PyObject *keepdims;
};

/* "cupy/core/core.pxd":63
 *     cpdef ndarray var(self, axis=*, dtype=*, out=*, ddof=*,
 *                       keepdims=*)
 *     cpdef ndarray std(self, axis=*, dtype=*, out=*, ddof=*,             # <<<<<<<<<<<<<<
 *                       keepdims=*)
 *     cpdef ndarray prod(self, axis=*, dtype=*, out=*, keepdims=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_std {
  int __pyx_n;
  PyObject *axis;
  PyObject *dtype;
  PyObject *out;
  PyObject *ddof;
  PyObject *keepdims;
};

/* "cupy/core/core.pxd":65
 *     cpdef ndarray std(self, axis=*, dtype=*, out=*, ddof=*,
 *                       keepdims=*)
 *     cpdef ndarray prod(self, axis=*, dtype=*, out=*, keepdims=*)             # <<<<<<<<<<<<<<
 *     cpdef ndarray cumprod(self, axis=*, dtype=*, out=*)
 *     cpdef ndarray all(self, axis=*, out=*, keepdims=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_prod {
  int __pyx_n;
  PyObject *axis;
  PyObject *dtype;
  PyObject *out;
  PyObject *keepdims;
};

/* "cupy/core/core.pxd":66
 *                       keepdims=*)
 *     cpdef ndarray prod(self, axis=*, dtype=*, out=*, keepdims=*)
 *     cpdef ndarray cumprod(self, axis=*, dtype=*, out=*)             # <<<<<<<<<<<<<<
 *     cpdef ndarray all(self, axis=*, out=*, keepdims=*)
 *     cpdef ndarray any(self, axis=*, out=*, keepdims=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_cumprod {
  int __pyx_n;
  PyObject *axis;
  PyObject *dtype;
  PyObject *out;
};

/* "cupy/core/core.pxd":67
 *     cpdef ndarray prod(self, axis=*, dtype=*, out=*, keepdims=*)
 *     cpdef ndarray cumprod(self, axis=*, dtype=*, out=*)
 *     cpdef ndarray all(self, axis=*, out=*, keepdims=*)             # <<<<<<<<<<<<<<
 *     cpdef ndarray any(self, axis=*, out=*, keepdims=*)
 *     cpdef ndarray conj(self)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_all {
  int __pyx_n;
  PyObject *axis;
  PyObject *out;
  PyObject *keepdims;
};

/* "cupy/core/core.pxd":68
 *     cpdef ndarray cumprod(self, axis=*, dtype=*, out=*)
 *     cpdef ndarray all(self, axis=*, out=*, keepdims=*)
 *     cpdef ndarray any(self, axis=*, out=*, keepdims=*)             # <<<<<<<<<<<<<<
 *     cpdef ndarray conj(self)
 *     cpdef get(self, stream=*, order=*, out=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_any {
  int __pyx_n;
  PyObject *axis;
  PyObject *out;
  PyObject *keepdims;
};

/* "cupy/core/core.pxd":70
 *     cpdef ndarray any(self, axis=*, out=*, keepdims=*)
 *     cpdef ndarray conj(self)
 *     cpdef get(self, stream=*, order=*, out=*)             # <<<<<<<<<<<<<<
 *     cpdef set(self, arr, stream=*)
 *     cpdef ndarray reduced_view(self, dtype=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_get {
  int __pyx_n;
  PyObject *stream;
  PyObject *order;
  PyObject *out;
};

/* "cupy/core/core.pxd":71
 *     cpdef ndarray conj(self)
 *     cpdef get(self, stream=*, order=*, out=*)
 *     cpdef set(self, arr, stream=*)             # <<<<<<<<<<<<<<
 *     cpdef ndarray reduced_view(self, dtype=*)
 *     cpdef _update_c_contiguity(self)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_set {
  int __pyx_n;
  PyObject *stream;
};

/* "cupy/core/core.pxd":72
 *     cpdef get(self, stream=*, order=*, out=*)
 *     cpdef set(self, arr, stream=*)
 *     cpdef ndarray reduced_view(self, dtype=*)             # <<<<<<<<<<<<<<
 *     cpdef _update_c_contiguity(self)
 *     cpdef _update_f_contiguity(self)
 */
struct __pyx_opt_args_4cupy_4core_4core_7ndarray_reduced_view {
  int __pyx_n;
  PyObject *dtype;
};

/* "cupy/core/core.pxd":100
 * cpdef ndarray _internal_ascontiguousarray(ndarray a)
 * cpdef ndarray _internal_asfortranarray(ndarray a)
 * cpdef ndarray ascontiguousarray(ndarray a, dtype=*)             # <<<<<<<<<<<<<<
 * cpdef ndarray asfortranarray(ndarray a, dtype=*)
 * 
 */
struct __pyx_opt_args_4cupy_4core_4core_ascontiguousarray {
  int __pyx_n;
  PyObject *dtype;
};

/* "cupy/core/core.pxd":101
 * cpdef ndarray _internal_asfortranarray(ndarray a)
 * cpdef ndarray ascontiguousarray(ndarray a, dtype=*)
 * cpdef ndarray asfortranarray(ndarray a, dtype=*)             # <<<<<<<<<<<<<<
 * 
 * cpdef Module compile_with_cache(str source, tuple options=*, arch=*,
 */
struct __pyx_opt_args_4cupy_4core_4core_asfortranarray {
  int __pyx_n;
  PyObject *dtype;
};

/* "cupy/core/core.pxd":103
 * cpdef ndarray asfortranarray(ndarray a, dtype=*)
 * 
 * cpdef Module compile_with_cache(str source, tuple options=*, arch=*,             # <<<<<<<<<<<<<<
 *                                 cachd_dir=*, prepend_cupy_headers=*,
 *                                 backend=*, translate_cucomplex=*)
 */
struct __pyx_opt_args_4cupy_4core_4core_compile_with_cache {
  int __pyx_n;
  PyObject *options;
  PyObject *arch;
  PyObject *cachd_dir;
  PyObject *prepend_cupy_headers;
  PyObject *backend;
  PyObject *translate_cucomplex;
};

/* "cupy/core/core.pxd":109
 * 
 * # TODO(niboshi): Move to _routines_creation.pyx
 * cpdef ndarray array(obj, dtype=*, bint copy=*, order=*, bint subok=*,             # <<<<<<<<<<<<<<
 *                     Py_ssize_t ndmin=*)
 * cpdef ndarray _convert_object_with_cuda_array_interface(a)
 */
struct __pyx_opt_args_4cupy_4core_4core_array {
  int __pyx_n;
  PyObject *dtype;
  int copy;
  PyObject *order;
  int subok;
  Py_ssize_t ndmin;
};
struct __pyx_opt_args_4cupy_4core_14_routines_math_scan;

/* "_routines_math.pxd":18
 * cpdef ndarray _nanprod(ndarray a, axis, dtype, out, keepdims)
 * 
 * cdef ndarray scan(ndarray a, ndarray out=*)             # <<<<<<<<<<<<<<
 * cdef object _sum_auto_dtype
 * cdef object _add
 */
struct __pyx_opt_args_4cupy_4core_14_routines_math_scan {
  int __pyx_n;
  struct __pyx_obj_4cupy_4core_4core_ndarray *out;
};
struct __pyx_opt_args_4cupy_4core_22_routines_manipulation_rollaxis;

/* "_routines_manipulation.pxd":25
 * 
 * cpdef ndarray moveaxis(ndarray a, source, destination)
 * cpdef ndarray rollaxis(ndarray a, Py_ssize_t axis, Py_ssize_t start=*)             # <<<<<<<<<<<<<<
 * cpdef ndarray broadcast_to(ndarray array, shape)
 * cpdef ndarray _reshape(ndarray self,
 */
struct __pyx_opt_args_4cupy_4core_22_routines_manipulation_rollaxis {
  int __pyx_n;
  Py_ssize_t start;
};
struct __pyx_opt_args_4cupy_4core_8internal__normalize_order;

/* "internal.pxd":49
 * cpdef float from_float16(uint16_t v)
 * 
 * cdef int _normalize_order(order, cpp_bool allow_k=*) except? 0             # <<<<<<<<<<<<<<
 * 
 * cpdef bint _contig_axes(tuple axes)
 */
struct __pyx_opt_args_4cupy_4core_8internal__normalize_order {
  int __pyx_n;
  bool allow_k;
};
struct __pyx_opt_args_4cupy_4core_18_routines_indexing__take;
struct __pyx_opt_args_4cupy_4core_18_routines_indexing__scatter_op_single;
struct __pyx_opt_args_4cupy_4core_18_routines_indexing__diagonal;

/* "cupy/core/_routines_indexing.pyx":594
 * 
 * 
 * cdef ndarray _take(ndarray a, indices, int li, int ri, ndarray out=None):             # <<<<<<<<<<<<<<
 *     # When li + 1 == ri this function behaves similarly to np.take
 *     cdef tuple out_shape, ind_shape, indices_shape
 */
struct __pyx_opt_args_4cupy_4core_18_routines_indexing__take {
  int __pyx_n;
  struct __pyx_obj_4cupy_4core_4core_ndarray *out;
};

/* "cupy/core/_routines_indexing.pyx":658
 * 
 * cdef _scatter_op_single(
 *         ndarray a, ndarray indices, v, Py_ssize_t li=0, Py_ssize_t ri=0,             # <<<<<<<<<<<<<<
 *         op=''):
 *     # When op == 'update', this function behaves similarly to
 */
struct __pyx_opt_args_4cupy_4core_18_routines_indexing__scatter_op_single {
  int __pyx_n;
  Py_ssize_t li;
  Py_ssize_t ri;
  PyObject *op;
};

/* "cupy/core/_routines_indexing.pyx":825
 * 
 * 
 * cdef ndarray _diagonal(             # <<<<<<<<<<<<<<
 *         ndarray a, Py_ssize_t offset=0, Py_ssize_t axis1=0,
 *         Py_ssize_t axis2=1):
 */
struct __pyx_opt_args_4cupy_4core_18_routines_indexing__diagonal {
  int __pyx_n;
  Py_ssize_t offset;
  Py_ssize_t axis1;
  Py_ssize_t axis2;
};

/* "device.pxd":7
 * cpdef str get_compute_capability()
 * 
 * cdef class Handle:             # <<<<<<<<<<<<<<
 *     cdef:
 *         public size_t handle
 */
struct __pyx_obj_4cupy_4cuda_6device_Handle {
  PyObject_HEAD
  size_t handle;
  PyObject *_destroy_func;
};


/* "device.pxd":12
 *         object _destroy_func
 * 
 * cdef class Device:             # <<<<<<<<<<<<<<
 *     cdef:
 *         public int id
 */
struct __pyx_obj_4cupy_4cuda_6device_Device {
  PyObject_HEAD
  struct __pyx_vtabstruct_4cupy_4cuda_6device_Device *__pyx_vtab;
  int id;
  PyObject *_device_stack;
};


/* "memory.pxd":11
 * 
 * @cython.no_gc
 * cdef class BaseMemory:             # <<<<<<<<<<<<<<
 * 
 *     cdef:
 */
struct __pyx_obj_4cupy_4cuda_6memory_BaseMemory {
  PyObject_HEAD
  intptr_t ptr;
  size_t size;
  int device_id;
};


/* "memory.pxd":20
 * 
 * @cython.final
 * cdef class MemoryPointer:             # <<<<<<<<<<<<<<
 * 
 *     cdef:
 */
struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer {
  PyObject_HEAD
  struct __pyx_vtabstruct_4cupy_4cuda_6memory_MemoryPointer *__pyx_vtab;
  intptr_t ptr;
  int device_id;
  struct __pyx_obj_4cupy_4cuda_6memory_BaseMemory *mem;
};


/* "memory.pxd":49
 * 
 * 
 * cdef class MemoryPool:             # <<<<<<<<<<<<<<
 * 
 *     cdef:
 */
struct __pyx_obj_4cupy_4cuda_6memory_MemoryPool {
  PyObject_HEAD
  struct __pyx_vtabstruct_4cupy_4cuda_6memory_MemoryPool *__pyx_vtab;
  PyObject *_pools;
};


/* "memory.pxd":66
 * 
 * @cython.no_gc
 * cdef class CFunctionAllocatorMemory(BaseMemory):             # <<<<<<<<<<<<<<
 * 
 *     cdef:
 */
struct __pyx_obj_4cupy_4cuda_6memory_CFunctionAllocatorMemory {
  struct __pyx_obj_4cupy_4cuda_6memory_BaseMemory __pyx_base;
  intptr_t _param;
  intptr_t _free_func;
};


/* "memory.pxd":73
 * 
 * 
 * cdef class CFunctionAllocator:             # <<<<<<<<<<<<<<
 * 
 *     cdef:
 */
struct __pyx_obj_4cupy_4cuda_6memory_CFunctionAllocator {
  PyObject_HEAD
  struct __pyx_vtabstruct_4cupy_4cuda_6memory_CFunctionAllocator *__pyx_vtab;
  intptr_t _param;
  intptr_t _malloc_func;
  intptr_t _free_func;
  PyObject *_owner;
};


/* "cupy/cuda/function.pxd":4
 * 
 * 
 * cdef class CPointer:             # <<<<<<<<<<<<<<
 *     cdef void* ptr
 * 
 */
struct __pyx_obj_4cupy_4cuda_8function_CPointer {
  PyObject_HEAD
  void *ptr;
};


/* "cupy/cuda/function.pxd":8
 * 
 * 
 * cdef class Function:             # <<<<<<<<<<<<<<
 * 
 *     cdef:
 */
struct __pyx_obj_4cupy_4cuda_8function_Function {
  PyObject_HEAD
  struct __pyx_vtabstruct_4cupy_4cuda_8function_Function *__pyx_vtab;
  struct __pyx_obj_4cupy_4cuda_8function_Module *module;
  intptr_t ptr;
};


/* "cupy/cuda/function.pxd":18
 * 
 * 
 * cdef class Module:             # <<<<<<<<<<<<<<
 * 
 *     cdef:
 */
struct __pyx_obj_4cupy_4cuda_8function_Module {
  PyObject_HEAD
  struct __pyx_vtabstruct_4cupy_4cuda_8function_Module *__pyx_vtab;
  intptr_t ptr;
};


/* "cupy/cuda/function.pxd":30
 * 
 * 
 * cdef class LinkState:             # <<<<<<<<<<<<<<
 * 
 *     cdef:
 */
struct __pyx_obj_4cupy_4cuda_8function_LinkState {
  PyObject_HEAD
  struct __pyx_vtabstruct_4cupy_4cuda_8function_LinkState *__pyx_vtab;
  intptr_t ptr;
};


/* "cupy/core/core.pxd":7
 * from cupy.cuda.function cimport Module
 * 
 * cdef class ndarray:             # <<<<<<<<<<<<<<
 *     cdef:
 *         object __weakref__
 */
struct __pyx_obj_4cupy_4core_4core_ndarray {
  PyObject_HEAD
  struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *__pyx_vtab;
  PyObject *__weakref__;
  Py_ssize_t size;
  std::vector<Py_ssize_t>  _shape;
  std::vector<Py_ssize_t>  _strides;
  int _c_contiguous;
  int _f_contiguous;
  PyObject *dtype;
  struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer *data;
  struct __pyx_obj_4cupy_4core_4core_ndarray *base;
};


/* "cupy/core/core.pxd":90
 * 
 * 
 * cdef class Indexer:             # <<<<<<<<<<<<<<
 *     cdef:
 *         readonly Py_ssize_t size
 */
struct __pyx_obj_4cupy_4core_4core_Indexer {
  PyObject_HEAD
  struct __pyx_vtabstruct_4cupy_4core_4core_Indexer *__pyx_vtab;
  Py_ssize_t size;
  PyObject *shape;
};


/* "_routines_manipulation.pxd":6
 * 
 * 
 * cdef class broadcast:             # <<<<<<<<<<<<<<
 *     cdef:
 *         readonly tuple values
 */
struct __pyx_obj_4cupy_4core_22_routines_manipulation_broadcast {
  PyObject_HEAD
  PyObject *values;
  PyObject *shape;
  Py_ssize_t size;
  Py_ssize_t nd;
};



/* "device.pxd":12
 *         object _destroy_func
 * 
 * cdef class Device:             # <<<<<<<<<<<<<<
 *     cdef:
 *         public int id
 */

struct __pyx_vtabstruct_4cupy_4cuda_6device_Device {
  PyObject *(*use)(struct __pyx_obj_4cupy_4cuda_6device_Device *, int __pyx_skip_dispatch);
  PyObject *(*synchronize)(struct __pyx_obj_4cupy_4cuda_6device_Device *, int __pyx_skip_dispatch);
};
static struct __pyx_vtabstruct_4cupy_4cuda_6device_Device *__pyx_vtabptr_4cupy_4cuda_6device_Device;


/* "memory.pxd":20
 * 
 * @cython.final
 * cdef class MemoryPointer:             # <<<<<<<<<<<<<<
 * 
 *     cdef:
 */

struct __pyx_vtabstruct_4cupy_4cuda_6memory_MemoryPointer {
  PyObject *(*_init)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer *, struct __pyx_obj_4cupy_4cuda_6memory_BaseMemory *, ptrdiff_t);
  PyObject *(*copy_from_device)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer *, struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer *, size_t, int __pyx_skip_dispatch);
  PyObject *(*copy_from_device_async)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer *, struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer *, size_t, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4cuda_6memory_13MemoryPointer_copy_from_device_async *__pyx_optional_args);
  PyObject *(*copy_from_host)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer *, PyObject *, size_t, int __pyx_skip_dispatch);
  PyObject *(*copy_from_host_async)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer *, PyObject *, size_t, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4cuda_6memory_13MemoryPointer_copy_from_host_async *__pyx_optional_args);
  PyObject *(*copy_from)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer *, PyObject *, size_t, int __pyx_skip_dispatch);
  PyObject *(*copy_from_async)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer *, PyObject *, size_t, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4cuda_6memory_13MemoryPointer_copy_from_async *__pyx_optional_args);
  PyObject *(*copy_to_host)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer *, PyObject *, size_t, int __pyx_skip_dispatch);
  PyObject *(*copy_to_host_async)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer *, PyObject *, size_t, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4cuda_6memory_13MemoryPointer_copy_to_host_async *__pyx_optional_args);
  PyObject *(*memset)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer *, int, size_t, int __pyx_skip_dispatch);
  PyObject *(*memset_async)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer *, int, size_t, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4cuda_6memory_13MemoryPointer_memset_async *__pyx_optional_args);
};
static struct __pyx_vtabstruct_4cupy_4cuda_6memory_MemoryPointer *__pyx_vtabptr_4cupy_4cuda_6memory_MemoryPointer;


/* "memory.pxd":49
 * 
 * 
 * cdef class MemoryPool:             # <<<<<<<<<<<<<<
 * 
 *     cdef:
 */

struct __pyx_vtabstruct_4cupy_4cuda_6memory_MemoryPool {
  struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer *(*malloc)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPool *, size_t, int __pyx_skip_dispatch);
  PyObject *(*free_all_blocks)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPool *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4cuda_6memory_10MemoryPool_free_all_blocks *__pyx_optional_args);
  PyObject *(*free_all_free)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPool *, int __pyx_skip_dispatch);
  size_t (*n_free_blocks)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPool *, int __pyx_skip_dispatch);
  size_t (*used_bytes)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPool *, int __pyx_skip_dispatch);
  size_t (*free_bytes)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPool *, int __pyx_skip_dispatch);
  size_t (*total_bytes)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPool *, int __pyx_skip_dispatch);
  PyObject *(*set_limit)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPool *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4cuda_6memory_10MemoryPool_set_limit *__pyx_optional_args);
  size_t (*get_limit)(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPool *, int __pyx_skip_dispatch);
};
static struct __pyx_vtabstruct_4cupy_4cuda_6memory_MemoryPool *__pyx_vtabptr_4cupy_4cuda_6memory_MemoryPool;


/* "memory.pxd":73
 * 
 * 
 * cdef class CFunctionAllocator:             # <<<<<<<<<<<<<<
 * 
 *     cdef:
 */

struct __pyx_vtabstruct_4cupy_4cuda_6memory_CFunctionAllocator {
  struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer *(*malloc)(struct __pyx_obj_4cupy_4cuda_6memory_CFunctionAllocator *, size_t, int __pyx_skip_dispatch);
};
static struct __pyx_vtabstruct_4cupy_4cuda_6memory_CFunctionAllocator *__pyx_vtabptr_4cupy_4cuda_6memory_CFunctionAllocator;


/* "cupy/cuda/function.pxd":8
 * 
 * 
 * cdef class Function:             # <<<<<<<<<<<<<<
 * 
 *     cdef:
 */

struct __pyx_vtabstruct_4cupy_4cuda_8function_Function {
  PyObject *(*linear_launch)(struct __pyx_obj_4cupy_4cuda_8function_Function *, size_t, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4cuda_8function_8Function_linear_launch *__pyx_optional_args);
};
static struct __pyx_vtabstruct_4cupy_4cuda_8function_Function *__pyx_vtabptr_4cupy_4cuda_8function_Function;


/* "cupy/cuda/function.pxd":18
 * 
 * 
 * cdef class Module:             # <<<<<<<<<<<<<<
 * 
 *     cdef:
 */

struct __pyx_vtabstruct_4cupy_4cuda_8function_Module {
  PyObject *(*load_file)(struct __pyx_obj_4cupy_4cuda_8function_Module *, PyObject *, int __pyx_skip_dispatch);
  PyObject *(*load)(struct __pyx_obj_4cupy_4cuda_8function_Module *, PyObject *, int __pyx_skip_dispatch);
  PyObject *(*get_global_var)(struct __pyx_obj_4cupy_4cuda_8function_Module *, PyObject *, int __pyx_skip_dispatch);
  PyObject *(*get_function)(struct __pyx_obj_4cupy_4cuda_8function_Module *, PyObject *, int __pyx_skip_dispatch);
  PyObject *(*get_texref)(struct __pyx_obj_4cupy_4cuda_8function_Module *, PyObject *, int __pyx_skip_dispatch);
};
static struct __pyx_vtabstruct_4cupy_4cuda_8function_Module *__pyx_vtabptr_4cupy_4cuda_8function_Module;


/* "cupy/cuda/function.pxd":30
 * 
 * 
 * cdef class LinkState:             # <<<<<<<<<<<<<<
 * 
 *     cdef:
 */

struct __pyx_vtabstruct_4cupy_4cuda_8function_LinkState {
  PyObject *(*add_ptr_data)(struct __pyx_obj_4cupy_4cuda_8function_LinkState *, PyObject *, PyObject *, int __pyx_skip_dispatch);
  PyObject *(*add_ptr_file)(struct __pyx_obj_4cupy_4cuda_8function_LinkState *, PyObject *, int __pyx_skip_dispatch);
  PyObject *(*complete)(struct __pyx_obj_4cupy_4cuda_8function_LinkState *, int __pyx_skip_dispatch);
};
static struct __pyx_vtabstruct_4cupy_4cuda_8function_LinkState *__pyx_vtabptr_4cupy_4cuda_8function_LinkState;


/* "cupy/core/core.pxd":7
 * from cupy.cuda.function cimport Module
 * 
 * cdef class ndarray:             # <<<<<<<<<<<<<<
 *     cdef:
 *         object __weakref__
 */

struct __pyx_vtabstruct_4cupy_4core_4core_ndarray {
  PyObject *(*_init_fast)(struct __pyx_obj_4cupy_4core_4core_ndarray *, std::vector<Py_ssize_t>  const &, PyObject *, int);
  PyObject *(*item)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch);
  PyObject *(*tolist)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch);
  PyObject *(*tobytes)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_tobytes *__pyx_optional_args);
  PyObject *(*tofile)(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_tofile *__pyx_optional_args);
  PyObject *(*dump)(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, int __pyx_skip_dispatch);
  PyObject *(*dumps)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*astype)(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_astype *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*copy)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_copy *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*view)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_view *__pyx_optional_args);
  PyObject *(*fill)(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, int __pyx_skip_dispatch);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*swapaxes)(struct __pyx_obj_4cupy_4core_4core_ndarray *, Py_ssize_t, Py_ssize_t, int __pyx_skip_dispatch);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*flatten)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*ravel)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_ravel *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*squeeze)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_squeeze *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*take)(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_take *__pyx_optional_args);
  PyObject *(*put)(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_put *__pyx_optional_args);
  PyObject *(*repeat)(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_repeat *__pyx_optional_args);
  PyObject *(*choose)(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_choose *__pyx_optional_args);
  PyObject *(*sort)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_sort *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*argsort)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_argsort *__pyx_optional_args);
  PyObject *(*partition)(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_partition *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*argpartition)(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_argpartition *__pyx_optional_args);
  PyObject *(*nonzero)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*diagonal)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_diagonal *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*max)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_max *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*argmax)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_argmax *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*min)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_min *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*argmin)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_argmin *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*clip)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_clip *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*round)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_round *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*trace)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_trace *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*sum)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_sum *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*cumsum)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_cumsum *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*mean)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_mean *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*var)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_var *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*std)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_std *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*prod)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_prod *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*cumprod)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_cumprod *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*all)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_all *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*any)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_any *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*conj)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch);
  PyObject *(*get)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_get *__pyx_optional_args);
  PyObject *(*set)(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_set *__pyx_optional_args);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*reduced_view)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_7ndarray_reduced_view *__pyx_optional_args);
  PyObject *(*_update_c_contiguity)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch);
  PyObject *(*_update_f_contiguity)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch);
  PyObject *(*_update_contiguity)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch);
  PyObject *(*_set_shape_and_strides)(struct __pyx_obj_4cupy_4core_4core_ndarray *, std::vector<Py_ssize_t>  const &, std::vector<Py_ssize_t>  const &, int, int, int __pyx_skip_dispatch);
  struct __pyx_obj_4cupy_4core_4core_ndarray *(*_view)(struct __pyx_obj_4cupy_4core_4core_ndarray *, std::vector<Py_ssize_t>  const &, std::vector<Py_ssize_t>  const &, int, int);
  PyObject *(*_set_contiguous_strides)(struct __pyx_obj_4cupy_4core_4core_ndarray *, Py_ssize_t, int, int __pyx_skip_dispatch);
  struct __pyx_obj_4cupy_4cuda_8function_CPointer *(*get_pointer)(struct __pyx_obj_4cupy_4core_4core_ndarray *);
  PyObject *(*toDlpack)(struct __pyx_obj_4cupy_4core_4core_ndarray *, int __pyx_skip_dispatch);
};
static struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *__pyx_vtabptr_4cupy_4core_4core_ndarray;


/* "cupy/core/core.pxd":90
 * 
 * 
 * cdef class Indexer:             # <<<<<<<<<<<<<<
 *     cdef:
 *         readonly Py_ssize_t size
 */

struct __pyx_vtabstruct_4cupy_4core_4core_Indexer {
  struct __pyx_obj_4cupy_4cuda_8function_CPointer *(*get_pointer)(struct __pyx_obj_4cupy_4core_4core_Indexer *);
};
static struct __pyx_vtabstruct_4cupy_4core_4core_Indexer *__pyx_vtabptr_4cupy_4core_4core_Indexer;

/* --- 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);
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif

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

/* RaiseTooManyValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

/* RaiseNeedMoreValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

/* RaiseNoneIterError.proto */
static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);

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

/* ExtTypeTest.proto */
static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type);

/* PyIntCompare.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, long inplace);

/* PyCFunctionFastCall.proto */
#if CYTHON_FAST_PYCCALL
static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
#else
#define __Pyx_PyCFunction_FastCall(func, args, nargs)  (assert(0), NULL)
#endif

/* PyFunctionFastCall.proto */
#if CYTHON_FAST_PYCALL
#define __Pyx_PyFunction_FastCall(func, args, nargs)\
    __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs);
#else
#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
#endif
#define __Pyx_BUILD_ASSERT_EXPR(cond)\
    (sizeof(char [1 - 2*!(cond)]) - 1)
#ifndef Py_MEMBER_SIZE
#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member)
#endif
  static size_t __pyx_pyframe_localsplus_offset = 0;
  #include "frameobject.h"
  #define __Pxy_PyFrame_Initialize_Offsets()\
    ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\
     (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus)))
  #define __Pyx_PyFrame_GetLocalsplus(frame)\
    (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset))
#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

/* PyObjectCallMethO.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
#endif

/* PyObjectCallOneArg.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);

/* UnpackUnboundCMethod.proto */
typedef struct {
    PyObject *type;
    PyObject **method_name;
    PyCFunction func;
    PyObject *method;
    int flag;
} __Pyx_CachedCFunction;

/* CallUnboundCMethod1.proto */
static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg);
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg);
#else
#define __Pyx_CallUnboundCMethod1(cfunc, self, arg)  __Pyx__CallUnboundCMethod1(cfunc, self, arg)
#endif

/* ObjectGetItem.proto */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key);
#else
#define __Pyx_PyObject_GetItem(obj, key)  PyObject_GetItem(obj, key)
#endif

/* PyDictVersioning.proto */
#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
#define __PYX_DICT_VERSION_INIT  ((PY_UINT64_T) -1)
#define __PYX_GET_DICT_VERSION(dict)  (((PyDictObject*)(dict))->ma_version_tag)
#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\
    (version_var) = __PYX_GET_DICT_VERSION(dict);\
    (cache_var) = (value);
#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\
    static PY_UINT64_T __pyx_dict_version = 0;\
    static PyObject *__pyx_dict_cached_value = NULL;\
    if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\
        (VAR) = __pyx_dict_cached_value;\
    } else {\
        (VAR) = __pyx_dict_cached_value = (LOOKUP);\
        __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\
    }\
}
static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj);
static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj);
static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version);
#else
#define __PYX_GET_DICT_VERSION(dict)  (0)
#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)
#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP)  (VAR) = (LOOKUP);
#endif

/* GetModuleGlobalName.proto */
#if CYTHON_USE_DICT_VERSIONS
#define __Pyx_GetModuleGlobalName(var, name)  {\
    static PY_UINT64_T __pyx_dict_version = 0;\
    static PyObject *__pyx_dict_cached_value = NULL;\
    (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\
        (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\
        __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
}
#define __Pyx_GetModuleGlobalNameUncached(var, name)  {\
    PY_UINT64_T __pyx_dict_version;\
    PyObject *__pyx_dict_cached_value;\
    (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\
}
static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value);
#else
#define __Pyx_GetModuleGlobalName(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
#define __Pyx_GetModuleGlobalNameUncached(var, name)  (var) = __Pyx__GetModuleGlobalName(name)
static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name);
#endif

/* None.proto */
static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname);

/* 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);
#else
#define __Pyx_PyObject_DelAttrStr(o,n)   PyObject_DelAttr(o,n)
#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v)
#endif

/* ListCompAppend.proto */
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) {
    PyListObject* L = (PyListObject*) list;
    Py_ssize_t len = Py_SIZE(list);
    if (likely(L->allocated > len)) {
        Py_INCREF(x);
        PyList_SET_ITEM(list, len, x);
        __Pyx_SET_SIZE(list, len + 1);
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x)
#endif

/* IncludeStringH.proto */
#include <string.h>

/* BytesEquals.proto */
static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals);

/* UnicodeEquals.proto */
static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals);

/* PyThreadStateGet.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyThreadState_declare  PyThreadState *__pyx_tstate;
#define __Pyx_PyThreadState_assign  __pyx_tstate = __Pyx_PyThreadState_Current;
#define __Pyx_PyErr_Occurred()  __pyx_tstate->curexc_type
#else
#define __Pyx_PyThreadState_declare
#define __Pyx_PyThreadState_assign
#define __Pyx_PyErr_Occurred()  PyErr_Occurred()
#endif

/* PyErrFetchRestore.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL)
#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);
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL))
#else
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#endif
#else
#define __Pyx_PyErr_Clear() PyErr_Clear()
#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc)
#define __Pyx_ErrRestoreWithState(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestoreInState(tstate, type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchInState(tstate, 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);

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

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_SubtractObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2))
#endif

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check);
#else
#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace, zerodivision_check)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

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

/* PyObjectCall2Args.proto */
static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2);

/* UnicodeAsUCS4.proto */
static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject*);

/* object_ord.proto */
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyObject_Ord(c)\
    (likely(PyUnicode_Check(c)) ? (long)__Pyx_PyUnicode_AsPy_UCS4(c) : __Pyx__PyObject_Ord(c))
#else
#define __Pyx_PyObject_Ord(c) __Pyx__PyObject_Ord(c)
#endif
static long __Pyx__PyObject_Ord(PyObject* c);

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

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

/* RaiseDoubleKeywords.proto */
static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);

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

/* ListAppend.proto */
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
static CYTHON_INLINE int __Pyx_PyList_Append(PyObject* list, PyObject* x) {
    PyListObject* L = (PyListObject*) list;
    Py_ssize_t len = Py_SIZE(list);
    if (likely(L->allocated > len) & likely(len > (L->allocated >> 1))) {
        Py_INCREF(x);
        PyList_SET_ITEM(list, len, x);
        __Pyx_SET_SIZE(list, len + 1);
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_PyList_Append(L,x) PyList_Append(L,x)
#endif

/* None.proto */
static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t, Py_ssize_t);

/* UnaryNegOverflows.proto */
#define UNARY_NEG_WOULD_OVERFLOW(x)\
        (((x) < 0) & ((unsigned long)(x) == 0-(unsigned long)(x)))

/* PyObjectFormatAndDecref.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f);
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f);

/* BuildPyUnicode.proto */
static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength,
                                                int prepend_sign, char padding_char);

/* CIntToPyUnicode.proto */
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_Py_ssize_t(Py_ssize_t value, Py_ssize_t width, char padding_char, char format_char);

/* JoinPyUnicode.proto */
static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength,
                                      Py_UCS4 max_char);

/* ArgTypeTest.proto */
#define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\
    ((likely((Py_TYPE(obj) == type) | (none_allowed && (obj == Py_None)))) ? 1 :\
        __Pyx__ArgTypeTest(obj, type, name, exact))
static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact);

/* IterFinish.proto */
static CYTHON_INLINE int __Pyx_IterFinish(void);

/* UnpackItemEndCheck.proto */
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected);

/* None.proto */
static CYTHON_INLINE int __Pyx_mod_int(int, int);

/* None.proto */
static CYTHON_INLINE Py_ssize_t __Pyx_mod_Py_ssize_t(Py_ssize_t, Py_ssize_t);

/* SliceTupleAndList.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop);
static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop);
#else
#define __Pyx_PyList_GetSlice(seq, start, stop)   PySequence_GetSlice(seq, start, stop)
#define __Pyx_PyTuple_GetSlice(seq, start, stop)  PySequence_GetSlice(seq, start, stop)
#endif

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

/* PyIntCompare.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_NeObjC(PyObject *op1, PyObject *op2, long intval, long inplace);

/* TypeImport.proto */
#ifndef __PYX_HAVE_RT_ImportType_proto
#define __PYX_HAVE_RT_ImportType_proto
enum __Pyx_ImportType_CheckSize {
   __Pyx_ImportType_CheckSize_Error = 0,
   __Pyx_ImportType_CheckSize_Warn = 1,
   __Pyx_ImportType_CheckSize_Ignore = 2
};
static PyTypeObject *__Pyx_ImportType(PyObject* module, const char *module_name, const char *class_name, size_t size, enum __Pyx_ImportType_CheckSize check_size);
#endif

/* GetVTable.proto */
static void* __Pyx_GetVtable(PyObject *dict);

/* Import.proto */
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);

/* ImportFrom.proto */
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);

/* CLineInTraceback.proto */
#ifdef CYTHON_CLINE_IN_TRACEBACK
#define __Pyx_CLineForTraceback(tstate, c_line)  (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0)
#else
static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
#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_long(long value);

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

/* CppExceptionConversion.proto */
#ifndef __Pyx_CppExn2PyErr
#include <new>
#include <typeinfo>
#include <stdexcept>
#include <ios>
static void __Pyx_CppExn2PyErr() {
  try {
    if (PyErr_Occurred())
      ; // let the latest Python exn pass through and ignore the current one
    else
      throw;
  } catch (const std::bad_alloc& exn) {
    PyErr_SetString(PyExc_MemoryError, exn.what());
  } catch (const std::bad_cast& exn) {
    PyErr_SetString(PyExc_TypeError, exn.what());
  } catch (const std::bad_typeid& exn) {
    PyErr_SetString(PyExc_TypeError, exn.what());
  } catch (const std::domain_error& exn) {
    PyErr_SetString(PyExc_ValueError, exn.what());
  } catch (const std::invalid_argument& exn) {
    PyErr_SetString(PyExc_ValueError, exn.what());
  } catch (const std::ios_base::failure& exn) {
    PyErr_SetString(PyExc_IOError, exn.what());
  } catch (const std::out_of_range& exn) {
    PyErr_SetString(PyExc_IndexError, exn.what());
  } catch (const std::overflow_error& exn) {
    PyErr_SetString(PyExc_OverflowError, exn.what());
  } catch (const std::range_error& exn) {
    PyErr_SetString(PyExc_ArithmeticError, exn.what());
  } catch (const std::underflow_error& exn) {
    PyErr_SetString(PyExc_ArithmeticError, exn.what());
  } catch (const std::exception& exn) {
    PyErr_SetString(PyExc_RuntimeError, exn.what());
  }
  catch (...)
  {
    PyErr_SetString(PyExc_RuntimeError, "Unknown exception");
  }
}
#endif

/* None.proto */
#include <new>

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

/* CIntFromPy.proto */
static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *);

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

/* FastTypeChecks.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b);
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type);
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2);
#else
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type)
#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2))
#endif
#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)

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

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

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

/* FunctionImport.proto */
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig);

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


/* Module declarations from 'libcpp' */

/* Module declarations from 'libcpp.vector' */

/* Module declarations from 'cupy.cuda' */

/* Module declarations from 'cython' */

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

/* Module declarations from 'libcpp.utility' */

/* Module declarations from 'libcpp.map' */

/* Module declarations from 'cupy.cuda.device' */
static PyTypeObject *__pyx_ptype_4cupy_4cuda_6device_Handle = 0;
static PyTypeObject *__pyx_ptype_4cupy_4cuda_6device_Device = 0;

/* Module declarations from 'cupy.cuda.memory' */
static PyTypeObject *__pyx_ptype_4cupy_4cuda_6memory_BaseMemory = 0;
static PyTypeObject *__pyx_ptype_4cupy_4cuda_6memory_MemoryPointer = 0;
static PyTypeObject *__pyx_ptype_4cupy_4cuda_6memory_MemoryPool = 0;
static PyTypeObject *__pyx_ptype_4cupy_4cuda_6memory_CFunctionAllocatorMemory = 0;
static PyTypeObject *__pyx_ptype_4cupy_4cuda_6memory_CFunctionAllocator = 0;

/* Module declarations from 'cupy.cuda.function' */
static PyTypeObject *__pyx_ptype_4cupy_4cuda_8function_CPointer = 0;
static PyTypeObject *__pyx_ptype_4cupy_4cuda_8function_Function = 0;
static PyTypeObject *__pyx_ptype_4cupy_4cuda_8function_Module = 0;
static PyTypeObject *__pyx_ptype_4cupy_4cuda_8function_LinkState = 0;

/* Module declarations from 'cupy.core.core' */
static PyTypeObject *__pyx_ptype_4cupy_4core_4core_ndarray = 0;
static PyTypeObject *__pyx_ptype_4cupy_4core_4core_Indexer = 0;
static struct __pyx_obj_4cupy_4core_4core_ndarray *(*__pyx_f_4cupy_4core_4core_array)(PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_array *__pyx_optional_args); /*proto*/

/* Module declarations from 'cupy.core' */

/* Module declarations from 'cupy.core._routines_math' */
static PyObject **__pyx_vp_4cupy_4core_14_routines_math__sum_auto_dtype = 0;
#define __pyx_v_4cupy_4core_14_routines_math__sum_auto_dtype (*__pyx_vp_4cupy_4core_14_routines_math__sum_auto_dtype)
static PyObject **__pyx_vp_4cupy_4core_14_routines_math__add = 0;
#define __pyx_v_4cupy_4core_14_routines_math__add (*__pyx_vp_4cupy_4core_14_routines_math__add)
static PyObject **__pyx_vp_4cupy_4core_14_routines_math__conj = 0;
#define __pyx_v_4cupy_4core_14_routines_math__conj (*__pyx_vp_4cupy_4core_14_routines_math__conj)
static PyObject **__pyx_vp_4cupy_4core_14_routines_math__angle = 0;
#define __pyx_v_4cupy_4core_14_routines_math__angle (*__pyx_vp_4cupy_4core_14_routines_math__angle)
static PyObject **__pyx_vp_4cupy_4core_14_routines_math__real = 0;
#define __pyx_v_4cupy_4core_14_routines_math__real (*__pyx_vp_4cupy_4core_14_routines_math__real)
static PyObject **__pyx_vp_4cupy_4core_14_routines_math__imag = 0;
#define __pyx_v_4cupy_4core_14_routines_math__imag (*__pyx_vp_4cupy_4core_14_routines_math__imag)
static PyObject **__pyx_vp_4cupy_4core_14_routines_math__negative = 0;
#define __pyx_v_4cupy_4core_14_routines_math__negative (*__pyx_vp_4cupy_4core_14_routines_math__negative)
static PyObject **__pyx_vp_4cupy_4core_14_routines_math__multiply = 0;
#define __pyx_v_4cupy_4core_14_routines_math__multiply (*__pyx_vp_4cupy_4core_14_routines_math__multiply)
static PyObject **__pyx_vp_4cupy_4core_14_routines_math__divide = 0;
#define __pyx_v_4cupy_4core_14_routines_math__divide (*__pyx_vp_4cupy_4core_14_routines_math__divide)
static PyObject **__pyx_vp_4cupy_4core_14_routines_math__power = 0;
#define __pyx_v_4cupy_4core_14_routines_math__power (*__pyx_vp_4cupy_4core_14_routines_math__power)
static PyObject **__pyx_vp_4cupy_4core_14_routines_math__subtract = 0;
#define __pyx_v_4cupy_4core_14_routines_math__subtract (*__pyx_vp_4cupy_4core_14_routines_math__subtract)
static PyObject **__pyx_vp_4cupy_4core_14_routines_math__true_divide = 0;
#define __pyx_v_4cupy_4core_14_routines_math__true_divide (*__pyx_vp_4cupy_4core_14_routines_math__true_divide)
static PyObject **__pyx_vp_4cupy_4core_14_routines_math__floor_divide = 0;
#define __pyx_v_4cupy_4core_14_routines_math__floor_divide (*__pyx_vp_4cupy_4core_14_routines_math__floor_divide)
static PyObject **__pyx_vp_4cupy_4core_14_routines_math__remainder = 0;
#define __pyx_v_4cupy_4core_14_routines_math__remainder (*__pyx_vp_4cupy_4core_14_routines_math__remainder)
static PyObject **__pyx_vp_4cupy_4core_14_routines_math__absolute = 0;
#define __pyx_v_4cupy_4core_14_routines_math__absolute (*__pyx_vp_4cupy_4core_14_routines_math__absolute)
static PyObject **__pyx_vp_4cupy_4core_14_routines_math__sqrt = 0;
#define __pyx_v_4cupy_4core_14_routines_math__sqrt (*__pyx_vp_4cupy_4core_14_routines_math__sqrt)
static struct __pyx_obj_4cupy_4core_4core_ndarray *(*__pyx_f_4cupy_4core_14_routines_math_scan)(struct __pyx_obj_4cupy_4core_4core_ndarray *, struct __pyx_opt_args_4cupy_4core_14_routines_math_scan *__pyx_optional_args); /*proto*/

/* Module declarations from 'cupy.core._routines_manipulation' */
static PyTypeObject *__pyx_ptype_4cupy_4core_22_routines_manipulation_broadcast = 0;
static struct __pyx_obj_4cupy_4core_4core_ndarray *(*__pyx_f_4cupy_4core_22_routines_manipulation_broadcast_to)(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, int __pyx_skip_dispatch); /*proto*/
static struct __pyx_obj_4cupy_4core_4core_ndarray *(*__pyx_f_4cupy_4core_22_routines_manipulation__reshape)(struct __pyx_obj_4cupy_4core_4core_ndarray *, std::vector<Py_ssize_t>  const &, int __pyx_skip_dispatch); /*proto*/
static struct __pyx_obj_4cupy_4core_4core_ndarray *(*__pyx_f_4cupy_4core_22_routines_manipulation__transpose)(struct __pyx_obj_4cupy_4core_4core_ndarray *, std::vector<Py_ssize_t>  const &, int __pyx_skip_dispatch); /*proto*/

/* Module declarations from 'cupy.core.internal' */
static Py_ssize_t (*__pyx_f_4cupy_4core_8internal_prod)(std::vector<Py_ssize_t>  const &, int __pyx_skip_dispatch); /*proto*/
static Py_ssize_t (*__pyx_f_4cupy_4core_8internal_prod_sequence)(PyObject *, int __pyx_skip_dispatch); /*proto*/
static int (*__pyx_f_4cupy_4core_8internal_vector_equal)(std::vector<Py_ssize_t>  const &, std::vector<Py_ssize_t>  const &, int __pyx_skip_dispatch); /*proto*/
static PyObject *(*__pyx_f_4cupy_4core_8internal_complete_slice)(PyObject *, Py_ssize_t, int __pyx_skip_dispatch); /*proto*/
static PyObject *(*__pyx_f_4cupy_4core_8internal_complete_slice_list)(PyObject *, Py_ssize_t, int __pyx_skip_dispatch); /*proto*/

/* Module declarations from 'cupy.core._routines_indexing' */
static PyObject *__pyx_v_4cupy_4core_18_routines_indexing__put_raise_kernel = 0;
static PyObject *__pyx_v_4cupy_4core_18_routines_indexing__put_wrap_kernel = 0;
static PyObject *__pyx_v_4cupy_4core_18_routines_indexing__put_clip_kernel = 0;
static struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_f_4cupy_4core_18_routines_indexing__simple_getitem(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *); /*proto*/
static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__prepare_slice_list(PyObject *, Py_ssize_t, int __pyx_skip_dispatch); /*proto*/
static Py_ssize_t __pyx_f_4cupy_4core_18_routines_indexing__get_mask_index(PyObject *); /*proto*/
static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__prepare_advanced_indexing(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *); /*proto*/
static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__prepare_mask_indexing_single(struct __pyx_obj_4cupy_4core_4core_ndarray *, struct __pyx_obj_4cupy_4core_4core_ndarray *, Py_ssize_t, int __pyx_skip_dispatch); /*proto*/
static struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_f_4cupy_4core_18_routines_indexing__getitem_mask_single(struct __pyx_obj_4cupy_4core_4core_ndarray *, struct __pyx_obj_4cupy_4core_4core_ndarray *, int, int __pyx_skip_dispatch); /*proto*/
static struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_f_4cupy_4core_18_routines_indexing__take(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, int, int, struct __pyx_opt_args_4cupy_4core_18_routines_indexing__take *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__scatter_op_single(struct __pyx_obj_4cupy_4core_4core_ndarray *, struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, struct __pyx_opt_args_4cupy_4core_18_routines_indexing__scatter_op_single *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__scatter_op_mask_single(struct __pyx_obj_4cupy_4core_4core_ndarray *, struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, Py_ssize_t, PyObject *); /*proto*/
static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__scatter_op(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, PyObject *, PyObject *); /*proto*/
static struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_f_4cupy_4core_18_routines_indexing__diagonal(struct __pyx_obj_4cupy_4core_4core_ndarray *, struct __pyx_opt_args_4cupy_4core_18_routines_indexing__diagonal *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__prepare_multiple_array_indexing(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *); /*proto*/
static struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_f_4cupy_4core_18_routines_indexing__getitem_multiple(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *); /*proto*/
static std::vector<Py_ssize_t>  __pyx_convert_vector_from_py_Py_ssize_t(PyObject *); /*proto*/
static PyObject *__pyx_convert_vector_to_py_Py_ssize_t(const std::vector<Py_ssize_t>  &); /*proto*/
#define __Pyx_MODULE_NAME "cupy.core._routines_indexing"
extern int __pyx_module_is_main_cupy__core___routines_indexing;
int __pyx_module_is_main_cupy__core___routines_indexing = 0;

/* Implementation of 'cupy.core._routines_indexing' */
static PyObject *__pyx_builtin_sum;
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_TypeError;
static PyObject *__pyx_builtin_IndexError;
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_enumerate;
static const char __pyx_k_a[] = "a";
static const char __pyx_k_i[] = "i";
static const char __pyx_k_u[] = "u";
static const char __pyx_k_T_a[] = "T a";
static const char __pyx_k_T_y[] = "T y";
static const char __pyx_k__19[] = "";
static const char __pyx_k_add[] = "add";
static const char __pyx_k_all[] = "all";
static const char __pyx_k_max[] = "max";
static const char __pyx_k_min[] = "min";
static const char __pyx_k_sum[] = "sum";
static const char __pyx_k_sys[] = "sys";
static const char __pyx_k_axis[] = "axis";
static const char __pyx_k_bool[] = "bool_";
static const char __pyx_k_clip[] = "clip";
static const char __pyx_k_copy[] = "copy";
static const char __pyx_k_core[] = "core";
static const char __pyx_k_cupy[] = "cupy";
static const char __pyx_k_kind[] = "kind";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_mask[] = "mask";
static const char __pyx_k_name[] = "__name__";
static const char __pyx_k_ndim[] = "ndim";
static const char __pyx_k_prod[] = "prod";
static const char __pyx_k_size[] = "size";
static const char __pyx_k_take[] = "take";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_type[] = "type";
static const char __pyx_k_wrap[] = "wrap";
static const char __pyx_k_Index[] = "Index ";
static const char __pyx_k_S_out[] = "S out";
static const char __pyx_k_T_out[] = "T out";
static const char __pyx_k_array[] = "array";
static const char __pyx_k_dtype[] = "dtype";
static const char __pyx_k_index[] = "index";
static const char __pyx_k_int32[] = "int32";
static const char __pyx_k_int64[] = "int64";
static const char __pyx_k_numpy[] = "numpy";
static const char __pyx_k_raise[] = "raise";
static const char __pyx_k_range[] = "range";
static const char __pyx_k_ravel[] = "ravel";
static const char __pyx_k_shape[] = "shape";
static const char __pyx_k_zeros[] = "zeros";
static const char __pyx_k_astype[] = "astype";
static const char __pyx_k_errors[] = "_errors";
static const char __pyx_k_format[] = "format";
static const char __pyx_k_import[] = "__import__";
static const char __pyx_k_nbytes[] = "nbytes";
static const char __pyx_k_slices[] = "slices";
static const char __pyx_k_uint32[] = "uint32";
static const char __pyx_k_uint64[] = "uint64";
static const char __pyx_k_update[] = "update";
static const char __pyx_k_values[] = "values";
static const char __pyx_k_float16[] = "float16";
static const char __pyx_k_float32[] = "float32";
static const char __pyx_k_float64[] = "float64";
static const char __pyx_k_maximum[] = "maximum";
static const char __pyx_k_minimum[] = "minimum";
static const char __pyx_k_ndarray[] = "ndarray";
static const char __pyx_k_raw_T_a[] = "raw T a";
static const char __pyx_k_strides[] = "strides";
static const char __pyx_k_isscalar[] = "isscalar";
static const char __pyx_k_itemsize[] = "itemsize";
static const char __pyx_k_AxisError[] = "_AxisError";
static const char __pyx_k_TypeError[] = "TypeError";
static const char __pyx_k_cupy_core[] = "cupy.core";
static const char __pyx_k_cupy_take[] = "cupy_take";
static const char __pyx_k_enumerate[] = "enumerate";
static const char __pyx_k_not_equal[] = "not_equal";
static const char __pyx_k_raw_S_dst[] = "raw S dst";
static const char __pyx_k_raw_T_out[] = "raw T out";
static const char __pyx_k_ulonglong[] = "ulonglong";
static const char __pyx_k_with_size[] = " with size ";
static const char __pyx_k_IndexError[] = "IndexError";
static const char __pyx_k_ValueError[] = "ValueError";
static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
static const char __pyx_k_raw_U_data[] = "raw U data";
static const char __pyx_k_cupy_choose[] = "cupy_choose";
static const char __pyx_k_reduce_dims[] = "reduce_dims";
static const char __pyx_k_take_kernel[] = "_take_kernel";
static const char __pyx_k_Axis_overrun[] = "Axis overrun";
static const char __pyx_k_T_src_S_index[] = "T src, S index";
static const char __pyx_k_choose_kernel[] = "_choose_kernel";
static const char __pyx_k_cupy_put_clip[] = "cupy_put_clip";
static const char __pyx_k_cupy_put_wrap[] = "cupy_put_wrap";
static const char __pyx_k_cupy_put_raise[] = "cupy_put_raise";
static const char __pyx_k_nonzero_kernel[] = "_nonzero_kernel";
static const char __pyx_k_cupy_choose_clip[] = "cupy_choose_clip";
static const char __pyx_k_cupy_scatter_add[] = "cupy_scatter_add";
static const char __pyx_k_cupy_scatter_max[] = "cupy_scatter_max";
static const char __pyx_k_cupy_scatter_min[] = "cupy_scatter_min";
static const char __pyx_k_cupy_take_scalar[] = "cupy_take_scalar";
static const char __pyx_k_elementwise_copy[] = "elementwise_copy";
static const char __pyx_k_nonzero_kernel_2[] = "nonzero_kernel";
static const char __pyx_k_take_kernel_core[] = "_take_kernel_core";
static const char __pyx_k_ElementwiseKernel[] = "ElementwiseKernel";
static const char __pyx_k_cupy_core__kernel[] = "cupy.core._kernel";
static const char __pyx_k_cupy_core__ufuncs[] = "cupy.core._ufuncs";
static const char __pyx_k_cupy_getitem_mask[] = "cupy_getitem_mask";
static const char __pyx_k_nonzero_kernel_1d[] = "_nonzero_kernel_1d";
static const char __pyx_k_requires_a_ndim_1[] = "requires a.ndim >= 1";
static const char __pyx_k_T_s_S_len_S_stride[] = "T s, S len, S stride";
static const char __pyx_k_choose_clip_kernel[] = "_choose_clip_kernel";
static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
static const char __pyx_k_scatter_add_kernel[] = "_scatter_add_kernel";
static const char __pyx_k_scatter_max_kernel[] = "_scatter_max_kernel";
static const char __pyx_k_scatter_min_kernel[] = "_scatter_min_kernel";
static const char __pyx_k_take_kernel_scalar[] = "_take_kernel_scalar";
static const char __pyx_k_cupy_scatter_update[] = "cupy_scatter_update";
static const char __pyx_k_getitem_mask_kernel[] = "_getitem_mask_kernel";
static const char __pyx_k_nonzero_kernel_1d_2[] = "nonzero_kernel_1d";
static const char __pyx_k_Invalid_index_type_s[] = "Invalid index type: %s";
static const char __pyx_k_Output_dtype_mismatch[] = "Output dtype mismatch";
static const char __pyx_k_Output_shape_mismatch[] = "Output shape mismatch";
static const char __pyx_k_cupy_scatter_add_mask[] = "cupy_scatter_add_mask";
static const char __pyx_k_cupy_scatter_max_mask[] = "cupy_scatter_max_mask";
static const char __pyx_k_cupy_scatter_min_mask[] = "cupy_scatter_min_mask";
static const char __pyx_k_scatter_update_kernel[] = "_scatter_update_kernel";
static const char __pyx_k_if_src_0_dst_index_1_i[] = "if (src != 0) dst[index - 1] = i";
static const char __pyx_k_prepare_array_indexing[] = "_prepare_array_indexing";
static const char __pyx_k_clipmode_not_understood[] = "clipmode not understood";
static const char __pyx_k_raw_U_data_raw_bool_err[] = "raw U data, raw bool err";
static const char __pyx_k_scatter_add_mask_kernel[] = "_scatter_add_mask_kernel";
static const char __pyx_k_scatter_max_mask_kernel[] = "_scatter_max_mask_kernel";
static const char __pyx_k_scatter_min_mask_kernel[] = "_scatter_min_mask_kernel";
static const char __pyx_k_y_choices_i_n_channel_a[] = "y = choices[i + n_channel * a]";
static const char __pyx_k_cupy_scatter_update_mask[] = "cupy_scatter_update_mask";
static const char __pyx_k_this_op_is_not_supported[] = "this op is not supported";
static const char __pyx_k_is_out_of_bounds_for_axis[] = " is out of bounds for axis ";
static const char __pyx_k_if_mask_a_v_mask_scanned_1[] = "if (mask) a = v[mask_scanned - 1]";
static const char __pyx_k_scatter_update_mask_kernel[] = "_scatter_update_mask_kernel";
static const char __pyx_k_too_many_indices_for_array[] = "too many indices for array";
static const char __pyx_k_boolean_index_did_not_match[] = "boolean index did not match";
static const char __pyx_k_cupy_prepare_array_indexing[] = "cupy_prepare_array_indexing";
static const char __pyx_k_T_a_bool_mask_S_mask_scanned[] = "T a, bool mask, S mask_scanned";
static const char __pyx_k_if_mask_a_a_v_mask_scanned_1[] = "if (mask) a = a + v[mask_scanned - 1]";
static const char __pyx_k_if_mask_out_mask_scanned_1_a[] = "if (mask) out[mask_scanned - 1] = a";
static const char __pyx_k_provided_op_is_not_supported[] = "provided op is not supported";
static const char __pyx_k_invalid_entry_in_choice_array[] = "invalid entry in choice array";
static const char __pyx_k_S_in0_s_in1_len_out_stride_in0[] = "S in0 = s, in1 = len;out += stride * (in0 - _floor_divide(in0, in1) * in1)";
static const char __pyx_k_S_wrap_indices_indices_adim_if[] = "\n      S wrap_indices = indices % adim;\n      if (wrap_indices < 0) wrap_indices += adim;\n      ptrdiff_t li = i / (rdim * cdim);\n      ptrdiff_t ri = i % rdim;\n      a[(li * adim + wrap_indices) * rdim + ri] = v;\n    ";
static const char __pyx_k_S_x_a_if_a_0_x_0_else_if_a_n_x[] = "\n      S x = a;\n      if (a < 0) {\n        x = 0;\n      } else if (a >= n) {\n        x = n - 1;\n      }\n      y = choices[i + n_channel * x];\n    ";
static const char __pyx_k_invalid_entry_in_indices_array[] = "invalid entry in indices array";
static const char __pyx_k_cannot_do_a_non_empty_take_from[] = "cannot do a non-empty take from an empty axes.";
static const char __pyx_k_if_src_0_for_int_j_0_j__ind_ndi[] = "\n    if (src != 0){\n        for(int j = 0; j < _ind.ndim; j++){\n            ptrdiff_t ind[] = {j, index - 1};\n            dst[ind] = _ind.get()[j];\n        }\n    }";
static const char __pyx_k_ptrdiff_t_ind__ind_if_ind__0_in[] = "\n      ptrdiff_t ind_ = ind;\n      if (ind_ < 0) {\n        ind_ = 0;\n      } else if (ind_ >= n) {\n        ind_ = n - 1;\n      }\n      data[ind_] = (U)(vals[i % n_vals]);\n    ";
static const char __pyx_k_ptrdiff_t_ind__ind_if_n_ind__in[] = "\n      ptrdiff_t ind_ = ind;\n      if (!(-n <= ind_ && ind_ < n)) {\n        err[0] = 1;\n      } else {\n        if (ind_ < 0) ind_ += n;\n        data[ind_] = (U)(vals[i % n_vals]);\n      }\n    ";
static const char __pyx_k_ptrdiff_t_ind__ind_ind__n_if_in[] = "\n      ptrdiff_t ind_ = ind;\n      ind_ %= n;\n      if (ind_ < 0) ind_ += n;\n      data[ind_] = (U)(vals[i % n_vals]);\n    ";
static const char __pyx_k_ptrdiff_t_out_i_indices_index_r[] = "\nptrdiff_t out_i = indices % index_range;\nif (out_i < 0) out_i += index_range;\nif (ldim != 1) out_i += (i / (cdim * rdim)) * index_range;\nif (rdim != 1) out_i = out_i * rdim + i % rdim;\nout = a[out_i];\n";
static const char __pyx_k_scatter_add_only_supports_int32[] = "scatter_add only supports int32, float16, float32, float64, uint32, uint64, as data type";
static const char __pyx_k_scatter_max_only_supports_int32[] = "scatter_max only supports int32, float32, float64, uint32, uint64 as data type";
static const char __pyx_k_scatter_min_only_supports_int32[] = "scatter_min only supports int32, float32, float64, uint32, uint64 as data type";
static const char __pyx_k_S_a_raw_T_choices_int32_n_channe[] = "S a, raw T choices, int32 n_channel";
static const char __pyx_k_S_ind_raw_T_vals_int64_n_vals_in[] = "S ind, raw T vals, int64 n_vals, int64 n";
static const char __pyx_k_S_wrap_indices_indices_adim_if_2[] = "\n      S wrap_indices = indices % adim;\n      if (wrap_indices < 0) wrap_indices += adim;\n      ptrdiff_t li = i / (rdim * cdim);\n      ptrdiff_t ri = i % rdim;\n      atomicAdd(&a[(li * adim + wrap_indices) * rdim + ri], v[i]);\n    ";
static const char __pyx_k_S_wrap_indices_indices_adim_if_3[] = "\n      S wrap_indices = indices % adim;\n      if (wrap_indices < 0) wrap_indices += adim;\n      ptrdiff_t li = i / (rdim * cdim);\n      ptrdiff_t ri = i % rdim;\n      atomicMax(&a[(li * adim + wrap_indices) * rdim + ri], v[i]);\n    ";
static const char __pyx_k_S_wrap_indices_indices_adim_if_4[] = "\n      S wrap_indices = indices % adim;\n      if (wrap_indices < 0) wrap_indices += adim;\n      ptrdiff_t li = i / (rdim * cdim);\n      ptrdiff_t ri = i % rdim;\n      atomicMin(&a[(li * adim + wrap_indices) * rdim + ri], v[i]);\n    ";
static const char __pyx_k_T_v_S_indices_int32_cdim_int32_r[] = "T v, S indices, int32 cdim, int32 rdim, int32 adim";
static const char __pyx_k_arrays_used_as_indices_must_be_o[] = "arrays used as indices must be of integer or boolean type. (actual: {})";
static const char __pyx_k_axis1_0_and_axis2_1_must_be_with[] = "axis1(={0}) and axis2(={1}) must be within range (ndim={2})";
static const char __pyx_k_currently_CuPy_only_supports_sli[] = "currently, CuPy only supports slices that consist of one boolean array.";
static const char __pyx_k_if_mask_a_max_a_v_mask_scanned_1[] = "if (mask) a = max(a, v[mask_scanned - 1])";
static const char __pyx_k_if_mask_a_min_a_v_mask_scanned_1[] = "if (mask) a = min(a, v[mask_scanned - 1])";
static const char __pyx_k_only_integers_slices_ellipsis_nu[] = "only integers, slices (`:`), ellipsis (`...`),numpy.newaxis (`None`) and integer or boolean arrays are valid indices";
static const char __pyx_k_raw_T_a_S_indices_uint32_ldim_ui[] = "raw T a, S indices, uint32 ldim, uint32 cdim, uint32 rdim, int64 index_range";
static const char __pyx_k_raw_T_a_int64_indices_uint32_ldi[] = "raw T a, int64 indices, uint32 ldim, uint32 cdim, uint32 rdim, int64 index_range";
static const char __pyx_k_raw_T_v_S_indices_int32_cdim_int[] = "raw T v, S indices, int32 cdim, int32 rdim, int32 adim";
static const char __pyx_k_raw_T_v_bool_mask_S_mask_scanned[] = "raw T v, bool mask, S mask_scanned";
static const char __pyx_k_S_a_raw_T_choices_int32_n_channe_2[] = "S a, raw T choices, int32 n_channel, int32 n";
static PyObject *__pyx_n_s_AxisError;
static PyObject *__pyx_kp_u_Axis_overrun;
static PyObject *__pyx_n_s_ElementwiseKernel;
static PyObject *__pyx_kp_u_Index;
static PyObject *__pyx_n_s_IndexError;
static PyObject *__pyx_kp_u_Invalid_index_type_s;
static PyObject *__pyx_kp_u_Output_dtype_mismatch;
static PyObject *__pyx_kp_u_Output_shape_mismatch;
static PyObject *__pyx_kp_u_S_a_raw_T_choices_int32_n_channe;
static PyObject *__pyx_kp_u_S_a_raw_T_choices_int32_n_channe_2;
static PyObject *__pyx_kp_u_S_in0_s_in1_len_out_stride_in0;
static PyObject *__pyx_kp_u_S_ind_raw_T_vals_int64_n_vals_in;
static PyObject *__pyx_kp_u_S_out;
static PyObject *__pyx_kp_u_S_wrap_indices_indices_adim_if;
static PyObject *__pyx_kp_u_S_wrap_indices_indices_adim_if_2;
static PyObject *__pyx_kp_u_S_wrap_indices_indices_adim_if_3;
static PyObject *__pyx_kp_u_S_wrap_indices_indices_adim_if_4;
static PyObject *__pyx_kp_u_S_x_a_if_a_0_x_0_else_if_a_n_x;
static PyObject *__pyx_kp_u_T_a;
static PyObject *__pyx_kp_u_T_a_bool_mask_S_mask_scanned;
static PyObject *__pyx_kp_u_T_out;
static PyObject *__pyx_kp_u_T_s_S_len_S_stride;
static PyObject *__pyx_kp_u_T_src_S_index;
static PyObject *__pyx_kp_u_T_v_S_indices_int32_cdim_int32_r;
static PyObject *__pyx_kp_u_T_y;
static PyObject *__pyx_n_s_TypeError;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_kp_u__19;
static PyObject *__pyx_n_s_a;
static PyObject *__pyx_n_u_add;
static PyObject *__pyx_n_s_all;
static PyObject *__pyx_n_s_array;
static PyObject *__pyx_kp_u_arrays_used_as_indices_must_be_o;
static PyObject *__pyx_n_s_astype;
static PyObject *__pyx_n_s_axis;
static PyObject *__pyx_kp_u_axis1_0_and_axis2_1_must_be_with;
static PyObject *__pyx_n_s_bool;
static PyObject *__pyx_kp_u_boolean_index_did_not_match;
static PyObject *__pyx_kp_u_cannot_do_a_non_empty_take_from;
static PyObject *__pyx_n_s_choose_clip_kernel;
static PyObject *__pyx_n_s_choose_kernel;
static PyObject *__pyx_n_s_cline_in_traceback;
static PyObject *__pyx_n_u_clip;
static PyObject *__pyx_kp_u_clipmode_not_understood;
static PyObject *__pyx_n_s_copy;
static PyObject *__pyx_n_s_core;
static PyObject *__pyx_n_s_cupy;
static PyObject *__pyx_n_u_cupy_choose;
static PyObject *__pyx_n_u_cupy_choose_clip;
static PyObject *__pyx_n_s_cupy_core;
static PyObject *__pyx_n_s_cupy_core__kernel;
static PyObject *__pyx_n_s_cupy_core__ufuncs;
static PyObject *__pyx_n_u_cupy_getitem_mask;
static PyObject *__pyx_n_u_cupy_prepare_array_indexing;
static PyObject *__pyx_n_u_cupy_put_clip;
static PyObject *__pyx_n_u_cupy_put_raise;
static PyObject *__pyx_n_u_cupy_put_wrap;
static PyObject *__pyx_n_u_cupy_scatter_add;
static PyObject *__pyx_n_u_cupy_scatter_add_mask;
static PyObject *__pyx_n_u_cupy_scatter_max;
static PyObject *__pyx_n_u_cupy_scatter_max_mask;
static PyObject *__pyx_n_u_cupy_scatter_min;
static PyObject *__pyx_n_u_cupy_scatter_min_mask;
static PyObject *__pyx_n_u_cupy_scatter_update;
static PyObject *__pyx_n_u_cupy_scatter_update_mask;
static PyObject *__pyx_n_u_cupy_take;
static PyObject *__pyx_n_u_cupy_take_scalar;
static PyObject *__pyx_kp_u_currently_CuPy_only_supports_sli;
static PyObject *__pyx_n_s_dtype;
static PyObject *__pyx_n_s_elementwise_copy;
static PyObject *__pyx_n_s_enumerate;
static PyObject *__pyx_n_s_errors;
static PyObject *__pyx_n_s_float16;
static PyObject *__pyx_n_s_float32;
static PyObject *__pyx_n_s_float64;
static PyObject *__pyx_n_s_format;
static PyObject *__pyx_n_s_getitem_mask_kernel;
static PyObject *__pyx_n_u_i;
static PyObject *__pyx_kp_u_if_mask_a_a_v_mask_scanned_1;
static PyObject *__pyx_kp_u_if_mask_a_max_a_v_mask_scanned_1;
static PyObject *__pyx_kp_u_if_mask_a_min_a_v_mask_scanned_1;
static PyObject *__pyx_kp_u_if_mask_a_v_mask_scanned_1;
static PyObject *__pyx_kp_u_if_mask_out_mask_scanned_1_a;
static PyObject *__pyx_kp_u_if_src_0_dst_index_1_i;
static PyObject *__pyx_kp_u_if_src_0_for_int_j_0_j__ind_ndi;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_index;
static PyObject *__pyx_n_s_int32;
static PyObject *__pyx_n_s_int64;
static PyObject *__pyx_kp_u_invalid_entry_in_choice_array;
static PyObject *__pyx_kp_u_invalid_entry_in_indices_array;
static PyObject *__pyx_kp_u_is_out_of_bounds_for_axis;
static PyObject *__pyx_n_s_isscalar;
static PyObject *__pyx_n_s_itemsize;
static PyObject *__pyx_n_s_kind;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_mask;
static PyObject *__pyx_n_u_max;
static PyObject *__pyx_n_s_maximum;
static PyObject *__pyx_n_u_min;
static PyObject *__pyx_n_s_minimum;
static PyObject *__pyx_n_s_name;
static PyObject *__pyx_n_s_nbytes;
static PyObject *__pyx_n_s_ndarray;
static PyObject *__pyx_n_s_ndim;
static PyObject *__pyx_n_s_nonzero_kernel;
static PyObject *__pyx_n_s_nonzero_kernel_1d;
static PyObject *__pyx_n_u_nonzero_kernel_1d_2;
static PyObject *__pyx_n_u_nonzero_kernel_2;
static PyObject *__pyx_n_s_not_equal;
static PyObject *__pyx_n_s_numpy;
static PyObject *__pyx_kp_u_only_integers_slices_ellipsis_nu;
static PyObject *__pyx_n_s_prepare_array_indexing;
static PyObject *__pyx_n_s_prod;
static PyObject *__pyx_kp_u_provided_op_is_not_supported;
static PyObject *__pyx_kp_u_ptrdiff_t_ind__ind_if_ind__0_in;
static PyObject *__pyx_kp_u_ptrdiff_t_ind__ind_if_n_ind__in;
static PyObject *__pyx_kp_u_ptrdiff_t_ind__ind_ind__n_if_in;
static PyObject *__pyx_kp_u_ptrdiff_t_out_i_indices_index_r;
static PyObject *__pyx_n_s_pyx_vtable;
static PyObject *__pyx_n_u_raise;
static PyObject *__pyx_n_s_range;
static PyObject *__pyx_n_s_ravel;
static PyObject *__pyx_kp_u_raw_S_dst;
static PyObject *__pyx_kp_u_raw_T_a;
static PyObject *__pyx_kp_u_raw_T_a_S_indices_uint32_ldim_ui;
static PyObject *__pyx_kp_u_raw_T_a_int64_indices_uint32_ldi;
static PyObject *__pyx_kp_u_raw_T_out;
static PyObject *__pyx_kp_u_raw_T_v_S_indices_int32_cdim_int;
static PyObject *__pyx_kp_u_raw_T_v_bool_mask_S_mask_scanned;
static PyObject *__pyx_kp_u_raw_U_data;
static PyObject *__pyx_kp_u_raw_U_data_raw_bool_err;
static PyObject *__pyx_n_s_reduce_dims;
static PyObject *__pyx_kp_u_requires_a_ndim_1;
static PyObject *__pyx_n_s_scatter_add_kernel;
static PyObject *__pyx_n_s_scatter_add_mask_kernel;
static PyObject *__pyx_kp_u_scatter_add_only_supports_int32;
static PyObject *__pyx_n_s_scatter_max_kernel;
static PyObject *__pyx_n_s_scatter_max_mask_kernel;
static PyObject *__pyx_kp_u_scatter_max_only_supports_int32;
static PyObject *__pyx_n_s_scatter_min_kernel;
static PyObject *__pyx_n_s_scatter_min_mask_kernel;
static PyObject *__pyx_kp_u_scatter_min_only_supports_int32;
static PyObject *__pyx_n_s_scatter_update_kernel;
static PyObject *__pyx_n_s_scatter_update_mask_kernel;
static PyObject *__pyx_n_s_shape;
static PyObject *__pyx_n_s_size;
static PyObject *__pyx_n_s_slices;
static PyObject *__pyx_n_s_strides;
static PyObject *__pyx_n_s_sum;
static PyObject *__pyx_n_s_sys;
static PyObject *__pyx_n_s_take;
static PyObject *__pyx_n_s_take_kernel;
static PyObject *__pyx_n_s_take_kernel_core;
static PyObject *__pyx_n_s_take_kernel_scalar;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_kp_u_this_op_is_not_supported;
static PyObject *__pyx_kp_u_too_many_indices_for_array;
static PyObject *__pyx_n_s_type;
static PyObject *__pyx_n_u_u;
static PyObject *__pyx_n_s_uint32;
static PyObject *__pyx_n_s_uint64;
static PyObject *__pyx_n_s_ulonglong;
static PyObject *__pyx_n_u_update;
static PyObject *__pyx_n_s_values;
static PyObject *__pyx_kp_u_with_size;
static PyObject *__pyx_n_u_wrap;
static PyObject *__pyx_kp_u_y_choices_i_n_channel_a;
static PyObject *__pyx_n_s_zeros;
static PyObject *__pyx_pf_4cupy_4core_18_routines_indexing__prepare_slice_list(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_slices, Py_ssize_t __pyx_v_ndim); /* proto */
static PyObject *__pyx_pf_4cupy_4core_18_routines_indexing_2_prepare_mask_indexing_single(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_a, struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_mask, Py_ssize_t __pyx_v_axis); /* proto */
static PyObject *__pyx_pf_4cupy_4core_18_routines_indexing_4_getitem_mask_single(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_a, struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_mask, int __pyx_v_axis); /* proto */
static __Pyx_CachedCFunction __pyx_umethod_PyList_Type_index = {0, &__pyx_n_s_index, 0, 0, 0};
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_2147483647;
static PyObject *__pyx_int_neg_2;
static PyObject *__pyx_tuple_;
static PyObject *__pyx_slice__7;
static PyObject *__pyx_slice__9;
static PyObject *__pyx_tuple__2;
static PyObject *__pyx_tuple__3;
static PyObject *__pyx_tuple__4;
static PyObject *__pyx_tuple__5;
static PyObject *__pyx_tuple__6;
static PyObject *__pyx_tuple__8;
static PyObject *__pyx_slice__27;
static PyObject *__pyx_tuple__10;
static PyObject *__pyx_tuple__11;
static PyObject *__pyx_tuple__12;
static PyObject *__pyx_tuple__13;
static PyObject *__pyx_tuple__14;
static PyObject *__pyx_tuple__15;
static PyObject *__pyx_tuple__16;
static PyObject *__pyx_tuple__17;
static PyObject *__pyx_tuple__18;
static PyObject *__pyx_tuple__20;
static PyObject *__pyx_tuple__21;
static PyObject *__pyx_tuple__22;
static PyObject *__pyx_tuple__23;
static PyObject *__pyx_tuple__24;
static PyObject *__pyx_tuple__25;
static PyObject *__pyx_tuple__26;
static PyObject *__pyx_tuple__28;
static PyObject *__pyx_tuple__29;
static PyObject *__pyx_tuple__30;
static PyObject *__pyx_tuple__31;
static PyObject *__pyx_tuple__32;
static PyObject *__pyx_tuple__33;
static PyObject *__pyx_tuple__34;
static PyObject *__pyx_tuple__35;
static PyObject *__pyx_tuple__36;
static PyObject *__pyx_tuple__37;
static PyObject *__pyx_tuple__38;
static PyObject *__pyx_tuple__39;
static PyObject *__pyx_tuple__40;
static PyObject *__pyx_tuple__41;
static PyObject *__pyx_tuple__42;
static PyObject *__pyx_tuple__43;
static PyObject *__pyx_tuple__44;
/* Late includes */

/* "cupy/core/_routines_indexing.pyx":23
 * 
 * 
 * cdef ndarray _ndarray_getitem(ndarray self, slices):             # <<<<<<<<<<<<<<
 *     # supports basic indexing (by slices, ints or Ellipsis) and
 *     # some parts of advanced indexing by integer or boolean arrays.
 */

static struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_f_4cupy_4core_18_routines_indexing__ndarray_getitem(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_self, PyObject *__pyx_v_slices) {
  Py_ssize_t __pyx_v_mask_i;
  PyObject *__pyx_v_slice_list = 0;
  PyObject *__pyx_v_adv_mask = 0;
  PyObject *__pyx_v_adv_slices = 0;
  int __pyx_v_advanced;
  int __pyx_v_mask_exists;
  PyObject *__pyx_v_a = NULL;
  PyObject *__pyx_v_axis = NULL;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_ndarray_getitem", 0);

  /* "cupy/core/_routines_indexing.pyx":31
 *     cdef bint advanced, mask_exists
 * 
 *     slice_list, advanced, mask_exists = _prepare_slice_list(             # <<<<<<<<<<<<<<
 *         slices, self._shape.size())
 * 
 */
  __pyx_t_1 = __pyx_f_4cupy_4core_18_routines_indexing__prepare_slice_list(__pyx_v_slices, __pyx_v_self->_shape.size(), 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 31, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (likely(__pyx_t_1 != Py_None)) {
    PyObject* sequence = __pyx_t_1;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 3)) {
      if (size > 3) __Pyx_RaiseTooManyValuesError(3);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 31, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
    __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
    __pyx_t_4 = PyTuple_GET_ITEM(sequence, 2); 
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_4);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 31, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 31, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    #endif
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(0, 31, __pyx_L1_error)
  }
  if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 31, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 31, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 31, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_slice_list = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_v_advanced = __pyx_t_5;
  __pyx_v_mask_exists = __pyx_t_6;

  /* "cupy/core/_routines_indexing.pyx":34
 *         slices, self._shape.size())
 * 
 *     if mask_exists:             # <<<<<<<<<<<<<<
 *         mask_i = _get_mask_index(slice_list)
 *         return _getitem_mask_single(self, slice_list[mask_i], mask_i)
 */
  __pyx_t_6 = (__pyx_v_mask_exists != 0);
  if (__pyx_t_6) {

    /* "cupy/core/_routines_indexing.pyx":35
 * 
 *     if mask_exists:
 *         mask_i = _get_mask_index(slice_list)             # <<<<<<<<<<<<<<
 *         return _getitem_mask_single(self, slice_list[mask_i], mask_i)
 *     if advanced:
 */
    __pyx_t_7 = __pyx_f_4cupy_4core_18_routines_indexing__get_mask_index(__pyx_v_slice_list); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 35, __pyx_L1_error)
    __pyx_v_mask_i = __pyx_t_7;

    /* "cupy/core/_routines_indexing.pyx":36
 *     if mask_exists:
 *         mask_i = _get_mask_index(slice_list)
 *         return _getitem_mask_single(self, slice_list[mask_i], mask_i)             # <<<<<<<<<<<<<<
 *     if advanced:
 *         a, adv_slices, adv_mask = _prepare_advanced_indexing(
 */
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    if (unlikely(__pyx_v_slice_list == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 36, __pyx_L1_error)
    }
    __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_slice_list, __pyx_v_mask_i, Py_ssize_t, 1, PyInt_FromSsize_t, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 36, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 36, __pyx_L1_error)
    __pyx_t_4 = ((PyObject *)__pyx_f_4cupy_4core_18_routines_indexing__getitem_mask_single(__pyx_v_self, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_1), __pyx_v_mask_i, 0)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 36, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_r = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_4);
    __pyx_t_4 = 0;
    goto __pyx_L0;

    /* "cupy/core/_routines_indexing.pyx":34
 *         slices, self._shape.size())
 * 
 *     if mask_exists:             # <<<<<<<<<<<<<<
 *         mask_i = _get_mask_index(slice_list)
 *         return _getitem_mask_single(self, slice_list[mask_i], mask_i)
 */
  }

  /* "cupy/core/_routines_indexing.pyx":37
 *         mask_i = _get_mask_index(slice_list)
 *         return _getitem_mask_single(self, slice_list[mask_i], mask_i)
 *     if advanced:             # <<<<<<<<<<<<<<
 *         a, adv_slices, adv_mask = _prepare_advanced_indexing(
 *             self, slice_list)
 */
  __pyx_t_6 = (__pyx_v_advanced != 0);
  if (__pyx_t_6) {

    /* "cupy/core/_routines_indexing.pyx":38
 *         return _getitem_mask_single(self, slice_list[mask_i], mask_i)
 *     if advanced:
 *         a, adv_slices, adv_mask = _prepare_advanced_indexing(             # <<<<<<<<<<<<<<
 *             self, slice_list)
 *         if sum(adv_mask) == 1:
 */
    __pyx_t_4 = __pyx_f_4cupy_4core_18_routines_indexing__prepare_advanced_indexing(__pyx_v_self, __pyx_v_slice_list); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 38, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (likely(__pyx_t_4 != Py_None)) {
      PyObject* sequence = __pyx_t_4;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 3)) {
        if (size > 3) __Pyx_RaiseTooManyValuesError(3);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 38, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 2); 
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      #else
      __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 38, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 38, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 38, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      #endif
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else {
      __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(0, 38, __pyx_L1_error)
    }
    if (!(likely(PyList_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 38, __pyx_L1_error)
    if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 38, __pyx_L1_error)
    __pyx_v_a = __pyx_t_1;
    __pyx_t_1 = 0;
    __pyx_v_adv_slices = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_v_adv_mask = ((PyObject*)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":40
 *         a, adv_slices, adv_mask = _prepare_advanced_indexing(
 *             self, slice_list)
 *         if sum(adv_mask) == 1:             # <<<<<<<<<<<<<<
 *             axis = adv_mask.index(True)
 *             return a.take(adv_slices[axis], axis)
 */
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_sum, __pyx_v_adv_mask); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 40, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_4, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 40, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 40, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_6) {

      /* "cupy/core/_routines_indexing.pyx":41
 *             self, slice_list)
 *         if sum(adv_mask) == 1:
 *             axis = adv_mask.index(True)             # <<<<<<<<<<<<<<
 *             return a.take(adv_slices[axis], axis)
 *         return _getitem_multiple(a, adv_slices)
 */
      __pyx_t_2 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyList_Type_index, __pyx_v_adv_mask, Py_True); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 41, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_v_axis = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "cupy/core/_routines_indexing.pyx":42
 *         if sum(adv_mask) == 1:
 *             axis = adv_mask.index(True)
 *             return a.take(adv_slices[axis], axis)             # <<<<<<<<<<<<<<
 *         return _getitem_multiple(a, adv_slices)
 * 
 */
      __Pyx_XDECREF(((PyObject *)__pyx_r));
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_a, __pyx_n_s_take); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 42, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (unlikely(__pyx_v_adv_slices == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 42, __pyx_L1_error)
      }
      __pyx_t_3 = __Pyx_PyObject_GetItem(__pyx_v_adv_slices, __pyx_v_axis); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 42, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_1 = NULL;
      __pyx_t_8 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
          __pyx_t_8 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_4)) {
        PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_t_3, __pyx_v_axis};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
        PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_t_3, __pyx_v_axis};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else
      #endif
      {
        __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 42, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        if (__pyx_t_1) {
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); __pyx_t_1 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_t_3);
        __Pyx_INCREF(__pyx_v_axis);
        __Pyx_GIVEREF(__pyx_v_axis);
        PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_v_axis);
        __pyx_t_3 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 42, __pyx_L1_error)
      __pyx_r = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2);
      __pyx_t_2 = 0;
      goto __pyx_L0;

      /* "cupy/core/_routines_indexing.pyx":40
 *         a, adv_slices, adv_mask = _prepare_advanced_indexing(
 *             self, slice_list)
 *         if sum(adv_mask) == 1:             # <<<<<<<<<<<<<<
 *             axis = adv_mask.index(True)
 *             return a.take(adv_slices[axis], axis)
 */
    }

    /* "cupy/core/_routines_indexing.pyx":43
 *             axis = adv_mask.index(True)
 *             return a.take(adv_slices[axis], axis)
 *         return _getitem_multiple(a, adv_slices)             # <<<<<<<<<<<<<<
 * 
 *     return _simple_getitem(self, slice_list)
 */
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    if (!(likely(((__pyx_v_a) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_a, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 43, __pyx_L1_error)
    __pyx_t_2 = ((PyObject *)__pyx_f_4cupy_4core_18_routines_indexing__getitem_multiple(((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_v_a), __pyx_v_adv_slices)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_r = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2);
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "cupy/core/_routines_indexing.pyx":37
 *         mask_i = _get_mask_index(slice_list)
 *         return _getitem_mask_single(self, slice_list[mask_i], mask_i)
 *     if advanced:             # <<<<<<<<<<<<<<
 *         a, adv_slices, adv_mask = _prepare_advanced_indexing(
 *             self, slice_list)
 */
  }

  /* "cupy/core/_routines_indexing.pyx":45
 *         return _getitem_multiple(a, adv_slices)
 * 
 *     return _simple_getitem(self, slice_list)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __pyx_t_2 = ((PyObject *)__pyx_f_4cupy_4core_18_routines_indexing__simple_getitem(__pyx_v_self, __pyx_v_slice_list)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_r = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2);
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "cupy/core/_routines_indexing.pyx":23
 * 
 * 
 * cdef ndarray _ndarray_getitem(ndarray self, slices):             # <<<<<<<<<<<<<<
 *     # supports basic indexing (by slices, ints or Ellipsis) and
 *     # some parts of advanced indexing by integer or boolean arrays.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("cupy.core._routines_indexing._ndarray_getitem", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_slice_list);
  __Pyx_XDECREF(__pyx_v_adv_mask);
  __Pyx_XDECREF(__pyx_v_adv_slices);
  __Pyx_XDECREF(__pyx_v_a);
  __Pyx_XDECREF(__pyx_v_axis);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":48
 * 
 * 
 * cdef _ndarray_setitem(ndarray self, slices, value):             # <<<<<<<<<<<<<<
 *     _scatter_op(self, slices, value, 'update')
 * 
 */

static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__ndarray_setitem(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_self, PyObject *__pyx_v_slices, PyObject *__pyx_v_value) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_ndarray_setitem", 0);

  /* "cupy/core/_routines_indexing.pyx":49
 * 
 * cdef _ndarray_setitem(ndarray self, slices, value):
 *     _scatter_op(self, slices, value, 'update')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __pyx_f_4cupy_4core_18_routines_indexing__scatter_op(__pyx_v_self, __pyx_v_slices, __pyx_v_value, __pyx_n_u_update); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 49, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":48
 * 
 * 
 * cdef _ndarray_setitem(ndarray self, slices, value):             # <<<<<<<<<<<<<<
 *     _scatter_op(self, slices, value, 'update')
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cupy.core._routines_indexing._ndarray_setitem", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":52
 * 
 * 
 * cdef tuple _ndarray_nonzero(ndarray self):             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t count_nonzero
 *     cdef int ndim
 */

static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__ndarray_nonzero(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_self) {
  Py_ssize_t __pyx_v_count_nonzero;
  int __pyx_v_ndim;
  PyObject *__pyx_v_dtype = NULL;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_r = NULL;
  PyObject *__pyx_v_nonzero = NULL;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_scan_index = NULL;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_dst = NULL;
  int __pyx_7genexpr__pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  Py_ssize_t __pyx_t_8;
  long __pyx_t_9;
  long __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_ndarray_nonzero", 0);

  /* "cupy/core/_routines_indexing.pyx":55
 *     cdef Py_ssize_t count_nonzero
 *     cdef int ndim
 *     dtype = numpy.int64             # <<<<<<<<<<<<<<
 *     if self.size == 0:
 *         count_nonzero = 0
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 55, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_int64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 55, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_dtype = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "cupy/core/_routines_indexing.pyx":56
 *     cdef int ndim
 *     dtype = numpy.int64
 *     if self.size == 0:             # <<<<<<<<<<<<<<
 *         count_nonzero = 0
 *     else:
 */
  __pyx_t_3 = ((__pyx_v_self->size == 0) != 0);
  if (__pyx_t_3) {

    /* "cupy/core/_routines_indexing.pyx":57
 *     dtype = numpy.int64
 *     if self.size == 0:
 *         count_nonzero = 0             # <<<<<<<<<<<<<<
 *     else:
 *         r = self.ravel()
 */
    __pyx_v_count_nonzero = 0;

    /* "cupy/core/_routines_indexing.pyx":56
 *     cdef int ndim
 *     dtype = numpy.int64
 *     if self.size == 0:             # <<<<<<<<<<<<<<
 *         count_nonzero = 0
 *     else:
 */
    goto __pyx_L3;
  }

  /* "cupy/core/_routines_indexing.pyx":59
 *         count_nonzero = 0
 *     else:
 *         r = self.ravel()             # <<<<<<<<<<<<<<
 *         nonzero = cupy.core.not_equal(r, 0, ndarray(r.shape, dtype))
 *         del r
 */
  /*else*/ {
    __pyx_t_2 = ((PyObject *)((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)__pyx_v_self->__pyx_vtab)->ravel(__pyx_v_self, 0, NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 59, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_r = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":60
 *     else:
 *         r = self.ravel()
 *         nonzero = cupy.core.not_equal(r, 0, ndarray(r.shape, dtype))             # <<<<<<<<<<<<<<
 *         del r
 *         scan_index = _math.scan(nonzero)
 */
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_cupy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 60, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_core); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 60, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_not_equal); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 60, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_r), __pyx_n_s_shape); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 60, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 60, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
    __Pyx_INCREF(__pyx_v_dtype);
    __Pyx_GIVEREF(__pyx_v_dtype);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_dtype);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_4cupy_4core_4core_ndarray), __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 60, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    __pyx_t_6 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
        __pyx_t_6 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[4] = {__pyx_t_5, ((PyObject *)__pyx_v_r), __pyx_int_0, __pyx_t_4};
      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 60, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[4] = {__pyx_t_5, ((PyObject *)__pyx_v_r), __pyx_int_0, __pyx_t_4};
      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 60, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    {
      __pyx_t_7 = PyTuple_New(3+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 60, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      if (__pyx_t_5) {
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_r));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_r));
      PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, ((PyObject *)__pyx_v_r));
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_GIVEREF(__pyx_int_0);
      PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_int_0);
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_7, 2+__pyx_t_6, __pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 60, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_nonzero = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":61
 *         r = self.ravel()
 *         nonzero = cupy.core.not_equal(r, 0, ndarray(r.shape, dtype))
 *         del r             # <<<<<<<<<<<<<<
 *         scan_index = _math.scan(nonzero)
 *         count_nonzero = int(scan_index[-1])  # synchronize!
 */
    __Pyx_DECREF(((PyObject *)__pyx_v_r));
    __pyx_v_r = NULL;

    /* "cupy/core/_routines_indexing.pyx":62
 *         nonzero = cupy.core.not_equal(r, 0, ndarray(r.shape, dtype))
 *         del r
 *         scan_index = _math.scan(nonzero)             # <<<<<<<<<<<<<<
 *         count_nonzero = int(scan_index[-1])  # synchronize!
 *     ndim = max(<int>self._shape.size(), 1)
 */
    if (!(likely(((__pyx_v_nonzero) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_nonzero, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 62, __pyx_L1_error)
    __pyx_t_2 = ((PyObject *)__pyx_f_4cupy_4core_14_routines_math_scan(((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_v_nonzero), NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 62, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_scan_index = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":63
 *         del r
 *         scan_index = _math.scan(nonzero)
 *         count_nonzero = int(scan_index[-1])  # synchronize!             # <<<<<<<<<<<<<<
 *     ndim = max(<int>self._shape.size(), 1)
 *     if count_nonzero == 0:
 */
    __pyx_t_2 = __Pyx_GetItemInt(((PyObject *)__pyx_v_scan_index), -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 63, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 63, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 63, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_count_nonzero = __pyx_t_8;
  }
  __pyx_L3:;

  /* "cupy/core/_routines_indexing.pyx":64
 *         scan_index = _math.scan(nonzero)
 *         count_nonzero = int(scan_index[-1])  # synchronize!
 *     ndim = max(<int>self._shape.size(), 1)             # <<<<<<<<<<<<<<
 *     if count_nonzero == 0:
 *         return (ndarray((0,), dtype=dtype),) * ndim
 */
  __pyx_t_9 = 1;
  __pyx_t_6 = ((int)__pyx_v_self->_shape.size());
  if (((__pyx_t_9 > __pyx_t_6) != 0)) {
    __pyx_t_10 = __pyx_t_9;
  } else {
    __pyx_t_10 = __pyx_t_6;
  }
  __pyx_v_ndim = __pyx_t_10;

  /* "cupy/core/_routines_indexing.pyx":65
 *         count_nonzero = int(scan_index[-1])  # synchronize!
 *     ndim = max(<int>self._shape.size(), 1)
 *     if count_nonzero == 0:             # <<<<<<<<<<<<<<
 *         return (ndarray((0,), dtype=dtype),) * ndim
 * 
 */
  __pyx_t_3 = ((__pyx_v_count_nonzero == 0) != 0);
  if (__pyx_t_3) {

    /* "cupy/core/_routines_indexing.pyx":66
 *     ndim = max(<int>self._shape.size(), 1)
 *     if count_nonzero == 0:
 *         return (ndarray((0,), dtype=dtype),) * ndim             # <<<<<<<<<<<<<<
 * 
 *     if ndim <= 1:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 66, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_v_dtype) < 0) __PYX_ERR(0, 66, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_4cupy_4core_4core_ndarray), __pyx_tuple__2, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 66, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1 * ((__pyx_v_ndim<0) ? 0:__pyx_v_ndim)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 66, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    { Py_ssize_t __pyx_temp;
      for (__pyx_temp=0; __pyx_temp < __pyx_v_ndim; __pyx_temp++) {
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_1, __pyx_temp, __pyx_t_2);
      }
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_r = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "cupy/core/_routines_indexing.pyx":65
 *         count_nonzero = int(scan_index[-1])  # synchronize!
 *     ndim = max(<int>self._shape.size(), 1)
 *     if count_nonzero == 0:             # <<<<<<<<<<<<<<
 *         return (ndarray((0,), dtype=dtype),) * ndim
 * 
 */
  }

  /* "cupy/core/_routines_indexing.pyx":68
 *         return (ndarray((0,), dtype=dtype),) * ndim
 * 
 *     if ndim <= 1:             # <<<<<<<<<<<<<<
 *         dst = ndarray((count_nonzero,), dtype=dtype)
 *         _nonzero_kernel_1d(nonzero, scan_index, dst)
 */
  __pyx_t_3 = ((__pyx_v_ndim <= 1) != 0);
  if (__pyx_t_3) {

    /* "cupy/core/_routines_indexing.pyx":69
 * 
 *     if ndim <= 1:
 *         dst = ndarray((count_nonzero,), dtype=dtype)             # <<<<<<<<<<<<<<
 *         _nonzero_kernel_1d(nonzero, scan_index, dst)
 *         return dst,
 */
    __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_count_nonzero); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 69, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 69, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
    __pyx_t_1 = 0;
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 69, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 69, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_dtype, __pyx_v_dtype) < 0) __PYX_ERR(0, 69, __pyx_L1_error)
    __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_4cupy_4core_4core_ndarray), __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 69, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_dst = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_7);
    __pyx_t_7 = 0;

    /* "cupy/core/_routines_indexing.pyx":70
 *     if ndim <= 1:
 *         dst = ndarray((count_nonzero,), dtype=dtype)
 *         _nonzero_kernel_1d(nonzero, scan_index, dst)             # <<<<<<<<<<<<<<
 *         return dst,
 *     else:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_nonzero_kernel_1d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 70, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (unlikely(!__pyx_v_nonzero)) { __Pyx_RaiseUnboundLocalError("nonzero"); __PYX_ERR(0, 70, __pyx_L1_error) }
    if (unlikely(!__pyx_v_scan_index)) { __Pyx_RaiseUnboundLocalError("scan_index"); __PYX_ERR(0, 70, __pyx_L1_error) }
    __pyx_t_1 = NULL;
    __pyx_t_6 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_6 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_v_nonzero, ((PyObject *)__pyx_v_scan_index), ((PyObject *)__pyx_v_dst)};
      __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 70, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_7);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_v_nonzero, ((PyObject *)__pyx_v_scan_index), ((PyObject *)__pyx_v_dst)};
      __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 70, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_7);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(3+__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 70, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (__pyx_t_1) {
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __pyx_t_1 = NULL;
      }
      __Pyx_INCREF(__pyx_v_nonzero);
      __Pyx_GIVEREF(__pyx_v_nonzero);
      PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_6, __pyx_v_nonzero);
      __Pyx_INCREF(((PyObject *)__pyx_v_scan_index));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_scan_index));
      PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_6, ((PyObject *)__pyx_v_scan_index));
      __Pyx_INCREF(((PyObject *)__pyx_v_dst));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_dst));
      PyTuple_SET_ITEM(__pyx_t_4, 2+__pyx_t_6, ((PyObject *)__pyx_v_dst));
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 70, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "cupy/core/_routines_indexing.pyx":71
 *         dst = ndarray((count_nonzero,), dtype=dtype)
 *         _nonzero_kernel_1d(nonzero, scan_index, dst)
 *         return dst,             # <<<<<<<<<<<<<<
 *     else:
 *         nonzero.shape = self.shape
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 71, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_INCREF(((PyObject *)__pyx_v_dst));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_dst));
    PyTuple_SET_ITEM(__pyx_t_7, 0, ((PyObject *)__pyx_v_dst));
    __pyx_r = ((PyObject*)__pyx_t_7);
    __pyx_t_7 = 0;
    goto __pyx_L0;

    /* "cupy/core/_routines_indexing.pyx":68
 *         return (ndarray((0,), dtype=dtype),) * ndim
 * 
 *     if ndim <= 1:             # <<<<<<<<<<<<<<
 *         dst = ndarray((count_nonzero,), dtype=dtype)
 *         _nonzero_kernel_1d(nonzero, scan_index, dst)
 */
  }

  /* "cupy/core/_routines_indexing.pyx":73
 *         return dst,
 *     else:
 *         nonzero.shape = self.shape             # <<<<<<<<<<<<<<
 *         scan_index.shape = self.shape
 *         dst = ndarray((ndim, count_nonzero), dtype=dtype)
 */
  /*else*/ {
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_shape); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 73, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (unlikely(!__pyx_v_nonzero)) { __Pyx_RaiseUnboundLocalError("nonzero"); __PYX_ERR(0, 73, __pyx_L1_error) }
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_nonzero, __pyx_n_s_shape, __pyx_t_7) < 0) __PYX_ERR(0, 73, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "cupy/core/_routines_indexing.pyx":74
 *     else:
 *         nonzero.shape = self.shape
 *         scan_index.shape = self.shape             # <<<<<<<<<<<<<<
 *         dst = ndarray((ndim, count_nonzero), dtype=dtype)
 *         _nonzero_kernel(nonzero, scan_index, dst)
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_shape); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 74, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (unlikely(!__pyx_v_scan_index)) { __Pyx_RaiseUnboundLocalError("scan_index"); __PYX_ERR(0, 74, __pyx_L1_error) }
    if (__Pyx_PyObject_SetAttrStr(((PyObject *)__pyx_v_scan_index), __pyx_n_s_shape, __pyx_t_7) < 0) __PYX_ERR(0, 74, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "cupy/core/_routines_indexing.pyx":75
 *         nonzero.shape = self.shape
 *         scan_index.shape = self.shape
 *         dst = ndarray((ndim, count_nonzero), dtype=dtype)             # <<<<<<<<<<<<<<
 *         _nonzero_kernel(nonzero, scan_index, dst)
 *         return tuple([dst[i] for i in range(ndim)])
 */
    __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_ndim); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 75, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_count_nonzero); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 75, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 75, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
    __pyx_t_7 = 0;
    __pyx_t_2 = 0;
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 75, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 75, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_v_dtype) < 0) __PYX_ERR(0, 75, __pyx_L1_error)
    __pyx_t_7 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_4cupy_4core_4core_ndarray), __pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 75, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_dst = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_7);
    __pyx_t_7 = 0;

    /* "cupy/core/_routines_indexing.pyx":76
 *         scan_index.shape = self.shape
 *         dst = ndarray((ndim, count_nonzero), dtype=dtype)
 *         _nonzero_kernel(nonzero, scan_index, dst)             # <<<<<<<<<<<<<<
 *         return tuple([dst[i] for i in range(ndim)])
 * 
 */
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_nonzero_kernel); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 76, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (unlikely(!__pyx_v_nonzero)) { __Pyx_RaiseUnboundLocalError("nonzero"); __PYX_ERR(0, 76, __pyx_L1_error) }
    if (unlikely(!__pyx_v_scan_index)) { __Pyx_RaiseUnboundLocalError("scan_index"); __PYX_ERR(0, 76, __pyx_L1_error) }
    __pyx_t_2 = NULL;
    __pyx_t_6 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
        __pyx_t_6 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_v_nonzero, ((PyObject *)__pyx_v_scan_index), ((PyObject *)__pyx_v_dst)};
      __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 76, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_7);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_v_nonzero, ((PyObject *)__pyx_v_scan_index), ((PyObject *)__pyx_v_dst)};
      __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 3+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 76, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_7);
    } else
    #endif
    {
      __pyx_t_1 = PyTuple_New(3+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 76, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (__pyx_t_2) {
        __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); __pyx_t_2 = NULL;
      }
      __Pyx_INCREF(__pyx_v_nonzero);
      __Pyx_GIVEREF(__pyx_v_nonzero);
      PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_6, __pyx_v_nonzero);
      __Pyx_INCREF(((PyObject *)__pyx_v_scan_index));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_scan_index));
      PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_6, ((PyObject *)__pyx_v_scan_index));
      __Pyx_INCREF(((PyObject *)__pyx_v_dst));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_dst));
      PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_6, ((PyObject *)__pyx_v_dst));
      __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 76, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "cupy/core/_routines_indexing.pyx":77
 *         dst = ndarray((ndim, count_nonzero), dtype=dtype)
 *         _nonzero_kernel(nonzero, scan_index, dst)
 *         return tuple([dst[i] for i in range(ndim)])             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    { /* enter inner scope */
      __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 77, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = __pyx_v_ndim;
      __pyx_t_11 = __pyx_t_6;
      for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {
        __pyx_7genexpr__pyx_v_i = __pyx_t_12;
        __pyx_t_4 = __Pyx_GetItemInt(((PyObject *)__pyx_v_dst), __pyx_7genexpr__pyx_v_i, int, 1, __Pyx_PyInt_From_int, 0, 1, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 77, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_7, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 77, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
    } /* exit inner scope */
    __pyx_t_4 = PyList_AsTuple(((PyObject*)__pyx_t_7)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 77, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_r = ((PyObject*)__pyx_t_4);
    __pyx_t_4 = 0;
    goto __pyx_L0;
  }

  /* "cupy/core/_routines_indexing.pyx":52
 * 
 * 
 * cdef tuple _ndarray_nonzero(ndarray self):             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t count_nonzero
 *     cdef int ndim
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("cupy.core._routines_indexing._ndarray_nonzero", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_dtype);
  __Pyx_XDECREF((PyObject *)__pyx_v_r);
  __Pyx_XDECREF(__pyx_v_nonzero);
  __Pyx_XDECREF((PyObject *)__pyx_v_scan_index);
  __Pyx_XDECREF((PyObject *)__pyx_v_dst);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":80
 * 
 * 
 * cdef _ndarray_scatter_add(ndarray self, slices, value):             # <<<<<<<<<<<<<<
 *     _scatter_op(self, slices, value, 'add')
 * 
 */

static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__ndarray_scatter_add(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_self, PyObject *__pyx_v_slices, PyObject *__pyx_v_value) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_ndarray_scatter_add", 0);

  /* "cupy/core/_routines_indexing.pyx":81
 * 
 * cdef _ndarray_scatter_add(ndarray self, slices, value):
 *     _scatter_op(self, slices, value, 'add')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __pyx_f_4cupy_4core_18_routines_indexing__scatter_op(__pyx_v_self, __pyx_v_slices, __pyx_v_value, __pyx_n_u_add); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 81, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":80
 * 
 * 
 * cdef _ndarray_scatter_add(ndarray self, slices, value):             # <<<<<<<<<<<<<<
 *     _scatter_op(self, slices, value, 'add')
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cupy.core._routines_indexing._ndarray_scatter_add", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":84
 * 
 * 
 * cdef _ndarray_scatter_max(ndarray self, slices, value):             # <<<<<<<<<<<<<<
 *     _scatter_op(self, slices, value, 'max')
 * 
 */

static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__ndarray_scatter_max(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_self, PyObject *__pyx_v_slices, PyObject *__pyx_v_value) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_ndarray_scatter_max", 0);

  /* "cupy/core/_routines_indexing.pyx":85
 * 
 * cdef _ndarray_scatter_max(ndarray self, slices, value):
 *     _scatter_op(self, slices, value, 'max')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __pyx_f_4cupy_4core_18_routines_indexing__scatter_op(__pyx_v_self, __pyx_v_slices, __pyx_v_value, __pyx_n_u_max); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 85, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":84
 * 
 * 
 * cdef _ndarray_scatter_max(ndarray self, slices, value):             # <<<<<<<<<<<<<<
 *     _scatter_op(self, slices, value, 'max')
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cupy.core._routines_indexing._ndarray_scatter_max", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":88
 * 
 * 
 * cdef _ndarray_scatter_min(ndarray self, slices, value):             # <<<<<<<<<<<<<<
 *     _scatter_op(self, slices, value, 'min')
 * 
 */

static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__ndarray_scatter_min(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_self, PyObject *__pyx_v_slices, PyObject *__pyx_v_value) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_ndarray_scatter_min", 0);

  /* "cupy/core/_routines_indexing.pyx":89
 * 
 * cdef _ndarray_scatter_min(ndarray self, slices, value):
 *     _scatter_op(self, slices, value, 'min')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_1 = __pyx_f_4cupy_4core_18_routines_indexing__scatter_op(__pyx_v_self, __pyx_v_slices, __pyx_v_value, __pyx_n_u_min); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":88
 * 
 * 
 * cdef _ndarray_scatter_min(ndarray self, slices, value):             # <<<<<<<<<<<<<<
 *     _scatter_op(self, slices, value, 'min')
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cupy.core._routines_indexing._ndarray_scatter_min", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":92
 * 
 * 
 * cdef ndarray _ndarray_take(ndarray self, indices, axis, out):             # <<<<<<<<<<<<<<
 *     if axis is None:
 *         return _take(self, indices, 0, self._shape.size() - 1, out)
 */

static struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_f_4cupy_4core_18_routines_indexing__ndarray_take(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_self, PyObject *__pyx_v_indices, PyObject *__pyx_v_axis, PyObject *__pyx_v_out) {
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  struct __pyx_opt_args_4cupy_4core_18_routines_indexing__take __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_ndarray_take", 0);

  /* "cupy/core/_routines_indexing.pyx":93
 * 
 * cdef ndarray _ndarray_take(ndarray self, indices, axis, out):
 *     if axis is None:             # <<<<<<<<<<<<<<
 *         return _take(self, indices, 0, self._shape.size() - 1, out)
 *     else:
 */
  __pyx_t_1 = (__pyx_v_axis == Py_None);
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "cupy/core/_routines_indexing.pyx":94
 * cdef ndarray _ndarray_take(ndarray self, indices, axis, out):
 *     if axis is None:
 *         return _take(self, indices, 0, self._shape.size() - 1, out)             # <<<<<<<<<<<<<<
 *     else:
 *         return _take(self, indices, axis, axis, out)
 */
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    if (!(likely(((__pyx_v_out) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_out, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 94, __pyx_L1_error)
    __pyx_t_4.__pyx_n = 1;
    __pyx_t_4.out = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_v_out);
    __pyx_t_3 = ((PyObject *)__pyx_f_4cupy_4core_18_routines_indexing__take(__pyx_v_self, __pyx_v_indices, 0, (__pyx_v_self->_shape.size() - 1), &__pyx_t_4)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 94, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "cupy/core/_routines_indexing.pyx":93
 * 
 * cdef ndarray _ndarray_take(ndarray self, indices, axis, out):
 *     if axis is None:             # <<<<<<<<<<<<<<
 *         return _take(self, indices, 0, self._shape.size() - 1, out)
 *     else:
 */
  }

  /* "cupy/core/_routines_indexing.pyx":96
 *         return _take(self, indices, 0, self._shape.size() - 1, out)
 *     else:
 *         return _take(self, indices, axis, axis, out)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_v_axis); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 96, __pyx_L1_error)
    __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_axis); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 96, __pyx_L1_error)
    if (!(likely(((__pyx_v_out) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_out, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 96, __pyx_L1_error)
    __pyx_t_4.__pyx_n = 1;
    __pyx_t_4.out = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_v_out);
    __pyx_t_3 = ((PyObject *)__pyx_f_4cupy_4core_18_routines_indexing__take(__pyx_v_self, __pyx_v_indices, __pyx_t_5, __pyx_t_6, &__pyx_t_4)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 96, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_r = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_3);
    __pyx_t_3 = 0;
    goto __pyx_L0;
  }

  /* "cupy/core/_routines_indexing.pyx":92
 * 
 * 
 * cdef ndarray _ndarray_take(ndarray self, indices, axis, out):             # <<<<<<<<<<<<<<
 *     if axis is None:
 *         return _take(self, indices, 0, self._shape.size() - 1, out)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_AddTraceback("cupy.core._routines_indexing._ndarray_take", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":99
 * 
 * 
 * cdef ndarray _ndarray_put(ndarray self, indices, values, mode):             # <<<<<<<<<<<<<<
 *     if mode not in ('raise', 'wrap', 'clip'):
 *         raise TypeError('clipmode not understood')
 */

static struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_f_4cupy_4core_18_routines_indexing__ndarray_put(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_self, PyObject *__pyx_v_indices, PyObject *__pyx_v_values, PyObject *__pyx_v_mode) {
  Py_ssize_t __pyx_v_n;
  PyObject *__pyx_v_err = NULL;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  struct __pyx_opt_args_4cupy_4core_4core_array __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_ndarray_put", 0);
  __Pyx_INCREF(__pyx_v_indices);
  __Pyx_INCREF(__pyx_v_values);

  /* "cupy/core/_routines_indexing.pyx":100
 * 
 * cdef ndarray _ndarray_put(ndarray self, indices, values, mode):
 *     if mode not in ('raise', 'wrap', 'clip'):             # <<<<<<<<<<<<<<
 *         raise TypeError('clipmode not understood')
 * 
 */
  __Pyx_INCREF(__pyx_v_mode);
  __pyx_t_1 = __pyx_v_mode;
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_n_u_raise, Py_NE)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 100, __pyx_L1_error)
  if (__pyx_t_3) {
  } else {
    __pyx_t_2 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_n_u_wrap, Py_NE)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 100, __pyx_L1_error)
  if (__pyx_t_3) {
  } else {
    __pyx_t_2 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_n_u_clip, Py_NE)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 100, __pyx_L1_error)
  __pyx_t_2 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = (__pyx_t_2 != 0);
  if (unlikely(__pyx_t_3)) {

    /* "cupy/core/_routines_indexing.pyx":101
 * cdef ndarray _ndarray_put(ndarray self, indices, values, mode):
 *     if mode not in ('raise', 'wrap', 'clip'):
 *         raise TypeError('clipmode not understood')             # <<<<<<<<<<<<<<
 * 
 *     n = self.size
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 101, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 101, __pyx_L1_error)

    /* "cupy/core/_routines_indexing.pyx":100
 * 
 * cdef ndarray _ndarray_put(ndarray self, indices, values, mode):
 *     if mode not in ('raise', 'wrap', 'clip'):             # <<<<<<<<<<<<<<
 *         raise TypeError('clipmode not understood')
 * 
 */
  }

  /* "cupy/core/_routines_indexing.pyx":103
 *         raise TypeError('clipmode not understood')
 * 
 *     n = self.size             # <<<<<<<<<<<<<<
 *     if not isinstance(indices, ndarray):
 *         indices = core.array(indices)
 */
  __pyx_t_4 = __pyx_v_self->size;
  __pyx_v_n = __pyx_t_4;

  /* "cupy/core/_routines_indexing.pyx":104
 * 
 *     n = self.size
 *     if not isinstance(indices, ndarray):             # <<<<<<<<<<<<<<
 *         indices = core.array(indices)
 *     indices = indices.ravel()
 */
  __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_indices, __pyx_ptype_4cupy_4core_4core_ndarray); 
  __pyx_t_2 = ((!(__pyx_t_3 != 0)) != 0);
  if (__pyx_t_2) {

    /* "cupy/core/_routines_indexing.pyx":105
 *     n = self.size
 *     if not isinstance(indices, ndarray):
 *         indices = core.array(indices)             # <<<<<<<<<<<<<<
 *     indices = indices.ravel()
 * 
 */
    __pyx_t_1 = ((PyObject *)__pyx_f_4cupy_4core_4core_array(__pyx_v_indices, 0, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 105, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_indices, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "cupy/core/_routines_indexing.pyx":104
 * 
 *     n = self.size
 *     if not isinstance(indices, ndarray):             # <<<<<<<<<<<<<<
 *         indices = core.array(indices)
 *     indices = indices.ravel()
 */
  }

  /* "cupy/core/_routines_indexing.pyx":106
 *     if not isinstance(indices, ndarray):
 *         indices = core.array(indices)
 *     indices = indices.ravel()             # <<<<<<<<<<<<<<
 * 
 *     if not isinstance(values, ndarray):
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_indices, __pyx_n_s_ravel); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 106, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF_SET(__pyx_v_indices, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":108
 *     indices = indices.ravel()
 * 
 *     if not isinstance(values, ndarray):             # <<<<<<<<<<<<<<
 *         values = core.array(values, dtype=self.dtype)
 *     if values.size == 0:
 */
  __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_values, __pyx_ptype_4cupy_4core_4core_ndarray); 
  __pyx_t_3 = ((!(__pyx_t_2 != 0)) != 0);
  if (__pyx_t_3) {

    /* "cupy/core/_routines_indexing.pyx":109
 * 
 *     if not isinstance(values, ndarray):
 *         values = core.array(values, dtype=self.dtype)             # <<<<<<<<<<<<<<
 *     if values.size == 0:
 *         return
 */
    __pyx_t_1 = __pyx_v_self->dtype;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_7.__pyx_n = 1;
    __pyx_t_7.dtype = __pyx_t_1;
    __pyx_t_5 = ((PyObject *)__pyx_f_4cupy_4core_4core_array(__pyx_v_values, 0, &__pyx_t_7)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 109, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_values, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "cupy/core/_routines_indexing.pyx":108
 *     indices = indices.ravel()
 * 
 *     if not isinstance(values, ndarray):             # <<<<<<<<<<<<<<
 *         values = core.array(values, dtype=self.dtype)
 *     if values.size == 0:
 */
  }

  /* "cupy/core/_routines_indexing.pyx":110
 *     if not isinstance(values, ndarray):
 *         values = core.array(values, dtype=self.dtype)
 *     if values.size == 0:             # <<<<<<<<<<<<<<
 *         return
 * 
 */
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_values, __pyx_n_s_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_t_5, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 110, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 110, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_3) {

    /* "cupy/core/_routines_indexing.pyx":111
 *         values = core.array(values, dtype=self.dtype)
 *     if values.size == 0:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     if mode == 'raise':
 */
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __pyx_r = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)Py_None); __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "cupy/core/_routines_indexing.pyx":110
 *     if not isinstance(values, ndarray):
 *         values = core.array(values, dtype=self.dtype)
 *     if values.size == 0:             # <<<<<<<<<<<<<<
 *         return
 * 
 */
  }

  /* "cupy/core/_routines_indexing.pyx":113
 *         return
 * 
 *     if mode == 'raise':             # <<<<<<<<<<<<<<
 *         err = cupy.zeros((), dtype=numpy.bool_)
 *         _put_raise_kernel(indices, values, values.size, n, self, err)
 */
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_mode, __pyx_n_u_raise, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 113, __pyx_L1_error)
  if (__pyx_t_3) {

    /* "cupy/core/_routines_indexing.pyx":114
 * 
 *     if mode == 'raise':
 *         err = cupy.zeros((), dtype=numpy.bool_)             # <<<<<<<<<<<<<<
 *         _put_raise_kernel(indices, values, values.size, n, self, err)
 *         if err:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_cupy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 114, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_zeros); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 114, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 114, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_numpy); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 114, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_bool); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 114, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_8) < 0) __PYX_ERR(0, 114, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__4, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 114, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_err = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":115
 *     if mode == 'raise':
 *         err = cupy.zeros((), dtype=numpy.bool_)
 *         _put_raise_kernel(indices, values, values.size, n, self, err)             # <<<<<<<<<<<<<<
 *         if err:
 *             raise IndexError('invalid entry in indices array')
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_values, __pyx_n_s_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 115, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_n); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 115, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_v_4cupy_4core_18_routines_indexing__put_raise_kernel);
    __pyx_t_6 = __pyx_v_4cupy_4core_18_routines_indexing__put_raise_kernel; __pyx_t_9 = NULL;
    __pyx_t_10 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
        __pyx_t_10 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_6)) {
      PyObject *__pyx_temp[7] = {__pyx_t_9, __pyx_v_indices, __pyx_v_values, __pyx_t_1, __pyx_t_5, ((PyObject *)__pyx_v_self), __pyx_v_err};
      __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_10, 6+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 115, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
      PyObject *__pyx_temp[7] = {__pyx_t_9, __pyx_v_indices, __pyx_v_values, __pyx_t_1, __pyx_t_5, ((PyObject *)__pyx_v_self), __pyx_v_err};
      __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_10, 6+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 115, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else
    #endif
    {
      __pyx_t_11 = PyTuple_New(6+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 115, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      if (__pyx_t_9) {
        __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_9); __pyx_t_9 = NULL;
      }
      __Pyx_INCREF(__pyx_v_indices);
      __Pyx_GIVEREF(__pyx_v_indices);
      PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_v_indices);
      __Pyx_INCREF(__pyx_v_values);
      __Pyx_GIVEREF(__pyx_v_values);
      PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_v_values);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_11, 2+__pyx_t_10, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_11, 3+__pyx_t_10, __pyx_t_5);
      __Pyx_INCREF(((PyObject *)__pyx_v_self));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_t_11, 4+__pyx_t_10, ((PyObject *)__pyx_v_self));
      __Pyx_INCREF(__pyx_v_err);
      __Pyx_GIVEREF(__pyx_v_err);
      PyTuple_SET_ITEM(__pyx_t_11, 5+__pyx_t_10, __pyx_v_err);
      __pyx_t_1 = 0;
      __pyx_t_5 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_11, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 115, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":116
 *         err = cupy.zeros((), dtype=numpy.bool_)
 *         _put_raise_kernel(indices, values, values.size, n, self, err)
 *         if err:             # <<<<<<<<<<<<<<
 *             raise IndexError('invalid entry in indices array')
 *     elif mode == 'wrap':
 */
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_err); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 116, __pyx_L1_error)
    if (unlikely(__pyx_t_3)) {

      /* "cupy/core/_routines_indexing.pyx":117
 *         _put_raise_kernel(indices, values, values.size, n, self, err)
 *         if err:
 *             raise IndexError('invalid entry in indices array')             # <<<<<<<<<<<<<<
 *     elif mode == 'wrap':
 *         _put_wrap_kernel(indices, values, values.size, n, self)
 */
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 117, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __PYX_ERR(0, 117, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":116
 *         err = cupy.zeros((), dtype=numpy.bool_)
 *         _put_raise_kernel(indices, values, values.size, n, self, err)
 *         if err:             # <<<<<<<<<<<<<<
 *             raise IndexError('invalid entry in indices array')
 *     elif mode == 'wrap':
 */
    }

    /* "cupy/core/_routines_indexing.pyx":113
 *         return
 * 
 *     if mode == 'raise':             # <<<<<<<<<<<<<<
 *         err = cupy.zeros((), dtype=numpy.bool_)
 *         _put_raise_kernel(indices, values, values.size, n, self, err)
 */
    goto __pyx_L10;
  }

  /* "cupy/core/_routines_indexing.pyx":118
 *         if err:
 *             raise IndexError('invalid entry in indices array')
 *     elif mode == 'wrap':             # <<<<<<<<<<<<<<
 *         _put_wrap_kernel(indices, values, values.size, n, self)
 *     elif mode == 'clip':
 */
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_mode, __pyx_n_u_wrap, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 118, __pyx_L1_error)
  if (__pyx_t_3) {

    /* "cupy/core/_routines_indexing.pyx":119
 *             raise IndexError('invalid entry in indices array')
 *     elif mode == 'wrap':
 *         _put_wrap_kernel(indices, values, values.size, n, self)             # <<<<<<<<<<<<<<
 *     elif mode == 'clip':
 *         _put_clip_kernel(indices, values, values.size, n, self)
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_values, __pyx_n_s_size); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 119, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_11 = PyInt_FromSsize_t(__pyx_v_n); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 119, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_INCREF(__pyx_v_4cupy_4core_18_routines_indexing__put_wrap_kernel);
    __pyx_t_5 = __pyx_v_4cupy_4core_18_routines_indexing__put_wrap_kernel; __pyx_t_1 = NULL;
    __pyx_t_10 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
        __pyx_t_10 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[6] = {__pyx_t_1, __pyx_v_indices, __pyx_v_values, __pyx_t_6, __pyx_t_11, ((PyObject *)__pyx_v_self)};
      __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_10, 5+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 119, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[6] = {__pyx_t_1, __pyx_v_indices, __pyx_v_values, __pyx_t_6, __pyx_t_11, ((PyObject *)__pyx_v_self)};
      __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_10, 5+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 119, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    } else
    #endif
    {
      __pyx_t_9 = PyTuple_New(5+__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 119, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      if (__pyx_t_1) {
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); __pyx_t_1 = NULL;
      }
      __Pyx_INCREF(__pyx_v_indices);
      __Pyx_GIVEREF(__pyx_v_indices);
      PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_10, __pyx_v_indices);
      __Pyx_INCREF(__pyx_v_values);
      __Pyx_GIVEREF(__pyx_v_values);
      PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_10, __pyx_v_values);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_9, 2+__pyx_t_10, __pyx_t_6);
      __Pyx_GIVEREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_9, 3+__pyx_t_10, __pyx_t_11);
      __Pyx_INCREF(((PyObject *)__pyx_v_self));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_t_9, 4+__pyx_t_10, ((PyObject *)__pyx_v_self));
      __pyx_t_6 = 0;
      __pyx_t_11 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 119, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":118
 *         if err:
 *             raise IndexError('invalid entry in indices array')
 *     elif mode == 'wrap':             # <<<<<<<<<<<<<<
 *         _put_wrap_kernel(indices, values, values.size, n, self)
 *     elif mode == 'clip':
 */
    goto __pyx_L10;
  }

  /* "cupy/core/_routines_indexing.pyx":120
 *     elif mode == 'wrap':
 *         _put_wrap_kernel(indices, values, values.size, n, self)
 *     elif mode == 'clip':             # <<<<<<<<<<<<<<
 *         _put_clip_kernel(indices, values, values.size, n, self)
 * 
 */
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_mode, __pyx_n_u_clip, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 120, __pyx_L1_error)
  if (__pyx_t_3) {

    /* "cupy/core/_routines_indexing.pyx":121
 *         _put_wrap_kernel(indices, values, values.size, n, self)
 *     elif mode == 'clip':
 *         _put_clip_kernel(indices, values, values.size, n, self)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_values, __pyx_n_s_size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 121, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_9 = PyInt_FromSsize_t(__pyx_v_n); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 121, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_INCREF(__pyx_v_4cupy_4core_18_routines_indexing__put_clip_kernel);
    __pyx_t_11 = __pyx_v_4cupy_4core_18_routines_indexing__put_clip_kernel; __pyx_t_6 = NULL;
    __pyx_t_10 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_11);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_11, function);
        __pyx_t_10 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_11)) {
      PyObject *__pyx_temp[6] = {__pyx_t_6, __pyx_v_indices, __pyx_v_values, __pyx_t_5, __pyx_t_9, ((PyObject *)__pyx_v_self)};
      __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 5+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 121, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
      PyObject *__pyx_temp[6] = {__pyx_t_6, __pyx_v_indices, __pyx_v_values, __pyx_t_5, __pyx_t_9, ((PyObject *)__pyx_v_self)};
      __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 5+__pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 121, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    } else
    #endif
    {
      __pyx_t_1 = PyTuple_New(5+__pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 121, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (__pyx_t_6) {
        __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_6); __pyx_t_6 = NULL;
      }
      __Pyx_INCREF(__pyx_v_indices);
      __Pyx_GIVEREF(__pyx_v_indices);
      PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_10, __pyx_v_indices);
      __Pyx_INCREF(__pyx_v_values);
      __Pyx_GIVEREF(__pyx_v_values);
      PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_10, __pyx_v_values);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_10, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_1, 3+__pyx_t_10, __pyx_t_9);
      __Pyx_INCREF(((PyObject *)__pyx_v_self));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_self));
      PyTuple_SET_ITEM(__pyx_t_1, 4+__pyx_t_10, ((PyObject *)__pyx_v_self));
      __pyx_t_5 = 0;
      __pyx_t_9 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_1, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 121, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":120
 *     elif mode == 'wrap':
 *         _put_wrap_kernel(indices, values, values.size, n, self)
 *     elif mode == 'clip':             # <<<<<<<<<<<<<<
 *         _put_clip_kernel(indices, values, values.size, n, self)
 * 
 */
  }
  __pyx_L10:;

  /* "cupy/core/_routines_indexing.pyx":99
 * 
 * 
 * cdef ndarray _ndarray_put(ndarray self, indices, values, mode):             # <<<<<<<<<<<<<<
 *     if mode not in ('raise', 'wrap', 'clip'):
 *         raise TypeError('clipmode not understood')
 */

  /* function exit code */
  __pyx_r = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)Py_None); __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_AddTraceback("cupy.core._routines_indexing._ndarray_put", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_err);
  __Pyx_XDECREF(__pyx_v_indices);
  __Pyx_XDECREF(__pyx_v_values);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":124
 * 
 * 
 * cdef ndarray _ndarray_choose(ndarray self, choices, out, mode):             # <<<<<<<<<<<<<<
 *     a = self
 *     n = choices.shape[0]
 */

static struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_f_4cupy_4core_18_routines_indexing__ndarray_choose(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_self, PyObject *__pyx_v_choices, PyObject *__pyx_v_out, PyObject *__pyx_v_mode) {
  PyObject *__pyx_v_a = NULL;
  PyObject *__pyx_v_n = NULL;
  CYTHON_UNUSED PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_v_ba = NULL;
  PyObject *__pyx_v_bcs = NULL;
  PyObject *__pyx_v_n_channel = NULL;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_ndarray_choose", 0);
  __Pyx_INCREF(__pyx_v_choices);
  __Pyx_INCREF(__pyx_v_out);

  /* "cupy/core/_routines_indexing.pyx":125
 * 
 * cdef ndarray _ndarray_choose(ndarray self, choices, out, mode):
 *     a = self             # <<<<<<<<<<<<<<
 *     n = choices.shape[0]
 * 
 */
  __Pyx_INCREF(((PyObject *)__pyx_v_self));
  __pyx_v_a = ((PyObject *)__pyx_v_self);

  /* "cupy/core/_routines_indexing.pyx":126
 * cdef ndarray _ndarray_choose(ndarray self, choices, out, mode):
 *     a = self
 *     n = choices.shape[0]             # <<<<<<<<<<<<<<
 * 
 *     # broadcast `a` and `choices[i]` for all i
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_choices, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 126, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 126, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_n = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "cupy/core/_routines_indexing.pyx":129
 * 
 *     # broadcast `a` and `choices[i]` for all i
 *     if a.ndim < choices.ndim - 1:             # <<<<<<<<<<<<<<
 *         for i in range(choices.ndim - 1 - a.ndim):
 *             a = a[None, ...]
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_a, __pyx_n_s_ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 129, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_choices, __pyx_n_s_ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_t_1, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 129, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 129, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_4) {

    /* "cupy/core/_routines_indexing.pyx":130
 *     # broadcast `a` and `choices[i]` for all i
 *     if a.ndim < choices.ndim - 1:
 *         for i in range(choices.ndim - 1 - a.ndim):             # <<<<<<<<<<<<<<
 *             a = a[None, ...]
 *     elif a.ndim > choices.ndim - 1:
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_choices, __pyx_n_s_ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 130, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_t_1, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 130, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_a, __pyx_n_s_ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 130, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyNumber_Subtract(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 130, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 130, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
      __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = 0;
      __pyx_t_6 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 130, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 130, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (;;) {
      if (likely(!__pyx_t_6)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 130, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 130, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        } else {
          if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 130, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 130, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        }
      } else {
        __pyx_t_1 = __pyx_t_6(__pyx_t_2);
        if (unlikely(!__pyx_t_1)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 130, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "cupy/core/_routines_indexing.pyx":131
 *     if a.ndim < choices.ndim - 1:
 *         for i in range(choices.ndim - 1 - a.ndim):
 *             a = a[None, ...]             # <<<<<<<<<<<<<<
 *     elif a.ndim > choices.ndim - 1:
 *         for i in range(a.ndim + 1 - choices.ndim):
 */
      __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_a, __pyx_tuple__6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 131, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF_SET(__pyx_v_a, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "cupy/core/_routines_indexing.pyx":130
 *     # broadcast `a` and `choices[i]` for all i
 *     if a.ndim < choices.ndim - 1:
 *         for i in range(choices.ndim - 1 - a.ndim):             # <<<<<<<<<<<<<<
 *             a = a[None, ...]
 *     elif a.ndim > choices.ndim - 1:
 */
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":129
 * 
 *     # broadcast `a` and `choices[i]` for all i
 *     if a.ndim < choices.ndim - 1:             # <<<<<<<<<<<<<<
 *         for i in range(choices.ndim - 1 - a.ndim):
 *             a = a[None, ...]
 */
    goto __pyx_L3;
  }

  /* "cupy/core/_routines_indexing.pyx":132
 *         for i in range(choices.ndim - 1 - a.ndim):
 *             a = a[None, ...]
 *     elif a.ndim > choices.ndim - 1:             # <<<<<<<<<<<<<<
 *         for i in range(a.ndim + 1 - choices.ndim):
 *             choices = choices[:, None, ...]
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_a, __pyx_n_s_ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 132, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_choices, __pyx_n_s_ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 132, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyInt_SubtractObjC(__pyx_t_1, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 132, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 132, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 132, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_4) {

    /* "cupy/core/_routines_indexing.pyx":133
 *             a = a[None, ...]
 *     elif a.ndim > choices.ndim - 1:
 *         for i in range(a.ndim + 1 - choices.ndim):             # <<<<<<<<<<<<<<
 *             choices = choices[:, None, ...]
 *     ba, bcs = _manipulation.broadcast(a, choices).values
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_a, __pyx_n_s_ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_choices, __pyx_n_s_ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyNumber_Subtract(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
      __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = 0;
      __pyx_t_6 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 133, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 133, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    for (;;) {
      if (likely(!__pyx_t_6)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 133, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        } else {
          if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 133, __pyx_L1_error)
          #else
          __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          #endif
        }
      } else {
        __pyx_t_1 = __pyx_t_6(__pyx_t_2);
        if (unlikely(!__pyx_t_1)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 133, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_1);
      }
      __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "cupy/core/_routines_indexing.pyx":134
 *     elif a.ndim > choices.ndim - 1:
 *         for i in range(a.ndim + 1 - choices.ndim):
 *             choices = choices[:, None, ...]             # <<<<<<<<<<<<<<
 *     ba, bcs = _manipulation.broadcast(a, choices).values
 * 
 */
      __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_choices, __pyx_tuple__8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 134, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF_SET(__pyx_v_choices, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "cupy/core/_routines_indexing.pyx":133
 *             a = a[None, ...]
 *     elif a.ndim > choices.ndim - 1:
 *         for i in range(a.ndim + 1 - choices.ndim):             # <<<<<<<<<<<<<<
 *             choices = choices[:, None, ...]
 *     ba, bcs = _manipulation.broadcast(a, choices).values
 */
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":132
 *         for i in range(choices.ndim - 1 - a.ndim):
 *             a = a[None, ...]
 *     elif a.ndim > choices.ndim - 1:             # <<<<<<<<<<<<<<
 *         for i in range(a.ndim + 1 - choices.ndim):
 *             choices = choices[:, None, ...]
 */
  }
  __pyx_L3:;

  /* "cupy/core/_routines_indexing.pyx":135
 *         for i in range(a.ndim + 1 - choices.ndim):
 *             choices = choices[:, None, ...]
 *     ba, bcs = _manipulation.broadcast(a, choices).values             # <<<<<<<<<<<<<<
 * 
 *     if out is None:
 */
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_a);
  __Pyx_GIVEREF(__pyx_v_a);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_a);
  __Pyx_INCREF(__pyx_v_choices);
  __Pyx_GIVEREF(__pyx_v_choices);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_choices);
  __pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_4cupy_4core_22_routines_manipulation_broadcast), __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 135, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = ((struct __pyx_obj_4cupy_4core_22_routines_manipulation_broadcast *)__pyx_t_1)->values;
  __Pyx_INCREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (likely(__pyx_t_2 != Py_None)) {
    PyObject* sequence = __pyx_t_2;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 135, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
    __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_3);
    #else
    __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 135, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 135, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(0, 135, __pyx_L1_error)
  }
  __pyx_v_ba = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_v_bcs = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "cupy/core/_routines_indexing.pyx":137
 *     ba, bcs = _manipulation.broadcast(a, choices).values
 * 
 *     if out is None:             # <<<<<<<<<<<<<<
 *         out = ndarray(ba.shape[1:], choices.dtype)
 * 
 */
  __pyx_t_4 = (__pyx_v_out == Py_None);
  __pyx_t_7 = (__pyx_t_4 != 0);
  if (__pyx_t_7) {

    /* "cupy/core/_routines_indexing.pyx":138
 * 
 *     if out is None:
 *         out = ndarray(ba.shape[1:], choices.dtype)             # <<<<<<<<<<<<<<
 * 
 *     n_channel = numpy.prod(bcs[0].shape)
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_ba, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 138, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetSlice(__pyx_t_2, 1, 0, NULL, NULL, &__pyx_slice__9, 1, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 138, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_choices, __pyx_n_s_dtype); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 138, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 138, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
    __pyx_t_3 = 0;
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_4cupy_4core_4core_ndarray), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 138, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF_SET(__pyx_v_out, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":137
 *     ba, bcs = _manipulation.broadcast(a, choices).values
 * 
 *     if out is None:             # <<<<<<<<<<<<<<
 *         out = ndarray(ba.shape[1:], choices.dtype)
 * 
 */
  }

  /* "cupy/core/_routines_indexing.pyx":140
 *         out = ndarray(ba.shape[1:], choices.dtype)
 * 
 *     n_channel = numpy.prod(bcs[0].shape)             # <<<<<<<<<<<<<<
 *     if mode == 'raise':
 *         if not ((a < n).all() and (0 <= a).all()):
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_numpy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 140, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_prod); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 140, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_bcs, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 140, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_shape); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 140, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_2 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_1, __pyx_t_8) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_8);
  __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 140, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_n_channel = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "cupy/core/_routines_indexing.pyx":141
 * 
 *     n_channel = numpy.prod(bcs[0].shape)
 *     if mode == 'raise':             # <<<<<<<<<<<<<<
 *         if not ((a < n).all() and (0 <= a).all()):
 *             raise ValueError('invalid entry in choice array')
 */
  __pyx_t_7 = (__Pyx_PyUnicode_Equals(__pyx_v_mode, __pyx_n_u_raise, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 141, __pyx_L1_error)
  if (__pyx_t_7) {

    /* "cupy/core/_routines_indexing.pyx":142
 *     n_channel = numpy.prod(bcs[0].shape)
 *     if mode == 'raise':
 *         if not ((a < n).all() and (0 <= a).all()):             # <<<<<<<<<<<<<<
 *             raise ValueError('invalid entry in choice array')
 *         _choose_kernel(ba[0], bcs, n_channel, out)
 */
    __pyx_t_3 = PyObject_RichCompare(__pyx_v_a, __pyx_v_n, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 142, __pyx_L1_error)
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_all); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 142, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
      }
    }
    __pyx_t_2 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_8);
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 142, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 142, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_4) {
    } else {
      __pyx_t_7 = __pyx_t_4;
      goto __pyx_L11_bool_binop_done;
    }
    __pyx_t_8 = PyObject_RichCompare(__pyx_int_0, __pyx_v_a, Py_LE); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 142, __pyx_L1_error)
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_all); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 142, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_2 = (__pyx_t_8) ? __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_8) : __Pyx_PyObject_CallNoArg(__pyx_t_3);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 142, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 142, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_7 = __pyx_t_4;
    __pyx_L11_bool_binop_done:;
    __pyx_t_4 = ((!__pyx_t_7) != 0);
    if (unlikely(__pyx_t_4)) {

      /* "cupy/core/_routines_indexing.pyx":143
 *     if mode == 'raise':
 *         if not ((a < n).all() and (0 <= a).all()):
 *             raise ValueError('invalid entry in choice array')             # <<<<<<<<<<<<<<
 *         _choose_kernel(ba[0], bcs, n_channel, out)
 *     elif mode == 'wrap':
 */
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 143, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_Raise(__pyx_t_2, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __PYX_ERR(0, 143, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":142
 *     n_channel = numpy.prod(bcs[0].shape)
 *     if mode == 'raise':
 *         if not ((a < n).all() and (0 <= a).all()):             # <<<<<<<<<<<<<<
 *             raise ValueError('invalid entry in choice array')
 *         _choose_kernel(ba[0], bcs, n_channel, out)
 */
    }

    /* "cupy/core/_routines_indexing.pyx":144
 *         if not ((a < n).all() and (0 <= a).all()):
 *             raise ValueError('invalid entry in choice array')
 *         _choose_kernel(ba[0], bcs, n_channel, out)             # <<<<<<<<<<<<<<
 *     elif mode == 'wrap':
 *         ba = ba[0] % n
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_choose_kernel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 144, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_ba, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 144, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_1 = NULL;
    __pyx_t_9 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_9 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[5] = {__pyx_t_1, __pyx_t_8, __pyx_v_bcs, __pyx_v_n_channel, __pyx_v_out};
      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_9, 4+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 144, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[5] = {__pyx_t_1, __pyx_t_8, __pyx_v_bcs, __pyx_v_n_channel, __pyx_v_out};
      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_9, 4+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 144, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    } else
    #endif
    {
      __pyx_t_10 = PyTuple_New(4+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 144, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      if (__pyx_t_1) {
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_1); __pyx_t_1 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_t_8);
      __Pyx_INCREF(__pyx_v_bcs);
      __Pyx_GIVEREF(__pyx_v_bcs);
      PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_v_bcs);
      __Pyx_INCREF(__pyx_v_n_channel);
      __Pyx_GIVEREF(__pyx_v_n_channel);
      PyTuple_SET_ITEM(__pyx_t_10, 2+__pyx_t_9, __pyx_v_n_channel);
      __Pyx_INCREF(__pyx_v_out);
      __Pyx_GIVEREF(__pyx_v_out);
      PyTuple_SET_ITEM(__pyx_t_10, 3+__pyx_t_9, __pyx_v_out);
      __pyx_t_8 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_10, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 144, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":141
 * 
 *     n_channel = numpy.prod(bcs[0].shape)
 *     if mode == 'raise':             # <<<<<<<<<<<<<<
 *         if not ((a < n).all() and (0 <= a).all()):
 *             raise ValueError('invalid entry in choice array')
 */
    goto __pyx_L9;
  }

  /* "cupy/core/_routines_indexing.pyx":145
 *             raise ValueError('invalid entry in choice array')
 *         _choose_kernel(ba[0], bcs, n_channel, out)
 *     elif mode == 'wrap':             # <<<<<<<<<<<<<<
 *         ba = ba[0] % n
 *         _choose_kernel(ba, bcs, n_channel, out)
 */
  __pyx_t_4 = (__Pyx_PyUnicode_Equals(__pyx_v_mode, __pyx_n_u_wrap, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 145, __pyx_L1_error)
  if (__pyx_t_4) {

    /* "cupy/core/_routines_indexing.pyx":146
 *         _choose_kernel(ba[0], bcs, n_channel, out)
 *     elif mode == 'wrap':
 *         ba = ba[0] % n             # <<<<<<<<<<<<<<
 *         _choose_kernel(ba, bcs, n_channel, out)
 *     elif mode == 'clip':
 */
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_ba, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 146, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PyNumber_Remainder(__pyx_t_2, __pyx_v_n); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 146, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF_SET(__pyx_v_ba, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "cupy/core/_routines_indexing.pyx":147
 *     elif mode == 'wrap':
 *         ba = ba[0] % n
 *         _choose_kernel(ba, bcs, n_channel, out)             # <<<<<<<<<<<<<<
 *     elif mode == 'clip':
 *         _choose_clip_kernel(ba[0], bcs, n_channel, n, out)
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_choose_kernel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 147, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_10 = NULL;
    __pyx_t_9 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_10)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_10);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_9 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[5] = {__pyx_t_10, __pyx_v_ba, __pyx_v_bcs, __pyx_v_n_channel, __pyx_v_out};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 4+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 147, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[5] = {__pyx_t_10, __pyx_v_ba, __pyx_v_bcs, __pyx_v_n_channel, __pyx_v_out};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 4+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 147, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else
    #endif
    {
      __pyx_t_8 = PyTuple_New(4+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 147, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      if (__pyx_t_10) {
        __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_10); __pyx_t_10 = NULL;
      }
      __Pyx_INCREF(__pyx_v_ba);
      __Pyx_GIVEREF(__pyx_v_ba);
      PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_9, __pyx_v_ba);
      __Pyx_INCREF(__pyx_v_bcs);
      __Pyx_GIVEREF(__pyx_v_bcs);
      PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_9, __pyx_v_bcs);
      __Pyx_INCREF(__pyx_v_n_channel);
      __Pyx_GIVEREF(__pyx_v_n_channel);
      PyTuple_SET_ITEM(__pyx_t_8, 2+__pyx_t_9, __pyx_v_n_channel);
      __Pyx_INCREF(__pyx_v_out);
      __Pyx_GIVEREF(__pyx_v_out);
      PyTuple_SET_ITEM(__pyx_t_8, 3+__pyx_t_9, __pyx_v_out);
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 147, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "cupy/core/_routines_indexing.pyx":145
 *             raise ValueError('invalid entry in choice array')
 *         _choose_kernel(ba[0], bcs, n_channel, out)
 *     elif mode == 'wrap':             # <<<<<<<<<<<<<<
 *         ba = ba[0] % n
 *         _choose_kernel(ba, bcs, n_channel, out)
 */
    goto __pyx_L9;
  }

  /* "cupy/core/_routines_indexing.pyx":148
 *         ba = ba[0] % n
 *         _choose_kernel(ba, bcs, n_channel, out)
 *     elif mode == 'clip':             # <<<<<<<<<<<<<<
 *         _choose_clip_kernel(ba[0], bcs, n_channel, n, out)
 *     else:
 */
  __pyx_t_4 = (__Pyx_PyUnicode_Equals(__pyx_v_mode, __pyx_n_u_clip, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 148, __pyx_L1_error)
  if (likely(__pyx_t_4)) {

    /* "cupy/core/_routines_indexing.pyx":149
 *         _choose_kernel(ba, bcs, n_channel, out)
 *     elif mode == 'clip':
 *         _choose_clip_kernel(ba[0], bcs, n_channel, n, out)             # <<<<<<<<<<<<<<
 *     else:
 *         raise TypeError('clipmode not understood')
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_choose_clip_kernel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 149, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_ba, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 149, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_10 = NULL;
    __pyx_t_9 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_10)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_10);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_9 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[6] = {__pyx_t_10, __pyx_t_8, __pyx_v_bcs, __pyx_v_n_channel, __pyx_v_n, __pyx_v_out};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 5+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 149, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[6] = {__pyx_t_10, __pyx_t_8, __pyx_v_bcs, __pyx_v_n_channel, __pyx_v_n, __pyx_v_out};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 5+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 149, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    } else
    #endif
    {
      __pyx_t_1 = PyTuple_New(5+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 149, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (__pyx_t_10) {
        __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_10); __pyx_t_10 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_9, __pyx_t_8);
      __Pyx_INCREF(__pyx_v_bcs);
      __Pyx_GIVEREF(__pyx_v_bcs);
      PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_9, __pyx_v_bcs);
      __Pyx_INCREF(__pyx_v_n_channel);
      __Pyx_GIVEREF(__pyx_v_n_channel);
      PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_9, __pyx_v_n_channel);
      __Pyx_INCREF(__pyx_v_n);
      __Pyx_GIVEREF(__pyx_v_n);
      PyTuple_SET_ITEM(__pyx_t_1, 3+__pyx_t_9, __pyx_v_n);
      __Pyx_INCREF(__pyx_v_out);
      __Pyx_GIVEREF(__pyx_v_out);
      PyTuple_SET_ITEM(__pyx_t_1, 4+__pyx_t_9, __pyx_v_out);
      __pyx_t_8 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 149, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "cupy/core/_routines_indexing.pyx":148
 *         ba = ba[0] % n
 *         _choose_kernel(ba, bcs, n_channel, out)
 *     elif mode == 'clip':             # <<<<<<<<<<<<<<
 *         _choose_clip_kernel(ba[0], bcs, n_channel, n, out)
 *     else:
 */
    goto __pyx_L9;
  }

  /* "cupy/core/_routines_indexing.pyx":151
 *         _choose_clip_kernel(ba[0], bcs, n_channel, n, out)
 *     else:
 *         raise TypeError('clipmode not understood')             # <<<<<<<<<<<<<<
 * 
 *     return out
 */
  /*else*/ {
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 151, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 151, __pyx_L1_error)
  }
  __pyx_L9:;

  /* "cupy/core/_routines_indexing.pyx":153
 *         raise TypeError('clipmode not understood')
 * 
 *     return out             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  if (!(likely(((__pyx_v_out) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_out, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 153, __pyx_L1_error)
  __Pyx_INCREF(__pyx_v_out);
  __pyx_r = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_v_out);
  goto __pyx_L0;

  /* "cupy/core/_routines_indexing.pyx":124
 * 
 * 
 * cdef ndarray _ndarray_choose(ndarray self, choices, out, mode):             # <<<<<<<<<<<<<<
 *     a = self
 *     n = choices.shape[0]
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("cupy.core._routines_indexing._ndarray_choose", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_a);
  __Pyx_XDECREF(__pyx_v_n);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XDECREF(__pyx_v_ba);
  __Pyx_XDECREF(__pyx_v_bcs);
  __Pyx_XDECREF(__pyx_v_n_channel);
  __Pyx_XDECREF(__pyx_v_choices);
  __Pyx_XDECREF(__pyx_v_out);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":156
 * 
 * 
 * cdef ndarray _ndarray_diagonal(ndarray self, offset, axis1, axis2):             # <<<<<<<<<<<<<<
 *     return _diagonal(self, offset, axis1, axis2)
 * 
 */

static struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_f_4cupy_4core_18_routines_indexing__ndarray_diagonal(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_self, PyObject *__pyx_v_offset, PyObject *__pyx_v_axis1, PyObject *__pyx_v_axis2) {
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  Py_ssize_t __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  struct __pyx_opt_args_4cupy_4core_18_routines_indexing__diagonal __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_ndarray_diagonal", 0);

  /* "cupy/core/_routines_indexing.pyx":157
 * 
 * cdef ndarray _ndarray_diagonal(ndarray self, offset, axis1, axis2):
 *     return _diagonal(self, offset, axis1, axis2)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_v_offset); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 157, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_v_axis1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 157, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyIndex_AsSsize_t(__pyx_v_axis2); if (unlikely((__pyx_t_3 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 157, __pyx_L1_error)
  __pyx_t_5.__pyx_n = 3;
  __pyx_t_5.offset = __pyx_t_1;
  __pyx_t_5.axis1 = __pyx_t_2;
  __pyx_t_5.axis2 = __pyx_t_3;
  __pyx_t_4 = ((PyObject *)__pyx_f_4cupy_4core_18_routines_indexing__diagonal(__pyx_v_self, &__pyx_t_5)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 157, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_r = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_4);
  __pyx_t_4 = 0;
  goto __pyx_L0;

  /* "cupy/core/_routines_indexing.pyx":156
 * 
 * 
 * cdef ndarray _ndarray_diagonal(ndarray self, offset, axis1, axis2):             # <<<<<<<<<<<<<<
 *     return _diagonal(self, offset, axis1, axis2)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("cupy.core._routines_indexing._ndarray_diagonal", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":163
 * 
 * 
 * cpdef tuple _prepare_slice_list(slices, Py_ssize_t ndim):             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t i, n_newaxes, axis
 *     cdef list slice_list
 */

static PyObject *__pyx_pw_4cupy_4core_18_routines_indexing_1_prepare_slice_list(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__prepare_slice_list(PyObject *__pyx_v_slices, Py_ssize_t __pyx_v_ndim, CYTHON_UNUSED int __pyx_skip_dispatch) {
  Py_ssize_t __pyx_v_i;
  Py_ssize_t __pyx_v_n_newaxes;
  PyObject *__pyx_v_slice_list = 0;
  char __pyx_v_kind;
  int __pyx_v_advanced;
  int __pyx_v_mask_exists;
  PyObject *__pyx_v_s = NULL;
  int __pyx_v_to_gpu;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  Py_ssize_t __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  long __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_prepare_slice_list", 0);

  /* "cupy/core/_routines_indexing.pyx":169
 *     cdef bint advanced, mask_exists
 * 
 *     if isinstance(slices, tuple):             # <<<<<<<<<<<<<<
 *         slice_list = list(slices)
 *     elif isinstance(slices, list):
 */
  __pyx_t_1 = PyTuple_Check(__pyx_v_slices); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "cupy/core/_routines_indexing.pyx":170
 * 
 *     if isinstance(slices, tuple):
 *         slice_list = list(slices)             # <<<<<<<<<<<<<<
 *     elif isinstance(slices, list):
 *         slice_list = list(slices)  # copy list
 */
    __pyx_t_3 = PySequence_List(__pyx_v_slices); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 170, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_slice_list = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "cupy/core/_routines_indexing.pyx":169
 *     cdef bint advanced, mask_exists
 * 
 *     if isinstance(slices, tuple):             # <<<<<<<<<<<<<<
 *         slice_list = list(slices)
 *     elif isinstance(slices, list):
 */
    goto __pyx_L3;
  }

  /* "cupy/core/_routines_indexing.pyx":171
 *     if isinstance(slices, tuple):
 *         slice_list = list(slices)
 *     elif isinstance(slices, list):             # <<<<<<<<<<<<<<
 *         slice_list = list(slices)  # copy list
 *         for s in slice_list:
 */
  __pyx_t_2 = PyList_Check(__pyx_v_slices); 
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (__pyx_t_1) {

    /* "cupy/core/_routines_indexing.pyx":172
 *         slice_list = list(slices)
 *     elif isinstance(slices, list):
 *         slice_list = list(slices)  # copy list             # <<<<<<<<<<<<<<
 *         for s in slice_list:
 *             if not isinstance(s, int):
 */
    __pyx_t_3 = PySequence_List(__pyx_v_slices); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 172, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_slice_list = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "cupy/core/_routines_indexing.pyx":173
 *     elif isinstance(slices, list):
 *         slice_list = list(slices)  # copy list
 *         for s in slice_list:             # <<<<<<<<<<<<<<
 *             if not isinstance(s, int):
 *                 break
 */
    __pyx_t_3 = __pyx_v_slice_list; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0;
    for (;;) {
      if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_5 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_5); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 173, __pyx_L1_error)
      #else
      __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 173, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      #endif
      __Pyx_XDECREF_SET(__pyx_v_s, __pyx_t_5);
      __pyx_t_5 = 0;

      /* "cupy/core/_routines_indexing.pyx":174
 *         slice_list = list(slices)  # copy list
 *         for s in slice_list:
 *             if not isinstance(s, int):             # <<<<<<<<<<<<<<
 *                 break
 *         else:
 */
      __pyx_t_1 = PyInt_Check(__pyx_v_s); 
      __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
      if (__pyx_t_2) {

        /* "cupy/core/_routines_indexing.pyx":175
 *         for s in slice_list:
 *             if not isinstance(s, int):
 *                 break             # <<<<<<<<<<<<<<
 *         else:
 *             slice_list = [slice_list]
 */
        goto __pyx_L5_break;

        /* "cupy/core/_routines_indexing.pyx":174
 *         slice_list = list(slices)  # copy list
 *         for s in slice_list:
 *             if not isinstance(s, int):             # <<<<<<<<<<<<<<
 *                 break
 *         else:
 */
      }

      /* "cupy/core/_routines_indexing.pyx":173
 *     elif isinstance(slices, list):
 *         slice_list = list(slices)  # copy list
 *         for s in slice_list:             # <<<<<<<<<<<<<<
 *             if not isinstance(s, int):
 *                 break
 */
    }
    /*else*/ {

      /* "cupy/core/_routines_indexing.pyx":177
 *                 break
 *         else:
 *             slice_list = [slice_list]             # <<<<<<<<<<<<<<
 *     else:
 *         slice_list = [slices]
 */
      __pyx_t_5 = PyList_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 177, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_v_slice_list);
      __Pyx_GIVEREF(__pyx_v_slice_list);
      PyList_SET_ITEM(__pyx_t_5, 0, __pyx_v_slice_list);
      __Pyx_DECREF_SET(__pyx_v_slice_list, ((PyObject*)__pyx_t_5));
      __pyx_t_5 = 0;
    }

    /* "cupy/core/_routines_indexing.pyx":173
 *     elif isinstance(slices, list):
 *         slice_list = list(slices)  # copy list
 *         for s in slice_list:             # <<<<<<<<<<<<<<
 *             if not isinstance(s, int):
 *                 break
 */
    __pyx_L5_break:;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "cupy/core/_routines_indexing.pyx":171
 *     if isinstance(slices, tuple):
 *         slice_list = list(slices)
 *     elif isinstance(slices, list):             # <<<<<<<<<<<<<<
 *         slice_list = list(slices)  # copy list
 *         for s in slice_list:
 */
    goto __pyx_L3;
  }

  /* "cupy/core/_routines_indexing.pyx":179
 *             slice_list = [slice_list]
 *     else:
 *         slice_list = [slices]             # <<<<<<<<<<<<<<
 * 
 *     slice_list, n_newaxes = internal.complete_slice_list(slice_list, ndim)
 */
  /*else*/ {
    __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 179, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_slices);
    __Pyx_GIVEREF(__pyx_v_slices);
    PyList_SET_ITEM(__pyx_t_3, 0, __pyx_v_slices);
    __pyx_v_slice_list = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;
  }
  __pyx_L3:;

  /* "cupy/core/_routines_indexing.pyx":181
 *         slice_list = [slices]
 * 
 *     slice_list, n_newaxes = internal.complete_slice_list(slice_list, ndim)             # <<<<<<<<<<<<<<
 * 
 *     # Check if advanced is true,
 */
  __pyx_t_3 = __pyx_f_4cupy_4core_8internal_complete_slice_list(__pyx_v_slice_list, __pyx_v_ndim, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 181, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (likely(__pyx_t_3 != Py_None)) {
    PyObject* sequence = __pyx_t_3;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 2)) {
      if (size > 2) __Pyx_RaiseTooManyValuesError(2);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 181, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); 
    __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); 
    __Pyx_INCREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_t_6);
    #else
    __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 181, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 181, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(0, 181, __pyx_L1_error)
  }
  if (!(likely(PyList_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 181, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_t_6); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 181, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF_SET(__pyx_v_slice_list, ((PyObject*)__pyx_t_5));
  __pyx_t_5 = 0;
  __pyx_v_n_newaxes = __pyx_t_4;

  /* "cupy/core/_routines_indexing.pyx":185
 *     # Check if advanced is true,
 *     # and convert list/NumPy arrays to cupy.ndarray
 *     advanced = False             # <<<<<<<<<<<<<<
 *     mask_exists = False
 *     for i, s in enumerate(slice_list):
 */
  __pyx_v_advanced = 0;

  /* "cupy/core/_routines_indexing.pyx":186
 *     # and convert list/NumPy arrays to cupy.ndarray
 *     advanced = False
 *     mask_exists = False             # <<<<<<<<<<<<<<
 *     for i, s in enumerate(slice_list):
 *         to_gpu = True
 */
  __pyx_v_mask_exists = 0;

  /* "cupy/core/_routines_indexing.pyx":187
 *     advanced = False
 *     mask_exists = False
 *     for i, s in enumerate(slice_list):             # <<<<<<<<<<<<<<
 *         to_gpu = True
 *         if isinstance(s, list):
 */
  __pyx_t_4 = 0;
  __pyx_t_3 = __pyx_v_slice_list; __Pyx_INCREF(__pyx_t_3); __pyx_t_7 = 0;
  for (;;) {
    if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_3)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_6 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_7); __Pyx_INCREF(__pyx_t_6); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 187, __pyx_L1_error)
    #else
    __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 187, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_s, __pyx_t_6);
    __pyx_t_6 = 0;
    __pyx_v_i = __pyx_t_4;
    __pyx_t_4 = (__pyx_t_4 + 1);

    /* "cupy/core/_routines_indexing.pyx":188
 *     mask_exists = False
 *     for i, s in enumerate(slice_list):
 *         to_gpu = True             # <<<<<<<<<<<<<<
 *         if isinstance(s, list):
 *             # handle the case when s is an empty list
 */
    __pyx_v_to_gpu = 1;

    /* "cupy/core/_routines_indexing.pyx":189
 *     for i, s in enumerate(slice_list):
 *         to_gpu = True
 *         if isinstance(s, list):             # <<<<<<<<<<<<<<
 *             # handle the case when s is an empty list
 *             s = numpy.array(s)
 */
    __pyx_t_2 = PyList_Check(__pyx_v_s); 
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "cupy/core/_routines_indexing.pyx":191
 *         if isinstance(s, list):
 *             # handle the case when s is an empty list
 *             s = numpy.array(s)             # <<<<<<<<<<<<<<
 *             if s.size == 0:
 *                 s = s.astype(numpy.int32)
 */
      __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_numpy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 191, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_array); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 191, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
        }
      }
      __pyx_t_6 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_5, __pyx_v_s) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_s);
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 191, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "cupy/core/_routines_indexing.pyx":192
 *             # handle the case when s is an empty list
 *             s = numpy.array(s)
 *             if s.size == 0:             # <<<<<<<<<<<<<<
 *                 s = s.astype(numpy.int32)
 *         elif isinstance(s, bool):
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_s, __pyx_n_s_size); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 192, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_8 = __Pyx_PyInt_EqObjC(__pyx_t_6, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 192, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 192, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      if (__pyx_t_1) {

        /* "cupy/core/_routines_indexing.pyx":193
 *             s = numpy.array(s)
 *             if s.size == 0:
 *                 s = s.astype(numpy.int32)             # <<<<<<<<<<<<<<
 *         elif isinstance(s, bool):
 *             s = numpy.array(s)
 */
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_s, __pyx_n_s_astype); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 193, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_numpy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 193, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_int32); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 193, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_5)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
          }
        }
        __pyx_t_8 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_9);
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 193, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_8);
        __pyx_t_8 = 0;

        /* "cupy/core/_routines_indexing.pyx":192
 *             # handle the case when s is an empty list
 *             s = numpy.array(s)
 *             if s.size == 0:             # <<<<<<<<<<<<<<
 *                 s = s.astype(numpy.int32)
 *         elif isinstance(s, bool):
 */
      }

      /* "cupy/core/_routines_indexing.pyx":189
 *     for i, s in enumerate(slice_list):
 *         to_gpu = True
 *         if isinstance(s, list):             # <<<<<<<<<<<<<<
 *             # handle the case when s is an empty list
 *             s = numpy.array(s)
 */
      goto __pyx_L10;
    }

    /* "cupy/core/_routines_indexing.pyx":194
 *             if s.size == 0:
 *                 s = s.astype(numpy.int32)
 *         elif isinstance(s, bool):             # <<<<<<<<<<<<<<
 *             s = numpy.array(s)
 *         elif isinstance(s, ndarray):
 */
    __pyx_t_8 = ((PyObject*)&PyBool_Type);
    __Pyx_INCREF(__pyx_t_8);
    __pyx_t_1 = PyObject_IsInstance(__pyx_v_s, __pyx_t_8); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 194, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_2 = (__pyx_t_1 != 0);
    if (__pyx_t_2) {

      /* "cupy/core/_routines_indexing.pyx":195
 *                 s = s.astype(numpy.int32)
 *         elif isinstance(s, bool):
 *             s = numpy.array(s)             # <<<<<<<<<<<<<<
 *         elif isinstance(s, ndarray):
 *             to_gpu = False
 */
      __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_numpy); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 195, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_array); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 195, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
        }
      }
      __pyx_t_8 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_6, __pyx_v_s) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_s);
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 195, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_8);
      __pyx_t_8 = 0;

      /* "cupy/core/_routines_indexing.pyx":194
 *             if s.size == 0:
 *                 s = s.astype(numpy.int32)
 *         elif isinstance(s, bool):             # <<<<<<<<<<<<<<
 *             s = numpy.array(s)
 *         elif isinstance(s, ndarray):
 */
      goto __pyx_L10;
    }

    /* "cupy/core/_routines_indexing.pyx":196
 *         elif isinstance(s, bool):
 *             s = numpy.array(s)
 *         elif isinstance(s, ndarray):             # <<<<<<<<<<<<<<
 *             to_gpu = False
 *         elif not isinstance(s, numpy.ndarray):
 */
    __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_s, __pyx_ptype_4cupy_4core_4core_ndarray); 
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "cupy/core/_routines_indexing.pyx":197
 *             s = numpy.array(s)
 *         elif isinstance(s, ndarray):
 *             to_gpu = False             # <<<<<<<<<<<<<<
 *         elif not isinstance(s, numpy.ndarray):
 *             continue
 */
      __pyx_v_to_gpu = 0;

      /* "cupy/core/_routines_indexing.pyx":196
 *         elif isinstance(s, bool):
 *             s = numpy.array(s)
 *         elif isinstance(s, ndarray):             # <<<<<<<<<<<<<<
 *             to_gpu = False
 *         elif not isinstance(s, numpy.ndarray):
 */
      goto __pyx_L10;
    }

    /* "cupy/core/_routines_indexing.pyx":198
 *         elif isinstance(s, ndarray):
 *             to_gpu = False
 *         elif not isinstance(s, numpy.ndarray):             # <<<<<<<<<<<<<<
 *             continue
 *         kind = ord(s.dtype.kind)
 */
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 198, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_ndarray); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 198, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_1 = PyObject_IsInstance(__pyx_v_s, __pyx_t_9); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 198, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_2 = ((!(__pyx_t_1 != 0)) != 0);
    if (__pyx_t_2) {

      /* "cupy/core/_routines_indexing.pyx":199
 *             to_gpu = False
 *         elif not isinstance(s, numpy.ndarray):
 *             continue             # <<<<<<<<<<<<<<
 *         kind = ord(s.dtype.kind)
 *         if kind == b'i' or kind == b'u':
 */
      goto __pyx_L8_continue;

      /* "cupy/core/_routines_indexing.pyx":198
 *         elif isinstance(s, ndarray):
 *             to_gpu = False
 *         elif not isinstance(s, numpy.ndarray):             # <<<<<<<<<<<<<<
 *             continue
 *         kind = ord(s.dtype.kind)
 */
    }
    __pyx_L10:;

    /* "cupy/core/_routines_indexing.pyx":200
 *         elif not isinstance(s, numpy.ndarray):
 *             continue
 *         kind = ord(s.dtype.kind)             # <<<<<<<<<<<<<<
 *         if kind == b'i' or kind == b'u':
 *             advanced = True
 */
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_s, __pyx_n_s_dtype); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 200, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_kind); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 200, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_10 = __Pyx_PyObject_Ord(__pyx_t_8); if (unlikely(__pyx_t_10 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 200, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_v_kind = __pyx_t_10;

    /* "cupy/core/_routines_indexing.pyx":201
 *             continue
 *         kind = ord(s.dtype.kind)
 *         if kind == b'i' or kind == b'u':             # <<<<<<<<<<<<<<
 *             advanced = True
 *         elif kind == b'b':
 */
    switch (__pyx_v_kind) {
      case 'i':
      case 'u':

      /* "cupy/core/_routines_indexing.pyx":202
 *         kind = ord(s.dtype.kind)
 *         if kind == b'i' or kind == b'u':
 *             advanced = True             # <<<<<<<<<<<<<<
 *         elif kind == b'b':
 *             mask_exists = True
 */
      __pyx_v_advanced = 1;

      /* "cupy/core/_routines_indexing.pyx":201
 *             continue
 *         kind = ord(s.dtype.kind)
 *         if kind == b'i' or kind == b'u':             # <<<<<<<<<<<<<<
 *             advanced = True
 *         elif kind == b'b':
 */
      break;
      case 'b':

      /* "cupy/core/_routines_indexing.pyx":204
 *             advanced = True
 *         elif kind == b'b':
 *             mask_exists = True             # <<<<<<<<<<<<<<
 *         else:
 *             raise IndexError(
 */
      __pyx_v_mask_exists = 1;

      /* "cupy/core/_routines_indexing.pyx":203
 *         if kind == b'i' or kind == b'u':
 *             advanced = True
 *         elif kind == b'b':             # <<<<<<<<<<<<<<
 *             mask_exists = True
 *         else:
 */
      break;
      default:

      /* "cupy/core/_routines_indexing.pyx":208
 *             raise IndexError(
 *                 'arrays used as indices must be of integer or boolean '
 *                 'type. (actual: {})'.format(s.dtype.type))             # <<<<<<<<<<<<<<
 *         if to_gpu:
 *             slice_list[i] = core.array(s)
 */
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_arrays_used_as_indices_must_be_o, __pyx_n_s_format); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 208, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_s, __pyx_n_s_dtype); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 208, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_type); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 208, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
        }
      }
      __pyx_t_8 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_6, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_5);
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 208, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "cupy/core/_routines_indexing.pyx":206
 *             mask_exists = True
 *         else:
 *             raise IndexError(             # <<<<<<<<<<<<<<
 *                 'arrays used as indices must be of integer or boolean '
 *                 'type. (actual: {})'.format(s.dtype.type))
 */
      __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 206, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_Raise(__pyx_t_9, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __PYX_ERR(0, 206, __pyx_L1_error)
      break;
    }

    /* "cupy/core/_routines_indexing.pyx":209
 *                 'arrays used as indices must be of integer or boolean '
 *                 'type. (actual: {})'.format(s.dtype.type))
 *         if to_gpu:             # <<<<<<<<<<<<<<
 *             slice_list[i] = core.array(s)
 * 
 */
    __pyx_t_2 = (__pyx_v_to_gpu != 0);
    if (__pyx_t_2) {

      /* "cupy/core/_routines_indexing.pyx":210
 *                 'type. (actual: {})'.format(s.dtype.type))
 *         if to_gpu:
 *             slice_list[i] = core.array(s)             # <<<<<<<<<<<<<<
 * 
 *     if not mask_exists and len(slice_list) > ndim + n_newaxes:
 */
      __pyx_t_9 = ((PyObject *)__pyx_f_4cupy_4core_4core_array(__pyx_v_s, 0, NULL)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 210, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      if (unlikely(__pyx_v_slice_list == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 210, __pyx_L1_error)
      }
      if (unlikely(__Pyx_SetItemInt(__pyx_v_slice_list, __pyx_v_i, __pyx_t_9, Py_ssize_t, 1, PyInt_FromSsize_t, 1, 1, 1) < 0)) __PYX_ERR(0, 210, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "cupy/core/_routines_indexing.pyx":209
 *                 'arrays used as indices must be of integer or boolean '
 *                 'type. (actual: {})'.format(s.dtype.type))
 *         if to_gpu:             # <<<<<<<<<<<<<<
 *             slice_list[i] = core.array(s)
 * 
 */
    }

    /* "cupy/core/_routines_indexing.pyx":187
 *     advanced = False
 *     mask_exists = False
 *     for i, s in enumerate(slice_list):             # <<<<<<<<<<<<<<
 *         to_gpu = True
 *         if isinstance(s, list):
 */
    __pyx_L8_continue:;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "cupy/core/_routines_indexing.pyx":212
 *             slice_list[i] = core.array(s)
 * 
 *     if not mask_exists and len(slice_list) > ndim + n_newaxes:             # <<<<<<<<<<<<<<
 *         raise IndexError('too many indices for array')
 *     return slice_list, advanced, mask_exists
 */
  __pyx_t_1 = ((!(__pyx_v_mask_exists != 0)) != 0);
  if (__pyx_t_1) {
  } else {
    __pyx_t_2 = __pyx_t_1;
    goto __pyx_L14_bool_binop_done;
  }
  if (unlikely(__pyx_v_slice_list == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 212, __pyx_L1_error)
  }
  __pyx_t_4 = PyList_GET_SIZE(__pyx_v_slice_list); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 212, __pyx_L1_error)
  __pyx_t_1 = ((__pyx_t_4 > (__pyx_v_ndim + __pyx_v_n_newaxes)) != 0);
  __pyx_t_2 = __pyx_t_1;
  __pyx_L14_bool_binop_done:;
  if (unlikely(__pyx_t_2)) {

    /* "cupy/core/_routines_indexing.pyx":213
 * 
 *     if not mask_exists and len(slice_list) > ndim + n_newaxes:
 *         raise IndexError('too many indices for array')             # <<<<<<<<<<<<<<
 *     return slice_list, advanced, mask_exists
 * 
 */
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 213, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 213, __pyx_L1_error)

    /* "cupy/core/_routines_indexing.pyx":212
 *             slice_list[i] = core.array(s)
 * 
 *     if not mask_exists and len(slice_list) > ndim + n_newaxes:             # <<<<<<<<<<<<<<
 *         raise IndexError('too many indices for array')
 *     return slice_list, advanced, mask_exists
 */
  }

  /* "cupy/core/_routines_indexing.pyx":214
 *     if not mask_exists and len(slice_list) > ndim + n_newaxes:
 *         raise IndexError('too many indices for array')
 *     return slice_list, advanced, mask_exists             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_v_advanced); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 214, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_9 = __Pyx_PyBool_FromLong(__pyx_v_mask_exists); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 214, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 214, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_INCREF(__pyx_v_slice_list);
  __Pyx_GIVEREF(__pyx_v_slice_list);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_slice_list);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_9);
  PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_9);
  __pyx_t_3 = 0;
  __pyx_t_9 = 0;
  __pyx_r = ((PyObject*)__pyx_t_8);
  __pyx_t_8 = 0;
  goto __pyx_L0;

  /* "cupy/core/_routines_indexing.pyx":163
 * 
 * 
 * cpdef tuple _prepare_slice_list(slices, Py_ssize_t ndim):             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t i, n_newaxes, axis
 *     cdef list slice_list
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("cupy.core._routines_indexing._prepare_slice_list", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_slice_list);
  __Pyx_XDECREF(__pyx_v_s);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_4cupy_4core_18_routines_indexing_1_prepare_slice_list(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4cupy_4core_18_routines_indexing__prepare_slice_list[] = "_prepare_slice_list(slices, Py_ssize_t ndim) -> tuple";
static PyObject *__pyx_pw_4cupy_4core_18_routines_indexing_1_prepare_slice_list(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_slices = 0;
  Py_ssize_t __pyx_v_ndim;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_prepare_slice_list (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_slices,&__pyx_n_s_ndim,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_slices)) != 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_ndim)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_prepare_slice_list", 1, 2, 2, 1); __PYX_ERR(0, 163, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_prepare_slice_list") < 0)) __PYX_ERR(0, 163, __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_slices = values[0];
    __pyx_v_ndim = __Pyx_PyIndex_AsSsize_t(values[1]); if (unlikely((__pyx_v_ndim == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 163, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_prepare_slice_list", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 163, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("cupy.core._routines_indexing._prepare_slice_list", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_4cupy_4core_18_routines_indexing__prepare_slice_list(__pyx_self, __pyx_v_slices, __pyx_v_ndim);

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

static PyObject *__pyx_pf_4cupy_4core_18_routines_indexing__prepare_slice_list(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_slices, Py_ssize_t __pyx_v_ndim) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_prepare_slice_list", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_4cupy_4core_18_routines_indexing__prepare_slice_list(__pyx_v_slices, __pyx_v_ndim, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cupy.core._routines_indexing._prepare_slice_list", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":217
 * 
 * 
 * cdef Py_ssize_t _get_mask_index(list slice_list) except *:             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t i, n_not_slice_none, mask_i
 *     cdef slice none_slice = slice(None)
 */

static Py_ssize_t __pyx_f_4cupy_4core_18_routines_indexing__get_mask_index(PyObject *__pyx_v_slice_list) {
  Py_ssize_t __pyx_v_i;
  Py_ssize_t __pyx_v_n_not_slice_none;
  Py_ssize_t __pyx_v_mask_i;
  PyObject *__pyx_v_none_slice = 0;
  PyObject *__pyx_v_s = NULL;
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_get_mask_index", 0);

  /* "cupy/core/_routines_indexing.pyx":219
 * cdef Py_ssize_t _get_mask_index(list slice_list) except *:
 *     cdef Py_ssize_t i, n_not_slice_none, mask_i
 *     cdef slice none_slice = slice(None)             # <<<<<<<<<<<<<<
 *     n_not_slice_none = 0
 *     mask_i = -1
 */
  __pyx_t_1 = __pyx_slice__7;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_none_slice = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":220
 *     cdef Py_ssize_t i, n_not_slice_none, mask_i
 *     cdef slice none_slice = slice(None)
 *     n_not_slice_none = 0             # <<<<<<<<<<<<<<
 *     mask_i = -1
 *     for i, s in enumerate(slice_list):
 */
  __pyx_v_n_not_slice_none = 0;

  /* "cupy/core/_routines_indexing.pyx":221
 *     cdef slice none_slice = slice(None)
 *     n_not_slice_none = 0
 *     mask_i = -1             # <<<<<<<<<<<<<<
 *     for i, s in enumerate(slice_list):
 *         if not isinstance(s, slice) or s != none_slice:
 */
  __pyx_v_mask_i = -1L;

  /* "cupy/core/_routines_indexing.pyx":222
 *     n_not_slice_none = 0
 *     mask_i = -1
 *     for i, s in enumerate(slice_list):             # <<<<<<<<<<<<<<
 *         if not isinstance(s, slice) or s != none_slice:
 *             n_not_slice_none += 1
 */
  __pyx_t_2 = 0;
  __pyx_t_1 = __pyx_v_slice_list; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
  for (;;) {
    if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 222, __pyx_L1_error)
    #else
    __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 222, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_s, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_v_i = __pyx_t_2;
    __pyx_t_2 = (__pyx_t_2 + 1);

    /* "cupy/core/_routines_indexing.pyx":223
 *     mask_i = -1
 *     for i, s in enumerate(slice_list):
 *         if not isinstance(s, slice) or s != none_slice:             # <<<<<<<<<<<<<<
 *             n_not_slice_none += 1
 *             if isinstance(s, ndarray) and s.dtype == numpy.bool_:
 */
    __pyx_t_6 = PySlice_Check(__pyx_v_s); 
    __pyx_t_7 = ((!(__pyx_t_6 != 0)) != 0);
    if (!__pyx_t_7) {
    } else {
      __pyx_t_5 = __pyx_t_7;
      goto __pyx_L6_bool_binop_done;
    }
    __pyx_t_4 = PyObject_RichCompare(__pyx_v_s, __pyx_v_none_slice, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 223, __pyx_L1_error)
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 223, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = __pyx_t_7;
    __pyx_L6_bool_binop_done:;
    if (__pyx_t_5) {

      /* "cupy/core/_routines_indexing.pyx":224
 *     for i, s in enumerate(slice_list):
 *         if not isinstance(s, slice) or s != none_slice:
 *             n_not_slice_none += 1             # <<<<<<<<<<<<<<
 *             if isinstance(s, ndarray) and s.dtype == numpy.bool_:
 *                 mask_i = i
 */
      __pyx_v_n_not_slice_none = (__pyx_v_n_not_slice_none + 1);

      /* "cupy/core/_routines_indexing.pyx":225
 *         if not isinstance(s, slice) or s != none_slice:
 *             n_not_slice_none += 1
 *             if isinstance(s, ndarray) and s.dtype == numpy.bool_:             # <<<<<<<<<<<<<<
 *                 mask_i = i
 *     if n_not_slice_none != 1 or mask_i == -1:
 */
      __pyx_t_7 = __Pyx_TypeCheck(__pyx_v_s, __pyx_ptype_4cupy_4core_4core_ndarray); 
      __pyx_t_6 = (__pyx_t_7 != 0);
      if (__pyx_t_6) {
      } else {
        __pyx_t_5 = __pyx_t_6;
        goto __pyx_L9_bool_binop_done;
      }
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_s, __pyx_n_s_dtype); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 225, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 225, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_bool); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 225, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = PyObject_RichCompare(__pyx_t_4, __pyx_t_9, Py_EQ); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 225, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 225, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_5 = __pyx_t_6;
      __pyx_L9_bool_binop_done:;
      if (__pyx_t_5) {

        /* "cupy/core/_routines_indexing.pyx":226
 *             n_not_slice_none += 1
 *             if isinstance(s, ndarray) and s.dtype == numpy.bool_:
 *                 mask_i = i             # <<<<<<<<<<<<<<
 *     if n_not_slice_none != 1 or mask_i == -1:
 *         raise ValueError('currently, CuPy only supports slices that '
 */
        __pyx_v_mask_i = __pyx_v_i;

        /* "cupy/core/_routines_indexing.pyx":225
 *         if not isinstance(s, slice) or s != none_slice:
 *             n_not_slice_none += 1
 *             if isinstance(s, ndarray) and s.dtype == numpy.bool_:             # <<<<<<<<<<<<<<
 *                 mask_i = i
 *     if n_not_slice_none != 1 or mask_i == -1:
 */
      }

      /* "cupy/core/_routines_indexing.pyx":223
 *     mask_i = -1
 *     for i, s in enumerate(slice_list):
 *         if not isinstance(s, slice) or s != none_slice:             # <<<<<<<<<<<<<<
 *             n_not_slice_none += 1
 *             if isinstance(s, ndarray) and s.dtype == numpy.bool_:
 */
    }

    /* "cupy/core/_routines_indexing.pyx":222
 *     n_not_slice_none = 0
 *     mask_i = -1
 *     for i, s in enumerate(slice_list):             # <<<<<<<<<<<<<<
 *         if not isinstance(s, slice) or s != none_slice:
 *             n_not_slice_none += 1
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":227
 *             if isinstance(s, ndarray) and s.dtype == numpy.bool_:
 *                 mask_i = i
 *     if n_not_slice_none != 1 or mask_i == -1:             # <<<<<<<<<<<<<<
 *         raise ValueError('currently, CuPy only supports slices that '
 *                          'consist of one boolean array.')
 */
  __pyx_t_6 = ((__pyx_v_n_not_slice_none != 1) != 0);
  if (!__pyx_t_6) {
  } else {
    __pyx_t_5 = __pyx_t_6;
    goto __pyx_L12_bool_binop_done;
  }
  __pyx_t_6 = ((__pyx_v_mask_i == -1L) != 0);
  __pyx_t_5 = __pyx_t_6;
  __pyx_L12_bool_binop_done:;
  if (unlikely(__pyx_t_5)) {

    /* "cupy/core/_routines_indexing.pyx":228
 *                 mask_i = i
 *     if n_not_slice_none != 1 or mask_i == -1:
 *         raise ValueError('currently, CuPy only supports slices that '             # <<<<<<<<<<<<<<
 *                          'consist of one boolean array.')
 *     return mask_i
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 228, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 228, __pyx_L1_error)

    /* "cupy/core/_routines_indexing.pyx":227
 *             if isinstance(s, ndarray) and s.dtype == numpy.bool_:
 *                 mask_i = i
 *     if n_not_slice_none != 1 or mask_i == -1:             # <<<<<<<<<<<<<<
 *         raise ValueError('currently, CuPy only supports slices that '
 *                          'consist of one boolean array.')
 */
  }

  /* "cupy/core/_routines_indexing.pyx":230
 *         raise ValueError('currently, CuPy only supports slices that '
 *                          'consist of one boolean array.')
 *     return mask_i             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_mask_i;
  goto __pyx_L0;

  /* "cupy/core/_routines_indexing.pyx":217
 * 
 * 
 * cdef Py_ssize_t _get_mask_index(list slice_list) except *:             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t i, n_not_slice_none, mask_i
 *     cdef slice none_slice = slice(None)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("cupy.core._routines_indexing._get_mask_index", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = -1;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_none_slice);
  __Pyx_XDECREF(__pyx_v_s);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":233
 * 
 * 
 * cdef tuple _prepare_advanced_indexing(ndarray a, list slice_list):             # <<<<<<<<<<<<<<
 *     cdef slice none_slice = slice(None)
 * 
 */

static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__prepare_advanced_indexing(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_a, PyObject *__pyx_v_slice_list) {
  PyObject *__pyx_v_none_slice = 0;
  PyObject *__pyx_v_basic_slices = 0;
  PyObject *__pyx_v_adv_slices = 0;
  PyObject *__pyx_v_adv_mask = 0;
  int __pyx_v_use_basic_indexing;
  CYTHON_UNUSED Py_ssize_t __pyx_v_i;
  PyObject *__pyx_v_s = NULL;
  PyObject *__pyx_v_kind = NULL;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_scalar_array = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_prepare_advanced_indexing", 0);
  __Pyx_INCREF((PyObject *)__pyx_v_a);

  /* "cupy/core/_routines_indexing.pyx":234
 * 
 * cdef tuple _prepare_advanced_indexing(ndarray a, list slice_list):
 *     cdef slice none_slice = slice(None)             # <<<<<<<<<<<<<<
 * 
 *     # split slices that can be handled by basic-indexing
 */
  __pyx_t_1 = __pyx_slice__7;
  __Pyx_INCREF(__pyx_t_1);
  __pyx_v_none_slice = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":237
 * 
 *     # split slices that can be handled by basic-indexing
 *     cdef list basic_slices = []             # <<<<<<<<<<<<<<
 *     cdef list adv_slices = []
 *     cdef list adv_mask = []
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 237, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_basic_slices = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":238
 *     # split slices that can be handled by basic-indexing
 *     cdef list basic_slices = []
 *     cdef list adv_slices = []             # <<<<<<<<<<<<<<
 *     cdef list adv_mask = []
 *     cdef bint use_basic_indexing = False
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 238, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_adv_slices = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":239
 *     cdef list basic_slices = []
 *     cdef list adv_slices = []
 *     cdef list adv_mask = []             # <<<<<<<<<<<<<<
 *     cdef bint use_basic_indexing = False
 *     for i, s in enumerate(slice_list):
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 239, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_adv_mask = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":240
 *     cdef list adv_slices = []
 *     cdef list adv_mask = []
 *     cdef bint use_basic_indexing = False             # <<<<<<<<<<<<<<
 *     for i, s in enumerate(slice_list):
 *         if s is None:
 */
  __pyx_v_use_basic_indexing = 0;

  /* "cupy/core/_routines_indexing.pyx":241
 *     cdef list adv_mask = []
 *     cdef bint use_basic_indexing = False
 *     for i, s in enumerate(slice_list):             # <<<<<<<<<<<<<<
 *         if s is None:
 *             basic_slices.append(None)
 */
  __pyx_t_2 = 0;
  __pyx_t_1 = __pyx_v_slice_list; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
  for (;;) {
    if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 241, __pyx_L1_error)
    #else
    __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 241, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_s, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_v_i = __pyx_t_2;
    __pyx_t_2 = (__pyx_t_2 + 1);

    /* "cupy/core/_routines_indexing.pyx":242
 *     cdef bint use_basic_indexing = False
 *     for i, s in enumerate(slice_list):
 *         if s is None:             # <<<<<<<<<<<<<<
 *             basic_slices.append(None)
 *             adv_slices.append(none_slice)
 */
    __pyx_t_5 = (__pyx_v_s == Py_None);
    __pyx_t_6 = (__pyx_t_5 != 0);
    if (__pyx_t_6) {

      /* "cupy/core/_routines_indexing.pyx":243
 *     for i, s in enumerate(slice_list):
 *         if s is None:
 *             basic_slices.append(None)             # <<<<<<<<<<<<<<
 *             adv_slices.append(none_slice)
 *             adv_mask.append(False)
 */
      __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_basic_slices, Py_None); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 243, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":244
 *         if s is None:
 *             basic_slices.append(None)
 *             adv_slices.append(none_slice)             # <<<<<<<<<<<<<<
 *             adv_mask.append(False)
 *             use_basic_indexing = True
 */
      __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_adv_slices, __pyx_v_none_slice); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 244, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":245
 *             basic_slices.append(None)
 *             adv_slices.append(none_slice)
 *             adv_mask.append(False)             # <<<<<<<<<<<<<<
 *             use_basic_indexing = True
 *         elif isinstance(s, slice):
 */
      __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_adv_mask, Py_False); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 245, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":246
 *             adv_slices.append(none_slice)
 *             adv_mask.append(False)
 *             use_basic_indexing = True             # <<<<<<<<<<<<<<
 *         elif isinstance(s, slice):
 *             basic_slices.append(s)
 */
      __pyx_v_use_basic_indexing = 1;

      /* "cupy/core/_routines_indexing.pyx":242
 *     cdef bint use_basic_indexing = False
 *     for i, s in enumerate(slice_list):
 *         if s is None:             # <<<<<<<<<<<<<<
 *             basic_slices.append(None)
 *             adv_slices.append(none_slice)
 */
      goto __pyx_L5;
    }

    /* "cupy/core/_routines_indexing.pyx":247
 *             adv_mask.append(False)
 *             use_basic_indexing = True
 *         elif isinstance(s, slice):             # <<<<<<<<<<<<<<
 *             basic_slices.append(s)
 *             adv_slices.append(none_slice)
 */
    __pyx_t_6 = PySlice_Check(__pyx_v_s); 
    __pyx_t_5 = (__pyx_t_6 != 0);
    if (__pyx_t_5) {

      /* "cupy/core/_routines_indexing.pyx":248
 *             use_basic_indexing = True
 *         elif isinstance(s, slice):
 *             basic_slices.append(s)             # <<<<<<<<<<<<<<
 *             adv_slices.append(none_slice)
 *             adv_mask.append(False)
 */
      __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_basic_slices, __pyx_v_s); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 248, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":249
 *         elif isinstance(s, slice):
 *             basic_slices.append(s)
 *             adv_slices.append(none_slice)             # <<<<<<<<<<<<<<
 *             adv_mask.append(False)
 *             use_basic_indexing |= s != none_slice
 */
      __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_adv_slices, __pyx_v_none_slice); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 249, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":250
 *             basic_slices.append(s)
 *             adv_slices.append(none_slice)
 *             adv_mask.append(False)             # <<<<<<<<<<<<<<
 *             use_basic_indexing |= s != none_slice
 *         elif isinstance(s, ndarray):
 */
      __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_adv_mask, Py_False); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 250, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":251
 *             adv_slices.append(none_slice)
 *             adv_mask.append(False)
 *             use_basic_indexing |= s != none_slice             # <<<<<<<<<<<<<<
 *         elif isinstance(s, ndarray):
 *             kind = s.dtype.kind
 */
      __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_v_use_basic_indexing); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 251, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_8 = PyObject_RichCompare(__pyx_v_s, __pyx_v_none_slice, Py_NE); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 251, __pyx_L1_error)
      __pyx_t_9 = PyNumber_InPlaceOr(__pyx_t_4, __pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 251, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 251, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_v_use_basic_indexing = __pyx_t_5;

      /* "cupy/core/_routines_indexing.pyx":247
 *             adv_mask.append(False)
 *             use_basic_indexing = True
 *         elif isinstance(s, slice):             # <<<<<<<<<<<<<<
 *             basic_slices.append(s)
 *             adv_slices.append(none_slice)
 */
      goto __pyx_L5;
    }

    /* "cupy/core/_routines_indexing.pyx":252
 *             adv_mask.append(False)
 *             use_basic_indexing |= s != none_slice
 *         elif isinstance(s, ndarray):             # <<<<<<<<<<<<<<
 *             kind = s.dtype.kind
 *             assert kind == 'i' or kind == 'u'
 */
    __pyx_t_5 = __Pyx_TypeCheck(__pyx_v_s, __pyx_ptype_4cupy_4core_4core_ndarray); 
    __pyx_t_6 = (__pyx_t_5 != 0);
    if (__pyx_t_6) {

      /* "cupy/core/_routines_indexing.pyx":253
 *             use_basic_indexing |= s != none_slice
 *         elif isinstance(s, ndarray):
 *             kind = s.dtype.kind             # <<<<<<<<<<<<<<
 *             assert kind == 'i' or kind == 'u'
 *             basic_slices.append(none_slice)
 */
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_s, __pyx_n_s_dtype); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 253, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_kind); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 253, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_XDECREF_SET(__pyx_v_kind, __pyx_t_8);
      __pyx_t_8 = 0;

      /* "cupy/core/_routines_indexing.pyx":254
 *         elif isinstance(s, ndarray):
 *             kind = s.dtype.kind
 *             assert kind == 'i' or kind == 'u'             # <<<<<<<<<<<<<<
 *             basic_slices.append(none_slice)
 *             adv_slices.append(s)
 */
      #ifndef CYTHON_WITHOUT_ASSERTIONS
      if (unlikely(!Py_OptimizeFlag)) {
        __pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_v_kind, __pyx_n_u_i, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 254, __pyx_L1_error)
        if (!__pyx_t_5) {
        } else {
          __pyx_t_6 = __pyx_t_5;
          goto __pyx_L6_bool_binop_done;
        }
        __pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_v_kind, __pyx_n_u_u, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 254, __pyx_L1_error)
        __pyx_t_6 = __pyx_t_5;
        __pyx_L6_bool_binop_done:;
        if (unlikely(!__pyx_t_6)) {
          PyErr_SetNone(PyExc_AssertionError);
          __PYX_ERR(0, 254, __pyx_L1_error)
        }
      }
      #endif

      /* "cupy/core/_routines_indexing.pyx":255
 *             kind = s.dtype.kind
 *             assert kind == 'i' or kind == 'u'
 *             basic_slices.append(none_slice)             # <<<<<<<<<<<<<<
 *             adv_slices.append(s)
 *             adv_mask.append(True)
 */
      __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_basic_slices, __pyx_v_none_slice); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 255, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":256
 *             assert kind == 'i' or kind == 'u'
 *             basic_slices.append(none_slice)
 *             adv_slices.append(s)             # <<<<<<<<<<<<<<
 *             adv_mask.append(True)
 *         elif isinstance(s, int):
 */
      __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_adv_slices, __pyx_v_s); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 256, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":257
 *             basic_slices.append(none_slice)
 *             adv_slices.append(s)
 *             adv_mask.append(True)             # <<<<<<<<<<<<<<
 *         elif isinstance(s, int):
 *             basic_slices.append(none_slice)
 */
      __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_adv_mask, Py_True); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 257, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":252
 *             adv_mask.append(False)
 *             use_basic_indexing |= s != none_slice
 *         elif isinstance(s, ndarray):             # <<<<<<<<<<<<<<
 *             kind = s.dtype.kind
 *             assert kind == 'i' or kind == 'u'
 */
      goto __pyx_L5;
    }

    /* "cupy/core/_routines_indexing.pyx":258
 *             adv_slices.append(s)
 *             adv_mask.append(True)
 *         elif isinstance(s, int):             # <<<<<<<<<<<<<<
 *             basic_slices.append(none_slice)
 *             scalar_array = ndarray((), dtype=numpy.int64)
 */
    __pyx_t_6 = PyInt_Check(__pyx_v_s); 
    __pyx_t_5 = (__pyx_t_6 != 0);
    if (likely(__pyx_t_5)) {

      /* "cupy/core/_routines_indexing.pyx":259
 *             adv_mask.append(True)
 *         elif isinstance(s, int):
 *             basic_slices.append(none_slice)             # <<<<<<<<<<<<<<
 *             scalar_array = ndarray((), dtype=numpy.int64)
 *             scalar_array.fill(s)
 */
      __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_basic_slices, __pyx_v_none_slice); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 259, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":260
 *         elif isinstance(s, int):
 *             basic_slices.append(none_slice)
 *             scalar_array = ndarray((), dtype=numpy.int64)             # <<<<<<<<<<<<<<
 *             scalar_array.fill(s)
 *             adv_slices.append(scalar_array)
 */
      __pyx_t_8 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 260, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_numpy); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 260, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_int64); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 260, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_dtype, __pyx_t_4) < 0) __PYX_ERR(0, 260, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_4cupy_4core_4core_ndarray), __pyx_tuple__4, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 260, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_XDECREF_SET(__pyx_v_scalar_array, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_4));
      __pyx_t_4 = 0;

      /* "cupy/core/_routines_indexing.pyx":261
 *             basic_slices.append(none_slice)
 *             scalar_array = ndarray((), dtype=numpy.int64)
 *             scalar_array.fill(s)             # <<<<<<<<<<<<<<
 *             adv_slices.append(scalar_array)
 *             adv_mask.append(True)
 */
      __pyx_t_4 = ((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)__pyx_v_scalar_array->__pyx_vtab)->fill(__pyx_v_scalar_array, __pyx_v_s, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 261, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "cupy/core/_routines_indexing.pyx":262
 *             scalar_array = ndarray((), dtype=numpy.int64)
 *             scalar_array.fill(s)
 *             adv_slices.append(scalar_array)             # <<<<<<<<<<<<<<
 *             adv_mask.append(True)
 *         else:
 */
      __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_adv_slices, ((PyObject *)__pyx_v_scalar_array)); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 262, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":263
 *             scalar_array.fill(s)
 *             adv_slices.append(scalar_array)
 *             adv_mask.append(True)             # <<<<<<<<<<<<<<
 *         else:
 *             raise IndexError(
 */
      __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_adv_mask, Py_True); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 263, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":258
 *             adv_slices.append(s)
 *             adv_mask.append(True)
 *         elif isinstance(s, int):             # <<<<<<<<<<<<<<
 *             basic_slices.append(none_slice)
 *             scalar_array = ndarray((), dtype=numpy.int64)
 */
      goto __pyx_L5;
    }

    /* "cupy/core/_routines_indexing.pyx":265
 *             adv_mask.append(True)
 *         else:
 *             raise IndexError(             # <<<<<<<<<<<<<<
 *                 'only integers, slices (`:`), ellipsis (`...`),'
 *                 'numpy.newaxis (`None`) and integer or '
 */
    /*else*/ {
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 265, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_Raise(__pyx_t_4, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __PYX_ERR(0, 265, __pyx_L1_error)
    }
    __pyx_L5:;

    /* "cupy/core/_routines_indexing.pyx":241
 *     cdef list adv_mask = []
 *     cdef bint use_basic_indexing = False
 *     for i, s in enumerate(slice_list):             # <<<<<<<<<<<<<<
 *         if s is None:
 *             basic_slices.append(None)
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":271
 * 
 *     # check if this is a combination of basic and advanced indexing
 *     if use_basic_indexing:             # <<<<<<<<<<<<<<
 *         a = _simple_getitem(a, basic_slices)
 * 
 */
  __pyx_t_5 = (__pyx_v_use_basic_indexing != 0);
  if (__pyx_t_5) {

    /* "cupy/core/_routines_indexing.pyx":272
 *     # check if this is a combination of basic and advanced indexing
 *     if use_basic_indexing:
 *         a = _simple_getitem(a, basic_slices)             # <<<<<<<<<<<<<<
 * 
 *     return a, adv_slices, adv_mask
 */
    __pyx_t_1 = ((PyObject *)__pyx_f_4cupy_4core_18_routines_indexing__simple_getitem(__pyx_v_a, __pyx_v_basic_slices)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 272, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_a, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "cupy/core/_routines_indexing.pyx":271
 * 
 *     # check if this is a combination of basic and advanced indexing
 *     if use_basic_indexing:             # <<<<<<<<<<<<<<
 *         a = _simple_getitem(a, basic_slices)
 * 
 */
  }

  /* "cupy/core/_routines_indexing.pyx":274
 *         a = _simple_getitem(a, basic_slices)
 * 
 *     return a, adv_slices, adv_mask             # <<<<<<<<<<<<<<
 * 
 * cdef ndarray _simple_getitem(ndarray a, list slice_list):
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 274, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(((PyObject *)__pyx_v_a));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_a));
  PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_a));
  __Pyx_INCREF(__pyx_v_adv_slices);
  __Pyx_GIVEREF(__pyx_v_adv_slices);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_adv_slices);
  __Pyx_INCREF(__pyx_v_adv_mask);
  __Pyx_GIVEREF(__pyx_v_adv_mask);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_adv_mask);
  __pyx_r = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cupy/core/_routines_indexing.pyx":233
 * 
 * 
 * cdef tuple _prepare_advanced_indexing(ndarray a, list slice_list):             # <<<<<<<<<<<<<<
 *     cdef slice none_slice = slice(None)
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("cupy.core._routines_indexing._prepare_advanced_indexing", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_none_slice);
  __Pyx_XDECREF(__pyx_v_basic_slices);
  __Pyx_XDECREF(__pyx_v_adv_slices);
  __Pyx_XDECREF(__pyx_v_adv_mask);
  __Pyx_XDECREF(__pyx_v_s);
  __Pyx_XDECREF(__pyx_v_kind);
  __Pyx_XDECREF((PyObject *)__pyx_v_scalar_array);
  __Pyx_XDECREF((PyObject *)__pyx_v_a);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":276
 *     return a, adv_slices, adv_mask
 * 
 * cdef ndarray _simple_getitem(ndarray a, list slice_list):             # <<<<<<<<<<<<<<
 *     cdef vector.vector[Py_ssize_t] shape, strides
 *     cdef ndarray v
 */

static struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_f_4cupy_4core_18_routines_indexing__simple_getitem(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_a, PyObject *__pyx_v_slice_list) {
  std::vector<Py_ssize_t>  __pyx_v_shape;
  std::vector<Py_ssize_t>  __pyx_v_strides;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_v = 0;
  Py_ssize_t __pyx_v_i;
  Py_ssize_t __pyx_v_j;
  Py_ssize_t __pyx_v_offset;
  Py_ssize_t __pyx_v_ndim;
  Py_ssize_t __pyx_v_s_start;
  Py_ssize_t __pyx_v_s_stop;
  Py_ssize_t __pyx_v_s_step;
  Py_ssize_t __pyx_v_dim;
  Py_ssize_t __pyx_v_ind;
  PyObject *__pyx_v_ss = 0;
  PyObject *__pyx_v_s = NULL;
  PyObject *__pyx_v_msg = NULL;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  Py_UCS4 __pyx_t_10;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_simple_getitem", 0);

  /* "cupy/core/_routines_indexing.pyx":284
 * 
 *     # Create new shape and stride
 *     j = 0             # <<<<<<<<<<<<<<
 *     offset = 0
 *     ndim = a._shape.size()
 */
  __pyx_v_j = 0;

  /* "cupy/core/_routines_indexing.pyx":285
 *     # Create new shape and stride
 *     j = 0
 *     offset = 0             # <<<<<<<<<<<<<<
 *     ndim = a._shape.size()
 *     for i, s in enumerate(slice_list):
 */
  __pyx_v_offset = 0;

  /* "cupy/core/_routines_indexing.pyx":286
 *     j = 0
 *     offset = 0
 *     ndim = a._shape.size()             # <<<<<<<<<<<<<<
 *     for i, s in enumerate(slice_list):
 *         if s is None:
 */
  __pyx_v_ndim = __pyx_v_a->_shape.size();

  /* "cupy/core/_routines_indexing.pyx":287
 *     offset = 0
 *     ndim = a._shape.size()
 *     for i, s in enumerate(slice_list):             # <<<<<<<<<<<<<<
 *         if s is None:
 *             shape.push_back(1)
 */
  __pyx_t_1 = 0;
  __pyx_t_2 = __pyx_v_slice_list; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
  for (;;) {
    if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_4); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 287, __pyx_L1_error)
    #else
    __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 287, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_s, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_v_i = __pyx_t_1;
    __pyx_t_1 = (__pyx_t_1 + 1);

    /* "cupy/core/_routines_indexing.pyx":288
 *     ndim = a._shape.size()
 *     for i, s in enumerate(slice_list):
 *         if s is None:             # <<<<<<<<<<<<<<
 *             shape.push_back(1)
 *             if j < ndim:
 */
    __pyx_t_5 = (__pyx_v_s == Py_None);
    __pyx_t_6 = (__pyx_t_5 != 0);
    if (__pyx_t_6) {

      /* "cupy/core/_routines_indexing.pyx":289
 *     for i, s in enumerate(slice_list):
 *         if s is None:
 *             shape.push_back(1)             # <<<<<<<<<<<<<<
 *             if j < ndim:
 *                 strides.push_back(a._strides[j])
 */
      try {
        __pyx_v_shape.push_back(1);
      } catch(...) {
        __Pyx_CppExn2PyErr();
        __PYX_ERR(0, 289, __pyx_L1_error)
      }

      /* "cupy/core/_routines_indexing.pyx":290
 *         if s is None:
 *             shape.push_back(1)
 *             if j < ndim:             # <<<<<<<<<<<<<<
 *                 strides.push_back(a._strides[j])
 *             elif ndim > 0:
 */
      __pyx_t_6 = ((__pyx_v_j < __pyx_v_ndim) != 0);
      if (__pyx_t_6) {

        /* "cupy/core/_routines_indexing.pyx":291
 *             shape.push_back(1)
 *             if j < ndim:
 *                 strides.push_back(a._strides[j])             # <<<<<<<<<<<<<<
 *             elif ndim > 0:
 *                 strides.push_back(a._strides[ndim - 1])
 */
        try {
          __pyx_v_strides.push_back((__pyx_v_a->_strides[__pyx_v_j]));
        } catch(...) {
          __Pyx_CppExn2PyErr();
          __PYX_ERR(0, 291, __pyx_L1_error)
        }

        /* "cupy/core/_routines_indexing.pyx":290
 *         if s is None:
 *             shape.push_back(1)
 *             if j < ndim:             # <<<<<<<<<<<<<<
 *                 strides.push_back(a._strides[j])
 *             elif ndim > 0:
 */
        goto __pyx_L6;
      }

      /* "cupy/core/_routines_indexing.pyx":292
 *             if j < ndim:
 *                 strides.push_back(a._strides[j])
 *             elif ndim > 0:             # <<<<<<<<<<<<<<
 *                 strides.push_back(a._strides[ndim - 1])
 *             else:
 */
      __pyx_t_6 = ((__pyx_v_ndim > 0) != 0);
      if (__pyx_t_6) {

        /* "cupy/core/_routines_indexing.pyx":293
 *                 strides.push_back(a._strides[j])
 *             elif ndim > 0:
 *                 strides.push_back(a._strides[ndim - 1])             # <<<<<<<<<<<<<<
 *             else:
 *                 strides.push_back(a.itemsize)
 */
        try {
          __pyx_v_strides.push_back((__pyx_v_a->_strides[(__pyx_v_ndim - 1)]));
        } catch(...) {
          __Pyx_CppExn2PyErr();
          __PYX_ERR(0, 293, __pyx_L1_error)
        }

        /* "cupy/core/_routines_indexing.pyx":292
 *             if j < ndim:
 *                 strides.push_back(a._strides[j])
 *             elif ndim > 0:             # <<<<<<<<<<<<<<
 *                 strides.push_back(a._strides[ndim - 1])
 *             else:
 */
        goto __pyx_L6;
      }

      /* "cupy/core/_routines_indexing.pyx":295
 *                 strides.push_back(a._strides[ndim - 1])
 *             else:
 *                 strides.push_back(a.itemsize)             # <<<<<<<<<<<<<<
 *         elif ndim <= j:
 *             raise IndexError('too many indices for array')
 */
      /*else*/ {
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_itemsize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 295, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 295, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        try {
          __pyx_v_strides.push_back(__pyx_t_7);
        } catch(...) {
          __Pyx_CppExn2PyErr();
          __PYX_ERR(0, 295, __pyx_L1_error)
        }
      }
      __pyx_L6:;

      /* "cupy/core/_routines_indexing.pyx":288
 *     ndim = a._shape.size()
 *     for i, s in enumerate(slice_list):
 *         if s is None:             # <<<<<<<<<<<<<<
 *             shape.push_back(1)
 *             if j < ndim:
 */
      goto __pyx_L5;
    }

    /* "cupy/core/_routines_indexing.pyx":296
 *             else:
 *                 strides.push_back(a.itemsize)
 *         elif ndim <= j:             # <<<<<<<<<<<<<<
 *             raise IndexError('too many indices for array')
 *         elif isinstance(s, slice):
 */
    __pyx_t_6 = ((__pyx_v_ndim <= __pyx_v_j) != 0);
    if (unlikely(__pyx_t_6)) {

      /* "cupy/core/_routines_indexing.pyx":297
 *                 strides.push_back(a.itemsize)
 *         elif ndim <= j:
 *             raise IndexError('too many indices for array')             # <<<<<<<<<<<<<<
 *         elif isinstance(s, slice):
 *             ss = internal.complete_slice(s, a._shape[j])
 */
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 297, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_Raise(__pyx_t_4, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __PYX_ERR(0, 297, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":296
 *             else:
 *                 strides.push_back(a.itemsize)
 *         elif ndim <= j:             # <<<<<<<<<<<<<<
 *             raise IndexError('too many indices for array')
 *         elif isinstance(s, slice):
 */
    }

    /* "cupy/core/_routines_indexing.pyx":298
 *         elif ndim <= j:
 *             raise IndexError('too many indices for array')
 *         elif isinstance(s, slice):             # <<<<<<<<<<<<<<
 *             ss = internal.complete_slice(s, a._shape[j])
 *             s_start = ss.start
 */
    __pyx_t_6 = PySlice_Check(__pyx_v_s); 
    __pyx_t_5 = (__pyx_t_6 != 0);
    if (__pyx_t_5) {

      /* "cupy/core/_routines_indexing.pyx":299
 *             raise IndexError('too many indices for array')
 *         elif isinstance(s, slice):
 *             ss = internal.complete_slice(s, a._shape[j])             # <<<<<<<<<<<<<<
 *             s_start = ss.start
 *             s_stop = ss.stop
 */
      if (!(likely(PySlice_Check(__pyx_v_s))||((__pyx_v_s) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "slice", Py_TYPE(__pyx_v_s)->tp_name), 0))) __PYX_ERR(0, 299, __pyx_L1_error)
      __pyx_t_4 = __pyx_f_4cupy_4core_8internal_complete_slice(((PyObject*)__pyx_v_s), (__pyx_v_a->_shape[__pyx_v_j]), 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 299, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_XDECREF_SET(__pyx_v_ss, ((PyObject*)__pyx_t_4));
      __pyx_t_4 = 0;

      /* "cupy/core/_routines_indexing.pyx":300
 *         elif isinstance(s, slice):
 *             ss = internal.complete_slice(s, a._shape[j])
 *             s_start = ss.start             # <<<<<<<<<<<<<<
 *             s_stop = ss.stop
 *             s_step = ss.step
 */
      __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(((PySliceObject*)__pyx_v_ss)->start); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 300, __pyx_L1_error)
      __pyx_v_s_start = __pyx_t_7;

      /* "cupy/core/_routines_indexing.pyx":301
 *             ss = internal.complete_slice(s, a._shape[j])
 *             s_start = ss.start
 *             s_stop = ss.stop             # <<<<<<<<<<<<<<
 *             s_step = ss.step
 *             if s_step > 0:
 */
      __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(((PySliceObject*)__pyx_v_ss)->stop); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 301, __pyx_L1_error)
      __pyx_v_s_stop = __pyx_t_7;

      /* "cupy/core/_routines_indexing.pyx":302
 *             s_start = ss.start
 *             s_stop = ss.stop
 *             s_step = ss.step             # <<<<<<<<<<<<<<
 *             if s_step > 0:
 *                 dim = (s_stop - s_start - 1) // s_step + 1
 */
      __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(((PySliceObject*)__pyx_v_ss)->step); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 302, __pyx_L1_error)
      __pyx_v_s_step = __pyx_t_7;

      /* "cupy/core/_routines_indexing.pyx":303
 *             s_stop = ss.stop
 *             s_step = ss.step
 *             if s_step > 0:             # <<<<<<<<<<<<<<
 *                 dim = (s_stop - s_start - 1) // s_step + 1
 *             else:
 */
      __pyx_t_5 = ((__pyx_v_s_step > 0) != 0);
      if (__pyx_t_5) {

        /* "cupy/core/_routines_indexing.pyx":304
 *             s_step = ss.step
 *             if s_step > 0:
 *                 dim = (s_stop - s_start - 1) // s_step + 1             # <<<<<<<<<<<<<<
 *             else:
 *                 dim = (s_stop - s_start + 1) // s_step + 1
 */
        __pyx_t_7 = ((__pyx_v_s_stop - __pyx_v_s_start) - 1);
        if (unlikely(__pyx_v_s_step == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
          __PYX_ERR(0, 304, __pyx_L1_error)
        }
        else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_v_s_step == (Py_ssize_t)-1)  && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_7))) {
          PyErr_SetString(PyExc_OverflowError, "value too large to perform division");
          __PYX_ERR(0, 304, __pyx_L1_error)
        }
        __pyx_v_dim = (__Pyx_div_Py_ssize_t(__pyx_t_7, __pyx_v_s_step) + 1);

        /* "cupy/core/_routines_indexing.pyx":303
 *             s_stop = ss.stop
 *             s_step = ss.step
 *             if s_step > 0:             # <<<<<<<<<<<<<<
 *                 dim = (s_stop - s_start - 1) // s_step + 1
 *             else:
 */
        goto __pyx_L7;
      }

      /* "cupy/core/_routines_indexing.pyx":306
 *                 dim = (s_stop - s_start - 1) // s_step + 1
 *             else:
 *                 dim = (s_stop - s_start + 1) // s_step + 1             # <<<<<<<<<<<<<<
 * 
 *             if dim == 0:
 */
      /*else*/ {
        __pyx_t_7 = ((__pyx_v_s_stop - __pyx_v_s_start) + 1);
        if (unlikely(__pyx_v_s_step == 0)) {
          PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
          __PYX_ERR(0, 306, __pyx_L1_error)
        }
        else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_v_s_step == (Py_ssize_t)-1)  && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_t_7))) {
          PyErr_SetString(PyExc_OverflowError, "value too large to perform division");
          __PYX_ERR(0, 306, __pyx_L1_error)
        }
        __pyx_v_dim = (__Pyx_div_Py_ssize_t(__pyx_t_7, __pyx_v_s_step) + 1);
      }
      __pyx_L7:;

      /* "cupy/core/_routines_indexing.pyx":308
 *                 dim = (s_stop - s_start + 1) // s_step + 1
 * 
 *             if dim == 0:             # <<<<<<<<<<<<<<
 *                 strides.push_back(a._strides[j])
 *             else:
 */
      __pyx_t_5 = ((__pyx_v_dim == 0) != 0);
      if (__pyx_t_5) {

        /* "cupy/core/_routines_indexing.pyx":309
 * 
 *             if dim == 0:
 *                 strides.push_back(a._strides[j])             # <<<<<<<<<<<<<<
 *             else:
 *                 strides.push_back(a._strides[j] * s_step)
 */
        try {
          __pyx_v_strides.push_back((__pyx_v_a->_strides[__pyx_v_j]));
        } catch(...) {
          __Pyx_CppExn2PyErr();
          __PYX_ERR(0, 309, __pyx_L1_error)
        }

        /* "cupy/core/_routines_indexing.pyx":308
 *                 dim = (s_stop - s_start + 1) // s_step + 1
 * 
 *             if dim == 0:             # <<<<<<<<<<<<<<
 *                 strides.push_back(a._strides[j])
 *             else:
 */
        goto __pyx_L8;
      }

      /* "cupy/core/_routines_indexing.pyx":311
 *                 strides.push_back(a._strides[j])
 *             else:
 *                 strides.push_back(a._strides[j] * s_step)             # <<<<<<<<<<<<<<
 * 
 *             if s_start > 0:
 */
      /*else*/ {
        try {
          __pyx_v_strides.push_back(((__pyx_v_a->_strides[__pyx_v_j]) * __pyx_v_s_step));
        } catch(...) {
          __Pyx_CppExn2PyErr();
          __PYX_ERR(0, 311, __pyx_L1_error)
        }
      }
      __pyx_L8:;

      /* "cupy/core/_routines_indexing.pyx":313
 *                 strides.push_back(a._strides[j] * s_step)
 * 
 *             if s_start > 0:             # <<<<<<<<<<<<<<
 *                 offset += a._strides[j] * s_start
 *             shape.push_back(dim)
 */
      __pyx_t_5 = ((__pyx_v_s_start > 0) != 0);
      if (__pyx_t_5) {

        /* "cupy/core/_routines_indexing.pyx":314
 * 
 *             if s_start > 0:
 *                 offset += a._strides[j] * s_start             # <<<<<<<<<<<<<<
 *             shape.push_back(dim)
 *             j += 1
 */
        __pyx_v_offset = (__pyx_v_offset + ((__pyx_v_a->_strides[__pyx_v_j]) * __pyx_v_s_start));

        /* "cupy/core/_routines_indexing.pyx":313
 *                 strides.push_back(a._strides[j] * s_step)
 * 
 *             if s_start > 0:             # <<<<<<<<<<<<<<
 *                 offset += a._strides[j] * s_start
 *             shape.push_back(dim)
 */
      }

      /* "cupy/core/_routines_indexing.pyx":315
 *             if s_start > 0:
 *                 offset += a._strides[j] * s_start
 *             shape.push_back(dim)             # <<<<<<<<<<<<<<
 *             j += 1
 *         elif numpy.isscalar(s):
 */
      try {
        __pyx_v_shape.push_back(__pyx_v_dim);
      } catch(...) {
        __Pyx_CppExn2PyErr();
        __PYX_ERR(0, 315, __pyx_L1_error)
      }

      /* "cupy/core/_routines_indexing.pyx":316
 *                 offset += a._strides[j] * s_start
 *             shape.push_back(dim)
 *             j += 1             # <<<<<<<<<<<<<<
 *         elif numpy.isscalar(s):
 *             ind = int(s)
 */
      __pyx_v_j = (__pyx_v_j + 1);

      /* "cupy/core/_routines_indexing.pyx":298
 *         elif ndim <= j:
 *             raise IndexError('too many indices for array')
 *         elif isinstance(s, slice):             # <<<<<<<<<<<<<<
 *             ss = internal.complete_slice(s, a._shape[j])
 *             s_start = ss.start
 */
      goto __pyx_L5;
    }

    /* "cupy/core/_routines_indexing.pyx":317
 *             shape.push_back(dim)
 *             j += 1
 *         elif numpy.isscalar(s):             # <<<<<<<<<<<<<<
 *             ind = int(s)
 *             if ind < 0:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 317, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_isscalar); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 317, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_9, function);
      }
    }
    __pyx_t_4 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_8, __pyx_v_s) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_s);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 317, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 317, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (likely(__pyx_t_5)) {

      /* "cupy/core/_routines_indexing.pyx":318
 *             j += 1
 *         elif numpy.isscalar(s):
 *             ind = int(s)             # <<<<<<<<<<<<<<
 *             if ind < 0:
 *                 ind += a._shape[j]
 */
      __pyx_t_4 = __Pyx_PyNumber_Int(__pyx_v_s); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 318, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 318, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_v_ind = __pyx_t_7;

      /* "cupy/core/_routines_indexing.pyx":319
 *         elif numpy.isscalar(s):
 *             ind = int(s)
 *             if ind < 0:             # <<<<<<<<<<<<<<
 *                 ind += a._shape[j]
 *             if not (0 <= ind < a._shape[j]):
 */
      __pyx_t_5 = ((__pyx_v_ind < 0) != 0);
      if (__pyx_t_5) {

        /* "cupy/core/_routines_indexing.pyx":320
 *             ind = int(s)
 *             if ind < 0:
 *                 ind += a._shape[j]             # <<<<<<<<<<<<<<
 *             if not (0 <= ind < a._shape[j]):
 *                 msg = ('Index %s is out of bounds for axis %s with '
 */
        __pyx_v_ind = (__pyx_v_ind + (__pyx_v_a->_shape[__pyx_v_j]));

        /* "cupy/core/_routines_indexing.pyx":319
 *         elif numpy.isscalar(s):
 *             ind = int(s)
 *             if ind < 0:             # <<<<<<<<<<<<<<
 *                 ind += a._shape[j]
 *             if not (0 <= ind < a._shape[j]):
 */
      }

      /* "cupy/core/_routines_indexing.pyx":321
 *             if ind < 0:
 *                 ind += a._shape[j]
 *             if not (0 <= ind < a._shape[j]):             # <<<<<<<<<<<<<<
 *                 msg = ('Index %s is out of bounds for axis %s with '
 *                        'size %s' % (s, j, a._shape[j]))
 */
      __pyx_t_5 = (0 <= __pyx_v_ind);
      if (__pyx_t_5) {
        __pyx_t_5 = (__pyx_v_ind < (__pyx_v_a->_shape[__pyx_v_j]));
      }
      __pyx_t_6 = ((!(__pyx_t_5 != 0)) != 0);
      if (unlikely(__pyx_t_6)) {

        /* "cupy/core/_routines_indexing.pyx":322
 *                 ind += a._shape[j]
 *             if not (0 <= ind < a._shape[j]):
 *                 msg = ('Index %s is out of bounds for axis %s with '             # <<<<<<<<<<<<<<
 *                        'size %s' % (s, j, a._shape[j]))
 *                 raise IndexError(msg)
 */
        __pyx_t_4 = PyTuple_New(6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 322, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_7 = 0;
        __pyx_t_10 = 127;
        __Pyx_INCREF(__pyx_kp_u_Index);
        __pyx_t_7 += 6;
        __Pyx_GIVEREF(__pyx_kp_u_Index);
        PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_Index);

        /* "cupy/core/_routines_indexing.pyx":323
 *             if not (0 <= ind < a._shape[j]):
 *                 msg = ('Index %s is out of bounds for axis %s with '
 *                        'size %s' % (s, j, a._shape[j]))             # <<<<<<<<<<<<<<
 *                 raise IndexError(msg)
 *             offset += ind * a._strides[j]
 */
        __pyx_t_9 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_s), __pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 323, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) : __pyx_t_10;
        __pyx_t_7 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_9);
        __pyx_t_9 = 0;
        __Pyx_INCREF(__pyx_kp_u_is_out_of_bounds_for_axis);
        __pyx_t_7 += 27;
        __Pyx_GIVEREF(__pyx_kp_u_is_out_of_bounds_for_axis);
        PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u_is_out_of_bounds_for_axis);
        __pyx_t_9 = __Pyx_PyUnicode_From_Py_ssize_t(__pyx_v_j, 0, ' ', 'd'); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 323, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_7 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9);
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_9);
        __pyx_t_9 = 0;
        __Pyx_INCREF(__pyx_kp_u_with_size);
        __pyx_t_7 += 11;
        __Pyx_GIVEREF(__pyx_kp_u_with_size);
        PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_kp_u_with_size);
        __pyx_t_9 = PyInt_FromSsize_t((__pyx_v_a->_shape[__pyx_v_j])); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 323, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_8 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_t_9), __pyx_empty_unicode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 323, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __pyx_t_10 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8) > __pyx_t_10) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8) : __pyx_t_10;
        __pyx_t_7 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_4, 5, __pyx_t_8);
        __pyx_t_8 = 0;

        /* "cupy/core/_routines_indexing.pyx":322
 *                 ind += a._shape[j]
 *             if not (0 <= ind < a._shape[j]):
 *                 msg = ('Index %s is out of bounds for axis %s with '             # <<<<<<<<<<<<<<
 *                        'size %s' % (s, j, a._shape[j]))
 *                 raise IndexError(msg)
 */
        __pyx_t_8 = __Pyx_PyUnicode_Join(__pyx_t_4, 6, __pyx_t_7, __pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 322, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_v_msg = ((PyObject*)__pyx_t_8);
        __pyx_t_8 = 0;

        /* "cupy/core/_routines_indexing.pyx":324
 *                 msg = ('Index %s is out of bounds for axis %s with '
 *                        'size %s' % (s, j, a._shape[j]))
 *                 raise IndexError(msg)             # <<<<<<<<<<<<<<
 *             offset += ind * a._strides[j]
 *             j += 1
 */
        __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_IndexError, __pyx_v_msg); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 324, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_Raise(__pyx_t_8, 0, 0, 0);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __PYX_ERR(0, 324, __pyx_L1_error)

        /* "cupy/core/_routines_indexing.pyx":321
 *             if ind < 0:
 *                 ind += a._shape[j]
 *             if not (0 <= ind < a._shape[j]):             # <<<<<<<<<<<<<<
 *                 msg = ('Index %s is out of bounds for axis %s with '
 *                        'size %s' % (s, j, a._shape[j]))
 */
      }

      /* "cupy/core/_routines_indexing.pyx":325
 *                        'size %s' % (s, j, a._shape[j]))
 *                 raise IndexError(msg)
 *             offset += ind * a._strides[j]             # <<<<<<<<<<<<<<
 *             j += 1
 *         else:
 */
      __pyx_v_offset = (__pyx_v_offset + (__pyx_v_ind * (__pyx_v_a->_strides[__pyx_v_j])));

      /* "cupy/core/_routines_indexing.pyx":326
 *                 raise IndexError(msg)
 *             offset += ind * a._strides[j]
 *             j += 1             # <<<<<<<<<<<<<<
 *         else:
 *             raise TypeError('Invalid index type: %s' % type(slice_list[i]))
 */
      __pyx_v_j = (__pyx_v_j + 1);

      /* "cupy/core/_routines_indexing.pyx":317
 *             shape.push_back(dim)
 *             j += 1
 *         elif numpy.isscalar(s):             # <<<<<<<<<<<<<<
 *             ind = int(s)
 *             if ind < 0:
 */
      goto __pyx_L5;
    }

    /* "cupy/core/_routines_indexing.pyx":328
 *             j += 1
 *         else:
 *             raise TypeError('Invalid index type: %s' % type(slice_list[i]))             # <<<<<<<<<<<<<<
 * 
 *     v = a.view()
 */
    /*else*/ {
      if (unlikely(__pyx_v_slice_list == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 328, __pyx_L1_error)
      }
      __pyx_t_8 = __Pyx_GetItemInt_List(__pyx_v_slice_list, __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 1, 1, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 328, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_4 = __Pyx_PyUnicode_FormatSafe(__pyx_kp_u_Invalid_index_type_s, ((PyObject *)Py_TYPE(__pyx_t_8))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 328, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 328, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __PYX_ERR(0, 328, __pyx_L1_error)
    }
    __pyx_L5:;

    /* "cupy/core/_routines_indexing.pyx":287
 *     offset = 0
 *     ndim = a._shape.size()
 *     for i, s in enumerate(slice_list):             # <<<<<<<<<<<<<<
 *         if s is None:
 *             shape.push_back(1)
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cupy/core/_routines_indexing.pyx":330
 *             raise TypeError('Invalid index type: %s' % type(slice_list[i]))
 * 
 *     v = a.view()             # <<<<<<<<<<<<<<
 *     if a.size != 0:
 *         v.data = a.data + offset
 */
  __pyx_t_2 = ((PyObject *)((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)__pyx_v_a->__pyx_vtab)->view(__pyx_v_a, 0, NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 330, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_v = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "cupy/core/_routines_indexing.pyx":331
 * 
 *     v = a.view()
 *     if a.size != 0:             # <<<<<<<<<<<<<<
 *         v.data = a.data + offset
 *     # TODO(niboshi): Confirm update_x_contiguity flags
 */
  __pyx_t_6 = ((__pyx_v_a->size != 0) != 0);
  if (__pyx_t_6) {

    /* "cupy/core/_routines_indexing.pyx":332
 *     v = a.view()
 *     if a.size != 0:
 *         v.data = a.data + offset             # <<<<<<<<<<<<<<
 *     # TODO(niboshi): Confirm update_x_contiguity flags
 *     v._set_shape_and_strides(shape, strides, True, True)
 */
    __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_offset); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 332, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_8 = PyNumber_Add(((PyObject *)__pyx_v_a->data), __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 332, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_4cupy_4cuda_6memory_MemoryPointer))))) __PYX_ERR(0, 332, __pyx_L1_error)
    __Pyx_GIVEREF(__pyx_t_8);
    __Pyx_GOTREF(__pyx_v_v->data);
    __Pyx_DECREF(((PyObject *)__pyx_v_v->data));
    __pyx_v_v->data = ((struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer *)__pyx_t_8);
    __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":331
 * 
 *     v = a.view()
 *     if a.size != 0:             # <<<<<<<<<<<<<<
 *         v.data = a.data + offset
 *     # TODO(niboshi): Confirm update_x_contiguity flags
 */
  }

  /* "cupy/core/_routines_indexing.pyx":334
 *         v.data = a.data + offset
 *     # TODO(niboshi): Confirm update_x_contiguity flags
 *     v._set_shape_and_strides(shape, strides, True, True)             # <<<<<<<<<<<<<<
 *     return v
 * 
 */
  __pyx_t_8 = ((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)__pyx_v_v->__pyx_vtab)->_set_shape_and_strides(__pyx_v_v, __pyx_v_shape, __pyx_v_strides, 1, 1, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 334, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "cupy/core/_routines_indexing.pyx":335
 *     # TODO(niboshi): Confirm update_x_contiguity flags
 *     v._set_shape_and_strides(shape, strides, True, True)
 *     return v             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_v));
  __pyx_r = __pyx_v_v;
  goto __pyx_L0;

  /* "cupy/core/_routines_indexing.pyx":276
 *     return a, adv_slices, adv_mask
 * 
 * cdef ndarray _simple_getitem(ndarray a, list slice_list):             # <<<<<<<<<<<<<<
 *     cdef vector.vector[Py_ssize_t] shape, strides
 *     cdef ndarray v
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("cupy.core._routines_indexing._simple_getitem", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_v);
  __Pyx_XDECREF(__pyx_v_ss);
  __Pyx_XDECREF(__pyx_v_s);
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":529
 * 
 * 
 * cpdef _prepare_mask_indexing_single(ndarray a, ndarray mask, Py_ssize_t axis):             # <<<<<<<<<<<<<<
 *     cdef ndarray mask_scanned, mask_br, mask_br_scanned
 *     cdef int n_true
 */

static PyObject *__pyx_pw_4cupy_4core_18_routines_indexing_3_prepare_mask_indexing_single(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__prepare_mask_indexing_single(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_a, struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_mask, Py_ssize_t __pyx_v_axis, CYTHON_UNUSED int __pyx_skip_dispatch) {
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_mask_scanned = 0;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_mask_br = 0;
  int __pyx_v_n_true;
  PyObject *__pyx_v_lshape = 0;
  PyObject *__pyx_v_rshape = 0;
  PyObject *__pyx_v_masked_shape = NULL;
  PyObject *__pyx_v_i = NULL;
  PyObject *__pyx_v_s = NULL;
  PyObject *__pyx_v_mask_type = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  std::vector<Py_ssize_t>  __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_prepare_mask_indexing_single", 0);
  __Pyx_INCREF((PyObject *)__pyx_v_mask);

  /* "cupy/core/_routines_indexing.pyx":534
 *     cdef tuple lshape, rshape, out_shape
 * 
 *     lshape = a.shape[:axis]             # <<<<<<<<<<<<<<
 *     rshape = a.shape[axis + mask._shape.size():]
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 534, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_t_1, 0, __pyx_v_axis, NULL, NULL, NULL, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 534, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(PyTuple_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 534, __pyx_L1_error)
  __pyx_v_lshape = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "cupy/core/_routines_indexing.pyx":535
 * 
 *     lshape = a.shape[:axis]
 *     rshape = a.shape[axis + mask._shape.size():]             # <<<<<<<<<<<<<<
 * 
 *     if mask.size == 0:
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 535, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_t_2, (__pyx_v_axis + __pyx_v_mask->_shape.size()), 0, NULL, NULL, NULL, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 535, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (!(likely(PyTuple_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 535, __pyx_L1_error)
  __pyx_v_rshape = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":537
 *     rshape = a.shape[axis + mask._shape.size():]
 * 
 *     if mask.size == 0:             # <<<<<<<<<<<<<<
 *         masked_shape = lshape + (0,) + rshape
 *         mask_br = _manipulation._reshape(mask, masked_shape)
 */
  __pyx_t_3 = ((__pyx_v_mask->size == 0) != 0);
  if (__pyx_t_3) {

    /* "cupy/core/_routines_indexing.pyx":538
 * 
 *     if mask.size == 0:
 *         masked_shape = lshape + (0,) + rshape             # <<<<<<<<<<<<<<
 *         mask_br = _manipulation._reshape(mask, masked_shape)
 *         return mask_br, mask_br, masked_shape
 */
    __pyx_t_1 = PyNumber_Add(__pyx_v_lshape, __pyx_tuple_); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 538, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_v_rshape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 538, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_masked_shape = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":539
 *     if mask.size == 0:
 *         masked_shape = lshape + (0,) + rshape
 *         mask_br = _manipulation._reshape(mask, masked_shape)             # <<<<<<<<<<<<<<
 *         return mask_br, mask_br, masked_shape
 * 
 */
    __pyx_t_4 = __pyx_convert_vector_from_py_Py_ssize_t(__pyx_v_masked_shape); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 539, __pyx_L1_error)
    __pyx_t_2 = ((PyObject *)__pyx_f_4cupy_4core_22_routines_manipulation__reshape(__pyx_v_mask, __pyx_t_4, 0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 539, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_mask_br = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":540
 *         masked_shape = lshape + (0,) + rshape
 *         mask_br = _manipulation._reshape(mask, masked_shape)
 *         return mask_br, mask_br, masked_shape             # <<<<<<<<<<<<<<
 * 
 *     for i, s in enumerate(mask._shape):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 540, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_v_mask_br));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_mask_br));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_mask_br));
    __Pyx_INCREF(((PyObject *)__pyx_v_mask_br));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_mask_br));
    PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_mask_br));
    __Pyx_INCREF(__pyx_v_masked_shape);
    __Pyx_GIVEREF(__pyx_v_masked_shape);
    PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_masked_shape);
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "cupy/core/_routines_indexing.pyx":537
 *     rshape = a.shape[axis + mask._shape.size():]
 * 
 *     if mask.size == 0:             # <<<<<<<<<<<<<<
 *         masked_shape = lshape + (0,) + rshape
 *         mask_br = _manipulation._reshape(mask, masked_shape)
 */
  }

  /* "cupy/core/_routines_indexing.pyx":542
 *         return mask_br, mask_br, masked_shape
 * 
 *     for i, s in enumerate(mask._shape):             # <<<<<<<<<<<<<<
 *         if a.shape[axis + i] != s:
 *             raise IndexError('boolean index did not match')
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_t_2 = __pyx_int_0;
  __pyx_t_1 = __pyx_convert_vector_to_py_Py_ssize_t(__pyx_v_mask->_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 542, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_5 = __pyx_t_1; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0;
    __pyx_t_7 = NULL;
  } else {
    __pyx_t_6 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 542, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 542, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_7)) {
      if (likely(PyList_CheckExact(__pyx_t_5))) {
        if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 542, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 542, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_1); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 542, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 542, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_7(__pyx_t_5);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 542, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_s, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_XDECREF_SET(__pyx_v_i, __pyx_t_2);
    __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 542, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_2);
    __pyx_t_2 = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "cupy/core/_routines_indexing.pyx":543
 * 
 *     for i, s in enumerate(mask._shape):
 *         if a.shape[axis + i] != s:             # <<<<<<<<<<<<<<
 *             raise IndexError('boolean index did not match')
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 543, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_8 = PyInt_FromSsize_t(__pyx_v_axis); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 543, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = PyNumber_Add(__pyx_t_8, __pyx_v_i); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 543, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_GetItem(__pyx_t_1, __pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 543, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = PyObject_RichCompare(__pyx_t_8, __pyx_v_s, Py_NE); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 543, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 543, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(__pyx_t_3)) {

      /* "cupy/core/_routines_indexing.pyx":544
 *     for i, s in enumerate(mask._shape):
 *         if a.shape[axis + i] != s:
 *             raise IndexError('boolean index did not match')             # <<<<<<<<<<<<<<
 * 
 *     # Get number of True in the mask to determine the shape of the array
 */
      __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__14, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 544, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_Raise(__pyx_t_9, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __PYX_ERR(0, 544, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":543
 * 
 *     for i, s in enumerate(mask._shape):
 *         if a.shape[axis + i] != s:             # <<<<<<<<<<<<<<
 *             raise IndexError('boolean index did not match')
 * 
 */
    }

    /* "cupy/core/_routines_indexing.pyx":542
 *         return mask_br, mask_br, masked_shape
 * 
 *     for i, s in enumerate(mask._shape):             # <<<<<<<<<<<<<<
 *         if a.shape[axis + i] != s:
 *             raise IndexError('boolean index did not match')
 */
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cupy/core/_routines_indexing.pyx":548
 *     # Get number of True in the mask to determine the shape of the array
 *     # after masking.
 *     if mask.size <= 2 ** 31 - 1:             # <<<<<<<<<<<<<<
 *         mask_type = numpy.int32
 *     else:
 */
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_mask->size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 548, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_2, __pyx_int_2147483647, Py_LE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 548, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 548, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__pyx_t_3) {

    /* "cupy/core/_routines_indexing.pyx":549
 *     # after masking.
 *     if mask.size <= 2 ** 31 - 1:
 *         mask_type = numpy.int32             # <<<<<<<<<<<<<<
 *     else:
 *         mask_type = numpy.int64
 */
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_numpy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 549, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_int32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 549, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_mask_type = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":548
 *     # Get number of True in the mask to determine the shape of the array
 *     # after masking.
 *     if mask.size <= 2 ** 31 - 1:             # <<<<<<<<<<<<<<
 *         mask_type = numpy.int32
 *     else:
 */
    goto __pyx_L7;
  }

  /* "cupy/core/_routines_indexing.pyx":551
 *         mask_type = numpy.int32
 *     else:
 *         mask_type = numpy.int64             # <<<<<<<<<<<<<<
 *     mask_scanned = _math.scan(mask.astype(mask_type).ravel())  # starts with 1
 *     n_true = int(mask_scanned[-1])
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 551, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 551, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_mask_type = __pyx_t_5;
    __pyx_t_5 = 0;
  }
  __pyx_L7:;

  /* "cupy/core/_routines_indexing.pyx":552
 *     else:
 *         mask_type = numpy.int64
 *     mask_scanned = _math.scan(mask.astype(mask_type).ravel())  # starts with 1             # <<<<<<<<<<<<<<
 *     n_true = int(mask_scanned[-1])
 *     masked_shape = lshape + (n_true,) + rshape
 */
  __pyx_t_5 = ((PyObject *)((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)__pyx_v_mask->__pyx_vtab)->astype(__pyx_v_mask, __pyx_v_mask_type, 0, NULL)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 552, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = ((PyObject *)((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_5)->__pyx_vtab)->ravel(((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_5), 0, NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 552, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = ((PyObject *)__pyx_f_4cupy_4core_14_routines_math_scan(((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2), NULL)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 552, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_mask_scanned = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_5);
  __pyx_t_5 = 0;

  /* "cupy/core/_routines_indexing.pyx":553
 *         mask_type = numpy.int64
 *     mask_scanned = _math.scan(mask.astype(mask_type).ravel())  # starts with 1
 *     n_true = int(mask_scanned[-1])             # <<<<<<<<<<<<<<
 *     masked_shape = lshape + (n_true,) + rshape
 * 
 */
  __pyx_t_5 = __Pyx_GetItemInt(((PyObject *)__pyx_v_mask_scanned), -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 553, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = __Pyx_PyNumber_Int(__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 553, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_2); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 553, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_n_true = __pyx_t_10;

  /* "cupy/core/_routines_indexing.pyx":554
 *     mask_scanned = _math.scan(mask.astype(mask_type).ravel())  # starts with 1
 *     n_true = int(mask_scanned[-1])
 *     masked_shape = lshape + (n_true,) + rshape             # <<<<<<<<<<<<<<
 * 
 *     # When mask covers the entire array, broadcasting is not necessary.
 */
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_n_true); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 554, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 554, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyNumber_Add(__pyx_v_lshape, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 554, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyNumber_Add(__pyx_t_2, __pyx_v_rshape); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 554, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_masked_shape = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "cupy/core/_routines_indexing.pyx":557
 * 
 *     # When mask covers the entire array, broadcasting is not necessary.
 *     if mask._shape.size() == a._shape.size() and axis == 0:             # <<<<<<<<<<<<<<
 *         return (
 *             mask,
 */
  __pyx_t_11 = ((__pyx_v_mask->_shape.size() == __pyx_v_a->_shape.size()) != 0);
  if (__pyx_t_11) {
  } else {
    __pyx_t_3 = __pyx_t_11;
    goto __pyx_L9_bool_binop_done;
  }
  __pyx_t_11 = ((__pyx_v_axis == 0) != 0);
  __pyx_t_3 = __pyx_t_11;
  __pyx_L9_bool_binop_done:;
  if (__pyx_t_3) {

    /* "cupy/core/_routines_indexing.pyx":558
 *     # When mask covers the entire array, broadcasting is not necessary.
 *     if mask._shape.size() == a._shape.size() and axis == 0:
 *         return (             # <<<<<<<<<<<<<<
 *             mask,
 *             _manipulation._reshape(mask_scanned, mask._shape),
 */
    __Pyx_XDECREF(__pyx_r);

    /* "cupy/core/_routines_indexing.pyx":560
 *         return (
 *             mask,
 *             _manipulation._reshape(mask_scanned, mask._shape),             # <<<<<<<<<<<<<<
 *             masked_shape)
 *     mask_scanned = None
 */
    __pyx_t_5 = ((PyObject *)__pyx_f_4cupy_4core_22_routines_manipulation__reshape(__pyx_v_mask_scanned, __pyx_v_mask->_shape, 0)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 560, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);

    /* "cupy/core/_routines_indexing.pyx":559
 *     if mask._shape.size() == a._shape.size() and axis == 0:
 *         return (
 *             mask,             # <<<<<<<<<<<<<<
 *             _manipulation._reshape(mask_scanned, mask._shape),
 *             masked_shape)
 */
    __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 559, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(((PyObject *)__pyx_v_mask));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_mask));
    PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_mask));
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
    __Pyx_INCREF(__pyx_v_masked_shape);
    __Pyx_GIVEREF(__pyx_v_masked_shape);
    PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_masked_shape);
    __pyx_t_5 = 0;
    __pyx_r = __pyx_t_2;
    __pyx_t_2 = 0;
    goto __pyx_L0;

    /* "cupy/core/_routines_indexing.pyx":557
 * 
 *     # When mask covers the entire array, broadcasting is not necessary.
 *     if mask._shape.size() == a._shape.size() and axis == 0:             # <<<<<<<<<<<<<<
 *         return (
 *             mask,
 */
  }

  /* "cupy/core/_routines_indexing.pyx":562
 *             _manipulation._reshape(mask_scanned, mask._shape),
 *             masked_shape)
 *     mask_scanned = None             # <<<<<<<<<<<<<<
 * 
 *     # The scan of the broadcasted array is used to index on kernel.
 */
  __Pyx_INCREF(Py_None);
  __Pyx_DECREF_SET(__pyx_v_mask_scanned, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)Py_None));

  /* "cupy/core/_routines_indexing.pyx":567
 *     mask = _manipulation._reshape(
 *         mask,
 *         axis * (1,) + mask.shape + (a.ndim - axis - mask.ndim) * (1,))             # <<<<<<<<<<<<<<
 *     if <Py_ssize_t>mask._shape.size() > a._shape.size():
 *         raise IndexError('too many indices for array')
 */
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_axis); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_2, __pyx_tuple__15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_mask), __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_9 = PyNumber_Add(__pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_ndim); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_axis); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_8 = PyNumber_Subtract(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_mask), __pyx_n_s_ndim); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = PyNumber_Subtract(__pyx_t_8, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PyNumber_Multiply(__pyx_t_2, __pyx_tuple__15); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyNumber_Add(__pyx_t_9, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_4 = __pyx_convert_vector_from_py_Py_ssize_t(__pyx_t_2); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cupy/core/_routines_indexing.pyx":565
 * 
 *     # The scan of the broadcasted array is used to index on kernel.
 *     mask = _manipulation._reshape(             # <<<<<<<<<<<<<<
 *         mask,
 *         axis * (1,) + mask.shape + (a.ndim - axis - mask.ndim) * (1,))
 */
  __pyx_t_2 = ((PyObject *)__pyx_f_4cupy_4core_22_routines_manipulation__reshape(__pyx_v_mask, __pyx_t_4, 0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 565, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF_SET(__pyx_v_mask, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2));
  __pyx_t_2 = 0;

  /* "cupy/core/_routines_indexing.pyx":568
 *         mask,
 *         axis * (1,) + mask.shape + (a.ndim - axis - mask.ndim) * (1,))
 *     if <Py_ssize_t>mask._shape.size() > a._shape.size():             # <<<<<<<<<<<<<<
 *         raise IndexError('too many indices for array')
 * 
 */
  __pyx_t_3 = ((((Py_ssize_t)__pyx_v_mask->_shape.size()) > __pyx_v_a->_shape.size()) != 0);
  if (unlikely(__pyx_t_3)) {

    /* "cupy/core/_routines_indexing.pyx":569
 *         axis * (1,) + mask.shape + (a.ndim - axis - mask.ndim) * (1,))
 *     if <Py_ssize_t>mask._shape.size() > a._shape.size():
 *         raise IndexError('too many indices for array')             # <<<<<<<<<<<<<<
 * 
 *     mask = _manipulation.broadcast_to(mask, a.shape)
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 569, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 569, __pyx_L1_error)

    /* "cupy/core/_routines_indexing.pyx":568
 *         mask,
 *         axis * (1,) + mask.shape + (a.ndim - axis - mask.ndim) * (1,))
 *     if <Py_ssize_t>mask._shape.size() > a._shape.size():             # <<<<<<<<<<<<<<
 *         raise IndexError('too many indices for array')
 * 
 */
  }

  /* "cupy/core/_routines_indexing.pyx":571
 *         raise IndexError('too many indices for array')
 * 
 *     mask = _manipulation.broadcast_to(mask, a.shape)             # <<<<<<<<<<<<<<
 *     if mask.size <= 2 ** 31 - 1:
 *         mask_type = numpy.int32
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 571, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = ((PyObject *)__pyx_f_4cupy_4core_22_routines_manipulation_broadcast_to(__pyx_v_mask, __pyx_t_2, 0)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 571, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF_SET(__pyx_v_mask, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_5));
  __pyx_t_5 = 0;

  /* "cupy/core/_routines_indexing.pyx":572
 * 
 *     mask = _manipulation.broadcast_to(mask, a.shape)
 *     if mask.size <= 2 ** 31 - 1:             # <<<<<<<<<<<<<<
 *         mask_type = numpy.int32
 *     else:
 */
  __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_mask->size); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 572, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_5, __pyx_int_2147483647, Py_LE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 572, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 572, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "cupy/core/_routines_indexing.pyx":573
 *     mask = _manipulation.broadcast_to(mask, a.shape)
 *     if mask.size <= 2 ** 31 - 1:
 *         mask_type = numpy.int32             # <<<<<<<<<<<<<<
 *     else:
 *         mask_type = numpy.int64
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_numpy); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 573, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 573, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF_SET(__pyx_v_mask_type, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "cupy/core/_routines_indexing.pyx":572
 * 
 *     mask = _manipulation.broadcast_to(mask, a.shape)
 *     if mask.size <= 2 ** 31 - 1:             # <<<<<<<<<<<<<<
 *         mask_type = numpy.int32
 *     else:
 */
    goto __pyx_L12;
  }

  /* "cupy/core/_routines_indexing.pyx":575
 *         mask_type = numpy.int32
 *     else:
 *         mask_type = numpy.int64             # <<<<<<<<<<<<<<
 *     mask_scanned = _manipulation._reshape(
 *         _math.scan(mask.astype(mask_type).ravel()),
 */
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_numpy); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 575, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_int64); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 575, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF_SET(__pyx_v_mask_type, __pyx_t_2);
    __pyx_t_2 = 0;
  }
  __pyx_L12:;

  /* "cupy/core/_routines_indexing.pyx":577
 *         mask_type = numpy.int64
 *     mask_scanned = _manipulation._reshape(
 *         _math.scan(mask.astype(mask_type).ravel()),             # <<<<<<<<<<<<<<
 *         mask._shape)
 *     return mask, mask_scanned, masked_shape
 */
  __pyx_t_2 = ((PyObject *)((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)__pyx_v_mask->__pyx_vtab)->astype(__pyx_v_mask, __pyx_v_mask_type, 0, NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = ((PyObject *)((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2)->__pyx_vtab)->ravel(((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2), 0, NULL)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = ((PyObject *)__pyx_f_4cupy_4core_14_routines_math_scan(((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_5), NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "cupy/core/_routines_indexing.pyx":576
 *     else:
 *         mask_type = numpy.int64
 *     mask_scanned = _manipulation._reshape(             # <<<<<<<<<<<<<<
 *         _math.scan(mask.astype(mask_type).ravel()),
 *         mask._shape)
 */
  __pyx_t_5 = ((PyObject *)__pyx_f_4cupy_4core_22_routines_manipulation__reshape(((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2), __pyx_v_mask->_shape, 0)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 576, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF_SET(__pyx_v_mask_scanned, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_5));
  __pyx_t_5 = 0;

  /* "cupy/core/_routines_indexing.pyx":579
 *         _math.scan(mask.astype(mask_type).ravel()),
 *         mask._shape)
 *     return mask, mask_scanned, masked_shape             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(((PyObject *)__pyx_v_mask));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_mask));
  PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_mask));
  __Pyx_INCREF(((PyObject *)__pyx_v_mask_scanned));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_mask_scanned));
  PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_mask_scanned));
  __Pyx_INCREF(__pyx_v_masked_shape);
  __Pyx_GIVEREF(__pyx_v_masked_shape);
  PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_masked_shape);
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "cupy/core/_routines_indexing.pyx":529
 * 
 * 
 * cpdef _prepare_mask_indexing_single(ndarray a, ndarray mask, Py_ssize_t axis):             # <<<<<<<<<<<<<<
 *     cdef ndarray mask_scanned, mask_br, mask_br_scanned
 *     cdef int n_true
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("cupy.core._routines_indexing._prepare_mask_indexing_single", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_mask_scanned);
  __Pyx_XDECREF((PyObject *)__pyx_v_mask_br);
  __Pyx_XDECREF(__pyx_v_lshape);
  __Pyx_XDECREF(__pyx_v_rshape);
  __Pyx_XDECREF(__pyx_v_masked_shape);
  __Pyx_XDECREF(__pyx_v_i);
  __Pyx_XDECREF(__pyx_v_s);
  __Pyx_XDECREF(__pyx_v_mask_type);
  __Pyx_XDECREF((PyObject *)__pyx_v_mask);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_4cupy_4core_18_routines_indexing_3_prepare_mask_indexing_single(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4cupy_4core_18_routines_indexing_2_prepare_mask_indexing_single[] = "_prepare_mask_indexing_single(ndarray a, ndarray mask, Py_ssize_t axis)";
static PyObject *__pyx_pw_4cupy_4core_18_routines_indexing_3_prepare_mask_indexing_single(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_a = 0;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_mask = 0;
  Py_ssize_t __pyx_v_axis;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_prepare_mask_indexing_single (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_a,&__pyx_n_s_mask,&__pyx_n_s_axis,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_a)) != 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_mask)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_prepare_mask_indexing_single", 1, 3, 3, 1); __PYX_ERR(0, 529, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_axis)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_prepare_mask_indexing_single", 1, 3, 3, 2); __PYX_ERR(0, 529, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_prepare_mask_indexing_single") < 0)) __PYX_ERR(0, 529, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_a = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)values[0]);
    __pyx_v_mask = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)values[1]);
    __pyx_v_axis = __Pyx_PyIndex_AsSsize_t(values[2]); if (unlikely((__pyx_v_axis == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 529, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_prepare_mask_indexing_single", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 529, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("cupy.core._routines_indexing._prepare_mask_indexing_single", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_a), __pyx_ptype_4cupy_4core_4core_ndarray, 1, "a", 0))) __PYX_ERR(0, 529, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_mask), __pyx_ptype_4cupy_4core_4core_ndarray, 1, "mask", 0))) __PYX_ERR(0, 529, __pyx_L1_error)
  __pyx_r = __pyx_pf_4cupy_4core_18_routines_indexing_2_prepare_mask_indexing_single(__pyx_self, __pyx_v_a, __pyx_v_mask, __pyx_v_axis);

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

static PyObject *__pyx_pf_4cupy_4core_18_routines_indexing_2_prepare_mask_indexing_single(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_a, struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_mask, Py_ssize_t __pyx_v_axis) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_prepare_mask_indexing_single", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_4cupy_4core_18_routines_indexing__prepare_mask_indexing_single(__pyx_v_a, __pyx_v_mask, __pyx_v_axis, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 529, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cupy.core._routines_indexing._prepare_mask_indexing_single", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":582
 * 
 * 
 * cpdef ndarray _getitem_mask_single(ndarray a, ndarray mask, int axis):             # <<<<<<<<<<<<<<
 *     cdef ndarray mask_scanned
 *     cdef tuple masked_shape
 */

static PyObject *__pyx_pw_4cupy_4core_18_routines_indexing_5_getitem_mask_single(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_f_4cupy_4core_18_routines_indexing__getitem_mask_single(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_a, struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_mask, int __pyx_v_axis, CYTHON_UNUSED int __pyx_skip_dispatch) {
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_mask_scanned = 0;
  PyObject *__pyx_v_masked_shape = 0;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_out = NULL;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *(*__pyx_t_6)(PyObject *);
  int __pyx_t_7;
  int __pyx_t_8;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_getitem_mask_single", 0);
  __Pyx_INCREF((PyObject *)__pyx_v_mask);

  /* "cupy/core/_routines_indexing.pyx":586
 *     cdef tuple masked_shape
 * 
 *     mask, mask_scanned, masked_shape = _prepare_mask_indexing_single(             # <<<<<<<<<<<<<<
 *         a, mask, axis)
 *     out = ndarray(masked_shape, dtype=a.dtype)
 */
  __pyx_t_1 = __pyx_f_4cupy_4core_18_routines_indexing__prepare_mask_indexing_single(__pyx_v_a, __pyx_v_mask, __pyx_v_axis, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 586, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
    PyObject* sequence = __pyx_t_1;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 3)) {
      if (size > 3) __Pyx_RaiseTooManyValuesError(3);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 586, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 2); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_4 = PyList_GET_ITEM(sequence, 2); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_4);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 586, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 586, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 586, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    #endif
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_5 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 586, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_6 = Py_TYPE(__pyx_t_5)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L3_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_3);
    index = 2; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L3_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_4);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 3) < 0) __PYX_ERR(0, 586, __pyx_L1_error)
    __pyx_t_6 = NULL;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    goto __pyx_L4_unpacking_done;
    __pyx_L3_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 586, __pyx_L1_error)
    __pyx_L4_unpacking_done:;
  }
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 586, __pyx_L1_error)
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 586, __pyx_L1_error)
  if (!(likely(PyTuple_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 586, __pyx_L1_error)
  __Pyx_DECREF_SET(__pyx_v_mask, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2));
  __pyx_t_2 = 0;
  __pyx_v_mask_scanned = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_v_masked_shape = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "cupy/core/_routines_indexing.pyx":588
 *     mask, mask_scanned, masked_shape = _prepare_mask_indexing_single(
 *         a, mask, axis)
 *     out = ndarray(masked_shape, dtype=a.dtype)             # <<<<<<<<<<<<<<
 *     if out.size == 0:
 *         return out
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 588, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_masked_shape);
  __Pyx_GIVEREF(__pyx_v_masked_shape);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_masked_shape);
  __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 588, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dtype, __pyx_v_a->dtype) < 0) __PYX_ERR(0, 588, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_4cupy_4core_4core_ndarray), __pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 588, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_out = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "cupy/core/_routines_indexing.pyx":589
 *         a, mask, axis)
 *     out = ndarray(masked_shape, dtype=a.dtype)
 *     if out.size == 0:             # <<<<<<<<<<<<<<
 *         return out
 *     return _getitem_mask_kernel(a, mask, mask_scanned, out)
 */
  __pyx_t_7 = ((__pyx_v_out->size == 0) != 0);
  if (__pyx_t_7) {

    /* "cupy/core/_routines_indexing.pyx":590
 *     out = ndarray(masked_shape, dtype=a.dtype)
 *     if out.size == 0:
 *         return out             # <<<<<<<<<<<<<<
 *     return _getitem_mask_kernel(a, mask, mask_scanned, out)
 * 
 */
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __Pyx_INCREF(((PyObject *)__pyx_v_out));
    __pyx_r = __pyx_v_out;
    goto __pyx_L0;

    /* "cupy/core/_routines_indexing.pyx":589
 *         a, mask, axis)
 *     out = ndarray(masked_shape, dtype=a.dtype)
 *     if out.size == 0:             # <<<<<<<<<<<<<<
 *         return out
 *     return _getitem_mask_kernel(a, mask, mask_scanned, out)
 */
  }

  /* "cupy/core/_routines_indexing.pyx":591
 *     if out.size == 0:
 *         return out
 *     return _getitem_mask_kernel(a, mask, mask_scanned, out)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_getitem_mask_kernel); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 591, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = NULL;
  __pyx_t_8 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_4, function);
      __pyx_t_8 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[5] = {__pyx_t_1, ((PyObject *)__pyx_v_a), ((PyObject *)__pyx_v_mask), ((PyObject *)__pyx_v_mask_scanned), ((PyObject *)__pyx_v_out)};
    __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 4+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 591, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[5] = {__pyx_t_1, ((PyObject *)__pyx_v_a), ((PyObject *)__pyx_v_mask), ((PyObject *)__pyx_v_mask_scanned), ((PyObject *)__pyx_v_out)};
    __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_8, 4+__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 591, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else
  #endif
  {
    __pyx_t_2 = PyTuple_New(4+__pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 591, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (__pyx_t_1) {
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __pyx_t_1 = NULL;
    }
    __Pyx_INCREF(((PyObject *)__pyx_v_a));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_a));
    PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_8, ((PyObject *)__pyx_v_a));
    __Pyx_INCREF(((PyObject *)__pyx_v_mask));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_mask));
    PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_8, ((PyObject *)__pyx_v_mask));
    __Pyx_INCREF(((PyObject *)__pyx_v_mask_scanned));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_mask_scanned));
    PyTuple_SET_ITEM(__pyx_t_2, 2+__pyx_t_8, ((PyObject *)__pyx_v_mask_scanned));
    __Pyx_INCREF(((PyObject *)__pyx_v_out));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_out));
    PyTuple_SET_ITEM(__pyx_t_2, 3+__pyx_t_8, ((PyObject *)__pyx_v_out));
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 591, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 591, __pyx_L1_error)
  __pyx_r = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_3);
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "cupy/core/_routines_indexing.pyx":582
 * 
 * 
 * cpdef ndarray _getitem_mask_single(ndarray a, ndarray mask, int axis):             # <<<<<<<<<<<<<<
 *     cdef ndarray mask_scanned
 *     cdef tuple masked_shape
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("cupy.core._routines_indexing._getitem_mask_single", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_mask_scanned);
  __Pyx_XDECREF(__pyx_v_masked_shape);
  __Pyx_XDECREF((PyObject *)__pyx_v_out);
  __Pyx_XDECREF((PyObject *)__pyx_v_mask);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_4cupy_4core_18_routines_indexing_5_getitem_mask_single(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_4cupy_4core_18_routines_indexing_4_getitem_mask_single[] = "_getitem_mask_single(ndarray a, ndarray mask, int axis) -> ndarray";
static PyObject *__pyx_pw_4cupy_4core_18_routines_indexing_5_getitem_mask_single(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_a = 0;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_mask = 0;
  int __pyx_v_axis;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_getitem_mask_single (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_a,&__pyx_n_s_mask,&__pyx_n_s_axis,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_a)) != 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_mask)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_getitem_mask_single", 1, 3, 3, 1); __PYX_ERR(0, 582, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_axis)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("_getitem_mask_single", 1, 3, 3, 2); __PYX_ERR(0, 582, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_getitem_mask_single") < 0)) __PYX_ERR(0, 582, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_a = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)values[0]);
    __pyx_v_mask = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)values[1]);
    __pyx_v_axis = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_axis == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 582, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("_getitem_mask_single", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 582, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("cupy.core._routines_indexing._getitem_mask_single", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_a), __pyx_ptype_4cupy_4core_4core_ndarray, 1, "a", 0))) __PYX_ERR(0, 582, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_mask), __pyx_ptype_4cupy_4core_4core_ndarray, 1, "mask", 0))) __PYX_ERR(0, 582, __pyx_L1_error)
  __pyx_r = __pyx_pf_4cupy_4core_18_routines_indexing_4_getitem_mask_single(__pyx_self, __pyx_v_a, __pyx_v_mask, __pyx_v_axis);

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

static PyObject *__pyx_pf_4cupy_4core_18_routines_indexing_4_getitem_mask_single(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_a, struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_mask, int __pyx_v_axis) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_getitem_mask_single", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = ((PyObject *)__pyx_f_4cupy_4core_18_routines_indexing__getitem_mask_single(__pyx_v_a, __pyx_v_mask, __pyx_v_axis, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 582, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("cupy.core._routines_indexing._getitem_mask_single", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":594
 * 
 * 
 * cdef ndarray _take(ndarray a, indices, int li, int ri, ndarray out=None):             # <<<<<<<<<<<<<<
 *     # When li + 1 == ri this function behaves similarly to np.take
 *     cdef tuple out_shape, ind_shape, indices_shape
 */

static struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_f_4cupy_4core_18_routines_indexing__take(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_a, PyObject *__pyx_v_indices, int __pyx_v_li, int __pyx_v_ri, struct __pyx_opt_args_4cupy_4core_18_routines_indexing__take *__pyx_optional_args) {
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_out = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)Py_None);
  PyObject *__pyx_v_out_shape = 0;
  PyObject *__pyx_v_indices_shape = 0;
  int __pyx_v_i;
  int __pyx_v_ndim;
  Py_ssize_t __pyx_v_ldim;
  Py_ssize_t __pyx_v_cdim;
  Py_ssize_t __pyx_v_rdim;
  Py_ssize_t __pyx_v_index_range;
  PyObject *__pyx_v_a_shape = NULL;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  struct __pyx_opt_args_4cupy_4core_4core_array __pyx_t_7;
  Py_ssize_t __pyx_t_8;
  std::vector<Py_ssize_t>  __pyx_t_9;
  int __pyx_t_10;
  int __pyx_t_11;
  int __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_take", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_out = __pyx_optional_args->out;
    }
  }
  __Pyx_INCREF((PyObject *)__pyx_v_a);
  __Pyx_INCREF(__pyx_v_indices);
  __Pyx_INCREF((PyObject *)__pyx_v_out);

  /* "cupy/core/_routines_indexing.pyx":597
 *     # When li + 1 == ri this function behaves similarly to np.take
 *     cdef tuple out_shape, ind_shape, indices_shape
 *     cdef int i, ndim = a._shape.size()             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t ldim, cdim, rdim, index_range
 *     if ndim == 0:
 */
  __pyx_v_ndim = __pyx_v_a->_shape.size();

  /* "cupy/core/_routines_indexing.pyx":599
 *     cdef int i, ndim = a._shape.size()
 *     cdef Py_ssize_t ldim, cdim, rdim, index_range
 *     if ndim == 0:             # <<<<<<<<<<<<<<
 *         a = a.ravel()
 *         ndim = 1
 */
  __pyx_t_1 = ((__pyx_v_ndim == 0) != 0);
  if (__pyx_t_1) {

    /* "cupy/core/_routines_indexing.pyx":600
 *     cdef Py_ssize_t ldim, cdim, rdim, index_range
 *     if ndim == 0:
 *         a = a.ravel()             # <<<<<<<<<<<<<<
 *         ndim = 1
 * 
 */
    __pyx_t_2 = ((PyObject *)((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)__pyx_v_a->__pyx_vtab)->ravel(__pyx_v_a, 0, NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 600, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF_SET(__pyx_v_a, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2));
    __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":601
 *     if ndim == 0:
 *         a = a.ravel()
 *         ndim = 1             # <<<<<<<<<<<<<<
 * 
 *     if not (-ndim <= li < ndim and -ndim <= ri < ndim):
 */
    __pyx_v_ndim = 1;

    /* "cupy/core/_routines_indexing.pyx":599
 *     cdef int i, ndim = a._shape.size()
 *     cdef Py_ssize_t ldim, cdim, rdim, index_range
 *     if ndim == 0:             # <<<<<<<<<<<<<<
 *         a = a.ravel()
 *         ndim = 1
 */
  }

  /* "cupy/core/_routines_indexing.pyx":603
 *         ndim = 1
 * 
 *     if not (-ndim <= li < ndim and -ndim <= ri < ndim):             # <<<<<<<<<<<<<<
 *         raise _errors._AxisError('Axis overrun')
 * 
 */
  __pyx_t_3 = ((-__pyx_v_ndim) <= __pyx_v_li);
  if (__pyx_t_3) {
    __pyx_t_3 = (__pyx_v_li < __pyx_v_ndim);
  }
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_1 = __pyx_t_4;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_4 = ((-__pyx_v_ndim) <= __pyx_v_ri);
  if (__pyx_t_4) {
    __pyx_t_4 = (__pyx_v_ri < __pyx_v_ndim);
  }
  __pyx_t_3 = (__pyx_t_4 != 0);
  __pyx_t_1 = __pyx_t_3;
  __pyx_L5_bool_binop_done:;
  __pyx_t_3 = ((!__pyx_t_1) != 0);
  if (unlikely(__pyx_t_3)) {

    /* "cupy/core/_routines_indexing.pyx":604
 * 
 *     if not (-ndim <= li < ndim and -ndim <= ri < ndim):
 *         raise _errors._AxisError('Axis overrun')             # <<<<<<<<<<<<<<
 * 
 *     if ndim == 1:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_errors); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 604, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_AxisError); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 604, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_2 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_5, __pyx_kp_u_Axis_overrun) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_kp_u_Axis_overrun);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 604, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 604, __pyx_L1_error)

    /* "cupy/core/_routines_indexing.pyx":603
 *         ndim = 1
 * 
 *     if not (-ndim <= li < ndim and -ndim <= ri < ndim):             # <<<<<<<<<<<<<<
 *         raise _errors._AxisError('Axis overrun')
 * 
 */
  }

  /* "cupy/core/_routines_indexing.pyx":606
 *         raise _errors._AxisError('Axis overrun')
 * 
 *     if ndim == 1:             # <<<<<<<<<<<<<<
 *         li = ri = 0
 *     else:
 */
  __pyx_t_3 = ((__pyx_v_ndim == 1) != 0);
  if (__pyx_t_3) {

    /* "cupy/core/_routines_indexing.pyx":607
 * 
 *     if ndim == 1:
 *         li = ri = 0             # <<<<<<<<<<<<<<
 *     else:
 *         li %= ndim
 */
    __pyx_v_li = 0;
    __pyx_v_ri = 0;

    /* "cupy/core/_routines_indexing.pyx":606
 *         raise _errors._AxisError('Axis overrun')
 * 
 *     if ndim == 1:             # <<<<<<<<<<<<<<
 *         li = ri = 0
 *     else:
 */
    goto __pyx_L7;
  }

  /* "cupy/core/_routines_indexing.pyx":609
 *         li = ri = 0
 *     else:
 *         li %= ndim             # <<<<<<<<<<<<<<
 *         ri %= ndim
 *         assert 0 <= li <= ri
 */
  /*else*/ {
    if (unlikely(__pyx_v_ndim == 0)) {
      PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
      __PYX_ERR(0, 609, __pyx_L1_error)
    }
    __pyx_v_li = __Pyx_mod_int(__pyx_v_li, __pyx_v_ndim);

    /* "cupy/core/_routines_indexing.pyx":610
 *     else:
 *         li %= ndim
 *         ri %= ndim             # <<<<<<<<<<<<<<
 *         assert 0 <= li <= ri
 * 
 */
    if (unlikely(__pyx_v_ndim == 0)) {
      PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
      __PYX_ERR(0, 610, __pyx_L1_error)
    }
    __pyx_v_ri = __Pyx_mod_int(__pyx_v_ri, __pyx_v_ndim);

    /* "cupy/core/_routines_indexing.pyx":611
 *         li %= ndim
 *         ri %= ndim
 *         assert 0 <= li <= ri             # <<<<<<<<<<<<<<
 * 
 *     if numpy.isscalar(indices):
 */
    #ifndef CYTHON_WITHOUT_ASSERTIONS
    if (unlikely(!Py_OptimizeFlag)) {
      __pyx_t_3 = (0 <= __pyx_v_li);
      if (__pyx_t_3) {
        __pyx_t_3 = (__pyx_v_li <= __pyx_v_ri);
      }
      if (unlikely(!(__pyx_t_3 != 0))) {
        PyErr_SetNone(PyExc_AssertionError);
        __PYX_ERR(0, 611, __pyx_L1_error)
      }
    }
    #endif
  }
  __pyx_L7:;

  /* "cupy/core/_routines_indexing.pyx":613
 *         assert 0 <= li <= ri
 * 
 *     if numpy.isscalar(indices):             # <<<<<<<<<<<<<<
 *         indices_shape = ()
 *         cdim = 1
 */
  __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_numpy); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_isscalar); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  __pyx_t_2 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_5, __pyx_t_6, __pyx_v_indices) : __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_indices);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 613, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 613, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "cupy/core/_routines_indexing.pyx":614
 * 
 *     if numpy.isscalar(indices):
 *         indices_shape = ()             # <<<<<<<<<<<<<<
 *         cdim = 1
 *     else:
 */
    __Pyx_INCREF(__pyx_empty_tuple);
    __pyx_v_indices_shape = __pyx_empty_tuple;

    /* "cupy/core/_routines_indexing.pyx":615
 *     if numpy.isscalar(indices):
 *         indices_shape = ()
 *         cdim = 1             # <<<<<<<<<<<<<<
 *     else:
 *         if not isinstance(indices, ndarray):
 */
    __pyx_v_cdim = 1;

    /* "cupy/core/_routines_indexing.pyx":613
 *         assert 0 <= li <= ri
 * 
 *     if numpy.isscalar(indices):             # <<<<<<<<<<<<<<
 *         indices_shape = ()
 *         cdim = 1
 */
    goto __pyx_L8;
  }

  /* "cupy/core/_routines_indexing.pyx":617
 *         cdim = 1
 *     else:
 *         if not isinstance(indices, ndarray):             # <<<<<<<<<<<<<<
 *             indices = core.array(indices, dtype=int)
 *         indices_shape = indices.shape
 */
  /*else*/ {
    __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_indices, __pyx_ptype_4cupy_4core_4core_ndarray); 
    __pyx_t_1 = ((!(__pyx_t_3 != 0)) != 0);
    if (__pyx_t_1) {

      /* "cupy/core/_routines_indexing.pyx":618
 *     else:
 *         if not isinstance(indices, ndarray):
 *             indices = core.array(indices, dtype=int)             # <<<<<<<<<<<<<<
 *         indices_shape = indices.shape
 *         cdim = indices.size
 */
      __pyx_t_7.__pyx_n = 1;
      __pyx_t_7.dtype = ((PyObject *)(&PyInt_Type));
      __pyx_t_2 = ((PyObject *)__pyx_f_4cupy_4core_4core_array(__pyx_v_indices, 0, &__pyx_t_7)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 618, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF_SET(__pyx_v_indices, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "cupy/core/_routines_indexing.pyx":617
 *         cdim = 1
 *     else:
 *         if not isinstance(indices, ndarray):             # <<<<<<<<<<<<<<
 *             indices = core.array(indices, dtype=int)
 *         indices_shape = indices.shape
 */
    }

    /* "cupy/core/_routines_indexing.pyx":619
 *         if not isinstance(indices, ndarray):
 *             indices = core.array(indices, dtype=int)
 *         indices_shape = indices.shape             # <<<<<<<<<<<<<<
 *         cdim = indices.size
 * 
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_indices, __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 619, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (!(likely(PyTuple_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 619, __pyx_L1_error)
    __pyx_v_indices_shape = ((PyObject*)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":620
 *             indices = core.array(indices, dtype=int)
 *         indices_shape = indices.shape
 *         cdim = indices.size             # <<<<<<<<<<<<<<
 * 
 *     ldim = rdim = 1
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_indices, __pyx_n_s_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 620, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 620, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_v_cdim = __pyx_t_8;
  }
  __pyx_L8:;

  /* "cupy/core/_routines_indexing.pyx":622
 *         cdim = indices.size
 * 
 *     ldim = rdim = 1             # <<<<<<<<<<<<<<
 *     if ndim == 1:
 *         out_shape = indices_shape
 */
  __pyx_v_ldim = 1;
  __pyx_v_rdim = 1;

  /* "cupy/core/_routines_indexing.pyx":623
 * 
 *     ldim = rdim = 1
 *     if ndim == 1:             # <<<<<<<<<<<<<<
 *         out_shape = indices_shape
 *         index_range = a.size
 */
  __pyx_t_1 = ((__pyx_v_ndim == 1) != 0);
  if (__pyx_t_1) {

    /* "cupy/core/_routines_indexing.pyx":624
 *     ldim = rdim = 1
 *     if ndim == 1:
 *         out_shape = indices_shape             # <<<<<<<<<<<<<<
 *         index_range = a.size
 *     else:
 */
    __Pyx_INCREF(__pyx_v_indices_shape);
    __pyx_v_out_shape = __pyx_v_indices_shape;

    /* "cupy/core/_routines_indexing.pyx":625
 *     if ndim == 1:
 *         out_shape = indices_shape
 *         index_range = a.size             # <<<<<<<<<<<<<<
 *     else:
 *         a_shape = a.shape
 */
    __pyx_t_8 = __pyx_v_a->size;
    __pyx_v_index_range = __pyx_t_8;

    /* "cupy/core/_routines_indexing.pyx":623
 * 
 *     ldim = rdim = 1
 *     if ndim == 1:             # <<<<<<<<<<<<<<
 *         out_shape = indices_shape
 *         index_range = a.size
 */
    goto __pyx_L10;
  }

  /* "cupy/core/_routines_indexing.pyx":627
 *         index_range = a.size
 *     else:
 *         a_shape = a.shape             # <<<<<<<<<<<<<<
 *         out_shape = a_shape[:li] + indices_shape + a_shape[ri + 1:]
 *         if len(indices_shape) != 0:
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_shape); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 627, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_a_shape = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":628
 *     else:
 *         a_shape = a.shape
 *         out_shape = a_shape[:li] + indices_shape + a_shape[ri + 1:]             # <<<<<<<<<<<<<<
 *         if len(indices_shape) != 0:
 *             indices = _manipulation._reshape(
 */
    __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_a_shape, 0, __pyx_v_li, NULL, NULL, NULL, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 628, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = PyNumber_Add(__pyx_t_2, __pyx_v_indices_shape); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 628, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_a_shape, (__pyx_v_ri + 1), 0, NULL, NULL, NULL, 1, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 628, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = PyNumber_Add(__pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 628, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (!(likely(PyTuple_CheckExact(__pyx_t_6))||((__pyx_t_6) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_6)->tp_name), 0))) __PYX_ERR(0, 628, __pyx_L1_error)
    __pyx_v_out_shape = ((PyObject*)__pyx_t_6);
    __pyx_t_6 = 0;

    /* "cupy/core/_routines_indexing.pyx":629
 *         a_shape = a.shape
 *         out_shape = a_shape[:li] + indices_shape + a_shape[ri + 1:]
 *         if len(indices_shape) != 0:             # <<<<<<<<<<<<<<
 *             indices = _manipulation._reshape(
 *                 indices,
 */
    if (unlikely(__pyx_v_indices_shape == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
      __PYX_ERR(0, 629, __pyx_L1_error)
    }
    __pyx_t_8 = PyTuple_GET_SIZE(__pyx_v_indices_shape); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 629, __pyx_L1_error)
    __pyx_t_1 = ((__pyx_t_8 != 0) != 0);
    if (__pyx_t_1) {

      /* "cupy/core/_routines_indexing.pyx":631
 *         if len(indices_shape) != 0:
 *             indices = _manipulation._reshape(
 *                 indices,             # <<<<<<<<<<<<<<
 *                 (1,) * li + indices_shape + (1,) * (ndim - (ri + 1)))
 *         for i in range(li):
 */
      if (!(likely(((__pyx_v_indices) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_indices, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 631, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":632
 *             indices = _manipulation._reshape(
 *                 indices,
 *                 (1,) * li + indices_shape + (1,) * (ndim - (ri + 1)))             # <<<<<<<<<<<<<<
 *         for i in range(li):
 *             ldim *= a._shape[i]
 */
      __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_li); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 632, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_2 = PyNumber_Multiply(__pyx_tuple__15, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 632, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyNumber_Add(__pyx_t_2, __pyx_v_indices_shape); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 632, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyInt_From_long((__pyx_v_ndim - (__pyx_v_ri + 1))); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 632, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = PyNumber_Multiply(__pyx_tuple__15, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 632, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyNumber_Add(__pyx_t_6, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 632, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_9 = __pyx_convert_vector_from_py_Py_ssize_t(__pyx_t_2); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 632, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "cupy/core/_routines_indexing.pyx":630
 *         out_shape = a_shape[:li] + indices_shape + a_shape[ri + 1:]
 *         if len(indices_shape) != 0:
 *             indices = _manipulation._reshape(             # <<<<<<<<<<<<<<
 *                 indices,
 *                 (1,) * li + indices_shape + (1,) * (ndim - (ri + 1)))
 */
      __pyx_t_2 = ((PyObject *)__pyx_f_4cupy_4core_22_routines_manipulation__reshape(((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_v_indices), __pyx_t_9, 0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 630, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF_SET(__pyx_v_indices, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "cupy/core/_routines_indexing.pyx":629
 *         a_shape = a.shape
 *         out_shape = a_shape[:li] + indices_shape + a_shape[ri + 1:]
 *         if len(indices_shape) != 0:             # <<<<<<<<<<<<<<
 *             indices = _manipulation._reshape(
 *                 indices,
 */
    }

    /* "cupy/core/_routines_indexing.pyx":633
 *                 indices,
 *                 (1,) * li + indices_shape + (1,) * (ndim - (ri + 1)))
 *         for i in range(li):             # <<<<<<<<<<<<<<
 *             ldim *= a._shape[i]
 *         for i in range(ri + 1, ndim):
 */
    __pyx_t_10 = __pyx_v_li;
    __pyx_t_11 = __pyx_t_10;
    for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {
      __pyx_v_i = __pyx_t_12;

      /* "cupy/core/_routines_indexing.pyx":634
 *                 (1,) * li + indices_shape + (1,) * (ndim - (ri + 1)))
 *         for i in range(li):
 *             ldim *= a._shape[i]             # <<<<<<<<<<<<<<
 *         for i in range(ri + 1, ndim):
 *             rdim *= a._shape[i]
 */
      __pyx_v_ldim = (__pyx_v_ldim * (__pyx_v_a->_shape[__pyx_v_i]));
    }

    /* "cupy/core/_routines_indexing.pyx":635
 *         for i in range(li):
 *             ldim *= a._shape[i]
 *         for i in range(ri + 1, ndim):             # <<<<<<<<<<<<<<
 *             rdim *= a._shape[i]
 *         index_range = a.size // (ldim * rdim)
 */
    __pyx_t_10 = __pyx_v_ndim;
    __pyx_t_11 = __pyx_t_10;
    for (__pyx_t_12 = (__pyx_v_ri + 1); __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) {
      __pyx_v_i = __pyx_t_12;

      /* "cupy/core/_routines_indexing.pyx":636
 *             ldim *= a._shape[i]
 *         for i in range(ri + 1, ndim):
 *             rdim *= a._shape[i]             # <<<<<<<<<<<<<<
 *         index_range = a.size // (ldim * rdim)
 * 
 */
      __pyx_v_rdim = (__pyx_v_rdim * (__pyx_v_a->_shape[__pyx_v_i]));
    }

    /* "cupy/core/_routines_indexing.pyx":637
 *         for i in range(ri + 1, ndim):
 *             rdim *= a._shape[i]
 *         index_range = a.size // (ldim * rdim)             # <<<<<<<<<<<<<<
 * 
 *     if out is None:
 */
    __pyx_t_8 = (__pyx_v_ldim * __pyx_v_rdim);
    if (unlikely(__pyx_t_8 == 0)) {
      PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
      __PYX_ERR(0, 637, __pyx_L1_error)
    }
    else if (sizeof(Py_ssize_t) == sizeof(long) && (!(((Py_ssize_t)-1) > 0)) && unlikely(__pyx_t_8 == (Py_ssize_t)-1)  && unlikely(UNARY_NEG_WOULD_OVERFLOW(__pyx_v_a->size))) {
      PyErr_SetString(PyExc_OverflowError, "value too large to perform division");
      __PYX_ERR(0, 637, __pyx_L1_error)
    }
    __pyx_v_index_range = __Pyx_div_Py_ssize_t(__pyx_v_a->size, __pyx_t_8);
  }
  __pyx_L10:;

  /* "cupy/core/_routines_indexing.pyx":639
 *         index_range = a.size // (ldim * rdim)
 * 
 *     if out is None:             # <<<<<<<<<<<<<<
 *         out = ndarray(out_shape, dtype=a.dtype)
 *     else:
 */
  __pyx_t_1 = (((PyObject *)__pyx_v_out) == Py_None);
  __pyx_t_3 = (__pyx_t_1 != 0);
  if (__pyx_t_3) {

    /* "cupy/core/_routines_indexing.pyx":640
 * 
 *     if out is None:
 *         out = ndarray(out_shape, dtype=a.dtype)             # <<<<<<<<<<<<<<
 *     else:
 *         if out.dtype != a.dtype:
 */
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 640, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_v_out_shape);
    __Pyx_GIVEREF(__pyx_v_out_shape);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_out_shape);
    __pyx_t_5 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 640, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_dtype, __pyx_v_a->dtype) < 0) __PYX_ERR(0, 640, __pyx_L1_error)
    __pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_4cupy_4core_4core_ndarray), __pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 640, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF_SET(__pyx_v_out, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_6));
    __pyx_t_6 = 0;

    /* "cupy/core/_routines_indexing.pyx":639
 *         index_range = a.size // (ldim * rdim)
 * 
 *     if out is None:             # <<<<<<<<<<<<<<
 *         out = ndarray(out_shape, dtype=a.dtype)
 *     else:
 */
    goto __pyx_L16;
  }

  /* "cupy/core/_routines_indexing.pyx":642
 *         out = ndarray(out_shape, dtype=a.dtype)
 *     else:
 *         if out.dtype != a.dtype:             # <<<<<<<<<<<<<<
 *             raise TypeError('Output dtype mismatch')
 *         if out.shape != out_shape:
 */
  /*else*/ {
    __pyx_t_6 = PyObject_RichCompare(__pyx_v_out->dtype, __pyx_v_a->dtype, Py_NE); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 642, __pyx_L1_error)
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 642, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(__pyx_t_3)) {

      /* "cupy/core/_routines_indexing.pyx":643
 *     else:
 *         if out.dtype != a.dtype:
 *             raise TypeError('Output dtype mismatch')             # <<<<<<<<<<<<<<
 *         if out.shape != out_shape:
 *             raise ValueError('Output shape mismatch')
 */
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__16, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 643, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_Raise(__pyx_t_6, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __PYX_ERR(0, 643, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":642
 *         out = ndarray(out_shape, dtype=a.dtype)
 *     else:
 *         if out.dtype != a.dtype:             # <<<<<<<<<<<<<<
 *             raise TypeError('Output dtype mismatch')
 *         if out.shape != out_shape:
 */
    }

    /* "cupy/core/_routines_indexing.pyx":644
 *         if out.dtype != a.dtype:
 *             raise TypeError('Output dtype mismatch')
 *         if out.shape != out_shape:             # <<<<<<<<<<<<<<
 *             raise ValueError('Output shape mismatch')
 *     if a.size == 0 and out.size != 0:
 */
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_out), __pyx_n_s_shape); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 644, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_6, __pyx_v_out_shape, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 644, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 644, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (unlikely(__pyx_t_3)) {

      /* "cupy/core/_routines_indexing.pyx":645
 *             raise TypeError('Output dtype mismatch')
 *         if out.shape != out_shape:
 *             raise ValueError('Output shape mismatch')             # <<<<<<<<<<<<<<
 *     if a.size == 0 and out.size != 0:
 *         raise IndexError('cannot do a non-empty take from an empty axes.')
 */
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__17, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 645, __pyx_L1_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, 645, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":644
 *         if out.dtype != a.dtype:
 *             raise TypeError('Output dtype mismatch')
 *         if out.shape != out_shape:             # <<<<<<<<<<<<<<
 *             raise ValueError('Output shape mismatch')
 *     if a.size == 0 and out.size != 0:
 */
    }
  }
  __pyx_L16:;

  /* "cupy/core/_routines_indexing.pyx":646
 *         if out.shape != out_shape:
 *             raise ValueError('Output shape mismatch')
 *     if a.size == 0 and out.size != 0:             # <<<<<<<<<<<<<<
 *         raise IndexError('cannot do a non-empty take from an empty axes.')
 * 
 */
  __pyx_t_1 = ((__pyx_v_a->size == 0) != 0);
  if (__pyx_t_1) {
  } else {
    __pyx_t_3 = __pyx_t_1;
    goto __pyx_L20_bool_binop_done;
  }
  __pyx_t_1 = ((__pyx_v_out->size != 0) != 0);
  __pyx_t_3 = __pyx_t_1;
  __pyx_L20_bool_binop_done:;
  if (unlikely(__pyx_t_3)) {

    /* "cupy/core/_routines_indexing.pyx":647
 *             raise ValueError('Output shape mismatch')
 *     if a.size == 0 and out.size != 0:
 *         raise IndexError('cannot do a non-empty take from an empty axes.')             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(indices, ndarray):
 */
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 647, __pyx_L1_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, 647, __pyx_L1_error)

    /* "cupy/core/_routines_indexing.pyx":646
 *         if out.shape != out_shape:
 *             raise ValueError('Output shape mismatch')
 *     if a.size == 0 and out.size != 0:             # <<<<<<<<<<<<<<
 *         raise IndexError('cannot do a non-empty take from an empty axes.')
 * 
 */
  }

  /* "cupy/core/_routines_indexing.pyx":649
 *         raise IndexError('cannot do a non-empty take from an empty axes.')
 * 
 *     if isinstance(indices, ndarray):             # <<<<<<<<<<<<<<
 *         return _take_kernel(
 *             a.reduced_view(), indices, ldim, cdim, rdim, index_range, out)
 */
  __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_indices, __pyx_ptype_4cupy_4core_4core_ndarray); 
  __pyx_t_1 = (__pyx_t_3 != 0);
  if (__pyx_t_1) {

    /* "cupy/core/_routines_indexing.pyx":650
 * 
 *     if isinstance(indices, ndarray):
 *         return _take_kernel(             # <<<<<<<<<<<<<<
 *             a.reduced_view(), indices, ldim, cdim, rdim, index_range, out)
 *     else:
 */
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_take_kernel); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 650, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);

    /* "cupy/core/_routines_indexing.pyx":651
 *     if isinstance(indices, ndarray):
 *         return _take_kernel(
 *             a.reduced_view(), indices, ldim, cdim, rdim, index_range, out)             # <<<<<<<<<<<<<<
 *     else:
 *         return _take_kernel_scalar(
 */
    __pyx_t_2 = ((PyObject *)((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)__pyx_v_a->__pyx_vtab)->reduced_view(__pyx_v_a, 0, NULL)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 651, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_13 = PyInt_FromSsize_t(__pyx_v_ldim); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 651, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_14 = PyInt_FromSsize_t(__pyx_v_cdim); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 651, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __pyx_t_15 = PyInt_FromSsize_t(__pyx_v_rdim); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 651, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_16 = PyInt_FromSsize_t(__pyx_v_index_range); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 651, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __pyx_t_17 = NULL;
    __pyx_t_10 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_17)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_17);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
        __pyx_t_10 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_6)) {
      PyObject *__pyx_temp[8] = {__pyx_t_17, __pyx_t_2, __pyx_v_indices, __pyx_t_13, __pyx_t_14, __pyx_t_15, __pyx_t_16, ((PyObject *)__pyx_v_out)};
      __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_10, 7+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 650, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
      PyObject *__pyx_temp[8] = {__pyx_t_17, __pyx_t_2, __pyx_v_indices, __pyx_t_13, __pyx_t_14, __pyx_t_15, __pyx_t_16, ((PyObject *)__pyx_v_out)};
      __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_10, 7+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 650, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    } else
    #endif
    {
      __pyx_t_18 = PyTuple_New(7+__pyx_t_10); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 650, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_18);
      if (__pyx_t_17) {
        __Pyx_GIVEREF(__pyx_t_17); PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_17); __pyx_t_17 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_18, 0+__pyx_t_10, __pyx_t_2);
      __Pyx_INCREF(__pyx_v_indices);
      __Pyx_GIVEREF(__pyx_v_indices);
      PyTuple_SET_ITEM(__pyx_t_18, 1+__pyx_t_10, __pyx_v_indices);
      __Pyx_GIVEREF(__pyx_t_13);
      PyTuple_SET_ITEM(__pyx_t_18, 2+__pyx_t_10, __pyx_t_13);
      __Pyx_GIVEREF(__pyx_t_14);
      PyTuple_SET_ITEM(__pyx_t_18, 3+__pyx_t_10, __pyx_t_14);
      __Pyx_GIVEREF(__pyx_t_15);
      PyTuple_SET_ITEM(__pyx_t_18, 4+__pyx_t_10, __pyx_t_15);
      __Pyx_GIVEREF(__pyx_t_16);
      PyTuple_SET_ITEM(__pyx_t_18, 5+__pyx_t_10, __pyx_t_16);
      __Pyx_INCREF(((PyObject *)__pyx_v_out));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_out));
      PyTuple_SET_ITEM(__pyx_t_18, 6+__pyx_t_10, ((PyObject *)__pyx_v_out));
      __pyx_t_2 = 0;
      __pyx_t_13 = 0;
      __pyx_t_14 = 0;
      __pyx_t_15 = 0;
      __pyx_t_16 = 0;
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_18, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 650, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "cupy/core/_routines_indexing.pyx":650
 * 
 *     if isinstance(indices, ndarray):
 *         return _take_kernel(             # <<<<<<<<<<<<<<
 *             a.reduced_view(), indices, ldim, cdim, rdim, index_range, out)
 *     else:
 */
    if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 650, __pyx_L1_error)
    __pyx_r = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_5);
    __pyx_t_5 = 0;
    goto __pyx_L0;

    /* "cupy/core/_routines_indexing.pyx":649
 *         raise IndexError('cannot do a non-empty take from an empty axes.')
 * 
 *     if isinstance(indices, ndarray):             # <<<<<<<<<<<<<<
 *         return _take_kernel(
 *             a.reduced_view(), indices, ldim, cdim, rdim, index_range, out)
 */
  }

  /* "cupy/core/_routines_indexing.pyx":653
 *             a.reduced_view(), indices, ldim, cdim, rdim, index_range, out)
 *     else:
 *         return _take_kernel_scalar(             # <<<<<<<<<<<<<<
 *             a.reduced_view(), indices, ldim, cdim, rdim, index_range, out)
 * 
 */
  /*else*/ {
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_take_kernel_scalar); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 653, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);

    /* "cupy/core/_routines_indexing.pyx":654
 *     else:
 *         return _take_kernel_scalar(
 *             a.reduced_view(), indices, ldim, cdim, rdim, index_range, out)             # <<<<<<<<<<<<<<
 * 
 * 
 */
    __pyx_t_18 = ((PyObject *)((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)__pyx_v_a->__pyx_vtab)->reduced_view(__pyx_v_a, 0, NULL)); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 654, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_16 = PyInt_FromSsize_t(__pyx_v_ldim); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 654, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __pyx_t_15 = PyInt_FromSsize_t(__pyx_v_cdim); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 654, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_14 = PyInt_FromSsize_t(__pyx_v_rdim); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 654, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __pyx_t_13 = PyInt_FromSsize_t(__pyx_v_index_range); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 654, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_2 = NULL;
    __pyx_t_10 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
        __pyx_t_10 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_6)) {
      PyObject *__pyx_temp[8] = {__pyx_t_2, __pyx_t_18, __pyx_v_indices, __pyx_t_16, __pyx_t_15, __pyx_t_14, __pyx_t_13, ((PyObject *)__pyx_v_out)};
      __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_10, 7+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 653, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
      PyObject *__pyx_temp[8] = {__pyx_t_2, __pyx_t_18, __pyx_v_indices, __pyx_t_16, __pyx_t_15, __pyx_t_14, __pyx_t_13, ((PyObject *)__pyx_v_out)};
      __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_10, 7+__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 653, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    } else
    #endif
    {
      __pyx_t_17 = PyTuple_New(7+__pyx_t_10); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 653, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_17);
      if (__pyx_t_2) {
        __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_2); __pyx_t_2 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_18);
      PyTuple_SET_ITEM(__pyx_t_17, 0+__pyx_t_10, __pyx_t_18);
      __Pyx_INCREF(__pyx_v_indices);
      __Pyx_GIVEREF(__pyx_v_indices);
      PyTuple_SET_ITEM(__pyx_t_17, 1+__pyx_t_10, __pyx_v_indices);
      __Pyx_GIVEREF(__pyx_t_16);
      PyTuple_SET_ITEM(__pyx_t_17, 2+__pyx_t_10, __pyx_t_16);
      __Pyx_GIVEREF(__pyx_t_15);
      PyTuple_SET_ITEM(__pyx_t_17, 3+__pyx_t_10, __pyx_t_15);
      __Pyx_GIVEREF(__pyx_t_14);
      PyTuple_SET_ITEM(__pyx_t_17, 4+__pyx_t_10, __pyx_t_14);
      __Pyx_GIVEREF(__pyx_t_13);
      PyTuple_SET_ITEM(__pyx_t_17, 5+__pyx_t_10, __pyx_t_13);
      __Pyx_INCREF(((PyObject *)__pyx_v_out));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_out));
      PyTuple_SET_ITEM(__pyx_t_17, 6+__pyx_t_10, ((PyObject *)__pyx_v_out));
      __pyx_t_18 = 0;
      __pyx_t_16 = 0;
      __pyx_t_15 = 0;
      __pyx_t_14 = 0;
      __pyx_t_13 = 0;
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_17, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 653, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "cupy/core/_routines_indexing.pyx":653
 *             a.reduced_view(), indices, ldim, cdim, rdim, index_range, out)
 *     else:
 *         return _take_kernel_scalar(             # <<<<<<<<<<<<<<
 *             a.reduced_view(), indices, ldim, cdim, rdim, index_range, out)
 * 
 */
    if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 653, __pyx_L1_error)
    __pyx_r = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_5);
    __pyx_t_5 = 0;
    goto __pyx_L0;
  }

  /* "cupy/core/_routines_indexing.pyx":594
 * 
 * 
 * cdef ndarray _take(ndarray a, indices, int li, int ri, ndarray out=None):             # <<<<<<<<<<<<<<
 *     # When li + 1 == ri this function behaves similarly to np.take
 *     cdef tuple out_shape, ind_shape, indices_shape
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_AddTraceback("cupy.core._routines_indexing._take", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_out_shape);
  __Pyx_XDECREF(__pyx_v_indices_shape);
  __Pyx_XDECREF(__pyx_v_a_shape);
  __Pyx_XDECREF((PyObject *)__pyx_v_a);
  __Pyx_XDECREF(__pyx_v_indices);
  __Pyx_XDECREF((PyObject *)__pyx_v_out);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":657
 * 
 * 
 * cdef _scatter_op_single(             # <<<<<<<<<<<<<<
 *         ndarray a, ndarray indices, v, Py_ssize_t li=0, Py_ssize_t ri=0,
 *         op=''):
 */

static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__scatter_op_single(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_a, struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_indices, PyObject *__pyx_v_v, struct __pyx_opt_args_4cupy_4core_18_routines_indexing__scatter_op_single *__pyx_optional_args) {
  Py_ssize_t __pyx_v_li = ((Py_ssize_t)0);
  Py_ssize_t __pyx_v_ri = ((Py_ssize_t)0);
  PyObject *__pyx_v_op = ((PyObject *)__pyx_kp_u__19);
  Py_ssize_t __pyx_v_ndim;
  Py_ssize_t __pyx_v_adim;
  Py_ssize_t __pyx_v_cdim;
  Py_ssize_t __pyx_v_rdim;
  PyObject *__pyx_v_a_shape = 0;
  PyObject *__pyx_v_indices_shape = 0;
  PyObject *__pyx_v_lshape = 0;
  PyObject *__pyx_v_rshape = 0;
  PyObject *__pyx_v_v_shape = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  int __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  struct __pyx_opt_args_4cupy_4core_4core_array __pyx_t_6;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  Py_ssize_t __pyx_t_9;
  std::vector<Py_ssize_t>  __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *__pyx_t_13 = NULL;
  int __pyx_t_14;
  PyObject *__pyx_t_15 = NULL;
  PyObject *__pyx_t_16 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_scatter_op_single", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_li = __pyx_optional_args->li;
      if (__pyx_optional_args->__pyx_n > 1) {
        __pyx_v_ri = __pyx_optional_args->ri;
        if (__pyx_optional_args->__pyx_n > 2) {
          __pyx_v_op = __pyx_optional_args->op;
        }
      }
    }
  }
  __Pyx_INCREF((PyObject *)__pyx_v_indices);
  __Pyx_INCREF(__pyx_v_v);

  /* "cupy/core/_routines_indexing.pyx":673
 *     cdef tuple a_shape, indices_shape, lshape, rshape, v_shape
 * 
 *     ndim = a._shape.size()             # <<<<<<<<<<<<<<
 * 
 *     if ndim == 0:
 */
  __pyx_v_ndim = __pyx_v_a->_shape.size();

  /* "cupy/core/_routines_indexing.pyx":675
 *     ndim = a._shape.size()
 * 
 *     if ndim == 0:             # <<<<<<<<<<<<<<
 *         raise ValueError('requires a.ndim >= 1')
 *     if not (-ndim <= li < ndim and -ndim <= ri < ndim):
 */
  __pyx_t_1 = ((__pyx_v_ndim == 0) != 0);
  if (unlikely(__pyx_t_1)) {

    /* "cupy/core/_routines_indexing.pyx":676
 * 
 *     if ndim == 0:
 *         raise ValueError('requires a.ndim >= 1')             # <<<<<<<<<<<<<<
 *     if not (-ndim <= li < ndim and -ndim <= ri < ndim):
 *         raise ValueError('Axis overrun')
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 676, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 676, __pyx_L1_error)

    /* "cupy/core/_routines_indexing.pyx":675
 *     ndim = a._shape.size()
 * 
 *     if ndim == 0:             # <<<<<<<<<<<<<<
 *         raise ValueError('requires a.ndim >= 1')
 *     if not (-ndim <= li < ndim and -ndim <= ri < ndim):
 */
  }

  /* "cupy/core/_routines_indexing.pyx":677
 *     if ndim == 0:
 *         raise ValueError('requires a.ndim >= 1')
 *     if not (-ndim <= li < ndim and -ndim <= ri < ndim):             # <<<<<<<<<<<<<<
 *         raise ValueError('Axis overrun')
 * 
 */
  __pyx_t_3 = ((-__pyx_v_ndim) <= __pyx_v_li);
  if (__pyx_t_3) {
    __pyx_t_3 = (__pyx_v_li < __pyx_v_ndim);
  }
  __pyx_t_4 = (__pyx_t_3 != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_1 = __pyx_t_4;
    goto __pyx_L5_bool_binop_done;
  }
  __pyx_t_4 = ((-__pyx_v_ndim) <= __pyx_v_ri);
  if (__pyx_t_4) {
    __pyx_t_4 = (__pyx_v_ri < __pyx_v_ndim);
  }
  __pyx_t_3 = (__pyx_t_4 != 0);
  __pyx_t_1 = __pyx_t_3;
  __pyx_L5_bool_binop_done:;
  __pyx_t_3 = ((!__pyx_t_1) != 0);
  if (unlikely(__pyx_t_3)) {

    /* "cupy/core/_routines_indexing.pyx":678
 *         raise ValueError('requires a.ndim >= 1')
 *     if not (-ndim <= li < ndim and -ndim <= ri < ndim):
 *         raise ValueError('Axis overrun')             # <<<<<<<<<<<<<<
 * 
 *     if not isinstance(v, ndarray):
 */
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 678, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 678, __pyx_L1_error)

    /* "cupy/core/_routines_indexing.pyx":677
 *     if ndim == 0:
 *         raise ValueError('requires a.ndim >= 1')
 *     if not (-ndim <= li < ndim and -ndim <= ri < ndim):             # <<<<<<<<<<<<<<
 *         raise ValueError('Axis overrun')
 * 
 */
  }

  /* "cupy/core/_routines_indexing.pyx":680
 *         raise ValueError('Axis overrun')
 * 
 *     if not isinstance(v, ndarray):             # <<<<<<<<<<<<<<
 *         v = core.array(v, dtype=a.dtype)
 *     else:
 */
  __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_v, __pyx_ptype_4cupy_4core_4core_ndarray); 
  __pyx_t_1 = ((!(__pyx_t_3 != 0)) != 0);
  if (__pyx_t_1) {

    /* "cupy/core/_routines_indexing.pyx":681
 * 
 *     if not isinstance(v, ndarray):
 *         v = core.array(v, dtype=a.dtype)             # <<<<<<<<<<<<<<
 *     else:
 *         v = v.astype(a.dtype, copy=False)
 */
    __pyx_t_2 = __pyx_v_a->dtype;
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_6.__pyx_n = 1;
    __pyx_t_6.dtype = __pyx_t_2;
    __pyx_t_5 = ((PyObject *)__pyx_f_4cupy_4core_4core_array(__pyx_v_v, 0, &__pyx_t_6)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 681, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF_SET(__pyx_v_v, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "cupy/core/_routines_indexing.pyx":680
 *         raise ValueError('Axis overrun')
 * 
 *     if not isinstance(v, ndarray):             # <<<<<<<<<<<<<<
 *         v = core.array(v, dtype=a.dtype)
 *     else:
 */
    goto __pyx_L7;
  }

  /* "cupy/core/_routines_indexing.pyx":683
 *         v = core.array(v, dtype=a.dtype)
 *     else:
 *         v = v.astype(a.dtype, copy=False)             # <<<<<<<<<<<<<<
 * 
 *     a_shape = a.shape
 */
  /*else*/ {
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_v, __pyx_n_s_astype); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 683, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 683, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_v_a->dtype);
    __Pyx_GIVEREF(__pyx_v_a->dtype);
    PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_a->dtype);
    __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 683, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_copy, Py_False) < 0) __PYX_ERR(0, 683, __pyx_L1_error)
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 683, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF_SET(__pyx_v_v, __pyx_t_8);
    __pyx_t_8 = 0;
  }
  __pyx_L7:;

  /* "cupy/core/_routines_indexing.pyx":685
 *         v = v.astype(a.dtype, copy=False)
 * 
 *     a_shape = a.shape             # <<<<<<<<<<<<<<
 *     li %= ndim
 *     ri %= ndim
 */
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_shape); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 685, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  if (!(likely(PyTuple_CheckExact(__pyx_t_8))||((__pyx_t_8) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_8)->tp_name), 0))) __PYX_ERR(0, 685, __pyx_L1_error)
  __pyx_v_a_shape = ((PyObject*)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "cupy/core/_routines_indexing.pyx":686
 * 
 *     a_shape = a.shape
 *     li %= ndim             # <<<<<<<<<<<<<<
 *     ri %= ndim
 * 
 */
  if (unlikely(__pyx_v_ndim == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
    __PYX_ERR(0, 686, __pyx_L1_error)
  }
  __pyx_v_li = __Pyx_mod_Py_ssize_t(__pyx_v_li, __pyx_v_ndim);

  /* "cupy/core/_routines_indexing.pyx":687
 *     a_shape = a.shape
 *     li %= ndim
 *     ri %= ndim             # <<<<<<<<<<<<<<
 * 
 *     lshape = a_shape[:li]
 */
  if (unlikely(__pyx_v_ndim == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
    __PYX_ERR(0, 687, __pyx_L1_error)
  }
  __pyx_v_ri = __Pyx_mod_Py_ssize_t(__pyx_v_ri, __pyx_v_ndim);

  /* "cupy/core/_routines_indexing.pyx":689
 *     ri %= ndim
 * 
 *     lshape = a_shape[:li]             # <<<<<<<<<<<<<<
 *     rshape = a_shape[ri + 1:]
 *     adim = internal.prod_sequence(a_shape[li:ri + 1])
 */
  if (unlikely(__pyx_v_a_shape == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 689, __pyx_L1_error)
  }
  __pyx_t_8 = __Pyx_PyTuple_GetSlice(__pyx_v_a_shape, 0, __pyx_v_li); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 689, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_v_lshape = ((PyObject*)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "cupy/core/_routines_indexing.pyx":690
 * 
 *     lshape = a_shape[:li]
 *     rshape = a_shape[ri + 1:]             # <<<<<<<<<<<<<<
 *     adim = internal.prod_sequence(a_shape[li:ri + 1])
 * 
 */
  if (unlikely(__pyx_v_a_shape == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 690, __pyx_L1_error)
  }
  __pyx_t_8 = __Pyx_PyTuple_GetSlice(__pyx_v_a_shape, (__pyx_v_ri + 1), PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 690, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_v_rshape = ((PyObject*)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "cupy/core/_routines_indexing.pyx":691
 *     lshape = a_shape[:li]
 *     rshape = a_shape[ri + 1:]
 *     adim = internal.prod_sequence(a_shape[li:ri + 1])             # <<<<<<<<<<<<<<
 * 
 *     indices_shape = indices.shape
 */
  if (unlikely(__pyx_v_a_shape == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 691, __pyx_L1_error)
  }
  __pyx_t_8 = __Pyx_PyTuple_GetSlice(__pyx_v_a_shape, __pyx_v_li, (__pyx_v_ri + 1)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 691, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_v_adim = __pyx_f_4cupy_4core_8internal_prod_sequence(__pyx_t_8, 0);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "cupy/core/_routines_indexing.pyx":693
 *     adim = internal.prod_sequence(a_shape[li:ri + 1])
 * 
 *     indices_shape = indices.shape             # <<<<<<<<<<<<<<
 *     v_shape = lshape + indices_shape + rshape
 *     v = _manipulation.broadcast_to(v, v_shape)
 */
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_indices), __pyx_n_s_shape); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 693, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  if (!(likely(PyTuple_CheckExact(__pyx_t_8))||((__pyx_t_8) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_8)->tp_name), 0))) __PYX_ERR(0, 693, __pyx_L1_error)
  __pyx_v_indices_shape = ((PyObject*)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "cupy/core/_routines_indexing.pyx":694
 * 
 *     indices_shape = indices.shape
 *     v_shape = lshape + indices_shape + rshape             # <<<<<<<<<<<<<<
 *     v = _manipulation.broadcast_to(v, v_shape)
 * 
 */
  __pyx_t_8 = PyNumber_Add(__pyx_v_lshape, __pyx_v_indices_shape); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 694, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_7 = PyNumber_Add(__pyx_t_8, __pyx_v_rshape); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 694, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_v_v_shape = ((PyObject*)__pyx_t_7);
  __pyx_t_7 = 0;

  /* "cupy/core/_routines_indexing.pyx":695
 *     indices_shape = indices.shape
 *     v_shape = lshape + indices_shape + rshape
 *     v = _manipulation.broadcast_to(v, v_shape)             # <<<<<<<<<<<<<<
 * 
 *     cdim = indices.size
 */
  if (!(likely(((__pyx_v_v) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_v, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 695, __pyx_L1_error)
  __pyx_t_7 = ((PyObject *)__pyx_f_4cupy_4core_22_routines_manipulation_broadcast_to(((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_v_v), __pyx_v_v_shape, 0)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 695, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF_SET(__pyx_v_v, __pyx_t_7);
  __pyx_t_7 = 0;

  /* "cupy/core/_routines_indexing.pyx":697
 *     v = _manipulation.broadcast_to(v, v_shape)
 * 
 *     cdim = indices.size             # <<<<<<<<<<<<<<
 *     rdim = internal.prod_sequence(rshape)
 *     indices = _manipulation._reshape(
 */
  __pyx_t_9 = __pyx_v_indices->size;
  __pyx_v_cdim = __pyx_t_9;

  /* "cupy/core/_routines_indexing.pyx":698
 * 
 *     cdim = indices.size
 *     rdim = internal.prod_sequence(rshape)             # <<<<<<<<<<<<<<
 *     indices = _manipulation._reshape(
 *         indices,
 */
  __pyx_v_rdim = __pyx_f_4cupy_4core_8internal_prod_sequence(__pyx_v_rshape, 0);

  /* "cupy/core/_routines_indexing.pyx":701
 *     indices = _manipulation._reshape(
 *         indices,
 *         (1,) * len(lshape) + indices_shape + (1,) * len(rshape))             # <<<<<<<<<<<<<<
 *     indices = _manipulation.broadcast_to(indices, v_shape)
 * 
 */
  __pyx_t_9 = PyTuple_GET_SIZE(__pyx_v_lshape); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 701, __pyx_L1_error)
  __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 701, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = PyNumber_Multiply(__pyx_tuple__15, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 701, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyNumber_Add(__pyx_t_8, __pyx_v_indices_shape); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 701, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_9 = PyTuple_GET_SIZE(__pyx_v_rshape); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 701, __pyx_L1_error)
  __pyx_t_8 = PyInt_FromSsize_t(__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 701, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_2 = PyNumber_Multiply(__pyx_tuple__15, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 701, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyNumber_Add(__pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 701, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_10 = __pyx_convert_vector_from_py_Py_ssize_t(__pyx_t_8); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 701, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "cupy/core/_routines_indexing.pyx":699
 *     cdim = indices.size
 *     rdim = internal.prod_sequence(rshape)
 *     indices = _manipulation._reshape(             # <<<<<<<<<<<<<<
 *         indices,
 *         (1,) * len(lshape) + indices_shape + (1,) * len(rshape))
 */
  __pyx_t_8 = ((PyObject *)__pyx_f_4cupy_4core_22_routines_manipulation__reshape(__pyx_v_indices, __pyx_t_10, 0)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 699, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF_SET(__pyx_v_indices, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_8));
  __pyx_t_8 = 0;

  /* "cupy/core/_routines_indexing.pyx":702
 *         indices,
 *         (1,) * len(lshape) + indices_shape + (1,) * len(rshape))
 *     indices = _manipulation.broadcast_to(indices, v_shape)             # <<<<<<<<<<<<<<
 * 
 *     if op == 'update':
 */
  __pyx_t_8 = ((PyObject *)__pyx_f_4cupy_4core_22_routines_manipulation_broadcast_to(__pyx_v_indices, __pyx_v_v_shape, 0)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 702, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF_SET(__pyx_v_indices, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_8));
  __pyx_t_8 = 0;

  /* "cupy/core/_routines_indexing.pyx":704
 *     indices = _manipulation.broadcast_to(indices, v_shape)
 * 
 *     if op == 'update':             # <<<<<<<<<<<<<<
 *         _scatter_update_kernel(
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 */
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_op, __pyx_n_u_update, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 704, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "cupy/core/_routines_indexing.pyx":705
 * 
 *     if op == 'update':
 *         _scatter_update_kernel(             # <<<<<<<<<<<<<<
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 *     elif op == 'add':
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_scatter_update_kernel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 705, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);

    /* "cupy/core/_routines_indexing.pyx":706
 *     if op == 'update':
 *         _scatter_update_kernel(
 *             v, indices, cdim, rdim, adim, a.reduced_view())             # <<<<<<<<<<<<<<
 *     elif op == 'add':
 *         # There is constraints on types because atomicAdd() in CUDA 7.5
 */
    __pyx_t_7 = PyInt_FromSsize_t(__pyx_v_cdim); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 706, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_rdim); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 706, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_11 = PyInt_FromSsize_t(__pyx_v_adim); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 706, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_12 = ((PyObject *)((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)__pyx_v_a->__pyx_vtab)->reduced_view(__pyx_v_a, 0, NULL)); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 706, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_13 = NULL;
    __pyx_t_14 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_13)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_13);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_14 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[7] = {__pyx_t_13, __pyx_v_v, ((PyObject *)__pyx_v_indices), __pyx_t_7, __pyx_t_5, __pyx_t_11, __pyx_t_12};
      __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_14, 6+__pyx_t_14); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 705, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[7] = {__pyx_t_13, __pyx_v_v, ((PyObject *)__pyx_v_indices), __pyx_t_7, __pyx_t_5, __pyx_t_11, __pyx_t_12};
      __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_14, 6+__pyx_t_14); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 705, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    } else
    #endif
    {
      __pyx_t_15 = PyTuple_New(6+__pyx_t_14); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 705, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      if (__pyx_t_13) {
        __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_13); __pyx_t_13 = NULL;
      }
      __Pyx_INCREF(__pyx_v_v);
      __Pyx_GIVEREF(__pyx_v_v);
      PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_14, __pyx_v_v);
      __Pyx_INCREF(((PyObject *)__pyx_v_indices));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_indices));
      PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_14, ((PyObject *)__pyx_v_indices));
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_15, 2+__pyx_t_14, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_15, 3+__pyx_t_14, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_15, 4+__pyx_t_14, __pyx_t_11);
      __Pyx_GIVEREF(__pyx_t_12);
      PyTuple_SET_ITEM(__pyx_t_15, 5+__pyx_t_14, __pyx_t_12);
      __pyx_t_7 = 0;
      __pyx_t_5 = 0;
      __pyx_t_11 = 0;
      __pyx_t_12 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_15, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 705, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":704
 *     indices = _manipulation.broadcast_to(indices, v_shape)
 * 
 *     if op == 'update':             # <<<<<<<<<<<<<<
 *         _scatter_update_kernel(
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 */
    goto __pyx_L8;
  }

  /* "cupy/core/_routines_indexing.pyx":707
 *         _scatter_update_kernel(
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 *     elif op == 'add':             # <<<<<<<<<<<<<<
 *         # There is constraints on types because atomicAdd() in CUDA 7.5
 *         # only supports int32, uint32, uint64, and float32.
 */
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_op, __pyx_n_u_add, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 707, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "cupy/core/_routines_indexing.pyx":710
 *         # There is constraints on types because atomicAdd() in CUDA 7.5
 *         # only supports int32, uint32, uint64, and float32.
 *         if not issubclass(v.dtype.type,             # <<<<<<<<<<<<<<
 *                           (numpy.int32, numpy.float16, numpy.float32,
 *                            numpy.float64, numpy.uint32, numpy.uint64,
 */
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_v, __pyx_n_s_dtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 710, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_type); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 710, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":711
 *         # only supports int32, uint32, uint64, and float32.
 *         if not issubclass(v.dtype.type,
 *                           (numpy.int32, numpy.float16, numpy.float32,             # <<<<<<<<<<<<<<
 *                            numpy.float64, numpy.uint32, numpy.uint64,
 *                            numpy.ulonglong)):
 */
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_int32); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_float16); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_float32); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":712
 *         if not issubclass(v.dtype.type,
 *                           (numpy.int32, numpy.float16, numpy.float32,
 *                            numpy.float64, numpy.uint32, numpy.uint64,             # <<<<<<<<<<<<<<
 *                            numpy.ulonglong)):
 *             raise TypeError(
 */
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 712, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_float64); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 712, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 712, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_uint32); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 712, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 712, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_uint64); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 712, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":713
 *                           (numpy.int32, numpy.float16, numpy.float32,
 *                            numpy.float64, numpy.uint32, numpy.uint64,
 *                            numpy.ulonglong)):             # <<<<<<<<<<<<<<
 *             raise TypeError(
 *                 'scatter_add only supports int32, float16, float32, float64, '
 */
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 713, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_ulonglong); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 713, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":711
 *         # only supports int32, uint32, uint64, and float32.
 *         if not issubclass(v.dtype.type,
 *                           (numpy.int32, numpy.float16, numpy.float32,             # <<<<<<<<<<<<<<
 *                            numpy.float64, numpy.uint32, numpy.uint64,
 *                            numpy.ulonglong)):
 */
    __pyx_t_8 = PyTuple_New(7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 711, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_15);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_15);
    __Pyx_GIVEREF(__pyx_t_12);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_12);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_13);
    PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_t_13);
    __Pyx_GIVEREF(__pyx_t_16);
    PyTuple_SET_ITEM(__pyx_t_8, 6, __pyx_t_16);
    __pyx_t_15 = 0;
    __pyx_t_12 = 0;
    __pyx_t_11 = 0;
    __pyx_t_5 = 0;
    __pyx_t_7 = 0;
    __pyx_t_13 = 0;
    __pyx_t_16 = 0;

    /* "cupy/core/_routines_indexing.pyx":710
 *         # There is constraints on types because atomicAdd() in CUDA 7.5
 *         # only supports int32, uint32, uint64, and float32.
 *         if not issubclass(v.dtype.type,             # <<<<<<<<<<<<<<
 *                           (numpy.int32, numpy.float16, numpy.float32,
 *                            numpy.float64, numpy.uint32, numpy.uint64,
 */
    __pyx_t_1 = PyObject_IsSubclass(__pyx_t_2, __pyx_t_8); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 710, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_3 = ((!(__pyx_t_1 != 0)) != 0);
    if (unlikely(__pyx_t_3)) {

      /* "cupy/core/_routines_indexing.pyx":714
 *                            numpy.float64, numpy.uint32, numpy.uint64,
 *                            numpy.ulonglong)):
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 'scatter_add only supports int32, float16, float32, float64, '
 *                 'uint32, uint64, as data type')
 */
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 714, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __PYX_ERR(0, 714, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":710
 *         # There is constraints on types because atomicAdd() in CUDA 7.5
 *         # only supports int32, uint32, uint64, and float32.
 *         if not issubclass(v.dtype.type,             # <<<<<<<<<<<<<<
 *                           (numpy.int32, numpy.float16, numpy.float32,
 *                            numpy.float64, numpy.uint32, numpy.uint64,
 */
    }

    /* "cupy/core/_routines_indexing.pyx":717
 *                 'scatter_add only supports int32, float16, float32, float64, '
 *                 'uint32, uint64, as data type')
 *         _scatter_add_kernel(             # <<<<<<<<<<<<<<
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 *     elif op == 'max':
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_scatter_add_kernel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 717, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);

    /* "cupy/core/_routines_indexing.pyx":718
 *                 'uint32, uint64, as data type')
 *         _scatter_add_kernel(
 *             v, indices, cdim, rdim, adim, a.reduced_view())             # <<<<<<<<<<<<<<
 *     elif op == 'max':
 *         if not issubclass(v.dtype.type,
 */
    __pyx_t_16 = PyInt_FromSsize_t(__pyx_v_cdim); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 718, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __pyx_t_13 = PyInt_FromSsize_t(__pyx_v_rdim); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 718, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_7 = PyInt_FromSsize_t(__pyx_v_adim); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 718, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_5 = ((PyObject *)((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)__pyx_v_a->__pyx_vtab)->reduced_view(__pyx_v_a, 0, NULL)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 718, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_11 = NULL;
    __pyx_t_14 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_11)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_11);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_14 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[7] = {__pyx_t_11, __pyx_v_v, ((PyObject *)__pyx_v_indices), __pyx_t_16, __pyx_t_13, __pyx_t_7, __pyx_t_5};
      __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_14, 6+__pyx_t_14); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 717, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[7] = {__pyx_t_11, __pyx_v_v, ((PyObject *)__pyx_v_indices), __pyx_t_16, __pyx_t_13, __pyx_t_7, __pyx_t_5};
      __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_14, 6+__pyx_t_14); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 717, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else
    #endif
    {
      __pyx_t_12 = PyTuple_New(6+__pyx_t_14); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 717, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      if (__pyx_t_11) {
        __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL;
      }
      __Pyx_INCREF(__pyx_v_v);
      __Pyx_GIVEREF(__pyx_v_v);
      PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_14, __pyx_v_v);
      __Pyx_INCREF(((PyObject *)__pyx_v_indices));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_indices));
      PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_14, ((PyObject *)__pyx_v_indices));
      __Pyx_GIVEREF(__pyx_t_16);
      PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_14, __pyx_t_16);
      __Pyx_GIVEREF(__pyx_t_13);
      PyTuple_SET_ITEM(__pyx_t_12, 3+__pyx_t_14, __pyx_t_13);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_12, 4+__pyx_t_14, __pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_12, 5+__pyx_t_14, __pyx_t_5);
      __pyx_t_16 = 0;
      __pyx_t_13 = 0;
      __pyx_t_7 = 0;
      __pyx_t_5 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_12, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 717, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":707
 *         _scatter_update_kernel(
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 *     elif op == 'add':             # <<<<<<<<<<<<<<
 *         # There is constraints on types because atomicAdd() in CUDA 7.5
 *         # only supports int32, uint32, uint64, and float32.
 */
    goto __pyx_L8;
  }

  /* "cupy/core/_routines_indexing.pyx":719
 *         _scatter_add_kernel(
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 *     elif op == 'max':             # <<<<<<<<<<<<<<
 *         if not issubclass(v.dtype.type,
 *                           (numpy.int32, numpy.float32, numpy.float64,
 */
  __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_op, __pyx_n_u_max, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 719, __pyx_L1_error)
  if (__pyx_t_3) {

    /* "cupy/core/_routines_indexing.pyx":720
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 *     elif op == 'max':
 *         if not issubclass(v.dtype.type,             # <<<<<<<<<<<<<<
 *                           (numpy.int32, numpy.float32, numpy.float64,
 *                            numpy.uint32, numpy.uint64, numpy.ulonglong)):
 */
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_v, __pyx_n_s_dtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 720, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_type); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 720, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":721
 *     elif op == 'max':
 *         if not issubclass(v.dtype.type,
 *                           (numpy.int32, numpy.float32, numpy.float64,             # <<<<<<<<<<<<<<
 *                            numpy.uint32, numpy.uint64, numpy.ulonglong)):
 *             raise TypeError(
 */
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 721, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_int32); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 721, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 721, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_float32); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 721, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 721, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_float64); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 721, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":722
 *         if not issubclass(v.dtype.type,
 *                           (numpy.int32, numpy.float32, numpy.float64,
 *                            numpy.uint32, numpy.uint64, numpy.ulonglong)):             # <<<<<<<<<<<<<<
 *             raise TypeError(
 *                 'scatter_max only supports int32, float32, float64, '
 */
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 722, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_uint32); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 722, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 722, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_uint64); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 722, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 722, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_ulonglong); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 722, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":721
 *     elif op == 'max':
 *         if not issubclass(v.dtype.type,
 *                           (numpy.int32, numpy.float32, numpy.float64,             # <<<<<<<<<<<<<<
 *                            numpy.uint32, numpy.uint64, numpy.ulonglong)):
 *             raise TypeError(
 */
    __pyx_t_8 = PyTuple_New(6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 721, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_12);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_12);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_13);
    PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_13);
    __Pyx_GIVEREF(__pyx_t_16);
    PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_t_16);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_t_11);
    __pyx_t_12 = 0;
    __pyx_t_5 = 0;
    __pyx_t_7 = 0;
    __pyx_t_13 = 0;
    __pyx_t_16 = 0;
    __pyx_t_11 = 0;

    /* "cupy/core/_routines_indexing.pyx":720
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 *     elif op == 'max':
 *         if not issubclass(v.dtype.type,             # <<<<<<<<<<<<<<
 *                           (numpy.int32, numpy.float32, numpy.float64,
 *                            numpy.uint32, numpy.uint64, numpy.ulonglong)):
 */
    __pyx_t_3 = PyObject_IsSubclass(__pyx_t_2, __pyx_t_8); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 720, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_1 = ((!(__pyx_t_3 != 0)) != 0);
    if (unlikely(__pyx_t_1)) {

      /* "cupy/core/_routines_indexing.pyx":723
 *                           (numpy.int32, numpy.float32, numpy.float64,
 *                            numpy.uint32, numpy.uint64, numpy.ulonglong)):
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 'scatter_max only supports int32, float32, float64, '
 *                 'uint32, uint64 as data type')
 */
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 723, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __PYX_ERR(0, 723, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":720
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 *     elif op == 'max':
 *         if not issubclass(v.dtype.type,             # <<<<<<<<<<<<<<
 *                           (numpy.int32, numpy.float32, numpy.float64,
 *                            numpy.uint32, numpy.uint64, numpy.ulonglong)):
 */
    }

    /* "cupy/core/_routines_indexing.pyx":726
 *                 'scatter_max only supports int32, float32, float64, '
 *                 'uint32, uint64 as data type')
 *         _scatter_max_kernel(             # <<<<<<<<<<<<<<
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 *     elif op == 'min':
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_scatter_max_kernel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 726, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);

    /* "cupy/core/_routines_indexing.pyx":727
 *                 'uint32, uint64 as data type')
 *         _scatter_max_kernel(
 *             v, indices, cdim, rdim, adim, a.reduced_view())             # <<<<<<<<<<<<<<
 *     elif op == 'min':
 *         if not issubclass(v.dtype.type,
 */
    __pyx_t_11 = PyInt_FromSsize_t(__pyx_v_cdim); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 727, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_16 = PyInt_FromSsize_t(__pyx_v_rdim); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 727, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __pyx_t_13 = PyInt_FromSsize_t(__pyx_v_adim); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 727, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_7 = ((PyObject *)((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)__pyx_v_a->__pyx_vtab)->reduced_view(__pyx_v_a, 0, NULL)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 727, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_5 = NULL;
    __pyx_t_14 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_14 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[7] = {__pyx_t_5, __pyx_v_v, ((PyObject *)__pyx_v_indices), __pyx_t_11, __pyx_t_16, __pyx_t_13, __pyx_t_7};
      __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_14, 6+__pyx_t_14); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 726, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[7] = {__pyx_t_5, __pyx_v_v, ((PyObject *)__pyx_v_indices), __pyx_t_11, __pyx_t_16, __pyx_t_13, __pyx_t_7};
      __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_14, 6+__pyx_t_14); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 726, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    } else
    #endif
    {
      __pyx_t_12 = PyTuple_New(6+__pyx_t_14); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 726, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      if (__pyx_t_5) {
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_5); __pyx_t_5 = NULL;
      }
      __Pyx_INCREF(__pyx_v_v);
      __Pyx_GIVEREF(__pyx_v_v);
      PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_14, __pyx_v_v);
      __Pyx_INCREF(((PyObject *)__pyx_v_indices));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_indices));
      PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_14, ((PyObject *)__pyx_v_indices));
      __Pyx_GIVEREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_14, __pyx_t_11);
      __Pyx_GIVEREF(__pyx_t_16);
      PyTuple_SET_ITEM(__pyx_t_12, 3+__pyx_t_14, __pyx_t_16);
      __Pyx_GIVEREF(__pyx_t_13);
      PyTuple_SET_ITEM(__pyx_t_12, 4+__pyx_t_14, __pyx_t_13);
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_12, 5+__pyx_t_14, __pyx_t_7);
      __pyx_t_11 = 0;
      __pyx_t_16 = 0;
      __pyx_t_13 = 0;
      __pyx_t_7 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_12, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 726, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":719
 *         _scatter_add_kernel(
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 *     elif op == 'max':             # <<<<<<<<<<<<<<
 *         if not issubclass(v.dtype.type,
 *                           (numpy.int32, numpy.float32, numpy.float64,
 */
    goto __pyx_L8;
  }

  /* "cupy/core/_routines_indexing.pyx":728
 *         _scatter_max_kernel(
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 *     elif op == 'min':             # <<<<<<<<<<<<<<
 *         if not issubclass(v.dtype.type,
 *                           (numpy.int32, numpy.float32, numpy.float64,
 */
  __pyx_t_1 = (__Pyx_PyUnicode_Equals(__pyx_v_op, __pyx_n_u_min, Py_EQ)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 728, __pyx_L1_error)
  if (likely(__pyx_t_1)) {

    /* "cupy/core/_routines_indexing.pyx":729
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 *     elif op == 'min':
 *         if not issubclass(v.dtype.type,             # <<<<<<<<<<<<<<
 *                           (numpy.int32, numpy.float32, numpy.float64,
 *                            numpy.uint32, numpy.uint64, numpy.ulonglong)):
 */
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_v, __pyx_n_s_dtype); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 729, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_type); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 729, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":730
 *     elif op == 'min':
 *         if not issubclass(v.dtype.type,
 *                           (numpy.int32, numpy.float32, numpy.float64,             # <<<<<<<<<<<<<<
 *                            numpy.uint32, numpy.uint64, numpy.ulonglong)):
 *             raise TypeError(
 */
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 730, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_int32); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 730, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 730, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_float32); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 730, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 730, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_float64); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 730, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":731
 *         if not issubclass(v.dtype.type,
 *                           (numpy.int32, numpy.float32, numpy.float64,
 *                            numpy.uint32, numpy.uint64, numpy.ulonglong)):             # <<<<<<<<<<<<<<
 *             raise TypeError(
 *                 'scatter_min only supports int32, float32, float64, '
 */
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 731, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_uint32); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 731, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 731, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_uint64); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 731, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_numpy); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 731, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_ulonglong); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 731, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":730
 *     elif op == 'min':
 *         if not issubclass(v.dtype.type,
 *                           (numpy.int32, numpy.float32, numpy.float64,             # <<<<<<<<<<<<<<
 *                            numpy.uint32, numpy.uint64, numpy.ulonglong)):
 *             raise TypeError(
 */
    __pyx_t_8 = PyTuple_New(6); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 730, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_12);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_12);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_13);
    PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_13);
    __Pyx_GIVEREF(__pyx_t_16);
    PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_16);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_8, 4, __pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_8, 5, __pyx_t_5);
    __pyx_t_12 = 0;
    __pyx_t_7 = 0;
    __pyx_t_13 = 0;
    __pyx_t_16 = 0;
    __pyx_t_11 = 0;
    __pyx_t_5 = 0;

    /* "cupy/core/_routines_indexing.pyx":729
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 *     elif op == 'min':
 *         if not issubclass(v.dtype.type,             # <<<<<<<<<<<<<<
 *                           (numpy.int32, numpy.float32, numpy.float64,
 *                            numpy.uint32, numpy.uint64, numpy.ulonglong)):
 */
    __pyx_t_1 = PyObject_IsSubclass(__pyx_t_2, __pyx_t_8); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 729, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_3 = ((!(__pyx_t_1 != 0)) != 0);
    if (unlikely(__pyx_t_3)) {

      /* "cupy/core/_routines_indexing.pyx":732
 *                           (numpy.int32, numpy.float32, numpy.float64,
 *                            numpy.uint32, numpy.uint64, numpy.ulonglong)):
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 'scatter_min only supports int32, float32, float64, '
 *                 'uint32, uint64 as data type')
 */
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 732, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_Raise(__pyx_t_8, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __PYX_ERR(0, 732, __pyx_L1_error)

      /* "cupy/core/_routines_indexing.pyx":729
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 *     elif op == 'min':
 *         if not issubclass(v.dtype.type,             # <<<<<<<<<<<<<<
 *                           (numpy.int32, numpy.float32, numpy.float64,
 *                            numpy.uint32, numpy.uint64, numpy.ulonglong)):
 */
    }

    /* "cupy/core/_routines_indexing.pyx":735
 *                 'scatter_min only supports int32, float32, float64, '
 *                 'uint32, uint64 as data type')
 *         _scatter_min_kernel(             # <<<<<<<<<<<<<<
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 *     else:
 */
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_scatter_min_kernel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 735, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);

    /* "cupy/core/_routines_indexing.pyx":736
 *                 'uint32, uint64 as data type')
 *         _scatter_min_kernel(
 *             v, indices, cdim, rdim, adim, a.reduced_view())             # <<<<<<<<<<<<<<
 *     else:
 *         raise ValueError('provided op is not supported')
 */
    __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_cdim); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 736, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_11 = PyInt_FromSsize_t(__pyx_v_rdim); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 736, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_16 = PyInt_FromSsize_t(__pyx_v_adim); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 736, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __pyx_t_13 = ((PyObject *)((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)__pyx_v_a->__pyx_vtab)->reduced_view(__pyx_v_a, 0, NULL)); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 736, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __pyx_t_7 = NULL;
    __pyx_t_14 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
        __pyx_t_14 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[7] = {__pyx_t_7, __pyx_v_v, ((PyObject *)__pyx_v_indices), __pyx_t_5, __pyx_t_11, __pyx_t_16, __pyx_t_13};
      __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_14, 6+__pyx_t_14); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 735, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[7] = {__pyx_t_7, __pyx_v_v, ((PyObject *)__pyx_v_indices), __pyx_t_5, __pyx_t_11, __pyx_t_16, __pyx_t_13};
      __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_14, 6+__pyx_t_14); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 735, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    } else
    #endif
    {
      __pyx_t_12 = PyTuple_New(6+__pyx_t_14); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 735, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      if (__pyx_t_7) {
        __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_7); __pyx_t_7 = NULL;
      }
      __Pyx_INCREF(__pyx_v_v);
      __Pyx_GIVEREF(__pyx_v_v);
      PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_14, __pyx_v_v);
      __Pyx_INCREF(((PyObject *)__pyx_v_indices));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_indices));
      PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_14, ((PyObject *)__pyx_v_indices));
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_14, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_12, 3+__pyx_t_14, __pyx_t_11);
      __Pyx_GIVEREF(__pyx_t_16);
      PyTuple_SET_ITEM(__pyx_t_12, 4+__pyx_t_14, __pyx_t_16);
      __Pyx_GIVEREF(__pyx_t_13);
      PyTuple_SET_ITEM(__pyx_t_12, 5+__pyx_t_14, __pyx_t_13);
      __pyx_t_5 = 0;
      __pyx_t_11 = 0;
      __pyx_t_16 = 0;
      __pyx_t_13 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_12, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 735, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "cupy/core/_routines_indexing.pyx":728
 *         _scatter_max_kernel(
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 *     elif op == 'min':             # <<<<<<<<<<<<<<
 *         if not issubclass(v.dtype.type,
 *                           (numpy.int32, numpy.float32, numpy.float64,
 */
    goto __pyx_L8;
  }

  /* "cupy/core/_routines_indexing.pyx":738
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 *     else:
 *         raise ValueError('provided op is not supported')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 738, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_Raise(__pyx_t_8, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __PYX_ERR(0, 738, __pyx_L1_error)
  }
  __pyx_L8:;

  /* "cupy/core/_routines_indexing.pyx":657
 * 
 * 
 * cdef _scatter_op_single(             # <<<<<<<<<<<<<<
 *         ndarray a, ndarray indices, v, Py_ssize_t li=0, Py_ssize_t ri=0,
 *         op=''):
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_15);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_AddTraceback("cupy.core._routines_indexing._scatter_op_single", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_a_shape);
  __Pyx_XDECREF(__pyx_v_indices_shape);
  __Pyx_XDECREF(__pyx_v_lshape);
  __Pyx_XDECREF(__pyx_v_rshape);
  __Pyx_XDECREF(__pyx_v_v_shape);
  __Pyx_XDECREF((PyObject *)__pyx_v_indices);
  __Pyx_XDECREF(__pyx_v_v);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":741
 * 
 * 
 * cdef _scatter_op_mask_single(ndarray a, ndarray mask, v, Py_ssize_t axis, op):             # <<<<<<<<<<<<<<
 *     cdef ndarray mask_scanned, src
 *     cdef tuple masked_shape
 */

static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__scatter_op_mask_single(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_a, struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_mask, PyObject *__pyx_v_v, Py_ssize_t __pyx_v_axis, PyObject *__pyx_v_op) {
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_mask_scanned = 0;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_src = 0;
  PyObject *__pyx_v_masked_shape = 0;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *(*__pyx_t_6)(PyObject *);
  std::vector<Py_ssize_t>  __pyx_t_7;
  int __pyx_t_8;
  int __pyx_t_9;
  struct __pyx_opt_args_4cupy_4core_4core_array __pyx_t_10;
  int __pyx_t_11;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_scatter_op_mask_single", 0);
  __Pyx_INCREF((PyObject *)__pyx_v_mask);

  /* "cupy/core/_routines_indexing.pyx":745
 *     cdef tuple masked_shape
 * 
 *     mask, mask_scanned, masked_shape = _prepare_mask_indexing_single(             # <<<<<<<<<<<<<<
 *         a, mask, axis)
 *     if internal.prod(masked_shape) == 0:
 */
  __pyx_t_1 = __pyx_f_4cupy_4core_18_routines_indexing__prepare_mask_indexing_single(__pyx_v_a, __pyx_v_mask, __pyx_v_axis, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 745, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
    PyObject* sequence = __pyx_t_1;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 3)) {
      if (size > 3) __Pyx_RaiseTooManyValuesError(3);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 745, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 2); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_4 = PyList_GET_ITEM(sequence, 2); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_4);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 745, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 745, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 745, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    #endif
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_5 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 745, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_6 = Py_TYPE(__pyx_t_5)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L3_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_3);
    index = 2; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L3_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_4);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 3) < 0) __PYX_ERR(0, 745, __pyx_L1_error)
    __pyx_t_6 = NULL;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    goto __pyx_L4_unpacking_done;
    __pyx_L3_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 745, __pyx_L1_error)
    __pyx_L4_unpacking_done:;
  }
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 745, __pyx_L1_error)
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 745, __pyx_L1_error)
  if (!(likely(PyTuple_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "tuple", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 745, __pyx_L1_error)
  __Pyx_DECREF_SET(__pyx_v_mask, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2));
  __pyx_t_2 = 0;
  __pyx_v_mask_scanned = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_v_masked_shape = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "cupy/core/_routines_indexing.pyx":747
 *     mask, mask_scanned, masked_shape = _prepare_mask_indexing_single(
 *         a, mask, axis)
 *     if internal.prod(masked_shape) == 0:             # <<<<<<<<<<<<<<
 *         return
 * 
 */
  __pyx_t_7 = __pyx_convert_vector_from_py_Py_ssize_t(__pyx_v_masked_shape); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 747, __pyx_L1_error)
  __pyx_t_8 = ((__pyx_f_4cupy_4core_8internal_prod(__pyx_t_7, 0) == 0) != 0);
  if (__pyx_t_8) {

    /* "cupy/core/_routines_indexing.pyx":748
 *         a, mask, axis)
 *     if internal.prod(masked_shape) == 0:
 *         return             # <<<<<<<<<<<<<<
 * 
 *     if not isinstance(v, ndarray):
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "cupy/core/_routines_indexing.pyx":747
 *     mask, mask_scanned, masked_shape = _prepare_mask_indexing_single(
 *         a, mask, axis)
 *     if internal.prod(masked_shape) == 0:             # <<<<<<<<<<<<<<
 *         return
 * 
 */
  }

  /* "cupy/core/_routines_indexing.pyx":750
 *         return
 * 
 *     if not isinstance(v, ndarray):             # <<<<<<<<<<<<<<
 *         src = core.array(v, dtype=a.dtype)
 *     else:
 */
  __pyx_t_8 = __Pyx_TypeCheck(__pyx_v_v, __pyx_ptype_4cupy_4core_4core_ndarray); 
  __pyx_t_9 = ((!(__pyx_t_8 != 0)) != 0);
  if (__pyx_t_9) {

    /* "cupy/core/_routines_indexing.pyx":751
 * 
 *     if not isinstance(v, ndarray):
 *         src = core.array(v, dtype=a.dtype)             # <<<<<<<<<<<<<<
 *     else:
 *         src = v
 */
    __pyx_t_1 = __pyx_v_a->dtype;
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_10.__pyx_n = 1;
    __pyx_t_10.dtype = __pyx_t_1;
    __pyx_t_4 = ((PyObject *)__pyx_f_4cupy_4core_4core_array(__pyx_v_v, 0, &__pyx_t_10)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 751, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_src = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "cupy/core/_routines_indexing.pyx":750
 *         return
 * 
 *     if not isinstance(v, ndarray):             # <<<<<<<<<<<<<<
 *         src = core.array(v, dtype=a.dtype)
 *     else:
 */
    goto __pyx_L6;
  }

  /* "cupy/core/_routines_indexing.pyx":753
 *         src = core.array(v, dtype=a.dtype)
 *     else:
 *         src = v             # <<<<<<<<<<<<<<
 *         # Cython's static resolution does not work because of omitted arguments
 *         src = (<object>src).astype(a.dtype, copy=False)
 */
  /*else*/ {
    if (!(likely(((__pyx_v_v) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_v, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 753, __pyx_L1_error)
    __pyx_t_4 = __pyx_v_v;
    __Pyx_INCREF(__pyx_t_4);
    __pyx_v_src = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "cupy/core/_routines_indexing.pyx":755
 *         src = v
 *         # Cython's static resolution does not work because of omitted arguments
 *         src = (<object>src).astype(a.dtype, copy=False)             # <<<<<<<<<<<<<<
 *     # broadcast src to shape determined by the mask
 *     src = _manipulation.broadcast_to(src, masked_shape)
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_src), __pyx_n_s_astype); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 755, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 755, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_a->dtype);
    __Pyx_GIVEREF(__pyx_v_a->dtype);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_a->dtype);
    __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 755, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_copy, Py_False) < 0) __PYX_ERR(0, 755, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 755, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 755, __pyx_L1_error)
    __Pyx_DECREF_SET(__pyx_v_src, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2));
    __pyx_t_2 = 0;
  }
  __pyx_L6:;

  /* "cupy/core/_routines_indexing.pyx":757
 *         src = (<object>src).astype(a.dtype, copy=False)
 *     # broadcast src to shape determined by the mask
 *     src = _manipulation.broadcast_to(src, masked_shape)             # <<<<<<<<<<<<<<
 * 
 *     if op == 'update':
 */
  __pyx_t_2 = ((PyObject *)__pyx_f_4cupy_4core_22_routines_manipulation_broadcast_to(__pyx_v_src, __pyx_v_masked_shape, 0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 757, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF_SET(__pyx_v_src, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2));
  __pyx_t_2 = 0;

  /* "cupy/core/_routines_indexing.pyx":759
 *     src = _manipulation.broadcast_to(src, masked_shape)
 * 
 *     if op == 'update':             # <<<<<<<<<<<<<<
 *         _scatter_update_mask_kernel(src, mask, mask_scanned, a)
 *     elif op == 'add':
 */
  __pyx_t_9 = (__Pyx_PyUnicode_Equals(__pyx_v_op, __pyx_n_u_update, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 759, __pyx_L1_error)
  if (__pyx_t_9) {

    /* "cupy/core/_routines_indexing.pyx":760
 * 
 *     if op == 'update':
 *         _scatter_update_mask_kernel(src, mask, mask_scanned, a)             # <<<<<<<<<<<<<<
 *     elif op == 'add':
 *         _scatter_add_mask_kernel(src, mask, mask_scanned, a)
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_scatter_update_mask_kernel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 760, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = NULL;
    __pyx_t_11 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_11 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[5] = {__pyx_t_1, ((PyObject *)__pyx_v_src), ((PyObject *)__pyx_v_mask), ((PyObject *)__pyx_v_mask_scanned), ((PyObject *)__pyx_v_a)};
      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 4+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 760, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[5] = {__pyx_t_1, ((PyObject *)__pyx_v_src), ((PyObject *)__pyx_v_mask), ((PyObject *)__pyx_v_mask_scanned), ((PyObject *)__pyx_v_a)};
      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 4+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 760, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(4+__pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 760, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (__pyx_t_1) {
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __pyx_t_1 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_src));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_src));
      PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_11, ((PyObject *)__pyx_v_src));
      __Pyx_INCREF(((PyObject *)__pyx_v_mask));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_mask));
      PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_11, ((PyObject *)__pyx_v_mask));
      __Pyx_INCREF(((PyObject *)__pyx_v_mask_scanned));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_mask_scanned));
      PyTuple_SET_ITEM(__pyx_t_4, 2+__pyx_t_11, ((PyObject *)__pyx_v_mask_scanned));
      __Pyx_INCREF(((PyObject *)__pyx_v_a));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_a));
      PyTuple_SET_ITEM(__pyx_t_4, 3+__pyx_t_11, ((PyObject *)__pyx_v_a));
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 760, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":759
 *     src = _manipulation.broadcast_to(src, masked_shape)
 * 
 *     if op == 'update':             # <<<<<<<<<<<<<<
 *         _scatter_update_mask_kernel(src, mask, mask_scanned, a)
 *     elif op == 'add':
 */
    goto __pyx_L7;
  }

  /* "cupy/core/_routines_indexing.pyx":761
 *     if op == 'update':
 *         _scatter_update_mask_kernel(src, mask, mask_scanned, a)
 *     elif op == 'add':             # <<<<<<<<<<<<<<
 *         _scatter_add_mask_kernel(src, mask, mask_scanned, a)
 *     elif op == 'max':
 */
  __pyx_t_9 = (__Pyx_PyUnicode_Equals(__pyx_v_op, __pyx_n_u_add, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 761, __pyx_L1_error)
  if (__pyx_t_9) {

    /* "cupy/core/_routines_indexing.pyx":762
 *         _scatter_update_mask_kernel(src, mask, mask_scanned, a)
 *     elif op == 'add':
 *         _scatter_add_mask_kernel(src, mask, mask_scanned, a)             # <<<<<<<<<<<<<<
 *     elif op == 'max':
 *         _scatter_max_mask_kernel(src, mask, mask_scanned, a)
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_scatter_add_mask_kernel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 762, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    __pyx_t_11 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_11 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[5] = {__pyx_t_4, ((PyObject *)__pyx_v_src), ((PyObject *)__pyx_v_mask), ((PyObject *)__pyx_v_mask_scanned), ((PyObject *)__pyx_v_a)};
      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 4+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 762, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[5] = {__pyx_t_4, ((PyObject *)__pyx_v_src), ((PyObject *)__pyx_v_mask), ((PyObject *)__pyx_v_mask_scanned), ((PyObject *)__pyx_v_a)};
      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 4+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 762, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else
    #endif
    {
      __pyx_t_1 = PyTuple_New(4+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 762, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (__pyx_t_4) {
        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); __pyx_t_4 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_src));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_src));
      PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_11, ((PyObject *)__pyx_v_src));
      __Pyx_INCREF(((PyObject *)__pyx_v_mask));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_mask));
      PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_11, ((PyObject *)__pyx_v_mask));
      __Pyx_INCREF(((PyObject *)__pyx_v_mask_scanned));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_mask_scanned));
      PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_11, ((PyObject *)__pyx_v_mask_scanned));
      __Pyx_INCREF(((PyObject *)__pyx_v_a));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_a));
      PyTuple_SET_ITEM(__pyx_t_1, 3+__pyx_t_11, ((PyObject *)__pyx_v_a));
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 762, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":761
 *     if op == 'update':
 *         _scatter_update_mask_kernel(src, mask, mask_scanned, a)
 *     elif op == 'add':             # <<<<<<<<<<<<<<
 *         _scatter_add_mask_kernel(src, mask, mask_scanned, a)
 *     elif op == 'max':
 */
    goto __pyx_L7;
  }

  /* "cupy/core/_routines_indexing.pyx":763
 *     elif op == 'add':
 *         _scatter_add_mask_kernel(src, mask, mask_scanned, a)
 *     elif op == 'max':             # <<<<<<<<<<<<<<
 *         _scatter_max_mask_kernel(src, mask, mask_scanned, a)
 *     elif op == 'min':
 */
  __pyx_t_9 = (__Pyx_PyUnicode_Equals(__pyx_v_op, __pyx_n_u_max, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 763, __pyx_L1_error)
  if (__pyx_t_9) {

    /* "cupy/core/_routines_indexing.pyx":764
 *         _scatter_add_mask_kernel(src, mask, mask_scanned, a)
 *     elif op == 'max':
 *         _scatter_max_mask_kernel(src, mask, mask_scanned, a)             # <<<<<<<<<<<<<<
 *     elif op == 'min':
 *         _scatter_min_mask_kernel(src, mask, mask_scanned, a)
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_scatter_max_mask_kernel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 764, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = NULL;
    __pyx_t_11 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_11 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[5] = {__pyx_t_1, ((PyObject *)__pyx_v_src), ((PyObject *)__pyx_v_mask), ((PyObject *)__pyx_v_mask_scanned), ((PyObject *)__pyx_v_a)};
      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 4+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 764, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[5] = {__pyx_t_1, ((PyObject *)__pyx_v_src), ((PyObject *)__pyx_v_mask), ((PyObject *)__pyx_v_mask_scanned), ((PyObject *)__pyx_v_a)};
      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 4+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 764, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(4+__pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 764, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (__pyx_t_1) {
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __pyx_t_1 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_src));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_src));
      PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_11, ((PyObject *)__pyx_v_src));
      __Pyx_INCREF(((PyObject *)__pyx_v_mask));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_mask));
      PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_11, ((PyObject *)__pyx_v_mask));
      __Pyx_INCREF(((PyObject *)__pyx_v_mask_scanned));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_mask_scanned));
      PyTuple_SET_ITEM(__pyx_t_4, 2+__pyx_t_11, ((PyObject *)__pyx_v_mask_scanned));
      __Pyx_INCREF(((PyObject *)__pyx_v_a));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_a));
      PyTuple_SET_ITEM(__pyx_t_4, 3+__pyx_t_11, ((PyObject *)__pyx_v_a));
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 764, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":763
 *     elif op == 'add':
 *         _scatter_add_mask_kernel(src, mask, mask_scanned, a)
 *     elif op == 'max':             # <<<<<<<<<<<<<<
 *         _scatter_max_mask_kernel(src, mask, mask_scanned, a)
 *     elif op == 'min':
 */
    goto __pyx_L7;
  }

  /* "cupy/core/_routines_indexing.pyx":765
 *     elif op == 'max':
 *         _scatter_max_mask_kernel(src, mask, mask_scanned, a)
 *     elif op == 'min':             # <<<<<<<<<<<<<<
 *         _scatter_min_mask_kernel(src, mask, mask_scanned, a)
 *     else:
 */
  __pyx_t_9 = (__Pyx_PyUnicode_Equals(__pyx_v_op, __pyx_n_u_min, Py_EQ)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 765, __pyx_L1_error)
  if (likely(__pyx_t_9)) {

    /* "cupy/core/_routines_indexing.pyx":766
 *         _scatter_max_mask_kernel(src, mask, mask_scanned, a)
 *     elif op == 'min':
 *         _scatter_min_mask_kernel(src, mask, mask_scanned, a)             # <<<<<<<<<<<<<<
 *     else:
 *         raise ValueError('provided op is not supported')
 */
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_scatter_min_mask_kernel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 766, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    __pyx_t_11 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_11 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[5] = {__pyx_t_4, ((PyObject *)__pyx_v_src), ((PyObject *)__pyx_v_mask), ((PyObject *)__pyx_v_mask_scanned), ((PyObject *)__pyx_v_a)};
      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 4+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 766, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[5] = {__pyx_t_4, ((PyObject *)__pyx_v_src), ((PyObject *)__pyx_v_mask), ((PyObject *)__pyx_v_mask_scanned), ((PyObject *)__pyx_v_a)};
      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_11, 4+__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 766, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else
    #endif
    {
      __pyx_t_1 = PyTuple_New(4+__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 766, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (__pyx_t_4) {
        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4); __pyx_t_4 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_src));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_src));
      PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_11, ((PyObject *)__pyx_v_src));
      __Pyx_INCREF(((PyObject *)__pyx_v_mask));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_mask));
      PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_11, ((PyObject *)__pyx_v_mask));
      __Pyx_INCREF(((PyObject *)__pyx_v_mask_scanned));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_mask_scanned));
      PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_11, ((PyObject *)__pyx_v_mask_scanned));
      __Pyx_INCREF(((PyObject *)__pyx_v_a));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_a));
      PyTuple_SET_ITEM(__pyx_t_1, 3+__pyx_t_11, ((PyObject *)__pyx_v_a));
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 766, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":765
 *     elif op == 'max':
 *         _scatter_max_mask_kernel(src, mask, mask_scanned, a)
 *     elif op == 'min':             # <<<<<<<<<<<<<<
 *         _scatter_min_mask_kernel(src, mask, mask_scanned, a)
 *     else:
 */
    goto __pyx_L7;
  }

  /* "cupy/core/_routines_indexing.pyx":768
 *         _scatter_min_mask_kernel(src, mask, mask_scanned, a)
 *     else:
 *         raise ValueError('provided op is not supported')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__25, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 768, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_Raise(__pyx_t_2, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __PYX_ERR(0, 768, __pyx_L1_error)
  }
  __pyx_L7:;

  /* "cupy/core/_routines_indexing.pyx":741
 * 
 * 
 * cdef _scatter_op_mask_single(ndarray a, ndarray mask, v, Py_ssize_t axis, op):             # <<<<<<<<<<<<<<
 *     cdef ndarray mask_scanned, src
 *     cdef tuple masked_shape
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("cupy.core._routines_indexing._scatter_op_mask_single", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_mask_scanned);
  __Pyx_XDECREF((PyObject *)__pyx_v_src);
  __Pyx_XDECREF(__pyx_v_masked_shape);
  __Pyx_XDECREF((PyObject *)__pyx_v_mask);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":771
 * 
 * 
 * cdef _scatter_op(ndarray a, slices, value, op):             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t i, li, ri
 *     cdef ndarray v, x, y, a_interm, reduced_idx
 */

static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__scatter_op(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_a, PyObject *__pyx_v_slices, PyObject *__pyx_v_value, PyObject *__pyx_v_op) {
  Py_ssize_t __pyx_v_li;
  Py_ssize_t __pyx_v_ri;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_x = 0;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_y = 0;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_a_interm = 0;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_reduced_idx = 0;
  PyObject *__pyx_v_slice_list = 0;
  PyObject *__pyx_v_adv_mask = 0;
  PyObject *__pyx_v_adv_slices = 0;
  int __pyx_v_advanced;
  int __pyx_v_mask_exists;
  Py_ssize_t __pyx_v_mask_i;
  PyObject *__pyx_v_axis = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  int __pyx_t_5;
  int __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  Py_ssize_t __pyx_t_8;
  struct __pyx_opt_args_4cupy_4core_18_routines_indexing__scatter_op_single __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  size_t __pyx_t_11;
  int __pyx_t_12;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_scatter_op", 0);
  __Pyx_INCREF((PyObject *)__pyx_v_a);

  /* "cupy/core/_routines_indexing.pyx":777
 *     cdef bint advanced, mask_exists
 * 
 *     slice_list, advanced, mask_exists = _prepare_slice_list(             # <<<<<<<<<<<<<<
 *         slices, a._shape.size())
 * 
 */
  __pyx_t_1 = __pyx_f_4cupy_4core_18_routines_indexing__prepare_slice_list(__pyx_v_slices, __pyx_v_a->_shape.size(), 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 777, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (likely(__pyx_t_1 != Py_None)) {
    PyObject* sequence = __pyx_t_1;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 3)) {
      if (size > 3) __Pyx_RaiseTooManyValuesError(3);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 777, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
    __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
    __pyx_t_4 = PyTuple_GET_ITEM(sequence, 2); 
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_4);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 777, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 777, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 777, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    #endif
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(0, 777, __pyx_L1_error)
  }
  if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 777, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 777, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 777, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_slice_list = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_v_advanced = __pyx_t_5;
  __pyx_v_mask_exists = __pyx_t_6;

  /* "cupy/core/_routines_indexing.pyx":780
 *         slices, a._shape.size())
 * 
 *     if mask_exists:             # <<<<<<<<<<<<<<
 *         mask_i = _get_mask_index(slice_list)
 *         _scatter_op_mask_single(a, slice_list[mask_i], value, mask_i, op)
 */
  __pyx_t_6 = (__pyx_v_mask_exists != 0);
  if (__pyx_t_6) {

    /* "cupy/core/_routines_indexing.pyx":781
 * 
 *     if mask_exists:
 *         mask_i = _get_mask_index(slice_list)             # <<<<<<<<<<<<<<
 *         _scatter_op_mask_single(a, slice_list[mask_i], value, mask_i, op)
 *         return
 */
    __pyx_t_7 = __pyx_f_4cupy_4core_18_routines_indexing__get_mask_index(__pyx_v_slice_list); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 781, __pyx_L1_error)
    __pyx_v_mask_i = __pyx_t_7;

    /* "cupy/core/_routines_indexing.pyx":782
 *     if mask_exists:
 *         mask_i = _get_mask_index(slice_list)
 *         _scatter_op_mask_single(a, slice_list[mask_i], value, mask_i, op)             # <<<<<<<<<<<<<<
 *         return
 * 
 */
    if (unlikely(__pyx_v_slice_list == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 782, __pyx_L1_error)
    }
    __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_slice_list, __pyx_v_mask_i, Py_ssize_t, 1, PyInt_FromSsize_t, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 782, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 782, __pyx_L1_error)
    __pyx_t_4 = __pyx_f_4cupy_4core_18_routines_indexing__scatter_op_mask_single(__pyx_v_a, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_1), __pyx_v_value, __pyx_v_mask_i, __pyx_v_op); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 782, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "cupy/core/_routines_indexing.pyx":783
 *         mask_i = _get_mask_index(slice_list)
 *         _scatter_op_mask_single(a, slice_list[mask_i], value, mask_i, op)
 *         return             # <<<<<<<<<<<<<<
 * 
 *     if advanced:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "cupy/core/_routines_indexing.pyx":780
 *         slices, a._shape.size())
 * 
 *     if mask_exists:             # <<<<<<<<<<<<<<
 *         mask_i = _get_mask_index(slice_list)
 *         _scatter_op_mask_single(a, slice_list[mask_i], value, mask_i, op)
 */
  }

  /* "cupy/core/_routines_indexing.pyx":785
 *         return
 * 
 *     if advanced:             # <<<<<<<<<<<<<<
 *         a, adv_slices, adv_mask = _prepare_advanced_indexing(a, slice_list)
 *         if sum(adv_mask) == 1:
 */
  __pyx_t_6 = (__pyx_v_advanced != 0);
  if (__pyx_t_6) {

    /* "cupy/core/_routines_indexing.pyx":786
 * 
 *     if advanced:
 *         a, adv_slices, adv_mask = _prepare_advanced_indexing(a, slice_list)             # <<<<<<<<<<<<<<
 *         if sum(adv_mask) == 1:
 *             axis = adv_mask.index(True)
 */
    __pyx_t_4 = __pyx_f_4cupy_4core_18_routines_indexing__prepare_advanced_indexing(__pyx_v_a, __pyx_v_slice_list); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 786, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (likely(__pyx_t_4 != Py_None)) {
      PyObject* sequence = __pyx_t_4;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 3)) {
        if (size > 3) __Pyx_RaiseTooManyValuesError(3);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 786, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 2); 
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      #else
      __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 786, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 786, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_2 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 786, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      #endif
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else {
      __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(0, 786, __pyx_L1_error)
    }
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 786, __pyx_L1_error)
    if (!(likely(PyList_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 786, __pyx_L1_error)
    if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 786, __pyx_L1_error)
    __Pyx_DECREF_SET(__pyx_v_a, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_1));
    __pyx_t_1 = 0;
    __pyx_v_adv_slices = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_v_adv_mask = ((PyObject*)__pyx_t_2);
    __pyx_t_2 = 0;

    /* "cupy/core/_routines_indexing.pyx":787
 *     if advanced:
 *         a, adv_slices, adv_mask = _prepare_advanced_indexing(a, slice_list)
 *         if sum(adv_mask) == 1:             # <<<<<<<<<<<<<<
 *             axis = adv_mask.index(True)
 *             _scatter_op_single(a, adv_slices[axis], value, axis, axis, op)
 */
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_sum, __pyx_v_adv_mask); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 787, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyInt_EqObjC(__pyx_t_4, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 787, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 787, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_6) {

      /* "cupy/core/_routines_indexing.pyx":788
 *         a, adv_slices, adv_mask = _prepare_advanced_indexing(a, slice_list)
 *         if sum(adv_mask) == 1:
 *             axis = adv_mask.index(True)             # <<<<<<<<<<<<<<
 *             _scatter_op_single(a, adv_slices[axis], value, axis, axis, op)
 *             return
 */
      __pyx_t_2 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyList_Type_index, __pyx_v_adv_mask, Py_True); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 788, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_v_axis = __pyx_t_2;
      __pyx_t_2 = 0;

      /* "cupy/core/_routines_indexing.pyx":789
 *         if sum(adv_mask) == 1:
 *             axis = adv_mask.index(True)
 *             _scatter_op_single(a, adv_slices[axis], value, axis, axis, op)             # <<<<<<<<<<<<<<
 *             return
 * 
 */
      if (unlikely(__pyx_v_adv_slices == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 789, __pyx_L1_error)
      }
      __pyx_t_2 = __Pyx_PyObject_GetItem(__pyx_v_adv_slices, __pyx_v_axis); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 789, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 789, __pyx_L1_error)
      __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_v_axis); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 789, __pyx_L1_error)
      __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_v_axis); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 789, __pyx_L1_error)
      __pyx_t_9.__pyx_n = 3;
      __pyx_t_9.li = __pyx_t_7;
      __pyx_t_9.ri = __pyx_t_8;
      __pyx_t_9.op = __pyx_v_op;
      __pyx_t_4 = __pyx_f_4cupy_4core_18_routines_indexing__scatter_op_single(__pyx_v_a, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2), __pyx_v_value, &__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 789, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "cupy/core/_routines_indexing.pyx":790
 *             axis = adv_mask.index(True)
 *             _scatter_op_single(a, adv_slices[axis], value, axis, axis, op)
 *             return             # <<<<<<<<<<<<<<
 * 
 *         # scatter_op with multiple integer arrays
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_r = Py_None; __Pyx_INCREF(Py_None);
      goto __pyx_L0;

      /* "cupy/core/_routines_indexing.pyx":787
 *     if advanced:
 *         a, adv_slices, adv_mask = _prepare_advanced_indexing(a, slice_list)
 *         if sum(adv_mask) == 1:             # <<<<<<<<<<<<<<
 *             axis = adv_mask.index(True)
 *             _scatter_op_single(a, adv_slices[axis], value, axis, axis, op)
 */
    }

    /* "cupy/core/_routines_indexing.pyx":794
 *         # scatter_op with multiple integer arrays
 *         a_interm, reduced_idx, li, ri =\
 *             _prepare_multiple_array_indexing(a, adv_slices)             # <<<<<<<<<<<<<<
 *         _scatter_op_single(a_interm, reduced_idx, value, li, ri, op)
 *         return
 */
    __pyx_t_4 = __pyx_f_4cupy_4core_18_routines_indexing__prepare_multiple_array_indexing(__pyx_v_a, __pyx_v_adv_slices); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 794, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (likely(__pyx_t_4 != Py_None)) {
      PyObject* sequence = __pyx_t_4;
      Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
      if (unlikely(size != 4)) {
        if (size > 4) __Pyx_RaiseTooManyValuesError(4);
        else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
        __PYX_ERR(0, 793, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 2); 
      __pyx_t_10 = PyTuple_GET_ITEM(sequence, 3); 
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_10);
      #else
      {
        Py_ssize_t i;
        PyObject** temps[4] = {&__pyx_t_2,&__pyx_t_3,&__pyx_t_1,&__pyx_t_10};
        for (i=0; i < 4; i++) {
          PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 793, __pyx_L1_error)
          __Pyx_GOTREF(item);
          *(temps[i]) = item;
        }
      }
      #endif
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else {
      __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(0, 793, __pyx_L1_error)
    }

    /* "cupy/core/_routines_indexing.pyx":793
 * 
 *         # scatter_op with multiple integer arrays
 *         a_interm, reduced_idx, li, ri =\             # <<<<<<<<<<<<<<
 *             _prepare_multiple_array_indexing(a, adv_slices)
 *         _scatter_op_single(a_interm, reduced_idx, value, li, ri, op)
 */
    if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 793, __pyx_L1_error)
    if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 793, __pyx_L1_error)
    __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 793, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_t_10); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 793, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_v_a_interm = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_v_reduced_idx = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_v_li = __pyx_t_8;
    __pyx_v_ri = __pyx_t_7;

    /* "cupy/core/_routines_indexing.pyx":795
 *         a_interm, reduced_idx, li, ri =\
 *             _prepare_multiple_array_indexing(a, adv_slices)
 *         _scatter_op_single(a_interm, reduced_idx, value, li, ri, op)             # <<<<<<<<<<<<<<
 *         return
 * 
 */
    __pyx_t_9.__pyx_n = 3;
    __pyx_t_9.li = __pyx_v_li;
    __pyx_t_9.ri = __pyx_v_ri;
    __pyx_t_9.op = __pyx_v_op;
    __pyx_t_4 = __pyx_f_4cupy_4core_18_routines_indexing__scatter_op_single(__pyx_v_a_interm, __pyx_v_reduced_idx, __pyx_v_value, &__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 795, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "cupy/core/_routines_indexing.pyx":796
 *             _prepare_multiple_array_indexing(a, adv_slices)
 *         _scatter_op_single(a_interm, reduced_idx, value, li, ri, op)
 *         return             # <<<<<<<<<<<<<<
 * 
 *     y = _simple_getitem(a, slice_list)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "cupy/core/_routines_indexing.pyx":785
 *         return
 * 
 *     if advanced:             # <<<<<<<<<<<<<<
 *         a, adv_slices, adv_mask = _prepare_advanced_indexing(a, slice_list)
 *         if sum(adv_mask) == 1:
 */
  }

  /* "cupy/core/_routines_indexing.pyx":798
 *         return
 * 
 *     y = _simple_getitem(a, slice_list)             # <<<<<<<<<<<<<<
 *     if op == 'update':
 *         if not isinstance(value, ndarray):
 */
  __pyx_t_4 = ((PyObject *)__pyx_f_4cupy_4core_18_routines_indexing__simple_getitem(__pyx_v_a, __pyx_v_slice_list)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 798, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_v_y = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "cupy/core/_routines_indexing.pyx":799
 * 
 *     y = _simple_getitem(a, slice_list)
 *     if op == 'update':             # <<<<<<<<<<<<<<
 *         if not isinstance(value, ndarray):
 *             y.fill(value)
 */
  __pyx_t_6 = (__Pyx_PyUnicode_Equals(__pyx_v_op, __pyx_n_u_update, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 799, __pyx_L1_error)
  if (__pyx_t_6) {

    /* "cupy/core/_routines_indexing.pyx":800
 *     y = _simple_getitem(a, slice_list)
 *     if op == 'update':
 *         if not isinstance(value, ndarray):             # <<<<<<<<<<<<<<
 *             y.fill(value)
 *             return
 */
    __pyx_t_6 = __Pyx_TypeCheck(__pyx_v_value, __pyx_ptype_4cupy_4core_4core_ndarray); 
    __pyx_t_5 = ((!(__pyx_t_6 != 0)) != 0);
    if (__pyx_t_5) {

      /* "cupy/core/_routines_indexing.pyx":801
 *     if op == 'update':
 *         if not isinstance(value, ndarray):
 *             y.fill(value)             # <<<<<<<<<<<<<<
 *             return
 *         x = value
 */
      __pyx_t_4 = ((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)__pyx_v_y->__pyx_vtab)->fill(__pyx_v_y, __pyx_v_value, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 801, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "cupy/core/_routines_indexing.pyx":802
 *         if not isinstance(value, ndarray):
 *             y.fill(value)
 *             return             # <<<<<<<<<<<<<<
 *         x = value
 *         if (internal.vector_equal(y._shape, x._shape) and
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_r = Py_None; __Pyx_INCREF(Py_None);
      goto __pyx_L0;

      /* "cupy/core/_routines_indexing.pyx":800
 *     y = _simple_getitem(a, slice_list)
 *     if op == 'update':
 *         if not isinstance(value, ndarray):             # <<<<<<<<<<<<<<
 *             y.fill(value)
 *             return
 */
    }

    /* "cupy/core/_routines_indexing.pyx":803
 *             y.fill(value)
 *             return
 *         x = value             # <<<<<<<<<<<<<<
 *         if (internal.vector_equal(y._shape, x._shape) and
 *                 internal.vector_equal(y._strides, x._strides)):
 */
    if (!(likely(((__pyx_v_value) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_value, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 803, __pyx_L1_error)
    __pyx_t_4 = __pyx_v_value;
    __Pyx_INCREF(__pyx_t_4);
    __pyx_v_x = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_4);
    __pyx_t_4 = 0;

    /* "cupy/core/_routines_indexing.pyx":804
 *             return
 *         x = value
 *         if (internal.vector_equal(y._shape, x._shape) and             # <<<<<<<<<<<<<<
 *                 internal.vector_equal(y._strides, x._strides)):
 *             if y.data.ptr == x.data.ptr:
 */
    __pyx_t_6 = (__pyx_f_4cupy_4core_8internal_vector_equal(__pyx_v_y->_shape, __pyx_v_x->_shape, 0) != 0);
    if (__pyx_t_6) {
    } else {
      __pyx_t_5 = __pyx_t_6;
      goto __pyx_L9_bool_binop_done;
    }

    /* "cupy/core/_routines_indexing.pyx":805
 *         x = value
 *         if (internal.vector_equal(y._shape, x._shape) and
 *                 internal.vector_equal(y._strides, x._strides)):             # <<<<<<<<<<<<<<
 *             if y.data.ptr == x.data.ptr:
 *                 return  # Skip since x and y are the same array
 */
    __pyx_t_6 = (__pyx_f_4cupy_4core_8internal_vector_equal(__pyx_v_y->_strides, __pyx_v_x->_strides, 0) != 0);
    __pyx_t_5 = __pyx_t_6;
    __pyx_L9_bool_binop_done:;

    /* "cupy/core/_routines_indexing.pyx":804
 *             return
 *         x = value
 *         if (internal.vector_equal(y._shape, x._shape) and             # <<<<<<<<<<<<<<
 *                 internal.vector_equal(y._strides, x._strides)):
 *             if y.data.ptr == x.data.ptr:
 */
    if (__pyx_t_5) {

      /* "cupy/core/_routines_indexing.pyx":806
 *         if (internal.vector_equal(y._shape, x._shape) and
 *                 internal.vector_equal(y._strides, x._strides)):
 *             if y.data.ptr == x.data.ptr:             # <<<<<<<<<<<<<<
 *                 return  # Skip since x and y are the same array
 *             elif y._c_contiguous and x.dtype == y.dtype:
 */
      __pyx_t_5 = ((__pyx_v_y->data->ptr == __pyx_v_x->data->ptr) != 0);
      if (__pyx_t_5) {

        /* "cupy/core/_routines_indexing.pyx":807
 *                 internal.vector_equal(y._strides, x._strides)):
 *             if y.data.ptr == x.data.ptr:
 *                 return  # Skip since x and y are the same array             # <<<<<<<<<<<<<<
 *             elif y._c_contiguous and x.dtype == y.dtype:
 *                 y.data.copy_from_device_async(x.data, x.nbytes)
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_r = Py_None; __Pyx_INCREF(Py_None);
        goto __pyx_L0;

        /* "cupy/core/_routines_indexing.pyx":806
 *         if (internal.vector_equal(y._shape, x._shape) and
 *                 internal.vector_equal(y._strides, x._strides)):
 *             if y.data.ptr == x.data.ptr:             # <<<<<<<<<<<<<<
 *                 return  # Skip since x and y are the same array
 *             elif y._c_contiguous and x.dtype == y.dtype:
 */
      }

      /* "cupy/core/_routines_indexing.pyx":808
 *             if y.data.ptr == x.data.ptr:
 *                 return  # Skip since x and y are the same array
 *             elif y._c_contiguous and x.dtype == y.dtype:             # <<<<<<<<<<<<<<
 *                 y.data.copy_from_device_async(x.data, x.nbytes)
 *                 return
 */
      __pyx_t_6 = (__pyx_v_y->_c_contiguous != 0);
      if (__pyx_t_6) {
      } else {
        __pyx_t_5 = __pyx_t_6;
        goto __pyx_L12_bool_binop_done;
      }
      __pyx_t_4 = PyObject_RichCompare(__pyx_v_x->dtype, __pyx_v_y->dtype, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 808, __pyx_L1_error)
      __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 808, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_5 = __pyx_t_6;
      __pyx_L12_bool_binop_done:;
      if (__pyx_t_5) {

        /* "cupy/core/_routines_indexing.pyx":809
 *                 return  # Skip since x and y are the same array
 *             elif y._c_contiguous and x.dtype == y.dtype:
 *                 y.data.copy_from_device_async(x.data, x.nbytes)             # <<<<<<<<<<<<<<
 *                 return
 *         elementwise_copy(x, y)
 */
        __pyx_t_4 = ((PyObject *)__pyx_v_x->data);
        __Pyx_INCREF(__pyx_t_4);
        __pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_x), __pyx_n_s_nbytes); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 809, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_11 = __Pyx_PyInt_As_size_t(__pyx_t_10); if (unlikely((__pyx_t_11 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 809, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_10 = ((struct __pyx_vtabstruct_4cupy_4cuda_6memory_MemoryPointer *)__pyx_v_y->data->__pyx_vtab)->copy_from_device_async(__pyx_v_y->data, ((struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer *)__pyx_t_4), __pyx_t_11, 0, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 809, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

        /* "cupy/core/_routines_indexing.pyx":810
 *             elif y._c_contiguous and x.dtype == y.dtype:
 *                 y.data.copy_from_device_async(x.data, x.nbytes)
 *                 return             # <<<<<<<<<<<<<<
 *         elementwise_copy(x, y)
 *         return
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_r = Py_None; __Pyx_INCREF(Py_None);
        goto __pyx_L0;

        /* "cupy/core/_routines_indexing.pyx":808
 *             if y.data.ptr == x.data.ptr:
 *                 return  # Skip since x and y are the same array
 *             elif y._c_contiguous and x.dtype == y.dtype:             # <<<<<<<<<<<<<<
 *                 y.data.copy_from_device_async(x.data, x.nbytes)
 *                 return
 */
      }

      /* "cupy/core/_routines_indexing.pyx":804
 *             return
 *         x = value
 *         if (internal.vector_equal(y._shape, x._shape) and             # <<<<<<<<<<<<<<
 *                 internal.vector_equal(y._strides, x._strides)):
 *             if y.data.ptr == x.data.ptr:
 */
    }

    /* "cupy/core/_routines_indexing.pyx":811
 *                 y.data.copy_from_device_async(x.data, x.nbytes)
 *                 return
 *         elementwise_copy(x, y)             # <<<<<<<<<<<<<<
 *         return
 *     if op == 'add':
 */
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_elementwise_copy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 811, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = NULL;
    __pyx_t_12 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
        __pyx_t_12 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[3] = {__pyx_t_1, ((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)};
      __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 811, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_10);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[3] = {__pyx_t_1, ((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)};
      __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 811, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_10);
    } else
    #endif
    {
      __pyx_t_3 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 811, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__pyx_t_1) {
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1); __pyx_t_1 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_x));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_x));
      PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_12, ((PyObject *)__pyx_v_x));
      __Pyx_INCREF(((PyObject *)__pyx_v_y));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_y));
      PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_12, ((PyObject *)__pyx_v_y));
      __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 811, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

    /* "cupy/core/_routines_indexing.pyx":812
 *                 return
 *         elementwise_copy(x, y)
 *         return             # <<<<<<<<<<<<<<
 *     if op == 'add':
 *         _math._add(y, value, y)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "cupy/core/_routines_indexing.pyx":799
 * 
 *     y = _simple_getitem(a, slice_list)
 *     if op == 'update':             # <<<<<<<<<<<<<<
 *         if not isinstance(value, ndarray):
 *             y.fill(value)
 */
  }

  /* "cupy/core/_routines_indexing.pyx":813
 *         elementwise_copy(x, y)
 *         return
 *     if op == 'add':             # <<<<<<<<<<<<<<
 *         _math._add(y, value, y)
 *         return
 */
  __pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_v_op, __pyx_n_u_add, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 813, __pyx_L1_error)
  if (__pyx_t_5) {

    /* "cupy/core/_routines_indexing.pyx":814
 *         return
 *     if op == 'add':
 *         _math._add(y, value, y)             # <<<<<<<<<<<<<<
 *         return
 *     if op == 'max':
 */
    __Pyx_INCREF(__pyx_v_4cupy_4core_14_routines_math__add);
    __pyx_t_4 = __pyx_v_4cupy_4core_14_routines_math__add; __pyx_t_3 = NULL;
    __pyx_t_12 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
        __pyx_t_12 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[4] = {__pyx_t_3, ((PyObject *)__pyx_v_y), __pyx_v_value, ((PyObject *)__pyx_v_y)};
      __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_12, 3+__pyx_t_12); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 814, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_10);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[4] = {__pyx_t_3, ((PyObject *)__pyx_v_y), __pyx_v_value, ((PyObject *)__pyx_v_y)};
      __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_12, 3+__pyx_t_12); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 814, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_10);
    } else
    #endif
    {
      __pyx_t_1 = PyTuple_New(3+__pyx_t_12); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 814, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      if (__pyx_t_3) {
        __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); __pyx_t_3 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_y));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_y));
      PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_12, ((PyObject *)__pyx_v_y));
      __Pyx_INCREF(__pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_12, __pyx_v_value);
      __Pyx_INCREF(((PyObject *)__pyx_v_y));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_y));
      PyTuple_SET_ITEM(__pyx_t_1, 2+__pyx_t_12, ((PyObject *)__pyx_v_y));
      __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 814, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

    /* "cupy/core/_routines_indexing.pyx":815
 *     if op == 'add':
 *         _math._add(y, value, y)
 *         return             # <<<<<<<<<<<<<<
 *     if op == 'max':
 *         cupy.maximum(y, value, y)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "cupy/core/_routines_indexing.pyx":813
 *         elementwise_copy(x, y)
 *         return
 *     if op == 'add':             # <<<<<<<<<<<<<<
 *         _math._add(y, value, y)
 *         return
 */
  }

  /* "cupy/core/_routines_indexing.pyx":816
 *         _math._add(y, value, y)
 *         return
 *     if op == 'max':             # <<<<<<<<<<<<<<
 *         cupy.maximum(y, value, y)
 *         return
 */
  __pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_v_op, __pyx_n_u_max, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 816, __pyx_L1_error)
  if (__pyx_t_5) {

    /* "cupy/core/_routines_indexing.pyx":817
 *         return
 *     if op == 'max':
 *         cupy.maximum(y, value, y)             # <<<<<<<<<<<<<<
 *         return
 *     if op == 'min':
 */
    __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_cupy); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 817, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_maximum); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 817, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = NULL;
    __pyx_t_12 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
        __pyx_t_12 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[4] = {__pyx_t_4, ((PyObject *)__pyx_v_y), __pyx_v_value, ((PyObject *)__pyx_v_y)};
      __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_12, 3+__pyx_t_12); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 817, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_10);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[4] = {__pyx_t_4, ((PyObject *)__pyx_v_y), __pyx_v_value, ((PyObject *)__pyx_v_y)};
      __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_12, 3+__pyx_t_12); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 817, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_10);
    } else
    #endif
    {
      __pyx_t_3 = PyTuple_New(3+__pyx_t_12); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 817, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (__pyx_t_4) {
        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_y));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_y));
      PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_12, ((PyObject *)__pyx_v_y));
      __Pyx_INCREF(__pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_12, __pyx_v_value);
      __Pyx_INCREF(((PyObject *)__pyx_v_y));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_y));
      PyTuple_SET_ITEM(__pyx_t_3, 2+__pyx_t_12, ((PyObject *)__pyx_v_y));
      __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 817, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

    /* "cupy/core/_routines_indexing.pyx":818
 *     if op == 'max':
 *         cupy.maximum(y, value, y)
 *         return             # <<<<<<<<<<<<<<
 *     if op == 'min':
 *         cupy.minimum(y, value, y)
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "cupy/core/_routines_indexing.pyx":816
 *         _math._add(y, value, y)
 *         return
 *     if op == 'max':             # <<<<<<<<<<<<<<
 *         cupy.maximum(y, value, y)
 *         return
 */
  }

  /* "cupy/core/_routines_indexing.pyx":819
 *         cupy.maximum(y, value, y)
 *         return
 *     if op == 'min':             # <<<<<<<<<<<<<<
 *         cupy.minimum(y, value, y)
 *         return
 */
  __pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_v_op, __pyx_n_u_min, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 819, __pyx_L1_error)
  if (__pyx_t_5) {

    /* "cupy/core/_routines_indexing.pyx":820
 *         return
 *     if op == 'min':
 *         cupy.minimum(y, value, y)             # <<<<<<<<<<<<<<
 *         return
 *     raise ValueError('this op is not supported')
 */
    __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_cupy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 820, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_minimum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 820, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = NULL;
    __pyx_t_12 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_12 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[4] = {__pyx_t_1, ((PyObject *)__pyx_v_y), __pyx_v_value, ((PyObject *)__pyx_v_y)};
      __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_12, 3+__pyx_t_12); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 820, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_10);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[4] = {__pyx_t_1, ((PyObject *)__pyx_v_y), __pyx_v_value, ((PyObject *)__pyx_v_y)};
      __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_12, 3+__pyx_t_12); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 820, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_10);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(3+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 820, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (__pyx_t_1) {
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); __pyx_t_1 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_y));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_y));
      PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_12, ((PyObject *)__pyx_v_y));
      __Pyx_INCREF(__pyx_v_value);
      __Pyx_GIVEREF(__pyx_v_value);
      PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_12, __pyx_v_value);
      __Pyx_INCREF(((PyObject *)__pyx_v_y));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_y));
      PyTuple_SET_ITEM(__pyx_t_4, 2+__pyx_t_12, ((PyObject *)__pyx_v_y));
      __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 820, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

    /* "cupy/core/_routines_indexing.pyx":821
 *     if op == 'min':
 *         cupy.minimum(y, value, y)
 *         return             # <<<<<<<<<<<<<<
 *     raise ValueError('this op is not supported')
 * 
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_r = Py_None; __Pyx_INCREF(Py_None);
    goto __pyx_L0;

    /* "cupy/core/_routines_indexing.pyx":819
 *         cupy.maximum(y, value, y)
 *         return
 *     if op == 'min':             # <<<<<<<<<<<<<<
 *         cupy.minimum(y, value, y)
 *         return
 */
  }

  /* "cupy/core/_routines_indexing.pyx":822
 *         cupy.minimum(y, value, y)
 *         return
 *     raise ValueError('this op is not supported')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 822, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_Raise(__pyx_t_10, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __PYX_ERR(0, 822, __pyx_L1_error)

  /* "cupy/core/_routines_indexing.pyx":771
 * 
 * 
 * cdef _scatter_op(ndarray a, slices, value, op):             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t i, li, ri
 *     cdef ndarray v, x, y, a_interm, reduced_idx
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("cupy.core._routines_indexing._scatter_op", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_x);
  __Pyx_XDECREF((PyObject *)__pyx_v_y);
  __Pyx_XDECREF((PyObject *)__pyx_v_a_interm);
  __Pyx_XDECREF((PyObject *)__pyx_v_reduced_idx);
  __Pyx_XDECREF(__pyx_v_slice_list);
  __Pyx_XDECREF(__pyx_v_adv_mask);
  __Pyx_XDECREF(__pyx_v_adv_slices);
  __Pyx_XDECREF(__pyx_v_axis);
  __Pyx_XDECREF((PyObject *)__pyx_v_a);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":825
 * 
 * 
 * cdef ndarray _diagonal(             # <<<<<<<<<<<<<<
 *         ndarray a, Py_ssize_t offset=0, Py_ssize_t axis1=0,
 *         Py_ssize_t axis2=1):
 */

static struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_f_4cupy_4core_18_routines_indexing__diagonal(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_a, struct __pyx_opt_args_4cupy_4core_18_routines_indexing__diagonal *__pyx_optional_args) {
  Py_ssize_t __pyx_v_offset = ((Py_ssize_t)0);
  Py_ssize_t __pyx_v_axis1 = ((Py_ssize_t)0);
  Py_ssize_t __pyx_v_axis2 = ((Py_ssize_t)1);
  Py_ssize_t __pyx_v_ndim;
  Py_ssize_t __pyx_v_min_axis;
  Py_ssize_t __pyx_v_max_axis;
  PyObject *__pyx_v_tr = NULL;
  PyObject *__pyx_v_diag_size = NULL;
  PyObject *__pyx_v_ret_shape = NULL;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_ret = NULL;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  int __pyx_t_3;
  int __pyx_t_4;
  int __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  int __pyx_t_13;
  PyObject *__pyx_t_14 = NULL;
  Py_ssize_t __pyx_t_15;
  std::vector<Py_ssize_t>  __pyx_t_16;
  long __pyx_t_17;
  std::vector<Py_ssize_t>  __pyx_t_18;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_diagonal", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_offset = __pyx_optional_args->offset;
      if (__pyx_optional_args->__pyx_n > 1) {
        __pyx_v_axis1 = __pyx_optional_args->axis1;
        if (__pyx_optional_args->__pyx_n > 2) {
          __pyx_v_axis2 = __pyx_optional_args->axis2;
        }
      }
    }
  }
  __Pyx_INCREF((PyObject *)__pyx_v_a);

  /* "cupy/core/_routines_indexing.pyx":828
 *         ndarray a, Py_ssize_t offset=0, Py_ssize_t axis1=0,
 *         Py_ssize_t axis2=1):
 *     cdef Py_ssize_t ndim = a.ndim             # <<<<<<<<<<<<<<
 *     if not (-ndim <= axis1 < ndim and -ndim <= axis2 < ndim):
 *         raise _errors._AxisError(
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 828, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_2 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 828, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_ndim = __pyx_t_2;

  /* "cupy/core/_routines_indexing.pyx":829
 *         Py_ssize_t axis2=1):
 *     cdef Py_ssize_t ndim = a.ndim
 *     if not (-ndim <= axis1 < ndim and -ndim <= axis2 < ndim):             # <<<<<<<<<<<<<<
 *         raise _errors._AxisError(
 *             'axis1(={0}) and axis2(={1}) must be within range '
 */
  __pyx_t_4 = ((-__pyx_v_ndim) <= __pyx_v_axis1);
  if (__pyx_t_4) {
    __pyx_t_4 = (__pyx_v_axis1 < __pyx_v_ndim);
  }
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (__pyx_t_5) {
  } else {
    __pyx_t_3 = __pyx_t_5;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_5 = ((-__pyx_v_ndim) <= __pyx_v_axis2);
  if (__pyx_t_5) {
    __pyx_t_5 = (__pyx_v_axis2 < __pyx_v_ndim);
  }
  __pyx_t_4 = (__pyx_t_5 != 0);
  __pyx_t_3 = __pyx_t_4;
  __pyx_L4_bool_binop_done:;
  __pyx_t_4 = ((!__pyx_t_3) != 0);
  if (unlikely(__pyx_t_4)) {

    /* "cupy/core/_routines_indexing.pyx":830
 *     cdef Py_ssize_t ndim = a.ndim
 *     if not (-ndim <= axis1 < ndim and -ndim <= axis2 < ndim):
 *         raise _errors._AxisError(             # <<<<<<<<<<<<<<
 *             'axis1(={0}) and axis2(={1}) must be within range '
 *             '(ndim={2})'.format(axis1, axis2, ndim))
 */
    __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_errors); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 830, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_AxisError); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 830, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "cupy/core/_routines_indexing.pyx":832
 *         raise _errors._AxisError(
 *             'axis1(={0}) and axis2(={1}) must be within range '
 *             '(ndim={2})'.format(axis1, axis2, ndim))             # <<<<<<<<<<<<<<
 * 
 *     axis1 %= ndim
 */
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_kp_u_axis1_0_and_axis2_1_must_be_with, __pyx_n_s_format); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 832, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = PyInt_FromSsize_t(__pyx_v_axis1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 832, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_10 = PyInt_FromSsize_t(__pyx_v_axis2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 832, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_11 = PyInt_FromSsize_t(__pyx_v_ndim); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 832, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_12 = NULL;
    __pyx_t_13 = 0;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_12)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_12);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
        __pyx_t_13 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[4] = {__pyx_t_12, __pyx_t_9, __pyx_t_10, __pyx_t_11};
      __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_13, 3+__pyx_t_13); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 832, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[4] = {__pyx_t_12, __pyx_t_9, __pyx_t_10, __pyx_t_11};
      __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_13, 3+__pyx_t_13); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 832, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    } else
    #endif
    {
      __pyx_t_14 = PyTuple_New(3+__pyx_t_13); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 832, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      if (__pyx_t_12) {
        __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_12); __pyx_t_12 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_13, __pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_10);
      PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_13, __pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_14, 2+__pyx_t_13, __pyx_t_11);
      __pyx_t_9 = 0;
      __pyx_t_10 = 0;
      __pyx_t_11 = 0;
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_14, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 832, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    }
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_7, __pyx_t_8, __pyx_t_6) : __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6);
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 830, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 830, __pyx_L1_error)

    /* "cupy/core/_routines_indexing.pyx":829
 *         Py_ssize_t axis2=1):
 *     cdef Py_ssize_t ndim = a.ndim
 *     if not (-ndim <= axis1 < ndim and -ndim <= axis2 < ndim):             # <<<<<<<<<<<<<<
 *         raise _errors._AxisError(
 *             'axis1(={0}) and axis2(={1}) must be within range '
 */
  }

  /* "cupy/core/_routines_indexing.pyx":834
 *             '(ndim={2})'.format(axis1, axis2, ndim))
 * 
 *     axis1 %= ndim             # <<<<<<<<<<<<<<
 *     axis2 %= ndim
 *     if axis1 < axis2:
 */
  if (unlikely(__pyx_v_ndim == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
    __PYX_ERR(0, 834, __pyx_L1_error)
  }
  __pyx_v_axis1 = __Pyx_mod_Py_ssize_t(__pyx_v_axis1, __pyx_v_ndim);

  /* "cupy/core/_routines_indexing.pyx":835
 * 
 *     axis1 %= ndim
 *     axis2 %= ndim             # <<<<<<<<<<<<<<
 *     if axis1 < axis2:
 *         min_axis, max_axis = axis1, axis2
 */
  if (unlikely(__pyx_v_ndim == 0)) {
    PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero");
    __PYX_ERR(0, 835, __pyx_L1_error)
  }
  __pyx_v_axis2 = __Pyx_mod_Py_ssize_t(__pyx_v_axis2, __pyx_v_ndim);

  /* "cupy/core/_routines_indexing.pyx":836
 *     axis1 %= ndim
 *     axis2 %= ndim
 *     if axis1 < axis2:             # <<<<<<<<<<<<<<
 *         min_axis, max_axis = axis1, axis2
 *     else:
 */
  __pyx_t_4 = ((__pyx_v_axis1 < __pyx_v_axis2) != 0);
  if (__pyx_t_4) {

    /* "cupy/core/_routines_indexing.pyx":837
 *     axis2 %= ndim
 *     if axis1 < axis2:
 *         min_axis, max_axis = axis1, axis2             # <<<<<<<<<<<<<<
 *     else:
 *         min_axis, max_axis = axis2, axis1
 */
    __pyx_t_2 = __pyx_v_axis1;
    __pyx_t_15 = __pyx_v_axis2;
    __pyx_v_min_axis = __pyx_t_2;
    __pyx_v_max_axis = __pyx_t_15;

    /* "cupy/core/_routines_indexing.pyx":836
 *     axis1 %= ndim
 *     axis2 %= ndim
 *     if axis1 < axis2:             # <<<<<<<<<<<<<<
 *         min_axis, max_axis = axis1, axis2
 *     else:
 */
    goto __pyx_L6;
  }

  /* "cupy/core/_routines_indexing.pyx":839
 *         min_axis, max_axis = axis1, axis2
 *     else:
 *         min_axis, max_axis = axis2, axis1             # <<<<<<<<<<<<<<
 * 
 *     tr = list(range(ndim))
 */
  /*else*/ {
    __pyx_t_15 = __pyx_v_axis2;
    __pyx_t_2 = __pyx_v_axis1;
    __pyx_v_min_axis = __pyx_t_15;
    __pyx_v_max_axis = __pyx_t_2;
  }
  __pyx_L6:;

  /* "cupy/core/_routines_indexing.pyx":841
 *         min_axis, max_axis = axis2, axis1
 * 
 *     tr = list(range(ndim))             # <<<<<<<<<<<<<<
 *     del tr[max_axis]
 *     del tr[min_axis]
 */
  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_ndim); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 841, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 841, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PySequence_List(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 841, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_tr = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":842
 * 
 *     tr = list(range(ndim))
 *     del tr[max_axis]             # <<<<<<<<<<<<<<
 *     del tr[min_axis]
 *     if offset >= 0:
 */
  if (unlikely(__Pyx_DelItemInt(__pyx_v_tr, __pyx_v_max_axis, Py_ssize_t, 1, PyInt_FromSsize_t, 1, 1, 1) < 0)) __PYX_ERR(0, 842, __pyx_L1_error)

  /* "cupy/core/_routines_indexing.pyx":843
 *     tr = list(range(ndim))
 *     del tr[max_axis]
 *     del tr[min_axis]             # <<<<<<<<<<<<<<
 *     if offset >= 0:
 *         a = _manipulation._transpose(a, tr + [axis1, axis2])
 */
  if (unlikely(__Pyx_DelItemInt(__pyx_v_tr, __pyx_v_min_axis, Py_ssize_t, 1, PyInt_FromSsize_t, 1, 1, 1) < 0)) __PYX_ERR(0, 843, __pyx_L1_error)

  /* "cupy/core/_routines_indexing.pyx":844
 *     del tr[max_axis]
 *     del tr[min_axis]
 *     if offset >= 0:             # <<<<<<<<<<<<<<
 *         a = _manipulation._transpose(a, tr + [axis1, axis2])
 *     else:
 */
  __pyx_t_4 = ((__pyx_v_offset >= 0) != 0);
  if (__pyx_t_4) {

    /* "cupy/core/_routines_indexing.pyx":845
 *     del tr[min_axis]
 *     if offset >= 0:
 *         a = _manipulation._transpose(a, tr + [axis1, axis2])             # <<<<<<<<<<<<<<
 *     else:
 *         a = _manipulation._transpose(a, tr + [axis2, axis1])
 */
    __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_axis1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 845, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = PyInt_FromSsize_t(__pyx_v_axis2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 845, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = PyList_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 845, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_1);
    PyList_SET_ITEM(__pyx_t_6, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_7);
    PyList_SET_ITEM(__pyx_t_6, 1, __pyx_t_7);
    __pyx_t_1 = 0;
    __pyx_t_7 = 0;
    __pyx_t_7 = PyNumber_Add(__pyx_v_tr, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 845, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_16 = __pyx_convert_vector_from_py_Py_ssize_t(__pyx_t_7); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 845, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = ((PyObject *)__pyx_f_4cupy_4core_22_routines_manipulation__transpose(__pyx_v_a, __pyx_t_16, 0)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 845, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF_SET(__pyx_v_a, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_7));
    __pyx_t_7 = 0;

    /* "cupy/core/_routines_indexing.pyx":844
 *     del tr[max_axis]
 *     del tr[min_axis]
 *     if offset >= 0:             # <<<<<<<<<<<<<<
 *         a = _manipulation._transpose(a, tr + [axis1, axis2])
 *     else:
 */
    goto __pyx_L7;
  }

  /* "cupy/core/_routines_indexing.pyx":847
 *         a = _manipulation._transpose(a, tr + [axis1, axis2])
 *     else:
 *         a = _manipulation._transpose(a, tr + [axis2, axis1])             # <<<<<<<<<<<<<<
 *         offset = -offset
 * 
 */
  /*else*/ {
    __pyx_t_7 = PyInt_FromSsize_t(__pyx_v_axis2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 847, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_axis1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 847, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 847, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_7);
    PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_6);
    PyList_SET_ITEM(__pyx_t_1, 1, __pyx_t_6);
    __pyx_t_7 = 0;
    __pyx_t_6 = 0;
    __pyx_t_6 = PyNumber_Add(__pyx_v_tr, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 847, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_16 = __pyx_convert_vector_from_py_Py_ssize_t(__pyx_t_6); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 847, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = ((PyObject *)__pyx_f_4cupy_4core_22_routines_manipulation__transpose(__pyx_v_a, __pyx_t_16, 0)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 847, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF_SET(__pyx_v_a, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_6));
    __pyx_t_6 = 0;

    /* "cupy/core/_routines_indexing.pyx":848
 *     else:
 *         a = _manipulation._transpose(a, tr + [axis2, axis1])
 *         offset = -offset             # <<<<<<<<<<<<<<
 * 
 *     diag_size = max(0, min(a.shape[-2], a.shape[-1] - offset))
 */
    __pyx_v_offset = (-__pyx_v_offset);
  }
  __pyx_L7:;

  /* "cupy/core/_routines_indexing.pyx":850
 *         offset = -offset
 * 
 *     diag_size = max(0, min(a.shape[-2], a.shape[-1] - offset))             # <<<<<<<<<<<<<<
 *     ret_shape = a.shape[:-2] + (diag_size,)
 *     if diag_size == 0:
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_shape); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_6, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_offset); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyNumber_Subtract(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_shape); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_6, -2L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_8 = PyObject_RichCompare(__pyx_t_7, __pyx_t_1, Py_LT); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 850, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (__pyx_t_4) {
    __Pyx_INCREF(__pyx_t_7);
    __pyx_t_6 = __pyx_t_7;
  } else {
    __Pyx_INCREF(__pyx_t_1);
    __pyx_t_6 = __pyx_t_1;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_INCREF(__pyx_t_6);
  __pyx_t_7 = __pyx_t_6;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_17 = 0;
  __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_t_17); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = PyObject_RichCompare(__pyx_t_7, __pyx_t_1, Py_GT); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 850, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (__pyx_t_4) {
    __Pyx_INCREF(__pyx_t_7);
    __pyx_t_6 = __pyx_t_7;
  } else {
    __pyx_t_8 = __Pyx_PyInt_From_long(__pyx_t_17); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 850, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_6 = __pyx_t_8;
    __pyx_t_8 = 0;
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = __pyx_t_6;
  __Pyx_INCREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_v_diag_size = __pyx_t_7;
  __pyx_t_7 = 0;

  /* "cupy/core/_routines_indexing.pyx":851
 * 
 *     diag_size = max(0, min(a.shape[-2], a.shape[-1] - offset))
 *     ret_shape = a.shape[:-2] + (diag_size,)             # <<<<<<<<<<<<<<
 *     if diag_size == 0:
 *         return ndarray(ret_shape, dtype=a.dtype)
 */
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_shape); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 851, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = __Pyx_PyObject_GetSlice(__pyx_t_7, 0, -2L, NULL, NULL, &__pyx_slice__27, 0, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 851, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 851, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_v_diag_size);
  __Pyx_GIVEREF(__pyx_v_diag_size);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_diag_size);
  __pyx_t_8 = PyNumber_Add(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 851, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_v_ret_shape = __pyx_t_8;
  __pyx_t_8 = 0;

  /* "cupy/core/_routines_indexing.pyx":852
 *     diag_size = max(0, min(a.shape[-2], a.shape[-1] - offset))
 *     ret_shape = a.shape[:-2] + (diag_size,)
 *     if diag_size == 0:             # <<<<<<<<<<<<<<
 *         return ndarray(ret_shape, dtype=a.dtype)
 * 
 */
  __pyx_t_8 = __Pyx_PyInt_EqObjC(__pyx_v_diag_size, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 852, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 852, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (__pyx_t_4) {

    /* "cupy/core/_routines_indexing.pyx":853
 *     ret_shape = a.shape[:-2] + (diag_size,)
 *     if diag_size == 0:
 *         return ndarray(ret_shape, dtype=a.dtype)             # <<<<<<<<<<<<<<
 * 
 *     a = a[..., :diag_size, offset:offset + diag_size]
 */
    __Pyx_XDECREF(((PyObject *)__pyx_r));
    __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 853, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_INCREF(__pyx_v_ret_shape);
    __Pyx_GIVEREF(__pyx_v_ret_shape);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_ret_shape);
    __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 853, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_v_a->dtype) < 0) __PYX_ERR(0, 853, __pyx_L1_error)
    __pyx_t_6 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_4cupy_4core_4core_ndarray), __pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 853, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_r = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_6);
    __pyx_t_6 = 0;
    goto __pyx_L0;

    /* "cupy/core/_routines_indexing.pyx":852
 *     diag_size = max(0, min(a.shape[-2], a.shape[-1] - offset))
 *     ret_shape = a.shape[:-2] + (diag_size,)
 *     if diag_size == 0:             # <<<<<<<<<<<<<<
 *         return ndarray(ret_shape, dtype=a.dtype)
 * 
 */
  }

  /* "cupy/core/_routines_indexing.pyx":855
 *         return ndarray(ret_shape, dtype=a.dtype)
 * 
 *     a = a[..., :diag_size, offset:offset + diag_size]             # <<<<<<<<<<<<<<
 * 
 *     ret = a.view()
 */
  __pyx_t_6 = PySlice_New(Py_None, __pyx_v_diag_size, Py_None); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 855, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = PyInt_FromSsize_t(__pyx_v_offset); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 855, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_8 = PyInt_FromSsize_t(__pyx_v_offset); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 855, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_1 = PyNumber_Add(__pyx_t_8, __pyx_v_diag_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 855, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PySlice_New(__pyx_t_7, __pyx_t_1, Py_None); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 855, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 855, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(Py_Ellipsis);
  __Pyx_GIVEREF(Py_Ellipsis);
  PyTuple_SET_ITEM(__pyx_t_1, 0, Py_Ellipsis);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_8);
  __pyx_t_6 = 0;
  __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_a), __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 855, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_8) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_8, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 855, __pyx_L1_error)
  __Pyx_DECREF_SET(__pyx_v_a, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_8));
  __pyx_t_8 = 0;

  /* "cupy/core/_routines_indexing.pyx":857
 *     a = a[..., :diag_size, offset:offset + diag_size]
 * 
 *     ret = a.view()             # <<<<<<<<<<<<<<
 *     # TODO(niboshi): Confirm update_x_contiguity flags
 *     ret._set_shape_and_strides(
 */
  __pyx_t_8 = ((PyObject *)((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)__pyx_v_a->__pyx_vtab)->view(__pyx_v_a, 0, NULL)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 857, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_v_ret = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_8);
  __pyx_t_8 = 0;

  /* "cupy/core/_routines_indexing.pyx":860
 *     # TODO(niboshi): Confirm update_x_contiguity flags
 *     ret._set_shape_and_strides(
 *         a.shape[:-2] + (diag_size,),             # <<<<<<<<<<<<<<
 *         a.strides[:-2] + (a.strides[-1] + a.strides[-2],),
 *         True, True)
 */
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_shape); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 860, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_t_8, 0, -2L, NULL, NULL, &__pyx_slice__27, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 860, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 860, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_INCREF(__pyx_v_diag_size);
  __Pyx_GIVEREF(__pyx_v_diag_size);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_diag_size);
  __pyx_t_6 = PyNumber_Add(__pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 860, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_16 = __pyx_convert_vector_from_py_Py_ssize_t(__pyx_t_6); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 860, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "cupy/core/_routines_indexing.pyx":861
 *     ret._set_shape_and_strides(
 *         a.shape[:-2] + (diag_size,),
 *         a.strides[:-2] + (a.strides[-1] + a.strides[-2],),             # <<<<<<<<<<<<<<
 *         True, True)
 *     return ret
 */
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_strides); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_8 = __Pyx_PyObject_GetSlice(__pyx_t_6, 0, -2L, NULL, NULL, &__pyx_slice__27, 0, 1, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_strides); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_6, -1L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_strides); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_6, -2L, long, 1, __Pyx_PyInt_From_long, 0, 1, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = PyNumber_Add(__pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6);
  __pyx_t_6 = 0;
  __pyx_t_6 = PyNumber_Add(__pyx_t_8, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 861, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_18 = __pyx_convert_vector_from_py_Py_ssize_t(__pyx_t_6); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 861, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "cupy/core/_routines_indexing.pyx":859
 *     ret = a.view()
 *     # TODO(niboshi): Confirm update_x_contiguity flags
 *     ret._set_shape_and_strides(             # <<<<<<<<<<<<<<
 *         a.shape[:-2] + (diag_size,),
 *         a.strides[:-2] + (a.strides[-1] + a.strides[-2],),
 */
  __pyx_t_6 = ((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)__pyx_v_ret->__pyx_vtab)->_set_shape_and_strides(__pyx_v_ret, __pyx_t_16, __pyx_t_18, 1, 1, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 859, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

  /* "cupy/core/_routines_indexing.pyx":863
 *         a.strides[:-2] + (a.strides[-1] + a.strides[-2],),
 *         True, True)
 *     return ret             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __Pyx_INCREF(((PyObject *)__pyx_v_ret));
  __pyx_r = __pyx_v_ret;
  goto __pyx_L0;

  /* "cupy/core/_routines_indexing.pyx":825
 * 
 * 
 * cdef ndarray _diagonal(             # <<<<<<<<<<<<<<
 *         ndarray a, Py_ssize_t offset=0, Py_ssize_t axis1=0,
 *         Py_ssize_t axis2=1):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_14);
  __Pyx_AddTraceback("cupy.core._routines_indexing._diagonal", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_tr);
  __Pyx_XDECREF(__pyx_v_diag_size);
  __Pyx_XDECREF(__pyx_v_ret_shape);
  __Pyx_XDECREF((PyObject *)__pyx_v_ret);
  __Pyx_XDECREF((PyObject *)__pyx_v_a);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":874
 * 
 * 
 * cdef tuple _prepare_multiple_array_indexing(ndarray a, list slices):             # <<<<<<<<<<<<<<
 *     # slices consist of either slice(None) or ndarray
 *     cdef Py_ssize_t i, p, li, ri, stride, prev_arr_i
 */

static PyObject *__pyx_f_4cupy_4core_18_routines_indexing__prepare_multiple_array_indexing(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_a, PyObject *__pyx_v_slices) {
  Py_ssize_t __pyx_v_i;
  Py_ssize_t __pyx_v_li;
  Py_ssize_t __pyx_v_ri;
  Py_ssize_t __pyx_v_stride;
  Py_ssize_t __pyx_v_prev_arr_i;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_reduced_idx = 0;
  int __pyx_v_do_transpose;
  PyObject *__pyx_v_br = NULL;
  PyObject *__pyx_v_s = NULL;
  PyObject *__pyx_v_transp_a = NULL;
  PyObject *__pyx_v_transp_b = NULL;
  PyObject *__pyx_v_slices_a = NULL;
  PyObject *__pyx_v_slices_b = NULL;
  PyObject *__pyx_v_a_shape_i = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  int __pyx_t_5;
  int __pyx_t_6;
  int __pyx_t_7;
  std::vector<Py_ssize_t>  __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  Py_ssize_t __pyx_t_11;
  int __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  Py_ssize_t __pyx_t_14;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_prepare_multiple_array_indexing", 0);
  __Pyx_INCREF((PyObject *)__pyx_v_a);
  __Pyx_INCREF(__pyx_v_slices);

  /* "cupy/core/_routines_indexing.pyx":880
 *     cdef bint do_transpose
 * 
 *     br = _manipulation.broadcast(*slices)             # <<<<<<<<<<<<<<
 *     slices = list(br.values)
 * 
 */
  __pyx_t_1 = PySequence_Tuple(__pyx_v_slices); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 880, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_4cupy_4core_22_routines_manipulation_broadcast), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 880, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_br = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "cupy/core/_routines_indexing.pyx":881
 * 
 *     br = _manipulation.broadcast(*slices)
 *     slices = list(br.values)             # <<<<<<<<<<<<<<
 * 
 *     # check if transpose is necessasry
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_br, __pyx_n_s_values); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 881, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PySequence_List(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 881, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF_SET(__pyx_v_slices, ((PyObject*)__pyx_t_1));
  __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":886
 *     # li:  index of the leftmost array in slices
 *     # ri:  index of the rightmost array in slices
 *     do_transpose = False             # <<<<<<<<<<<<<<
 *     prev_arr_i = -1
 *     li = 0
 */
  __pyx_v_do_transpose = 0;

  /* "cupy/core/_routines_indexing.pyx":887
 *     # ri:  index of the rightmost array in slices
 *     do_transpose = False
 *     prev_arr_i = -1             # <<<<<<<<<<<<<<
 *     li = 0
 *     ri = 0
 */
  __pyx_v_prev_arr_i = -1L;

  /* "cupy/core/_routines_indexing.pyx":888
 *     do_transpose = False
 *     prev_arr_i = -1
 *     li = 0             # <<<<<<<<<<<<<<
 *     ri = 0
 *     for i, s in enumerate(slices):
 */
  __pyx_v_li = 0;

  /* "cupy/core/_routines_indexing.pyx":889
 *     prev_arr_i = -1
 *     li = 0
 *     ri = 0             # <<<<<<<<<<<<<<
 *     for i, s in enumerate(slices):
 *         if isinstance(s, ndarray):
 */
  __pyx_v_ri = 0;

  /* "cupy/core/_routines_indexing.pyx":890
 *     li = 0
 *     ri = 0
 *     for i, s in enumerate(slices):             # <<<<<<<<<<<<<<
 *         if isinstance(s, ndarray):
 *             if prev_arr_i == -1:
 */
  __pyx_t_3 = 0;
  __pyx_t_1 = __pyx_v_slices; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0;
  for (;;) {
    if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 890, __pyx_L1_error)
    #else
    __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 890, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    #endif
    __Pyx_XDECREF_SET(__pyx_v_s, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_v_i = __pyx_t_3;
    __pyx_t_3 = (__pyx_t_3 + 1);

    /* "cupy/core/_routines_indexing.pyx":891
 *     ri = 0
 *     for i, s in enumerate(slices):
 *         if isinstance(s, ndarray):             # <<<<<<<<<<<<<<
 *             if prev_arr_i == -1:
 *                 prev_arr_i = i
 */
    __pyx_t_5 = __Pyx_TypeCheck(__pyx_v_s, __pyx_ptype_4cupy_4core_4core_ndarray); 
    __pyx_t_6 = (__pyx_t_5 != 0);
    if (__pyx_t_6) {

      /* "cupy/core/_routines_indexing.pyx":892
 *     for i, s in enumerate(slices):
 *         if isinstance(s, ndarray):
 *             if prev_arr_i == -1:             # <<<<<<<<<<<<<<
 *                 prev_arr_i = i
 *                 li = i
 */
      __pyx_t_6 = ((__pyx_v_prev_arr_i == -1L) != 0);
      if (__pyx_t_6) {

        /* "cupy/core/_routines_indexing.pyx":893
 *         if isinstance(s, ndarray):
 *             if prev_arr_i == -1:
 *                 prev_arr_i = i             # <<<<<<<<<<<<<<
 *                 li = i
 *             elif i - prev_arr_i > 1:
 */
        __pyx_v_prev_arr_i = __pyx_v_i;

        /* "cupy/core/_routines_indexing.pyx":894
 *             if prev_arr_i == -1:
 *                 prev_arr_i = i
 *                 li = i             # <<<<<<<<<<<<<<
 *             elif i - prev_arr_i > 1:
 *                 do_transpose = True
 */
        __pyx_v_li = __pyx_v_i;

        /* "cupy/core/_routines_indexing.pyx":892
 *     for i, s in enumerate(slices):
 *         if isinstance(s, ndarray):
 *             if prev_arr_i == -1:             # <<<<<<<<<<<<<<
 *                 prev_arr_i = i
 *                 li = i
 */
        goto __pyx_L6;
      }

      /* "cupy/core/_routines_indexing.pyx":895
 *                 prev_arr_i = i
 *                 li = i
 *             elif i - prev_arr_i > 1:             # <<<<<<<<<<<<<<
 *                 do_transpose = True
 *             else:
 */
      __pyx_t_6 = (((__pyx_v_i - __pyx_v_prev_arr_i) > 1) != 0);
      if (__pyx_t_6) {

        /* "cupy/core/_routines_indexing.pyx":896
 *                 li = i
 *             elif i - prev_arr_i > 1:
 *                 do_transpose = True             # <<<<<<<<<<<<<<
 *             else:
 *                 prev_arr_i = i
 */
        __pyx_v_do_transpose = 1;

        /* "cupy/core/_routines_indexing.pyx":895
 *                 prev_arr_i = i
 *                 li = i
 *             elif i - prev_arr_i > 1:             # <<<<<<<<<<<<<<
 *                 do_transpose = True
 *             else:
 */
        goto __pyx_L6;
      }

      /* "cupy/core/_routines_indexing.pyx":898
 *                 do_transpose = True
 *             else:
 *                 prev_arr_i = i             # <<<<<<<<<<<<<<
 *                 ri = i
 * 
 */
      /*else*/ {
        __pyx_v_prev_arr_i = __pyx_v_i;

        /* "cupy/core/_routines_indexing.pyx":899
 *             else:
 *                 prev_arr_i = i
 *                 ri = i             # <<<<<<<<<<<<<<
 * 
 *     if do_transpose:
 */
        __pyx_v_ri = __pyx_v_i;
      }
      __pyx_L6:;

      /* "cupy/core/_routines_indexing.pyx":891
 *     ri = 0
 *     for i, s in enumerate(slices):
 *         if isinstance(s, ndarray):             # <<<<<<<<<<<<<<
 *             if prev_arr_i == -1:
 *                 prev_arr_i = i
 */
    }

    /* "cupy/core/_routines_indexing.pyx":890
 *     li = 0
 *     ri = 0
 *     for i, s in enumerate(slices):             # <<<<<<<<<<<<<<
 *         if isinstance(s, ndarray):
 *             if prev_arr_i == -1:
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":901
 *                 ri = i
 * 
 *     if do_transpose:             # <<<<<<<<<<<<<<
 *         transp_a = []
 *         transp_b = []
 */
  __pyx_t_6 = (__pyx_v_do_transpose != 0);
  if (__pyx_t_6) {

    /* "cupy/core/_routines_indexing.pyx":902
 * 
 *     if do_transpose:
 *         transp_a = []             # <<<<<<<<<<<<<<
 *         transp_b = []
 *         slices_a = []
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 902, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_transp_a = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "cupy/core/_routines_indexing.pyx":903
 *     if do_transpose:
 *         transp_a = []
 *         transp_b = []             # <<<<<<<<<<<<<<
 *         slices_a = []
 *         slices_b = []
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 903, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_transp_b = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "cupy/core/_routines_indexing.pyx":904
 *         transp_a = []
 *         transp_b = []
 *         slices_a = []             # <<<<<<<<<<<<<<
 *         slices_b = []
 * 
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 904, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_slices_a = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "cupy/core/_routines_indexing.pyx":905
 *         transp_b = []
 *         slices_a = []
 *         slices_b = []             # <<<<<<<<<<<<<<
 * 
 *         for i, s in enumerate(slices):
 */
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 905, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_v_slices_b = ((PyObject*)__pyx_t_1);
    __pyx_t_1 = 0;

    /* "cupy/core/_routines_indexing.pyx":907
 *         slices_b = []
 * 
 *         for i, s in enumerate(slices):             # <<<<<<<<<<<<<<
 *             if isinstance(s, ndarray):
 *                 transp_a.append(i)
 */
    __pyx_t_3 = 0;
    __pyx_t_1 = __pyx_v_slices; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = 0;
    for (;;) {
      if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_4); __Pyx_INCREF(__pyx_t_2); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 907, __pyx_L1_error)
      #else
      __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 907, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      #endif
      __Pyx_XDECREF_SET(__pyx_v_s, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_v_i = __pyx_t_3;
      __pyx_t_3 = (__pyx_t_3 + 1);

      /* "cupy/core/_routines_indexing.pyx":908
 * 
 *         for i, s in enumerate(slices):
 *             if isinstance(s, ndarray):             # <<<<<<<<<<<<<<
 *                 transp_a.append(i)
 *                 slices_a.append(s)
 */
      __pyx_t_6 = __Pyx_TypeCheck(__pyx_v_s, __pyx_ptype_4cupy_4core_4core_ndarray); 
      __pyx_t_5 = (__pyx_t_6 != 0);
      if (__pyx_t_5) {

        /* "cupy/core/_routines_indexing.pyx":909
 *         for i, s in enumerate(slices):
 *             if isinstance(s, ndarray):
 *                 transp_a.append(i)             # <<<<<<<<<<<<<<
 *                 slices_a.append(s)
 *             else:
 */
        __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 909, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_transp_a, __pyx_t_2); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 909, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "cupy/core/_routines_indexing.pyx":910
 *             if isinstance(s, ndarray):
 *                 transp_a.append(i)
 *                 slices_a.append(s)             # <<<<<<<<<<<<<<
 *             else:
 *                 transp_b.append(i)
 */
        __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_slices_a, __pyx_v_s); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 910, __pyx_L1_error)

        /* "cupy/core/_routines_indexing.pyx":908
 * 
 *         for i, s in enumerate(slices):
 *             if isinstance(s, ndarray):             # <<<<<<<<<<<<<<
 *                 transp_a.append(i)
 *                 slices_a.append(s)
 */
        goto __pyx_L10;
      }

      /* "cupy/core/_routines_indexing.pyx":912
 *                 slices_a.append(s)
 *             else:
 *                 transp_b.append(i)             # <<<<<<<<<<<<<<
 *                 slices_b.append(s)
 *         a = _manipulation._transpose(a, transp_a + transp_b)
 */
      /*else*/ {
        __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 912, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_transp_b, __pyx_t_2); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 912, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "cupy/core/_routines_indexing.pyx":913
 *             else:
 *                 transp_b.append(i)
 *                 slices_b.append(s)             # <<<<<<<<<<<<<<
 *         a = _manipulation._transpose(a, transp_a + transp_b)
 *         slices = slices_a + slices_b
 */
        __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_slices_b, __pyx_v_s); if (unlikely(__pyx_t_7 == ((int)-1))) __PYX_ERR(0, 913, __pyx_L1_error)
      }
      __pyx_L10:;

      /* "cupy/core/_routines_indexing.pyx":907
 *         slices_b = []
 * 
 *         for i, s in enumerate(slices):             # <<<<<<<<<<<<<<
 *             if isinstance(s, ndarray):
 *                 transp_a.append(i)
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "cupy/core/_routines_indexing.pyx":914
 *                 transp_b.append(i)
 *                 slices_b.append(s)
 *         a = _manipulation._transpose(a, transp_a + transp_b)             # <<<<<<<<<<<<<<
 *         slices = slices_a + slices_b
 *         li = 0
 */
    __pyx_t_1 = PyNumber_Add(__pyx_v_transp_a, __pyx_v_transp_b); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 914, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_8 = __pyx_convert_vector_from_py_Py_ssize_t(__pyx_t_1); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 914, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = ((PyObject *)__pyx_f_4cupy_4core_22_routines_manipulation__transpose(__pyx_v_a, __pyx_t_8, 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 914, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_a, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "cupy/core/_routines_indexing.pyx":915
 *                 slices_b.append(s)
 *         a = _manipulation._transpose(a, transp_a + transp_b)
 *         slices = slices_a + slices_b             # <<<<<<<<<<<<<<
 *         li = 0
 *         ri = len(transp_a) - 1
 */
    __pyx_t_1 = PyNumber_Add(__pyx_v_slices_a, __pyx_v_slices_b); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 915, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF_SET(__pyx_v_slices, ((PyObject*)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "cupy/core/_routines_indexing.pyx":916
 *         a = _manipulation._transpose(a, transp_a + transp_b)
 *         slices = slices_a + slices_b
 *         li = 0             # <<<<<<<<<<<<<<
 *         ri = len(transp_a) - 1
 * 
 */
    __pyx_v_li = 0;

    /* "cupy/core/_routines_indexing.pyx":917
 *         slices = slices_a + slices_b
 *         li = 0
 *         ri = len(transp_a) - 1             # <<<<<<<<<<<<<<
 * 
 *     reduced_idx = ndarray(br.shape, dtype=numpy.int64)
 */
    __pyx_t_3 = PyList_GET_SIZE(__pyx_v_transp_a); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 917, __pyx_L1_error)
    __pyx_v_ri = (__pyx_t_3 - 1);

    /* "cupy/core/_routines_indexing.pyx":901
 *                 ri = i
 * 
 *     if do_transpose:             # <<<<<<<<<<<<<<
 *         transp_a = []
 *         transp_b = []
 */
  }

  /* "cupy/core/_routines_indexing.pyx":919
 *         ri = len(transp_a) - 1
 * 
 *     reduced_idx = ndarray(br.shape, dtype=numpy.int64)             # <<<<<<<<<<<<<<
 *     reduced_idx.fill(0)
 *     stride = 1
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_br, __pyx_n_s_shape); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 919, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 919, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 919, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_numpy); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 919, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_int64); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 919, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_10) < 0) __PYX_ERR(0, 919, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_10 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_4cupy_4core_4core_ndarray), __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 919, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_reduced_idx = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_10);
  __pyx_t_10 = 0;

  /* "cupy/core/_routines_indexing.pyx":920
 * 
 *     reduced_idx = ndarray(br.shape, dtype=numpy.int64)
 *     reduced_idx.fill(0)             # <<<<<<<<<<<<<<
 *     stride = 1
 *     for i in range(ri, li - 1, -1):
 */
  __pyx_t_10 = ((struct __pyx_vtabstruct_4cupy_4core_4core_ndarray *)__pyx_v_reduced_idx->__pyx_vtab)->fill(__pyx_v_reduced_idx, __pyx_int_0, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 920, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

  /* "cupy/core/_routines_indexing.pyx":921
 *     reduced_idx = ndarray(br.shape, dtype=numpy.int64)
 *     reduced_idx.fill(0)
 *     stride = 1             # <<<<<<<<<<<<<<
 *     for i in range(ri, li - 1, -1):
 *         s = slices[i]
 */
  __pyx_v_stride = 1;

  /* "cupy/core/_routines_indexing.pyx":922
 *     reduced_idx.fill(0)
 *     stride = 1
 *     for i in range(ri, li - 1, -1):             # <<<<<<<<<<<<<<
 *         s = slices[i]
 *         a_shape_i = a._shape[i]
 */
  __pyx_t_3 = (__pyx_v_li - 1);
  __pyx_t_4 = __pyx_t_3;
  for (__pyx_t_11 = __pyx_v_ri; __pyx_t_11 > __pyx_t_4; __pyx_t_11-=1) {
    __pyx_v_i = __pyx_t_11;

    /* "cupy/core/_routines_indexing.pyx":923
 *     stride = 1
 *     for i in range(ri, li - 1, -1):
 *         s = slices[i]             # <<<<<<<<<<<<<<
 *         a_shape_i = a._shape[i]
 *         # wrap all out-of-bound indices
 */
    __pyx_t_10 = __Pyx_GetItemInt_List(__pyx_v_slices, __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 1, 1, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 923, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_XDECREF_SET(__pyx_v_s, __pyx_t_10);
    __pyx_t_10 = 0;

    /* "cupy/core/_routines_indexing.pyx":924
 *     for i in range(ri, li - 1, -1):
 *         s = slices[i]
 *         a_shape_i = a._shape[i]             # <<<<<<<<<<<<<<
 *         # wrap all out-of-bound indices
 *         if a_shape_i != 0:
 */
    __pyx_t_10 = PyInt_FromSsize_t((__pyx_v_a->_shape[__pyx_v_i])); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 924, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_XDECREF_SET(__pyx_v_a_shape_i, __pyx_t_10);
    __pyx_t_10 = 0;

    /* "cupy/core/_routines_indexing.pyx":926
 *         a_shape_i = a._shape[i]
 *         # wrap all out-of-bound indices
 *         if a_shape_i != 0:             # <<<<<<<<<<<<<<
 *             _prepare_array_indexing(s, a_shape_i, stride, reduced_idx)
 *         stride *= a_shape_i
 */
    __pyx_t_10 = __Pyx_PyInt_NeObjC(__pyx_v_a_shape_i, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 926, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 926, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    if (__pyx_t_5) {

      /* "cupy/core/_routines_indexing.pyx":927
 *         # wrap all out-of-bound indices
 *         if a_shape_i != 0:
 *             _prepare_array_indexing(s, a_shape_i, stride, reduced_idx)             # <<<<<<<<<<<<<<
 *         stride *= a_shape_i
 * 
 */
      __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_prepare_array_indexing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 927, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PyInt_FromSsize_t(__pyx_v_stride); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 927, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_9 = NULL;
      __pyx_t_12 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_1, function);
          __pyx_t_12 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[5] = {__pyx_t_9, __pyx_v_s, __pyx_v_a_shape_i, __pyx_t_2, ((PyObject *)__pyx_v_reduced_idx)};
        __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_12, 4+__pyx_t_12); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 927, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[5] = {__pyx_t_9, __pyx_v_s, __pyx_v_a_shape_i, __pyx_t_2, ((PyObject *)__pyx_v_reduced_idx)};
        __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_12, 4+__pyx_t_12); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 927, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      } else
      #endif
      {
        __pyx_t_13 = PyTuple_New(4+__pyx_t_12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 927, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        if (__pyx_t_9) {
          __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_9); __pyx_t_9 = NULL;
        }
        __Pyx_INCREF(__pyx_v_s);
        __Pyx_GIVEREF(__pyx_v_s);
        PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_12, __pyx_v_s);
        __Pyx_INCREF(__pyx_v_a_shape_i);
        __Pyx_GIVEREF(__pyx_v_a_shape_i);
        PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_12, __pyx_v_a_shape_i);
        __Pyx_GIVEREF(__pyx_t_2);
        PyTuple_SET_ITEM(__pyx_t_13, 2+__pyx_t_12, __pyx_t_2);
        __Pyx_INCREF(((PyObject *)__pyx_v_reduced_idx));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_reduced_idx));
        PyTuple_SET_ITEM(__pyx_t_13, 3+__pyx_t_12, ((PyObject *)__pyx_v_reduced_idx));
        __pyx_t_2 = 0;
        __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_13, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 927, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

      /* "cupy/core/_routines_indexing.pyx":926
 *         a_shape_i = a._shape[i]
 *         # wrap all out-of-bound indices
 *         if a_shape_i != 0:             # <<<<<<<<<<<<<<
 *             _prepare_array_indexing(s, a_shape_i, stride, reduced_idx)
 *         stride *= a_shape_i
 */
    }

    /* "cupy/core/_routines_indexing.pyx":928
 *         if a_shape_i != 0:
 *             _prepare_array_indexing(s, a_shape_i, stride, reduced_idx)
 *         stride *= a_shape_i             # <<<<<<<<<<<<<<
 * 
 *     return a, reduced_idx, li, ri
 */
    __pyx_t_10 = PyInt_FromSsize_t(__pyx_v_stride); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_1 = PyNumber_InPlaceMultiply(__pyx_t_10, __pyx_v_a_shape_i); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_14 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_14 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 928, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_stride = __pyx_t_14;
  }

  /* "cupy/core/_routines_indexing.pyx":930
 *         stride *= a_shape_i
 * 
 *     return a, reduced_idx, li, ri             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyInt_FromSsize_t(__pyx_v_li); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 930, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_10 = PyInt_FromSsize_t(__pyx_v_ri); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 930, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_13 = PyTuple_New(4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 930, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __Pyx_INCREF(((PyObject *)__pyx_v_a));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_a));
  PyTuple_SET_ITEM(__pyx_t_13, 0, ((PyObject *)__pyx_v_a));
  __Pyx_INCREF(((PyObject *)__pyx_v_reduced_idx));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_reduced_idx));
  PyTuple_SET_ITEM(__pyx_t_13, 1, ((PyObject *)__pyx_v_reduced_idx));
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_13, 2, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_10);
  PyTuple_SET_ITEM(__pyx_t_13, 3, __pyx_t_10);
  __pyx_t_1 = 0;
  __pyx_t_10 = 0;
  __pyx_r = ((PyObject*)__pyx_t_13);
  __pyx_t_13 = 0;
  goto __pyx_L0;

  /* "cupy/core/_routines_indexing.pyx":874
 * 
 * 
 * cdef tuple _prepare_multiple_array_indexing(ndarray a, list slices):             # <<<<<<<<<<<<<<
 *     # slices consist of either slice(None) or ndarray
 *     cdef Py_ssize_t i, p, li, ri, stride, prev_arr_i
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_AddTraceback("cupy.core._routines_indexing._prepare_multiple_array_indexing", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_reduced_idx);
  __Pyx_XDECREF(__pyx_v_br);
  __Pyx_XDECREF(__pyx_v_s);
  __Pyx_XDECREF(__pyx_v_transp_a);
  __Pyx_XDECREF(__pyx_v_transp_b);
  __Pyx_XDECREF(__pyx_v_slices_a);
  __Pyx_XDECREF(__pyx_v_slices_b);
  __Pyx_XDECREF(__pyx_v_a_shape_i);
  __Pyx_XDECREF((PyObject *)__pyx_v_a);
  __Pyx_XDECREF(__pyx_v_slices);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "cupy/core/_routines_indexing.pyx":933
 * 
 * 
 * cdef ndarray _getitem_multiple(ndarray a, list slices):             # <<<<<<<<<<<<<<
 *     a, reduced_idx, li, ri = _prepare_multiple_array_indexing(a, slices)
 *     return _take(a, reduced_idx, li, ri)
 */

static struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_f_4cupy_4core_18_routines_indexing__getitem_multiple(struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_v_a, PyObject *__pyx_v_slices) {
  PyObject *__pyx_v_reduced_idx = NULL;
  PyObject *__pyx_v_li = NULL;
  PyObject *__pyx_v_ri = NULL;
  struct __pyx_obj_4cupy_4core_4core_ndarray *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  int __pyx_t_7;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("_getitem_multiple", 0);
  __Pyx_INCREF((PyObject *)__pyx_v_a);

  /* "cupy/core/_routines_indexing.pyx":934
 * 
 * cdef ndarray _getitem_multiple(ndarray a, list slices):
 *     a, reduced_idx, li, ri = _prepare_multiple_array_indexing(a, slices)             # <<<<<<<<<<<<<<
 *     return _take(a, reduced_idx, li, ri)
 */
  __pyx_t_1 = __pyx_f_4cupy_4core_18_routines_indexing__prepare_multiple_array_indexing(__pyx_v_a, __pyx_v_slices); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 934, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (likely(__pyx_t_1 != Py_None)) {
    PyObject* sequence = __pyx_t_1;
    Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
    if (unlikely(size != 4)) {
      if (size > 4) __Pyx_RaiseTooManyValuesError(4);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 934, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
    __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
    __pyx_t_4 = PyTuple_GET_ITEM(sequence, 2); 
    __pyx_t_5 = PyTuple_GET_ITEM(sequence, 3); 
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_5);
    #else
    {
      Py_ssize_t i;
      PyObject** temps[4] = {&__pyx_t_2,&__pyx_t_3,&__pyx_t_4,&__pyx_t_5};
      for (i=0; i < 4; i++) {
        PyObject* item = PySequence_ITEM(sequence, i); if (unlikely(!item)) __PYX_ERR(0, 934, __pyx_L1_error)
        __Pyx_GOTREF(item);
        *(temps[i]) = item;
      }
    }
    #endif
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(0, 934, __pyx_L1_error)
  }
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_4cupy_4core_4core_ndarray))))) __PYX_ERR(0, 934, __pyx_L1_error)
  __Pyx_DECREF_SET(__pyx_v_a, ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_2));
  __pyx_t_2 = 0;
  __pyx_v_reduced_idx = __pyx_t_3;
  __pyx_t_3 = 0;
  __pyx_v_li = __pyx_t_4;
  __pyx_t_4 = 0;
  __pyx_v_ri = __pyx_t_5;
  __pyx_t_5 = 0;

  /* "cupy/core/_routines_indexing.pyx":935
 * cdef ndarray _getitem_multiple(ndarray a, list slices):
 *     a, reduced_idx, li, ri = _prepare_multiple_array_indexing(a, slices)
 *     return _take(a, reduced_idx, li, ri)             # <<<<<<<<<<<<<<
 */
  __Pyx_XDECREF(((PyObject *)__pyx_r));
  __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_v_li); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 935, __pyx_L1_error)
  __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_v_ri); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 935, __pyx_L1_error)
  __pyx_t_1 = ((PyObject *)__pyx_f_4cupy_4core_18_routines_indexing__take(__pyx_v_a, __pyx_v_reduced_idx, __pyx_t_6, __pyx_t_7, NULL)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 935, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = ((struct __pyx_obj_4cupy_4core_4core_ndarray *)__pyx_t_1);
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "cupy/core/_routines_indexing.pyx":933
 * 
 * 
 * cdef ndarray _getitem_multiple(ndarray a, list slices):             # <<<<<<<<<<<<<<
 *     a, reduced_idx, li, ri = _prepare_multiple_array_indexing(a, slices)
 *     return _take(a, reduced_idx, li, ri)
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("cupy.core._routines_indexing._getitem_multiple", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_reduced_idx);
  __Pyx_XDECREF(__pyx_v_li);
  __Pyx_XDECREF(__pyx_v_ri);
  __Pyx_XDECREF((PyObject *)__pyx_v_a);
  __Pyx_XGIVEREF((PyObject *)__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "vector.from_py":45
 * 
 * @cname("__pyx_convert_vector_from_py_Py_ssize_t")
 * cdef vector[X] __pyx_convert_vector_from_py_Py_ssize_t(object o) except *:             # <<<<<<<<<<<<<<
 *     cdef vector[X] v
 *     for item in o:
 */

static std::vector<Py_ssize_t>  __pyx_convert_vector_from_py_Py_ssize_t(PyObject *__pyx_v_o) {
  std::vector<Py_ssize_t>  __pyx_v_v;
  PyObject *__pyx_v_item = NULL;
  std::vector<Py_ssize_t>  __pyx_r;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  Py_ssize_t __pyx_t_2;
  PyObject *(*__pyx_t_3)(PyObject *);
  PyObject *__pyx_t_4 = NULL;
  Py_ssize_t __pyx_t_5;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_convert_vector_from_py_Py_ssize_t", 0);

  /* "vector.from_py":47
 * cdef vector[X] __pyx_convert_vector_from_py_Py_ssize_t(object o) except *:
 *     cdef vector[X] v
 *     for item in o:             # <<<<<<<<<<<<<<
 *         v.push_back(<X>item)
 *     return v
 */
  if (likely(PyList_CheckExact(__pyx_v_o)) || PyTuple_CheckExact(__pyx_v_o)) {
    __pyx_t_1 = __pyx_v_o; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
    __pyx_t_3 = NULL;
  } else {
    __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_o); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 47, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 47, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_3)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(1, 47, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 47, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(1, 47, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 47, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_3(__pyx_t_1);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(1, 47, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "vector.from_py":48
 *     cdef vector[X] v
 *     for item in o:
 *         v.push_back(<X>item)             # <<<<<<<<<<<<<<
 *     return v
 * 
 */
    __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_item); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 48, __pyx_L1_error)
    __pyx_v_v.push_back(((Py_ssize_t)__pyx_t_5));

    /* "vector.from_py":47
 * cdef vector[X] __pyx_convert_vector_from_py_Py_ssize_t(object o) except *:
 *     cdef vector[X] v
 *     for item in o:             # <<<<<<<<<<<<<<
 *         v.push_back(<X>item)
 *     return v
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "vector.from_py":49
 *     for item in o:
 *         v.push_back(<X>item)
 *     return v             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_r = __pyx_v_v;
  goto __pyx_L0;

  /* "vector.from_py":45
 * 
 * @cname("__pyx_convert_vector_from_py_Py_ssize_t")
 * cdef vector[X] __pyx_convert_vector_from_py_Py_ssize_t(object o) except *:             # <<<<<<<<<<<<<<
 *     cdef vector[X] v
 *     for item in o:
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("vector.from_py.__pyx_convert_vector_from_py_Py_ssize_t", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_pretend_to_initialize(&__pyx_r);
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_item);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "vector.to_py":60
 * 
 * @cname("__pyx_convert_vector_to_py_Py_ssize_t")
 * cdef object __pyx_convert_vector_to_py_Py_ssize_t(vector[X]& v):             # <<<<<<<<<<<<<<
 *     return [v[i] for i in range(v.size())]
 * 
 */

static PyObject *__pyx_convert_vector_to_py_Py_ssize_t(const std::vector<Py_ssize_t>  &__pyx_v_v) {
  size_t __pyx_v_i;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  size_t __pyx_t_2;
  size_t __pyx_t_3;
  size_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__pyx_convert_vector_to_py_Py_ssize_t", 0);

  /* "vector.to_py":61
 * @cname("__pyx_convert_vector_to_py_Py_ssize_t")
 * cdef object __pyx_convert_vector_to_py_Py_ssize_t(vector[X]& v):
 *     return [v[i] for i in range(v.size())]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 61, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __pyx_v_v.size();
  __pyx_t_3 = __pyx_t_2;
  for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_i = __pyx_t_4;
    __pyx_t_5 = PyInt_FromSsize_t((__pyx_v_v[__pyx_v_i])); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 61, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(1, 61, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "vector.to_py":60
 * 
 * @cname("__pyx_convert_vector_to_py_Py_ssize_t")
 * cdef object __pyx_convert_vector_to_py_Py_ssize_t(vector[X]& v):             # <<<<<<<<<<<<<<
 *     return [v[i] for i in range(v.size())]
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("vector.to_py.__pyx_convert_vector_to_py_Py_ssize_t", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyMethodDef __pyx_methods[] = {
  {"_prepare_slice_list", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_4cupy_4core_18_routines_indexing_1_prepare_slice_list, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4cupy_4core_18_routines_indexing__prepare_slice_list},
  {"_prepare_mask_indexing_single", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_4cupy_4core_18_routines_indexing_3_prepare_mask_indexing_single, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4cupy_4core_18_routines_indexing_2_prepare_mask_indexing_single},
  {"_getitem_mask_single", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_4cupy_4core_18_routines_indexing_5_getitem_mask_single, METH_VARARGS|METH_KEYWORDS, __pyx_doc_4cupy_4core_18_routines_indexing_4_getitem_mask_single},
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
#if CYTHON_PEP489_MULTI_PHASE_INIT
static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/
static int __pyx_pymod_exec__routines_indexing(PyObject* module); /*proto*/
static PyModuleDef_Slot __pyx_moduledef_slots[] = {
  {Py_mod_create, (void*)__pyx_pymod_create},
  {Py_mod_exec, (void*)__pyx_pymod_exec__routines_indexing},
  {0, NULL}
};
#endif

static struct PyModuleDef __pyx_moduledef = {
    PyModuleDef_HEAD_INIT,
    "_routines_indexing",
    0, /* m_doc */
  #if CYTHON_PEP489_MULTI_PHASE_INIT
    0, /* m_size */
  #else
    -1, /* m_size */
  #endif
    __pyx_methods /* m_methods */,
  #if CYTHON_PEP489_MULTI_PHASE_INIT
    __pyx_moduledef_slots, /* m_slots */
  #else
    NULL, /* m_reload */
  #endif
    NULL, /* m_traverse */
    NULL, /* m_clear */
    NULL /* m_free */
};
#endif
#ifndef CYTHON_SMALL_CODE
#if defined(__clang__)
    #define CYTHON_SMALL_CODE
#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
    #define CYTHON_SMALL_CODE __attribute__((cold))
#else
    #define CYTHON_SMALL_CODE
#endif
#endif

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_n_s_AxisError, __pyx_k_AxisError, sizeof(__pyx_k_AxisError), 0, 0, 1, 1},
  {&__pyx_kp_u_Axis_overrun, __pyx_k_Axis_overrun, sizeof(__pyx_k_Axis_overrun), 0, 1, 0, 0},
  {&__pyx_n_s_ElementwiseKernel, __pyx_k_ElementwiseKernel, sizeof(__pyx_k_ElementwiseKernel), 0, 0, 1, 1},
  {&__pyx_kp_u_Index, __pyx_k_Index, sizeof(__pyx_k_Index), 0, 1, 0, 0},
  {&__pyx_n_s_IndexError, __pyx_k_IndexError, sizeof(__pyx_k_IndexError), 0, 0, 1, 1},
  {&__pyx_kp_u_Invalid_index_type_s, __pyx_k_Invalid_index_type_s, sizeof(__pyx_k_Invalid_index_type_s), 0, 1, 0, 0},
  {&__pyx_kp_u_Output_dtype_mismatch, __pyx_k_Output_dtype_mismatch, sizeof(__pyx_k_Output_dtype_mismatch), 0, 1, 0, 0},
  {&__pyx_kp_u_Output_shape_mismatch, __pyx_k_Output_shape_mismatch, sizeof(__pyx_k_Output_shape_mismatch), 0, 1, 0, 0},
  {&__pyx_kp_u_S_a_raw_T_choices_int32_n_channe, __pyx_k_S_a_raw_T_choices_int32_n_channe, sizeof(__pyx_k_S_a_raw_T_choices_int32_n_channe), 0, 1, 0, 0},
  {&__pyx_kp_u_S_a_raw_T_choices_int32_n_channe_2, __pyx_k_S_a_raw_T_choices_int32_n_channe_2, sizeof(__pyx_k_S_a_raw_T_choices_int32_n_channe_2), 0, 1, 0, 0},
  {&__pyx_kp_u_S_in0_s_in1_len_out_stride_in0, __pyx_k_S_in0_s_in1_len_out_stride_in0, sizeof(__pyx_k_S_in0_s_in1_len_out_stride_in0), 0, 1, 0, 0},
  {&__pyx_kp_u_S_ind_raw_T_vals_int64_n_vals_in, __pyx_k_S_ind_raw_T_vals_int64_n_vals_in, sizeof(__pyx_k_S_ind_raw_T_vals_int64_n_vals_in), 0, 1, 0, 0},
  {&__pyx_kp_u_S_out, __pyx_k_S_out, sizeof(__pyx_k_S_out), 0, 1, 0, 0},
  {&__pyx_kp_u_S_wrap_indices_indices_adim_if, __pyx_k_S_wrap_indices_indices_adim_if, sizeof(__pyx_k_S_wrap_indices_indices_adim_if), 0, 1, 0, 0},
  {&__pyx_kp_u_S_wrap_indices_indices_adim_if_2, __pyx_k_S_wrap_indices_indices_adim_if_2, sizeof(__pyx_k_S_wrap_indices_indices_adim_if_2), 0, 1, 0, 0},
  {&__pyx_kp_u_S_wrap_indices_indices_adim_if_3, __pyx_k_S_wrap_indices_indices_adim_if_3, sizeof(__pyx_k_S_wrap_indices_indices_adim_if_3), 0, 1, 0, 0},
  {&__pyx_kp_u_S_wrap_indices_indices_adim_if_4, __pyx_k_S_wrap_indices_indices_adim_if_4, sizeof(__pyx_k_S_wrap_indices_indices_adim_if_4), 0, 1, 0, 0},
  {&__pyx_kp_u_S_x_a_if_a_0_x_0_else_if_a_n_x, __pyx_k_S_x_a_if_a_0_x_0_else_if_a_n_x, sizeof(__pyx_k_S_x_a_if_a_0_x_0_else_if_a_n_x), 0, 1, 0, 0},
  {&__pyx_kp_u_T_a, __pyx_k_T_a, sizeof(__pyx_k_T_a), 0, 1, 0, 0},
  {&__pyx_kp_u_T_a_bool_mask_S_mask_scanned, __pyx_k_T_a_bool_mask_S_mask_scanned, sizeof(__pyx_k_T_a_bool_mask_S_mask_scanned), 0, 1, 0, 0},
  {&__pyx_kp_u_T_out, __pyx_k_T_out, sizeof(__pyx_k_T_out), 0, 1, 0, 0},
  {&__pyx_kp_u_T_s_S_len_S_stride, __pyx_k_T_s_S_len_S_stride, sizeof(__pyx_k_T_s_S_len_S_stride), 0, 1, 0, 0},
  {&__pyx_kp_u_T_src_S_index, __pyx_k_T_src_S_index, sizeof(__pyx_k_T_src_S_index), 0, 1, 0, 0},
  {&__pyx_kp_u_T_v_S_indices_int32_cdim_int32_r, __pyx_k_T_v_S_indices_int32_cdim_int32_r, sizeof(__pyx_k_T_v_S_indices_int32_cdim_int32_r), 0, 1, 0, 0},
  {&__pyx_kp_u_T_y, __pyx_k_T_y, sizeof(__pyx_k_T_y), 0, 1, 0, 0},
  {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1},
  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  {&__pyx_kp_u__19, __pyx_k__19, sizeof(__pyx_k__19), 0, 1, 0, 0},
  {&__pyx_n_s_a, __pyx_k_a, sizeof(__pyx_k_a), 0, 0, 1, 1},
  {&__pyx_n_u_add, __pyx_k_add, sizeof(__pyx_k_add), 0, 1, 0, 1},
  {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1},
  {&__pyx_n_s_array, __pyx_k_array, sizeof(__pyx_k_array), 0, 0, 1, 1},
  {&__pyx_kp_u_arrays_used_as_indices_must_be_o, __pyx_k_arrays_used_as_indices_must_be_o, sizeof(__pyx_k_arrays_used_as_indices_must_be_o), 0, 1, 0, 0},
  {&__pyx_n_s_astype, __pyx_k_astype, sizeof(__pyx_k_astype), 0, 0, 1, 1},
  {&__pyx_n_s_axis, __pyx_k_axis, sizeof(__pyx_k_axis), 0, 0, 1, 1},
  {&__pyx_kp_u_axis1_0_and_axis2_1_must_be_with, __pyx_k_axis1_0_and_axis2_1_must_be_with, sizeof(__pyx_k_axis1_0_and_axis2_1_must_be_with), 0, 1, 0, 0},
  {&__pyx_n_s_bool, __pyx_k_bool, sizeof(__pyx_k_bool), 0, 0, 1, 1},
  {&__pyx_kp_u_boolean_index_did_not_match, __pyx_k_boolean_index_did_not_match, sizeof(__pyx_k_boolean_index_did_not_match), 0, 1, 0, 0},
  {&__pyx_kp_u_cannot_do_a_non_empty_take_from, __pyx_k_cannot_do_a_non_empty_take_from, sizeof(__pyx_k_cannot_do_a_non_empty_take_from), 0, 1, 0, 0},
  {&__pyx_n_s_choose_clip_kernel, __pyx_k_choose_clip_kernel, sizeof(__pyx_k_choose_clip_kernel), 0, 0, 1, 1},
  {&__pyx_n_s_choose_kernel, __pyx_k_choose_kernel, sizeof(__pyx_k_choose_kernel), 0, 0, 1, 1},
  {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
  {&__pyx_n_u_clip, __pyx_k_clip, sizeof(__pyx_k_clip), 0, 1, 0, 1},
  {&__pyx_kp_u_clipmode_not_understood, __pyx_k_clipmode_not_understood, sizeof(__pyx_k_clipmode_not_understood), 0, 1, 0, 0},
  {&__pyx_n_s_copy, __pyx_k_copy, sizeof(__pyx_k_copy), 0, 0, 1, 1},
  {&__pyx_n_s_core, __pyx_k_core, sizeof(__pyx_k_core), 0, 0, 1, 1},
  {&__pyx_n_s_cupy, __pyx_k_cupy, sizeof(__pyx_k_cupy), 0, 0, 1, 1},
  {&__pyx_n_u_cupy_choose, __pyx_k_cupy_choose, sizeof(__pyx_k_cupy_choose), 0, 1, 0, 1},
  {&__pyx_n_u_cupy_choose_clip, __pyx_k_cupy_choose_clip, sizeof(__pyx_k_cupy_choose_clip), 0, 1, 0, 1},
  {&__pyx_n_s_cupy_core, __pyx_k_cupy_core, sizeof(__pyx_k_cupy_core), 0, 0, 1, 1},
  {&__pyx_n_s_cupy_core__kernel, __pyx_k_cupy_core__kernel, sizeof(__pyx_k_cupy_core__kernel), 0, 0, 1, 1},
  {&__pyx_n_s_cupy_core__ufuncs, __pyx_k_cupy_core__ufuncs, sizeof(__pyx_k_cupy_core__ufuncs), 0, 0, 1, 1},
  {&__pyx_n_u_cupy_getitem_mask, __pyx_k_cupy_getitem_mask, sizeof(__pyx_k_cupy_getitem_mask), 0, 1, 0, 1},
  {&__pyx_n_u_cupy_prepare_array_indexing, __pyx_k_cupy_prepare_array_indexing, sizeof(__pyx_k_cupy_prepare_array_indexing), 0, 1, 0, 1},
  {&__pyx_n_u_cupy_put_clip, __pyx_k_cupy_put_clip, sizeof(__pyx_k_cupy_put_clip), 0, 1, 0, 1},
  {&__pyx_n_u_cupy_put_raise, __pyx_k_cupy_put_raise, sizeof(__pyx_k_cupy_put_raise), 0, 1, 0, 1},
  {&__pyx_n_u_cupy_put_wrap, __pyx_k_cupy_put_wrap, sizeof(__pyx_k_cupy_put_wrap), 0, 1, 0, 1},
  {&__pyx_n_u_cupy_scatter_add, __pyx_k_cupy_scatter_add, sizeof(__pyx_k_cupy_scatter_add), 0, 1, 0, 1},
  {&__pyx_n_u_cupy_scatter_add_mask, __pyx_k_cupy_scatter_add_mask, sizeof(__pyx_k_cupy_scatter_add_mask), 0, 1, 0, 1},
  {&__pyx_n_u_cupy_scatter_max, __pyx_k_cupy_scatter_max, sizeof(__pyx_k_cupy_scatter_max), 0, 1, 0, 1},
  {&__pyx_n_u_cupy_scatter_max_mask, __pyx_k_cupy_scatter_max_mask, sizeof(__pyx_k_cupy_scatter_max_mask), 0, 1, 0, 1},
  {&__pyx_n_u_cupy_scatter_min, __pyx_k_cupy_scatter_min, sizeof(__pyx_k_cupy_scatter_min), 0, 1, 0, 1},
  {&__pyx_n_u_cupy_scatter_min_mask, __pyx_k_cupy_scatter_min_mask, sizeof(__pyx_k_cupy_scatter_min_mask), 0, 1, 0, 1},
  {&__pyx_n_u_cupy_scatter_update, __pyx_k_cupy_scatter_update, sizeof(__pyx_k_cupy_scatter_update), 0, 1, 0, 1},
  {&__pyx_n_u_cupy_scatter_update_mask, __pyx_k_cupy_scatter_update_mask, sizeof(__pyx_k_cupy_scatter_update_mask), 0, 1, 0, 1},
  {&__pyx_n_u_cupy_take, __pyx_k_cupy_take, sizeof(__pyx_k_cupy_take), 0, 1, 0, 1},
  {&__pyx_n_u_cupy_take_scalar, __pyx_k_cupy_take_scalar, sizeof(__pyx_k_cupy_take_scalar), 0, 1, 0, 1},
  {&__pyx_kp_u_currently_CuPy_only_supports_sli, __pyx_k_currently_CuPy_only_supports_sli, sizeof(__pyx_k_currently_CuPy_only_supports_sli), 0, 1, 0, 0},
  {&__pyx_n_s_dtype, __pyx_k_dtype, sizeof(__pyx_k_dtype), 0, 0, 1, 1},
  {&__pyx_n_s_elementwise_copy, __pyx_k_elementwise_copy, sizeof(__pyx_k_elementwise_copy), 0, 0, 1, 1},
  {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1},
  {&__pyx_n_s_errors, __pyx_k_errors, sizeof(__pyx_k_errors), 0, 0, 1, 1},
  {&__pyx_n_s_float16, __pyx_k_float16, sizeof(__pyx_k_float16), 0, 0, 1, 1},
  {&__pyx_n_s_float32, __pyx_k_float32, sizeof(__pyx_k_float32), 0, 0, 1, 1},
  {&__pyx_n_s_float64, __pyx_k_float64, sizeof(__pyx_k_float64), 0, 0, 1, 1},
  {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1},
  {&__pyx_n_s_getitem_mask_kernel, __pyx_k_getitem_mask_kernel, sizeof(__pyx_k_getitem_mask_kernel), 0, 0, 1, 1},
  {&__pyx_n_u_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 1, 0, 1},
  {&__pyx_kp_u_if_mask_a_a_v_mask_scanned_1, __pyx_k_if_mask_a_a_v_mask_scanned_1, sizeof(__pyx_k_if_mask_a_a_v_mask_scanned_1), 0, 1, 0, 0},
  {&__pyx_kp_u_if_mask_a_max_a_v_mask_scanned_1, __pyx_k_if_mask_a_max_a_v_mask_scanned_1, sizeof(__pyx_k_if_mask_a_max_a_v_mask_scanned_1), 0, 1, 0, 0},
  {&__pyx_kp_u_if_mask_a_min_a_v_mask_scanned_1, __pyx_k_if_mask_a_min_a_v_mask_scanned_1, sizeof(__pyx_k_if_mask_a_min_a_v_mask_scanned_1), 0, 1, 0, 0},
  {&__pyx_kp_u_if_mask_a_v_mask_scanned_1, __pyx_k_if_mask_a_v_mask_scanned_1, sizeof(__pyx_k_if_mask_a_v_mask_scanned_1), 0, 1, 0, 0},
  {&__pyx_kp_u_if_mask_out_mask_scanned_1_a, __pyx_k_if_mask_out_mask_scanned_1_a, sizeof(__pyx_k_if_mask_out_mask_scanned_1_a), 0, 1, 0, 0},
  {&__pyx_kp_u_if_src_0_dst_index_1_i, __pyx_k_if_src_0_dst_index_1_i, sizeof(__pyx_k_if_src_0_dst_index_1_i), 0, 1, 0, 0},
  {&__pyx_kp_u_if_src_0_for_int_j_0_j__ind_ndi, __pyx_k_if_src_0_for_int_j_0_j__ind_ndi, sizeof(__pyx_k_if_src_0_for_int_j_0_j__ind_ndi), 0, 1, 0, 0},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_n_s_index, __pyx_k_index, sizeof(__pyx_k_index), 0, 0, 1, 1},
  {&__pyx_n_s_int32, __pyx_k_int32, sizeof(__pyx_k_int32), 0, 0, 1, 1},
  {&__pyx_n_s_int64, __pyx_k_int64, sizeof(__pyx_k_int64), 0, 0, 1, 1},
  {&__pyx_kp_u_invalid_entry_in_choice_array, __pyx_k_invalid_entry_in_choice_array, sizeof(__pyx_k_invalid_entry_in_choice_array), 0, 1, 0, 0},
  {&__pyx_kp_u_invalid_entry_in_indices_array, __pyx_k_invalid_entry_in_indices_array, sizeof(__pyx_k_invalid_entry_in_indices_array), 0, 1, 0, 0},
  {&__pyx_kp_u_is_out_of_bounds_for_axis, __pyx_k_is_out_of_bounds_for_axis, sizeof(__pyx_k_is_out_of_bounds_for_axis), 0, 1, 0, 0},
  {&__pyx_n_s_isscalar, __pyx_k_isscalar, sizeof(__pyx_k_isscalar), 0, 0, 1, 1},
  {&__pyx_n_s_itemsize, __pyx_k_itemsize, sizeof(__pyx_k_itemsize), 0, 0, 1, 1},
  {&__pyx_n_s_kind, __pyx_k_kind, sizeof(__pyx_k_kind), 0, 0, 1, 1},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_n_s_mask, __pyx_k_mask, sizeof(__pyx_k_mask), 0, 0, 1, 1},
  {&__pyx_n_u_max, __pyx_k_max, sizeof(__pyx_k_max), 0, 1, 0, 1},
  {&__pyx_n_s_maximum, __pyx_k_maximum, sizeof(__pyx_k_maximum), 0, 0, 1, 1},
  {&__pyx_n_u_min, __pyx_k_min, sizeof(__pyx_k_min), 0, 1, 0, 1},
  {&__pyx_n_s_minimum, __pyx_k_minimum, sizeof(__pyx_k_minimum), 0, 0, 1, 1},
  {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
  {&__pyx_n_s_nbytes, __pyx_k_nbytes, sizeof(__pyx_k_nbytes), 0, 0, 1, 1},
  {&__pyx_n_s_ndarray, __pyx_k_ndarray, sizeof(__pyx_k_ndarray), 0, 0, 1, 1},
  {&__pyx_n_s_ndim, __pyx_k_ndim, sizeof(__pyx_k_ndim), 0, 0, 1, 1},
  {&__pyx_n_s_nonzero_kernel, __pyx_k_nonzero_kernel, sizeof(__pyx_k_nonzero_kernel), 0, 0, 1, 1},
  {&__pyx_n_s_nonzero_kernel_1d, __pyx_k_nonzero_kernel_1d, sizeof(__pyx_k_nonzero_kernel_1d), 0, 0, 1, 1},
  {&__pyx_n_u_nonzero_kernel_1d_2, __pyx_k_nonzero_kernel_1d_2, sizeof(__pyx_k_nonzero_kernel_1d_2), 0, 1, 0, 1},
  {&__pyx_n_u_nonzero_kernel_2, __pyx_k_nonzero_kernel_2, sizeof(__pyx_k_nonzero_kernel_2), 0, 1, 0, 1},
  {&__pyx_n_s_not_equal, __pyx_k_not_equal, sizeof(__pyx_k_not_equal), 0, 0, 1, 1},
  {&__pyx_n_s_numpy, __pyx_k_numpy, sizeof(__pyx_k_numpy), 0, 0, 1, 1},
  {&__pyx_kp_u_only_integers_slices_ellipsis_nu, __pyx_k_only_integers_slices_ellipsis_nu, sizeof(__pyx_k_only_integers_slices_ellipsis_nu), 0, 1, 0, 0},
  {&__pyx_n_s_prepare_array_indexing, __pyx_k_prepare_array_indexing, sizeof(__pyx_k_prepare_array_indexing), 0, 0, 1, 1},
  {&__pyx_n_s_prod, __pyx_k_prod, sizeof(__pyx_k_prod), 0, 0, 1, 1},
  {&__pyx_kp_u_provided_op_is_not_supported, __pyx_k_provided_op_is_not_supported, sizeof(__pyx_k_provided_op_is_not_supported), 0, 1, 0, 0},
  {&__pyx_kp_u_ptrdiff_t_ind__ind_if_ind__0_in, __pyx_k_ptrdiff_t_ind__ind_if_ind__0_in, sizeof(__pyx_k_ptrdiff_t_ind__ind_if_ind__0_in), 0, 1, 0, 0},
  {&__pyx_kp_u_ptrdiff_t_ind__ind_if_n_ind__in, __pyx_k_ptrdiff_t_ind__ind_if_n_ind__in, sizeof(__pyx_k_ptrdiff_t_ind__ind_if_n_ind__in), 0, 1, 0, 0},
  {&__pyx_kp_u_ptrdiff_t_ind__ind_ind__n_if_in, __pyx_k_ptrdiff_t_ind__ind_ind__n_if_in, sizeof(__pyx_k_ptrdiff_t_ind__ind_ind__n_if_in), 0, 1, 0, 0},
  {&__pyx_kp_u_ptrdiff_t_out_i_indices_index_r, __pyx_k_ptrdiff_t_out_i_indices_index_r, sizeof(__pyx_k_ptrdiff_t_out_i_indices_index_r), 0, 1, 0, 0},
  {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1},
  {&__pyx_n_u_raise, __pyx_k_raise, sizeof(__pyx_k_raise), 0, 1, 0, 1},
  {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
  {&__pyx_n_s_ravel, __pyx_k_ravel, sizeof(__pyx_k_ravel), 0, 0, 1, 1},
  {&__pyx_kp_u_raw_S_dst, __pyx_k_raw_S_dst, sizeof(__pyx_k_raw_S_dst), 0, 1, 0, 0},
  {&__pyx_kp_u_raw_T_a, __pyx_k_raw_T_a, sizeof(__pyx_k_raw_T_a), 0, 1, 0, 0},
  {&__pyx_kp_u_raw_T_a_S_indices_uint32_ldim_ui, __pyx_k_raw_T_a_S_indices_uint32_ldim_ui, sizeof(__pyx_k_raw_T_a_S_indices_uint32_ldim_ui), 0, 1, 0, 0},
  {&__pyx_kp_u_raw_T_a_int64_indices_uint32_ldi, __pyx_k_raw_T_a_int64_indices_uint32_ldi, sizeof(__pyx_k_raw_T_a_int64_indices_uint32_ldi), 0, 1, 0, 0},
  {&__pyx_kp_u_raw_T_out, __pyx_k_raw_T_out, sizeof(__pyx_k_raw_T_out), 0, 1, 0, 0},
  {&__pyx_kp_u_raw_T_v_S_indices_int32_cdim_int, __pyx_k_raw_T_v_S_indices_int32_cdim_int, sizeof(__pyx_k_raw_T_v_S_indices_int32_cdim_int), 0, 1, 0, 0},
  {&__pyx_kp_u_raw_T_v_bool_mask_S_mask_scanned, __pyx_k_raw_T_v_bool_mask_S_mask_scanned, sizeof(__pyx_k_raw_T_v_bool_mask_S_mask_scanned), 0, 1, 0, 0},
  {&__pyx_kp_u_raw_U_data, __pyx_k_raw_U_data, sizeof(__pyx_k_raw_U_data), 0, 1, 0, 0},
  {&__pyx_kp_u_raw_U_data_raw_bool_err, __pyx_k_raw_U_data_raw_bool_err, sizeof(__pyx_k_raw_U_data_raw_bool_err), 0, 1, 0, 0},
  {&__pyx_n_s_reduce_dims, __pyx_k_reduce_dims, sizeof(__pyx_k_reduce_dims), 0, 0, 1, 1},
  {&__pyx_kp_u_requires_a_ndim_1, __pyx_k_requires_a_ndim_1, sizeof(__pyx_k_requires_a_ndim_1), 0, 1, 0, 0},
  {&__pyx_n_s_scatter_add_kernel, __pyx_k_scatter_add_kernel, sizeof(__pyx_k_scatter_add_kernel), 0, 0, 1, 1},
  {&__pyx_n_s_scatter_add_mask_kernel, __pyx_k_scatter_add_mask_kernel, sizeof(__pyx_k_scatter_add_mask_kernel), 0, 0, 1, 1},
  {&__pyx_kp_u_scatter_add_only_supports_int32, __pyx_k_scatter_add_only_supports_int32, sizeof(__pyx_k_scatter_add_only_supports_int32), 0, 1, 0, 0},
  {&__pyx_n_s_scatter_max_kernel, __pyx_k_scatter_max_kernel, sizeof(__pyx_k_scatter_max_kernel), 0, 0, 1, 1},
  {&__pyx_n_s_scatter_max_mask_kernel, __pyx_k_scatter_max_mask_kernel, sizeof(__pyx_k_scatter_max_mask_kernel), 0, 0, 1, 1},
  {&__pyx_kp_u_scatter_max_only_supports_int32, __pyx_k_scatter_max_only_supports_int32, sizeof(__pyx_k_scatter_max_only_supports_int32), 0, 1, 0, 0},
  {&__pyx_n_s_scatter_min_kernel, __pyx_k_scatter_min_kernel, sizeof(__pyx_k_scatter_min_kernel), 0, 0, 1, 1},
  {&__pyx_n_s_scatter_min_mask_kernel, __pyx_k_scatter_min_mask_kernel, sizeof(__pyx_k_scatter_min_mask_kernel), 0, 0, 1, 1},
  {&__pyx_kp_u_scatter_min_only_supports_int32, __pyx_k_scatter_min_only_supports_int32, sizeof(__pyx_k_scatter_min_only_supports_int32), 0, 1, 0, 0},
  {&__pyx_n_s_scatter_update_kernel, __pyx_k_scatter_update_kernel, sizeof(__pyx_k_scatter_update_kernel), 0, 0, 1, 1},
  {&__pyx_n_s_scatter_update_mask_kernel, __pyx_k_scatter_update_mask_kernel, sizeof(__pyx_k_scatter_update_mask_kernel), 0, 0, 1, 1},
  {&__pyx_n_s_shape, __pyx_k_shape, sizeof(__pyx_k_shape), 0, 0, 1, 1},
  {&__pyx_n_s_size, __pyx_k_size, sizeof(__pyx_k_size), 0, 0, 1, 1},
  {&__pyx_n_s_slices, __pyx_k_slices, sizeof(__pyx_k_slices), 0, 0, 1, 1},
  {&__pyx_n_s_strides, __pyx_k_strides, sizeof(__pyx_k_strides), 0, 0, 1, 1},
  {&__pyx_n_s_sum, __pyx_k_sum, sizeof(__pyx_k_sum), 0, 0, 1, 1},
  {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1},
  {&__pyx_n_s_take, __pyx_k_take, sizeof(__pyx_k_take), 0, 0, 1, 1},
  {&__pyx_n_s_take_kernel, __pyx_k_take_kernel, sizeof(__pyx_k_take_kernel), 0, 0, 1, 1},
  {&__pyx_n_s_take_kernel_core, __pyx_k_take_kernel_core, sizeof(__pyx_k_take_kernel_core), 0, 0, 1, 1},
  {&__pyx_n_s_take_kernel_scalar, __pyx_k_take_kernel_scalar, sizeof(__pyx_k_take_kernel_scalar), 0, 0, 1, 1},
  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  {&__pyx_kp_u_this_op_is_not_supported, __pyx_k_this_op_is_not_supported, sizeof(__pyx_k_this_op_is_not_supported), 0, 1, 0, 0},
  {&__pyx_kp_u_too_many_indices_for_array, __pyx_k_too_many_indices_for_array, sizeof(__pyx_k_too_many_indices_for_array), 0, 1, 0, 0},
  {&__pyx_n_s_type, __pyx_k_type, sizeof(__pyx_k_type), 0, 0, 1, 1},
  {&__pyx_n_u_u, __pyx_k_u, sizeof(__pyx_k_u), 0, 1, 0, 1},
  {&__pyx_n_s_uint32, __pyx_k_uint32, sizeof(__pyx_k_uint32), 0, 0, 1, 1},
  {&__pyx_n_s_uint64, __pyx_k_uint64, sizeof(__pyx_k_uint64), 0, 0, 1, 1},
  {&__pyx_n_s_ulonglong, __pyx_k_ulonglong, sizeof(__pyx_k_ulonglong), 0, 0, 1, 1},
  {&__pyx_n_u_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 1, 0, 1},
  {&__pyx_n_s_values, __pyx_k_values, sizeof(__pyx_k_values), 0, 0, 1, 1},
  {&__pyx_kp_u_with_size, __pyx_k_with_size, sizeof(__pyx_k_with_size), 0, 1, 0, 0},
  {&__pyx_n_u_wrap, __pyx_k_wrap, sizeof(__pyx_k_wrap), 0, 1, 0, 1},
  {&__pyx_kp_u_y_choices_i_n_channel_a, __pyx_k_y_choices_i_n_channel_a, sizeof(__pyx_k_y_choices_i_n_channel_a), 0, 1, 0, 0},
  {&__pyx_n_s_zeros, __pyx_k_zeros, sizeof(__pyx_k_zeros), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_sum = __Pyx_GetBuiltinName(__pyx_n_s_sum); if (!__pyx_builtin_sum) __PYX_ERR(0, 40, __pyx_L1_error)
  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 77, __pyx_L1_error)
  __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 101, __pyx_L1_error)
  __pyx_builtin_IndexError = __Pyx_GetBuiltinName(__pyx_n_s_IndexError); if (!__pyx_builtin_IndexError) __PYX_ERR(0, 117, __pyx_L1_error)
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 143, __pyx_L1_error)
  __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 187, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

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

  /* "cupy/core/_routines_indexing.pyx":66
 *     ndim = max(<int>self._shape.size(), 1)
 *     if count_nonzero == 0:
 *         return (ndarray((0,), dtype=dtype),) * ndim             # <<<<<<<<<<<<<<
 * 
 *     if ndim <= 1:
 */
  __pyx_tuple_ = PyTuple_Pack(1, __pyx_int_0); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 66, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);
  __pyx_tuple__2 = PyTuple_Pack(1, __pyx_tuple_); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 66, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__2);
  __Pyx_GIVEREF(__pyx_tuple__2);

  /* "cupy/core/_routines_indexing.pyx":101
 * cdef ndarray _ndarray_put(ndarray self, indices, values, mode):
 *     if mode not in ('raise', 'wrap', 'clip'):
 *         raise TypeError('clipmode not understood')             # <<<<<<<<<<<<<<
 * 
 *     n = self.size
 */
  __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_u_clipmode_not_understood); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 101, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__3);
  __Pyx_GIVEREF(__pyx_tuple__3);

  /* "cupy/core/_routines_indexing.pyx":114
 * 
 *     if mode == 'raise':
 *         err = cupy.zeros((), dtype=numpy.bool_)             # <<<<<<<<<<<<<<
 *         _put_raise_kernel(indices, values, values.size, n, self, err)
 *         if err:
 */
  __pyx_tuple__4 = PyTuple_Pack(1, __pyx_empty_tuple); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 114, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__4);
  __Pyx_GIVEREF(__pyx_tuple__4);

  /* "cupy/core/_routines_indexing.pyx":117
 *         _put_raise_kernel(indices, values, values.size, n, self, err)
 *         if err:
 *             raise IndexError('invalid entry in indices array')             # <<<<<<<<<<<<<<
 *     elif mode == 'wrap':
 *         _put_wrap_kernel(indices, values, values.size, n, self)
 */
  __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_u_invalid_entry_in_indices_array); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 117, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__5);
  __Pyx_GIVEREF(__pyx_tuple__5);

  /* "cupy/core/_routines_indexing.pyx":131
 *     if a.ndim < choices.ndim - 1:
 *         for i in range(choices.ndim - 1 - a.ndim):
 *             a = a[None, ...]             # <<<<<<<<<<<<<<
 *     elif a.ndim > choices.ndim - 1:
 *         for i in range(a.ndim + 1 - choices.ndim):
 */
  __pyx_tuple__6 = PyTuple_Pack(2, Py_None, Py_Ellipsis); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 131, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__6);
  __Pyx_GIVEREF(__pyx_tuple__6);

  /* "cupy/core/_routines_indexing.pyx":134
 *     elif a.ndim > choices.ndim - 1:
 *         for i in range(a.ndim + 1 - choices.ndim):
 *             choices = choices[:, None, ...]             # <<<<<<<<<<<<<<
 *     ba, bcs = _manipulation.broadcast(a, choices).values
 * 
 */
  __pyx_slice__7 = PySlice_New(Py_None, Py_None, Py_None); if (unlikely(!__pyx_slice__7)) __PYX_ERR(0, 134, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__7);
  __Pyx_GIVEREF(__pyx_slice__7);
  __pyx_tuple__8 = PyTuple_Pack(3, __pyx_slice__7, Py_None, Py_Ellipsis); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 134, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__8);
  __Pyx_GIVEREF(__pyx_tuple__8);

  /* "cupy/core/_routines_indexing.pyx":138
 * 
 *     if out is None:
 *         out = ndarray(ba.shape[1:], choices.dtype)             # <<<<<<<<<<<<<<
 * 
 *     n_channel = numpy.prod(bcs[0].shape)
 */
  __pyx_slice__9 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__9)) __PYX_ERR(0, 138, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__9);
  __Pyx_GIVEREF(__pyx_slice__9);

  /* "cupy/core/_routines_indexing.pyx":143
 *     if mode == 'raise':
 *         if not ((a < n).all() and (0 <= a).all()):
 *             raise ValueError('invalid entry in choice array')             # <<<<<<<<<<<<<<
 *         _choose_kernel(ba[0], bcs, n_channel, out)
 *     elif mode == 'wrap':
 */
  __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_u_invalid_entry_in_choice_array); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 143, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__10);
  __Pyx_GIVEREF(__pyx_tuple__10);

  /* "cupy/core/_routines_indexing.pyx":213
 * 
 *     if not mask_exists and len(slice_list) > ndim + n_newaxes:
 *         raise IndexError('too many indices for array')             # <<<<<<<<<<<<<<
 *     return slice_list, advanced, mask_exists
 * 
 */
  __pyx_tuple__11 = PyTuple_Pack(1, __pyx_kp_u_too_many_indices_for_array); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 213, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__11);
  __Pyx_GIVEREF(__pyx_tuple__11);

  /* "cupy/core/_routines_indexing.pyx":228
 *                 mask_i = i
 *     if n_not_slice_none != 1 or mask_i == -1:
 *         raise ValueError('currently, CuPy only supports slices that '             # <<<<<<<<<<<<<<
 *                          'consist of one boolean array.')
 *     return mask_i
 */
  __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_u_currently_CuPy_only_supports_sli); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 228, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);

  /* "cupy/core/_routines_indexing.pyx":265
 *             adv_mask.append(True)
 *         else:
 *             raise IndexError(             # <<<<<<<<<<<<<<
 *                 'only integers, slices (`:`), ellipsis (`...`),'
 *                 'numpy.newaxis (`None`) and integer or '
 */
  __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_u_only_integers_slices_ellipsis_nu); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 265, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__13);
  __Pyx_GIVEREF(__pyx_tuple__13);

  /* "cupy/core/_routines_indexing.pyx":544
 *     for i, s in enumerate(mask._shape):
 *         if a.shape[axis + i] != s:
 *             raise IndexError('boolean index did not match')             # <<<<<<<<<<<<<<
 * 
 *     # Get number of True in the mask to determine the shape of the array
 */
  __pyx_tuple__14 = PyTuple_Pack(1, __pyx_kp_u_boolean_index_did_not_match); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 544, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__14);
  __Pyx_GIVEREF(__pyx_tuple__14);

  /* "cupy/core/_routines_indexing.pyx":567
 *     mask = _manipulation._reshape(
 *         mask,
 *         axis * (1,) + mask.shape + (a.ndim - axis - mask.ndim) * (1,))             # <<<<<<<<<<<<<<
 *     if <Py_ssize_t>mask._shape.size() > a._shape.size():
 *         raise IndexError('too many indices for array')
 */
  __pyx_tuple__15 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__15);
  __Pyx_GIVEREF(__pyx_tuple__15);

  /* "cupy/core/_routines_indexing.pyx":643
 *     else:
 *         if out.dtype != a.dtype:
 *             raise TypeError('Output dtype mismatch')             # <<<<<<<<<<<<<<
 *         if out.shape != out_shape:
 *             raise ValueError('Output shape mismatch')
 */
  __pyx_tuple__16 = PyTuple_Pack(1, __pyx_kp_u_Output_dtype_mismatch); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 643, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__16);
  __Pyx_GIVEREF(__pyx_tuple__16);

  /* "cupy/core/_routines_indexing.pyx":645
 *             raise TypeError('Output dtype mismatch')
 *         if out.shape != out_shape:
 *             raise ValueError('Output shape mismatch')             # <<<<<<<<<<<<<<
 *     if a.size == 0 and out.size != 0:
 *         raise IndexError('cannot do a non-empty take from an empty axes.')
 */
  __pyx_tuple__17 = PyTuple_Pack(1, __pyx_kp_u_Output_shape_mismatch); if (unlikely(!__pyx_tuple__17)) __PYX_ERR(0, 645, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__17);
  __Pyx_GIVEREF(__pyx_tuple__17);

  /* "cupy/core/_routines_indexing.pyx":647
 *             raise ValueError('Output shape mismatch')
 *     if a.size == 0 and out.size != 0:
 *         raise IndexError('cannot do a non-empty take from an empty axes.')             # <<<<<<<<<<<<<<
 * 
 *     if isinstance(indices, ndarray):
 */
  __pyx_tuple__18 = PyTuple_Pack(1, __pyx_kp_u_cannot_do_a_non_empty_take_from); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 647, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__18);
  __Pyx_GIVEREF(__pyx_tuple__18);

  /* "cupy/core/_routines_indexing.pyx":676
 * 
 *     if ndim == 0:
 *         raise ValueError('requires a.ndim >= 1')             # <<<<<<<<<<<<<<
 *     if not (-ndim <= li < ndim and -ndim <= ri < ndim):
 *         raise ValueError('Axis overrun')
 */
  __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_u_requires_a_ndim_1); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 676, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__20);
  __Pyx_GIVEREF(__pyx_tuple__20);

  /* "cupy/core/_routines_indexing.pyx":678
 *         raise ValueError('requires a.ndim >= 1')
 *     if not (-ndim <= li < ndim and -ndim <= ri < ndim):
 *         raise ValueError('Axis overrun')             # <<<<<<<<<<<<<<
 * 
 *     if not isinstance(v, ndarray):
 */
  __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_u_Axis_overrun); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__21);
  __Pyx_GIVEREF(__pyx_tuple__21);

  /* "cupy/core/_routines_indexing.pyx":714
 *                            numpy.float64, numpy.uint32, numpy.uint64,
 *                            numpy.ulonglong)):
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 'scatter_add only supports int32, float16, float32, float64, '
 *                 'uint32, uint64, as data type')
 */
  __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_u_scatter_add_only_supports_int32); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 714, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__22);
  __Pyx_GIVEREF(__pyx_tuple__22);

  /* "cupy/core/_routines_indexing.pyx":723
 *                           (numpy.int32, numpy.float32, numpy.float64,
 *                            numpy.uint32, numpy.uint64, numpy.ulonglong)):
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 'scatter_max only supports int32, float32, float64, '
 *                 'uint32, uint64 as data type')
 */
  __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_u_scatter_max_only_supports_int32); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 723, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__23);
  __Pyx_GIVEREF(__pyx_tuple__23);

  /* "cupy/core/_routines_indexing.pyx":732
 *                           (numpy.int32, numpy.float32, numpy.float64,
 *                            numpy.uint32, numpy.uint64, numpy.ulonglong)):
 *             raise TypeError(             # <<<<<<<<<<<<<<
 *                 'scatter_min only supports int32, float32, float64, '
 *                 'uint32, uint64 as data type')
 */
  __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_u_scatter_min_only_supports_int32); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 732, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__24);
  __Pyx_GIVEREF(__pyx_tuple__24);

  /* "cupy/core/_routines_indexing.pyx":738
 *             v, indices, cdim, rdim, adim, a.reduced_view())
 *     else:
 *         raise ValueError('provided op is not supported')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__25 = PyTuple_Pack(1, __pyx_kp_u_provided_op_is_not_supported); if (unlikely(!__pyx_tuple__25)) __PYX_ERR(0, 738, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__25);
  __Pyx_GIVEREF(__pyx_tuple__25);

  /* "cupy/core/_routines_indexing.pyx":822
 *         cupy.minimum(y, value, y)
 *         return
 *     raise ValueError('this op is not supported')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_u_this_op_is_not_supported); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 822, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__26);
  __Pyx_GIVEREF(__pyx_tuple__26);

  /* "cupy/core/_routines_indexing.pyx":851
 * 
 *     diag_size = max(0, min(a.shape[-2], a.shape[-1] - offset))
 *     ret_shape = a.shape[:-2] + (diag_size,)             # <<<<<<<<<<<<<<
 *     if diag_size == 0:
 *         return ndarray(ret_shape, dtype=a.dtype)
 */
  __pyx_slice__27 = PySlice_New(Py_None, __pyx_int_neg_2, Py_None); if (unlikely(!__pyx_slice__27)) __PYX_ERR(0, 851, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__27);
  __Pyx_GIVEREF(__pyx_slice__27);

  /* "cupy/core/_routines_indexing.pyx":338
 * 
 * 
 * _nonzero_kernel_1d = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'T src, S index', 'raw S dst',
 *     'if (src != 0) dst[index - 1] = i',
 */
  __pyx_tuple__28 = PyTuple_Pack(4, __pyx_kp_u_T_src_S_index, __pyx_kp_u_raw_S_dst, __pyx_kp_u_if_src_0_dst_index_1_i, __pyx_n_u_nonzero_kernel_1d_2); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 338, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__28);
  __Pyx_GIVEREF(__pyx_tuple__28);

  /* "cupy/core/_routines_indexing.pyx":344
 * 
 * 
 * _nonzero_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'T src, S index', 'raw S dst',
 *     '''
 */
  __pyx_tuple__29 = PyTuple_Pack(4, __pyx_kp_u_T_src_S_index, __pyx_kp_u_raw_S_dst, __pyx_kp_u_if_src_0_for_int_j_0_j__ind_ndi, __pyx_n_u_nonzero_kernel_2); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 344, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__29);
  __Pyx_GIVEREF(__pyx_tuple__29);

  /* "cupy/core/_routines_indexing.pyx":378
 * 
 * 
 * _choose_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'S a, raw T choices, int32 n_channel',
 *     'T y',
 */
  __pyx_tuple__30 = PyTuple_Pack(4, __pyx_kp_u_S_a_raw_T_choices_int32_n_channe, __pyx_kp_u_T_y, __pyx_kp_u_y_choices_i_n_channel_a, __pyx_n_u_cupy_choose); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 378, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__30);
  __Pyx_GIVEREF(__pyx_tuple__30);

  /* "cupy/core/_routines_indexing.pyx":385
 * 
 * 
 * _choose_clip_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'S a, raw T choices, int32 n_channel, int32 n',
 *     'T y',
 */
  __pyx_tuple__31 = PyTuple_Pack(4, __pyx_kp_u_S_a_raw_T_choices_int32_n_channe_2, __pyx_kp_u_T_y, __pyx_kp_u_S_x_a_if_a_0_x_0_else_if_a_n_x, __pyx_n_u_cupy_choose_clip); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 385, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__31);
  __Pyx_GIVEREF(__pyx_tuple__31);

  /* "cupy/core/_routines_indexing.pyx":400
 * 
 * 
 * cdef _put_raise_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'S ind, raw T vals, int64 n_vals, int64 n',
 *     'raw U data, raw bool err',
 */
  __pyx_tuple__32 = PyTuple_Pack(4, __pyx_kp_u_S_ind_raw_T_vals_int64_n_vals_in, __pyx_kp_u_raw_U_data_raw_bool_err, __pyx_kp_u_ptrdiff_t_ind__ind_if_n_ind__in, __pyx_n_u_cupy_put_raise); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 400, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__32);
  __Pyx_GIVEREF(__pyx_tuple__32);

  /* "cupy/core/_routines_indexing.pyx":415
 * 
 * 
 * cdef _put_wrap_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'S ind, raw T vals, int64 n_vals, int64 n',
 *     'raw U data',
 */
  __pyx_tuple__33 = PyTuple_Pack(4, __pyx_kp_u_S_ind_raw_T_vals_int64_n_vals_in, __pyx_kp_u_raw_U_data, __pyx_kp_u_ptrdiff_t_ind__ind_ind__n_if_in, __pyx_n_u_cupy_put_wrap); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 415, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__33);
  __Pyx_GIVEREF(__pyx_tuple__33);

  /* "cupy/core/_routines_indexing.pyx":427
 * 
 * 
 * cdef _put_clip_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'S ind, raw T vals, int64 n_vals, int64 n',
 *     'raw U data',
 */
  __pyx_tuple__34 = PyTuple_Pack(4, __pyx_kp_u_S_ind_raw_T_vals_int64_n_vals_in, __pyx_kp_u_raw_U_data, __pyx_kp_u_ptrdiff_t_ind__ind_if_ind__0_in, __pyx_n_u_cupy_put_clip); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 427, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__34);
  __Pyx_GIVEREF(__pyx_tuple__34);

  /* "cupy/core/_routines_indexing.pyx":442
 * 
 * 
 * _scatter_update_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'T v, S indices, int32 cdim, int32 rdim, int32 adim',
 *     'raw T a',
 */
  __pyx_tuple__35 = PyTuple_Pack(4, __pyx_kp_u_T_v_S_indices_int32_cdim_int32_r, __pyx_kp_u_raw_T_a, __pyx_kp_u_S_wrap_indices_indices_adim_if, __pyx_n_u_cupy_scatter_update); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 442, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__35);
  __Pyx_GIVEREF(__pyx_tuple__35);

  /* "cupy/core/_routines_indexing.pyx":455
 * 
 * 
 * _scatter_add_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'raw T v, S indices, int32 cdim, int32 rdim, int32 adim',
 *     'raw T a',
 */
  __pyx_tuple__36 = PyTuple_Pack(4, __pyx_kp_u_raw_T_v_S_indices_int32_cdim_int, __pyx_kp_u_raw_T_a, __pyx_kp_u_S_wrap_indices_indices_adim_if_2, __pyx_n_u_cupy_scatter_add); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 455, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__36);
  __Pyx_GIVEREF(__pyx_tuple__36);

  /* "cupy/core/_routines_indexing.pyx":468
 * 
 * 
 * _scatter_max_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'raw T v, S indices, int32 cdim, int32 rdim, int32 adim',
 *     'raw T a',
 */
  __pyx_tuple__37 = PyTuple_Pack(4, __pyx_kp_u_raw_T_v_S_indices_int32_cdim_int, __pyx_kp_u_raw_T_a, __pyx_kp_u_S_wrap_indices_indices_adim_if_3, __pyx_n_u_cupy_scatter_max); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 468, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__37);
  __Pyx_GIVEREF(__pyx_tuple__37);

  /* "cupy/core/_routines_indexing.pyx":481
 * 
 * 
 * _scatter_min_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'raw T v, S indices, int32 cdim, int32 rdim, int32 adim',
 *     'raw T a',
 */
  __pyx_tuple__38 = PyTuple_Pack(4, __pyx_kp_u_raw_T_v_S_indices_int32_cdim_int, __pyx_kp_u_raw_T_a, __pyx_kp_u_S_wrap_indices_indices_adim_if_4, __pyx_n_u_cupy_scatter_min); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(0, 481, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__38);
  __Pyx_GIVEREF(__pyx_tuple__38);

  /* "cupy/core/_routines_indexing.pyx":494
 * 
 * 
 * _scatter_update_mask_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'raw T v, bool mask, S mask_scanned',
 *     'T a',
 */
  __pyx_tuple__39 = PyTuple_Pack(4, __pyx_kp_u_raw_T_v_bool_mask_S_mask_scanned, __pyx_kp_u_T_a, __pyx_kp_u_if_mask_a_v_mask_scanned_1, __pyx_n_u_cupy_scatter_update_mask); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(0, 494, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__39);
  __Pyx_GIVEREF(__pyx_tuple__39);

  /* "cupy/core/_routines_indexing.pyx":501
 * 
 * 
 * _scatter_add_mask_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'raw T v, bool mask, S mask_scanned',
 *     'T a',
 */
  __pyx_tuple__40 = PyTuple_Pack(4, __pyx_kp_u_raw_T_v_bool_mask_S_mask_scanned, __pyx_kp_u_T_a, __pyx_kp_u_if_mask_a_a_v_mask_scanned_1, __pyx_n_u_cupy_scatter_add_mask); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(0, 501, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__40);
  __Pyx_GIVEREF(__pyx_tuple__40);

  /* "cupy/core/_routines_indexing.pyx":508
 * 
 * 
 * _scatter_max_mask_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'raw T v, bool mask, S mask_scanned',
 *     'T a',
 */
  __pyx_tuple__41 = PyTuple_Pack(4, __pyx_kp_u_raw_T_v_bool_mask_S_mask_scanned, __pyx_kp_u_T_a, __pyx_kp_u_if_mask_a_max_a_v_mask_scanned_1, __pyx_n_u_cupy_scatter_max_mask); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(0, 508, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__41);
  __Pyx_GIVEREF(__pyx_tuple__41);

  /* "cupy/core/_routines_indexing.pyx":515
 * 
 * 
 * _scatter_min_mask_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'raw T v, bool mask, S mask_scanned',
 *     'T a',
 */
  __pyx_tuple__42 = PyTuple_Pack(4, __pyx_kp_u_raw_T_v_bool_mask_S_mask_scanned, __pyx_kp_u_T_a, __pyx_kp_u_if_mask_a_min_a_v_mask_scanned_1, __pyx_n_u_cupy_scatter_min_mask); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(0, 515, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__42);
  __Pyx_GIVEREF(__pyx_tuple__42);

  /* "cupy/core/_routines_indexing.pyx":522
 * 
 * 
 * _getitem_mask_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'T a, bool mask, S mask_scanned',
 *     'raw T out',
 */
  __pyx_tuple__43 = PyTuple_Pack(4, __pyx_kp_u_T_a_bool_mask_S_mask_scanned, __pyx_kp_u_raw_T_out, __pyx_kp_u_if_mask_out_mask_scanned_1_a, __pyx_n_u_cupy_getitem_mask); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(0, 522, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__43);
  __Pyx_GIVEREF(__pyx_tuple__43);

  /* "cupy/core/_routines_indexing.pyx":866
 * 
 * 
 * _prepare_array_indexing = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'T s, S len, S stride',
 *     'S out',
 */
  __pyx_tuple__44 = PyTuple_Pack(4, __pyx_kp_u_T_s_S_len_S_stride, __pyx_kp_u_S_out, __pyx_kp_u_S_in0_s_in1_len_out_stride_in0, __pyx_n_u_cupy_prepare_array_indexing); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(0, 866, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__44);
  __Pyx_GIVEREF(__pyx_tuple__44);
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) {
  __pyx_umethod_PyList_Type_index.type = (PyObject*)&PyList_Type;
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_2147483647 = PyInt_FromLong(2147483647L); if (unlikely(!__pyx_int_2147483647)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_neg_2 = PyInt_FromLong(-2); if (unlikely(!__pyx_int_neg_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/
static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/

static int __Pyx_modinit_global_init_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0);
  /*--- Global init code ---*/
  __pyx_v_4cupy_4core_18_routines_indexing__put_raise_kernel = Py_None; Py_INCREF(Py_None);
  __pyx_v_4cupy_4core_18_routines_indexing__put_wrap_kernel = Py_None; Py_INCREF(Py_None);
  __pyx_v_4cupy_4core_18_routines_indexing__put_clip_kernel = Py_None; Py_INCREF(Py_None);
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_variable_export_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0);
  /*--- Variable export code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_function_export_code(void) {
  __Pyx_RefNannyDeclarations
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0);
  /*--- Function export code ---*/
  if (__Pyx_ExportFunction("_ndarray_getitem", (void (*)(void))__pyx_f_4cupy_4core_18_routines_indexing__ndarray_getitem, "struct __pyx_obj_4cupy_4core_4core_ndarray *(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("_ndarray_setitem", (void (*)(void))__pyx_f_4cupy_4core_18_routines_indexing__ndarray_setitem, "PyObject *(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("_ndarray_nonzero", (void (*)(void))__pyx_f_4cupy_4core_18_routines_indexing__ndarray_nonzero, "PyObject *(struct __pyx_obj_4cupy_4core_4core_ndarray *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("_ndarray_scatter_add", (void (*)(void))__pyx_f_4cupy_4core_18_routines_indexing__ndarray_scatter_add, "PyObject *(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("_ndarray_scatter_max", (void (*)(void))__pyx_f_4cupy_4core_18_routines_indexing__ndarray_scatter_max, "PyObject *(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("_ndarray_scatter_min", (void (*)(void))__pyx_f_4cupy_4core_18_routines_indexing__ndarray_scatter_min, "PyObject *(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("_ndarray_take", (void (*)(void))__pyx_f_4cupy_4core_18_routines_indexing__ndarray_take, "struct __pyx_obj_4cupy_4core_4core_ndarray *(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, PyObject *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("_ndarray_put", (void (*)(void))__pyx_f_4cupy_4core_18_routines_indexing__ndarray_put, "struct __pyx_obj_4cupy_4core_4core_ndarray *(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, PyObject *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("_ndarray_choose", (void (*)(void))__pyx_f_4cupy_4core_18_routines_indexing__ndarray_choose, "struct __pyx_obj_4cupy_4core_4core_ndarray *(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, PyObject *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("_ndarray_diagonal", (void (*)(void))__pyx_f_4cupy_4core_18_routines_indexing__ndarray_diagonal, "struct __pyx_obj_4cupy_4core_4core_ndarray *(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, PyObject *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ExportFunction("_simple_getitem", (void (*)(void))__pyx_f_4cupy_4core_18_routines_indexing__simple_getitem, "struct __pyx_obj_4cupy_4core_4core_ndarray *(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_type_init_code(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
  /*--- Type init code ---*/
  __Pyx_RefNannyFinishContext();
  return 0;
}

static int __Pyx_modinit_type_import_code(void) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0);
  /*--- Type import code ---*/
  __pyx_t_1 = PyImport_ImportModule("cupy.cuda.device"); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_4cupy_4cuda_6device_Handle = __Pyx_ImportType(__pyx_t_1, "cupy.cuda.device", "Handle", sizeof(struct __pyx_obj_4cupy_4cuda_6device_Handle), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_4cupy_4cuda_6device_Handle) __PYX_ERR(2, 7, __pyx_L1_error)
  __pyx_ptype_4cupy_4cuda_6device_Device = __Pyx_ImportType(__pyx_t_1, "cupy.cuda.device", "Device", sizeof(struct __pyx_obj_4cupy_4cuda_6device_Device), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_4cupy_4cuda_6device_Device) __PYX_ERR(2, 12, __pyx_L1_error)
  __pyx_vtabptr_4cupy_4cuda_6device_Device = (struct __pyx_vtabstruct_4cupy_4cuda_6device_Device*)__Pyx_GetVtable(__pyx_ptype_4cupy_4cuda_6device_Device->tp_dict); if (unlikely(!__pyx_vtabptr_4cupy_4cuda_6device_Device)) __PYX_ERR(2, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule("cupy.cuda.memory"); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 11, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_4cupy_4cuda_6memory_BaseMemory = __Pyx_ImportType(__pyx_t_1, "cupy.cuda.memory", "BaseMemory", sizeof(struct __pyx_obj_4cupy_4cuda_6memory_BaseMemory), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_4cupy_4cuda_6memory_BaseMemory) __PYX_ERR(3, 11, __pyx_L1_error)
  __pyx_ptype_4cupy_4cuda_6memory_MemoryPointer = __Pyx_ImportType(__pyx_t_1, "cupy.cuda.memory", "MemoryPointer", sizeof(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPointer), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_4cupy_4cuda_6memory_MemoryPointer) __PYX_ERR(3, 20, __pyx_L1_error)
  __pyx_vtabptr_4cupy_4cuda_6memory_MemoryPointer = (struct __pyx_vtabstruct_4cupy_4cuda_6memory_MemoryPointer*)__Pyx_GetVtable(__pyx_ptype_4cupy_4cuda_6memory_MemoryPointer->tp_dict); if (unlikely(!__pyx_vtabptr_4cupy_4cuda_6memory_MemoryPointer)) __PYX_ERR(3, 20, __pyx_L1_error)
  __pyx_ptype_4cupy_4cuda_6memory_MemoryPool = __Pyx_ImportType(__pyx_t_1, "cupy.cuda.memory", "MemoryPool", sizeof(struct __pyx_obj_4cupy_4cuda_6memory_MemoryPool), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_4cupy_4cuda_6memory_MemoryPool) __PYX_ERR(3, 49, __pyx_L1_error)
  __pyx_vtabptr_4cupy_4cuda_6memory_MemoryPool = (struct __pyx_vtabstruct_4cupy_4cuda_6memory_MemoryPool*)__Pyx_GetVtable(__pyx_ptype_4cupy_4cuda_6memory_MemoryPool->tp_dict); if (unlikely(!__pyx_vtabptr_4cupy_4cuda_6memory_MemoryPool)) __PYX_ERR(3, 49, __pyx_L1_error)
  __pyx_ptype_4cupy_4cuda_6memory_CFunctionAllocatorMemory = __Pyx_ImportType(__pyx_t_1, "cupy.cuda.memory", "CFunctionAllocatorMemory", sizeof(struct __pyx_obj_4cupy_4cuda_6memory_CFunctionAllocatorMemory), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_4cupy_4cuda_6memory_CFunctionAllocatorMemory) __PYX_ERR(3, 66, __pyx_L1_error)
  __pyx_ptype_4cupy_4cuda_6memory_CFunctionAllocator = __Pyx_ImportType(__pyx_t_1, "cupy.cuda.memory", "CFunctionAllocator", sizeof(struct __pyx_obj_4cupy_4cuda_6memory_CFunctionAllocator), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_4cupy_4cuda_6memory_CFunctionAllocator) __PYX_ERR(3, 73, __pyx_L1_error)
  __pyx_vtabptr_4cupy_4cuda_6memory_CFunctionAllocator = (struct __pyx_vtabstruct_4cupy_4cuda_6memory_CFunctionAllocator*)__Pyx_GetVtable(__pyx_ptype_4cupy_4cuda_6memory_CFunctionAllocator->tp_dict); if (unlikely(!__pyx_vtabptr_4cupy_4cuda_6memory_CFunctionAllocator)) __PYX_ERR(3, 73, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule("cupy.cuda.function"); if (unlikely(!__pyx_t_1)) __PYX_ERR(4, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_4cupy_4cuda_8function_CPointer = __Pyx_ImportType(__pyx_t_1, "cupy.cuda.function", "CPointer", sizeof(struct __pyx_obj_4cupy_4cuda_8function_CPointer), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_4cupy_4cuda_8function_CPointer) __PYX_ERR(4, 4, __pyx_L1_error)
  __pyx_ptype_4cupy_4cuda_8function_Function = __Pyx_ImportType(__pyx_t_1, "cupy.cuda.function", "Function", sizeof(struct __pyx_obj_4cupy_4cuda_8function_Function), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_4cupy_4cuda_8function_Function) __PYX_ERR(4, 8, __pyx_L1_error)
  __pyx_vtabptr_4cupy_4cuda_8function_Function = (struct __pyx_vtabstruct_4cupy_4cuda_8function_Function*)__Pyx_GetVtable(__pyx_ptype_4cupy_4cuda_8function_Function->tp_dict); if (unlikely(!__pyx_vtabptr_4cupy_4cuda_8function_Function)) __PYX_ERR(4, 8, __pyx_L1_error)
  __pyx_ptype_4cupy_4cuda_8function_Module = __Pyx_ImportType(__pyx_t_1, "cupy.cuda.function", "Module", sizeof(struct __pyx_obj_4cupy_4cuda_8function_Module), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_4cupy_4cuda_8function_Module) __PYX_ERR(4, 18, __pyx_L1_error)
  __pyx_vtabptr_4cupy_4cuda_8function_Module = (struct __pyx_vtabstruct_4cupy_4cuda_8function_Module*)__Pyx_GetVtable(__pyx_ptype_4cupy_4cuda_8function_Module->tp_dict); if (unlikely(!__pyx_vtabptr_4cupy_4cuda_8function_Module)) __PYX_ERR(4, 18, __pyx_L1_error)
  __pyx_ptype_4cupy_4cuda_8function_LinkState = __Pyx_ImportType(__pyx_t_1, "cupy.cuda.function", "LinkState", sizeof(struct __pyx_obj_4cupy_4cuda_8function_LinkState), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_4cupy_4cuda_8function_LinkState) __PYX_ERR(4, 30, __pyx_L1_error)
  __pyx_vtabptr_4cupy_4cuda_8function_LinkState = (struct __pyx_vtabstruct_4cupy_4cuda_8function_LinkState*)__Pyx_GetVtable(__pyx_ptype_4cupy_4cuda_8function_LinkState->tp_dict); if (unlikely(!__pyx_vtabptr_4cupy_4cuda_8function_LinkState)) __PYX_ERR(4, 30, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule("cupy.core.core"); if (unlikely(!__pyx_t_1)) __PYX_ERR(5, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_4cupy_4core_4core_ndarray = __Pyx_ImportType(__pyx_t_1, "cupy.core.core", "ndarray", sizeof(struct __pyx_obj_4cupy_4core_4core_ndarray), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_4cupy_4core_4core_ndarray) __PYX_ERR(5, 7, __pyx_L1_error)
  __pyx_vtabptr_4cupy_4core_4core_ndarray = (struct __pyx_vtabstruct_4cupy_4core_4core_ndarray*)__Pyx_GetVtable(__pyx_ptype_4cupy_4core_4core_ndarray->tp_dict); if (unlikely(!__pyx_vtabptr_4cupy_4core_4core_ndarray)) __PYX_ERR(5, 7, __pyx_L1_error)
  __pyx_ptype_4cupy_4core_4core_Indexer = __Pyx_ImportType(__pyx_t_1, "cupy.core.core", "Indexer", sizeof(struct __pyx_obj_4cupy_4core_4core_Indexer), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_4cupy_4core_4core_Indexer) __PYX_ERR(5, 90, __pyx_L1_error)
  __pyx_vtabptr_4cupy_4core_4core_Indexer = (struct __pyx_vtabstruct_4cupy_4core_4core_Indexer*)__Pyx_GetVtable(__pyx_ptype_4cupy_4core_4core_Indexer->tp_dict); if (unlikely(!__pyx_vtabptr_4cupy_4core_4core_Indexer)) __PYX_ERR(5, 90, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule("cupy.core._routines_manipulation"); if (unlikely(!__pyx_t_1)) __PYX_ERR(6, 6, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_ptype_4cupy_4core_22_routines_manipulation_broadcast = __Pyx_ImportType(__pyx_t_1, "cupy.core._routines_manipulation", "broadcast", sizeof(struct __pyx_obj_4cupy_4core_22_routines_manipulation_broadcast), __Pyx_ImportType_CheckSize_Warn);
   if (!__pyx_ptype_4cupy_4core_22_routines_manipulation_broadcast) __PYX_ERR(6, 6, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_variable_import_code(void) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0);
  /*--- Variable import code ---*/
  __pyx_t_1 = PyImport_ImportModule("cupy.core._routines_math"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "_sum_auto_dtype", (void **)&__pyx_vp_4cupy_4core_14_routines_math__sum_auto_dtype, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "_add", (void **)&__pyx_vp_4cupy_4core_14_routines_math__add, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "_conj", (void **)&__pyx_vp_4cupy_4core_14_routines_math__conj, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "_angle", (void **)&__pyx_vp_4cupy_4core_14_routines_math__angle, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "_real", (void **)&__pyx_vp_4cupy_4core_14_routines_math__real, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "_imag", (void **)&__pyx_vp_4cupy_4core_14_routines_math__imag, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "_negative", (void **)&__pyx_vp_4cupy_4core_14_routines_math__negative, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "_multiply", (void **)&__pyx_vp_4cupy_4core_14_routines_math__multiply, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "_divide", (void **)&__pyx_vp_4cupy_4core_14_routines_math__divide, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "_power", (void **)&__pyx_vp_4cupy_4core_14_routines_math__power, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "_subtract", (void **)&__pyx_vp_4cupy_4core_14_routines_math__subtract, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "_true_divide", (void **)&__pyx_vp_4cupy_4core_14_routines_math__true_divide, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "_floor_divide", (void **)&__pyx_vp_4cupy_4core_14_routines_math__floor_divide, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "_remainder", (void **)&__pyx_vp_4cupy_4core_14_routines_math__remainder, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "_absolute", (void **)&__pyx_vp_4cupy_4core_14_routines_math__absolute, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "_sqrt", (void **)&__pyx_vp_4cupy_4core_14_routines_math__sqrt, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_modinit_function_import_code(void) {
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0);
  /*--- Function import code ---*/
  __pyx_t_1 = PyImport_ImportModule("cupy.core.core"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_ImportFunction(__pyx_t_1, "array", (void (**)(void))&__pyx_f_4cupy_4core_4core_array, "struct __pyx_obj_4cupy_4core_4core_ndarray *(PyObject *, int __pyx_skip_dispatch, struct __pyx_opt_args_4cupy_4core_4core_array *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule("cupy.core._routines_math"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_ImportFunction(__pyx_t_1, "scan", (void (**)(void))&__pyx_f_4cupy_4core_14_routines_math_scan, "struct __pyx_obj_4cupy_4core_4core_ndarray *(struct __pyx_obj_4cupy_4core_4core_ndarray *, struct __pyx_opt_args_4cupy_4core_14_routines_math_scan *__pyx_optional_args)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule("cupy.core._routines_manipulation"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_ImportFunction(__pyx_t_1, "broadcast_to", (void (**)(void))&__pyx_f_4cupy_4core_22_routines_manipulation_broadcast_to, "struct __pyx_obj_4cupy_4core_4core_ndarray *(struct __pyx_obj_4cupy_4core_4core_ndarray *, PyObject *, int __pyx_skip_dispatch)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction(__pyx_t_1, "_reshape", (void (**)(void))&__pyx_f_4cupy_4core_22_routines_manipulation__reshape, "struct __pyx_obj_4cupy_4core_4core_ndarray *(struct __pyx_obj_4cupy_4core_4core_ndarray *, std::vector<Py_ssize_t>  const &, int __pyx_skip_dispatch)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction(__pyx_t_1, "_transpose", (void (**)(void))&__pyx_f_4cupy_4core_22_routines_manipulation__transpose, "struct __pyx_obj_4cupy_4core_4core_ndarray *(struct __pyx_obj_4cupy_4core_4core_ndarray *, std::vector<Py_ssize_t>  const &, int __pyx_skip_dispatch)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyImport_ImportModule("cupy.core.internal"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_ImportFunction(__pyx_t_1, "prod", (void (**)(void))&__pyx_f_4cupy_4core_8internal_prod, "Py_ssize_t (std::vector<Py_ssize_t>  const &, int __pyx_skip_dispatch)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction(__pyx_t_1, "prod_sequence", (void (**)(void))&__pyx_f_4cupy_4core_8internal_prod_sequence, "Py_ssize_t (PyObject *, int __pyx_skip_dispatch)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction(__pyx_t_1, "vector_equal", (void (**)(void))&__pyx_f_4cupy_4core_8internal_vector_equal, "int (std::vector<Py_ssize_t>  const &, std::vector<Py_ssize_t>  const &, int __pyx_skip_dispatch)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction(__pyx_t_1, "complete_slice", (void (**)(void))&__pyx_f_4cupy_4core_8internal_complete_slice, "PyObject *(PyObject *, Py_ssize_t, int __pyx_skip_dispatch)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction(__pyx_t_1, "complete_slice_list", (void (**)(void))&__pyx_f_4cupy_4core_8internal_complete_slice_list, "PyObject *(PyObject *, Py_ssize_t, int __pyx_skip_dispatch)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_RefNannyFinishContext();
  return -1;
}


#ifndef CYTHON_NO_PYINIT_EXPORT
#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC
#elif PY_MAJOR_VERSION < 3
#ifdef __cplusplus
#define __Pyx_PyMODINIT_FUNC extern "C" void
#else
#define __Pyx_PyMODINIT_FUNC void
#endif
#else
#ifdef __cplusplus
#define __Pyx_PyMODINIT_FUNC extern "C" PyObject *
#else
#define __Pyx_PyMODINIT_FUNC PyObject *
#endif
#endif


#if PY_MAJOR_VERSION < 3
__Pyx_PyMODINIT_FUNC init_routines_indexing(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC init_routines_indexing(void)
#else
__Pyx_PyMODINIT_FUNC PyInit__routines_indexing(void) CYTHON_SMALL_CODE; /*proto*/
__Pyx_PyMODINIT_FUNC PyInit__routines_indexing(void)
#if CYTHON_PEP489_MULTI_PHASE_INIT
{
  return PyModuleDef_Init(&__pyx_moduledef);
}
static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) {
    #if PY_VERSION_HEX >= 0x030700A1
    static PY_INT64_T main_interpreter_id = -1;
    PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp);
    if (main_interpreter_id == -1) {
        main_interpreter_id = current_id;
        return (unlikely(current_id == -1)) ? -1 : 0;
    } else if (unlikely(main_interpreter_id != current_id))
    #else
    static PyInterpreterState *main_interpreter = NULL;
    PyInterpreterState *current_interpreter = PyThreadState_Get()->interp;
    if (!main_interpreter) {
        main_interpreter = current_interpreter;
    } else if (unlikely(main_interpreter != current_interpreter))
    #endif
    {
        PyErr_SetString(
            PyExc_ImportError,
            "Interpreter change detected - this module can only be loaded into one interpreter per process.");
        return -1;
    }
    return 0;
}
static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) {
    PyObject *value = PyObject_GetAttrString(spec, from_name);
    int result = 0;
    if (likely(value)) {
        if (allow_none || value != Py_None) {
            result = PyDict_SetItemString(moddict, to_name, value);
        }
        Py_DECREF(value);
    } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Clear();
    } else {
        result = -1;
    }
    return result;
}
static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) {
    PyObject *module = NULL, *moddict, *modname;
    if (__Pyx_check_single_interpreter())
        return NULL;
    if (__pyx_m)
        return __Pyx_NewRef(__pyx_m);
    modname = PyObject_GetAttrString(spec, "name");
    if (unlikely(!modname)) goto bad;
    module = PyModule_NewObject(modname);
    Py_DECREF(modname);
    if (unlikely(!module)) goto bad;
    moddict = PyModule_GetDict(module);
    if (unlikely(!moddict)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad;
    if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad;
    return module;
bad:
    Py_XDECREF(module);
    return NULL;
}


static CYTHON_SMALL_CODE int __pyx_pymod_exec__routines_indexing(PyObject *__pyx_pyinit_module)
#endif
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;
  __Pyx_RefNannyDeclarations
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  if (__pyx_m) {
    if (__pyx_m == __pyx_pyinit_module) return 0;
    PyErr_SetString(PyExc_RuntimeError, "Module '_routines_indexing' has already been imported. Re-initialisation is not supported.");
    return -1;
  }
  #elif PY_MAJOR_VERSION >= 3
  if (__pyx_m) return __Pyx_NewRef(__pyx_m);
  #endif
  #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("__Pyx_PyMODINIT_FUNC PyInit__routines_indexing(void)", 0);
  if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pxy_PyFrame_Initialize_Offsets
  __Pxy_PyFrame_Initialize_Offsets();
  #endif
  __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_AsyncGen_USED
  if (__pyx_AsyncGen_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 CYTHON_PEP489_MULTI_PHASE_INIT
  __pyx_m = __pyx_pyinit_module;
  Py_INCREF(__pyx_m);
  #else
  #if PY_MAJOR_VERSION < 3
  __pyx_m = Py_InitModule4("_routines_indexing", __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)
  #endif
  __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)
  Py_INCREF(__pyx_b);
  __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_cython_runtime);
  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_cupy__core___routines_indexing) {
    if (PyObject_SetAttr(__pyx_m, __pyx_n_s_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, "cupy.core._routines_indexing")) {
      if (unlikely(PyDict_SetItemString(modules, "cupy.core._routines_indexing", __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 type/function init code ---*/
  (void)__Pyx_modinit_global_init_code();
  (void)__Pyx_modinit_variable_export_code();
  if (unlikely(__Pyx_modinit_function_export_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  (void)__Pyx_modinit_type_init_code();
  if (unlikely(__Pyx_modinit_type_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  if (unlikely(__Pyx_modinit_variable_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  if (unlikely(__Pyx_modinit_function_import_code() < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Execution code ---*/
  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif

  /* "cupy/core/_routines_indexing.pyx":2
 * # distutils: language = c++
 * import sys             # <<<<<<<<<<<<<<
 * 
 * import numpy
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":4
 * import sys
 * 
 * import numpy             # <<<<<<<<<<<<<<
 * 
 * import cupy
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 4, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_numpy, __pyx_t_1) < 0) __PYX_ERR(0, 4, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":6
 * import numpy
 * 
 * import cupy             # <<<<<<<<<<<<<<
 * from cupy.core import _errors
 * from cupy.core._kernel import ElementwiseKernel
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_cupy, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_cupy, __pyx_t_1) < 0) __PYX_ERR(0, 6, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":7
 * 
 * import cupy
 * from cupy.core import _errors             # <<<<<<<<<<<<<<
 * from cupy.core._kernel import ElementwiseKernel
 * from cupy.core._ufuncs import elementwise_copy
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_errors);
  __Pyx_GIVEREF(__pyx_n_s_errors);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_errors);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_cupy_core, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_errors); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_errors, __pyx_t_1) < 0) __PYX_ERR(0, 7, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cupy/core/_routines_indexing.pyx":8
 * import cupy
 * from cupy.core import _errors
 * from cupy.core._kernel import ElementwiseKernel             # <<<<<<<<<<<<<<
 * from cupy.core._ufuncs import elementwise_copy
 * 
 */
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_ElementwiseKernel);
  __Pyx_GIVEREF(__pyx_n_s_ElementwiseKernel);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_ElementwiseKernel);
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_cupy_core__kernel, __pyx_t_2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_ElementwiseKernel, __pyx_t_2) < 0) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":9
 * from cupy.core import _errors
 * from cupy.core._kernel import ElementwiseKernel
 * from cupy.core._ufuncs import elementwise_copy             # <<<<<<<<<<<<<<
 * 
 * from libcpp cimport vector
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_elementwise_copy);
  __Pyx_GIVEREF(__pyx_n_s_elementwise_copy);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_elementwise_copy);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_cupy_core__ufuncs, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_elementwise_copy); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_elementwise_copy, __pyx_t_1) < 0) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cupy/core/_routines_indexing.pyx":338
 * 
 * 
 * _nonzero_kernel_1d = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'T src, S index', 'raw S dst',
 *     'if (src != 0) dst[index - 1] = i',
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 338, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 338, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_nonzero_kernel_1d, __pyx_t_1) < 0) __PYX_ERR(0, 338, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":344
 * 
 * 
 * _nonzero_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'T src, S index', 'raw S dst',
 *     '''
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 344, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "cupy/core/_routines_indexing.pyx":354
 *     }''',
 *     'nonzero_kernel',
 *     reduce_dims=False)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 354, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_reduce_dims, Py_False) < 0) __PYX_ERR(0, 354, __pyx_L1_error)

  /* "cupy/core/_routines_indexing.pyx":344
 * 
 * 
 * _nonzero_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'T src, S index', 'raw S dst',
 *     '''
 */
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__29, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 344, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_nonzero_kernel, __pyx_t_3) < 0) __PYX_ERR(0, 344, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "cupy/core/_routines_indexing.pyx":357
 * 
 * 
 * _take_kernel_core = '''             # <<<<<<<<<<<<<<
 * ptrdiff_t out_i = indices % index_range;
 * if (out_i < 0) out_i += index_range;
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_take_kernel_core, __pyx_kp_u_ptrdiff_t_out_i_indices_index_r) < 0) __PYX_ERR(0, 357, __pyx_L1_error)

  /* "cupy/core/_routines_indexing.pyx":366
 * 
 * 
 * _take_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'raw T a, S indices, uint32 ldim, uint32 cdim, uint32 rdim, '
 *     'int64 index_range',
 */
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 366, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);

  /* "cupy/core/_routines_indexing.pyx":369
 *     'raw T a, S indices, uint32 ldim, uint32 cdim, uint32 rdim, '
 *     'int64 index_range',
 *     'T out', _take_kernel_core, 'cupy_take')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_take_kernel_core); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 369, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "cupy/core/_routines_indexing.pyx":366
 * 
 * 
 * _take_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'raw T a, S indices, uint32 ldim, uint32 cdim, uint32 rdim, '
 *     'int64 index_range',
 */
  __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 366, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_kp_u_raw_T_a_S_indices_uint32_ldim_ui);
  __Pyx_GIVEREF(__pyx_kp_u_raw_T_a_S_indices_uint32_ldim_ui);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_raw_T_a_S_indices_uint32_ldim_ui);
  __Pyx_INCREF(__pyx_kp_u_T_out);
  __Pyx_GIVEREF(__pyx_kp_u_T_out);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_kp_u_T_out);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_2);
  __Pyx_INCREF(__pyx_n_u_cupy_take);
  __Pyx_GIVEREF(__pyx_n_u_cupy_take);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_n_u_cupy_take);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 366, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_take_kernel, __pyx_t_2) < 0) __PYX_ERR(0, 366, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "cupy/core/_routines_indexing.pyx":372
 * 
 * 
 * _take_kernel_scalar = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'raw T a, int64 indices, uint32 ldim, uint32 cdim, uint32 rdim, '
 *     'int64 index_range',
 */
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 372, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "cupy/core/_routines_indexing.pyx":375
 *     'raw T a, int64 indices, uint32 ldim, uint32 cdim, uint32 rdim, '
 *     'int64 index_range',
 *     'T out', _take_kernel_core, 'cupy_take_scalar')             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_take_kernel_core); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 375, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "cupy/core/_routines_indexing.pyx":372
 * 
 * 
 * _take_kernel_scalar = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'raw T a, int64 indices, uint32 ldim, uint32 cdim, uint32 rdim, '
 *     'int64 index_range',
 */
  __pyx_t_3 = PyTuple_New(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 372, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_kp_u_raw_T_a_int64_indices_uint32_ldi);
  __Pyx_GIVEREF(__pyx_kp_u_raw_T_a_int64_indices_uint32_ldi);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_u_raw_T_a_int64_indices_uint32_ldi);
  __Pyx_INCREF(__pyx_kp_u_T_out);
  __Pyx_GIVEREF(__pyx_kp_u_T_out);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_kp_u_T_out);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_1);
  __Pyx_INCREF(__pyx_n_u_cupy_take_scalar);
  __Pyx_GIVEREF(__pyx_n_u_cupy_take_scalar);
  PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_n_u_cupy_take_scalar);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 372, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_take_kernel_scalar, __pyx_t_1) < 0) __PYX_ERR(0, 372, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":378
 * 
 * 
 * _choose_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'S a, raw T choices, int32 n_channel',
 *     'T y',
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 378, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 378, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_choose_kernel, __pyx_t_3) < 0) __PYX_ERR(0, 378, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "cupy/core/_routines_indexing.pyx":385
 * 
 * 
 * _choose_clip_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'S a, raw T choices, int32 n_channel, int32 n',
 *     'T y',
 */
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 385, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 385, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_choose_clip_kernel, __pyx_t_1) < 0) __PYX_ERR(0, 385, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":400
 * 
 * 
 * cdef _put_raise_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'S ind, raw T vals, int64 n_vals, int64 n',
 *     'raw U data, raw bool err',
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 400, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 400, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_XGOTREF(__pyx_v_4cupy_4core_18_routines_indexing__put_raise_kernel);
  __Pyx_DECREF_SET(__pyx_v_4cupy_4core_18_routines_indexing__put_raise_kernel, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;

  /* "cupy/core/_routines_indexing.pyx":415
 * 
 * 
 * cdef _put_wrap_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'S ind, raw T vals, int64 n_vals, int64 n',
 *     'raw U data',
 */
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 415, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__33, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 415, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_XGOTREF(__pyx_v_4cupy_4core_18_routines_indexing__put_wrap_kernel);
  __Pyx_DECREF_SET(__pyx_v_4cupy_4core_18_routines_indexing__put_wrap_kernel, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":427
 * 
 * 
 * cdef _put_clip_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'S ind, raw T vals, int64 n_vals, int64 n',
 *     'raw U data',
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 427, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__34, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 427, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_XGOTREF(__pyx_v_4cupy_4core_18_routines_indexing__put_clip_kernel);
  __Pyx_DECREF_SET(__pyx_v_4cupy_4core_18_routines_indexing__put_clip_kernel, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_3);
  __pyx_t_3 = 0;

  /* "cupy/core/_routines_indexing.pyx":442
 * 
 * 
 * _scatter_update_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'T v, S indices, int32 cdim, int32 rdim, int32 adim',
 *     'raw T a',
 */
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 442, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__35, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 442, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_scatter_update_kernel, __pyx_t_1) < 0) __PYX_ERR(0, 442, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":455
 * 
 * 
 * _scatter_add_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'raw T v, S indices, int32 cdim, int32 rdim, int32 adim',
 *     'raw T a',
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 455, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__36, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 455, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_scatter_add_kernel, __pyx_t_3) < 0) __PYX_ERR(0, 455, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "cupy/core/_routines_indexing.pyx":468
 * 
 * 
 * _scatter_max_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'raw T v, S indices, int32 cdim, int32 rdim, int32 adim',
 *     'raw T a',
 */
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 468, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__37, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 468, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_scatter_max_kernel, __pyx_t_1) < 0) __PYX_ERR(0, 468, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":481
 * 
 * 
 * _scatter_min_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'raw T v, S indices, int32 cdim, int32 rdim, int32 adim',
 *     'raw T a',
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 481, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__38, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 481, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_scatter_min_kernel, __pyx_t_3) < 0) __PYX_ERR(0, 481, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "cupy/core/_routines_indexing.pyx":494
 * 
 * 
 * _scatter_update_mask_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'raw T v, bool mask, S mask_scanned',
 *     'T a',
 */
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 494, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 494, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_scatter_update_mask_kernel, __pyx_t_1) < 0) __PYX_ERR(0, 494, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":501
 * 
 * 
 * _scatter_add_mask_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'raw T v, bool mask, S mask_scanned',
 *     'T a',
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 501, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 501, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_scatter_add_mask_kernel, __pyx_t_3) < 0) __PYX_ERR(0, 501, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "cupy/core/_routines_indexing.pyx":508
 * 
 * 
 * _scatter_max_mask_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'raw T v, bool mask, S mask_scanned',
 *     'T a',
 */
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 508, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__41, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 508, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_scatter_max_mask_kernel, __pyx_t_1) < 0) __PYX_ERR(0, 508, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":515
 * 
 * 
 * _scatter_min_mask_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'raw T v, bool mask, S mask_scanned',
 *     'T a',
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 515, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__42, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 515, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_scatter_min_mask_kernel, __pyx_t_3) < 0) __PYX_ERR(0, 515, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "cupy/core/_routines_indexing.pyx":522
 * 
 * 
 * _getitem_mask_kernel = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'T a, bool mask, S mask_scanned',
 *     'raw T out',
 */
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 522, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__43, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 522, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_getitem_mask_kernel, __pyx_t_1) < 0) __PYX_ERR(0, 522, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "cupy/core/_routines_indexing.pyx":866
 * 
 * 
 * _prepare_array_indexing = ElementwiseKernel(             # <<<<<<<<<<<<<<
 *     'T s, S len, S stride',
 *     'S out',
 */
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ElementwiseKernel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 866, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__44, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 866, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_prepare_array_indexing, __pyx_t_3) < 0) __PYX_ERR(0, 866, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "cupy/core/_routines_indexing.pyx":1
 * # distutils: language = c++             # <<<<<<<<<<<<<<
 * import sys
 * 
 */
  __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_3) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "vector.to_py":60
 * 
 * @cname("__pyx_convert_vector_to_py_Py_ssize_t")
 * cdef object __pyx_convert_vector_to_py_Py_ssize_t(vector[X]& v):             # <<<<<<<<<<<<<<
 *     return [v[i] for i in range(v.size())]
 * 
 */

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

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init cupy.core._routines_indexing", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    Py_CLEAR(__pyx_m);
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init cupy.core._routines_indexing");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if CYTHON_PEP489_MULTI_PHASE_INIT
  return (__pyx_m != NULL) ? 0 : -1;
  #elif PY_MAJOR_VERSION >= 3
  return __pyx_m;
  #else
  return;
  #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(modname);
    if (!m) goto end;
    p = PyObject_GetAttrString(m, "RefNannyAPI");
    if (!p) goto end;
    r = PyLong_AsVoidPtr(p);
end:
    Py_XDECREF(p);
    Py_XDECREF(m);
    return (__Pyx_RefNannyAPIStruct *)r;
}
#endif

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

/* RaiseTooManyValuesToUnpack */
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
    PyErr_Format(PyExc_ValueError,
                 "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
}

/* RaiseNeedMoreValuesToUnpack */
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
                 index, (index == 1) ? "" : "s");
}

/* RaiseNoneIterError */
static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}

/* GetItemInt */
static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) {
    PyObject *r;
    if (!j) return NULL;
    r = PyObject_GetItem(o, j);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    Py_ssize_t wrapped_i = i;
    if (wraparound & unlikely(i < 0)) {
        wrapped_i += PyList_GET_SIZE(o);
    }
    if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, wrapped_i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    Py_ssize_t wrapped_i = i;
    if (wraparound & unlikely(i < 0)) {
        wrapped_i += PyTuple_GET_SIZE(o);
    }
    if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, wrapped_i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
                                                     CYTHON_NCP_UNUSED int wraparound,
                                                     CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) {
            PyObject *r = PyList_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    }
    else if (PyTuple_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                        return NULL;
                    PyErr_Clear();
                }
            }
            return m->sq_item(o, i);
        }
    }
#else
    if (is_list || PySequence_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

/* ExtTypeTest */
static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(__Pyx_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

/* PyIntCompare */
static CYTHON_INLINE PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long inplace) {
    if (op1 == op2) {
        Py_RETURN_TRUE;
    }
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
        if (a == b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        int unequal;
        unsigned long uintval;
        Py_ssize_t size = Py_SIZE(op1);
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        if (intval == 0) {
            if (size == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
        } else if (intval < 0) {
            if (size >= 0)
                Py_RETURN_FALSE;
            intval = -intval;
            size = -size;
        } else {
            if (size <= 0)
                Py_RETURN_FALSE;
        }
        uintval = (unsigned long) intval;
#if PyLong_SHIFT * 4 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 4)) {
            unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 3 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 3)) {
            unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 2 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 2)) {
            unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 1 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 1)) {
            unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
            unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
        if (unequal == 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
        if ((double)a == (double)b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    return (
        PyObject_RichCompare(op1, op2, Py_EQ));
}

/* PyCFunctionFastCall */
#if CYTHON_FAST_PYCCALL
static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
    PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
    PyCFunction meth = PyCFunction_GET_FUNCTION(func);
    PyObject *self = PyCFunction_GET_SELF(func);
    int flags = PyCFunction_GET_FLAGS(func);
    assert(PyCFunction_Check(func));
    assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS)));
    assert(nargs >= 0);
    assert(nargs == 0 || args != NULL);
    /* _PyCFunction_FastCallDict() must not be called with an exception set,
       because it may clear it (directly or indirectly) and so the
       caller loses its exception */
    assert(!PyErr_Occurred());
    if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) {
        return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL);
    } else {
        return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs);
    }
}
#endif

/* PyFunctionFastCall */
#if CYTHON_FAST_PYCALL
static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
                                               PyObject *globals) {
    PyFrameObject *f;
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject **fastlocals;
    Py_ssize_t i;
    PyObject *result;
    assert(globals != NULL);
    /* XXX Perhaps we should create a specialized
       PyFrame_New() that doesn't take locals, but does
       take builtins without sanity checking them.
       */
    assert(tstate != NULL);
    f = PyFrame_New(tstate, co, globals, NULL);
    if (f == NULL) {
        return NULL;
    }
    fastlocals = __Pyx_PyFrame_GetLocalsplus(f);
    for (i = 0; i < na; i++) {
        Py_INCREF(*args);
        fastlocals[i] = *args++;
    }
    result = PyEval_EvalFrameEx(f,0);
    ++tstate->recursion_depth;
    Py_DECREF(f);
    --tstate->recursion_depth;
    return result;
}
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) {
    PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
    PyObject *globals = PyFunction_GET_GLOBALS(func);
    PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
    PyObject *closure;
#if PY_MAJOR_VERSION >= 3
    PyObject *kwdefs;
#endif
    PyObject *kwtuple, **k;
    PyObject **d;
    Py_ssize_t nd;
    Py_ssize_t nk;
    PyObject *result;
    assert(kwargs == NULL || PyDict_Check(kwargs));
    nk = kwargs ? PyDict_Size(kwargs) : 0;
    if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
        return NULL;
    }
    if (
#if PY_MAJOR_VERSION >= 3
            co->co_kwonlyargcount == 0 &&
#endif
            likely(kwargs == NULL || nk == 0) &&
            co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
        if (argdefs == NULL && co->co_argcount == nargs) {
            result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
            goto done;
        }
        else if (nargs == 0 && argdefs != NULL
                 && co->co_argcount == Py_SIZE(argdefs)) {
            /* function called with no arguments, but all parameters have
               a default value: use default values as arguments .*/
            args = &PyTuple_GET_ITEM(argdefs, 0);
            result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
            goto done;
        }
    }
    if (kwargs != NULL) {
        Py_ssize_t pos, i;
        kwtuple = PyTuple_New(2 * nk);
        if (kwtuple == NULL) {
            result = NULL;
            goto done;
        }
        k = &PyTuple_GET_ITEM(kwtuple, 0);
        pos = i = 0;
        while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
            Py_INCREF(k[i]);
            Py_INCREF(k[i+1]);
            i += 2;
        }
        nk = i / 2;
    }
    else {
        kwtuple = NULL;
        k = NULL;
    }
    closure = PyFunction_GET_CLOSURE(func);
#if PY_MAJOR_VERSION >= 3
    kwdefs = PyFunction_GET_KW_DEFAULTS(func);
#endif
    if (argdefs != NULL) {
        d = &PyTuple_GET_ITEM(argdefs, 0);
        nd = Py_SIZE(argdefs);
    }
    else {
        d = NULL;
        nd = 0;
    }
#if PY_MAJOR_VERSION >= 3
    result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
                               args, (int)nargs,
                               k, (int)nk,
                               d, (int)nd, kwdefs, closure);
#else
    result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
                               args, (int)nargs,
                               k, (int)nk,
                               d, (int)nd, closure);
#endif
    Py_XDECREF(kwtuple);
done:
    Py_LeaveRecursiveCall();
    return result;
}
#endif
#endif

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

/* PyObjectCallMethO */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
    PyObject *self, *result;
    PyCFunction cfunc;
    cfunc = PyCFunction_GET_FUNCTION(func);
    self = PyCFunction_GET_SELF(func);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = cfunc(self, arg);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectCallOneArg */
#if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_New(1);
    if (unlikely(!args)) return NULL;
    Py_INCREF(arg);
    PyTuple_SET_ITEM(args, 0, arg);
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCall(func, &arg, 1);
    }
#endif
    if (likely(PyCFunction_Check(func))) {
        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
            return __Pyx_PyObject_CallMethO(func, arg);
#if CYTHON_FAST_PYCCALL
        } else if (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) {
            return __Pyx_PyCFunction_FastCall(func, &arg, 1);
#endif
        }
    }
    return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_Pack(1, arg);
    if (unlikely(!args)) return NULL;
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
#endif

/* UnpackUnboundCMethod */
static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
    PyObject *method;
    method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name);
    if (unlikely(!method))
        return -1;
    target->method = method;
#if CYTHON_COMPILING_IN_CPYTHON
    #if PY_MAJOR_VERSION >= 3
    if (likely(__Pyx_TypeCheck(method, &PyMethodDescr_Type)))
    #endif
    {
        PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
        target->func = descr->d_method->ml_meth;
        target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS);
    }
#endif
    return 0;
}

/* CallUnboundCMethod1 */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg) {
    if (likely(cfunc->func)) {
        int flag = cfunc->flag;
        if (flag == METH_O) {
            return (*(cfunc->func))(self, arg);
        } else if (PY_VERSION_HEX >= 0x030600B1 && flag == METH_FASTCALL) {
            if (PY_VERSION_HEX >= 0x030700A0) {
                return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, &arg, 1);
            } else {
                return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL);
            }
        } else if (PY_VERSION_HEX >= 0x030700A0 && flag == (METH_FASTCALL | METH_KEYWORDS)) {
            return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL);
        }
    }
    return __Pyx__CallUnboundCMethod1(cfunc, self, arg);
}
#endif
static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg){
    PyObject *args, *result = NULL;
    if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
#if CYTHON_COMPILING_IN_CPYTHON
    if (cfunc->func && (cfunc->flag & METH_VARARGS)) {
        args = PyTuple_New(1);
        if (unlikely(!args)) goto bad;
        Py_INCREF(arg);
        PyTuple_SET_ITEM(args, 0, arg);
        if (cfunc->flag & METH_KEYWORDS)
            result = (*(PyCFunctionWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, NULL);
        else
            result = (*cfunc->func)(self, args);
    } else {
        args = PyTuple_New(2);
        if (unlikely(!args)) goto bad;
        Py_INCREF(self);
        PyTuple_SET_ITEM(args, 0, self);
        Py_INCREF(arg);
        PyTuple_SET_ITEM(args, 1, arg);
        result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
    }
#else
    args = PyTuple_Pack(2, self, arg);
    if (unlikely(!args)) goto bad;
    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
#endif
bad:
    Py_XDECREF(args);
    return result;
}

/* ObjectGetItem */
#if CYTHON_USE_TYPE_SLOTS
static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) {
    PyObject *runerr;
    Py_ssize_t key_value;
    PySequenceMethods *m = Py_TYPE(obj)->tp_as_sequence;
    if (unlikely(!(m && m->sq_item))) {
        PyErr_Format(PyExc_TypeError, "'%.200s' object is not subscriptable", Py_TYPE(obj)->tp_name);
        return NULL;
    }
    key_value = __Pyx_PyIndex_AsSsize_t(index);
    if (likely(key_value != -1 || !(runerr = PyErr_Occurred()))) {
        return __Pyx_GetItemInt_Fast(obj, key_value, 0, 1, 1);
    }
    if (PyErr_GivenExceptionMatches(runerr, PyExc_OverflowError)) {
        PyErr_Clear();
        PyErr_Format(PyExc_IndexError, "cannot fit '%.200s' into an index-sized integer", Py_TYPE(index)->tp_name);
    }
    return NULL;
}
static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key) {
    PyMappingMethods *m = Py_TYPE(obj)->tp_as_mapping;
    if (likely(m && m->mp_subscript)) {
        return m->mp_subscript(obj, key);
    }
    return __Pyx_PyObject_GetIndex(obj, key);
}
#endif

/* PyDictVersioning */
#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) {
    PyObject *dict = Py_TYPE(obj)->tp_dict;
    return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0;
}
static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) {
    PyObject **dictptr = NULL;
    Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset;
    if (offset) {
#if CYTHON_COMPILING_IN_CPYTHON
        dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj);
#else
        dictptr = _PyObject_GetDictPtr(obj);
#endif
    }
    return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0;
}
static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) {
    PyObject *dict = Py_TYPE(obj)->tp_dict;
    if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict)))
        return 0;
    return obj_dict_version == __Pyx_get_object_dict_version(obj);
}
#endif

/* GetModuleGlobalName */
#if CYTHON_USE_DICT_VERSIONS
static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value)
#else
static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name)
#endif
{
    PyObject *result;
#if !CYTHON_AVOID_BORROWED_REFS
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1
    result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    } else if (unlikely(PyErr_Occurred())) {
        return NULL;
    }
#else
    result = PyDict_GetItem(__pyx_d, name);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    }
#endif
#else
    result = PyObject_GetItem(__pyx_d, name);
    __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version)
    if (likely(result)) {
        return __Pyx_NewRef(result);
    }
    PyErr_Clear();
#endif
    return __Pyx_GetBuiltinName(name);
}

/* None */
static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
}

/* PyObjectSetAttrStr */
#if CYTHON_USE_TYPE_SLOTS
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);
}
#endif

/* BytesEquals */
static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
    if (s1 == s2) {
        return (equals == Py_EQ);
    } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) {
        const char *ps1, *ps2;
        Py_ssize_t length = PyBytes_GET_SIZE(s1);
        if (length != PyBytes_GET_SIZE(s2))
            return (equals == Py_NE);
        ps1 = PyBytes_AS_STRING(s1);
        ps2 = PyBytes_AS_STRING(s2);
        if (ps1[0] != ps2[0]) {
            return (equals == Py_NE);
        } else if (length == 1) {
            return (equals == Py_EQ);
        } else {
            int result;
#if CYTHON_USE_UNICODE_INTERNALS
            Py_hash_t hash1, hash2;
            hash1 = ((PyBytesObject*)s1)->ob_shash;
            hash2 = ((PyBytesObject*)s2)->ob_shash;
            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
                return (equals == Py_NE);
            }
#endif
            result = memcmp(ps1, ps2, (size_t)length);
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) {
        return (equals == Py_NE);
    } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) {
        return (equals == Py_NE);
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
#endif
}

/* UnicodeEquals */
static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) {
#if CYTHON_COMPILING_IN_PYPY
    return PyObject_RichCompareBool(s1, s2, equals);
#else
#if PY_MAJOR_VERSION < 3
    PyObject* owned_ref = NULL;
#endif
    int s1_is_unicode, s2_is_unicode;
    if (s1 == s2) {
        goto return_eq;
    }
    s1_is_unicode = PyUnicode_CheckExact(s1);
    s2_is_unicode = PyUnicode_CheckExact(s2);
#if PY_MAJOR_VERSION < 3
    if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) {
        owned_ref = PyUnicode_FromObject(s2);
        if (unlikely(!owned_ref))
            return -1;
        s2 = owned_ref;
        s2_is_unicode = 1;
    } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) {
        owned_ref = PyUnicode_FromObject(s1);
        if (unlikely(!owned_ref))
            return -1;
        s1 = owned_ref;
        s1_is_unicode = 1;
    } else if (((!s2_is_unicode) & (!s1_is_unicode))) {
        return __Pyx_PyBytes_Equals(s1, s2, equals);
    }
#endif
    if (s1_is_unicode & s2_is_unicode) {
        Py_ssize_t length;
        int kind;
        void *data1, *data2;
        if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0))
            return -1;
        length = __Pyx_PyUnicode_GET_LENGTH(s1);
        if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) {
            goto return_ne;
        }
#if CYTHON_USE_UNICODE_INTERNALS
        {
            Py_hash_t hash1, hash2;
        #if CYTHON_PEP393_ENABLED
            hash1 = ((PyASCIIObject*)s1)->hash;
            hash2 = ((PyASCIIObject*)s2)->hash;
        #else
            hash1 = ((PyUnicodeObject*)s1)->hash;
            hash2 = ((PyUnicodeObject*)s2)->hash;
        #endif
            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
                goto return_ne;
            }
        }
#endif
        kind = __Pyx_PyUnicode_KIND(s1);
        if (kind != __Pyx_PyUnicode_KIND(s2)) {
            goto return_ne;
        }
        data1 = __Pyx_PyUnicode_DATA(s1);
        data2 = __Pyx_PyUnicode_DATA(s2);
        if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) {
            goto return_ne;
        } else if (length == 1) {
            goto return_eq;
        } else {
            int result = memcmp(data1, data2, (size_t)(length * kind));
            #if PY_MAJOR_VERSION < 3
            Py_XDECREF(owned_ref);
            #endif
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & s2_is_unicode) {
        goto return_ne;
    } else if ((s2 == Py_None) & s1_is_unicode) {
        goto return_ne;
    } else {
        int result;
        PyObject* py_result = PyObject_RichCompare(s1, s2, equals);
        #if PY_MAJOR_VERSION < 3
        Py_XDECREF(owned_ref);
        #endif
        if (!py_result)
            return -1;
        result = __Pyx_PyObject_IsTrue(py_result);
        Py_DECREF(py_result);
        return result;
    }
return_eq:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_EQ);
return_ne:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_NE);
#endif
}

/* 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 (cause) {
        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 = __Pyx_PyThreadState_Current;
        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

/* PyObjectCallNoArg */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCall(func, NULL, 0);
    }
#endif
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func)))
#else
    if (likely(PyCFunction_Check(func)))
#endif
    {
        if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
            return __Pyx_PyObject_CallMethO(func, NULL);
        }
    }
    return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
}
#endif

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_SubtractObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
    (void)inplace;
    (void)zerodivision_check;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = (long)((unsigned long)a - b);
            if (likely((x^a) >= 0 || (x^~b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
            }
        }
                x = a - b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla - llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            PyFPE_START_PROTECT("subtract", return NULL)
            result = ((double)a) - (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceSubtract : PyNumber_Subtract)(op1, op2);
}
#endif

/* PyIntBinop */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, int inplace, int zerodivision_check) {
    (void)inplace;
    (void)zerodivision_check;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = (long)((unsigned long)a + b);
            if (likely((x^a) >= 0 || (x^b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_add(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                    CYTHON_FALLTHROUGH;
                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
            }
        }
                x = a + b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla + llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            PyFPE_START_PROTECT("add", return NULL)
            result = ((double)a) + (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
}
#endif

/* SliceObject */
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj,
        Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
        int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) {
#if CYTHON_USE_TYPE_SLOTS
    PyMappingMethods* mp;
#if PY_MAJOR_VERSION < 3
    PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence;
    if (likely(ms && ms->sq_slice)) {
        if (!has_cstart) {
            if (_py_start && (*_py_start != Py_None)) {
                cstart = __Pyx_PyIndex_AsSsize_t(*_py_start);
                if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstart = 0;
        }
        if (!has_cstop) {
            if (_py_stop && (*_py_stop != Py_None)) {
                cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop);
                if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstop = PY_SSIZE_T_MAX;
        }
        if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) {
            Py_ssize_t l = ms->sq_length(obj);
            if (likely(l >= 0)) {
                if (cstop < 0) {
                    cstop += l;
                    if (cstop < 0) cstop = 0;
                }
                if (cstart < 0) {
                    cstart += l;
                    if (cstart < 0) cstart = 0;
                }
            } else {
                if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                    goto bad;
                PyErr_Clear();
            }
        }
        return ms->sq_slice(obj, cstart, cstop);
    }
#endif
    mp = Py_TYPE(obj)->tp_as_mapping;
    if (likely(mp && mp->mp_subscript))
#endif
    {
        PyObject* result;
        PyObject *py_slice, *py_start, *py_stop;
        if (_py_slice) {
            py_slice = *_py_slice;
        } else {
            PyObject* owned_start = NULL;
            PyObject* owned_stop = NULL;
            if (_py_start) {
                py_start = *_py_start;
            } else {
                if (has_cstart) {
                    owned_start = py_start = PyInt_FromSsize_t(cstart);
                    if (unlikely(!py_start)) goto bad;
                } else
                    py_start = Py_None;
            }
            if (_py_stop) {
                py_stop = *_py_stop;
            } else {
                if (has_cstop) {
                    owned_stop = py_stop = PyInt_FromSsize_t(cstop);
                    if (unlikely(!py_stop)) {
                        Py_XDECREF(owned_start);
                        goto bad;
                    }
                } else
                    py_stop = Py_None;
            }
            py_slice = PySlice_New(py_start, py_stop, Py_None);
            Py_XDECREF(owned_start);
            Py_XDECREF(owned_stop);
            if (unlikely(!py_slice)) goto bad;
        }
#if CYTHON_USE_TYPE_SLOTS
        result = mp->mp_subscript(obj, py_slice);
#else
        result = PyObject_GetItem(obj, py_slice);
#endif
        if (!_py_slice) {
            Py_DECREF(py_slice);
        }
        return result;
    }
    PyErr_Format(PyExc_TypeError,
        "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name);
bad:
    return NULL;
}

/* PyObjectCall2Args */
static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) {
    PyObject *args, *result = NULL;
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(function)) {
        PyObject *args[2] = {arg1, arg2};
        return __Pyx_PyFunction_FastCall(function, args, 2);
    }
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(function)) {
        PyObject *args[2] = {arg1, arg2};
        return __Pyx_PyCFunction_FastCall(function, args, 2);
    }
    #endif
    args = PyTuple_New(2);
    if (unlikely(!args)) goto done;
    Py_INCREF(arg1);
    PyTuple_SET_ITEM(args, 0, arg1);
    Py_INCREF(arg2);
    PyTuple_SET_ITEM(args, 1, arg2);
    Py_INCREF(function);
    result = __Pyx_PyObject_Call(function, args, NULL);
    Py_DECREF(args);
    Py_DECREF(function);
done:
    return result;
}

/* UnicodeAsUCS4 */
static CYTHON_INLINE Py_UCS4 __Pyx_PyUnicode_AsPy_UCS4(PyObject* x) {
   Py_ssize_t length;
   #if CYTHON_PEP393_ENABLED
   length = PyUnicode_GET_LENGTH(x);
   if (likely(length == 1)) {
       return PyUnicode_READ_CHAR(x, 0);
   }
   #else
   length = PyUnicode_GET_SIZE(x);
   if (likely(length == 1)) {
       return PyUnicode_AS_UNICODE(x)[0];
   }
   #if Py_UNICODE_SIZE == 2
   else if (PyUnicode_GET_SIZE(x) == 2) {
       Py_UCS4 high_val = PyUnicode_AS_UNICODE(x)[0];
       if (high_val >= 0xD800 && high_val <= 0xDBFF) {
           Py_UCS4 low_val = PyUnicode_AS_UNICODE(x)[1];
           if (low_val >= 0xDC00 && low_val <= 0xDFFF) {
               return 0x10000 + (((high_val & ((1<<10)-1)) << 10) | (low_val & ((1<<10)-1)));
           }
       }
   }
   #endif
   #endif
   PyErr_Format(PyExc_ValueError,
                "only single character unicode strings can be converted to Py_UCS4, "
                "got length %" CYTHON_FORMAT_SSIZE_T "d", length);
   return (Py_UCS4)-1;
}

/* object_ord */
static long __Pyx__PyObject_Ord(PyObject* c) {
    Py_ssize_t size;
    if (PyBytes_Check(c)) {
        size = PyBytes_GET_SIZE(c);
        if (likely(size == 1)) {
            return (unsigned char) PyBytes_AS_STRING(c)[0];
        }
#if PY_MAJOR_VERSION < 3
    } else if (PyUnicode_Check(c)) {
        return (long)__Pyx_PyUnicode_AsPy_UCS4(c);
#endif
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
    } else if (PyByteArray_Check(c)) {
        size = PyByteArray_GET_SIZE(c);
        if (likely(size == 1)) {
            return (unsigned char) PyByteArray_AS_STRING(c)[0];
        }
#endif
    } else {
        PyErr_Format(PyExc_TypeError,
            "ord() expected string of length 1, but %.200s found", c->ob_type->tp_name);
        return (long)(Py_UCS4)-1;
    }
    PyErr_Format(PyExc_TypeError,
        "ord() expected a character, but string of length %zd found", size);
    return (long)(Py_UCS4)-1;
}

/* SetItemInt */
static int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) {
    int r;
    if (!j) return -1;
    r = PyObject_SetItem(o, j, v);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v, int is_list,
                                               CYTHON_NCP_UNUSED int wraparound, CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = (!wraparound) ? i : ((likely(i >= 0)) ? i : i + PyList_GET_SIZE(o));
        if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o)))) {
            PyObject* old = PyList_GET_ITEM(o, n);
            Py_INCREF(v);
            PyList_SET_ITEM(o, n, v);
            Py_DECREF(old);
            return 1;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_ass_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                        return -1;
                    PyErr_Clear();
                }
            }
            return m->sq_ass_item(o, i, v);
        }
    }
#else
#if CYTHON_COMPILING_IN_PYPY
    if (is_list || (PySequence_Check(o) && !PyDict_Check(o)))
#else
    if (is_list || PySequence_Check(o))
#endif
    {
        return PySequence_SetItem(o, i, v);
    }
#endif
    return __Pyx_SetItemInt_Generic(o, PyInt_FromSsize_t(i), v);
}

/* RaiseArgTupleInvalid */
static void __Pyx_RaiseArgtupleInvalid(
    const char* func_name,
    int exact,
    Py_ssize_t num_min,
    Py_ssize_t num_max,
    Py_ssize_t num_found)
{
    Py_ssize_t num_expected;
    const char *more_or_less;
    if (num_found < num_min) {
        num_expected = num_min;
        more_or_less = "at least";
    } else {
        num_expected = num_max;
        more_or_less = "at most";
    }
    if (exact) {
        more_or_less = "exactly";
    }
    PyErr_Format(PyExc_TypeError,
                 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

/* RaiseDoubleKeywords */
static void __Pyx_RaiseDoubleKeywordsError(
    const char* func_name,
    PyObject* kw_name)
{
    PyErr_Format(PyExc_TypeError,
        #if PY_MAJOR_VERSION >= 3
        "%s() got multiple values for keyword argument '%U'", func_name, kw_name);
        #else
        "%s() got multiple values for keyword argument '%s'", func_name,
        PyString_AsString(kw_name));
        #endif
}

/* ParseKeywords */
static int __Pyx_ParseOptionalKeywords(
    PyObject *kwds,
    PyObject **argnames[],
    PyObject *kwds2,
    PyObject *values[],
    Py_ssize_t num_pos_args,
    const char* function_name)
{
    PyObject *key = 0, *value = 0;
    Py_ssize_t pos = 0;
    PyObject*** name;
    PyObject*** first_kw_arg = argnames + num_pos_args;
    while (PyDict_Next(kwds, &pos, &key, &value)) {
        name = first_kw_arg;
        while (*name && (**name != key)) name++;
        if (*name) {
            values[name-argnames] = value;
            continue;
        }
        name = first_kw_arg;
        #if PY_MAJOR_VERSION < 3
        if (likely(PyString_Check(key))) {
            while (*name) {
                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
                        && _PyString_Eq(**name, key)) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    if ((**argname == key) || (
                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
                             && _PyString_Eq(**argname, key))) {
                        goto arg_passed_twice;
                    }
                    argname++;
                }
            }
        } else
        #endif
        if (likely(PyUnicode_Check(key))) {
            while (*name) {
                int cmp = (**name == key) ? 0 :
                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                    (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 :
                #endif
                    PyUnicode_Compare(**name, key);
                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                if (cmp == 0) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    int cmp = (**argname == key) ? 0 :
                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                        (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 :
                    #endif
                        PyUnicode_Compare(**argname, key);
                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                    if (cmp == 0) goto arg_passed_twice;
                    argname++;
                }
            }
        } else
            goto invalid_keyword_type;
        if (kwds2) {
            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
        } else {
            goto invalid_keyword;
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, key);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

/* None */
static CYTHON_INLINE Py_ssize_t __Pyx_div_Py_ssize_t(Py_ssize_t a, Py_ssize_t b) {
    Py_ssize_t q = a / b;
    Py_ssize_t r = a - q*b;
    q -= ((r != 0) & ((r ^ b) < 0));
    return q;
}

/* PyObjectFormatAndDecref */
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatSimpleAndDecref(PyObject* s, PyObject* f) {
    if (unlikely(!s)) return NULL;
    if (likely(PyUnicode_CheckExact(s))) return s;
    #if PY_MAJOR_VERSION < 3
    if (likely(PyString_CheckExact(s))) {
        PyObject *result = PyUnicode_FromEncodedObject(s, NULL, "strict");
        Py_DECREF(s);
        return result;
    }
    #endif
    return __Pyx_PyObject_FormatAndDecref(s, f);
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_FormatAndDecref(PyObject* s, PyObject* f) {
    PyObject *result = PyObject_Format(s, f);
    Py_DECREF(s);
    return result;
}

/* CIntToDigits */
static const char DIGIT_PAIRS_10[2*10*10+1] = {
    "00010203040506070809"
    "10111213141516171819"
    "20212223242526272829"
    "30313233343536373839"
    "40414243444546474849"
    "50515253545556575859"
    "60616263646566676869"
    "70717273747576777879"
    "80818283848586878889"
    "90919293949596979899"
};
static const char DIGIT_PAIRS_8[2*8*8+1] = {
    "0001020304050607"
    "1011121314151617"
    "2021222324252627"
    "3031323334353637"
    "4041424344454647"
    "5051525354555657"
    "6061626364656667"
    "7071727374757677"
};
static const char DIGITS_HEX[2*16+1] = {
    "0123456789abcdef"
    "0123456789ABCDEF"
};

/* BuildPyUnicode */
static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength,
                                                int prepend_sign, char padding_char) {
    PyObject *uval;
    Py_ssize_t uoffset = ulength - clength;
#if CYTHON_USE_UNICODE_INTERNALS
    Py_ssize_t i;
#if CYTHON_PEP393_ENABLED
    void *udata;
    uval = PyUnicode_New(ulength, 127);
    if (unlikely(!uval)) return NULL;
    udata = PyUnicode_DATA(uval);
#else
    Py_UNICODE *udata;
    uval = PyUnicode_FromUnicode(NULL, ulength);
    if (unlikely(!uval)) return NULL;
    udata = PyUnicode_AS_UNICODE(uval);
#endif
    if (uoffset > 0) {
        i = 0;
        if (prepend_sign) {
            __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, 0, '-');
            i++;
        }
        for (; i < uoffset; i++) {
            __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, i, padding_char);
        }
    }
    for (i=0; i < clength; i++) {
        __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, uoffset+i, chars[i]);
    }
#else
    {
        PyObject *sign = NULL, *padding = NULL;
        uval = NULL;
        if (uoffset > 0) {
            prepend_sign = !!prepend_sign;
            if (uoffset > prepend_sign) {
                padding = PyUnicode_FromOrdinal(padding_char);
                if (likely(padding) && uoffset > prepend_sign + 1) {
                    PyObject *tmp;
                    PyObject *repeat = PyInt_FromSize_t(uoffset - prepend_sign);
                    if (unlikely(!repeat)) goto done_or_error;
                    tmp = PyNumber_Multiply(padding, repeat);
                    Py_DECREF(repeat);
                    Py_DECREF(padding);
                    padding = tmp;
                }
                if (unlikely(!padding)) goto done_or_error;
            }
            if (prepend_sign) {
                sign = PyUnicode_FromOrdinal('-');
                if (unlikely(!sign)) goto done_or_error;
            }
        }
        uval = PyUnicode_DecodeASCII(chars, clength, NULL);
        if (likely(uval) && padding) {
            PyObject *tmp = PyNumber_Add(padding, uval);
            Py_DECREF(uval);
            uval = tmp;
        }
        if (likely(uval) && sign) {
            PyObject *tmp = PyNumber_Add(sign, uval);
            Py_DECREF(uval);
            uval = tmp;
        }
done_or_error:
        Py_XDECREF(padding);
        Py_XDECREF(sign);
    }
#endif
    return uval;
}

/* CIntToPyUnicode */
#ifdef _MSC_VER
    #ifndef _MSC_STDINT_H_
        #if _MSC_VER < 1300
           typedef unsigned short    uint16_t;
        #else
           typedef unsigned __int16  uint16_t;
        #endif
    #endif
#else
   #include <stdint.h>
#endif
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
#define GCC_DIAGNOSTIC
#endif
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_Py_ssize_t(Py_ssize_t value, Py_ssize_t width, char padding_char, char format_char) {
    char digits[sizeof(Py_ssize_t)*3+2];
    char *dpos, *end = digits + sizeof(Py_ssize_t)*3+2;
    const char *hex_digits = DIGITS_HEX;
    Py_ssize_t length, ulength;
    int prepend_sign, last_one_off;
    Py_ssize_t remaining;
#ifdef GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
    const Py_ssize_t neg_one = (Py_ssize_t) -1, const_zero = (Py_ssize_t) 0;
#ifdef GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
    const int is_unsigned = neg_one > const_zero;
    if (format_char == 'X') {
        hex_digits += 16;
        format_char = 'x';
    }
    remaining = value;
    last_one_off = 0;
    dpos = end;
    do {
        int digit_pos;
        switch (format_char) {
        case 'o':
            digit_pos = abs((int)(remaining % (8*8)));
            remaining = (Py_ssize_t) (remaining / (8*8));
            dpos -= 2;
            *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_8)[digit_pos];
            last_one_off = (digit_pos < 8);
            break;
        case 'd':
            digit_pos = abs((int)(remaining % (10*10)));
            remaining = (Py_ssize_t) (remaining / (10*10));
            dpos -= 2;
            *(uint16_t*)dpos = ((const uint16_t*)DIGIT_PAIRS_10)[digit_pos];
            last_one_off = (digit_pos < 10);
            break;
        case 'x':
            *(--dpos) = hex_digits[abs((int)(remaining % 16))];
            remaining = (Py_ssize_t) (remaining / 16);
            break;
        default:
            assert(0);
            break;
        }
    } while (unlikely(remaining != 0));
    if (last_one_off) {
        assert(*dpos == '0');
        dpos++;
    }
    length = end - dpos;
    ulength = length;
    prepend_sign = 0;
    if (!is_unsigned && value <= neg_one) {
        if (padding_char == ' ' || width <= length + 1) {
            *(--dpos) = '-';
            ++length;
        } else {
            prepend_sign = 1;
        }
        ++ulength;
    }
    if (width > ulength) {
        ulength = width;
    }
    if (ulength == 1) {
        return PyUnicode_FromOrdinal(*dpos);
    }
    return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char);
}

/* JoinPyUnicode */
static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength,
                                      CYTHON_UNUSED Py_UCS4 max_char) {
#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    PyObject *result_uval;
    int result_ukind;
    Py_ssize_t i, char_pos;
    void *result_udata;
#if CYTHON_PEP393_ENABLED
    result_uval = PyUnicode_New(result_ulength, max_char);
    if (unlikely(!result_uval)) return NULL;
    result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND;
    result_udata = PyUnicode_DATA(result_uval);
#else
    result_uval = PyUnicode_FromUnicode(NULL, result_ulength);
    if (unlikely(!result_uval)) return NULL;
    result_ukind = sizeof(Py_UNICODE);
    result_udata = PyUnicode_AS_UNICODE(result_uval);
#endif
    char_pos = 0;
    for (i=0; i < value_count; i++) {
        int ukind;
        Py_ssize_t ulength;
        void *udata;
        PyObject *uval = PyTuple_GET_ITEM(value_tuple, i);
        if (unlikely(__Pyx_PyUnicode_READY(uval)))
            goto bad;
        ulength = __Pyx_PyUnicode_GET_LENGTH(uval);
        if (unlikely(!ulength))
            continue;
        if (unlikely(char_pos + ulength < 0))
            goto overflow;
        ukind = __Pyx_PyUnicode_KIND(uval);
        udata = __Pyx_PyUnicode_DATA(uval);
        if (!CYTHON_PEP393_ENABLED || ukind == result_ukind) {
            memcpy((char *)result_udata + char_pos * result_ukind, udata, (size_t) (ulength * result_ukind));
        } else {
            #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030300F0 || defined(_PyUnicode_FastCopyCharacters)
            _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength);
            #else
            Py_ssize_t j;
            for (j=0; j < ulength; j++) {
                Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j);
                __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar);
            }
            #endif
        }
        char_pos += ulength;
    }
    return result_uval;
overflow:
    PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string");
bad:
    Py_DECREF(result_uval);
    return NULL;
#else
    result_ulength++;
    value_count++;
    return PyUnicode_Join(__pyx_empty_unicode, value_tuple);
#endif
}

/* ArgTypeTest */
static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact)
{
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    else if (exact) {
        #if PY_MAJOR_VERSION == 2
        if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
        #endif
    }
    else {
        if (likely(__Pyx_TypeCheck(obj, type))) return 1;
    }
    PyErr_Format(PyExc_TypeError,
        "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
    return 0;
}

/* IterFinish */
static CYTHON_INLINE int __Pyx_IterFinish(void) {
#if CYTHON_FAST_THREAD_STATE
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    PyObject* exc_type = tstate->curexc_type;
    if (unlikely(exc_type)) {
        if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) {
            PyObject *exc_value, *exc_tb;
            exc_value = tstate->curexc_value;
            exc_tb = tstate->curexc_traceback;
            tstate->curexc_type = 0;
            tstate->curexc_value = 0;
            tstate->curexc_traceback = 0;
            Py_DECREF(exc_type);
            Py_XDECREF(exc_value);
            Py_XDECREF(exc_tb);
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#else
    if (unlikely(PyErr_Occurred())) {
        if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) {
            PyErr_Clear();
            return 0;
        } else {
            return -1;
        }
    }
    return 0;
#endif
}

/* UnpackItemEndCheck */
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) {
    if (unlikely(retval)) {
        Py_DECREF(retval);
        __Pyx_RaiseTooManyValuesError(expected);
        return -1;
    } else {
        return __Pyx_IterFinish();
    }
    return 0;
}

/* None */
static CYTHON_INLINE int __Pyx_mod_int(int a, int b) {
    int r = a % b;
    r += ((r != 0) & ((r ^ b) < 0)) * b;
    return r;
}

/* None */
static CYTHON_INLINE Py_ssize_t __Pyx_mod_Py_ssize_t(Py_ssize_t a, Py_ssize_t b) {
    Py_ssize_t r = a % b;
    r += ((r != 0) & ((r ^ b) < 0)) * b;
    return r;
}

/* SliceTupleAndList */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE void __Pyx_crop_slice(Py_ssize_t* _start, Py_ssize_t* _stop, Py_ssize_t* _length) {
    Py_ssize_t start = *_start, stop = *_stop, length = *_length;
    if (start < 0) {
        start += length;
        if (start < 0)
            start = 0;
    }
    if (stop < 0)
        stop += length;
    else if (stop > length)
        stop = length;
    *_length = stop - start;
    *_start = start;
    *_stop = stop;
}
static CYTHON_INLINE void __Pyx_copy_object_array(PyObject** CYTHON_RESTRICT src, PyObject** CYTHON_RESTRICT dest, Py_ssize_t length) {
    PyObject *v;
    Py_ssize_t i;
    for (i = 0; i < length; i++) {
        v = dest[i] = src[i];
        Py_INCREF(v);
    }
}
static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(
            PyObject* src, Py_ssize_t start, Py_ssize_t stop) {
    PyObject* dest;
    Py_ssize_t length = PyList_GET_SIZE(src);
    __Pyx_crop_slice(&start, &stop, &length);
    if (unlikely(length <= 0))
        return PyList_New(0);
    dest = PyList_New(length);
    if (unlikely(!dest))
        return NULL;
    __Pyx_copy_object_array(
        ((PyListObject*)src)->ob_item + start,
        ((PyListObject*)dest)->ob_item,
        length);
    return dest;
}
static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(
            PyObject* src, Py_ssize_t start, Py_ssize_t stop) {
    PyObject* dest;
    Py_ssize_t length = PyTuple_GET_SIZE(src);
    __Pyx_crop_slice(&start, &stop, &length);
    if (unlikely(length <= 0))
        return PyTuple_New(0);
    dest = PyTuple_New(length);
    if (unlikely(!dest))
        return NULL;
    __Pyx_copy_object_array(
        ((PyTupleObject*)src)->ob_item + start,
        ((PyTupleObject*)dest)->ob_item,
        length);
    return dest;
}
#endif

/* DelItemInt */
static int __Pyx_DelItem_Generic(PyObject *o, PyObject *j) {
    int r;
    if (!j) return -1;
    r = PyObject_DelItem(o, j);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE int __Pyx_DelItemInt_Fast(PyObject *o, Py_ssize_t i,
                                               CYTHON_UNUSED int is_list, CYTHON_NCP_UNUSED int wraparound) {
#if !CYTHON_USE_TYPE_SLOTS
    if (is_list || PySequence_Check(o)) {
        return PySequence_DelItem(o, i);
    }
#else
    PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
    if (likely(m && m->sq_ass_item)) {
        if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
            Py_ssize_t l = m->sq_length(o);
            if (likely(l >= 0)) {
                i += l;
            } else {
                if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                    return -1;
                PyErr_Clear();
            }
        }
        return m->sq_ass_item(o, i, (PyObject *)NULL);
    }
#endif
    return __Pyx_DelItem_Generic(o, PyInt_FromSsize_t(i));
}

/* PyIntCompare */
static CYTHON_INLINE PyObject* __Pyx_PyInt_NeObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED long inplace) {
    if (op1 == op2) {
        Py_RETURN_FALSE;
    }
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
        if (a != b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        int unequal;
        unsigned long uintval;
        Py_ssize_t size = Py_SIZE(op1);
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        if (intval == 0) {
            if (size != 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
        } else if (intval < 0) {
            if (size >= 0)
                Py_RETURN_TRUE;
            intval = -intval;
            size = -size;
        } else {
            if (size <= 0)
                Py_RETURN_TRUE;
        }
        uintval = (unsigned long) intval;
#if PyLong_SHIFT * 4 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 4)) {
            unequal = (size != 5) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[4] != ((uintval >> (4 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 3 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 3)) {
            unequal = (size != 4) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[3] != ((uintval >> (3 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 2 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 2)) {
            unequal = (size != 3) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)) | (digits[2] != ((uintval >> (2 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
#if PyLong_SHIFT * 1 < SIZEOF_LONG*8
        if (uintval >> (PyLong_SHIFT * 1)) {
            unequal = (size != 2) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
                 | (digits[1] != ((uintval >> (1 * PyLong_SHIFT)) & (unsigned long) PyLong_MASK));
        } else
#endif
            unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
        if (unequal != 0) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
        if ((double)a != (double)b) Py_RETURN_TRUE; else Py_RETURN_FALSE;
    }
    return (
        PyObject_RichCompare(op1, op2, Py_NE));
}

/* TypeImport */
#ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static PyTypeObject *__Pyx_ImportType(PyObject *module, const char *module_name, const char *class_name,
    size_t size, enum __Pyx_ImportType_CheckSize check_size)
{
    PyObject *result = 0;
    char warning[200];
    Py_ssize_t basicsize;
#ifdef Py_LIMITED_API
    PyObject *py_basicsize;
#endif
    result = PyObject_GetAttrString(module, class_name);
    if (!result)
        goto bad;
    if (!PyType_Check(result)) {
        PyErr_Format(PyExc_TypeError,
            "%.200s.%.200s is not a type object",
            module_name, class_name);
        goto bad;
    }
#ifndef Py_LIMITED_API
    basicsize = ((PyTypeObject *)result)->tp_basicsize;
#else
    py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
    if (!py_basicsize)
        goto bad;
    basicsize = PyLong_AsSsize_t(py_basicsize);
    Py_DECREF(py_basicsize);
    py_basicsize = 0;
    if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
        goto bad;
#endif
    if ((size_t)basicsize < size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize);
        goto bad;
    }
    if (check_size == __Pyx_ImportType_CheckSize_Error && (size_t)basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize);
        goto bad;
    }
    else if (check_size == __Pyx_ImportType_CheckSize_Warn && (size_t)basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility. "
            "Expected %zd from C header, got %zd from PyObject",
            module_name, class_name, size, basicsize);
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(result);
    return NULL;
}
#endif

/* GetVTable */
static void* __Pyx_GetVtable(PyObject *dict) {
    void* ptr;
    PyObject *ob = PyObject_GetItem(dict, __pyx_n_s_pyx_vtable);
    if (!ob)
        goto bad;
#if PY_VERSION_HEX >= 0x02070000
    ptr = PyCapsule_GetPointer(ob, 0);
#else
    ptr = PyCObject_AsVoidPtr(ob);
#endif
    if (!ptr && !PyErr_Occurred())
        PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type");
    Py_DECREF(ob);
    return ptr;
bad:
    Py_XDECREF(ob);
    return NULL;
}

/* Import */
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    #if PY_MAJOR_VERSION < 3
    PyObject *py_import;
    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
    if (!py_import)
        goto bad;
    #endif
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    {
        #if PY_MAJOR_VERSION >= 3
        if (level == -1) {
            if ((1) && (strchr(__Pyx_MODULE_NAME, '.'))) {
                module = PyImport_ImportModuleLevelObject(
                    name, global_dict, empty_dict, list, 1);
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0;
        }
        #endif
        if (!module) {
            #if PY_MAJOR_VERSION < 3
            PyObject *py_level = PyInt_FromLong(level);
            if (!py_level)
                goto bad;
            module = PyObject_CallFunctionObjArgs(py_import,
                name, global_dict, empty_dict, list, py_level, (PyObject *)NULL);
            Py_DECREF(py_level);
            #else
            module = PyImport_ImportModuleLevelObject(
                name, global_dict, empty_dict, list, level);
            #endif
        }
    }
bad:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

/* ImportFrom */
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
    PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
    if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Format(PyExc_ImportError,
        #if PY_MAJOR_VERSION < 3
            "cannot import name %.230s", PyString_AS_STRING(name));
        #else
            "cannot import name %S", name);
        #endif
    }
    return value;
}

/* CLineInTraceback */
#ifndef CYTHON_CLINE_IN_TRACEBACK
static int __Pyx_CLineForTraceback(CYTHON_NCP_UNUSED PyThreadState *tstate, int c_line) {
    PyObject *use_cline;
    PyObject *ptype, *pvalue, *ptraceback;
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject **cython_runtime_dict;
#endif
    if (unlikely(!__pyx_cython_runtime)) {
        return c_line;
    }
    __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback);
#if CYTHON_COMPILING_IN_CPYTHON
    cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
    if (likely(cython_runtime_dict)) {
        __PYX_PY_DICT_LOOKUP_IF_MODIFIED(
            use_cline, *cython_runtime_dict,
            __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback))
    } else
#endif
    {
      PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
      if (use_cline_obj) {
        use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
        Py_DECREF(use_cline_obj);
      } else {
        PyErr_Clear();
        use_cline = NULL;
      }
    }
    if (!use_cline) {
        c_line = 0;
        PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
    }
    else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) {
        c_line = 0;
    }
    __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback);
    return c_line;
}
#endif

/* 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;
    PyThreadState *tstate = __Pyx_PyThreadState_Current;
    if (c_line) {
        c_line = __Pyx_CLineForTraceback(tstate, c_line);
    }
    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(
        tstate,            /*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);
}

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

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
    const long neg_one = (long) ((long) 0 - (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);
    }
}

/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
    const int neg_one = (int) ((int) 0 - (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);
    }
}

/* CIntFromPy */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
    const int neg_one = (int) ((int) 0 - (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;
}

/* CIntFromPy */
static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) {
    const size_t neg_one = (size_t) ((size_t) 0 - (size_t) 1), const_zero = (size_t) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(size_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(size_t, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (size_t) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (size_t) 0;
                case  1: __PYX_VERIFY_RETURN_INT(size_t, digit, digits[0])
                case 2:
                    if (8 * sizeof(size_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) >= 2 * PyLong_SHIFT) {
                            return (size_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(size_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) >= 3 * PyLong_SHIFT) {
                            return (size_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(size_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) >= 4 * PyLong_SHIFT) {
                            return (size_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (size_t) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(size_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(size_t) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, 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 (size_t) 0;
                case -1: __PYX_VERIFY_RETURN_INT(size_t, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(size_t,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(size_t) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
                            return (size_t) (((size_t)-1)*(((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(size_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
                            return (size_t) ((((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
                            return (size_t) (((size_t)-1)*(((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(size_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
                            return (size_t) ((((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 4 * PyLong_SHIFT) {
                            return (size_t) (((size_t)-1)*(((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(size_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 4 * PyLong_SHIFT) {
                            return (size_t) ((((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(size_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(size_t) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, 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
            size_t 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 (size_t) -1;
        }
    } else {
        size_t val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (size_t) -1;
        val = __Pyx_PyInt_As_size_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to size_t");
    return (size_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to size_t");
    return (size_t) -1;
}

/* CIntFromPy */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
    const long neg_one = (long) ((long) 0 - (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;
}

/* FastTypeChecks */
#if CYTHON_COMPILING_IN_CPYTHON
static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
    while (a) {
        a = a->tp_base;
        if (a == b)
            return 1;
    }
    return b == &PyBaseObject_Type;
}
static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) {
    PyObject *mro;
    if (a == b) return 1;
    mro = a->tp_mro;
    if (likely(mro)) {
        Py_ssize_t i, n;
        n = PyTuple_GET_SIZE(mro);
        for (i = 0; i < n; i++) {
            if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
                return 1;
        }
        return 0;
    }
    return __Pyx_InBases(a, b);
}
#if PY_MAJOR_VERSION == 2
static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) {
    PyObject *exception, *value, *tb;
    int res;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&exception, &value, &tb);
    res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0;
    if (unlikely(res == -1)) {
        PyErr_WriteUnraisable(err);
        res = 0;
    }
    if (!res) {
        res = PyObject_IsSubclass(err, exc_type2);
        if (unlikely(res == -1)) {
            PyErr_WriteUnraisable(err);
            res = 0;
        }
    }
    __Pyx_ErrRestore(exception, value, tb);
    return res;
}
#else
static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) {
    int res = exc_type1 ? __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type1) : 0;
    if (!res) {
        res = __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2);
    }
    return res;
}
#endif
static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) {
    Py_ssize_t i, n;
    assert(PyExceptionClass_Check(exc_type));
    n = PyTuple_GET_SIZE(tuple);
#if PY_MAJOR_VERSION >= 3
    for (i=0; i<n; i++) {
        if (exc_type == PyTuple_GET_ITEM(tuple, i)) return 1;
    }
#endif
    for (i=0; i<n; i++) {
        PyObject *t = PyTuple_GET_ITEM(tuple, i);
        #if PY_MAJOR_VERSION < 3
        if (likely(exc_type == t)) return 1;
        #endif
        if (likely(PyExceptionClass_Check(t))) {
            if (__Pyx_inner_PyErr_GivenExceptionMatches2(exc_type, NULL, t)) return 1;
        } else {
        }
    }
    return 0;
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject* exc_type) {
    if (likely(err == exc_type)) return 1;
    if (likely(PyExceptionClass_Check(err))) {
        if (likely(PyExceptionClass_Check(exc_type))) {
            return __Pyx_inner_PyErr_GivenExceptionMatches2(err, NULL, exc_type);
        } else if (likely(PyTuple_Check(exc_type))) {
            return __Pyx_PyErr_GivenExceptionMatchesTuple(err, exc_type);
        } else {
        }
    }
    return PyErr_GivenExceptionMatches(err, exc_type);
}
static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *exc_type1, PyObject *exc_type2) {
    assert(PyExceptionClass_Check(exc_type1));
    assert(PyExceptionClass_Check(exc_type2));
    if (likely(err == exc_type1 || err == exc_type2)) return 1;
    if (likely(PyExceptionClass_Check(err))) {
        return __Pyx_inner_PyErr_GivenExceptionMatches2(err, exc_type1, exc_type2);
    }
    return (PyErr_GivenExceptionMatches(err, exc_type1) || PyErr_GivenExceptionMatches(err, exc_type2));
}
#endif

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

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

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

/* FunctionImport */
#ifndef __PYX_HAVE_RT_ImportFunction
#define __PYX_HAVE_RT_ImportFunction
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
    PyObject *d = 0;
    PyObject *cobj = 0;
    union {
        void (*fp)(void);
        void *p;
    } tmp;
    d = PyObject_GetAttrString(module, (char *)"__pyx_capi__");
    if (!d)
        goto bad;
    cobj = PyDict_GetItemString(d, funcname);
    if (!cobj) {
        PyErr_Format(PyExc_ImportError,
            "%.200s does not export expected C function %.200s",
                PyModule_GetName(module), funcname);
        goto bad;
    }
#if PY_VERSION_HEX >= 0x02070000
    if (!PyCapsule_IsValid(cobj, sig)) {
        PyErr_Format(PyExc_TypeError,
            "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
             PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
        goto bad;
    }
    tmp.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 function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
             PyModule_GetName(module), funcname, sig, desc);
        goto bad;
    }
    tmp.p = PyCObject_AsVoidPtr(cobj);}
#endif
    *f = tmp.fp;
    if (!(*f))
        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;
        if (PyObject_Hash(*t->p) == -1)
            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 const char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
#if !CYTHON_PEP393_ENABLED
static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    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
static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
    if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
    if (likely(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
#endif
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if __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)) {
        return __Pyx_PyUnicode_AsStringAndSize(o, length);
    } 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 int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) {
    int retval;
    if (unlikely(!x)) return -1;
    retval = __Pyx_PyObject_IsTrue(x);
    Py_DECREF(x);
    return retval;
}
static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) {
#if PY_MAJOR_VERSION >= 3
    if (PyLong_Check(result)) {
        if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
                "__int__ returned non-int (type %.200s).  "
                "The ability to return an instance of a strict subclass of int "
                "is deprecated, and may be removed in a future version of Python.",
                Py_TYPE(result)->tp_name)) {
            Py_DECREF(result);
            return NULL;
        }
        return result;
    }
#endif
    PyErr_Format(PyExc_TypeError,
                 "__%.4s__ returned non-%.4s (type %.200s)",
                 type_name, type_name, Py_TYPE(result)->tp_name);
    Py_DECREF(result);
    return NULL;
}
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 (likely(PyInt_Check(x) || PyLong_Check(x)))
#else
  if (likely(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 = m->nb_int(x);
  }
  else if (m && m->nb_long) {
    name = "long";
    res = m->nb_long(x);
  }
  #else
  if (likely(m && m->nb_int)) {
    name = "int";
    res = m->nb_int(x);
  }
  #endif
#else
  if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) {
    res = PyNumber_Int(x);
  }
#endif
  if (likely(res)) {
#if PY_MAJOR_VERSION < 3
    if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) {
#else
    if (unlikely(!PyLong_CheckExact(res))) {
#endif
        return __Pyx_PyNumber_IntOrLongWrongResultType(res, name);
    }
  }
  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(b);
  }
#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_PyBool_FromLong(long b) {
  return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False);
}
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) {
    return PyInt_FromSize_t(ival);
}


#endif /* Py_PYTHON_H */
