cherry-pick 50d0cb02c53f7b8a21264914cf2a3750eff394e5
cherry-pick 50d0cb02c53f7b8a21264914cf2a3750eff394e5

stan-dev/stan,stan-dev/math,stan-dev/math,stan-dev/math,stan-dev/math,stan-dev/stan,stan-dev/stan,stan-dev/stan,stan-dev/math,stan-dev/math,stan-dev/stan,stan-dev/math,stan-dev/math,stan-dev/math