From edf8e54297139171d7a96925558ca3ccc4917709 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 18 Oct 2020 13:32:28 -0400 Subject: [PATCH 001/172] change in Makefile.manual changed the object name from stdlib_stats_distribution_implementation.o to stdlib_stats_distribution_imp.o --- src/Makefile.manual | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Makefile.manual b/src/Makefile.manual index 1c731b9bb..129dbe553 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -12,7 +12,10 @@ SRC = f18estop.f90 \ stdlib_stats.f90 \ stdlib_stats_mean.f90 \ stdlib_stats_moment.f90 \ - stdlib_stats_var.f90 + stdlib_stats_var.f90 \ + stdlib_stats_distribution.f90 \ + stdlib_stats_distribution_rvs.f90 \ + stdlib_stats_distribution_implementation.f90 \ LIB = libstdlib.a @@ -61,7 +64,13 @@ stdlib_stats_var.o: \ stdlib_optval.o \ stdlib_kinds.o \ stdlib_stats.o - +stdlib_stats_distribution_rvs.o: stdlib_kinds.o +stdlib_stats_distribution.o: \ + stdlib_error.o \ + stdlib_kinds.o \ + stdlib_stats_distribution_rvs.o \ +stdlib_stats_distribution_imp.o: \ + stdlib_stats_distribution.o # Fortran sources that are built from fypp templates stdlib_io.f90: stdlib_io.fypp stdlib_linalg.f90: stdlib_linalg.fypp @@ -71,3 +80,7 @@ stdlib_stats.f90: stdlib_stats.fypp stdlib_stats_mean.f90: stdlib_stats_mean.fypp stdlib_stats_moment.f90: stdlib_stats_moment.fypp stdlib_stats_var.f90: stdlib_stats_var.fypp +stdlib_stats_distribution_rvs.f90: stdlib_stats_distribution_rvs.fypp +stdlib_stats_distribution.f90: stdlib_stats_distribution.fypp +stdlib_stats_distribution_implementation.f90: \ + stdlib_stats_distribution_implementation.fypp \ No newline at end of file From 322a3a8d3dd2c8d3a1ccb9f8f49fca6567f38310 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 20 Dec 2020 11:01:05 -0500 Subject: [PATCH 002/172] Add files via upload --- src/CMakeLists.txt | 5 + src/Makefile.manual | 35 +- src/stdlib_stats_distribution_uniform.fypp | 480 +++++++++++++++++++++ 3 files changed, 505 insertions(+), 15 deletions(-) create mode 100644 src/stdlib_stats_distribution_uniform.fypp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ea7403663..ab827981f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,9 @@ # Create a list of the files to be preprocessed set(fppFiles + stdlib_bitsets.fypp + stdlib_bitsets_64.fypp + stdlib_bitsets_large.fypp stdlib_io.fypp stdlib_linalg.fypp stdlib_linalg_diag.fypp @@ -15,6 +18,8 @@ set(fppFiles stdlib_quadrature.fypp stdlib_quadrature_trapz.fypp stdlib_quadrature_simps.fypp + stdlib_stats_distribution_PRNG.fypp + stdlib_stats_distribution_uniform.fypp ) diff --git a/src/Makefile.manual b/src/Makefile.manual index 129dbe553..60904023c 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -1,5 +1,8 @@ SRC = f18estop.f90 \ stdlib_ascii.f90 \ + stdlib_bitsets.f90 \ + stdlib_bitsets_64.f90 \ + stdlib_bitsets_large.f90 \ stdlib_error.f90 \ stdlib_io.f90 \ stdlib_kinds.f90 \ @@ -13,10 +16,9 @@ SRC = f18estop.f90 \ stdlib_stats_mean.f90 \ stdlib_stats_moment.f90 \ stdlib_stats_var.f90 \ - stdlib_stats_distribution.f90 \ - stdlib_stats_distribution_rvs.f90 \ - stdlib_stats_distribution_implementation.f90 \ - + stdlib_stats_distribution_PRNG.f90\ + stdlib_stats_distribution_uniform.f90 + LIB = libstdlib.a @@ -43,6 +45,9 @@ clean: # Fortran module dependencies f18estop.o: stdlib_error.o +stdlib_bitsets.o: stdlib_kinds.o +stdlib_bitsets_64.o: stdlib_bitsets.o +stdlib_bitsets_large.o: stdlib_bitsets.o stdlib_error.o: stdlib_optval.o stdlib_io.o: \ stdlib_error.o \ @@ -64,14 +69,16 @@ stdlib_stats_var.o: \ stdlib_optval.o \ stdlib_kinds.o \ stdlib_stats.o -stdlib_stats_distribution_rvs.o: stdlib_kinds.o -stdlib_stats_distribution.o: \ - stdlib_error.o \ - stdlib_kinds.o \ - stdlib_stats_distribution_rvs.o \ -stdlib_stats_distribution_imp.o: \ - stdlib_stats_distribution.o +stdlib_stats_distribution_PRNG.o: stdlib_kinds.o +stdlib_stats_distribution_uniform.o: \ + stdlib_kinds.o \ + stdlib_error.o \ + stdlib_stats_distribution_PRNG.o + # Fortran sources that are built from fypp templates +stdlib_bitsets_64.f90: stdlib_bitsets_64.fypp +stdlib_bitsets_large.f90: stdlib_bitsets_large.fypp +stdlib_bitsets.f90: stdlib_bitsets.fypp stdlib_io.f90: stdlib_io.fypp stdlib_linalg.f90: stdlib_linalg.fypp stdlib_linalg_diag.f90: stdlib_linalg_diag.fypp @@ -80,7 +87,5 @@ stdlib_stats.f90: stdlib_stats.fypp stdlib_stats_mean.f90: stdlib_stats_mean.fypp stdlib_stats_moment.f90: stdlib_stats_moment.fypp stdlib_stats_var.f90: stdlib_stats_var.fypp -stdlib_stats_distribution_rvs.f90: stdlib_stats_distribution_rvs.fypp -stdlib_stats_distribution.f90: stdlib_stats_distribution.fypp -stdlib_stats_distribution_implementation.f90: \ - stdlib_stats_distribution_implementation.fypp \ No newline at end of file +stdlib_stats_distribution_PRNG.f90: stdlib_stats_distribution_PRNG.fypp +stdlib_stats_distribution_uniform.f90: stdlib_stats_distribution_uniform.fypp \ No newline at end of file diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp new file mode 100644 index 000000000..1b767e48b --- /dev/null +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -0,0 +1,480 @@ +#:include "common.fypp" +#:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES +#:set ALL_KINDS_TYPES = INT_KINDS_TYPES + RC_KINDS_TYPES +Module stdlib_stats_distribution_uniform + use stdlib_kinds + use stdlib_error, only : error_stop + use stdlib_stats_distribution_PRNG, only : dist_rand + + implicit none + private + + real(dp), parameter :: MESENNE_NUMBER = 1.0_dp / (2.0_dp ** 53 - 1.0_dp) + integer(int64), parameter :: INT_ONE = 1_int64 + + public :: uniform_distribution_rvs + public :: uniform_distribution_pdf + public :: uniform_distribution_cdf + public :: shuffle + + interface uniform_distribution_rvs + !! Version experimental + !! + !! Get uniformly distributed random variate for integer, real and complex + !! ([Specification](../page/specs/stdlib_stats_distribution_uniform.html# + !! description)) + + module procedure unif_dist_rvs_0_rsp ! 0 dummy variable + + #:for k1, t1 in ALL_KINDS_TYPES + module procedure unif_dist_rvs_1_${t1[0]}$${k1}$ ! 1 dummy variable + #:endfor + + #:for k1, t1 in ALL_KINDS_TYPES + module procedure unif_dist_rvs_${t1[0]}$${k1}$ ! 2 dummy variables + #:endfor + + #:for k1, t1 in ALL_KINDS_TYPES + module procedure unif_dist_rvs_array_${t1[0]}$${k1}$ ! 3 dummy variables + #:endfor + end interface uniform_distribution_rvs + + interface uniform_distribution_pdf + !! Version experiment + !! + !! Get uniform distribution probability density (pdf) for integer, real and complex variables + !! ([Specification](../page/specs/stdlib_stats_distribution_uniform.html# + !! description)) + + #:for k1, t1 in ALL_KINDS_TYPES + module procedure unif_dist_pdf_${t1[0]}$${k1}$ + #:endfor + end interface uniform_distribution_pdf + + interface uniform_distribution_cdf + !! Version experimental + !! + !! Get uniform distribution cumulative distribution function (cdf) for integer, real and complex variables + !! ([Specification](../page/specs/stdlib_stats_distribution_uniform.html# + !! description)) + !! + #:for k1, t1 in ALL_KINDS_TYPES + module procedure unif_dist_cdf_${t1[0]}$${k1}$ + #:endfor + end interface uniform_distribution_cdf + + interface shuffle + !! Version experimental + !! + !! Fisher-Yates shuffle algorithm for a rank one array of integer, real and complex variables + !! ([Specification](../page/specs/stdlib_stats_distribution_uniform.html# + !! description)) + !! + #:for k1, t1 in ALL_KINDS_TYPES + module procedure shuffle_${t1[0]}$${k1}$ + #:endfor + end interface shuffle + + + contains + + #:for k1, t1 in INT_KINDS_TYPES + impure elemental function unif_dist_rvs_1_${t1[0]}$${k1}$(scale) result(res) + ! Uniformly distributed integer in [0, scale] + ! Bitmask with rejection + ! https://www.pcg-random.org/posts/bounded-rands.html + ! + ! Fortran 90 translated from c by Jim-215-fisher + ${t1}$, intent(in) :: scale + ${t1}$ :: res, u, mask, n + integer :: zeros, bits_left, bits + + n = scale + if(n == 0_${k1}$) call error_stop("Error: Uniform distribution scale" & + //" parameter must be non-zero") + zeros = leadz(n) + bits = bit_size(n) - zeros + mask = shiftr(not(0_${k1}$), zeros) + L1 : do + u = dist_rand(n) + res = iand(u, mask) + if(res <= n) exit L1 + bits_left = zeros + L2 : do + if(bits_left < bits) exit L2 + u = shiftr(u, bits) + res = iand(u, mask) + if(res <= n) exit L1 + bits_left = bits_left - bits + end do L2 + end do L1 + return + end function unif_dist_rvs_1_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in INT_KINDS_TYPES + impure elemental function unif_dist_rvs_${t1[0]}$${k1}$(loc, scale) & + result( res ) + ! Uniformly distributed integer in [loc, loc + scale] + ! + ${t1}$, intent(in) :: loc, scale + ${t1}$ :: res + + if(scale == 0_${k1}$) call error_stop("Error: Uniform distribution" & + //" scale parameter must be non-zero") + res = loc + unif_dist_rvs_1_${t1[0]}$${k1}$(scale) + return + end function unif_dist_rvs_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in REAL_KINDS_TYPES + impure elemental function unif_dist_rvs_0_${t1[0]}$${k1}$( ) result(res) + ! Uniformly distributed float in [0,1] + ! Based on the paper by Frederic Goualard, "Generating Random Floating- + ! Point Numbers By Dividing Integers: a Case Study", Proceedings of + ! ICCS 2020, June 20202, Amsterdam, Netherlands + ! + ${t1}$ :: res + integer(int64) :: tmp + + tmp = shiftr(dist_rand(INT_ONE), 11) ! Get random from [0,2^53-1] + res = real(tmp * MESENNE_NUMBER, kind =${k1}$) ! convert to [0,1] + return + end function unif_dist_rvs_0_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in REAL_KINDS_TYPES + impure elemental function unif_dist_rvs_1_${t1[0]}$${k1}$(scale) result(res) + ! Uniformly distributed float in [0, scale] + ! + ${t1}$, intent(in) :: scale + ${t1}$ :: res + + if(scale == 0_${k1}$) call error_stop("Error: Uniform distribution" & + //" scale parameter must be non-zero") + res = scale * unif_dist_rvs_0_${t1[0]}$${k1}$( ) + return + end function unif_dist_rvs_1_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in REAL_KINDS_TYPES + impure elemental function unif_dist_rvs_${t1[0]}$${k1}$(loc, scale) & + result(res) + ! Uniformly distributed float in [loc, loc + scale] + ! + ${t1}$, intent(in) :: loc, scale + ${t1}$ :: res + + if(scale == 0_${k1}$) call error_stop("Error: Uniform distribution" & + //" scale parameter must be non-zero") + res = loc + scale * unif_dist_rvs_0_${t1[0]}$${k1}$( ) + return + end function unif_dist_rvs_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in CMPLX_KINDS_TYPES + impure elemental function unif_dist_rvs_1_${t1[0]}$${k1}$(scale) result(res) + ! Uniformly distributed complex in [(0,0i), (scale, i(scale)] + ! The real part and imaginary part are independent of each other, so that + ! the joint distribution is on an unit square [(0,0i), scale,i(scale)] + ! + ${t1}$, intent(in) :: scale + ${t1}$ :: res + integer(int64) :: tmp + real(${k1}$) :: r1, r2 + + if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error: Uniform" & + //" distribution scale parameter must be non-zero") + r1 = unif_dist_rvs_0_r${k1}$( ) + if(scale%re == 0.0_${k1}$) then + res%im = scale%im * r1 + res%re = 0.0_${k1}$ + elseif(scale%im == 0.0_${k1}$) then + res%re = scale%re * r1 + res%im = 0.0_${k1}$ + else + r2 = unif_dist_rvs_0_r${k1}$( ) + res%re = scale%re * r1 + res%im = scale%im * r2 + endif + return + end function unif_dist_rvs_1_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in CMPLX_KINDS_TYPES + impure elemental function unif_dist_rvs_${t1[0]}$${k1}$(loc, scale) & + result(res) + ! Uniformly distributed complex in [(loc,iloc), (loc + scale, i(loc + scale)] + ! The real part and imaginary part are independent of each other, so that + ! the joint distribution is on an unit square [(loc,iloc), (loc + scale, + ! i(loc + scale))] + ! + ${t1}$, intent(in) :: loc, scale + ${t1}$ :: res + integer(int64) :: tmp + real(${k1}$) :: r1, r2 + + if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error: Uniform" & + //" distribution scale parameter must be non-zero") + r1 = unif_dist_rvs_0_r${k1}$( ) + if(scale%re == 0.0_${k1}$) then + res%re = loc%re + res%im = loc%im + scale%im * r1 + elseif(scale%im == 0.0_${k1}$) then + res%re = loc%re + scale%re * r1 + res%im = loc%im + else + r2 = unif_dist_rvs_0_r${k1}$( ) + res%re = loc%re + scale%re * r1 + res%im = loc%im + scale%im * r2 + endif + return + end function unif_dist_rvs_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in INT_KINDS_TYPES + function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & + result(res) + ${t1}$, intent(in) :: loc, scale + ${t1}$, allocatable :: res(:) + ${t1}$ :: u, mask, n, nn + integer, intent(in) :: array_size + integer :: i, zeros, bits_left, bits + + n = scale + if(n == 0_${k1}$) call error_stop("Error: Uniform distribution" & + //" scale parameter must be non-zero") + allocate(res(array_size)) + zeros = leadz(n) + bits = bit_size(n) - zeros + mask = shiftr(not(0_${k1}$), zeros) + do i = 1, array_size + L1 : do + u = dist_rand(n) + nn = iand(u, mask) + if(nn <= n) exit L1 + bits_left = zeros + L2 : do + if(bits_left < bits) exit L2 + u = shiftr(u, bits) + nn = iand(u, mask) + if(nn <= n) exit L1 + bits_left = bits_left - bits + end do L2 + end do L1 + res(i) = loc + nn + end do + return + end function unif_dist_rvs_array_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in REAL_KINDS_TYPES + function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & + result(res) + ${t1}$, intent(in) :: loc, scale + ${t1}$, allocatable :: res(:) + ${t1}$ :: t + integer, intent(in) :: array_size + integer(int64) :: tmp + integer :: i + + + if(scale == 0_${k1}$) call error_stop("Error: Uniform distribution" & + //" scale parameter must be non-zero") + allocate(res(array_size)) + do i = 1, array_size + tmp = shiftr(dist_rand(INT_ONE), 11) + t = real(tmp * MESENNE_NUMBER, kind = ${k1}$) + res(i) = loc + scale * t + enddo + return + end function unif_dist_rvs_array_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in CMPLX_KINDS_TYPES + function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & + result(res) + ${t1}$, intent(in) :: loc, scale + ${t1}$, allocatable :: res(:) + ${t1}$ :: t + real(${k1}$) :: r1, r2 + integer, intent(in) :: array_size + integer(int64) :: tmp + integer :: i + + + if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error: Uniform" & + //" distribution scale parameter must be non-zero") + allocate(res(array_size)) + do i = 1, array_size + tmp = shiftr(dist_rand(INT_ONE), 11) + r1 = real(tmp * MESENNE_NUMBER, kind = ${k1}$) + if(scale%re == 0.0_${k1}$) then + t%re = loc%re + t%im = loc%im + scale%im * r1 + elseif(scale%im == 0.0_${k1}$) then + t%re = loc%re + scale%re * r1 + t%im = loc%im + else + tmp = shiftr(dist_rand(INT_ONE), 11) + r2 = real(tmp * MESENNE_NUMBER, kind = ${k1}$) + t%re = loc%re + scale%re * r1 + t%im = loc%im + scale%im * r2 + endif + res(i) = t + enddo + return + end function unif_dist_rvs_array_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in INT_KINDS_TYPES + elemental function unif_dist_pdf_${t1[0]}$${k1}$(x, loc, scale) result(res) + ${t1}$, intent(in) :: x, loc, scale + real :: res + + if(scale == 0) then + res = 0.0 + elseif(x < loc .or. x >loc + scale) then + res = 0.0 + else + res = 1. / (scale + 1) + end if + return + end function unif_dist_pdf_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in REAL_KINDS_TYPES + elemental function unif_dist_pdf_${t1[0]}$${k1}$(x, loc, scale) result(res) + ${t1}$, intent(in) :: x, loc, scale + real :: res + + if(scale == 0.0_${k1}$) then + res = 0.0 + elseif(x <= loc .or. x >= (loc + scale)) then + res = 0.0 + else + res = 1.0 / scale + end if + return + end function unif_dist_pdf_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in CMPLX_KINDS_TYPES + elemental function unif_dist_pdf_${t1[0]}$${k1}$(x, loc, scale) result(res) + ${t1}$, intent(in) :: x, loc, scale + real :: res + + if(scale == (0.0_${k1}$,0.0_${k1}$)) then + res = 0.0 + elseif((x%re >= loc%re .and. x%re <= loc%re + scale%re) .and. & + (x%im >= loc%im .and. x%im <= loc%im + scale%im)) then + res = 1.0 / (scale%re * scale%im) + else + res = 0.0 + end if + return + end function unif_dist_pdf_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in INT_KINDS_TYPES + elemental function unif_dist_cdf_${t1[0]}$${k1}$(x, loc, scale) result(res) + ${t1}$, intent(in) :: x, loc, scale + real :: res + + if(scale == 0) then + res = 0.0 + elseif(x < loc) then + res = 0.0 + elseif(x >= loc .and. x <= (loc + scale)) then + res = real((x - loc + 1)) / real((scale + 1)) + else + res = 1.0 + end if + return + end function unif_dist_cdf_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in REAL_KINDS_TYPES + elemental function unif_dist_cdf_${t1[0]}$${k1}$(x, loc, scale) result(res) + ${t1}$, intent(in) :: x, loc, scale + real :: res + + if(scale == 0.0_${k1}$) then + res = 0.0 + elseif(x < loc) then + res = 0.0 + elseif(x >= loc .and. x <= (loc + scale)) then + res = (x - loc) / scale + else + res = 1.0 + end if + return + end function unif_dist_cdf_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in CMPLX_KINDS_TYPES + elemental function unif_dist_cdf_${t1[0]}$${k1}$(x, loc, scale) result(res) + ${t1}$, intent(in) :: x, loc, scale + real :: res + logical :: r1, r2, i1, i2 + + if(scale == (0.0_${k1}$,0.0_${k1}$)) then + res = 0.0 + return + endif + r1 = x%re < loc%re + r2 = x%re > (loc%re + scale%re) + i1 = x%im < loc%im + i2 = x%im > (loc%im + scale%im) + if(r1 .or. i1) then + res = 0.0 + elseif((.not. r1) .and. (.not. r2) .and. i2) then + res = (x%re - loc%re) / scale%re + elseif((.not. i1) .and. (.not. i2) .and. r2) then + res = (x%im - loc%im) / scale%im + elseif((.not. r1) .and. (.not. r2) .and. (.not. i1) .and. (.not. i2)) & + then + res = (x%re - loc%re) * (x%im - loc%im) / (scale%re * scale%im) + elseif(r2 .and. i2)then + res = 1.0 + end if + return + end function unif_dist_cdf_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in ALL_KINDS_TYPES + function shuffle_${t1[0]}$${k1}$( list ) result(res) + ${t1}$, intent(in) :: list(:) + ${t1}$, allocatable :: res(:) + ${t1}$ :: tmp + integer :: n, i, j + + n = size(list) + allocate(res(n), source=list) + do i = 1, n - 1 + j = uniform_distribution_rvs(n - i) + i + tmp = res(i) + res(i) = res(j) + res(j) = tmp + end do + return + end function shuffle_${t1[0]}$${k1}$ + + #:endfor +end module stdlib_stats_distribution_uniform \ No newline at end of file From 4b336dedfc040201aaeaa048a9fa6bf61c4e1984 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 20 Dec 2020 11:09:31 -0500 Subject: [PATCH 003/172] initial commit --- src/tests/stats/CMakeLists.txt | 1 + src/tests/stats/Makefile.manual | 6 +- src/tests/stats/test_distribution_uniform.f90 | 871 ++++++++++++++++++ 3 files changed, 876 insertions(+), 2 deletions(-) create mode 100644 src/tests/stats/test_distribution_uniform.f90 diff --git a/src/tests/stats/CMakeLists.txt b/src/tests/stats/CMakeLists.txt index 36ffc7aeb..0f40ea69b 100644 --- a/src/tests/stats/CMakeLists.txt +++ b/src/tests/stats/CMakeLists.txt @@ -5,6 +5,7 @@ ADDTEST(moment) ADDTEST(rawmoment) ADDTEST(var) ADDTEST(varn) +ADDTEST(distribution_uniform) if(DEFINED CMAKE_MAXIMUM_RANK) if(${CMAKE_MAXIMUM_RANK} GREATER 7) diff --git a/src/tests/stats/Makefile.manual b/src/tests/stats/Makefile.manual index aacaf98ab..ab425a69c 100644 --- a/src/tests/stats/Makefile.manual +++ b/src/tests/stats/Makefile.manual @@ -1,3 +1,5 @@ -PROGS_SRC = test_mean.f90 test_moment.f90 test_var.f90 -include ../Makefile.manual.test.mk +PROGS_SRC = test_mean.f90 test_moment.f90 test_var.f90 \ + test_distribution_uniform.f90 + +include ../Makefile.manual.test.mk \ No newline at end of file diff --git a/src/tests/stats/test_distribution_uniform.f90 b/src/tests/stats/test_distribution_uniform.f90 new file mode 100644 index 000000000..da30cde4e --- /dev/null +++ b/src/tests/stats/test_distribution_uniform.f90 @@ -0,0 +1,871 @@ +program test_distribution_uniform + use stdlib_error, only : check + use stdlib_kinds + use stdlib_stats_distribution_PRNG, only : random_seed, dist_rand + use stdlib_stats_distribution_uniform, & + uni_rvs => uniform_distribution_rvs, & + uni_pdf => uniform_distribution_pdf, & + uni_cdf => uniform_distribution_cdf + + implicit none + logical :: warn = .true. + real(sp), parameter :: sptol = 1000 * epsilon(1.0_sp) + real(dp), parameter :: dptol = 1000 * epsilon(1.0_dp) + real(qp), parameter :: qptol = 1000 * epsilon(1.0_qp) + integer :: put, get + complex :: loc, scale + real :: a(3,4,5), b(3,4,5), x(3,4,5) + put = 135792468 + put = 1234567 + call random_seed(put, get) + print *, uni_cdf(0.5,0.,1.) ! a cumulative at 0.5 in [0., 1.] + print *, uni_cdf(0.7,-1.0,2.0) ! a cumulative at 0.7 in [-1.0, 1.0] + + print *, uni_cdf(6, 2, 10) ! a cumulative at 6 in [2, 10] + + a(:,:,:) = -1.0 + b(:,:,:) = 2.0 + x = reshape(uni_rvs(-1.0,2.0,60),[3,4,5]) ! uniform random variates array + print *, uni_cdf(x,a,b) ! cumulative array in [-1.0, 1.0] + + loc = (0., 0.) + scale=(2., 1.) + print *, uni_cdf((1.2,0.5), loc, scale) + stop + call test_shuffle + + call test_uni_rvs_0 + + call test_uni_rvs_iint8 + call test_uni_rvs_iint16 + call test_uni_rvs_iint32 + call test_uni_rvs_iint64 + call test_uni_rvs_rsp + call test_uni_rvs_rdp + call test_uni_rvs_rqp + call test_uni_rvs_csp + call test_uni_rvs_cdp + call test_uni_rvs_cqp + + call test_uni_pdf_iint8 + call test_uni_pdf_iint16 + call test_uni_pdf_iint32 + call test_uni_pdf_iint64 + call test_uni_pdf_rsp + call test_uni_pdf_rdp + call test_uni_pdf_rqp + call test_uni_pdf_csp + call test_uni_pdf_cdp + call test_uni_pdf_cqp + + call test_uni_cdf_iint8 + call test_uni_cdf_iint16 + call test_uni_cdf_iint32 + call test_uni_cdf_iint64 + call test_uni_cdf_rsp + call test_uni_cdf_rdp + call test_uni_cdf_rqp + call test_uni_cdf_csp + call test_uni_cdf_cdp + call test_uni_cdf_cqp + stop + + contains + + subroutine test_shuffle + integer :: n(10), na(10) = [10, 6, 9, 2, 8, 1, 3, 5, 7, 4] + real :: x(10), xa(10)= [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, & + 7.0, 6.0] + complex :: z(10), za(10)=[(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), & + (1.0, 1.0), (5.0, 5.0), (9.0, 9.0), & + (6.0, 6.0), (3.0, 3.0), (2.0, 2.0), & + (10.0, 10.0)] + integer :: i, put, get + + do i=1, 10 + n(i) = i + x(i) = real(i) + z(i) = cmplx(real(i),real(i)) + end do + put = 32165498 + call random_seed(put, get) + n(:) = shuffle(n) + x(:) = shuffle(x) + z(:) = shuffle(z) + call check(all(n == na), & + msg="Integer shuffle failed test", warn=warn) + call check(all(x == xa), & + msg="Real shuffle failed test", warn=warn) + call check(all(z == za), & + msg="Complex shuffle failed test", warn=warn) + end subroutine test_shuffle + + subroutine test_uni_rvs_0 + integer :: i, j, freq(0:1000), num=10000000 + real(dp) :: chisq, expct + + print *,"" + print *, "Test uniform random generator with chi-squared" + freq = 0 + do i = 1, num + j = 1000 * uni_rvs( ) + freq(j) = freq(j) + 1 + end do + chisq = 0.0_dp + expct = num / 1000 + do i = 0, 999 + chisq = chisq + (freq(i) - expct) ** 2 / expct + end do + write(*,*) "The critical values for chi-squared with 1000 d. of f. are" & + //" 1143.92" + write(*,*) "Chi-squared for uniform random generator is : ", chisq + call check((chisq < 1143.9) , & + msg="uniform randomness failed chi-squared test", warn=warn) + end subroutine test_uni_rvs_0 + + subroutine test_uni_rvs_iint8 + integer(int8) :: res(15), scale, loc + integer :: i, n, seed, get, k + + integer(int8) :: ans(15) = [47, 99, 43, 37, 48, 30, 27, 100, 30, 33, 21, & + 103, 55, 54, 110] + + print *, "Test uniform_distribution_rvs_iint8" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = 15_int8; scale = 100_int8 + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(res == ans), & + msg="uniform_distribution_rvs_iint8 failed", warn=warn) + end subroutine test_uni_rvs_iint8 + + subroutine test_uni_rvs_iint16 + integer(int16) :: res(15), scale, loc + integer :: i, n, seed, get, k + + integer(int16) :: ans(15) = [25, 4, 81, 98, 49, 34, 32, 62, 115, 112, 26, & + 20, 37, 100, 82] + + print *, "Test uniform_distribution_rvs_iint16" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = 15_int16; scale = 100_int16 + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(res == ans), & + msg="uniform_distribution_rvs_iint16 failed", warn=warn) + end subroutine test_uni_rvs_iint16 + + subroutine test_uni_rvs_iint32 + integer(int32) :: res(15), scale, loc + integer :: i, n, seed, get, k + + integer(int32) :: ans(15) = [19, 52, 56, 20, 59, 44, 34, 102, 19, 39, 60, & + 50, 97, 56, 67] + + print *, "Test uniform_distribution_rvs_iint32" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = 15_int32; scale = 100_int32 + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(res == ans), & + msg="uniform_distribution_rvs_iint32 failed", warn=warn) + end subroutine test_uni_rvs_iint32 + + subroutine test_uni_rvs_iint64 + integer(int64) :: res(15), scale, loc + integer :: i, n, seed, get, k + + integer(int64) :: ans(15) = [76, 45, 43, 75, 76, 15, 25, 24, 114, 113, 94, & + 29, 109, 93, 89] + + print *, "Test uniform_distribution_rvs_iint64" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = 15_int64; scale = 100_int64 + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(res == ans), & + msg="uniform_distribution_rvs_iint64 failed", warn=warn) + end subroutine test_uni_rvs_iint64 + + subroutine test_uni_rvs_rsp + real(sp) :: res(15), scale, loc + integer :: i, n, seed, get, k + + real(sp) :: ans(15) = & + [0.914826628538749186958511927514337003_sp, & + 0.367330098664966409049981166390352882_sp, & + 1.77591243057709280428468900936422870_sp, & + 0.885921308987590139238932351872790605_sp, & + 0.950735656542987861428173346212133765_sp, & + -0.659562573857055134407545438079978339_sp, & + -0.116661718506947176265953203255776316_sp, & + 0.837391893893859151631886561517603695_sp, & + -0.703954396598600540269075054311542772_sp, & + 0.382592729851141566399519433616660535_sp, & + -0.132472493978185168472805344208609313_sp, & + -0.878723366294216184924081858298450243_sp, & + -0.901660046141515819639877804547722917_sp, & + -0.164090614147737401395943379611708224_sp, & + -0.333886718190384290672056977200554684_sp] + + print *, "Test uniform_distribution_rvs_rsp" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = -1.0_sp; scale = 2.0_sp + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(abs(res - ans) < sptol), & + msg="uniform_distribution_rvs_rsp failed", warn=warn) + end subroutine test_uni_rvs_rsp + + subroutine test_uni_rvs_rdp + real(dp) :: res(15), scale, loc + integer :: i, n, seed, get, k + + real(dp) :: ans(15) = & + [0.914826628538749186958511927514337003_dp, & + 0.367330098664966409049981166390352882_dp, & + 1.77591243057709280428468900936422870_dp, & + 0.885921308987590139238932351872790605_dp, & + 0.950735656542987861428173346212133765_dp, & + -0.659562573857055134407545438079978339_dp, & + -0.116661718506947176265953203255776316_dp, & + 0.837391893893859151631886561517603695_dp, & + -0.703954396598600540269075054311542772_dp, & + 0.382592729851141566399519433616660535_dp, & + -0.132472493978185168472805344208609313_dp, & + -0.878723366294216184924081858298450243_dp, & + -0.901660046141515819639877804547722917_dp, & + -0.164090614147737401395943379611708224_dp, & + -0.333886718190384290672056977200554684_dp] + + print *, "Test uniform_distribution_rvs_rdp" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = -1.0_dp; scale = 2.0_dp + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(abs(res - ans) < dptol), & + msg="uniform_distribution_rvs_rdp failed", warn=warn) + end subroutine test_uni_rvs_rdp + + subroutine test_uni_rvs_rqp + real(qp) :: res(15), scale, loc + integer :: i, n, seed, get, k + + real(qp) :: ans(15) = & + [0.914826628538749186958511927514337003_qp, & + 0.367330098664966409049981166390352882_qp, & + 1.77591243057709280428468900936422870_qp, & + 0.885921308987590139238932351872790605_qp, & + 0.950735656542987861428173346212133765_qp, & + -0.659562573857055134407545438079978339_qp, & + -0.116661718506947176265953203255776316_qp, & + 0.837391893893859151631886561517603695_qp, & + -0.703954396598600540269075054311542772_qp, & + 0.382592729851141566399519433616660535_qp, & + -0.132472493978185168472805344208609313_qp, & + -0.878723366294216184924081858298450243_qp, & + -0.901660046141515819639877804547722917_qp, & + -0.164090614147737401395943379611708224_qp, & + -0.333886718190384290672056977200554684_qp] + + print *, "Test uniform_distribution_rvs_rqp" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = -1.0_qp; scale = 2.0_qp + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(abs(res - ans) < qptol), & + msg="uniform_distribution_rvs_rqp failed", warn=warn) + end subroutine test_uni_rvs_rqp + + subroutine test_uni_rvs_csp + complex(sp) :: res(15), scale, loc + integer :: i, n, seed, get, k + + complex(sp) :: ans(15) = [(0.457413314269374593479255963757168502_sp, & + 0.183665049332483204524990583195176441_sp), & + (0.887956215288546402142344504682114348_sp, & + 0.442960654493795069619466175936395302_sp), & + (0.475367828271493930714086673106066883_sp, & + 0.170218713071472432796227280960010830_sp), & + (0.441669140746526411867023398372111842_sp, & + 0.918695946946929575815943280758801848_sp), & + (0.148022801700699729865462472844228614_sp, & + 0.691296364925570783199759716808330268_sp), & + (-6.623624698909258423640267210430465639E-0002_sp, & + 0.560638316852891907537959070850774879_sp), & + (-0.450830023070757909819938902273861459_sp, & + 0.917954692926131299302028310194145888_sp), & + (-0.166943359095192145336028488600277342_sp, & + 1.05997401970850635422038976685144007_sp), & + (-0.429652190199228276035192664039641386_sp, & + 0.523558274341032421628217008446881664_sp), & + (0.427181091476823815433760955784237012_sp, & + 1.34628934976074521312483511792379431_sp), & + (-0.343281426018765739582860874179459643_sp, & + 1.15357331316264255516301773241139017_sp), & + (-0.127590074749816595467422075671493076_sp, & + 1.06891199479835175001340985545539297_sp), & + (0.262287586904722758163188700564205647_sp, & + 1.29508919831907332032017166056903079_sp), & + (-0.192677407376582732201342196276527829_sp, & + 1.32794925614337933073016984053538181_sp), & + (-0.264742129752461530234342035328154452_sp, & + 1.01282963412172621886497836385387927_sp)] + + print *, "Test uniform_distribution_rvs_csp" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = (-0.5_sp,0.5_sp); scale = (1.0_sp, 1.0_sp) + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(abs(res%re - ans%re) < sptol) .and. & + all(abs(res%im - ans%im) < sptol), & + msg="uniform_distribution_rvs_csp failed", warn=warn) + end subroutine test_uni_rvs_csp + + subroutine test_uni_rvs_cdp + complex(dp) :: res(15), scale, loc + integer :: i, n, seed, get, k + + complex(dp) :: ans(15) = [(0.457413314269374593479255963757168502_dp, & + 0.183665049332483204524990583195176441_dp), & + (0.887956215288546402142344504682114348_dp, & + 0.442960654493795069619466175936395302_dp), & + (0.475367828271493930714086673106066883_dp, & + 0.170218713071472432796227280960010830_dp), & + (0.441669140746526411867023398372111842_dp, & + 0.918695946946929575815943280758801848_dp), & + (0.148022801700699729865462472844228614_dp, & + 0.691296364925570783199759716808330268_dp), & + (-6.623624698909258423640267210430465639E-0002_dp, & + 0.560638316852891907537959070850774879_dp), & + (-0.450830023070757909819938902273861459_dp, & + 0.917954692926131299302028310194145888_dp), & + (-0.166943359095192145336028488600277342_dp, & + 1.05997401970850635422038976685144007_dp), & + (-0.429652190199228276035192664039641386_dp, & + 0.523558274341032421628217008446881664_dp), & + (0.427181091476823815433760955784237012_dp, & + 1.34628934976074521312483511792379431_dp), & + (-0.343281426018765739582860874179459643_dp, & + 1.15357331316264255516301773241139017_dp), & + (-0.127590074749816595467422075671493076_dp, & + 1.06891199479835175001340985545539297_dp), & + (0.262287586904722758163188700564205647_dp, & + 1.29508919831907332032017166056903079_dp), & + (-0.192677407376582732201342196276527829_dp, & + 1.32794925614337933073016984053538181_dp), & + (-0.264742129752461530234342035328154452_dp, & + 1.01282963412172621886497836385387927_dp)] + + print *, "Test uniform_distribution_rvs_cdp" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = (-0.5_dp,0.5_dp); scale = (1.0_dp, 1.0_dp) + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(abs(res%re - ans%re) < dptol) .and. & + all(abs(res%im - ans%im) < dptol), & + msg="uniform_distribution_rvs_cdp failed", warn=warn) + end subroutine test_uni_rvs_cdp + + subroutine test_uni_rvs_cqp + complex(qp) :: res(15), scale, loc + integer :: i, n, seed, get, k + + complex(qp) :: ans(15) = [(0.457413314269374593479255963757168502_qp, & + 0.183665049332483204524990583195176441_qp), & + (0.887956215288546402142344504682114348_qp, & + 0.442960654493795069619466175936395302_qp), & + (0.475367828271493930714086673106066883_qp, & + 0.170218713071472432796227280960010830_qp), & + (0.441669140746526411867023398372111842_qp, & + 0.918695946946929575815943280758801848_qp), & + (0.148022801700699729865462472844228614_qp, & + 0.691296364925570783199759716808330268_qp), & + (-6.623624698909258423640267210430465639E-0002_qp, & + 0.560638316852891907537959070850774879_qp), & + (-0.450830023070757909819938902273861459_qp, & + 0.917954692926131299302028310194145888_qp), & + (-0.166943359095192145336028488600277342_qp, & + 1.05997401970850635422038976685144007_qp), & + (-0.429652190199228276035192664039641386_qp, & + 0.523558274341032421628217008446881664_qp), & + (0.427181091476823815433760955784237012_qp, & + 1.34628934976074521312483511792379431_qp), & + (-0.343281426018765739582860874179459643_qp, & + 1.15357331316264255516301773241139017_qp), & + (-0.127590074749816595467422075671493076_qp, & + 1.06891199479835175001340985545539297_qp), & + (0.262287586904722758163188700564205647_qp, & + 1.29508919831907332032017166056903079_qp), & + (-0.192677407376582732201342196276527829_qp, & + 1.32794925614337933073016984053538181_qp), & + (-0.264742129752461530234342035328154452_qp, & + 1.01282963412172621886497836385387927_qp)] + + print *, "Test uniform_distribution_rvs_cqp" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = (-0.5_qp,0.5_qp); scale = (1.0_qp, 1.0_qp) + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(abs(res%re - ans%re) < qptol) .and. & + all(abs(res%im - ans%im) < qptol), & + msg="uniform_distribution_rvs_cqp failed", warn=warn) + end subroutine test_uni_rvs_cqp + + + subroutine test_uni_pdf_iint8 + integer(int8) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(1.96078438E-02, i=1,15)] + + print *, "Test uniform_distribution_pdf_iint8" + seed = 147258639 + call random_seed(seed, get) + loc = 0_int8; scale = 50_int8 + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_iint8 failed", warn=warn) + end subroutine test_uni_pdf_iint8 + + subroutine test_uni_pdf_iint16 + integer(int16) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(1.96078438E-02, i=1,15)] + + print *, "Test uniform_distribution_pdf_iint16" + seed = 147258639 + call random_seed(seed, get) + loc = 0_int16; scale = 50_int16 + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_iint16 failed", warn=warn) + end subroutine test_uni_pdf_iint16 + + subroutine test_uni_pdf_iint32 + integer(int32) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(1.96078438E-02, i=1,15)] + + print *, "Test uniform_distribution_pdf_iint32" + seed = 147258639 + call random_seed(seed, get) + loc = 0_int32; scale = 50_int32 + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_iint32 failed", warn=warn) + end subroutine test_uni_pdf_iint32 + + subroutine test_uni_pdf_iint64 + integer(int64) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(1.96078438E-02, i=1,15)] + + print *, "Test uniform_distribution_pdf_iint64" + seed = 147258639 + call random_seed(seed, get) + loc = 0_int64; scale = 50_int64 + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_iint64 failed", warn=warn) + end subroutine test_uni_pdf_iint64 + + subroutine test_uni_pdf_rsp + real(sp) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(0.5, i=1,15)] + + print *, "Test uniform_distribution_pdf_rsp" + seed = 147258639 + call random_seed(seed, get) + loc = 0.0_sp; scale = 2.0_sp + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_rsp failed", warn=warn) + end subroutine test_uni_pdf_rsp + + subroutine test_uni_pdf_rdp + real(dp) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(0.5, i=1,15)] + + print *, "Test uniform_distribution_pdf_rdp" + seed = 147258639 + call random_seed(seed, get) + loc = 0.0_dp; scale = 2.0_dp + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_rdp failed", warn=warn) + end subroutine test_uni_pdf_rdp + + subroutine test_uni_pdf_rqp + real(qp) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(0.5, i=1,15)] + + print *, "Test uniform_distribution_pdf_rqp" + seed = 147258639 + call random_seed(seed, get) + loc = 0.0_qp; scale = 2.0_qp + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_rqp failed", warn=warn) + end subroutine test_uni_pdf_rqp + + subroutine test_uni_pdf_csp + complex(sp) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(1.0, i=1,15)] + + print *, "Test uniform_distribution_pdf_csp" + seed = 147258639 + call random_seed(seed, get) + loc = (-0.5_sp, 0.5_sp); scale = (1.0_sp, 1.0_sp) + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_csp failed", warn=warn) + end subroutine test_uni_pdf_csp + + subroutine test_uni_pdf_cdp + complex(dp) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(1.0, i=1,15)] + + print *, "Test uniform_distribution_pdf_cdp" + seed = 147258639 + call random_seed(seed, get) + loc = (-0.5_dp, 0.5_dp); scale = (1.0_dp, 1.0_dp) + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_cdp failed", warn=warn) + end subroutine test_uni_pdf_cdp + + subroutine test_uni_pdf_cqp + complex(qp) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(1.0, i=1,15)] + + print *, "Test uniform_distribution_pdf_cqp" + seed = 147258639 + call random_seed(seed, get) + loc = (-0.5_qp, 0.5_qp); scale = (1.0_qp, 1.0_qp) + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_cqp failed", warn=warn) + end subroutine test_uni_pdf_cqp + + + subroutine test_uni_cdf_iint8 + integer(int8) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [0.435643554, 0.435643554, 0.435643554, 0.702970326, & + 0.653465331, 0.485148519, 0.386138618, 0.386138618, & + 0.336633652, 0.277227730, 0.237623766, 0.524752498, & + 0.732673287, 0.534653485, 0.415841579] + + print *, "Test uniform_distribution_cdf_iint8" + seed = 369147258 + call random_seed(seed, get) + loc = 14_int8; scale = 100_int8 + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_iint8 failed", warn=warn) + end subroutine test_uni_cdf_iint8 + + subroutine test_uni_cdf_iint16 + integer(int16) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [0.178217828, 0.178217828, 0.178217828, 0.465346545, & + 0.673267305, 0.247524753, 0.158415839, 0.792079210, & + 0.742574275, 0.574257433, 0.881188095, 0.663366318, & + 0.524752498, 0.623762369, 0.178217828] + + print *, "Test uniform_distribution_cdf_iint16" + seed = 369147258 + call random_seed(seed, get) + loc = 14_int16; scale = 100_int16 + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_iint16 failed", warn=warn) + end subroutine test_uni_cdf_iint16 + + subroutine test_uni_cdf_iint32 + integer(int32) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [0.732673287, 0.732673287, 0.732673287, 0.722772300, & + 0.792079210, 5.94059415E-02, 0.841584146,0.405940592,& + 0.960396051, 0.534653485, 0.782178223, 0.861386120, & + 0.564356446, 0.613861382, 0.306930691] + + print *, "Test uniform_distribution_cdf_iint32" + seed = 369147258 + call random_seed(seed, get) + loc = 14_int32; scale = 100_int32 + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_iint32 failed", warn=warn) + end subroutine test_uni_cdf_iint32 + + subroutine test_uni_cdf_iint64 + integer(int64) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [0.455445558, 0.455445558, 0.455445558, 0.277227730, & + 0.455445558, 0.930693090, 0.851485133, 0.623762369, & + 5.94059415E-02,0.693069279, 0.544554472, 0.207920790,& + 0.306930691, 0.356435657, 0.128712878] + + print *, "Test uniform_distribution_cdf_iint64" + seed = 369147258 + call random_seed(seed, get) + loc = 14_int64; scale = 100_int64 + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_iint64 failed", warn=warn) + end subroutine test_uni_cdf_iint64 + + subroutine test_uni_cdf_rsp + real(sp) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [0.170192942, 0.170192942, 0.170192942, 0.276106149, & + 0.754930079, 0.406620681, 0.187742814, 0.651605546, & + 0.934733927, 0.151271492, 0.987674534, 0.130533904, & + 0.106271908, 9.27578658E-02, 0.203399420] + + print *, "Test uniform_distribution_cdf_rsp" + seed = 369147258 + call random_seed(seed, get) + loc = 0.0_sp; scale = 2.0_sp + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_rsp failed", warn=warn) + end subroutine test_uni_cdf_rsp + + subroutine test_uni_cdf_rdp + real(dp) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [0.170192942, 0.170192942, 0.170192942, 0.276106149, & + 0.754930079, 0.406620681, 0.187742814, 0.651605546, & + 0.934733927, 0.151271492, 0.987674534, 0.130533904, & + 0.106271908, 9.27578658E-02, 0.203399420] + + print *, "Test uniform_distribution_cdf_rdp" + seed = 369147258 + call random_seed(seed, get) + loc = 0.0_dp; scale = 2.0_dp + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_rdp failed", warn=warn) + end subroutine test_uni_cdf_rdp + + subroutine test_uni_cdf_rqp + real(qp) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [0.170192942, 0.170192942, 0.170192942, 0.276106149, & + 0.754930079, 0.406620681, 0.187742814, 0.651605546, & + 0.934733927, 0.151271492, 0.987674534, 0.130533904, & + 0.106271908, 9.27578658E-02, 0.203399420] + + print *, "Test uniform_distribution_cdf_rqp" + seed = 369147258 + call random_seed(seed, get) + loc = 0.0_qp; scale = 2.0_qp + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_rqp failed", warn=warn) + end subroutine test_uni_cdf_rqp + + subroutine test_uni_cdf_csp + complex(sp) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [4.69913185E-02, 4.69913185E-02, 4.69913185E-02, & + 0.306970179, 0.122334257, 0.141398594, 0.128925011, & + 9.85755492E-03, 8.16527531E-02, 0.163921610, & + 7.81712309E-02, 0.446415812, 5.31753292E-04, & + 0.101455867, 0.155276477] + + print *, "Test uniform_distribution_cdf_csp" + seed = 369147258 + call random_seed(seed, get) + loc = (-0.5_sp, -0.5_sp); scale = (1.0_sp, 1.0_sp) + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_csp failed", warn=warn) + end subroutine test_uni_cdf_csp + + subroutine test_uni_cdf_cdp + complex(dp) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [4.69913185E-02, 4.69913185E-02, 4.69913185E-02, & + 0.306970179, 0.122334257, 0.141398594, 0.128925011, & + 9.85755492E-03, 8.16527531E-02, 0.163921610, & + 7.81712309E-02, 0.446415812, 5.31753292E-04, & + 0.101455867, 0.155276477] + + print *, "Test uniform_distribution_cdf_cdp" + seed = 369147258 + call random_seed(seed, get) + loc = (-0.5_dp, -0.5_dp); scale = (1.0_dp, 1.0_dp) + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_cdp failed", warn=warn) + end subroutine test_uni_cdf_cdp + + subroutine test_uni_cdf_cqp + complex(qp) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [4.69913185E-02, 4.69913185E-02, 4.69913185E-02, & + 0.306970179, 0.122334257, 0.141398594, 0.128925011, & + 9.85755492E-03, 8.16527531E-02, 0.163921610, & + 7.81712309E-02, 0.446415812, 5.31753292E-04, & + 0.101455867, 0.155276477] + + print *, "Test uniform_distribution_cdf_cqp" + seed = 369147258 + call random_seed(seed, get) + loc = (-0.5_qp, -0.5_qp); scale = (1.0_qp, 1.0_qp) + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_cqp failed", warn=warn) + end subroutine test_uni_cdf_cqp + + +end program test_distribution_uniform \ No newline at end of file From 1664d4242b80afabe79388c71f4bfe2a7d218c43 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 20 Dec 2020 11:10:09 -0500 Subject: [PATCH 004/172] initial commit --- doc/specs/index.md | 1 + .../stdlib_stats_distribution_uniform.md | 344 ++++++++++++++++++ 2 files changed, 345 insertions(+) create mode 100644 doc/specs/stdlib_stats_distribution_uniform.md diff --git a/doc/specs/index.md b/doc/specs/index.md index 91284c2df..ad99ebf78 100644 --- a/doc/specs/index.md +++ b/doc/specs/index.md @@ -17,6 +17,7 @@ This is and index/directory of the specifications (specs) for each new module/fe - [optval](./stdlib_optval.html) - Fallback value for optional arguments - [quadrature](./stdlib_quadrature.html) - Numerical integration - [stats](./stdlib_stats.html) - Descriptive Statistics + - [stats_distribution_PRNG](./stdlib_stats_distribution_PRNG.html) - Probability Distributions random number generator ## Missing specs diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md new file mode 100644 index 000000000..bd34e7a7f --- /dev/null +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -0,0 +1,344 @@ +--- +title: stats_distribution +--- + +# Statistical Distributions Uniform Module + +[TOC] + +## `shuffle` - Using Fisher-Yates algorithm to generate a random permutation of a list. + +### Status + +Experimental + +### Description + +Applying Fisher-Yates algorithm to generate an unbiased permutation for any list of intrinsic numerical data types. + +### Syntax + +`result = [[stdlib_stats_distribution_uniform(module):shuffle(interface)]]( list )` + +### Arguments + +`list`: argument has intent `in` and is a rank one array of integer, real, or complx type. + +### Return value + +Return a randomized rank one array of the input type. + +### Example + +```fortran +program demo_shuffle + use stdlib_stats_distribution_PRNG, only : random_seed + use stdlib_stats_distribution_uniform, only : shuffle + implicit none + integer :: seed_put, seed_get, i + real :: x(10) + integer :: n(10) + complex :: z(10) + + do i=1, 10 + n(i) = i + x(i) = real(i) + z(i) = cmplx(real(i), real(i)) + end do + seed_put = 32165498 + call random_seed(seed_put, seed_get) ! set and get current value of seed + n = shuffle(n) ! get randomized n +![10, 6, 9, 2, 8, 1, 3, 5, 7, 4] + x = shuffle(x) ! get randomized x +! [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, 7.0, 6.0] + z = shuffle(z) ! get randomized z +![(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), (1.0, 1.0), (5.0, 5.0), (9.0, 9.0), +!(6.0, 6.0), (3.0, 3.0), (2.0, 2.0), (10.0, 10.0)] +end program demo_shuffle +``` + +## `uniform_distribution_rvs` - uniform distribution random variates + +### Status + +Experimental + +### Description + +Without augument the function returns a scalar standard uniformly distributed variate U(0,1) of real type with single precision on [0,1]. + +With single augument `scale` of integer type the function returns a scalar uniformly distributed variate of integer type on [0,scale]. This is the standard Rectangular distribtuion. Function is elemental. + +With single augument `scale` of real or complx type the function returns a scalar uniformly distributed variate of real or complx type on [0, scale]. The real part and imaginary part of a complx type are independent of each other. Function is elemental. + +With double auguments `loc` and `scale` the function returns a scalar uniformly distributed random variates of integer, real or complx type on [loc, loc + scale] dependent of input type. If it is complex augument, the real part and imaginary part are independent of each other. Function is elemental. + +With triple auguments `loc`, `scale` and `array_size` the function returns a rank one array of uniformly distributed variates of integer, real or complx type with an array size of `array_size`. + +### Syntax + +`result = [[stdlib_stats_distribution_uniform(module):uniform_distribution_rvs(interface)]]([[loc,] scale] [[[,array_size]]])` + +### Arguments + +`loc`: optional argument has intent `in` and is a scalar of type `integer`, `real` or `complx`. + +`scale`: optional argument has intent `in` and is a scalar of type `integer`, `real` or `complx`. + +`array_size`: optional argument has intent `in` and is a scalar of type `integer`. + +`loc` and `scale` must have the same type when both are present. + +### Return value + +The result is a scalar or a rank one array, with size of `array_size`, of type `integer`, `real` or `complx` depending on the input type. + +### Example + +```fortran +program demo_uniform_rvs + use stdlib_stats_distribution_PRNG, only:random_seed + use stdlib_stats_distribution_uniform, only:uni=> uniform_distribution_rvs + + implicit none + complx :: loc, scale + real :: a(3,4,5), b(3,4,5) + integer :: seed_put, seed_get + + seed_put = 1234567 + call random_seed(seed_put, seed_get) + + print *, uni( ) !real standard uniform random variate in [0., 1.] +! 0.161520019 + + print *, uni(3.0) !an uniform random variate in [0., 3.] +! 1.65974522 + + print *, uni(-0.5, 1.0) !an uniform random variate in [-0.5, 0.5] +! 0.486900032 + + print *, uni(-1.0,2.0,10) !an array of 10 uniform random variates in [-1., 1.] +![0.884182811, -0.771520197, 0.560377002, 0.709313750, -7.12267756E-02, !-0.431066573, 0.497536063, -0.396331906, -0.325983286, 0.137686729] + + print *, uni(20) !a random integer variate in [0, 20] +! 17 + + print *, uni(5,13) !a random integer variate in [5, 13] +! 15 + + print *, uni(3,19,10) !an array of 10 integer variates in [3,19] +! [7, 16, 16, 12, 9, 21, 19, 4, 3, 19] + + loc = (-0.5, -0.5) + scale = (1.0, 1.0) + + print *, uni(scale) !a complex uniform random variate in unit square +!(0.139202669,0.361759573) + + print *, uni(loc,scale) + !a complex uniform random variate in [(-0.5, -0.5), (0.5, 0.5)] +!(0.296536088,-0.143987954) + + print *, uni(loc, scale, 10) + !an array of 10 complex uniform random variate in [(-0.5, -0.5), (0.5, 0.5)] + +![(-0.302334785,-0.401923567), (0.281620383,9.534919262E-02), +! (-0.374348879,0.457528770), (0.442990601,-0.240510434), +! (-0.421572685,0.279313922), (-0.182090610,5.901372433E-02), +! (-7.864198089E-02,0.378484428), (-0.423258364,-0.201292425), +! (0.193327367,-0.353985727), (-0.397661150,0.355926156)] + + a(:,:,:) = -0.5 + b(:,:,:) = 1.0 + + print *, uni(a,b) + !a rank 3 array of random variates in [-0.5,0.5] + +! [-0.249188632, -0.199248433, -0.389813602, 2.88307667E-03, 0.238479793, +! 0.264856219, -0.205177426, -0.480921626, 0.131218433, 0.252170086, +! -0.303151041, -8.89462233E-02, -0.377370685, 0.341802299, 0.323204756, +! 0.358679056, -0.138909757, 0.384329498, -0.109372199, 0.132353067, +! 0.494320452, 0.419343710, -0.103044361, 0.461389005, 0.403132677, +! 0.121850729, 0.403839290, -0.349389791, 0.490482628, 0.156600773, +! 8.46788883E-02, -0.483680278, 0.388107836, 0.119698405, 0.154214382, +! 0.153113484, 0.236523747, 0.155937552, -0.135760903, 0.219589531, +! 0.394639254, 6.30156994E-02, -0.342692465, -0.444846451, -0.215700030, +! 0.204189956, -0.208748132, 0.355063021, 8.98272395E-02, -0.237928331, +! 2.98077464E-02, -0.485149682, -8.06870461E-02, -0.372713923, +! -0.178335011, 0.283877611, -2.13934183E-02, -9.21690464E-03, 4.56320047E-02, +! 0.220112979] +end program demo_uniform_rvs +``` + +## `uniform_distribution_pdf` - uniform probability density function + +### Status + +Experimental + +### Description + +The probability density function of the uniform distribution. + +f(x) = 1 / (scale + 1); for discrete uniform distribution +f(x) = 1 / scale; for continuous uniform distribution +f(x) = 1 / (scale%re * scale%im); for complx uniform distribution + +### Syntax + +`result = [[stdlib_stats_distribution_uniform(module):uniform_distribution_pdf(interface)]](x, loc, scale)` + +### Arguments + +`x`: has intent `in` and is a scalar of type `integer`, `real` or `complx`. + +`loc`: has intent `in` and is a scalar of type `integer`, `real` or `complx`. + +`scale`: has intent `in` and is a scalar of type `integer`, `real` or `complx`. + +The function is elemental, i.e., all three auguments could be arrays conformable to each other. All three arguments must have the same type. + +### Return value + +The result is a scalar or an array, with a shape conformable to auguments, of type `real`. + +### Example + +```fortran +program demo_uniform_pdf + use stdlib_stats_distribution_PRNG, only : random_seed + use stdlib_stats_distribution_uniform, only : & + uni_pdf => uniform_distribution_pdf, & + uni => uniform_distribution_rvs + + implicit none + complx :: loc, scale + real :: a(3,4,5), b(3,4,5), x(3,4,5) + integer :: seed_put, seed_get + + seed_put = 1234567 + call random_seed(seed_put, seed_get) + + print *, uni_pdf(3, 2, 10) !probability density at 3 in range [2, 10] + +! 9.09090936E-02 + + print *, uni_pdf(0.5,0.0,1.0) !a probability density at 0.5 in [0., 1.] + +! 1.00000000 + + + print *, uni_pdf(0.7,-1.0,2.0) !a probability density at 0.7 in [-1., 1.] + +! 0.500000000 + + a(:,:,:) = 0.0 + b(:,:,:) = 2.0 + x = reshape(uni(0.,2.,60),[3,4,5])! uniform random variates array in [0., 2.] + print *, uni_pdf(x, a, b) ! probability density array in [0., 2.] + +![0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, & +! 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, & +! 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, & +! 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, & +! 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, & +! 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, & +! 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, & +! 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, & +! 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, & +! 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000] + + loc = (-0.5,-0.5) + scale = (1.0,1.0) + print *, uni_pdf((-0.1,0.2), loc, scale) + ! joint probability density at (-0.1,0.2) in [(-0.5, -0.5), (0.5, 0.5)] + +! 1.00000000 +end program demo_uniform_pdf + +``` + +## `uniform_distribution_cdf` - uniform cumulative distribution function + +### Status + +Experimental + +### Description + +Cumulative distribution function of the uniform distribution + +F(x) = (x - loc + 1) / (scale + 1); for discrete uniform distribution +F(x) = (x - loc) / scale; for continuous uniform distribution +F(x) = (x%re - loc%re)(x%im - loc%im) / (scale%re * scale%im); for complx uniform distribution + +### Syntax + +`result = [[stdlib_stats_distribution_uniform(module):uniform_distribution_cdf(interface)]](x, loc, scale)` + +### Arguments + +`x`: has intent `in` and is a scalar of type `integer`, `real` or `complx`. + +`loc`: has intent `in` and is a scalar of type `integer`, `real` or `complx`. + +`scale`: has intent `in` and is a scalar of type `integer`, `real` or `complx`. + +The function is elemental, i.e., all three auguments could be arrays conformable to each other. All three arguments must have the same type. + +### Return value + +The result is a scalar or an array, with a shape conformable to auguments, of type `real`. + +### Example + +```fortran +program demo_uniform_cdf + use stdlib_stats_distribution, only : uni_cdf => uniform_distribution_cdf, & + uni => uniform_distribution_rvs, & + random_seed + implicit none + real :: x(3,4,5), a(3,4,5), b(3,4,5) + complx :: loc, scale + integer :: seed_put, seed_get + + seed_put = 1234567 + call random_seed(seed_put, seed_get) + + print *, uni_cdf(0.5,0.,1.) ! a cumulative at 0.5 in [0., 1.] + +!0.500000000 + + print *, uni_cdf(0.7,-1.0,2.0) ! a cumulative at 0.7 in [-1.0, 1.0] + +! 0.850000024 + + print *, uni_cdf(6, 2, 10) ! a cumulative at 6 in [2, 10] + +! 0.454545468 + + a(:,:,:) = -1.0 + b(:,:,:) = 2.0 + x = reshape(uni(-1.0,2.0,60),[3,4,5]) ! uniform random variates array + print *, uni_cdf(x,a,b) ! cumulative array in [-1.0, 1.0] + +![0.161520004, 0.553248405, 0.986900032, 0.942091405, 0.114239901, 0.780188501, & +! 0.854656875, 0.464386612, 0.284466714, 0.748768032, 0.301834047, 0.337008357, & +!0.568843365, 0.596165061, 0.180993259, 0.614166319, 0.214835495,7.98164606E-02,& +!0.641274095, 0.607101977, 0.701139212, 0.230517209, 1.97925568E-02,0.857982159,& +!0.712761045, 0.139202654, 0.361759573, 0.796536088, 0.356012046, 0.197665215, & +!9.80764329E-02,0.781620383, 0.595349193, 0.125651121, 0.957528770, 0.942990601,& +!0.259489566, 7.84273148E-02, 0.779313922, 0.317909390, 0.559013724,0.421358019,& +!0.878484428, 7.67416358E-02, 0.298707575, 0.693327367, 0.146014273,0.102338850,& +!0.855926156, 0.250811368, 0.300751567, 0.110186398, 0.502883077, 0.738479793, & +!0.764856219, 0.294822574, 1.90783739E-02,0.631218433,0.752170086, 0.196848959] + + loc = (0., 0.) + scale=(2., 1.) + print *, uni_cdf((1.2,0.5), loc, scale) + ! joint cumulative distribution at (1.2,0.5) in [(0.,0.), (2.,1.)] + +! 0.300000012 +end program demo_uniform_cdf + +``` From dbb7de76a2f643fce38702a0baecc5764894a8df Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 20 Dec 2020 11:11:29 -0500 Subject: [PATCH 005/172] Add files via upload --- src/stdlib_stats_distribution_PRNG.fypp | 211 ++++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 src/stdlib_stats_distribution_PRNG.fypp diff --git a/src/stdlib_stats_distribution_PRNG.fypp b/src/stdlib_stats_distribution_PRNG.fypp new file mode 100644 index 000000000..90d9f367e --- /dev/null +++ b/src/stdlib_stats_distribution_PRNG.fypp @@ -0,0 +1,211 @@ +#:include "common.fypp" +module stdlib_stats_distribution_PRNG + use stdlib_kinds + implicit none + private + integer, parameter :: MAX_INT_BIT_SIZE = 64 + integer(int64), save :: st(4), si = 614872703977525537_int64 + logical, save :: seed_initialized = .false. + + public :: random_seed + public :: dist_rand + public :: jump + public :: long_jump + + + interface dist_rand + !! Version experimental + !! + !! Generation of random integers with different kinds + !! ([Specification](../page/specs/stdlib_stats_distribution_PRNG.html# + !! description)) + #:for k1, t1 in INT_KINDS_TYPES + module procedure dist_rand_${t1[0]}$${k1}$ + #:endfor + end interface dist_rand + + interface random_seed + !! Version experimental + !! + !! Set seed value for random number generator + !! ([Specification](../page/specs/stdlib_stats_distribution_PRNG.html# + !! description)) + !! + #:for k1, t1 in INT_KINDS_TYPES + module procedure random_distribution_seed_${t1[0]}$${k1}$ + #:endfor + end interface random_seed + + + contains + + #:for k1, t1 in INT_KINDS_TYPES + function dist_rand_${t1[0]}$${k1}$(n) result(res) + !! Random integer generation for various kinds + !! result = [-2^k, 2^k - 1], k = 7, 15, 31, 63, depending on input kind + !! Result is used as bit model number instead of regular arithmetic number + !! + ${t1}$, intent(in) :: n + ${t1}$ :: res + integer :: k + + k = MAX_INT_BIT_SIZE - bit_size(n) + res = shiftr(xoshiro256ss( ), k) + end function dist_rand_${t1[0]}$${k1}$ + + #:endfor + + function xoshiro256ss( ) result (res) + ! Generate random 64-bit integers + ! Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org) + ! + ! This is xoshiro256** 1.0, one of our all-purpose, rock-solid + ! generators. It has excellent (sub-ns) speed, a state (256 bits) that is + ! large enough for any parallel application, and it passes all tests we + ! are aware of. + ! + ! The state must be seeded so that it is not everywhere zero. If you have + ! a 64-bit seed, we suggest to seed a splitmix64 generator and use its + ! output to fill st. + ! + ! Fortran 90 version translated from C by Jim-215-Fisher + ! + integer(int64) :: res, t + + if(.not. seed_initialized) call random_distribution_seed_iint64(si,t) + res = rol64(st(2) * 5 , 7) * 9 + t = shiftl(st(2), 17) + st(3) = ieor(st(3), st(1)) + st(4) = ieor(st(4), st(2)) + st(2) = ieor(st(2), st(3)) + st(1) = ieor(st(1), st(4)) + st(3) = ieor(st(3), t) + st(4) = rol64(st(4), 45) + return + end function xoshiro256ss + + function rol64(x, k) result(res) + integer(int64), intent(in) :: x + integer, intent(in) :: k + integer(int64) :: t1, t2, res + + t1 = shiftr(x, (64 - k)) + t2 = shiftl(x, k) + res = ior(t1, t2) + return + end function rol64 + + + subroutine jump + ! This is the jump function for the xoshiro256ss generator. It is equivalent + ! to 2^128 calls to xoshiro256ss(); it can be used to generate 2^128 + ! non-overlapping subsequences for parallel computations. + ! Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org) + ! + ! Fortran 90 version translated from C by Jim-215-Fisher + integer(int64) :: jp(4) = [1733541517147835066_int64, & + -3051731464161248980_int64, & + -6244198995065845334_int64, & + 4155657270789760540_int64] + integer(int64) :: s1 = 0, s2 = 0, s3 = 0, s4 = 0, c = 1_int64 + integer :: i, j, k + + do i = 1, 4 + do j = 1, 64 + if(iand(jp(i), shiftl(c, j - 1)) /= 0) then + s1 = ieor(s1, st(1)) + s2 = ieor(s2, st(2)) + s3 = ieor(s3, st(3)) + s4 = ieor(s4, st(4)) + end if + k = xoshiro256ss( ) + end do + end do + st(1) = s1 + st(2) = s2 + st(3) = s3 + st(4) = s4 + end subroutine jump + + subroutine long_jump + ! This is the long-jump function for the xoshiro256ss generator. It is + ! equivalent to 2^192 calls to xoshiro256ss(); it can be used to generate + ! 2^64 starting points, from each of which jump() will generate 2^64 + ! non-overlapping subsequences for parallel distributed computations + ! Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org) + ! + ! Fortran 90 version translated from C by Jim-215-Fisher + integer(int64) :: jp(4) = [8566230491382795199_int64, & + -4251311993797857357_int64, & + 8606660816089834049_int64, & + 4111957640723818037_int64] + integer(int64) :: s1 = 0, s2 = 0, s3 = 0, s4 = 0, c = 1_int64 + integer(int32) :: i, j, k + + do i = 1, 4 + do j = 1, 64 + if(iand(jp(i), shiftl(c, j - 1)) /= 0) then + s1 = ieor(s1, st(1)) + s2 = ieor(s2, st(2)) + s3 = ieor(s3, st(3)) + s4 = ieor(s4, st(4)) + end if + k = xoshiro256ss() + end do + end do + st(1) = s1 + st(2) = s2 + st(3) = s3 + st(4) = s4 + end subroutine long_jump + + function splitmix64(s) result(res) + ! Written in 2015 by Sebastiano Vigna (vigna@acm.org) + ! This is a fixed-increment version of Java 8's SplittableRandom + ! generator. + ! See http://dx.doi.org/10.1145/2714064.2660195 and + ! http://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html + ! + ! It is a very fast generator passing BigCrush, and it can be useful if + ! for some reason you absolutely want 64 bits of state. + ! + ! Fortran 90 translated from C by Jim-215-Fisher + ! + integer(int64) :: res, int01, int02, int03 + integer(int64), intent(in), optional :: s + data int01, int02, int03/-7046029254386353131_int64, & + -4658895280553007687_int64, & + -7723592293110705685_int64/ + + if(present(s)) si = s + res = si + si = res + int01 + res = ieor(res, shiftr(res, 30)) * int02 + res = ieor(res, shiftr(res, 27)) * int03 + res = ieor(res, shiftr(res, 31)) + return + end function splitmix64 + + #:for k1, t1 in INT_KINDS_TYPES + subroutine random_distribution_seed_${t1[0]}$${k1}$(put, get) + !! Set seed value for random number generator + !! + ${t1}$, intent(in) :: put + ${t1}$, intent(out) :: get + integer(int64) :: tmp + integer :: i + + tmp = splitmix64(int(put, kind = int64)) + do i = 1, 10 + tmp = splitmix64( ) + end do + do i = 1, 4 + tmp = splitmix64( ) + st(i) = tmp + end do + get = int(tmp, kind = ${k1}$) + seed_initialized = .true. + end subroutine random_distribution_seed_${t1[0]}$${k1}$ + + #:endfor +end module stdlib_stats_distribution_PRNG \ No newline at end of file From d3214fc25ea60ad008a39883d107e7f4172863af Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 20 Dec 2020 11:24:11 -0500 Subject: [PATCH 006/172] correct file --- src/tests/test_distribution_uniform.f90 | 855 ++++++++++++++++++++++++ 1 file changed, 855 insertions(+) create mode 100644 src/tests/test_distribution_uniform.f90 diff --git a/src/tests/test_distribution_uniform.f90 b/src/tests/test_distribution_uniform.f90 new file mode 100644 index 000000000..152c5a3dd --- /dev/null +++ b/src/tests/test_distribution_uniform.f90 @@ -0,0 +1,855 @@ +program test_distribution_uniform + use stdlib_error, only : check + use stdlib_kinds + use stdlib_stats_distribution_PRNG, only : random_seed, dist_rand + use stdlib_stats_distribution_uniform, & + uni_rvs => uniform_distribution_rvs, & + uni_pdf => uniform_distribution_pdf, & + uni_cdf => uniform_distribution_cdf + + implicit none + logical :: warn = .true. + real(sp), parameter :: sptol = 1000 * epsilon(1.0_sp) + real(dp), parameter :: dptol = 1000 * epsilon(1.0_dp) + real(qp), parameter :: qptol = 1000 * epsilon(1.0_qp) + integer :: put, get + + put = 135792468 + + call test_shuffle + + call test_uni_rvs_0 + + call test_uni_rvs_iint8 + call test_uni_rvs_iint16 + call test_uni_rvs_iint32 + call test_uni_rvs_iint64 + call test_uni_rvs_rsp + call test_uni_rvs_rdp + call test_uni_rvs_rqp + call test_uni_rvs_csp + call test_uni_rvs_cdp + call test_uni_rvs_cqp + + call test_uni_pdf_iint8 + call test_uni_pdf_iint16 + call test_uni_pdf_iint32 + call test_uni_pdf_iint64 + call test_uni_pdf_rsp + call test_uni_pdf_rdp + call test_uni_pdf_rqp + call test_uni_pdf_csp + call test_uni_pdf_cdp + call test_uni_pdf_cqp + + call test_uni_cdf_iint8 + call test_uni_cdf_iint16 + call test_uni_cdf_iint32 + call test_uni_cdf_iint64 + call test_uni_cdf_rsp + call test_uni_cdf_rdp + call test_uni_cdf_rqp + call test_uni_cdf_csp + call test_uni_cdf_cdp + call test_uni_cdf_cqp + stop + + contains + + subroutine test_shuffle + integer :: n(10), na(10) = [10, 6, 9, 2, 8, 1, 3, 5, 7, 4] + real :: x(10), xa(10)= [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, & + 7.0, 6.0] + complex :: z(10), za(10)=[(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), & + (1.0, 1.0), (5.0, 5.0), (9.0, 9.0), & + (6.0, 6.0), (3.0, 3.0), (2.0, 2.0), & + (10.0, 10.0)] + integer :: i, put, get + + do i=1, 10 + n(i) = i + x(i) = real(i) + z(i) = cmplx(real(i),real(i)) + end do + put = 32165498 + call random_seed(put, get) + n(:) = shuffle(n) + x(:) = shuffle(x) + z(:) = shuffle(z) + call check(all(n == na), & + msg="Integer shuffle failed test", warn=warn) + call check(all(x == xa), & + msg="Real shuffle failed test", warn=warn) + call check(all(z == za), & + msg="Complex shuffle failed test", warn=warn) + end subroutine test_shuffle + + subroutine test_uni_rvs_0 + integer :: i, j, freq(0:1000), num=10000000 + real(dp) :: chisq, expct + + print *,"" + print *, "Test uniform random generator with chi-squared" + freq = 0 + do i = 1, num + j = 1000 * uni_rvs( ) + freq(j) = freq(j) + 1 + end do + chisq = 0.0_dp + expct = num / 1000 + do i = 0, 999 + chisq = chisq + (freq(i) - expct) ** 2 / expct + end do + write(*,*) "The critical values for chi-squared with 1000 d. of f. are" & + //" 1143.92" + write(*,*) "Chi-squared for uniform random generator is : ", chisq + call check((chisq < 1143.9) , & + msg="uniform randomness failed chi-squared test", warn=warn) + end subroutine test_uni_rvs_0 + + subroutine test_uni_rvs_iint8 + integer(int8) :: res(15), scale, loc + integer :: i, n, seed, get, k + + integer(int8) :: ans(15) = [47, 99, 43, 37, 48, 30, 27, 100, 30, 33, 21, & + 103, 55, 54, 110] + + print *, "Test uniform_distribution_rvs_iint8" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = 15_int8; scale = 100_int8 + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(res == ans), & + msg="uniform_distribution_rvs_iint8 failed", warn=warn) + end subroutine test_uni_rvs_iint8 + + subroutine test_uni_rvs_iint16 + integer(int16) :: res(15), scale, loc + integer :: i, n, seed, get, k + + integer(int16) :: ans(15) = [25, 4, 81, 98, 49, 34, 32, 62, 115, 112, 26, & + 20, 37, 100, 82] + + print *, "Test uniform_distribution_rvs_iint16" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = 15_int16; scale = 100_int16 + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(res == ans), & + msg="uniform_distribution_rvs_iint16 failed", warn=warn) + end subroutine test_uni_rvs_iint16 + + subroutine test_uni_rvs_iint32 + integer(int32) :: res(15), scale, loc + integer :: i, n, seed, get, k + + integer(int32) :: ans(15) = [19, 52, 56, 20, 59, 44, 34, 102, 19, 39, 60, & + 50, 97, 56, 67] + + print *, "Test uniform_distribution_rvs_iint32" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = 15_int32; scale = 100_int32 + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(res == ans), & + msg="uniform_distribution_rvs_iint32 failed", warn=warn) + end subroutine test_uni_rvs_iint32 + + subroutine test_uni_rvs_iint64 + integer(int64) :: res(15), scale, loc + integer :: i, n, seed, get, k + + integer(int64) :: ans(15) = [76, 45, 43, 75, 76, 15, 25, 24, 114, 113, 94, & + 29, 109, 93, 89] + + print *, "Test uniform_distribution_rvs_iint64" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = 15_int64; scale = 100_int64 + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(res == ans), & + msg="uniform_distribution_rvs_iint64 failed", warn=warn) + end subroutine test_uni_rvs_iint64 + + subroutine test_uni_rvs_rsp + real(sp) :: res(15), scale, loc + integer :: i, n, seed, get, k + + real(sp) :: ans(15) = & + [0.914826628538749186958511927514337003_sp, & + 0.367330098664966409049981166390352882_sp, & + 1.77591243057709280428468900936422870_sp, & + 0.885921308987590139238932351872790605_sp, & + 0.950735656542987861428173346212133765_sp, & + -0.659562573857055134407545438079978339_sp, & + -0.116661718506947176265953203255776316_sp, & + 0.837391893893859151631886561517603695_sp, & + -0.703954396598600540269075054311542772_sp, & + 0.382592729851141566399519433616660535_sp, & + -0.132472493978185168472805344208609313_sp, & + -0.878723366294216184924081858298450243_sp, & + -0.901660046141515819639877804547722917_sp, & + -0.164090614147737401395943379611708224_sp, & + -0.333886718190384290672056977200554684_sp] + + print *, "Test uniform_distribution_rvs_rsp" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = -1.0_sp; scale = 2.0_sp + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(abs(res - ans) < sptol), & + msg="uniform_distribution_rvs_rsp failed", warn=warn) + end subroutine test_uni_rvs_rsp + + subroutine test_uni_rvs_rdp + real(dp) :: res(15), scale, loc + integer :: i, n, seed, get, k + + real(dp) :: ans(15) = & + [0.914826628538749186958511927514337003_dp, & + 0.367330098664966409049981166390352882_dp, & + 1.77591243057709280428468900936422870_dp, & + 0.885921308987590139238932351872790605_dp, & + 0.950735656542987861428173346212133765_dp, & + -0.659562573857055134407545438079978339_dp, & + -0.116661718506947176265953203255776316_dp, & + 0.837391893893859151631886561517603695_dp, & + -0.703954396598600540269075054311542772_dp, & + 0.382592729851141566399519433616660535_dp, & + -0.132472493978185168472805344208609313_dp, & + -0.878723366294216184924081858298450243_dp, & + -0.901660046141515819639877804547722917_dp, & + -0.164090614147737401395943379611708224_dp, & + -0.333886718190384290672056977200554684_dp] + + print *, "Test uniform_distribution_rvs_rdp" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = -1.0_dp; scale = 2.0_dp + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(abs(res - ans) < dptol), & + msg="uniform_distribution_rvs_rdp failed", warn=warn) + end subroutine test_uni_rvs_rdp + + subroutine test_uni_rvs_rqp + real(qp) :: res(15), scale, loc + integer :: i, n, seed, get, k + + real(qp) :: ans(15) = & + [0.914826628538749186958511927514337003_qp, & + 0.367330098664966409049981166390352882_qp, & + 1.77591243057709280428468900936422870_qp, & + 0.885921308987590139238932351872790605_qp, & + 0.950735656542987861428173346212133765_qp, & + -0.659562573857055134407545438079978339_qp, & + -0.116661718506947176265953203255776316_qp, & + 0.837391893893859151631886561517603695_qp, & + -0.703954396598600540269075054311542772_qp, & + 0.382592729851141566399519433616660535_qp, & + -0.132472493978185168472805344208609313_qp, & + -0.878723366294216184924081858298450243_qp, & + -0.901660046141515819639877804547722917_qp, & + -0.164090614147737401395943379611708224_qp, & + -0.333886718190384290672056977200554684_qp] + + print *, "Test uniform_distribution_rvs_rqp" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = -1.0_qp; scale = 2.0_qp + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(abs(res - ans) < qptol), & + msg="uniform_distribution_rvs_rqp failed", warn=warn) + end subroutine test_uni_rvs_rqp + + subroutine test_uni_rvs_csp + complex(sp) :: res(15), scale, loc + integer :: i, n, seed, get, k + + complex(sp) :: ans(15) = [(0.457413314269374593479255963757168502_sp, & + 0.183665049332483204524990583195176441_sp), & + (0.887956215288546402142344504682114348_sp, & + 0.442960654493795069619466175936395302_sp), & + (0.475367828271493930714086673106066883_sp, & + 0.170218713071472432796227280960010830_sp), & + (0.441669140746526411867023398372111842_sp, & + 0.918695946946929575815943280758801848_sp), & + (0.148022801700699729865462472844228614_sp, & + 0.691296364925570783199759716808330268_sp), & + (-6.623624698909258423640267210430465639E-0002_sp, & + 0.560638316852891907537959070850774879_sp), & + (-0.450830023070757909819938902273861459_sp, & + 0.917954692926131299302028310194145888_sp), & + (-0.166943359095192145336028488600277342_sp, & + 1.05997401970850635422038976685144007_sp), & + (-0.429652190199228276035192664039641386_sp, & + 0.523558274341032421628217008446881664_sp), & + (0.427181091476823815433760955784237012_sp, & + 1.34628934976074521312483511792379431_sp), & + (-0.343281426018765739582860874179459643_sp, & + 1.15357331316264255516301773241139017_sp), & + (-0.127590074749816595467422075671493076_sp, & + 1.06891199479835175001340985545539297_sp), & + (0.262287586904722758163188700564205647_sp, & + 1.29508919831907332032017166056903079_sp), & + (-0.192677407376582732201342196276527829_sp, & + 1.32794925614337933073016984053538181_sp), & + (-0.264742129752461530234342035328154452_sp, & + 1.01282963412172621886497836385387927_sp)] + + print *, "Test uniform_distribution_rvs_csp" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = (-0.5_sp,0.5_sp); scale = (1.0_sp, 1.0_sp) + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(abs(res%re - ans%re) < sptol) .and. & + all(abs(res%im - ans%im) < sptol), & + msg="uniform_distribution_rvs_csp failed", warn=warn) + end subroutine test_uni_rvs_csp + + subroutine test_uni_rvs_cdp + complex(dp) :: res(15), scale, loc + integer :: i, n, seed, get, k + + complex(dp) :: ans(15) = [(0.457413314269374593479255963757168502_dp, & + 0.183665049332483204524990583195176441_dp), & + (0.887956215288546402142344504682114348_dp, & + 0.442960654493795069619466175936395302_dp), & + (0.475367828271493930714086673106066883_dp, & + 0.170218713071472432796227280960010830_dp), & + (0.441669140746526411867023398372111842_dp, & + 0.918695946946929575815943280758801848_dp), & + (0.148022801700699729865462472844228614_dp, & + 0.691296364925570783199759716808330268_dp), & + (-6.623624698909258423640267210430465639E-0002_dp, & + 0.560638316852891907537959070850774879_dp), & + (-0.450830023070757909819938902273861459_dp, & + 0.917954692926131299302028310194145888_dp), & + (-0.166943359095192145336028488600277342_dp, & + 1.05997401970850635422038976685144007_dp), & + (-0.429652190199228276035192664039641386_dp, & + 0.523558274341032421628217008446881664_dp), & + (0.427181091476823815433760955784237012_dp, & + 1.34628934976074521312483511792379431_dp), & + (-0.343281426018765739582860874179459643_dp, & + 1.15357331316264255516301773241139017_dp), & + (-0.127590074749816595467422075671493076_dp, & + 1.06891199479835175001340985545539297_dp), & + (0.262287586904722758163188700564205647_dp, & + 1.29508919831907332032017166056903079_dp), & + (-0.192677407376582732201342196276527829_dp, & + 1.32794925614337933073016984053538181_dp), & + (-0.264742129752461530234342035328154452_dp, & + 1.01282963412172621886497836385387927_dp)] + + print *, "Test uniform_distribution_rvs_cdp" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = (-0.5_dp,0.5_dp); scale = (1.0_dp, 1.0_dp) + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(abs(res%re - ans%re) < dptol) .and. & + all(abs(res%im - ans%im) < dptol), & + msg="uniform_distribution_rvs_cdp failed", warn=warn) + end subroutine test_uni_rvs_cdp + + subroutine test_uni_rvs_cqp + complex(qp) :: res(15), scale, loc + integer :: i, n, seed, get, k + + complex(qp) :: ans(15) = [(0.457413314269374593479255963757168502_qp, & + 0.183665049332483204524990583195176441_qp), & + (0.887956215288546402142344504682114348_qp, & + 0.442960654493795069619466175936395302_qp), & + (0.475367828271493930714086673106066883_qp, & + 0.170218713071472432796227280960010830_qp), & + (0.441669140746526411867023398372111842_qp, & + 0.918695946946929575815943280758801848_qp), & + (0.148022801700699729865462472844228614_qp, & + 0.691296364925570783199759716808330268_qp), & + (-6.623624698909258423640267210430465639E-0002_qp, & + 0.560638316852891907537959070850774879_qp), & + (-0.450830023070757909819938902273861459_qp, & + 0.917954692926131299302028310194145888_qp), & + (-0.166943359095192145336028488600277342_qp, & + 1.05997401970850635422038976685144007_qp), & + (-0.429652190199228276035192664039641386_qp, & + 0.523558274341032421628217008446881664_qp), & + (0.427181091476823815433760955784237012_qp, & + 1.34628934976074521312483511792379431_qp), & + (-0.343281426018765739582860874179459643_qp, & + 1.15357331316264255516301773241139017_qp), & + (-0.127590074749816595467422075671493076_qp, & + 1.06891199479835175001340985545539297_qp), & + (0.262287586904722758163188700564205647_qp, & + 1.29508919831907332032017166056903079_qp), & + (-0.192677407376582732201342196276527829_qp, & + 1.32794925614337933073016984053538181_qp), & + (-0.264742129752461530234342035328154452_qp, & + 1.01282963412172621886497836385387927_qp)] + + print *, "Test uniform_distribution_rvs_cqp" + seed = 258147369; k = 5 + call random_seed(seed, get) + loc = (-0.5_qp,0.5_qp); scale = (1.0_qp, 1.0_qp) + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + call check(all(abs(res%re - ans%re) < qptol) .and. & + all(abs(res%im - ans%im) < qptol), & + msg="uniform_distribution_rvs_cqp failed", warn=warn) + end subroutine test_uni_rvs_cqp + + + subroutine test_uni_pdf_iint8 + integer(int8) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(1.96078438E-02, i=1,15)] + + print *, "Test uniform_distribution_pdf_iint8" + seed = 147258639 + call random_seed(seed, get) + loc = 0_int8; scale = 50_int8 + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_iint8 failed", warn=warn) + end subroutine test_uni_pdf_iint8 + + subroutine test_uni_pdf_iint16 + integer(int16) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(1.96078438E-02, i=1,15)] + + print *, "Test uniform_distribution_pdf_iint16" + seed = 147258639 + call random_seed(seed, get) + loc = 0_int16; scale = 50_int16 + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_iint16 failed", warn=warn) + end subroutine test_uni_pdf_iint16 + + subroutine test_uni_pdf_iint32 + integer(int32) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(1.96078438E-02, i=1,15)] + + print *, "Test uniform_distribution_pdf_iint32" + seed = 147258639 + call random_seed(seed, get) + loc = 0_int32; scale = 50_int32 + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_iint32 failed", warn=warn) + end subroutine test_uni_pdf_iint32 + + subroutine test_uni_pdf_iint64 + integer(int64) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(1.96078438E-02, i=1,15)] + + print *, "Test uniform_distribution_pdf_iint64" + seed = 147258639 + call random_seed(seed, get) + loc = 0_int64; scale = 50_int64 + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_iint64 failed", warn=warn) + end subroutine test_uni_pdf_iint64 + + subroutine test_uni_pdf_rsp + real(sp) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(0.5, i=1,15)] + + print *, "Test uniform_distribution_pdf_rsp" + seed = 147258639 + call random_seed(seed, get) + loc = 0.0_sp; scale = 2.0_sp + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_rsp failed", warn=warn) + end subroutine test_uni_pdf_rsp + + subroutine test_uni_pdf_rdp + real(dp) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(0.5, i=1,15)] + + print *, "Test uniform_distribution_pdf_rdp" + seed = 147258639 + call random_seed(seed, get) + loc = 0.0_dp; scale = 2.0_dp + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_rdp failed", warn=warn) + end subroutine test_uni_pdf_rdp + + subroutine test_uni_pdf_rqp + real(qp) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(0.5, i=1,15)] + + print *, "Test uniform_distribution_pdf_rqp" + seed = 147258639 + call random_seed(seed, get) + loc = 0.0_qp; scale = 2.0_qp + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_rqp failed", warn=warn) + end subroutine test_uni_pdf_rqp + + subroutine test_uni_pdf_csp + complex(sp) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(1.0, i=1,15)] + + print *, "Test uniform_distribution_pdf_csp" + seed = 147258639 + call random_seed(seed, get) + loc = (-0.5_sp, 0.5_sp); scale = (1.0_sp, 1.0_sp) + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_csp failed", warn=warn) + end subroutine test_uni_pdf_csp + + subroutine test_uni_pdf_cdp + complex(dp) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(1.0, i=1,15)] + + print *, "Test uniform_distribution_pdf_cdp" + seed = 147258639 + call random_seed(seed, get) + loc = (-0.5_dp, 0.5_dp); scale = (1.0_dp, 1.0_dp) + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_cdp failed", warn=warn) + end subroutine test_uni_pdf_cdp + + subroutine test_uni_pdf_cqp + complex(qp) :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + real :: ans(15) = [(1.0, i=1,15)] + + print *, "Test uniform_distribution_pdf_cqp" + seed = 147258639 + call random_seed(seed, get) + loc = (-0.5_qp, 0.5_qp); scale = (1.0_qp, 1.0_qp) + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_cqp failed", warn=warn) + end subroutine test_uni_pdf_cqp + + + subroutine test_uni_cdf_iint8 + integer(int8) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [0.435643554, 0.435643554, 0.435643554, 0.702970326, & + 0.653465331, 0.485148519, 0.386138618, 0.386138618, & + 0.336633652, 0.277227730, 0.237623766, 0.524752498, & + 0.732673287, 0.534653485, 0.415841579] + + print *, "Test uniform_distribution_cdf_iint8" + seed = 369147258 + call random_seed(seed, get) + loc = 14_int8; scale = 100_int8 + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_iint8 failed", warn=warn) + end subroutine test_uni_cdf_iint8 + + subroutine test_uni_cdf_iint16 + integer(int16) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [0.178217828, 0.178217828, 0.178217828, 0.465346545, & + 0.673267305, 0.247524753, 0.158415839, 0.792079210, & + 0.742574275, 0.574257433, 0.881188095, 0.663366318, & + 0.524752498, 0.623762369, 0.178217828] + + print *, "Test uniform_distribution_cdf_iint16" + seed = 369147258 + call random_seed(seed, get) + loc = 14_int16; scale = 100_int16 + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_iint16 failed", warn=warn) + end subroutine test_uni_cdf_iint16 + + subroutine test_uni_cdf_iint32 + integer(int32) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [0.732673287, 0.732673287, 0.732673287, 0.722772300, & + 0.792079210, 5.94059415E-02, 0.841584146,0.405940592,& + 0.960396051, 0.534653485, 0.782178223, 0.861386120, & + 0.564356446, 0.613861382, 0.306930691] + + print *, "Test uniform_distribution_cdf_iint32" + seed = 369147258 + call random_seed(seed, get) + loc = 14_int32; scale = 100_int32 + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_iint32 failed", warn=warn) + end subroutine test_uni_cdf_iint32 + + subroutine test_uni_cdf_iint64 + integer(int64) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [0.455445558, 0.455445558, 0.455445558, 0.277227730, & + 0.455445558, 0.930693090, 0.851485133, 0.623762369, & + 5.94059415E-02,0.693069279, 0.544554472, 0.207920790,& + 0.306930691, 0.356435657, 0.128712878] + + print *, "Test uniform_distribution_cdf_iint64" + seed = 369147258 + call random_seed(seed, get) + loc = 14_int64; scale = 100_int64 + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_iint64 failed", warn=warn) + end subroutine test_uni_cdf_iint64 + + subroutine test_uni_cdf_rsp + real(sp) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [0.170192942, 0.170192942, 0.170192942, 0.276106149, & + 0.754930079, 0.406620681, 0.187742814, 0.651605546, & + 0.934733927, 0.151271492, 0.987674534, 0.130533904, & + 0.106271908, 9.27578658E-02, 0.203399420] + + print *, "Test uniform_distribution_cdf_rsp" + seed = 369147258 + call random_seed(seed, get) + loc = 0.0_sp; scale = 2.0_sp + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_rsp failed", warn=warn) + end subroutine test_uni_cdf_rsp + + subroutine test_uni_cdf_rdp + real(dp) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [0.170192942, 0.170192942, 0.170192942, 0.276106149, & + 0.754930079, 0.406620681, 0.187742814, 0.651605546, & + 0.934733927, 0.151271492, 0.987674534, 0.130533904, & + 0.106271908, 9.27578658E-02, 0.203399420] + + print *, "Test uniform_distribution_cdf_rdp" + seed = 369147258 + call random_seed(seed, get) + loc = 0.0_dp; scale = 2.0_dp + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_rdp failed", warn=warn) + end subroutine test_uni_cdf_rdp + + subroutine test_uni_cdf_rqp + real(qp) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [0.170192942, 0.170192942, 0.170192942, 0.276106149, & + 0.754930079, 0.406620681, 0.187742814, 0.651605546, & + 0.934733927, 0.151271492, 0.987674534, 0.130533904, & + 0.106271908, 9.27578658E-02, 0.203399420] + + print *, "Test uniform_distribution_cdf_rqp" + seed = 369147258 + call random_seed(seed, get) + loc = 0.0_qp; scale = 2.0_qp + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_rqp failed", warn=warn) + end subroutine test_uni_cdf_rqp + + subroutine test_uni_cdf_csp + complex(sp) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [4.69913185E-02, 4.69913185E-02, 4.69913185E-02, & + 0.306970179, 0.122334257, 0.141398594, 0.128925011, & + 9.85755492E-03, 8.16527531E-02, 0.163921610, & + 7.81712309E-02, 0.446415812, 5.31753292E-04, & + 0.101455867, 0.155276477] + + print *, "Test uniform_distribution_cdf_csp" + seed = 369147258 + call random_seed(seed, get) + loc = (-0.5_sp, -0.5_sp); scale = (1.0_sp, 1.0_sp) + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_csp failed", warn=warn) + end subroutine test_uni_cdf_csp + + subroutine test_uni_cdf_cdp + complex(dp) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [4.69913185E-02, 4.69913185E-02, 4.69913185E-02, & + 0.306970179, 0.122334257, 0.141398594, 0.128925011, & + 9.85755492E-03, 8.16527531E-02, 0.163921610, & + 7.81712309E-02, 0.446415812, 5.31753292E-04, & + 0.101455867, 0.155276477] + + print *, "Test uniform_distribution_cdf_cdp" + seed = 369147258 + call random_seed(seed, get) + loc = (-0.5_dp, -0.5_dp); scale = (1.0_dp, 1.0_dp) + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_cdp failed", warn=warn) + end subroutine test_uni_cdf_cdp + + subroutine test_uni_cdf_cqp + complex(qp) :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + real :: ans(15) = [4.69913185E-02, 4.69913185E-02, 4.69913185E-02, & + 0.306970179, 0.122334257, 0.141398594, 0.128925011, & + 9.85755492E-03, 8.16527531E-02, 0.163921610, & + 7.81712309E-02, 0.446415812, 5.31753292E-04, & + 0.101455867, 0.155276477] + + print *, "Test uniform_distribution_cdf_cqp" + seed = 369147258 + call random_seed(seed, get) + loc = (-0.5_qp, -0.5_qp); scale = (1.0_qp, 1.0_qp) + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_cqp failed", warn=warn) + end subroutine test_uni_cdf_cqp + + +end program test_distribution_uniform \ No newline at end of file From 7d304924fae3e84003e6b02b0e0ad4e0cd24497a Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 20 Dec 2020 12:44:29 -0500 Subject: [PATCH 007/172] convert % complex representation to real() and aimag() representation --- src/test_distribution_uniform.fypp | 282 +++++++++++++++++++++++++++++ 1 file changed, 282 insertions(+) create mode 100644 src/test_distribution_uniform.fypp diff --git a/src/test_distribution_uniform.fypp b/src/test_distribution_uniform.fypp new file mode 100644 index 000000000..9be961062 --- /dev/null +++ b/src/test_distribution_uniform.fypp @@ -0,0 +1,282 @@ +#:include "common.fypp" +#:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES +#:set ALL_KINDS_TYPES = INT_KINDS_TYPES + RC_KINDS_TYPES +program test_distribution_uniform + use stdlib_error, only : check + use stdlib_kinds + use stdlib_stats_distribution_PRNG, only : random_seed, dist_rand + use stdlib_stats_distribution_uniform, & + uni_rvs => uniform_distribution_rvs, & + uni_pdf => uniform_distribution_pdf, & + uni_cdf => uniform_distribution_cdf + + implicit none + logical :: warn = .true. + #:for k1, t1 in REAL_KINDS_TYPES + ${t1}$, parameter :: ${k1}$tol = 1000 * epsilon(1.0_${k1}$) + #:endfor + integer :: put, get + + put = 135792468 + + call test_shuffle + + call test_uni_rvs_0 + + #:for k1, t1 in ALL_KINDS_TYPES + call test_uni_rvs_${t1[0]}$${k1}$ + #:endfor + + #:for k1, t1 in ALL_KINDS_TYPES + call test_uni_pdf_${t1[0]}$${k1}$ + #:endfor + + #:for k1, t1 in ALL_KINDS_TYPES + call test_uni_cdf_${t1[0]}$${k1}$ + #:endfor + stop + + contains + + subroutine test_shuffle + integer :: n(10), na(10) = [10, 6, 9, 2, 8, 1, 3, 5, 7, 4] + real :: x(10), xa(10)= [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, & + 7.0, 6.0] + complex :: z(10), za(10)=[(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), & + (1.0, 1.0), (5.0, 5.0), (9.0, 9.0), & + (6.0, 6.0), (3.0, 3.0), (2.0, 2.0), & + (10.0, 10.0)] + integer :: i, put, get + + do i=1, 10 + n(i) = i + x(i) = real(i) + z(i) = cmplx(real(i),real(i)) + end do + put = 32165498 + call random_seed(put, get) + n(:) = shuffle(n) + x(:) = shuffle(x) + z(:) = shuffle(z) + call check(all(n == na), & + msg="Integer shuffle failed test", warn=warn) + call check(all(x == xa), & + msg="Real shuffle failed test", warn=warn) + call check(all(z == za), & + msg="Complex shuffle failed test", warn=warn) + end subroutine test_shuffle + + subroutine test_uni_rvs_0 + integer :: i, j, freq(0:1000), num=10000000 + real(dp) :: chisq, expct + + print *,"" + print *, "Test uniform random generator with chi-squared" + freq = 0 + do i = 1, num + j = 1000 * uni_rvs( ) + freq(j) = freq(j) + 1 + end do + chisq = 0.0_dp + expct = num / 1000 + do i = 0, 999 + chisq = chisq + (freq(i) - expct) ** 2 / expct + end do + write(*,*) "The critical values for chi-squared with 1000 d. of f. are" & + //" 1143.92" + write(*,*) "Chi-squared for uniform random generator is : ", chisq + call check((chisq < 1143.9) , & + msg="uniform randomness failed chi-squared test", warn=warn) + end subroutine test_uni_rvs_0 + + #:for k1, t1 in ALL_KINDS_TYPES + subroutine test_uni_rvs_${t1[0]}$${k1}$ + ${t1}$ :: res(15), scale, loc + integer :: i, n, seed, get, k + + #:if k1 == "int8" + ${t1}$ :: ans(15) = [47, 99, 43, 37, 48, 30, 27, 100, 30, 33, 21, & + 103, 55, 54, 110] + #:elif k1 == "int16" + ${t1}$ :: ans(15) = [25, 4, 81, 98, 49, 34, 32, 62, 115, 112, 26, & + 20, 37, 100, 82] + #:elif k1 == "int32" + ${t1}$ :: ans(15) = [19, 52, 56, 20, 59, 44, 34, 102, 19, 39, 60, & + 50, 97, 56, 67] + #:elif k1 == "int64" + ${t1}$ :: ans(15) = [76, 45, 43, 75, 76, 15, 25, 24, 114, 113, 94, & + 29, 109, 93, 89] + #:elif t1[0] == "r" + ${t1}$ :: ans(15) = & + [0.914826628538749186958511927514337003_${k1}$, & + 0.367330098664966409049981166390352882_${k1}$, & + 1.77591243057709280428468900936422870_${k1}$, & + 0.885921308987590139238932351872790605_${k1}$, & + 0.950735656542987861428173346212133765_${k1}$, & + -0.659562573857055134407545438079978339_${k1}$, & + -0.116661718506947176265953203255776316_${k1}$, & + 0.837391893893859151631886561517603695_${k1}$, & + -0.703954396598600540269075054311542772_${k1}$, & + 0.382592729851141566399519433616660535_${k1}$, & + -0.132472493978185168472805344208609313_${k1}$, & + -0.878723366294216184924081858298450243_${k1}$, & + -0.901660046141515819639877804547722917_${k1}$, & + -0.164090614147737401395943379611708224_${k1}$, & + -0.333886718190384290672056977200554684_${k1}$] + #:else + ${t1}$ :: ans(15) = [(0.457413315773010253906250000000000000_${k1}$, & + 0.183665052056312561035156250000000000_${k1}$), & + (0.887956202030181884765625000000000000_${k1}$, & + 0.442960649728775024414062500000000000_${k1}$), & + (0.475367814302444458007812500000000000_${k1}$, & + 0.170218706130981445312500000000000000_${k1}$), & + (0.441669136285781860351562500000000000_${k1}$, & + 0.918695926666259765625000000000000000_${k1}$), & + (0.148022800683975219726562500000000000_${k1}$, & + 0.691296339035034179687500000000000000_${k1}$), & + (-6.623625010251998901367187500000000000E-0002_${k1}$, & + 0.560638308525085449218750000000000000_${k1}$), & + (-0.450830012559890747070312500000000000_${k1}$, & + 0.917954683303833007812500000000000000_${k1}$), & + (-0.166943356394767761230468750000000000_${k1}$, & + 1.05997407436370849609375000000000000_${k1}$), & + (-0.429652184247970581054687500000000000_${k1}$, & + 0.523558259010314941406250000000000000_${k1}$), & + (0.427181094884872436523437500000000000_${k1}$, & + 1.34628939628601074218750000000000000_${k1}$), & + (-0.343281418085098266601562500000000000_${k1}$, & + 1.15357327461242675781250000000000000_${k1}$), & + (-0.127590075135231018066406250000000000_${k1}$, & + 1.06891202926635742187500000000000000_${k1}$), & + (0.262287586927413940429687500000000000_${k1}$, & + 1.29508924484252929687500000000000000_${k1}$), & + (-0.192677408456802368164062500000000000_${k1}$, & + 1.32794928550720214843750000000000000_${k1}$), & + (-0.264742136001586914062500000000000000_${k1}$, & + 1.01282966136932373046875000000000000_${k1}$)] + #:endif + + print *, "Test uniform_distribution_rvs_${t1[0]}$${k1}$" + seed = 258147369; k = 5 + call random_seed(seed, get) + #:if t1[0] == "i" + loc = 15_${k1}$; scale = 100_${k1}$ + #:elif t1[0] == "r" + loc = -1.0_${k1}$; scale = 2.0_${k1}$ + #:else + loc = (-0.5_${k1}$,0.5_${k1}$); scale = (1.0_${k1}$, 1.0_${k1}$) + #:endif + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + #:if t1[0] == "i" + call check(all(res == ans), & + msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) + #:elif t1[0] == "r" + call check(all(abs(res - ans) < ${k1}$tol), & + msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) + #:else + call check(all(abs(real(res) - real(ans)) < ${k1}$tol) .and. & + all(abs(aimag(res) - aimag(ans)) < ${k1}$tol), & + msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) + #:endif + end subroutine test_uni_rvs_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in ALL_KINDS_TYPES + subroutine test_uni_pdf_${t1[0]}$${k1}$ + ${t1}$ :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + #:if t1[0] == "i" + real :: ans(15) = [(1.96078438E-02, i=1,15)] + #:elif t1[0] == "r" + real :: ans(15) = [(0.5, i=1,15)] + #:else + real :: ans(15) = [(1.0, i=1,15)] + #:endif + + print *, "Test uniform_distribution_pdf_${t1[0]}$${k1}$" + seed = 147258639 + call random_seed(seed, get) + #:if t1[0] == "i" + loc = 0_${k1}$; scale = 50_${k1}$ + #:elif t1[0] == "r" + loc = 0.0_${k1}$; scale = 2.0_${k1}$ + #:else + loc = (-0.5_${k1}$, 0.5_${k1}$); scale = (1.0_${k1}$, 1.0_${k1}$) + #:endif + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_${t1[0]}$${k1}$ failed", warn=warn) + end subroutine test_uni_pdf_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in ALL_KINDS_TYPES + subroutine test_uni_cdf_${t1[0]}$${k1}$ + ${t1}$ :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + #:if k1 == "int8" + real :: ans(15) = [0.435643554, 0.435643554, 0.435643554, 0.702970326, & + 0.653465331, 0.485148519, 0.386138618, 0.386138618, & + 0.336633652, 0.277227730, 0.237623766, 0.524752498, & + 0.732673287, 0.534653485, 0.415841579] + #:elif k1 == "int16" + real :: ans(15) = [0.178217828, 0.178217828, 0.178217828, 0.465346545, & + 0.673267305, 0.247524753, 0.158415839, 0.792079210, & + 0.742574275, 0.574257433, 0.881188095, 0.663366318, & + 0.524752498, 0.623762369, 0.178217828] + #:elif k1 == "int32" + real :: ans(15) = [0.732673287, 0.732673287, 0.732673287, 0.722772300, & + 0.792079210, 5.94059415E-02, 0.841584146,0.405940592,& + 0.960396051, 0.534653485, 0.782178223, 0.861386120, & + 0.564356446, 0.613861382, 0.306930691] + #:elif k1 == "int64" + real :: ans(15) = [0.455445558, 0.455445558, 0.455445558, 0.277227730, & + 0.455445558, 0.930693090, 0.851485133, 0.623762369, & + 5.94059415E-02,0.693069279, 0.544554472, 0.207920790,& + 0.306930691, 0.356435657, 0.128712878] + #:elif t1[0] == "r" + real :: ans(15) = [0.170192942, 0.170192942, 0.170192942, 0.276106149, & + 0.754930079, 0.406620681, 0.187742814, 0.651605546, & + 0.934733927, 0.151271492, 0.987674534, 0.130533904, & + 0.106271908, 9.27578658E-02, 0.203399420] + #:else + real :: ans(15) = [4.69913185E-02, 4.69913185E-02, 4.69913185E-02, & + 0.306970179, 0.122334257, 0.141398594, 0.128925011, & + 9.85755492E-03, 8.16527531E-02, 0.163921610, & + 7.81712309E-02, 0.446415812, 5.31753292E-04, & + 0.101455867, 0.155276477] + #:endif + + print *, "Test uniform_distribution_cdf_${t1[0]}$${k1}$" + seed = 369147258 + call random_seed(seed, get) + #:if t1[0] == "i" + loc = 14_${k1}$; scale = 100_${k1}$ + #:elif t1[0] == "r" + loc = 0.0_${k1}$; scale = 2.0_${k1}$ + #:else + loc = (-0.5_${k1}$, -0.5_${k1}$); scale = (1.0_${k1}$, 1.0_${k1}$) + #:endif + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_${t1[0]}$${k1}$ failed", warn=warn) + end subroutine test_uni_cdf_${t1[0]}$${k1}$ + + #:endfor + +end program test_distribution_uniform \ No newline at end of file From 0d3b59fe7ec7b2283000395795a6bdec1df3972f Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 20 Dec 2020 12:45:22 -0500 Subject: [PATCH 008/172] Convert complex representation --- src/tests/test_distribution_uniform.f90 | 198 ++++++++++++------------ 1 file changed, 99 insertions(+), 99 deletions(-) diff --git a/src/tests/test_distribution_uniform.f90 b/src/tests/test_distribution_uniform.f90 index 152c5a3dd..0f6315a6a 100644 --- a/src/tests/test_distribution_uniform.f90 +++ b/src/tests/test_distribution_uniform.f90 @@ -227,7 +227,7 @@ subroutine test_uni_rvs_rsp res(i) = uni_rvs(loc, scale) ! 2 dummies end do res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(res - ans) < sptol), & + call check(all(abs(res - ans) < sptol), & msg="uniform_distribution_rvs_rsp failed", warn=warn) end subroutine test_uni_rvs_rsp @@ -263,7 +263,7 @@ subroutine test_uni_rvs_rdp res(i) = uni_rvs(loc, scale) ! 2 dummies end do res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(res - ans) < dptol), & + call check(all(abs(res - ans) < dptol), & msg="uniform_distribution_rvs_rdp failed", warn=warn) end subroutine test_uni_rvs_rdp @@ -299,7 +299,7 @@ subroutine test_uni_rvs_rqp res(i) = uni_rvs(loc, scale) ! 2 dummies end do res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(res - ans) < qptol), & + call check(all(abs(res - ans) < qptol), & msg="uniform_distribution_rvs_rqp failed", warn=warn) end subroutine test_uni_rvs_rqp @@ -307,36 +307,36 @@ subroutine test_uni_rvs_csp complex(sp) :: res(15), scale, loc integer :: i, n, seed, get, k - complex(sp) :: ans(15) = [(0.457413314269374593479255963757168502_sp, & - 0.183665049332483204524990583195176441_sp), & - (0.887956215288546402142344504682114348_sp, & - 0.442960654493795069619466175936395302_sp), & - (0.475367828271493930714086673106066883_sp, & - 0.170218713071472432796227280960010830_sp), & - (0.441669140746526411867023398372111842_sp, & - 0.918695946946929575815943280758801848_sp), & - (0.148022801700699729865462472844228614_sp, & - 0.691296364925570783199759716808330268_sp), & - (-6.623624698909258423640267210430465639E-0002_sp, & - 0.560638316852891907537959070850774879_sp), & - (-0.450830023070757909819938902273861459_sp, & - 0.917954692926131299302028310194145888_sp), & - (-0.166943359095192145336028488600277342_sp, & - 1.05997401970850635422038976685144007_sp), & - (-0.429652190199228276035192664039641386_sp, & - 0.523558274341032421628217008446881664_sp), & - (0.427181091476823815433760955784237012_sp, & - 1.34628934976074521312483511792379431_sp), & - (-0.343281426018765739582860874179459643_sp, & - 1.15357331316264255516301773241139017_sp), & - (-0.127590074749816595467422075671493076_sp, & - 1.06891199479835175001340985545539297_sp), & - (0.262287586904722758163188700564205647_sp, & - 1.29508919831907332032017166056903079_sp), & - (-0.192677407376582732201342196276527829_sp, & - 1.32794925614337933073016984053538181_sp), & - (-0.264742129752461530234342035328154452_sp, & - 1.01282963412172621886497836385387927_sp)] + complex(sp) :: ans(15) = [(0.457413315773010253906250000000000000_sp, & + 0.183665052056312561035156250000000000_sp), & + (0.887956202030181884765625000000000000_sp, & + 0.442960649728775024414062500000000000_sp), & + (0.475367814302444458007812500000000000_sp, & + 0.170218706130981445312500000000000000_sp), & + (0.441669136285781860351562500000000000_sp, & + 0.918695926666259765625000000000000000_sp), & + (0.148022800683975219726562500000000000_sp, & + 0.691296339035034179687500000000000000_sp), & + (-6.623625010251998901367187500000000000E-0002_sp, & + 0.560638308525085449218750000000000000_sp), & + (-0.450830012559890747070312500000000000_sp, & + 0.917954683303833007812500000000000000_sp), & + (-0.166943356394767761230468750000000000_sp, & + 1.05997407436370849609375000000000000_sp), & + (-0.429652184247970581054687500000000000_sp, & + 0.523558259010314941406250000000000000_sp), & + (0.427181094884872436523437500000000000_sp, & + 1.34628939628601074218750000000000000_sp), & + (-0.343281418085098266601562500000000000_sp, & + 1.15357327461242675781250000000000000_sp), & + (-0.127590075135231018066406250000000000_sp, & + 1.06891202926635742187500000000000000_sp), & + (0.262287586927413940429687500000000000_sp, & + 1.29508924484252929687500000000000000_sp), & + (-0.192677408456802368164062500000000000_sp, & + 1.32794928550720214843750000000000000_sp), & + (-0.264742136001586914062500000000000000_sp, & + 1.01282966136932373046875000000000000_sp)] print *, "Test uniform_distribution_rvs_csp" seed = 258147369; k = 5 @@ -349,8 +349,8 @@ subroutine test_uni_rvs_csp res(i) = uni_rvs(loc, scale) ! 2 dummies end do res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(res%re - ans%re) < sptol) .and. & - all(abs(res%im - ans%im) < sptol), & + call check(all(abs(real(res) - real(ans)) < sptol) .and. & + all(abs(aimag(res) - aimag(ans)) < sptol), & msg="uniform_distribution_rvs_csp failed", warn=warn) end subroutine test_uni_rvs_csp @@ -358,36 +358,36 @@ subroutine test_uni_rvs_cdp complex(dp) :: res(15), scale, loc integer :: i, n, seed, get, k - complex(dp) :: ans(15) = [(0.457413314269374593479255963757168502_dp, & - 0.183665049332483204524990583195176441_dp), & - (0.887956215288546402142344504682114348_dp, & - 0.442960654493795069619466175936395302_dp), & - (0.475367828271493930714086673106066883_dp, & - 0.170218713071472432796227280960010830_dp), & - (0.441669140746526411867023398372111842_dp, & - 0.918695946946929575815943280758801848_dp), & - (0.148022801700699729865462472844228614_dp, & - 0.691296364925570783199759716808330268_dp), & - (-6.623624698909258423640267210430465639E-0002_dp, & - 0.560638316852891907537959070850774879_dp), & - (-0.450830023070757909819938902273861459_dp, & - 0.917954692926131299302028310194145888_dp), & - (-0.166943359095192145336028488600277342_dp, & - 1.05997401970850635422038976685144007_dp), & - (-0.429652190199228276035192664039641386_dp, & - 0.523558274341032421628217008446881664_dp), & - (0.427181091476823815433760955784237012_dp, & - 1.34628934976074521312483511792379431_dp), & - (-0.343281426018765739582860874179459643_dp, & - 1.15357331316264255516301773241139017_dp), & - (-0.127590074749816595467422075671493076_dp, & - 1.06891199479835175001340985545539297_dp), & - (0.262287586904722758163188700564205647_dp, & - 1.29508919831907332032017166056903079_dp), & - (-0.192677407376582732201342196276527829_dp, & - 1.32794925614337933073016984053538181_dp), & - (-0.264742129752461530234342035328154452_dp, & - 1.01282963412172621886497836385387927_dp)] + complex(dp) :: ans(15) = [(0.457413315773010253906250000000000000_dp, & + 0.183665052056312561035156250000000000_dp), & + (0.887956202030181884765625000000000000_dp, & + 0.442960649728775024414062500000000000_dp), & + (0.475367814302444458007812500000000000_dp, & + 0.170218706130981445312500000000000000_dp), & + (0.441669136285781860351562500000000000_dp, & + 0.918695926666259765625000000000000000_dp), & + (0.148022800683975219726562500000000000_dp, & + 0.691296339035034179687500000000000000_dp), & + (-6.623625010251998901367187500000000000E-0002_dp, & + 0.560638308525085449218750000000000000_dp), & + (-0.450830012559890747070312500000000000_dp, & + 0.917954683303833007812500000000000000_dp), & + (-0.166943356394767761230468750000000000_dp, & + 1.05997407436370849609375000000000000_dp), & + (-0.429652184247970581054687500000000000_dp, & + 0.523558259010314941406250000000000000_dp), & + (0.427181094884872436523437500000000000_dp, & + 1.34628939628601074218750000000000000_dp), & + (-0.343281418085098266601562500000000000_dp, & + 1.15357327461242675781250000000000000_dp), & + (-0.127590075135231018066406250000000000_dp, & + 1.06891202926635742187500000000000000_dp), & + (0.262287586927413940429687500000000000_dp, & + 1.29508924484252929687500000000000000_dp), & + (-0.192677408456802368164062500000000000_dp, & + 1.32794928550720214843750000000000000_dp), & + (-0.264742136001586914062500000000000000_dp, & + 1.01282966136932373046875000000000000_dp)] print *, "Test uniform_distribution_rvs_cdp" seed = 258147369; k = 5 @@ -400,8 +400,8 @@ subroutine test_uni_rvs_cdp res(i) = uni_rvs(loc, scale) ! 2 dummies end do res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(res%re - ans%re) < dptol) .and. & - all(abs(res%im - ans%im) < dptol), & + call check(all(abs(real(res) - real(ans)) < dptol) .and. & + all(abs(aimag(res) - aimag(ans)) < dptol), & msg="uniform_distribution_rvs_cdp failed", warn=warn) end subroutine test_uni_rvs_cdp @@ -409,36 +409,36 @@ subroutine test_uni_rvs_cqp complex(qp) :: res(15), scale, loc integer :: i, n, seed, get, k - complex(qp) :: ans(15) = [(0.457413314269374593479255963757168502_qp, & - 0.183665049332483204524990583195176441_qp), & - (0.887956215288546402142344504682114348_qp, & - 0.442960654493795069619466175936395302_qp), & - (0.475367828271493930714086673106066883_qp, & - 0.170218713071472432796227280960010830_qp), & - (0.441669140746526411867023398372111842_qp, & - 0.918695946946929575815943280758801848_qp), & - (0.148022801700699729865462472844228614_qp, & - 0.691296364925570783199759716808330268_qp), & - (-6.623624698909258423640267210430465639E-0002_qp, & - 0.560638316852891907537959070850774879_qp), & - (-0.450830023070757909819938902273861459_qp, & - 0.917954692926131299302028310194145888_qp), & - (-0.166943359095192145336028488600277342_qp, & - 1.05997401970850635422038976685144007_qp), & - (-0.429652190199228276035192664039641386_qp, & - 0.523558274341032421628217008446881664_qp), & - (0.427181091476823815433760955784237012_qp, & - 1.34628934976074521312483511792379431_qp), & - (-0.343281426018765739582860874179459643_qp, & - 1.15357331316264255516301773241139017_qp), & - (-0.127590074749816595467422075671493076_qp, & - 1.06891199479835175001340985545539297_qp), & - (0.262287586904722758163188700564205647_qp, & - 1.29508919831907332032017166056903079_qp), & - (-0.192677407376582732201342196276527829_qp, & - 1.32794925614337933073016984053538181_qp), & - (-0.264742129752461530234342035328154452_qp, & - 1.01282963412172621886497836385387927_qp)] + complex(qp) :: ans(15) = [(0.457413315773010253906250000000000000_qp, & + 0.183665052056312561035156250000000000_qp), & + (0.887956202030181884765625000000000000_qp, & + 0.442960649728775024414062500000000000_qp), & + (0.475367814302444458007812500000000000_qp, & + 0.170218706130981445312500000000000000_qp), & + (0.441669136285781860351562500000000000_qp, & + 0.918695926666259765625000000000000000_qp), & + (0.148022800683975219726562500000000000_qp, & + 0.691296339035034179687500000000000000_qp), & + (-6.623625010251998901367187500000000000E-0002_qp, & + 0.560638308525085449218750000000000000_qp), & + (-0.450830012559890747070312500000000000_qp, & + 0.917954683303833007812500000000000000_qp), & + (-0.166943356394767761230468750000000000_qp, & + 1.05997407436370849609375000000000000_qp), & + (-0.429652184247970581054687500000000000_qp, & + 0.523558259010314941406250000000000000_qp), & + (0.427181094884872436523437500000000000_qp, & + 1.34628939628601074218750000000000000_qp), & + (-0.343281418085098266601562500000000000_qp, & + 1.15357327461242675781250000000000000_qp), & + (-0.127590075135231018066406250000000000_qp, & + 1.06891202926635742187500000000000000_qp), & + (0.262287586927413940429687500000000000_qp, & + 1.29508924484252929687500000000000000_qp), & + (-0.192677408456802368164062500000000000_qp, & + 1.32794928550720214843750000000000000_qp), & + (-0.264742136001586914062500000000000000_qp, & + 1.01282966136932373046875000000000000_qp)] print *, "Test uniform_distribution_rvs_cqp" seed = 258147369; k = 5 @@ -451,8 +451,8 @@ subroutine test_uni_rvs_cqp res(i) = uni_rvs(loc, scale) ! 2 dummies end do res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(res%re - ans%re) < qptol) .and. & - all(abs(res%im - ans%im) < qptol), & + call check(all(abs(real(res) - real(ans)) < qptol) .and. & + all(abs(aimag(res) - aimag(ans)) < qptol), & msg="uniform_distribution_rvs_cqp failed", warn=warn) end subroutine test_uni_rvs_cqp From 3987d62b258bf24c1cb14687e8a85cea6bba9db4 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 20 Dec 2020 12:46:14 -0500 Subject: [PATCH 009/172] Convert complex number representtion --- src/stdlib_stats_distribution_uniform.fypp | 88 +++++++++++----------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index 1b767e48b..c8314f3d9 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -153,7 +153,7 @@ Module stdlib_stats_distribution_uniform ${t1}$, intent(in) :: scale ${t1}$ :: res - if(scale == 0_${k1}$) call error_stop("Error: Uniform distribution" & + if(scale == 0._${k1}$) call error_stop("Error: Uniform distribution" & //" scale parameter must be non-zero") res = scale * unif_dist_rvs_0_${t1[0]}$${k1}$( ) return @@ -169,7 +169,7 @@ Module stdlib_stats_distribution_uniform ${t1}$, intent(in) :: loc, scale ${t1}$ :: res - if(scale == 0_${k1}$) call error_stop("Error: Uniform distribution" & + if(scale == 0._${k1}$) call error_stop("Error: Uniform distribution" & //" scale parameter must be non-zero") res = loc + scale * unif_dist_rvs_0_${t1[0]}$${k1}$( ) return @@ -186,22 +186,23 @@ Module stdlib_stats_distribution_uniform ${t1}$, intent(in) :: scale ${t1}$ :: res integer(int64) :: tmp - real(${k1}$) :: r1, r2 + real(${k1}$) :: r1, r2, tr, ti if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error: Uniform" & //" distribution scale parameter must be non-zero") r1 = unif_dist_rvs_0_r${k1}$( ) - if(scale%re == 0.0_${k1}$) then - res%im = scale%im * r1 - res%re = 0.0_${k1}$ - elseif(scale%im == 0.0_${k1}$) then - res%re = scale%re * r1 - res%im = 0.0_${k1}$ + if(real(scale) == 0.0_${k1}$) then + ti = aimag(scale) * r1 + tr = 0.0_${k1}$ + elseif(aimag(scale) == 0.0_${k1}$) then + tr = real(scale) * r1 + ti = 0.0_${k1}$ else r2 = unif_dist_rvs_0_r${k1}$( ) - res%re = scale%re * r1 - res%im = scale%im * r2 + tr = real(scale) * r1 + ti = aimag(scale) * r2 endif + res = cmplx(tr, ti) return end function unif_dist_rvs_1_${t1[0]}$${k1}$ @@ -218,22 +219,23 @@ Module stdlib_stats_distribution_uniform ${t1}$, intent(in) :: loc, scale ${t1}$ :: res integer(int64) :: tmp - real(${k1}$) :: r1, r2 + real(${k1}$) :: r1, r2, tr, ti if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error: Uniform" & //" distribution scale parameter must be non-zero") r1 = unif_dist_rvs_0_r${k1}$( ) - if(scale%re == 0.0_${k1}$) then - res%re = loc%re - res%im = loc%im + scale%im * r1 - elseif(scale%im == 0.0_${k1}$) then - res%re = loc%re + scale%re * r1 - res%im = loc%im + if(real(scale) == 0.0_${k1}$) then + tr = real(loc) + ti = aimag(loc) + aimag(scale) * r1 + elseif(aimag(scale) == 0.0_${k1}$) then + tr = real(loc) + real(scale) * r1 + ti = aimag(loc) else r2 = unif_dist_rvs_0_r${k1}$( ) - res%re = loc%re + scale%re * r1 - res%im = loc%im + scale%im * r2 + tr = real(loc) + real(scale) * r1 + ti = aimag(loc) + aimag(scale) * r2 endif + res = cmplx(tr, ti) return end function unif_dist_rvs_${t1[0]}$${k1}$ @@ -287,7 +289,7 @@ Module stdlib_stats_distribution_uniform integer :: i - if(scale == 0_${k1}$) call error_stop("Error: Uniform distribution" & + if(scale == 0._${k1}$) call error_stop("Error: Uniform distribution" & //" scale parameter must be non-zero") allocate(res(array_size)) do i = 1, array_size @@ -305,8 +307,7 @@ Module stdlib_stats_distribution_uniform result(res) ${t1}$, intent(in) :: loc, scale ${t1}$, allocatable :: res(:) - ${t1}$ :: t - real(${k1}$) :: r1, r2 + real(${k1}$) :: r1, r2, tr, ti integer, intent(in) :: array_size integer(int64) :: tmp integer :: i @@ -318,19 +319,19 @@ Module stdlib_stats_distribution_uniform do i = 1, array_size tmp = shiftr(dist_rand(INT_ONE), 11) r1 = real(tmp * MESENNE_NUMBER, kind = ${k1}$) - if(scale%re == 0.0_${k1}$) then - t%re = loc%re - t%im = loc%im + scale%im * r1 - elseif(scale%im == 0.0_${k1}$) then - t%re = loc%re + scale%re * r1 - t%im = loc%im + if(real(scale) == 0.0_${k1}$) then + tr = real(loc) + ti = aimag(loc) + aimag(scale) * r1 + elseif(aimag(scale) == 0.0_${k1}$) then + tr = real(loc) + real(scale) * r1 + ti = aimag(loc) else tmp = shiftr(dist_rand(INT_ONE), 11) r2 = real(tmp * MESENNE_NUMBER, kind = ${k1}$) - t%re = loc%re + scale%re * r1 - t%im = loc%im + scale%im * r2 + tr = real(loc) + real(scale) * r1 + ti = aimag(loc) + aimag(scale) * r2 endif - res(i) = t + res(i) = cmplx(tr, ti) enddo return end function unif_dist_rvs_array_${t1[0]}$${k1}$ @@ -375,12 +376,14 @@ Module stdlib_stats_distribution_uniform elemental function unif_dist_pdf_${t1[0]}$${k1}$(x, loc, scale) result(res) ${t1}$, intent(in) :: x, loc, scale real :: res + real(${k1}$) :: tr, ti + tr = real(loc) + real(scale); ti = aimag(loc) + aimag(scale) if(scale == (0.0_${k1}$,0.0_${k1}$)) then res = 0.0 - elseif((x%re >= loc%re .and. x%re <= loc%re + scale%re) .and. & - (x%im >= loc%im .and. x%im <= loc%im + scale%im)) then - res = 1.0 / (scale%re * scale%im) + elseif((real(x) >= real(loc) .and. real(x) <= tr) .and. & + (aimag(x) >= aimag(loc) .and. aimag(x) <= ti)) then + res = 1.0 / (real(scale) * aimag(scale)) else res = 0.0 end if @@ -437,19 +440,20 @@ Module stdlib_stats_distribution_uniform res = 0.0 return endif - r1 = x%re < loc%re - r2 = x%re > (loc%re + scale%re) - i1 = x%im < loc%im - i2 = x%im > (loc%im + scale%im) + r1 = real(x) < real(loc) + r2 = real(x) > (real(loc) + real(scale)) + i1 = aimag(x) < aimag(loc) + i2 = aimag(x) > (aimag(loc) + aimag(scale)) if(r1 .or. i1) then res = 0.0 elseif((.not. r1) .and. (.not. r2) .and. i2) then - res = (x%re - loc%re) / scale%re + res = (real(x) - real(loc)) / real(scale) elseif((.not. i1) .and. (.not. i2) .and. r2) then - res = (x%im - loc%im) / scale%im + res = (aimag(x) - aimag(loc)) / aimag(scale) elseif((.not. r1) .and. (.not. r2) .and. (.not. i1) .and. (.not. i2)) & then - res = (x%re - loc%re) * (x%im - loc%im) / (scale%re * scale%im) + res = (real(x) - real(loc)) * (aimag(x) - aimag(loc)) / & + (real(scale) * aimag(scale)) elseif(r2 .and. i2)then res = 1.0 end if From 98e3d4817a1cfda80007d78ab9772f5010b833a6 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 20 Dec 2020 12:53:47 -0500 Subject: [PATCH 010/172] remove tab --- src/stdlib_stats_distribution_uniform.fypp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index c8314f3d9..005adbf84 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -202,7 +202,7 @@ Module stdlib_stats_distribution_uniform tr = real(scale) * r1 ti = aimag(scale) * r2 endif - res = cmplx(tr, ti) + res = cmplx(tr, ti) return end function unif_dist_rvs_1_${t1[0]}$${k1}$ @@ -235,7 +235,7 @@ Module stdlib_stats_distribution_uniform tr = real(loc) + real(scale) * r1 ti = aimag(loc) + aimag(scale) * r2 endif - res = cmplx(tr, ti) + res = cmplx(tr, ti) return end function unif_dist_rvs_${t1[0]}$${k1}$ @@ -453,7 +453,7 @@ Module stdlib_stats_distribution_uniform elseif((.not. r1) .and. (.not. r2) .and. (.not. i1) .and. (.not. i2)) & then res = (real(x) - real(loc)) * (aimag(x) - aimag(loc)) / & - (real(scale) * aimag(scale)) + (real(scale) * aimag(scale)) elseif(r2 .and. i2)then res = 1.0 end if From b71419406b3db6ef17cc74044e9353270dfdb043 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 20 Dec 2020 12:54:12 -0500 Subject: [PATCH 011/172] remove tab --- src/tests/stats/test_distribution_uniform.f90 | 218 ++++++++---------- 1 file changed, 101 insertions(+), 117 deletions(-) diff --git a/src/tests/stats/test_distribution_uniform.f90 b/src/tests/stats/test_distribution_uniform.f90 index da30cde4e..f299f96d3 100644 --- a/src/tests/stats/test_distribution_uniform.f90 +++ b/src/tests/stats/test_distribution_uniform.f90 @@ -13,25 +13,9 @@ program test_distribution_uniform real(dp), parameter :: dptol = 1000 * epsilon(1.0_dp) real(qp), parameter :: qptol = 1000 * epsilon(1.0_qp) integer :: put, get - complex :: loc, scale - real :: a(3,4,5), b(3,4,5), x(3,4,5) + put = 135792468 - put = 1234567 - call random_seed(put, get) - print *, uni_cdf(0.5,0.,1.) ! a cumulative at 0.5 in [0., 1.] - print *, uni_cdf(0.7,-1.0,2.0) ! a cumulative at 0.7 in [-1.0, 1.0] - - print *, uni_cdf(6, 2, 10) ! a cumulative at 6 in [2, 10] - - a(:,:,:) = -1.0 - b(:,:,:) = 2.0 - x = reshape(uni_rvs(-1.0,2.0,60),[3,4,5]) ! uniform random variates array - print *, uni_cdf(x,a,b) ! cumulative array in [-1.0, 1.0] - - loc = (0., 0.) - scale=(2., 1.) - print *, uni_cdf((1.2,0.5), loc, scale) - stop + call test_shuffle call test_uni_rvs_0 @@ -243,7 +227,7 @@ subroutine test_uni_rvs_rsp res(i) = uni_rvs(loc, scale) ! 2 dummies end do res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(res - ans) < sptol), & + call check(all(abs(res - ans) < sptol), & msg="uniform_distribution_rvs_rsp failed", warn=warn) end subroutine test_uni_rvs_rsp @@ -279,7 +263,7 @@ subroutine test_uni_rvs_rdp res(i) = uni_rvs(loc, scale) ! 2 dummies end do res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(res - ans) < dptol), & + call check(all(abs(res - ans) < dptol), & msg="uniform_distribution_rvs_rdp failed", warn=warn) end subroutine test_uni_rvs_rdp @@ -315,7 +299,7 @@ subroutine test_uni_rvs_rqp res(i) = uni_rvs(loc, scale) ! 2 dummies end do res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(res - ans) < qptol), & + call check(all(abs(res - ans) < qptol), & msg="uniform_distribution_rvs_rqp failed", warn=warn) end subroutine test_uni_rvs_rqp @@ -323,36 +307,36 @@ subroutine test_uni_rvs_csp complex(sp) :: res(15), scale, loc integer :: i, n, seed, get, k - complex(sp) :: ans(15) = [(0.457413314269374593479255963757168502_sp, & - 0.183665049332483204524990583195176441_sp), & - (0.887956215288546402142344504682114348_sp, & - 0.442960654493795069619466175936395302_sp), & - (0.475367828271493930714086673106066883_sp, & - 0.170218713071472432796227280960010830_sp), & - (0.441669140746526411867023398372111842_sp, & - 0.918695946946929575815943280758801848_sp), & - (0.148022801700699729865462472844228614_sp, & - 0.691296364925570783199759716808330268_sp), & - (-6.623624698909258423640267210430465639E-0002_sp, & - 0.560638316852891907537959070850774879_sp), & - (-0.450830023070757909819938902273861459_sp, & - 0.917954692926131299302028310194145888_sp), & - (-0.166943359095192145336028488600277342_sp, & - 1.05997401970850635422038976685144007_sp), & - (-0.429652190199228276035192664039641386_sp, & - 0.523558274341032421628217008446881664_sp), & - (0.427181091476823815433760955784237012_sp, & - 1.34628934976074521312483511792379431_sp), & - (-0.343281426018765739582860874179459643_sp, & - 1.15357331316264255516301773241139017_sp), & - (-0.127590074749816595467422075671493076_sp, & - 1.06891199479835175001340985545539297_sp), & - (0.262287586904722758163188700564205647_sp, & - 1.29508919831907332032017166056903079_sp), & - (-0.192677407376582732201342196276527829_sp, & - 1.32794925614337933073016984053538181_sp), & - (-0.264742129752461530234342035328154452_sp, & - 1.01282963412172621886497836385387927_sp)] + complex(sp) :: ans(15) = [(0.457413315773010253906250000000000000_sp, & + 0.183665052056312561035156250000000000_sp), & + (0.887956202030181884765625000000000000_sp, & + 0.442960649728775024414062500000000000_sp), & + (0.475367814302444458007812500000000000_sp, & + 0.170218706130981445312500000000000000_sp), & + (0.441669136285781860351562500000000000_sp, & + 0.918695926666259765625000000000000000_sp), & + (0.148022800683975219726562500000000000_sp, & + 0.691296339035034179687500000000000000_sp), & + (-6.623625010251998901367187500000000000E-0002_sp, & + 0.560638308525085449218750000000000000_sp), & + (-0.450830012559890747070312500000000000_sp, & + 0.917954683303833007812500000000000000_sp), & + (-0.166943356394767761230468750000000000_sp, & + 1.05997407436370849609375000000000000_sp), & + (-0.429652184247970581054687500000000000_sp, & + 0.523558259010314941406250000000000000_sp), & + (0.427181094884872436523437500000000000_sp, & + 1.34628939628601074218750000000000000_sp), & + (-0.343281418085098266601562500000000000_sp, & + 1.15357327461242675781250000000000000_sp), & + (-0.127590075135231018066406250000000000_sp, & + 1.06891202926635742187500000000000000_sp), & + (0.262287586927413940429687500000000000_sp, & + 1.29508924484252929687500000000000000_sp), & + (-0.192677408456802368164062500000000000_sp, & + 1.32794928550720214843750000000000000_sp), & + (-0.264742136001586914062500000000000000_sp, & + 1.01282966136932373046875000000000000_sp)] print *, "Test uniform_distribution_rvs_csp" seed = 258147369; k = 5 @@ -365,8 +349,8 @@ subroutine test_uni_rvs_csp res(i) = uni_rvs(loc, scale) ! 2 dummies end do res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(res%re - ans%re) < sptol) .and. & - all(abs(res%im - ans%im) < sptol), & + call check(all(abs(real(res) - real(ans)) < sptol) .and. & + all(abs(aimag(res) - aimag(ans)) < sptol), & msg="uniform_distribution_rvs_csp failed", warn=warn) end subroutine test_uni_rvs_csp @@ -374,36 +358,36 @@ subroutine test_uni_rvs_cdp complex(dp) :: res(15), scale, loc integer :: i, n, seed, get, k - complex(dp) :: ans(15) = [(0.457413314269374593479255963757168502_dp, & - 0.183665049332483204524990583195176441_dp), & - (0.887956215288546402142344504682114348_dp, & - 0.442960654493795069619466175936395302_dp), & - (0.475367828271493930714086673106066883_dp, & - 0.170218713071472432796227280960010830_dp), & - (0.441669140746526411867023398372111842_dp, & - 0.918695946946929575815943280758801848_dp), & - (0.148022801700699729865462472844228614_dp, & - 0.691296364925570783199759716808330268_dp), & - (-6.623624698909258423640267210430465639E-0002_dp, & - 0.560638316852891907537959070850774879_dp), & - (-0.450830023070757909819938902273861459_dp, & - 0.917954692926131299302028310194145888_dp), & - (-0.166943359095192145336028488600277342_dp, & - 1.05997401970850635422038976685144007_dp), & - (-0.429652190199228276035192664039641386_dp, & - 0.523558274341032421628217008446881664_dp), & - (0.427181091476823815433760955784237012_dp, & - 1.34628934976074521312483511792379431_dp), & - (-0.343281426018765739582860874179459643_dp, & - 1.15357331316264255516301773241139017_dp), & - (-0.127590074749816595467422075671493076_dp, & - 1.06891199479835175001340985545539297_dp), & - (0.262287586904722758163188700564205647_dp, & - 1.29508919831907332032017166056903079_dp), & - (-0.192677407376582732201342196276527829_dp, & - 1.32794925614337933073016984053538181_dp), & - (-0.264742129752461530234342035328154452_dp, & - 1.01282963412172621886497836385387927_dp)] + complex(dp) :: ans(15) = [(0.457413315773010253906250000000000000_dp, & + 0.183665052056312561035156250000000000_dp), & + (0.887956202030181884765625000000000000_dp, & + 0.442960649728775024414062500000000000_dp), & + (0.475367814302444458007812500000000000_dp, & + 0.170218706130981445312500000000000000_dp), & + (0.441669136285781860351562500000000000_dp, & + 0.918695926666259765625000000000000000_dp), & + (0.148022800683975219726562500000000000_dp, & + 0.691296339035034179687500000000000000_dp), & + (-6.623625010251998901367187500000000000E-0002_dp, & + 0.560638308525085449218750000000000000_dp), & + (-0.450830012559890747070312500000000000_dp, & + 0.917954683303833007812500000000000000_dp), & + (-0.166943356394767761230468750000000000_dp, & + 1.05997407436370849609375000000000000_dp), & + (-0.429652184247970581054687500000000000_dp, & + 0.523558259010314941406250000000000000_dp), & + (0.427181094884872436523437500000000000_dp, & + 1.34628939628601074218750000000000000_dp), & + (-0.343281418085098266601562500000000000_dp, & + 1.15357327461242675781250000000000000_dp), & + (-0.127590075135231018066406250000000000_dp, & + 1.06891202926635742187500000000000000_dp), & + (0.262287586927413940429687500000000000_dp, & + 1.29508924484252929687500000000000000_dp), & + (-0.192677408456802368164062500000000000_dp, & + 1.32794928550720214843750000000000000_dp), & + (-0.264742136001586914062500000000000000_dp, & + 1.01282966136932373046875000000000000_dp)] print *, "Test uniform_distribution_rvs_cdp" seed = 258147369; k = 5 @@ -416,8 +400,8 @@ subroutine test_uni_rvs_cdp res(i) = uni_rvs(loc, scale) ! 2 dummies end do res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(res%re - ans%re) < dptol) .and. & - all(abs(res%im - ans%im) < dptol), & + call check(all(abs(real(res) - real(ans)) < dptol) .and. & + all(abs(aimag(res) - aimag(ans)) < dptol), & msg="uniform_distribution_rvs_cdp failed", warn=warn) end subroutine test_uni_rvs_cdp @@ -425,36 +409,36 @@ subroutine test_uni_rvs_cqp complex(qp) :: res(15), scale, loc integer :: i, n, seed, get, k - complex(qp) :: ans(15) = [(0.457413314269374593479255963757168502_qp, & - 0.183665049332483204524990583195176441_qp), & - (0.887956215288546402142344504682114348_qp, & - 0.442960654493795069619466175936395302_qp), & - (0.475367828271493930714086673106066883_qp, & - 0.170218713071472432796227280960010830_qp), & - (0.441669140746526411867023398372111842_qp, & - 0.918695946946929575815943280758801848_qp), & - (0.148022801700699729865462472844228614_qp, & - 0.691296364925570783199759716808330268_qp), & - (-6.623624698909258423640267210430465639E-0002_qp, & - 0.560638316852891907537959070850774879_qp), & - (-0.450830023070757909819938902273861459_qp, & - 0.917954692926131299302028310194145888_qp), & - (-0.166943359095192145336028488600277342_qp, & - 1.05997401970850635422038976685144007_qp), & - (-0.429652190199228276035192664039641386_qp, & - 0.523558274341032421628217008446881664_qp), & - (0.427181091476823815433760955784237012_qp, & - 1.34628934976074521312483511792379431_qp), & - (-0.343281426018765739582860874179459643_qp, & - 1.15357331316264255516301773241139017_qp), & - (-0.127590074749816595467422075671493076_qp, & - 1.06891199479835175001340985545539297_qp), & - (0.262287586904722758163188700564205647_qp, & - 1.29508919831907332032017166056903079_qp), & - (-0.192677407376582732201342196276527829_qp, & - 1.32794925614337933073016984053538181_qp), & - (-0.264742129752461530234342035328154452_qp, & - 1.01282963412172621886497836385387927_qp)] + complex(qp) :: ans(15) = [(0.457413315773010253906250000000000000_qp, & + 0.183665052056312561035156250000000000_qp), & + (0.887956202030181884765625000000000000_qp, & + 0.442960649728775024414062500000000000_qp), & + (0.475367814302444458007812500000000000_qp, & + 0.170218706130981445312500000000000000_qp), & + (0.441669136285781860351562500000000000_qp, & + 0.918695926666259765625000000000000000_qp), & + (0.148022800683975219726562500000000000_qp, & + 0.691296339035034179687500000000000000_qp), & + (-6.623625010251998901367187500000000000E-0002_qp, & + 0.560638308525085449218750000000000000_qp), & + (-0.450830012559890747070312500000000000_qp, & + 0.917954683303833007812500000000000000_qp), & + (-0.166943356394767761230468750000000000_qp, & + 1.05997407436370849609375000000000000_qp), & + (-0.429652184247970581054687500000000000_qp, & + 0.523558259010314941406250000000000000_qp), & + (0.427181094884872436523437500000000000_qp, & + 1.34628939628601074218750000000000000_qp), & + (-0.343281418085098266601562500000000000_qp, & + 1.15357327461242675781250000000000000_qp), & + (-0.127590075135231018066406250000000000_qp, & + 1.06891202926635742187500000000000000_qp), & + (0.262287586927413940429687500000000000_qp, & + 1.29508924484252929687500000000000000_qp), & + (-0.192677408456802368164062500000000000_qp, & + 1.32794928550720214843750000000000000_qp), & + (-0.264742136001586914062500000000000000_qp, & + 1.01282966136932373046875000000000000_qp)] print *, "Test uniform_distribution_rvs_cqp" seed = 258147369; k = 5 @@ -467,8 +451,8 @@ subroutine test_uni_rvs_cqp res(i) = uni_rvs(loc, scale) ! 2 dummies end do res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(res%re - ans%re) < qptol) .and. & - all(abs(res%im - ans%im) < qptol), & + call check(all(abs(real(res) - real(ans)) < qptol) .and. & + all(abs(aimag(res) - aimag(ans)) < qptol), & msg="uniform_distribution_rvs_cqp failed", warn=warn) end subroutine test_uni_rvs_cqp From 49f9d8967f77f82fb1e9e25e0879e1d1fb47cf75 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 20 Dec 2020 18:29:50 -0500 Subject: [PATCH 012/172] minor change --- src/stdlib_stats_distribution_uniform.fypp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index 005adbf84..d092129ce 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -90,8 +90,8 @@ Module stdlib_stats_distribution_uniform integer :: zeros, bits_left, bits n = scale - if(n == 0_${k1}$) call error_stop("Error: Uniform distribution scale" & - //" parameter must be non-zero") + if(n <= 0_${k1}$) call error_stop("Error: Uniform distribution scale" & + //" parameter must be positive") zeros = leadz(n) bits = bit_size(n) - zeros mask = shiftr(not(0_${k1}$), zeros) From d900cfd7298e72a2a6a8a75b72183d096372afd6 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 20 Dec 2020 20:17:44 -0500 Subject: [PATCH 013/172] some corrections --- .../stdlib_stats_distribution_uniform.md | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index bd34e7a7f..3c35b8673 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -22,7 +22,7 @@ Applying Fisher-Yates algorithm to generate an unbiased permutation for any list ### Arguments -`list`: argument has intent `in` and is a rank one array of integer, real, or complx type. +`list`: argument has `intent(in)` and is a rank one array of integer, real, or complx type. ### Return value @@ -81,11 +81,11 @@ With triple auguments `loc`, `scale` and `array_size` the function returns a ran ### Arguments -`loc`: optional argument has intent `in` and is a scalar of type `integer`, `real` or `complx`. +`loc`: optional argument has `intent(in)` and is a scalar of type `integer`, `real` or `complx`. -`scale`: optional argument has intent `in` and is a scalar of type `integer`, `real` or `complx`. +`scale`: optional argument has `intent(in)` and is a scalar of type `integer`, `real` or `complx`. -`array_size`: optional argument has intent `in` and is a scalar of type `integer`. +`array_size`: optional argument has `intent(in)` and is a scalar of type `integer`. `loc` and `scale` must have the same type when both are present. @@ -118,15 +118,15 @@ program demo_uniform_rvs ! 0.486900032 print *, uni(-1.0,2.0,10) !an array of 10 uniform random variates in [-1., 1.] -![0.884182811, -0.771520197, 0.560377002, 0.709313750, -7.12267756E-02, !-0.431066573, 0.497536063, -0.396331906, -0.325983286, 0.137686729] +![0.884182811, -0.771520197, 0.560377002, 0.709313750, -7.12267756E-02, -0.431066573, 0.497536063, -0.396331906, -0.325983286, 0.137686729] print *, uni(20) !a random integer variate in [0, 20] ! 17 - print *, uni(5,13) !a random integer variate in [5, 13] + print *, uni(5,13) !a random integer variate in [5, 18] ! 15 - print *, uni(3,19,10) !an array of 10 integer variates in [3,19] + print *, uni(3,19,10) !an array of 10 integer variates in [3,22] ! [7, 16, 16, 12, 9, 21, 19, 4, 3, 19] loc = (-0.5, -0.5) @@ -190,11 +190,11 @@ f(x) = 1 / (scale%re * scale%im); for complx uniform distribution ### Arguments -`x`: has intent `in` and is a scalar of type `integer`, `real` or `complx`. +`x`: has `intent(in)` and is a scalar of type `integer`, `real` or `complx`. -`loc`: has intent `in` and is a scalar of type `integer`, `real` or `complx`. +`loc`: has `intent(in)` and is a scalar of type `integer`, `real` or `complx`. -`scale`: has intent `in` and is a scalar of type `integer`, `real` or `complx`. +`scale`: has `intent(in)` and is a scalar of type `integer`, `real` or `complx`. The function is elemental, i.e., all three auguments could be arrays conformable to each other. All three arguments must have the same type. @@ -278,11 +278,11 @@ F(x) = (x%re - loc%re)(x%im - loc%im) / (scale%re * scale%im); for complx unifor ### Arguments -`x`: has intent `in` and is a scalar of type `integer`, `real` or `complx`. +`x`: has `intent(in)` and is a scalar of type `integer`, `real` or `complx`. -`loc`: has intent `in` and is a scalar of type `integer`, `real` or `complx`. +`loc`: has `intent(in)` and is a scalar of type `integer`, `real` or `complx`. -`scale`: has intent `in` and is a scalar of type `integer`, `real` or `complx`. +`scale`: has `intent(in)` and is a scalar of type `integer`, `real` or `complx`. The function is elemental, i.e., all three auguments could be arrays conformable to each other. All three arguments must have the same type. @@ -294,9 +294,9 @@ The result is a scalar or an array, with a shape conformable to auguments, of ty ```fortran program demo_uniform_cdf - use stdlib_stats_distribution, only : uni_cdf => uniform_distribution_cdf, & - uni => uniform_distribution_rvs, & - random_seed + use stdlib_stats_distribution_uniform, only : uni_cdf => uniform_distribution_cdf, & + uni => uniform_distribution_rvs, & + use stdlib_stats_distribution_PRNG, only : random_seed implicit none real :: x(3,4,5), a(3,4,5), b(3,4,5) complx :: loc, scale From 2a650edd69aa70ad3d35ac2bc6f56dac1dff3988 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 20 Dec 2020 20:21:16 -0500 Subject: [PATCH 014/172] minor corrections --- doc/specs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/specs/index.md b/doc/specs/index.md index ad99ebf78..8916dffef 100644 --- a/doc/specs/index.md +++ b/doc/specs/index.md @@ -18,7 +18,7 @@ This is and index/directory of the specifications (specs) for each new module/fe - [quadrature](./stdlib_quadrature.html) - Numerical integration - [stats](./stdlib_stats.html) - Descriptive Statistics - [stats_distribution_PRNG](./stdlib_stats_distribution_PRNG.html) - Probability Distributions random number generator - + - [stats_distribution_uniform](./stdlib_stats_distribution_uniform.html) - Uniform probability distribution ## Missing specs - [ascii](https://github.com/fortran-lang/stdlib/blob/master/src/stdlib_ascii.f90) From d4f701c43768937487ce0337c25c2d65cba4aea1 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 20 Dec 2020 21:14:22 -0500 Subject: [PATCH 015/172] wrong place --- src/test_distribution_uniform.fypp | 282 ----------------------------- 1 file changed, 282 deletions(-) delete mode 100644 src/test_distribution_uniform.fypp diff --git a/src/test_distribution_uniform.fypp b/src/test_distribution_uniform.fypp deleted file mode 100644 index 9be961062..000000000 --- a/src/test_distribution_uniform.fypp +++ /dev/null @@ -1,282 +0,0 @@ -#:include "common.fypp" -#:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES -#:set ALL_KINDS_TYPES = INT_KINDS_TYPES + RC_KINDS_TYPES -program test_distribution_uniform - use stdlib_error, only : check - use stdlib_kinds - use stdlib_stats_distribution_PRNG, only : random_seed, dist_rand - use stdlib_stats_distribution_uniform, & - uni_rvs => uniform_distribution_rvs, & - uni_pdf => uniform_distribution_pdf, & - uni_cdf => uniform_distribution_cdf - - implicit none - logical :: warn = .true. - #:for k1, t1 in REAL_KINDS_TYPES - ${t1}$, parameter :: ${k1}$tol = 1000 * epsilon(1.0_${k1}$) - #:endfor - integer :: put, get - - put = 135792468 - - call test_shuffle - - call test_uni_rvs_0 - - #:for k1, t1 in ALL_KINDS_TYPES - call test_uni_rvs_${t1[0]}$${k1}$ - #:endfor - - #:for k1, t1 in ALL_KINDS_TYPES - call test_uni_pdf_${t1[0]}$${k1}$ - #:endfor - - #:for k1, t1 in ALL_KINDS_TYPES - call test_uni_cdf_${t1[0]}$${k1}$ - #:endfor - stop - - contains - - subroutine test_shuffle - integer :: n(10), na(10) = [10, 6, 9, 2, 8, 1, 3, 5, 7, 4] - real :: x(10), xa(10)= [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, & - 7.0, 6.0] - complex :: z(10), za(10)=[(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), & - (1.0, 1.0), (5.0, 5.0), (9.0, 9.0), & - (6.0, 6.0), (3.0, 3.0), (2.0, 2.0), & - (10.0, 10.0)] - integer :: i, put, get - - do i=1, 10 - n(i) = i - x(i) = real(i) - z(i) = cmplx(real(i),real(i)) - end do - put = 32165498 - call random_seed(put, get) - n(:) = shuffle(n) - x(:) = shuffle(x) - z(:) = shuffle(z) - call check(all(n == na), & - msg="Integer shuffle failed test", warn=warn) - call check(all(x == xa), & - msg="Real shuffle failed test", warn=warn) - call check(all(z == za), & - msg="Complex shuffle failed test", warn=warn) - end subroutine test_shuffle - - subroutine test_uni_rvs_0 - integer :: i, j, freq(0:1000), num=10000000 - real(dp) :: chisq, expct - - print *,"" - print *, "Test uniform random generator with chi-squared" - freq = 0 - do i = 1, num - j = 1000 * uni_rvs( ) - freq(j) = freq(j) + 1 - end do - chisq = 0.0_dp - expct = num / 1000 - do i = 0, 999 - chisq = chisq + (freq(i) - expct) ** 2 / expct - end do - write(*,*) "The critical values for chi-squared with 1000 d. of f. are" & - //" 1143.92" - write(*,*) "Chi-squared for uniform random generator is : ", chisq - call check((chisq < 1143.9) , & - msg="uniform randomness failed chi-squared test", warn=warn) - end subroutine test_uni_rvs_0 - - #:for k1, t1 in ALL_KINDS_TYPES - subroutine test_uni_rvs_${t1[0]}$${k1}$ - ${t1}$ :: res(15), scale, loc - integer :: i, n, seed, get, k - - #:if k1 == "int8" - ${t1}$ :: ans(15) = [47, 99, 43, 37, 48, 30, 27, 100, 30, 33, 21, & - 103, 55, 54, 110] - #:elif k1 == "int16" - ${t1}$ :: ans(15) = [25, 4, 81, 98, 49, 34, 32, 62, 115, 112, 26, & - 20, 37, 100, 82] - #:elif k1 == "int32" - ${t1}$ :: ans(15) = [19, 52, 56, 20, 59, 44, 34, 102, 19, 39, 60, & - 50, 97, 56, 67] - #:elif k1 == "int64" - ${t1}$ :: ans(15) = [76, 45, 43, 75, 76, 15, 25, 24, 114, 113, 94, & - 29, 109, 93, 89] - #:elif t1[0] == "r" - ${t1}$ :: ans(15) = & - [0.914826628538749186958511927514337003_${k1}$, & - 0.367330098664966409049981166390352882_${k1}$, & - 1.77591243057709280428468900936422870_${k1}$, & - 0.885921308987590139238932351872790605_${k1}$, & - 0.950735656542987861428173346212133765_${k1}$, & - -0.659562573857055134407545438079978339_${k1}$, & - -0.116661718506947176265953203255776316_${k1}$, & - 0.837391893893859151631886561517603695_${k1}$, & - -0.703954396598600540269075054311542772_${k1}$, & - 0.382592729851141566399519433616660535_${k1}$, & - -0.132472493978185168472805344208609313_${k1}$, & - -0.878723366294216184924081858298450243_${k1}$, & - -0.901660046141515819639877804547722917_${k1}$, & - -0.164090614147737401395943379611708224_${k1}$, & - -0.333886718190384290672056977200554684_${k1}$] - #:else - ${t1}$ :: ans(15) = [(0.457413315773010253906250000000000000_${k1}$, & - 0.183665052056312561035156250000000000_${k1}$), & - (0.887956202030181884765625000000000000_${k1}$, & - 0.442960649728775024414062500000000000_${k1}$), & - (0.475367814302444458007812500000000000_${k1}$, & - 0.170218706130981445312500000000000000_${k1}$), & - (0.441669136285781860351562500000000000_${k1}$, & - 0.918695926666259765625000000000000000_${k1}$), & - (0.148022800683975219726562500000000000_${k1}$, & - 0.691296339035034179687500000000000000_${k1}$), & - (-6.623625010251998901367187500000000000E-0002_${k1}$, & - 0.560638308525085449218750000000000000_${k1}$), & - (-0.450830012559890747070312500000000000_${k1}$, & - 0.917954683303833007812500000000000000_${k1}$), & - (-0.166943356394767761230468750000000000_${k1}$, & - 1.05997407436370849609375000000000000_${k1}$), & - (-0.429652184247970581054687500000000000_${k1}$, & - 0.523558259010314941406250000000000000_${k1}$), & - (0.427181094884872436523437500000000000_${k1}$, & - 1.34628939628601074218750000000000000_${k1}$), & - (-0.343281418085098266601562500000000000_${k1}$, & - 1.15357327461242675781250000000000000_${k1}$), & - (-0.127590075135231018066406250000000000_${k1}$, & - 1.06891202926635742187500000000000000_${k1}$), & - (0.262287586927413940429687500000000000_${k1}$, & - 1.29508924484252929687500000000000000_${k1}$), & - (-0.192677408456802368164062500000000000_${k1}$, & - 1.32794928550720214843750000000000000_${k1}$), & - (-0.264742136001586914062500000000000000_${k1}$, & - 1.01282966136932373046875000000000000_${k1}$)] - #:endif - - print *, "Test uniform_distribution_rvs_${t1[0]}$${k1}$" - seed = 258147369; k = 5 - call random_seed(seed, get) - #:if t1[0] == "i" - loc = 15_${k1}$; scale = 100_${k1}$ - #:elif t1[0] == "r" - loc = -1.0_${k1}$; scale = 2.0_${k1}$ - #:else - loc = (-0.5_${k1}$,0.5_${k1}$); scale = (1.0_${k1}$, 1.0_${k1}$) - #:endif - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - #:if t1[0] == "i" - call check(all(res == ans), & - msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) - #:elif t1[0] == "r" - call check(all(abs(res - ans) < ${k1}$tol), & - msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) - #:else - call check(all(abs(real(res) - real(ans)) < ${k1}$tol) .and. & - all(abs(aimag(res) - aimag(ans)) < ${k1}$tol), & - msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) - #:endif - end subroutine test_uni_rvs_${t1[0]}$${k1}$ - - #:endfor - - #:for k1, t1 in ALL_KINDS_TYPES - subroutine test_uni_pdf_${t1[0]}$${k1}$ - ${t1}$ :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - #:if t1[0] == "i" - real :: ans(15) = [(1.96078438E-02, i=1,15)] - #:elif t1[0] == "r" - real :: ans(15) = [(0.5, i=1,15)] - #:else - real :: ans(15) = [(1.0, i=1,15)] - #:endif - - print *, "Test uniform_distribution_pdf_${t1[0]}$${k1}$" - seed = 147258639 - call random_seed(seed, get) - #:if t1[0] == "i" - loc = 0_${k1}$; scale = 50_${k1}$ - #:elif t1[0] == "r" - loc = 0.0_${k1}$; scale = 2.0_${k1}$ - #:else - loc = (-0.5_${k1}$, 0.5_${k1}$); scale = (1.0_${k1}$, 1.0_${k1}$) - #:endif - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_${t1[0]}$${k1}$ failed", warn=warn) - end subroutine test_uni_pdf_${t1[0]}$${k1}$ - - #:endfor - - #:for k1, t1 in ALL_KINDS_TYPES - subroutine test_uni_cdf_${t1[0]}$${k1}$ - ${t1}$ :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - #:if k1 == "int8" - real :: ans(15) = [0.435643554, 0.435643554, 0.435643554, 0.702970326, & - 0.653465331, 0.485148519, 0.386138618, 0.386138618, & - 0.336633652, 0.277227730, 0.237623766, 0.524752498, & - 0.732673287, 0.534653485, 0.415841579] - #:elif k1 == "int16" - real :: ans(15) = [0.178217828, 0.178217828, 0.178217828, 0.465346545, & - 0.673267305, 0.247524753, 0.158415839, 0.792079210, & - 0.742574275, 0.574257433, 0.881188095, 0.663366318, & - 0.524752498, 0.623762369, 0.178217828] - #:elif k1 == "int32" - real :: ans(15) = [0.732673287, 0.732673287, 0.732673287, 0.722772300, & - 0.792079210, 5.94059415E-02, 0.841584146,0.405940592,& - 0.960396051, 0.534653485, 0.782178223, 0.861386120, & - 0.564356446, 0.613861382, 0.306930691] - #:elif k1 == "int64" - real :: ans(15) = [0.455445558, 0.455445558, 0.455445558, 0.277227730, & - 0.455445558, 0.930693090, 0.851485133, 0.623762369, & - 5.94059415E-02,0.693069279, 0.544554472, 0.207920790,& - 0.306930691, 0.356435657, 0.128712878] - #:elif t1[0] == "r" - real :: ans(15) = [0.170192942, 0.170192942, 0.170192942, 0.276106149, & - 0.754930079, 0.406620681, 0.187742814, 0.651605546, & - 0.934733927, 0.151271492, 0.987674534, 0.130533904, & - 0.106271908, 9.27578658E-02, 0.203399420] - #:else - real :: ans(15) = [4.69913185E-02, 4.69913185E-02, 4.69913185E-02, & - 0.306970179, 0.122334257, 0.141398594, 0.128925011, & - 9.85755492E-03, 8.16527531E-02, 0.163921610, & - 7.81712309E-02, 0.446415812, 5.31753292E-04, & - 0.101455867, 0.155276477] - #:endif - - print *, "Test uniform_distribution_cdf_${t1[0]}$${k1}$" - seed = 369147258 - call random_seed(seed, get) - #:if t1[0] == "i" - loc = 14_${k1}$; scale = 100_${k1}$ - #:elif t1[0] == "r" - loc = 0.0_${k1}$; scale = 2.0_${k1}$ - #:else - loc = (-0.5_${k1}$, -0.5_${k1}$); scale = (1.0_${k1}$, 1.0_${k1}$) - #:endif - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_${t1[0]}$${k1}$ failed", warn=warn) - end subroutine test_uni_cdf_${t1[0]}$${k1}$ - - #:endfor - -end program test_distribution_uniform \ No newline at end of file From 2a495abc6144d8d8cec86d82c838578dbcf10f83 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Mon, 21 Dec 2020 19:10:52 -0500 Subject: [PATCH 016/172] Add files via upload --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6143b5ab5..d62689913 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,9 @@ if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU) endif() elseif(CMAKE_Fortran_COMPILER_ID STREQUAL Intel) add_compile_options(-warn declarations,general,usage,interfaces,unused) - add_compile_options(-standard-semantics) + if(NOT CMAKE_Fortran_COMPILER_VERSION VERSION_EQUAL 20.2.1.20200827) + add_compile_options(-standard-semantics) + endif() if(CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 18.0) add_compile_options(-stand f15) else() @@ -35,7 +37,7 @@ endif() # --- compiler feature checks include(CheckFortranSourceCompiles) include(CheckFortranSourceRuns) -check_fortran_source_compiles("error stop i; end" f18errorstop SRC_EXT f90) +check_fortran_source_runs("i=0; error stop i; end" f18errorstop SRC_EXT f90) check_fortran_source_compiles("real, allocatable :: array(:, :, :, :, :, :, :, :, :, :); end" f03rank SRC_EXT f90) check_fortran_source_runs("use, intrinsic :: iso_fortran_env, only : real128; real(real128) :: x; x = x+1; end" f03real128) From 8e95e05633fbb8fc4da16f602250c764851c9cde Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Mon, 21 Dec 2020 19:11:19 -0500 Subject: [PATCH 017/172] Add files via upload From 3d8e3e69ef4bce57b210e853362722c5058c12ce Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Mon, 21 Dec 2020 19:25:20 -0500 Subject: [PATCH 018/172] Add files via upload --- src/CMakeLists.txt | 3 +++ src/Makefile.manual | 26 +++++++++++--------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ea7403663..02604959e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,9 @@ # Create a list of the files to be preprocessed set(fppFiles + stdlib_bitsets.fypp + stdlib_bitsets_64.fypp + stdlib_bitsets_large.fypp stdlib_io.fypp stdlib_linalg.fypp stdlib_linalg_diag.fypp diff --git a/src/Makefile.manual b/src/Makefile.manual index 129dbe553..872f704c0 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -1,5 +1,8 @@ SRC = f18estop.f90 \ stdlib_ascii.f90 \ + stdlib_bitsets.f90 \ + stdlib_bitsets_64.f90 \ + stdlib_bitsets_large.f90 \ stdlib_error.f90 \ stdlib_io.f90 \ stdlib_kinds.f90 \ @@ -12,10 +15,7 @@ SRC = f18estop.f90 \ stdlib_stats.f90 \ stdlib_stats_mean.f90 \ stdlib_stats_moment.f90 \ - stdlib_stats_var.f90 \ - stdlib_stats_distribution.f90 \ - stdlib_stats_distribution_rvs.f90 \ - stdlib_stats_distribution_implementation.f90 \ + stdlib_stats_var.f90 LIB = libstdlib.a @@ -43,6 +43,9 @@ clean: # Fortran module dependencies f18estop.o: stdlib_error.o +stdlib_bitsets.o: stdlib_kinds.o +stdlib_bitsets_64.o: stdlib_bitsets.o +stdlib_bitsets_large.o: stdlib_bitsets.o stdlib_error.o: stdlib_optval.o stdlib_io.o: \ stdlib_error.o \ @@ -64,14 +67,11 @@ stdlib_stats_var.o: \ stdlib_optval.o \ stdlib_kinds.o \ stdlib_stats.o -stdlib_stats_distribution_rvs.o: stdlib_kinds.o -stdlib_stats_distribution.o: \ - stdlib_error.o \ - stdlib_kinds.o \ - stdlib_stats_distribution_rvs.o \ -stdlib_stats_distribution_imp.o: \ - stdlib_stats_distribution.o + # Fortran sources that are built from fypp templates +stdlib_bitsets_64.f90: stdlib_bitsets_64.fypp +stdlib_bitsets_large.f90: stdlib_bitsets_large.fypp +stdlib_bitsets.f90: stdlib_bitsets.fypp stdlib_io.f90: stdlib_io.fypp stdlib_linalg.f90: stdlib_linalg.fypp stdlib_linalg_diag.f90: stdlib_linalg_diag.fypp @@ -80,7 +80,3 @@ stdlib_stats.f90: stdlib_stats.fypp stdlib_stats_mean.f90: stdlib_stats_mean.fypp stdlib_stats_moment.f90: stdlib_stats_moment.fypp stdlib_stats_var.f90: stdlib_stats_var.fypp -stdlib_stats_distribution_rvs.f90: stdlib_stats_distribution_rvs.fypp -stdlib_stats_distribution.f90: stdlib_stats_distribution.fypp -stdlib_stats_distribution_implementation.f90: \ - stdlib_stats_distribution_implementation.fypp \ No newline at end of file From 0629dbf37b413e9c1bdfc4eb1e126988c1f135fa Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Mon, 21 Dec 2020 20:20:23 -0500 Subject: [PATCH 019/172] Update stdlib_stats_distribution_uniform.fypp --- src/stdlib_stats_distribution_uniform.fypp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index d092129ce..d51680f0f 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -185,7 +185,6 @@ Module stdlib_stats_distribution_uniform ! ${t1}$, intent(in) :: scale ${t1}$ :: res - integer(int64) :: tmp real(${k1}$) :: r1, r2, tr, ti if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error: Uniform" & @@ -218,7 +217,6 @@ Module stdlib_stats_distribution_uniform ! ${t1}$, intent(in) :: loc, scale ${t1}$ :: res - integer(int64) :: tmp real(${k1}$) :: r1, r2, tr, ti if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error: Uniform" & @@ -481,4 +479,4 @@ Module stdlib_stats_distribution_uniform end function shuffle_${t1[0]}$${k1}$ #:endfor -end module stdlib_stats_distribution_uniform \ No newline at end of file +end module stdlib_stats_distribution_uniform From b076c2d5fc8c94eeee9a5bc437edf79413042d0d Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Tue, 22 Dec 2020 10:02:16 -0500 Subject: [PATCH 020/172] Update stdlib_stats_distribution_uniform.md --- doc/specs/stdlib_stats_distribution_uniform.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index 3c35b8673..97f7c1137 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -2,7 +2,7 @@ title: stats_distribution --- -# Statistical Distributions Uniform Module +# Statistical Distributions -- Uniform Distribution Module [TOC] From b58681c58ffcaaf8699cc01a0d5ad743a18cd5ff Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 27 Dec 2020 10:54:50 -0500 Subject: [PATCH 021/172] chg. complex numbers with kinds --- src/stdlib_stats_distribution_uniform.fypp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index d51680f0f..572caaf37 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -134,7 +134,7 @@ Module stdlib_stats_distribution_uniform ! Uniformly distributed float in [0,1] ! Based on the paper by Frederic Goualard, "Generating Random Floating- ! Point Numbers By Dividing Integers: a Case Study", Proceedings of - ! ICCS 2020, June 20202, Amsterdam, Netherlands + ! ICCS 2020, June 2020, Amsterdam, Netherlands ! ${t1}$ :: res integer(int64) :: tmp @@ -201,7 +201,7 @@ Module stdlib_stats_distribution_uniform tr = real(scale) * r1 ti = aimag(scale) * r2 endif - res = cmplx(tr, ti) + res = cmplx(tr, ti, kind=${k1}$) return end function unif_dist_rvs_1_${t1[0]}$${k1}$ @@ -233,7 +233,7 @@ Module stdlib_stats_distribution_uniform tr = real(loc) + real(scale) * r1 ti = aimag(loc) + aimag(scale) * r2 endif - res = cmplx(tr, ti) + res = cmplx(tr, ti, kind=${k1}$) return end function unif_dist_rvs_${t1[0]}$${k1}$ @@ -329,7 +329,7 @@ Module stdlib_stats_distribution_uniform tr = real(loc) + real(scale) * r1 ti = aimag(loc) + aimag(scale) * r2 endif - res(i) = cmplx(tr, ti) + res(i) = cmplx(tr, ti, kind=${k1}$) enddo return end function unif_dist_rvs_array_${t1[0]}$${k1}$ @@ -343,10 +343,10 @@ Module stdlib_stats_distribution_uniform if(scale == 0) then res = 0.0 - elseif(x < loc .or. x >loc + scale) then + elseif(x < loc .or. x > (loc + scale)) then res = 0.0 else - res = 1. / (scale + 1) + res = 1. / (scale + 1_${k1}$) end if return end function unif_dist_pdf_${t1[0]}$${k1}$ @@ -400,7 +400,7 @@ Module stdlib_stats_distribution_uniform elseif(x < loc) then res = 0.0 elseif(x >= loc .and. x <= (loc + scale)) then - res = real((x - loc + 1)) / real((scale + 1)) + res = real((x - loc + 1_${k1}$)) / real((scale + 1_${k1}$)) else res = 1.0 end if @@ -479,4 +479,4 @@ Module stdlib_stats_distribution_uniform end function shuffle_${t1[0]}$${k1}$ #:endfor -end module stdlib_stats_distribution_uniform +end module stdlib_stats_distribution_uniform \ No newline at end of file From c2f11087daf0c3dc863a3bc0e3bd55a0b3cc656e Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 27 Dec 2020 10:55:50 -0500 Subject: [PATCH 022/172] chn. complex number to kinds causes change in complex random number --- src/tests/stats/test_distribution_uniform.f90 | 180 +++++++++--------- 1 file changed, 90 insertions(+), 90 deletions(-) diff --git a/src/tests/stats/test_distribution_uniform.f90 b/src/tests/stats/test_distribution_uniform.f90 index f299f96d3..4ed0c88b9 100644 --- a/src/tests/stats/test_distribution_uniform.f90 +++ b/src/tests/stats/test_distribution_uniform.f90 @@ -307,36 +307,36 @@ subroutine test_uni_rvs_csp complex(sp) :: res(15), scale, loc integer :: i, n, seed, get, k - complex(sp) :: ans(15) = [(0.457413315773010253906250000000000000_sp, & - 0.183665052056312561035156250000000000_sp), & - (0.887956202030181884765625000000000000_sp, & - 0.442960649728775024414062500000000000_sp), & - (0.475367814302444458007812500000000000_sp, & - 0.170218706130981445312500000000000000_sp), & - (0.441669136285781860351562500000000000_sp, & - 0.918695926666259765625000000000000000_sp), & - (0.148022800683975219726562500000000000_sp, & - 0.691296339035034179687500000000000000_sp), & - (-6.623625010251998901367187500000000000E-0002_sp, & - 0.560638308525085449218750000000000000_sp), & - (-0.450830012559890747070312500000000000_sp, & - 0.917954683303833007812500000000000000_sp), & - (-0.166943356394767761230468750000000000_sp, & - 1.05997407436370849609375000000000000_sp), & - (-0.429652184247970581054687500000000000_sp, & - 0.523558259010314941406250000000000000_sp), & - (0.427181094884872436523437500000000000_sp, & - 1.34628939628601074218750000000000000_sp), & - (-0.343281418085098266601562500000000000_sp, & - 1.15357327461242675781250000000000000_sp), & - (-0.127590075135231018066406250000000000_sp, & - 1.06891202926635742187500000000000000_sp), & - (0.262287586927413940429687500000000000_sp, & - 1.29508924484252929687500000000000000_sp), & - (-0.192677408456802368164062500000000000_sp, & - 1.32794928550720214843750000000000000_sp), & - (-0.264742136001586914062500000000000000_sp, & - 1.01282966136932373046875000000000000_sp)] + complex(sp) :: ans(15) = [(0.457413314269374593479255963757168502_sp, & + 0.183665049332483204524990583195176441_sp), & + (0.887956215288546402142344504682114348_sp, & + 0.442960654493795069619466175936395302_sp), & + (0.475367828271493930714086673106066883_sp, & + 0.170218713071472432796227280960010830_sp), & + (0.441669140746526411867023398372111842_sp, & + 0.918695946946929575815943280758801848_sp), & + (0.148022801700699729865462472844228614_sp, & + 0.691296364925570783199759716808330268_sp), & + (-6.623624698909258423640267210430465639E-0002_sp, & + 0.560638316852891907537959070850774879_sp), & + (-0.450830023070757909819938902273861459_sp, & + 0.917954692926131299302028310194145888_sp), & + (-0.166943359095192145336028488600277342_sp, & + 1.05997401970850635422038976685144007_sp), & + (-0.429652190199228276035192664039641386_sp, & + 0.523558274341032421628217008446881664_sp), & + (0.427181091476823815433760955784237012_sp, & + 1.34628934976074521312483511792379431_sp), & + (-0.343281426018765739582860874179459643_sp, & + 1.15357331316264255516301773241139017_sp), & + (-0.127590074749816595467422075671493076_sp, & + 1.06891199479835175001340985545539297_sp), & + (0.262287586904722758163188700564205647_sp, & + 1.29508919831907332032017166056903079_sp), & + (-0.192677407376582732201342196276527829_sp, & + 1.32794925614337933073016984053538181_sp), & + (-0.264742129752461530234342035328154452_sp, & + 1.01282963412172621886497836385387927_sp)] print *, "Test uniform_distribution_rvs_csp" seed = 258147369; k = 5 @@ -358,36 +358,36 @@ subroutine test_uni_rvs_cdp complex(dp) :: res(15), scale, loc integer :: i, n, seed, get, k - complex(dp) :: ans(15) = [(0.457413315773010253906250000000000000_dp, & - 0.183665052056312561035156250000000000_dp), & - (0.887956202030181884765625000000000000_dp, & - 0.442960649728775024414062500000000000_dp), & - (0.475367814302444458007812500000000000_dp, & - 0.170218706130981445312500000000000000_dp), & - (0.441669136285781860351562500000000000_dp, & - 0.918695926666259765625000000000000000_dp), & - (0.148022800683975219726562500000000000_dp, & - 0.691296339035034179687500000000000000_dp), & - (-6.623625010251998901367187500000000000E-0002_dp, & - 0.560638308525085449218750000000000000_dp), & - (-0.450830012559890747070312500000000000_dp, & - 0.917954683303833007812500000000000000_dp), & - (-0.166943356394767761230468750000000000_dp, & - 1.05997407436370849609375000000000000_dp), & - (-0.429652184247970581054687500000000000_dp, & - 0.523558259010314941406250000000000000_dp), & - (0.427181094884872436523437500000000000_dp, & - 1.34628939628601074218750000000000000_dp), & - (-0.343281418085098266601562500000000000_dp, & - 1.15357327461242675781250000000000000_dp), & - (-0.127590075135231018066406250000000000_dp, & - 1.06891202926635742187500000000000000_dp), & - (0.262287586927413940429687500000000000_dp, & - 1.29508924484252929687500000000000000_dp), & - (-0.192677408456802368164062500000000000_dp, & - 1.32794928550720214843750000000000000_dp), & - (-0.264742136001586914062500000000000000_dp, & - 1.01282966136932373046875000000000000_dp)] + complex(dp) :: ans(15) = [(0.457413314269374593479255963757168502_dp, & + 0.183665049332483204524990583195176441_dp), & + (0.887956215288546402142344504682114348_dp, & + 0.442960654493795069619466175936395302_dp), & + (0.475367828271493930714086673106066883_dp, & + 0.170218713071472432796227280960010830_dp), & + (0.441669140746526411867023398372111842_dp, & + 0.918695946946929575815943280758801848_dp), & + (0.148022801700699729865462472844228614_dp, & + 0.691296364925570783199759716808330268_dp), & + (-6.623624698909258423640267210430465639E-0002_dp, & + 0.560638316852891907537959070850774879_dp), & + (-0.450830023070757909819938902273861459_dp, & + 0.917954692926131299302028310194145888_dp), & + (-0.166943359095192145336028488600277342_dp, & + 1.05997401970850635422038976685144007_dp), & + (-0.429652190199228276035192664039641386_dp, & + 0.523558274341032421628217008446881664_dp), & + (0.427181091476823815433760955784237012_dp, & + 1.34628934976074521312483511792379431_dp), & + (-0.343281426018765739582860874179459643_dp, & + 1.15357331316264255516301773241139017_dp), & + (-0.127590074749816595467422075671493076_dp, & + 1.06891199479835175001340985545539297_dp), & + (0.262287586904722758163188700564205647_dp, & + 1.29508919831907332032017166056903079_dp), & + (-0.192677407376582732201342196276527829_dp, & + 1.32794925614337933073016984053538181_dp), & + (-0.264742129752461530234342035328154452_dp, & + 1.01282963412172621886497836385387927_dp)] print *, "Test uniform_distribution_rvs_cdp" seed = 258147369; k = 5 @@ -409,36 +409,36 @@ subroutine test_uni_rvs_cqp complex(qp) :: res(15), scale, loc integer :: i, n, seed, get, k - complex(qp) :: ans(15) = [(0.457413315773010253906250000000000000_qp, & - 0.183665052056312561035156250000000000_qp), & - (0.887956202030181884765625000000000000_qp, & - 0.442960649728775024414062500000000000_qp), & - (0.475367814302444458007812500000000000_qp, & - 0.170218706130981445312500000000000000_qp), & - (0.441669136285781860351562500000000000_qp, & - 0.918695926666259765625000000000000000_qp), & - (0.148022800683975219726562500000000000_qp, & - 0.691296339035034179687500000000000000_qp), & - (-6.623625010251998901367187500000000000E-0002_qp, & - 0.560638308525085449218750000000000000_qp), & - (-0.450830012559890747070312500000000000_qp, & - 0.917954683303833007812500000000000000_qp), & - (-0.166943356394767761230468750000000000_qp, & - 1.05997407436370849609375000000000000_qp), & - (-0.429652184247970581054687500000000000_qp, & - 0.523558259010314941406250000000000000_qp), & - (0.427181094884872436523437500000000000_qp, & - 1.34628939628601074218750000000000000_qp), & - (-0.343281418085098266601562500000000000_qp, & - 1.15357327461242675781250000000000000_qp), & - (-0.127590075135231018066406250000000000_qp, & - 1.06891202926635742187500000000000000_qp), & - (0.262287586927413940429687500000000000_qp, & - 1.29508924484252929687500000000000000_qp), & - (-0.192677408456802368164062500000000000_qp, & - 1.32794928550720214843750000000000000_qp), & - (-0.264742136001586914062500000000000000_qp, & - 1.01282966136932373046875000000000000_qp)] + complex(qp) :: ans(15) = [(0.457413314269374593479255963757168502_qp, & + 0.183665049332483204524990583195176441_qp), & + (0.887956215288546402142344504682114348_qp, & + 0.442960654493795069619466175936395302_qp), & + (0.475367828271493930714086673106066883_qp, & + 0.170218713071472432796227280960010830_qp), & + (0.441669140746526411867023398372111842_qp, & + 0.918695946946929575815943280758801848_qp), & + (0.148022801700699729865462472844228614_qp, & + 0.691296364925570783199759716808330268_qp), & + (-6.623624698909258423640267210430465639E-0002_qp, & + 0.560638316852891907537959070850774879_qp), & + (-0.450830023070757909819938902273861459_qp, & + 0.917954692926131299302028310194145888_qp), & + (-0.166943359095192145336028488600277342_qp, & + 1.05997401970850635422038976685144007_qp), & + (-0.429652190199228276035192664039641386_qp, & + 0.523558274341032421628217008446881664_qp), & + (0.427181091476823815433760955784237012_qp, & + 1.34628934976074521312483511792379431_qp), & + (-0.343281426018765739582860874179459643_qp, & + 1.15357331316264255516301773241139017_qp), & + (-0.127590074749816595467422075671493076_qp, & + 1.06891199479835175001340985545539297_qp), & + (0.262287586904722758163188700564205647_qp, & + 1.29508919831907332032017166056903079_qp), & + (-0.192677407376582732201342196276527829_qp, & + 1.32794925614337933073016984053538181_qp), & + (-0.264742129752461530234342035328154452_qp, & + 1.01282963412172621886497836385387927_qp)] print *, "Test uniform_distribution_rvs_cqp" seed = 258147369; k = 5 From be19e11da15ae0218db186ae6b43d28baf80e210 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 27 Dec 2020 11:02:48 -0500 Subject: [PATCH 023/172] remove tab --- src/tests/stats/test_distribution_uniform.f90 | 168 +++++++++--------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/src/tests/stats/test_distribution_uniform.f90 b/src/tests/stats/test_distribution_uniform.f90 index 4ed0c88b9..b77371192 100644 --- a/src/tests/stats/test_distribution_uniform.f90 +++ b/src/tests/stats/test_distribution_uniform.f90 @@ -308,35 +308,35 @@ subroutine test_uni_rvs_csp integer :: i, n, seed, get, k complex(sp) :: ans(15) = [(0.457413314269374593479255963757168502_sp, & - 0.183665049332483204524990583195176441_sp), & - (0.887956215288546402142344504682114348_sp, & - 0.442960654493795069619466175936395302_sp), & - (0.475367828271493930714086673106066883_sp, & - 0.170218713071472432796227280960010830_sp), & - (0.441669140746526411867023398372111842_sp, & - 0.918695946946929575815943280758801848_sp), & - (0.148022801700699729865462472844228614_sp, & - 0.691296364925570783199759716808330268_sp), & + 0.183665049332483204524990583195176441_sp), & + (0.887956215288546402142344504682114348_sp, & + 0.442960654493795069619466175936395302_sp), & + (0.475367828271493930714086673106066883_sp, & + 0.170218713071472432796227280960010830_sp), & + (0.441669140746526411867023398372111842_sp, & + 0.918695946946929575815943280758801848_sp), & + (0.148022801700699729865462472844228614_sp, & + 0.691296364925570783199759716808330268_sp), & (-6.623624698909258423640267210430465639E-0002_sp, & - 0.560638316852891907537959070850774879_sp), & - (-0.450830023070757909819938902273861459_sp, & - 0.917954692926131299302028310194145888_sp), & - (-0.166943359095192145336028488600277342_sp, & - 1.05997401970850635422038976685144007_sp), & - (-0.429652190199228276035192664039641386_sp, & - 0.523558274341032421628217008446881664_sp), & - (0.427181091476823815433760955784237012_sp, & - 1.34628934976074521312483511792379431_sp), & - (-0.343281426018765739582860874179459643_sp, & - 1.15357331316264255516301773241139017_sp), & - (-0.127590074749816595467422075671493076_sp, & - 1.06891199479835175001340985545539297_sp), & - (0.262287586904722758163188700564205647_sp, & - 1.29508919831907332032017166056903079_sp), & - (-0.192677407376582732201342196276527829_sp, & - 1.32794925614337933073016984053538181_sp), & - (-0.264742129752461530234342035328154452_sp, & - 1.01282963412172621886497836385387927_sp)] + 0.560638316852891907537959070850774879_sp), & + (-0.450830023070757909819938902273861459_sp, & + 0.917954692926131299302028310194145888_sp), & + (-0.166943359095192145336028488600277342_sp, & + 1.05997401970850635422038976685144007_sp), & + (-0.429652190199228276035192664039641386_sp, & + 0.523558274341032421628217008446881664_sp), & + (0.427181091476823815433760955784237012_sp, & + 1.34628934976074521312483511792379431_sp), & + (-0.343281426018765739582860874179459643_sp, & + 1.15357331316264255516301773241139017_sp), & + (-0.127590074749816595467422075671493076_sp, & + 1.06891199479835175001340985545539297_sp), & + (0.262287586904722758163188700564205647_sp, & + 1.29508919831907332032017166056903079_sp), & + (-0.192677407376582732201342196276527829_sp, & + 1.32794925614337933073016984053538181_sp), & + (-0.264742129752461530234342035328154452_sp, & + 1.01282963412172621886497836385387927_sp)] print *, "Test uniform_distribution_rvs_csp" seed = 258147369; k = 5 @@ -359,35 +359,35 @@ subroutine test_uni_rvs_cdp integer :: i, n, seed, get, k complex(dp) :: ans(15) = [(0.457413314269374593479255963757168502_dp, & - 0.183665049332483204524990583195176441_dp), & - (0.887956215288546402142344504682114348_dp, & - 0.442960654493795069619466175936395302_dp), & - (0.475367828271493930714086673106066883_dp, & - 0.170218713071472432796227280960010830_dp), & - (0.441669140746526411867023398372111842_dp, & - 0.918695946946929575815943280758801848_dp), & - (0.148022801700699729865462472844228614_dp, & - 0.691296364925570783199759716808330268_dp), & + 0.183665049332483204524990583195176441_dp), & + (0.887956215288546402142344504682114348_dp, & + 0.442960654493795069619466175936395302_dp), & + (0.475367828271493930714086673106066883_dp, & + 0.170218713071472432796227280960010830_dp), & + (0.441669140746526411867023398372111842_dp, & + 0.918695946946929575815943280758801848_dp), & + (0.148022801700699729865462472844228614_dp, & + 0.691296364925570783199759716808330268_dp), & (-6.623624698909258423640267210430465639E-0002_dp, & - 0.560638316852891907537959070850774879_dp), & - (-0.450830023070757909819938902273861459_dp, & - 0.917954692926131299302028310194145888_dp), & - (-0.166943359095192145336028488600277342_dp, & - 1.05997401970850635422038976685144007_dp), & - (-0.429652190199228276035192664039641386_dp, & - 0.523558274341032421628217008446881664_dp), & - (0.427181091476823815433760955784237012_dp, & - 1.34628934976074521312483511792379431_dp), & - (-0.343281426018765739582860874179459643_dp, & - 1.15357331316264255516301773241139017_dp), & - (-0.127590074749816595467422075671493076_dp, & - 1.06891199479835175001340985545539297_dp), & - (0.262287586904722758163188700564205647_dp, & - 1.29508919831907332032017166056903079_dp), & - (-0.192677407376582732201342196276527829_dp, & - 1.32794925614337933073016984053538181_dp), & - (-0.264742129752461530234342035328154452_dp, & - 1.01282963412172621886497836385387927_dp)] + 0.560638316852891907537959070850774879_dp), & + (-0.450830023070757909819938902273861459_dp, & + 0.917954692926131299302028310194145888_dp), & + (-0.166943359095192145336028488600277342_dp, & + 1.05997401970850635422038976685144007_dp), & + (-0.429652190199228276035192664039641386_dp, & + 0.523558274341032421628217008446881664_dp), & + (0.427181091476823815433760955784237012_dp, & + 1.34628934976074521312483511792379431_dp), & + (-0.343281426018765739582860874179459643_dp, & + 1.15357331316264255516301773241139017_dp), & + (-0.127590074749816595467422075671493076_dp, & + 1.06891199479835175001340985545539297_dp), & + (0.262287586904722758163188700564205647_dp, & + 1.29508919831907332032017166056903079_dp), & + (-0.192677407376582732201342196276527829_dp, & + 1.32794925614337933073016984053538181_dp), & + (-0.264742129752461530234342035328154452_dp, & + 1.01282963412172621886497836385387927_dp)] print *, "Test uniform_distribution_rvs_cdp" seed = 258147369; k = 5 @@ -410,35 +410,35 @@ subroutine test_uni_rvs_cqp integer :: i, n, seed, get, k complex(qp) :: ans(15) = [(0.457413314269374593479255963757168502_qp, & - 0.183665049332483204524990583195176441_qp), & - (0.887956215288546402142344504682114348_qp, & - 0.442960654493795069619466175936395302_qp), & - (0.475367828271493930714086673106066883_qp, & - 0.170218713071472432796227280960010830_qp), & - (0.441669140746526411867023398372111842_qp, & - 0.918695946946929575815943280758801848_qp), & - (0.148022801700699729865462472844228614_qp, & - 0.691296364925570783199759716808330268_qp), & + 0.183665049332483204524990583195176441_qp), & + (0.887956215288546402142344504682114348_qp, & + 0.442960654493795069619466175936395302_qp), & + (0.475367828271493930714086673106066883_qp, & + 0.170218713071472432796227280960010830_qp), & + (0.441669140746526411867023398372111842_qp, & + 0.918695946946929575815943280758801848_qp), & + (0.148022801700699729865462472844228614_qp, & + 0.691296364925570783199759716808330268_qp), & (-6.623624698909258423640267210430465639E-0002_qp, & - 0.560638316852891907537959070850774879_qp), & - (-0.450830023070757909819938902273861459_qp, & - 0.917954692926131299302028310194145888_qp), & - (-0.166943359095192145336028488600277342_qp, & - 1.05997401970850635422038976685144007_qp), & - (-0.429652190199228276035192664039641386_qp, & - 0.523558274341032421628217008446881664_qp), & - (0.427181091476823815433760955784237012_qp, & - 1.34628934976074521312483511792379431_qp), & - (-0.343281426018765739582860874179459643_qp, & - 1.15357331316264255516301773241139017_qp), & - (-0.127590074749816595467422075671493076_qp, & - 1.06891199479835175001340985545539297_qp), & - (0.262287586904722758163188700564205647_qp, & - 1.29508919831907332032017166056903079_qp), & - (-0.192677407376582732201342196276527829_qp, & - 1.32794925614337933073016984053538181_qp), & - (-0.264742129752461530234342035328154452_qp, & - 1.01282963412172621886497836385387927_qp)] + 0.560638316852891907537959070850774879_qp), & + (-0.450830023070757909819938902273861459_qp, & + 0.917954692926131299302028310194145888_qp), & + (-0.166943359095192145336028488600277342_qp, & + 1.05997401970850635422038976685144007_qp), & + (-0.429652190199228276035192664039641386_qp, & + 0.523558274341032421628217008446881664_qp), & + (0.427181091476823815433760955784237012_qp, & + 1.34628934976074521312483511792379431_qp), & + (-0.343281426018765739582860874179459643_qp, & + 1.15357331316264255516301773241139017_qp), & + (-0.127590074749816595467422075671493076_qp, & + 1.06891199479835175001340985545539297_qp), & + (0.262287586904722758163188700564205647_qp, & + 1.29508919831907332032017166056903079_qp), & + (-0.192677407376582732201342196276527829_qp, & + 1.32794925614337933073016984053538181_qp), & + (-0.264742129752461530234342035328154452_qp, & + 1.01282963412172621886497836385387927_qp)] print *, "Test uniform_distribution_rvs_cqp" seed = 258147369; k = 5 From ad6e40a4f23295856fbdece5aa935115d1bf6b56 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Tue, 29 Dec 2020 17:07:40 -0500 Subject: [PATCH 024/172] Update stdlib_stats_distribution_uniform.md --- doc/specs/stdlib_stats_distribution_uniform.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index 97f7c1137..8ae020a39 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -22,7 +22,7 @@ Applying Fisher-Yates algorithm to generate an unbiased permutation for any list ### Arguments -`list`: argument has `intent(in)` and is a rank one array of integer, real, or complx type. +`list`: argument has `intent(in)` and is a rank one array of integer, real, or complex type. ### Return value @@ -69,12 +69,14 @@ Without augument the function returns a scalar standard uniformly distributed va With single augument `scale` of integer type the function returns a scalar uniformly distributed variate of integer type on [0,scale]. This is the standard Rectangular distribtuion. Function is elemental. -With single augument `scale` of real or complx type the function returns a scalar uniformly distributed variate of real or complx type on [0, scale]. The real part and imaginary part of a complx type are independent of each other. Function is elemental. +With single augument `scale` of real or complex type the function returns a scalar uniformly distributed variate of real or complex type on [0, scale]. The real part and imaginary part of a complex type are independent of each other. Function is elemental. With double auguments `loc` and `scale` the function returns a scalar uniformly distributed random variates of integer, real or complx type on [loc, loc + scale] dependent of input type. If it is complex augument, the real part and imaginary part are independent of each other. Function is elemental. With triple auguments `loc`, `scale` and `array_size` the function returns a rank one array of uniformly distributed variates of integer, real or complx type with an array size of `array_size`. +`scale` must be greater than 0. + ### Syntax `result = [[stdlib_stats_distribution_uniform(module):uniform_distribution_rvs(interface)]]([[loc,] scale] [[[,array_size]]])` From 6fceac9cf2b11fb40ea63e401e972cc5170341f2 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Tue, 29 Dec 2020 17:42:45 -0500 Subject: [PATCH 025/172] Update Makefile.manual --- src/Makefile.manual | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Makefile.manual b/src/Makefile.manual index 60904023c..64a9873bb 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -14,7 +14,9 @@ SRC = f18estop.f90 \ stdlib_quadrature_trapz.f90 \ stdlib_stats.f90 \ stdlib_stats_mean.f90 \ - stdlib_stats_moment.f90 \ + stdlib_stats_moment_all.f90 \ + stdlib_stats_moment_mask.f90 \ + stdlib_stats_moment_scalar.f90 \ stdlib_stats_var.f90 \ stdlib_stats_distribution_PRNG.f90\ stdlib_stats_distribution_uniform.f90 @@ -88,4 +90,4 @@ stdlib_stats_mean.f90: stdlib_stats_mean.fypp stdlib_stats_moment.f90: stdlib_stats_moment.fypp stdlib_stats_var.f90: stdlib_stats_var.fypp stdlib_stats_distribution_PRNG.f90: stdlib_stats_distribution_PRNG.fypp -stdlib_stats_distribution_uniform.f90: stdlib_stats_distribution_uniform.fypp \ No newline at end of file +stdlib_stats_distribution_uniform.f90: stdlib_stats_distribution_uniform.fypp From f00cd1551f2a991acb64f47bc19696ee719526ee Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Tue, 29 Dec 2020 17:47:07 -0500 Subject: [PATCH 026/172] Update Makefile.manual --- src/Makefile.manual | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Makefile.manual b/src/Makefile.manual index 64a9873bb..7f7f6031b 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -14,6 +14,7 @@ SRC = f18estop.f90 \ stdlib_quadrature_trapz.f90 \ stdlib_stats.f90 \ stdlib_stats_mean.f90 \ + stdlib_stats_moment.f90 \ stdlib_stats_moment_all.f90 \ stdlib_stats_moment_mask.f90 \ stdlib_stats_moment_scalar.f90 \ From afb881e8bc1fd6d669e4141202e5ecb46a812f4b Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Tue, 29 Dec 2020 17:52:40 -0500 Subject: [PATCH 027/172] Update Makefile.manual --- src/Makefile.manual | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Makefile.manual b/src/Makefile.manual index 872f704c0..dd6f12708 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -15,6 +15,9 @@ SRC = f18estop.f90 \ stdlib_stats.f90 \ stdlib_stats_mean.f90 \ stdlib_stats_moment.f90 \ + stdlib_stats_moment_all.f90 \ + stdlib_stats_moment_mask.f90 \ + stdlib_stats_moment_scalar.f90 \ stdlib_stats_var.f90 LIB = libstdlib.a @@ -79,4 +82,7 @@ stdlib_quadrature.f90: stdlib_quadrature.fypp stdlib_stats.f90: stdlib_stats.fypp stdlib_stats_mean.f90: stdlib_stats_mean.fypp stdlib_stats_moment.f90: stdlib_stats_moment.fypp +stdlib_stats_moment_all.f90: stdlib_stats_moment_all.fypp +stdlib_stats_moment_mask.f90: stdlib_stats_moment_mask.fypp +stdlib_stats_moment_scalar.f90: stdlib_stats_moment_scalar.fypp stdlib_stats_var.f90: stdlib_stats_var.fypp From 8abb168c53e184b82b2b1976d732d145a3b80d21 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Tue, 29 Dec 2020 18:00:43 -0500 Subject: [PATCH 028/172] Update CMakeLists.txt --- src/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 02604959e..e2caa0bbc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,6 +14,9 @@ set(fppFiles stdlib_stats_cov.fypp stdlib_stats_mean.fypp stdlib_stats_moment.fypp + stdlib_stats_moment_all.fypp + stdlib_stats_moment_mask.fypp + stdlib_stats_moment_scalar.fypp stdlib_stats_var.fypp stdlib_quadrature.fypp stdlib_quadrature_trapz.fypp From 157dba80e588a64f1e85505ddf11d9fe6c9979c0 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Tue, 29 Dec 2020 18:19:44 -0500 Subject: [PATCH 029/172] Update CMakeLists.txt --- src/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e2caa0bbc..8cdccdf68 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,6 +21,7 @@ set(fppFiles stdlib_quadrature.fypp stdlib_quadrature_trapz.fypp stdlib_quadrature_simps.fypp + stdlib_stats_distribution_PRNG.fypp ) From d7643cbc5d9ad4f25d9346e5cdc27a9508a49ab2 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Tue, 29 Dec 2020 18:21:31 -0500 Subject: [PATCH 030/172] Update Makefile.manual --- src/Makefile.manual | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Makefile.manual b/src/Makefile.manual index dd6f12708..302d1e21b 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -18,7 +18,8 @@ SRC = f18estop.f90 \ stdlib_stats_moment_all.f90 \ stdlib_stats_moment_mask.f90 \ stdlib_stats_moment_scalar.f90 \ - stdlib_stats_var.f90 + stdlib_stats_var.f90 \ + stdlib_stats_distribution_PRNG.f90 LIB = libstdlib.a @@ -70,6 +71,7 @@ stdlib_stats_var.o: \ stdlib_optval.o \ stdlib_kinds.o \ stdlib_stats.o +stdlib_stats_distribution.PRNG.o: stdlib_kinds.o stdlib_error.o # Fortran sources that are built from fypp templates stdlib_bitsets_64.f90: stdlib_bitsets_64.fypp @@ -86,3 +88,4 @@ stdlib_stats_moment_all.f90: stdlib_stats_moment_all.fypp stdlib_stats_moment_mask.f90: stdlib_stats_moment_mask.fypp stdlib_stats_moment_scalar.f90: stdlib_stats_moment_scalar.fypp stdlib_stats_var.f90: stdlib_stats_var.fypp +stdlib_stats_distribution_PRNG.f90: stdlib_stats_distribution_PRNG.fypp From 5651f5e62f92caa30326fe888f1b97616a9a90f6 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Tue, 29 Dec 2020 18:22:09 -0500 Subject: [PATCH 031/172] Update CMakeLists.txt --- src/tests/stats/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/stats/CMakeLists.txt b/src/tests/stats/CMakeLists.txt index 36ffc7aeb..38f9bb84b 100644 --- a/src/tests/stats/CMakeLists.txt +++ b/src/tests/stats/CMakeLists.txt @@ -5,6 +5,7 @@ ADDTEST(moment) ADDTEST(rawmoment) ADDTEST(var) ADDTEST(varn) +ADDTEST(distribution_PRNG) if(DEFINED CMAKE_MAXIMUM_RANK) if(${CMAKE_MAXIMUM_RANK} GREATER 7) From 5afcba5801a34115ca638eb9cc95804af73d7f16 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Tue, 29 Dec 2020 18:26:08 -0500 Subject: [PATCH 032/172] Update CMakeLists.txt --- src/tests/stats/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tests/stats/CMakeLists.txt b/src/tests/stats/CMakeLists.txt index 38f9bb84b..36ffc7aeb 100644 --- a/src/tests/stats/CMakeLists.txt +++ b/src/tests/stats/CMakeLists.txt @@ -5,7 +5,6 @@ ADDTEST(moment) ADDTEST(rawmoment) ADDTEST(var) ADDTEST(varn) -ADDTEST(distribution_PRNG) if(DEFINED CMAKE_MAXIMUM_RANK) if(${CMAKE_MAXIMUM_RANK} GREATER 7) From 4cb0041d95e536c2fc325b828ac083b086286d4f Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Tue, 29 Dec 2020 18:26:30 -0500 Subject: [PATCH 033/172] Update CMakeLists.txt --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8cdccdf68..1704e12ab 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,7 +21,7 @@ set(fppFiles stdlib_quadrature.fypp stdlib_quadrature_trapz.fypp stdlib_quadrature_simps.fypp - stdlib_stats_distribution_PRNG.fypp + ) From 91c1ad42b9abfbcc4544bb1b977467368c86846a Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Tue, 29 Dec 2020 18:27:11 -0500 Subject: [PATCH 034/172] Update Makefile.manual --- src/Makefile.manual | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Makefile.manual b/src/Makefile.manual index 302d1e21b..dd6f12708 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -18,8 +18,7 @@ SRC = f18estop.f90 \ stdlib_stats_moment_all.f90 \ stdlib_stats_moment_mask.f90 \ stdlib_stats_moment_scalar.f90 \ - stdlib_stats_var.f90 \ - stdlib_stats_distribution_PRNG.f90 + stdlib_stats_var.f90 LIB = libstdlib.a @@ -71,7 +70,6 @@ stdlib_stats_var.o: \ stdlib_optval.o \ stdlib_kinds.o \ stdlib_stats.o -stdlib_stats_distribution.PRNG.o: stdlib_kinds.o stdlib_error.o # Fortran sources that are built from fypp templates stdlib_bitsets_64.f90: stdlib_bitsets_64.fypp @@ -88,4 +86,3 @@ stdlib_stats_moment_all.f90: stdlib_stats_moment_all.fypp stdlib_stats_moment_mask.f90: stdlib_stats_moment_mask.fypp stdlib_stats_moment_scalar.f90: stdlib_stats_moment_scalar.fypp stdlib_stats_var.f90: stdlib_stats_var.fypp -stdlib_stats_distribution_PRNG.f90: stdlib_stats_distribution_PRNG.fypp From aed0d77c219cfd8557c5194f75308fd48dd09404 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 31 Dec 2020 14:55:33 -0500 Subject: [PATCH 035/172] Update CMakeLists.txt --- src/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ab827981f..dba50f019 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,8 +18,8 @@ set(fppFiles stdlib_quadrature.fypp stdlib_quadrature_trapz.fypp stdlib_quadrature_simps.fypp - stdlib_stats_distribution_PRNG.fypp - stdlib_stats_distribution_uniform.fypp +# stdlib_stats_distribution_PRNG.fypp +# stdlib_stats_distribution_uniform.fypp ) From 4d7fb2d1c6158025b892412d3e74105910149755 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 31 Dec 2020 14:56:23 -0500 Subject: [PATCH 036/172] Update Makefile.manual --- src/Makefile.manual | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Makefile.manual b/src/Makefile.manual index 7f7f6031b..e0a329884 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -19,8 +19,8 @@ SRC = f18estop.f90 \ stdlib_stats_moment_mask.f90 \ stdlib_stats_moment_scalar.f90 \ stdlib_stats_var.f90 \ - stdlib_stats_distribution_PRNG.f90\ - stdlib_stats_distribution_uniform.f90 +# stdlib_stats_distribution_PRNG.f90\ +# stdlib_stats_distribution_uniform.f90 LIB = libstdlib.a @@ -72,11 +72,11 @@ stdlib_stats_var.o: \ stdlib_optval.o \ stdlib_kinds.o \ stdlib_stats.o -stdlib_stats_distribution_PRNG.o: stdlib_kinds.o -stdlib_stats_distribution_uniform.o: \ - stdlib_kinds.o \ - stdlib_error.o \ - stdlib_stats_distribution_PRNG.o +# stdlib_stats_distribution_PRNG.o: stdlib_kinds.o +# stdlib_stats_distribution_uniform.o: \ +# stdlib_kinds.o \ +# stdlib_error.o \ +# stdlib_stats_distribution_PRNG.o # Fortran sources that are built from fypp templates stdlib_bitsets_64.f90: stdlib_bitsets_64.fypp @@ -90,5 +90,5 @@ stdlib_stats.f90: stdlib_stats.fypp stdlib_stats_mean.f90: stdlib_stats_mean.fypp stdlib_stats_moment.f90: stdlib_stats_moment.fypp stdlib_stats_var.f90: stdlib_stats_var.fypp -stdlib_stats_distribution_PRNG.f90: stdlib_stats_distribution_PRNG.fypp -stdlib_stats_distribution_uniform.f90: stdlib_stats_distribution_uniform.fypp +#stdlib_stats_distribution_PRNG.f90: stdlib_stats_distribution_PRNG.fypp +#stdlib_stats_distribution_uniform.f90: stdlib_stats_distribution_uniform.fypp From 20a3403c9ea45d376940155d22ef0e20b8704572 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 31 Dec 2020 14:58:22 -0500 Subject: [PATCH 037/172] Update CMakeLists.txt --- src/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dba50f019..02604959e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,8 +18,6 @@ set(fppFiles stdlib_quadrature.fypp stdlib_quadrature_trapz.fypp stdlib_quadrature_simps.fypp -# stdlib_stats_distribution_PRNG.fypp -# stdlib_stats_distribution_uniform.fypp ) From fce3d03e42f1b5941e687cc89bbaf63271b9e9dd Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 31 Dec 2020 14:58:52 -0500 Subject: [PATCH 038/172] Update Makefile.manual --- src/Makefile.manual | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/Makefile.manual b/src/Makefile.manual index e0a329884..98ff119a7 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -18,9 +18,7 @@ SRC = f18estop.f90 \ stdlib_stats_moment_all.f90 \ stdlib_stats_moment_mask.f90 \ stdlib_stats_moment_scalar.f90 \ - stdlib_stats_var.f90 \ -# stdlib_stats_distribution_PRNG.f90\ -# stdlib_stats_distribution_uniform.f90 + stdlib_stats_var.f90 LIB = libstdlib.a @@ -72,11 +70,6 @@ stdlib_stats_var.o: \ stdlib_optval.o \ stdlib_kinds.o \ stdlib_stats.o -# stdlib_stats_distribution_PRNG.o: stdlib_kinds.o -# stdlib_stats_distribution_uniform.o: \ -# stdlib_kinds.o \ -# stdlib_error.o \ -# stdlib_stats_distribution_PRNG.o # Fortran sources that are built from fypp templates stdlib_bitsets_64.f90: stdlib_bitsets_64.fypp @@ -90,5 +83,3 @@ stdlib_stats.f90: stdlib_stats.fypp stdlib_stats_mean.f90: stdlib_stats_mean.fypp stdlib_stats_moment.f90: stdlib_stats_moment.fypp stdlib_stats_var.f90: stdlib_stats_var.fypp -#stdlib_stats_distribution_PRNG.f90: stdlib_stats_distribution_PRNG.fypp -#stdlib_stats_distribution_uniform.f90: stdlib_stats_distribution_uniform.fypp From a39f5ef6fe4ec347c55a7937409f2252c391ecb1 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 31 Dec 2020 14:59:57 -0500 Subject: [PATCH 039/172] Update Makefile.manual --- src/Makefile.manual | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Makefile.manual b/src/Makefile.manual index 98ff119a7..fece5254b 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -19,7 +19,8 @@ SRC = f18estop.f90 \ stdlib_stats_moment_mask.f90 \ stdlib_stats_moment_scalar.f90 \ stdlib_stats_var.f90 - + + LIB = libstdlib.a From deb318a3a8b5c9e769ce33f87c2913d4a975b565 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 31 Dec 2020 15:00:31 -0500 Subject: [PATCH 040/172] Update Makefile.manual --- src/Makefile.manual | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Makefile.manual b/src/Makefile.manual index fece5254b..8b54c2144 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -20,7 +20,6 @@ SRC = f18estop.f90 \ stdlib_stats_moment_scalar.f90 \ stdlib_stats_var.f90 - LIB = libstdlib.a From ea14a812620ceeba15563034bb8f4b2c500da24b Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 31 Dec 2020 15:01:37 -0500 Subject: [PATCH 041/172] Update CMakeLists.txt --- src/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1704e12ab..8929f3a76 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,6 +21,8 @@ set(fppFiles stdlib_quadrature.fypp stdlib_quadrature_trapz.fypp stdlib_quadrature_simps.fypp + stdlib_stats_distribution_PRNG.fypp + stdlib_stats_distribution_uniform.fypp ) From d791afeca9ced1150c835dc4453fe3f1cad5bb98 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 31 Dec 2020 15:04:24 -0500 Subject: [PATCH 042/172] Update Makefile.manual --- src/Makefile.manual | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Makefile.manual b/src/Makefile.manual index dd6f12708..935126563 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -18,7 +18,9 @@ SRC = f18estop.f90 \ stdlib_stats_moment_all.f90 \ stdlib_stats_moment_mask.f90 \ stdlib_stats_moment_scalar.f90 \ - stdlib_stats_var.f90 + stdlib_stats_var.f90 \ + stdlib_stats_distribution_PRNG.f90 \ + stdlib_stats_distribution_uniform.f90 LIB = libstdlib.a @@ -70,6 +72,11 @@ stdlib_stats_var.o: \ stdlib_optval.o \ stdlib_kinds.o \ stdlib_stats.o +stdlib_stats_distribution_PRNG.o: stdlib_kinds.o stdlib_error.o +stdlib_stats_distribution.uniform.o: \ + stdlib_kinds.o \ + stdlib_error.o \ + stdlib_stats_distribution.o # Fortran sources that are built from fypp templates stdlib_bitsets_64.f90: stdlib_bitsets_64.fypp @@ -86,3 +93,5 @@ stdlib_stats_moment_all.f90: stdlib_stats_moment_all.fypp stdlib_stats_moment_mask.f90: stdlib_stats_moment_mask.fypp stdlib_stats_moment_scalar.f90: stdlib_stats_moment_scalar.fypp stdlib_stats_var.f90: stdlib_stats_var.fypp +stdlib_stats_distribution_PRNG.f90: stdlib_stats_distribution_PRNG.fypp +stdlib_stats_distribution_uniform.f90: stdlib_stats_distribution_uniform.fypp From 8cbbb519f6637f1f80e0addba7233950b7b099d7 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 31 Dec 2020 15:04:42 -0500 Subject: [PATCH 043/172] Delete test_distribution_uniform.f90 --- src/tests/test_distribution_uniform.f90 | 855 ------------------------ 1 file changed, 855 deletions(-) delete mode 100644 src/tests/test_distribution_uniform.f90 diff --git a/src/tests/test_distribution_uniform.f90 b/src/tests/test_distribution_uniform.f90 deleted file mode 100644 index 0f6315a6a..000000000 --- a/src/tests/test_distribution_uniform.f90 +++ /dev/null @@ -1,855 +0,0 @@ -program test_distribution_uniform - use stdlib_error, only : check - use stdlib_kinds - use stdlib_stats_distribution_PRNG, only : random_seed, dist_rand - use stdlib_stats_distribution_uniform, & - uni_rvs => uniform_distribution_rvs, & - uni_pdf => uniform_distribution_pdf, & - uni_cdf => uniform_distribution_cdf - - implicit none - logical :: warn = .true. - real(sp), parameter :: sptol = 1000 * epsilon(1.0_sp) - real(dp), parameter :: dptol = 1000 * epsilon(1.0_dp) - real(qp), parameter :: qptol = 1000 * epsilon(1.0_qp) - integer :: put, get - - put = 135792468 - - call test_shuffle - - call test_uni_rvs_0 - - call test_uni_rvs_iint8 - call test_uni_rvs_iint16 - call test_uni_rvs_iint32 - call test_uni_rvs_iint64 - call test_uni_rvs_rsp - call test_uni_rvs_rdp - call test_uni_rvs_rqp - call test_uni_rvs_csp - call test_uni_rvs_cdp - call test_uni_rvs_cqp - - call test_uni_pdf_iint8 - call test_uni_pdf_iint16 - call test_uni_pdf_iint32 - call test_uni_pdf_iint64 - call test_uni_pdf_rsp - call test_uni_pdf_rdp - call test_uni_pdf_rqp - call test_uni_pdf_csp - call test_uni_pdf_cdp - call test_uni_pdf_cqp - - call test_uni_cdf_iint8 - call test_uni_cdf_iint16 - call test_uni_cdf_iint32 - call test_uni_cdf_iint64 - call test_uni_cdf_rsp - call test_uni_cdf_rdp - call test_uni_cdf_rqp - call test_uni_cdf_csp - call test_uni_cdf_cdp - call test_uni_cdf_cqp - stop - - contains - - subroutine test_shuffle - integer :: n(10), na(10) = [10, 6, 9, 2, 8, 1, 3, 5, 7, 4] - real :: x(10), xa(10)= [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, & - 7.0, 6.0] - complex :: z(10), za(10)=[(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), & - (1.0, 1.0), (5.0, 5.0), (9.0, 9.0), & - (6.0, 6.0), (3.0, 3.0), (2.0, 2.0), & - (10.0, 10.0)] - integer :: i, put, get - - do i=1, 10 - n(i) = i - x(i) = real(i) - z(i) = cmplx(real(i),real(i)) - end do - put = 32165498 - call random_seed(put, get) - n(:) = shuffle(n) - x(:) = shuffle(x) - z(:) = shuffle(z) - call check(all(n == na), & - msg="Integer shuffle failed test", warn=warn) - call check(all(x == xa), & - msg="Real shuffle failed test", warn=warn) - call check(all(z == za), & - msg="Complex shuffle failed test", warn=warn) - end subroutine test_shuffle - - subroutine test_uni_rvs_0 - integer :: i, j, freq(0:1000), num=10000000 - real(dp) :: chisq, expct - - print *,"" - print *, "Test uniform random generator with chi-squared" - freq = 0 - do i = 1, num - j = 1000 * uni_rvs( ) - freq(j) = freq(j) + 1 - end do - chisq = 0.0_dp - expct = num / 1000 - do i = 0, 999 - chisq = chisq + (freq(i) - expct) ** 2 / expct - end do - write(*,*) "The critical values for chi-squared with 1000 d. of f. are" & - //" 1143.92" - write(*,*) "Chi-squared for uniform random generator is : ", chisq - call check((chisq < 1143.9) , & - msg="uniform randomness failed chi-squared test", warn=warn) - end subroutine test_uni_rvs_0 - - subroutine test_uni_rvs_iint8 - integer(int8) :: res(15), scale, loc - integer :: i, n, seed, get, k - - integer(int8) :: ans(15) = [47, 99, 43, 37, 48, 30, 27, 100, 30, 33, 21, & - 103, 55, 54, 110] - - print *, "Test uniform_distribution_rvs_iint8" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = 15_int8; scale = 100_int8 - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(res == ans), & - msg="uniform_distribution_rvs_iint8 failed", warn=warn) - end subroutine test_uni_rvs_iint8 - - subroutine test_uni_rvs_iint16 - integer(int16) :: res(15), scale, loc - integer :: i, n, seed, get, k - - integer(int16) :: ans(15) = [25, 4, 81, 98, 49, 34, 32, 62, 115, 112, 26, & - 20, 37, 100, 82] - - print *, "Test uniform_distribution_rvs_iint16" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = 15_int16; scale = 100_int16 - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(res == ans), & - msg="uniform_distribution_rvs_iint16 failed", warn=warn) - end subroutine test_uni_rvs_iint16 - - subroutine test_uni_rvs_iint32 - integer(int32) :: res(15), scale, loc - integer :: i, n, seed, get, k - - integer(int32) :: ans(15) = [19, 52, 56, 20, 59, 44, 34, 102, 19, 39, 60, & - 50, 97, 56, 67] - - print *, "Test uniform_distribution_rvs_iint32" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = 15_int32; scale = 100_int32 - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(res == ans), & - msg="uniform_distribution_rvs_iint32 failed", warn=warn) - end subroutine test_uni_rvs_iint32 - - subroutine test_uni_rvs_iint64 - integer(int64) :: res(15), scale, loc - integer :: i, n, seed, get, k - - integer(int64) :: ans(15) = [76, 45, 43, 75, 76, 15, 25, 24, 114, 113, 94, & - 29, 109, 93, 89] - - print *, "Test uniform_distribution_rvs_iint64" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = 15_int64; scale = 100_int64 - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(res == ans), & - msg="uniform_distribution_rvs_iint64 failed", warn=warn) - end subroutine test_uni_rvs_iint64 - - subroutine test_uni_rvs_rsp - real(sp) :: res(15), scale, loc - integer :: i, n, seed, get, k - - real(sp) :: ans(15) = & - [0.914826628538749186958511927514337003_sp, & - 0.367330098664966409049981166390352882_sp, & - 1.77591243057709280428468900936422870_sp, & - 0.885921308987590139238932351872790605_sp, & - 0.950735656542987861428173346212133765_sp, & - -0.659562573857055134407545438079978339_sp, & - -0.116661718506947176265953203255776316_sp, & - 0.837391893893859151631886561517603695_sp, & - -0.703954396598600540269075054311542772_sp, & - 0.382592729851141566399519433616660535_sp, & - -0.132472493978185168472805344208609313_sp, & - -0.878723366294216184924081858298450243_sp, & - -0.901660046141515819639877804547722917_sp, & - -0.164090614147737401395943379611708224_sp, & - -0.333886718190384290672056977200554684_sp] - - print *, "Test uniform_distribution_rvs_rsp" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = -1.0_sp; scale = 2.0_sp - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(res - ans) < sptol), & - msg="uniform_distribution_rvs_rsp failed", warn=warn) - end subroutine test_uni_rvs_rsp - - subroutine test_uni_rvs_rdp - real(dp) :: res(15), scale, loc - integer :: i, n, seed, get, k - - real(dp) :: ans(15) = & - [0.914826628538749186958511927514337003_dp, & - 0.367330098664966409049981166390352882_dp, & - 1.77591243057709280428468900936422870_dp, & - 0.885921308987590139238932351872790605_dp, & - 0.950735656542987861428173346212133765_dp, & - -0.659562573857055134407545438079978339_dp, & - -0.116661718506947176265953203255776316_dp, & - 0.837391893893859151631886561517603695_dp, & - -0.703954396598600540269075054311542772_dp, & - 0.382592729851141566399519433616660535_dp, & - -0.132472493978185168472805344208609313_dp, & - -0.878723366294216184924081858298450243_dp, & - -0.901660046141515819639877804547722917_dp, & - -0.164090614147737401395943379611708224_dp, & - -0.333886718190384290672056977200554684_dp] - - print *, "Test uniform_distribution_rvs_rdp" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = -1.0_dp; scale = 2.0_dp - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(res - ans) < dptol), & - msg="uniform_distribution_rvs_rdp failed", warn=warn) - end subroutine test_uni_rvs_rdp - - subroutine test_uni_rvs_rqp - real(qp) :: res(15), scale, loc - integer :: i, n, seed, get, k - - real(qp) :: ans(15) = & - [0.914826628538749186958511927514337003_qp, & - 0.367330098664966409049981166390352882_qp, & - 1.77591243057709280428468900936422870_qp, & - 0.885921308987590139238932351872790605_qp, & - 0.950735656542987861428173346212133765_qp, & - -0.659562573857055134407545438079978339_qp, & - -0.116661718506947176265953203255776316_qp, & - 0.837391893893859151631886561517603695_qp, & - -0.703954396598600540269075054311542772_qp, & - 0.382592729851141566399519433616660535_qp, & - -0.132472493978185168472805344208609313_qp, & - -0.878723366294216184924081858298450243_qp, & - -0.901660046141515819639877804547722917_qp, & - -0.164090614147737401395943379611708224_qp, & - -0.333886718190384290672056977200554684_qp] - - print *, "Test uniform_distribution_rvs_rqp" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = -1.0_qp; scale = 2.0_qp - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(res - ans) < qptol), & - msg="uniform_distribution_rvs_rqp failed", warn=warn) - end subroutine test_uni_rvs_rqp - - subroutine test_uni_rvs_csp - complex(sp) :: res(15), scale, loc - integer :: i, n, seed, get, k - - complex(sp) :: ans(15) = [(0.457413315773010253906250000000000000_sp, & - 0.183665052056312561035156250000000000_sp), & - (0.887956202030181884765625000000000000_sp, & - 0.442960649728775024414062500000000000_sp), & - (0.475367814302444458007812500000000000_sp, & - 0.170218706130981445312500000000000000_sp), & - (0.441669136285781860351562500000000000_sp, & - 0.918695926666259765625000000000000000_sp), & - (0.148022800683975219726562500000000000_sp, & - 0.691296339035034179687500000000000000_sp), & - (-6.623625010251998901367187500000000000E-0002_sp, & - 0.560638308525085449218750000000000000_sp), & - (-0.450830012559890747070312500000000000_sp, & - 0.917954683303833007812500000000000000_sp), & - (-0.166943356394767761230468750000000000_sp, & - 1.05997407436370849609375000000000000_sp), & - (-0.429652184247970581054687500000000000_sp, & - 0.523558259010314941406250000000000000_sp), & - (0.427181094884872436523437500000000000_sp, & - 1.34628939628601074218750000000000000_sp), & - (-0.343281418085098266601562500000000000_sp, & - 1.15357327461242675781250000000000000_sp), & - (-0.127590075135231018066406250000000000_sp, & - 1.06891202926635742187500000000000000_sp), & - (0.262287586927413940429687500000000000_sp, & - 1.29508924484252929687500000000000000_sp), & - (-0.192677408456802368164062500000000000_sp, & - 1.32794928550720214843750000000000000_sp), & - (-0.264742136001586914062500000000000000_sp, & - 1.01282966136932373046875000000000000_sp)] - - print *, "Test uniform_distribution_rvs_csp" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = (-0.5_sp,0.5_sp); scale = (1.0_sp, 1.0_sp) - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(real(res) - real(ans)) < sptol) .and. & - all(abs(aimag(res) - aimag(ans)) < sptol), & - msg="uniform_distribution_rvs_csp failed", warn=warn) - end subroutine test_uni_rvs_csp - - subroutine test_uni_rvs_cdp - complex(dp) :: res(15), scale, loc - integer :: i, n, seed, get, k - - complex(dp) :: ans(15) = [(0.457413315773010253906250000000000000_dp, & - 0.183665052056312561035156250000000000_dp), & - (0.887956202030181884765625000000000000_dp, & - 0.442960649728775024414062500000000000_dp), & - (0.475367814302444458007812500000000000_dp, & - 0.170218706130981445312500000000000000_dp), & - (0.441669136285781860351562500000000000_dp, & - 0.918695926666259765625000000000000000_dp), & - (0.148022800683975219726562500000000000_dp, & - 0.691296339035034179687500000000000000_dp), & - (-6.623625010251998901367187500000000000E-0002_dp, & - 0.560638308525085449218750000000000000_dp), & - (-0.450830012559890747070312500000000000_dp, & - 0.917954683303833007812500000000000000_dp), & - (-0.166943356394767761230468750000000000_dp, & - 1.05997407436370849609375000000000000_dp), & - (-0.429652184247970581054687500000000000_dp, & - 0.523558259010314941406250000000000000_dp), & - (0.427181094884872436523437500000000000_dp, & - 1.34628939628601074218750000000000000_dp), & - (-0.343281418085098266601562500000000000_dp, & - 1.15357327461242675781250000000000000_dp), & - (-0.127590075135231018066406250000000000_dp, & - 1.06891202926635742187500000000000000_dp), & - (0.262287586927413940429687500000000000_dp, & - 1.29508924484252929687500000000000000_dp), & - (-0.192677408456802368164062500000000000_dp, & - 1.32794928550720214843750000000000000_dp), & - (-0.264742136001586914062500000000000000_dp, & - 1.01282966136932373046875000000000000_dp)] - - print *, "Test uniform_distribution_rvs_cdp" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = (-0.5_dp,0.5_dp); scale = (1.0_dp, 1.0_dp) - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(real(res) - real(ans)) < dptol) .and. & - all(abs(aimag(res) - aimag(ans)) < dptol), & - msg="uniform_distribution_rvs_cdp failed", warn=warn) - end subroutine test_uni_rvs_cdp - - subroutine test_uni_rvs_cqp - complex(qp) :: res(15), scale, loc - integer :: i, n, seed, get, k - - complex(qp) :: ans(15) = [(0.457413315773010253906250000000000000_qp, & - 0.183665052056312561035156250000000000_qp), & - (0.887956202030181884765625000000000000_qp, & - 0.442960649728775024414062500000000000_qp), & - (0.475367814302444458007812500000000000_qp, & - 0.170218706130981445312500000000000000_qp), & - (0.441669136285781860351562500000000000_qp, & - 0.918695926666259765625000000000000000_qp), & - (0.148022800683975219726562500000000000_qp, & - 0.691296339035034179687500000000000000_qp), & - (-6.623625010251998901367187500000000000E-0002_qp, & - 0.560638308525085449218750000000000000_qp), & - (-0.450830012559890747070312500000000000_qp, & - 0.917954683303833007812500000000000000_qp), & - (-0.166943356394767761230468750000000000_qp, & - 1.05997407436370849609375000000000000_qp), & - (-0.429652184247970581054687500000000000_qp, & - 0.523558259010314941406250000000000000_qp), & - (0.427181094884872436523437500000000000_qp, & - 1.34628939628601074218750000000000000_qp), & - (-0.343281418085098266601562500000000000_qp, & - 1.15357327461242675781250000000000000_qp), & - (-0.127590075135231018066406250000000000_qp, & - 1.06891202926635742187500000000000000_qp), & - (0.262287586927413940429687500000000000_qp, & - 1.29508924484252929687500000000000000_qp), & - (-0.192677408456802368164062500000000000_qp, & - 1.32794928550720214843750000000000000_qp), & - (-0.264742136001586914062500000000000000_qp, & - 1.01282966136932373046875000000000000_qp)] - - print *, "Test uniform_distribution_rvs_cqp" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = (-0.5_qp,0.5_qp); scale = (1.0_qp, 1.0_qp) - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(real(res) - real(ans)) < qptol) .and. & - all(abs(aimag(res) - aimag(ans)) < qptol), & - msg="uniform_distribution_rvs_cqp failed", warn=warn) - end subroutine test_uni_rvs_cqp - - - subroutine test_uni_pdf_iint8 - integer(int8) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(1.96078438E-02, i=1,15)] - - print *, "Test uniform_distribution_pdf_iint8" - seed = 147258639 - call random_seed(seed, get) - loc = 0_int8; scale = 50_int8 - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_iint8 failed", warn=warn) - end subroutine test_uni_pdf_iint8 - - subroutine test_uni_pdf_iint16 - integer(int16) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(1.96078438E-02, i=1,15)] - - print *, "Test uniform_distribution_pdf_iint16" - seed = 147258639 - call random_seed(seed, get) - loc = 0_int16; scale = 50_int16 - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_iint16 failed", warn=warn) - end subroutine test_uni_pdf_iint16 - - subroutine test_uni_pdf_iint32 - integer(int32) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(1.96078438E-02, i=1,15)] - - print *, "Test uniform_distribution_pdf_iint32" - seed = 147258639 - call random_seed(seed, get) - loc = 0_int32; scale = 50_int32 - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_iint32 failed", warn=warn) - end subroutine test_uni_pdf_iint32 - - subroutine test_uni_pdf_iint64 - integer(int64) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(1.96078438E-02, i=1,15)] - - print *, "Test uniform_distribution_pdf_iint64" - seed = 147258639 - call random_seed(seed, get) - loc = 0_int64; scale = 50_int64 - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_iint64 failed", warn=warn) - end subroutine test_uni_pdf_iint64 - - subroutine test_uni_pdf_rsp - real(sp) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(0.5, i=1,15)] - - print *, "Test uniform_distribution_pdf_rsp" - seed = 147258639 - call random_seed(seed, get) - loc = 0.0_sp; scale = 2.0_sp - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_rsp failed", warn=warn) - end subroutine test_uni_pdf_rsp - - subroutine test_uni_pdf_rdp - real(dp) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(0.5, i=1,15)] - - print *, "Test uniform_distribution_pdf_rdp" - seed = 147258639 - call random_seed(seed, get) - loc = 0.0_dp; scale = 2.0_dp - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_rdp failed", warn=warn) - end subroutine test_uni_pdf_rdp - - subroutine test_uni_pdf_rqp - real(qp) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(0.5, i=1,15)] - - print *, "Test uniform_distribution_pdf_rqp" - seed = 147258639 - call random_seed(seed, get) - loc = 0.0_qp; scale = 2.0_qp - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_rqp failed", warn=warn) - end subroutine test_uni_pdf_rqp - - subroutine test_uni_pdf_csp - complex(sp) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(1.0, i=1,15)] - - print *, "Test uniform_distribution_pdf_csp" - seed = 147258639 - call random_seed(seed, get) - loc = (-0.5_sp, 0.5_sp); scale = (1.0_sp, 1.0_sp) - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_csp failed", warn=warn) - end subroutine test_uni_pdf_csp - - subroutine test_uni_pdf_cdp - complex(dp) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(1.0, i=1,15)] - - print *, "Test uniform_distribution_pdf_cdp" - seed = 147258639 - call random_seed(seed, get) - loc = (-0.5_dp, 0.5_dp); scale = (1.0_dp, 1.0_dp) - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_cdp failed", warn=warn) - end subroutine test_uni_pdf_cdp - - subroutine test_uni_pdf_cqp - complex(qp) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(1.0, i=1,15)] - - print *, "Test uniform_distribution_pdf_cqp" - seed = 147258639 - call random_seed(seed, get) - loc = (-0.5_qp, 0.5_qp); scale = (1.0_qp, 1.0_qp) - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_cqp failed", warn=warn) - end subroutine test_uni_pdf_cqp - - - subroutine test_uni_cdf_iint8 - integer(int8) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [0.435643554, 0.435643554, 0.435643554, 0.702970326, & - 0.653465331, 0.485148519, 0.386138618, 0.386138618, & - 0.336633652, 0.277227730, 0.237623766, 0.524752498, & - 0.732673287, 0.534653485, 0.415841579] - - print *, "Test uniform_distribution_cdf_iint8" - seed = 369147258 - call random_seed(seed, get) - loc = 14_int8; scale = 100_int8 - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_iint8 failed", warn=warn) - end subroutine test_uni_cdf_iint8 - - subroutine test_uni_cdf_iint16 - integer(int16) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [0.178217828, 0.178217828, 0.178217828, 0.465346545, & - 0.673267305, 0.247524753, 0.158415839, 0.792079210, & - 0.742574275, 0.574257433, 0.881188095, 0.663366318, & - 0.524752498, 0.623762369, 0.178217828] - - print *, "Test uniform_distribution_cdf_iint16" - seed = 369147258 - call random_seed(seed, get) - loc = 14_int16; scale = 100_int16 - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_iint16 failed", warn=warn) - end subroutine test_uni_cdf_iint16 - - subroutine test_uni_cdf_iint32 - integer(int32) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [0.732673287, 0.732673287, 0.732673287, 0.722772300, & - 0.792079210, 5.94059415E-02, 0.841584146,0.405940592,& - 0.960396051, 0.534653485, 0.782178223, 0.861386120, & - 0.564356446, 0.613861382, 0.306930691] - - print *, "Test uniform_distribution_cdf_iint32" - seed = 369147258 - call random_seed(seed, get) - loc = 14_int32; scale = 100_int32 - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_iint32 failed", warn=warn) - end subroutine test_uni_cdf_iint32 - - subroutine test_uni_cdf_iint64 - integer(int64) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [0.455445558, 0.455445558, 0.455445558, 0.277227730, & - 0.455445558, 0.930693090, 0.851485133, 0.623762369, & - 5.94059415E-02,0.693069279, 0.544554472, 0.207920790,& - 0.306930691, 0.356435657, 0.128712878] - - print *, "Test uniform_distribution_cdf_iint64" - seed = 369147258 - call random_seed(seed, get) - loc = 14_int64; scale = 100_int64 - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_iint64 failed", warn=warn) - end subroutine test_uni_cdf_iint64 - - subroutine test_uni_cdf_rsp - real(sp) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [0.170192942, 0.170192942, 0.170192942, 0.276106149, & - 0.754930079, 0.406620681, 0.187742814, 0.651605546, & - 0.934733927, 0.151271492, 0.987674534, 0.130533904, & - 0.106271908, 9.27578658E-02, 0.203399420] - - print *, "Test uniform_distribution_cdf_rsp" - seed = 369147258 - call random_seed(seed, get) - loc = 0.0_sp; scale = 2.0_sp - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_rsp failed", warn=warn) - end subroutine test_uni_cdf_rsp - - subroutine test_uni_cdf_rdp - real(dp) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [0.170192942, 0.170192942, 0.170192942, 0.276106149, & - 0.754930079, 0.406620681, 0.187742814, 0.651605546, & - 0.934733927, 0.151271492, 0.987674534, 0.130533904, & - 0.106271908, 9.27578658E-02, 0.203399420] - - print *, "Test uniform_distribution_cdf_rdp" - seed = 369147258 - call random_seed(seed, get) - loc = 0.0_dp; scale = 2.0_dp - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_rdp failed", warn=warn) - end subroutine test_uni_cdf_rdp - - subroutine test_uni_cdf_rqp - real(qp) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [0.170192942, 0.170192942, 0.170192942, 0.276106149, & - 0.754930079, 0.406620681, 0.187742814, 0.651605546, & - 0.934733927, 0.151271492, 0.987674534, 0.130533904, & - 0.106271908, 9.27578658E-02, 0.203399420] - - print *, "Test uniform_distribution_cdf_rqp" - seed = 369147258 - call random_seed(seed, get) - loc = 0.0_qp; scale = 2.0_qp - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_rqp failed", warn=warn) - end subroutine test_uni_cdf_rqp - - subroutine test_uni_cdf_csp - complex(sp) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [4.69913185E-02, 4.69913185E-02, 4.69913185E-02, & - 0.306970179, 0.122334257, 0.141398594, 0.128925011, & - 9.85755492E-03, 8.16527531E-02, 0.163921610, & - 7.81712309E-02, 0.446415812, 5.31753292E-04, & - 0.101455867, 0.155276477] - - print *, "Test uniform_distribution_cdf_csp" - seed = 369147258 - call random_seed(seed, get) - loc = (-0.5_sp, -0.5_sp); scale = (1.0_sp, 1.0_sp) - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_csp failed", warn=warn) - end subroutine test_uni_cdf_csp - - subroutine test_uni_cdf_cdp - complex(dp) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [4.69913185E-02, 4.69913185E-02, 4.69913185E-02, & - 0.306970179, 0.122334257, 0.141398594, 0.128925011, & - 9.85755492E-03, 8.16527531E-02, 0.163921610, & - 7.81712309E-02, 0.446415812, 5.31753292E-04, & - 0.101455867, 0.155276477] - - print *, "Test uniform_distribution_cdf_cdp" - seed = 369147258 - call random_seed(seed, get) - loc = (-0.5_dp, -0.5_dp); scale = (1.0_dp, 1.0_dp) - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_cdp failed", warn=warn) - end subroutine test_uni_cdf_cdp - - subroutine test_uni_cdf_cqp - complex(qp) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [4.69913185E-02, 4.69913185E-02, 4.69913185E-02, & - 0.306970179, 0.122334257, 0.141398594, 0.128925011, & - 9.85755492E-03, 8.16527531E-02, 0.163921610, & - 7.81712309E-02, 0.446415812, 5.31753292E-04, & - 0.101455867, 0.155276477] - - print *, "Test uniform_distribution_cdf_cqp" - seed = 369147258 - call random_seed(seed, get) - loc = (-0.5_qp, -0.5_qp); scale = (1.0_qp, 1.0_qp) - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_cqp failed", warn=warn) - end subroutine test_uni_cdf_cqp - - -end program test_distribution_uniform \ No newline at end of file From 460fdd5505b1f0c6c8b8fdac9c74fab4ee1e28a8 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 31 Dec 2020 15:05:31 -0500 Subject: [PATCH 044/172] Update index.md --- doc/specs/index.md | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/specs/index.md b/doc/specs/index.md index 3a7fb02ae..5912ea38a 100644 --- a/doc/specs/index.md +++ b/doc/specs/index.md @@ -19,7 +19,6 @@ This is and index/directory of the specifications (specs) for each new module/fe - [optval](./stdlib_optval.html) - Fallback value for optional arguments - [quadrature](./stdlib_quadrature.html) - Numerical integration - [stats](./stdlib_stats.html) - Descriptive Statistics - - [stats_distribution_PRNG](./stdlib_stats_distribution_PRNG.html) - Probability Distributions random number generator - [stats_distribution_uniform](./stdlib_stats_distribution_uniform.html) - Uniform probability distribution ## Missing specs From e678818822cf39f34ca1db60c0370cb6afce807b Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 31 Dec 2020 19:05:25 -0500 Subject: [PATCH 045/172] Update Makefile.manual --- src/Makefile.manual | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.manual b/src/Makefile.manual index 935126563..42e55df9c 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -72,7 +72,7 @@ stdlib_stats_var.o: \ stdlib_optval.o \ stdlib_kinds.o \ stdlib_stats.o -stdlib_stats_distribution_PRNG.o: stdlib_kinds.o stdlib_error.o +stdlib_stats_distribution_PRNG.o: stdlib_kinds.o stdlib_stats_distribution.uniform.o: \ stdlib_kinds.o \ stdlib_error.o \ From d25097f3bc665cffb733e24958c7f0bfe1a9e866 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sat, 2 Jan 2021 23:43:23 -0500 Subject: [PATCH 046/172] Update doc/specs/stdlib_stats_distribution_uniform.md Co-authored-by: Jeremie Vandenplas --- doc/specs/stdlib_stats_distribution_uniform.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index 8ae020a39..a785e2dfc 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -67,7 +67,7 @@ Experimental Without augument the function returns a scalar standard uniformly distributed variate U(0,1) of real type with single precision on [0,1]. -With single augument `scale` of integer type the function returns a scalar uniformly distributed variate of integer type on [0,scale]. This is the standard Rectangular distribtuion. Function is elemental. +With single augument `scale` of integer type the function returns a scalar uniformly distributed variate of integer type on [0,scale]. This is the standard Rectangular distribution. The function is elemental. With single augument `scale` of real or complex type the function returns a scalar uniformly distributed variate of real or complex type on [0, scale]. The real part and imaginary part of a complex type are independent of each other. Function is elemental. From 800d94e31622ba44b2ca5750e917cda27756dddc Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Mon, 18 Jan 2021 12:51:03 -0500 Subject: [PATCH 047/172] add proedure name in error message --- src/stdlib_stats_distribution_uniform.fypp | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index 572caaf37..f4056aa67 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -90,8 +90,8 @@ Module stdlib_stats_distribution_uniform integer :: zeros, bits_left, bits n = scale - if(n <= 0_${k1}$) call error_stop("Error: Uniform distribution scale" & - //" parameter must be positive") + if(n <= 0_${k1}$) call error_stop("Error(unif_dist_rvs_1): Uniform" & + //" distribution scale parameter must be positive") zeros = leadz(n) bits = bit_size(n) - zeros mask = shiftr(not(0_${k1}$), zeros) @@ -121,8 +121,8 @@ Module stdlib_stats_distribution_uniform ${t1}$, intent(in) :: loc, scale ${t1}$ :: res - if(scale == 0_${k1}$) call error_stop("Error: Uniform distribution" & - //" scale parameter must be non-zero") + if(scale <= 0_${k1}$) call error_stop("Error(unif_dist_rvs): Uniform" & + //" distribution scale parameter must be positive") res = loc + unif_dist_rvs_1_${t1[0]}$${k1}$(scale) return end function unif_dist_rvs_${t1[0]}$${k1}$ @@ -153,8 +153,8 @@ Module stdlib_stats_distribution_uniform ${t1}$, intent(in) :: scale ${t1}$ :: res - if(scale == 0._${k1}$) call error_stop("Error: Uniform distribution" & - //" scale parameter must be non-zero") + if(scale == 0._${k1}$) call error_stop("Error(unif_dist_rvs_1): " & + //"Uniform distribution scale parameter must be non-zero") res = scale * unif_dist_rvs_0_${t1[0]}$${k1}$( ) return end function unif_dist_rvs_1_${t1[0]}$${k1}$ @@ -169,8 +169,8 @@ Module stdlib_stats_distribution_uniform ${t1}$, intent(in) :: loc, scale ${t1}$ :: res - if(scale == 0._${k1}$) call error_stop("Error: Uniform distribution" & - //" scale parameter must be non-zero") + if(scale == 0._${k1}$) call error_stop("Error(unif_dist_rvs): " & + //"Uniform distribution scale parameter must be non-zero") res = loc + scale * unif_dist_rvs_0_${t1[0]}$${k1}$( ) return end function unif_dist_rvs_${t1[0]}$${k1}$ @@ -187,8 +187,8 @@ Module stdlib_stats_distribution_uniform ${t1}$ :: res real(${k1}$) :: r1, r2, tr, ti - if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error: Uniform" & - //" distribution scale parameter must be non-zero") + if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(uni_dist_" & + //"rvs_1): Uniform distribution scale parameter must be non-zero") r1 = unif_dist_rvs_0_r${k1}$( ) if(real(scale) == 0.0_${k1}$) then ti = aimag(scale) * r1 @@ -219,8 +219,8 @@ Module stdlib_stats_distribution_uniform ${t1}$ :: res real(${k1}$) :: r1, r2, tr, ti - if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error: Uniform" & - //" distribution scale parameter must be non-zero") + if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(uni_dist_" & + //"rvs): Uniform distribution scale parameter must be non-zero") r1 = unif_dist_rvs_0_r${k1}$( ) if(real(scale) == 0.0_${k1}$) then tr = real(loc) @@ -249,8 +249,8 @@ Module stdlib_stats_distribution_uniform integer :: i, zeros, bits_left, bits n = scale - if(n == 0_${k1}$) call error_stop("Error: Uniform distribution" & - //" scale parameter must be non-zero") + if(n == 0_${k1}$) call error_stop("Error(unif_dist_rvs_array): Uniform" & + //" distribution scale parameter must be non-zero") allocate(res(array_size)) zeros = leadz(n) bits = bit_size(n) - zeros @@ -287,8 +287,8 @@ Module stdlib_stats_distribution_uniform integer :: i - if(scale == 0._${k1}$) call error_stop("Error: Uniform distribution" & - //" scale parameter must be non-zero") + if(scale == 0._${k1}$) call error_stop("Error(unif_dist_rvs_array):" & + //" Uniform distribution scale parameter must be non-zero") allocate(res(array_size)) do i = 1, array_size tmp = shiftr(dist_rand(INT_ONE), 11) @@ -311,8 +311,8 @@ Module stdlib_stats_distribution_uniform integer :: i - if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error: Uniform" & - //" distribution scale parameter must be non-zero") + if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(unif_dist_"& + //"rvs_array): Uniform distribution scale parameter must be non-zero") allocate(res(array_size)) do i = 1, array_size tmp = shiftr(dist_rand(INT_ONE), 11) From c6c5fa7347906e92d107a9df98b9fbb6fa0bbb4f Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Mon, 18 Jan 2021 12:52:55 -0500 Subject: [PATCH 048/172] final version --- src/stdlib_stats_distribution_PRNG.fypp | 84 ++++--------------------- 1 file changed, 12 insertions(+), 72 deletions(-) diff --git a/src/stdlib_stats_distribution_PRNG.fypp b/src/stdlib_stats_distribution_PRNG.fypp index 90d9f367e..3fdbf0438 100644 --- a/src/stdlib_stats_distribution_PRNG.fypp +++ b/src/stdlib_stats_distribution_PRNG.fypp @@ -1,16 +1,16 @@ #:include "common.fypp" module stdlib_stats_distribution_PRNG - use stdlib_kinds + use stdlib_kinds, only: int8, int16, int32, int64 + use stdlib_error implicit none private - integer, parameter :: MAX_INT_BIT_SIZE = 64 - integer(int64), save :: st(4), si = 614872703977525537_int64 + integer, parameter :: MAX_INT_BIT_SIZE = bit_size(1_int64) + integer(int64), save :: st(4) ! internal states for xoshiro256ss function + integer(int64), save :: si = 614872703977525537_int64 ! default seed value logical, save :: seed_initialized = .false. public :: random_seed public :: dist_rand - public :: jump - public :: long_jump interface dist_rand @@ -43,13 +43,16 @@ module stdlib_stats_distribution_PRNG function dist_rand_${t1[0]}$${k1}$(n) result(res) !! Random integer generation for various kinds !! result = [-2^k, 2^k - 1], k = 7, 15, 31, 63, depending on input kind - !! Result is used as bit model number instead of regular arithmetic number + !! Result will be operated by bitwise operators to generate desired integer + !! and real pseudorandom numbers !! ${t1}$, intent(in) :: n ${t1}$ :: res integer :: k k = MAX_INT_BIT_SIZE - bit_size(n) + if(k < 0) call error_stop("Error(dist_rand): Integer bit size is" & + //" greater than 64bit") res = shiftr(xoshiro256ss( ), k) end function dist_rand_${t1[0]}$${k1}$ @@ -58,6 +61,7 @@ module stdlib_stats_distribution_PRNG function xoshiro256ss( ) result (res) ! Generate random 64-bit integers ! Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org) + ! http://prng.di.unimi.it/xoshiro256starstar.c ! ! This is xoshiro256** 1.0, one of our all-purpose, rock-solid ! generators. It has excellent (sub-ns) speed, a state (256 bits) that is @@ -81,7 +85,6 @@ module stdlib_stats_distribution_PRNG st(1) = ieor(st(1), st(4)) st(3) = ieor(st(3), t) st(4) = rol64(st(4), 45) - return end function xoshiro256ss function rol64(x, k) result(res) @@ -92,73 +95,9 @@ module stdlib_stats_distribution_PRNG t1 = shiftr(x, (64 - k)) t2 = shiftl(x, k) res = ior(t1, t2) - return end function rol64 - subroutine jump - ! This is the jump function for the xoshiro256ss generator. It is equivalent - ! to 2^128 calls to xoshiro256ss(); it can be used to generate 2^128 - ! non-overlapping subsequences for parallel computations. - ! Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org) - ! - ! Fortran 90 version translated from C by Jim-215-Fisher - integer(int64) :: jp(4) = [1733541517147835066_int64, & - -3051731464161248980_int64, & - -6244198995065845334_int64, & - 4155657270789760540_int64] - integer(int64) :: s1 = 0, s2 = 0, s3 = 0, s4 = 0, c = 1_int64 - integer :: i, j, k - - do i = 1, 4 - do j = 1, 64 - if(iand(jp(i), shiftl(c, j - 1)) /= 0) then - s1 = ieor(s1, st(1)) - s2 = ieor(s2, st(2)) - s3 = ieor(s3, st(3)) - s4 = ieor(s4, st(4)) - end if - k = xoshiro256ss( ) - end do - end do - st(1) = s1 - st(2) = s2 - st(3) = s3 - st(4) = s4 - end subroutine jump - - subroutine long_jump - ! This is the long-jump function for the xoshiro256ss generator. It is - ! equivalent to 2^192 calls to xoshiro256ss(); it can be used to generate - ! 2^64 starting points, from each of which jump() will generate 2^64 - ! non-overlapping subsequences for parallel distributed computations - ! Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org) - ! - ! Fortran 90 version translated from C by Jim-215-Fisher - integer(int64) :: jp(4) = [8566230491382795199_int64, & - -4251311993797857357_int64, & - 8606660816089834049_int64, & - 4111957640723818037_int64] - integer(int64) :: s1 = 0, s2 = 0, s3 = 0, s4 = 0, c = 1_int64 - integer(int32) :: i, j, k - - do i = 1, 4 - do j = 1, 64 - if(iand(jp(i), shiftl(c, j - 1)) /= 0) then - s1 = ieor(s1, st(1)) - s2 = ieor(s2, st(2)) - s3 = ieor(s3, st(3)) - s4 = ieor(s4, st(4)) - end if - k = xoshiro256ss() - end do - end do - st(1) = s1 - st(2) = s2 - st(3) = s3 - st(4) = s4 - end subroutine long_jump - function splitmix64(s) result(res) ! Written in 2015 by Sebastiano Vigna (vigna@acm.org) ! This is a fixed-increment version of Java 8's SplittableRandom @@ -176,6 +115,8 @@ module stdlib_stats_distribution_PRNG data int01, int02, int03/-7046029254386353131_int64, & -4658895280553007687_int64, & -7723592293110705685_int64/ + ! Values are converted from C unsigned integer of 0x9e3779b97f4a7c15, + ! 0xbf58476d1ce4e5b9, 0x94d049bb133111eb if(present(s)) si = s res = si @@ -183,7 +124,6 @@ module stdlib_stats_distribution_PRNG res = ieor(res, shiftr(res, 30)) * int02 res = ieor(res, shiftr(res, 27)) * int03 res = ieor(res, shiftr(res, 31)) - return end function splitmix64 #:for k1, t1 in INT_KINDS_TYPES From c379711a43e70cf044f5e21285badd7435601211 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 21 Jan 2021 11:31:33 -0500 Subject: [PATCH 049/172] Delete Makefile.manual --- src/Makefile.manual | 97 --------------------------------------------- 1 file changed, 97 deletions(-) delete mode 100644 src/Makefile.manual diff --git a/src/Makefile.manual b/src/Makefile.manual deleted file mode 100644 index 42e55df9c..000000000 --- a/src/Makefile.manual +++ /dev/null @@ -1,97 +0,0 @@ -SRC = f18estop.f90 \ - stdlib_ascii.f90 \ - stdlib_bitsets.f90 \ - stdlib_bitsets_64.f90 \ - stdlib_bitsets_large.f90 \ - stdlib_error.f90 \ - stdlib_io.f90 \ - stdlib_kinds.f90 \ - stdlib_linalg.f90 \ - stdlib_linalg_diag.f90 \ - stdlib_logger.f90 \ - stdlib_optval.f90 \ - stdlib_quadrature.f90 \ - stdlib_quadrature_trapz.f90 \ - stdlib_stats.f90 \ - stdlib_stats_mean.f90 \ - stdlib_stats_moment.f90 \ - stdlib_stats_moment_all.f90 \ - stdlib_stats_moment_mask.f90 \ - stdlib_stats_moment_scalar.f90 \ - stdlib_stats_var.f90 \ - stdlib_stats_distribution_PRNG.f90 \ - stdlib_stats_distribution_uniform.f90 - -LIB = libstdlib.a - - - -OBJS = $(SRC:.f90=.o) -MODS = $(OBJS:.o=.mod) -SMODS = $(OBJS:.o=*.smod) - -.PHONY: all clean - -all: $(LIB) - -$(LIB): $(OBJS) - ar rcs $@ $(OBJS) - -clean: - $(RM) $(LIB) $(OBJS) $(MODS) $(SMODS) - -%.o: %.f90 - $(FC) $(FFLAGS) -c $< - -%.f90: %.fypp - fypp $(FYPPFLAGS) $< $@ - -# Fortran module dependencies -f18estop.o: stdlib_error.o -stdlib_bitsets.o: stdlib_kinds.o -stdlib_bitsets_64.o: stdlib_bitsets.o -stdlib_bitsets_large.o: stdlib_bitsets.o -stdlib_error.o: stdlib_optval.o -stdlib_io.o: \ - stdlib_error.o \ - stdlib_optval.o \ - stdlib_kinds.o -stdlib_linalg_diag.o: stdlib_kinds.o -stdlib_logger.o: stdlib_ascii.o stdlib_optval.o -stdlib_optval.o: stdlib_kinds.o -stdlib_quadrature.o: stdlib_kinds.o -stdlib_stats_mean.o: \ - stdlib_optval.o \ - stdlib_kinds.o \ - stdlib_stats.o -stdlib_stats_moment.o: \ - stdlib_optval.o \ - stdlib_kinds.o \ - stdlib_stats.o -stdlib_stats_var.o: \ - stdlib_optval.o \ - stdlib_kinds.o \ - stdlib_stats.o -stdlib_stats_distribution_PRNG.o: stdlib_kinds.o -stdlib_stats_distribution.uniform.o: \ - stdlib_kinds.o \ - stdlib_error.o \ - stdlib_stats_distribution.o - -# Fortran sources that are built from fypp templates -stdlib_bitsets_64.f90: stdlib_bitsets_64.fypp -stdlib_bitsets_large.f90: stdlib_bitsets_large.fypp -stdlib_bitsets.f90: stdlib_bitsets.fypp -stdlib_io.f90: stdlib_io.fypp -stdlib_linalg.f90: stdlib_linalg.fypp -stdlib_linalg_diag.f90: stdlib_linalg_diag.fypp -stdlib_quadrature.f90: stdlib_quadrature.fypp -stdlib_stats.f90: stdlib_stats.fypp -stdlib_stats_mean.f90: stdlib_stats_mean.fypp -stdlib_stats_moment.f90: stdlib_stats_moment.fypp -stdlib_stats_moment_all.f90: stdlib_stats_moment_all.fypp -stdlib_stats_moment_mask.f90: stdlib_stats_moment_mask.fypp -stdlib_stats_moment_scalar.f90: stdlib_stats_moment_scalar.fypp -stdlib_stats_var.f90: stdlib_stats_var.fypp -stdlib_stats_distribution_PRNG.f90: stdlib_stats_distribution_PRNG.fypp -stdlib_stats_distribution_uniform.f90: stdlib_stats_distribution_uniform.fypp From a5735ea0f258ee3672a822753721de308959ff56 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 21 Jan 2021 11:38:52 -0500 Subject: [PATCH 050/172] Update CMakeLists.txt --- src/CMakeLists.txt | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8929f3a76..256bb6e71 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,8 +21,6 @@ set(fppFiles stdlib_quadrature.fypp stdlib_quadrature_trapz.fypp stdlib_quadrature_simps.fypp - stdlib_stats_distribution_PRNG.fypp - stdlib_stats_distribution_uniform.fypp ) @@ -47,27 +45,28 @@ set(SRC ${outFiles} ) -add_library(fortran_stdlib ${SRC}) +add_library(${PROJECT_NAME} ${SRC}) set(LIB_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/mod_files/) -set_target_properties(fortran_stdlib PROPERTIES +set_target_properties(${PROJECT_NAME} PROPERTIES Fortran_MODULE_DIRECTORY ${LIB_MOD_DIR}) -target_include_directories(fortran_stdlib PUBLIC +target_include_directories(${PROJECT_NAME} PUBLIC $ $ ) if(f18errorstop) - target_sources(fortran_stdlib PRIVATE f18estop.f90) + target_sources(${PROJECT_NAME} PRIVATE f18estop.f90) else() - target_sources(fortran_stdlib PRIVATE f08estop.f90) + target_sources(${PROJECT_NAME} PRIVATE f08estop.f90) endif() add_subdirectory(tests) -install(TARGETS fortran_stdlib - RUNTIME DESTINATION bin - ARCHIVE DESTINATION lib - LIBRARY DESTINATION lib - ) -install(DIRECTORY ${LIB_MOD_DIR} DESTINATION include) +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}-targets + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) +install(DIRECTORY ${LIB_MOD_DIR} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") From bd66d4211b3e738d19f973493f0c12d79977ddc9 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 21 Jan 2021 11:39:27 -0500 Subject: [PATCH 051/172] Add files via upload --- src/Makefile.manual | 105 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 src/Makefile.manual diff --git a/src/Makefile.manual b/src/Makefile.manual new file mode 100644 index 000000000..ad0ed9d03 --- /dev/null +++ b/src/Makefile.manual @@ -0,0 +1,105 @@ +SRCFYPP =\ + stdlib_bitsets_64.fypp \ + stdlib_bitsets_large.fypp \ + stdlib_bitsets.fypp \ + stdlib_io.fypp \ + stdlib_linalg.fypp \ + stdlib_linalg_diag.fypp \ + stdlib_optval.fypp \ + stdlib_quadrature.fypp \ + stdlib_quadrature_trapz.fypp \ + stdlib_quadrature_simps.fypp \ + stdlib_stats.fypp \ + stdlib_stats_corr.fypp \ + stdlib_stats_cov.fypp \ + stdlib_stats_mean.fypp \ + stdlib_stats_moment.fypp \ + stdlib_stats_moment_all.fypp \ + stdlib_stats_moment_mask.fypp \ + stdlib_stats_moment_scalar.fypp \ + stdlib_stats_var.fypp + +SRC = f18estop.f90 \ + stdlib_ascii.f90 \ + stdlib_error.f90 \ + stdlib_kinds.f90 \ + stdlib_logger.f90 \ + $(SRCGEN) + +LIB = libstdlib.a + + +SRCGEN = $(SRCFYPP:.fypp=.f90) +OBJS = $(SRC:.f90=.o) +MODS = $(OBJS:.o=.mod) +SMODS = $(OBJS:.o=*.smod) + +.PHONY: all clean + +all: $(LIB) + +$(LIB): $(OBJS) + ar rcs $@ $(OBJS) + +clean: + $(RM) $(LIB) $(OBJS) $(MODS) $(SMODS) $(SRCGEN) + +%.o: %.f90 + $(FC) $(FFLAGS) -c $< + +$(SRCGEN): %.f90: %.fypp common.fypp + fypp $(FYPPFLAGS) $< $@ + +# Fortran module dependencies +f18estop.o: stdlib_error.o +stdlib_bitsets.o: stdlib_kinds.o +stdlib_bitsets_64.o: stdlib_bitsets.o +stdlib_bitsets_large.o: stdlib_bitsets.o +stdlib_error.o: stdlib_optval.o +stdlib_io.o: \ + stdlib_error.o \ + stdlib_optval.o \ + stdlib_kinds.o +stdlib_linalg.o: \ + stdlib_kinds.o +stdlib_linalg_diag.o: \ + stdlib_linalg.o \ + stdlib_kinds.o +stdlib_logger.o: stdlib_ascii.o stdlib_optval.o +stdlib_optval.o: stdlib_kinds.o +stdlib_quadrature.o: stdlib_kinds.o +stdlib_quadrature_simps.o: \ + stdlib_quadrature.o \ + stdlib_error.o \ + stdlib_kinds.o +stdlib_quadrature_trapz.o: \ + stdlib_quadrature.o \ + stdlib_error.o \ + stdlib_kinds.o +stdlib_stats.o: \ + stdlib_kinds.o +stdlib_stats_corr.o: \ + stdlib_optval.o \ + stdlib_kinds.o \ + stdlib_stats.o +stdlib_stats_cov.o: \ + stdlib_optval.o \ + stdlib_kinds.o \ + stdlib_stats.o +stdlib_stats_mean.o: \ + stdlib_optval.o \ + stdlib_kinds.o \ + stdlib_stats.o +stdlib_stats_moment.o: \ + stdlib_optval.o \ + stdlib_kinds.o \ + stdlib_stats.o +stdlib_stats_moment_all.o: \ + stdlib_stats_moment.o +stdlib_stats_moment_mask.o: \ + stdlib_stats_moment.o +stdlib_stats_moment_scalar.o: \ + stdlib_stats_moment.o +stdlib_stats_var.o: \ + stdlib_optval.o \ + stdlib_kinds.o \ \ No newline at end of file From 3e89cdc6a7a24d1fa25a46ce27b5932f32b5561a Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 21 Jan 2021 11:47:43 -0500 Subject: [PATCH 052/172] Update Makefile.manual From a1543f204f946b944edefde82f373f7e1bc2c860 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 21 Jan 2021 11:49:04 -0500 Subject: [PATCH 053/172] Update Makefile.manual --- src/Makefile.manual | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Makefile.manual b/src/Makefile.manual index ad0ed9d03..9351a374a 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -102,4 +102,5 @@ stdlib_stats_moment_scalar.o: \ stdlib_stats_moment.o stdlib_stats_var.o: \ stdlib_optval.o \ - stdlib_kinds.o \ \ No newline at end of file + stdlib_kinds.o \ + stdlib_stats.o From 6abd81cedd44782b1134ad2ff0cd0120d4f68b69 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 21 Jan 2021 11:51:11 -0500 Subject: [PATCH 054/172] Update CMakeLists.txt --- src/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 256bb6e71..f8aa14128 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,7 +21,8 @@ set(fppFiles stdlib_quadrature.fypp stdlib_quadrature_trapz.fypp stdlib_quadrature_simps.fypp - + stdlib_stats_distribution_PRNG.fypp + stdlib_stats_distribution_uniform.fypp ) From af74dac08eace6144dccc7a84c9641d850435ec5 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 21 Jan 2021 11:54:59 -0500 Subject: [PATCH 055/172] Update Makefile.manual --- src/Makefile.manual | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Makefile.manual b/src/Makefile.manual index 9351a374a..c4035cce6 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -17,7 +17,9 @@ SRCFYPP =\ stdlib_stats_moment_all.fypp \ stdlib_stats_moment_mask.fypp \ stdlib_stats_moment_scalar.fypp \ - stdlib_stats_var.fypp + stdlib_stats_var.fypp \ + stdlib_stats_distribution_PRNG.fypp \ + stdlib_stats_distribution_uniform.fypp SRC = f18estop.f90 \ stdlib_ascii.f90 \ @@ -104,3 +106,10 @@ stdlib_stats_var.o: \ stdlib_optval.o \ stdlib_kinds.o \ stdlib_stats.o +stdlib_stats_distribution_PRNG.o: \ + stdlib_kinds.o \ + stdlib_error.o +stdlib_stats_distribution_uniform.o: \ + stdlib_kinds.o \ + stdlib_error.o \ + stdlib_stats_distribution_PRNG.o From fbd5f52c52b77debaf526be5f25794a17cca50c2 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 21 Jan 2021 11:57:23 -0500 Subject: [PATCH 056/172] Add files via upload From d9709df6b0173c0779f301e246928a9d0cc425ff Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 21 Jan 2021 11:58:50 -0500 Subject: [PATCH 057/172] Add files via upload --- .../stdlib_stats_distribution_uniform.md | 164 ++++++++++-------- 1 file changed, 88 insertions(+), 76 deletions(-) diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index a785e2dfc..145a1822f 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -2,7 +2,7 @@ title: stats_distribution --- -# Statistical Distributions -- Uniform Distribution Module +# Statistical Distributions Uniform Module [TOC] @@ -22,7 +22,7 @@ Applying Fisher-Yates algorithm to generate an unbiased permutation for any list ### Arguments -`list`: argument has `intent(in)` and is a rank one array of integer, real, or complex type. +`list`: argument has `intent(in)` and is a rank one array of `integer`, `real`, or `complex` type. ### Return value @@ -47,13 +47,19 @@ program demo_shuffle end do seed_put = 32165498 call random_seed(seed_put, seed_get) ! set and get current value of seed - n = shuffle(n) ! get randomized n -![10, 6, 9, 2, 8, 1, 3, 5, 7, 4] - x = shuffle(x) ! get randomized x -! [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, 7.0, 6.0] - z = shuffle(z) ! get randomized z -![(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), (1.0, 1.0), (5.0, 5.0), (9.0, 9.0), -!(6.0, 6.0), (3.0, 3.0), (2.0, 2.0), (10.0, 10.0)] + print *, shuffle(n) ! get randomized n + +!10 6 9 2 8 1 3 5 7 4 + + print *, shuffle(x) ! get randomized x + +!5.0 10.0 9.0 4.0 3.0 8.0 2.0 1.0 7.0 6.0 + + print *, shuffle(z) ! get randomized z + +!(8.0, 8.0) (7.0, 7.0) (4.0, 4.0) (1.0, 1.0) (5.0, 5.0) +!(9.0, 9.0) (6.0, 6.0) (3.0, 3.0) (2.0, 2.0) (10.0, 10.0) + end program demo_shuffle ``` @@ -65,17 +71,15 @@ Experimental ### Description -Without augument the function returns a scalar standard uniformly distributed variate U(0,1) of real type with single precision on [0,1]. - -With single augument `scale` of integer type the function returns a scalar uniformly distributed variate of integer type on [0,scale]. This is the standard Rectangular distribution. The function is elemental. +Without augument the function returns a scalar standard uniformly distributed variate U(0,1) of `real` type with single precision on [0,1]. -With single augument `scale` of real or complex type the function returns a scalar uniformly distributed variate of real or complex type on [0, scale]. The real part and imaginary part of a complex type are independent of each other. Function is elemental. +With single augument `scale` of `integer` type the function returns a scalar uniformly distributed variate of `integer` type on [0,scale]. This is the standard Rectangular distribtuion. Function is elemental. -With double auguments `loc` and `scale` the function returns a scalar uniformly distributed random variates of integer, real or complx type on [loc, loc + scale] dependent of input type. If it is complex augument, the real part and imaginary part are independent of each other. Function is elemental. +With single augument `scale` of `real` or `complex` type the function returns a scalar uniformly distributed variate of `real` or `complex` type on [0, scale]. The real part and imaginary part of a `complex` type are independent of each other. Function is elemental. -With triple auguments `loc`, `scale` and `array_size` the function returns a rank one array of uniformly distributed variates of integer, real or complx type with an array size of `array_size`. +With double auguments `loc` and `scale` the function returns a scalar uniformly distributed random variates of `integer`, `real` or `complex` type on [loc, loc + scale] dependent of input type. If it is `complex` augument, the real part and imaginary part are independent of each other. Function is elemental. -`scale` must be greater than 0. +With triple auguments `loc`, `scale` and `array_size` the function returns a rank one array of uniformly distributed variates of `integer`, `real` or `complex` type with an array size of `array_size`. ### Syntax @@ -83,9 +87,9 @@ With triple auguments `loc`, `scale` and `array_size` the function returns a ran ### Arguments -`loc`: optional argument has `intent(in)` and is a scalar of type `integer`, `real` or `complx`. +`loc`: optional argument has `intent(in)` and is a scalar of type `integer`, `real` or `complex`. -`scale`: optional argument has `intent(in)` and is a scalar of type `integer`, `real` or `complx`. +`scale`: optional argument has `intent(in)` and is a scalar of type `integer`, `real` or `complex`. `array_size`: optional argument has `intent(in)` and is a scalar of type `integer`. @@ -93,7 +97,7 @@ With triple auguments `loc`, `scale` and `array_size` the function returns a ran ### Return value -The result is a scalar or a rank one array, with size of `array_size`, of type `integer`, `real` or `complx` depending on the input type. +The result is a scalar or a rank one array, with size of `array_size`, of type `integer`, `real` or `complex` depending on the input type. ### Example @@ -103,7 +107,7 @@ program demo_uniform_rvs use stdlib_stats_distribution_uniform, only:uni=> uniform_distribution_rvs implicit none - complx :: loc, scale + complex :: loc, scale real :: a(3,4,5), b(3,4,5) integer :: seed_put, seed_get @@ -119,8 +123,10 @@ program demo_uniform_rvs print *, uni(-0.5, 1.0) !an uniform random variate in [-0.5, 0.5] ! 0.486900032 - print *, uni(-1.0,2.0,10) !an array of 10 uniform random variates in [-1., 1.] -![0.884182811, -0.771520197, 0.560377002, 0.709313750, -7.12267756E-02, -0.431066573, 0.497536063, -0.396331906, -0.325983286, 0.137686729] + print *, uni(-1.0,2.0,10) + !an array of 10 uniform random variates in [-1., 1.] + +!0.884182811 -0.771520197 0.560377002 0.709313750 -7.12267756E-02 !-0.431066573 0.497536063 -0.396331906 -0.325983286 0.137686729 print *, uni(20) !a random integer variate in [0, 20] ! 17 @@ -129,26 +135,29 @@ program demo_uniform_rvs ! 15 print *, uni(3,19,10) !an array of 10 integer variates in [3,22] -! [7, 16, 16, 12, 9, 21, 19, 4, 3, 19] + +!7 16 16 12 9 21 19 4 3 19 loc = (-0.5, -0.5) scale = (1.0, 1.0) print *, uni(scale) !a complex uniform random variate in unit square -!(0.139202669,0.361759573) + +!(0.139202669, 0.361759573) print *, uni(loc,scale) !a complex uniform random variate in [(-0.5, -0.5), (0.5, 0.5)] + !(0.296536088,-0.143987954) print *, uni(loc, scale, 10) !an array of 10 complex uniform random variate in [(-0.5, -0.5), (0.5, 0.5)] -![(-0.302334785,-0.401923567), (0.281620383,9.534919262E-02), -! (-0.374348879,0.457528770), (0.442990601,-0.240510434), -! (-0.421572685,0.279313922), (-0.182090610,5.901372433E-02), -! (-7.864198089E-02,0.378484428), (-0.423258364,-0.201292425), -! (0.193327367,-0.353985727), (-0.397661150,0.355926156)] +!(-0.302334785,-0.401923567) (0.281620383,9.534919262E-02) +! (-0.374348879,0.457528770) (0.442990601,-0.240510434) +! (-0.421572685,0.279313922) (-0.182090610,5.901372433E-02) +! (-7.864198089E-02,0.378484428) (-0.423258364,-0.201292425) +! (0.193327367,-0.353985727) (-0.397661150,0.355926156) a(:,:,:) = -0.5 b(:,:,:) = 1.0 @@ -156,23 +165,24 @@ program demo_uniform_rvs print *, uni(a,b) !a rank 3 array of random variates in [-0.5,0.5] -! [-0.249188632, -0.199248433, -0.389813602, 2.88307667E-03, 0.238479793, -! 0.264856219, -0.205177426, -0.480921626, 0.131218433, 0.252170086, -! -0.303151041, -8.89462233E-02, -0.377370685, 0.341802299, 0.323204756, -! 0.358679056, -0.138909757, 0.384329498, -0.109372199, 0.132353067, -! 0.494320452, 0.419343710, -0.103044361, 0.461389005, 0.403132677, -! 0.121850729, 0.403839290, -0.349389791, 0.490482628, 0.156600773, -! 8.46788883E-02, -0.483680278, 0.388107836, 0.119698405, 0.154214382, -! 0.153113484, 0.236523747, 0.155937552, -0.135760903, 0.219589531, -! 0.394639254, 6.30156994E-02, -0.342692465, -0.444846451, -0.215700030, -! 0.204189956, -0.208748132, 0.355063021, 8.98272395E-02, -0.237928331, -! 2.98077464E-02, -0.485149682, -8.06870461E-02, -0.372713923, -! -0.178335011, 0.283877611, -2.13934183E-02, -9.21690464E-03, 4.56320047E-02, -! 0.220112979] +! -0.249188632 -0.199248433 -0.389813602 2.88307667E-03 0.238479793, +! 0.264856219 -0.205177426 -0.480921626 0.131218433 0.252170086, +! -0.303151041 -8.89462233E-02 -0.377370685 0.341802299 0.323204756, +! 0.358679056 -0.138909757 0.384329498 -0.109372199 0.132353067, +! 0.494320452 0.419343710 -0.103044361 0.461389005 0.403132677 +! 0.121850729 0.403839290 -0.349389791 0.490482628 0.156600773 +! 8.46788883E-02 -0.483680278 0.388107836 0.119698405 0.154214382 +! 0.153113484 0.236523747 0.155937552 -0.135760903 0.219589531 +! 0.394639254 6.30156994E-02 -0.342692465 -0.444846451 -0.215700030 +! 0.204189956 -0.208748132 0.355063021 8.98272395E-02 -0.237928331 +! 2.98077464E-02 -0.485149682 -8.06870461E-02 -0.372713923 +! -0.178335011 0.283877611 -2.13934183E-02 -9.21690464E-03 +! 4.56320047E-02 0.220112979 + end program demo_uniform_rvs ``` -## `uniform_distribution_pdf` - uniform probability density function +## `uniform_distribution_pdf` - Uniform probability density function ### Status @@ -184,7 +194,7 @@ The probability density function of the uniform distribution. f(x) = 1 / (scale + 1); for discrete uniform distribution f(x) = 1 / scale; for continuous uniform distribution -f(x) = 1 / (scale%re * scale%im); for complx uniform distribution +f(x) = 1 / (scale%re * scale%im); for complex uniform distribution ### Syntax @@ -192,11 +202,11 @@ f(x) = 1 / (scale%re * scale%im); for complx uniform distribution ### Arguments -`x`: has `intent(in)` and is a scalar of type `integer`, `real` or `complx`. +`x`: has `intent(in)` and is a scalar of type `integer`, `real` or `complex`. -`loc`: has `intent(in)` and is a scalar of type `integer`, `real` or `complx`. +`loc`: has `intent(in)` and is a scalar of type `integer`, `real` or `complex`. -`scale`: has `intent(in)` and is a scalar of type `integer`, `real` or `complx`. +`scale`: has `intent(in)` and is a scalar of type `integer`, `real` or `complex`. The function is elemental, i.e., all three auguments could be arrays conformable to each other. All three arguments must have the same type. @@ -214,7 +224,7 @@ program demo_uniform_pdf uni => uniform_distribution_rvs implicit none - complx :: loc, scale + complex :: loc, scale real :: a(3,4,5), b(3,4,5), x(3,4,5) integer :: seed_put, seed_get @@ -239,16 +249,16 @@ program demo_uniform_pdf x = reshape(uni(0.,2.,60),[3,4,5])! uniform random variates array in [0., 2.] print *, uni_pdf(x, a, b) ! probability density array in [0., 2.] -![0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, & -! 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, & -! 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, & -! 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, & -! 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, & -! 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, & -! 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, & -! 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, & -! 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, & -! 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000, 0.500000000] +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 & +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 & +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 & +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 & +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 & +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 & +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 & +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 & +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 & +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 loc = (-0.5,-0.5) scale = (1.0,1.0) @@ -260,7 +270,7 @@ end program demo_uniform_pdf ``` -## `uniform_distribution_cdf` - uniform cumulative distribution function +## `uniform_distribution_cdf` - Uniform cumulative distribution function ### Status @@ -272,7 +282,7 @@ Cumulative distribution function of the uniform distribution F(x) = (x - loc + 1) / (scale + 1); for discrete uniform distribution F(x) = (x - loc) / scale; for continuous uniform distribution -F(x) = (x%re - loc%re)(x%im - loc%im) / (scale%re * scale%im); for complx uniform distribution +F(x) = (x%re - loc%re)(x%im - loc%im) / (scale%re * scale%im); for complex uniform distribution ### Syntax @@ -280,11 +290,11 @@ F(x) = (x%re - loc%re)(x%im - loc%im) / (scale%re * scale%im); for complx unifor ### Arguments -`x`: has `intent(in)` and is a scalar of type `integer`, `real` or `complx`. +`x`: has `intent(in)` and is a scalar of type `integer`, `real` or `complex`. -`loc`: has `intent(in)` and is a scalar of type `integer`, `real` or `complx`. +`loc`: has `intent(in)` and is a scalar of type `integer`, `real` or `complex`. -`scale`: has `intent(in)` and is a scalar of type `integer`, `real` or `complx`. +`scale`: has `intent(in)` and is a scalar of type `integer`, `real` or `complex`. The function is elemental, i.e., all three auguments could be arrays conformable to each other. All three arguments must have the same type. @@ -296,12 +306,14 @@ The result is a scalar or an array, with a shape conformable to auguments, of ty ```fortran program demo_uniform_cdf - use stdlib_stats_distribution_uniform, only : uni_cdf => uniform_distribution_cdf, & - uni => uniform_distribution_rvs, & use stdlib_stats_distribution_PRNG, only : random_seed + use stdlib_stats_distribution_uniform, only : & + uni_cdf => uniform_distribution_cdf, & + uni => uniform_distribution_rvs, & + implicit none real :: x(3,4,5), a(3,4,5), b(3,4,5) - complx :: loc, scale + complex :: loc, scale integer :: seed_put, seed_get seed_put = 1234567 @@ -324,16 +336,16 @@ program demo_uniform_cdf x = reshape(uni(-1.0,2.0,60),[3,4,5]) ! uniform random variates array print *, uni_cdf(x,a,b) ! cumulative array in [-1.0, 1.0] -![0.161520004, 0.553248405, 0.986900032, 0.942091405, 0.114239901, 0.780188501, & -! 0.854656875, 0.464386612, 0.284466714, 0.748768032, 0.301834047, 0.337008357, & -!0.568843365, 0.596165061, 0.180993259, 0.614166319, 0.214835495,7.98164606E-02,& -!0.641274095, 0.607101977, 0.701139212, 0.230517209, 1.97925568E-02,0.857982159,& -!0.712761045, 0.139202654, 0.361759573, 0.796536088, 0.356012046, 0.197665215, & -!9.80764329E-02,0.781620383, 0.595349193, 0.125651121, 0.957528770, 0.942990601,& -!0.259489566, 7.84273148E-02, 0.779313922, 0.317909390, 0.559013724,0.421358019,& -!0.878484428, 7.67416358E-02, 0.298707575, 0.693327367, 0.146014273,0.102338850,& -!0.855926156, 0.250811368, 0.300751567, 0.110186398, 0.502883077, 0.738479793, & -!0.764856219, 0.294822574, 1.90783739E-02,0.631218433,0.752170086, 0.196848959] +!0.161520004 0.553248405 0.986900032 0.942091405 0.114239901 0.780188501 & +! 0.854656875 0.464386612 0.284466714 0.748768032 0.301834047 0.337008357 & +!0.568843365 0.596165061 0.180993259 0.614166319 0.214835495 7.98164606E-02 & +!0.641274095 0.607101977 0.701139212 0.230517209 1.97925568E-02 0.857982159 & +!0.712761045 0.139202654 0.361759573 0.796536088 0.356012046 0.197665215 & +!9.80764329E-02 0.781620383 0.595349193 0.125651121 0.957528770 0.942990601 & +!0.259489566 7.84273148E-02 0.779313922 0.317909390 0.559013724 0.421358019 & +!0.878484428 7.67416358E-02 0.298707575 0.693327367 0.146014273 0.102338850 & +!0.855926156 0.250811368 0.300751567 0.110186398 0.502883077 0.738479793 & +!0.764856219 0.294822574 1.90783739E-02 0.631218433 0.752170086 0.196848959 loc = (0., 0.) scale=(2., 1.) From da7d2771ec915fe923494958c22a69384e5479c9 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 21 Jan 2021 14:28:37 -0500 Subject: [PATCH 058/172] Add files via upload From ffdb937f47757acee87d15e6bcf76757cfd24932 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 21 Jan 2021 20:10:09 -0500 Subject: [PATCH 059/172] Update stdlib_stats_distribution_uniform.md --- doc/specs/stdlib_stats_distribution_uniform.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index 145a1822f..775fa54ad 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -2,7 +2,7 @@ title: stats_distribution --- -# Statistical Distributions Uniform Module +# Statistical Distributions -- Uniform Module [TOC] From c7cf916ede4cce55059fb6d3a98e18260951d545 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 21 Jan 2021 20:23:20 -0500 Subject: [PATCH 060/172] Update CMakeLists.txt --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 256bb6e71..2429f555a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,7 +21,7 @@ set(fppFiles stdlib_quadrature.fypp stdlib_quadrature_trapz.fypp stdlib_quadrature_simps.fypp - + stdlib_stats_distribution_PRNG.fypp ) From ba70104445d27a714d414b5cdca3849b66308cd1 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Thu, 21 Jan 2021 20:23:38 -0500 Subject: [PATCH 061/172] Update CMakeLists.txt --- src/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2429f555a..02413b415 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,7 +21,6 @@ set(fppFiles stdlib_quadrature.fypp stdlib_quadrature_trapz.fypp stdlib_quadrature_simps.fypp - stdlib_stats_distribution_PRNG.fypp ) From e155e1e0ee4c3ed0220871ccbda94775073c8cea Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sat, 6 Feb 2021 10:33:19 -0500 Subject: [PATCH 062/172] Update stdlib_stats_distribution_uniform.fypp --- src/stdlib_stats_distribution_uniform.fypp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index f4056aa67..92f48577b 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -210,7 +210,7 @@ Module stdlib_stats_distribution_uniform #:for k1, t1 in CMPLX_KINDS_TYPES impure elemental function unif_dist_rvs_${t1[0]}$${k1}$(loc, scale) & result(res) - ! Uniformly distributed complex in [(loc,iloc), (loc + scale, i(loc + scale)] + ! Uniformly distributed complex in [(loc,iloc), (loc + scale, i(loc + scale))] ! The real part and imaginary part are independent of each other, so that ! the joint distribution is on an unit square [(loc,iloc), (loc + scale, ! i(loc + scale))] @@ -479,4 +479,4 @@ Module stdlib_stats_distribution_uniform end function shuffle_${t1[0]}$${k1}$ #:endfor -end module stdlib_stats_distribution_uniform \ No newline at end of file +end module stdlib_stats_distribution_uniform From 2e810fcea3ae23c1eaa4395b82cc1d72728acc08 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sat, 6 Feb 2021 10:37:45 -0500 Subject: [PATCH 063/172] update PRNG module --- src/stdlib_stats_distribution_PRNG.fypp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/stdlib_stats_distribution_PRNG.fypp b/src/stdlib_stats_distribution_PRNG.fypp index 3fdbf0438..71f3c7064 100644 --- a/src/stdlib_stats_distribution_PRNG.fypp +++ b/src/stdlib_stats_distribution_PRNG.fypp @@ -1,13 +1,13 @@ #:include "common.fypp" module stdlib_stats_distribution_PRNG use stdlib_kinds, only: int8, int16, int32, int64 - use stdlib_error + use stdlib_error, only: error_stop implicit none private integer, parameter :: MAX_INT_BIT_SIZE = bit_size(1_int64) - integer(int64), save :: st(4) ! internal states for xoshiro256ss function - integer(int64), save :: si = 614872703977525537_int64 ! default seed value - logical, save :: seed_initialized = .false. + integer(int64) :: st(4) ! internal states for xoshiro256ss function + integer(int64) :: si = 614872703977525537_int64 ! default seed value + logical :: seed_initialized = .false. public :: random_seed public :: dist_rand @@ -77,7 +77,7 @@ module stdlib_stats_distribution_PRNG integer(int64) :: res, t if(.not. seed_initialized) call random_distribution_seed_iint64(si,t) - res = rol64(st(2) * 5 , 7) * 9 + res = rol64(st(2) * 5, 7) * 9 t = shiftl(st(2), 17) st(3) = ieor(st(3), st(1)) st(4) = ieor(st(4), st(2)) @@ -87,7 +87,7 @@ module stdlib_stats_distribution_PRNG st(4) = rol64(st(4), 45) end function xoshiro256ss - function rol64(x, k) result(res) + pure function rol64(x, k) result(res) integer(int64), intent(in) :: x integer, intent(in) :: k integer(int64) :: t1, t2, res @@ -110,11 +110,11 @@ module stdlib_stats_distribution_PRNG ! ! Fortran 90 translated from C by Jim-215-Fisher ! - integer(int64) :: res, int01, int02, int03 + integer(int64) :: res integer(int64), intent(in), optional :: s - data int01, int02, int03/-7046029254386353131_int64, & - -4658895280553007687_int64, & - -7723592293110705685_int64/ + integer(int64) :: int01 = -7046029254386353131_int64, & + int02 = -4658895280553007687_int64, & + int03 = -7723592293110705685_int64 ! Values are converted from C unsigned integer of 0x9e3779b97f4a7c15, ! 0xbf58476d1ce4e5b9, 0x94d049bb133111eb From ce9c467f140f83e247e6ec939c5e3aba055dd896 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:04:18 -0500 Subject: [PATCH 064/172] Update index.md --- doc/specs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/specs/index.md b/doc/specs/index.md index 5912ea38a..2e4c675fa 100644 --- a/doc/specs/index.md +++ b/doc/specs/index.md @@ -19,7 +19,7 @@ This is and index/directory of the specifications (specs) for each new module/fe - [optval](./stdlib_optval.html) - Fallback value for optional arguments - [quadrature](./stdlib_quadrature.html) - Numerical integration - [stats](./stdlib_stats.html) - Descriptive Statistics - - [stats_distribution_uniform](./stdlib_stats_distribution_uniform.html) - Uniform probability distribution + - [stats_distribution_PRNG](./stdlib_stats_distribution_PRNG.html) - Probability Distributions random number generator ## Missing specs - [ascii](https://github.com/fortran-lang/stdlib/blob/master/src/stdlib_ascii.f90) From 9691008941290ab16351532173a0f1ed4fa51369 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:06:23 -0500 Subject: [PATCH 065/172] Delete CMakeLists.txt --- src/CMakeLists.txt | 73 ---------------------------------------------- 1 file changed, 73 deletions(-) delete mode 100644 src/CMakeLists.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index f8aa14128..000000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,73 +0,0 @@ -### Pre-process: .fpp -> .f90 via Fypp - -# Create a list of the files to be preprocessed -set(fppFiles - stdlib_bitsets.fypp - stdlib_bitsets_64.fypp - stdlib_bitsets_large.fypp - stdlib_io.fypp - stdlib_linalg.fypp - stdlib_linalg_diag.fypp - stdlib_optval.fypp - stdlib_stats.fypp - stdlib_stats_corr.fypp - stdlib_stats_cov.fypp - stdlib_stats_mean.fypp - stdlib_stats_moment.fypp - stdlib_stats_moment_all.fypp - stdlib_stats_moment_mask.fypp - stdlib_stats_moment_scalar.fypp - stdlib_stats_var.fypp - stdlib_quadrature.fypp - stdlib_quadrature_trapz.fypp - stdlib_quadrature_simps.fypp - stdlib_stats_distribution_PRNG.fypp - stdlib_stats_distribution_uniform.fypp -) - - -# Custom preprocessor flags -if(DEFINED CMAKE_MAXIMUM_RANK) - set(fyppFlags "-DMAXRANK=${CMAKE_MAXIMUM_RANK}") -elseif(f03rank) - set(fyppFlags) -else() - set(fyppFlags "-DVERSION90") -endif() - -fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) - -set(SRC - stdlib_ascii.f90 - stdlib_error.f90 - stdlib_kinds.f90 - stdlib_logger.f90 - stdlib_system.F90 - ${outFiles} -) - -add_library(${PROJECT_NAME} ${SRC}) - -set(LIB_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/mod_files/) -set_target_properties(${PROJECT_NAME} PROPERTIES - Fortran_MODULE_DIRECTORY ${LIB_MOD_DIR}) -target_include_directories(${PROJECT_NAME} PUBLIC - $ - $ -) - -if(f18errorstop) - target_sources(${PROJECT_NAME} PRIVATE f18estop.f90) -else() - target_sources(${PROJECT_NAME} PRIVATE f08estop.f90) -endif() - -add_subdirectory(tests) - -install(TARGETS ${PROJECT_NAME} - EXPORT ${PROJECT_NAME}-targets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" -) -install(DIRECTORY ${LIB_MOD_DIR} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") From 1513e84600608f0cfdd07194e8ab45905832bf8a Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:06:29 -0500 Subject: [PATCH 066/172] Delete Makefile.manual --- src/Makefile.manual | 115 -------------------------------------------- 1 file changed, 115 deletions(-) delete mode 100644 src/Makefile.manual diff --git a/src/Makefile.manual b/src/Makefile.manual deleted file mode 100644 index c4035cce6..000000000 --- a/src/Makefile.manual +++ /dev/null @@ -1,115 +0,0 @@ -SRCFYPP =\ - stdlib_bitsets_64.fypp \ - stdlib_bitsets_large.fypp \ - stdlib_bitsets.fypp \ - stdlib_io.fypp \ - stdlib_linalg.fypp \ - stdlib_linalg_diag.fypp \ - stdlib_optval.fypp \ - stdlib_quadrature.fypp \ - stdlib_quadrature_trapz.fypp \ - stdlib_quadrature_simps.fypp \ - stdlib_stats.fypp \ - stdlib_stats_corr.fypp \ - stdlib_stats_cov.fypp \ - stdlib_stats_mean.fypp \ - stdlib_stats_moment.fypp \ - stdlib_stats_moment_all.fypp \ - stdlib_stats_moment_mask.fypp \ - stdlib_stats_moment_scalar.fypp \ - stdlib_stats_var.fypp \ - stdlib_stats_distribution_PRNG.fypp \ - stdlib_stats_distribution_uniform.fypp - -SRC = f18estop.f90 \ - stdlib_ascii.f90 \ - stdlib_error.f90 \ - stdlib_kinds.f90 \ - stdlib_logger.f90 \ - $(SRCGEN) - -LIB = libstdlib.a - - -SRCGEN = $(SRCFYPP:.fypp=.f90) -OBJS = $(SRC:.f90=.o) -MODS = $(OBJS:.o=.mod) -SMODS = $(OBJS:.o=*.smod) - -.PHONY: all clean - -all: $(LIB) - -$(LIB): $(OBJS) - ar rcs $@ $(OBJS) - -clean: - $(RM) $(LIB) $(OBJS) $(MODS) $(SMODS) $(SRCGEN) - -%.o: %.f90 - $(FC) $(FFLAGS) -c $< - -$(SRCGEN): %.f90: %.fypp common.fypp - fypp $(FYPPFLAGS) $< $@ - -# Fortran module dependencies -f18estop.o: stdlib_error.o -stdlib_bitsets.o: stdlib_kinds.o -stdlib_bitsets_64.o: stdlib_bitsets.o -stdlib_bitsets_large.o: stdlib_bitsets.o -stdlib_error.o: stdlib_optval.o -stdlib_io.o: \ - stdlib_error.o \ - stdlib_optval.o \ - stdlib_kinds.o -stdlib_linalg.o: \ - stdlib_kinds.o -stdlib_linalg_diag.o: \ - stdlib_linalg.o \ - stdlib_kinds.o -stdlib_logger.o: stdlib_ascii.o stdlib_optval.o -stdlib_optval.o: stdlib_kinds.o -stdlib_quadrature.o: stdlib_kinds.o -stdlib_quadrature_simps.o: \ - stdlib_quadrature.o \ - stdlib_error.o \ - stdlib_kinds.o -stdlib_quadrature_trapz.o: \ - stdlib_quadrature.o \ - stdlib_error.o \ - stdlib_kinds.o -stdlib_stats.o: \ - stdlib_kinds.o -stdlib_stats_corr.o: \ - stdlib_optval.o \ - stdlib_kinds.o \ - stdlib_stats.o -stdlib_stats_cov.o: \ - stdlib_optval.o \ - stdlib_kinds.o \ - stdlib_stats.o -stdlib_stats_mean.o: \ - stdlib_optval.o \ - stdlib_kinds.o \ - stdlib_stats.o -stdlib_stats_moment.o: \ - stdlib_optval.o \ - stdlib_kinds.o \ - stdlib_stats.o -stdlib_stats_moment_all.o: \ - stdlib_stats_moment.o -stdlib_stats_moment_mask.o: \ - stdlib_stats_moment.o -stdlib_stats_moment_scalar.o: \ - stdlib_stats_moment.o -stdlib_stats_var.o: \ - stdlib_optval.o \ - stdlib_kinds.o \ - stdlib_stats.o -stdlib_stats_distribution_PRNG.o: \ - stdlib_kinds.o \ - stdlib_error.o -stdlib_stats_distribution_uniform.o: \ - stdlib_kinds.o \ - stdlib_error.o \ - stdlib_stats_distribution_PRNG.o From 5600315bdaf7d81f552cff05dda60ee7143c2dfd Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:06:41 -0500 Subject: [PATCH 067/172] Delete CMakeLists.txt --- src/tests/stats/CMakeLists.txt | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 src/tests/stats/CMakeLists.txt diff --git a/src/tests/stats/CMakeLists.txt b/src/tests/stats/CMakeLists.txt deleted file mode 100644 index 0f40ea69b..000000000 --- a/src/tests/stats/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -ADDTEST(corr) -ADDTEST(cov) -ADDTEST(mean) -ADDTEST(moment) -ADDTEST(rawmoment) -ADDTEST(var) -ADDTEST(varn) -ADDTEST(distribution_uniform) - -if(DEFINED CMAKE_MAXIMUM_RANK) - if(${CMAKE_MAXIMUM_RANK} GREATER 7) - ADDTEST(mean_f03) - endif() -elseif(f03rank) - ADDTEST(mean_f03) -endif() From c74589efbc71ed995d83f3ff42927e7ddd34cb10 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:06:49 -0500 Subject: [PATCH 068/172] Delete Makefile.manual --- src/tests/stats/Makefile.manual | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/tests/stats/Makefile.manual diff --git a/src/tests/stats/Makefile.manual b/src/tests/stats/Makefile.manual deleted file mode 100644 index ab425a69c..000000000 --- a/src/tests/stats/Makefile.manual +++ /dev/null @@ -1,5 +0,0 @@ - -PROGS_SRC = test_mean.f90 test_moment.f90 test_var.f90 \ - test_distribution_uniform.f90 - -include ../Makefile.manual.test.mk \ No newline at end of file From 6bd7b2ac728e52d394a55f59dd7ab52a95cb23ae Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:08:46 -0500 Subject: [PATCH 069/172] Delete stdlib_stats_distribution_PRNG.fypp --- src/stdlib_stats_distribution_PRNG.fypp | 151 ------------------------ 1 file changed, 151 deletions(-) delete mode 100644 src/stdlib_stats_distribution_PRNG.fypp diff --git a/src/stdlib_stats_distribution_PRNG.fypp b/src/stdlib_stats_distribution_PRNG.fypp deleted file mode 100644 index 71f3c7064..000000000 --- a/src/stdlib_stats_distribution_PRNG.fypp +++ /dev/null @@ -1,151 +0,0 @@ -#:include "common.fypp" -module stdlib_stats_distribution_PRNG - use stdlib_kinds, only: int8, int16, int32, int64 - use stdlib_error, only: error_stop - implicit none - private - integer, parameter :: MAX_INT_BIT_SIZE = bit_size(1_int64) - integer(int64) :: st(4) ! internal states for xoshiro256ss function - integer(int64) :: si = 614872703977525537_int64 ! default seed value - logical :: seed_initialized = .false. - - public :: random_seed - public :: dist_rand - - - interface dist_rand - !! Version experimental - !! - !! Generation of random integers with different kinds - !! ([Specification](../page/specs/stdlib_stats_distribution_PRNG.html# - !! description)) - #:for k1, t1 in INT_KINDS_TYPES - module procedure dist_rand_${t1[0]}$${k1}$ - #:endfor - end interface dist_rand - - interface random_seed - !! Version experimental - !! - !! Set seed value for random number generator - !! ([Specification](../page/specs/stdlib_stats_distribution_PRNG.html# - !! description)) - !! - #:for k1, t1 in INT_KINDS_TYPES - module procedure random_distribution_seed_${t1[0]}$${k1}$ - #:endfor - end interface random_seed - - - contains - - #:for k1, t1 in INT_KINDS_TYPES - function dist_rand_${t1[0]}$${k1}$(n) result(res) - !! Random integer generation for various kinds - !! result = [-2^k, 2^k - 1], k = 7, 15, 31, 63, depending on input kind - !! Result will be operated by bitwise operators to generate desired integer - !! and real pseudorandom numbers - !! - ${t1}$, intent(in) :: n - ${t1}$ :: res - integer :: k - - k = MAX_INT_BIT_SIZE - bit_size(n) - if(k < 0) call error_stop("Error(dist_rand): Integer bit size is" & - //" greater than 64bit") - res = shiftr(xoshiro256ss( ), k) - end function dist_rand_${t1[0]}$${k1}$ - - #:endfor - - function xoshiro256ss( ) result (res) - ! Generate random 64-bit integers - ! Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org) - ! http://prng.di.unimi.it/xoshiro256starstar.c - ! - ! This is xoshiro256** 1.0, one of our all-purpose, rock-solid - ! generators. It has excellent (sub-ns) speed, a state (256 bits) that is - ! large enough for any parallel application, and it passes all tests we - ! are aware of. - ! - ! The state must be seeded so that it is not everywhere zero. If you have - ! a 64-bit seed, we suggest to seed a splitmix64 generator and use its - ! output to fill st. - ! - ! Fortran 90 version translated from C by Jim-215-Fisher - ! - integer(int64) :: res, t - - if(.not. seed_initialized) call random_distribution_seed_iint64(si,t) - res = rol64(st(2) * 5, 7) * 9 - t = shiftl(st(2), 17) - st(3) = ieor(st(3), st(1)) - st(4) = ieor(st(4), st(2)) - st(2) = ieor(st(2), st(3)) - st(1) = ieor(st(1), st(4)) - st(3) = ieor(st(3), t) - st(4) = rol64(st(4), 45) - end function xoshiro256ss - - pure function rol64(x, k) result(res) - integer(int64), intent(in) :: x - integer, intent(in) :: k - integer(int64) :: t1, t2, res - - t1 = shiftr(x, (64 - k)) - t2 = shiftl(x, k) - res = ior(t1, t2) - end function rol64 - - - function splitmix64(s) result(res) - ! Written in 2015 by Sebastiano Vigna (vigna@acm.org) - ! This is a fixed-increment version of Java 8's SplittableRandom - ! generator. - ! See http://dx.doi.org/10.1145/2714064.2660195 and - ! http://docs.oracle.com/javase/8/docs/api/java/util/SplittableRandom.html - ! - ! It is a very fast generator passing BigCrush, and it can be useful if - ! for some reason you absolutely want 64 bits of state. - ! - ! Fortran 90 translated from C by Jim-215-Fisher - ! - integer(int64) :: res - integer(int64), intent(in), optional :: s - integer(int64) :: int01 = -7046029254386353131_int64, & - int02 = -4658895280553007687_int64, & - int03 = -7723592293110705685_int64 - ! Values are converted from C unsigned integer of 0x9e3779b97f4a7c15, - ! 0xbf58476d1ce4e5b9, 0x94d049bb133111eb - - if(present(s)) si = s - res = si - si = res + int01 - res = ieor(res, shiftr(res, 30)) * int02 - res = ieor(res, shiftr(res, 27)) * int03 - res = ieor(res, shiftr(res, 31)) - end function splitmix64 - - #:for k1, t1 in INT_KINDS_TYPES - subroutine random_distribution_seed_${t1[0]}$${k1}$(put, get) - !! Set seed value for random number generator - !! - ${t1}$, intent(in) :: put - ${t1}$, intent(out) :: get - integer(int64) :: tmp - integer :: i - - tmp = splitmix64(int(put, kind = int64)) - do i = 1, 10 - tmp = splitmix64( ) - end do - do i = 1, 4 - tmp = splitmix64( ) - st(i) = tmp - end do - get = int(tmp, kind = ${k1}$) - seed_initialized = .true. - end subroutine random_distribution_seed_${t1[0]}$${k1}$ - - #:endfor -end module stdlib_stats_distribution_PRNG \ No newline at end of file From bc93073ee28db91926b873059f30e1b538d93550 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:09:47 -0500 Subject: [PATCH 070/172] Create CmakeLists.txt --- src/CmakeLists.txt | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/CmakeLists.txt diff --git a/src/CmakeLists.txt b/src/CmakeLists.txt new file mode 100644 index 000000000..2429f555a --- /dev/null +++ b/src/CmakeLists.txt @@ -0,0 +1,72 @@ +### Pre-process: .fpp -> .f90 via Fypp + +# Create a list of the files to be preprocessed +set(fppFiles + stdlib_bitsets.fypp + stdlib_bitsets_64.fypp + stdlib_bitsets_large.fypp + stdlib_io.fypp + stdlib_linalg.fypp + stdlib_linalg_diag.fypp + stdlib_optval.fypp + stdlib_stats.fypp + stdlib_stats_corr.fypp + stdlib_stats_cov.fypp + stdlib_stats_mean.fypp + stdlib_stats_moment.fypp + stdlib_stats_moment_all.fypp + stdlib_stats_moment_mask.fypp + stdlib_stats_moment_scalar.fypp + stdlib_stats_var.fypp + stdlib_quadrature.fypp + stdlib_quadrature_trapz.fypp + stdlib_quadrature_simps.fypp + stdlib_stats_distribution_PRNG.fypp +) + + +# Custom preprocessor flags +if(DEFINED CMAKE_MAXIMUM_RANK) + set(fyppFlags "-DMAXRANK=${CMAKE_MAXIMUM_RANK}") +elseif(f03rank) + set(fyppFlags) +else() + set(fyppFlags "-DVERSION90") +endif() + +fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) + +set(SRC + stdlib_ascii.f90 + stdlib_error.f90 + stdlib_kinds.f90 + stdlib_logger.f90 + stdlib_system.F90 + ${outFiles} +) + +add_library(${PROJECT_NAME} ${SRC}) + +set(LIB_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/mod_files/) +set_target_properties(${PROJECT_NAME} PROPERTIES + Fortran_MODULE_DIRECTORY ${LIB_MOD_DIR}) +target_include_directories(${PROJECT_NAME} PUBLIC + $ + $ +) + +if(f18errorstop) + target_sources(${PROJECT_NAME} PRIVATE f18estop.f90) +else() + target_sources(${PROJECT_NAME} PRIVATE f08estop.f90) +endif() + +add_subdirectory(tests) + +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}-targets + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) +install(DIRECTORY ${LIB_MOD_DIR} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") From 652094abbe2b20161c3e8bb4f0a31ca0eef777bf Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:10:20 -0500 Subject: [PATCH 071/172] Delete CmakeLists.txt --- src/CmakeLists.txt | 72 ---------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 src/CmakeLists.txt diff --git a/src/CmakeLists.txt b/src/CmakeLists.txt deleted file mode 100644 index 2429f555a..000000000 --- a/src/CmakeLists.txt +++ /dev/null @@ -1,72 +0,0 @@ -### Pre-process: .fpp -> .f90 via Fypp - -# Create a list of the files to be preprocessed -set(fppFiles - stdlib_bitsets.fypp - stdlib_bitsets_64.fypp - stdlib_bitsets_large.fypp - stdlib_io.fypp - stdlib_linalg.fypp - stdlib_linalg_diag.fypp - stdlib_optval.fypp - stdlib_stats.fypp - stdlib_stats_corr.fypp - stdlib_stats_cov.fypp - stdlib_stats_mean.fypp - stdlib_stats_moment.fypp - stdlib_stats_moment_all.fypp - stdlib_stats_moment_mask.fypp - stdlib_stats_moment_scalar.fypp - stdlib_stats_var.fypp - stdlib_quadrature.fypp - stdlib_quadrature_trapz.fypp - stdlib_quadrature_simps.fypp - stdlib_stats_distribution_PRNG.fypp -) - - -# Custom preprocessor flags -if(DEFINED CMAKE_MAXIMUM_RANK) - set(fyppFlags "-DMAXRANK=${CMAKE_MAXIMUM_RANK}") -elseif(f03rank) - set(fyppFlags) -else() - set(fyppFlags "-DVERSION90") -endif() - -fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) - -set(SRC - stdlib_ascii.f90 - stdlib_error.f90 - stdlib_kinds.f90 - stdlib_logger.f90 - stdlib_system.F90 - ${outFiles} -) - -add_library(${PROJECT_NAME} ${SRC}) - -set(LIB_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/mod_files/) -set_target_properties(${PROJECT_NAME} PROPERTIES - Fortran_MODULE_DIRECTORY ${LIB_MOD_DIR}) -target_include_directories(${PROJECT_NAME} PUBLIC - $ - $ -) - -if(f18errorstop) - target_sources(${PROJECT_NAME} PRIVATE f18estop.f90) -else() - target_sources(${PROJECT_NAME} PRIVATE f08estop.f90) -endif() - -add_subdirectory(tests) - -install(TARGETS ${PROJECT_NAME} - EXPORT ${PROJECT_NAME}-targets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" -) -install(DIRECTORY ${LIB_MOD_DIR} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") From 310c047c1dd8a0e802abb73b184f6f171ce29859 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:10:41 -0500 Subject: [PATCH 072/172] Create CMakeLists.txt --- src/CMakeLists.txt | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/CMakeLists.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000..2429f555a --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,72 @@ +### Pre-process: .fpp -> .f90 via Fypp + +# Create a list of the files to be preprocessed +set(fppFiles + stdlib_bitsets.fypp + stdlib_bitsets_64.fypp + stdlib_bitsets_large.fypp + stdlib_io.fypp + stdlib_linalg.fypp + stdlib_linalg_diag.fypp + stdlib_optval.fypp + stdlib_stats.fypp + stdlib_stats_corr.fypp + stdlib_stats_cov.fypp + stdlib_stats_mean.fypp + stdlib_stats_moment.fypp + stdlib_stats_moment_all.fypp + stdlib_stats_moment_mask.fypp + stdlib_stats_moment_scalar.fypp + stdlib_stats_var.fypp + stdlib_quadrature.fypp + stdlib_quadrature_trapz.fypp + stdlib_quadrature_simps.fypp + stdlib_stats_distribution_PRNG.fypp +) + + +# Custom preprocessor flags +if(DEFINED CMAKE_MAXIMUM_RANK) + set(fyppFlags "-DMAXRANK=${CMAKE_MAXIMUM_RANK}") +elseif(f03rank) + set(fyppFlags) +else() + set(fyppFlags "-DVERSION90") +endif() + +fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) + +set(SRC + stdlib_ascii.f90 + stdlib_error.f90 + stdlib_kinds.f90 + stdlib_logger.f90 + stdlib_system.F90 + ${outFiles} +) + +add_library(${PROJECT_NAME} ${SRC}) + +set(LIB_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/mod_files/) +set_target_properties(${PROJECT_NAME} PROPERTIES + Fortran_MODULE_DIRECTORY ${LIB_MOD_DIR}) +target_include_directories(${PROJECT_NAME} PUBLIC + $ + $ +) + +if(f18errorstop) + target_sources(${PROJECT_NAME} PRIVATE f18estop.f90) +else() + target_sources(${PROJECT_NAME} PRIVATE f08estop.f90) +endif() + +add_subdirectory(tests) + +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}-targets + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) +install(DIRECTORY ${LIB_MOD_DIR} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") From b026328efa6c91e9586b68f7d7870a6f1b10304a Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:11:28 -0500 Subject: [PATCH 073/172] Create Makefile.manual --- src/Makefile.manual | 110 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 src/Makefile.manual diff --git a/src/Makefile.manual b/src/Makefile.manual new file mode 100644 index 000000000..a57253e2b --- /dev/null +++ b/src/Makefile.manual @@ -0,0 +1,110 @@ +SRCFYPP =\ + stdlib_bitsets_64.fypp \ + stdlib_bitsets_large.fypp \ + stdlib_bitsets.fypp \ + stdlib_io.fypp \ + stdlib_linalg.fypp \ + stdlib_linalg_diag.fypp \ + stdlib_optval.fypp \ + stdlib_quadrature.fypp \ + stdlib_quadrature_trapz.fypp \ + stdlib_quadrature_simps.fypp \ + stdlib_stats.fypp \ + stdlib_stats_corr.fypp \ + stdlib_stats_cov.fypp \ + stdlib_stats_mean.fypp \ + stdlib_stats_moment.fypp \ + stdlib_stats_moment_all.fypp \ + stdlib_stats_moment_mask.fypp \ + stdlib_stats_moment_scalar.fypp \ + stdlib_stats_var.fypp \ + stdlib_stats_distribution_PRNG.fypp + +SRC = f18estop.f90 \ + stdlib_ascii.f90 \ + stdlib_error.f90 \ + stdlib_kinds.f90 \ + stdlib_logger.f90 \ + $(SRCGEN) + +LIB = libstdlib.a + + +SRCGEN = $(SRCFYPP:.fypp=.f90) +OBJS = $(SRC:.f90=.o) +MODS = $(OBJS:.o=.mod) +SMODS = $(OBJS:.o=*.smod) + +.PHONY: all clean + +all: $(LIB) + +$(LIB): $(OBJS) + ar rcs $@ $(OBJS) + +clean: + $(RM) $(LIB) $(OBJS) $(MODS) $(SMODS) $(SRCGEN) + +%.o: %.f90 + $(FC) $(FFLAGS) -c $< + +$(SRCGEN): %.f90: %.fypp common.fypp + fypp $(FYPPFLAGS) $< $@ + +# Fortran module dependencies +f18estop.o: stdlib_error.o +stdlib_bitsets.o: stdlib_kinds.o +stdlib_bitsets_64.o: stdlib_bitsets.o +stdlib_bitsets_large.o: stdlib_bitsets.o +stdlib_error.o: stdlib_optval.o +stdlib_io.o: \ + stdlib_error.o \ + stdlib_optval.o \ + stdlib_kinds.o +stdlib_linalg.o: \ + stdlib_kinds.o +stdlib_linalg_diag.o: \ + stdlib_linalg.o \ + stdlib_kinds.o +stdlib_logger.o: stdlib_ascii.o stdlib_optval.o +stdlib_optval.o: stdlib_kinds.o +stdlib_quadrature.o: stdlib_kinds.o +stdlib_quadrature_simps.o: \ + stdlib_quadrature.o \ + stdlib_error.o \ + stdlib_kinds.o +stdlib_quadrature_trapz.o: \ + stdlib_quadrature.o \ + stdlib_error.o \ + stdlib_kinds.o +stdlib_stats.o: \ + stdlib_kinds.o +stdlib_stats_corr.o: \ + stdlib_optval.o \ + stdlib_kinds.o \ + stdlib_stats.o +stdlib_stats_cov.o: \ + stdlib_optval.o \ + stdlib_kinds.o \ + stdlib_stats.o +stdlib_stats_mean.o: \ + stdlib_optval.o \ + stdlib_kinds.o \ + stdlib_stats.o +stdlib_stats_moment.o: \ + stdlib_optval.o \ + stdlib_kinds.o \ + stdlib_stats.o +stdlib_stats_moment_all.o: \ + stdlib_stats_moment.o +stdlib_stats_moment_mask.o: \ + stdlib_stats_moment.o +stdlib_stats_moment_scalar.o: \ + stdlib_stats_moment.o +stdlib_stats_var.o: \ + stdlib_optval.o \ + stdlib_kinds.o \ + stdlib_stats.o +stdlib_stats_distribution_PRNG.o: \ + stdlib_kinds.o \ + stdlib_error.o From 80b1cc79f6a5dde2cc17b91c91d449d0cc93568a Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:13:10 -0500 Subject: [PATCH 074/172] Create CMakeLists.txt --- src/tests/stats/CMakeLists.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/tests/stats/CMakeLists.txt diff --git a/src/tests/stats/CMakeLists.txt b/src/tests/stats/CMakeLists.txt new file mode 100644 index 000000000..38f9bb84b --- /dev/null +++ b/src/tests/stats/CMakeLists.txt @@ -0,0 +1,16 @@ +ADDTEST(corr) +ADDTEST(cov) +ADDTEST(mean) +ADDTEST(moment) +ADDTEST(rawmoment) +ADDTEST(var) +ADDTEST(varn) +ADDTEST(distribution_PRNG) + +if(DEFINED CMAKE_MAXIMUM_RANK) + if(${CMAKE_MAXIMUM_RANK} GREATER 7) + ADDTEST(mean_f03) + endif() +elseif(f03rank) + ADDTEST(mean_f03) +endif() From 48ba19403b31bc6312cd4a64e5ce5a9e44c5e5a0 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:13:44 -0500 Subject: [PATCH 075/172] Create Makefile.manual --- src/tests/stats/Makefile.manual | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/tests/stats/Makefile.manual diff --git a/src/tests/stats/Makefile.manual b/src/tests/stats/Makefile.manual new file mode 100644 index 000000000..a1a3451cf --- /dev/null +++ b/src/tests/stats/Makefile.manual @@ -0,0 +1,4 @@ +PROGS_SRC = test_mean.f90 test_moment.f90 test_var.f90 \ + test_distribution_PRNG.f90 + +include ../Makefile.manual.test.mk From e9433cf7076280eeb7c74e8c2015a33d35ab3305 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:14:45 -0500 Subject: [PATCH 076/172] Delete index.md --- doc/specs/index.md | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 doc/specs/index.md diff --git a/doc/specs/index.md b/doc/specs/index.md deleted file mode 100644 index 2e4c675fa..000000000 --- a/doc/specs/index.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: Specifications (specs) ---- - -# Fortran stdlib Specifications (specs) - -This is and index/directory of the specifications (specs) for each new module/feature as described in the -[workflow document](../Workflow.html). - -[TOC] - -## Experimental Features & Modules - - - [bitsets](./stdlib_bitsets.html) - Bitset data types and procedures - - [error](./stdlib_error.html) - Catching and handling errors - - [IO](./stdlib_io.html) - Input/output helper & convenience - - [linalg](./stdlib_linalg.html) - Linear Algebra - - [logger](./stdlib_logger.html) - Runtime logging system - - [optval](./stdlib_optval.html) - Fallback value for optional arguments - - [quadrature](./stdlib_quadrature.html) - Numerical integration - - [stats](./stdlib_stats.html) - Descriptive Statistics - - [stats_distribution_PRNG](./stdlib_stats_distribution_PRNG.html) - Probability Distributions random number generator -## Missing specs - - - [ascii](https://github.com/fortran-lang/stdlib/blob/master/src/stdlib_ascii.f90) - - [kinds](https://github.com/fortran-lang/stdlib/blob/master/src/stdlib_kinds.f90) - -## Released/Stable Features & Modules - - - (None yet) From baa949583dc83838187f6b84618cef9655aa01a8 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:14:58 -0500 Subject: [PATCH 077/172] Create index.md --- doc/specs/index.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 doc/specs/index.md diff --git a/doc/specs/index.md b/doc/specs/index.md new file mode 100644 index 000000000..edd00ed95 --- /dev/null +++ b/doc/specs/index.md @@ -0,0 +1,31 @@ +--- +title: Specifications (specs) +--- + +# Fortran stdlib Specifications (specs) + +This is and index/directory of the specifications (specs) for each new module/feature as described in the +[workflow document](../Workflow.html). + +[TOC] + +## Experimental Features & Modules + + - [bitsets](./stdlib_bitsets.html) - Bitset data types and procedures + - [error](./stdlib_error.html) - Catching and handling errors + - [IO](./stdlib_io.html) - Input/output helper & convenience + - [linalg](./stdlib_linalg.html) - Linear Algebra + - [logger](./stdlib_logger.html) - Runtime logging system + - [optval](./stdlib_optval.html) - Fallback value for optional arguments + - [quadrature](./stdlib_quadrature.html) - Numerical integration + - [stats](./stdlib_stats.html) - Descriptive Statistics + - [stats_distribution_PRNG](./stdlib_stats_distribution_PRNG.html) - Probability Distributions random number generator + +## Missing specs + + - [ascii](https://github.com/fortran-lang/stdlib/blob/master/src/stdlib_ascii.f90) + - [kinds](https://github.com/fortran-lang/stdlib/blob/master/src/stdlib_kinds.f90) + +## Released/Stable Features & Modules + + - (None yet) From 8040c3ecceb2427a54b8883db3ff7bfadcc9b2a6 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:15:44 -0500 Subject: [PATCH 078/172] Delete Makefile.manual --- src/tests/stats/Makefile.manual | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 src/tests/stats/Makefile.manual diff --git a/src/tests/stats/Makefile.manual b/src/tests/stats/Makefile.manual deleted file mode 100644 index a1a3451cf..000000000 --- a/src/tests/stats/Makefile.manual +++ /dev/null @@ -1,4 +0,0 @@ -PROGS_SRC = test_mean.f90 test_moment.f90 test_var.f90 \ - test_distribution_PRNG.f90 - -include ../Makefile.manual.test.mk From 0ebfbde7a5c3c3afb7bee2e276d8ef0a86798d97 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:16:26 -0500 Subject: [PATCH 079/172] Create Makefile.manual --- src/tests/stats/Makefile.manual | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/tests/stats/Makefile.manual diff --git a/src/tests/stats/Makefile.manual b/src/tests/stats/Makefile.manual new file mode 100644 index 000000000..a1a3451cf --- /dev/null +++ b/src/tests/stats/Makefile.manual @@ -0,0 +1,4 @@ +PROGS_SRC = test_mean.f90 test_moment.f90 test_var.f90 \ + test_distribution_PRNG.f90 + +include ../Makefile.manual.test.mk From b0fe2c45584636d45b609cd6d78b1a052898d5cc Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:19:29 -0500 Subject: [PATCH 080/172] Update Makefile.manual From b148167b0b4a906601c945c91b4794844a666b68 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:21:57 -0500 Subject: [PATCH 081/172] Delete Makefile.manual --- src/tests/stats/Makefile.manual | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 src/tests/stats/Makefile.manual diff --git a/src/tests/stats/Makefile.manual b/src/tests/stats/Makefile.manual deleted file mode 100644 index a1a3451cf..000000000 --- a/src/tests/stats/Makefile.manual +++ /dev/null @@ -1,4 +0,0 @@ -PROGS_SRC = test_mean.f90 test_moment.f90 test_var.f90 \ - test_distribution_PRNG.f90 - -include ../Makefile.manual.test.mk From bb7118e63c528b66ff8c8656030f1a957f919d42 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:23:13 -0500 Subject: [PATCH 082/172] Create Makefile.manual --- src/tests/stats/Makefile.manual | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/tests/stats/Makefile.manual diff --git a/src/tests/stats/Makefile.manual b/src/tests/stats/Makefile.manual new file mode 100644 index 000000000..e167cff50 --- /dev/null +++ b/src/tests/stats/Makefile.manual @@ -0,0 +1,5 @@ + +PROGS_SRC = test_mean.f90 test_moment.f90 test_var.f90 \ + test_distribution_PRNG.f90 + +include ../Makefile.manual.test.mk From b184825341bdcdca01e58e4bf58348f00ffeb078 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:24:42 -0500 Subject: [PATCH 083/172] Update Makefile.manual --- src/tests/stats/Makefile.manual | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tests/stats/Makefile.manual b/src/tests/stats/Makefile.manual index a0731e8f4..a1a3451cf 100644 --- a/src/tests/stats/Makefile.manual +++ b/src/tests/stats/Makefile.manual @@ -1,5 +1,4 @@ - PROGS_SRC = test_mean.f90 test_moment.f90 test_var.f90 \ test_distribution_PRNG.f90 -include ../Makefile.manual.test.mk \ No newline at end of file +include ../Makefile.manual.test.mk From a47ea7997c092c0b813443f0f53980e97053878b Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:28:07 -0500 Subject: [PATCH 084/172] Update Makefile.manual --- src/tests/stats/Makefile.manual | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tests/stats/Makefile.manual b/src/tests/stats/Makefile.manual index e167cff50..a1a3451cf 100644 --- a/src/tests/stats/Makefile.manual +++ b/src/tests/stats/Makefile.manual @@ -1,4 +1,3 @@ - PROGS_SRC = test_mean.f90 test_moment.f90 test_var.f90 \ test_distribution_PRNG.f90 From f8e1f76bebede028c61fc7650119734b7956062f Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:29:24 -0500 Subject: [PATCH 085/172] Update index.md --- doc/specs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/specs/index.md b/doc/specs/index.md index edd00ed95..3a7fb02ae 100644 --- a/doc/specs/index.md +++ b/doc/specs/index.md @@ -20,7 +20,7 @@ This is and index/directory of the specifications (specs) for each new module/fe - [quadrature](./stdlib_quadrature.html) - Numerical integration - [stats](./stdlib_stats.html) - Descriptive Statistics - [stats_distribution_PRNG](./stdlib_stats_distribution_PRNG.html) - Probability Distributions random number generator - + - [stats_distribution_uniform](./stdlib_stats_distribution_uniform.html) - Uniform probability distribution ## Missing specs - [ascii](https://github.com/fortran-lang/stdlib/blob/master/src/stdlib_ascii.f90) From f40c0233f03f241b3bb6d4de009701b82923d1cc Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:29:46 -0500 Subject: [PATCH 086/172] Update index.md --- doc/specs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/specs/index.md b/doc/specs/index.md index 3a7fb02ae..edd00ed95 100644 --- a/doc/specs/index.md +++ b/doc/specs/index.md @@ -20,7 +20,7 @@ This is and index/directory of the specifications (specs) for each new module/fe - [quadrature](./stdlib_quadrature.html) - Numerical integration - [stats](./stdlib_stats.html) - Descriptive Statistics - [stats_distribution_PRNG](./stdlib_stats_distribution_PRNG.html) - Probability Distributions random number generator - - [stats_distribution_uniform](./stdlib_stats_distribution_uniform.html) - Uniform probability distribution + ## Missing specs - [ascii](https://github.com/fortran-lang/stdlib/blob/master/src/stdlib_ascii.f90) From 63a015ed0dc54526e580ddb1c0e643798051a860 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:30:08 -0500 Subject: [PATCH 087/172] Update index.md --- doc/specs/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/specs/index.md b/doc/specs/index.md index edd00ed95..f3dbd85c5 100644 --- a/doc/specs/index.md +++ b/doc/specs/index.md @@ -20,7 +20,8 @@ This is and index/directory of the specifications (specs) for each new module/fe - [quadrature](./stdlib_quadrature.html) - Numerical integration - [stats](./stdlib_stats.html) - Descriptive Statistics - [stats_distribution_PRNG](./stdlib_stats_distribution_PRNG.html) - Probability Distributions random number generator - + - [stats_distribution_uniform](./stdlib_stats_distribution_uniform.html) - Uniform probability distribution + ## Missing specs - [ascii](https://github.com/fortran-lang/stdlib/blob/master/src/stdlib_ascii.f90) From 6c7a3c6dd45584c59e607f3a799432c63d7825b4 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:31:23 -0500 Subject: [PATCH 088/172] Update CMakeLists.txt --- src/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2429f555a..f8aa14128 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,6 +22,7 @@ set(fppFiles stdlib_quadrature_trapz.fypp stdlib_quadrature_simps.fypp stdlib_stats_distribution_PRNG.fypp + stdlib_stats_distribution_uniform.fypp ) From d39097cf6cbc3b5b1f2b5584961e092eec729d90 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:32:54 -0500 Subject: [PATCH 089/172] Update Makefile.manual --- src/Makefile.manual | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Makefile.manual b/src/Makefile.manual index a57253e2b..f2f41e7d3 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -18,7 +18,8 @@ SRCFYPP =\ stdlib_stats_moment_mask.fypp \ stdlib_stats_moment_scalar.fypp \ stdlib_stats_var.fypp \ - stdlib_stats_distribution_PRNG.fypp + stdlib_stats_distribution_PRNG.fypp \ + stdlib_stats_distribution_uniform.fypp SRC = f18estop.f90 \ stdlib_ascii.f90 \ @@ -108,3 +109,7 @@ stdlib_stats_var.o: \ stdlib_stats_distribution_PRNG.o: \ stdlib_kinds.o \ stdlib_error.o +stdlib_stats_distribution_uniform.0: \ + stdlib_kinds.o \ + stdlib_error.o \ + stdlib_stats_distribution_PRNG.o From e4a405abd26d5a4ac16250fe9ad79090682cc13c Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:33:28 -0500 Subject: [PATCH 090/172] Update CMakeLists.txt --- src/tests/stats/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/stats/CMakeLists.txt b/src/tests/stats/CMakeLists.txt index 38f9bb84b..f312c383a 100644 --- a/src/tests/stats/CMakeLists.txt +++ b/src/tests/stats/CMakeLists.txt @@ -6,6 +6,7 @@ ADDTEST(rawmoment) ADDTEST(var) ADDTEST(varn) ADDTEST(distribution_PRNG) +ADDTEST(distribution_uniform) if(DEFINED CMAKE_MAXIMUM_RANK) if(${CMAKE_MAXIMUM_RANK} GREATER 7) From 03d5a81a8b782ed0882ec6a36f9d023541943d58 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 11:33:53 -0500 Subject: [PATCH 091/172] Update Makefile.manual --- src/tests/stats/Makefile.manual | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/stats/Makefile.manual b/src/tests/stats/Makefile.manual index a1a3451cf..66713a3cb 100644 --- a/src/tests/stats/Makefile.manual +++ b/src/tests/stats/Makefile.manual @@ -1,4 +1,4 @@ PROGS_SRC = test_mean.f90 test_moment.f90 test_var.f90 \ - test_distribution_PRNG.f90 + test_distribution_PRNG.f90 test_distribution_uniform.f90 include ../Makefile.manual.test.mk From cdfb497fa6dca3bc58ff3563d6e0375a59c9446c Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 21:23:45 -0500 Subject: [PATCH 092/172] Update stdlib_stats_distribution_uniform.md --- doc/specs/stdlib_stats_distribution_uniform.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index 775fa54ad..887adbcfa 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -2,7 +2,7 @@ title: stats_distribution --- -# Statistical Distributions -- Uniform Module +# Statistical Distributions -- Uniform Distribution Module [TOC] From e62f241f01dc032bc339daa85314d36ee00651a6 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 21:28:16 -0500 Subject: [PATCH 093/172] Update stdlib_stats_distribution_uniform.md --- doc/specs/stdlib_stats_distribution_uniform.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index 887adbcfa..c2905c0a8 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -93,7 +93,7 @@ With triple auguments `loc`, `scale` and `array_size` the function returns a ran `array_size`: optional argument has `intent(in)` and is a scalar of type `integer`. -`loc` and `scale` must have the same type when both are present. +`loc` and `scale` must have the same type and kind when both are present. ### Return value @@ -208,7 +208,7 @@ f(x) = 1 / (scale%re * scale%im); for complex uniform distribution `scale`: has `intent(in)` and is a scalar of type `integer`, `real` or `complex`. -The function is elemental, i.e., all three auguments could be arrays conformable to each other. All three arguments must have the same type. +The function is elemental, i.e., all three auguments could be arrays conformable to each other. All three arguments must have the same type and kind. ### Return value @@ -296,7 +296,7 @@ F(x) = (x%re - loc%re)(x%im - loc%im) / (scale%re * scale%im); for complex unifo `scale`: has `intent(in)` and is a scalar of type `integer`, `real` or `complex`. -The function is elemental, i.e., all three auguments could be arrays conformable to each other. All three arguments must have the same type. +The function is elemental, i.e., all three auguments could be arrays conformable to each other. All three arguments must have the same type and kind. ### Return value From cf408bc8bff3b1b3fe84abc510374aa1c92db6b2 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 21:31:11 -0500 Subject: [PATCH 094/172] Update stdlib_stats_distribution_uniform.md --- .../stdlib_stats_distribution_uniform.md | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index c2905c0a8..af25314f2 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -126,7 +126,8 @@ program demo_uniform_rvs print *, uni(-1.0,2.0,10) !an array of 10 uniform random variates in [-1., 1.] -!0.884182811 -0.771520197 0.560377002 0.709313750 -7.12267756E-02 !-0.431066573 0.497536063 -0.396331906 -0.325983286 0.137686729 +!0.884182811 -0.771520197 0.560377002 0.709313750 -7.12267756E-02 +!-0.431066573 0.497536063 -0.396331906 -0.325983286 0.137686729 print *, uni(20) !a random integer variate in [0, 20] ! 17 @@ -249,15 +250,15 @@ program demo_uniform_pdf x = reshape(uni(0.,2.,60),[3,4,5])! uniform random variates array in [0., 2.] print *, uni_pdf(x, a, b) ! probability density array in [0., 2.] -! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 & -! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 & -! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 & -! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 & -! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 & -! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 & -! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 & -! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 & -! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 & +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 +! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 ! 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 0.500000000 loc = (-0.5,-0.5) From 376bdc1395da1a724140ef20a6ae036342ea6f68 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 7 Feb 2021 21:36:01 -0500 Subject: [PATCH 095/172] Update Makefile.manual --- src/Makefile.manual | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.manual b/src/Makefile.manual index f2f41e7d3..fb1f84166 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -109,7 +109,7 @@ stdlib_stats_var.o: \ stdlib_stats_distribution_PRNG.o: \ stdlib_kinds.o \ stdlib_error.o -stdlib_stats_distribution_uniform.0: \ +stdlib_stats_distribution_uniform.o: \ stdlib_kinds.o \ stdlib_error.o \ stdlib_stats_distribution_PRNG.o From 9bebab0f65cf66a92ec54da6ee5870d58f095b13 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 18:00:36 -0400 Subject: [PATCH 096/172] Update doc/specs/stdlib_stats_distribution_uniform.md Co-authored-by: Jeremie Vandenplas --- doc/specs/stdlib_stats_distribution_uniform.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index af25314f2..8d889d73d 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -73,7 +73,7 @@ Experimental Without augument the function returns a scalar standard uniformly distributed variate U(0,1) of `real` type with single precision on [0,1]. -With single augument `scale` of `integer` type the function returns a scalar uniformly distributed variate of `integer` type on [0,scale]. This is the standard Rectangular distribtuion. Function is elemental. +With single augument `scale` of `integer` type the function returns a scalar uniformly distributed variate of `integer` type on [0,scale]. This is the standard Rectangular distribution. With single augument `scale` of `real` or `complex` type the function returns a scalar uniformly distributed variate of `real` or `complex` type on [0, scale]. The real part and imaginary part of a `complex` type are independent of each other. Function is elemental. From af7e8319533cf9716a72c9d0b26a8383b34b0288 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 18:07:28 -0400 Subject: [PATCH 097/172] Update doc/specs/stdlib_stats_distribution_uniform.md Co-authored-by: Jeremie Vandenplas --- doc/specs/stdlib_stats_distribution_uniform.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index 8d889d73d..a5301fca4 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -20,6 +20,8 @@ Applying Fisher-Yates algorithm to generate an unbiased permutation for any list `result = [[stdlib_stats_distribution_uniform(module):shuffle(interface)]]( list )` +Class +Function. ### Arguments `list`: argument has `intent(in)` and is a rank one array of `integer`, `real`, or `complex` type. From 09a172cdbc18a4cd1fb3b71f5e0b443a5bdc01cf Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 18:07:55 -0400 Subject: [PATCH 098/172] Update doc/specs/stdlib_stats_distribution_uniform.md Co-authored-by: Jeremie Vandenplas --- doc/specs/stdlib_stats_distribution_uniform.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index a5301fca4..e20e084ec 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -87,6 +87,9 @@ With triple auguments `loc`, `scale` and `array_size` the function returns a ran `result = [[stdlib_stats_distribution_uniform(module):uniform_distribution_rvs(interface)]]([[loc,] scale] [[[,array_size]]])` +### Class +Elemental function. + ### Arguments `loc`: optional argument has `intent(in)` and is a scalar of type `integer`, `real` or `complex`. From a55a671feea1cac82a604de4934cbedaf0c61d23 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 18:09:54 -0400 Subject: [PATCH 099/172] Update stdlib_stats_distribution_uniform.md --- doc/specs/stdlib_stats_distribution_uniform.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index e20e084ec..b40e0d199 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -20,8 +20,10 @@ Applying Fisher-Yates algorithm to generate an unbiased permutation for any list `result = [[stdlib_stats_distribution_uniform(module):shuffle(interface)]]( list )` -Class +### Class + Function. + ### Arguments `list`: argument has `intent(in)` and is a rank one array of `integer`, `real`, or `complex` type. @@ -77,9 +79,9 @@ Without augument the function returns a scalar standard uniformly distributed va With single augument `scale` of `integer` type the function returns a scalar uniformly distributed variate of `integer` type on [0,scale]. This is the standard Rectangular distribution. -With single augument `scale` of `real` or `complex` type the function returns a scalar uniformly distributed variate of `real` or `complex` type on [0, scale]. The real part and imaginary part of a `complex` type are independent of each other. Function is elemental. +With single augument `scale` of `real` or `complex` type the function returns a scalar uniformly distributed variate of `real` or `complex` type on [0, scale]. The real part and imaginary part of a `complex` type are independent of each other. -With double auguments `loc` and `scale` the function returns a scalar uniformly distributed random variates of `integer`, `real` or `complex` type on [loc, loc + scale] dependent of input type. If it is `complex` augument, the real part and imaginary part are independent of each other. Function is elemental. +With double auguments `loc` and `scale` the function returns a scalar uniformly distributed random variates of `integer`, `real` or `complex` type on [loc, loc + scale] dependent of input type. If it is `complex` augument, the real part and imaginary part are independent of each other. With triple auguments `loc`, `scale` and `array_size` the function returns a rank one array of uniformly distributed variates of `integer`, `real` or `complex` type with an array size of `array_size`. @@ -88,6 +90,7 @@ With triple auguments `loc`, `scale` and `array_size` the function returns a ran `result = [[stdlib_stats_distribution_uniform(module):uniform_distribution_rvs(interface)]]([[loc,] scale] [[[,array_size]]])` ### Class + Elemental function. ### Arguments From 5dbad35f1552ea1fe4142a00c554302716933814 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 18:14:14 -0400 Subject: [PATCH 100/172] Update src/stdlib_stats_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/stdlib_stats_distribution_uniform.fypp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index 92f48577b..e196dc68d 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -455,7 +455,6 @@ Module stdlib_stats_distribution_uniform elseif(r2 .and. i2)then res = 1.0 end if - return end function unif_dist_cdf_${t1[0]}$${k1}$ #:endfor From 8b9d16d754a0750291f7ff793387ca7b20b4ed32 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 18:14:29 -0400 Subject: [PATCH 101/172] Update src/stdlib_stats_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/stdlib_stats_distribution_uniform.fypp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index e196dc68d..33fc5f3b9 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -474,7 +474,6 @@ Module stdlib_stats_distribution_uniform res(i) = res(j) res(j) = tmp end do - return end function shuffle_${t1[0]}$${k1}$ #:endfor From 06174e462850d1083ef00775d70a503dad9eddd2 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 18:15:00 -0400 Subject: [PATCH 102/172] Update src/tests/stats/test_distribution_uniform.f90 Co-authored-by: Jeremie Vandenplas --- src/tests/stats/test_distribution_uniform.f90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/stats/test_distribution_uniform.f90 b/src/tests/stats/test_distribution_uniform.f90 index b77371192..7b1f46df0 100644 --- a/src/tests/stats/test_distribution_uniform.f90 +++ b/src/tests/stats/test_distribution_uniform.f90 @@ -1,6 +1,6 @@ program test_distribution_uniform use stdlib_error, only : check - use stdlib_kinds + use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, qp use stdlib_stats_distribution_PRNG, only : random_seed, dist_rand use stdlib_stats_distribution_uniform, & uni_rvs => uniform_distribution_rvs, & @@ -852,4 +852,4 @@ subroutine test_uni_cdf_cqp end subroutine test_uni_cdf_cqp -end program test_distribution_uniform \ No newline at end of file +end program test_distribution_uniform From 0a00a03a4ae9ea7787f3868a66de8df14d5b41cb Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 18:20:00 -0400 Subject: [PATCH 103/172] Update stdlib_stats_distribution_uniform.md --- .../stdlib_stats_distribution_uniform.md | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index b40e0d199..c19c442b7 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -201,14 +201,20 @@ Experimental The probability density function of the uniform distribution. -f(x) = 1 / (scale + 1); for discrete uniform distribution -f(x) = 1 / scale; for continuous uniform distribution -f(x) = 1 / (scale%re * scale%im); for complex uniform distribution +f(x) = 1 / (scale + 1); for discrete uniform distribution. + +f(x) = 1 / scale; for continuous uniform distribution. + +f(x) = 1 / (scale%re * scale%im); for complex uniform distribution. ### Syntax `result = [[stdlib_stats_distribution_uniform(module):uniform_distribution_pdf(interface)]](x, loc, scale)` +### Class + +Elemental function. + ### Arguments `x`: has `intent(in)` and is a scalar of type `integer`, `real` or `complex`. @@ -217,7 +223,7 @@ f(x) = 1 / (scale%re * scale%im); for complex uniform distribution `scale`: has `intent(in)` and is a scalar of type `integer`, `real` or `complex`. -The function is elemental, i.e., all three auguments could be arrays conformable to each other. All three arguments must have the same type and kind. +All three auguments could be arrays conformable to each other. All three arguments must have the same type and kind. ### Return value @@ -289,14 +295,20 @@ Experimental Cumulative distribution function of the uniform distribution -F(x) = (x - loc + 1) / (scale + 1); for discrete uniform distribution -F(x) = (x - loc) / scale; for continuous uniform distribution -F(x) = (x%re - loc%re)(x%im - loc%im) / (scale%re * scale%im); for complex uniform distribution +F(x) = (x - loc + 1) / (scale + 1); for discrete uniform distribution. + +F(x) = (x - loc) / scale; for continuous uniform distribution. + +F(x) = (x%re - loc%re)(x%im - loc%im) / (scale%re * scale%im); for complex uniform distribution. ### Syntax `result = [[stdlib_stats_distribution_uniform(module):uniform_distribution_cdf(interface)]](x, loc, scale)` +### Class + +Elemental function. + ### Arguments `x`: has `intent(in)` and is a scalar of type `integer`, `real` or `complex`. @@ -305,7 +317,7 @@ F(x) = (x%re - loc%re)(x%im - loc%im) / (scale%re * scale%im); for complex unifo `scale`: has `intent(in)` and is a scalar of type `integer`, `real` or `complex`. -The function is elemental, i.e., all three auguments could be arrays conformable to each other. All three arguments must have the same type and kind. +All three auguments could be arrays conformable to each other. All three arguments must have the same type and kind. ### Return value From 193a9c5031ac9f9227ffc26d015f3aa6fbe35022 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 18:26:32 -0400 Subject: [PATCH 104/172] Update test_distribution_uniform.f90 --- src/tests/stats/test_distribution_uniform.f90 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tests/stats/test_distribution_uniform.f90 b/src/tests/stats/test_distribution_uniform.f90 index 7b1f46df0..d0a519ff9 100644 --- a/src/tests/stats/test_distribution_uniform.f90 +++ b/src/tests/stats/test_distribution_uniform.f90 @@ -52,9 +52,8 @@ program test_distribution_uniform call test_uni_cdf_csp call test_uni_cdf_cdp call test_uni_cdf_cqp - stop - contains +contains subroutine test_shuffle integer :: n(10), na(10) = [10, 6, 9, 2, 8, 1, 3, 5, 7, 4] From 93acc2c8c7a821984d5f94d8dced1216dca795ef Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 19:08:42 -0400 Subject: [PATCH 105/172] Update stdlib_stats_distribution_uniform.fypp --- src/stdlib_stats_distribution_uniform.fypp | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index 33fc5f3b9..57e688aff 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -108,7 +108,6 @@ Module stdlib_stats_distribution_uniform bits_left = bits_left - bits end do L2 end do L1 - return end function unif_dist_rvs_1_${t1[0]}$${k1}$ #:endfor @@ -124,7 +123,6 @@ Module stdlib_stats_distribution_uniform if(scale <= 0_${k1}$) call error_stop("Error(unif_dist_rvs): Uniform" & //" distribution scale parameter must be positive") res = loc + unif_dist_rvs_1_${t1[0]}$${k1}$(scale) - return end function unif_dist_rvs_${t1[0]}$${k1}$ #:endfor @@ -141,7 +139,6 @@ Module stdlib_stats_distribution_uniform tmp = shiftr(dist_rand(INT_ONE), 11) ! Get random from [0,2^53-1] res = real(tmp * MESENNE_NUMBER, kind =${k1}$) ! convert to [0,1] - return end function unif_dist_rvs_0_${t1[0]}$${k1}$ #:endfor @@ -156,7 +153,6 @@ Module stdlib_stats_distribution_uniform if(scale == 0._${k1}$) call error_stop("Error(unif_dist_rvs_1): " & //"Uniform distribution scale parameter must be non-zero") res = scale * unif_dist_rvs_0_${t1[0]}$${k1}$( ) - return end function unif_dist_rvs_1_${t1[0]}$${k1}$ #:endfor @@ -172,7 +168,6 @@ Module stdlib_stats_distribution_uniform if(scale == 0._${k1}$) call error_stop("Error(unif_dist_rvs): " & //"Uniform distribution scale parameter must be non-zero") res = loc + scale * unif_dist_rvs_0_${t1[0]}$${k1}$( ) - return end function unif_dist_rvs_${t1[0]}$${k1}$ #:endfor @@ -202,7 +197,6 @@ Module stdlib_stats_distribution_uniform ti = aimag(scale) * r2 endif res = cmplx(tr, ti, kind=${k1}$) - return end function unif_dist_rvs_1_${t1[0]}$${k1}$ #:endfor @@ -234,7 +228,6 @@ Module stdlib_stats_distribution_uniform ti = aimag(loc) + aimag(scale) * r2 endif res = cmplx(tr, ti, kind=${k1}$) - return end function unif_dist_rvs_${t1[0]}$${k1}$ #:endfor @@ -271,7 +264,6 @@ Module stdlib_stats_distribution_uniform end do L1 res(i) = loc + nn end do - return end function unif_dist_rvs_array_${t1[0]}$${k1}$ #:endfor @@ -295,7 +287,6 @@ Module stdlib_stats_distribution_uniform t = real(tmp * MESENNE_NUMBER, kind = ${k1}$) res(i) = loc + scale * t enddo - return end function unif_dist_rvs_array_${t1[0]}$${k1}$ #:endfor @@ -330,8 +321,7 @@ Module stdlib_stats_distribution_uniform ti = aimag(loc) + aimag(scale) * r2 endif res(i) = cmplx(tr, ti, kind=${k1}$) - enddo - return + end do end function unif_dist_rvs_array_${t1[0]}$${k1}$ #:endfor @@ -348,7 +338,6 @@ Module stdlib_stats_distribution_uniform else res = 1. / (scale + 1_${k1}$) end if - return end function unif_dist_pdf_${t1[0]}$${k1}$ #:endfor @@ -365,7 +354,6 @@ Module stdlib_stats_distribution_uniform else res = 1.0 / scale end if - return end function unif_dist_pdf_${t1[0]}$${k1}$ #:endfor @@ -385,7 +373,6 @@ Module stdlib_stats_distribution_uniform else res = 0.0 end if - return end function unif_dist_pdf_${t1[0]}$${k1}$ #:endfor @@ -404,7 +391,6 @@ Module stdlib_stats_distribution_uniform else res = 1.0 end if - return end function unif_dist_cdf_${t1[0]}$${k1}$ #:endfor @@ -423,7 +409,6 @@ Module stdlib_stats_distribution_uniform else res = 1.0 end if - return end function unif_dist_cdf_${t1[0]}$${k1}$ #:endfor From c2dac0e95fa69e4fa5194d438a084b2811b44b20 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 19:18:45 -0400 Subject: [PATCH 106/172] Update Makefile.manual --- src/tests/Makefile.manual | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/Makefile.manual b/src/tests/Makefile.manual index e8fdbc139..7ab184016 100644 --- a/src/tests/Makefile.manual +++ b/src/tests/Makefile.manual @@ -6,6 +6,7 @@ all test clean: $(MAKE) -f Makefile.manual --directory=io $@ $(MAKE) -f Makefile.manual --directory=logger $@ $(MAKE) -f Makefile.manual --directory=optval $@ + $(MAKE) -f Makefile.manual --directory=sorting $@ $(MAKE) -f Makefile.manual --directory=quadrature $@ $(MAKE) -f Makefile.manual --directory=stats $@ $(MAKE) -f Makefile.manual --directory=string $@ From 231bd35313d29fc0142cac03e8205c75705c5b95 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 19:20:39 -0400 Subject: [PATCH 107/172] Delete Makefile.manual --- src/tests/Makefile.manual | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 src/tests/Makefile.manual diff --git a/src/tests/Makefile.manual b/src/tests/Makefile.manual deleted file mode 100644 index 7ab184016..000000000 --- a/src/tests/Makefile.manual +++ /dev/null @@ -1,13 +0,0 @@ -.PHONY: all clean test - -all test clean: - $(MAKE) -f Makefile.manual --directory=ascii $@ - $(MAKE) -f Makefile.manual --directory=bitsets $@ - $(MAKE) -f Makefile.manual --directory=io $@ - $(MAKE) -f Makefile.manual --directory=logger $@ - $(MAKE) -f Makefile.manual --directory=optval $@ - $(MAKE) -f Makefile.manual --directory=sorting $@ - $(MAKE) -f Makefile.manual --directory=quadrature $@ - $(MAKE) -f Makefile.manual --directory=stats $@ - $(MAKE) -f Makefile.manual --directory=string $@ - $(MAKE) -f Makefile.manual --directory=math $@ From b9091e01e9836300123dd08ac98aec3db8e50fa2 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 19:21:47 -0400 Subject: [PATCH 108/172] Create Makefile.manual --- src/tests/Makefile.manual | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/tests/Makefile.manual diff --git a/src/tests/Makefile.manual b/src/tests/Makefile.manual new file mode 100644 index 000000000..7ab184016 --- /dev/null +++ b/src/tests/Makefile.manual @@ -0,0 +1,13 @@ +.PHONY: all clean test + +all test clean: + $(MAKE) -f Makefile.manual --directory=ascii $@ + $(MAKE) -f Makefile.manual --directory=bitsets $@ + $(MAKE) -f Makefile.manual --directory=io $@ + $(MAKE) -f Makefile.manual --directory=logger $@ + $(MAKE) -f Makefile.manual --directory=optval $@ + $(MAKE) -f Makefile.manual --directory=sorting $@ + $(MAKE) -f Makefile.manual --directory=quadrature $@ + $(MAKE) -f Makefile.manual --directory=stats $@ + $(MAKE) -f Makefile.manual --directory=string $@ + $(MAKE) -f Makefile.manual --directory=math $@ From 8214d74c47377fb71fad3263ab0da6de9a19aad4 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 19:27:16 -0400 Subject: [PATCH 109/172] Update Makefile.manual --- src/tests/stats/Makefile.manual | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/tests/stats/Makefile.manual b/src/tests/stats/Makefile.manual index a1a3451cf..cf8e3d295 100644 --- a/src/tests/stats/Makefile.manual +++ b/src/tests/stats/Makefile.manual @@ -1,4 +1,12 @@ -PROGS_SRC = test_mean.f90 test_moment.f90 test_var.f90 \ +SRCFYPP =\ + test_median.fypp \ + +SRCGEN = $(SRCFYPP:.fypp=.f90) + +$(SRCGEN): %.f90: %.fypp common.fypp + fypp $(FYPPFLAGS) $< $@ + +PROGS_SRC = $(SRCGEN) test_mean.f90 test_moment.f90 test_var.f90 \ test_distribution_PRNG.f90 include ../Makefile.manual.test.mk From 6e3aca5a3703ed82547efd60d39fdd892a2e1467 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 19:30:19 -0400 Subject: [PATCH 110/172] Delete CMakeLists.txt --- src/tests/stats/CMakeLists.txt | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 src/tests/stats/CMakeLists.txt diff --git a/src/tests/stats/CMakeLists.txt b/src/tests/stats/CMakeLists.txt deleted file mode 100644 index 38f9bb84b..000000000 --- a/src/tests/stats/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -ADDTEST(corr) -ADDTEST(cov) -ADDTEST(mean) -ADDTEST(moment) -ADDTEST(rawmoment) -ADDTEST(var) -ADDTEST(varn) -ADDTEST(distribution_PRNG) - -if(DEFINED CMAKE_MAXIMUM_RANK) - if(${CMAKE_MAXIMUM_RANK} GREATER 7) - ADDTEST(mean_f03) - endif() -elseif(f03rank) - ADDTEST(mean_f03) -endif() From ed25e21d24a78092bfd5b5e0810ed18afc671ee7 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 19:30:26 -0400 Subject: [PATCH 111/172] Delete Makefile.manual --- src/tests/stats/Makefile.manual | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 src/tests/stats/Makefile.manual diff --git a/src/tests/stats/Makefile.manual b/src/tests/stats/Makefile.manual deleted file mode 100644 index cf8e3d295..000000000 --- a/src/tests/stats/Makefile.manual +++ /dev/null @@ -1,12 +0,0 @@ -SRCFYPP =\ - test_median.fypp \ - -SRCGEN = $(SRCFYPP:.fypp=.f90) - -$(SRCGEN): %.f90: %.fypp common.fypp - fypp $(FYPPFLAGS) $< $@ - -PROGS_SRC = $(SRCGEN) test_mean.f90 test_moment.f90 test_var.f90 \ - test_distribution_PRNG.f90 - -include ../Makefile.manual.test.mk From cfbee660f2817c4e13bdcf1237a33c51bdee51e9 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 19:40:34 -0400 Subject: [PATCH 112/172] Create CMakeLists.txt --- src/tests/stats/CMakeLists.txt | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/tests/stats/CMakeLists.txt diff --git a/src/tests/stats/CMakeLists.txt b/src/tests/stats/CMakeLists.txt new file mode 100644 index 000000000..600e925e5 --- /dev/null +++ b/src/tests/stats/CMakeLists.txt @@ -0,0 +1,35 @@ +### Pre-process: .fpp -> .f90 via Fypp + +# Create a list of the files to be preprocessed +set(fppFiles + test_median.fypp +) + +# Custom preprocessor flags +if(DEFINED CMAKE_MAXIMUM_RANK) + set(fyppFlags "-DMAXRANK=${CMAKE_MAXIMUM_RANK}") +elseif(f03rank) + set(fyppFlags) +else() + set(fyppFlags "-DVERSION90") +endif() + +fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) + +ADDTEST(corr) +ADDTEST(cov) +ADDTEST(mean) +ADDTEST(median) +ADDTEST(moment) +ADDTEST(rawmoment) +ADDTEST(var) +ADDTEST(varn) +ADDTEST(distribution_PRNG) + +if(DEFINED CMAKE_MAXIMUM_RANK) + if(${CMAKE_MAXIMUM_RANK} GREATER 7) + ADDTEST(mean_f03) + endif() +elseif(f03rank) + ADDTEST(mean_f03) +endif() From 58394f119eeeb78db10837251d784435efe748d3 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 19:41:42 -0400 Subject: [PATCH 113/172] Create Makefile.manual --- src/tests/stats/Makefile.manual | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/tests/stats/Makefile.manual diff --git a/src/tests/stats/Makefile.manual b/src/tests/stats/Makefile.manual new file mode 100644 index 000000000..55a21c5f4 --- /dev/null +++ b/src/tests/stats/Makefile.manual @@ -0,0 +1,12 @@ +SRCFYPP =\ + test_median.fypp + +SRCGEN = $(SRCFYPP:.fypp=.f90) + +$(SRCGEN): %.f90: %.fypp common.fypp + fypp $(FYPPFLAGS) $< $@ + +PROGS_SRC = $(SRCGEN) test_mean.f90 test_moment.f90 test_var.f90 \ + test_distribution_PRNG.f90 + +include ../Makefile.manual.test.mk From cd061f608555cf3683fb014c16192205926fe432 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 19:44:08 -0400 Subject: [PATCH 114/172] Delete test_distribution_uniform.f90 --- src/tests/stats/test_distribution_uniform.f90 | 854 ------------------ 1 file changed, 854 deletions(-) delete mode 100644 src/tests/stats/test_distribution_uniform.f90 diff --git a/src/tests/stats/test_distribution_uniform.f90 b/src/tests/stats/test_distribution_uniform.f90 deleted file mode 100644 index d0a519ff9..000000000 --- a/src/tests/stats/test_distribution_uniform.f90 +++ /dev/null @@ -1,854 +0,0 @@ -program test_distribution_uniform - use stdlib_error, only : check - use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, qp - use stdlib_stats_distribution_PRNG, only : random_seed, dist_rand - use stdlib_stats_distribution_uniform, & - uni_rvs => uniform_distribution_rvs, & - uni_pdf => uniform_distribution_pdf, & - uni_cdf => uniform_distribution_cdf - - implicit none - logical :: warn = .true. - real(sp), parameter :: sptol = 1000 * epsilon(1.0_sp) - real(dp), parameter :: dptol = 1000 * epsilon(1.0_dp) - real(qp), parameter :: qptol = 1000 * epsilon(1.0_qp) - integer :: put, get - - put = 135792468 - - call test_shuffle - - call test_uni_rvs_0 - - call test_uni_rvs_iint8 - call test_uni_rvs_iint16 - call test_uni_rvs_iint32 - call test_uni_rvs_iint64 - call test_uni_rvs_rsp - call test_uni_rvs_rdp - call test_uni_rvs_rqp - call test_uni_rvs_csp - call test_uni_rvs_cdp - call test_uni_rvs_cqp - - call test_uni_pdf_iint8 - call test_uni_pdf_iint16 - call test_uni_pdf_iint32 - call test_uni_pdf_iint64 - call test_uni_pdf_rsp - call test_uni_pdf_rdp - call test_uni_pdf_rqp - call test_uni_pdf_csp - call test_uni_pdf_cdp - call test_uni_pdf_cqp - - call test_uni_cdf_iint8 - call test_uni_cdf_iint16 - call test_uni_cdf_iint32 - call test_uni_cdf_iint64 - call test_uni_cdf_rsp - call test_uni_cdf_rdp - call test_uni_cdf_rqp - call test_uni_cdf_csp - call test_uni_cdf_cdp - call test_uni_cdf_cqp - -contains - - subroutine test_shuffle - integer :: n(10), na(10) = [10, 6, 9, 2, 8, 1, 3, 5, 7, 4] - real :: x(10), xa(10)= [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, & - 7.0, 6.0] - complex :: z(10), za(10)=[(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), & - (1.0, 1.0), (5.0, 5.0), (9.0, 9.0), & - (6.0, 6.0), (3.0, 3.0), (2.0, 2.0), & - (10.0, 10.0)] - integer :: i, put, get - - do i=1, 10 - n(i) = i - x(i) = real(i) - z(i) = cmplx(real(i),real(i)) - end do - put = 32165498 - call random_seed(put, get) - n(:) = shuffle(n) - x(:) = shuffle(x) - z(:) = shuffle(z) - call check(all(n == na), & - msg="Integer shuffle failed test", warn=warn) - call check(all(x == xa), & - msg="Real shuffle failed test", warn=warn) - call check(all(z == za), & - msg="Complex shuffle failed test", warn=warn) - end subroutine test_shuffle - - subroutine test_uni_rvs_0 - integer :: i, j, freq(0:1000), num=10000000 - real(dp) :: chisq, expct - - print *,"" - print *, "Test uniform random generator with chi-squared" - freq = 0 - do i = 1, num - j = 1000 * uni_rvs( ) - freq(j) = freq(j) + 1 - end do - chisq = 0.0_dp - expct = num / 1000 - do i = 0, 999 - chisq = chisq + (freq(i) - expct) ** 2 / expct - end do - write(*,*) "The critical values for chi-squared with 1000 d. of f. are" & - //" 1143.92" - write(*,*) "Chi-squared for uniform random generator is : ", chisq - call check((chisq < 1143.9) , & - msg="uniform randomness failed chi-squared test", warn=warn) - end subroutine test_uni_rvs_0 - - subroutine test_uni_rvs_iint8 - integer(int8) :: res(15), scale, loc - integer :: i, n, seed, get, k - - integer(int8) :: ans(15) = [47, 99, 43, 37, 48, 30, 27, 100, 30, 33, 21, & - 103, 55, 54, 110] - - print *, "Test uniform_distribution_rvs_iint8" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = 15_int8; scale = 100_int8 - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(res == ans), & - msg="uniform_distribution_rvs_iint8 failed", warn=warn) - end subroutine test_uni_rvs_iint8 - - subroutine test_uni_rvs_iint16 - integer(int16) :: res(15), scale, loc - integer :: i, n, seed, get, k - - integer(int16) :: ans(15) = [25, 4, 81, 98, 49, 34, 32, 62, 115, 112, 26, & - 20, 37, 100, 82] - - print *, "Test uniform_distribution_rvs_iint16" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = 15_int16; scale = 100_int16 - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(res == ans), & - msg="uniform_distribution_rvs_iint16 failed", warn=warn) - end subroutine test_uni_rvs_iint16 - - subroutine test_uni_rvs_iint32 - integer(int32) :: res(15), scale, loc - integer :: i, n, seed, get, k - - integer(int32) :: ans(15) = [19, 52, 56, 20, 59, 44, 34, 102, 19, 39, 60, & - 50, 97, 56, 67] - - print *, "Test uniform_distribution_rvs_iint32" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = 15_int32; scale = 100_int32 - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(res == ans), & - msg="uniform_distribution_rvs_iint32 failed", warn=warn) - end subroutine test_uni_rvs_iint32 - - subroutine test_uni_rvs_iint64 - integer(int64) :: res(15), scale, loc - integer :: i, n, seed, get, k - - integer(int64) :: ans(15) = [76, 45, 43, 75, 76, 15, 25, 24, 114, 113, 94, & - 29, 109, 93, 89] - - print *, "Test uniform_distribution_rvs_iint64" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = 15_int64; scale = 100_int64 - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(res == ans), & - msg="uniform_distribution_rvs_iint64 failed", warn=warn) - end subroutine test_uni_rvs_iint64 - - subroutine test_uni_rvs_rsp - real(sp) :: res(15), scale, loc - integer :: i, n, seed, get, k - - real(sp) :: ans(15) = & - [0.914826628538749186958511927514337003_sp, & - 0.367330098664966409049981166390352882_sp, & - 1.77591243057709280428468900936422870_sp, & - 0.885921308987590139238932351872790605_sp, & - 0.950735656542987861428173346212133765_sp, & - -0.659562573857055134407545438079978339_sp, & - -0.116661718506947176265953203255776316_sp, & - 0.837391893893859151631886561517603695_sp, & - -0.703954396598600540269075054311542772_sp, & - 0.382592729851141566399519433616660535_sp, & - -0.132472493978185168472805344208609313_sp, & - -0.878723366294216184924081858298450243_sp, & - -0.901660046141515819639877804547722917_sp, & - -0.164090614147737401395943379611708224_sp, & - -0.333886718190384290672056977200554684_sp] - - print *, "Test uniform_distribution_rvs_rsp" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = -1.0_sp; scale = 2.0_sp - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(res - ans) < sptol), & - msg="uniform_distribution_rvs_rsp failed", warn=warn) - end subroutine test_uni_rvs_rsp - - subroutine test_uni_rvs_rdp - real(dp) :: res(15), scale, loc - integer :: i, n, seed, get, k - - real(dp) :: ans(15) = & - [0.914826628538749186958511927514337003_dp, & - 0.367330098664966409049981166390352882_dp, & - 1.77591243057709280428468900936422870_dp, & - 0.885921308987590139238932351872790605_dp, & - 0.950735656542987861428173346212133765_dp, & - -0.659562573857055134407545438079978339_dp, & - -0.116661718506947176265953203255776316_dp, & - 0.837391893893859151631886561517603695_dp, & - -0.703954396598600540269075054311542772_dp, & - 0.382592729851141566399519433616660535_dp, & - -0.132472493978185168472805344208609313_dp, & - -0.878723366294216184924081858298450243_dp, & - -0.901660046141515819639877804547722917_dp, & - -0.164090614147737401395943379611708224_dp, & - -0.333886718190384290672056977200554684_dp] - - print *, "Test uniform_distribution_rvs_rdp" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = -1.0_dp; scale = 2.0_dp - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(res - ans) < dptol), & - msg="uniform_distribution_rvs_rdp failed", warn=warn) - end subroutine test_uni_rvs_rdp - - subroutine test_uni_rvs_rqp - real(qp) :: res(15), scale, loc - integer :: i, n, seed, get, k - - real(qp) :: ans(15) = & - [0.914826628538749186958511927514337003_qp, & - 0.367330098664966409049981166390352882_qp, & - 1.77591243057709280428468900936422870_qp, & - 0.885921308987590139238932351872790605_qp, & - 0.950735656542987861428173346212133765_qp, & - -0.659562573857055134407545438079978339_qp, & - -0.116661718506947176265953203255776316_qp, & - 0.837391893893859151631886561517603695_qp, & - -0.703954396598600540269075054311542772_qp, & - 0.382592729851141566399519433616660535_qp, & - -0.132472493978185168472805344208609313_qp, & - -0.878723366294216184924081858298450243_qp, & - -0.901660046141515819639877804547722917_qp, & - -0.164090614147737401395943379611708224_qp, & - -0.333886718190384290672056977200554684_qp] - - print *, "Test uniform_distribution_rvs_rqp" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = -1.0_qp; scale = 2.0_qp - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(res - ans) < qptol), & - msg="uniform_distribution_rvs_rqp failed", warn=warn) - end subroutine test_uni_rvs_rqp - - subroutine test_uni_rvs_csp - complex(sp) :: res(15), scale, loc - integer :: i, n, seed, get, k - - complex(sp) :: ans(15) = [(0.457413314269374593479255963757168502_sp, & - 0.183665049332483204524990583195176441_sp), & - (0.887956215288546402142344504682114348_sp, & - 0.442960654493795069619466175936395302_sp), & - (0.475367828271493930714086673106066883_sp, & - 0.170218713071472432796227280960010830_sp), & - (0.441669140746526411867023398372111842_sp, & - 0.918695946946929575815943280758801848_sp), & - (0.148022801700699729865462472844228614_sp, & - 0.691296364925570783199759716808330268_sp), & - (-6.623624698909258423640267210430465639E-0002_sp, & - 0.560638316852891907537959070850774879_sp), & - (-0.450830023070757909819938902273861459_sp, & - 0.917954692926131299302028310194145888_sp), & - (-0.166943359095192145336028488600277342_sp, & - 1.05997401970850635422038976685144007_sp), & - (-0.429652190199228276035192664039641386_sp, & - 0.523558274341032421628217008446881664_sp), & - (0.427181091476823815433760955784237012_sp, & - 1.34628934976074521312483511792379431_sp), & - (-0.343281426018765739582860874179459643_sp, & - 1.15357331316264255516301773241139017_sp), & - (-0.127590074749816595467422075671493076_sp, & - 1.06891199479835175001340985545539297_sp), & - (0.262287586904722758163188700564205647_sp, & - 1.29508919831907332032017166056903079_sp), & - (-0.192677407376582732201342196276527829_sp, & - 1.32794925614337933073016984053538181_sp), & - (-0.264742129752461530234342035328154452_sp, & - 1.01282963412172621886497836385387927_sp)] - - print *, "Test uniform_distribution_rvs_csp" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = (-0.5_sp,0.5_sp); scale = (1.0_sp, 1.0_sp) - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(real(res) - real(ans)) < sptol) .and. & - all(abs(aimag(res) - aimag(ans)) < sptol), & - msg="uniform_distribution_rvs_csp failed", warn=warn) - end subroutine test_uni_rvs_csp - - subroutine test_uni_rvs_cdp - complex(dp) :: res(15), scale, loc - integer :: i, n, seed, get, k - - complex(dp) :: ans(15) = [(0.457413314269374593479255963757168502_dp, & - 0.183665049332483204524990583195176441_dp), & - (0.887956215288546402142344504682114348_dp, & - 0.442960654493795069619466175936395302_dp), & - (0.475367828271493930714086673106066883_dp, & - 0.170218713071472432796227280960010830_dp), & - (0.441669140746526411867023398372111842_dp, & - 0.918695946946929575815943280758801848_dp), & - (0.148022801700699729865462472844228614_dp, & - 0.691296364925570783199759716808330268_dp), & - (-6.623624698909258423640267210430465639E-0002_dp, & - 0.560638316852891907537959070850774879_dp), & - (-0.450830023070757909819938902273861459_dp, & - 0.917954692926131299302028310194145888_dp), & - (-0.166943359095192145336028488600277342_dp, & - 1.05997401970850635422038976685144007_dp), & - (-0.429652190199228276035192664039641386_dp, & - 0.523558274341032421628217008446881664_dp), & - (0.427181091476823815433760955784237012_dp, & - 1.34628934976074521312483511792379431_dp), & - (-0.343281426018765739582860874179459643_dp, & - 1.15357331316264255516301773241139017_dp), & - (-0.127590074749816595467422075671493076_dp, & - 1.06891199479835175001340985545539297_dp), & - (0.262287586904722758163188700564205647_dp, & - 1.29508919831907332032017166056903079_dp), & - (-0.192677407376582732201342196276527829_dp, & - 1.32794925614337933073016984053538181_dp), & - (-0.264742129752461530234342035328154452_dp, & - 1.01282963412172621886497836385387927_dp)] - - print *, "Test uniform_distribution_rvs_cdp" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = (-0.5_dp,0.5_dp); scale = (1.0_dp, 1.0_dp) - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(real(res) - real(ans)) < dptol) .and. & - all(abs(aimag(res) - aimag(ans)) < dptol), & - msg="uniform_distribution_rvs_cdp failed", warn=warn) - end subroutine test_uni_rvs_cdp - - subroutine test_uni_rvs_cqp - complex(qp) :: res(15), scale, loc - integer :: i, n, seed, get, k - - complex(qp) :: ans(15) = [(0.457413314269374593479255963757168502_qp, & - 0.183665049332483204524990583195176441_qp), & - (0.887956215288546402142344504682114348_qp, & - 0.442960654493795069619466175936395302_qp), & - (0.475367828271493930714086673106066883_qp, & - 0.170218713071472432796227280960010830_qp), & - (0.441669140746526411867023398372111842_qp, & - 0.918695946946929575815943280758801848_qp), & - (0.148022801700699729865462472844228614_qp, & - 0.691296364925570783199759716808330268_qp), & - (-6.623624698909258423640267210430465639E-0002_qp, & - 0.560638316852891907537959070850774879_qp), & - (-0.450830023070757909819938902273861459_qp, & - 0.917954692926131299302028310194145888_qp), & - (-0.166943359095192145336028488600277342_qp, & - 1.05997401970850635422038976685144007_qp), & - (-0.429652190199228276035192664039641386_qp, & - 0.523558274341032421628217008446881664_qp), & - (0.427181091476823815433760955784237012_qp, & - 1.34628934976074521312483511792379431_qp), & - (-0.343281426018765739582860874179459643_qp, & - 1.15357331316264255516301773241139017_qp), & - (-0.127590074749816595467422075671493076_qp, & - 1.06891199479835175001340985545539297_qp), & - (0.262287586904722758163188700564205647_qp, & - 1.29508919831907332032017166056903079_qp), & - (-0.192677407376582732201342196276527829_qp, & - 1.32794925614337933073016984053538181_qp), & - (-0.264742129752461530234342035328154452_qp, & - 1.01282963412172621886497836385387927_qp)] - - print *, "Test uniform_distribution_rvs_cqp" - seed = 258147369; k = 5 - call random_seed(seed, get) - loc = (-0.5_qp,0.5_qp); scale = (1.0_qp, 1.0_qp) - do i=1, 5 - res(i) = uni_rvs(scale) ! 1 dummy - end do - do i=6,10 - res(i) = uni_rvs(loc, scale) ! 2 dummies - end do - res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - call check(all(abs(real(res) - real(ans)) < qptol) .and. & - all(abs(aimag(res) - aimag(ans)) < qptol), & - msg="uniform_distribution_rvs_cqp failed", warn=warn) - end subroutine test_uni_rvs_cqp - - - subroutine test_uni_pdf_iint8 - integer(int8) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(1.96078438E-02, i=1,15)] - - print *, "Test uniform_distribution_pdf_iint8" - seed = 147258639 - call random_seed(seed, get) - loc = 0_int8; scale = 50_int8 - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_iint8 failed", warn=warn) - end subroutine test_uni_pdf_iint8 - - subroutine test_uni_pdf_iint16 - integer(int16) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(1.96078438E-02, i=1,15)] - - print *, "Test uniform_distribution_pdf_iint16" - seed = 147258639 - call random_seed(seed, get) - loc = 0_int16; scale = 50_int16 - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_iint16 failed", warn=warn) - end subroutine test_uni_pdf_iint16 - - subroutine test_uni_pdf_iint32 - integer(int32) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(1.96078438E-02, i=1,15)] - - print *, "Test uniform_distribution_pdf_iint32" - seed = 147258639 - call random_seed(seed, get) - loc = 0_int32; scale = 50_int32 - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_iint32 failed", warn=warn) - end subroutine test_uni_pdf_iint32 - - subroutine test_uni_pdf_iint64 - integer(int64) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(1.96078438E-02, i=1,15)] - - print *, "Test uniform_distribution_pdf_iint64" - seed = 147258639 - call random_seed(seed, get) - loc = 0_int64; scale = 50_int64 - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_iint64 failed", warn=warn) - end subroutine test_uni_pdf_iint64 - - subroutine test_uni_pdf_rsp - real(sp) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(0.5, i=1,15)] - - print *, "Test uniform_distribution_pdf_rsp" - seed = 147258639 - call random_seed(seed, get) - loc = 0.0_sp; scale = 2.0_sp - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_rsp failed", warn=warn) - end subroutine test_uni_pdf_rsp - - subroutine test_uni_pdf_rdp - real(dp) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(0.5, i=1,15)] - - print *, "Test uniform_distribution_pdf_rdp" - seed = 147258639 - call random_seed(seed, get) - loc = 0.0_dp; scale = 2.0_dp - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_rdp failed", warn=warn) - end subroutine test_uni_pdf_rdp - - subroutine test_uni_pdf_rqp - real(qp) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(0.5, i=1,15)] - - print *, "Test uniform_distribution_pdf_rqp" - seed = 147258639 - call random_seed(seed, get) - loc = 0.0_qp; scale = 2.0_qp - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_rqp failed", warn=warn) - end subroutine test_uni_pdf_rqp - - subroutine test_uni_pdf_csp - complex(sp) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(1.0, i=1,15)] - - print *, "Test uniform_distribution_pdf_csp" - seed = 147258639 - call random_seed(seed, get) - loc = (-0.5_sp, 0.5_sp); scale = (1.0_sp, 1.0_sp) - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_csp failed", warn=warn) - end subroutine test_uni_pdf_csp - - subroutine test_uni_pdf_cdp - complex(dp) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(1.0, i=1,15)] - - print *, "Test uniform_distribution_pdf_cdp" - seed = 147258639 - call random_seed(seed, get) - loc = (-0.5_dp, 0.5_dp); scale = (1.0_dp, 1.0_dp) - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_cdp failed", warn=warn) - end subroutine test_uni_pdf_cdp - - subroutine test_uni_pdf_cqp - complex(qp) :: x1, x2(3,4), loc, scale - integer :: seed, get, i - real :: res(3,5) - real :: ans(15) = [(1.0, i=1,15)] - - print *, "Test uniform_distribution_pdf_cqp" - seed = 147258639 - call random_seed(seed, get) - loc = (-0.5_qp, 0.5_qp); scale = (1.0_qp, 1.0_qp) - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_pdf(x1, loc, scale) - res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_cqp failed", warn=warn) - end subroutine test_uni_pdf_cqp - - - subroutine test_uni_cdf_iint8 - integer(int8) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [0.435643554, 0.435643554, 0.435643554, 0.702970326, & - 0.653465331, 0.485148519, 0.386138618, 0.386138618, & - 0.336633652, 0.277227730, 0.237623766, 0.524752498, & - 0.732673287, 0.534653485, 0.415841579] - - print *, "Test uniform_distribution_cdf_iint8" - seed = 369147258 - call random_seed(seed, get) - loc = 14_int8; scale = 100_int8 - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_iint8 failed", warn=warn) - end subroutine test_uni_cdf_iint8 - - subroutine test_uni_cdf_iint16 - integer(int16) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [0.178217828, 0.178217828, 0.178217828, 0.465346545, & - 0.673267305, 0.247524753, 0.158415839, 0.792079210, & - 0.742574275, 0.574257433, 0.881188095, 0.663366318, & - 0.524752498, 0.623762369, 0.178217828] - - print *, "Test uniform_distribution_cdf_iint16" - seed = 369147258 - call random_seed(seed, get) - loc = 14_int16; scale = 100_int16 - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_iint16 failed", warn=warn) - end subroutine test_uni_cdf_iint16 - - subroutine test_uni_cdf_iint32 - integer(int32) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [0.732673287, 0.732673287, 0.732673287, 0.722772300, & - 0.792079210, 5.94059415E-02, 0.841584146,0.405940592,& - 0.960396051, 0.534653485, 0.782178223, 0.861386120, & - 0.564356446, 0.613861382, 0.306930691] - - print *, "Test uniform_distribution_cdf_iint32" - seed = 369147258 - call random_seed(seed, get) - loc = 14_int32; scale = 100_int32 - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_iint32 failed", warn=warn) - end subroutine test_uni_cdf_iint32 - - subroutine test_uni_cdf_iint64 - integer(int64) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [0.455445558, 0.455445558, 0.455445558, 0.277227730, & - 0.455445558, 0.930693090, 0.851485133, 0.623762369, & - 5.94059415E-02,0.693069279, 0.544554472, 0.207920790,& - 0.306930691, 0.356435657, 0.128712878] - - print *, "Test uniform_distribution_cdf_iint64" - seed = 369147258 - call random_seed(seed, get) - loc = 14_int64; scale = 100_int64 - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_iint64 failed", warn=warn) - end subroutine test_uni_cdf_iint64 - - subroutine test_uni_cdf_rsp - real(sp) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [0.170192942, 0.170192942, 0.170192942, 0.276106149, & - 0.754930079, 0.406620681, 0.187742814, 0.651605546, & - 0.934733927, 0.151271492, 0.987674534, 0.130533904, & - 0.106271908, 9.27578658E-02, 0.203399420] - - print *, "Test uniform_distribution_cdf_rsp" - seed = 369147258 - call random_seed(seed, get) - loc = 0.0_sp; scale = 2.0_sp - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_rsp failed", warn=warn) - end subroutine test_uni_cdf_rsp - - subroutine test_uni_cdf_rdp - real(dp) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [0.170192942, 0.170192942, 0.170192942, 0.276106149, & - 0.754930079, 0.406620681, 0.187742814, 0.651605546, & - 0.934733927, 0.151271492, 0.987674534, 0.130533904, & - 0.106271908, 9.27578658E-02, 0.203399420] - - print *, "Test uniform_distribution_cdf_rdp" - seed = 369147258 - call random_seed(seed, get) - loc = 0.0_dp; scale = 2.0_dp - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_rdp failed", warn=warn) - end subroutine test_uni_cdf_rdp - - subroutine test_uni_cdf_rqp - real(qp) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [0.170192942, 0.170192942, 0.170192942, 0.276106149, & - 0.754930079, 0.406620681, 0.187742814, 0.651605546, & - 0.934733927, 0.151271492, 0.987674534, 0.130533904, & - 0.106271908, 9.27578658E-02, 0.203399420] - - print *, "Test uniform_distribution_cdf_rqp" - seed = 369147258 - call random_seed(seed, get) - loc = 0.0_qp; scale = 2.0_qp - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_rqp failed", warn=warn) - end subroutine test_uni_cdf_rqp - - subroutine test_uni_cdf_csp - complex(sp) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [4.69913185E-02, 4.69913185E-02, 4.69913185E-02, & - 0.306970179, 0.122334257, 0.141398594, 0.128925011, & - 9.85755492E-03, 8.16527531E-02, 0.163921610, & - 7.81712309E-02, 0.446415812, 5.31753292E-04, & - 0.101455867, 0.155276477] - - print *, "Test uniform_distribution_cdf_csp" - seed = 369147258 - call random_seed(seed, get) - loc = (-0.5_sp, -0.5_sp); scale = (1.0_sp, 1.0_sp) - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_csp failed", warn=warn) - end subroutine test_uni_cdf_csp - - subroutine test_uni_cdf_cdp - complex(dp) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [4.69913185E-02, 4.69913185E-02, 4.69913185E-02, & - 0.306970179, 0.122334257, 0.141398594, 0.128925011, & - 9.85755492E-03, 8.16527531E-02, 0.163921610, & - 7.81712309E-02, 0.446415812, 5.31753292E-04, & - 0.101455867, 0.155276477] - - print *, "Test uniform_distribution_cdf_cdp" - seed = 369147258 - call random_seed(seed, get) - loc = (-0.5_dp, -0.5_dp); scale = (1.0_dp, 1.0_dp) - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_cdp failed", warn=warn) - end subroutine test_uni_cdf_cdp - - subroutine test_uni_cdf_cqp - complex(qp) :: x1, x2(3,4), loc, scale - real :: res(3,5) - integer :: seed, get - real :: ans(15) = [4.69913185E-02, 4.69913185E-02, 4.69913185E-02, & - 0.306970179, 0.122334257, 0.141398594, 0.128925011, & - 9.85755492E-03, 8.16527531E-02, 0.163921610, & - 7.81712309E-02, 0.446415812, 5.31753292E-04, & - 0.101455867, 0.155276477] - - print *, "Test uniform_distribution_cdf_cqp" - seed = 369147258 - call random_seed(seed, get) - loc = (-0.5_qp, -0.5_qp); scale = (1.0_qp, 1.0_qp) - x1 = uni_rvs(loc, scale) - x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) - res(:,1) = uni_cdf(x1, loc, scale) - res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_cqp failed", warn=warn) - end subroutine test_uni_cdf_cqp - - -end program test_distribution_uniform From 230c1c6f1a56125acc4dfb82935af05537382f8b Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 19:44:52 -0400 Subject: [PATCH 115/172] Add files via upload --- .../stats/test_distribution_uniform.fypp | 282 ++++++++++++++++++ 1 file changed, 282 insertions(+) create mode 100644 src/tests/stats/test_distribution_uniform.fypp diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp new file mode 100644 index 000000000..9b8b22588 --- /dev/null +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -0,0 +1,282 @@ +#:include "common.fypp" +#:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES +#:set ALL_KINDS_TYPES = INT_KINDS_TYPES + RC_KINDS_TYPES +program test_distribution_uniform + use stdlib_error, only : check + use stdlib_kinds + use stdlib_stats_distribution_PRNG, only : random_seed, dist_rand + use stdlib_stats_distribution_uniform, & + uni_rvs => uniform_distribution_rvs, & + uni_pdf => uniform_distribution_pdf, & + uni_cdf => uniform_distribution_cdf + + implicit none + logical :: warn = .true. + #:for k1, t1 in REAL_KINDS_TYPES + ${t1}$, parameter :: ${k1}$tol = 1000 * epsilon(1.0_${k1}$) + #:endfor + integer :: put, get + + put = 135792468 + + call test_shuffle + + call test_uni_rvs_0 + + #:for k1, t1 in ALL_KINDS_TYPES + call test_uni_rvs_${t1[0]}$${k1}$ + #:endfor + + #:for k1, t1 in ALL_KINDS_TYPES + call test_uni_pdf_${t1[0]}$${k1}$ + #:endfor + + #:for k1, t1 in ALL_KINDS_TYPES + call test_uni_cdf_${t1[0]}$${k1}$ + #:endfor + stop + + contains + + subroutine test_shuffle + integer :: n(10), na(10) = [10, 6, 9, 2, 8, 1, 3, 5, 7, 4] + real :: x(10), xa(10)= [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, & + 7.0, 6.0] + complex :: z(10), za(10)=[(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), & + (1.0, 1.0), (5.0, 5.0), (9.0, 9.0), & + (6.0, 6.0), (3.0, 3.0), (2.0, 2.0), & + (10.0, 10.0)] + integer :: i, put, get + + do i=1, 10 + n(i) = i + x(i) = real(i) + z(i) = cmplx(real(i),real(i)) + end do + put = 32165498 + call random_seed(put, get) + n(:) = shuffle(n) + x(:) = shuffle(x) + z(:) = shuffle(z) + call check(all(n == na), & + msg="Integer shuffle failed test", warn=warn) + call check(all(x == xa), & + msg="Real shuffle failed test", warn=warn) + call check(all(z == za), & + msg="Complex shuffle failed test", warn=warn) + end subroutine test_shuffle + + subroutine test_uni_rvs_0 + integer :: i, j, freq(0:1000), num=10000000 + real(dp) :: chisq, expct + + print *,"" + print *, "Test uniform random generator with chi-squared" + freq = 0 + do i = 1, num + j = 1000 * uni_rvs( ) + freq(j) = freq(j) + 1 + end do + chisq = 0.0_dp + expct = num / 1000 + do i = 0, 999 + chisq = chisq + (freq(i) - expct) ** 2 / expct + end do + write(*,*) "The critical values for chi-squared with 1000 d. of f. are" & + //" 1143.92" + write(*,*) "Chi-squared for uniform random generator is : ", chisq + call check((chisq < 1143.9) , & + msg="uniform randomness failed chi-squared test", warn=warn) + end subroutine test_uni_rvs_0 + + #:for k1, t1 in ALL_KINDS_TYPES + subroutine test_uni_rvs_${t1[0]}$${k1}$ + ${t1}$ :: res(15), scale, loc + integer :: i, n, seed, get, k + + #:if k1 == "int8" + ${t1}$ :: ans(15) = [47, 99, 43, 37, 48, 30, 27, 100, 30, 33, 21, & + 103, 55, 54, 110] + #:elif k1 == "int16" + ${t1}$ :: ans(15) = [25, 4, 81, 98, 49, 34, 32, 62, 115, 112, 26, & + 20, 37, 100, 82] + #:elif k1 == "int32" + ${t1}$ :: ans(15) = [19, 52, 56, 20, 59, 44, 34, 102, 19, 39, 60, & + 50, 97, 56, 67] + #:elif k1 == "int64" + ${t1}$ :: ans(15) = [76, 45, 43, 75, 76, 15, 25, 24, 114, 113, 94, & + 29, 109, 93, 89] + #:elif t1[0] == "r" + ${t1}$ :: ans(15) = & + [0.914826628538749186958511927514337003_${k1}$, & + 0.367330098664966409049981166390352882_${k1}$, & + 1.77591243057709280428468900936422870_${k1}$, & + 0.885921308987590139238932351872790605_${k1}$, & + 0.950735656542987861428173346212133765_${k1}$, & + -0.659562573857055134407545438079978339_${k1}$, & + -0.116661718506947176265953203255776316_${k1}$, & + 0.837391893893859151631886561517603695_${k1}$, & + -0.703954396598600540269075054311542772_${k1}$, & + 0.382592729851141566399519433616660535_${k1}$, & + -0.132472493978185168472805344208609313_${k1}$, & + -0.878723366294216184924081858298450243_${k1}$, & + -0.901660046141515819639877804547722917_${k1}$, & + -0.164090614147737401395943379611708224_${k1}$, & + -0.333886718190384290672056977200554684_${k1}$] + #:else + ${t1}$ :: ans(15) = [(0.457413314269374593479255963757168502_${k1}$, & + 0.183665049332483204524990583195176441_${k1}$), & + (0.887956215288546402142344504682114348_${k1}$, & + 0.442960654493795069619466175936395302_${k1}$), & + (0.475367828271493930714086673106066883_${k1}$, & + 0.170218713071472432796227280960010830_${k1}$), & + (0.441669140746526411867023398372111842_${k1}$, & + 0.918695946946929575815943280758801848_${k1}$), & + (0.148022801700699729865462472844228614_${k1}$, & + 0.691296364925570783199759716808330268_${k1}$), & + (-6.623624698909258423640267210430465639E-0002_${k1}$, & + 0.560638316852891907537959070850774879_${k1}$), & + (-0.450830023070757909819938902273861459_${k1}$, & + 0.917954692926131299302028310194145888_${k1}$), & + (-0.166943359095192145336028488600277342_${k1}$, & + 1.05997401970850635422038976685144007_${k1}$), & + (-0.429652190199228276035192664039641386_${k1}$, & + 0.523558274341032421628217008446881664_${k1}$), & + (0.427181091476823815433760955784237012_${k1}$, & + 1.34628934976074521312483511792379431_${k1}$), & + (-0.343281426018765739582860874179459643_${k1}$, & + 1.15357331316264255516301773241139017_${k1}$), & + (-0.127590074749816595467422075671493076_${k1}$, & + 1.06891199479835175001340985545539297_${k1}$), & + (0.262287586904722758163188700564205647_${k1}$, & + 1.29508919831907332032017166056903079_${k1}$), & + (-0.192677407376582732201342196276527829_${k1}$, & + 1.32794925614337933073016984053538181_${k1}$), & + (-0.264742129752461530234342035328154452_${k1}$, & + 1.01282963412172621886497836385387927_${k1}$)] + #:endif + + print *, "Test uniform_distribution_rvs_${t1[0]}$${k1}$" + seed = 258147369; k = 5 + call random_seed(seed, get) + #:if t1[0] == "i" + loc = 15_${k1}$; scale = 100_${k1}$ + #:elif t1[0] == "r" + loc = -1.0_${k1}$; scale = 2.0_${k1}$ + #:else + loc = (-0.5_${k1}$,0.5_${k1}$); scale = (1.0_${k1}$, 1.0_${k1}$) + #:endif + do i=1, 5 + res(i) = uni_rvs(scale) ! 1 dummy + end do + do i=6,10 + res(i) = uni_rvs(loc, scale) ! 2 dummies + end do + res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies + #:if t1[0] == "i" + call check(all(res == ans), & + msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) + #:elif t1[0] == "r" + call check(all(abs(res - ans) < ${k1}$tol), & + msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) + #:else + call check(all(abs(real(res) - real(ans)) < ${k1}$tol) .and. & + all(abs(aimag(res) - aimag(ans)) < ${k1}$tol), & + msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) + #:endif + end subroutine test_uni_rvs_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in ALL_KINDS_TYPES + subroutine test_uni_pdf_${t1[0]}$${k1}$ + ${t1}$ :: x1, x2(3,4), loc, scale + integer :: seed, get, i + real :: res(3,5) + #:if t1[0] == "i" + real :: ans(15) = [(1.96078438E-02, i=1,15)] + #:elif t1[0] == "r" + real :: ans(15) = [(0.5, i=1,15)] + #:else + real :: ans(15) = [(1.0, i=1,15)] + #:endif + + print *, "Test uniform_distribution_pdf_${t1[0]}$${k1}$" + seed = 147258639 + call random_seed(seed, get) + #:if t1[0] == "i" + loc = 0_${k1}$; scale = 50_${k1}$ + #:elif t1[0] == "r" + loc = 0.0_${k1}$; scale = 2.0_${k1}$ + #:else + loc = (-0.5_${k1}$, 0.5_${k1}$); scale = (1.0_${k1}$, 1.0_${k1}$) + #:endif + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_pdf(x1, loc, scale) + res(:, 2:5) = uni_pdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_pdf_${t1[0]}$${k1}$ failed", warn=warn) + end subroutine test_uni_pdf_${t1[0]}$${k1}$ + + #:endfor + + #:for k1, t1 in ALL_KINDS_TYPES + subroutine test_uni_cdf_${t1[0]}$${k1}$ + ${t1}$ :: x1, x2(3,4), loc, scale + real :: res(3,5) + integer :: seed, get + #:if k1 == "int8" + real :: ans(15) = [0.435643554, 0.435643554, 0.435643554, 0.702970326, & + 0.653465331, 0.485148519, 0.386138618, 0.386138618, & + 0.336633652, 0.277227730, 0.237623766, 0.524752498, & + 0.732673287, 0.534653485, 0.415841579] + #:elif k1 == "int16" + real :: ans(15) = [0.178217828, 0.178217828, 0.178217828, 0.465346545, & + 0.673267305, 0.247524753, 0.158415839, 0.792079210, & + 0.742574275, 0.574257433, 0.881188095, 0.663366318, & + 0.524752498, 0.623762369, 0.178217828] + #:elif k1 == "int32" + real :: ans(15) = [0.732673287, 0.732673287, 0.732673287, 0.722772300, & + 0.792079210, 5.94059415E-02, 0.841584146,0.405940592,& + 0.960396051, 0.534653485, 0.782178223, 0.861386120, & + 0.564356446, 0.613861382, 0.306930691] + #:elif k1 == "int64" + real :: ans(15) = [0.455445558, 0.455445558, 0.455445558, 0.277227730, & + 0.455445558, 0.930693090, 0.851485133, 0.623762369, & + 5.94059415E-02,0.693069279, 0.544554472, 0.207920790,& + 0.306930691, 0.356435657, 0.128712878] + #:elif t1[0] == "r" + real :: ans(15) = [0.170192942, 0.170192942, 0.170192942, 0.276106149, & + 0.754930079, 0.406620681, 0.187742814, 0.651605546, & + 0.934733927, 0.151271492, 0.987674534, 0.130533904, & + 0.106271908, 9.27578658E-02, 0.203399420] + #:else + real :: ans(15) = [4.69913185E-02, 4.69913185E-02, 4.69913185E-02, & + 0.306970179, 0.122334257, 0.141398594, 0.128925011, & + 9.85755492E-03, 8.16527531E-02, 0.163921610, & + 7.81712309E-02, 0.446415812, 5.31753292E-04, & + 0.101455867, 0.155276477] + #:endif + + print *, "Test uniform_distribution_cdf_${t1[0]}$${k1}$" + seed = 369147258 + call random_seed(seed, get) + #:if t1[0] == "i" + loc = 14_${k1}$; scale = 100_${k1}$ + #:elif t1[0] == "r" + loc = 0.0_${k1}$; scale = 2.0_${k1}$ + #:else + loc = (-0.5_${k1}$, -0.5_${k1}$); scale = (1.0_${k1}$, 1.0_${k1}$) + #:endif + x1 = uni_rvs(loc, scale) + x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) + res(:,1) = uni_cdf(x1, loc, scale) + res(:, 2:5) = uni_cdf(x2, loc, scale) + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + msg="uniform_distribution_cdf_${t1[0]}$${k1}$ failed", warn=warn) + end subroutine test_uni_cdf_${t1[0]}$${k1}$ + + #:endfor + +end program test_distribution_uniform \ No newline at end of file From 635cc7bdb383ca1cceccea6406c47b64e6f78571 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 19:50:39 -0400 Subject: [PATCH 116/172] Update index.md --- doc/specs/index.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/specs/index.md b/doc/specs/index.md index f3dbd85c5..cc804bd31 100644 --- a/doc/specs/index.md +++ b/doc/specs/index.md @@ -11,21 +11,21 @@ This is and index/directory of the specifications (specs) for each new module/fe ## Experimental Features & Modules + - [ascii](./stdlib_ascii.html) - Procedures for handling ASCII characters - [bitsets](./stdlib_bitsets.html) - Bitset data types and procedures - [error](./stdlib_error.html) - Catching and handling errors - [IO](./stdlib_io.html) - Input/output helper & convenience + - [kinds](./stdlib_kinds.html) - Kind parameters - [linalg](./stdlib_linalg.html) - Linear Algebra - [logger](./stdlib_logger.html) - Runtime logging system + - [math](./stdlib_math.html) - General purpose mathematical functions - [optval](./stdlib_optval.html) - Fallback value for optional arguments - [quadrature](./stdlib_quadrature.html) - Numerical integration + - [sorting](./stdlib_sorting.html) - Sorting of rank one arrays - [stats](./stdlib_stats.html) - Descriptive Statistics - [stats_distribution_PRNG](./stdlib_stats_distribution_PRNG.html) - Probability Distributions random number generator - - [stats_distribution_uniform](./stdlib_stats_distribution_uniform.html) - Uniform probability distribution - -## Missing specs - - - [ascii](https://github.com/fortran-lang/stdlib/blob/master/src/stdlib_ascii.f90) - - [kinds](https://github.com/fortran-lang/stdlib/blob/master/src/stdlib_kinds.f90) + - [string\_type](./stdlib_string_type.html) - Basic string support + - [strings](./stdlib_strings.html) - String handling and manipulation routines ## Released/Stable Features & Modules From 50d04e27925c1b85317162640764d408ebd41577 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 19:51:25 -0400 Subject: [PATCH 117/172] Update CMakeLists.txt --- src/CMakeLists.txt | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f8aa14128..c4f6d76e7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,17 +2,24 @@ # Create a list of the files to be preprocessed set(fppFiles + stdlib_ascii.fypp stdlib_bitsets.fypp stdlib_bitsets_64.fypp stdlib_bitsets_large.fypp stdlib_io.fypp stdlib_linalg.fypp stdlib_linalg_diag.fypp + stdlib_linalg_outer_product.fypp stdlib_optval.fypp + stdlib_sorting.fypp + stdlib_sorting_ord_sort.fypp + stdlib_sorting_sort.fypp + stdlib_sorting_sort_index.fypp stdlib_stats.fypp stdlib_stats_corr.fypp stdlib_stats_cov.fypp stdlib_stats_mean.fypp + stdlib_stats_median.fypp stdlib_stats_moment.fypp stdlib_stats_moment_all.fypp stdlib_stats_moment_mask.fypp @@ -22,7 +29,10 @@ set(fppFiles stdlib_quadrature_trapz.fypp stdlib_quadrature_simps.fypp stdlib_stats_distribution_PRNG.fypp - stdlib_stats_distribution_uniform.fypp + stdlib_math.fypp + stdlib_math_linspace.fypp + stdlib_math_logspace.fypp + stdlib_string_type.fypp ) @@ -38,11 +48,14 @@ endif() fypp_f90("${fyppFlags}" "${fppFiles}" outFiles) set(SRC - stdlib_ascii.f90 stdlib_error.f90 stdlib_kinds.f90 stdlib_logger.f90 + stdlib_strings.f90 stdlib_system.F90 + stdlib_specialfunctions.f90 + stdlib_specialfunctions_legendre.f90 + stdlib_quadrature_gauss.f90 ${outFiles} ) @@ -53,7 +66,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES Fortran_MODULE_DIRECTORY ${LIB_MOD_DIR}) target_include_directories(${PROJECT_NAME} PUBLIC $ - $ + $ ) if(f18errorstop) @@ -70,4 +83,4 @@ install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ) -install(DIRECTORY ${LIB_MOD_DIR} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") +install(DIRECTORY ${LIB_MOD_DIR} DESTINATION "${CMAKE_INSTALL_MODULEDIR}") From 8eac7f1fdb5a81915588068f7dc33e8f25ce67c0 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 19:51:53 -0400 Subject: [PATCH 118/172] Update Makefile.manual --- src/Makefile.manual | 56 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/src/Makefile.manual b/src/Makefile.manual index fb1f84166..a12f81255 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -1,31 +1,45 @@ SRCFYPP =\ + stdlib_ascii.fypp \ stdlib_bitsets_64.fypp \ stdlib_bitsets_large.fypp \ stdlib_bitsets.fypp \ stdlib_io.fypp \ stdlib_linalg.fypp \ stdlib_linalg_diag.fypp \ + stdlib_linalg_outer_product.fypp \ stdlib_optval.fypp \ stdlib_quadrature.fypp \ stdlib_quadrature_trapz.fypp \ stdlib_quadrature_simps.fypp \ + stdlib_sorting.fypp \ + stdlib_sorting_ord_sort.fypp \ + stdlib_sorting_sort.fypp \ + stdlib_sorting_sort_index.fypp \ stdlib_stats.fypp \ stdlib_stats_corr.fypp \ stdlib_stats_cov.fypp \ stdlib_stats_mean.fypp \ + stdlib_stats_median.fypp \ stdlib_stats_moment.fypp \ stdlib_stats_moment_all.fypp \ stdlib_stats_moment_mask.fypp \ stdlib_stats_moment_scalar.fypp \ stdlib_stats_var.fypp \ - stdlib_stats_distribution_PRNG.fypp \ - stdlib_stats_distribution_uniform.fypp + stdlib_math.fypp \ + stdlib_math_linspace.fypp \ + stdlib_math_logspace.fypp \ + stdlib_stats_distribution_PRNG.fypp \ + stdlib_string_type.fypp SRC = f18estop.f90 \ - stdlib_ascii.f90 \ stdlib_error.f90 \ + stdlib_specialfunctions.f90 \ + stdlib_specialfunctions_legendre.f90 \ + stdlib_io.f90 \ stdlib_kinds.f90 \ stdlib_logger.f90 \ + stdlib_quadrature_gauss.f90 \ + stdlib_strings.f90 \ $(SRCGEN) LIB = libstdlib.a @@ -54,11 +68,15 @@ $(SRCGEN): %.f90: %.fypp common.fypp # Fortran module dependencies f18estop.o: stdlib_error.o +stdlib_ascii.o: stdlib_kinds.o stdlib_bitsets.o: stdlib_kinds.o stdlib_bitsets_64.o: stdlib_bitsets.o stdlib_bitsets_large.o: stdlib_bitsets.o stdlib_error.o: stdlib_optval.o +stdlib_specialfunctions.o: stdlib_kinds.o +stdlib_specialfunctions_legendre.o: stdlib_kinds.o stdlib_specialfunctions.o stdlib_io.o: \ + stdlib_ascii.o \ stdlib_error.o \ stdlib_optval.o \ stdlib_kinds.o @@ -70,6 +88,9 @@ stdlib_linalg_diag.o: \ stdlib_logger.o: stdlib_ascii.o stdlib_optval.o stdlib_optval.o: stdlib_kinds.o stdlib_quadrature.o: stdlib_kinds.o + +stdlib_quadrature_gauss.o: stdlib_kinds.o stdlib_quadrature.o + stdlib_quadrature_simps.o: \ stdlib_quadrature.o \ stdlib_error.o \ @@ -78,6 +99,15 @@ stdlib_quadrature_trapz.o: \ stdlib_quadrature.o \ stdlib_error.o \ stdlib_kinds.o +stdlib_sorting.o: \ + stdlib_kinds.o \ + stdlib_string_type.o +stdlib_sorting_ord_sort.o: \ + stdlib_sorting.o +stdlib_sorting_sort.o: \ + stdlib_sorting.o +stdlib_sorting_sort_index.o: \ + stdlib_sorting.o stdlib_stats.o: \ stdlib_kinds.o stdlib_stats_corr.o: \ @@ -92,6 +122,11 @@ stdlib_stats_mean.o: \ stdlib_optval.o \ stdlib_kinds.o \ stdlib_stats.o +stdlib_stats_median.o: \ + stdlib_optval.o \ + stdlib_kinds.o \ + stdlib_sorting.o \ + stdlib_stats.o stdlib_stats_moment.o: \ stdlib_optval.o \ stdlib_kinds.o \ @@ -109,7 +144,14 @@ stdlib_stats_var.o: \ stdlib_stats_distribution_PRNG.o: \ stdlib_kinds.o \ stdlib_error.o -stdlib_stats_distribution_uniform.o: \ - stdlib_kinds.o \ - stdlib_error.o \ - stdlib_stats_distribution_PRNG.o +stdlib_string_type.o: stdlib_ascii.o \ + stdlib_kinds.o +stdlib_strings.o: stdlib_ascii.o \ + stdlib_string_type.o \ + stdlib_optval.o +stdlib_math.o: stdlib_kinds.o +stdlib_math_linspace.o: \ + stdlib_math.o +stdlib_math_logspace.o: \ + stdlib_math_linspace.o +stdlib_linalg_outer_product.o: stdlib_linalg.o From 732714211fba0c8f4ce30d3fe6a56151f67d68c8 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 19:52:49 -0400 Subject: [PATCH 119/172] Update Makefile.manual --- src/tests/stats/Makefile.manual | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/tests/stats/Makefile.manual b/src/tests/stats/Makefile.manual index 66713a3cb..55a21c5f4 100644 --- a/src/tests/stats/Makefile.manual +++ b/src/tests/stats/Makefile.manual @@ -1,4 +1,12 @@ -PROGS_SRC = test_mean.f90 test_moment.f90 test_var.f90 \ - test_distribution_PRNG.f90 test_distribution_uniform.f90 +SRCFYPP =\ + test_median.fypp + +SRCGEN = $(SRCFYPP:.fypp=.f90) + +$(SRCGEN): %.f90: %.fypp common.fypp + fypp $(FYPPFLAGS) $< $@ + +PROGS_SRC = $(SRCGEN) test_mean.f90 test_moment.f90 test_var.f90 \ + test_distribution_PRNG.f90 include ../Makefile.manual.test.mk From 14a7e0956f57324f331ff60beacfb6b4ed99c46e Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 19:54:24 -0400 Subject: [PATCH 120/172] Update CMakeLists.txt --- src/tests/stats/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/stats/CMakeLists.txt b/src/tests/stats/CMakeLists.txt index f9e5e94a9..14fed4167 100644 --- a/src/tests/stats/CMakeLists.txt +++ b/src/tests/stats/CMakeLists.txt @@ -3,6 +3,7 @@ # Create a list of the files to be preprocessed set(fppFiles test_median.fypp + test_distribution_uniform.fypp ) # Custom preprocessor flags From 5c2e5da63cf6de16a82c9e009547e88650806fc5 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 19:54:53 -0400 Subject: [PATCH 121/172] Update Makefile.manual --- src/tests/stats/Makefile.manual | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tests/stats/Makefile.manual b/src/tests/stats/Makefile.manual index 55a21c5f4..2274db12b 100644 --- a/src/tests/stats/Makefile.manual +++ b/src/tests/stats/Makefile.manual @@ -1,5 +1,6 @@ SRCFYPP =\ - test_median.fypp + test_median.fypp \ + test_distribution_uniform.fypp SRCGEN = $(SRCFYPP:.fypp=.f90) From ad23f64295f006bdc52815ed69ce1b65e7390429 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 20:15:38 -0400 Subject: [PATCH 122/172] Update common.fypp --- src/tests/stats/common.fypp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/tests/stats/common.fypp b/src/tests/stats/common.fypp index 9ebaac6b9..b8a51460f 100644 --- a/src/tests/stats/common.fypp +++ b/src/tests/stats/common.fypp @@ -18,6 +18,14 @@ #! Collected (kind, type) tuples for integer types #:set INT_KINDS_TYPES = list(zip(INT_KINDS, INT_TYPES)) +#! Complex kinds to be considered during templating +#:set CMPLX_KINDS = ["sp", "dp", "qp"] + +#! Complex types to be considered during templating +#:set CMPLX_TYPES = ["complex({})".format(k) for k in CMPLX_KINDS] + +#! Collected (kind, type) tuples for complex types +#:set CMPLX_KINDS_TYPES = list(zip(CMPLX_KINDS, CMPLX_TYPES)) #! Whether Fortran 90 compatible code should be generated #:set VERSION90 = defined('VERSION90') From d963f0994e522e9b7e0c5c934ea7840425e665f6 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 20:25:52 -0400 Subject: [PATCH 123/172] Update CMakeLists.txt --- src/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c4f6d76e7..b9f5b905c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,6 +29,7 @@ set(fppFiles stdlib_quadrature_trapz.fypp stdlib_quadrature_simps.fypp stdlib_stats_distribution_PRNG.fypp + stdlib_stats_distribution_uniform.fypp stdlib_math.fypp stdlib_math_linspace.fypp stdlib_math_logspace.fypp From d5cba5b016c3b794b53962044743ce7dab37e57d Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Fri, 30 Jul 2021 20:28:11 -0400 Subject: [PATCH 124/172] Update Makefile.manual --- src/Makefile.manual | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Makefile.manual b/src/Makefile.manual index a12f81255..a9247338c 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -29,6 +29,7 @@ SRCFYPP =\ stdlib_math_linspace.fypp \ stdlib_math_logspace.fypp \ stdlib_stats_distribution_PRNG.fypp \ + stdlib_stats_distribution_uniform.fypp \ stdlib_string_type.fypp SRC = f18estop.f90 \ @@ -144,6 +145,10 @@ stdlib_stats_var.o: \ stdlib_stats_distribution_PRNG.o: \ stdlib_kinds.o \ stdlib_error.o +stdlib_stats_distribution_uniform.o: \ + stdlib_kinds.o \ + stdlib_error.o \ + stdlib_stats_distribution_PRNG.o stdlib_string_type.o: stdlib_ascii.o \ stdlib_kinds.o stdlib_strings.o: stdlib_ascii.o \ From 669fc99ede02c51f6bc3c4c379033894be33da70 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sat, 31 Jul 2021 15:47:07 -0400 Subject: [PATCH 125/172] Update src/tests/stats/test_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/tests/stats/test_distribution_uniform.fypp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index 9b8b22588..dad97f415 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -3,7 +3,7 @@ #:set ALL_KINDS_TYPES = INT_KINDS_TYPES + RC_KINDS_TYPES program test_distribution_uniform use stdlib_error, only : check - use stdlib_kinds + use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, qp use stdlib_stats_distribution_PRNG, only : random_seed, dist_rand use stdlib_stats_distribution_uniform, & uni_rvs => uniform_distribution_rvs, & @@ -279,4 +279,4 @@ program test_distribution_uniform #:endfor -end program test_distribution_uniform \ No newline at end of file +end program test_distribution_uniform From 464fa31566086fb94ee282d8b96b7bee7eb593d1 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sat, 31 Jul 2021 15:47:38 -0400 Subject: [PATCH 126/172] Update src/tests/stats/test_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/tests/stats/test_distribution_uniform.fypp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index dad97f415..5fd6aca5a 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -40,7 +40,7 @@ program test_distribution_uniform subroutine test_shuffle integer :: n(10), na(10) = [10, 6, 9, 2, 8, 1, 3, 5, 7, 4] - real :: x(10), xa(10)= [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, & + real :: x(10), xa(10) = [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, & 7.0, 6.0] complex :: z(10), za(10)=[(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), & (1.0, 1.0), (5.0, 5.0), (9.0, 9.0), & From bc8a0533d77860e70a1459c589013cb989510343 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sat, 31 Jul 2021 15:47:51 -0400 Subject: [PATCH 127/172] Update src/tests/stats/test_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/tests/stats/test_distribution_uniform.fypp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index 5fd6aca5a..6ab739159 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -42,7 +42,7 @@ program test_distribution_uniform integer :: n(10), na(10) = [10, 6, 9, 2, 8, 1, 3, 5, 7, 4] real :: x(10), xa(10) = [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, & 7.0, 6.0] - complex :: z(10), za(10)=[(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), & + complex :: z(10), za(10) = [(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), & (1.0, 1.0), (5.0, 5.0), (9.0, 9.0), & (6.0, 6.0), (3.0, 3.0), (2.0, 2.0), & (10.0, 10.0)] From c70b9204cf0a752d89702342c79b7189257ed2f4 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sat, 31 Jul 2021 16:20:55 -0400 Subject: [PATCH 128/172] Update src/tests/stats/test_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/tests/stats/test_distribution_uniform.fypp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index 6ab739159..730c90fcb 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -1,6 +1,5 @@ #:include "common.fypp" -#:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES -#:set ALL_KINDS_TYPES = INT_KINDS_TYPES + RC_KINDS_TYPES +#:set ALL_KINDS_TYPES = INT_KINDS_TYPES + REAL_KINDS_TYPES + CMPLX_KINDS_TYPES program test_distribution_uniform use stdlib_error, only : check use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, qp From 75a66b2ab16e3f9c033f846ba763832412ee87cd Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 09:11:15 -0400 Subject: [PATCH 129/172] Update src/stdlib_stats_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/stdlib_stats_distribution_uniform.fypp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index 57e688aff..83faf2482 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -1,7 +1,7 @@ #:include "common.fypp" #:set RC_KINDS_TYPES = REAL_KINDS_TYPES + CMPLX_KINDS_TYPES #:set ALL_KINDS_TYPES = INT_KINDS_TYPES + RC_KINDS_TYPES -Module stdlib_stats_distribution_uniform +module stdlib_stats_distribution_uniform use stdlib_kinds use stdlib_error, only : error_stop use stdlib_stats_distribution_PRNG, only : dist_rand From 61718ab20b4f61d6c82d7012835fce9109dd921e Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 09:20:12 -0400 Subject: [PATCH 130/172] Update src/stdlib_stats_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/stdlib_stats_distribution_uniform.fypp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index 83faf2482..b0a5a8aa0 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -138,7 +138,7 @@ module stdlib_stats_distribution_uniform integer(int64) :: tmp tmp = shiftr(dist_rand(INT_ONE), 11) ! Get random from [0,2^53-1] - res = real(tmp * MESENNE_NUMBER, kind =${k1}$) ! convert to [0,1] + res = real(tmp * MESENNE_NUMBER, kind = ${k1}$) ! convert to [0,1] end function unif_dist_rvs_0_${t1[0]}$${k1}$ #:endfor From 9849dcdeb7da2ffe62cec6c7413dfc42858a13a3 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 09:31:32 -0400 Subject: [PATCH 131/172] Update src/stdlib_stats_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/stdlib_stats_distribution_uniform.fypp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index b0a5a8aa0..ae74cf293 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -236,7 +236,7 @@ module stdlib_stats_distribution_uniform function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & result(res) ${t1}$, intent(in) :: loc, scale - ${t1}$, allocatable :: res(:) + ${t1}$ :: res(array_size) ${t1}$ :: u, mask, n, nn integer, intent(in) :: array_size integer :: i, zeros, bits_left, bits From 5d33ba7f0ea12e354b55a1eab82b831bdef8377b Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 09:33:34 -0400 Subject: [PATCH 132/172] Update src/stdlib_stats_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/stdlib_stats_distribution_uniform.fypp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index ae74cf293..e7ab9ea59 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -452,7 +452,7 @@ module stdlib_stats_distribution_uniform integer :: n, i, j n = size(list) - allocate(res(n), source=list) + res = list do i = 1, n - 1 j = uniform_distribution_rvs(n - i) + i tmp = res(i) From 5cebe3237cb1125e1d758120717ca7892742e2b9 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 09:33:56 -0400 Subject: [PATCH 133/172] Update src/stdlib_stats_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/stdlib_stats_distribution_uniform.fypp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index e7ab9ea59..a771ab32a 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -447,7 +447,7 @@ module stdlib_stats_distribution_uniform #:for k1, t1 in ALL_KINDS_TYPES function shuffle_${t1[0]}$${k1}$( list ) result(res) ${t1}$, intent(in) :: list(:) - ${t1}$, allocatable :: res(:) + ${t1}$ :: res(size(list)) ${t1}$ :: tmp integer :: n, i, j From d2117debf90231c5d836f30246f6ecec3b66262e Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 11:20:11 -0400 Subject: [PATCH 134/172] Update stdlib_stats_distribution_uniform.fypp --- src/stdlib_stats_distribution_uniform.fypp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index a771ab32a..dd5aefec4 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -235,16 +235,15 @@ module stdlib_stats_distribution_uniform #:for k1, t1 in INT_KINDS_TYPES function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & result(res) + integer, intent(in) :: array_size ${t1}$, intent(in) :: loc, scale ${t1}$ :: res(array_size) ${t1}$ :: u, mask, n, nn - integer, intent(in) :: array_size integer :: i, zeros, bits_left, bits n = scale if(n == 0_${k1}$) call error_stop("Error(unif_dist_rvs_array): Uniform" & //" distribution scale parameter must be non-zero") - allocate(res(array_size)) zeros = leadz(n) bits = bit_size(n) - zeros mask = shiftr(not(0_${k1}$), zeros) @@ -271,17 +270,16 @@ module stdlib_stats_distribution_uniform #:for k1, t1 in REAL_KINDS_TYPES function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & result(res) + integer, intent(in) :: array_size ${t1}$, intent(in) :: loc, scale - ${t1}$, allocatable :: res(:) + ${t1}$ :: res(array_size) ${t1}$ :: t - integer, intent(in) :: array_size integer(int64) :: tmp integer :: i if(scale == 0._${k1}$) call error_stop("Error(unif_dist_rvs_array):" & //" Uniform distribution scale parameter must be non-zero") - allocate(res(array_size)) do i = 1, array_size tmp = shiftr(dist_rand(INT_ONE), 11) t = real(tmp * MESENNE_NUMBER, kind = ${k1}$) @@ -294,17 +292,16 @@ module stdlib_stats_distribution_uniform #:for k1, t1 in CMPLX_KINDS_TYPES function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & result(res) + integer, intent(in) :: array_size ${t1}$, intent(in) :: loc, scale - ${t1}$, allocatable :: res(:) + ${t1}$ :: res(array_size) real(${k1}$) :: r1, r2, tr, ti - integer, intent(in) :: array_size integer(int64) :: tmp integer :: i if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(unif_dist_"& //"rvs_array): Uniform distribution scale parameter must be non-zero") - allocate(res(array_size)) do i = 1, array_size tmp = shiftr(dist_rand(INT_ONE), 11) r1 = real(tmp * MESENNE_NUMBER, kind = ${k1}$) From 615ac9519b1cbca4ebce3bed196de91158c6c4ff Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 11:38:26 -0400 Subject: [PATCH 135/172] Update stdlib_stats_distribution_uniform.fypp --- src/stdlib_stats_distribution_uniform.fypp | 68 +++++++++++----------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index dd5aefec4..47c864056 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -185,16 +185,16 @@ module stdlib_stats_distribution_uniform if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(uni_dist_" & //"rvs_1): Uniform distribution scale parameter must be non-zero") r1 = unif_dist_rvs_0_r${k1}$( ) - if(real(scale) == 0.0_${k1}$) then - ti = aimag(scale) * r1 + if(scale % re == 0.0_${k1}$) then + ti = scale % im * r1 tr = 0.0_${k1}$ - elseif(aimag(scale) == 0.0_${k1}$) then - tr = real(scale) * r1 + elseif(scale % im == 0.0_${k1}$) then + tr = scale % re * r1 ti = 0.0_${k1}$ else r2 = unif_dist_rvs_0_r${k1}$( ) - tr = real(scale) * r1 - ti = aimag(scale) * r2 + tr = scale % re * r1 + ti = scale % im * r2 endif res = cmplx(tr, ti, kind=${k1}$) end function unif_dist_rvs_1_${t1[0]}$${k1}$ @@ -216,16 +216,16 @@ module stdlib_stats_distribution_uniform if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(uni_dist_" & //"rvs): Uniform distribution scale parameter must be non-zero") r1 = unif_dist_rvs_0_r${k1}$( ) - if(real(scale) == 0.0_${k1}$) then - tr = real(loc) - ti = aimag(loc) + aimag(scale) * r1 - elseif(aimag(scale) == 0.0_${k1}$) then - tr = real(loc) + real(scale) * r1 - ti = aimag(loc) + if(scale % re == 0.0_${k1}$) then + tr = loc % re + ti = loc % im + scale % im * r1 + elseif(scale % im == 0.0_${k1}$) then + tr = loc % re + scale % re * r1 + ti = loc % im else r2 = unif_dist_rvs_0_r${k1}$( ) - tr = real(loc) + real(scale) * r1 - ti = aimag(loc) + aimag(scale) * r2 + tr = loc % re + scale % re * r1 + ti = loc % im + scale % im * r2 endif res = cmplx(tr, ti, kind=${k1}$) end function unif_dist_rvs_${t1[0]}$${k1}$ @@ -305,17 +305,17 @@ module stdlib_stats_distribution_uniform do i = 1, array_size tmp = shiftr(dist_rand(INT_ONE), 11) r1 = real(tmp * MESENNE_NUMBER, kind = ${k1}$) - if(real(scale) == 0.0_${k1}$) then - tr = real(loc) - ti = aimag(loc) + aimag(scale) * r1 - elseif(aimag(scale) == 0.0_${k1}$) then - tr = real(loc) + real(scale) * r1 - ti = aimag(loc) + if(scale % re == 0.0_${k1}$) then + tr = loc % re + ti = loc % im + scale % im * r1 + elseif(scale % im == 0.0_${k1}$) then + tr = loc % re + scale % re * r1 + ti = loc % im else tmp = shiftr(dist_rand(INT_ONE), 11) r2 = real(tmp * MESENNE_NUMBER, kind = ${k1}$) - tr = real(loc) + real(scale) * r1 - ti = aimag(loc) + aimag(scale) * r2 + tr = loc % re + scale % re * r1 + ti = loc % im + scale % im * r2 endif res(i) = cmplx(tr, ti, kind=${k1}$) end do @@ -361,12 +361,12 @@ module stdlib_stats_distribution_uniform real :: res real(${k1}$) :: tr, ti - tr = real(loc) + real(scale); ti = aimag(loc) + aimag(scale) + tr = loc % re + scale % re; ti = loc % im + scale % im if(scale == (0.0_${k1}$,0.0_${k1}$)) then res = 0.0 - elseif((real(x) >= real(loc) .and. real(x) <= tr) .and. & - (aimag(x) >= aimag(loc) .and. aimag(x) <= ti)) then - res = 1.0 / (real(scale) * aimag(scale)) + elseif((x % re >= loc % re .and. x % re <= tr) .and. & + (x % im >= loc % im .and. x % im <= ti)) then + res = 1.0 / (scale % re * scale % im) else res = 0.0 end if @@ -420,20 +420,20 @@ module stdlib_stats_distribution_uniform res = 0.0 return endif - r1 = real(x) < real(loc) - r2 = real(x) > (real(loc) + real(scale)) - i1 = aimag(x) < aimag(loc) - i2 = aimag(x) > (aimag(loc) + aimag(scale)) + r1 = x % re < loc % re + r2 = x % re > (loc % re + scale % re) + i1 = x % im < loc % im + i2 = x % im > (loc % im + scale % im) if(r1 .or. i1) then res = 0.0 elseif((.not. r1) .and. (.not. r2) .and. i2) then - res = (real(x) - real(loc)) / real(scale) + res = (x % re - loc % re) / scale % re elseif((.not. i1) .and. (.not. i2) .and. r2) then - res = (aimag(x) - aimag(loc)) / aimag(scale) + res = (x % im - loc % im) / scale % im elseif((.not. r1) .and. (.not. r2) .and. (.not. i1) .and. (.not. i2)) & then - res = (real(x) - real(loc)) * (aimag(x) - aimag(loc)) / & - (real(scale) * aimag(scale)) + res = (x % re - loc % re) * (x % im - loc % im) / & + (scale % re * scale % im) elseif(r2 .and. i2)then res = 1.0 end if From e728ae09e94e1ed75991ca7e1a26e2eca654e443 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 11:45:29 -0400 Subject: [PATCH 136/172] Update stdlib_stats_distribution_uniform.fypp --- src/stdlib_stats_distribution_uniform.fypp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index 47c864056..dd19a8646 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -180,7 +180,7 @@ module stdlib_stats_distribution_uniform ! ${t1}$, intent(in) :: scale ${t1}$ :: res - real(${k1}$) :: r1, r2, tr, ti + real(${k1}$) :: r1, tr, ti if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(uni_dist_" & //"rvs_1): Uniform distribution scale parameter must be non-zero") @@ -192,9 +192,9 @@ module stdlib_stats_distribution_uniform tr = scale % re * r1 ti = 0.0_${k1}$ else - r2 = unif_dist_rvs_0_r${k1}$( ) - tr = scale % re * r1 - ti = scale % im * r2 + tr = scale % re * r1 + r1 = unif_dist_rvs_0_r${k1}$( ) + ti = scale % im * r1 endif res = cmplx(tr, ti, kind=${k1}$) end function unif_dist_rvs_1_${t1[0]}$${k1}$ @@ -211,7 +211,7 @@ module stdlib_stats_distribution_uniform ! ${t1}$, intent(in) :: loc, scale ${t1}$ :: res - real(${k1}$) :: r1, r2, tr, ti + real(${k1}$) :: r1, tr, ti if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(uni_dist_" & //"rvs): Uniform distribution scale parameter must be non-zero") @@ -223,9 +223,9 @@ module stdlib_stats_distribution_uniform tr = loc % re + scale % re * r1 ti = loc % im else - r2 = unif_dist_rvs_0_r${k1}$( ) tr = loc % re + scale % re * r1 - ti = loc % im + scale % im * r2 + r1 = unif_dist_rvs_0_r${k1}$( ) + ti = loc % im + scale % im * r1 endif res = cmplx(tr, ti, kind=${k1}$) end function unif_dist_rvs_${t1[0]}$${k1}$ @@ -295,7 +295,7 @@ module stdlib_stats_distribution_uniform integer, intent(in) :: array_size ${t1}$, intent(in) :: loc, scale ${t1}$ :: res(array_size) - real(${k1}$) :: r1, r2, tr, ti + real(${k1}$) :: r1, tr, ti integer(int64) :: tmp integer :: i @@ -312,10 +312,10 @@ module stdlib_stats_distribution_uniform tr = loc % re + scale % re * r1 ti = loc % im else - tmp = shiftr(dist_rand(INT_ONE), 11) - r2 = real(tmp * MESENNE_NUMBER, kind = ${k1}$) tr = loc % re + scale % re * r1 - ti = loc % im + scale % im * r2 + tmp = shiftr(dist_rand(INT_ONE), 11) + r1 = real(tmp * MESENNE_NUMBER, kind = ${k1}$) + ti = loc % im + scale % im * r1 endif res(i) = cmplx(tr, ti, kind=${k1}$) end do From fecbedf7949b98b4d28caf4a897015b9d814a90e Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:03:47 -0400 Subject: [PATCH 137/172] Update doc/specs/stdlib_stats_distribution_uniform.md Co-authored-by: Jeremie Vandenplas --- doc/specs/stdlib_stats_distribution_uniform.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index c19c442b7..b393cd78d 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -6,7 +6,7 @@ title: stats_distribution [TOC] -## `shuffle` - Using Fisher-Yates algorithm to generate a random permutation of a list. +## `shuffle` - Using Fisher-Yates algorithm to generate a random permutation of a list ### Status From 4b2152d2cac1b51a5258f3a3553fbd2e8e221643 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:08:35 -0400 Subject: [PATCH 138/172] Update src/stdlib_stats_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/stdlib_stats_distribution_uniform.fypp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index dd19a8646..40e0be459 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -86,25 +86,24 @@ module stdlib_stats_distribution_uniform ! ! Fortran 90 translated from c by Jim-215-fisher ${t1}$, intent(in) :: scale - ${t1}$ :: res, u, mask, n + ${t1}$ :: res, u, mask integer :: zeros, bits_left, bits - n = scale - if(n <= 0_${k1}$) call error_stop("Error(unif_dist_rvs_1): Uniform" & + if(scale <= 0_${k1}$) call error_stop("Error(unif_dist_rvs_1): Uniform" & //" distribution scale parameter must be positive") - zeros = leadz(n) - bits = bit_size(n) - zeros + zeros = leadz(scale) + bits = bit_size(scale) - zeros mask = shiftr(not(0_${k1}$), zeros) L1 : do - u = dist_rand(n) + u = dist_rand(scale) res = iand(u, mask) - if(res <= n) exit L1 + if(res <= scale) exit L1 bits_left = zeros L2 : do if(bits_left < bits) exit L2 u = shiftr(u, bits) res = iand(u, mask) - if(res <= n) exit L1 + if(res <= scale) exit L1 bits_left = bits_left - bits end do L2 end do L1 From d21a17ce8dcd6240c4393212002f4aedaae1e16f Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:08:49 -0400 Subject: [PATCH 139/172] Update src/tests/stats/test_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/tests/stats/test_distribution_uniform.fypp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index 730c90fcb..702f5aadf 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -33,7 +33,6 @@ program test_distribution_uniform #:for k1, t1 in ALL_KINDS_TYPES call test_uni_cdf_${t1[0]}$${k1}$ #:endfor - stop contains From aaeb17ab03f6840f970fbda610f2a1459a871e42 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:10:00 -0400 Subject: [PATCH 140/172] Update src/stdlib_stats_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/stdlib_stats_distribution_uniform.fypp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index 40e0be459..f58edb52f 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -237,20 +237,19 @@ module stdlib_stats_distribution_uniform integer, intent(in) :: array_size ${t1}$, intent(in) :: loc, scale ${t1}$ :: res(array_size) - ${t1}$ :: u, mask, n, nn + ${t1}$ :: u, mask, nn integer :: i, zeros, bits_left, bits - n = scale - if(n == 0_${k1}$) call error_stop("Error(unif_dist_rvs_array): Uniform" & + if(scale == 0_${k1}$) call error_stop("Error(unif_dist_rvs_array): Uniform" & //" distribution scale parameter must be non-zero") - zeros = leadz(n) - bits = bit_size(n) - zeros + zeros = leadz(scale) + bits = bit_size(scale) - zeros mask = shiftr(not(0_${k1}$), zeros) do i = 1, array_size L1 : do - u = dist_rand(n) + u = dist_rand(scale) nn = iand(u, mask) - if(nn <= n) exit L1 + if(nn <= scale) exit L1 bits_left = zeros L2 : do if(bits_left < bits) exit L2 From 51e234c772a8dd840d0e7c8d1643b6df76d12c65 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:10:36 -0400 Subject: [PATCH 141/172] Update src/tests/stats/test_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/tests/stats/test_distribution_uniform.fypp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index 702f5aadf..006408b11 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -93,19 +93,19 @@ program test_distribution_uniform integer :: i, n, seed, get, k #:if k1 == "int8" - ${t1}$ :: ans(15) = [47, 99, 43, 37, 48, 30, 27, 100, 30, 33, 21, & + ${t1}$, parameter :: ans(15) = [47, 99, 43, 37, 48, 30, 27, 100, 30, 33, 21, & 103, 55, 54, 110] #:elif k1 == "int16" - ${t1}$ :: ans(15) = [25, 4, 81, 98, 49, 34, 32, 62, 115, 112, 26, & + ${t1}$, parameter :: ans(15) = [25, 4, 81, 98, 49, 34, 32, 62, 115, 112, 26, & 20, 37, 100, 82] #:elif k1 == "int32" - ${t1}$ :: ans(15) = [19, 52, 56, 20, 59, 44, 34, 102, 19, 39, 60, & + ${t1}$, parameter :: ans(15) = [19, 52, 56, 20, 59, 44, 34, 102, 19, 39, 60, & 50, 97, 56, 67] #:elif k1 == "int64" - ${t1}$ :: ans(15) = [76, 45, 43, 75, 76, 15, 25, 24, 114, 113, 94, & + ${t1}$, parameter :: ans(15) = [76, 45, 43, 75, 76, 15, 25, 24, 114, 113, 94, & 29, 109, 93, 89] #:elif t1[0] == "r" - ${t1}$ :: ans(15) = & + ${t1}$, parameter :: ans(15) = & [0.914826628538749186958511927514337003_${k1}$, & 0.367330098664966409049981166390352882_${k1}$, & 1.77591243057709280428468900936422870_${k1}$, & From 3611e59e39feb15d8a1ef0e25625e204529f0bde Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:10:56 -0400 Subject: [PATCH 142/172] Update src/tests/stats/test_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/tests/stats/test_distribution_uniform.fypp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index 006408b11..3cb890259 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -122,7 +122,7 @@ program test_distribution_uniform -0.164090614147737401395943379611708224_${k1}$, & -0.333886718190384290672056977200554684_${k1}$] #:else - ${t1}$ :: ans(15) = [(0.457413314269374593479255963757168502_${k1}$, & + ${t1}$, parameter :: ans(15) = [(0.457413314269374593479255963757168502_${k1}$, & 0.183665049332483204524990583195176441_${k1}$), & (0.887956215288546402142344504682114348_${k1}$, & 0.442960654493795069619466175936395302_${k1}$), & From 922ad3ce8aee57e51ed8c271e9c6ddfa8a8f5d3d Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:11:13 -0400 Subject: [PATCH 143/172] Update src/tests/stats/test_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/tests/stats/test_distribution_uniform.fypp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index 3cb890259..21ee1ca6f 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -178,8 +178,8 @@ program test_distribution_uniform call check(all(abs(res - ans) < ${k1}$tol), & msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) #:else - call check(all(abs(real(res) - real(ans)) < ${k1}$tol) .and. & - all(abs(aimag(res) - aimag(ans)) < ${k1}$tol), & + call check(all(abs(res % re - ans % re) < ${k1}$tol) .and. & + all(abs(res % im -ans % im) < ${k1}$tol), & msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) #:endif end subroutine test_uni_rvs_${t1[0]}$${k1}$ From 1fa3094c6171906d1184a5ac715c784d2c98e974 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:11:47 -0400 Subject: [PATCH 144/172] Update src/tests/stats/test_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/tests/stats/test_distribution_uniform.fypp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index 21ee1ca6f..f9516658e 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -37,7 +37,8 @@ program test_distribution_uniform contains subroutine test_shuffle - integer :: n(10), na(10) = [10, 6, 9, 2, 8, 1, 3, 5, 7, 4] + integer :: n(10) + integer, paramter :: na(10) = [10, 6, 9, 2, 8, 1, 3, 5, 7, 4] real :: x(10), xa(10) = [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, & 7.0, 6.0] complex :: z(10), za(10) = [(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), & From bf126c0e6576a882bfb2f8c8f5c31d0e1c4a0215 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:11:58 -0400 Subject: [PATCH 145/172] Update src/tests/stats/test_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/tests/stats/test_distribution_uniform.fypp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index f9516658e..1fdc3d3b4 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -39,7 +39,8 @@ program test_distribution_uniform subroutine test_shuffle integer :: n(10) integer, paramter :: na(10) = [10, 6, 9, 2, 8, 1, 3, 5, 7, 4] - real :: x(10), xa(10) = [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, & + real :: x(10) + real, parameter :: xa(10) = [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, & 7.0, 6.0] complex :: z(10), za(10) = [(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), & (1.0, 1.0), (5.0, 5.0), (9.0, 9.0), & From d0f62b25e89e2e77ffe84635d33b67851fd0e083 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:12:27 -0400 Subject: [PATCH 146/172] Update src/tests/stats/test_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/tests/stats/test_distribution_uniform.fypp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index 1fdc3d3b4..7ca64b414 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -42,7 +42,8 @@ program test_distribution_uniform real :: x(10) real, parameter :: xa(10) = [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, & 7.0, 6.0] - complex :: z(10), za(10) = [(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), & + complex :: z(10) + complex, parameter :: za(10) = [(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), & (1.0, 1.0), (5.0, 5.0), (9.0, 9.0), & (6.0, 6.0), (3.0, 3.0), (2.0, 2.0), & (10.0, 10.0)] From 54bcd2236195fe0a29651b5889820684eb218d70 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:12:54 -0400 Subject: [PATCH 147/172] Update src/tests/stats/test_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/tests/stats/test_distribution_uniform.fypp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index 7ca64b414..00e2090b6 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -68,7 +68,9 @@ program test_distribution_uniform end subroutine test_shuffle subroutine test_uni_rvs_0 - integer :: i, j, freq(0:1000), num=10000000 + integer, parameter :: num=10000000 + integer, parameter :: array_size = 1000 + integer :: i, j, freq(0:array_size) real(dp) :: chisq, expct print *,"" From 1fac09138b68f1df7101de9ffdb0f9ce2e78e31b Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:13:24 -0400 Subject: [PATCH 148/172] Update src/tests/stats/test_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/tests/stats/test_distribution_uniform.fypp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index 00e2090b6..1df7b565a 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -197,11 +197,11 @@ program test_distribution_uniform integer :: seed, get, i real :: res(3,5) #:if t1[0] == "i" - real :: ans(15) = [(1.96078438E-02, i=1,15)] + real, parameter :: ans(15) = [(1.96078438E-02, i=1,15)] #:elif t1[0] == "r" - real :: ans(15) = [(0.5, i=1,15)] + real, parameter :: ans(15) = [(0.5, i=1,15)] #:else - real :: ans(15) = [(1.0, i=1,15)] + real, parameter :: ans(15) = [(1.0, i=1,15)] #:endif print *, "Test uniform_distribution_pdf_${t1[0]}$${k1}$" From a2a993dc53c18bc519b2e67a3b9bd0048427df41 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:14:02 -0400 Subject: [PATCH 149/172] Update src/tests/stats/test_distribution_uniform.fypp Co-authored-by: Jeremie Vandenplas --- src/tests/stats/test_distribution_uniform.fypp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index 1df7b565a..ab1a41e96 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -230,32 +230,32 @@ program test_distribution_uniform real :: res(3,5) integer :: seed, get #:if k1 == "int8" - real :: ans(15) = [0.435643554, 0.435643554, 0.435643554, 0.702970326, & + real, parameter :: ans(15) = [0.435643554, 0.435643554, 0.435643554, 0.702970326, & 0.653465331, 0.485148519, 0.386138618, 0.386138618, & 0.336633652, 0.277227730, 0.237623766, 0.524752498, & 0.732673287, 0.534653485, 0.415841579] #:elif k1 == "int16" - real :: ans(15) = [0.178217828, 0.178217828, 0.178217828, 0.465346545, & + real, parameter :: ans(15) = [0.178217828, 0.178217828, 0.178217828, 0.465346545, & 0.673267305, 0.247524753, 0.158415839, 0.792079210, & 0.742574275, 0.574257433, 0.881188095, 0.663366318, & 0.524752498, 0.623762369, 0.178217828] #:elif k1 == "int32" - real :: ans(15) = [0.732673287, 0.732673287, 0.732673287, 0.722772300, & + real, parameter :: ans(15) = [0.732673287, 0.732673287, 0.732673287, 0.722772300, & 0.792079210, 5.94059415E-02, 0.841584146,0.405940592,& 0.960396051, 0.534653485, 0.782178223, 0.861386120, & 0.564356446, 0.613861382, 0.306930691] #:elif k1 == "int64" - real :: ans(15) = [0.455445558, 0.455445558, 0.455445558, 0.277227730, & + real, parameter :: ans(15) = [0.455445558, 0.455445558, 0.455445558, 0.277227730, & 0.455445558, 0.930693090, 0.851485133, 0.623762369, & 5.94059415E-02,0.693069279, 0.544554472, 0.207920790,& 0.306930691, 0.356435657, 0.128712878] #:elif t1[0] == "r" - real :: ans(15) = [0.170192942, 0.170192942, 0.170192942, 0.276106149, & + real, parameter :: ans(15) = [0.170192942, 0.170192942, 0.170192942, 0.276106149, & 0.754930079, 0.406620681, 0.187742814, 0.651605546, & 0.934733927, 0.151271492, 0.987674534, 0.130533904, & 0.106271908, 9.27578658E-02, 0.203399420] #:else - real :: ans(15) = [4.69913185E-02, 4.69913185E-02, 4.69913185E-02, & + real, parameter :: ans(15) = [4.69913185E-02, 4.69913185E-02, 4.69913185E-02, & 0.306970179, 0.122334257, 0.141398594, 0.128925011, & 9.85755492E-03, 8.16527531E-02, 0.163921610, & 7.81712309E-02, 0.446415812, 5.31753292E-04, & From c331d67e430e5ef27761d925d7ecc231d5340386 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:15:12 -0400 Subject: [PATCH 150/172] Update stdlib_stats_distribution_uniform.fypp --- src/stdlib_stats_distribution_uniform.fypp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index f58edb52f..a1224d7ad 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -255,7 +255,7 @@ module stdlib_stats_distribution_uniform if(bits_left < bits) exit L2 u = shiftr(u, bits) nn = iand(u, mask) - if(nn <= n) exit L1 + if(nn <= scale) exit L1 bits_left = bits_left - bits end do L2 end do L1 From 1152f04c6fc7c7ef4af63d9583d88c23a2b34e07 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:17:38 -0400 Subject: [PATCH 151/172] Update test_distribution_uniform.fypp --- src/tests/stats/test_distribution_uniform.fypp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index ab1a41e96..9375677d0 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -82,7 +82,7 @@ program test_distribution_uniform end do chisq = 0.0_dp expct = num / 1000 - do i = 0, 999 + do i = 0, array_size - 1 chisq = chisq + (freq(i) - expct) ** 2 / expct end do write(*,*) "The critical values for chi-squared with 1000 d. of f. are" & From 8186ead712819099f4ee383ceb5582199292fd67 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 15:33:14 -0400 Subject: [PATCH 152/172] Update test_distribution_uniform.fypp --- src/tests/stats/test_distribution_uniform.fypp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index 9375677d0..c4b480aac 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -70,18 +70,18 @@ program test_distribution_uniform subroutine test_uni_rvs_0 integer, parameter :: num=10000000 integer, parameter :: array_size = 1000 - integer :: i, j, freq(0:array_size) + integer :: i, j, freq(0:array_size - 1) real(dp) :: chisq, expct print *,"" print *, "Test uniform random generator with chi-squared" freq = 0 do i = 1, num - j = 1000 * uni_rvs( ) + j = array_size * uni_rvs( ) freq(j) = freq(j) + 1 end do chisq = 0.0_dp - expct = num / 1000 + expct = num / array_size do i = 0, array_size - 1 chisq = chisq + (freq(i) - expct) ** 2 / expct end do From 939fd1a95ea67684f6438575a87c289b3ad4b127 Mon Sep 17 00:00:00 2001 From: Jing <53905783+Jim-215-Fisher@users.noreply.github.com> Date: Sun, 1 Aug 2021 16:36:03 -0400 Subject: [PATCH 153/172] Update test_distribution_uniform.fypp --- src/tests/stats/test_distribution_uniform.fypp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index c4b480aac..be9a9e909 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -38,7 +38,7 @@ program test_distribution_uniform subroutine test_shuffle integer :: n(10) - integer, paramter :: na(10) = [10, 6, 9, 2, 8, 1, 3, 5, 7, 4] + integer, parameter :: na(10) = [10, 6, 9, 2, 8, 1, 3, 5, 7, 4] real :: x(10) real, parameter :: xa(10) = [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, & 7.0, 6.0] From a4330ccc5f55eedd41c416ec023a070a6fae5e3f Mon Sep 17 00:00:00 2001 From: Jim-215-Fisher Date: Sun, 15 Aug 2021 17:58:55 -0400 Subject: [PATCH 154/172] slightly changed format and some minor corrections --- src/stdlib_stats_distribution_uniform.fypp | 90 ++++++++++++++++++---- 1 file changed, 75 insertions(+), 15 deletions(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index a1224d7ad..643c29419 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -17,6 +17,7 @@ module stdlib_stats_distribution_uniform public :: uniform_distribution_cdf public :: shuffle + interface uniform_distribution_rvs !! Version experimental !! @@ -39,10 +40,12 @@ module stdlib_stats_distribution_uniform #:endfor end interface uniform_distribution_rvs + interface uniform_distribution_pdf !! Version experiment !! - !! Get uniform distribution probability density (pdf) for integer, real and complex variables + !! Get uniform distribution probability density (pdf) for integer, real and + !! complex variables. !! ([Specification](../page/specs/stdlib_stats_distribution_uniform.html# !! description)) @@ -51,10 +54,12 @@ module stdlib_stats_distribution_uniform #:endfor end interface uniform_distribution_pdf + interface uniform_distribution_cdf !! Version experimental !! - !! Get uniform distribution cumulative distribution function (cdf) for integer, real and complex variables + !! Get uniform distribution cumulative distribution function (cdf) for integer, + !! real and complex variables. !! ([Specification](../page/specs/stdlib_stats_distribution_uniform.html# !! description)) !! @@ -63,10 +68,12 @@ module stdlib_stats_distribution_uniform #:endfor end interface uniform_distribution_cdf + interface shuffle !! Version experimental !! - !! Fisher-Yates shuffle algorithm for a rank one array of integer, real and complex variables + !! Fisher-Yates shuffle algorithm for a rank one array of integer, real and + !! complex variables !! ([Specification](../page/specs/stdlib_stats_distribution_uniform.html# !! description)) !! @@ -76,20 +83,25 @@ module stdlib_stats_distribution_uniform end interface shuffle - contains + + +contains + #:for k1, t1 in INT_KINDS_TYPES impure elemental function unif_dist_rvs_1_${t1[0]}$${k1}$(scale) result(res) + ! ! Uniformly distributed integer in [0, scale] ! Bitmask with rejection ! https://www.pcg-random.org/posts/bounded-rands.html ! ! Fortran 90 translated from c by Jim-215-fisher + ! ${t1}$, intent(in) :: scale ${t1}$ :: res, u, mask integer :: zeros, bits_left, bits - if(scale <= 0_${k1}$) call error_stop("Error(unif_dist_rvs_1): Uniform" & + if(scale <= 0_${k1}$) call error_stop("Error(unif_dist_rvs_1): Uniform" & //" distribution scale parameter must be positive") zeros = leadz(scale) bits = bit_size(scale) - zeros @@ -111,9 +123,12 @@ module stdlib_stats_distribution_uniform #:endfor + + #:for k1, t1 in INT_KINDS_TYPES impure elemental function unif_dist_rvs_${t1[0]}$${k1}$(loc, scale) & - result( res ) + result( res ) + ! ! Uniformly distributed integer in [loc, loc + scale] ! ${t1}$, intent(in) :: loc, scale @@ -126,8 +141,11 @@ module stdlib_stats_distribution_uniform #:endfor + + #:for k1, t1 in REAL_KINDS_TYPES impure elemental function unif_dist_rvs_0_${t1[0]}$${k1}$( ) result(res) + ! ! Uniformly distributed float in [0,1] ! Based on the paper by Frederic Goualard, "Generating Random Floating- ! Point Numbers By Dividing Integers: a Case Study", Proceedings of @@ -142,8 +160,11 @@ module stdlib_stats_distribution_uniform #:endfor + + #:for k1, t1 in REAL_KINDS_TYPES impure elemental function unif_dist_rvs_1_${t1[0]}$${k1}$(scale) result(res) + ! ! Uniformly distributed float in [0, scale] ! ${t1}$, intent(in) :: scale @@ -156,9 +177,12 @@ module stdlib_stats_distribution_uniform #:endfor + + #:for k1, t1 in REAL_KINDS_TYPES impure elemental function unif_dist_rvs_${t1[0]}$${k1}$(loc, scale) & - result(res) + result(res) + ! ! Uniformly distributed float in [loc, loc + scale] ! ${t1}$, intent(in) :: loc, scale @@ -171,11 +195,14 @@ module stdlib_stats_distribution_uniform #:endfor + + #:for k1, t1 in CMPLX_KINDS_TYPES impure elemental function unif_dist_rvs_1_${t1[0]}$${k1}$(scale) result(res) - ! Uniformly distributed complex in [(0,0i), (scale, i(scale)] + ! + ! Uniformly distributed complex in [(0,0i), (scale, i(scale))] ! The real part and imaginary part are independent of each other, so that - ! the joint distribution is on an unit square [(0,0i), scale,i(scale)] + ! the joint distribution is on an unit square [(0,0i), (scale,i(scale))] ! ${t1}$, intent(in) :: scale ${t1}$ :: res @@ -191,7 +218,7 @@ module stdlib_stats_distribution_uniform tr = scale % re * r1 ti = 0.0_${k1}$ else - tr = scale % re * r1 + tr = scale % re * r1 r1 = unif_dist_rvs_0_r${k1}$( ) ti = scale % im * r1 endif @@ -200,9 +227,12 @@ module stdlib_stats_distribution_uniform #:endfor + + #:for k1, t1 in CMPLX_KINDS_TYPES impure elemental function unif_dist_rvs_${t1[0]}$${k1}$(loc, scale) & - result(res) + result(res) + ! ! Uniformly distributed complex in [(loc,iloc), (loc + scale, i(loc + scale))] ! The real part and imaginary part are independent of each other, so that ! the joint distribution is on an unit square [(loc,iloc), (loc + scale, @@ -231,9 +261,12 @@ module stdlib_stats_distribution_uniform #:endfor + + #:for k1, t1 in INT_KINDS_TYPES function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & - result(res) + result(res) + integer, intent(in) :: array_size ${t1}$, intent(in) :: loc, scale ${t1}$ :: res(array_size) @@ -265,9 +298,12 @@ module stdlib_stats_distribution_uniform #:endfor + + #:for k1, t1 in REAL_KINDS_TYPES function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & - result(res) + result(res) + integer, intent(in) :: array_size ${t1}$, intent(in) :: loc, scale ${t1}$ :: res(array_size) @@ -287,9 +323,12 @@ module stdlib_stats_distribution_uniform #:endfor + + #:for k1, t1 in CMPLX_KINDS_TYPES function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & - result(res) + result(res) + integer, intent(in) :: array_size ${t1}$, intent(in) :: loc, scale ${t1}$ :: res(array_size) @@ -321,8 +360,11 @@ module stdlib_stats_distribution_uniform #:endfor + + #:for k1, t1 in INT_KINDS_TYPES elemental function unif_dist_pdf_${t1[0]}$${k1}$(x, loc, scale) result(res) + ${t1}$, intent(in) :: x, loc, scale real :: res @@ -337,8 +379,11 @@ module stdlib_stats_distribution_uniform #:endfor + + #:for k1, t1 in REAL_KINDS_TYPES elemental function unif_dist_pdf_${t1[0]}$${k1}$(x, loc, scale) result(res) + ${t1}$, intent(in) :: x, loc, scale real :: res @@ -353,8 +398,11 @@ module stdlib_stats_distribution_uniform #:endfor + + #:for k1, t1 in CMPLX_KINDS_TYPES elemental function unif_dist_pdf_${t1[0]}$${k1}$(x, loc, scale) result(res) + ${t1}$, intent(in) :: x, loc, scale real :: res real(${k1}$) :: tr, ti @@ -372,8 +420,11 @@ module stdlib_stats_distribution_uniform #:endfor + + #:for k1, t1 in INT_KINDS_TYPES elemental function unif_dist_cdf_${t1[0]}$${k1}$(x, loc, scale) result(res) + ${t1}$, intent(in) :: x, loc, scale real :: res @@ -390,8 +441,11 @@ module stdlib_stats_distribution_uniform #:endfor + + #:for k1, t1 in REAL_KINDS_TYPES elemental function unif_dist_cdf_${t1[0]}$${k1}$(x, loc, scale) result(res) + ${t1}$, intent(in) :: x, loc, scale real :: res @@ -408,8 +462,11 @@ module stdlib_stats_distribution_uniform #:endfor + + #:for k1, t1 in CMPLX_KINDS_TYPES elemental function unif_dist_cdf_${t1[0]}$${k1}$(x, loc, scale) result(res) + ${t1}$, intent(in) :: x, loc, scale real :: res logical :: r1, r2, i1, i2 @@ -430,7 +487,7 @@ module stdlib_stats_distribution_uniform res = (x % im - loc % im) / scale % im elseif((.not. r1) .and. (.not. r2) .and. (.not. i1) .and. (.not. i2)) & then - res = (x % re - loc % re) * (x % im - loc % im) / & + res = (x % re - loc % re) * (x % im - loc % im) / & (scale % re * scale % im) elseif(r2 .and. i2)then res = 1.0 @@ -439,8 +496,11 @@ module stdlib_stats_distribution_uniform #:endfor + + #:for k1, t1 in ALL_KINDS_TYPES function shuffle_${t1[0]}$${k1}$( list ) result(res) + ${t1}$, intent(in) :: list(:) ${t1}$ :: res(size(list)) ${t1}$ :: tmp From 63794580e56ddd4a2785a0bbd12d9995b8421420 Mon Sep 17 00:00:00 2001 From: Jim-215-Fisher Date: Sun, 22 Aug 2021 14:56:33 -0400 Subject: [PATCH 155/172] test --- src/CMakeLists.txt | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b9f5b905c..7e09d2e6f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -67,21 +67,10 @@ set_target_properties(${PROJECT_NAME} PROPERTIES Fortran_MODULE_DIRECTORY ${LIB_MOD_DIR}) target_include_directories(${PROJECT_NAME} PUBLIC $ - $ ) -if(f18errorstop) - target_sources(${PROJECT_NAME} PRIVATE f18estop.f90) -else() - target_sources(${PROJECT_NAME} PRIVATE f08estop.f90) -endif() - -add_subdirectory(tests) - -install(TARGETS ${PROJECT_NAME} - EXPORT ${PROJECT_NAME}-targets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" +target_link_libraries( + ${PROJECT_NAME} + PRIVATE + fortran_stdlib::fortran_stdlib ) -install(DIRECTORY ${LIB_MOD_DIR} DESTINATION "${CMAKE_INSTALL_MODULEDIR}") From 1c46c10fc5c2ff8773ca295e7f1a53268bbf2aac Mon Sep 17 00:00:00 2001 From: Jim-215-Fisher Date: Sun, 22 Aug 2021 16:20:30 -0400 Subject: [PATCH 156/172] Spell checked and minor correction --- .../stdlib_stats_distribution_uniform.md | 20 +- src/stdlib_stats_distribution_uniform.fypp | 4 +- .../stats/test_distribution_uniform.fypp | 214 ++++++++++-------- 3 files changed, 127 insertions(+), 111 deletions(-) diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index b393cd78d..9ff958dfb 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -75,15 +75,17 @@ Experimental ### Description -Without augument the function returns a scalar standard uniformly distributed variate U(0,1) of `real` type with single precision on [0,1]. +Without argument the function returns a scalar standard uniformly distributed variate U(0,1) of `real` type with single precision on [0,1]. -With single augument `scale` of `integer` type the function returns a scalar uniformly distributed variate of `integer` type on [0,scale]. This is the standard Rectangular distribution. +With single argument `scale` of `integer` type the function returns a scalar uniformly distributed variate of `integer` type on [0,scale]. This is the standard Rectangular distribution. -With single augument `scale` of `real` or `complex` type the function returns a scalar uniformly distributed variate of `real` or `complex` type on [0, scale]. The real part and imaginary part of a `complex` type are independent of each other. +With single argument `scale` of `real` or `complex` type the function returns a scalar uniformly distributed variate of `real` or `complex` type on [0, scale]. -With double auguments `loc` and `scale` the function returns a scalar uniformly distributed random variates of `integer`, `real` or `complex` type on [loc, loc + scale] dependent of input type. If it is `complex` augument, the real part and imaginary part are independent of each other. +With double arguments `loc` and `scale` the function returns a scalar uniformly distributed random variates of `integer`, `real` or `complex` type on [loc, loc + scale] dependent of input type. -With triple auguments `loc`, `scale` and `array_size` the function returns a rank one array of uniformly distributed variates of `integer`, `real` or `complex` type with an array size of `array_size`. +With triple arguments `loc`, `scale` and `array_size` the function returns a rank one array of uniformly distributed variates of `integer`, `real` or `complex` type with an array size of `array_size`. + +For `complex` type, the real part and imaginary part are independent of each other. ### Syntax @@ -223,11 +225,11 @@ Elemental function. `scale`: has `intent(in)` and is a scalar of type `integer`, `real` or `complex`. -All three auguments could be arrays conformable to each other. All three arguments must have the same type and kind. +All three arguments must have the same type and kind. ### Return value -The result is a scalar or an array, with a shape conformable to auguments, of type `real`. +The result is a scalar or an array, with a shape conformable to arguments, of type `real`. ### Example @@ -317,11 +319,11 @@ Elemental function. `scale`: has `intent(in)` and is a scalar of type `integer`, `real` or `complex`. -All three auguments could be arrays conformable to each other. All three arguments must have the same type and kind. +All three arguments must have the same type and kind. ### Return value -The result is a scalar or an array, with a shape conformable to auguments, of type `real`. +The result is a scalar or an array, with a shape conformable to arguments, of type `real`. ### Example diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index 643c29419..526a00989 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -368,7 +368,7 @@ contains ${t1}$, intent(in) :: x, loc, scale real :: res - if(scale == 0) then + if(scale == 0_${k1}$) then res = 0.0 elseif(x < loc .or. x > (loc + scale)) then res = 0.0 @@ -428,7 +428,7 @@ contains ${t1}$, intent(in) :: x, loc, scale real :: res - if(scale == 0) then + if(scale == 0_${k1}$) then res = 0.0 elseif(x < loc) then res = 0.0 diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index be9a9e909..f91f9f6c0 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -4,9 +4,9 @@ program test_distribution_uniform use stdlib_error, only : check use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, qp use stdlib_stats_distribution_PRNG, only : random_seed, dist_rand - use stdlib_stats_distribution_uniform, & - uni_rvs => uniform_distribution_rvs, & - uni_pdf => uniform_distribution_pdf, & + use stdlib_stats_distribution_uniform, & + uni_rvs => uniform_distribution_rvs, & + uni_pdf => uniform_distribution_pdf, & uni_cdf => uniform_distribution_cdf implicit none @@ -34,18 +34,21 @@ program test_distribution_uniform call test_uni_cdf_${t1[0]}$${k1}$ #:endfor - contains + + + +contains subroutine test_shuffle integer :: n(10) integer, parameter :: na(10) = [10, 6, 9, 2, 8, 1, 3, 5, 7, 4] real :: x(10) - real, parameter :: xa(10) = [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, & + real, parameter :: xa(10) = [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, & 7.0, 6.0] complex :: z(10) - complex, parameter :: za(10) = [(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), & - (1.0, 1.0), (5.0, 5.0), (9.0, 9.0), & - (6.0, 6.0), (3.0, 3.0), (2.0, 2.0), & + complex, parameter :: za(10) = [(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), & + (1.0, 1.0), (5.0, 5.0), (9.0, 9.0), & + (6.0, 6.0), (3.0, 3.0), (2.0, 2.0), & (10.0, 10.0)] integer :: i, put, get @@ -67,10 +70,12 @@ program test_distribution_uniform msg="Complex shuffle failed test", warn=warn) end subroutine test_shuffle + + subroutine test_uni_rvs_0 integer, parameter :: num=10000000 integer, parameter :: array_size = 1000 - integer :: i, j, freq(0:array_size - 1) + integer :: i, j, freq(0 : array_size - 1) real(dp) :: chisq, expct print *,"" @@ -85,78 +90,81 @@ program test_distribution_uniform do i = 0, array_size - 1 chisq = chisq + (freq(i) - expct) ** 2 / expct end do - write(*,*) "The critical values for chi-squared with 1000 d. of f. are" & + write(*,*) "The critical values for chi-squared with 1000 d. of f. are"& //" 1143.92" write(*,*) "Chi-squared for uniform random generator is : ", chisq call check((chisq < 1143.9) , & msg="uniform randomness failed chi-squared test", warn=warn) end subroutine test_uni_rvs_0 + + #:for k1, t1 in ALL_KINDS_TYPES subroutine test_uni_rvs_${t1[0]}$${k1}$ ${t1}$ :: res(15), scale, loc integer :: i, n, seed, get, k #:if k1 == "int8" - ${t1}$, parameter :: ans(15) = [47, 99, 43, 37, 48, 30, 27, 100, 30, 33, 21, & - 103, 55, 54, 110] + ${t1}$, parameter :: ans(15) = [47, 99, 43, 37, 48, 30, 27, 100, 30, & + 33, 21, 103, 55, 54, 110] #:elif k1 == "int16" - ${t1}$, parameter :: ans(15) = [25, 4, 81, 98, 49, 34, 32, 62, 115, 112, 26, & - 20, 37, 100, 82] + ${t1}$, parameter :: ans(15) = [25, 4, 81, 98, 49, 34, 32, 62, 115, & + 112, 26, 20, 37, 100, 82] #:elif k1 == "int32" - ${t1}$, parameter :: ans(15) = [19, 52, 56, 20, 59, 44, 34, 102, 19, 39, 60, & - 50, 97, 56, 67] + ${t1}$, parameter :: ans(15) = [19, 52, 56, 20, 59, 44, 34, 102, 19, & + 39, 60, 50, 97, 56, 67] #:elif k1 == "int64" - ${t1}$, parameter :: ans(15) = [76, 45, 43, 75, 76, 15, 25, 24, 114, 113, 94, & - 29, 109, 93, 89] + ${t1}$, parameter :: ans(15) = [76, 45, 43, 75, 76, 15, 25, 24, 114, & + 113, 94, 29, 109, 93, 89] #:elif t1[0] == "r" - ${t1}$, parameter :: ans(15) = & - [0.914826628538749186958511927514337003_${k1}$, & - 0.367330098664966409049981166390352882_${k1}$, & - 1.77591243057709280428468900936422870_${k1}$, & - 0.885921308987590139238932351872790605_${k1}$, & - 0.950735656542987861428173346212133765_${k1}$, & - -0.659562573857055134407545438079978339_${k1}$, & - -0.116661718506947176265953203255776316_${k1}$, & - 0.837391893893859151631886561517603695_${k1}$, & - -0.703954396598600540269075054311542772_${k1}$, & - 0.382592729851141566399519433616660535_${k1}$, & - -0.132472493978185168472805344208609313_${k1}$, & - -0.878723366294216184924081858298450243_${k1}$, & - -0.901660046141515819639877804547722917_${k1}$, & - -0.164090614147737401395943379611708224_${k1}$, & + ${t1}$, parameter :: ans(15) = & + [0.914826628538749186958511927514337003_${k1}$, & + 0.367330098664966409049981166390352882_${k1}$, & + 1.77591243057709280428468900936422870_${k1}$, & + 0.885921308987590139238932351872790605_${k1}$, & + 0.950735656542987861428173346212133765_${k1}$, & + -0.659562573857055134407545438079978339_${k1}$, & + -0.116661718506947176265953203255776316_${k1}$, & + 0.837391893893859151631886561517603695_${k1}$, & + -0.703954396598600540269075054311542772_${k1}$, & + 0.382592729851141566399519433616660535_${k1}$, & + -0.132472493978185168472805344208609313_${k1}$, & + -0.878723366294216184924081858298450243_${k1}$, & + -0.901660046141515819639877804547722917_${k1}$, & + -0.164090614147737401395943379611708224_${k1}$, & -0.333886718190384290672056977200554684_${k1}$] #:else - ${t1}$, parameter :: ans(15) = [(0.457413314269374593479255963757168502_${k1}$, & - 0.183665049332483204524990583195176441_${k1}$), & - (0.887956215288546402142344504682114348_${k1}$, & - 0.442960654493795069619466175936395302_${k1}$), & - (0.475367828271493930714086673106066883_${k1}$, & - 0.170218713071472432796227280960010830_${k1}$), & - (0.441669140746526411867023398372111842_${k1}$, & - 0.918695946946929575815943280758801848_${k1}$), & - (0.148022801700699729865462472844228614_${k1}$, & - 0.691296364925570783199759716808330268_${k1}$), & - (-6.623624698909258423640267210430465639E-0002_${k1}$, & - 0.560638316852891907537959070850774879_${k1}$), & - (-0.450830023070757909819938902273861459_${k1}$, & - 0.917954692926131299302028310194145888_${k1}$), & - (-0.166943359095192145336028488600277342_${k1}$, & - 1.05997401970850635422038976685144007_${k1}$), & - (-0.429652190199228276035192664039641386_${k1}$, & - 0.523558274341032421628217008446881664_${k1}$), & - (0.427181091476823815433760955784237012_${k1}$, & - 1.34628934976074521312483511792379431_${k1}$), & - (-0.343281426018765739582860874179459643_${k1}$, & - 1.15357331316264255516301773241139017_${k1}$), & - (-0.127590074749816595467422075671493076_${k1}$, & - 1.06891199479835175001340985545539297_${k1}$), & - (0.262287586904722758163188700564205647_${k1}$, & - 1.29508919831907332032017166056903079_${k1}$), & - (-0.192677407376582732201342196276527829_${k1}$, & - 1.32794925614337933073016984053538181_${k1}$), & - (-0.264742129752461530234342035328154452_${k1}$, & - 1.01282963412172621886497836385387927_${k1}$)] + ${t1}$, parameter :: ans(15) = & + [(0.457413314269374593479255963757168502_${k1}$, & + 0.183665049332483204524990583195176441_${k1}$), & + (0.887956215288546402142344504682114348_${k1}$, & + 0.442960654493795069619466175936395302_${k1}$), & + (0.475367828271493930714086673106066883_${k1}$, & + 0.170218713071472432796227280960010830_${k1}$), & + (0.441669140746526411867023398372111842_${k1}$, & + 0.918695946946929575815943280758801848_${k1}$), & + (0.148022801700699729865462472844228614_${k1}$, & + 0.691296364925570783199759716808330268_${k1}$), & + (-6.623624698909258423640267210430465639E-0002_${k1}$, & + 0.560638316852891907537959070850774879_${k1}$), & + (-0.450830023070757909819938902273861459_${k1}$, & + 0.917954692926131299302028310194145888_${k1}$), & + (-0.166943359095192145336028488600277342_${k1}$, & + 1.05997401970850635422038976685144007_${k1}$), & + (-0.429652190199228276035192664039641386_${k1}$, & + 0.523558274341032421628217008446881664_${k1}$), & + (0.427181091476823815433760955784237012_${k1}$, & + 1.34628934976074521312483511792379431_${k1}$), & + (-0.343281426018765739582860874179459643_${k1}$, & + 1.15357331316264255516301773241139017_${k1}$), & + (-0.127590074749816595467422075671493076_${k1}$, & + 1.06891199479835175001340985545539297_${k1}$), & + (0.262287586904722758163188700564205647_${k1}$, & + 1.29508919831907332032017166056903079_${k1}$), & + (-0.192677407376582732201342196276527829_${k1}$, & + 1.32794925614337933073016984053538181_${k1}$), & + (-0.264742129752461530234342035328154452_${k1}$, & + 1.01282963412172621886497836385387927_${k1}$)] #:endif print *, "Test uniform_distribution_rvs_${t1[0]}$${k1}$" @@ -169,28 +177,26 @@ program test_distribution_uniform #:else loc = (-0.5_${k1}$,0.5_${k1}$); scale = (1.0_${k1}$, 1.0_${k1}$) #:endif - do i=1, 5 + do i = 1, 5 res(i) = uni_rvs(scale) ! 1 dummy end do - do i=6,10 + do i = 6,10 res(i) = uni_rvs(loc, scale) ! 2 dummies end do res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies #:if t1[0] == "i" - call check(all(res == ans), & + call check(all(res == ans), & + msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) + #:elif + call check(all(abs(res - ans) < ${k1}$tol), & msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) - #:elif t1[0] == "r" - call check(all(abs(res - ans) < ${k1}$tol), & - msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) - #:else - call check(all(abs(res % re - ans % re) < ${k1}$tol) .and. & - all(abs(res % im -ans % im) < ${k1}$tol), & - msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) #:endif end subroutine test_uni_rvs_${t1[0]}$${k1}$ #:endfor + + #:for k1, t1 in ALL_KINDS_TYPES subroutine test_uni_pdf_${t1[0]}$${k1}$ ${t1}$ :: x1, x2(3,4), loc, scale @@ -218,48 +224,56 @@ program test_distribution_uniform x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) res(:,1) = uni_pdf(x1, loc, scale) res(:, 2:5) = uni_pdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & msg="uniform_distribution_pdf_${t1[0]}$${k1}$ failed", warn=warn) end subroutine test_uni_pdf_${t1[0]}$${k1}$ #:endfor + + #:for k1, t1 in ALL_KINDS_TYPES subroutine test_uni_cdf_${t1[0]}$${k1}$ ${t1}$ :: x1, x2(3,4), loc, scale real :: res(3,5) integer :: seed, get #:if k1 == "int8" - real, parameter :: ans(15) = [0.435643554, 0.435643554, 0.435643554, 0.702970326, & - 0.653465331, 0.485148519, 0.386138618, 0.386138618, & - 0.336633652, 0.277227730, 0.237623766, 0.524752498, & - 0.732673287, 0.534653485, 0.415841579] + real, parameter :: ans(15) = [0.435643554, 0.435643554, 0.435643554, & + 0.702970326, 0.653465331, 0.485148519, & + 0.386138618, 0.386138618, 0.336633652, & + 0.277227730, 0.237623766, 0.524752498, & + 0.732673287, 0.534653485, 0.415841579] #:elif k1 == "int16" - real, parameter :: ans(15) = [0.178217828, 0.178217828, 0.178217828, 0.465346545, & - 0.673267305, 0.247524753, 0.158415839, 0.792079210, & - 0.742574275, 0.574257433, 0.881188095, 0.663366318, & - 0.524752498, 0.623762369, 0.178217828] + real, parameter :: ans(15) = [0.178217828, 0.178217828, 0.178217828, & + 0.465346545, 0.673267305, 0.247524753, & + 0.158415839, 0.792079210, 0.742574275, & + 0.574257433, 0.881188095, 0.663366318, & + 0.524752498, 0.623762369, 0.178217828] #:elif k1 == "int32" - real, parameter :: ans(15) = [0.732673287, 0.732673287, 0.732673287, 0.722772300, & - 0.792079210, 5.94059415E-02, 0.841584146,0.405940592,& - 0.960396051, 0.534653485, 0.782178223, 0.861386120, & - 0.564356446, 0.613861382, 0.306930691] + real, parameter :: ans(15) = [0.732673287, 0.732673287, 0.732673287, & + 0.722772300, 0.792079210, 5.94059415E-02,& + 0.841584146, 0.405940592, 0.960396051, & + 0.534653485, 0.782178223, 0.861386120, & + 0.564356446, 0.613861382, 0.306930691] #:elif k1 == "int64" - real, parameter :: ans(15) = [0.455445558, 0.455445558, 0.455445558, 0.277227730, & - 0.455445558, 0.930693090, 0.851485133, 0.623762369, & - 5.94059415E-02,0.693069279, 0.544554472, 0.207920790,& - 0.306930691, 0.356435657, 0.128712878] + real, parameter :: ans(15) = [0.455445558, 0.455445558, 0.455445558, & + 0.277227730, 0.455445558, 0.930693090, & + 0.851485133, 0.623762369, 5.94059415E-02,& + 0.693069279, 0.544554472, 0.207920790, & + 0.306930691, 0.356435657, 0.128712878] #:elif t1[0] == "r" - real, parameter :: ans(15) = [0.170192942, 0.170192942, 0.170192942, 0.276106149, & - 0.754930079, 0.406620681, 0.187742814, 0.651605546, & - 0.934733927, 0.151271492, 0.987674534, 0.130533904, & - 0.106271908, 9.27578658E-02, 0.203399420] + real, parameter :: ans(15) = [0.170192942, 0.170192942, 0.170192942, & + 0.276106149, 0.754930079, 0.406620681, & + 0.187742814, 0.651605546, 0.934733927, & + 0.151271492, 0.987674534, 0.130533904, & + 0.106271908, 9.27578658E-02, 0.203399420] #:else - real, parameter :: ans(15) = [4.69913185E-02, 4.69913185E-02, 4.69913185E-02, & - 0.306970179, 0.122334257, 0.141398594, 0.128925011, & - 9.85755492E-03, 8.16527531E-02, 0.163921610, & - 7.81712309E-02, 0.446415812, 5.31753292E-04, & - 0.101455867, 0.155276477] + real, parameter :: ans(15) = [4.69913185E-02, 4.69913185E-02, & + 4.69913185E-02, 0.306970179, 0.122334257,& + 0.141398594, 0.128925011, 9.85755492E-03,& + 8.16527531E-02, 0.163921610, & + 7.81712309E-02, 0.446415812, & + 5.31753292E-04, 0.101455867, 0.155276477] #:endif print *, "Test uniform_distribution_cdf_${t1[0]}$${k1}$" @@ -276,7 +290,7 @@ program test_distribution_uniform x2 = reshape(uni_rvs(loc, scale, 12), [3,4]) res(:,1) = uni_cdf(x1, loc, scale) res(:, 2:5) = uni_cdf(x2, loc, scale) - call check(all(abs(res - reshape(ans,[3,5])) < sptol), & + call check(all(abs(res - reshape(ans,[3,5])) < sptol), & msg="uniform_distribution_cdf_${t1[0]}$${k1}$ failed", warn=warn) end subroutine test_uni_cdf_${t1[0]}$${k1}$ From a2bf0ed14eee0f7ba84e60627f298c2eb80c8a46 Mon Sep 17 00:00:00 2001 From: Jim-215-Fisher Date: Sun, 22 Aug 2021 16:44:50 -0400 Subject: [PATCH 157/172] modify index.md, CMakeList.txt and Makefile.manual --- doc/specs/index.md | 1 + src/CMakeLists.txt | 23 +++++++++++++++++------ src/Makefile.manual | 5 +++++ src/tests/stats/Makefile.manual | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/doc/specs/index.md b/doc/specs/index.md index cc804bd31..342abeacd 100644 --- a/doc/specs/index.md +++ b/doc/specs/index.md @@ -24,6 +24,7 @@ This is and index/directory of the specifications (specs) for each new module/fe - [sorting](./stdlib_sorting.html) - Sorting of rank one arrays - [stats](./stdlib_stats.html) - Descriptive Statistics - [stats_distribution_PRNG](./stdlib_stats_distribution_PRNG.html) - Probability Distributions random number generator + - [stats_distribution_uniform](./stdlib_stats_distribution_uniform.html) - Uniform probability distribution - [string\_type](./stdlib_string_type.html) - Basic string support - [strings](./stdlib_strings.html) - String handling and manipulation routines diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ee5c47200..da4cc7a33 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -### Pre-process: .fpp -> .f90 via Fypp +#### Pre-process: .fpp -> .f90 via Fypp # Create a list of the files to be preprocessed set(fppFiles @@ -14,7 +14,7 @@ set(fppFiles stdlib_sorting.fypp stdlib_sorting_ord_sort.fypp stdlib_sorting_sort.fypp - stdlib_sorting_sort_index.fypp + stdlib_sorting_sort_index.fypp stdlib_stats.fypp stdlib_stats_corr.fypp stdlib_stats_cov.fypp @@ -70,10 +70,21 @@ set_target_properties(${PROJECT_NAME} PROPERTIES Fortran_MODULE_DIRECTORY ${LIB_MOD_DIR}) target_include_directories(${PROJECT_NAME} PUBLIC $ + $ ) -target_link_libraries( - ${PROJECT_NAME} - PRIVATE - fortran_stdlib::fortran_stdlib +if(f18errorstop) + target_sources(${PROJECT_NAME} PRIVATE f18estop.f90) +else() + target_sources(${PROJECT_NAME} PRIVATE f08estop.f90) +endif() + +add_subdirectory(tests) + +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}-targets + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" ) +install(DIRECTORY ${LIB_MOD_DIR} DESTINATION "${CMAKE_INSTALL_MODULEDIR}") diff --git a/src/Makefile.manual b/src/Makefile.manual index 5c1d2ba8d..46e80c7a8 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -30,6 +30,7 @@ SRCFYPP = \ stdlib_math_linspace.fypp \ stdlib_math_logspace.fypp \ stdlib_stats_distribution_PRNG.fypp \ + stdlib_stats_distribution_uniform.fypp \ stdlib_string_type.fypp \ stdlib_string_type_constructor.fypp \ stdlib_strings.fypp \ @@ -146,6 +147,10 @@ stdlib_stats_var.o: \ stdlib_stats_distribution_PRNG.o: \ stdlib_kinds.o \ stdlib_error.o +stdlib_stats_distribution_uniform.o: \ + stdlib_kinds.o \ + stdlib_error.o \ + stdlib_stats_distribution_PRNG.o stdlib_string_type.o: stdlib_ascii.o \ stdlib_kinds.o stdlib_string_type_constructor.o: stdlib_string_type.o \ diff --git a/src/tests/stats/Makefile.manual b/src/tests/stats/Makefile.manual index 2274db12b..515b6c113 100644 --- a/src/tests/stats/Makefile.manual +++ b/src/tests/stats/Makefile.manual @@ -1,6 +1,6 @@ SRCFYPP =\ test_median.fypp \ - test_distribution_uniform.fypp + test_distribution_uniform.fypp SRCGEN = $(SRCFYPP:.fypp=.f90) From 7bdfc05423ba37cd836d4b5f507e4a12c297f311 Mon Sep 17 00:00:00 2001 From: Jim-215-Fisher Date: Sun, 22 Aug 2021 17:30:51 -0400 Subject: [PATCH 158/172] minor change --- src/tests/stats/test_distribution_uniform.fypp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index f91f9f6c0..10fa98802 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -187,7 +187,7 @@ contains #:if t1[0] == "i" call check(all(res == ans), & msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) - #:elif + #:else call check(all(abs(res - ans) < ${k1}$tol), & msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) #:endif From 65ec424ada91496c9208a9d93898461cbd05143c Mon Sep 17 00:00:00 2001 From: milancurcic Date: Sun, 19 Sep 2021 13:35:17 -0400 Subject: [PATCH 159/172] Minor style change for consistency with most other stdlib modules --- src/stdlib_stats_distribution_uniform.fypp | 38 +++++++++++----------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index 526a00989..b4ffeadc9 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -214,14 +214,14 @@ contains if(scale % re == 0.0_${k1}$) then ti = scale % im * r1 tr = 0.0_${k1}$ - elseif(scale % im == 0.0_${k1}$) then + else if(scale % im == 0.0_${k1}$) then tr = scale % re * r1 ti = 0.0_${k1}$ else tr = scale % re * r1 r1 = unif_dist_rvs_0_r${k1}$( ) ti = scale % im * r1 - endif + end if res = cmplx(tr, ti, kind=${k1}$) end function unif_dist_rvs_1_${t1[0]}$${k1}$ @@ -248,14 +248,14 @@ contains if(scale % re == 0.0_${k1}$) then tr = loc % re ti = loc % im + scale % im * r1 - elseif(scale % im == 0.0_${k1}$) then + else if(scale % im == 0.0_${k1}$) then tr = loc % re + scale % re * r1 ti = loc % im else tr = loc % re + scale % re * r1 r1 = unif_dist_rvs_0_r${k1}$( ) ti = loc % im + scale % im * r1 - endif + end if res = cmplx(tr, ti, kind=${k1}$) end function unif_dist_rvs_${t1[0]}$${k1}$ @@ -318,7 +318,7 @@ contains tmp = shiftr(dist_rand(INT_ONE), 11) t = real(tmp * MESENNE_NUMBER, kind = ${k1}$) res(i) = loc + scale * t - enddo + end do end function unif_dist_rvs_array_${t1[0]}$${k1}$ #:endfor @@ -345,7 +345,7 @@ contains if(scale % re == 0.0_${k1}$) then tr = loc % re ti = loc % im + scale % im * r1 - elseif(scale % im == 0.0_${k1}$) then + else if(scale % im == 0.0_${k1}$) then tr = loc % re + scale % re * r1 ti = loc % im else @@ -353,7 +353,7 @@ contains tmp = shiftr(dist_rand(INT_ONE), 11) r1 = real(tmp * MESENNE_NUMBER, kind = ${k1}$) ti = loc % im + scale % im * r1 - endif + end if res(i) = cmplx(tr, ti, kind=${k1}$) end do end function unif_dist_rvs_array_${t1[0]}$${k1}$ @@ -370,7 +370,7 @@ contains if(scale == 0_${k1}$) then res = 0.0 - elseif(x < loc .or. x > (loc + scale)) then + else if(x < loc .or. x > (loc + scale)) then res = 0.0 else res = 1. / (scale + 1_${k1}$) @@ -389,7 +389,7 @@ contains if(scale == 0.0_${k1}$) then res = 0.0 - elseif(x <= loc .or. x >= (loc + scale)) then + else if(x <= loc .or. x >= (loc + scale)) then res = 0.0 else res = 1.0 / scale @@ -410,7 +410,7 @@ contains tr = loc % re + scale % re; ti = loc % im + scale % im if(scale == (0.0_${k1}$,0.0_${k1}$)) then res = 0.0 - elseif((x % re >= loc % re .and. x % re <= tr) .and. & + else if((x % re >= loc % re .and. x % re <= tr) .and. & (x % im >= loc % im .and. x % im <= ti)) then res = 1.0 / (scale % re * scale % im) else @@ -430,9 +430,9 @@ contains if(scale == 0_${k1}$) then res = 0.0 - elseif(x < loc) then + else if(x < loc) then res = 0.0 - elseif(x >= loc .and. x <= (loc + scale)) then + else if(x >= loc .and. x <= (loc + scale)) then res = real((x - loc + 1_${k1}$)) / real((scale + 1_${k1}$)) else res = 1.0 @@ -451,9 +451,9 @@ contains if(scale == 0.0_${k1}$) then res = 0.0 - elseif(x < loc) then + else if(x < loc) then res = 0.0 - elseif(x >= loc .and. x <= (loc + scale)) then + else if(x >= loc .and. x <= (loc + scale)) then res = (x - loc) / scale else res = 1.0 @@ -474,22 +474,22 @@ contains if(scale == (0.0_${k1}$,0.0_${k1}$)) then res = 0.0 return - endif + end if r1 = x % re < loc % re r2 = x % re > (loc % re + scale % re) i1 = x % im < loc % im i2 = x % im > (loc % im + scale % im) if(r1 .or. i1) then res = 0.0 - elseif((.not. r1) .and. (.not. r2) .and. i2) then + else if((.not. r1) .and. (.not. r2) .and. i2) then res = (x % re - loc % re) / scale % re - elseif((.not. i1) .and. (.not. i2) .and. r2) then + else if((.not. i1) .and. (.not. i2) .and. r2) then res = (x % im - loc % im) / scale % im - elseif((.not. r1) .and. (.not. r2) .and. (.not. i1) .and. (.not. i2)) & + else if((.not. r1) .and. (.not. r2) .and. (.not. i1) .and. (.not. i2)) & then res = (x % re - loc % re) * (x % im - loc % im) / & (scale % re * scale % im) - elseif(r2 .and. i2)then + else if(r2 .and. i2)then res = 1.0 end if end function unif_dist_cdf_${t1[0]}$${k1}$ From edf6ac84c18926517ecc2ad5d1d6e440accc2615 Mon Sep 17 00:00:00 2001 From: Jim-215-Fisher Date: Tue, 21 Sep 2021 18:40:22 -0400 Subject: [PATCH 160/172] public naming change and some corrections --- .../stdlib_stats_distribution_uniform.md | 42 ++++----- src/stdlib_stats_distribution_uniform.fypp | 92 ++++++++++--------- .../stats/test_distribution_uniform.fypp | 43 +++++---- 3 files changed, 90 insertions(+), 87 deletions(-) diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index 9ff958dfb..730836621 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -67,7 +67,7 @@ program demo_shuffle end program demo_shuffle ``` -## `uniform_distribution_rvs` - uniform distribution random variates +## `rvs_uniform` - uniform distribution random variates ### Status @@ -89,11 +89,11 @@ For `complex` type, the real part and imaginary part are independent of each oth ### Syntax -`result = [[stdlib_stats_distribution_uniform(module):uniform_distribution_rvs(interface)]]([[loc,] scale] [[[,array_size]]])` +`result = [[stdlib_stats_distribution_uniform(module):rvs_uniform(interface)]]([[loc,] scale] [[[,array_size]]])` ### Class -Elemental function. +Elemental function (without the third argument). ### Arguments @@ -114,7 +114,7 @@ The result is a scalar or a rank one array, with size of `array_size`, of type ` ```fortran program demo_uniform_rvs use stdlib_stats_distribution_PRNG, only:random_seed - use stdlib_stats_distribution_uniform, only:uni=> uniform_distribution_rvs + use stdlib_stats_distribution_uniform, only:uni=> rvs_uniform implicit none complex :: loc, scale @@ -193,7 +193,7 @@ program demo_uniform_rvs end program demo_uniform_rvs ``` -## `uniform_distribution_pdf` - Uniform probability density function +## `pdf_uniform` - Uniform probability density function ### Status @@ -236,9 +236,8 @@ The result is a scalar or an array, with a shape conformable to arguments, of ty ```fortran program demo_uniform_pdf use stdlib_stats_distribution_PRNG, only : random_seed - use stdlib_stats_distribution_uniform, only : & - uni_pdf => uniform_distribution_pdf, & - uni => uniform_distribution_rvs + use stdlib_stats_distribution_uniform, only : uni_pdf => pdf_uniform, & + uni => rvs_uniform implicit none complex :: loc, scale @@ -287,7 +286,7 @@ end program demo_uniform_pdf ``` -## `uniform_distribution_cdf` - Uniform cumulative distribution function +## `cdf_uniform` - Uniform cumulative distribution function ### Status @@ -305,7 +304,7 @@ F(x) = (x%re - loc%re)(x%im - loc%im) / (scale%re * scale%im); for complex unifo ### Syntax -`result = [[stdlib_stats_distribution_uniform(module):uniform_distribution_cdf(interface)]](x, loc, scale)` +`result = [[stdlib_stats_distribution_uniform(module):cdf_uniform(interface)]](x, loc, scale)` ### Class @@ -330,9 +329,8 @@ The result is a scalar or an array, with a shape conformable to arguments, of ty ```fortran program demo_uniform_cdf use stdlib_stats_distribution_PRNG, only : random_seed - use stdlib_stats_distribution_uniform, only : & - uni_cdf => uniform_distribution_cdf, & - uni => uniform_distribution_rvs, & + use stdlib_stats_distribution_uniform, only : uni_cdf => cdf_uniform, & + uni => rvs_uniform implicit none real :: x(3,4,5), a(3,4,5), b(3,4,5) @@ -359,15 +357,15 @@ program demo_uniform_cdf x = reshape(uni(-1.0,2.0,60),[3,4,5]) ! uniform random variates array print *, uni_cdf(x,a,b) ! cumulative array in [-1.0, 1.0] -!0.161520004 0.553248405 0.986900032 0.942091405 0.114239901 0.780188501 & -! 0.854656875 0.464386612 0.284466714 0.748768032 0.301834047 0.337008357 & -!0.568843365 0.596165061 0.180993259 0.614166319 0.214835495 7.98164606E-02 & -!0.641274095 0.607101977 0.701139212 0.230517209 1.97925568E-02 0.857982159 & -!0.712761045 0.139202654 0.361759573 0.796536088 0.356012046 0.197665215 & -!9.80764329E-02 0.781620383 0.595349193 0.125651121 0.957528770 0.942990601 & -!0.259489566 7.84273148E-02 0.779313922 0.317909390 0.559013724 0.421358019 & -!0.878484428 7.67416358E-02 0.298707575 0.693327367 0.146014273 0.102338850 & -!0.855926156 0.250811368 0.300751567 0.110186398 0.502883077 0.738479793 & +!0.161520004 0.553248405 0.986900032 0.942091405 0.114239901 0.780188501 +! 0.854656875 0.464386612 0.284466714 0.748768032 0.301834047 0.337008357 +!0.568843365 0.596165061 0.180993259 0.614166319 0.214835495 7.98164606E-02 +!0.641274095 0.607101977 0.701139212 0.230517209 1.97925568E-02 0.857982159 +!0.712761045 0.139202654 0.361759573 0.796536088 0.356012046 0.197665215 +!9.80764329E-02 0.781620383 0.595349193 0.125651121 0.957528770 0.942990601 +!0.259489566 7.84273148E-02 0.779313922 0.317909390 0.559013724 0.421358019 +!0.878484428 7.67416358E-02 0.298707575 0.693327367 0.146014273 0.102338850 +!0.855926156 0.250811368 0.300751567 0.110186398 0.502883077 0.738479793 !0.764856219 0.294822574 1.90783739E-02 0.631218433 0.752170086 0.196848959 loc = (0., 0.) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index 526a00989..d7b8189cd 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -12,16 +12,17 @@ module stdlib_stats_distribution_uniform real(dp), parameter :: MESENNE_NUMBER = 1.0_dp / (2.0_dp ** 53 - 1.0_dp) integer(int64), parameter :: INT_ONE = 1_int64 - public :: uniform_distribution_rvs - public :: uniform_distribution_pdf - public :: uniform_distribution_cdf + public :: rvs_uniform + public :: pdf_uniform + public :: cdf_uniform public :: shuffle - interface uniform_distribution_rvs + interface rvs_uniform !! Version experimental !! !! Get uniformly distributed random variate for integer, real and complex + !! variables. !! ([Specification](../page/specs/stdlib_stats_distribution_uniform.html# !! description)) @@ -38,11 +39,11 @@ module stdlib_stats_distribution_uniform #:for k1, t1 in ALL_KINDS_TYPES module procedure unif_dist_rvs_array_${t1[0]}$${k1}$ ! 3 dummy variables #:endfor - end interface uniform_distribution_rvs + end interface rvs_uniform - interface uniform_distribution_pdf - !! Version experiment + interface pdf_uniform + !! Version experimental !! !! Get uniform distribution probability density (pdf) for integer, real and !! complex variables. @@ -52,10 +53,10 @@ module stdlib_stats_distribution_uniform #:for k1, t1 in ALL_KINDS_TYPES module procedure unif_dist_pdf_${t1[0]}$${k1}$ #:endfor - end interface uniform_distribution_pdf + end interface pdf_uniform - interface uniform_distribution_cdf + interface cdf_uniform !! Version experimental !! !! Get uniform distribution cumulative distribution function (cdf) for integer, @@ -66,14 +67,14 @@ module stdlib_stats_distribution_uniform #:for k1, t1 in ALL_KINDS_TYPES module procedure unif_dist_cdf_${t1[0]}$${k1}$ #:endfor - end interface uniform_distribution_cdf + end interface cdf_uniform interface shuffle !! Version experimental !! !! Fisher-Yates shuffle algorithm for a rank one array of integer, real and - !! complex variables + !! complex variables. !! ([Specification](../page/specs/stdlib_stats_distribution_uniform.html# !! description)) !! @@ -85,6 +86,8 @@ module stdlib_stats_distribution_uniform + + contains @@ -101,8 +104,8 @@ contains ${t1}$ :: res, u, mask integer :: zeros, bits_left, bits - if(scale <= 0_${k1}$) call error_stop("Error(unif_dist_rvs_1): Uniform" & - //" distribution scale parameter must be positive") + if(scale <= 0_${k1}$) call error_stop("Error(unif_dist_rvs_1): Uniform"& + //" distribution scale parameter must be positive") zeros = leadz(scale) bits = bit_size(scale) - zeros mask = shiftr(not(0_${k1}$), zeros) @@ -126,7 +129,7 @@ contains #:for k1, t1 in INT_KINDS_TYPES - impure elemental function unif_dist_rvs_${t1[0]}$${k1}$(loc, scale) & + impure elemental function unif_dist_rvs_${t1[0]}$${k1}$(loc, scale) & result( res ) ! ! Uniformly distributed integer in [loc, loc + scale] @@ -134,8 +137,8 @@ contains ${t1}$, intent(in) :: loc, scale ${t1}$ :: res - if(scale <= 0_${k1}$) call error_stop("Error(unif_dist_rvs): Uniform" & - //" distribution scale parameter must be positive") + if(scale <= 0_${k1}$) call error_stop("Error(unif_dist_rvs): Uniform" & + //" distribution scale parameter must be positive") res = loc + unif_dist_rvs_1_${t1[0]}$${k1}$(scale) end function unif_dist_rvs_${t1[0]}$${k1}$ @@ -170,8 +173,8 @@ contains ${t1}$, intent(in) :: scale ${t1}$ :: res - if(scale == 0._${k1}$) call error_stop("Error(unif_dist_rvs_1): " & - //"Uniform distribution scale parameter must be non-zero") + if(scale == 0._${k1}$) call error_stop("Error(unif_dist_rvs_1): " & + //"Uniform distribution scale parameter must be non-zero") res = scale * unif_dist_rvs_0_${t1[0]}$${k1}$( ) end function unif_dist_rvs_1_${t1[0]}$${k1}$ @@ -180,7 +183,7 @@ contains #:for k1, t1 in REAL_KINDS_TYPES - impure elemental function unif_dist_rvs_${t1[0]}$${k1}$(loc, scale) & + impure elemental function unif_dist_rvs_${t1[0]}$${k1}$(loc, scale) & result(res) ! ! Uniformly distributed float in [loc, loc + scale] @@ -188,8 +191,8 @@ contains ${t1}$, intent(in) :: loc, scale ${t1}$ :: res - if(scale == 0._${k1}$) call error_stop("Error(unif_dist_rvs): " & - //"Uniform distribution scale parameter must be non-zero") + if(scale == 0._${k1}$) call error_stop("Error(unif_dist_rvs): " & + //"Uniform distribution scale parameter must be non-zero") res = loc + scale * unif_dist_rvs_0_${t1[0]}$${k1}$( ) end function unif_dist_rvs_${t1[0]}$${k1}$ @@ -198,7 +201,8 @@ contains #:for k1, t1 in CMPLX_KINDS_TYPES - impure elemental function unif_dist_rvs_1_${t1[0]}$${k1}$(scale) result(res) + impure elemental function unif_dist_rvs_1_${t1[0]}$${k1}$(scale) & + result(res) ! ! Uniformly distributed complex in [(0,0i), (scale, i(scale))] ! The real part and imaginary part are independent of each other, so that @@ -208,8 +212,8 @@ contains ${t1}$ :: res real(${k1}$) :: r1, tr, ti - if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(uni_dist_" & - //"rvs_1): Uniform distribution scale parameter must be non-zero") + if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(uni_dist_"& + //"rvs_1): Uniform distribution scale parameter must be non-zero") r1 = unif_dist_rvs_0_r${k1}$( ) if(scale % re == 0.0_${k1}$) then ti = scale % im * r1 @@ -230,10 +234,11 @@ contains #:for k1, t1 in CMPLX_KINDS_TYPES - impure elemental function unif_dist_rvs_${t1[0]}$${k1}$(loc, scale) & + impure elemental function unif_dist_rvs_${t1[0]}$${k1}$(loc, scale) & result(res) ! - ! Uniformly distributed complex in [(loc,iloc), (loc + scale, i(loc + scale))] + ! Uniformly distributed complex in [(loc,iloc), (loc + scale, i(loc + + ! scale))]. ! The real part and imaginary part are independent of each other, so that ! the joint distribution is on an unit square [(loc,iloc), (loc + scale, ! i(loc + scale))] @@ -242,8 +247,8 @@ contains ${t1}$ :: res real(${k1}$) :: r1, tr, ti - if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(uni_dist_" & - //"rvs): Uniform distribution scale parameter must be non-zero") + if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(uni_dist_"& + //"rvs): Uniform distribution scale parameter must be non-zero") r1 = unif_dist_rvs_0_r${k1}$( ) if(scale % re == 0.0_${k1}$) then tr = loc % re @@ -264,7 +269,7 @@ contains #:for k1, t1 in INT_KINDS_TYPES - function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & + function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & result(res) integer, intent(in) :: array_size @@ -273,8 +278,8 @@ contains ${t1}$ :: u, mask, nn integer :: i, zeros, bits_left, bits - if(scale == 0_${k1}$) call error_stop("Error(unif_dist_rvs_array): Uniform" & - //" distribution scale parameter must be non-zero") + if(scale == 0_${k1}$) call error_stop("Error(unif_dist_rvs_array): " & + //"Uniform distribution scale parameter must be non-zero") zeros = leadz(scale) bits = bit_size(scale) - zeros mask = shiftr(not(0_${k1}$), zeros) @@ -301,7 +306,7 @@ contains #:for k1, t1 in REAL_KINDS_TYPES - function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & + function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & result(res) integer, intent(in) :: array_size @@ -312,8 +317,8 @@ contains integer :: i - if(scale == 0._${k1}$) call error_stop("Error(unif_dist_rvs_array):" & - //" Uniform distribution scale parameter must be non-zero") + if(scale == 0._${k1}$) call error_stop("Error(unif_dist_rvs_array):" & + //" Uniform distribution scale parameter must be non-zero") do i = 1, array_size tmp = shiftr(dist_rand(INT_ONE), 11) t = real(tmp * MESENNE_NUMBER, kind = ${k1}$) @@ -326,7 +331,7 @@ contains #:for k1, t1 in CMPLX_KINDS_TYPES - function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & + function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & result(res) integer, intent(in) :: array_size @@ -337,8 +342,9 @@ contains integer :: i - if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(unif_dist_"& - //"rvs_array): Uniform distribution scale parameter must be non-zero") + if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(unif_dist"& + //"_rvs_array): Uniform distribution scale parameter must be " & + //"non-zero") do i = 1, array_size tmp = shiftr(dist_rand(INT_ONE), 11) r1 = real(tmp * MESENNE_NUMBER, kind = ${k1}$) @@ -389,7 +395,7 @@ contains if(scale == 0.0_${k1}$) then res = 0.0 - elseif(x <= loc .or. x >= (loc + scale)) then + elseif(x < loc .or. x > (loc + scale)) then res = 0.0 else res = 1.0 / scale @@ -410,8 +416,8 @@ contains tr = loc % re + scale % re; ti = loc % im + scale % im if(scale == (0.0_${k1}$,0.0_${k1}$)) then res = 0.0 - elseif((x % re >= loc % re .and. x % re <= tr) .and. & - (x % im >= loc % im .and. x % im <= ti)) then + elseif((x % re > loc % re .and. x % re < tr) .and. & + (x % im > loc % im .and. x % im < ti)) then res = 1.0 / (scale % re * scale % im) else res = 0.0 @@ -485,9 +491,9 @@ contains res = (x % re - loc % re) / scale % re elseif((.not. i1) .and. (.not. i2) .and. r2) then res = (x % im - loc % im) / scale % im - elseif((.not. r1) .and. (.not. r2) .and. (.not. i1) .and. (.not. i2)) & + elseif((.not. r1) .and. (.not. r2) .and. (.not. i1) .and. (.not. i2)) & then - res = (x % re - loc % re) * (x % im - loc % im) / & + res = (x % re - loc % re) * (x % im - loc % im) / & (scale % re * scale % im) elseif(r2 .and. i2)then res = 1.0 @@ -509,7 +515,7 @@ contains n = size(list) res = list do i = 1, n - 1 - j = uniform_distribution_rvs(n - i) + i + j = rvs_uniform(n - i) + i tmp = res(i) res(i) = res(j) res(j) = tmp diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index 10fa98802..b049acc2a 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -4,10 +4,9 @@ program test_distribution_uniform use stdlib_error, only : check use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, qp use stdlib_stats_distribution_PRNG, only : random_seed, dist_rand - use stdlib_stats_distribution_uniform, & - uni_rvs => uniform_distribution_rvs, & - uni_pdf => uniform_distribution_pdf, & - uni_cdf => uniform_distribution_cdf + use stdlib_stats_distribution_uniform, uni_rvs => rvs_uniform, & + uni_pdf => pdf_uniform, & + uni_cdf => cdf_uniform implicit none logical :: warn = .true. @@ -44,15 +43,15 @@ contains integer, parameter :: na(10) = [10, 6, 9, 2, 8, 1, 3, 5, 7, 4] real :: x(10) real, parameter :: xa(10) = [5.0, 10.0, 9.0, 4.0, 3.0, 8.0, 2.0, 1.0, & - 7.0, 6.0] + 7.0, 6.0] complex :: z(10) complex, parameter :: za(10) = [(8.0, 8.0), (7.0, 7.0), (4.0, 4.0), & - (1.0, 1.0), (5.0, 5.0), (9.0, 9.0), & - (6.0, 6.0), (3.0, 3.0), (2.0, 2.0), & - (10.0, 10.0)] + (1.0, 1.0), (5.0, 5.0), (9.0, 9.0), & + (6.0, 6.0), (3.0, 3.0), (2.0, 2.0), & + (10.0, 10.0)] integer :: i, put, get - do i=1, 10 + do i = 1, 10 n(i) = i x(i) = real(i) z(i) = cmplx(real(i),real(i)) @@ -62,18 +61,18 @@ contains n(:) = shuffle(n) x(:) = shuffle(x) z(:) = shuffle(z) - call check(all(n == na), & - msg="Integer shuffle failed test", warn=warn) - call check(all(x == xa), & - msg="Real shuffle failed test", warn=warn) - call check(all(z == za), & - msg="Complex shuffle failed test", warn=warn) + call check(all(n == na), & + msg = "Integer shuffle failed test", warn=warn) + call check(all(x == xa), & + msg = "Real shuffle failed test", warn=warn) + call check(all(z == za), & + msg = "Complex shuffle failed test", warn=warn) end subroutine test_shuffle subroutine test_uni_rvs_0 - integer, parameter :: num=10000000 + integer, parameter :: num = 10000000 integer, parameter :: array_size = 1000 integer :: i, j, freq(0 : array_size - 1) real(dp) :: chisq, expct @@ -90,11 +89,11 @@ contains do i = 0, array_size - 1 chisq = chisq + (freq(i) - expct) ** 2 / expct end do - write(*,*) "The critical values for chi-squared with 1000 d. of f. are"& - //" 1143.92" + write(*,*) "The critical value for chi-squared with 1000 d. of f. is" & + //" 1143.92" write(*,*) "Chi-squared for uniform random generator is : ", chisq - call check((chisq < 1143.9) , & - msg="uniform randomness failed chi-squared test", warn=warn) + call check((chisq < 1143.9) , & + msg = "uniform randomness failed chi-squared test", warn=warn) end subroutine test_uni_rvs_0 @@ -225,7 +224,7 @@ contains res(:,1) = uni_pdf(x1, loc, scale) res(:, 2:5) = uni_pdf(x2, loc, scale) call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_pdf_${t1[0]}$${k1}$ failed", warn=warn) + msg = "uniform_distribution_pdf_${t1[0]}$${k1}$ failed", warn=warn) end subroutine test_uni_pdf_${t1[0]}$${k1}$ #:endfor @@ -291,7 +290,7 @@ contains res(:,1) = uni_cdf(x1, loc, scale) res(:, 2:5) = uni_cdf(x2, loc, scale) call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg="uniform_distribution_cdf_${t1[0]}$${k1}$ failed", warn=warn) + msg = "uniform_distribution_cdf_${t1[0]}$${k1}$ failed", warn=warn) end subroutine test_uni_cdf_${t1[0]}$${k1}$ #:endfor From ae1c3f9b1f94a6d9140361738a279af3fbc41c8b Mon Sep 17 00:00:00 2001 From: Jim-215-Fisher Date: Wed, 22 Sep 2021 16:06:09 -0400 Subject: [PATCH 161/172] Add comments and change some function names --- src/stdlib_stats_distribution_uniform.fypp | 122 ++++++++---------- .../stats/test_distribution_uniform.fypp | 50 +++---- 2 files changed, 82 insertions(+), 90 deletions(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index 26fda8b7f..024e8b429 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -26,18 +26,18 @@ module stdlib_stats_distribution_uniform !! ([Specification](../page/specs/stdlib_stats_distribution_uniform.html# !! description)) - module procedure unif_dist_rvs_0_rsp ! 0 dummy variable + module procedure rvs_unif_0_rsp ! 0 dummy variable #:for k1, t1 in ALL_KINDS_TYPES - module procedure unif_dist_rvs_1_${t1[0]}$${k1}$ ! 1 dummy variable + module procedure rvs_unif_1_${t1[0]}$${k1}$ ! 1 dummy variable #:endfor #:for k1, t1 in ALL_KINDS_TYPES - module procedure unif_dist_rvs_${t1[0]}$${k1}$ ! 2 dummy variables + module procedure rvs_unif_${t1[0]}$${k1}$ ! 2 dummy variables #:endfor #:for k1, t1 in ALL_KINDS_TYPES - module procedure unif_dist_rvs_array_${t1[0]}$${k1}$ ! 3 dummy variables + module procedure rvs_unif_array_${t1[0]}$${k1}$ ! 3 dummy variables #:endfor end interface rvs_uniform @@ -51,7 +51,7 @@ module stdlib_stats_distribution_uniform !! description)) #:for k1, t1 in ALL_KINDS_TYPES - module procedure unif_dist_pdf_${t1[0]}$${k1}$ + module procedure pdf_unif_${t1[0]}$${k1}$ #:endfor end interface pdf_uniform @@ -65,7 +65,7 @@ module stdlib_stats_distribution_uniform !! description)) !! #:for k1, t1 in ALL_KINDS_TYPES - module procedure unif_dist_cdf_${t1[0]}$${k1}$ + module procedure cdf_unif_${t1[0]}$${k1}$ #:endfor end interface cdf_uniform @@ -92,7 +92,7 @@ contains #:for k1, t1 in INT_KINDS_TYPES - impure elemental function unif_dist_rvs_1_${t1[0]}$${k1}$(scale) result(res) + impure elemental function rvs_unif_1_${t1[0]}$${k1}$(scale) result(res) ! ! Uniformly distributed integer in [0, scale] ! Bitmask with rejection @@ -104,7 +104,7 @@ contains ${t1}$ :: res, u, mask integer :: zeros, bits_left, bits - if(scale <= 0_${k1}$) call error_stop("Error(unif_dist_rvs_1): Uniform"& + if(scale <= 0_${k1}$) call error_stop("Error(rvs_unif_1): Uniform" & //" distribution scale parameter must be positive") zeros = leadz(scale) bits = bit_size(scale) - zeros @@ -122,32 +122,31 @@ contains bits_left = bits_left - bits end do L2 end do L1 - end function unif_dist_rvs_1_${t1[0]}$${k1}$ + end function rvs_unif_1_${t1[0]}$${k1}$ #:endfor #:for k1, t1 in INT_KINDS_TYPES - impure elemental function unif_dist_rvs_${t1[0]}$${k1}$(loc, scale) & - result( res ) + impure elemental function rvs_unif_${t1[0]}$${k1}$(loc, scale) result(res) ! ! Uniformly distributed integer in [loc, loc + scale] ! ${t1}$, intent(in) :: loc, scale ${t1}$ :: res - if(scale <= 0_${k1}$) call error_stop("Error(unif_dist_rvs): Uniform" & + if(scale <= 0_${k1}$) call error_stop("Error(rvs_unif): Uniform" & //" distribution scale parameter must be positive") - res = loc + unif_dist_rvs_1_${t1[0]}$${k1}$(scale) - end function unif_dist_rvs_${t1[0]}$${k1}$ + res = loc + rvs_unif_1_${t1[0]}$${k1}$(scale) + end function rvs_unif_${t1[0]}$${k1}$ #:endfor #:for k1, t1 in REAL_KINDS_TYPES - impure elemental function unif_dist_rvs_0_${t1[0]}$${k1}$( ) result(res) + impure elemental function rvs_unif_0_${t1[0]}$${k1}$( ) result(res) ! ! Uniformly distributed float in [0,1] ! Based on the paper by Frederic Goualard, "Generating Random Floating- @@ -159,50 +158,48 @@ contains tmp = shiftr(dist_rand(INT_ONE), 11) ! Get random from [0,2^53-1] res = real(tmp * MESENNE_NUMBER, kind = ${k1}$) ! convert to [0,1] - end function unif_dist_rvs_0_${t1[0]}$${k1}$ + end function rvs_unif_0_${t1[0]}$${k1}$ #:endfor #:for k1, t1 in REAL_KINDS_TYPES - impure elemental function unif_dist_rvs_1_${t1[0]}$${k1}$(scale) result(res) + impure elemental function rvs_unif_1_${t1[0]}$${k1}$(scale) result(res) ! ! Uniformly distributed float in [0, scale] ! ${t1}$, intent(in) :: scale ${t1}$ :: res - if(scale == 0._${k1}$) call error_stop("Error(unif_dist_rvs_1): " & + if(scale == 0._${k1}$) call error_stop("Error(rvs_unif_1): " & //"Uniform distribution scale parameter must be non-zero") - res = scale * unif_dist_rvs_0_${t1[0]}$${k1}$( ) - end function unif_dist_rvs_1_${t1[0]}$${k1}$ + res = scale * rvs_unif_0_${t1[0]}$${k1}$( ) + end function rvs_unif_1_${t1[0]}$${k1}$ #:endfor #:for k1, t1 in REAL_KINDS_TYPES - impure elemental function unif_dist_rvs_${t1[0]}$${k1}$(loc, scale) & - result(res) + impure elemental function rvs_unif_${t1[0]}$${k1}$(loc, scale) result(res) ! ! Uniformly distributed float in [loc, loc + scale] ! ${t1}$, intent(in) :: loc, scale ${t1}$ :: res - if(scale == 0._${k1}$) call error_stop("Error(unif_dist_rvs): " & + if(scale == 0._${k1}$) call error_stop("Error(rvs_unif): " & //"Uniform distribution scale parameter must be non-zero") - res = loc + scale * unif_dist_rvs_0_${t1[0]}$${k1}$( ) - end function unif_dist_rvs_${t1[0]}$${k1}$ + res = loc + scale * rvs_unif_0_${t1[0]}$${k1}$( ) + end function rvs_unif_${t1[0]}$${k1}$ #:endfor #:for k1, t1 in CMPLX_KINDS_TYPES - impure elemental function unif_dist_rvs_1_${t1[0]}$${k1}$(scale) & - result(res) + impure elemental function rvs_unif_1_${t1[0]}$${k1}$(scale) result(res) ! ! Uniformly distributed complex in [(0,0i), (scale, i(scale))] ! The real part and imaginary part are independent of each other, so that @@ -212,9 +209,9 @@ contains ${t1}$ :: res real(${k1}$) :: r1, tr, ti - if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(uni_dist_"& - //"rvs_1): Uniform distribution scale parameter must be non-zero") - r1 = unif_dist_rvs_0_r${k1}$( ) + if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(rvs_uni_" & + //"1): Uniform distribution scale parameter must be non-zero") + r1 = rvs_unif_0_r${k1}$( ) if(scale % re == 0.0_${k1}$) then ti = scale % im * r1 tr = 0.0_${k1}$ @@ -223,19 +220,18 @@ contains ti = 0.0_${k1}$ else tr = scale % re * r1 - r1 = unif_dist_rvs_0_r${k1}$( ) + r1 = rvs_unif_0_r${k1}$( ) ti = scale % im * r1 end if res = cmplx(tr, ti, kind=${k1}$) - end function unif_dist_rvs_1_${t1[0]}$${k1}$ + end function rvs_unif_1_${t1[0]}$${k1}$ #:endfor #:for k1, t1 in CMPLX_KINDS_TYPES - impure elemental function unif_dist_rvs_${t1[0]}$${k1}$(loc, scale) & - result(res) + impure elemental function rvs_unif_${t1[0]}$${k1}$(loc, scale) result(res) ! ! Uniformly distributed complex in [(loc,iloc), (loc + scale, i(loc + ! scale))]. @@ -247,9 +243,9 @@ contains ${t1}$ :: res real(${k1}$) :: r1, tr, ti - if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(uni_dist_"& - //"rvs): Uniform distribution scale parameter must be non-zero") - r1 = unif_dist_rvs_0_r${k1}$( ) + if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(rvs_uni_" & + //"): Uniform distribution scale parameter must be non-zero") + r1 = rvs_unif_0_r${k1}$( ) if(scale % re == 0.0_${k1}$) then tr = loc % re ti = loc % im + scale % im * r1 @@ -258,19 +254,18 @@ contains ti = loc % im else tr = loc % re + scale % re * r1 - r1 = unif_dist_rvs_0_r${k1}$( ) + r1 = rvs_unif_0_r${k1}$( ) ti = loc % im + scale % im * r1 end if res = cmplx(tr, ti, kind=${k1}$) - end function unif_dist_rvs_${t1[0]}$${k1}$ + end function rvs_unif_${t1[0]}$${k1}$ #:endfor #:for k1, t1 in INT_KINDS_TYPES - function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & - result(res) + function rvs_unif_array_${t1[0]}$${k1}$(loc, scale, array_size) result(res) integer, intent(in) :: array_size ${t1}$, intent(in) :: loc, scale @@ -278,7 +273,7 @@ contains ${t1}$ :: u, mask, nn integer :: i, zeros, bits_left, bits - if(scale == 0_${k1}$) call error_stop("Error(unif_dist_rvs_array): " & + if(scale == 0_${k1}$) call error_stop("Error(rvs_unif_array): " & //"Uniform distribution scale parameter must be non-zero") zeros = leadz(scale) bits = bit_size(scale) - zeros @@ -299,15 +294,14 @@ contains end do L1 res(i) = loc + nn end do - end function unif_dist_rvs_array_${t1[0]}$${k1}$ + end function rvs_unif_array_${t1[0]}$${k1}$ #:endfor #:for k1, t1 in REAL_KINDS_TYPES - function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & - result(res) + function rvs_unif_array_${t1[0]}$${k1}$(loc, scale, array_size) result(res) integer, intent(in) :: array_size ${t1}$, intent(in) :: loc, scale @@ -317,22 +311,21 @@ contains integer :: i - if(scale == 0._${k1}$) call error_stop("Error(unif_dist_rvs_array):" & + if(scale == 0._${k1}$) call error_stop("Error(rvs_unif_array):" & //" Uniform distribution scale parameter must be non-zero") do i = 1, array_size tmp = shiftr(dist_rand(INT_ONE), 11) t = real(tmp * MESENNE_NUMBER, kind = ${k1}$) res(i) = loc + scale * t end do - end function unif_dist_rvs_array_${t1[0]}$${k1}$ + end function rvs_unif_array_${t1[0]}$${k1}$ #:endfor #:for k1, t1 in CMPLX_KINDS_TYPES - function unif_dist_rvs_array_${t1[0]}$${k1}$(loc, scale, array_size) & - result(res) + function rvs_unif_array_${t1[0]}$${k1}$(loc, scale, array_size) result(res) integer, intent(in) :: array_size ${t1}$, intent(in) :: loc, scale @@ -342,9 +335,8 @@ contains integer :: i - if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(unif_dist"& - //"_rvs_array): Uniform distribution scale parameter must be " & - //"non-zero") + if(scale == (0.0_${k1}$, 0.0_${k1}$)) call error_stop("Error(rvs_unif" & + //"_array): Uniform distribution scale parameter must be non-zero") do i = 1, array_size tmp = shiftr(dist_rand(INT_ONE), 11) r1 = real(tmp * MESENNE_NUMBER, kind = ${k1}$) @@ -362,14 +354,14 @@ contains end if res(i) = cmplx(tr, ti, kind=${k1}$) end do - end function unif_dist_rvs_array_${t1[0]}$${k1}$ + end function rvs_unif_array_${t1[0]}$${k1}$ #:endfor #:for k1, t1 in INT_KINDS_TYPES - elemental function unif_dist_pdf_${t1[0]}$${k1}$(x, loc, scale) result(res) + elemental function pdf_unif_${t1[0]}$${k1}$(x, loc, scale) result(res) ${t1}$, intent(in) :: x, loc, scale real :: res @@ -381,14 +373,14 @@ contains else res = 1. / (scale + 1_${k1}$) end if - end function unif_dist_pdf_${t1[0]}$${k1}$ + end function pdf_unif_${t1[0]}$${k1}$ #:endfor #:for k1, t1 in REAL_KINDS_TYPES - elemental function unif_dist_pdf_${t1[0]}$${k1}$(x, loc, scale) result(res) + elemental function pdf_unif_${t1[0]}$${k1}$(x, loc, scale) result(res) ${t1}$, intent(in) :: x, loc, scale real :: res @@ -400,14 +392,14 @@ contains else res = 1.0 / scale end if - end function unif_dist_pdf_${t1[0]}$${k1}$ + end function pdf_unif_${t1[0]}$${k1}$ #:endfor #:for k1, t1 in CMPLX_KINDS_TYPES - elemental function unif_dist_pdf_${t1[0]}$${k1}$(x, loc, scale) result(res) + elemental function pdf_unif_${t1[0]}$${k1}$(x, loc, scale) result(res) ${t1}$, intent(in) :: x, loc, scale real :: res @@ -422,14 +414,14 @@ contains else res = 0.0 end if - end function unif_dist_pdf_${t1[0]}$${k1}$ + end function pdf_unif_${t1[0]}$${k1}$ #:endfor #:for k1, t1 in INT_KINDS_TYPES - elemental function unif_dist_cdf_${t1[0]}$${k1}$(x, loc, scale) result(res) + elemental function cdf_unif_${t1[0]}$${k1}$(x, loc, scale) result(res) ${t1}$, intent(in) :: x, loc, scale real :: res @@ -443,14 +435,14 @@ contains else res = 1.0 end if - end function unif_dist_cdf_${t1[0]}$${k1}$ + end function cdf_unif_${t1[0]}$${k1}$ #:endfor #:for k1, t1 in REAL_KINDS_TYPES - elemental function unif_dist_cdf_${t1[0]}$${k1}$(x, loc, scale) result(res) + elemental function cdf_unif_${t1[0]}$${k1}$(x, loc, scale) result(res) ${t1}$, intent(in) :: x, loc, scale real :: res @@ -464,14 +456,14 @@ contains else res = 1.0 end if - end function unif_dist_cdf_${t1[0]}$${k1}$ + end function cdf_unif_${t1[0]}$${k1}$ #:endfor #:for k1, t1 in CMPLX_KINDS_TYPES - elemental function unif_dist_cdf_${t1[0]}$${k1}$(x, loc, scale) result(res) + elemental function cdf_unif_${t1[0]}$${k1}$(x, loc, scale) result(res) ${t1}$, intent(in) :: x, loc, scale real :: res @@ -498,7 +490,7 @@ contains else if(r2 .and. i2)then res = 1.0 end if - end function unif_dist_cdf_${t1[0]}$${k1}$ + end function cdf_unif_${t1[0]}$${k1}$ #:endfor diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index b049acc2a..385370eda 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -115,7 +115,7 @@ contains #:elif k1 == "int64" ${t1}$, parameter :: ans(15) = [76, 45, 43, 75, 76, 15, 25, 24, 114, & 113, 94, 29, 109, 93, 89] - #:elif t1[0] == "r" + #:elif t1[0] == "r" #! for real type ${t1}$, parameter :: ans(15) = & [0.914826628538749186958511927514337003_${k1}$, & 0.367330098664966409049981166390352882_${k1}$, & @@ -132,7 +132,7 @@ contains -0.901660046141515819639877804547722917_${k1}$, & -0.164090614147737401395943379611708224_${k1}$, & -0.333886718190384290672056977200554684_${k1}$] - #:else + #:else #! for complex type ${t1}$, parameter :: ans(15) = & [(0.457413314269374593479255963757168502_${k1}$, & 0.183665049332483204524990583195176441_${k1}$), & @@ -166,14 +166,14 @@ contains 1.01282963412172621886497836385387927_${k1}$)] #:endif - print *, "Test uniform_distribution_rvs_${t1[0]}$${k1}$" + print *, "Test rvs_uniform_${t1[0]}$${k1}$" seed = 258147369; k = 5 call random_seed(seed, get) - #:if t1[0] == "i" + #:if t1[0] == "i" #! for integer type loc = 15_${k1}$; scale = 100_${k1}$ - #:elif t1[0] == "r" + #:elif t1[0] == "r" #! for real type loc = -1.0_${k1}$; scale = 2.0_${k1}$ - #:else + #:else #! for complex type loc = (-0.5_${k1}$,0.5_${k1}$); scale = (1.0_${k1}$, 1.0_${k1}$) #:endif do i = 1, 5 @@ -183,12 +183,12 @@ contains res(i) = uni_rvs(loc, scale) ! 2 dummies end do res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - #:if t1[0] == "i" + #:if t1[0] == "i" #! for integer type call check(all(res == ans), & - msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) - #:else + msg="rvs_uniform_${t1[0]}$${k1}$ failed", warn=warn) + #:else #! for real and complex types call check(all(abs(res - ans) < ${k1}$tol), & - msg="uniform_distribution_rvs_${t1[0]}$${k1}$ failed", warn=warn) + msg="rvs_uniform_${t1[0]}$${k1}$ failed", warn=warn) #:endif end subroutine test_uni_rvs_${t1[0]}$${k1}$ @@ -201,22 +201,22 @@ contains ${t1}$ :: x1, x2(3,4), loc, scale integer :: seed, get, i real :: res(3,5) - #:if t1[0] == "i" + #:if t1[0] == "i" #! for integer type real, parameter :: ans(15) = [(1.96078438E-02, i=1,15)] - #:elif t1[0] == "r" + #:elif t1[0] == "r" #! for real type real, parameter :: ans(15) = [(0.5, i=1,15)] - #:else + #:else #! for complex type real, parameter :: ans(15) = [(1.0, i=1,15)] #:endif - print *, "Test uniform_distribution_pdf_${t1[0]}$${k1}$" + print *, "Test pdf_uniform_${t1[0]}$${k1}$" seed = 147258639 call random_seed(seed, get) - #:if t1[0] == "i" + #:if t1[0] == "i" #! for integer type loc = 0_${k1}$; scale = 50_${k1}$ - #:elif t1[0] == "r" + #:elif t1[0] == "r" #! for real type loc = 0.0_${k1}$; scale = 2.0_${k1}$ - #:else + #:else #! for complex type loc = (-0.5_${k1}$, 0.5_${k1}$); scale = (1.0_${k1}$, 1.0_${k1}$) #:endif x1 = uni_rvs(loc, scale) @@ -224,7 +224,7 @@ contains res(:,1) = uni_pdf(x1, loc, scale) res(:, 2:5) = uni_pdf(x2, loc, scale) call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg = "uniform_distribution_pdf_${t1[0]}$${k1}$ failed", warn=warn) + msg = "pdf_uniform_${t1[0]}$${k1}$ failed", warn=warn) end subroutine test_uni_pdf_${t1[0]}$${k1}$ #:endfor @@ -260,13 +260,13 @@ contains 0.851485133, 0.623762369, 5.94059415E-02,& 0.693069279, 0.544554472, 0.207920790, & 0.306930691, 0.356435657, 0.128712878] - #:elif t1[0] == "r" + #:elif t1[0] == "r" #! for real type real, parameter :: ans(15) = [0.170192942, 0.170192942, 0.170192942, & 0.276106149, 0.754930079, 0.406620681, & 0.187742814, 0.651605546, 0.934733927, & 0.151271492, 0.987674534, 0.130533904, & 0.106271908, 9.27578658E-02, 0.203399420] - #:else + #:else #! for complex type real, parameter :: ans(15) = [4.69913185E-02, 4.69913185E-02, & 4.69913185E-02, 0.306970179, 0.122334257,& 0.141398594, 0.128925011, 9.85755492E-03,& @@ -275,14 +275,14 @@ contains 5.31753292E-04, 0.101455867, 0.155276477] #:endif - print *, "Test uniform_distribution_cdf_${t1[0]}$${k1}$" + print *, "Test cdf_uniform_${t1[0]}$${k1}$" seed = 369147258 call random_seed(seed, get) - #:if t1[0] == "i" + #:if t1[0] == "i" #! for integer type loc = 14_${k1}$; scale = 100_${k1}$ - #:elif t1[0] == "r" + #:elif t1[0] == "r" #! for real type loc = 0.0_${k1}$; scale = 2.0_${k1}$ - #:else + #:else #! for complex type loc = (-0.5_${k1}$, -0.5_${k1}$); scale = (1.0_${k1}$, 1.0_${k1}$) #:endif x1 = uni_rvs(loc, scale) @@ -290,7 +290,7 @@ contains res(:,1) = uni_cdf(x1, loc, scale) res(:, 2:5) = uni_cdf(x2, loc, scale) call check(all(abs(res - reshape(ans,[3,5])) < sptol), & - msg = "uniform_distribution_cdf_${t1[0]}$${k1}$ failed", warn=warn) + msg = "cdf_uniform_${t1[0]}$${k1}$ failed", warn=warn) end subroutine test_uni_cdf_${t1[0]}$${k1}$ #:endfor From a9eee6b70935caf5e9309a4c438033d9d147234f Mon Sep 17 00:00:00 2001 From: Jim-215-Fisher Date: Wed, 22 Sep 2021 16:23:30 -0400 Subject: [PATCH 162/172] correct FYPP comment format --- .../stats/test_distribution_uniform.fypp | 54 ++++++++++++------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index 385370eda..b8efb996e 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -115,7 +115,8 @@ contains #:elif k1 == "int64" ${t1}$, parameter :: ans(15) = [76, 45, 43, 75, 76, 15, 25, 24, 114, & 113, 94, 29, 109, 93, 89] - #:elif t1[0] == "r" #! for real type + #:elif t1[0] == "r" + #! for real type ${t1}$, parameter :: ans(15) = & [0.914826628538749186958511927514337003_${k1}$, & 0.367330098664966409049981166390352882_${k1}$, & @@ -132,7 +133,8 @@ contains -0.901660046141515819639877804547722917_${k1}$, & -0.164090614147737401395943379611708224_${k1}$, & -0.333886718190384290672056977200554684_${k1}$] - #:else #! for complex type + #:else + #! for complex type ${t1}$, parameter :: ans(15) = & [(0.457413314269374593479255963757168502_${k1}$, & 0.183665049332483204524990583195176441_${k1}$), & @@ -169,11 +171,14 @@ contains print *, "Test rvs_uniform_${t1[0]}$${k1}$" seed = 258147369; k = 5 call random_seed(seed, get) - #:if t1[0] == "i" #! for integer type + #:if t1[0] == "i" + #! for integer type loc = 15_${k1}$; scale = 100_${k1}$ - #:elif t1[0] == "r" #! for real type + #:elif t1[0] == "r" + #! for real type loc = -1.0_${k1}$; scale = 2.0_${k1}$ - #:else #! for complex type + #:else + #! for complex type loc = (-0.5_${k1}$,0.5_${k1}$); scale = (1.0_${k1}$, 1.0_${k1}$) #:endif do i = 1, 5 @@ -183,10 +188,12 @@ contains res(i) = uni_rvs(loc, scale) ! 2 dummies end do res(11:15) = uni_rvs(loc, scale, k) ! 3 dummies - #:if t1[0] == "i" #! for integer type + #:if t1[0] == "i" + #! for integer type call check(all(res == ans), & msg="rvs_uniform_${t1[0]}$${k1}$ failed", warn=warn) - #:else #! for real and complex types + #:else + #! for real and complex types call check(all(abs(res - ans) < ${k1}$tol), & msg="rvs_uniform_${t1[0]}$${k1}$ failed", warn=warn) #:endif @@ -201,22 +208,28 @@ contains ${t1}$ :: x1, x2(3,4), loc, scale integer :: seed, get, i real :: res(3,5) - #:if t1[0] == "i" #! for integer type + #:if t1[0] == "i" + #! for integer type real, parameter :: ans(15) = [(1.96078438E-02, i=1,15)] - #:elif t1[0] == "r" #! for real type + #:elif t1[0] == "r" + #! for real type real, parameter :: ans(15) = [(0.5, i=1,15)] - #:else #! for complex type + #:else + #! for complex type real, parameter :: ans(15) = [(1.0, i=1,15)] #:endif print *, "Test pdf_uniform_${t1[0]}$${k1}$" seed = 147258639 call random_seed(seed, get) - #:if t1[0] == "i" #! for integer type + #:if t1[0] == "i" + #! for integer type loc = 0_${k1}$; scale = 50_${k1}$ - #:elif t1[0] == "r" #! for real type + #:elif t1[0] == "r" + #! for real type loc = 0.0_${k1}$; scale = 2.0_${k1}$ - #:else #! for complex type + #:else + #! for complex type loc = (-0.5_${k1}$, 0.5_${k1}$); scale = (1.0_${k1}$, 1.0_${k1}$) #:endif x1 = uni_rvs(loc, scale) @@ -260,13 +273,15 @@ contains 0.851485133, 0.623762369, 5.94059415E-02,& 0.693069279, 0.544554472, 0.207920790, & 0.306930691, 0.356435657, 0.128712878] - #:elif t1[0] == "r" #! for real type + #:elif t1[0] == "r" + #! for real type real, parameter :: ans(15) = [0.170192942, 0.170192942, 0.170192942, & 0.276106149, 0.754930079, 0.406620681, & 0.187742814, 0.651605546, 0.934733927, & 0.151271492, 0.987674534, 0.130533904, & 0.106271908, 9.27578658E-02, 0.203399420] - #:else #! for complex type + #:else + #! for complex type real, parameter :: ans(15) = [4.69913185E-02, 4.69913185E-02, & 4.69913185E-02, 0.306970179, 0.122334257,& 0.141398594, 0.128925011, 9.85755492E-03,& @@ -278,11 +293,14 @@ contains print *, "Test cdf_uniform_${t1[0]}$${k1}$" seed = 369147258 call random_seed(seed, get) - #:if t1[0] == "i" #! for integer type + #:if t1[0] == "i" + #! for integer type loc = 14_${k1}$; scale = 100_${k1}$ - #:elif t1[0] == "r" #! for real type + #:elif t1[0] == "r" + #! for real type loc = 0.0_${k1}$; scale = 2.0_${k1}$ - #:else #! for complex type + #:else + #! for complex type loc = (-0.5_${k1}$, -0.5_${k1}$); scale = (1.0_${k1}$, 1.0_${k1}$) #:endif x1 = uni_rvs(loc, scale) From a904337ec51d5f2323b1747a8b6a31c056b58dd8 Mon Sep 17 00:00:00 2001 From: Jeremie Vandenplas Date: Sat, 2 Oct 2021 20:45:49 +0200 Subject: [PATCH 163/172] changed Version to version:, such that ford considers it as meta-info --- src/stdlib_stats_distribution_uniform.fypp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index 024e8b429..016b37734 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -19,7 +19,7 @@ module stdlib_stats_distribution_uniform interface rvs_uniform - !! Version experimental + !! version: experimental !! !! Get uniformly distributed random variate for integer, real and complex !! variables. @@ -43,7 +43,7 @@ module stdlib_stats_distribution_uniform interface pdf_uniform - !! Version experimental + !! version: experimental !! !! Get uniform distribution probability density (pdf) for integer, real and !! complex variables. @@ -57,7 +57,7 @@ module stdlib_stats_distribution_uniform interface cdf_uniform - !! Version experimental + !! version: experimental !! !! Get uniform distribution cumulative distribution function (cdf) for integer, !! real and complex variables. @@ -71,7 +71,7 @@ module stdlib_stats_distribution_uniform interface shuffle - !! Version experimental + !! version: experimental !! !! Fisher-Yates shuffle algorithm for a rank one array of integer, real and !! complex variables. From 884623bbd694a721dfebef6f2826cced586fbc66 Mon Sep 17 00:00:00 2001 From: Jeremie Vandenplas Date: Sat, 2 Oct 2021 20:54:23 +0200 Subject: [PATCH 164/172] update all specs links --- src/stdlib_stats_distribution_uniform.fypp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index 016b37734..0441dc066 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -24,7 +24,7 @@ module stdlib_stats_distribution_uniform !! Get uniformly distributed random variate for integer, real and complex !! variables. !! ([Specification](../page/specs/stdlib_stats_distribution_uniform.html# - !! description)) + !! rvs_uniform-uniform-distribution-random-variates)) module procedure rvs_unif_0_rsp ! 0 dummy variable @@ -48,7 +48,7 @@ module stdlib_stats_distribution_uniform !! Get uniform distribution probability density (pdf) for integer, real and !! complex variables. !! ([Specification](../page/specs/stdlib_stats_distribution_uniform.html# - !! description)) + !! pdf_uniform-uniform-probability-density-function)) #:for k1, t1 in ALL_KINDS_TYPES module procedure pdf_unif_${t1[0]}$${k1}$ @@ -62,7 +62,7 @@ module stdlib_stats_distribution_uniform !! Get uniform distribution cumulative distribution function (cdf) for integer, !! real and complex variables. !! ([Specification](../page/specs/stdlib_stats_distribution_uniform.html# - !! description)) + !! cdf_uniform-uniform-cumulative-distribution-function)) !! #:for k1, t1 in ALL_KINDS_TYPES module procedure cdf_unif_${t1[0]}$${k1}$ @@ -76,7 +76,7 @@ module stdlib_stats_distribution_uniform !! Fisher-Yates shuffle algorithm for a rank one array of integer, real and !! complex variables. !! ([Specification](../page/specs/stdlib_stats_distribution_uniform.html# - !! description)) + !! shuffle-using-fisher-yates-algorithm-to-generate-a-random-permutation-of-a-list)) !! #:for k1, t1 in ALL_KINDS_TYPES module procedure shuffle_${t1[0]}$${k1}$ From a435b04c3f3b57b6bbd745d63c6031aeaa2a6034 Mon Sep 17 00:00:00 2001 From: Jeremie Vandenplas Date: Sat, 2 Oct 2021 20:56:45 +0200 Subject: [PATCH 165/172] correct issue with syntax of pdf_uniform --- doc/specs/stdlib_stats_distribution_uniform.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index 730836621..b9e6d61a0 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -211,7 +211,7 @@ f(x) = 1 / (scale%re * scale%im); for complex uniform distribution. ### Syntax -`result = [[stdlib_stats_distribution_uniform(module):uniform_distribution_pdf(interface)]](x, loc, scale)` +`result = [[stdlib_stats_distribution_uniform(module):pdf_uniform(interface)]](x, loc, scale)` ### Class From b877660dcef220b37e47cd091c96ce047e30fd09 Mon Sep 17 00:00:00 2001 From: Jeremie Vandenplas Date: Sat, 2 Oct 2021 21:19:20 +0200 Subject: [PATCH 166/172] update titles of specs of the different stdlib_stats_distribution --- doc/specs/stdlib_stats_distribution_PRNG.md | 2 +- doc/specs/stdlib_stats_distribution_uniform.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/specs/stdlib_stats_distribution_PRNG.md b/doc/specs/stdlib_stats_distribution_PRNG.md index 60067bde6..5d786a24a 100644 --- a/doc/specs/stdlib_stats_distribution_PRNG.md +++ b/doc/specs/stdlib_stats_distribution_PRNG.md @@ -1,5 +1,5 @@ --- -title: stats_distribution +title: stats_distribution_PRNG --- # Statistical Distributions -- Pseudorandom Number Generator Module diff --git a/doc/specs/stdlib_stats_distribution_uniform.md b/doc/specs/stdlib_stats_distribution_uniform.md index b9e6d61a0..485684b98 100644 --- a/doc/specs/stdlib_stats_distribution_uniform.md +++ b/doc/specs/stdlib_stats_distribution_uniform.md @@ -1,5 +1,5 @@ --- -title: stats_distribution +title: stats_distribution_uniform --- # Statistical Distributions -- Uniform Distribution Module From b13a48e3df90c4ed7c448427572d4c7159807d9c Mon Sep 17 00:00:00 2001 From: Jim-215-Fisher Date: Mon, 4 Oct 2021 10:22:51 -0400 Subject: [PATCH 167/172] remove uniform files --- src/CMakeLists.txt | 1 - src/Makefile.manual | 5 ----- 2 files changed, 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4f87a2dcd..0cceb49f7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,7 +29,6 @@ set(fppFiles stdlib_quadrature_trapz.fypp stdlib_quadrature_simps.fypp stdlib_stats_distribution_PRNG.fypp - stdlib_stats_distribution_uniform.fypp stdlib_math.fypp stdlib_math_linspace.fypp stdlib_math_logspace.fypp diff --git a/src/Makefile.manual b/src/Makefile.manual index e827c286f..7576cf3d8 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -30,7 +30,6 @@ SRCFYPP = \ stdlib_math_linspace.fypp \ stdlib_math_logspace.fypp \ stdlib_stats_distribution_PRNG.fypp \ - stdlib_stats_distribution_uniform.fypp \ stdlib_string_type.fypp \ stdlib_string_type_constructor.fypp \ stdlib_strings.fypp \ @@ -149,10 +148,6 @@ stdlib_stats_var.o: \ stdlib_stats_distribution_PRNG.o: \ stdlib_kinds.o \ stdlib_error.o -stdlib_stats_distribution_uniform.o: \ - stdlib_kinds.o \ - stdlib_error.o \ - stdlib_stats_distribution_PRNG.o stdlib_string_type.o: stdlib_ascii.o \ stdlib_kinds.o stdlib_string_type_constructor.o: stdlib_string_type.o \ From 3bc615b21ad6493ad5bc2227c4766ca33421d206 Mon Sep 17 00:00:00 2001 From: Jim-215-Fisher Date: Mon, 4 Oct 2021 10:40:31 -0400 Subject: [PATCH 168/172] modify CMakeLists, Makefile, and index --- doc/specs/index.md | 1 + src/CMakeLists.txt | 1 + src/Makefile.manual | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/doc/specs/index.md b/doc/specs/index.md index e4a5d8d76..7101ff029 100644 --- a/doc/specs/index.md +++ b/doc/specs/index.md @@ -24,6 +24,7 @@ This is and index/directory of the specifications (specs) for each new module/fe - [random](./stdlib_random.html) - Probability Distributions random number generator - [sorting](./stdlib_sorting.html) - Sorting of rank one arrays - [stats](./stdlib_stats.html) - Descriptive Statistics + - [stats_distributions_uniform](./stdlib_stats_distribtuion_uniform.html) - Uniform Probability Distribution - [string\_type](./stdlib_string_type.html) - Basic string support - [strings](./stdlib_strings.html) - String handling and manipulation routines - [stringlist_type](./stdlib_stringlist_type.html) - 1-Dimensional list of strings diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 612fb0dbc..bb9fb4fd8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,6 +24,7 @@ set(fppFiles stdlib_stats_moment_all.fypp stdlib_stats_moment_mask.fypp stdlib_stats_moment_scalar.fypp + stdlib_stats_distribution_uniform.fypp stdlib_stats_var.fypp stdlib_quadrature.fypp stdlib_quadrature_trapz.fypp diff --git a/src/Makefile.manual b/src/Makefile.manual index 0bf5ef02d..f1e662e92 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -26,6 +26,7 @@ SRCFYPP = \ stdlib_stats_moment_all.fypp \ stdlib_stats_moment_mask.fypp \ stdlib_stats_moment_scalar.fypp \ + stdlib_stats_distribution_uniform.fypp \ stdlib_stats_var.fypp \ stdlib_math.fypp \ stdlib_math_linspace.fypp \ @@ -145,6 +146,10 @@ stdlib_stats_var.o: \ stdlib_optval.o \ stdlib_kinds.o \ stdlib_stats.o +stdlib_stats_distribtuion_uniform.o: \ + stdlib_kinds.o \ + stdlib_error.o \ + stdlib_random.o stdlib_random.o: \ stdlib_kinds.o \ stdlib_error.o From 22a6023cd3e8ae8ff0ddfe7f6755c3a7d6f0af4a Mon Sep 17 00:00:00 2001 From: Jim-215-Fisher Date: Mon, 4 Oct 2021 10:45:25 -0400 Subject: [PATCH 169/172] change PRNG to random --- src/stdlib_stats_distribution_uniform.fypp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stdlib_stats_distribution_uniform.fypp b/src/stdlib_stats_distribution_uniform.fypp index 0441dc066..7c441a0b9 100644 --- a/src/stdlib_stats_distribution_uniform.fypp +++ b/src/stdlib_stats_distribution_uniform.fypp @@ -4,7 +4,7 @@ module stdlib_stats_distribution_uniform use stdlib_kinds use stdlib_error, only : error_stop - use stdlib_stats_distribution_PRNG, only : dist_rand + use stdlib_random, only : dist_rand implicit none private From 39e991b415be5f65af94de3a69e92707ab052421 Mon Sep 17 00:00:00 2001 From: Jim-215-Fisher Date: Mon, 4 Oct 2021 10:51:17 -0400 Subject: [PATCH 170/172] change PRNG in test to random --- src/tests/stats/test_distribution_uniform.fypp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/stats/test_distribution_uniform.fypp b/src/tests/stats/test_distribution_uniform.fypp index b8efb996e..738f89bfe 100644 --- a/src/tests/stats/test_distribution_uniform.fypp +++ b/src/tests/stats/test_distribution_uniform.fypp @@ -3,7 +3,7 @@ program test_distribution_uniform use stdlib_error, only : check use stdlib_kinds, only: int8, int16, int32, int64, sp, dp, qp - use stdlib_stats_distribution_PRNG, only : random_seed, dist_rand + use stdlib_random, only : random_seed, dist_rand use stdlib_stats_distribution_uniform, uni_rvs => rvs_uniform, & uni_pdf => pdf_uniform, & uni_cdf => cdf_uniform From 227e52018b001f39a436b68fa3bb40f6679a486b Mon Sep 17 00:00:00 2001 From: Jim-215-Fisher Date: Mon, 4 Oct 2021 10:58:21 -0400 Subject: [PATCH 171/172] spell checked --- doc/specs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/specs/index.md b/doc/specs/index.md index 7101ff029..a3b0a5def 100644 --- a/doc/specs/index.md +++ b/doc/specs/index.md @@ -24,7 +24,7 @@ This is and index/directory of the specifications (specs) for each new module/fe - [random](./stdlib_random.html) - Probability Distributions random number generator - [sorting](./stdlib_sorting.html) - Sorting of rank one arrays - [stats](./stdlib_stats.html) - Descriptive Statistics - - [stats_distributions_uniform](./stdlib_stats_distribtuion_uniform.html) - Uniform Probability Distribution + - [stats_distributions_uniform](./stdlib_stats_distribution_uniform.html) - Uniform Probability Distribution - [string\_type](./stdlib_string_type.html) - Basic string support - [strings](./stdlib_strings.html) - String handling and manipulation routines - [stringlist_type](./stdlib_stringlist_type.html) - 1-Dimensional list of strings From bcd876c234157d8db3af892d95bf584058a913fc Mon Sep 17 00:00:00 2001 From: Jim-215-Fisher Date: Mon, 4 Oct 2021 11:09:30 -0400 Subject: [PATCH 172/172] spell checked --- src/Makefile.manual | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.manual b/src/Makefile.manual index f1e662e92..179fc600f 100644 --- a/src/Makefile.manual +++ b/src/Makefile.manual @@ -146,7 +146,7 @@ stdlib_stats_var.o: \ stdlib_optval.o \ stdlib_kinds.o \ stdlib_stats.o -stdlib_stats_distribtuion_uniform.o: \ +stdlib_stats_distribution_uniform.o: \ stdlib_kinds.o \ stdlib_error.o \ stdlib_random.o