Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteae5c53

Browse files
committed
Convert umath_linalg to multi-phase init (PEP 489)
1 parentbbdebae commiteae5c53

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

‎numpy/linalg/umath_linalg.cpp

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4688,57 +4688,40 @@ static PyMethodDef UMath_LinAlgMethods[] = {
46884688
{NULL,NULL,0,NULL}/* Sentinel */
46894689
};
46904690

4691-
staticstructPyModuleDefmoduledef= {
4692-
PyModuleDef_HEAD_INIT,
4693-
UMATH_LINALG_MODULE_NAME,
4694-
NULL,
4695-
-1,
4696-
UMath_LinAlgMethods,
4697-
NULL,
4698-
NULL,
4699-
NULL,
4700-
NULL
4701-
};
4702-
4703-
PyMODINIT_FUNCPyInit__umath_linalg(void)
4691+
staticint
4692+
_umath_linalg_exec(PyObject*m)
47044693
{
4705-
PyObject*m;
47064694
PyObject*d;
47074695
PyObject*version;
47084696

4709-
m=PyModule_Create(&moduledef);
4710-
if (m==NULL) {
4711-
returnNULL;
4712-
}
4713-
4714-
import_array();
4715-
import_ufunc();
4697+
import_array1(-1);
4698+
import_umath1(-1);
47164699

47174700
d=PyModule_GetDict(m);
47184701
if (d==NULL) {
4719-
returnNULL;
4702+
return-1;
47204703
}
47214704

47224705
version=PyUnicode_FromString(umath_linalg_version_string);
47234706
if (version==NULL) {
4724-
returnNULL;
4707+
return-1;
47254708
}
47264709
intret=PyDict_SetItemString(d,"__version__",version);
47274710
Py_DECREF(version);
47284711
if (ret<0) {
4729-
returnNULL;
4712+
return-1;
47304713
}
47314714

47324715
/* Load the ufunc operators into the module's namespace */
47334716
if (addUfuncs(d)<0) {
4734-
returnNULL;
4717+
return-1;
47354718
}
47364719

47374720
#ifPY_VERSION_HEX<0x30d00b3&& !HAVE_EXTERNAL_LAPACK
47384721
lapack_lite_lock=PyThread_allocate_lock();
47394722
if (lapack_lite_lock==NULL) {
47404723
PyErr_NoMemory();
4741-
returnNULL;
4724+
return-1;
47424725
}
47434726
#endif
47444727

@@ -4748,10 +4731,30 @@ PyMODINIT_FUNC PyInit__umath_linalg(void)
47484731
PyDict_SetItemString(d,"_ilp64",Py_False);
47494732
#endif
47504733

4751-
#ifPy_GIL_DISABLED
4752-
// signal this module supports running with the GIL disabled
4753-
PyUnstable_Module_SetGIL(m,Py_MOD_GIL_NOT_USED);
4734+
return0;
4735+
}
4736+
4737+
staticstructPyModuleDef_Slot_umath_linalg_slots[]= {
4738+
{Py_mod_exec, (void*)_umath_linalg_exec},
4739+
#ifPY_VERSION_HEX >=0x030c00f0// Python 3.12+
4740+
{Py_mod_multiple_interpreters,Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
4741+
#endif
4742+
#ifPY_VERSION_HEX >=0x030d00f0// Python 3.13+
4743+
// signal that this module supports running without an active GIL
4744+
{Py_mod_gil,Py_MOD_GIL_NOT_USED},
47544745
#endif
4746+
{0,NULL},
4747+
};
4748+
4749+
staticstructPyModuleDefmoduledef= {
4750+
PyModuleDef_HEAD_INIT,/* m_base */
4751+
"_umath_linalg",/* m_name */
4752+
NULL,/* m_doc */
4753+
-1,/* m_size */
4754+
UMath_LinAlgMethods,/* m_methods */
4755+
_umath_linalg_slots,/* m_slots */
4756+
};
47554757

4756-
returnm;
4758+
PyMODINIT_FUNCPyInit__umath_linalg(void) {
4759+
returnPyModuleDef_Init(&moduledef);
47574760
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp