stan-dev / math

The Stan Math Library is a C++ template library for automatic differentiation of any order using forward, reverse, and mixed modes. It includes a range of built-in functions for probabilistic modeling, linear algebra, and equation solving.
https://mc-stan.org
BSD 3-Clause "New" or "Revised" License
754 stars 188 forks source link

log_mix(container, container) should check first argument is simplex #3125

Open bob-carpenter opened 3 days ago

bob-carpenter commented 3 days ago

Description

The function log_mix taking two collections does not check that the first container is a simplex.

Expected Output

Rejection when the first argument is not a simplex, e.g.,

target += log_mix({0.5, 0.9}, {-1.2, -4.2});

Current Version:

v4.9.0

WardBrian commented 3 days ago

If I had to theorize as to why it does not, it seems like check_simplex might not have overloads for non-Eigen containers: https://github.com/stan-dev/math/blob/develop/stan/math/prim/err/check_simplex.hpp

So that's a good place to start