File Coverage

blib/lib/PDL/NDBin/Action/StdDev.pm
Criterion Covered Total %
statement 29 29 100.0
branch 7 8 87.5
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 47 48 97.9


line stmt bran cond sub pod time code
1             package PDL::NDBin::Action::StdDev;
2             # ABSTRACT: Action for PDL::NDBin that computes standard deviation
3             $PDL::NDBin::Action::StdDev::VERSION = '0.020';
4              
5 2     2   2112 use strict;
  2         4  
  2         61  
6 2     2   9 use warnings;
  2         5  
  2         64  
7 2     2   12 use PDL::Lite; # do not import any functions into this namespace
  2         3  
  2         12  
8 2     2   253 use PDL::NDBin::Actions_PP;
  2         3  
  2         13  
9 2     2   286 use Params::Validate qw( validate OBJECT SCALAR );
  2         4  
  2         773  
10              
11              
12             sub new
13             {
14 45     45 1 6072 my $class = shift;
15 45         283 my $self = validate( @_, {
16             N => { type => SCALAR, regex => qr/^\d+$/ },
17             type => { type => OBJECT, isa => 'PDL::Type', default => PDL::double }
18             } );
19 45         1597 return bless $self, $class;
20             }
21              
22              
23             sub process
24             {
25 57     57 1 124 my $self = shift;
26 57         82 my $iter = shift;
27 57 100       246 $self->{out} = PDL->zeroes( $self->{type}, $self->{N} ) unless defined $self->{out};
28 57 50       3035 $self->{count} = PDL->zeroes( defined(&PDL::indx) ? PDL::indx() : PDL::long, $self->{N} ) unless defined $self->{count};
    100          
29             # as the internal computations happen in double, the type of 'avg' sticks to double
30 57 100       2622 $self->{avg} = PDL->zeroes( PDL::double, $self->{N} ) unless defined $self->{avg};
31 57         2462 PDL::NDBin::Actions_PP::_istddev_loop( $iter->data, $iter->idx, $self->{out}, $self->{count}, $self->{avg}, $self->{N} );
32             # as the plugin processes all bins at once, every variable
33             # needs to be visited only once
34 57         238 $iter->var_active( 0 );
35 57         174 return $self;
36             }
37              
38              
39             sub result
40             {
41 45     45 1 451 my $self = shift;
42 45         132 $self->{out}->inplace->_istddev_post( $self->{count} );
43 45         1476 return $self->{out};
44             }
45              
46             1;
47              
48             __END__