diff --git a/Changes b/Changes index 79edfd017..6c9fafaa9 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ - remove PDL_DATAFLOW_B entirely as meaningless (#485) - now an error to output to ndarray with inward but no backward dataflow (#485) - now slices etc with dataflow turn off backward dataflow if any input has inward-only dataflow (#485) +- add GSL::RNG::ran_shuffle_1d 2.089_02 2024-06-26 - PDL::VectorValued::vcos into Primitive - thanks @moocow-the-bovine diff --git a/Libtmp/GSL/RNG/gsl_random.pd b/Libtmp/GSL/RNG/gsl_random.pd index 5c0e5cca9..77ee93440 100644 --- a/Libtmp/GSL/RNG/gsl_random.pd +++ b/Libtmp/GSL/RNG/gsl_random.pd @@ -1,7 +1,7 @@ use strict; use warnings; -use PDL::Types qw(types); +use PDL::Types qw(types ppdefs_all); pp_bless('PDL::GSL::RNG'); # make the functions generated go into our namespace, and # not PDL's namespace @@ -444,6 +444,30 @@ sub pp_defnd { # hide the docs pp_def($name,%hash,Doc=>undef); } +pp_def('ran_shuffle_1d', + Pars => '[io]a(n)', + GenericTypes => [ppdefs_all()], + OtherPars => 'gsl_rng *rng', + Code => ' +gsl_ran_shuffle($COMP(rng), $P(a), $SIZE(n), sizeof($GENERIC())); +', + PMCode => <<'EOF', +sub ran_shuffle_1d { _ran_shuffle_1d_int(@_[1,0]) } +EOF + Doc => <<'EOF', +=for ref + +Takes n-dimensional ndarray, and shuffles it along its zero-th dimension. + +Usage: + +=for usage + + $vec2d = sequence(10,10); + $rng->ran_shuffle_1d($vec2d); +EOF +); + pp_def('get_uniform', Pars => '[o]a()', GenericTypes => ['F','D'], diff --git a/Libtmp/GSL/RNG/t/gsl_rng.t b/Libtmp/GSL/RNG/t/gsl_rng.t index 29998d59f..4b7cd6b42 100644 --- a/Libtmp/GSL/RNG/t/gsl_rng.t +++ b/Libtmp/GSL/RNG/t/gsl_rng.t @@ -131,4 +131,8 @@ my $vec2d = sequence(10,10); $rng->ran_shuffle($_) for $vec2d->dog; ok any($vec2d != sequence(10,10)), 'ran_shuffle() method'; +$vec2d = sequence(10,10); +$rng->ran_shuffle_1d($vec2d); +ok any($vec2d != sequence(10,10)), 'ran_shuffle_1d() method'; + done_testing;