Skip to content

Commit

Permalink
Refactor the loop to clarify the alignment with the oracle.
Browse files Browse the repository at this point in the history
Otherwise it's not very obvious that the range-based for loop iterates
over the same sequence as the subset vector used in the oracle.
  • Loading branch information
LTLA committed Nov 14, 2024
1 parent 9eeb6d1 commit 55c2f3d
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions include/scran_aggregate/aggregate_across_genes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void compute_aggregate_by_row(
// Identifying the subset of rows that actually need to be extracted.
auto subset = create_subset<Index_>(gene_sets);
size_t nsubs = subset.size();
auto sub_oracle = std::make_shared<tatami::FixedViewOracle<Index_> >(subset.data(), subset.size());
auto sub_oracle = std::make_shared<tatami::FixedViewOracle<Index_> >(subset.data(), nsubs);

const size_t num_sets = gene_sets.size();
std::vector<std::vector<std::pair<size_t, Weight_> > > remapping(nsubs);
Expand Down Expand Up @@ -196,13 +196,15 @@ void compute_aggregate_by_row(
std::vector<Data_> vbuffer(length);
std::vector<Index_> ibuffer(length);

for (const auto& sets : remapping) {
for (size_t sub = 0; sub < nsubs; ++sub) {
auto range = ext->fetch(vbuffer.data(), ibuffer.data());
const auto& sets = remapping[sub];

for (Index_ c = 0; c < range.number; ++c) {
auto cell = range.index[c];
auto val = range.value[c];
for (const auto& s : sets) {
buffers.sum[s.first][cell] += val * s.second;
for (const auto& sw : sets) {
buffers.sum[sw.first][cell] += val * sw.second;
}
}
}
Expand All @@ -213,13 +215,15 @@ void compute_aggregate_by_row(
auto ext = tatami::new_extractor<false, true>(&p, true, sub_oracle, start, length);
std::vector<Data_> vbuffer(length);

for (const auto& sets : remapping) {
for (size_t sub = 0; sub < nsubs; ++sub) {
auto ptr = ext->fetch(vbuffer.data());
const auto& sets = remapping[sub];

for (Index_ cell = 0; cell < length; ++cell) {
auto val = ptr[cell];
size_t pos = cell + start;
for (const auto& s : sets) {
buffers.sum[s.first][pos] += val * s.second;
for (const auto& sw : sets) {
buffers.sum[sw.first][pos] += val * sw.second;
}
}
}
Expand Down

0 comments on commit 55c2f3d

Please sign in to comment.