From fe2d7accd5d4143d848d74de1fd9d4348c3cf68c Mon Sep 17 00:00:00 2001 From: Samaresh Kumar Singh Date: Fri, 17 Apr 2026 20:43:30 -0500 Subject: [PATCH] Fix poisson and geometric missing default for template parameter T --- include/xtensor/generators/xrandom.hpp | 8 ++++---- test/test_xrandom.cpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/xtensor/generators/xrandom.hpp b/include/xtensor/generators/xrandom.hpp index d43a69876..73b1763ae 100644 --- a/include/xtensor/generators/xrandom.hpp +++ b/include/xtensor/generators/xrandom.hpp @@ -63,14 +63,14 @@ namespace xt auto binomial(const S& shape, T trials = 1, D prob = 0.5, E& engine = random::get_default_random_engine()); - template + template auto geometric(const S& shape, D prob = 0.5, E& engine = random::get_default_random_engine()); template auto negative_binomial(const S& shape, T k = 1, D prob = 0.5, E& engine = random::get_default_random_engine()); - template + template auto poisson(const S& shape, D rate = 1.0, E& engine = random::get_default_random_engine()); template @@ -123,7 +123,7 @@ namespace xt auto binomial(const I (&shape)[L], T trials = 1, D prob = 0.5, E& engine = random::get_default_random_engine()); - template + template auto geometric(const I (&shape)[L], D prob = 0.5, E& engine = random::get_default_random_engine()); template @@ -134,7 +134,7 @@ namespace xt E& engine = random::get_default_random_engine() ); - template + template auto poisson(const I (&shape)[L], D rate = 1.0, E& engine = random::get_default_random_engine()); template diff --git a/test/test_xrandom.cpp b/test/test_xrandom.cpp index c732e2ab4..0d824a794 100644 --- a/test/test_xrandom.cpp +++ b/test/test_xrandom.cpp @@ -237,6 +237,20 @@ namespace xt #endif } + TEST(xrandom, poisson_geometric_default_type) + { + // poisson and geometric have no parameter from which T can be deduced, + // so they require a default T (= int) to be callable without explicit template arg. + auto p = random::poisson({3, 3}, 1.0); + static_assert(std::is_same::value, "poisson default T must be int"); + + auto g = random::geometric({3, 3}, 0.5); + static_assert(std::is_same::value, "geometric default T must be int"); + + auto p2 = random::poisson({3, 3}); + static_assert(std::is_same::value, "poisson default T must be int"); + } + TEST(xrandom, permutation) { xt::random::seed(123);