/ lib / numpy / f2py / cfuncs.pyc
cfuncs.pyc
   1  o

   2  [��c���@s0dZddlZddlZddlmZejZejjZ	ggggggggggd�
   3  Z
   4  iZddiZdd	iZ
d
   5  diZdd
iZddiZddiZddiZddiZdddd�Zddd�Zded<ded <d!ed"<d#e
d$<d%e
d$<d&e
d'<d(ed)<d*ed+<d,ed-<d.ed/<d0ed1<d2ed3<d4ed5<d6ed7<d8ed9<d:ed;<d<ed=<d>ed?<d@edA<dBedC<dDedE<dFedG<dHedI<dJedK<dLedM<dNedO<dPedQ<dRedS<dTedU<d/gedV<dWedV<dXedY<d1gedZ<d[edZ<d5ged\<d]ed\<d^ed_<d`eda<d7gedb<dcedb<d;gedd<deedd<d9gedf<dgedf<d=gedh<diedh<d=gedj<dkedj<dMgedl<dmedl<dMgedn<doedn<dpdMgedq<dredq<dsedt<duedv<d dvgedw<dxedw<dyedz<d{ed|<d ged}<d~ed}<d dvgedp<dedp<d dvged�<d�ed�<d�ed�<d�ed�<d�ed�<d�ed�<d�ed�<d�ed�<d�ed�<d�ed�<d�ed�<d�ed�<gd��ed�<d�ed�<gd��ed�<d�ed�<d�ed�<d�ged�<d�ed�<d�d/ged�<d�ed�<d�ged�<d�ed�<d�ed�<d�ed�<d1ged�<d�ed�<d�d5ged�<d�ed�<d�ed�<d�ged�<d�ed�<gd��ed�<d�ed�<d;ged�<d�ed�<d9d�ged�<d�ed�<d�ed�<dSdlged�<d�ed�<dld)ged�<d�ed�<dld/ged�<d�ed�<dUdlged�<d�ed�<dVdlged�<d�ed�<dYdlged�<d�ed�<gdŢed�<d�ed�<dadlged�<d�ed�<d_dlged�<d�ed�<gd̢ed�<d�ed�<gdϢed�<d�ed�<gdҢed�<d�ed�<d�dքZd�d�d؄Zd�dڄZdS)�a�
   6  
   7  C declarations, CPP macros, and C functions for f2py2e.
   8  Only required declarations/macros/functions will be used.
   9  
  10  Copyright 1999,2000 Pearu Peterson all rights reserved,
  11  Pearu Peterson <pearu@ioc.ee>
  12  Permission to use, modify, and distribute this software is given under the
  13  terms of the NumPy License.
  14  
  15  NO WARRANTY IS EXPRESSED OR IMPLIED.  USE AT YOUR OWN RISK.
  16  $Date: 2005/05/06 11:42:34 $
  17  Pearu Peterson
  18  
  19  �N�)�__version__)
  20  �	includes0�includes�typedefs�typedefs_generated�userincludes�	cppmacros�cfuncs�	callbacks�f90modhooks�commonhooksrz/*need_includes0*/rz/*need_includes*/rz/*need_userincludes*/rz/*need_typedefs*/rz/*need_typedefs_generated*/r	z/*need_cppmacros*/r
  21  z/*need_cfuncs*/rz/*need_callbacks*/z/*need_f90modhooks*/z/*initf90modhooksstatic*/z/*initf90modhooksdynamic*/)rZinitf90modhooksstaticZinitf90modhooksdynamicz/*need_commonhooks*/z/*need_initcommonhooks*/)r
�initcommonhooksz#include <math.h>zmath.hz#include <string.h>zstring.hz#include <setjmp.h>zsetjmp.hzC#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API
  22  #include "arrayobject.h"z
arrayobject.hz#include "fortranobject.h"z#include <stdarg.h>zstdarg.hz$typedef unsigned char unsigned_char;�
unsigned_charz&typedef unsigned short unsigned_short;�unsigned_shortz$typedef unsigned long unsigned_long;�
unsigned_longz typedef signed char signed_char;�signed_charz�#if defined(NPY_OS_WIN32)
  23  typedef __int64 long_long;
  24  #else
  25  typedef long long long_long;
  26  typedef unsigned long long unsigned_long_long;
  27  #endif
  28  �	long_longzr#if defined(NPY_OS_WIN32)
  29  typedef __uint64 long_long;
  30  #else
  31  typedef unsigned long long unsigned_long_long;
  32  #endif
  33  �unsigned_long_longz=#ifndef _LONG_DOUBLE
  34  typedef long double long_double;
  35  #endif
  36  �long_doublez6typedef struct {long double r,i;} complex_long_double;�complex_long_doublez*typedef struct {float r,i;} complex_float;�
complex_floatz,typedef struct {double r,i;} complex_double;�complex_doubleztypedef char * string;�stringztypedef char character;�	charactera#ifdef DEBUGCFUNCS
  37  #define CFUNCSMESS(mess) fprintf(stderr,"debug-capi:"mess);
  38  #define CFUNCSMESSPY(mess,obj) CFUNCSMESS(mess) \
  39      PyObject_Print((PyObject *)obj,stderr,Py_PRINT_RAW);\
  40      fprintf(stderr,"\n");
  41  #else
  42  #define CFUNCSMESS(mess)
  43  #define CFUNCSMESSPY(mess,obj)
  44  #endif
  45  46  CFUNCSMESSao#if defined(PREPEND_FORTRAN)
  47  #if defined(NO_APPEND_FORTRAN)
  48  #if defined(UPPERCASE_FORTRAN)
  49  #define F_FUNC(f,F) _##F
  50  #else
  51  #define F_FUNC(f,F) _##f
  52  #endif
  53  #else
  54  #if defined(UPPERCASE_FORTRAN)
  55  #define F_FUNC(f,F) _##F##_
  56  #else
  57  #define F_FUNC(f,F) _##f##_
  58  #endif
  59  #endif
  60  #else
  61  #if defined(NO_APPEND_FORTRAN)
  62  #if defined(UPPERCASE_FORTRAN)
  63  #define F_FUNC(f,F) F
  64  #else
  65  #define F_FUNC(f,F) f
  66  #endif
  67  #else
  68  #if defined(UPPERCASE_FORTRAN)
  69  #define F_FUNC(f,F) F##_
  70  #else
  71  #define F_FUNC(f,F) f##_
  72  #endif
  73  #endif
  74  #endif
  75  #if defined(UNDERSCORE_G77)
  76  #define F_FUNC_US(f,F) F_FUNC(f##_,F##_)
  77  #else
  78  #define F_FUNC_US(f,F) F_FUNC(f,F)
  79  #endif
  80  �F_FUNCa#if defined(PREPEND_FORTRAN)
  81  #if defined(NO_APPEND_FORTRAN)
  82  #if defined(UPPERCASE_FORTRAN)
  83  #define F_WRAPPEDFUNC(f,F) _F2PYWRAP##F
  84  #else
  85  #define F_WRAPPEDFUNC(f,F) _f2pywrap##f
  86  #endif
  87  #else
  88  #if defined(UPPERCASE_FORTRAN)
  89  #define F_WRAPPEDFUNC(f,F) _F2PYWRAP##F##_
  90  #else
  91  #define F_WRAPPEDFUNC(f,F) _f2pywrap##f##_
  92  #endif
  93  #endif
  94  #else
  95  #if defined(NO_APPEND_FORTRAN)
  96  #if defined(UPPERCASE_FORTRAN)
  97  #define F_WRAPPEDFUNC(f,F) F2PYWRAP##F
  98  #else
  99  #define F_WRAPPEDFUNC(f,F) f2pywrap##f
 100  #endif
 101  #else
 102  #if defined(UPPERCASE_FORTRAN)
 103  #define F_WRAPPEDFUNC(f,F) F2PYWRAP##F##_
 104  #else
 105  #define F_WRAPPEDFUNC(f,F) f2pywrap##f##_
 106  #endif
 107  #endif
 108  #endif
 109  #if defined(UNDERSCORE_G77)
 110  #define F_WRAPPEDFUNC_US(f,F) F_WRAPPEDFUNC(f##_,F##_)
 111  #else
 112  #define F_WRAPPEDFUNC_US(f,F) F_WRAPPEDFUNC(f,F)
 113  #endif
 114  �
