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

Function _npy_clip_

numpy/core/src/umath/clip.cpp:116–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114
115template <class Tag, class T = typename Tag::type>
116static void
117_npy_clip_(T **args, npy_intp const *dimensions, npy_intp const *steps)
118{
119 npy_intp n = dimensions[0];
120 if (steps[1] == 0 && steps[2] == 0) {
121 /* min and max are constant throughout the loop, the most common case
122 */
123 /* NOTE: it may be possible to optimize these checks for nan */
124 T min_val = *args[1];
125 T max_val = *args[2];
126
127 T *ip1 = args[0], *op1 = args[3];
128 npy_intp is1 = steps[0] / sizeof(T), os1 = steps[3] / sizeof(T);
129
130 /* contiguous, branch to let the compiler optimize */
131 if (is1 == 1 && os1 == 1) {
132 for (npy_intp i = 0; i < n; i++, ip1++, op1++) {
133 *op1 = _NPY_CLIP<Tag>(*ip1, min_val, max_val);
134 }
135 }
136 else {
137 for (npy_intp i = 0; i < n; i++, ip1 += is1, op1 += os1) {
138 *op1 = _NPY_CLIP<Tag>(*ip1, min_val, max_val);
139 }
140 }
141 }
142 else {
143 T *ip1 = args[0], *ip2 = args[1], *ip3 = args[2], *op1 = args[3];
144 npy_intp is1 = steps[0] / sizeof(T), is2 = steps[1] / sizeof(T),
145 is3 = steps[2] / sizeof(T), os1 = steps[3] / sizeof(T);
146 for (npy_intp i = 0; i < n;
147 i++, ip1 += is1, ip2 += is2, ip3 += is3, op1 += os1)
148 *op1 = _NPY_CLIP<Tag>(*ip1, *ip2, *ip3);
149 }
150 npy_clear_floatstatus_barrier((char *)dimensions);
151}
152
153template <class Tag>
154static void

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected