From 55c2f3d1ed2ba2ed180d0e46f84425566bd8f06c Mon Sep 17 00:00:00 2001 From: LTLA Date: Wed, 13 Nov 2024 16:41:44 -0800 Subject: [PATCH] Refactor the loop to clarify the alignment with the oracle. 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. --- .../scran_aggregate/aggregate_across_genes.hpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/include/scran_aggregate/aggregate_across_genes.hpp b/include/scran_aggregate/aggregate_across_genes.hpp index 3698068..0794032 100644 --- a/include/scran_aggregate/aggregate_across_genes.hpp +++ b/include/scran_aggregate/aggregate_across_genes.hpp @@ -162,7 +162,7 @@ void compute_aggregate_by_row( // Identifying the subset of rows that actually need to be extracted. auto subset = create_subset(gene_sets); size_t nsubs = subset.size(); - auto sub_oracle = std::make_shared >(subset.data(), subset.size()); + auto sub_oracle = std::make_shared >(subset.data(), nsubs); const size_t num_sets = gene_sets.size(); std::vector > > remapping(nsubs); @@ -196,13 +196,15 @@ void compute_aggregate_by_row( std::vector vbuffer(length); std::vector 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; } } } @@ -213,13 +215,15 @@ void compute_aggregate_by_row( auto ext = tatami::new_extractor(&p, true, sub_oracle, start, length); std::vector 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; } } }