U
    #ºcí  ã                   @   sR   d dl Z d dlZd dlmZmZmZmZ d dlZdZdZdZ	ddd„Z
d	d
„ ZdS )é    N)ÚTypeApiÚGlobalVarApiÚFunctionApiÚBoolValuesApia¾  
#if defined(_MULTIARRAYMODULE) || defined(WITH_CPYCHECKER_STEALS_REFERENCE_TO_ARG_ATTRIBUTE)

typedef struct {
        PyObject_HEAD
        npy_bool obval;
} PyBoolScalarObject;

extern NPY_NO_EXPORT PyTypeObject PyArrayMapIter_Type;
extern NPY_NO_EXPORT PyTypeObject PyArrayNeighborhoodIter_Type;
extern NPY_NO_EXPORT PyBoolScalarObject _PyArrayScalar_BoolValues[2];

%s

#else

#if defined(PY_ARRAY_UNIQUE_SYMBOL)
#define PyArray_API PY_ARRAY_UNIQUE_SYMBOL
#endif

#if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)
extern void **PyArray_API;
#else
#if defined(PY_ARRAY_UNIQUE_SYMBOL)
void **PyArray_API;
#else
static void **PyArray_API=NULL;
#endif
#endif

%s

#if !defined(NO_IMPORT_ARRAY) && !defined(NO_IMPORT)
static int
_import_array(void)
{
  int st;
  PyObject *numpy = PyImport_ImportModule("numpy.core._multiarray_umath");
  PyObject *c_api = NULL;

  if (numpy == NULL) {
      return -1;
  }
  c_api = PyObject_GetAttrString(numpy, "_ARRAY_API");
  Py_DECREF(numpy);
  if (c_api == NULL) {
      PyErr_SetString(PyExc_AttributeError, "_ARRAY_API not found");
      return -1;
  }

  if (!PyCapsule_CheckExact(c_api)) {
      PyErr_SetString(PyExc_RuntimeError, "_ARRAY_API is not PyCapsule object");
      Py_DECREF(c_api);
      return -1;
  }
  PyArray_API = (void **)PyCapsule_GetPointer(c_api, NULL);
  Py_DECREF(c_api);
  if (PyArray_API == NULL) {
      PyErr_SetString(PyExc_RuntimeError, "_ARRAY_API is NULL pointer");
      return -1;
  }

  /* Perform runtime check of C API version */
  if (NPY_VERSION != PyArray_GetNDArrayCVersion()) {
      PyErr_Format(PyExc_RuntimeError, "module compiled against "\
             "ABI version 0x%%x but this version of numpy is 0x%%x", \
             (int) NPY_VERSION, (int) PyArray_GetNDArrayCVersion());
      return -1;
  }
  if (NPY_FEATURE_VERSION > PyArray_GetNDArrayCFeatureVersion()) {
      PyErr_Format(PyExc_RuntimeError, "module compiled against "\
             "API version 0x%%x but this version of numpy is 0x%%x . "\
             "Check the section C-API incompatibility at the "\
             "Troubleshooting ImportError section at "\
             "https://numpy.org/devdocs/user/troubleshooting-importerror.html"\
             "#c-api-incompatibility "\
              "for indications on how to solve this problem .", \
             (int) NPY_FEATURE_VERSION, (int) PyArray_GetNDArrayCFeatureVersion());
      return -1;
  }

  /*
   * Perform runtime check of endianness and check it matches the one set by
   * the headers (npy_endian.h) as a safeguard
   */
  st = PyArray_GetEndianness();
  if (st == NPY_CPU_UNKNOWN_ENDIAN) {
      PyErr_SetString(PyExc_RuntimeError,
                      "FATAL: module compiled as unknown endian");
      return -1;
  }
#if NPY_BYTE_ORDER == NPY_BIG_ENDIAN
  if (st != NPY_CPU_BIG) {
      PyErr_SetString(PyExc_RuntimeError,
                      "FATAL: module compiled as big endian, but "
                      "detected different endianness at runtime");
      return -1;
  }
#elif NPY_BYTE_ORDER == NPY_LITTLE_ENDIAN
  if (st != NPY_CPU_LITTLE) {
      PyErr_SetString(PyExc_RuntimeError,
                      "FATAL: module compiled as little endian, but "
                      "detected different endianness at runtime");
      return -1;
  }
#endif

  return 0;
}

#define import_array() {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); return NULL; } }

#define import_array1(ret) {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); return ret; } }

#define import_array2(msg, ret) {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, msg); return ret; } }

#endif

#endif
z{
/* These pointers will be stored in the C-object for use in other
    extension modules
*/

void *PyArray_API[] = {
%s
};
z%
===========
NumPy C-API
===========
Fc                 C   sr   d}t j | d| ¡}t j | d| ¡}t j | d| ¡}|||f}tj}|sdt |tjtg¡sd|S t||ƒ |S )NÚmultiarray_apiz__%s.hz__%s.cz%s.txt)	ÚosÚpathÚjoinÚ	numpy_apir   ÚgenapiZshould_rebuildÚ__file__Údo_generate_api)Ú
output_dirÚforceÚbasenameZh_fileÚc_fileZd_fileÚtargetsÚsources© r   úA/tmp/pip-unpacked-wheel-b2rbor69/numpy/core/generate_numpy_api.pyÚgenerate_api”   s    

r   c                 C   sb  | d }| d }| d }|d }|d }|d }|d }|d d … }	g }
g }g }t  |	¡}t  |¡ t  d|¡}d}i }|D ]D}|j}|| d }|| dd … }t|j|||j|j|ƒ||j< q|| ¡ D ]"\}}|\}}t	||||ƒ||< qÊ| ¡ D ] \}}|d }t
|||ƒ||< qö| ¡ D ]@\}}|d }t|ƒdkrBd n|d }t||d||ƒ||< q t|ƒt|ƒkr¤t| ¡ ƒ}t| ¡ ƒ}td || || ¡ƒ‚g }t  |¡D ]<\}}|| }| | ¡ ¡ | | ¡ ¡ |
 | ¡ ¡ q²td	 |
¡d	 |¡f }t  ||¡ td
 |¡ }t  ||¡ t}|D ]}|| ¡ 7 }|d7 }q6t  ||¡ | S )Nr   é   é   é   Z	NUMPY_APIZPyArray_APIZPyTypeObjectzNMultiarray API size mismatch - index has extra keys {}, dict has extra keys {}Ú
z,
z

)r   Zmerge_api_dictsZcheck_api_dictZget_api_functionsÚnamer   Úreturn_typeÚargsÚitemsr   r   Úlenr   ÚsetÚkeysÚAssertionErrorÚformatZ
order_dictÚappendZdefine_from_array_api_stringZarray_api_defineZinternal_defineÚ
h_templater	   Ú
write_fileÚ
c_templateÚc_api_headerZto_ReST)r   r   Zheader_filer   Zdoc_fileÚglobal_varsZscalar_bool_valuesZ	types_apiZmultiarray_funcsr   Zmodule_listZextension_listZ	init_listZmultiarray_api_indexZnumpyapi_listZapi_nameZmultiarray_api_dictÚfr   ÚindexÚannotationsÚvalÚtypeZinternal_typeZ	keys_dictZ
keys_indexZapi_itemÚsÚfuncr   r   r   r   ¥   sˆ    

ÿ
 þ    ÿ þÿr   )F)r   r   r   r   r   r   r
   r%   r'   r(   r   r   r   r   r   r   Ú<module>   s   z

