Skip to content

Commit

Permalink
capture & fix type-converting with a parent in downstream - #511
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Dec 20, 2024
1 parent c9d8fcd commit 179ccb4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/PDL/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2988,7 +2988,7 @@ sub PDL::reshape :lvalue {
$pdl->make_physical;
if ($pdl->nelem > $nelem) {
my $tmp = $pdl->flat->slice("$nelem:-1");
$tmp .= 0;
$tmp .= pdl($tmp->type, 0);
}
$_[0] = $pdl;
return $pdl;
Expand Down
3 changes: 1 addition & 2 deletions lib/PDL/Core/pdlapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1104,13 +1104,12 @@ static inline pdl_datatypes pdl__type_detect(pdl_trans *trans) {

pdl_error pdl_type_coerce(pdl_trans *trans) {
pdl_error PDL_err = {0, NULL, 0};
PDL_Indx i;
pdl_transvtable *vtable = trans->vtable;
pdl **pdls = trans->pdls;
char p2child_has_badvalue = (vtable->npdls == 2 && pdls[0]->has_badvalue
&& (vtable->par_flags[1] & PDL_PARAM_ISCREATEALWAYS));
PDL_Anyval parent_badvalue = p2child_has_badvalue ? pdls[0]->badvalue : (PDL_Anyval){PDL_INVALID, {0}};
PDL_Indx nchildren = vtable->npdls - vtable->nparents;
PDL_Indx i, nchildren = vtable->npdls - vtable->nparents;
/* copy the "real" (passed-in) outputs to the end-area to use as actual
outputs, possibly after being converted, leaving the passed-in ones
alone to be picked up for use in CopyBadStatusCode */
Expand Down
6 changes: 3 additions & 3 deletions lib/PDL/IO/Misc.pd
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,16 @@ sub _at_1D ($$) { # Called by wcols and swcols
# squeezes "fluffy" perl list values into column data type
sub _burp_1D {
my $data = $_[0]->[0];
my $databox = $_[0]->[1];
my $data = $_[0][0];
my $databox = $_[0][1];
my $index = $_[1];
my $start = $index - @{$databox} + 1;
if (ref $data eq 'ARRAY') {
push @{$data}, @{$databox};
} elsif ( ref($databox->[0]) eq "ARRAY" ) {
# could add POSIX::strtol for hex and octal support but
# can't break float conversions (how?)
$data->slice(":,$start:$index") .= pdl($databox);
$data->slice(":,$start:$index") .= pdl($data->type, $databox);
} else {
# could add POSIX::strtol for hex and octal support but
# can't break float conversions (how?)
Expand Down
1 change: 0 additions & 1 deletion lib/PDL/Primitive.pd
Original file line number Diff line number Diff line change
Expand Up @@ -3230,7 +3230,6 @@ sub PDL::interpND {
# (the 'x' is the normal perl repeat operator)
my $crnr = PDL::Basic::ndcoords( (2) x $index->dim(0) ) # (index,cth)
->mv(0,-1)->clump($index->dim(0))->mv(-1,0); # (index, clst)
# a & b are the weighting coefficients.
my($x,$y);
$index->where( 0 * $index ) .= -10; # Change NaN to invalid
Expand Down
14 changes: 6 additions & 8 deletions t/core.t
Original file line number Diff line number Diff line change
Expand Up @@ -492,16 +492,12 @@ ok !$y->is_inplace,"new_or_inplace clears the inplace flag";
}

{
# check reshape and dims. While we're at it, check null & empty creation too.
# check empty creation
is empty(float)->type, 'float', 'empty(float) works';
my $empty = empty();
is $empty->type->enum, 0, 'empty() gives lowest-numbered type';
is empty(float)->type, 'float', 'empty(float) works';
is $empty->nelem, 0, "you can make an empty PDL with zeroes(0)";
like "$empty", qr/Empty/, "an empty PDL prints 'Empty'";
}

{
my $empty = empty();
my $null = null;
is $null->nbytes, 0, 'a null has 0 nbytes';
is $null->info, 'PDL->null', "null ndarray's info is 'PDL->null'";
Expand Down Expand Up @@ -531,6 +527,9 @@ is_pdl $x, short([[3,4],[5,6]]), "reshape moved the elements to the right place"
my $y = $x->slice(":,:");
eval { $y->reshape(4); };
unlike $@, qr/Can't/, "reshape doesn't fail on a PDL with a parent";
my $nzai = zeroes(indx,6)->slice('');
eval {$nzai = $nzai->reshape(30)};
is $@, '', 'no reshape error';
}

{
Expand Down Expand Up @@ -803,8 +802,7 @@ my $oneway_slice = $y->slice('0:1');
is_pdl $oneway_slice, pdl '[4 5]';
eval {$oneway_slice .= 11};
isnt $@, '', 'error on assigning into one-way slice';
my $c = $y->flowing->_convert_int(cdouble->enum);
ok $c->fflows, 'flowing -> converted has "flowing" on';
ok $y->flowing->_convert_int(cdouble->enum)->fflows, 'flowing -> converted has "flowing" on';
}

{
Expand Down
4 changes: 4 additions & 0 deletions t/io-misc.t
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ is_pdl $y, long(2,4,6,8), "rcols: deftype option";
is_pdl $x, ushort(1,3,-5,7), "rcols: types option";
is_pdl $y, double(2,4,6,8), "rcols: types option";

# capturing problem in PDL::CCS
my $ix = PDL->rcols($file, [0,1], { TYPES => [ indx ], IGNORE => qr/^\s*#/ });
is_pdl $ix, indx('1 3 -5 7; 2 4 6 8'), "rcols: types option";

isa_ok $PDL::IO::Misc::deftype, "PDL::Type", "PDL::IO::Misc::deftype";
is $PDL::IO::Misc::deftype, 'double', "PDL::IO::Misc::deftype check";

Expand Down

0 comments on commit 179ccb4

Please sign in to comment.