77#include < stan/math/rev/core/chainable_object.hpp>
88#include < stan/math/rev/core/var_value_fwd_declare.hpp>
99#include < stan/math/prim/fun/to_ref.hpp>
10-
1110namespace stan {
1211namespace math {
1312
@@ -269,8 +268,10 @@ class arena_matrix<MatrixType, require_eigen_sparse_base_t<MatrixType>>
269268 */
270269 arena_matrix (const arena_matrix<MatrixType>& other)
271270 : Base::Map(other.rows(), other.cols(), other.nonZeros(),
272- other.outerIndexPtr(), other.innerIndexPtr(),
273- other.valuePtr(), other.innernonZeroPtr()) {}
271+ const_cast<StorageIndex*>(other.outerIndexPtr()),
272+ const_cast<StorageIndex*>(other.innerIndexPtr()),
273+ const_cast<Scalar*>(other.valuePtr()),
274+ const_cast<StorageIndex*>(other.innerNonZeroPtr())) {}
274275 /* *
275276 * Move constructor.
276277 * @note Since the memory for the arena matrix sits in Stan's memory arena all
@@ -279,8 +280,10 @@ class arena_matrix<MatrixType, require_eigen_sparse_base_t<MatrixType>>
279280 */
280281 arena_matrix (arena_matrix<MatrixType>&& other)
281282 : Base::Map(other.rows(), other.cols(), other.nonZeros(),
282- other.outerIndexPtr(), other.innerIndexPtr(),
283- other.valuePtr(), other.innerNonZeroPtr()) {}
283+ const_cast<StorageIndex*>(other.outerIndexPtr()),
284+ const_cast<StorageIndex*>(other.innerIndexPtr()),
285+ const_cast<Scalar*>(other.valuePtr()),
286+ const_cast<StorageIndex*>(other.innerNonZeroPtr())) {}
284287 /* *
285288 * Copy constructor. No actual copy is performed
286289 * @note Since the memory for the arena matrix sits in Stan's memory arena all
@@ -289,8 +292,10 @@ class arena_matrix<MatrixType, require_eigen_sparse_base_t<MatrixType>>
289292 */
290293 arena_matrix (arena_matrix<MatrixType>& other)
291294 : Base::Map(other.rows(), other.cols(), other.nonZeros(),
292- other.outerIndexPtr(), other.innerIndexPtr(),
293- other.valuePtr(), other.innerNonZeroPtr()) {}
295+ const_cast<StorageIndex*>(other.outerIndexPtr()),
296+ const_cast<StorageIndex*>(other.innerIndexPtr()),
297+ const_cast<Scalar*>(other.valuePtr()),
298+ const_cast<StorageIndex*>(other.innerNonZeroPtr())) {}
294299
295300 // without this using, compiler prefers combination of implicit construction
296301 // and copy assignment to the inherited operator when assigned an expression
@@ -303,7 +308,8 @@ class arena_matrix<MatrixType, require_eigen_sparse_base_t<MatrixType>>
303308 * @return `*this`
304309 */
305310 template <typename ArenaMatrix,
306- require_same_t <ArenaMatrix, arena_matrix<MatrixType>>* = nullptr >
311+ require_same_t <std::decay_t <ArenaMatrix>,
312+ arena_matrix<MatrixType>>* = nullptr >
307313 arena_matrix& operator =(ArenaMatrix&& other) {
308314 // placement new changes what data map points to - there is no allocation
309315 new (this ) Base (other.rows (), other.cols (), other.nonZeros (),
@@ -324,7 +330,7 @@ class arena_matrix<MatrixType, require_eigen_sparse_base_t<MatrixType>>
324330 template <typename Expr,
325331 require_not_same_t <Expr, arena_matrix<MatrixType>>* = nullptr >
326332 arena_matrix& operator =(Expr&& expr) {
327- * this = arena_matrix (std::forward<Expr>(expr));
333+ new ( this ) arena_matrix (std::forward<Expr>(expr));
328334 return *this ;
329335 }
330336
0 commit comments