mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 09:26:27 +03:00
Merge branch 'master' of ssh://github.com/spacy-io/spaCy
This commit is contained in:
commit
e526be5602
1
LICENSE
1
LICENSE
|
@ -1,6 +1,7 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (C) 2015 Matthew Honnibal
|
||||
2016 spaCy GmbH
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
"build": {
|
||||
"sdist": [
|
||||
"pip install -r requirements.txt",
|
||||
"pip install \"numpy<1.8\"",
|
||||
"python setup.py sdist"
|
||||
],
|
||||
"install": [
|
||||
|
|
259
include/msvc9/stdint.h
Normal file
259
include/msvc9/stdint.h
Normal file
|
@ -0,0 +1,259 @@
|
|||
// ISO C9x compliant stdint.h for Microsoft Visual Studio
|
||||
// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
|
||||
//
|
||||
// Copyright (c) 2006-2013 Alexander Chemeris
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the product nor the names of its contributors may
|
||||
// be used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _MSC_VER // [
|
||||
#error "Use this header only with Microsoft Visual C++ compilers!"
|
||||
#endif // _MSC_VER ]
|
||||
|
||||
#ifndef _MSC_STDINT_H_ // [
|
||||
#define _MSC_STDINT_H_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#if _MSC_VER >= 1600 // [
|
||||
#include <stdint.h>
|
||||
#else // ] _MSC_VER >= 1600 [
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
|
||||
// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}'
|
||||
// or compiler give many errors like this:
|
||||
// error C2733: second C linkage of overloaded function 'wmemchr' not allowed
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
# include <wchar.h>
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
// Define _W64 macros to mark types changing their size, like intptr_t.
|
||||
#ifndef _W64
|
||||
# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
|
||||
# define _W64 __w64
|
||||
# else
|
||||
# define _W64
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
// 7.18.1 Integer types
|
||||
|
||||
// 7.18.1.1 Exact-width integer types
|
||||
|
||||
// Visual Studio 6 and Embedded Visual C++ 4 doesn't
|
||||
// realize that, e.g. char has the same size as __int8
|
||||
// so we give up on __intX for them.
|
||||
#if (_MSC_VER < 1300)
|
||||
typedef signed char int8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#else
|
||||
typedef signed __int8 int8_t;
|
||||
typedef signed __int16 int16_t;
|
||||
typedef signed __int32 int32_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
#endif
|
||||
typedef signed __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
|
||||
|
||||
// 7.18.1.2 Minimum-width integer types
|
||||
typedef int8_t int_least8_t;
|
||||
typedef int16_t int_least16_t;
|
||||
typedef int32_t int_least32_t;
|
||||
typedef int64_t int_least64_t;
|
||||
typedef uint8_t uint_least8_t;
|
||||
typedef uint16_t uint_least16_t;
|
||||
typedef uint32_t uint_least32_t;
|
||||
typedef uint64_t uint_least64_t;
|
||||
|
||||
// 7.18.1.3 Fastest minimum-width integer types
|
||||
typedef int8_t int_fast8_t;
|
||||
typedef int16_t int_fast16_t;
|
||||
typedef int32_t int_fast32_t;
|
||||
typedef int64_t int_fast64_t;
|
||||
typedef uint8_t uint_fast8_t;
|
||||
typedef uint16_t uint_fast16_t;
|
||||
typedef uint32_t uint_fast32_t;
|
||||
typedef uint64_t uint_fast64_t;
|
||||
|
||||
// 7.18.1.4 Integer types capable of holding object pointers
|
||||
#ifdef _WIN64 // [
|
||||
typedef signed __int64 intptr_t;
|
||||
typedef unsigned __int64 uintptr_t;
|
||||
#else // _WIN64 ][
|
||||
typedef _W64 signed int intptr_t;
|
||||
typedef _W64 unsigned int uintptr_t;
|
||||
#endif // _WIN64 ]
|
||||
|
||||
// 7.18.1.5 Greatest-width integer types
|
||||
typedef int64_t intmax_t;
|
||||
typedef uint64_t uintmax_t;
|
||||
|
||||
|
||||
// 7.18.2 Limits of specified-width integer types
|
||||
|
||||
#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259
|
||||
|
||||
// 7.18.2.1 Limits of exact-width integer types
|
||||
#define INT8_MIN ((int8_t)_I8_MIN)
|
||||
#define INT8_MAX _I8_MAX
|
||||
#define INT16_MIN ((int16_t)_I16_MIN)
|
||||
#define INT16_MAX _I16_MAX
|
||||
#define INT32_MIN ((int32_t)_I32_MIN)
|
||||
#define INT32_MAX _I32_MAX
|
||||
#define INT64_MIN ((int64_t)_I64_MIN)
|
||||
#define INT64_MAX _I64_MAX
|
||||
#define UINT8_MAX _UI8_MAX
|
||||
#define UINT16_MAX _UI16_MAX
|
||||
#define UINT32_MAX _UI32_MAX
|
||||
#define UINT64_MAX _UI64_MAX
|
||||
|
||||
// 7.18.2.2 Limits of minimum-width integer types
|
||||
#define INT_LEAST8_MIN INT8_MIN
|
||||
#define INT_LEAST8_MAX INT8_MAX
|
||||
#define INT_LEAST16_MIN INT16_MIN
|
||||
#define INT_LEAST16_MAX INT16_MAX
|
||||
#define INT_LEAST32_MIN INT32_MIN
|
||||
#define INT_LEAST32_MAX INT32_MAX
|
||||
#define INT_LEAST64_MIN INT64_MIN
|
||||
#define INT_LEAST64_MAX INT64_MAX
|
||||
#define UINT_LEAST8_MAX UINT8_MAX
|
||||
#define UINT_LEAST16_MAX UINT16_MAX
|
||||
#define UINT_LEAST32_MAX UINT32_MAX
|
||||
#define UINT_LEAST64_MAX UINT64_MAX
|
||||
|
||||
// 7.18.2.3 Limits of fastest minimum-width integer types
|
||||
#define INT_FAST8_MIN INT8_MIN
|
||||
#define INT_FAST8_MAX INT8_MAX
|
||||
#define INT_FAST16_MIN INT16_MIN
|
||||
#define INT_FAST16_MAX INT16_MAX
|
||||
#define INT_FAST32_MIN INT32_MIN
|
||||
#define INT_FAST32_MAX INT32_MAX
|
||||
#define INT_FAST64_MIN INT64_MIN
|
||||
#define INT_FAST64_MAX INT64_MAX
|
||||
#define UINT_FAST8_MAX UINT8_MAX
|
||||
#define UINT_FAST16_MAX UINT16_MAX
|
||||
#define UINT_FAST32_MAX UINT32_MAX
|
||||
#define UINT_FAST64_MAX UINT64_MAX
|
||||
|
||||
// 7.18.2.4 Limits of integer types capable of holding object pointers
|
||||
#ifdef _WIN64 // [
|
||||
# define INTPTR_MIN INT64_MIN
|
||||
# define INTPTR_MAX INT64_MAX
|
||||
# define UINTPTR_MAX UINT64_MAX
|
||||
#else // _WIN64 ][
|
||||
# define INTPTR_MIN INT32_MIN
|
||||
# define INTPTR_MAX INT32_MAX
|
||||
# define UINTPTR_MAX UINT32_MAX
|
||||
#endif // _WIN64 ]
|
||||
|
||||
// 7.18.2.5 Limits of greatest-width integer types
|
||||
#define INTMAX_MIN INT64_MIN
|
||||
#define INTMAX_MAX INT64_MAX
|
||||
#define UINTMAX_MAX UINT64_MAX
|
||||
|
||||
// 7.18.3 Limits of other integer types
|
||||
|
||||
#ifdef _WIN64 // [
|
||||
# define PTRDIFF_MIN _I64_MIN
|
||||
# define PTRDIFF_MAX _I64_MAX
|
||||
#else // _WIN64 ][
|
||||
# define PTRDIFF_MIN _I32_MIN
|
||||
# define PTRDIFF_MAX _I32_MAX
|
||||
#endif // _WIN64 ]
|
||||
|
||||
#define SIG_ATOMIC_MIN INT_MIN
|
||||
#define SIG_ATOMIC_MAX INT_MAX
|
||||
|
||||
#ifndef SIZE_MAX // [
|
||||
# ifdef _WIN64 // [
|
||||
# define SIZE_MAX _UI64_MAX
|
||||
# else // _WIN64 ][
|
||||
# define SIZE_MAX _UI32_MAX
|
||||
# endif // _WIN64 ]
|
||||
#endif // SIZE_MAX ]
|
||||
|
||||
// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
|
||||
#ifndef WCHAR_MIN // [
|
||||
# define WCHAR_MIN 0
|
||||
#endif // WCHAR_MIN ]
|
||||
#ifndef WCHAR_MAX // [
|
||||
# define WCHAR_MAX _UI16_MAX
|
||||
#endif // WCHAR_MAX ]
|
||||
|
||||
#define WINT_MIN 0
|
||||
#define WINT_MAX _UI16_MAX
|
||||
|
||||
#endif // __STDC_LIMIT_MACROS ]
|
||||
|
||||
|
||||
// 7.18.4 Limits of other integer types
|
||||
|
||||
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
|
||||
|
||||
// 7.18.4.1 Macros for minimum-width integer constants
|
||||
|
||||
#define INT8_C(val) val##i8
|
||||
#define INT16_C(val) val##i16
|
||||
#define INT32_C(val) val##i32
|
||||
#define INT64_C(val) val##i64
|
||||
|
||||
#define UINT8_C(val) val##ui8
|
||||
#define UINT16_C(val) val##ui16
|
||||
#define UINT32_C(val) val##ui32
|
||||
#define UINT64_C(val) val##ui64
|
||||
|
||||
// 7.18.4.2 Macros for greatest-width integer constants
|
||||
// These #ifndef's are needed to prevent collisions with <boost/cstdint.hpp>.
|
||||
// Check out Issue 9 for the details.
|
||||
#ifndef INTMAX_C // [
|
||||
# define INTMAX_C INT64_C
|
||||
#endif // INTMAX_C ]
|
||||
#ifndef UINTMAX_C // [
|
||||
# define UINTMAX_C UINT64_C
|
||||
#endif // UINTMAX_C ]
|
||||
|
||||
#endif // __STDC_CONSTANT_MACROS ]
|
||||
|
||||
#endif // _MSC_VER >= 1600 ]
|
||||
|
||||
#endif // _MSC_STDINT_H_ ]
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
#if defined(_MULTIARRAYMODULE) || defined(WITH_CPYCHECKER_STEALS_REFERENCE_TO_ARG_ATTRIBUTE)
|
||||
#ifdef _MULTIARRAYMODULE
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
|
@ -270,7 +270,7 @@ NPY_NO_EXPORT char * PyArray_Zero \
|
|||
(PyArrayObject *);
|
||||
NPY_NO_EXPORT char * PyArray_One \
|
||||
(PyArrayObject *);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) NPY_GCC_NONNULL(2) PyObject * PyArray_CastToType \
|
||||
NPY_NO_EXPORT PyObject * PyArray_CastToType \
|
||||
(PyArrayObject *, PyArray_Descr *, int);
|
||||
NPY_NO_EXPORT int PyArray_CastTo \
|
||||
(PyArrayObject *, PyArrayObject *);
|
||||
|
@ -294,7 +294,7 @@ NPY_NO_EXPORT npy_intp PyArray_Size \
|
|||
(PyObject *);
|
||||
NPY_NO_EXPORT PyObject * PyArray_Scalar \
|
||||
(void *, PyArray_Descr *, PyObject *);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_FromScalar \
|
||||
NPY_NO_EXPORT PyObject * PyArray_FromScalar \
|
||||
(PyObject *, PyArray_Descr *);
|
||||
NPY_NO_EXPORT void PyArray_ScalarAsCtype \
|
||||
(PyObject *, void *);
|
||||
|
@ -308,13 +308,13 @@ NPY_NO_EXPORT PyArray_VectorUnaryFunc * PyArray_GetCastFunc \
|
|||
(PyArray_Descr *, int);
|
||||
NPY_NO_EXPORT PyObject * PyArray_FromDims \
|
||||
(int, int *, int);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(3) PyObject * PyArray_FromDimsAndDataAndDescr \
|
||||
NPY_NO_EXPORT PyObject * PyArray_FromDimsAndDataAndDescr \
|
||||
(int, int *, PyArray_Descr *, char *);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_FromAny \
|
||||
NPY_NO_EXPORT PyObject * PyArray_FromAny \
|
||||
(PyObject *, PyArray_Descr *, int, int, int, PyObject *);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(1) PyObject * PyArray_EnsureArray \
|
||||
NPY_NO_EXPORT PyObject * PyArray_EnsureArray \
|
||||
(PyObject *);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(1) PyObject * PyArray_EnsureAnyArray \
|
||||
NPY_NO_EXPORT PyObject * PyArray_EnsureAnyArray \
|
||||
(PyObject *);
|
||||
NPY_NO_EXPORT PyObject * PyArray_FromFile \
|
||||
(FILE *, PyArray_Descr *, npy_intp, char *);
|
||||
|
@ -322,13 +322,13 @@ NPY_NO_EXPORT PyObject * PyArray_FromString \
|
|||
(char *, npy_intp, PyArray_Descr *, npy_intp, char *);
|
||||
NPY_NO_EXPORT PyObject * PyArray_FromBuffer \
|
||||
(PyObject *, PyArray_Descr *, npy_intp, npy_intp);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_FromIter \
|
||||
NPY_NO_EXPORT PyObject * PyArray_FromIter \
|
||||
(PyObject *, PyArray_Descr *, npy_intp);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(1) PyObject * PyArray_Return \
|
||||
NPY_NO_EXPORT PyObject * PyArray_Return \
|
||||
(PyArrayObject *);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) NPY_GCC_NONNULL(2) PyObject * PyArray_GetField \
|
||||
NPY_NO_EXPORT PyObject * PyArray_GetField \
|
||||
(PyArrayObject *, PyArray_Descr *, int);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) NPY_GCC_NONNULL(2) int PyArray_SetField \
|
||||
NPY_NO_EXPORT int PyArray_SetField \
|
||||
(PyArrayObject *, PyArray_Descr *, int, PyObject *);
|
||||
NPY_NO_EXPORT PyObject * PyArray_Byteswap \
|
||||
(PyArrayObject *, npy_bool);
|
||||
|
@ -342,7 +342,7 @@ NPY_NO_EXPORT int PyArray_CopyAnyInto \
|
|||
(PyArrayObject *, PyArrayObject *);
|
||||
NPY_NO_EXPORT int PyArray_CopyObject \
|
||||
(PyArrayObject *, PyObject *);
|
||||
NPY_NO_EXPORT NPY_GCC_NONNULL(1) PyObject * PyArray_NewCopy \
|
||||
NPY_NO_EXPORT PyObject * PyArray_NewCopy \
|
||||
(PyArrayObject *, NPY_ORDER);
|
||||
NPY_NO_EXPORT PyObject * PyArray_ToList \
|
||||
(PyArrayObject *);
|
||||
|
@ -358,9 +358,9 @@ NPY_NO_EXPORT int PyArray_ValidType \
|
|||
(int);
|
||||
NPY_NO_EXPORT void PyArray_UpdateFlags \
|
||||
(PyArrayObject *, int);
|
||||
NPY_NO_EXPORT NPY_GCC_NONNULL(1) PyObject * PyArray_New \
|
||||
NPY_NO_EXPORT PyObject * PyArray_New \
|
||||
(PyTypeObject *, int, npy_intp *, int, npy_intp *, void *, int, int, PyObject *);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) NPY_GCC_NONNULL(1) NPY_GCC_NONNULL(2) PyObject * PyArray_NewFromDescr \
|
||||
NPY_NO_EXPORT PyObject * PyArray_NewFromDescr \
|
||||
(PyTypeObject *, PyArray_Descr *, int, npy_intp *, npy_intp *, void *, int, PyObject *);
|
||||
NPY_NO_EXPORT PyArray_Descr * PyArray_DescrNew \
|
||||
(PyArray_Descr *);
|
||||
|
@ -388,9 +388,9 @@ NPY_NO_EXPORT PyArray_Descr * PyArray_DescrNewByteorder \
|
|||
(PyArray_Descr *, char);
|
||||
NPY_NO_EXPORT PyObject * PyArray_IterAllButAxis \
|
||||
(PyObject *, int *);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_CheckFromAny \
|
||||
NPY_NO_EXPORT PyObject * PyArray_CheckFromAny \
|
||||
(PyObject *, PyArray_Descr *, int, int, int, PyObject *);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_FromArray \
|
||||
NPY_NO_EXPORT PyObject * PyArray_FromArray \
|
||||
(PyArrayObject *, PyArray_Descr *, int);
|
||||
NPY_NO_EXPORT PyObject * PyArray_FromInterface \
|
||||
(PyObject *);
|
||||
|
@ -446,7 +446,7 @@ NPY_NO_EXPORT PyObject * PyArray_Newshape \
|
|||
(PyArrayObject *, PyArray_Dims *, NPY_ORDER);
|
||||
NPY_NO_EXPORT PyObject * PyArray_Squeeze \
|
||||
(PyArrayObject *);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) PyObject * PyArray_View \
|
||||
NPY_NO_EXPORT PyObject * PyArray_View \
|
||||
(PyArrayObject *, PyArray_Descr *, PyTypeObject *);
|
||||
NPY_NO_EXPORT PyObject * PyArray_SwapAxes \
|
||||
(PyArrayObject *, int, int);
|
||||
|
@ -496,7 +496,7 @@ NPY_NO_EXPORT void * PyArray_GetPtr \
|
|||
(PyArrayObject *, npy_intp*);
|
||||
NPY_NO_EXPORT int PyArray_CompareLists \
|
||||
(npy_intp *, npy_intp *, int);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(5) int PyArray_AsCArray \
|
||||
NPY_NO_EXPORT int PyArray_AsCArray \
|
||||
(PyObject **, void *, npy_intp *, int, PyArray_Descr*);
|
||||
NPY_NO_EXPORT int PyArray_As1D \
|
||||
(PyObject **, char **, int *, int);
|
||||
|
@ -538,9 +538,9 @@ NPY_NO_EXPORT int PyArray_OrderConverter \
|
|||
(PyObject *, NPY_ORDER *);
|
||||
NPY_NO_EXPORT unsigned char PyArray_EquivTypes \
|
||||
(PyArray_Descr *, PyArray_Descr *);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(3) PyObject * PyArray_Zeros \
|
||||
NPY_NO_EXPORT PyObject * PyArray_Zeros \
|
||||
(int, npy_intp *, PyArray_Descr *, int);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(3) PyObject * PyArray_Empty \
|
||||
NPY_NO_EXPORT PyObject * PyArray_Empty \
|
||||
(int, npy_intp *, PyArray_Descr *, int);
|
||||
NPY_NO_EXPORT PyObject * PyArray_Where \
|
||||
(PyObject *, PyObject *, PyObject *);
|
||||
|
@ -746,7 +746,7 @@ NPY_NO_EXPORT npy_bool PyArray_CanCastTypeTo \
|
|||
(PyArray_Descr *, PyArray_Descr *, NPY_CASTING);
|
||||
NPY_NO_EXPORT PyArrayObject * PyArray_EinsteinSum \
|
||||
(char *, npy_intp, PyArrayObject **, PyArray_Descr *, NPY_ORDER, NPY_CASTING, PyArrayObject *);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(3) NPY_GCC_NONNULL(1) PyObject * PyArray_NewLikeArray \
|
||||
NPY_NO_EXPORT PyObject * PyArray_NewLikeArray \
|
||||
(PyArrayObject *, NPY_ORDER, PyArray_Descr *, int);
|
||||
NPY_NO_EXPORT int PyArray_GetArrayParamsFromObject \
|
||||
(PyObject *, PyArray_Descr *, npy_bool, PyArray_Descr **, int *, npy_intp *, PyArrayObject **, PyObject *);
|
||||
|
@ -756,7 +756,7 @@ NPY_NO_EXPORT PyObject * PyArray_MatrixProduct2 \
|
|||
(PyObject *, PyObject *, PyArrayObject*);
|
||||
NPY_NO_EXPORT npy_bool NpyIter_IsFirstVisit \
|
||||
(NpyIter *, int);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) int PyArray_SetBaseObject \
|
||||
NPY_NO_EXPORT int PyArray_SetBaseObject \
|
||||
(PyArrayObject *, PyObject *);
|
||||
NPY_NO_EXPORT void PyArray_CreateSortedStridePerm \
|
||||
(int, npy_intp *, npy_stride_sort_item *);
|
||||
|
@ -766,7 +766,7 @@ NPY_NO_EXPORT void PyArray_DebugPrint \
|
|||
(PyArrayObject *);
|
||||
NPY_NO_EXPORT int PyArray_FailUnlessWriteable \
|
||||
(PyArrayObject *, const char *);
|
||||
NPY_NO_EXPORT NPY_STEALS_REF_TO_ARG(2) int PyArray_SetUpdateIfCopyBase \
|
||||
NPY_NO_EXPORT int PyArray_SetUpdateIfCopyBase \
|
||||
(PyArrayObject *, PyArrayObject *);
|
||||
NPY_NO_EXPORT void * PyDataMem_NEW \
|
||||
(size_t);
|
||||
|
@ -782,22 +782,6 @@ NPY_NO_EXPORT PyDataMem_EventHookFunc * PyDataMem_SetEventHook \
|
|||
NPY_NO_EXPORT NPY_CASTING NPY_DEFAULT_ASSIGN_CASTING;
|
||||
#endif
|
||||
|
||||
NPY_NO_EXPORT void PyArray_MapIterSwapAxes \
|
||||
(PyArrayMapIterObject *, PyArrayObject **, int);
|
||||
NPY_NO_EXPORT PyObject * PyArray_MapIterArray \
|
||||
(PyArrayObject *, PyObject *);
|
||||
NPY_NO_EXPORT void PyArray_MapIterNext \
|
||||
(PyArrayMapIterObject *);
|
||||
NPY_NO_EXPORT int PyArray_Partition \
|
||||
(PyArrayObject *, PyArrayObject *, int, NPY_SELECTKIND);
|
||||
NPY_NO_EXPORT PyObject * PyArray_ArgPartition \
|
||||
(PyArrayObject *, PyArrayObject *, int, NPY_SELECTKIND);
|
||||
NPY_NO_EXPORT int PyArray_SelectkindConverter \
|
||||
(PyObject *, NPY_SELECTKIND *);
|
||||
NPY_NO_EXPORT void * PyDataMem_NEW_ZEROED \
|
||||
(size_t, size_t);
|
||||
NPY_NO_EXPORT NPY_GCC_NONNULL(1) int PyArray_CheckAnyScalarExact \
|
||||
(PyObject *);
|
||||
|
||||
#else
|
||||
|
||||
|
@ -1604,30 +1588,6 @@ static void **PyArray_API=NULL;
|
|||
(*(PyDataMem_EventHookFunc * (*)(PyDataMem_EventHookFunc *, void *, void **)) \
|
||||
PyArray_API[291])
|
||||
#define NPY_DEFAULT_ASSIGN_CASTING (*(NPY_CASTING *)PyArray_API[292])
|
||||
#define PyArray_MapIterSwapAxes \
|
||||
(*(void (*)(PyArrayMapIterObject *, PyArrayObject **, int)) \
|
||||
PyArray_API[293])
|
||||
#define PyArray_MapIterArray \
|
||||
(*(PyObject * (*)(PyArrayObject *, PyObject *)) \
|
||||
PyArray_API[294])
|
||||
#define PyArray_MapIterNext \
|
||||
(*(void (*)(PyArrayMapIterObject *)) \
|
||||
PyArray_API[295])
|
||||
#define PyArray_Partition \
|
||||
(*(int (*)(PyArrayObject *, PyArrayObject *, int, NPY_SELECTKIND)) \
|
||||
PyArray_API[296])
|
||||
#define PyArray_ArgPartition \
|
||||
(*(PyObject * (*)(PyArrayObject *, PyArrayObject *, int, NPY_SELECTKIND)) \
|
||||
PyArray_API[297])
|
||||
#define PyArray_SelectkindConverter \
|
||||
(*(int (*)(PyObject *, NPY_SELECTKIND *)) \
|
||||
PyArray_API[298])
|
||||
#define PyDataMem_NEW_ZEROED \
|
||||
(*(void * (*)(size_t, size_t)) \
|
||||
PyArray_API[299])
|
||||
#define PyArray_CheckAnyScalarExact \
|
||||
(*(int (*)(PyObject *)) \
|
||||
PyArray_API[300])
|
||||
|
||||
#if !defined(NO_IMPORT_ARRAY) && !defined(NO_IMPORT)
|
||||
static int
|
||||
|
|
|
@ -14,7 +14,7 @@ NPY_NO_EXPORT PyTypeObject PyUFunc_Type;
|
|||
#endif
|
||||
|
||||
NPY_NO_EXPORT PyObject * PyUFunc_FromFuncAndData \
|
||||
(PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, int);
|
||||
(PyUFuncGenericFunction *, void **, char *, int, int, int, int, char *, char *, int);
|
||||
NPY_NO_EXPORT int PyUFunc_RegisterLoopForType \
|
||||
(PyUFuncObject *, int, PyUFuncGenericFunction, int *, void *);
|
||||
NPY_NO_EXPORT int PyUFunc_GenericFunction \
|
||||
|
@ -74,7 +74,7 @@ NPY_NO_EXPORT int PyUFunc_handlefperr \
|
|||
NPY_NO_EXPORT int PyUFunc_ReplaceLoopBySignature \
|
||||
(PyUFuncObject *, PyUFuncGenericFunction, int *, PyUFuncGenericFunction *);
|
||||
NPY_NO_EXPORT PyObject * PyUFunc_FromFuncAndDataAndSignature \
|
||||
(PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, int, const char *);
|
||||
(PyUFuncGenericFunction *, void **, char *, int, int, int, int, char *, char *, int, const char *);
|
||||
NPY_NO_EXPORT int PyUFunc_SetUsesArraysAsData \
|
||||
(void **, size_t);
|
||||
NPY_NO_EXPORT void PyUFunc_e_e \
|
||||
|
@ -93,8 +93,6 @@ NPY_NO_EXPORT int PyUFunc_DefaultTypeResolver \
|
|||
(PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyObject *, PyArray_Descr **);
|
||||
NPY_NO_EXPORT int PyUFunc_ValidateCasting \
|
||||
(PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyArray_Descr **);
|
||||
NPY_NO_EXPORT int PyUFunc_RegisterLoopForDescr \
|
||||
(PyUFuncObject *, PyArray_Descr *, PyUFuncGenericFunction, PyArray_Descr **, void *);
|
||||
|
||||
#else
|
||||
|
||||
|
@ -114,7 +112,7 @@ static void **PyUFunc_API=NULL;
|
|||
|
||||
#define PyUFunc_Type (*(PyTypeObject *)PyUFunc_API[0])
|
||||
#define PyUFunc_FromFuncAndData \
|
||||
(*(PyObject * (*)(PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, int)) \
|
||||
(*(PyObject * (*)(PyUFuncGenericFunction *, void **, char *, int, int, int, int, char *, char *, int)) \
|
||||
PyUFunc_API[1])
|
||||
#define PyUFunc_RegisterLoopForType \
|
||||
(*(int (*)(PyUFuncObject *, int, PyUFuncGenericFunction, int *, void *)) \
|
||||
|
@ -204,7 +202,7 @@ static void **PyUFunc_API=NULL;
|
|||
(*(int (*)(PyUFuncObject *, PyUFuncGenericFunction, int *, PyUFuncGenericFunction *)) \
|
||||
PyUFunc_API[30])
|
||||
#define PyUFunc_FromFuncAndDataAndSignature \
|
||||
(*(PyObject * (*)(PyUFuncGenericFunction *, void **, char *, int, int, int, int, const char *, const char *, int, const char *)) \
|
||||
(*(PyObject * (*)(PyUFuncGenericFunction *, void **, char *, int, int, int, int, char *, char *, int, const char *)) \
|
||||
PyUFunc_API[31])
|
||||
#define PyUFunc_SetUsesArraysAsData \
|
||||
(*(int (*)(void **, size_t)) \
|
||||
|
@ -233,11 +231,8 @@ static void **PyUFunc_API=NULL;
|
|||
#define PyUFunc_ValidateCasting \
|
||||
(*(int (*)(PyUFuncObject *, NPY_CASTING, PyArrayObject **, PyArray_Descr **)) \
|
||||
PyUFunc_API[40])
|
||||
#define PyUFunc_RegisterLoopForDescr \
|
||||
(*(int (*)(PyUFuncObject *, PyArray_Descr *, PyUFuncGenericFunction, PyArray_Descr **, void *)) \
|
||||
PyUFunc_API[41])
|
||||
|
||||
static NPY_INLINE int
|
||||
static int
|
||||
_import_umath(void)
|
||||
{
|
||||
PyObject *numpy = PyImport_ImportModule("numpy.core.umath");
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#define NPY_SIZEOF_LONGDOUBLE 16
|
||||
#define NPY_SIZEOF_COMPLEX_LONGDOUBLE 32
|
||||
#define NPY_SIZEOF_PY_INTPTR_T 8
|
||||
#define NPY_SIZEOF_OFF_T 8
|
||||
#define NPY_SIZEOF_PY_LONG_LONG 8
|
||||
#define NPY_SIZEOF_LONGLONG 8
|
||||
#define NPY_NO_SMP 0
|
||||
|
@ -20,11 +19,10 @@
|
|||
#define NPY_HAVE_COMPLEX_DOUBLE 1
|
||||
#define NPY_HAVE_COMPLEX_FLOAT 1
|
||||
#define NPY_HAVE_COMPLEX_LONG_DOUBLE 1
|
||||
#define NPY_ENABLE_SEPARATE_COMPILATION 1
|
||||
#define NPY_USE_C99_FORMATS 1
|
||||
#define NPY_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
|
||||
#define NPY_ABI_VERSION 0x01000009
|
||||
#define NPY_API_VERSION 0x0000000A
|
||||
#define NPY_API_VERSION 0x00000007
|
||||
|
||||
#ifndef __STDC_FORMAT_MACROS
|
||||
#define __STDC_FORMAT_MACROS 1
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
|
||||
/* This expects the following variables to be defined (besides
|
||||
the usual ones from pyconfig.h
|
||||
|
||||
SIZEOF_LONG_DOUBLE -- sizeof(long double) or sizeof(double) if no
|
||||
long double is present on platform.
|
||||
CHAR_BIT -- number of bits in a char (usually 8)
|
||||
(should be in limits.h)
|
||||
|
||||
*/
|
||||
|
||||
#ifndef Py_ARRAYOBJECT_H
|
||||
#define Py_ARRAYOBJECT_H
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ Get pointer to one of correct type for array
|
|||
For backward compatibility
|
||||
|
||||
Cast an array using typecode structure.
|
||||
steals reference to dtype --- cannot be NULL
|
||||
steals reference to at --- cannot be NULL
|
||||
|
||||
This function always makes a copy of arr, even if the dtype
|
||||
doesn't change.
|
||||
|
@ -356,7 +356,6 @@ steals a reference to dtype (which cannot be NULL)
|
|||
|
||||
Return either an array or the appropriate Python object if the array
|
||||
is 0d and matches a Python type.
|
||||
steals reference to mp
|
||||
|
||||
::
|
||||
|
||||
|
@ -365,7 +364,6 @@ steals reference to mp
|
|||
offset)
|
||||
|
||||
Get a subset of bytes from each element of the array
|
||||
steals reference to typed, must not be NULL
|
||||
|
||||
::
|
||||
|
||||
|
@ -374,7 +372,6 @@ steals reference to typed, must not be NULL
|
|||
offset, PyObject *val)
|
||||
|
||||
Set a subset of bytes from each element of the array
|
||||
steals reference to dtype, must not be NULL
|
||||
|
||||
::
|
||||
|
||||
|
@ -1109,7 +1106,7 @@ as you get a new reference to it.
|
|||
PyArray_IntpFromSequence(PyObject *seq, npy_intp *vals, int maxvals)
|
||||
|
||||
PyArray_IntpFromSequence
|
||||
Returns the number of integers converted or -1 if an error occurred.
|
||||
Returns the number of dimensions or -1 if an error occurred.
|
||||
vals must be large enough to hold maxvals
|
||||
|
||||
::
|
||||
|
@ -2181,7 +2178,7 @@ int ndim = 0;
|
|||
npy_intp dims[NPY_MAXDIMS];
|
||||
|
||||
if (PyArray_GetArrayParamsFromObject(op, NULL, 1, &dtype,
|
||||
&ndim, dims, &arr, NULL) < 0) {
|
||||
&ndim, &dims, &arr, NULL) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (arr == NULL) {
|
||||
|
@ -2221,7 +2218,7 @@ could be applied to each axis, like in ravel_multi_index.
|
|||
PyArray_MatrixProduct2(PyObject *op1, PyObject
|
||||
*op2, PyArrayObject*out)
|
||||
|
||||
Numeric.matrixproduct2(a,v,out)
|
||||
Numeric.matrixproduct(a,v,out)
|
||||
just like inner product but does the swapaxes stuff on the fly
|
||||
|
||||
::
|
||||
|
@ -2287,10 +2284,6 @@ index zero for that axis.
|
|||
WARNING: If an axis flagged for removal has a shape equal to zero,
|
||||
the array will point to invalid memory. The caller must
|
||||
validate this!
|
||||
If an axis flagged for removal has a shape larger then one,
|
||||
the aligned flag (and in the future the contiguous flags),
|
||||
may need explicite update.
|
||||
(check also NPY_RELAXED_STRIDES_CHECKING)
|
||||
|
||||
For example, this can be used to remove the reduction axes
|
||||
from a reduction result once its computation is complete.
|
||||
|
@ -2380,70 +2373,3 @@ operations that might cause new allocation events (such as the
|
|||
creation/descruction numpy objects, or creating/destroying Python
|
||||
objects which might cause a gc)
|
||||
|
||||
::
|
||||
|
||||
void
|
||||
PyArray_MapIterSwapAxes(PyArrayMapIterObject *mit, PyArrayObject
|
||||
**ret, int getmap)
|
||||
|
||||
|
||||
::
|
||||
|
||||
PyObject *
|
||||
PyArray_MapIterArray(PyArrayObject *a, PyObject *index)
|
||||
|
||||
|
||||
Use advanced indexing to iterate an array. Please note
|
||||
that most of this public API is currently not guaranteed
|
||||
to stay the same between versions. If you plan on using
|
||||
it, please consider adding more utility functions here
|
||||
to accommodate new features.
|
||||
|
||||
::
|
||||
|
||||
void
|
||||
PyArray_MapIterNext(PyArrayMapIterObject *mit)
|
||||
|
||||
This function needs to update the state of the map iterator
|
||||
and point mit->dataptr to the memory-location of the next object
|
||||
|
||||
Note that this function never handles an extra operand but provides
|
||||
compatibility for an old (exposed) API.
|
||||
|
||||
::
|
||||
|
||||
int
|
||||
PyArray_Partition(PyArrayObject *op, PyArrayObject *ktharray, int
|
||||
axis, NPY_SELECTKIND which)
|
||||
|
||||
Partition an array in-place
|
||||
|
||||
::
|
||||
|
||||
PyObject *
|
||||
PyArray_ArgPartition(PyArrayObject *op, PyArrayObject *ktharray, int
|
||||
axis, NPY_SELECTKIND which)
|
||||
|
||||
ArgPartition an array
|
||||
|
||||
::
|
||||
|
||||
int
|
||||
PyArray_SelectkindConverter(PyObject *obj, NPY_SELECTKIND *selectkind)
|
||||
|
||||
Convert object to select kind
|
||||
|
||||
::
|
||||
|
||||
void *
|
||||
PyDataMem_NEW_ZEROED(size_t size, size_t elsize)
|
||||
|
||||
Allocates zeroed memory for array data.
|
||||
|
||||
::
|
||||
|
||||
int
|
||||
PyArray_CheckAnyScalarExact(PyObject *obj)
|
||||
|
||||
return true an object is exactly a numpy scalar
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ extern "C" CONFUSE_EMACS
|
|||
everything when you're typing */
|
||||
#endif
|
||||
|
||||
#include <Python.h>
|
||||
#include "ndarraytypes.h"
|
||||
|
||||
/* Includes the "function" C-API -- these are all stored in a
|
||||
|
@ -51,26 +50,14 @@ extern "C" CONFUSE_EMACS
|
|||
|
||||
#define PyArray_CheckScalar(m) (PyArray_IsScalar(m, Generic) || \
|
||||
PyArray_IsZeroDim(m))
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
#define PyArray_IsPythonNumber(obj) \
|
||||
(PyFloat_Check(obj) || PyComplex_Check(obj) || \
|
||||
PyLong_Check(obj) || PyBool_Check(obj))
|
||||
#define PyArray_IsIntegerScalar(obj) (PyLong_Check(obj) \
|
||||
|| PyArray_IsScalar((obj), Integer))
|
||||
#define PyArray_IsPythonScalar(obj) \
|
||||
(PyArray_IsPythonNumber(obj) || PyBytes_Check(obj) || \
|
||||
PyUnicode_Check(obj))
|
||||
#else
|
||||
|
||||
#define PyArray_IsPythonNumber(obj) \
|
||||
(PyInt_Check(obj) || PyFloat_Check(obj) || PyComplex_Check(obj) || \
|
||||
PyLong_Check(obj) || PyBool_Check(obj))
|
||||
#define PyArray_IsIntegerScalar(obj) (PyInt_Check(obj) \
|
||||
|| PyLong_Check(obj) \
|
||||
|| PyArray_IsScalar((obj), Integer))
|
||||
|
||||
#define PyArray_IsPythonScalar(obj) \
|
||||
(PyArray_IsPythonNumber(obj) || PyString_Check(obj) || \
|
||||
PyUnicode_Check(obj))
|
||||
#endif
|
||||
|
||||
#define PyArray_IsAnyScalar(obj) \
|
||||
(PyArray_IsScalar(obj, Generic) || PyArray_IsPythonScalar(obj))
|
||||
|
@ -78,6 +65,10 @@ extern "C" CONFUSE_EMACS
|
|||
#define PyArray_CheckAnyScalar(obj) (PyArray_IsPythonScalar(obj) || \
|
||||
PyArray_CheckScalar(obj))
|
||||
|
||||
#define PyArray_IsIntegerScalar(obj) (PyInt_Check(obj) \
|
||||
|| PyLong_Check(obj) \
|
||||
|| PyArray_IsScalar((obj), Integer))
|
||||
|
||||
|
||||
#define PyArray_GETCONTIGUOUS(m) (PyArray_ISCONTIGUOUS(m) ? \
|
||||
Py_INCREF(m), (m) : \
|
||||
|
@ -96,7 +87,7 @@ extern "C" CONFUSE_EMACS
|
|||
NULL)
|
||||
|
||||
#define PyArray_FROM_OT(m,type) PyArray_FromAny(m, \
|
||||
PyArray_DescrFromType(type), 0, 0, 0, NULL)
|
||||
PyArray_DescrFromType(type), 0, 0, 0, NULL);
|
||||
|
||||
#define PyArray_FROM_OTF(m, type, flags) \
|
||||
PyArray_FromAny(m, PyArray_DescrFromType(type), 0, 0, \
|
||||
|
@ -234,8 +225,15 @@ PyArray_XDECREF_ERR(PyArrayObject *arr)
|
|||
(PyTuple_GET_ITEM((value), 2) == (key)))
|
||||
|
||||
|
||||
/* Define python version independent deprecation macro */
|
||||
|
||||
#if PY_VERSION_HEX >= 0x02050000
|
||||
#define DEPRECATE(msg) PyErr_WarnEx(PyExc_DeprecationWarning,msg,1)
|
||||
#define DEPRECATE_FUTUREWARNING(msg) PyErr_WarnEx(PyExc_FutureWarning,msg,1)
|
||||
#else
|
||||
#define DEPRECATE(msg) PyErr_Warn(PyExc_DeprecationWarning,msg)
|
||||
#define DEPRECATE_FUTUREWARNING(msg) PyErr_Warn(PyExc_FutureWarning,msg)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#ifndef NDARRAYTYPES_H
|
||||
#define NDARRAYTYPES_H
|
||||
|
||||
/* numpyconfig.h is auto-generated by the installer */
|
||||
#include "numpyconfig.h"
|
||||
|
||||
#include "npy_common.h"
|
||||
#include "npy_endian.h"
|
||||
#include "npy_cpu.h"
|
||||
|
@ -155,12 +158,6 @@ typedef enum {
|
|||
#define NPY_NSORTS (NPY_MERGESORT + 1)
|
||||
|
||||
|
||||
typedef enum {
|
||||
NPY_INTROSELECT=0
|
||||
} NPY_SELECTKIND;
|
||||
#define NPY_NSELECTS (NPY_INTROSELECT + 1)
|
||||
|
||||
|
||||
typedef enum {
|
||||
NPY_SEARCHLEFT=0,
|
||||
NPY_SEARCHRIGHT=1
|
||||
|
@ -202,7 +199,13 @@ typedef enum {
|
|||
/* Allow safe casts or casts within the same kind */
|
||||
NPY_SAME_KIND_CASTING=3,
|
||||
/* Allow any casts */
|
||||
NPY_UNSAFE_CASTING=4
|
||||
NPY_UNSAFE_CASTING=4,
|
||||
|
||||
/*
|
||||
* Temporary internal definition only, will be removed in upcoming
|
||||
* release, see below
|
||||
* */
|
||||
NPY_INTERNAL_UNSAFE_CASTING_BUT_WARN_UNLESS_SAME_KIND = 100,
|
||||
} NPY_CASTING;
|
||||
|
||||
typedef enum {
|
||||
|
@ -391,12 +394,6 @@ typedef int (PyArray_FillFunc)(void *, npy_intp, void *);
|
|||
|
||||
typedef int (PyArray_SortFunc)(void *, npy_intp, void *);
|
||||
typedef int (PyArray_ArgSortFunc)(void *, npy_intp *, npy_intp, void *);
|
||||
typedef int (PyArray_PartitionFunc)(void *, npy_intp, npy_intp,
|
||||
npy_intp *, npy_intp *,
|
||||
void *);
|
||||
typedef int (PyArray_ArgPartitionFunc)(void *, npy_intp *, npy_intp, npy_intp,
|
||||
npy_intp *, npy_intp *,
|
||||
void *);
|
||||
|
||||
typedef int (PyArray_FillWithScalarFunc)(void *, npy_intp, void *, void *);
|
||||
|
||||
|
@ -619,10 +616,6 @@ typedef struct _PyArray_Descr {
|
|||
* for NumPy 1.7.0.
|
||||
*/
|
||||
NpyAuxData *c_metadata;
|
||||
/* Cached hash value (-1 if not yet computed).
|
||||
* This was added for NumPy 2.0.0.
|
||||
*/
|
||||
npy_hash_t hash;
|
||||
} PyArray_Descr;
|
||||
|
||||
typedef struct _arr_descr {
|
||||
|
@ -637,8 +630,8 @@ typedef struct _arr_descr {
|
|||
* (PyArray_DATA and friends) to access fields here for a number of
|
||||
* releases. Direct access to the members themselves is deprecated.
|
||||
* To ensure that your code does not use deprecated access,
|
||||
* #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
|
||||
* (or NPY_1_8_API_VERSION or higher as required).
|
||||
* #define NPY_NO_DEPRECATED_API NPY_1_7_VERSION
|
||||
* (or NPY_1_8_VERSION or higher as required).
|
||||
*/
|
||||
/* This struct will be moved to a private header in a future release */
|
||||
typedef struct tagPyArrayObject_fields {
|
||||
|
@ -685,8 +678,7 @@ typedef struct tagPyArrayObject_fields {
|
|||
* To hide the implementation details, we only expose
|
||||
* the Python struct HEAD.
|
||||
*/
|
||||
#if !defined(NPY_NO_DEPRECATED_API) || \
|
||||
(NPY_NO_DEPRECATED_API < NPY_1_7_API_VERSION)
|
||||
#if !(defined(NPY_NO_DEPRECATED_API) && (NPY_API_VERSION <= NPY_NO_DEPRECATED_API))
|
||||
/*
|
||||
* Can't put this in npy_deprecated_api.h like the others.
|
||||
* PyArrayObject field access is deprecated as of NumPy 1.7.
|
||||
|
@ -765,14 +757,7 @@ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *);
|
|||
|
||||
/*
|
||||
* Note: all 0-d arrays are C_CONTIGUOUS and F_CONTIGUOUS. If a
|
||||
* 1-d array is C_CONTIGUOUS it is also F_CONTIGUOUS. Arrays with
|
||||
* more then one dimension can be C_CONTIGUOUS and F_CONTIGUOUS
|
||||
* at the same time if they have either zero or one element.
|
||||
* If NPY_RELAXED_STRIDES_CHECKING is set, a higher dimensional
|
||||
* array is always C_CONTIGUOUS and F_CONTIGUOUS if it has zero elements
|
||||
* and the array is contiguous if ndarray.squeeze() is contiguous.
|
||||
* I.e. dimensions for which `ndarray.shape[dimension] == 1` are
|
||||
* ignored.
|
||||
* 1-d array is C_CONTIGUOUS it is also F_CONTIGUOUS
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -926,16 +911,12 @@ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *);
|
|||
#define PyArray_IS_C_CONTIGUOUS(m) PyArray_CHKFLAGS(m, NPY_ARRAY_C_CONTIGUOUS)
|
||||
#define PyArray_IS_F_CONTIGUOUS(m) PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS)
|
||||
|
||||
/* the variable is used in some places, so always define it */
|
||||
#define NPY_BEGIN_THREADS_DEF PyThreadState *_save=NULL;
|
||||
#if NPY_ALLOW_THREADS
|
||||
#define NPY_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
|
||||
#define NPY_END_ALLOW_THREADS Py_END_ALLOW_THREADS
|
||||
#define NPY_BEGIN_THREADS_DEF PyThreadState *_save=NULL;
|
||||
#define NPY_BEGIN_THREADS do {_save = PyEval_SaveThread();} while (0);
|
||||
#define NPY_END_THREADS do { if (_save) \
|
||||
{ PyEval_RestoreThread(_save); _save = NULL;} } while (0);
|
||||
#define NPY_BEGIN_THREADS_THRESHOLDED(loop_size) do { if (loop_size > 500) \
|
||||
{ _save = PyEval_SaveThread();} } while (0);
|
||||
#define NPY_END_THREADS do {if (_save) PyEval_RestoreThread(_save);} while (0);
|
||||
|
||||
#define NPY_BEGIN_THREADS_DESCR(dtype) \
|
||||
do {if (!(PyDataType_FLAGCHK(dtype, NPY_NEEDS_PYAPI))) \
|
||||
|
@ -951,9 +932,9 @@ typedef int (PyArray_FinalizeFunc)(PyArrayObject *, PyObject *);
|
|||
#else
|
||||
#define NPY_BEGIN_ALLOW_THREADS
|
||||
#define NPY_END_ALLOW_THREADS
|
||||
#define NPY_BEGIN_THREADS_DEF
|
||||
#define NPY_BEGIN_THREADS
|
||||
#define NPY_END_THREADS
|
||||
#define NPY_BEGIN_THREADS_THRESHOLDED(loop_size)
|
||||
#define NPY_BEGIN_THREADS_DESCR(dtype)
|
||||
#define NPY_END_THREADS_DESCR(dtype)
|
||||
#define NPY_ALLOW_C_API_DEF
|
||||
|
@ -1099,6 +1080,27 @@ struct PyArrayIterObject_tag {
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define _PyArray_ITER_NEXT3(it) do { \
|
||||
if ((it)->coordinates[2] < (it)->dims_m1[2]) { \
|
||||
(it)->coordinates[2]++; \
|
||||
(it)->dataptr += (it)->strides[2]; \
|
||||
} \
|
||||
else { \
|
||||
(it)->coordinates[2] = 0; \
|
||||
(it)->dataptr -= (it)->backstrides[2]; \
|
||||
if ((it)->coordinates[1] < (it)->dims_m1[1]) { \
|
||||
(it)->coordinates[1]++; \
|
||||
(it)->dataptr += (it)->strides[1]; \
|
||||
} \
|
||||
else { \
|
||||
(it)->coordinates[1] = 0; \
|
||||
(it)->coordinates[0]++; \
|
||||
(it)->dataptr += (it)->strides[0] \
|
||||
(it)->backstrides[1]; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define PyArray_ITER_NEXT(it) do { \
|
||||
_PyAIT(it)->index++; \
|
||||
if (_PyAIT(it)->nd_m1 == 0) { \
|
||||
|
@ -1233,12 +1235,8 @@ typedef struct {
|
|||
#define PyArray_MultiIter_NOTDONE(multi) \
|
||||
(_PyMIT(multi)->index < _PyMIT(multi)->size)
|
||||
|
||||
/* Store the information needed for fancy-indexing over an array */
|
||||
|
||||
/*
|
||||
* Store the information needed for fancy-indexing over an array. The
|
||||
* fields are slightly unordered to keep consec, dataptr and subspace
|
||||
* where they were originally.
|
||||
*/
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
/*
|
||||
|
@ -1253,71 +1251,29 @@ typedef struct {
|
|||
npy_intp index; /* current index */
|
||||
int nd; /* number of dims */
|
||||
npy_intp dimensions[NPY_MAXDIMS]; /* dimensions */
|
||||
NpyIter *outer; /* index objects
|
||||
iterator */
|
||||
void *unused[NPY_MAXDIMS - 2];
|
||||
PyArrayObject *array;
|
||||
/* Flat iterator for the indexed array. For compatibility solely. */
|
||||
PyArrayIterObject *ait;
|
||||
PyArrayIterObject *iters[NPY_MAXDIMS]; /* index object
|
||||
iterators */
|
||||
PyArrayIterObject *ait; /* flat Iterator for
|
||||
underlying array */
|
||||
|
||||
/*
|
||||
* Subspace array. For binary compatibility (was an iterator,
|
||||
* but only the check for NULL should be used).
|
||||
*/
|
||||
PyArrayObject *subspace;
|
||||
/* flat iterator for subspace (when numiter < nd) */
|
||||
PyArrayIterObject *subspace;
|
||||
|
||||
/*
|
||||
* if subspace iteration, then this is the array of axes in
|
||||
* the underlying array represented by the index objects
|
||||
*/
|
||||
int iteraxes[NPY_MAXDIMS];
|
||||
npy_intp fancy_strides[NPY_MAXDIMS];
|
||||
|
||||
/* pointer when all fancy indices are 0 */
|
||||
char *baseoffset;
|
||||
|
||||
/*
|
||||
* after binding consec denotes at which axis the fancy axes
|
||||
* are inserted.
|
||||
* if subspace iteration, the these are the coordinates to the
|
||||
* start of the subspace.
|
||||
*/
|
||||
npy_intp bscoord[NPY_MAXDIMS];
|
||||
|
||||
PyObject *indexobj; /* creating obj */
|
||||
int consec;
|
||||
char *dataptr;
|
||||
|
||||
int nd_fancy;
|
||||
npy_intp fancy_dims[NPY_MAXDIMS];
|
||||
|
||||
/* Whether the iterator (any of the iterators) requires API */
|
||||
int needs_api;
|
||||
|
||||
/*
|
||||
* Extra op information.
|
||||
*/
|
||||
PyArrayObject *extra_op;
|
||||
PyArray_Descr *extra_op_dtype; /* desired dtype */
|
||||
npy_uint32 *extra_op_flags; /* Iterator flags */
|
||||
|
||||
NpyIter *extra_op_iter;
|
||||
NpyIter_IterNextFunc *extra_op_next;
|
||||
char **extra_op_ptrs;
|
||||
|
||||
/*
|
||||
* Information about the iteration state.
|
||||
*/
|
||||
NpyIter_IterNextFunc *outer_next;
|
||||
char **outer_ptrs;
|
||||
npy_intp *outer_strides;
|
||||
|
||||
/*
|
||||
* Information about the subspace iterator.
|
||||
*/
|
||||
NpyIter *subspace_iter;
|
||||
NpyIter_IterNextFunc *subspace_next;
|
||||
char **subspace_ptrs;
|
||||
npy_intp *subspace_strides;
|
||||
|
||||
/* Count for the external loop (which ever it is) for API iteration */
|
||||
npy_intp iter_count;
|
||||
|
||||
} PyArrayMapIterObject;
|
||||
|
||||
enum {
|
||||
|
@ -1414,12 +1370,12 @@ PyArrayNeighborhoodIter_Next2D(PyArrayNeighborhoodIterObject* iter);
|
|||
PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS))
|
||||
|
||||
#define PyArray_ISFORTRAN(m) (PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS) && \
|
||||
(!PyArray_CHKFLAGS(m, NPY_ARRAY_C_CONTIGUOUS)))
|
||||
(PyArray_NDIM(m) > 1))
|
||||
|
||||
#define PyArray_FORTRAN_IF(m) ((PyArray_CHKFLAGS(m, NPY_ARRAY_F_CONTIGUOUS) ? \
|
||||
NPY_ARRAY_F_CONTIGUOUS : 0))
|
||||
|
||||
#if (defined(NPY_NO_DEPRECATED_API) && (NPY_1_7_API_VERSION <= NPY_NO_DEPRECATED_API))
|
||||
#if (defined(NPY_NO_DEPRECATED_API) && (NPY_API_VERSION <= NPY_NO_DEPRECATED_API))
|
||||
/*
|
||||
* Changing access macros into functions, to allow for future hiding
|
||||
* of the internal memory layout. This later hiding will allow the 2.x series
|
||||
|
@ -1469,13 +1425,13 @@ PyArray_STRIDE(const PyArrayObject *arr, int istride)
|
|||
return ((PyArrayObject_fields *)arr)->strides[istride];
|
||||
}
|
||||
|
||||
static NPY_INLINE NPY_RETURNS_BORROWED_REF PyObject *
|
||||
static NPY_INLINE PyObject *
|
||||
PyArray_BASE(PyArrayObject *arr)
|
||||
{
|
||||
return ((PyArrayObject_fields *)arr)->base;
|
||||
}
|
||||
|
||||
static NPY_INLINE NPY_RETURNS_BORROWED_REF PyArray_Descr *
|
||||
static NPY_INLINE PyArray_Descr *
|
||||
PyArray_DESCR(PyArrayObject *arr)
|
||||
{
|
||||
return ((PyArrayObject_fields *)arr)->descr;
|
||||
|
@ -1768,30 +1724,8 @@ typedef struct {
|
|||
typedef void (PyDataMem_EventHookFunc)(void *inp, void *outp, size_t size,
|
||||
void *user_data);
|
||||
|
||||
/*
|
||||
* Use the keyword NPY_DEPRECATED_INCLUDES to ensure that the header files
|
||||
* npy_*_*_deprecated_api.h are only included from here and nowhere else.
|
||||
*/
|
||||
#ifdef NPY_DEPRECATED_INCLUDES
|
||||
#error "Do not use the reserved keyword NPY_DEPRECATED_INCLUDES."
|
||||
#if !(defined(NPY_NO_DEPRECATED_API) && (NPY_API_VERSION <= NPY_NO_DEPRECATED_API))
|
||||
#include "npy_deprecated_api.h"
|
||||
#endif
|
||||
#define NPY_DEPRECATED_INCLUDES
|
||||
#if !defined(NPY_NO_DEPRECATED_API) || \
|
||||
(NPY_NO_DEPRECATED_API < NPY_1_7_API_VERSION)
|
||||
#include "npy_1_7_deprecated_api.h"
|
||||
#endif
|
||||
/*
|
||||
* There is no file npy_1_8_deprecated_api.h since there are no additional
|
||||
* deprecated API features in NumPy 1.8.
|
||||
*
|
||||
* Note to maintainers: insert code like the following in future NumPy
|
||||
* versions.
|
||||
*
|
||||
* #if !defined(NPY_NO_DEPRECATED_API) || \
|
||||
* (NPY_NO_DEPRECATED_API < NPY_1_9_API_VERSION)
|
||||
* #include "npy_1_9_deprecated_api.h"
|
||||
* #endif
|
||||
*/
|
||||
#undef NPY_DEPRECATED_INCLUDES
|
||||
|
||||
#endif /* NPY_ARRAYTYPES_H */
|
||||
|
|
|
@ -64,11 +64,8 @@
|
|||
#define datetime npy_datetime
|
||||
#define timedelta npy_timedelta
|
||||
|
||||
#define SIZEOF_LONGLONG NPY_SIZEOF_LONGLONG
|
||||
#define SIZEOF_INTP NPY_SIZEOF_INTP
|
||||
#define SIZEOF_UINTP NPY_SIZEOF_UINTP
|
||||
#define SIZEOF_HALF NPY_SIZEOF_HALF
|
||||
#define SIZEOF_LONGDOUBLE NPY_SIZEOF_LONGDOUBLE
|
||||
#define SIZEOF_DATETIME NPY_SIZEOF_DATETIME
|
||||
#define SIZEOF_TIMEDELTA NPY_SIZEOF_TIMEDELTA
|
||||
|
||||
|
@ -116,6 +113,9 @@
|
|||
#define MIN_TIMEDELTA NPY_MIN_TIMEDELTA
|
||||
#define MAX_TIMEDELTA NPY_MAX_TIMEDELTA
|
||||
|
||||
#define SIZEOF_LONGDOUBLE NPY_SIZEOF_LONGDOUBLE
|
||||
#define SIZEOF_LONGLONG NPY_SIZEOF_LONGLONG
|
||||
#define SIZEOF_HALF NPY_SIZEOF_HALF
|
||||
#define BITSOF_BOOL NPY_BITSOF_BOOL
|
||||
#define BITSOF_CHAR NPY_BITSOF_CHAR
|
||||
#define BITSOF_SHORT NPY_BITSOF_SHORT
|
||||
|
|
|
@ -141,17 +141,17 @@ PyUnicode_Concat2(PyObject **left, PyObject *right)
|
|||
* PyFile_* compatibility
|
||||
*/
|
||||
#if defined(NPY_PY3K)
|
||||
|
||||
/*
|
||||
* Get a FILE* handle to the file represented by the Python object
|
||||
*/
|
||||
static NPY_INLINE FILE*
|
||||
npy_PyFile_Dup2(PyObject *file, char *mode, npy_off_t *orig_pos)
|
||||
npy_PyFile_Dup(PyObject *file, char *mode)
|
||||
{
|
||||
int fd, fd2;
|
||||
PyObject *ret, *os;
|
||||
npy_off_t pos;
|
||||
Py_ssize_t pos;
|
||||
FILE *handle;
|
||||
|
||||
/* Flush first to ensure things end up in the file in the correct order */
|
||||
ret = PyObject_CallMethod(file, "flush", "");
|
||||
if (ret == NULL) {
|
||||
|
@ -162,11 +162,6 @@ npy_PyFile_Dup2(PyObject *file, char *mode, npy_off_t *orig_pos)
|
|||
if (fd == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* The handle needs to be dup'd because we have to call fclose
|
||||
* at the end
|
||||
*/
|
||||
os = PyImport_ImportModule("os");
|
||||
if (os == NULL) {
|
||||
return NULL;
|
||||
|
@ -178,8 +173,6 @@ npy_PyFile_Dup2(PyObject *file, char *mode, npy_off_t *orig_pos)
|
|||
}
|
||||
fd2 = PyNumber_AsSsize_t(ret, NULL);
|
||||
Py_DECREF(ret);
|
||||
|
||||
/* Convert to FILE* handle */
|
||||
#ifdef _WIN32
|
||||
handle = _fdopen(fd2, mode);
|
||||
#else
|
||||
|
@ -189,32 +182,18 @@ npy_PyFile_Dup2(PyObject *file, char *mode, npy_off_t *orig_pos)
|
|||
PyErr_SetString(PyExc_IOError,
|
||||
"Getting a FILE* from a Python file object failed");
|
||||
}
|
||||
|
||||
/* Record the original raw file handle position */
|
||||
*orig_pos = npy_ftell(handle);
|
||||
if (*orig_pos == -1) {
|
||||
PyErr_SetString(PyExc_IOError, "obtaining file position failed");
|
||||
fclose(handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Seek raw handle to the Python-side position */
|
||||
ret = PyObject_CallMethod(file, "tell", "");
|
||||
if (ret == NULL) {
|
||||
fclose(handle);
|
||||
return NULL;
|
||||
}
|
||||
pos = PyLong_AsLongLong(ret);
|
||||
pos = PyNumber_AsSsize_t(ret, PyExc_OverflowError);
|
||||
Py_DECREF(ret);
|
||||
if (PyErr_Occurred()) {
|
||||
fclose(handle);
|
||||
return NULL;
|
||||
}
|
||||
if (npy_fseek(handle, pos, SEEK_SET) == -1) {
|
||||
PyErr_SetString(PyExc_IOError, "seeking file failed");
|
||||
fclose(handle);
|
||||
return NULL;
|
||||
}
|
||||
npy_fseek(handle, pos, SEEK_SET);
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
@ -222,37 +201,14 @@ npy_PyFile_Dup2(PyObject *file, char *mode, npy_off_t *orig_pos)
|
|||
* Close the dup-ed file handle, and seek the Python one to the current position
|
||||
*/
|
||||
static NPY_INLINE int
|
||||
npy_PyFile_DupClose2(PyObject *file, FILE* handle, npy_off_t orig_pos)
|
||||
npy_PyFile_DupClose(PyObject *file, FILE* handle)
|
||||
{
|
||||
int fd;
|
||||
PyObject *ret;
|
||||
npy_off_t position;
|
||||
|
||||
Py_ssize_t position;
|
||||
position = npy_ftell(handle);
|
||||
|
||||
/* Close the FILE* handle */
|
||||
fclose(handle);
|
||||
|
||||
/*
|
||||
* Restore original file handle position, in order to not confuse
|
||||
* Python-side data structures
|
||||
*/
|
||||
fd = PyObject_AsFileDescriptor(file);
|
||||
if (fd == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (npy_lseek(fd, orig_pos, SEEK_SET) == -1) {
|
||||
PyErr_SetString(PyExc_IOError, "seeking file failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (position == -1) {
|
||||
PyErr_SetString(PyExc_IOError, "obtaining file position failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Seek Python-side handle to the FILE* handle position */
|
||||
ret = PyObject_CallMethod(file, "seek", NPY_OFF_T_PYFMT "i", position, 0);
|
||||
ret = PyObject_CallMethod(file, "seek", NPY_SSIZE_T_PYFMT "i", position, 0);
|
||||
if (ret == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -274,20 +230,8 @@ npy_PyFile_Check(PyObject *file)
|
|||
|
||||
#else
|
||||
|
||||
static NPY_INLINE FILE *
|
||||
npy_PyFile_Dup2(PyObject *file,
|
||||
const char *NPY_UNUSED(mode), npy_off_t *NPY_UNUSED(orig_pos))
|
||||
{
|
||||
return PyFile_AsFile(file);
|
||||
}
|
||||
|
||||
static NPY_INLINE int
|
||||
npy_PyFile_DupClose2(PyObject *NPY_UNUSED(file), FILE* NPY_UNUSED(handle),
|
||||
npy_off_t NPY_UNUSED(orig_pos))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define npy_PyFile_Dup(file, mode) PyFile_AsFile(file)
|
||||
#define npy_PyFile_DupClose(file, handle) (0)
|
||||
#define npy_PyFile_Check PyFile_Check
|
||||
|
||||
#endif
|
||||
|
@ -325,7 +269,7 @@ PyObject_Cmp(PyObject *i1, PyObject *i2, int *cmp)
|
|||
{
|
||||
int v;
|
||||
v = PyObject_RichCompareBool(i1, i2, Py_LT);
|
||||
if (v == 1) {
|
||||
if (v == 0) {
|
||||
*cmp = -1;
|
||||
return 1;
|
||||
}
|
||||
|
@ -334,7 +278,7 @@ PyObject_Cmp(PyObject *i1, PyObject *i2, int *cmp)
|
|||
}
|
||||
|
||||
v = PyObject_RichCompareBool(i1, i2, Py_GT);
|
||||
if (v == 1) {
|
||||
if (v == 0) {
|
||||
*cmp = 1;
|
||||
return 1;
|
||||
}
|
||||
|
@ -343,7 +287,7 @@ PyObject_Cmp(PyObject *i1, PyObject *i2, int *cmp)
|
|||
}
|
||||
|
||||
v = PyObject_RichCompareBool(i1, i2, Py_EQ);
|
||||
if (v == 1) {
|
||||
if (v == 0) {
|
||||
*cmp = 0;
|
||||
return 1;
|
||||
}
|
||||
|
@ -406,6 +350,12 @@ NpyCapsule_Check(PyObject *ptr)
|
|||
return PyCapsule_CheckExact(ptr);
|
||||
}
|
||||
|
||||
static NPY_INLINE void
|
||||
simple_capsule_dtor(PyObject *cap)
|
||||
{
|
||||
PyArray_free(PyCapsule_GetPointer(cap, NULL));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static NPY_INLINE PyObject *
|
||||
|
@ -439,6 +389,25 @@ NpyCapsule_Check(PyObject *ptr)
|
|||
return PyCObject_Check(ptr);
|
||||
}
|
||||
|
||||
static NPY_INLINE void
|
||||
simple_capsule_dtor(void *ptr)
|
||||
{
|
||||
PyArray_free(ptr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Hash value compatibility.
|
||||
* As of Python 3.2 hash values are of type Py_hash_t.
|
||||
* Previous versions use C long.
|
||||
*/
|
||||
#if PY_VERSION_HEX < 0x03020000
|
||||
typedef long npy_hash_t;
|
||||
#define NPY_SIZEOF_HASH_T NPY_SIZEOF_LONG
|
||||
#else
|
||||
typedef Py_hash_t npy_hash_t;
|
||||
#define NPY_SIZEOF_HASH_T NPY_SIZEOF_INTP
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -3,63 +3,6 @@
|
|||
|
||||
/* numpconfig.h is auto-generated */
|
||||
#include "numpyconfig.h"
|
||||
#ifdef HAVE_NPY_CONFIG_H
|
||||
#include <npy_config.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* gcc does not unroll even with -O3
|
||||
* use with care, unrolling on modern cpus rarely speeds things up
|
||||
*/
|
||||
#ifdef HAVE_ATTRIBUTE_OPTIMIZE_UNROLL_LOOPS
|
||||
#define NPY_GCC_UNROLL_LOOPS \
|
||||
__attribute__((optimize("unroll-loops")))
|
||||
#else
|
||||
#define NPY_GCC_UNROLL_LOOPS
|
||||
#endif
|
||||
|
||||
/* highest gcc optimization level, enabled autovectorizer */
|
||||
#ifdef HAVE_ATTRIBUTE_OPTIMIZE_OPT_3
|
||||
#define NPY_GCC_OPT_3 __attribute__((optimize("O3")))
|
||||
#else
|
||||
#define NPY_GCC_OPT_3
|
||||
#endif
|
||||
|
||||
/*
|
||||
* mark an argument (starting from 1) that must not be NULL and is not checked
|
||||
* DO NOT USE IF FUNCTION CHECKS FOR NULL!! the compiler will remove the check
|
||||
*/
|
||||
#ifdef HAVE_ATTRIBUTE_NONNULL
|
||||
#define NPY_GCC_NONNULL(n) __attribute__((nonnull(n)))
|
||||
#else
|
||||
#define NPY_GCC_NONNULL(n)
|
||||
#endif
|
||||
|
||||
#if defined HAVE_XMMINTRIN_H && defined HAVE__MM_LOAD_PS
|
||||
#define NPY_HAVE_SSE_INTRINSICS
|
||||
#endif
|
||||
|
||||
#if defined HAVE_EMMINTRIN_H && defined HAVE__MM_LOAD_PD
|
||||
#define NPY_HAVE_SSE2_INTRINSICS
|
||||
#endif
|
||||
|
||||
/*
|
||||
* give a hint to the compiler which branch is more likely or unlikely
|
||||
* to occur, e.g. rare error cases:
|
||||
*
|
||||
* if (NPY_UNLIKELY(failure == 0))
|
||||
* return NULL;
|
||||
*
|
||||
* the double !! is to cast the expression (e.g. NULL) to a boolean required by
|
||||
* the intrinsic
|
||||
*/
|
||||
#ifdef HAVE___BUILTIN_EXPECT
|
||||
#define NPY_LIKELY(x) __builtin_expect(!!(x), 1)
|
||||
#define NPY_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||
#else
|
||||
#define NPY_LIKELY(x) (x)
|
||||
#define NPY_UNLIKELY(x) (x)
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define NPY_INLINE __inline
|
||||
|
@ -73,82 +16,14 @@
|
|||
#define NPY_INLINE
|
||||
#endif
|
||||
|
||||
#ifdef HAVE___THREAD
|
||||
#define NPY_TLS __thread
|
||||
#else
|
||||
#ifdef HAVE___DECLSPEC_THREAD_
|
||||
#define NPY_TLS __declspec(thread)
|
||||
#else
|
||||
#define NPY_TLS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef WITH_CPYCHECKER_RETURNS_BORROWED_REF_ATTRIBUTE
|
||||
#define NPY_RETURNS_BORROWED_REF \
|
||||
__attribute__((cpychecker_returns_borrowed_ref))
|
||||
#else
|
||||
#define NPY_RETURNS_BORROWED_REF
|
||||
#endif
|
||||
|
||||
#ifdef WITH_CPYCHECKER_STEALS_REFERENCE_TO_ARG_ATTRIBUTE
|
||||
#define NPY_STEALS_REF_TO_ARG(n) \
|
||||
__attribute__((cpychecker_steals_reference_to_arg(n)))
|
||||
#else
|
||||
#define NPY_STEALS_REF_TO_ARG(n)
|
||||
#endif
|
||||
|
||||
/* 64 bit file position support, also on win-amd64. Ticket #1660 */
|
||||
#if defined(_MSC_VER) && defined(_WIN64) && (_MSC_VER > 1400) || \
|
||||
defined(__MINGW32__) || defined(__MINGW64__)
|
||||
#include <io.h>
|
||||
|
||||
/* mingw based on 3.4.5 has lseek but not ftell/fseek */
|
||||
#if defined(__MINGW32__) || defined(__MINGW64__)
|
||||
extern int __cdecl _fseeki64(FILE *, long long, int);
|
||||
extern long long __cdecl _ftelli64(FILE *);
|
||||
#endif
|
||||
|
||||
/* Enable 64 bit file position support on win-amd64. Ticket #1660 */
|
||||
#if defined(_MSC_VER) && defined(_WIN64) && (_MSC_VER > 1400)
|
||||
#define npy_fseek _fseeki64
|
||||
#define npy_ftell _ftelli64
|
||||
#define npy_lseek _lseeki64
|
||||
#define npy_off_t npy_int64
|
||||
|
||||
#if NPY_SIZEOF_INT == 8
|
||||
#define NPY_OFF_T_PYFMT "i"
|
||||
#elif NPY_SIZEOF_LONG == 8
|
||||
#define NPY_OFF_T_PYFMT "l"
|
||||
#elif NPY_SIZEOF_LONGLONG == 8
|
||||
#define NPY_OFF_T_PYFMT "L"
|
||||
#else
|
||||
#error Unsupported size for type off_t
|
||||
#endif
|
||||
#else
|
||||
#ifdef HAVE_FSEEKO
|
||||
#define npy_fseek fseeko
|
||||
#else
|
||||
#define npy_fseek fseek
|
||||
#endif
|
||||
#ifdef HAVE_FTELLO
|
||||
#define npy_ftell ftello
|
||||
#else
|
||||
#define npy_ftell ftell
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#define npy_lseek lseek
|
||||
#define npy_off_t off_t
|
||||
|
||||
#if NPY_SIZEOF_OFF_T == NPY_SIZEOF_SHORT
|
||||
#define NPY_OFF_T_PYFMT "h"
|
||||
#elif NPY_SIZEOF_OFF_T == NPY_SIZEOF_INT
|
||||
#define NPY_OFF_T_PYFMT "i"
|
||||
#elif NPY_SIZEOF_OFF_T == NPY_SIZEOF_LONG
|
||||
#define NPY_OFF_T_PYFMT "l"
|
||||
#elif NPY_SIZEOF_OFF_T == NPY_SIZEOF_LONGLONG
|
||||
#define NPY_OFF_T_PYFMT "L"
|
||||
#else
|
||||
#error Unsupported size for type off_t
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* enums for detected endianness */
|
||||
enum {
|
||||
|
@ -158,22 +33,15 @@ enum {
|
|||
};
|
||||
|
||||
/*
|
||||
* This is to typedef npy_intp to the appropriate pointer size for this
|
||||
* platform. Py_intptr_t, Py_uintptr_t are defined in pyport.h.
|
||||
* This is to typedef npy_intp to the appropriate pointer size for
|
||||
* this platform. Py_intptr_t, Py_uintptr_t are defined in pyport.h.
|
||||
*/
|
||||
typedef Py_intptr_t npy_intp;
|
||||
typedef Py_uintptr_t npy_uintp;
|
||||
|
||||
/*
|
||||
* Define sizes that were not defined in numpyconfig.h.
|
||||
*/
|
||||
#define NPY_SIZEOF_CHAR 1
|
||||
#define NPY_SIZEOF_BYTE 1
|
||||
#define NPY_SIZEOF_DATETIME 8
|
||||
#define NPY_SIZEOF_TIMEDELTA 8
|
||||
#define NPY_SIZEOF_INTP NPY_SIZEOF_PY_INTPTR_T
|
||||
#define NPY_SIZEOF_UINTP NPY_SIZEOF_PY_INTPTR_T
|
||||
#define NPY_SIZEOF_HALF 2
|
||||
#define NPY_SIZEOF_CFLOAT NPY_SIZEOF_COMPLEX_FLOAT
|
||||
#define NPY_SIZEOF_CDOUBLE NPY_SIZEOF_COMPLEX_DOUBLE
|
||||
#define NPY_SIZEOF_CLONGDOUBLE NPY_SIZEOF_COMPLEX_LONGDOUBLE
|
||||
|
@ -182,8 +50,18 @@ typedef Py_uintptr_t npy_uintp;
|
|||
#undef constchar
|
||||
#endif
|
||||
|
||||
#if (PY_VERSION_HEX < 0x02050000)
|
||||
#ifndef PY_SSIZE_T_MIN
|
||||
typedef int Py_ssize_t;
|
||||
#define PY_SSIZE_T_MAX INT_MAX
|
||||
#define PY_SSIZE_T_MIN INT_MIN
|
||||
#endif
|
||||
#define NPY_SSIZE_T_PYFMT "i"
|
||||
#define constchar const char
|
||||
#else
|
||||
#define NPY_SSIZE_T_PYFMT "n"
|
||||
#define constchar char
|
||||
#endif
|
||||
|
||||
/* NPY_INTP_FMT Note:
|
||||
* Unlike the other NPY_*_FMT macros which are used with
|
||||
|
@ -265,9 +143,18 @@ typedef unsigned PY_LONG_LONG npy_ulonglong;
|
|||
# ifdef _MSC_VER
|
||||
# define NPY_LONGLONG_FMT "I64d"
|
||||
# define NPY_ULONGLONG_FMT "I64u"
|
||||
# else
|
||||
# elif defined(__APPLE__) || defined(__FreeBSD__)
|
||||
/* "%Ld" only parses 4 bytes -- "L" is floating modifier on MacOS X/BSD */
|
||||
# define NPY_LONGLONG_FMT "lld"
|
||||
# define NPY_ULONGLONG_FMT "llu"
|
||||
/*
|
||||
another possible variant -- *quad_t works on *BSD, but is deprecated:
|
||||
#define LONGLONG_FMT "qd"
|
||||
#define ULONGLONG_FMT "qu"
|
||||
*/
|
||||
# else
|
||||
# define NPY_LONGLONG_FMT "Ld"
|
||||
# define NPY_ULONGLONG_FMT "Lu"
|
||||
# endif
|
||||
# ifdef _MSC_VER
|
||||
# define NPY_LONGLONG_SUFFIX(x) (x##i64)
|
||||
|
@ -316,19 +203,6 @@ typedef long npy_long;
|
|||
typedef float npy_float;
|
||||
typedef double npy_double;
|
||||
|
||||
/*
|
||||
* Hash value compatibility.
|
||||
* As of Python 3.2 hash values are of type Py_hash_t.
|
||||
* Previous versions use C long.
|
||||
*/
|
||||
#if PY_VERSION_HEX < 0x03020000
|
||||
typedef long npy_hash_t;
|
||||
#define NPY_SIZEOF_HASH_T NPY_SIZEOF_LONG
|
||||
#else
|
||||
typedef Py_hash_t npy_hash_t;
|
||||
#define NPY_SIZEOF_HASH_T NPY_SIZEOF_INTP
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Disabling C99 complex usage: a lot of C code in numpy/scipy rely on being
|
||||
* able to do .real/.imag. Will have to convert code first.
|
||||
|
@ -431,6 +305,10 @@ typedef struct { npy_longdouble real, imag; } npy_clongdouble;
|
|||
#define NPY_MIN_LONG LONG_MIN
|
||||
#define NPY_MAX_ULONG ULONG_MAX
|
||||
|
||||
#define NPY_SIZEOF_HALF 2
|
||||
#define NPY_SIZEOF_DATETIME 8
|
||||
#define NPY_SIZEOF_TIMEDELTA 8
|
||||
|
||||
#define NPY_BITSOF_BOOL (sizeof(npy_bool) * CHAR_BIT)
|
||||
#define NPY_BITSOF_CHAR CHAR_BIT
|
||||
#define NPY_BITSOF_BYTE (NPY_SIZEOF_BYTE * CHAR_BIT)
|
||||
|
@ -1049,3 +927,4 @@ typedef npy_int64 npy_datetime;
|
|||
/* End of typedefs for numarray style bit-width names */
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
* NPY_CPU_AMD64
|
||||
* NPY_CPU_PPC
|
||||
* NPY_CPU_PPC64
|
||||
* NPY_CPU_PPC64LE
|
||||
* NPY_CPU_SPARC
|
||||
* NPY_CPU_S390
|
||||
* NPY_CPU_IA64
|
||||
|
@ -20,7 +19,6 @@
|
|||
#define _NPY_CPUARCH_H_
|
||||
|
||||
#include "numpyconfig.h"
|
||||
#include <string.h> /* for memcpy */
|
||||
|
||||
#if defined( __i386__ ) || defined(i386) || defined(_M_IX86)
|
||||
/*
|
||||
|
@ -43,8 +41,6 @@
|
|||
* _ARCH_PPC is used by at least gcc on AIX
|
||||
*/
|
||||
#define NPY_CPU_PPC
|
||||
#elif defined(__ppc64le__)
|
||||
#define NPY_CPU_PPC64LE
|
||||
#elif defined(__ppc64__)
|
||||
#define NPY_CPU_PPC64
|
||||
#elif defined(__sparc__) || defined(__sparc)
|
||||
|
@ -70,23 +66,44 @@
|
|||
#define NPY_CPU_MIPSEL
|
||||
#elif defined(__MIPSEB__)
|
||||
#define NPY_CPU_MIPSEB
|
||||
#elif defined(__or1k__)
|
||||
#define NPY_CPU_OR1K
|
||||
#elif defined(__aarch64__)
|
||||
#define NPY_CPU_AARCH64
|
||||
#elif defined(__mc68000__)
|
||||
#define NPY_CPU_M68K
|
||||
#else
|
||||
#error Unknown CPU, please report this to numpy maintainers with \
|
||||
information about your platform (OS, CPU and compiler)
|
||||
#endif
|
||||
|
||||
#define NPY_COPY_PYOBJECT_PTR(dst, src) memcpy(dst, src, sizeof(PyObject *))
|
||||
/*
|
||||
This "white-lists" the architectures that we know don't require
|
||||
pointer alignment. We white-list, since the memcpy version will
|
||||
work everywhere, whereas assignment will only work where pointer
|
||||
dereferencing doesn't require alignment.
|
||||
|
||||
#if (defined(NPY_CPU_X86) || defined(NPY_CPU_AMD64))
|
||||
#define NPY_CPU_HAVE_UNALIGNED_ACCESS 1
|
||||
TODO: There may be more architectures we can white list.
|
||||
*/
|
||||
#if defined(NPY_CPU_X86) || defined(NPY_CPU_AMD64)
|
||||
#define NPY_COPY_PYOBJECT_PTR(dst, src) (*((PyObject **)(dst)) = *((PyObject **)(src)))
|
||||
#else
|
||||
#define NPY_CPU_HAVE_UNALIGNED_ACCESS 0
|
||||
#if NPY_SIZEOF_PY_INTPTR_T == 4
|
||||
#define NPY_COPY_PYOBJECT_PTR(dst, src) \
|
||||
((char*)(dst))[0] = ((char*)(src))[0]; \
|
||||
((char*)(dst))[1] = ((char*)(src))[1]; \
|
||||
((char*)(dst))[2] = ((char*)(src))[2]; \
|
||||
((char*)(dst))[3] = ((char*)(src))[3];
|
||||
#elif NPY_SIZEOF_PY_INTPTR_T == 8
|
||||
#define NPY_COPY_PYOBJECT_PTR(dst, src) \
|
||||
((char*)(dst))[0] = ((char*)(src))[0]; \
|
||||
((char*)(dst))[1] = ((char*)(src))[1]; \
|
||||
((char*)(dst))[2] = ((char*)(src))[2]; \
|
||||
((char*)(dst))[3] = ((char*)(src))[3]; \
|
||||
((char*)(dst))[4] = ((char*)(src))[4]; \
|
||||
((char*)(dst))[5] = ((char*)(src))[5]; \
|
||||
((char*)(dst))[6] = ((char*)(src))[6]; \
|
||||
((char*)(dst))[7] = ((char*)(src))[7];
|
||||
#else
|
||||
#error Unknown architecture, please report this to numpy maintainers with \
|
||||
information about your platform (OS, CPU and compiler)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
#ifndef _NPY_1_7_DEPRECATED_API_H
|
||||
#define _NPY_1_7_DEPRECATED_API_H
|
||||
|
||||
#ifndef NPY_DEPRECATED_INCLUDES
|
||||
#error "Should never include npy_*_*_deprecated_api directly."
|
||||
#endif
|
||||
#ifndef _NPY_DEPRECATED_API_H
|
||||
#define _NPY_DEPRECATED_API_H
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define _WARN___STR2__(x) #x
|
||||
|
@ -12,19 +8,21 @@
|
|||
#pragma message(_WARN___LOC__"Using deprecated NumPy API, disable it by " \
|
||||
"#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION")
|
||||
#elif defined(__GNUC__)
|
||||
#warning "Using deprecated NumPy API, disable it by " \
|
||||
"#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION"
|
||||
#warning "Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION"
|
||||
#endif
|
||||
/* TODO: How to do this warning message for other compilers? */
|
||||
|
||||
/*
|
||||
* This header exists to collect all dangerous/deprecated NumPy API
|
||||
* as of NumPy 1.7.
|
||||
* This header exists to collect all dangerous/deprecated NumPy API.
|
||||
*
|
||||
* This is an attempt to remove bad API, the proliferation of macros,
|
||||
* and namespace pollution currently produced by the NumPy headers.
|
||||
*/
|
||||
|
||||
#if defined(NPY_NO_DEPRECATED_API)
|
||||
#error Should never include npy_deprecated_api directly.
|
||||
#endif
|
||||
|
||||
/* These array flags are deprecated as of NumPy 1.7 */
|
||||
#define NPY_CONTIGUOUS NPY_ARRAY_C_CONTIGUOUS
|
||||
#define NPY_FORTRAN NPY_ARRAY_F_CONTIGUOUS
|
||||
|
@ -127,4 +125,5 @@
|
|||
*/
|
||||
#include "old_defines.h"
|
||||
|
||||
|
||||
#endif
|
|
@ -10,22 +10,10 @@
|
|||
/* Use endian.h if available */
|
||||
#include <endian.h>
|
||||
|
||||
#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && defined(LITTLE_ENDIAN)
|
||||
#define NPY_BYTE_ORDER BYTE_ORDER
|
||||
#define NPY_LITTLE_ENDIAN LITTLE_ENDIAN
|
||||
#define NPY_BIG_ENDIAN BIG_ENDIAN
|
||||
#elif defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN)
|
||||
#define NPY_BYTE_ORDER _BYTE_ORDER
|
||||
#define NPY_LITTLE_ENDIAN _LITTLE_ENDIAN
|
||||
#define NPY_BIG_ENDIAN _BIG_ENDIAN
|
||||
#elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && defined(__LITTLE_ENDIAN)
|
||||
#define NPY_BYTE_ORDER __BYTE_ORDER
|
||||
#define NPY_LITTLE_ENDIAN __LITTLE_ENDIAN
|
||||
#define NPY_BIG_ENDIAN __BIG_ENDIAN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef NPY_BYTE_ORDER
|
||||
#else
|
||||
/* Set endianness info using target CPU */
|
||||
#include "npy_cpu.h"
|
||||
|
||||
|
@ -39,8 +27,7 @@
|
|||
|| defined(NPY_CPU_ARMEL) \
|
||||
|| defined(NPY_CPU_AARCH64) \
|
||||
|| defined(NPY_CPU_SH_LE) \
|
||||
|| defined(NPY_CPU_MIPSEL) \
|
||||
|| defined(NPY_CPU_PPC64LE)
|
||||
|| defined(NPY_CPU_MIPSEL)
|
||||
#define NPY_BYTE_ORDER NPY_LITTLE_ENDIAN
|
||||
#elif defined(NPY_CPU_PPC) \
|
||||
|| defined(NPY_CPU_SPARC) \
|
||||
|
@ -49,9 +36,7 @@
|
|||
|| defined(NPY_CPU_PPC64) \
|
||||
|| defined(NPY_CPU_ARMEB) \
|
||||
|| defined(NPY_CPU_SH_BE) \
|
||||
|| defined(NPY_CPU_MIPSEB) \
|
||||
|| defined(NPY_CPU_OR1K) \
|
||||
|| defined(NPY_CPU_M68K)
|
||||
|| defined(NPY_CPU_MIPSEB)
|
||||
#define NPY_BYTE_ORDER NPY_BIG_ENDIAN
|
||||
#else
|
||||
#error Unknown CPU: can not set endianness
|
||||
|
|
|
@ -1,20 +1,12 @@
|
|||
#ifndef __NPY_MATH_C99_H_
|
||||
#define __NPY_MATH_C99_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#ifdef __SUNPRO_CC
|
||||
#include <sunmath.h>
|
||||
#endif
|
||||
#ifdef HAVE_NPY_CONFIG_H
|
||||
#include <npy_config.h>
|
||||
#endif
|
||||
#include <numpy/npy_common.h>
|
||||
|
||||
|
||||
/*
|
||||
* NAN and INFINITY like macros (same behavior as glibc for NAN, same as C99
|
||||
* for INFINITY)
|
||||
|
@ -118,12 +110,15 @@ double npy_tanh(double x);
|
|||
double npy_asin(double x);
|
||||
double npy_acos(double x);
|
||||
double npy_atan(double x);
|
||||
double npy_aexp(double x);
|
||||
double npy_alog(double x);
|
||||
double npy_asqrt(double x);
|
||||
double npy_afabs(double x);
|
||||
|
||||
double npy_log(double x);
|
||||
double npy_log10(double x);
|
||||
double npy_exp(double x);
|
||||
double npy_sqrt(double x);
|
||||
double npy_cbrt(double x);
|
||||
|
||||
double npy_fabs(double x);
|
||||
double npy_ceil(double x);
|
||||
|
@ -144,8 +139,6 @@ double npy_log2(double x);
|
|||
double npy_atan2(double x, double y);
|
||||
double npy_pow(double x, double y);
|
||||
double npy_modf(double x, double* y);
|
||||
double npy_frexp(double x, int* y);
|
||||
double npy_ldexp(double n, int y);
|
||||
|
||||
double npy_copysign(double x, double y);
|
||||
double npy_nextafter(double x, double y);
|
||||
|
@ -154,28 +147,16 @@ double npy_spacing(double x);
|
|||
/*
|
||||
* IEEE 754 fpu handling. Those are guaranteed to be macros
|
||||
*/
|
||||
|
||||
/* use builtins to avoid function calls in tight loops
|
||||
* only available if npy_config.h is available (= numpys own build) */
|
||||
#if HAVE___BUILTIN_ISNAN
|
||||
#define npy_isnan(x) __builtin_isnan(x)
|
||||
#else
|
||||
#ifndef NPY_HAVE_DECL_ISNAN
|
||||
#define npy_isnan(x) ((x) != (x))
|
||||
#else
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||
#ifdef _MSC_VER
|
||||
#define npy_isnan(x) _isnan((x))
|
||||
#else
|
||||
#define npy_isnan(x) isnan(x)
|
||||
#endif
|
||||
#define npy_isnan(x) isnan((x))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* only available if npy_config.h is available (= numpys own build) */
|
||||
#if HAVE___BUILTIN_ISFINITE
|
||||
#define npy_isfinite(x) __builtin_isfinite(x)
|
||||
#else
|
||||
#ifndef NPY_HAVE_DECL_ISFINITE
|
||||
#ifdef _MSC_VER
|
||||
#define npy_isfinite(x) _finite((x))
|
||||
|
@ -185,22 +166,16 @@ double npy_spacing(double x);
|
|||
#else
|
||||
#define npy_isfinite(x) isfinite((x))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* only available if npy_config.h is available (= numpys own build) */
|
||||
#if HAVE___BUILTIN_ISINF
|
||||
#define npy_isinf(x) __builtin_isinf(x)
|
||||
#else
|
||||
#ifndef NPY_HAVE_DECL_ISINF
|
||||
#define npy_isinf(x) (!npy_isfinite(x) && !npy_isnan(x))
|
||||
#else
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||
#ifdef _MSC_VER
|
||||
#define npy_isinf(x) (!_finite((x)) && !_isnan((x)))
|
||||
#else
|
||||
#define npy_isinf(x) isinf((x))
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef NPY_HAVE_DECL_SIGNBIT
|
||||
int _npy_signbit_f(float x);
|
||||
|
@ -230,7 +205,6 @@ float npy_ceilf(float x);
|
|||
float npy_rintf(float x);
|
||||
float npy_truncf(float x);
|
||||
float npy_sqrtf(float x);
|
||||
float npy_cbrtf(float x);
|
||||
float npy_log10f(float x);
|
||||
float npy_logf(float x);
|
||||
float npy_expf(float x);
|
||||
|
@ -251,15 +225,13 @@ float npy_powf(float x, float y);
|
|||
float npy_fmodf(float x, float y);
|
||||
|
||||
float npy_modff(float x, float* y);
|
||||
float npy_frexpf(float x, int* y);
|
||||
float npy_ldexpf(float x, int y);
|
||||
|
||||
float npy_copysignf(float x, float y);
|
||||
float npy_nextafterf(float x, float y);
|
||||
float npy_spacingf(float x);
|
||||
|
||||
/*
|
||||
* long double C99 math functions
|
||||
* float C99 math functions
|
||||
*/
|
||||
|
||||
npy_longdouble npy_sinl(npy_longdouble x);
|
||||
|
@ -274,7 +246,6 @@ npy_longdouble npy_ceill(npy_longdouble x);
|
|||
npy_longdouble npy_rintl(npy_longdouble x);
|
||||
npy_longdouble npy_truncl(npy_longdouble x);
|
||||
npy_longdouble npy_sqrtl(npy_longdouble x);
|
||||
npy_longdouble npy_cbrtl(npy_longdouble x);
|
||||
npy_longdouble npy_log10l(npy_longdouble x);
|
||||
npy_longdouble npy_logl(npy_longdouble x);
|
||||
npy_longdouble npy_expl(npy_longdouble x);
|
||||
|
@ -295,8 +266,6 @@ npy_longdouble npy_powl(npy_longdouble x, npy_longdouble y);
|
|||
npy_longdouble npy_fmodl(npy_longdouble x, npy_longdouble y);
|
||||
|
||||
npy_longdouble npy_modfl(npy_longdouble x, npy_longdouble* y);
|
||||
npy_longdouble npy_frexpl(npy_longdouble x, int* y);
|
||||
npy_longdouble npy_ldexpl(npy_longdouble x, int y);
|
||||
|
||||
npy_longdouble npy_copysignl(npy_longdouble x, npy_longdouble y);
|
||||
npy_longdouble npy_nextafterl(npy_longdouble x, npy_longdouble y);
|
||||
|
@ -425,19 +394,6 @@ npy_cdouble npy_csqrt(npy_cdouble z);
|
|||
|
||||
npy_cdouble npy_ccos(npy_cdouble z);
|
||||
npy_cdouble npy_csin(npy_cdouble z);
|
||||
npy_cdouble npy_ctan(npy_cdouble z);
|
||||
|
||||
npy_cdouble npy_ccosh(npy_cdouble z);
|
||||
npy_cdouble npy_csinh(npy_cdouble z);
|
||||
npy_cdouble npy_ctanh(npy_cdouble z);
|
||||
|
||||
npy_cdouble npy_cacos(npy_cdouble z);
|
||||
npy_cdouble npy_casin(npy_cdouble z);
|
||||
npy_cdouble npy_catan(npy_cdouble z);
|
||||
|
||||
npy_cdouble npy_cacosh(npy_cdouble z);
|
||||
npy_cdouble npy_casinh(npy_cdouble z);
|
||||
npy_cdouble npy_catanh(npy_cdouble z);
|
||||
|
||||
/*
|
||||
* Single precision complex functions
|
||||
|
@ -453,20 +409,6 @@ npy_cfloat npy_csqrtf(npy_cfloat z);
|
|||
|
||||
npy_cfloat npy_ccosf(npy_cfloat z);
|
||||
npy_cfloat npy_csinf(npy_cfloat z);
|
||||
npy_cfloat npy_ctanf(npy_cfloat z);
|
||||
|
||||
npy_cfloat npy_ccoshf(npy_cfloat z);
|
||||
npy_cfloat npy_csinhf(npy_cfloat z);
|
||||
npy_cfloat npy_ctanhf(npy_cfloat z);
|
||||
|
||||
npy_cfloat npy_cacosf(npy_cfloat z);
|
||||
npy_cfloat npy_casinf(npy_cfloat z);
|
||||
npy_cfloat npy_catanf(npy_cfloat z);
|
||||
|
||||
npy_cfloat npy_cacoshf(npy_cfloat z);
|
||||
npy_cfloat npy_casinhf(npy_cfloat z);
|
||||
npy_cfloat npy_catanhf(npy_cfloat z);
|
||||
|
||||
|
||||
/*
|
||||
* Extended precision complex functions
|
||||
|
@ -482,44 +424,15 @@ npy_clongdouble npy_csqrtl(npy_clongdouble z);
|
|||
|
||||
npy_clongdouble npy_ccosl(npy_clongdouble z);
|
||||
npy_clongdouble npy_csinl(npy_clongdouble z);
|
||||
npy_clongdouble npy_ctanl(npy_clongdouble z);
|
||||
|
||||
npy_clongdouble npy_ccoshl(npy_clongdouble z);
|
||||
npy_clongdouble npy_csinhl(npy_clongdouble z);
|
||||
npy_clongdouble npy_ctanhl(npy_clongdouble z);
|
||||
|
||||
npy_clongdouble npy_cacosl(npy_clongdouble z);
|
||||
npy_clongdouble npy_casinl(npy_clongdouble z);
|
||||
npy_clongdouble npy_catanl(npy_clongdouble z);
|
||||
|
||||
npy_clongdouble npy_cacoshl(npy_clongdouble z);
|
||||
npy_clongdouble npy_casinhl(npy_clongdouble z);
|
||||
npy_clongdouble npy_catanhl(npy_clongdouble z);
|
||||
|
||||
|
||||
/*
|
||||
* Functions that set the floating point error
|
||||
* status word.
|
||||
*/
|
||||
|
||||
/*
|
||||
* platform-dependent code translates floating point
|
||||
* status to an integer sum of these values
|
||||
*/
|
||||
#define NPY_FPE_DIVIDEBYZERO 1
|
||||
#define NPY_FPE_OVERFLOW 2
|
||||
#define NPY_FPE_UNDERFLOW 4
|
||||
#define NPY_FPE_INVALID 8
|
||||
|
||||
int npy_get_floatstatus(void);
|
||||
int npy_clear_floatstatus(void);
|
||||
void npy_set_floatstatus_divbyzero(void);
|
||||
void npy_set_floatstatus_overflow(void);
|
||||
void npy_set_floatstatus_underflow(void);
|
||||
void npy_set_floatstatus_invalid(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,8 +29,5 @@
|
|||
* #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
|
||||
*/
|
||||
#define NPY_1_7_API_VERSION 0x00000007
|
||||
#define NPY_1_8_API_VERSION 0x00000008
|
||||
#define NPY_1_9_API_VERSION 0x00000008
|
||||
#define NPY_1_10_API_VERSION 0x00000008
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,8 +7,8 @@ Numpy Ufunc C-API
|
|||
PyObject *
|
||||
PyUFunc_FromFuncAndData(PyUFuncGenericFunction *func, void
|
||||
**data, char *types, int ntypes, int nin, int
|
||||
nout, int identity, const char *name, const
|
||||
char *doc, int check_return)
|
||||
nout, int identity, char *name, char *doc, int
|
||||
check_return)
|
||||
|
||||
|
||||
::
|
||||
|
@ -229,9 +229,9 @@ owns a new reference to errobj.
|
|||
PyUFunc_FromFuncAndDataAndSignature(PyUFuncGenericFunction *func, void
|
||||
**data, char *types, int
|
||||
ntypes, int nin, int nout, int
|
||||
identity, const char *name, const
|
||||
char *doc, int check_return, const
|
||||
char *signature)
|
||||
identity, char *name, char
|
||||
*doc, int check_return, const char
|
||||
*signature)
|
||||
|
||||
|
||||
::
|
||||
|
@ -310,12 +310,3 @@ the output operands where provided.
|
|||
|
||||
Returns 0 on success, -1 (with exception raised) on validation failure.
|
||||
|
||||
::
|
||||
|
||||
int
|
||||
PyUFunc_RegisterLoopForDescr(PyUFuncObject *ufunc, PyArray_Descr
|
||||
*user_dtype, PyUFuncGenericFunction
|
||||
function, PyArray_Descr
|
||||
**arg_dtypes, void *data)
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define Py_UFUNCOBJECT_H
|
||||
|
||||
#include <numpy/npy_math.h>
|
||||
#include <numpy/npy_common.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -152,13 +151,13 @@ typedef struct _tagPyUFuncObject {
|
|||
int check_return;
|
||||
|
||||
/* The name of the ufunc */
|
||||
const char *name;
|
||||
char *name;
|
||||
|
||||
/* Array of type numbers, of size ('nargs' * 'ntypes') */
|
||||
char *types;
|
||||
|
||||
/* Documentation string */
|
||||
const char *doc;
|
||||
char *doc;
|
||||
|
||||
void *ptr;
|
||||
PyObject *obj;
|
||||
|
@ -213,20 +212,6 @@ typedef struct _tagPyUFuncObject {
|
|||
* A function which returns a masked inner loop for the ufunc.
|
||||
*/
|
||||
PyUFunc_MaskedInnerLoopSelectionFunc *masked_inner_loop_selector;
|
||||
|
||||
/*
|
||||
* List of flags for each operand when ufunc is called by nditer object.
|
||||
* These flags will be used in addition to the default flags for each
|
||||
* operand set by nditer object.
|
||||
*/
|
||||
npy_uint32 *op_flags;
|
||||
|
||||
/*
|
||||
* List of global flags used when ufunc is called by nditer object.
|
||||
* These flags will be used in addition to the default global flags
|
||||
* set by nditer object.
|
||||
*/
|
||||
npy_uint32 iter_flags;
|
||||
} PyUFuncObject;
|
||||
|
||||
#include "arrayobject.h"
|
||||
|
@ -251,11 +236,22 @@ typedef struct _tagPyUFuncObject {
|
|||
#define UFUNC_SHIFT_INVALID 9
|
||||
|
||||
|
||||
/* platform-dependent code translates floating point
|
||||
status to an integer sum of these values
|
||||
*/
|
||||
#define UFUNC_FPE_DIVIDEBYZERO 1
|
||||
#define UFUNC_FPE_OVERFLOW 2
|
||||
#define UFUNC_FPE_UNDERFLOW 4
|
||||
#define UFUNC_FPE_INVALID 8
|
||||
|
||||
/* Error mode that avoids look-up (no checking) */
|
||||
#define UFUNC_ERR_DEFAULT 0
|
||||
|
||||
#define UFUNC_OBJ_ISOBJECT 1
|
||||
#define UFUNC_OBJ_NEEDS_API 2
|
||||
|
||||
/* Default user error mode */
|
||||
#define UFUNC_ERR_DEFAULT \
|
||||
#define UFUNC_ERR_DEFAULT2 \
|
||||
(UFUNC_ERR_WARN << UFUNC_SHIFT_DIVIDEBYZERO) + \
|
||||
(UFUNC_ERR_WARN << UFUNC_SHIFT_OVERFLOW) + \
|
||||
(UFUNC_ERR_WARN << UFUNC_SHIFT_INVALID)
|
||||
|
@ -309,8 +305,6 @@ typedef struct _loop1d_info {
|
|||
void *data;
|
||||
int *arg_types;
|
||||
struct _loop1d_info *next;
|
||||
int nargs;
|
||||
PyArray_Descr **arg_dtypes;
|
||||
} PyUFunc_Loop1d;
|
||||
|
||||
|
||||
|
@ -326,47 +320,126 @@ typedef struct _loop1d_info {
|
|||
&(arg)->first))) \
|
||||
goto fail;} while (0)
|
||||
|
||||
/* This code checks the IEEE status flags in a platform-dependent way */
|
||||
/* Adapted from Numarray */
|
||||
|
||||
/* keep in sync with ieee754.c.src */
|
||||
#if defined(sun) || defined(__BSD__) || defined(__OpenBSD__) || \
|
||||
(defined(__FreeBSD__) && (__FreeBSD_version < 502114)) || \
|
||||
defined(__NetBSD__) || \
|
||||
defined(__GLIBC__) || defined(__APPLE__) || \
|
||||
defined(__CYGWIN__) || defined(__MINGW32__) || \
|
||||
(defined(__FreeBSD__) && (__FreeBSD_version >= 502114)) || \
|
||||
defined(_AIX) || \
|
||||
defined(_MSC_VER) || \
|
||||
defined(__osf__) && defined(__alpha)
|
||||
#else
|
||||
#define NO_FLOATING_POINT_SUPPORT
|
||||
#if (defined(__unix__) || defined(unix)) && !defined(USG)
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
/* OSF/Alpha (Tru64) ---------------------------------------------*/
|
||||
#if defined(__osf__) && defined(__alpha)
|
||||
|
||||
#include <machine/fpu.h>
|
||||
|
||||
#define UFUNC_CHECK_STATUS(ret) { \
|
||||
unsigned long fpstatus; \
|
||||
\
|
||||
fpstatus = ieee_get_fp_control(); \
|
||||
/* clear status bits as well as disable exception mode if on */ \
|
||||
ieee_set_fp_control( 0 ); \
|
||||
ret = ((IEEE_STATUS_DZE & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \
|
||||
| ((IEEE_STATUS_OVF & fpstatus) ? UFUNC_FPE_OVERFLOW : 0) \
|
||||
| ((IEEE_STATUS_UNF & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \
|
||||
| ((IEEE_STATUS_INV & fpstatus) ? UFUNC_FPE_INVALID : 0); \
|
||||
}
|
||||
|
||||
/* MS Windows -----------------------------------------------------*/
|
||||
#elif defined(_MSC_VER)
|
||||
|
||||
#include <float.h>
|
||||
|
||||
/* Clear the floating point exception default of Borland C++ */
|
||||
#if defined(__BORLANDC__)
|
||||
#define UFUNC_NOFPE _control87(MCW_EM, MCW_EM);
|
||||
#endif
|
||||
|
||||
#define UFUNC_CHECK_STATUS(ret) { \
|
||||
int fpstatus = (int) _clearfp(); \
|
||||
\
|
||||
ret = ((SW_ZERODIVIDE & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \
|
||||
| ((SW_OVERFLOW & fpstatus) ? UFUNC_FPE_OVERFLOW : 0) \
|
||||
| ((SW_UNDERFLOW & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \
|
||||
| ((SW_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0); \
|
||||
}
|
||||
|
||||
/* Solaris --------------------------------------------------------*/
|
||||
/* --------ignoring SunOS ieee_flags approach, someone else can
|
||||
** deal with that! */
|
||||
#elif defined(sun) || defined(__BSD__) || defined(__OpenBSD__) || \
|
||||
(defined(__FreeBSD__) && (__FreeBSD_version < 502114)) || \
|
||||
defined(__NetBSD__)
|
||||
#include <ieeefp.h>
|
||||
|
||||
#define UFUNC_CHECK_STATUS(ret) { \
|
||||
int fpstatus; \
|
||||
\
|
||||
fpstatus = (int) fpgetsticky(); \
|
||||
ret = ((FP_X_DZ & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \
|
||||
| ((FP_X_OFL & fpstatus) ? UFUNC_FPE_OVERFLOW : 0) \
|
||||
| ((FP_X_UFL & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \
|
||||
| ((FP_X_INV & fpstatus) ? UFUNC_FPE_INVALID : 0); \
|
||||
(void) fpsetsticky(0); \
|
||||
}
|
||||
|
||||
#elif defined(__GLIBC__) || defined(__APPLE__) || \
|
||||
defined(__CYGWIN__) || defined(__MINGW32__) || \
|
||||
(defined(__FreeBSD__) && (__FreeBSD_version >= 502114))
|
||||
|
||||
#if defined(__GLIBC__) || defined(__APPLE__) || \
|
||||
defined(__MINGW32__) || defined(__FreeBSD__)
|
||||
#include <fenv.h>
|
||||
#elif defined(__CYGWIN__)
|
||||
#include "fenv/fenv.c"
|
||||
#endif
|
||||
|
||||
#define UFUNC_CHECK_STATUS(ret) { \
|
||||
int fpstatus = (int) fetestexcept(FE_DIVBYZERO | FE_OVERFLOW | \
|
||||
FE_UNDERFLOW | FE_INVALID); \
|
||||
ret = ((FE_DIVBYZERO & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \
|
||||
| ((FE_OVERFLOW & fpstatus) ? UFUNC_FPE_OVERFLOW : 0) \
|
||||
| ((FE_UNDERFLOW & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \
|
||||
| ((FE_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0); \
|
||||
(void) feclearexcept(FE_DIVBYZERO | FE_OVERFLOW | \
|
||||
FE_UNDERFLOW | FE_INVALID); \
|
||||
}
|
||||
|
||||
#elif defined(_AIX)
|
||||
|
||||
#include <float.h>
|
||||
#include <fpxcp.h>
|
||||
|
||||
#define UFUNC_CHECK_STATUS(ret) { \
|
||||
fpflag_t fpstatus; \
|
||||
\
|
||||
fpstatus = fp_read_flag(); \
|
||||
ret = ((FP_DIV_BY_ZERO & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \
|
||||
| ((FP_OVERFLOW & fpstatus) ? UFUNC_FPE_OVERFLOW : 0) \
|
||||
| ((FP_UNDERFLOW & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \
|
||||
| ((FP_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0); \
|
||||
fp_swap_flag(0); \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define NO_FLOATING_POINT_SUPPORT
|
||||
#define UFUNC_CHECK_STATUS(ret) { \
|
||||
ret = 0; \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* THESE MACROS ARE DEPRECATED.
|
||||
* Use npy_set_floatstatus_* in the npymath library.
|
||||
*/
|
||||
#define UFUNC_FPE_DIVIDEBYZERO NPY_FPE_DIVIDEBYZERO
|
||||
#define UFUNC_FPE_OVERFLOW NPY_FPE_OVERFLOW
|
||||
#define UFUNC_FPE_UNDERFLOW NPY_FPE_UNDERFLOW
|
||||
#define UFUNC_FPE_INVALID NPY_FPE_INVALID
|
||||
|
||||
#define UFUNC_CHECK_STATUS(ret) \
|
||||
{ \
|
||||
ret = npy_clear_floatstatus(); \
|
||||
}
|
||||
#define generate_divbyzero_error() npy_set_floatstatus_divbyzero()
|
||||
#define generate_overflow_error() npy_set_floatstatus_overflow()
|
||||
|
||||
/* Make sure it gets defined if it isn't already */
|
||||
#ifndef UFUNC_NOFPE
|
||||
/* Clear the floating point exception default of Borland C++ */
|
||||
#if defined(__BORLANDC__)
|
||||
#define UFUNC_NOFPE _control87(MCW_EM, MCW_EM);
|
||||
#else
|
||||
#define UFUNC_NOFPE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
cython<0.24
|
||||
pathlib
|
||||
numpy
|
||||
numpy>=1.7
|
||||
cymem>=1.30,<1.32
|
||||
preshed>=0.46.1,<0.47.0
|
||||
thinc>=5.0.0,<5.1.0
|
||||
|
|
14
setup.py
14
setup.py
|
@ -6,6 +6,7 @@ import sys
|
|||
import contextlib
|
||||
from distutils.command.build_ext import build_ext
|
||||
from distutils.sysconfig import get_python_inc
|
||||
from distutils import ccompiler, msvccompiler
|
||||
|
||||
try:
|
||||
from setuptools import Extension, setup
|
||||
|
@ -68,9 +69,6 @@ MOD_NAMES = [
|
|||
'spacy.syntax.iterators']
|
||||
|
||||
|
||||
# By subclassing build_extensions we have the actual compiler that will be used
|
||||
# which is really known only after finalize_options
|
||||
# http://stackoverflow.com/questions/724664/python-distutils-how-to-get-a-compiler-that-is-going-to-be-used
|
||||
compile_options = {
|
||||
'msvc': ['/Ox', '/EHsc'],
|
||||
'mingw32' : ['-O3', '-Wno-strict-prototypes', '-Wno-unused-function'],
|
||||
|
@ -94,6 +92,8 @@ if not sys.platform.startswith('darwin'):
|
|||
link_options['other'].append('-fopenmp')
|
||||
|
||||
|
||||
# By subclassing build_extensions we have the actual compiler that will be used which is really known only after finalize_options
|
||||
# http://stackoverflow.com/questions/724664/python-distutils-how-to-get-a-compiler-that-is-going-to-be-used
|
||||
class build_ext_options:
|
||||
def build_options(self):
|
||||
for e in self.extensions:
|
||||
|
@ -162,6 +162,10 @@ def setup_package():
|
|||
get_python_inc(plat_specific=True),
|
||||
os.path.join(root, 'include')]
|
||||
|
||||
if (ccompiler.new_compiler().compiler_type == 'msvc'
|
||||
and msvccompiler.get_build_version() == 9):
|
||||
include_dirs.append(os.path.join(root, 'include', 'msvc9'))
|
||||
|
||||
ext_modules = []
|
||||
for mod_name in MOD_NAMES:
|
||||
mod_path = mod_name.replace('.', '/') + '.cpp'
|
||||
|
@ -186,9 +190,9 @@ def setup_package():
|
|||
license=about['__license__'],
|
||||
ext_modules=ext_modules,
|
||||
install_requires=[
|
||||
'numpy',
|
||||
'numpy>=1.7',
|
||||
'murmurhash>=0.26,<0.27',
|
||||
'cymem>=1.30,<1.32.0',
|
||||
'cymem>=1.30,<1.32',
|
||||
'preshed>=0.46.1,<0.47',
|
||||
'thinc>=5.0.0,<5.1.0',
|
||||
'plac',
|
||||
|
|
|
@ -22,7 +22,6 @@ from ._state cimport StateC, is_space_token
|
|||
|
||||
DEF NON_MONOTONIC = True
|
||||
DEF USE_BREAK = True
|
||||
DEF USE_ROOT_ARC_SEGMENT = True
|
||||
|
||||
cdef weight_t MIN_SCORE = -90000
|
||||
|
||||
|
@ -91,8 +90,6 @@ cdef weight_t arc_cost(StateClass stcls, const GoldParseC* gold, int head, int c
|
|||
cdef bint arc_is_gold(const GoldParseC* gold, int head, int child) nogil:
|
||||
if gold.labels[child] == -1:
|
||||
return True
|
||||
elif USE_ROOT_ARC_SEGMENT and _is_gold_root(gold, head) and _is_gold_root(gold, child):
|
||||
return True
|
||||
elif gold.heads[child] == head:
|
||||
return True
|
||||
else:
|
||||
|
@ -235,25 +232,12 @@ cdef class Break:
|
|||
return False
|
||||
elif st.stack_depth() < 1:
|
||||
return False
|
||||
# It is okay to predict a sentence boundary if the top item on the stack
|
||||
# and the first item on the buffer are adjacent tokens. If this is not the
|
||||
# case, it is still okay if there are only space tokens in between.
|
||||
# This is checked by testing whether the head of a space token immediately
|
||||
# preceding the first item in the buffer is the top item on the stack.
|
||||
# Intervening space tokens must be attached to the previous non-space token.
|
||||
# Therefore, if the head of a space token that immediately precedes the first
|
||||
# item on the buffer is the top item on the stack, a sentence boundary can be
|
||||
# predicted.
|
||||
elif (st.S(0) + 1) != st.B(0) \
|
||||
and not (is_space_token(st.safe_get(st.B(0)-1)) and st.H(st.B(0)-1) == st.S(0)):
|
||||
# Must break at the token boundary
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
cdef int transition(StateC* st, int label) nogil:
|
||||
st.set_break(st.B(0))
|
||||
st.set_break(st.B_(0).l_edge)
|
||||
st.fast_forward()
|
||||
|
||||
@staticmethod
|
||||
|
@ -295,8 +279,8 @@ cdef int _get_root(int word, const GoldParseC* gold) nogil:
|
|||
cdef class ArcEager(TransitionSystem):
|
||||
@classmethod
|
||||
def get_labels(cls, gold_parses):
|
||||
move_labels = {SHIFT: {'': True}, REDUCE: {'': True}, RIGHT: {'ROOT': True},
|
||||
LEFT: {'ROOT': True}, BREAK: {'ROOT': True}}
|
||||
move_labels = {SHIFT: {'': True}, REDUCE: {'': True}, RIGHT: {},
|
||||
LEFT: {}, BREAK: {'ROOT': True}}
|
||||
for raw_text, sents in gold_parses:
|
||||
for (ids, words, tags, heads, labels, iob), ctnts in sents:
|
||||
for child, head, label in zip(ids, heads, labels):
|
||||
|
@ -398,10 +382,6 @@ cdef class ArcEager(TransitionSystem):
|
|||
for i in range(st.length):
|
||||
if st._sent[i].head == 0 and st._sent[i].dep == 0:
|
||||
st._sent[i].dep = self.root_label
|
||||
# If we're not using the Break transition, we segment via root-labelled
|
||||
# arcs between the root words.
|
||||
elif USE_ROOT_ARC_SEGMENT and st._sent[i].dep == self.root_label:
|
||||
st._sent[i].head = 0
|
||||
|
||||
cdef int set_valid(self, int* output, const StateC* st) nogil:
|
||||
cdef bint[N_MOVES] is_valid
|
||||
|
|
|
@ -6,7 +6,7 @@ import spacy
|
|||
from spacy.matcher import Matcher
|
||||
from spacy.attrs import ORTH, LOWER, ENT_IOB, ENT_TYPE
|
||||
from spacy.attrs import ORTH, TAG, LOWER, IS_ALPHA, FLAG63
|
||||
from spacy.symbols import DATE
|
||||
from spacy.symbols import DATE, LOC
|
||||
|
||||
|
||||
def test_overlap_issue118(EN):
|
||||
|
@ -134,15 +134,59 @@ def test_overlap_prefix_reorder(EN):
|
|||
assert ents[0].end == 11
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_ner_interaction(EN):
|
||||
EN.matcher.add('LAX_Airport', 'AIRPORT', {}, [[{ORTH: 'LAX'}]])
|
||||
EN.matcher.add('SFO_Airport', 'AIRPORT', {}, [[{ORTH: 'SFO'}]])
|
||||
doc = EN(u'get me a flight from SFO to LAX leaving 20 December and arriving on January 5th')
|
||||
# @pytest.mark.models
|
||||
# def test_ner_interaction(EN):
|
||||
# EN.matcher.add('LAX_Airport', 'AIRPORT', {}, [[{ORTH: 'LAX'}]])
|
||||
# EN.matcher.add('SFO_Airport', 'AIRPORT', {}, [[{ORTH: 'SFO'}]])
|
||||
# doc = EN(u'get me a flight from SFO to LAX leaving 20 December and arriving on January 5th')
|
||||
|
||||
# ents = [(ent.label_, ent.text) for ent in doc.ents]
|
||||
# assert ents[0] == ('AIRPORT', 'SFO')
|
||||
# assert ents[1] == ('AIRPORT', 'LAX')
|
||||
# assert ents[2] == ('DATE', '20 December')
|
||||
# assert ents[3] == ('DATE', 'January 5th')
|
||||
|
||||
|
||||
# @pytest.mark.models
|
||||
# def test_ner_interaction(EN):
|
||||
# # ensure that matcher doesn't overwrite annotations set by the NER model
|
||||
# doc = EN.tokenizer.tokens_from_list(u'get me a flight from SFO to LAX leaving 20 December and arriving on January 5th'.split(' '))
|
||||
# EN.tagger(doc)
|
||||
|
||||
# columns = [ENT_IOB, ENT_TYPE]
|
||||
# values = numpy.ndarray(shape=(len(doc),len(columns)), dtype='int32')
|
||||
# # IOB values are 0=missing, 1=I, 2=O, 3=B
|
||||
# iobs = [2,2,2,2,2,3,2,3,2,3,1,2,2,2,3,1]
|
||||
# types = [0,0,0,0,0,LOC,0,LOC,0,DATE,DATE,0,0,0,DATE,DATE]
|
||||
# values[:] = zip(iobs,types)
|
||||
# doc.from_array(columns,values)
|
||||
|
||||
# assert doc[5].ent_type_ == 'LOC'
|
||||
# assert doc[7].ent_type_ == 'LOC'
|
||||
# assert doc[9].ent_type_ == 'DATE'
|
||||
# assert doc[10].ent_type_ == 'DATE'
|
||||
# assert doc[14].ent_type_ == 'DATE'
|
||||
# assert doc[15].ent_type_ == 'DATE'
|
||||
|
||||
# EN.matcher.add('LAX_Airport', 'AIRPORT', {}, [[{ORTH: 'LAX'}]])
|
||||
# EN.matcher.add('SFO_Airport', 'AIRPORT', {}, [[{ORTH: 'SFO'}]])
|
||||
# EN.matcher(doc)
|
||||
|
||||
# assert doc[5].ent_type_ != 'AIRPORT'
|
||||
# assert doc[7].ent_type_ != 'AIRPORT'
|
||||
# assert doc[5].ent_type_ == 'LOC'
|
||||
# assert doc[7].ent_type_ == 'LOC'
|
||||
# assert doc[9].ent_type_ == 'DATE'
|
||||
# assert doc[10].ent_type_ == 'DATE'
|
||||
# assert doc[14].ent_type_ == 'DATE'
|
||||
# assert doc[15].ent_type_ == 'DATE'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ents = [(ent.label_, ent.text) for ent in doc.ents]
|
||||
assert ents[0] == ('AIRPORT', 'SFO')
|
||||
assert ents[1] == ('AIRPORT', 'LAX')
|
||||
assert ents[2] == ('DATE', '20 December')
|
||||
assert ents[3] == ('DATE', 'January 5th')
|
||||
|
||||
|
|
|
@ -19,3 +19,80 @@ def test_one_word_sentence(EN):
|
|||
with EN.parser.step_through(doc) as _:
|
||||
pass
|
||||
assert doc[0].dep != 0
|
||||
|
||||
|
||||
def apply_transition_sequence(model, doc, sequence):
|
||||
with model.parser.step_through(doc) as stepwise:
|
||||
for transition in sequence:
|
||||
stepwise.transition(transition)
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_arc_eager_finalize_state(EN):
|
||||
# right branching
|
||||
example = EN.tokenizer.tokens_from_list(u"a b c d e".split(' '))
|
||||
apply_transition_sequence(EN, example, ['R-nsubj','D','R-nsubj','R-nsubj','D','R-ROOT'])
|
||||
|
||||
assert example[0].n_lefts == 0
|
||||
assert example[0].n_rights == 2
|
||||
assert example[0].left_edge.i == 0
|
||||
assert example[0].right_edge.i == 3
|
||||
assert example[0].head.i == 0
|
||||
|
||||
assert example[1].n_lefts == 0
|
||||
assert example[1].n_rights == 0
|
||||
assert example[1].left_edge.i == 1
|
||||
assert example[1].right_edge.i == 1
|
||||
assert example[1].head.i == 0
|
||||
|
||||
assert example[2].n_lefts == 0
|
||||
assert example[2].n_rights == 1
|
||||
assert example[2].left_edge.i == 2
|
||||
assert example[2].right_edge.i == 3
|
||||
assert example[2].head.i == 0
|
||||
|
||||
assert example[3].n_lefts == 0
|
||||
assert example[3].n_rights == 0
|
||||
assert example[3].left_edge.i == 3
|
||||
assert example[3].right_edge.i == 3
|
||||
assert example[3].head.i == 2
|
||||
|
||||
assert example[4].n_lefts == 0
|
||||
assert example[4].n_rights == 0
|
||||
assert example[4].left_edge.i == 4
|
||||
assert example[4].right_edge.i == 4
|
||||
assert example[4].head.i == 4
|
||||
|
||||
# left branching
|
||||
example = EN.tokenizer.tokens_from_list(u"a b c d e".split(' '))
|
||||
apply_transition_sequence(EN, example, ['S','L-nsubj','L-ROOT','S','L-nsubj','L-nsubj'])
|
||||
|
||||
assert example[0].n_lefts == 0
|
||||
assert example[0].n_rights == 0
|
||||
assert example[0].left_edge.i == 0
|
||||
assert example[0].right_edge.i == 0
|
||||
assert example[0].head.i == 0
|
||||
|
||||
assert example[1].n_lefts == 0
|
||||
assert example[1].n_rights == 0
|
||||
assert example[1].left_edge.i == 1
|
||||
assert example[1].right_edge.i == 1
|
||||
assert example[1].head.i == 2
|
||||
|
||||
assert example[2].n_lefts == 1
|
||||
assert example[2].n_rights == 0
|
||||
assert example[2].left_edge.i == 1
|
||||
assert example[2].right_edge.i == 2
|
||||
assert example[2].head.i == 4
|
||||
|
||||
assert example[3].n_lefts == 0
|
||||
assert example[3].n_rights == 0
|
||||
assert example[3].left_edge.i == 3
|
||||
assert example[3].right_edge.i == 3
|
||||
assert example[3].head.i == 4
|
||||
|
||||
assert example[4].n_lefts == 2
|
||||
assert example[4].n_rights == 0
|
||||
assert example[4].left_edge.i == 1
|
||||
assert example[4].right_edge.i == 4
|
||||
assert example[4].head.i == 4
|
||||
|
|
|
@ -57,8 +57,7 @@ def test_child_consistency(EN, sun_text):
|
|||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_edges(EN):
|
||||
sun_text = u"Chemically, about three quarters of the Sun's mass consists of hydrogen, while the rest is mostly helium."
|
||||
def test_edges(EN, sun_text):
|
||||
tokens = EN(sun_text)
|
||||
for token in tokens:
|
||||
subtree = list(token.subtree)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
from spacy.tokens import Doc
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
|
@ -42,7 +42,7 @@ def test_single_question(EN):
|
|||
|
||||
@pytest.mark.models
|
||||
def test_sentence_breaks_no_space(EN):
|
||||
doc = EN.tokenizer.tokens_from_list('This is a sentence . This is another one .'.split(' '))
|
||||
doc = EN.tokenizer.tokens_from_list(u'This is a sentence . This is another one .'.split(' '))
|
||||
EN.tagger(doc)
|
||||
with EN.parser.step_through(doc) as stepwise:
|
||||
# stack empty, automatic Shift (This)
|
||||
|
@ -83,7 +83,7 @@ def test_sentence_breaks_no_space(EN):
|
|||
|
||||
@pytest.mark.models
|
||||
def test_sentence_breaks_with_space(EN):
|
||||
doc = EN.tokenizer.tokens_from_list('\t This is \n a sentence \n \n . \n \t \n This is another \t one .'.split(' '))
|
||||
doc = EN.tokenizer.tokens_from_list(u'\t This is \n a sentence \n \n . \n \t \n This is another \t one .'.split(' '))
|
||||
EN.tagger(doc)
|
||||
with EN.parser.step_through(doc) as stepwise:
|
||||
# stack empty, automatic Shift (This)
|
||||
|
@ -120,3 +120,56 @@ def test_sentence_breaks_with_space(EN):
|
|||
for tok in doc:
|
||||
assert tok.dep != 0 or tok.is_space
|
||||
assert [ tok.head.i for tok in doc ] == [1,2,2,2,5,2,5,5,2,8,8,8,13,13,16,14,13,13]
|
||||
|
||||
|
||||
|
||||
def apply_transition_sequence(model, doc, sequence):
|
||||
with model.parser.step_through(doc) as stepwise:
|
||||
for transition in sequence:
|
||||
stepwise.transition(transition)
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_sbd_for_root_label_dependents(EN):
|
||||
"""
|
||||
make sure that the parser properly introduces a sentence boundary without
|
||||
the break transition by checking for dependents with the root label
|
||||
"""
|
||||
example = EN.tokenizer.tokens_from_list(u"I saw a firefly It glowed".split(' '))
|
||||
EN.tagger(example)
|
||||
apply_transition_sequence(EN, example, ['L-nsubj','S','L-det','R-dobj','D','S','L-nsubj','R-ROOT'])
|
||||
|
||||
assert example[1].head.i == 1
|
||||
assert example[5].head.i == 5
|
||||
|
||||
sents = list(example.sents)
|
||||
assert len(sents) == 2
|
||||
assert sents[1][0].orth_ == u'It'
|
||||
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_sbd_serialization(EN):
|
||||
"""
|
||||
test that before and after serialization, the sentence boundaries are the same even
|
||||
if the parser predicted two roots for the sentence that were made into two sentences
|
||||
after parsing by arc_eager.finalize()
|
||||
|
||||
This is actually an interaction between the sentence boundary prediction and doc.from_array
|
||||
The process is the following: if the parser doesn't predict a sentence boundary but attaches
|
||||
a word with the ROOT label, the second root node is made root of its own sentence after parsing.
|
||||
During serialization, sentence boundary information is lost and reintroduced when the code
|
||||
is deserialized by introducing sentence starts at every left-edge of every root node.
|
||||
|
||||
BUG that is tested here: So far, the parser wasn't introducing a sentence start when
|
||||
it introduced the second root node.
|
||||
"""
|
||||
|
||||
example = EN.tokenizer.tokens_from_list(u"I bought a couch from IKEA. It was n't very comfortable .".split(' '))
|
||||
EN.tagger(example)
|
||||
apply_transition_sequence(EN, example, ['L-nsubj','S','L-det','R-dobj','D','R-prep','R-pobj','D','D','S','L-nsubj','R-ROOT','R-neg','D','S','L-advmod','R-acomp','D','R-punct'])
|
||||
|
||||
example_serialized = Doc(EN.vocab).from_bytes(example.to_bytes())
|
||||
|
||||
assert example.to_bytes() == example_serialized.to_bytes()
|
||||
assert [s.text for s in example.sents] == [s.text for s in example_serialized.sents]
|
||||
|
|
88
spacy/tests/serialize/test_serialization.py
Normal file
88
spacy/tests/serialize/test_serialization.py
Normal file
|
@ -0,0 +1,88 @@
|
|||
from __future__ import unicode_literals
|
||||
import pytest
|
||||
|
||||
from spacy.tokens import Doc
|
||||
|
||||
def equal(doc1, doc2):
|
||||
# tokens
|
||||
assert [ t.orth for t in doc1 ] == [ t.orth for t in doc2 ]
|
||||
|
||||
# tags
|
||||
assert [ t.pos for t in doc1 ] == [ t.pos for t in doc2 ]
|
||||
assert [ t.tag for t in doc1 ] == [ t.tag for t in doc2 ]
|
||||
|
||||
# parse
|
||||
assert [ t.head.i for t in doc1 ] == [ t.head.i for t in doc2 ]
|
||||
assert [ t.dep for t in doc1 ] == [ t.dep for t in doc2 ]
|
||||
|
||||
if doc1.is_parsed and doc2.is_parsed:
|
||||
assert [ s for s in doc1.sents ] == [ s for s in doc2.sents ]
|
||||
|
||||
# entities
|
||||
assert [ t.ent_type for t in doc1 ] == [ t.ent_type for t in doc2 ]
|
||||
assert [ t.ent_iob for t in doc1 ] == [ t.ent_iob for t in doc2 ]
|
||||
assert [ ent for ent in doc1.ents ] == [ ent for ent in doc2.ents ]
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_serialize_tokens(EN):
|
||||
doc1 = EN(u'This is a test sentence.',tag=False,parse=False,entity=False)
|
||||
|
||||
doc2 = Doc(EN.vocab).from_bytes(doc1.to_bytes())
|
||||
equal(doc1,doc2)
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_serialize_tokens_tags(EN):
|
||||
doc1 = EN(u'This is a test sentence.',tag=True,parse=False,entity=False)
|
||||
|
||||
doc2 = Doc(EN.vocab).from_bytes(doc1.to_bytes())
|
||||
equal(doc1,doc2)
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_serialize_tokens_parse(EN):
|
||||
doc1 = EN(u'This is a test sentence.',tag=False,parse=True,entity=False)
|
||||
|
||||
doc2 = Doc(EN.vocab).from_bytes(doc1.to_bytes())
|
||||
equal(doc1,doc2)
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_serialize_tokens_ner(EN):
|
||||
doc1 = EN(u'This is a test sentence.',tag=False,parse=False,entity=True)
|
||||
|
||||
doc2 = Doc(EN.vocab).from_bytes(doc1.to_bytes())
|
||||
equal(doc1,doc2)
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_serialize_tokens_tags_parse(EN):
|
||||
doc1 = EN(u'This is a test sentence.',tag=True,parse=True,entity=True)
|
||||
|
||||
doc2 = Doc(EN.vocab).from_bytes(doc1.to_bytes())
|
||||
equal(doc1,doc2)
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_serialize_tokens_tags_ner(EN):
|
||||
doc1 = EN(u'This is a test sentence.',tag=True,parse=False,entity=True)
|
||||
|
||||
doc2 = Doc(EN.vocab).from_bytes(doc1.to_bytes())
|
||||
equal(doc1,doc2)
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_serialize_tokens_ner_parse(EN):
|
||||
doc1 = EN(u'This is a test sentence.',tag=False,parse=True,entity=True)
|
||||
|
||||
doc2 = Doc(EN.vocab).from_bytes(doc1.to_bytes())
|
||||
equal(doc1,doc2)
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_serialize_tokens_tags_parse_ner(EN):
|
||||
doc1 = EN(u'This is a test sentence.',tag=True,parse=True,entity=True)
|
||||
|
||||
doc2 = Doc(EN.vocab).from_bytes(doc1.to_bytes())
|
||||
equal(doc1,doc2)
|
|
@ -3,30 +3,10 @@ from __future__ import unicode_literals
|
|||
from spacy.en import English
|
||||
import pytest
|
||||
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tagged(EN):
|
||||
string = u'Bananas in pyjamas are geese.'
|
||||
tokens = EN(string, tag=True, parse=False)
|
||||
return tokens
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def lemmas(tagged):
|
||||
return [t.lemma_ for t in tagged]
|
||||
|
||||
|
||||
@pytest.mark.models
|
||||
def test_lemmas(lemmas, tagged):
|
||||
assert lemmas[0] == 'banana'
|
||||
assert lemmas[1] == 'in'
|
||||
assert lemmas[2] == 'pyjama'
|
||||
assert lemmas[3] == 'be'
|
||||
if tagged[2].tag == tagged[4].tag:
|
||||
assert lemmas[4] == 'goose'
|
||||
|
||||
|
||||
def test_didnt(EN):
|
||||
tokens = EN(u"I didn't do it")
|
||||
assert tokens[1].lemma_ != u""
|
||||
def test_lemma_assignment(EN):
|
||||
tokens = u'Bananas in pyjamas are geese .'.split(' ')
|
||||
doc = EN.tokenizer.tokens_from_list(tokens)
|
||||
assert all( t.lemma_ == u'' for t in doc )
|
||||
EN.tagger(doc)
|
||||
assert all( t.lemma_ != u'' for t in doc )
|
||||
|
|
|
@ -190,5 +190,5 @@ def test_right_edge(EN):
|
|||
token = doc[6]
|
||||
assert token.text == u'for'
|
||||
subtree = [w.text for w in token.subtree]
|
||||
assert subtree == [u'for' , u'the', u'sake', u'of']
|
||||
assert token.right_edge.text == u'of'
|
||||
assert subtree == [u'for' , u'the', u'sake', u'of', u'such', u'as', u'live', u'under', u'the', u'government', u'of', u'the', u'Romans', u',']
|
||||
assert token.right_edge.text == u','
|
||||
|
|
Loading…
Reference in New Issue
Block a user