-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
WIP: refactor dtype to be a type subclass #12585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b08d30c
1dcab70
f574588
fed8ecf
c8f3560
aaff618
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4437,10 +4437,8 @@ set_typeinfo(PyObject *dict) | |
* #DO_ELSIZE = 1*19, 0*3, 1*2# | ||
*/ | ||
|
||
#if USE_DTYPE_AS_PYOBJECT | ||
dtype = PyObject_New(PyArray_Descr, &PyArrayDescr_Type); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the advantage of heap allocating here vs the previous static allocation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personal preference. At some point perhaps subinterpreters support may become mature enough that we will want to allow reloading the NumPy module, and thinking about what that means for static allocation gets me confused. |
||
#else | ||
dtype = PyObject_GC_New(PyArray_Descr, &PyArrayDescr_Type); | ||
#ifndef USE_DTYPE_AS_PYOBJECT | ||
/* Don't copy PyObject_HEAD part */ | ||
memset((char *)dtype + sizeof(PyObject), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For me (and thus for future people looking at this...), it would be helpful to expand on why this is done. Does it get filled out later by actually instantiating? I realize links to documentation can get out of sync, but might still be better than nothing. Looking at the documentation for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the goal here is to ensure all the tp_ slots are initialized to null, without having to list them all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My question was whether it should be zeroed: presumably There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment here is wrong though - the word There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Arggh, I just looked so poorly - of course the code zeros everything beyond |
||
0, | ||
|
@@ -4540,7 +4538,6 @@ set_typeinfo(PyObject *dict) | |
infodict = PyDict_New(); | ||
if (infodict == NULL) return -1; | ||
|
||
|
||
/**begin repeat | ||
* | ||
* #name = BOOL, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this needs to be PyHeapTypeObject. The Cython team explored this and ran into the problem before until they made meta-types inherit from PyHeapTypeObject. See, for example, https://mail.python.org/pipermail/cython-devel/2013-September/003813.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this applies to us. From that thread:
In our case, the instance of the dtype is
malloc
'd and initialized byarraydescr_new
, so we're in complete control.As far as I can tell, the main purpose of
PyHeapTypeObject
is to convert builtin magic methods into slots, something we probably don't care about too much for dtypes.