Skip to content

Commit 1d73e4e

Browse files
committed
Pull request #4: Convert scalar types, comment out some initialization that is not needed by the game of life example
Merge ss/hpy-scalar-types to labs-hpy-port * commit '7ff906885dd929a6f33443aaad81ada3fed61f1e': Convert scalar types, comment out some initialization that is not needed by the game of life example
2 parents f1d256d + 7ff9068 commit 1d73e4e

13 files changed

+867
-290
lines changed

numpy/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
from . import linalg
149149
from . import fft
150150
from . import polynomial
151+
# from . import random
151152
from . import ctypeslib
152153
from . import ma
153154
from . import matrixlib as _mat

numpy/core/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@
9696

9797
# do this after everything else, to minimize the chance of this misleadingly
9898
# appearing in an import-time traceback
99-
from . import _add_newdocs
100-
from . import _add_newdocs_scalars
99+
#from . import _add_newdocs
100+
#from . import _add_newdocs_scalars
101101
# add these for module-freeze analysis (like PyInstaller)
102102
from . import _dtype_ctypes
103103
from . import _internal

numpy/core/_add_newdocs.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6682,36 +6682,36 @@ def refer_to_array_attribute(attr, method=True):
66826682
add_newdoc('numpy.core.numerictypes', 'generic',
66836683
refer_to_array_attribute('view'))
66846684

6685-
add_newdoc('numpy.core.numerictypes', 'number', ('__class_getitem__',
6686-
"""
6687-
__class_getitem__(item, /)
6685+
# add_newdoc('numpy.core.numerictypes', 'number', ('__class_getitem__',
6686+
# """
6687+
# __class_getitem__(item, /)
66886688

6689-
Return a parametrized wrapper around the `~numpy.number` type.
6689+
# Return a parametrized wrapper around the `~numpy.number` type.
66906690

6691-
.. versionadded:: 1.22
6691+
# .. versionadded:: 1.22
66926692

6693-
Returns
6694-
-------
6695-
alias : types.GenericAlias
6696-
A parametrized `~numpy.number` type.
6693+
# Returns
6694+
# -------
6695+
# alias : types.GenericAlias
6696+
# A parametrized `~numpy.number` type.
66976697

6698-
Examples
6699-
--------
6700-
>>> from typing import Any
6701-
>>> import numpy as np
6698+
# Examples
6699+
# --------
6700+
# >>> from typing import Any
6701+
# >>> import numpy as np
67026702

6703-
>>> np.signedinteger[Any]
6704-
numpy.signedinteger[typing.Any]
6703+
# >>> np.signedinteger[Any]
6704+
# numpy.signedinteger[typing.Any]
67056705

6706-
Notes
6707-
-----
6708-
This method is only available for python 3.9 and later.
6706+
# Notes
6707+
# -----
6708+
# This method is only available for python 3.9 and later.
67096709

6710-
See Also
6711-
--------
6712-
:pep:`585` : Type hinting generics in standard collections.
6710+
# See Also
6711+
# --------
6712+
# :pep:`585` : Type hinting generics in standard collections.
67136713

6714-
"""))
6714+
# """))
67156715

67166716
##############################################################################
67176717
#

numpy/core/code_generators/genapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def array_api_assign(self):
405405

406406
def internal_define(self):
407407
astr = """\
408-
extern NPY_NO_EXPORT PyBoolScalarObject _PyArrayScalar_BoolValues[2];
408+
extern NPY_NO_EXPORT PyBoolScalarObject *_PyArrayScalar_BoolValues[2];
409409
"""
410410
return astr
411411

numpy/core/code_generators/generate_numpy_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
1818
extern NPY_NO_EXPORT PyTypeObject *PyArrayMapIter_Type;
1919
extern NPY_NO_EXPORT PyTypeObject *PyArrayNeighborhoodIter_Type;
20-
extern NPY_NO_EXPORT PyBoolScalarObject _PyArrayScalar_BoolValues[2];
20+
extern NPY_NO_EXPORT PyBoolScalarObject *_PyArrayScalar_BoolValues[2];
2121
2222
%s
2323

