File Coverage

blib/lib/PDL/NDBin/Action/Max.pm
Criterion Covered Total %
statement 28 28 100.0
branch 4 4 100.0
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 43 43 100.0


line stmt bran cond sub pod time code
1             package PDL::NDBin::Action::Max;
2             # ABSTRACT: Action for PDL::NDBin that computes maximum
3             $PDL::NDBin::Action::Max::VERSION = '0.019';
4              
5 2     2   2154 use strict;
  2         4  
  2         60  
6 2     2   15 use warnings;
  2         4  
  2         52  
7 2     2   9 use PDL::Lite; # do not import any functions into this namespace
  2         4  
  2         12  
8 2     2   216 use PDL::NDBin::Actions_PP;
  2         3  
  2         30  
9 2     2   294 use Params::Validate qw( validate OBJECT SCALAR UNDEF );
  2         4  
  2         623  
10              
11              
12             sub new
13             {
14 44     44 1 10730 my $class = shift;
15 44         800 my $self = validate( @_, {
16             N => { type => SCALAR, regex => qr/^\d+$/ },
17             type => { type => OBJECT | UNDEF, isa => 'PDL::Type', optional => 1 }
18             } );
19 44         975 return bless $self, $class;
20             }
21              
22              
23             sub process
24             {
25 56     56 1 128 my $self = shift;
26 56         94 my $iter = shift;
27 56 100       165 if( ! defined $self->{out} ) {
28 44 100       155 my $type = defined $self->{type} ? $self->{type} : $iter->data->type;
29 44         971 $self->{out} = PDL->zeroes( $type, $self->{N} )->setbadif( 1 );
30             }
31 56         3420 PDL::NDBin::Actions_PP::_imax_loop( $iter->data, $iter->idx, $self->{out}, $self->{N} );
32             # as the plugin processes all bins at once, every variable
33             # needs to be visited only once
34 56         204 $iter->var_active( 0 );
35 56         169 return $self;
36             }
37              
38              
39             sub result
40             {
41 44     44 1 451 my $self = shift;
42 44         154 return $self->{out};
43             }
44              
45             1;
46              
47             __END__