From 598cd3405f86c60f5537b7ac6d3e98cc8a9603ed Mon Sep 17 00:00:00 2001 From: Ed J Date: Tue, 10 Sep 2024 18:12:25 +0100 Subject: [PATCH] doc that unpdl of 0-dim ndarray returns array-ref --- Basic/Core/Core.pm | 4 ++++ Basic/Core/Core.xs | 3 --- t/core.t | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Basic/Core/Core.pm b/Basic/Core/Core.pm index 552e62e2c..005b471dd 100644 --- a/Basic/Core/Core.pm +++ b/Basic/Core/Core.pm @@ -3320,6 +3320,10 @@ C 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. +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; diff --git a/Basic/Core/Core.xs b/Basic/Core/Core.xs index e0412ea48..d553229f4 100644 --- a/Basic/Core/Core.xs +++ b/Basic/Core/Core.xs @@ -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 diff --git a/t/core.t b/t/core.t index 1590257cb..cf406747d 100644 --- a/t/core.t +++ b/t/core.t @@ -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; {