Skip to content

Commit f3b3286

Browse files
author
Andrew Johnson
committed
Address comments
1 parent 1fce5ac commit f3b3286

File tree

8 files changed

+10
-10
lines changed

8 files changed

+10
-10
lines changed

stan/math/fwd/fun/log_softmax.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace math {
2222
*/
2323
template <typename T, require_t<is_fvar<scalar_type_t<T>>>...>
2424
inline auto log_softmax(const T& x) {
25-
return apply_vector_unary<T>::apply(x, [&](auto& alpha) {
25+
return apply_vector_unary<T>::apply(x, [&](const auto& alpha) {
2626
using T_fvar = value_type_t<decltype(alpha)>;
2727
using T_fvar_inner = typename T_fvar::Scalar;
2828

stan/math/fwd/fun/log_sum_exp.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ inline fvar<T> log_sum_exp(const fvar<T>& x1, double x2) {
5252
*/
5353
template <typename T, require_t<is_fvar<scalar_type_t<T>>>...>
5454
inline auto log_sum_exp(const T& x) {
55-
return apply_vector_unary<T>::reduce(x, [&](auto& v) {
55+
return apply_vector_unary<T>::reduce(x, [&](const auto& v) {
5656
using T_fvar_inner = typename value_type_t<decltype(v)>::Scalar;
5757
using mat_type = Eigen::Matrix<T_fvar_inner, -1, -1>;
5858
mat_type vals = v.val();

stan/math/prim/fun/log_softmax.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace math {
3939
*/
4040
template <typename T, require_t<std::is_arithmetic<scalar_type_t<T>>>...>
4141
inline auto log_softmax(const T& x) {
42-
return apply_vector_unary<T>::apply(x, [&](auto& v) {
42+
return apply_vector_unary<T>::apply(x, [&](const auto& v) {
4343
check_nonzero_size("log_softmax", "v", v);
4444
return (v.array() - log_sum_exp(v)).matrix();
4545
});

stan/math/prim/fun/log_sum_exp.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ inline return_type_t<T1, T2> log_sum_exp(const T2& a, const T1& b) {
7878
*/
7979
template <typename T, require_t<std::is_arithmetic<scalar_type_t<T>>>...>
8080
inline auto log_sum_exp(const T& x) {
81-
return apply_vector_unary<T>::reduce(x, [&](auto& v) {
81+
return apply_vector_unary<T>::reduce(x, [&](const auto& v) {
8282
if (v.size() == 0) {
8383
return NEGATIVE_INFTY;
8484
}

stan/math/prim/vectorize/apply_vector_unary.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef STAN_MATH_PRIM_VECTORIZE_APPLY_VECTOR_UNARY_HPP
22
#define STAN_MATH_PRIM_VECTORIZE_APPLY_VECTOR_UNARY_HPP
33

4-
#include <stan/math/prim/mat/fun/Eigen.hpp>
4+
#include <stan/math/prim/fun/Eigen.hpp>
55
#include <stan/math/prim/meta.hpp>
66
#include <vector>
77

stan/math/rev/core/matrix_vari.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class op_matrix_vari : public vari {
1717

1818
public:
1919
template <typename T, require_eigen_vt<is_var, T>...>
20-
op_matrix_vari(double f, T&& vs) : vari(f), size_(vs.size()) {
20+
op_matrix_vari(double f, const T& vs) : vari(f), size_(vs.size()) {
2121
vis_ = ChainableStack::instance_->memalloc_.alloc_array<vari*>(size_);
2222
Eigen::Map<Eigen::Matrix<vari*, -1, -1>>(vis_, vs.rows(), vs.cols())
2323
= vs.vi();

stan/math/rev/fun/log_softmax.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class log_softmax_elt_vari : public vari {
5757
*/
5858
template <typename T, require_t<is_var<scalar_type_t<T>>>...>
5959
inline auto log_softmax(const T& x) {
60-
return apply_vector_unary<T>::apply(x, [&](auto& alpha) {
60+
return apply_vector_unary<T>::apply(x, [&](const auto& alpha) {
6161
const int a_size = alpha.size();
6262

6363
check_nonzero_size("log_softmax", "alpha", alpha);

stan/math/rev/fun/log_sum_exp.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ namespace internal {
6565
class log_sum_exp_matrix_vari : public op_matrix_vari {
6666
public:
6767
template <typename T>
68-
explicit log_sum_exp_matrix_vari(T&& x)
69-
: op_matrix_vari(log_sum_exp(x.val()), std::forward<T>(x)) {}
68+
explicit log_sum_exp_matrix_vari(const T& x)
69+
: op_matrix_vari(log_sum_exp(x.val()), x) {}
7070
void chain() {
7171
Eigen::Map<vector_vi> vis_map(vis_, size_);
7272
vis_map.adj().array() += adj_ * (vis_map.val().array() - val_).exp();
@@ -82,7 +82,7 @@ class log_sum_exp_matrix_vari : public op_matrix_vari {
8282
*/
8383
template <typename T, require_t<is_var<scalar_type_t<T>>>...>
8484
inline auto log_sum_exp(const T& x) {
85-
return apply_vector_unary<T>::reduce(x, [&](auto& v) {
85+
return apply_vector_unary<T>::reduce(x, [&](const auto& v) {
8686
return var(new internal::log_sum_exp_matrix_vari(v));
8787
});
8888
}

0 commit comments

Comments
 (0)