stan-dev / stan-dev/math

integer parameters/variates can take real values in density/mass functions

Open
#1,696 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

code cleanup doc
Dominant language
C++
Stars
839
Forks
220
Avg merge
2d 4h
Merged PRs (30d)
14

Description

Description

Functions such as binomial_lpmf never check that their size (N) and number of success (n) parameters have integer value types. This also applies to hypergeometric_lpmf and others.

As written, they'll merrily accept real values and return nonsensical results.

In the past, we've just assumed nobody would call them with real values because we define the acceptable signatures in the Stan language.

It would be better to enforce integer base value types for these arguments. This can be done with something like the following template parameter to ensure all of T1, T2, and T3 have integer value types:

typename = std::enable_if_t<std::is_integral<scalar_type_t<T1>>::value
                            && std::is_integral<scalar_type_t<T2>>::value
                            && std::is_integral<scalar_type_t<T3>>::value>

The doc also needs to indicate this won't work. I don't know a good way to test that integer instantiations don't compile.

Current Version:

v3.1.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the binomial_lpmf and hypergeometric_lpmf entry points and inspect their template signatures and documentation, then identify the other probability functions with the same issue. Done means integer-valued parameters remain supported, real-valued arguments are rejected, and the documentation states this restriction.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend-api-design, documentation, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.