Skip to content

Commit

Permalink
Avoid unnecessary copies when returning const references from IIFEs.
Browse files Browse the repository at this point in the history
Also write out the full form of lambdas and the canonical form for
(return-by-value) IIFEs to avoid confusion.
  • Loading branch information
LTLA committed Feb 13, 2025
1 parent 07089f8 commit bdeff33
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion include/scran_pca/blocked_pca.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ class ResidualWrapper {

template<class Right_>
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<Right_, EigenVector_>::value) {
return rhs;
} else {
Expand Down
4 changes: 2 additions & 2 deletions include/scran_pca/simple_pca.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void compute_row_means_and_variances(const tatami::Matrix<Value_, Index_>& mat,
std::vector<Value_> 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);
Expand All @@ -111,7 +111,7 @@ void compute_row_means_and_variances(const tatami::Matrix<Value_, Index_>& mat,
tatami_stats::LocalOutputBuffer<Scalar> cbuffer(t, start, length, center_v.data());
tatami_stats::LocalOutputBuffer<Scalar> sbuffer(t, start, length, scale_v.data());

auto running = [&]() {
auto running = [&]{
if constexpr(sparse_) {
return tatami_stats::variances::RunningSparse<Scalar, Value_, Index_>(length, cbuffer.data(), sbuffer.data(), /* skip_nan = */ false, /* subtract = */ start);
} else {
Expand Down
4 changes: 2 additions & 2 deletions include/scran_pca/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class TransposedTatamiWrapper {
private:
template<class Right_>
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<Right_, EigenVector_>::value) {
return rhs;
} else {
Expand All @@ -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) {
Expand Down

0 comments on commit bdeff33

Please sign in to comment.