Skip to content

xt::random::poisson() function parameters do not include the template parameters #2884

@fsibley-necara

Description

@fsibley-necara

I am trying to create an xt::xarray using the xt::random::poisson() function and have encountered an issue with the templating.

I was able to create a desired array using xt::random::rand() as follows

xt::xarray<int64_t> randA = xt::random::rand({numElems}, lowerBound, upperBound);

However, a call to xt::random::poisson() always fails. The following two blocks of code are examples of how I have tried to call this function. I have varied the types and shapes several times just to be sure that I am not missing something.

xt::xarray<double> localData = xt::random::poisson({1024}, 0.01);

and

auto engine = xt::random::get_default_random_engine();
xt::xarray<double>::shape_type shape = {1};
xt::xarray<float> localData = xt::random::poisson(shape, 0.01, engine);

I see similar failures regardless of how I call this function, and the compiler hints that it is missing type T which is found in the template parameters but not in the function parameters.

/tmp/cust_base/library/testsuite/corr/SignalTests.cpp:85:58: error: no matching function for call to 'poisson(xt::xarray_container<xt::uvector<double, xsimd::aligned_allocator<double, 16> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>::shape_type&, double, std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>&)'
   85 |     xt::xarray<float> localData = xt::random::poisson(shape, 0.01, engine);
      |                                   ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
In file included from /tmp/cust_base/library/testsuite/corr/SignalTests.cpp:36:
/usr/include/xtensor/xrandom.hpp:415:21: note: candidate: 'template<class T, class S, class D, class E> auto xt::random::poisson(const S&, D, E&)'
  415 |         inline auto poisson(const S& shape, D rate, E& engine)
      |                     ^~~~~~~
/usr/include/xtensor/xrandom.hpp:415:21: note:   template argument deduction/substitution failed:
/tmp/cust_base/library/testsuite/corr/SignalTests.cpp:85:58: note:   couldn't deduce template parameter 'T'
   85 |     xt::xarray<float> localData = xt::random::poisson(shape, 0.01, engine);
      |                                   ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/xtensor/xrandom.hpp:683:21: note: candidate: 'template<class T, class I, long unsigned int L, class D, class E> auto xt::random::poisson(const I (&)[L], D, E&)'
  683 |         inline auto poisson(const I (&shape)[L], D rate, E& engine)
      |                     ^~~~~~~
/usr/include/xtensor/xrandom.hpp:683:21: note:   template argument deduction/substitution failed:
/tmp/cust_base/library/testsuite/corr/SignalTests.cpp:85:58: note:   mismatched types 'const I [L]' and 'xt::xarray_container<xt::uvector<double, xsimd::aligned_allocator<double, 16> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>::shape_type' {aka 'xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>'}
   85 |     xt::xarray<float> localData = xt::random::poisson(shape, 0.01, engine);
      |                                   ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~

Upon examination of xrandom.hpp, type T is missing from the parameters of poisson() whereas it is found in the parameters of other related functions.

        template <class T, class S, class D = double, class E = random::default_engine_type>
        auto
        negative_binomial(const S& shape, T k = 1, D prob = 0.5, E& engine = random::get_default_random_engine());

        template <class T, class S, class D = double, class E = random::default_engine_type>
        auto poisson(const S& shape, D rate = 1.0, E& engine = random::get_default_random_engine());

        template <class T, class S, class E = random::default_engine_type>
        auto exponential(const S& shape, T rate = 1.0, E& engine = random::get_default_random_engine());

Is there any way to call poisson() and not generate such an error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions