Running the following code on RHEL7:
#!/usr/bin/perl
use PDL;
print "OS: ".`uname -a`;
print "Perl: ".$^V."\n";
print "PDL: ".$PDL::VERSION."\n";
my $pdl = PDL->new([ [[0, 0]], [[1, 1]], [[2, 2]] ]);
print sprintf("\nPDL:%s\n", $pdl);
my $pslice = $pdl->where($pdl == 0);
print sprintf("\nPDL Slice:\n%s\n", $pslice);
my $data = $pdl->dice("X","X",[1, 0]);
print sprintf("\nData:%s\n", $data);
my $dslice = $data->where($data == 0);
print sprintf("Should be same as PDL Slice\nData Slice:\n%s\n", $dslice);
Generates the following output:
OS: Linux riskrh7 3.10.0-123.9.3.el7.x86_64 #1 SMP Thu Oct 30 00:16:40 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux
Perl: v5.16.3
PDL: 2.007_13
PDL:
[
[
[0 0]
]
[
[1 1]
]
[
[2 2]
]
]
PDL Slice:
[0 0]
Data:
[
[
[1 1]
]
[
[0 0]
]
]
Should be same as PDL Slice
Data Slice:
[7.897708e-28 3.1620201e-322]
Expected the "Data Slice" values to be the same as "PDL Slice".
Thank you for the bug report. I verified this also in stock 2.007, but it is not present in 2.006. So this appears to be a regression.
In the meantime, you can get around this by severing the dataflow connection between $pdl and $data:
Happy to hear you are able to reproduce the same problem.
Unfortunately for what we do we need the connection. The next thing we do generally is assign a value to that slice and expect it to update the original PDL. What we are finding is this never works and in some cases will cause a segmentation fault.
Running your test script through the perl debugger, it appears that the garbage comes in from clump. Specifically, where() (Primitive.pm line 2499)
which then goes to PDL::clump, and then
After that, we'll need to debug the pp_def'd _clump_int in slices.pd. I'm out of tuits for the moment (and don't have a perl with debugging symbols handy).
Just wondering if there is anything else I can do/provide to help move this forward.
Well I grabbed a copy of 2.012 and gave the code another try it has the same problem. So I took a look at Basic/Slices/slices.pd and modified like this:
Then I ran the script which generated this:
Nothing in the above jumps out at me as the potential problem. My guess is the issue is in the expansion of $PARENT in this for a slice vs pdl:
But so far I'm not finding much documentation on $PARENT.
Probably dig into the Basic/Slices/Slices.xs next it looks like that may have more of the details about potential differences between PARENT being the original PDL vs Slice of another PDL.
After tracing through the code... the initial problem is:
pdl_get_offset from Basic/Core/pdlsections.c
For the above example when pdl_at calls pdl_get_offset it returns a value outside the pdl_at data range which is from 0-3.
The reason it is getting values outside that range is the indx value is 2 so when we have a pos of 2 and 3 those values get multiplied by 2 resulting in a ioff value outside the possible range for the data resulting in bad values. We are determing the incs value to use in
XS_PDL__Core_listref_c Basic/Core/Core.c
My gues something in the logic for assigning the incs is probable not right in this context for some reason. I would assume we also have a similar issue in what ever code does assingments as well which is where core dumps are currently happening if attempt to write to these sorts of pdl's.
Let me know how else I can help to move this forward this seems like a fairly significant bug to have pdl core dumping from using clump results.
One more step closer.
It looks like PDL sets incs inside:
pdl_make_physvaffine Basic/Core/pdlapi.c
From comparing execution of good code vs bad code what I'm seeing is this:
Good Code:
it->trans->pdsl[0]->trans->incs[0]=1
it->trans->incs[0]=1
Bad Code:
it->trans->pdsl[0]->trans->incs[0]=2
it->trans->incs[0]=2
For the Bad Code because the slice now has incs of 2 pdl_make_physvaffine is using that in:
newinc += at->incs[j]*ninced
Next thing i can think of is to take a closer look at the dice code to sse how it is generating the pdls[0]->trans->incs[0] value of 2.
One thing I have noticed from the above is that with bad code the dice prints as:
[
[1 1
]
[0 0
]
]
But with good code the dice prints as:
[
[0 0
]
[1 1
]
]
Which sort of makes since givne that the code uses different incs values.
That previous post was incorrect both good code and bad code will produce the same exact results for the dice with the 1s first then the 0s.
But the dice transform is very different between the good and bad code.
For good code it looks something like this:
For bad code it looks something like this:
The above is created by adding the following debug output to
Basic/Core/Core.c line 1392
Basic/Core/pdlsections.c line 223
Last edit: Matthew McGillis 2015-08-26
This commit is what broke clump with dice:
http://sourceforge.net/p/pdl/code/ci/ef5728b56ed998658c774f3abe8c7598d471f2dd/
The change from:
To:
Is not compatible with clump. Would be ncie to revert back or find another solution that is compatible with clump results.
I added this to my t/slices.t to check for this issue:
Fixed in git master and will appear in coming PDL-2.014 release. Thanks for reporting and debugging the problem, Matt.
Thanks for getting the patch Craig put together into the next release.
Glanced at the commit and didn't see any additions to the test cases. The above provided test cases would help detect these sorts of issues if you add them in to the regression tests. If you didn't notice them you might want to consider induding them.
Added, thanks for the reminder. I didn't realize they weren't in the patch.
On Mon, Sep 28, 2015 at 3:01 PM, Matthew McGillis mmcgillis@users.sf.net
wrote: