MCPcopy Create free account
hub / github.com/numpy/numpy / make_ufuncs

Function make_ufuncs

numpy/core/code_generators/generate_umath.py:1274–1358  ·  view source on GitHub ↗
(funcdict)

Source from the content-addressed store, hash-verified

1272 return "\n".join(code1list), "\n".join(code2list)
1273
1274def make_ufuncs(funcdict):
1275 code3list = []
1276 names = sorted(funcdict.keys())
1277 for name in names:
1278 uf = funcdict[name]
1279 mlist = []
1280 if uf.signature is None:
1281 sig = "NULL"
1282 else:
1283 sig = '"{}"'.format(uf.signature)
1284 fmt = textwrap.dedent("""\
1285 identity = {identity_expr};
1286 if ({has_identity} && identity == NULL) {{
1287 return -1;
1288 }}
1289 f = PyUFunc_FromFuncAndDataAndSignatureAndIdentity(
1290 {name}_functions, {name}_data, {name}_signatures, {nloops},
1291 {nin}, {nout}, {identity}, "{name}",
1292 {doc}, 0, {sig}, identity
1293 );
1294 if ({has_identity}) {{
1295 Py_DECREF(identity);
1296 }}
1297 if (f == NULL) {{
1298 return -1;
1299 }}
1300 """)
1301 args = dict(
1302 name=name, nloops=len(uf.type_descriptions),
1303 nin=uf.nin, nout=uf.nout,
1304 has_identity='0' if uf.identity is None_ else '1',
1305 identity='PyUFunc_IdentityValue',
1306 identity_expr=uf.identity,
1307 doc=uf.docstring,
1308 sig=sig,
1309 )
1310
1311 # Only PyUFunc_None means don't reorder - we pass this using the old
1312 # argument
1313 if uf.identity is None_:
1314 args['identity'] = 'PyUFunc_None'
1315 args['identity_expr'] = 'NULL'
1316
1317 mlist.append(fmt.format(**args))
1318 if uf.typereso is not None:
1319 mlist.append(
1320 r"((PyUFuncObject *)f)->type_resolver = &%s;" % uf.typereso)
1321 for c in uf.indexed:
1322 # Handle indexed loops by getting the underlying ArrayMethodObject
1323 # from the list in f._loops and setting its field appropriately
1324 fmt = textwrap.dedent("""
1325 {{
1326 PyArray_DTypeMeta *dtype = PyArray_DTypeFromTypeNum({typenum});
1327 PyObject *info = get_info_no_cast((PyUFuncObject *)f,
1328 dtype, {count});
1329 if (info == NULL) {{
1330 return -1;
1331 }}

Callers 1

make_codeFunction · 0.85

Calls 3

keysMethod · 0.80
english_upperFunction · 0.70
joinMethod · 0.45

Tested by

no test coverage detected