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

Function npyiter_check_global_flags

numpy/core/src/multiarray/nditer_constr.c:758–821  ·  view source on GitHub ↗

Checks 'flags' for (C|F)_ORDER_INDEX, MULTI_INDEX, and EXTERNAL_LOOP, * setting the appropriate internal flags in 'itflags'. * * Returns 1 on success, 0 on error. */

Source from the content-addressed store, hash-verified

756 * Returns 1 on success, 0 on error.
757 */
758static int
759npyiter_check_global_flags(npy_uint32 flags, npy_uint32* itflags)
760{
761 if ((flags & NPY_ITER_PER_OP_FLAGS) != 0) {
762 PyErr_SetString(PyExc_ValueError,
763 "A per-operand flag was passed as a global flag "
764 "to the iterator constructor");
765 return 0;
766 }
767
768 /* Check for an index */
769 if (flags & (NPY_ITER_C_INDEX | NPY_ITER_F_INDEX)) {
770 if ((flags & (NPY_ITER_C_INDEX | NPY_ITER_F_INDEX)) ==
771 (NPY_ITER_C_INDEX | NPY_ITER_F_INDEX)) {
772 PyErr_SetString(PyExc_ValueError,
773 "Iterator flags C_INDEX and "
774 "F_INDEX cannot both be specified");
775 return 0;
776 }
777 (*itflags) |= NPY_ITFLAG_HASINDEX;
778 }
779 /* Check if a multi-index was requested */
780 if (flags & NPY_ITER_MULTI_INDEX) {
781 /*
782 * This flag primarily disables dimension manipulations that
783 * would produce an incorrect multi-index.
784 */
785 (*itflags) |= NPY_ITFLAG_HASMULTIINDEX;
786 }
787 /* Check if the caller wants to handle inner iteration */
788 if (flags & NPY_ITER_EXTERNAL_LOOP) {
789 if ((*itflags) & (NPY_ITFLAG_HASINDEX | NPY_ITFLAG_HASMULTIINDEX)) {
790 PyErr_SetString(PyExc_ValueError,
791 "Iterator flag EXTERNAL_LOOP cannot be used "
792 "if an index or multi-index is being tracked");
793 return 0;
794 }
795 (*itflags) |= NPY_ITFLAG_EXLOOP;
796 }
797 /* Ranged */
798 if (flags & NPY_ITER_RANGED) {
799 (*itflags) |= NPY_ITFLAG_RANGE;
800 if ((flags & NPY_ITER_EXTERNAL_LOOP) &&
801 !(flags & NPY_ITER_BUFFERED)) {
802 PyErr_SetString(PyExc_ValueError,
803 "Iterator flag RANGED cannot be used with "
804 "the flag EXTERNAL_LOOP unless "
805 "BUFFERED is also enabled");
806 return 0;
807 }
808 }
809 /* Buffering */
810 if (flags & NPY_ITER_BUFFERED) {
811 (*itflags) |= NPY_ITFLAG_BUFFER;
812 if (flags & NPY_ITER_GROWINNER) {
813 (*itflags) |= NPY_ITFLAG_GROWINNER;
814 }
815 if (flags & NPY_ITER_DELAY_BUFALLOC) {

Callers 1

NpyIter_AdvancedNewFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected