https://www.cdslab.org/paramonte/fortran/2
Current view: top level - test - test_pm_mathCumPropExp.F90 (source / functions) Hit Total Coverage
Test: ParaMonte 2.0.0 :: Serial Fortran - Code Coverage Report Lines: 31 31 100.0 %
Date: 2024-04-08 03:18:57 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       2             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       3             : !!!!                                                                                                                            !!!!
       4             : !!!!    ParaMonte: Parallel Monte Carlo and Machine Learning Library.                                                           !!!!
       5             : !!!!                                                                                                                            !!!!
       6             : !!!!    Copyright (C) 2012-present, The Computational Data Science Lab                                                          !!!!
       7             : !!!!                                                                                                                            !!!!
       8             : !!!!    This file is part of the ParaMonte library.                                                                             !!!!
       9             : !!!!                                                                                                                            !!!!
      10             : !!!!    LICENSE                                                                                                                 !!!!
      11             : !!!!                                                                                                                            !!!!
      12             : !!!!       https://github.com/cdslaborg/paramonte/blob/main/LICENSE.md                                                          !!!!
      13             : !!!!                                                                                                                            !!!!
      14             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      15             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      16             : 
      17             : !>  \brief
      18             : !>  This module contains tests of the module [pm_mathCumPropExp](@ref pm_mathCumPropExp).
      19             : !>
      20             : !>  \author
      21             : !>  \AmirShahmoradi, Tuesday 12:01 AM, August 11, 2021, Dallas, TX
      22             : 
      23             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      24             : 
      25             : module test_pm_mathCumPropExp
      26             : 
      27             :     use pm_mathCumPropExp ! LCOV_EXCL_LINE
      28             :     use pm_err, only: err_type
      29             :     use pm_test, only: test_type, LK
      30             :     use pm_kind, only: LK
      31             :     implicit none
      32             : 
      33             :     private
      34             :     public :: setTest
      35             :     type(test_type) :: test
      36             : 
      37             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      38             : 
      39             :     interface
      40             : 
      41             : #if     RK5_ENABLED
      42             :         module function test_getCumPropExpSel_RK5() result(assertion); logical(LK) :: assertion; end function
      43             : #endif
      44             : #if     RK4_ENABLED
      45             :         module function test_getCumPropExpSel_RK4() result(assertion); logical(LK) :: assertion; end function
      46             : #endif
      47             : #if     RK3_ENABLED
      48             :         module function test_getCumPropExpSel_RK3() result(assertion); logical(LK) :: assertion; end function
      49             : #endif
      50             : #if     RK2_ENABLED
      51             :         module function test_getCumPropExpSel_RK2() result(assertion); logical(LK) :: assertion; end function
      52             : #endif
      53             : #if     RK1_ENABLED
      54             :         module function test_getCumPropExpSel_RK1() result(assertion); logical(LK) :: assertion; end function
      55             : #endif
      56             : 
      57             :     end interface
      58             : 
      59             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      60             : 
      61             :     interface
      62             : 
      63             : #if     RK5_ENABLED
      64             :         module function test_getCumPropExpSeq_RK5() result(assertion); logical(LK) :: assertion; end function
      65             : #endif
      66             : #if     RK4_ENABLED
      67             :         module function test_getCumPropExpSeq_RK4() result(assertion); logical(LK) :: assertion; end function
      68             : #endif
      69             : #if     RK3_ENABLED
      70             :         module function test_getCumPropExpSeq_RK3() result(assertion); logical(LK) :: assertion; end function
      71             : #endif
      72             : #if     RK2_ENABLED
      73             :         module function test_getCumPropExpSeq_RK2() result(assertion); logical(LK) :: assertion; end function
      74             : #endif
      75             : #if     RK1_ENABLED
      76             :         module function test_getCumPropExpSeq_RK1() result(assertion); logical(LK) :: assertion; end function
      77             : #endif
      78             : 
      79             :     end interface
      80             : 
      81             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      82             : 
      83             :     interface
      84             : 
      85             : #if     RK5_ENABLED
      86             :         module function test_setCumPropExpSel_RK5() result(assertion); logical(LK) :: assertion; end function
      87             : #endif
      88             : #if     RK4_ENABLED
      89             :         module function test_setCumPropExpSel_RK4() result(assertion); logical(LK) :: assertion; end function
      90             : #endif
      91             : #if     RK3_ENABLED
      92             :         module function test_setCumPropExpSel_RK3() result(assertion); logical(LK) :: assertion; end function
      93             : #endif
      94             : #if     RK2_ENABLED
      95             :         module function test_setCumPropExpSel_RK2() result(assertion); logical(LK) :: assertion; end function
      96             : #endif
      97             : #if     RK1_ENABLED
      98             :         module function test_setCumPropExpSel_RK1() result(assertion); logical(LK) :: assertion; end function
      99             : #endif
     100             : 
     101             :     end interface
     102             : 
     103             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     104             : 
     105             :     interface
     106             : 
     107             : #if     RK5_ENABLED
     108             :         module function test_setCumPropExpSeq_RK5() result(assertion); logical(LK) :: assertion; end function
     109             : #endif
     110             : #if     RK4_ENABLED
     111             :         module function test_setCumPropExpSeq_RK4() result(assertion); logical(LK) :: assertion; end function
     112             : #endif
     113             : #if     RK3_ENABLED
     114             :         module function test_setCumPropExpSeq_RK3() result(assertion); logical(LK) :: assertion; end function
     115             : #endif
     116             : #if     RK2_ENABLED
     117             :         module function test_setCumPropExpSeq_RK2() result(assertion); logical(LK) :: assertion; end function
     118             : #endif
     119             : #if     RK1_ENABLED
     120             :         module function test_setCumPropExpSeq_RK1() result(assertion); logical(LK) :: assertion; end function
     121             : #endif
     122             : 
     123             :     end interface
     124             : 
     125             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     126             : 
     127             : contains
     128             : 
     129             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     130             : 
     131           1 :     subroutine setTest()
     132             : 
     133           1 :         test = test_type(MODULE_NAME)
     134             : 
     135             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     136             : 
     137             : #if     RK5_ENABLED
     138             :         call test%run(test_getCumPropExpSel_RK5, SK_"test_getCumPropExpSel_RK5")
     139             : #endif
     140             : #if     RK4_ENABLED
     141           1 :         call test%run(test_getCumPropExpSel_RK4, SK_"test_getCumPropExpSel_RK4")
     142             : #endif
     143             : #if     RK3_ENABLED
     144           1 :         call test%run(test_getCumPropExpSel_RK3, SK_"test_getCumPropExpSel_RK3")
     145             : #endif
     146             : #if     RK2_ENABLED
     147           1 :         call test%run(test_getCumPropExpSel_RK2, SK_"test_getCumPropExpSel_RK2")
     148             : #endif
     149             : #if     RK1_ENABLED
     150           1 :         call test%run(test_getCumPropExpSel_RK1, SK_"test_getCumPropExpSel_RK1")
     151             : #endif
     152             : 
     153             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     154             : 
     155             : #if     RK5_ENABLED
     156             :         call test%run(test_getCumPropExpSeq_RK5, SK_"test_getCumPropExpSeq_RK5")
     157             : #endif
     158             : #if     RK4_ENABLED
     159           1 :         call test%run(test_getCumPropExpSeq_RK4, SK_"test_getCumPropExpSeq_RK4")
     160             : #endif
     161             : #if     RK3_ENABLED
     162           1 :         call test%run(test_getCumPropExpSeq_RK3, SK_"test_getCumPropExpSeq_RK3")
     163             : #endif
     164             : #if     RK2_ENABLED
     165           1 :         call test%run(test_getCumPropExpSeq_RK2, SK_"test_getCumPropExpSeq_RK2")
     166             : #endif
     167             : #if     RK1_ENABLED
     168           1 :         call test%run(test_getCumPropExpSeq_RK1, SK_"test_getCumPropExpSeq_RK1")
     169             : #endif
     170             : 
     171             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     172             : 
     173             : #if     RK5_ENABLED
     174             :         call test%run(test_setCumPropExpSel_RK5, SK_"test_setCumPropExpSel_RK5")
     175             : #endif
     176             : #if     RK4_ENABLED
     177           1 :         call test%run(test_setCumPropExpSel_RK4, SK_"test_setCumPropExpSel_RK4")
     178             : #endif
     179             : #if     RK3_ENABLED
     180           1 :         call test%run(test_setCumPropExpSel_RK3, SK_"test_setCumPropExpSel_RK3")
     181             : #endif
     182             : #if     RK2_ENABLED
     183           1 :         call test%run(test_setCumPropExpSel_RK2, SK_"test_setCumPropExpSel_RK2")
     184             : #endif
     185             : #if     RK1_ENABLED
     186           1 :         call test%run(test_setCumPropExpSel_RK1, SK_"test_setCumPropExpSel_RK1")
     187             : #endif
     188             : 
     189             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     190             : 
     191             : #if     RK5_ENABLED
     192             :         call test%run(test_setCumPropExpSeq_RK5, SK_"test_setCumPropExpSeq_RK5")
     193             : #endif
     194             : #if     RK4_ENABLED
     195           1 :         call test%run(test_setCumPropExpSeq_RK4, SK_"test_setCumPropExpSeq_RK4")
     196             : #endif
     197             : #if     RK3_ENABLED
     198           1 :         call test%run(test_setCumPropExpSeq_RK3, SK_"test_setCumPropExpSeq_RK3")
     199             : #endif
     200             : #if     RK2_ENABLED
     201           1 :         call test%run(test_setCumPropExpSeq_RK2, SK_"test_setCumPropExpSeq_RK2")
     202             : #endif
     203             : #if     RK1_ENABLED
     204           1 :         call test%run(test_setCumPropExpSeq_RK1, SK_"test_setCumPropExpSeq_RK1")
     205             : #endif
     206             : 
     207             :         !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     208             : 
     209           1 :         call test%run(test_setCumPropExp_RK, SK_"test_setCumPropExp_RK")
     210             : 
     211           1 :         call test%summarize()
     212             : 
     213           1 :     end subroutine setTest
     214             : 
     215             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     216             : 
     217             :     !>  \brief
     218             :     !>  Test the special legacy interface: genLogCumProp_RK()
     219           1 :     function test_setCumPropExp_RK() result(assertion)
     220             : 
     221             :         use pm_kind, only: IK, RK
     222             :         use pm_mathCumSum, only: getCumSum ! LCOV_EXCL_LINE
     223             :         use pm_distUnif, only: getUnifRand ! LCOV_EXCL_LINE
     224             : 
     225             :         logical(LK)                 :: assertion
     226             :         real(RK)    , parameter     :: TOL = epsilon(1._RK) * 10._RK
     227             :         real(RK)    , allocatable   :: Array(:)
     228             :         real(RK)    , allocatable   :: cumPropExp_ref(:)
     229             :         real(RK)    , allocatable   :: cumPropExp(:)
     230             :         real(RK)    , allocatable   :: diff(:)
     231             :         integer(IK)                 :: i
     232             : 
     233         201 :         do i = 1, 200
     234        1440 :             Array = getUnifRand(minexponent(0._RK), maxexponent(0._RK), getUnifRand(1_IK, 10_IK))
     235        2653 :             cumPropExp_ref = getCumSum(exp(Array - maxval(Array)))
     236        1240 :             cumPropExp_ref = cumPropExp_ref / cumPropExp_ref(size(cumPropExp_ref))
     237        1613 :             cumPropExp = getCumPropExp_RK(Array, maxval(Array), size(Array, kind = IK))
     238        1440 :             diff = abs(cumPropExp - cumPropExp_ref)
     239        1240 :             assertion = all(diff < TOL)
     240         201 :             call test%assert(assertion, desc = "The genLogCumProp_RK() must correctly compute CumSumProp for an input array of real of default kind.")
     241             :         end do
     242             : 
     243           1 :     end function
     244             : 
     245             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     246             : 
     247             : end module test_pm_mathCumPropExp ! LCOV_EXCL_LINE

ParaMonte: Parallel Monte Carlo and Machine Learning Library 
The Computational Data Science Lab
© Copyright 2012 - 2024