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
723 stars 183 forks source link

Inconsistent type used for size of containers #3085

Closed WardBrian closed 1 week ago

WardBrian commented 1 week ago

Description

The various functions in the Math library that deal with sizes of containers return different types than each other:

In particular, size_t is problematic because it is an unsized type, which leads to bad semantics when the result is used in a mathematical expression as seen in this forum post

We should probably use the same type for all of these functions. Because int is what is used in the language, that seems like a reasonable choice. If we're worried about internal overflows, we should at least used a signed type like ssize_t/long int, rather than size_t

Current Version:

v4.9.0