| 1 |
|
| #ifdef __cplusplus |
| 2 |
|
| extern "C" { |
| 3 |
|
| #endif |
| 4 |
|
| |
| 5 |
|
| #define PERL_NO_GET_CONTEXT /* we want efficiency */ |
| 6 |
|
| #include <EXTERN.h> |
| 7 |
|
| #include <perl.h> |
| 8 |
|
| #include <XSUB.h> |
| 9 |
|
| |
| 10 |
|
| #ifdef __cplusplus |
| 11 |
|
| } /* extern "C" */ |
| 12 |
|
| #endif |
| 13 |
|
| |
| 14 |
|
| #define NEED_newSVpvn_flags |
| 15 |
|
| #include "ppport.h" |
| 16 |
|
| |
| 17 |
|
| MODULE = DSP::LinPred_XS PACKAGE = DSP::LinPred_XS |
| 18 |
|
| |
| 19 |
|
| PROTOTYPES: DISABLE |
| 20 |
|
| |
| 21 |
|
| void |
| 22 |
|
| get_stat(...) |
| 23 |
|
| PPCODE: |
| 24 |
|
| { |
| 25 |
5001 |
▶ | if(items != 1){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(items != 1){ |
0 |
5001 |
5001 |
|
| 26 |
0 |
| croak("Invalid argument"); |
| 27 |
|
| } |
| 28 |
5001 |
| SV* input = ST(0); |
| 29 |
5001 |
| AV* av = (AV*)SvRV(input); |
| 30 |
5001 |
| IV length = av_len(av) + 1; |
| 31 |
|
| IV k; |
| 32 |
5001 |
| NV sum = 0; |
| 33 |
5001 |
| NV variance = 0; |
| 34 |
|
| NV mean,stddev,temp; |
| 35 |
|
| SV** avv_ptr; |
| 36 |
|
| SV* av_val; |
| 37 |
|
| |
| 38 |
510001 |
▶ | for(k=0;k <= length -1;k++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(k=0;k <= length -1;k++){ |
505000 |
5001 |
510001 |
|
| 39 |
505000 |
| avv_ptr = av_fetch(av,k,FALSE); |
| 40 |
505000 |
▶ | av_val = avv_ptr ? *avv_ptr : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| av_val = avv_ptr ? *avv_ptr : &PL_sv_undef; |
505000 |
0 |
505000 |
|
| 41 |
505000 |
| sum = sum + SvNV(av_val); |
| 42 |
|
| } |
| 43 |
5001 |
| mean = sum / length; |
| 44 |
510001 |
▶ | for(k=0;k <= length -1;k++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(k=0;k <= length -1;k++){ |
505000 |
5001 |
510001 |
|
| 45 |
505000 |
| avv_ptr = av_fetch(av,k,FALSE); |
| 46 |
505000 |
▶ | av_val = avv_ptr ? *avv_ptr : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| av_val = avv_ptr ? *avv_ptr : &PL_sv_undef; |
505000 |
0 |
505000 |
|
| 47 |
505000 |
| temp = SvNV(av_val); |
| 48 |
505000 |
| variance = variance + (temp - mean)*(temp - mean); |
| 49 |
|
| } |
| 50 |
5001 |
| variance = variance / length; |
| 51 |
5001 |
| stddev = sqrt(variance); |
| 52 |
5001 |
▶ | mXPUSHs(newSVnv(sum)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newSVnv(sum)); |
0 |
5001 |
5001 |
|
| 53 |
5001 |
▶ | mXPUSHs(newSVnv(mean)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newSVnv(mean)); |
0 |
5001 |
5001 |
|
| 54 |
5001 |
▶ | mXPUSHs(newSVnv(variance)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newSVnv(variance)); |
0 |
5001 |
5001 |
|
| 55 |
5001 |
▶ | mXPUSHs(newSVnv(stddev)); |
Branch: 1 branch
| Branch | True | False | Total |
| mXPUSHs(newSVnv(stddev)); |
0 |
5001 |
5001 |
|
| 56 |
5001 |
| XSRETURN(4); |
| 57 |
|
| } |