numpy/core/code_generators/numpy_api.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -38,42 +38,42 @@
3838
'PyArrayFlags_Type': (4, None, "_PyArrayFlags_Type_p"),
3939
'PyArrayIter_Type': (5, None, "_PyArrayIter_Type_p"),
4040
'PyArrayMultiIter_Type': (6, None, "_PyArrayMultiIter_Type_p"),
41-
'PyBoolArrType_Type': (8,),
42-
'PyGenericArrType_Type': (10,),
43-
'PyNumberArrType_Type': (11,),
44-
'PyIntegerArrType_Type': (12,),
45-
'PySignedIntegerArrType_Type': (13,),
46-
'PyUnsignedIntegerArrType_Type': (14,),
47-
'PyInexactArrType_Type': (15,),
48-
'PyFloatingArrType_Type': (16,),
49-
'PyComplexFloatingArrType_Type': (17,),
50-
'PyFlexibleArrType_Type': (18,),
51-
'PyCharacterArrType_Type': (19,),
52-
'PyByteArrType_Type': (20,),
53-
'PyShortArrType_Type': (21,),
54-
'PyIntArrType_Type': (22,),
55-
'PyLongArrType_Type': (23,),
56-
'PyLongLongArrType_Type': (24,),
57-
'PyUByteArrType_Type': (25,),
58-
'PyUShortArrType_Type': (26,),
59-
'PyUIntArrType_Type': (27,),
60-
'PyULongArrType_Type': (28,),
61-
'PyULongLongArrType_Type': (29,),
62-
'PyFloatArrType_Type': (30,),
63-
'PyDoubleArrType_Type': (31,),
64-
'PyLongDoubleArrType_Type': (32,),
65-
'PyCFloatArrType_Type': (33,),
66-
'PyCDoubleArrType_Type': (34,),
67-
'PyCLongDoubleArrType_Type': (35,),
68-
'PyObjectArrType_Type': (36,),
69-
'PyStringArrType_Type': (37,),
70-
'PyUnicodeArrType_Type': (38,),
71-
'PyVoidArrType_Type': (39,),
41+
'PyBoolArrType_Type': (8, None, '&PyBoolArrType_Type'),
42+
'PyGenericArrType_Type': (10, None, "&PyGenericArrType_Type"),
43+
'PyNumberArrType_Type': (11, None, "&PyNumberArrType_Type"),
44+
'PyIntegerArrType_Type': (12, None, '&PyIntegerArrType_Type'),
45+
'PySignedIntegerArrType_Type': (13, None, '&PySignedIntegerArrType_Type'),
46+
'PyUnsignedIntegerArrType_Type': (14, None, '&PyUnsignedIntegerArrType_Type'),
47+
'PyInexactArrType_Type': (15, None, '&PyInexactArrType_Type'),
48+
'PyFloatingArrType_Type': (16, None, '&PyFloatingArrType_Type'),
49+
'PyComplexFloatingArrType_Type': (17, None, '&PyComplexFloatingArrType_Type'),
50+
'PyFlexibleArrType_Type': (18, None, '&PyFlexibleArrType_Type'),
51+
'PyCharacterArrType_Type': (19, None, '&PyCharacterArrType_Type'),
52+
'PyByteArrType_Type': (20, None, '&PyByteArrType_Type'),
53+
'PyShortArrType_Type': (21, None, '&PyShortArrType_Type'),
54+
'PyIntArrType_Type': (22, None, '&PyIntArrType_Type'),
55+
'PyLongArrType_Type': (23, None, '&PyLongArrType_Type'),
56+
'PyLongLongArrType_Type': (24, None, '&PyLongLongArrType_Type'),
57+
'PyUByteArrType_Type': (25, None, '&PyUByteArrType_Type'),
58+
'PyUShortArrType_Type': (26, None, '&PyUShortArrType_Type'),
59+
'PyUIntArrType_Type': (27, None, '&PyUIntArrType_Type'),
60+
'PyULongArrType_Type': (28, None, '&PyULongArrType_Type'),
61+
'PyULongLongArrType_Type': (29, None, '&PyULongLongArrType_Type'),
62+
'PyFloatArrType_Type': (30, None, '&PyFloatArrType_Type'),
63+
'PyDoubleArrType_Type': (31, None, '&PyDoubleArrType_Type'),
64+
'PyLongDoubleArrType_Type': (32, None, '&PyLongDoubleArrType_Type'),
65+
'PyCFloatArrType_Type': (33, None, '&PyCFloatArrType_Type'),
66+
'PyCDoubleArrType_Type': (34, None, '&PyCDoubleArrType_Type'),
67+
'PyCLongDoubleArrType_Type': (35, None, '&PyCLongDoubleArrType_Type'),
68+
'PyObjectArrType_Type': (36, None, '&PyObjectArrType_Type'),
69+
'PyStringArrType_Type': (37, None, '&PyStringArrType_Type'),
70+
'PyUnicodeArrType_Type': (38, None, '&PyUnicodeArrType_Type'),
71+
'PyVoidArrType_Type': (39, None, '&PyVoidArrType_Type'),
7272
# End 1.5 API
73-
'PyTimeIntegerArrType_Type': (214,),
74-
'PyDatetimeArrType_Type': (215,),
75-
'PyTimedeltaArrType_Type': (216,),
76-
'PyHalfArrType_Type': (217,),
73+
'PyTimeIntegerArrType_Type': (214, None, '&PyTimeIntegerArrType_Type'),
74+
'PyDatetimeArrType_Type': (215, None, '&PyDatetimeArrType_Type'),
75+
'PyTimedeltaArrType_Type': (216, None, '&PyTimedeltaArrType_Type'),
76+
'PyHalfArrType_Type': (217, None, '&PyHalfArrType_Type'),
7777
'NpyIter_Type': (218,),
7878
# End 1.6 API
7979
}

