Skip to content

Commit

Permalink
test, error-check dog - #421
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Sep 13, 2024
1 parent 1c54204 commit 0b961e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Basic/Core/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3645,6 +3645,8 @@ The output ndarrays are set bad if the original ndarray has its bad flag set.
sub PDL::dog {
my $opt = ref($_[-1]) eq 'HASH' ? pop @_ : {};
my $p = shift;
barf "Usage: \$pdl->dog([\\%opt])" if @_;
barf "dog: must have at least one dim\n" if !$p->ndims;
my $s = ":,"x($p->getndims-1);
my @res = map $p->slice($s."(".$_.")"), 0..$p->dim(-1)-1;
$$opt{Break} ? map $_->copy, @res : @res
Expand Down
10 changes: 8 additions & 2 deletions t/core.t
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,16 @@ my ($dogcopy) = $c2->dog({Break=>1});
$dogcopy++;
ok all($dogcopy != $c2->slice(':,(0)')), 'Break means copy'; # not lo as cat no flow
my ($dogslice) = $c2->dog;
$dogslice->dump;
$lo->dump;
$dogslice++;
ok all($dogslice == $c2->slice(':,(0)')), 'no Break means dataflow' or diag "got=$dogslice\nexpected=$lo";
eval {pdl([3])->dog(5)};
like $@, qr/Usage/, "error if excess args";
for ([[], qr/at least/], [[5]], [[4,5]]) {
my ($dims, $err) = @$_;
my @d = eval {zeroes(@$dims)->dog};
like($@, $err, "right error (@$dims)"), next if $err;
is 0+@d, $dims->[-1], "works (@$dims)";
}

$x = sequence(byte,5);

Expand Down

0 comments on commit 0b961e8

Please sign in to comment.