Skip to content

Commit

Permalink
add GSL::RNG::ran_shuffle_1d
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Aug 8, 2024
1 parent 40c26d8 commit adbb918
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -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
Expand Down
26 changes: 25 additions & 1 deletion Libtmp/GSL/RNG/gsl_random.pd
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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'],
Expand Down
4 changes: 4 additions & 0 deletions Libtmp/GSL/RNG/t/gsl_rng.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit adbb918

Please sign in to comment.