numpy/core/include/numpy/arrayscalars.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ typedef struct {
158158
are defined in ndarrayobject.h
159159
*/
160160

161-
#define PyArrayScalar_False ((PyObject *)(&(_PyArrayScalar_BoolValues[0])))
162-
#define PyArrayScalar_True ((PyObject *)(&(_PyArrayScalar_BoolValues[1])))
161+
#define PyArrayScalar_False ((PyObject *)((_PyArrayScalar_BoolValues[0])))
162+
#define PyArrayScalar_True ((PyObject *)((_PyArrayScalar_BoolValues[1])))
163163
#define PyArrayScalar_FromLong(i) \
164-
((PyObject *)(&(_PyArrayScalar_BoolValues[((i)!=0)])))
164+
((PyObject *)((_PyArrayScalar_BoolValues[((i)!=0)])))
165165
#define PyArrayScalar_RETURN_BOOL_FROM_LONG(i) \
166166
return Py_INCREF(PyArrayScalar_FromLong(i)), \
167167
PyArrayScalar_FromLong(i)

numpy/core/src/multiarray/arraytypes.c.src

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4190,7 +4190,7 @@ static PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {
41904190
static PyArray_Descr @from@_Descr = {
41914191
PyObject_HEAD_INIT((PyTypeObject* ) (&PyArrayDescr_TypeFull))
41924192
/* typeobj */
4193-
&Py@NAME@ArrType_Type,
4193+
NULL,
41944194
/* kind */
41954195
NPY_@from@LTR,
41964196
/* type */
@@ -4340,7 +4340,7 @@ static PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {
43404340
NPY_NO_EXPORT PyArray_Descr @from@_Descr = {
43414341
PyObject_HEAD_INIT((PyTypeObject* ) (&PyArrayDescr_TypeFull))
43424342
/* typeobj */
4343-
&Py@NAME@ArrType_Type,
4343+
NULL,
43444344
/* kind */
43454345
NPY_@kind@LTR,
43464346
/* type */
@@ -4433,6 +4433,29 @@ static HPy _hpy_builtin_descrs[] = {
44334433
HPy_NULL,
44344434
};
44354435

4436+
// HPY TODO: temporary hack, dtype (BOOL_Descr, etc.) are
4437+
// still statically allocated PyObjects, but cannot have dynamically
4438+
// allocated type in their static initializers...
4439+
NPY_NO_EXPORT void init_static_descrs_type_objs(HPyContext *ctx) {
4440+
/**begin repeat
4441+
*
4442+
* #from = VOID, STRING, UNICODE, BOOL,
4443+
* BYTE, UBYTE, SHORT, USHORT, INT, UINT,
4444+
* LONG, ULONG, LONGLONG, ULONGLONG,
4445+
* HALF, FLOAT, DOUBLE, LONGDOUBLE,
4446+
* CFLOAT, CDOUBLE, CLONGDOUBLE,
4447+
* OBJECT, DATETIME, TIMEDELTA#
4448+
* #NAME = Void, String, Unicode, Bool,
4449+
* Byte, UByte, Short, UShort, Int, UInt,
4450+
* Long, ULong, LongLong, ULongLong,
4451+
* Half, Float, Double, LongDouble,
4452+
* CFloat, CDouble, CLongDouble,
4453+
* Object, Datetime, Timedelta#
4454+
*/
4455+
@from@_Descr.typeobj = _Py@NAME@ArrType_Type_p;
4456+
/**end repeat**/
4457+
}
4458+
44364459
// HPY TODO: temporary hack, should be heap types in module state
44374460
void init_hpy_global_state(HPyContext *ctx) {
44384461
for (size_t i = 0; i < NPY_NTYPES; ++i) {

numpy/core/src/multiarray/arraytypes.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@ void init_hpy_global_state(HPyContext *ctx);
3333
NPY_NO_EXPORT HPy
3434
HPyArray_DescrFromType(HPyContext *ctx, int type);
3535

36+
NPY_NO_EXPORT void
37+
init_static_descrs_type_objs(HPyContext *ctx);
38+
3639
#endif /* NUMPY_CORE_SRC_MULTIARRAY_ARRAYTYPES_H_ */

numpy/core/src/multiarray/descriptor.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,6 @@ arraydescr_dealloc(PyArray_Descr *self)
19771977
fprintf(stderr, "*** Reference count error detected: "
19781978
"an attempt was made to deallocate the dtype %d (%c) ***\n",
19791979
self->type_num, self->type);
1980-
assert(0);
19811980
Py_INCREF(self);
19821981
Py_INCREF(self);
19831982
return;

0 commit comments

Comments
 (0)