Skip to content

Commit

Permalink
doc that unpdl of 0-dim ndarray returns array-ref
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Sep 10, 2024
1 parent c7e4f79 commit 598cd34
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
4 changes: 4 additions & 0 deletions Basic/Core/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3320,6 +3320,10 @@ C<unpdl> does not support this. However, it is suggested you would
generate an index-set with C<< $pdl->whereND($pdl == $PDL::undefval)
>>, then loop over the Perl data, setting those locations to C<undef>.
Another round-trip caveat: a zero-dimensional ndarray (a scalar) will be
returned as a single-element array-ref. This is conceptually incorrect,
but cannot now be changed due to backward compatibility.
=for example
use JSON;
Expand Down
3 changes: 0 additions & 3 deletions Basic/Core/Core.xs
Original file line number Diff line number Diff line change
Expand Up @@ -710,10 +710,7 @@ at_bad_c(x,pos)
OUTPUT:
RETVAL


# returns the string 'BAD' if an element is bad
#

SV *
listref_c(x)
pdl *x
Expand Down
20 changes: 10 additions & 10 deletions t/core.t
Original file line number Diff line number Diff line change
Expand Up @@ -531,16 +531,16 @@ like $@, qr/Position 2 at dimension 0 out of range/;
is $pb->at(-1,2), 5;
}

my $array = [
[[1,2],
[3,4]],
[[5,6],
[7,8]],
[[9,10],
[11,12]]
];
my $pdl = pdl $array;
is_deeply( unpdl($pdl), $array, "back convert 3d");
for my $array (
1,
[1..3],
[[[1,2], [3,4]], [[5,6], [7,8]], [[9,10], [11,12]]],
) {
my ($expected, $got) = ref $array ? $array : [$array]; # scalar not round-tripped right but back-compat
is_deeply $got = pdl($array)->unpdl, $expected,
"back convert ".join('', explain $array)
or diag explain $got;
}
SKIP: {
skip("your perl hasn't 64bit int support", 6) if $Config{ivsize} < 8;
{
Expand Down

0 comments on commit 598cd34

Please sign in to comment.