diff --git a/stan/math/rev/core/arena_matrix.hpp b/stan/math/rev/core/arena_matrix.hpp index 64467e19a35..ed5ee3102ab 100644 --- a/stan/math/rev/core/arena_matrix.hpp +++ b/stan/math/rev/core/arena_matrix.hpp @@ -96,7 +96,8 @@ class arena_matrix : public Eigen::Map { auto other = make_chainable_ptr(plain_type_t(std::move(x))); // other has it's rows and cols swapped already if it needed that - return base_map_t(&(other->coeffRef(0)), other->rows(), other->cols()); + return base_map_t(&(other->coeffRef(0)), other->rows(), + other->cols()); } else { base_map_t map( ChainableStack::instance_->memalloc_.alloc_array( @@ -156,29 +157,28 @@ class arena_matrix : public Eigen::Map { template * = nullptr> arena_matrix& operator=(T&& a) { using T_t = std::decay_t; - if (std::is_rvalue_reference::value - && is_plain_type::value) { - // Note: plain_type_t here does nothing since T_t is plain type - auto other - = make_chainable_ptr(plain_type_t(std::move(a))); - new (this) Base(&(other->coeffRef(0)), other->rows(), other->cols()); - return *this; + if (std::is_rvalue_reference::value && is_plain_type::value) { + // Note: plain_type_t here does nothing since T_t is plain type + auto other = make_chainable_ptr(plain_type_t(std::move(a))); + new (this) Base(&(other->coeffRef(0)), other->rows(), other->cols()); + return *this; } else { - // do we need to transpose? - if ((RowsAtCompileTime == 1 && T_t::ColsAtCompileTime == 1) - || (ColsAtCompileTime == 1 && T_t::RowsAtCompileTime == 1)) { - // placement new changes what data map points to - there is no allocation - new (this) Base( - ChainableStack::instance_->memalloc_.alloc_array(a.size()), - a.cols(), a.rows()); - - } else { - new (this) Base( - ChainableStack::instance_->memalloc_.alloc_array(a.size()), - a.rows(), a.cols()); - } - Base::operator=(a); - return *this; + // do we need to transpose? + if ((RowsAtCompileTime == 1 && T_t::ColsAtCompileTime == 1) + || (ColsAtCompileTime == 1 && T_t::RowsAtCompileTime == 1)) { + // placement new changes what data map points to - there is no + // allocation + new (this) Base( + ChainableStack::instance_->memalloc_.alloc_array(a.size()), + a.cols(), a.rows()); + + } else { + new (this) Base( + ChainableStack::instance_->memalloc_.alloc_array(a.size()), + a.rows(), a.cols()); + } + Base::operator=(a); + return *this; } } }; diff --git a/test/unit/math/rev/fun/fill_test.cpp b/test/unit/math/rev/fun/fill_test.cpp index fa328aa0a68..7dae163c0f7 100644 --- a/test/unit/math/rev/fun/fill_test.cpp +++ b/test/unit/math/rev/fun/fill_test.cpp @@ -60,7 +60,8 @@ TEST_F(AgradRev, fillVarMatDouble) { using stan::math::fill; using stan::math::sum; using stan::math::var_value; - Matrix y_val = Matrix::Constant(3, 2.0); + Matrix y_val + = Matrix::Constant(3, 2.0); var_value> y(y_val); fill(y, 3.0); EXPECT_EQ(3, y.size()); @@ -79,7 +80,8 @@ TEST_F(AgradRev, fillVarMatVar) { using stan::math::sum; using stan::math::var; using stan::math::var_value; - Matrix y_val = Matrix::Constant(3, 2.0); + Matrix y_val + = Matrix::Constant(3, 2.0); var_value> y(y_val); var z(3.0); fill(y, z);