NDBin/Action/Avg.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« NDBin/Iterator.pm ↑ Summary NDBin/Action/Count.pm »
1 package PDL::NDBin::Action::Avg;
2 # ABSTRACT: Action for PDL::NDBin that computes average
3 $PDL::NDBin::Action::Avg::VERSION = '0.016';
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use PDL::Lite; # do not import any functions into this namespace
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use PDL::NDBin::Actions_PP;
Subroutine BEGIN: called CC=1 SCAR=2.6
9 use Params::Validate qw( validate OBJECT SCALAR );
10  
11  
12 sub new
13 {
14 my $class = shift;
15 my $self = validate( @_, {
16 N => { type => SCALAR, regex => qr/^\d+$/ },
17 type => { type => OBJECT, isa => 'PDL::Type', default => PDL::double }
18 } );
19 return bless $self, $class;
20 }
21  
22  
23 sub process
24 {
25 my $self = shift;
26 my $iter = shift;
27 $self->{out} = PDL->zeroes( $self->{type}, $self->{N} ) unless defined $self->{out};
28 $self->{count} = PDL->zeroes( defined(&PDL::indx) ? PDL::indx() : PDL::long, $self->{N} ) unless defined $self->{count};
29 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 $iter->var_active( 0 );
33 return $self;
34 }
35  
36  
37 sub result
38 {
39 my $self = shift;
40 $self->{out}->inplace->_setnulltobad( $self->{count} );
41 return $self->{out};
42 }
43  
44 1;
45  
46 __END__
« NDBin/Iterator.pm ↑ Summary NDBin/Action/Count.pm »