45 auto dim = (row ? mat.
nrow() : mat.
ncol());
46 auto otherdim = (row ? mat.
ncol() : mat.
nrow());
47 std::fill(output, output + dim, 0);
53 bool count_zero = condition(0);
56 std::vector<Value_> xbuffer(otherdim);
57 std::vector<Index_> ibuffer(otherdim);
60 for (Index_ x = 0; x < len; ++x) {
61 auto range = ext->fetch(xbuffer.data(), ibuffer.data());
63 for (Index_ j = 0; j < range.number; ++j) {
64 target += condition(range.value[j]);
67 target += otherdim - range.number;
69 output[x + start] = target;
75 std::vector<Value_> xbuffer(otherdim);
78 for (Index_ x = 0; x < len; ++x) {
79 auto ptr = ext->fetch(xbuffer.data());
81 for (Index_ j = 0; j < otherdim; ++j) {
82 target += condition(ptr[j]);
84 output[x + start] = target;
90 std::vector<std::vector<Output_> > threaded_output(num_threads > 0 ? num_threads - 1 : 0);
95 bool count_zero = condition(0);
98 std::vector<Value_> xbuffer(dim);
99 std::vector<Index_> ibuffer(dim);
102 auto curoutput = output;
104 auto& outvec = threaded_output[thread - 1];
106 curoutput = outvec.data();
108 std::vector<Index_> nonzeros(dim);
110 for (Index_ x = 0; x < len; ++x) {
111 auto range = ext->fetch(xbuffer.data(), ibuffer.data());
112 for (Index_ j = 0; j < range.number; ++j) {
113 auto idx = range.index[j];
114 curoutput[idx] += condition(range.value[j]);
120 for (
int d = 0; d < dim; ++d) {
121 curoutput[d] += len - nonzeros[d];
124 }, otherdim, num_threads);
128 std::vector<Value_> xbuffer(dim);
131 auto curoutput = output;
133 auto& outvec = threaded_output[thread - 1];
135 curoutput = outvec.data();
138 for (Index_ x = 0; x < len; ++x) {
139 auto ptr = ext->fetch(xbuffer.data());
140 for (Index_ j = 0; j < dim; ++j) {
141 curoutput[j] += condition(ptr[j]);
144 }, otherdim, num_threads);
147 for (
const auto& curout : threaded_output) {
148 if (!curout.empty()) {
149 for (Index_ d = 0; d < dim; ++d) {
150 output[d] += curout[d];