I read the source code of the library Python numpyand found the following snippets. It seems that it performs elementary operations on vectors ( numpy.ndarray). For example, numpy.multiply([1,2,3],[4,5,6])get the result[4,10,18]
UNARY_LOOP { \
const tin in = *(tin *)ip1; \
tout * out = (tout *)op1; \
op; \
}
do { \
/* condition allows compiler to optimize the generic macro */ \
if (IS_UNARY_CONT(tin, tout)) { \
if (args[0] == args[1]) { \
BASE_UNARY_LOOP(tin, tout, op) \
} \
else { \
BASE_UNARY_LOOP(tin, tout, op) \
} \
} \
else { \
BASE_UNARY_LOOP(tin, tout, op) \
} \
} \
while (0)
It looks very strange to me, especially the comment inside UNARY_LOOP_FAST. What happens here using if A then X else Xlogic to optimize?
source
share