When PDL is subclassed uniq in some cases will not return the proper class. Take this simple sublcass of PDL.
TestPDL.pm
package TestPDL; use strict; use warnings; use base qw(PDL); sub new { my $class =shift; my $self = $class->SUPER::new(@_); return $self; } sub initialize { my $class = shift; my $self = { PDL => PDL->null }; $class = (ref $class ? ref $class : $class); bless $self, $class; } 1;
Then take this simple example code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #!/usr/bin/perl use strict; use warnings; use TestPDL; my $testSlice = TestPDL->new([1, 1, 1]); my $testSlice2 = TestPDL->new([1, 2, 3]); printf("Bug: If slice has same value, uniq would convert it to a normal PDL\n"); printf("Ref of Test Slice is %s\n", ref $testSlice); printf("Ref of Test Slice 2 is %s\n", ref $testSlice2); printf("After uniq operation\n"); printf("Ref of Test Slice is %s\n", ref $testSlice->uniq); printf("Ref of Test Slice 2 is %s\n", ref $testSlice2->uniq); |
The output from the above code produces:
Bug: If slice has same value, uniq would convert it to a normal PDL Ref of Test Slice is TestPDL Ref of Test Slice 2 is TestPDL After uniq operation Ref of Test Slice is PDL Ref of Test Slice 2 is TestPDL
Notice we get a PDL object for the first uniq result when we should have gotten back a TestPDL.
Fixed in PDL git. This will be available in the CPAN developers release PDL-2.006_04 and greater. Thanks for reporting the problem.