NDBin/Action/Sum.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/Action/StdDev.pm ↑ Summary NDBin.pm »
1 package PDL::NDBin::Action::Sum;
2 # ABSTRACT: Action for PDL::NDBin that computes sum
3 $PDL::NDBin::Action::Sum::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 UNDEF );
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 | UNDEF, isa => 'PDL::Type', optional => 1 }
18 } );
19 return bless $self, $class;
20 }
21  
22  
23 sub process
24 {
25 my $self = shift;
26 my $iter = shift;
27 if( ! defined $self->{out} ) {
28 my $type = $self->{type};
29 if( ! defined $type ) {
30 $type = $iter->data->type < PDL::long() ? PDL::long : $iter->data->type;
31 }
32 $self->{out} = PDL->zeroes( $type, $self->{N} );
33 }
34 $self->{count} = PDL->zeroes( defined(&PDL::indx) ? PDL::indx() : PDL::long, $self->{N} ) unless defined $self->{count};
35 PDL::NDBin::Actions_PP::_isum_loop( $iter->data, $iter->idx, $self->{out}, $self->{count}, $self->{N} );
36 # as the plugin processes all bins at once, every variable
37 # needs to be visited only once
38 $iter->var_active( 0 );
39 return $self;
40 }
41  
42  
43 sub result
44 {
45 my $self = shift;
46 $self->{out}->inplace->_setnulltobad( $self->{count} );
47 return $self->{out};
48 }
49  
50 1;
51  
52 __END__
« NDBin/Action/StdDev.pm ↑ Summary NDBin.pm »