MCPcopy Index your code
hub / github.com/numpy/numpy / make_ufuncs

Function make_ufuncs

numpy/_core/code_generators/generate_umath.py:1540–1631  ·  view source on GitHub ↗
(funcdict)

Source from the content-addressed store, hash-verified

1538 return "\n".join(code1list), "\n".join(code2list)
1539
1540def make_ufuncs(funcdict):
1541 code3list = []
1542 names = sorted(funcdict.keys())
1543 for name in names:
1544 uf = funcdict[name]
1545 mlist = []
1546 if uf.signature is None:
1547 sig = "NULL"
1548 else:
1549 sig = f'"{uf.signature}"'
1550 fmt = textwrap.dedent("""\
1551 identity = {identity_expr};
1552 if ({has_identity} && identity == NULL) {{
1553 return -1;
1554 }}
1555 f = PyUFunc_FromFuncAndDataAndSignatureAndIdentity(
1556 {funcs}, {data}, {signatures}, {nloops},
1557 {nin}, {nout}, {identity}, "{name}",
1558 {doc}, 0, {sig}, identity
1559 );
1560 if ({has_identity}) {{
1561 Py_DECREF(identity);
1562 }}
1563 if (f == NULL) {{
1564 return -1;
1565 }}
1566 """)
1567 args = {
1568 "name": name,
1569 "funcs": f"{name}_functions" if not uf.empty else "NULL",
1570 "data": f"{name}_data" if not uf.empty else "NULL",
1571 "signatures": f"{name}_signatures" if not uf.empty else "NULL",
1572 "nloops": len(uf.type_descriptions),
1573 "nin": uf.nin, "nout": uf.nout,
1574 "has_identity": '0' if uf.identity is None_ else '1',
1575 "identity": 'PyUFunc_IdentityValue',
1576 "identity_expr": uf.identity,
1577 "doc": uf.docstring,
1578 "sig": sig,
1579 }
1580
1581 # Only PyUFunc_None means don't reorder - we pass this using the old
1582 # argument
1583 if uf.identity is None_:
1584 args['identity'] = 'PyUFunc_None'
1585 args['identity_expr'] = 'NULL'
1586
1587 mlist.append(fmt.format(**args))
1588 if uf.typereso is not None:
1589 mlist.append(rf"((PyUFuncObject *)f)->type_resolver = &{uf.typereso};")
1590 for c in uf.indexed:
1591 # Handle indexed loops by getting the underlying ArrayMethodObject
1592 # from the dict in f._loops and setting its field appropriately
1593 fmt = textwrap.dedent("""
1594 {{
1595 PyArray_DTypeMeta *dtype = PyArray_DTypeFromTypeNum({typenum});
1596 PyObject *info = get_info_no_cast((PyUFuncObject *)f,
1597 dtype, {count});

Callers 1

make_codeFunction · 0.85

Calls 3

joinMethod · 0.80
english_upperFunction · 0.70
keysMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…