Menu

#403 reshape can't handle piddles with -C flag

critical
closed-fixed
nobody
None
9
2015-11-13
2015-10-13
No

This is a bug report based on the following pdl-general mailing list thread:
http://sourceforge.net/p/pdl/mailman/pdl-general/thread/561C0B26.3020004%40atlas.cz/#msg34534458

The gist is that the modified reshape() in PDL-2.014 has exposed problems
in the handling of piddles with the Changed flag set. As this is fundamental
to PDL operation, we need to resolve this as soon as possible to release a
new stable release with the fix.

Here are the problem sequences from the above discussion with thanks to kmx:

use PDL;

my $P = pdl('[ [ [0 1] [2 3] ] [ [4 5] [6 7] ] ]'); # Double D [2,2,2]
print "P-BEFORE info=". $P->info . " data: " . $P . "\n";
$P->reshape(4, 2);
print "P-AFTER  info=". $P->info . " data: " . $P . "\n";

my $Q = pdl([ [ [0,1],[2,3] ],[ [4,5],[6,7] ] ]); # Double D [2,2,2]
print "Q-BEFORE info=". $Q->info . " data: " . $Q . "\n";
$Q->reshape(4, 2);
print "Q-AFTER  info=". $Q->info . " data: " . $Q . "\n";

The P piddle was generated from the string input and results in a piddle with
the changed flag set resulting in the in-equivalent output for the two cases.
A fix in this case would be to add a sever to the PDL::Core::new_pdl_from_string.

Here is a second example showing that the problem is with the changed state
of the piddle:

use PDL;

print "PDL VERSION=$PDL::VERSION\n";
my $R = double([ [ [0,1],[2,3] ],[ [4,5],[6,7] ] ]);
print "1: info='".$R->info("%S")."' data=".$R."\n";
my $S = $R->mv(-1,0);
print "2: info='".$S->info("%S")."' data=".$S."\n";
my $T = $R->mv(-1,0)->reshape(4,2);
print "3: info='".$T->info("%S")."' data=".$T."\n";

And finally, here is some code that fails for both PDL-2.013 and PDL-2.014
so the problem is not just the most recent change to the reshape() method
(other than that change exposing this problem):

use PDL;
my $S = double([ [ [0,1],[2,3] ],[ [4,5],[6,7] ] ])->mv(-1,0);
print "1: info='".$S->info("%D:%S")."' data=".$S."\n";
$S->setdims([4,2]);
$S->upd_data;
print "2: info='".$S->info("%D:%S")."' data=".$S."\n";

Discussion

  • Craig DeForest

    Craig DeForest - 2015-11-13
    • status: open --> closed-fixed
     
  • Craig DeForest

    Craig DeForest - 2015-11-13

    The difficulty comes because of how mv() implements its dimension-shuffling with dataflow -- via PP macros that use precomputed offsets into the dims list of the child and parent PDL. When the parent dim list gets shorter, the trans structure associated with the mv() operation now points to hyperspace.

    Rather than rework the mv() architecture, I put a mask in the setdims() code in pdlcore that prevents running setdims() on a child PDL. The setdims() and reshape() methods shouldn't be used on connected PDLs anyhow -- they're intended for operations like rfits(), where you allocate a straight-up unconnected PDL, then slurp in the data for it and reorganize the dims to suit.

     

Log in to post a comment.