Skip to content

Commit d03d828

Browse files
committed
corr_dev: addition of test for dp complex numbers
1 parent 7901ee2 commit d03d828

File tree

1 file changed

+37
-45
lines changed

1 file changed

+37
-45
lines changed

src/tests/stats/test_corr.f90

+37-45
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
program test_corr
22
use stdlib_experimental_error, only: check
33
use stdlib_experimental_kinds, only: sp, dp, int32, int64
4-
use stdlib_experimental_stats, only: corr,cov
4+
use stdlib_experimental_stats, only: corr
55
use,intrinsic :: ieee_arithmetic, only : ieee_is_nan
66
implicit none
77

@@ -37,7 +37,7 @@ program test_corr
3737
!
3838
! call test_csp(cmplx(cd1, kind = sp), cmplx(ds, kind = sp))
3939
!
40-
! call test_cdp(cd1, ds)
40+
call test_cdp(cd1, ds)
4141

4242
contains
4343

@@ -439,47 +439,39 @@ end subroutine test_dp
439439
!
440440
! end subroutine test_csp
441441
!
442-
! subroutine test_cdp(x, x2)
443-
! complex(dp), intent(in) :: x(:)
444-
! complex(dp), intent(in) :: x2(:, :)
445-
!
446-
!! complex(dp), allocatable :: cd(:,:)
447-
!
448-
! call check( abs(cov(x, dim=1) -&
449-
! (var(real(x),1) + var(aimag(x), 1)) ) < dptol&
450-
! , 'cdp check 1')
451-
! call check( abs(cov(x, 1, aimag(x) == 0) -&
452-
! var(real(x), 1, aimag(x) == 0)) < dptol&
453-
! , 'cdp check 2')
454-
!
455-
! call check( abs(cov(x, dim=1, corrected=.false.) -&
456-
! (var(real(x), dim=1, corrected=.false.) +&
457-
! var(aimag(x), dim=1, corrected=.false.))) <&
458-
! dptol&
459-
! , 'cdp check 3')
460-
!
461-
! call check( ieee_is_nan(real(cov(x, 1, .false., corrected=.false.)))&
462-
! , 'cdp check 4')
463-
!
464-
! call check( abs(cov(x, 1, aimag(x) == 0, corrected=.false.) -&
465-
! var(real(x), 1, aimag(x) == 0,&
466-
! corrected=.false.)) < dptol&
467-
! , 'cdp check 5')
468-
!
469-
!
470-
! call check( all( abs( cov(x2, 1) - reshape([&
471-
! (2.5_dp,0._dp), (5.5_dp,-1._dp), (8.5_dp,-2._dp)&
472-
! , (5.5_dp,1._dp), (12.5_dp,0._dp), (19.5_dp,-1._dp)&
473-
! , (8.5_dp,2._dp), (19.5_dp,1._dp), (30.5_dp,0._dp)]&
474-
! ,[ size(x2, 2), size(x2, 2)])&
475-
! ) < dptol)&
476-
! , 'cdp check 6')
477-
! call check( all( abs( cov(x2, 2) - reshape([&
478-
! (4._dp,0._dp), (0._dp,4._dp),&
479-
! (0._dp,-4._dp), (4._dp,0._dp)]&
480-
! ,[ size(x2, 1), size(x2, 1)])&
481-
! ) < dptol)&
482-
! , 'cdp check 7')
442+
subroutine test_cdp(x, x2)
443+
complex(dp), intent(in) :: x(:)
444+
complex(dp), intent(in) :: x2(:, :)
445+
446+
! complex(dp), allocatable :: cd(:,:)
447+
448+
call check( abs(corr(x, dim=1) - 1._dp) < dptol&
449+
, 'cdp check 1')
450+
call check( abs(corr(x, 1, aimag(x) == 0) - 1._dp ) < dptol&
451+
, 'cdp check 2')
452+
453+
call check( ieee_is_nan(corr(x, 1, aimag(x) == -99 )) &
454+
, 'cdp check 3')
455+
456+
call check( ieee_is_nan(real(corr(x, 1, .false.)))&
457+
, 'cdp check 4')
458+
459+
call check( all( abs( corr(x2, 1) - reshape([&
460+
(1._dp,0._dp), (0.983869910099907_dp,-0.178885438199983_dp),&
461+
(0.973417168333576_dp,-0.229039333725547_dp),&
462+
(0.983869910099907_dp,0.178885438199983_dp), (1._dp,0._dp),&
463+
(0.998687663476588_dp,-0.051214751973158_dp),&
464+
(0.973417168333575_dp,0.229039333725547_dp),&
465+
(0.998687663476588_dp,0.0512147519731583_dp), (1._dp,0._dp) ]&
466+
,[ size(x2, 2), size(x2, 2)])&
467+
) < dptol)&
468+
, 'cdp check 6')
469+
call check( all( abs( corr(x2, 2) - reshape([&
470+
(1._dp,0._dp), (0._dp,1._dp),&
471+
(0._dp,-1._dp), (1._dp,0._dp)]&
472+
,[ size(x2, 1), size(x2, 1)])&
473+
) < dptol)&
474+
, 'cdp check 7')
483475
!
484476
! call check( all( abs( cov(x2, 1, corrected=.false.) - reshape([&
485477
! (2.5_dp,0._dp), (5.5_dp,-1._dp), (8.5_dp,-2._dp)&
@@ -524,6 +516,6 @@ end subroutine test_dp
524516
! ) < dptol)&
525517
! , 'cdp check 12')
526518
!
527-
! end subroutine test_cdp
528-
!
519+
end subroutine test_cdp
520+
529521
end program test_corr

0 commit comments

Comments
 (0)