39 module function test_getLogSumExp_CK3_1()
result(assertion); logical(LK) :: assertion; end function
42 module function test_getLogSumExp_CK2_1()
result(assertion); logical(LK) :: assertion; end function
45 module function test_getLogSumExp_CK1_1()
result(assertion); logical(LK) :: assertion; end function
51 module function test_getLogSumExp_RK3_1()
result(assertion); logical(LK) :: assertion; end function
54 module function test_getLogSumExp_RK2_1()
result(assertion); logical(LK) :: assertion; end function
57 module function test_getLogSumExp_RK1_1()
result(assertion); logical(LK) :: assertion; end function
77 call test%run(test_getLogSumExp_CK3_1, SK_
"test_getLogSumExp_CK3_1")
80 call test%run(test_getLogSumExp_CK2_1, SK_
"test_getLogSumExp_CK2_1")
83 call test%run(test_getLogSumExp_CK1_1, SK_
"test_getLogSumExp_CK1_1")
89 call test%run(test_getLogSumExp_RK3_1, SK_
"test_getLogSumExp_RK3_1")
92 call test%run(test_getLogSumExp_RK2_1, SK_
"test_getLogSumExp_RK2_1")
95 call test%run(test_getLogSumExp_RK1_1, SK_
"test_getLogSumExp_RK1_1")
100 call test%summarize()
109 logical(
LK) :: assertion
110 real(
RK),
parameter :: LogValue(
*)
= [
log(
0.5*huge(
1._RK)),
log(
0.9*huge(
1._RK)),
log(
0.1*huge(
1._RK)) ]
111 real(
RK),
parameter :: tolerance
= 1.e-10_RK
112 real(
RK),
parameter :: logSumExp_ref
= 710.1881779865910_RK
113 real(
RK) :: logSumExp
114 real(
RK) :: difference
116 difference
= abs(logSumExp
- logSumExp_ref)
117 assertion
= difference
< tolerance
118 if (
test%traceable
.and. .not. assertion)
then
120 write(
test%disp
%unit,
"(*(g0,:,' '))")
121 write(
test%disp
%unit,
"(*(g0,:,' '))")
"logSumExp_ref = ", logSumExp_ref
122 write(
test%disp
%unit,
"(*(g0,:,' '))")
"logSumExp = ", logSumExp
123 write(
test%disp
%unit,
"(*(g0,:,' '))")
"difference = ", difference
124 write(
test%disp
%unit,
"(*(g0,:,' '))")
134 logical(
LK) :: assertion
135 real(
RK),
parameter :: LogValue(
*)
= [
log(
0.5*huge(
1._RK)),
log(
0.9*huge(
1._RK)),
log(
0.1*huge(
1._RK)) ]
136 real(
RK),
parameter :: tolerance
= 1.e-10_RK
137 real(
RK),
parameter :: logSumExp_ref
= 710.1881779865910_RK
138 real(
RK) :: logSumExp
139 real(
RK) :: difference
141 difference
= abs(logSumExp
- logSumExp_ref)
142 assertion
= difference
< tolerance
143 if (
test%traceable
.and. .not. assertion)
then
145 write(
test%disp
%unit,
"(*(g0,:,' '))")
146 write(
test%disp
%unit,
"(*(g0,:,' '))")
"logSumExp_ref = ", logSumExp_ref
147 write(
test%disp
%unit,
"(*(g0,:,' '))")
"logSumExp = ", logSumExp
148 write(
test%disp
%unit,
"(*(g0,:,' '))")
"difference = ", difference
149 write(
test%disp
%unit,
"(*(g0,:,' '))")
159 logical(
LK) :: assertion
160 complex(
RK),
parameter :: LogValue(
*)
= [
cmplx(
log(
0.5*huge(
1._RK)),
0._RK,
kind = RK )
&
161 ,
cmplx(
log(
0.9*huge(
1._RK)),
0._RK,
kind = RK )
&
162 ,
cmplx(
log(
0.1*huge(
1._RK)),
0._RK,
kind = RK )
&
164 real(
RK),
parameter :: logSumExp_ref
= cmplx(
710.1881779865910_RK,
0._RK,
RK)
165 complex(
RK),
parameter :: tolerance
= cmplx(
1.e-10_RK,
0._RK,
RK)
166 complex(
RK) :: logSumExp
167 complex(
RK) :: difference
168 logSumExp
= getLogSumExp(LogValue,
cmplx(
maxval(
real(LogValue,
kind=RK)),
kind = RK ))
169 difference
= abs(logSumExp
- logSumExp_ref)
170 assertion
= real(difference,
RK)
< real(tolerance,
RK)
171 if (
test%traceable
.and. .not. assertion)
then
173 write(
test%disp
%unit,
"(*(g0,:,' '))")
174 write(
test%disp
%unit,
"(*(g0,:,' '))")
"logSumExp_ref = ", logSumExp_ref
175 write(
test%disp
%unit,
"(*(g0,:,' '))")
"logSumExp = ", logSumExp
176 write(
test%disp
%unit,
"(*(g0,:,' '))")
"difference = ", difference
177 write(
test%disp
%unit,
"(*(g0,:,' '))")
187 logical(
LK) :: assertion
188 complex(
RK),
parameter :: LogValue(
*)
= [
cmplx(
log(
0.5*huge(
1._RK)),
0._RK,
kind = RK )
&
189 ,
cmplx(
log(
0.9*huge(
1._RK)),
0._RK,
kind = RK )
&
190 ,
cmplx(
log(
0.1*huge(
1._RK)),
0._RK,
kind = RK )
&
192 real(
RK),
parameter :: logSumExp_ref
= cmplx(
710.1881779865910_RK,
0._RK,
RK)
193 complex(
RK),
parameter :: tolerance
= cmplx(
1.e-10_RK,
0._RK,
RK)
194 complex(
RK) :: logSumExp
195 complex(
RK) :: difference
196 logSumExp
= getLogSumExp(LogValue,
cmplx(
maxval(
real(LogValue,
kind=RK)),
kind = RK ))
197 difference
= abs(logSumExp
- logSumExp_ref)
198 assertion
= real(difference,
RK)
< real(tolerance,
RK)
199 if (
test%traceable
.and. .not. assertion)
then
201 write(
test%disp
%unit,
"(*(g0,:,' '))")
202 write(
test%disp
%unit,
"(*(g0,:,' '))")
"logSumExp_ref = ", logSumExp_ref
203 write(
test%disp
%unit,
"(*(g0,:,' '))")
"logSumExp = ", logSumExp
204 write(
test%disp
%unit,
"(*(g0,:,' '))")
"difference = ", difference
205 write(
test%disp
%unit,
"(*(g0,:,' '))")
Generate and return the natural logarithm of the sum of the exponential of the input array robustly (...
This module contains classes and procedures for reporting and handling errors.
character(*, SK), parameter MODULE_NAME
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
integer, parameter RK
The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
This module contains the procedures and interfaces for computing the natural logarithm of the sum of ...
This module contains a simple unit-testing framework for the Fortran libraries, including the ParaMon...
This module contains tests of the module pm_mathLogSumExp.
logical(LK) function test_getLogSumExp_CK_1()
logical(LK) function test_getLogSumExp_RK_1()
logical(LK) function test_getLogSumExp_RK_2()
logical(LK) function test_getLogSumExp_CK_2()
This is the derived type for generating objects to gracefully and verbosely handle runtime unexpected...
This is the derived type test_type for generating objects that facilitate testing of a series of proc...