F_WRAPPEDFUNCa0#if defined(F90MOD2CCONV1) /*E.g. Compaq Fortran */
 115  #if defined(NO_APPEND_FORTRAN)
 116  #define F_MODFUNCNAME(m,f) $ ## m ## $ ## f
 117  #else
 118  #define F_MODFUNCNAME(m,f) $ ## m ## $ ## f ## _
 119  #endif
 120  #endif
 121  
 122  #if defined(F90MOD2CCONV2) /*E.g. IBM XL Fortran, not tested though */
 123  #if defined(NO_APPEND_FORTRAN)
 124  #define F_MODFUNCNAME(m,f)  __ ## m ## _MOD_ ## f
 125  #else
 126  #define F_MODFUNCNAME(m,f)  __ ## m ## _MOD_ ## f ## _
 127  #endif
 128  #endif
 129  
 130  #if defined(F90MOD2CCONV3) /*E.g. MIPSPro Compilers */
 131  #if defined(NO_APPEND_FORTRAN)
 132  #define F_MODFUNCNAME(m,f)  f ## .in. ## m
 133  #else
 134  #define F_MODFUNCNAME(m,f)  f ## .in. ## m ## _
 135  #endif
 136  #endif
 137  /*
 138  #if defined(UPPERCASE_FORTRAN)
 139  #define F_MODFUNC(m,M,f,F) F_MODFUNCNAME(M,F)
 140  #else
 141  #define F_MODFUNC(m,M,f,F) F_MODFUNCNAME(m,f)
 142  #endif
 143  */
 144  
 145  #define F_MODFUNC(m,f) (*(f2pymodstruct##m##.##f))
 146  �	F_MODFUNCz�#define SWAP(a,b) (size_t)(a) = ((size_t)(a) ^ (size_t)(b));\
 147   (size_t)(b) = ((size_t)(a) ^ (size_t)(b));\
 148   (size_t)(a) = ((size_t)(a) ^ (size_t)(b))
 149  Z
 150  SWAPUNSAFEzF#define SWAP(a,b,t) {\
 151      t *c;\
 152      c = a;\
 153      a = b;\
 154      b = c;}
 155  �SWAPz�#define PRINTPYOBJERR(obj)\
 156      fprintf(stderr,"#modulename#.error is related to ");\
 157      PyObject_Print((PyObject *)obj,stderr,Py_PRINT_RAW);\
 158      fprintf(stderr,"\n");
 159  �
