Skip to content

Commit

Permalink
github #5 : add a PDL::SV::uniqind() method
Browse files Browse the repository at this point in the history
  • Loading branch information
iynehz committed Nov 27, 2021
1 parent ac145ea commit 0a1f26b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Revision history of Alt-Data-Frame-ButMore

0.0052_01 TBD
- Add a Data::Frame::drop_bad() method.
- Add a PDL::SV::uniqind() method.
- Add a "faithfuld" example.

0.0051 2019-06-01
Expand Down
20 changes: 17 additions & 3 deletions lib/PDL/SV.pm
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,30 @@ sub glue {
BAD values are not considered unique and are ignored.
=head2 uniqind()
Return the indices of all uniq elements of a piddle.
=cut

sub uniq {
my $self = shift;
my ($self) = @_;
my $class = ref($self);

my @uniq = List::AllUtils::uniq( grep { defined $_ }
@{ $self->_effective_internal } );
my $new = $class->new( \@uniq );
return $new;
return $class->new( \@uniq );
}

## Please see file perltidy.ERR
sub uniqind {
my ($self) = @_;

my $effective_internal = $self->_effective_internal;
my @uniqind = List::AllUtils::uniq_by { $effective_internal->[$_] }
grep { defined $effective_internal->[$_] }
( 0 .. $#$effective_internal );
return pdl( \@uniqind );
}

=head2 sever
Expand Down
7 changes: 5 additions & 2 deletions t/11-pdl_sv.t
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ subtest at => sub {
};

subtest uniq => sub {
my $p1 = PDL::SV->new( [qw(foo bar baz foo bar)] )->setbadat(1);
pdl_is( $p1->uniq, PDL::SV->new( [qw(foo baz bar)] ), 'uniq' );
my $p1 =
PDL::SV->new( [qw(foo bar baz foo bar)] )->setbadat(1)->setbadat(2);
pdl_is( $p1->uniq, PDL::SV->new( [qw(foo bar)] ), 'uniq' );

pdl_is( $p1->uniqind, pdl( [ 0, 4 ] ), 'uniqind' );
};

subtest sever => sub {
Expand Down

0 comments on commit 0a1f26b

Please sign in to comment.