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

Function PyUFunc_GenericFunctionInternal

numpy/core/src/umath/ufunc_object.c:2657–2749  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2655
2656
2657static int
2658PyUFunc_GenericFunctionInternal(PyUFuncObject *ufunc,
2659 PyArrayMethodObject *ufuncimpl, PyArray_Descr *operation_descrs[],
2660 PyArrayObject *op[], PyObject *extobj,
2661 NPY_CASTING casting, NPY_ORDER order,
2662 PyObject *output_array_prepare[], ufunc_full_args full_args,
2663 PyArrayObject *wheremask)
2664{
2665 int nin = ufunc->nin, nout = ufunc->nout, nop = nin + nout;
2666
2667 const char *ufunc_name = ufunc_get_name_cstr(ufunc);
2668
2669 npy_intp default_op_out_flags;
2670 npy_uint32 op_flags[NPY_MAXARGS];
2671
2672 /* These parameters come from extobj= or from a TLS global */
2673 int buffersize = 0, errormask = 0;
2674
2675 NPY_UF_DBG_PRINT1("\nEvaluating ufunc %s\n", ufunc_name);
2676
2677 /* Get the buffersize and errormask */
2678 if (_get_bufsize_errmask(extobj, ufunc_name, &buffersize, &errormask) < 0) {
2679 return -1;
2680 }
2681
2682 if (wheremask != NULL) {
2683 /* Set up the flags. */
2684 default_op_out_flags = NPY_ITER_NO_SUBTYPE |
2685 NPY_ITER_WRITEMASKED |
2686 NPY_UFUNC_DEFAULT_OUTPUT_FLAGS;
2687 _ufunc_setup_flags(ufunc, NPY_UFUNC_DEFAULT_INPUT_FLAGS,
2688 default_op_out_flags, op_flags);
2689 }
2690 else {
2691 /* Set up the flags. */
2692 default_op_out_flags = NPY_ITER_WRITEONLY |
2693 NPY_UFUNC_DEFAULT_OUTPUT_FLAGS;
2694 _ufunc_setup_flags(ufunc, NPY_UFUNC_DEFAULT_INPUT_FLAGS,
2695 default_op_out_flags, op_flags);
2696 }
2697
2698 /* Final preparation of the arraymethod call */
2699 PyArrayMethod_Context context = {
2700 .caller = (PyObject *)ufunc,
2701 .method = ufuncimpl,
2702 .descriptors = operation_descrs,
2703 };
2704
2705 /* Do the ufunc loop */
2706 if (wheremask != NULL) {
2707 NPY_UF_DBG_PRINT("Executing masked inner loop\n");
2708
2709 if (nop + 1 > NPY_MAXARGS) {
2710 PyErr_SetString(PyExc_ValueError,
2711 "Too many operands when including where= parameter");
2712 return -1;
2713 }
2714 op[nop] = wheremask;

Callers 1

ufunc_generic_fastcallFunction · 0.85

Calls 6

ufunc_get_name_cstrFunction · 0.85
_get_bufsize_errmaskFunction · 0.85
_ufunc_setup_flagsFunction · 0.85
execute_ufunc_loopFunction · 0.85
check_for_trivial_loopFunction · 0.85

Tested by

no test coverage detected