Skip to content

Commit

Permalink
Sprinkled in the new SUBPAR_VECTORIZABLE macro to encourage autovecto…
Browse files Browse the repository at this point in the history
…rization.
  • Loading branch information
LTLA committed Oct 24, 2024
1 parent a19defa commit d714d7f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ FetchContent_Declare(
FetchContent_Declare(
subpar
GIT_REPOSITORY https://github.com/LTLA/subpar
GIT_TAG master # ^0.3.0
GIT_TAG master # ^0.3.2
)

FetchContent_MakeAvailable(tatami)
Expand Down
4 changes: 4 additions & 0 deletions include/tatami_stats/counts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void apply(bool row, const tatami::Matrix<Value_, Index_>* p, Output_* output, i

for (Index_ x = 0; x < len; ++x) {
auto range = ext->fetch(xbuffer.data(), ibuffer.data());
SUBPAR_VECTORIZABLE
for (Index_ j = 0; j < range.number; ++j) {
auto idx = range.index[j];
curoutput[idx] += condition(range.value[j]);
Expand All @@ -119,6 +120,7 @@ void apply(bool row, const tatami::Matrix<Value_, Index_>* p, Output_* output, i
}

if (count_zero) {
SUBPAR_VECTORIZABLE
for (int d = 0; d < dim; ++d) {
curoutput[d] += len - nonzeros[d];
}
Expand All @@ -133,6 +135,7 @@ void apply(bool row, const tatami::Matrix<Value_, Index_>* p, Output_* output, i

for (Index_ x = 0; x < len; ++x) {
auto ptr = ext->fetch(xbuffer.data());
SUBPAR_VECTORIZABLE
for (Index_ j = 0; j < dim; ++j) {
curoutput[j] += condition(ptr[j]);
}
Expand All @@ -142,6 +145,7 @@ void apply(bool row, const tatami::Matrix<Value_, Index_>* p, Output_* output, i

for (int t = 1; t < num_threads; ++t) {
auto curoutput = threaded_output_ptrs[t];
SUBPAR_VECTORIZABLE
for (Index_ d = 0; d < dim; ++d) {
output[d] += curoutput[d];
}
Expand Down
5 changes: 5 additions & 0 deletions include/tatami_stats/ranges.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class RunningDense {
::tatami_stats::internal::nanable_ifelse<Value_>(
my_skip_nan,
[&]() {
SUBPAR_VECTORIZABLE
for (Index_ i = 0; i < my_num; ++i, ++ptr) {
auto val = *ptr;
if (std::isnan(val)) {
Expand All @@ -205,6 +206,7 @@ class RunningDense {
);

} else {
SUBPAR_VECTORIZABLE
for (Index_ i = 0; i < my_num; ++i, ++ptr) {
auto val = *ptr;
if (internal::is_better<minimum_>(my_store[i], val)) { // this should implicitly skip NaNs, any NaN comparison will be false.
Expand Down Expand Up @@ -269,6 +271,7 @@ class RunningSparse {
std::fill_n(my_store, my_num, internal::choose_placeholder<minimum_, Value_>());

if (!my_skip_nan) {
SUBPAR_VECTORIZABLE
for (Index_ i = 0; i < number; ++i, ++value, ++index) {
auto val = *value;
auto idx = *index - my_subtract;
Expand All @@ -280,6 +283,7 @@ class RunningSparse {
}
}

SUBPAR_VECTORIZABLE
for (Index_ i = 0; i < number; ++i, ++value, ++index) {
auto val = *value;
auto idx = *index - my_subtract;
Expand All @@ -298,6 +302,7 @@ class RunningSparse {
*/
void finish() {
if (my_count) {
SUBPAR_VECTORIZABLE
for (Index_ i = 0; i < my_num; ++i) {
if (my_count > my_nonzero[i]) {
auto& current = my_store[i];
Expand Down
4 changes: 4 additions & 0 deletions include/tatami_stats/sums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class RunningDense {
internal::nanable_ifelse<Value_>(
my_skip_nan,
[&]() {
SUBPAR_VECTORIZABLE
for (Index_ i = 0; i < my_num; ++i) {
auto val = ptr[i];
if (!std::isnan(val)) {
Expand All @@ -116,6 +117,7 @@ class RunningDense {
}
},
[&]() {
SUBPAR_VECTORIZABLE
for (Index_ i = 0; i < my_num; ++i) {
my_sum[i] += ptr[i];
}
Expand Down Expand Up @@ -164,6 +166,7 @@ class RunningSparse {
internal::nanable_ifelse<Value_>(
my_skip_nan,
[&]() {
SUBPAR_VECTORIZABLE
for (Index_ i = 0; i < number; ++i) {
auto val = value[i];
if (!std::isnan(val)) {
Expand All @@ -172,6 +175,7 @@ class RunningSparse {
}
},
[&]() {
SUBPAR_VECTORIZABLE
for (Index_ i = 0; i < number; ++i) {
my_sum[index[i] - my_subtract] += value[i];
}
Expand Down
8 changes: 8 additions & 0 deletions include/tatami_stats/variances.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class RunningDense {
::tatami_stats::internal::nanable_ifelse<Value_>(
my_skip_nan,
[&]() {
SUBPAR_VECTORIZABLE
for (Index_ i = 0; i < my_num; ++i, ++ptr) {
auto val = *ptr;
if (!std::isnan(val)) {
Expand All @@ -219,6 +220,7 @@ class RunningDense {
},
[&]() {
++my_count;
SUBPAR_VECTORIZABLE
for (Index_ i = 0; i < my_num; ++i, ++ptr) {
internal::add_welford(my_mean[i], my_variance[i], *ptr, my_count);
}
Expand All @@ -233,6 +235,7 @@ class RunningDense {
::tatami_stats::internal::nanable_ifelse<Value_>(
my_skip_nan,
[&]() {
SUBPAR_VECTORIZABLE
for (Index_ i = 0; i < my_num; ++i) {
auto ct = my_ok_count[i];
if (ct < 2) {
Expand All @@ -252,6 +255,7 @@ class RunningDense {
std::fill_n(my_mean, my_num, std::numeric_limits<Output_>::quiet_NaN());
}
} else {
SUBPAR_VECTORIZABLE
for (Index_ i = 0; i < my_num; ++i) {
my_variance[i] /= my_count - 1;
}
Expand Down Expand Up @@ -308,6 +312,7 @@ class RunningSparse {
::tatami_stats::internal::nanable_ifelse<Value_>(
my_skip_nan,
[&]() {
SUBPAR_VECTORIZABLE
for (Index_ i = 0; i < number; ++i) {
auto val = value[i];
auto ri = index[i] - my_subtract;
Expand All @@ -319,6 +324,7 @@ class RunningSparse {
}
},
[&]() {
SUBPAR_VECTORIZABLE
for (Index_ i = 0; i < number; ++i) {
auto ri = index[i] - my_subtract;
internal::add_welford(my_mean[ri], my_variance[ri], value[i], ++(my_nonzero[ri]));
Expand All @@ -334,6 +340,7 @@ class RunningSparse {
::tatami_stats::internal::nanable_ifelse<Value_>(
my_skip_nan,
[&]() {
SUBPAR_VECTORIZABLE
for (Index_ i = 0; i < my_num; ++i) {
auto& curM = my_mean[i];
auto& curV = my_variance[i];
Expand All @@ -357,6 +364,7 @@ class RunningSparse {
std::fill_n(my_mean, my_num, std::numeric_limits<Output_>::quiet_NaN());
}
} else {
SUBPAR_VECTORIZABLE
for (Index_ i = 0; i < my_num; ++i) {
auto& var = my_variance[i];
internal::add_welford_zeros(my_mean[i], var, my_nonzero[i], my_count);
Expand Down

0 comments on commit d714d7f

Please sign in to comment.