From bdeff33405b22b59e921211fd7925591c726cab8 Mon Sep 17 00:00:00 2001 From: LTLA Date: Thu, 13 Feb 2025 10:01:20 -0800 Subject: [PATCH] Avoid unnecessary copies when returning const references from IIFEs. Also write out the full form of lambdas and the canonical form for (return-by-value) IIFEs to avoid confusion. --- CMakeLists.txt | 2 +- include/scran_pca/blocked_pca.hpp | 2 +- include/scran_pca/simple_pca.hpp | 4 ++-- include/scran_pca/utils.hpp | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c829695..02a431a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.14) project(scran_pca - VERSION 0.1.1 + VERSION 0.1.2 DESCRIPTION "Principal components analysis for single-cell data" LANGUAGES CXX) diff --git a/include/scran_pca/blocked_pca.hpp b/include/scran_pca/blocked_pca.hpp index 9fb2768..cb1db1c 100644 --- a/include/scran_pca/blocked_pca.hpp +++ b/include/scran_pca/blocked_pca.hpp @@ -670,7 +670,7 @@ class ResidualWrapper { template void multiply(const Right_& rhs, Workspace& work, EigenVector_& output) const { - const auto& realized_rhs = [&]() { + const auto& realized_rhs = [&]() -> const auto& { if constexpr(std::is_same::value) { return rhs; } else { diff --git a/include/scran_pca/simple_pca.hpp b/include/scran_pca/simple_pca.hpp index 9137425..85c0697 100644 --- a/include/scran_pca/simple_pca.hpp +++ b/include/scran_pca/simple_pca.hpp @@ -87,7 +87,7 @@ void compute_row_means_and_variances(const tatami::Matrix& mat, std::vector vbuffer(ncells); for (Index_ r = start, end = start + length; r < end; ++r) { - auto results = [&]() { + auto results = [&]{ if constexpr(sparse_) { auto range = ext->fetch(vbuffer.data(), NULL); return tatami_stats::variances::direct(range.value, range.number, ncells, /* skip_nan = */ false); @@ -111,7 +111,7 @@ void compute_row_means_and_variances(const tatami::Matrix& mat, tatami_stats::LocalOutputBuffer cbuffer(t, start, length, center_v.data()); tatami_stats::LocalOutputBuffer sbuffer(t, start, length, scale_v.data()); - auto running = [&]() { + auto running = [&]{ if constexpr(sparse_) { return tatami_stats::variances::RunningSparse(length, cbuffer.data(), sbuffer.data(), /* skip_nan = */ false, /* subtract = */ start); } else { diff --git a/include/scran_pca/utils.hpp b/include/scran_pca/utils.hpp index dc75fc5..b8ce193 100644 --- a/include/scran_pca/utils.hpp +++ b/include/scran_pca/utils.hpp @@ -95,7 +95,7 @@ class TransposedTatamiWrapper { private: template void inner_multiply(const Right_& rhs, bool transposed, Workspace& work, EigenVector_& out) const { - const auto& realized_rhs = [&]() { + const auto& realized_rhs = [&]() -> const auto& { if constexpr(std::is_same::value) { return rhs; } else { @@ -107,7 +107,7 @@ class TransposedTatamiWrapper { auto resultdim = (transposed ? my_ncol : my_nrow); auto otherdim = (transposed ? my_nrow : my_ncol); - tatami::parallelize([&](size_t t, Index_ start, Index_ length) { + tatami::parallelize([&](size_t t, Index_ start, Index_ length) -> void { auto& vbuffer = work.vbuffers[t]; if (my_prefer_rows != transposed) {