Skip to content

Commit

Permalink
fixing Issue #105 on hydra::fill_random
Browse files Browse the repository at this point in the history
  • Loading branch information
AAAlvesJr committed Oct 23, 2020
1 parent 6871e54 commit ccc2757
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
13 changes: 7 additions & 6 deletions examples/random/fill_basic_distributions.inl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int main(int argv, char** argc)
}


auto data_d = hydra::device::vector<double>(nentries);
auto data_d = hydra::device::vector<xvar>(nentries);



Expand Down Expand Up @@ -164,10 +164,11 @@ int main(int argv, char** argc)

hydra::fill_random(data_d , gauss);

/*
std::cout << std::endl<< "Generated data:"<< std::endl;
for(size_t i=0; i<10; ++i)
std::cout << "[" << i << "] :" << data_d[i] << std::endl;

*/

#ifdef _ROOT_AVAILABLE_

Expand All @@ -186,7 +187,7 @@ int main(int argv, char** argc)

// copying the values in the host and fill the ROOT histogram

auto data_h = hydra::host::vector<double>(nentries);
auto data_h = hydra::host::vector<xvar>(nentries);

hydra::copy(data_d , data_h);

Expand All @@ -197,11 +198,11 @@ int main(int argv, char** argc)
// filling the container in the device
// and copy back to the host also for the
// other functors

/*
hydra::fill_random(data_d , lognormal);
hydra::copy(data_d , data_h);
for(auto x : data_h) hist_lognormal.Fill( x );
hydra::fill_random(data_d , bigauss);
hydra::copy(data_d , data_h);
for(auto x : data_h) hist_bigauss.Fill( x );
Expand Down Expand Up @@ -233,7 +234,7 @@ int main(int argv, char** argc)
hydra::fill_random(data_d , trapezoid);
hydra::copy(data_d , data_h);
for(auto x : data_h) hist_trapezoid.Fill( x );

*/


TApplication *myapp=new TApplication("myapp",0,0);
Expand Down
31 changes: 18 additions & 13 deletions hydra/Random.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ struct is_iterable: std::conditional<

template<typename T>
struct is_callable: std::conditional<

(hydra::detail::is_hydra_composite_functor<T>::value ||
hydra::detail::is_hydra_functor<T>::value ||
hydra::detail::is_hydra_lambda<T>::value ) &&
Expand All @@ -97,6 +96,19 @@ struct is_callable: std::conditional<
std::true_type,
std::false_type >::type {};

template< typename Engine, typename Functor, typename Iterable>
struct is_matching_iterable: std::conditional<
hydra::detail::is_iterable<Iterable>::value &&
!hydra::detail::is_iterator<Iterable>::value &&
(hydra::detail::is_hydra_composite_functor<Functor>::value ||
hydra::detail::is_hydra_functor<Functor>::value ||
hydra::detail::is_hydra_lambda<Functor>::value ) &&
hydra::detail::has_rng_formula<Functor>::value &&
std::is_convertible<
decltype(std::declval<RngFormula<Functor>>().Generate( std::declval<Engine&>(), std::declval<Functor const&>())),
typename hydra_thrust::iterator_traits<decltype(std::declval<Iterable>().begin())>::value_type>::value,
std::true_type, std::false_type
>::type{};
} // namespace random

} // namespace detail
Expand Down Expand Up @@ -576,9 +588,7 @@ fill_random(Iterator begin, Iterator end, FUNCTOR const& functor, size_t seed=0x
* @param rng_jump sequence offset for the underlying pseudo-random number generator
*/
template< typename Engine = hydra::default_random_engine, hydra::detail::Backend BACKEND, typename Iterable, typename FUNCTOR >
typename std::enable_if< hydra::detail::is_iterable<Iterable>::value && std::is_convertible<
decltype(*std::declval<Iterable>().begin()), typename FUNCTOR::return_type
>::value, void>::type
typename std::enable_if< detail::random::is_matching_iterable<Engine, FUNCTOR, Iterable>::value, void>::type
fill_random(hydra::detail::BackendPolicy<BACKEND> const& policy,
Iterable&& iterable, FUNCTOR const& functor, size_t seed=0x254a0afcf7da74a2, size_t rng_jump=0 );

Expand All @@ -593,9 +603,8 @@ fill_random(hydra::detail::BackendPolicy<BACKEND> const& policy,
* @param rng_jump sequence offset for the underlying pseudo-random number generator
*/
template< typename Engine = hydra::default_random_engine, typename Iterable, typename FUNCTOR >
typename std::enable_if< hydra::detail::is_iterable<Iterable>::value && std::is_convertible<
decltype(*std::declval<Iterable>().begin()), typename FUNCTOR::return_type
>::value, void>::type
typename std::enable_if< detail::random::is_matching_iterable<Engine, FUNCTOR, Iterable>::value,
void>::type
fill_random(Iterable&& iterable, FUNCTOR const& functor, size_t seed=0x254a0afcf7da74a2, size_t rng_jump=0 );

/**
Expand Down Expand Up @@ -680,9 +689,7 @@ fill_random(Iterator begin, Iterator end, FUNCTOR const& functor, size_t seed=0x
* @param rng_jump sequence offset for the underlying pseudo-random number generator
*/
template< typename Engine = hydra::default_random_engine, hydra::detail::Backend BACKEND, typename Iterable, typename FUNCTOR >
typename std::enable_if< !hydra::detail::is_iterable<Iterable>::value || !std::is_convertible<
decltype(*std::declval<Iterable>().begin()), typename FUNCTOR::return_type
>::value, void>::type
typename std::enable_if< !(detail::random::is_matching_iterable<Engine, FUNCTOR, Iterable>::value), void>::type
fill_random(hydra::detail::BackendPolicy<BACKEND> const& policy,
Iterable&& iterable, FUNCTOR const& functor, size_t seed=0x254a0afcf7da74a2, size_t rng_jump=0 );

Expand All @@ -697,9 +704,7 @@ fill_random(hydra::detail::BackendPolicy<BACKEND> const& policy,
* @param rng_jump sequence offset for the underlying pseudo-random number generator
*/
template< typename Engine = hydra::default_random_engine, typename Iterable, typename FUNCTOR >
typename std::enable_if< !hydra::detail::is_iterable<Iterable>::value || !std::is_convertible<
decltype(*std::declval<Iterable>().begin()), typename FUNCTOR::return_type
>::value, void>::type
typename std::enable_if<!(detail::random::is_matching_iterable<Engine, FUNCTOR, Iterable>::value),void>::type
fill_random(Iterable&& iterable, FUNCTOR const& functor, size_t seed=0x254a0afcf7da74a2, size_t rng_jump=0 );


Expand Down
17 changes: 5 additions & 12 deletions hydra/detail/RandomFill.inl
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ namespace hydra{
* @param functor distribution to be sampled
*/
template< typename Engine, hydra::detail::Backend BACKEND, typename Iterable, typename FUNCTOR >
typename std::enable_if< hydra::detail::is_iterable<Iterable>::value && std::is_convertible<
decltype(*std::declval<Iterable>().begin()), typename FUNCTOR::return_type
>::value, void>::type
typename std::enable_if< detail::random::is_matching_iterable<Engine, FUNCTOR, Iterable>::value, void>::type
fill_random(hydra::detail::BackendPolicy<BACKEND> const& policy,
Iterable&& iterable, FUNCTOR const& functor, size_t seed, size_t rng_jump){

Expand All @@ -112,9 +110,8 @@ namespace hydra{
* @param functor distribution to be sampled
*/
template< typename Engine, typename Iterable, typename FUNCTOR >
typename std::enable_if< hydra::detail::is_iterable<Iterable>::value && std::is_convertible<
decltype(*std::declval<Iterable>().begin()), typename FUNCTOR::return_type
>::value, void>::type
typename std::enable_if< detail::random::is_matching_iterable<Engine, FUNCTOR, Iterable>::value,
void>::type
fill_random(Iterable&& iterable, FUNCTOR const& functor, size_t seed, size_t rng_jump){

fill_random(std::forward<Iterable>(iterable).begin(),
Expand Down Expand Up @@ -186,9 +183,7 @@ namespace hydra{
* @brief Fall back function if the argument is not an Iterable or if it is not convertible to the Functor return value
*/
template< typename Engine, hydra::detail::Backend BACKEND, typename Iterable, typename FUNCTOR >
typename std::enable_if< !hydra::detail::is_iterable<Iterable>::value || !std::is_convertible<
decltype(*std::declval<Iterable>().begin()), typename FUNCTOR::return_type
>::value, void>::type
typename std::enable_if< !(detail::random::is_matching_iterable<Engine, FUNCTOR, Iterable>::value), void>::type
fill_random(hydra::detail::BackendPolicy<BACKEND> const& policy,
Iterable&& iterable, FUNCTOR const& functor, size_t seed, size_t rng_jump)
{
Expand All @@ -202,9 +197,7 @@ namespace hydra{
* @brief Fall back function if the argument is not an Iterable or if it is not convertible to the Functor return value
*/
template< typename Engine, typename Iterable, typename FUNCTOR >
typename std::enable_if< !hydra::detail::is_iterable<Iterable>::value || !std::is_convertible<
decltype(*std::declval<Iterable>().begin()), typename FUNCTOR::return_type
>::value, void>::type
typename std::enable_if<!detail::random::is_matching_iterable<Engine, FUNCTOR, Iterable>::value, void>::type
fill_random(Iterable&& iterable, FUNCTOR const& functor, size_t seed, size_t rng_jump)
{
HYDRA_STATIC_ASSERT( int(std::is_class<Engine>::value) ==-1 ,
Expand Down

0 comments on commit ccc2757

Please sign in to comment.