o
    1ή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BoolValuesApia0  
#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", \
             (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_Format(PyExc_RuntimeError, "FATAL: module compiled as unknown endian");
      return -1;
  }
#if NPY_BYTE_ORDER == NPY_BIG_ENDIAN
  if (st != NPY_CPU_BIG) {
      PyErr_Format(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_Format(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}|s2t|tjtgs2|S t|| |S )Nmultiarray_apiz__%s.hz__%s.cz%s.txt)	ospathjoin	numpy_apir   genapishould_rebuild__file__do_generate_api)
output_dirforcebasenameh_filec_filed_filetargetssources r   D/tmp/pip-target-vg8gfxp4/lib/python/numpy/core/generate_numpy_api.pygenerate_api   s   

r   c                 C   sZ  | d }| d }| d }|d }|d }|d }|d }|d d  }	g }
g }g }t |	}t | t d|}d}i }|D ]"}|j}|| d }|| dd  }t|j|||j|j|||j< q>| D ]\}}|\}}t	||||||< qe| D ]\}}|d }t
|||||< q{| D ]\}}|d }t|dkrd n|d }t||d||||< qt|t|krt| }t| }td|| || g }t |D ]\}}|| }||  ||  |
|  qtd	|
d	|f }t || td
| }t || t}|D ]}|| 7 }|d7 }qt || | S )Nr            	NUMPY_APIPyArray_APIPyTypeObjectzNMultiarray API size mismatch - index has extra keys {}, dict has extra keys {}
z,
z

)r   merge_api_dictscheck_api_dictget_api_functionsnamer   return_typeargsitemsr   r   lenr   setkeysAssertionErrorformat
order_dictappenddefine_from_array_api_stringarray_api_defineinternal_define
h_templater	   
write_file
c_templatec_api_headerto_ReST)r   r   header_filer   doc_fileglobal_varsscalar_bool_values	types_apimultiarray_funcsr   module_listextension_list	init_listmultiarray_api_indexnumpyapi_listapi_namemultiarray_api_dictfr$   indexannotationsvaltypeinternal_type	keys_dict
keys_indexapi_itemsfuncr   r   r   r      sz   




r   )F)r   r   r   r   r   r   r
   r2   r4   r5   r   r   r   r   r   r   <module>   s    r

