@@ -151,6 +151,46 @@ void mean(const vector_type& a, const vector_type& b, vector_type& res)
151
151
}
152
152
```
153
153
154
+ Algorithms like `xsimd::reduce` and `xsimd::transform` are available also in the batch explicit modality:
155
+
156
+ ```cpp
157
+ template <class C, class T = typename std::decay<decltype(*C().begin())>::type>
158
+ T nansum(const C& v)
159
+ {
160
+ return xsimd::reduce_batch(v.begin(), v.end(), 0.0,
161
+ [](auto x, auto y) {
162
+ return (std::isnan(x) ? 0.0 : x) + (std::isnan(y) ? 0.0 : y);
163
+ },
164
+ [](auto x, auto y) {
165
+ static decltype(x) zero(0.0);
166
+ auto xnan = xsimd::isnan(x);
167
+ auto ynan = xsimd::isnan(y);
168
+ auto xs = xsimd::select(xnan, zero, x);
169
+ auto ys = xsimd::select(ynan, zero, y);
170
+ return xs + ys;
171
+ });
172
+ }
173
+ ```
174
+
175
+ To switch from ` std::count_if ` to ` xsimd::count_if ` :
176
+
177
+ ``` cpp
178
+ // v is an aligned vector of int type
179
+ auto count_expected = std::count_if(v.begin(), v.end(),
180
+ [](auto x) {
181
+ return x >= 50 && x <= 70 ? 1 : 0;
182
+ });
183
+ auto count = xsimd::count_if(v.begin(), v.end(),
184
+ [](auto x) {
185
+ return x >= 50 && x <= 70 ? 1 : 0;
186
+ },
187
+ [](auto b) {
188
+ static decltype(b) zero(0);
189
+ static decltype(b) one(1);
190
+ return xsimd::hadd(xsimd::select(b >= 50 && b <= 70, one, zero));
191
+ });
192
+ assert (count_expected == count);
193
+ ```
154
194
155
195
## Building and Running the Tests
156
196
0 commit comments