PRINTPYOBJERRz�#ifndef max
 160  #define max(a,b) ((a > b) ? (a) : (b))
 161  #endif
 162  #ifndef min
 163  #define min(a,b) ((a < b) ? (a) : (b))
 164  #endif
 165  #ifndef MAX
 166  #define MAX(a,b) ((a > b) ? (a) : (b))
 167  #endif
 168  #ifndef MIN
 169  #define MIN(a,b) ((a < b) ? (a) : (b))
 170  #endif
 171  �MINMAXz�/* See fortranobject.h for definitions. The macros here are provided for BC. */
 172  #define rank f2py_rank
 173  #define shape f2py_shape
 174  #define fshape f2py_shape
 175  #define len f2py_len
 176  #define flen f2py_flen
 177  #define slen f2py_slen
 178  #define size f2py_size
 179  zlen..z0#define pyobj_from_char1(v) (PyLong_FromLong(v))Zpyobj_from_char1z1#define pyobj_from_short1(v) (PyLong_FromLong(v))Zpyobj_from_short1Zpyobj_from_int1z/#define pyobj_from_int1(v) (PyLong_FromLong(v))z0#define pyobj_from_long1(v) (PyLong_FromLong(v))Zpyobj_from_long1�pyobj_from_long_long1z�#ifdef HAVE_LONG_LONG
 180  #define pyobj_from_long_long1(v) (PyLong_FromLongLong(v))
 181  #else
 182  #warning HAVE_LONG_LONG is not available. Redefining pyobj_from_long_long.
 183  #define pyobj_from_long_long1(v) (PyLong_FromLong(v))
 184  #endif
 185  Zpyobj_from_long_double1z:#define pyobj_from_long_double1(v) (PyFloat_FromDouble(v))z5#define pyobj_from_double1(v) (PyFloat_FromDouble(v))Zpyobj_from_double1z4#define pyobj_from_float1(v) (PyFloat_FromDouble(v))Zpyobj_from_float1Zpyobj_from_complex_long_double1zK#define pyobj_from_complex_long_double1(v) (PyComplex_FromDoubles(v.r,v.i))�pyobj_from_complex_double1zF#define pyobj_from_complex_double1(v) (PyComplex_FromDoubles(v.r,v.i))�pyobj_from_complex_float1zE#define pyobj_from_complex_float1(v) (PyComplex_FromDoubles(v.r,v.i))Zpyobj_from_string1z?#define pyobj_from_string1(v) (PyUnicode_FromString((char *)v))Zpyobj_from_string1sizezS#define pyobj_from_string1size(v,len) (PyUnicode_FromStringAndSize((char *)v, len))�TRYPYARRAYTEMPLATEa�/* New SciPy */
 186  #define TRYPYARRAYTEMPLATECHAR case NPY_STRING: *(char *)(PyArray_DATA(arr))=*v; break;
 187  #define TRYPYARRAYTEMPLATELONG case NPY_LONG: *(long *)(PyArray_DATA(arr))=*v; break;
 188  #define TRYPYARRAYTEMPLATEOBJECT case NPY_OBJECT: PyArray_SETITEM(arr,PyArray_DATA(arr),pyobj_from_ ## ctype ## 1(*v)); break;
 189  
 190  #define TRYPYARRAYTEMPLATE(ctype,typecode) \
 191          PyArrayObject *arr = NULL;\
 192          if (!obj) return -2;\
 193          if (!PyArray_Check(obj)) return -1;\
 194          if (!(arr=(PyArrayObject *)obj)) {fprintf(stderr,"TRYPYARRAYTEMPLATE:");PRINTPYOBJERR(obj);return 0;}\
 195          if (PyArray_DESCR(arr)->type==typecode)  {*(ctype *)(PyArray_DATA(arr))=*v; return 1;}\
 196          switch (PyArray_TYPE(arr)) {\
 197                  case NPY_DOUBLE: *(npy_double *)(PyArray_DATA(arr))=*v; break;\
 198                  case NPY_INT: *(npy_int *)(PyArray_DATA(arr))=*v; break;\
 199                  case NPY_LONG: *(npy_long *)(PyArray_DATA(arr))=*v; break;\
 200                  case NPY_FLOAT: *(npy_float *)(PyArray_DATA(arr))=*v; break;\
 201                  case NPY_CDOUBLE: *(npy_double *)(PyArray_DATA(arr))=*v; break;\
 202                  case NPY_CFLOAT: *(npy_float *)(PyArray_DATA(arr))=*v; break;\
 203                  case NPY_BOOL: *(npy_bool *)(PyArray_DATA(arr))=(*v!=0); break;\
 204                  case NPY_UBYTE: *(npy_ubyte *)(PyArray_DATA(arr))=*v; break;\
 205                  case NPY_BYTE: *(npy_byte *)(PyArray_DATA(arr))=*v; break;\
 206                  case NPY_SHORT: *(npy_short *)(PyArray_DATA(arr))=*v; break;\
 207                  case NPY_USHORT: *(npy_ushort *)(PyArray_DATA(arr))=*v; break;\
 208                  case NPY_UINT: *(npy_uint *)(PyArray_DATA(arr))=*v; break;\
 209                  case NPY_ULONG: *(npy_ulong *)(PyArray_DATA(arr))=*v; break;\
 210                  case NPY_LONGLONG: *(npy_longlong *)(PyArray_DATA(arr))=*v; break;\
 211                  case NPY_ULONGLONG: *(npy_ulonglong *)(PyArray_DATA(arr))=*v; break;\
 212                  case NPY_LONGDOUBLE: *(npy_longdouble *)(PyArray_DATA(arr))=*v; break;\
 213                  case NPY_CLONGDOUBLE: *(npy_longdouble *)(PyArray_DATA(arr))=*v; break;\
 214                  case NPY_OBJECT: PyArray_SETITEM(arr, PyArray_DATA(arr), pyobj_from_ ## ctype ## 1(*v)); break;\
 215          default: return -2;\
 216          };\
 217          return 1
 218  �TRYCOMPLEXPYARRAYTEMPLATEa�
 219  #define TRYCOMPLEXPYARRAYTEMPLATEOBJECT case NPY_OBJECT: PyArray_SETITEM(arr, PyArray_DATA(arr), pyobj_from_complex_ ## ctype ## 1((*v))); break;
 220  #define TRYCOMPLEXPYARRAYTEMPLATE(ctype,typecode)\
 221          PyArrayObject *arr = NULL;\
 222          if (!obj) return -2;\
 223          if (!PyArray_Check(obj)) return -1;\
 224          if (!(arr=(PyArrayObject *)obj)) {fprintf(stderr,"TRYCOMPLEXPYARRAYTEMPLATE:");PRINTPYOBJERR(obj);return 0;}\
 225          if (PyArray_DESCR(arr)->type==typecode) {\
 226              *(ctype *)(PyArray_DATA(arr))=(*v).r;\
 227              *(ctype *)(PyArray_DATA(arr)+sizeof(ctype))=(*v).i;\
 228              return 1;\
 229          }\
 230          switch (PyArray_TYPE(arr)) {\
 231                  case NPY_CDOUBLE: *(npy_double *)(PyArray_DATA(arr))=(*v).r;\
 232                                    *(npy_double *)(PyArray_DATA(arr)+sizeof(npy_double))=(*v).i;\
 233                                    break;\
 234                  case NPY_CFLOAT: *(npy_float *)(PyArray_DATA(arr))=(*v).r;\
 235                                   *(npy_float *)(PyArray_DATA(arr)+sizeof(npy_float))=(*v).i;\
 236                                   break;\
 237                  case NPY_DOUBLE: *(npy_double *)(PyArray_DATA(arr))=(*v).r; break;\
 238                  case NPY_LONG: *(npy_long *)(PyArray_DATA(arr))=(*v).r; break;\
 239                  case NPY_FLOAT: *(npy_float *)(PyArray_DATA(arr))=(*v).r; break;\
 240                  case NPY_INT: *(npy_int *)(PyArray_DATA(arr))=(*v).r; break;\
 241                  case NPY_SHORT: *(npy_short *)(PyArray_DATA(arr))=(*v).r; break;\
 242                  case NPY_UBYTE: *(npy_ubyte *)(PyArray_DATA(arr))=(*v).r; break;\
 243                  case NPY_BYTE: *(npy_byte *)(PyArray_DATA(arr))=(*v).r; break;\
 244                  case NPY_BOOL: *(npy_bool *)(PyArray_DATA(arr))=((*v).r!=0 && (*v).i!=0); break;\
 245                  case NPY_USHORT: *(npy_ushort *)(PyArray_DATA(arr))=(*v).r; break;\
 246                  case NPY_UINT: *(npy_uint *)(PyArray_DATA(arr))=(*v).r; break;\
 247                  case NPY_ULONG: *(npy_ulong *)(PyArray_DATA(arr))=(*v).r; break;\
 248                  case NPY_LONGLONG: *(npy_longlong *)(PyArray_DATA(arr))=(*v).r; break;\
 249                  case NPY_ULONGLONG: *(npy_ulonglong *)(PyArray_DATA(arr))=(*v).r; break;\
 250                  case NPY_LONGDOUBLE: *(npy_longdouble *)(PyArray_DATA(arr))=(*v).r; break;\
 251                  case NPY_CLONGDOUBLE: *(npy_longdouble *)(PyArray_DATA(arr))=(*v).r;\
 252                                        *(npy_longdouble *)(PyArray_DATA(arr)+sizeof(npy_longdouble))=(*v).i;\
 253                                        break;\
 254                  case NPY_OBJECT: PyArray_SETITEM(arr, PyArray_DATA(arr), pyobj_from_complex_ ## ctype ## 1((*v))); break;\
 255                  default: return -2;\
 256          };\
 257          return -1;
 258  �STRINGCOPYN�GETSTRFROMPYTUPLEa�#define GETSTRFROMPYTUPLE(tuple,index,str,len) {\
 259          PyObject *rv_cb_str = PyTuple_GetItem((tuple),(index));\
 260          if (rv_cb_str == NULL)\
 261              goto capi_fail;\
 262          if (PyBytes_Check(rv_cb_str)) {\
 263              str[len-1]='\0';\
 264              STRINGCOPYN((str),PyBytes_AS_STRING((PyBytesObject*)rv_cb_str),(len));\
 265          } else {\
 266              PRINTPYOBJERR(rv_cb_str);\
 267              PyErr_SetString(#modulename#_error,"string object expected");\
 268              goto capi_fail;\
 269          }\
 270      }
 271  z�#define GETSCALARFROMPYTUPLE(tuple,index,var,ctype,mess) {\
 272          if ((capi_tmp = PyTuple_GetItem((tuple),(index)))==NULL) goto capi_fail;\
 273          if (!(ctype ## _from_pyobj((var),capi_tmp,mess)))\
 274              goto capi_fail;\
 275      }
 276  �GETSCALARFROMPYTUPLEal\
 277  #define FAILNULL(p) do {                                            \
 278      if ((p) == NULL) {                                              \
 279          PyErr_SetString(PyExc_MemoryError, "NULL pointer found");   \
 280          goto capi_fail;                                             \
 281      }                                                               \
 282  } while (0)
 283  ZFAILNULL�MEMCOPYzh#define MEMCOPY(to,from,n)\
 284      do { FAILNULL(to); FAILNULL(from); (void)memcpy(to,from,n); } while (0)
 285  z�#define STRINGMALLOC(str,len)\
 286      if ((str = (string)malloc(len+1)) == NULL) {\
 287          PyErr_SetString(PyExc_MemoryError, "out of memory");\
 288          goto capi_fail;\
 289      } else {\
 290          (str)[len] = '\0';\
 291      }
 292  �STRINGMALLOCzF#define STRINGFREE(str) do {if (!(str == NULL)) free(str);} while (0)
 293 294  STRINGFREE�
 295  STRINGPADNa�/*
 296  STRINGPADN replaces null values with padding values from the right.
 297  
 298  `to` must have size of at least N bytes.
 299  
 300  If the `to[N-1]` has null value, then replace it and all the
 301  preceding, nulls with the given padding.
 302  
 303  STRINGPADN(to, N, PADDING, NULLVALUE) is an inverse operation.
 304  */
 305  #define STRINGPADN(to, N, NULLVALUE, PADDING)                   \
 306      do {                                                        \
 307          int _m = (N);                                           \
 308          char *_to = (to);                                       \
 309          for (_m -= 1; _m >= 0 && _to[_m] == NULLVALUE; _m--) {  \
 310               _to[_m] = PADDING;                                 \
 311          }                                                       \
 312      } while (0)
 313  a1/*
 314  STRINGCOPYN copies N bytes.
 315  
 316  `to` and `from` buffers must have sizes of at least N bytes.
 317  */
 318  #define STRINGCOPYN(to,from,N)                                  \
 319      do {                                                        \
 320          int _m = (N);                                           \
 321          char *_to = (to);                                       \
 322          char *_from = (from);                                   \
 323          FAILNULL(_to); FAILNULL(_from);                         \
 324          (void)strncpy(_to, _from, _m);             \
 325      } while (0)
 326  Z
 327  STRINGCOPYzg#define STRINGCOPY(to,from)\
 328      do { FAILNULL(to); FAILNULL(from); (void)strcpy(to,from); } while (0)
 329  z�#define CHECKGENERIC(check,tcheck,name) \
 330      if (!(check)) {\
 331          PyErr_SetString(#modulename#_error,"("tcheck") failed for "name);\
 332          /*goto capi_fail;*/\
 333      } else �CHECKGENERICz�#define CHECKARRAY(check,tcheck,name) \
 334      if (!(check)) {\
 335          PyErr_SetString(#modulename#_error,"("tcheck") failed for "name);\
 336          /*goto capi_fail;*/\
 337      } else �
 338  CHECKARRAYa#define CHECKSTRING(check,tcheck,name,show,var)\
 339      if (!(check)) {\
 340          char errstring[256];\
 341          sprintf(errstring, "%s: "show, "("tcheck") failed for "name, slen(var), var);\
 342          PyErr_SetString(#modulename#_error, errstring);\
 343          /*goto capi_fail;*/\
 344      } else �CHECKSTRINGa#define CHECKSCALAR(check,tcheck,name,show,var)\
 345      if (!(check)) {\
 346          char errstring[256];\
 347          sprintf(errstring, "%s: "show, "("tcheck") failed for "name, var);\
 348          PyErr_SetString(#modulename#_error,errstring);\
 349          /*goto capi_fail;*/\
 350      } else �CHECKSCALARz>#define ARRSIZE(dims,rank) (_PyArray_multiply_list(dims,rank))ZARRSIZEzs#ifdef OLDPYNUM
 351  #error You need to install NumPy version 0.13 or higher. See https://scipy.org/install.html
 352  #endif
 353  ZOLDPYNUMa�#ifndef F2PY_THREAD_LOCAL_DECL
 354  #if defined(_MSC_VER)
 355  #define F2PY_THREAD_LOCAL_DECL __declspec(thread)
 356  #elif defined(NPY_OS_MINGW)
 357  #define F2PY_THREAD_LOCAL_DECL __thread
 358  #elif defined(__STDC_VERSION__) \
 359        && (__STDC_VERSION__ >= 201112L) \
 360        && !defined(__STDC_NO_THREADS__) \
 361        && (!defined(__GLIBC__) || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 12)) \
 362        && !defined(NPY_OS_OPENBSD) && !defined(NPY_OS_HAIKU)
 363  /* __STDC_NO_THREADS__ was first defined in a maintenance release of glibc 2.12,
 364     see https://lists.gnu.org/archive/html/commit-hurd/2012-07/msg00180.html,
 365     so `!defined(__STDC_NO_THREADS__)` may give false positive for the existence
 366     of `threads.h` when using an older release of glibc 2.12
 367     See gh-19437 for details on OpenBSD */
 368  #include <threads.h>
 369  #define F2PY_THREAD_LOCAL_DECL thread_local
 370  #elif defined(__GNUC__) \
 371        && (__GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 4)))
 372  #define F2PY_THREAD_LOCAL_DECL __thread
 373  #endif
 374  #endif
 375  �F2PY_THREAD_LOCAL_DECLz�static int calcarrindex(int *i,PyArrayObject *arr) {
 376      int k,ii = i[0];
 377      for (k=1; k < PyArray_NDIM(arr); k++)
 378          ii += (ii*(PyArray_DIM(arr,k) - 1)+i[k]); /* assuming contiguous arr */
 379      return ii;
 380  }Zcalcarrindexastatic int calcarrindextr(int *i,PyArrayObject *arr) {
 381      int k,ii = i[PyArray_NDIM(arr)-1];
 382      for (k=1; k < PyArray_NDIM(arr); k++)
 383          ii += (ii*(PyArray_DIM(arr,PyArray_NDIM(arr)-k-1) - 1)+i[PyArray_NDIM(arr)-k-1]); /* assuming contiguous arr */
 384      return ii;
 385  }ZcalcarrindextraTstatic struct { int nd;npy_intp *d;int *i,*i_tr,tr; } forcombcache;
 386  static int initforcomb(npy_intp *dims,int nd,int tr) {
 387    int k;
 388    if (dims==NULL) return 0;
 389    if (nd<0) return 0;
 390    forcombcache.nd = nd;
 391    forcombcache.d = dims;
 392    forcombcache.tr = tr;
 393    if ((forcombcache.i = (int *)malloc(sizeof(int)*nd))==NULL) return 0;
 394    if ((forcombcache.i_tr = (int *)malloc(sizeof(int)*nd))==NULL) return 0;
 395    for (k=1;k<nd;k++) {
 396      forcombcache.i[k] = forcombcache.i_tr[nd-k-1] = 0;
 397    }
 398    forcombcache.i[0] = forcombcache.i_tr[nd-1] = -1;
 399    return 1;
 400  }
 401  static int *nextforcomb(void) {
 402    int j,*i,*i_tr,k;
 403    int nd=forcombcache.nd;
 404    if ((i=forcombcache.i) == NULL) return NULL;
 405    if ((i_tr=forcombcache.i_tr) == NULL) return NULL;
 406    if (forcombcache.d == NULL) return NULL;
 407    i[0]++;
 408    if (i[0]==forcombcache.d[0]) {
 409      j=1;
 410      while ((j<nd) && (i[j]==forcombcache.d[j]-1)) j++;
 411      if (j==nd) {
 412        free(i);
 413        free(i_tr);
 414        return NULL;
 415      }
 416      for (k=0;k<j;k++) i[k] = i_tr[nd-k-1] = 0;
 417      i[j]++;
 418      i_tr[nd-j-1]++;
 419    } else
 420      i_tr[nd-1]++;
 421    if (forcombcache.tr) return i_tr;
 422    return i;
 423  }�forcomb)r'r rZtry_pyarr_from_stringa�/*
 424    try_pyarr_from_string copies str[:len(obj)] to the data of an `ndarray`.
 425  
 426    If obj is an `ndarray`, it is assumed to be contiguous.
 427  
 428    If the specified len==-1, str must be null-terminated.
 429  */
 430  static int try_pyarr_from_string(PyObject *obj,
 431                                   const string str, const int len) {
 432  #ifdef DEBUGCFUNCS
 433  fprintf(stderr, "try_pyarr_from_string(str='%s', len=%d, obj=%p)\n",
 434          (char*)str,len, obj);
 435  #endif
 436      if (PyArray_Check(obj)) {
 437          PyArrayObject *arr = (PyArrayObject *)obj;
 438          assert(ISCONTIGUOUS(arr));
 439          string buf = PyArray_DATA(arr);
 440          npy_intp n = len;
 441          if (n == -1) {
 442              /* Assuming null-terminated str. */
 443              n = strlen(str);
 444          }
 445          if (n > PyArray_NBYTES(arr)) {
 446              n = PyArray_NBYTES(arr);
 447          }
 448          STRINGCOPYN(buf, str, n);
 449          return 1;
 450      }
 451  capi_fail:
 452      PRINTPYOBJERR(obj);
 453      PyErr_SetString(#modulename#_error, "try_pyarr_from_string failed");
 454      return 0;
 455  }
 456  )rr+r'Zstring_from_pyobja�
 457  /*
 458    Create a new string buffer `str` of at most length `len` from a
 459    Python string-like object `obj`.
 460  
 461    The string buffer has given size (len) or the size of inistr when len==-1.
 462  
 463    The string buffer is padded with blanks: in Fortran, trailing blanks
 464    are insignificant contrary to C nulls.
 465   */
 466  static int
 467  string_from_pyobj(string *str, int *len, const string inistr, PyObject *obj,
 468                    const char *errmess)
 469  {
 470      PyObject *tmp = NULL;
 471      string buf = NULL;
 472      npy_intp n = -1;
 473  #ifdef DEBUGCFUNCS
 474  fprintf(stderr,"string_from_pyobj(str='%s',len=%d,inistr='%s',obj=%p)\n",
 475                 (char*)str, *len, (char *)inistr, obj);
 476  #endif
 477      if (obj == Py_None) {
 478          n = strlen(inistr);
 479          buf = inistr;
 480      }
 481      else if (PyArray_Check(obj)) {
 482          PyArrayObject *arr = (PyArrayObject *)obj;
 483          if (!ISCONTIGUOUS(arr)) {
 484              PyErr_SetString(PyExc_ValueError,
 485                              "array object is non-contiguous.");
 486              goto capi_fail;
 487          }
 488          n = PyArray_NBYTES(arr);
 489          buf = PyArray_DATA(arr);
 490          n = strnlen(buf, n);
 491      }
 492      else {
 493          if (PyBytes_Check(obj)) {
 494              tmp = obj;
 495              Py_INCREF(tmp);
 496          }
 497          else if (PyUnicode_Check(obj)) {
 498              tmp = PyUnicode_AsASCIIString(obj);
 499          }
 500          else {
 501              PyObject *tmp2;
 502              tmp2 = PyObject_Str(obj);
 503              if (tmp2) {
 504                  tmp = PyUnicode_AsASCIIString(tmp2);
 505                  Py_DECREF(tmp2);
 506              }
 507              else {
 508                  tmp = NULL;
 509              }
 510          }
 511          if (tmp == NULL) goto capi_fail;
 512          n = PyBytes_GET_SIZE(tmp);
 513          buf = PyBytes_AS_STRING(tmp);
 514      }
 515      if (*len == -1) {
 516          /* TODO: change the type of `len` so that we can remove this */
 517          if (n > NPY_MAX_INT) {
 518              PyErr_SetString(PyExc_OverflowError,
 519                              "object too large for a 32-bit int");
 520              goto capi_fail;
 521          }
 522          *len = n;
 523      }
 524      else if (*len < n) {
 525          /* discard the last (len-n) bytes of input buf */
 526          n = *len;
 527      }
 528      if (n < 0 || *len < 0 || buf == NULL) {
 529          goto capi_fail;
 530      }
 531      STRINGMALLOC(*str, *len);  // *str is allocated with size (*len + 1)
 532      if (n < *len) {
 533          /*
 534            Pad fixed-width string with nulls. The caller will replace
 535            nulls with blanks when the corresponding argument is not
 536            intent(c).
 537          */
 538          memset(*str + n, '\0', *len - n);
 539      }
 540      STRINGCOPYN(*str, buf, n);
 541      Py_XDECREF(tmp);
 542      return 1;
 543  capi_fail:
 544      Py_XDECREF(tmp);
 545      {
 546          PyObject* err = PyErr_Occurred();
 547          if (err == NULL) {
 548              err = #modulename#_error;
 549          }
 550          PyErr_SetString(err, errmess);
 551      }
 552      return 0;
 553  }
 554  a�static int
 555  character_from_pyobj(character* v, PyObject *obj, const char *errmess) {
 556      if (PyBytes_Check(obj)) {
 557          /* empty bytes has trailing null, so dereferencing is always safe */
 558          *v = PyBytes_AS_STRING(obj)[0];
 559          return 1;
 560      } else if (PyUnicode_Check(obj)) {
 561          PyObject* tmp = PyUnicode_AsASCIIString(obj);
 562          if (tmp != NULL) {
 563              *v = PyBytes_AS_STRING(tmp)[0];
 564              Py_DECREF(tmp);
 565              return 1;
 566          }
 567      } else if (PyArray_Check(obj)) {
 568          PyArrayObject* arr = (PyArrayObject*)obj;
 569          if (F2PY_ARRAY_IS_CHARACTER_COMPATIBLE(arr)) {
 570              *v = PyArray_BYTES(arr)[0];
 571              return 1;
 572          } else if (F2PY_IS_UNICODE_ARRAY(arr)) {
 573              // TODO: update when numpy will support 1-byte and
 574              // 2-byte unicode dtypes
 575              PyObject* tmp = PyUnicode_FromKindAndData(
 576                                PyUnicode_4BYTE_KIND,
 577                                PyArray_BYTES(arr),
 578                                (PyArray_NBYTES(arr)>0?1:0));
 579              if (tmp != NULL) {
 580                  if (character_from_pyobj(v, tmp, errmess)) {
 581                      Py_DECREF(tmp);
 582                      return 1;
 583                  }
 584                  Py_DECREF(tmp);
 585              }
 586          }
 587      } else if (PySequence_Check(obj)) {
 588          PyObject* tmp = PySequence_GetItem(obj,0);
 589          if (tmp != NULL) {
 590              if (character_from_pyobj(v, tmp, errmess)) {
 591                  Py_DECREF(tmp);
 592                  return 1;
 593              }
 594              Py_DECREF(tmp);
 595          }
 596      }
 597      {
 598          char mess[F2PY_MESSAGE_BUFFER_SIZE];
 599          strcpy(mess, errmess);
 600          PyObject* err = PyErr_Occurred();
 601          if (err == NULL) {
 602              err = PyExc_TypeError;
 603          }
 604          sprintf(mess + strlen(mess),
 605                  " -- expected str|bytes|sequence-of-str-or-bytes, got ");
 606          f2py_describe(obj, mess + strlen(mess));
 607          PyErr_SetString(err, mess);
 608      }
 609      return 0;
 610  }
 611  Zcharacter_from_pyobjZint_from_pyobjZchar_from_pyobjz�static int
 612  char_from_pyobj(char* v, PyObject *obj, const char *errmess) {
 613      int i = 0;
 614      if (int_from_pyobj(&i, obj, errmess)) {
 615          *v = (char)i;
 616          return 1;
 617      }
 618      return 0;
 619  }
 620  Zsigned_char_from_pyobjz�static int
 621  signed_char_from_pyobj(signed_char* v, PyObject *obj, const char *errmess) {
 622      int i = 0;
 623      if (int_from_pyobj(&i, obj, errmess)) {
 624          *v = (signed_char)i;
 625          return 1;
 626      }
 627      return 0;
 628  }
 629  Zshort_from_pyobjz�static int
 630  short_from_pyobj(short* v, PyObject *obj, const char *errmess) {
 631      int i = 0;
 632      if (int_from_pyobj(&i, obj, errmess)) {
 633          *v = (short)i;
 634          return 1;
 635      }
 636      return 0;
 637  }
 638  a�static int
 639  int_from_pyobj(int* v, PyObject *obj, const char *errmess)
 640  {
 641      PyObject* tmp = NULL;
 642  
 643      if (PyLong_Check(obj)) {
 644          *v = Npy__PyLong_AsInt(obj);
 645          return !(*v == -1 && PyErr_Occurred());
 646      }
 647  
 648      tmp = PyNumber_Long(obj);
 649      if (tmp) {
 650          *v = Npy__PyLong_AsInt(tmp);
 651          Py_DECREF(tmp);
 652          return !(*v == -1 && PyErr_Occurred());
 653      }
 654  
 655      if (PyComplex_Check(obj)) {
 656          PyErr_Clear();
 657          tmp = PyObject_GetAttrString(obj,"real");
 658      }
 659      else if (PyBytes_Check(obj) || PyUnicode_Check(obj)) {
 660          /*pass*/;
 661      }
 662      else if (PySequence_Check(obj)) {
 663          PyErr_Clear();
 664          tmp = PySequence_GetItem(obj, 0);
 665      }
 666  
 667      if (tmp) {
 668          if (int_from_pyobj(v, tmp, errmess)) {
 669              Py_DECREF(tmp);
 670              return 1;
 671          }
 672          Py_DECREF(tmp);
 673      }
 674  
 675      {
 676          PyObject* err = PyErr_Occurred();
 677          if (err == NULL) {
 678              err = #modulename#_error;
 679          }
 680          PyErr_SetString(err, errmess);
 681      }
 682      return 0;
 683  }
 684  a�static int
 685  long_from_pyobj(long* v, PyObject *obj, const char *errmess) {
 686      PyObject* tmp = NULL;
 687  
 688      if (PyLong_Check(obj)) {
 689          *v = PyLong_AsLong(obj);
 690          return !(*v == -1 && PyErr_Occurred());
 691      }
 692  
 693      tmp = PyNumber_Long(obj);
 694      if (tmp) {
 695          *v = PyLong_AsLong(tmp);
 696          Py_DECREF(tmp);
 697          return !(*v == -1 && PyErr_Occurred());
 698      }
 699  
 700      if (PyComplex_Check(obj)) {
 701          PyErr_Clear();
 702          tmp = PyObject_GetAttrString(obj,"real");
 703      }
 704      else if (PyBytes_Check(obj) || PyUnicode_Check(obj)) {
 705          /*pass*/;
 706      }
 707      else if (PySequence_Check(obj)) {
 708          PyErr_Clear();
 709          tmp = PySequence_GetItem(obj, 0);
 710      }
 711  
 712      if (tmp) {
 713          if (long_from_pyobj(v, tmp, errmess)) {
 714              Py_DECREF(tmp);
 715              return 1;
 716          }
 717          Py_DECREF(tmp);
 718      }
 719      {
 720          PyObject* err = PyErr_Occurred();
 721          if (err == NULL) {
 722              err = #modulename#_error;
 723          }
 724          PyErr_SetString(err, errmess);
 725      }
 726      return 0;
 727  }
 728  Zlong_from_pyobjZlong_long_from_pyobjastatic int
 729  long_long_from_pyobj(long_long* v, PyObject *obj, const char *errmess)
 730  {
 731      PyObject* tmp = NULL;
 732  
 733      if (PyLong_Check(obj)) {
 734          *v = PyLong_AsLongLong(obj);
 735          return !(*v == -1 && PyErr_Occurred());
 736      }
 737  
 738      tmp = PyNumber_Long(obj);
 739      if (tmp) {
 740          *v = PyLong_AsLongLong(tmp);
 741          Py_DECREF(tmp);
 742          return !(*v == -1 && PyErr_Occurred());
 743      }
 744  
 745      if (PyComplex_Check(obj)) {
 746          PyErr_Clear();
 747          tmp = PyObject_GetAttrString(obj,"real");
 748      }
 749      else if (PyBytes_Check(obj) || PyUnicode_Check(obj)) {
 750          /*pass*/;
 751      }
 752      else if (PySequence_Check(obj)) {
 753          PyErr_Clear();
 754          tmp = PySequence_GetItem(obj, 0);
 755      }
 756  
 757      if (tmp) {
 758          if (long_long_from_pyobj(v, tmp, errmess)) {
 759              Py_DECREF(tmp);
 760              return 1;
 761          }
 762          Py_DECREF(tmp);
 763      }
 764      {
 765          PyObject* err = PyErr_Occurred();
 766          if (err == NULL) {
 767              err = #modulename#_error;
 768          }
 769          PyErr_SetString(err,errmess);
 770      }
 771      return 0;
 772  }
 773  Zdouble_from_pyobjZlong_double_from_pyobja(static int
 774  long_double_from_pyobj(long_double* v, PyObject *obj, const char *errmess)
 775  {
 776      double d=0;
 777      if (PyArray_CheckScalar(obj)){
 778          if PyArray_IsScalar(obj, LongDouble) {
 779              PyArray_ScalarAsCtype(obj, v);
 780              return 1;
 781          }
 782          else if (PyArray_Check(obj) && PyArray_TYPE(obj) == NPY_LONGDOUBLE) {
 783              (*v) = *((npy_longdouble *)PyArray_DATA(obj));
 784              return 1;
 785          }
 786      }
 787      if (double_from_pyobj(&d, obj, errmess)) {
 788          *v = (long_double)d;
 789          return 1;
 790      }
 791      return 0;
 792  }
 793  a�static int
 794  double_from_pyobj(double* v, PyObject *obj, const char *errmess)
 795  {
 796      PyObject* tmp = NULL;
 797      if (PyFloat_Check(obj)) {
 798          *v = PyFloat_AsDouble(obj);
 799          return !(*v == -1.0 && PyErr_Occurred());
 800      }
 801  
 802      tmp = PyNumber_Float(obj);
 803      if (tmp) {
 804          *v = PyFloat_AsDouble(tmp);
 805          Py_DECREF(tmp);
 806          return !(*v == -1.0 && PyErr_Occurred());
 807      }
 808  
 809      if (PyComplex_Check(obj)) {
 810          PyErr_Clear();
 811          tmp = PyObject_GetAttrString(obj,"real");
 812      }
 813      else if (PyBytes_Check(obj) || PyUnicode_Check(obj)) {
 814          /*pass*/;
 815      }
 816      else if (PySequence_Check(obj)) {
 817          PyErr_Clear();
 818          tmp = PySequence_GetItem(obj, 0);
 819      }
 820  
 821      if (tmp) {
 822          if (double_from_pyobj(v,tmp,errmess)) {Py_DECREF(tmp); return 1;}
 823          Py_DECREF(tmp);
 824      }
 825      {
 826          PyObject* err = PyErr_Occurred();
 827          if (err==NULL) err = #modulename#_error;
 828          PyErr_SetString(err,errmess);
 829      }
 830      return 0;
 831  }
 832  Zfloat_from_pyobjz�static int
 833  float_from_pyobj(float* v, PyObject *obj, const char *errmess)
 834  {
 835      double d=0.0;
 836      if (double_from_pyobj(&d,obj,errmess)) {
 837          *v = (float)d;
 838          return 1;
 839      }
 840      return 0;
 841  }
 842  )rr�complex_double_from_pyobjZcomplex_long_double_from_pyobja�static int
 843  complex_long_double_from_pyobj(complex_long_double* v, PyObject *obj, const char *errmess)
 844  {
 845      complex_double cd = {0.0,0.0};
 846      if (PyArray_CheckScalar(obj)){
 847          if PyArray_IsScalar(obj, CLongDouble) {
 848              PyArray_ScalarAsCtype(obj, v);
 849              return 1;
 850          }
 851          else if (PyArray_Check(obj) && PyArray_TYPE(obj)==NPY_CLONGDOUBLE) {
 852              (*v).r = ((npy_clongdouble *)PyArray_DATA(obj))->real;
 853              (*v).i = ((npy_clongdouble *)PyArray_DATA(obj))->imag;
 854              return 1;
 855          }
 856      }
 857      if (complex_double_from_pyobj(&cd,obj,errmess)) {
 858          (*v).r = (long_double)cd.r;
 859          (*v).i = (long_double)cd.i;
 860          return 1;
 861      }
 862      return 0;
 863  }
 864  r4a�static int
 865  complex_double_from_pyobj(complex_double* v, PyObject *obj, const char *errmess) {
 866      Py_complex c;
 867      if (PyComplex_Check(obj)) {
 868          c = PyComplex_AsCComplex(obj);
 869          (*v).r = c.real;
 870          (*v).i = c.imag;
 871          return 1;
 872      }
 873      if (PyArray_IsScalar(obj, ComplexFloating)) {
 874          if (PyArray_IsScalar(obj, CFloat)) {
 875              npy_cfloat new;
 876              PyArray_ScalarAsCtype(obj, &new);
 877              (*v).r = (double)new.real;
 878              (*v).i = (double)new.imag;
 879          }
 880          else if (PyArray_IsScalar(obj, CLongDouble)) {
 881              npy_clongdouble new;
 882              PyArray_ScalarAsCtype(obj, &new);
 883              (*v).r = (double)new.real;
 884              (*v).i = (double)new.imag;
 885          }
 886          else { /* if (PyArray_IsScalar(obj, CDouble)) */
 887              PyArray_ScalarAsCtype(obj, v);
 888          }
 889          return 1;
 890      }
 891      if (PyArray_CheckScalar(obj)) { /* 0-dim array or still array scalar */
 892          PyArrayObject *arr;
 893          if (PyArray_Check(obj)) {
 894              arr = (PyArrayObject *)PyArray_Cast((PyArrayObject *)obj, NPY_CDOUBLE);
 895          }
 896          else {
 897              arr = (PyArrayObject *)PyArray_FromScalar(obj, PyArray_DescrFromType(NPY_CDOUBLE));
 898          }
 899          if (arr == NULL) {
 900              return 0;
 901          }
 902          (*v).r = ((npy_cdouble *)PyArray_DATA(arr))->real;
 903          (*v).i = ((npy_cdouble *)PyArray_DATA(arr))->imag;
 904          Py_DECREF(arr);
 905          return 1;
 906      }
 907      /* Python does not provide PyNumber_Complex function :-( */
 908      (*v).i = 0.0;
 909      if (PyFloat_Check(obj)) {
 910          (*v).r = PyFloat_AsDouble(obj);
 911          return !((*v).r == -1.0 && PyErr_Occurred());
 912      }
 913      if (PyLong_Check(obj)) {
 914          (*v).r = PyLong_AsDouble(obj);
 915          return !((*v).r == -1.0 && PyErr_Occurred());
 916      }
 917      if (PySequence_Check(obj) && !(PyBytes_Check(obj) || PyUnicode_Check(obj))) {
 918          PyObject *tmp = PySequence_GetItem(obj,0);
 919          if (tmp) {
 920              if (complex_double_from_pyobj(v,tmp,errmess)) {
 921                  Py_DECREF(tmp);
 922                  return 1;
 923              }
 924              Py_DECREF(tmp);
 925          }
 926      }
 927      {
 928          PyObject* err = PyErr_Occurred();
 929          if (err==NULL)
 930              err = PyExc_TypeError;
 931          PyErr_SetString(err,errmess);
 932      }
 933      return 0;
 934  }
 935  Zcomplex_float_from_pyobjastatic int
 936  complex_float_from_pyobj(complex_float* v,PyObject *obj,const char *errmess)
 937  {
 938      complex_double cd={0.0,0.0};
 939      if (complex_double_from_pyobj(&cd,obj,errmess)) {
 940          (*v).r = (float)cd.r;
 941          (*v).i = (float)cd.i;
 942          return 1;
 943      }
 944      return 0;
 945  }
 946  a�static int try_pyarr_from_character(PyObject* obj, character* v) {
 947      PyArrayObject *arr = (PyArrayObject*)obj;
 948      if (!obj) return -2;
 949      if (PyArray_Check(obj)) {
 950          if (F2PY_ARRAY_IS_CHARACTER_COMPATIBLE(arr))  {
 951              *(character *)(PyArray_DATA(arr)) = *v;
 952              return 1;
 953          }
 954      }
 955      {
 956          char mess[F2PY_MESSAGE_BUFFER_SIZE];
 957          PyObject* err = PyErr_Occurred();
 958          if (err == NULL) {
 959              err = PyExc_ValueError;
 960              strcpy(mess, "try_pyarr_from_character failed"
 961                           " -- expected bytes array-scalar|array, got ");
 962              f2py_describe(obj, mess + strlen(mess));
 963          }
 964          PyErr_SetString(err, mess);
 965      }
 966      return 0;
 967  }
 968  Ztry_pyarr_from_characterZtry_pyarr_from_charz\static int try_pyarr_from_char(PyObject* obj,char* v) {
 969      TRYPYARRAYTEMPLATE(char,'c');
 970  }
 971  Ztry_pyarr_from_signed_charzwstatic int try_pyarr_from_unsigned_char(PyObject* obj,unsigned_char* v) {
 972      TRYPYARRAYTEMPLATE(unsigned_char,'b');
 973  }
 974  Ztry_pyarr_from_unsigned_charzqstatic int try_pyarr_from_signed_char(PyObject* obj,signed_char* v) {
 975      TRYPYARRAYTEMPLATE(signed_char,'1');
 976  }
 977  Ztry_pyarr_from_shortz_static int try_pyarr_from_short(PyObject* obj,short* v) {
 978      TRYPYARRAYTEMPLATE(short,'s');
 979  }
 980  Ztry_pyarr_from_intzYstatic int try_pyarr_from_int(PyObject* obj,int* v) {
 981      TRYPYARRAYTEMPLATE(int,'i');
 982  }
 983  Ztry_pyarr_from_longz\static int try_pyarr_from_long(PyObject* obj,long* v) {
 984      TRYPYARRAYTEMPLATE(long,'l');
 985  }
 986  )r"r%rZtry_pyarr_from_long_longzkstatic int try_pyarr_from_long_long(PyObject* obj,long_long* v) {
 987      TRYPYARRAYTEMPLATE(long_long,'L');
 988  }
 989  Ztry_pyarr_from_floatz_static int try_pyarr_from_float(PyObject* obj,float* v) {
 990      TRYPYARRAYTEMPLATE(float,'f');
 991  }
 992  Ztry_pyarr_from_doublezbstatic int try_pyarr_from_double(PyObject* obj,double* v) {
 993      TRYPYARRAYTEMPLATE(double,'d');
 994  }
 995  )r$r&rZtry_pyarr_from_complex_floatzvstatic int try_pyarr_from_complex_float(PyObject* obj,complex_float* v) {
 996      TRYCOMPLEXPYARRAYTEMPLATE(float,'F');
 997  }
 998  )r#r&rZtry_pyarr_from_complex_doublezystatic int try_pyarr_from_complex_double(PyObject* obj,complex_double* v) {
 999      TRYCOMPLEXPYARRAYTEMPLATE(double,'D');
1000  }
1001  )rr r!�create_cb_arglistaFstatic int
1002  create_cb_arglist(PyObject* fun, PyTupleObject* xa , const int maxnofargs,
1003                    const int nofoptargs, int *nofargs, PyTupleObject **args,
1004                    const char *errmess)
1005  {
1006      PyObject *tmp = NULL;
1007      PyObject *tmp_fun = NULL;
1008      Py_ssize_t tot, opt, ext, siz, i, di = 0;
1009      CFUNCSMESS("create_cb_arglist\n");
1010      tot=opt=ext=siz=0;
1011      /* Get the total number of arguments */
1012      if (PyFunction_Check(fun)) {
1013          tmp_fun = fun;
1014          Py_INCREF(tmp_fun);
1015      }
1016      else {
1017          di = 1;
1018          if (PyObject_HasAttrString(fun,"im_func")) {
1019              tmp_fun = PyObject_GetAttrString(fun,"im_func");
1020          }
1021          else if (PyObject_HasAttrString(fun,"__call__")) {
1022              tmp = PyObject_GetAttrString(fun,"__call__");
1023              if (PyObject_HasAttrString(tmp,"im_func"))
1024                  tmp_fun = PyObject_GetAttrString(tmp,"im_func");
1025              else {
1026                  tmp_fun = fun; /* built-in function */
1027                  Py_INCREF(tmp_fun);
1028                  tot = maxnofargs;
1029                  if (PyCFunction_Check(fun)) {
1030                      /* In case the function has a co_argcount (like on PyPy) */
1031                      di = 0;
1032                  }
1033                  if (xa != NULL)
1034                      tot += PyTuple_Size((PyObject *)xa);
1035              }
1036              Py_XDECREF(tmp);
1037          }
1038          else if (PyFortran_Check(fun) || PyFortran_Check1(fun)) {
1039              tot = maxnofargs;
1040              if (xa != NULL)
1041                  tot += PyTuple_Size((PyObject *)xa);
1042              tmp_fun = fun;
1043              Py_INCREF(tmp_fun);
1044          }
1045          else if (F2PyCapsule_Check(fun)) {
1046              tot = maxnofargs;
1047              if (xa != NULL)
1048                  ext = PyTuple_Size((PyObject *)xa);
1049              if(ext>0) {
1050                  fprintf(stderr,"extra arguments tuple cannot be used with PyCapsule call-back\n");
1051                  goto capi_fail;
1052              }
1053              tmp_fun = fun;
1054              Py_INCREF(tmp_fun);
1055          }
1056      }
1057  
1058      if (tmp_fun == NULL) {
1059          fprintf(stderr,
1060                  "Call-back argument must be function|instance|instance.__call__|f2py-function "
1061                  "but got %s.\n",
1062                  ((fun == NULL) ? "NULL" : Py_TYPE(fun)->tp_name));
1063          goto capi_fail;
1064      }
1065  
1066      if (PyObject_HasAttrString(tmp_fun,"__code__")) {
1067          if (PyObject_HasAttrString(tmp = PyObject_GetAttrString(tmp_fun,"__code__"),"co_argcount")) {
1068              PyObject *tmp_argcount = PyObject_GetAttrString(tmp,"co_argcount");
1069              Py_DECREF(tmp);
1070              if (tmp_argcount == NULL) {
1071                  goto capi_fail;
1072              }
1073              tot = PyLong_AsSsize_t(tmp_argcount) - di;
1074              Py_DECREF(tmp_argcount);
1075          }
1076      }
1077      /* Get the number of optional arguments */
1078      if (PyObject_HasAttrString(tmp_fun,"__defaults__")) {
1079          if (PyTuple_Check(tmp = PyObject_GetAttrString(tmp_fun,"__defaults__")))
1080              opt = PyTuple_Size(tmp);
1081          Py_XDECREF(tmp);
1082      }
1083      /* Get the number of extra arguments */
1084      if (xa != NULL)
1085          ext = PyTuple_Size((PyObject *)xa);
1086      /* Calculate the size of call-backs argument list */
1087      siz = MIN(maxnofargs+ext,tot);
1088      *nofargs = MAX(0,siz-ext);
1089  
1090  #ifdef DEBUGCFUNCS
1091      fprintf(stderr,
1092              "debug-capi:create_cb_arglist:maxnofargs(-nofoptargs),"
1093              "tot,opt,ext,siz,nofargs = %d(-%d), %zd, %zd, %zd, %zd, %d\n",
1094              maxnofargs, nofoptargs, tot, opt, ext, siz, *nofargs);
1095  #endif
1096  
1097      if (siz < tot-opt) {
1098          fprintf(stderr,
1099                  "create_cb_arglist: Failed to build argument list "
1100                  "(siz) with enough arguments (tot-opt) required by "
1101                  "user-supplied function (siz,tot,opt=%zd, %zd, %zd).\n",
1102                  siz, tot, opt);
1103          goto capi_fail;
1104      }
1105  
1106      /* Initialize argument list */
1107      *args = (PyTupleObject *)PyTuple_New(siz);
1108      for (i=0;i<*nofargs;i++) {
1109          Py_INCREF(Py_None);
1110          PyTuple_SET_ITEM((PyObject *)(*args),i,Py_None);
1111      }
1112      if (xa != NULL)
1113          for (i=(*nofargs);i<siz;i++) {
1114              tmp = PyTuple_GetItem((PyObject *)xa,i-(*nofargs));
1115              Py_INCREF(tmp);
1116              PyTuple_SET_ITEM(*args,i,tmp);
1117          }
1118      CFUNCSMESS("create_cb_arglist-end\n");
1119      Py_DECREF(tmp_fun);
1120      return 1;
1121  
1122  capi_fail:
1123      if (PyErr_Occurred() == NULL)
1124          PyErr_SetString(#modulename#_error, errmess);
1125      Py_XDECREF(tmp_fun);
1126      return 0;
1127  }
1128  cCsRddlm}|��D]}d|}d|||ft|<q
1129  d}d|}d|t|<dS)Nr)�
1130  c2capi_mapzpyarr_from_p_%s1z>#define %s(v) (PyArray_SimpleNewFromData(0,NULL,%s,(char *)v))rzh#define %s(v,dims) (PyArray_New(&PyArray_Type, 1, dims, NPY_STRING, NULL, v, 1, NPY_ARRAY_CARRAY, NULL)))�	capi_mapsr6�keysr	)r6�k�m�r;��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\numpy\f2py\cfuncs.py�buildcfuncs�s����r=cCs,t|t�r|D]}t||�qdSt|t��r|sdS|tvr"d}nB|tvr)d}n;|tvr0d}n4|tvr7d}n-|tvr>d}n&|t	vrEd}n|t
1131  vrLd}n|tvrSd}n|tvrZd	}n
1132  t
d
1133  t|��dS|t|vrldS|r�i}|tvr�t|D](}t|d�}t|t�r�|��D]}||vr�||||||<q�||||<q�qx|��D]}||D]}|t|vr�|gt|t|<q�q�t|�|�dSi}|tvr�t|D](}t||�}t|t�r�|��D]}||vr�||||||<q�||||<q�q�||v�rg||<||�|�|St
dt|��dS)
Nrrrrr	r
1134  rrr
zappend_needs: unknown need %s
1135  rz2append_needs: expected list or string but got :%s
1136  )�
1137  isinstance�list�append_needs�strrrrrr	r
1138  rrr
�errmess�repr�outneeds�needs�dictr8�append)�need�flag�n�tmp�nn�tZnnnr;r;r<r@�s�
1139  �
1140  
1141  ���
1142  
1143  �
1144  
1145  �r@cCsXi}t��D]�}g}t�t|�}tt|�dkr�t|dtvr0|�t|d�t|d=n=d}t|dd�D]}|tt|dvrJd}nq:|r_t|dd�t|dgt|<n|�t|d�t|d=|r�dtdd�|t|�vr�t|gkr�t||�td�||}nt�t|�}tt|�dks|gkr�|g}|||<q|S)NrrcSs||kS)Nr;)�x�yr;r;r<�<lambda>�szget_needs.<locals>.<lambda>zQget_needs: no progress in sorting needs, probably circular dependence, skipping.
1146  )	rDr8�copy�lenrErG�map�printrB)�resrJ�outZsaveoutrIr9r;r;r<�	get_needs�s@�$
1147  
1148  ��
1149  rW)r)�__doc__�sysrQ�r�version�f2py_version�stderr�writerBrDrErrrrrr	r
1150  rrr
r=r@rWr;r;r;r<�<module>s������$$"	����
1151  ��
1152  
1153  ������
1154  ��
1155  ��
1156  ��
1157  ��
1158  ��
1159  
1160  $J	
1161  ��(#d
1162  <

1163  

2
1164  01
1165  +
1166  L�����������������������
1167  C