File Coverage

blib/lib/PDL/NDBin/Action/Avg.pm
Criterion Covered Total %
statement 28 28 100.0
branch 5 6 83.3
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 44 45 97.7


line stmt bran cond sub pod time code
1             package PDL::NDBin::Action::Avg;
2             # ABSTRACT: Action for PDL::NDBin that computes average
3             $PDL::NDBin::Action::Avg::VERSION = '0.019';
4              
5 3     3   3327 use strict;
  3         7  
  3         109  
6 3     3   20 use warnings;
  3         5  
  3         89  
7 3     3   16 use PDL::Lite; # do not import any functions into this namespace
  3         7  
  3         22  
8 3     3   416 use PDL::NDBin::Actions_PP;
  3         6  
  3         20  
9 3     3   536 use Params::Validate qw( validate OBJECT SCALAR );
  3         5  
  3         1207  
10              
11              
12             sub new
13             {
14 51     51 1 78940 my $class = shift;
15 51         353 my $self = validate( @_, {
16             N => { type => SCALAR, regex => qr/^\d+$/ },
17             type => { type => OBJECT, isa => 'PDL::Type', default => PDL::double }
18             } );
19 51         1894 return bless $self, $class;
20             }
21              
22              
23             sub process
24             {
25 63     63 1 150 my $self = shift;
26 63         81 my $iter = shift;
27 63 100       305 $self->{out} = PDL->zeroes( $self->{type}, $self->{N} ) unless defined $self->{out};
28 63 50       3528 $self->{count} = PDL->zeroes( defined(&PDL::indx) ? PDL::indx() : PDL::long, $self->{N} ) unless defined $self->{count};
    100          
29 63         2934 PDL::NDBin::Actions_PP::_iavg_loop( $iter->data, $iter->idx, $self->{out}, $self->{count}, $self->{N} );
30             # as the plugin processes all bins at once, every variable
31             # needs to be visited only once
32 63         268 $iter->var_active( 0 );
33 63         221 return $self;
34             }
35              
36              
37             sub result
38             {
39 51     51 1 545 my $self = shift;
40 51         163 $self->{out}->inplace->_setnulltobad( $self->{count} );
41 51         1755 return $self->{out};
42             }
43              
44             1;
45              
46             __END__