<commit_before>#ifndef STAN__MATH__PRIM__SCAL__PROB__HYPERGEOMETRIC_RNG_HPP
#define STAN__MATH__PRIM__SCAL__PROB__HYPERGEOMETRIC_RNG_HPP

#include <vector>
#include <boost/math/distributions.hpp>
#include <stan/math/prim/scal/err/check_consistent_sizes.hpp>
#include <stan/math/prim/scal/err/check_bounded.hpp>
#include <stan/math/prim/scal/err/check_finite.hpp>
#include <stan/math/prim/scal/err/check_greater.hpp>
#include <stan/math/prim/scal/err/check_positive.hpp>
#include <stan/math/prim/scal/fun/binomial_coefficient_log.hpp>
#include <stan/math/prim/scal/meta/length.hpp>
#include <stan/math/prim/scal/meta/is_constant_struct.hpp>
#include <stan/math/prim/scal/meta/VectorView.hpp>
#include <stan/math/prim/scal/meta/VectorBuilder.hpp>
#include <stan/math/prim/scal/meta/partials_return_type.hpp>
#include <stan/math/prim/scal/meta/return_type.hpp>
#include <stan/math/prim/scal/meta/include_summand.hpp>
#include <stan/math/prim/scal/meta/constants.hpp>
#include <stan/math/prim/scal/prob/uniform_rng.hpp>

namespace stan {

  namespace prob {

    template <class RNG>
    inline int
    hypergeometric_rng(const int N,
                       const int a,
                       const int b,
                       RNG& rng) {
      using boost::variate_generator;
      
      static const char* function("stan::prob::hypergeometric_rng");

      using stan::math::check_bounded;
      using stan::math::check_positive;

      check_bounded(function, "Draws parameter", N, 0, a+b);
      check_positive(function, "Draws parameter", N);
      check_positive(function, "Successes in population parameter", a);
      check_positive(function, "Failures in population parameter", b);

      boost::math::hypergeometric_distribution<>dist (b, N, a + b);
      std::vector<double> index(a);
      for(int i = 0; i < a; i++)
        index[i] = cdf(dist, i + 1);

      double c = uniform_rng(0.0, 1.0, rng);
      int min = 0;
      int max = a - 1;
      int mid = 0;
      while (min < max) {
        mid = (min + max) / 2;
        if(index[mid] > c)
          max = mid;
        else
          min = mid + 1;
      }
      return min + 1;
    }
  }
}
#endif
<commit_msg>cleaned hypergeometric_rng includes and removed vector use<commit_after>#ifndef STAN__MATH__PRIM__SCAL__PROB__HYPERGEOMETRIC_RNG_HPP
#define STAN__MATH__PRIM__SCAL__PROB__HYPERGEOMETRIC_RNG_HPP

#include <boost/math/distributions/hypergeometric.hpp>

#include <stan/math/prim/scal/err/check_bounded.hpp>
#include <stan/math/prim/scal/err/check_positive.hpp>
#include <stan/math/prim/scal/prob/uniform_rng.hpp>

namespace stan {

  namespace prob {

    template <class RNG>
    inline int
    hypergeometric_rng(int N, int a, int b, RNG& rng) {
      using boost::variate_generator;
      using boost::math::hypergeometric_distribution;
      using stan::math::check_bounded;
      using stan::math::check_positive;

      static const char* function("stan::prob::hypergeometric_rng");

      check_bounded(function, "Draws parameter", N, 0, a+b);
      check_positive(function, "Draws parameter", N);
      check_positive(function, "Successes in population parameter", a);
      check_positive(function, "Failures in population parameter", b);

      hypergeometric_distribution<> dist(b, N, a + b);

      double u = uniform_rng(0.0, 1.0, rng);
      int min = 0;
      int max = a - 1;
      while (min < max) {
        int mid = (min + max) / 2;
        if (cdf(dist,mid + 1) > u)
          max = mid;
        else
          min = mid + 1;
      }
      return min + 1;
    }

  }

}

#endif

{'fraction_non_alphanumeric': 0.12594458438287154, 'fraction_numerical': 0.006717044500419815, 'mean_word_length': 3.160651920838184, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6955197', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1226, 'n_words': 249}