diff --git a/fortran/bobyqa/geometry.f90 b/fortran/bobyqa/geometry.f90 index 2cd792b7f8..14c2324ab9 100644 --- a/fortran/bobyqa/geometry.f90 +++ b/fortran/bobyqa/geometry.f90 @@ -8,7 +8,7 @@ module geometry_bobyqa_mod ! ! Started: February 2022 ! -! Last Modified: Sunday, April 21, 2024 PM01:57:17 +! Last Modified: Sunday, April 21, 2024 PM03:19:27 !--------------------------------------------------------------------------------------------------! implicit none @@ -41,7 +41,7 @@ function setdrop_tr(kopt, ximproved, bmat, d, delta, rho, xpt, zmat) result(knew use, non_intrinsic :: consts_mod, only : RP, IK, ONE, DEBUGGING use, non_intrinsic :: debug_mod, only : assert use, non_intrinsic :: infnan_mod, only : is_nan, is_finite -use, non_intrinsic :: linalg_mod, only : issymmetric +use, non_intrinsic :: linalg_mod, only : issymmetric, trueloc use, non_intrinsic :: powalg_mod, only : calden implicit none @@ -139,14 +139,15 @@ function setdrop_tr(kopt, ximproved, bmat, d, delta, rho, xpt, zmat) result(knew score(kopt) = -ONE end if +! SCORE(K) = NaN implies DEN(K) = NaN. We exclude such K as we want DEN to be big. +score(trueloc(is_nan(score))) = -ONE + knew = 0 -! The following IF works slightly better than `IF (ANY(SCORE > 0))` from Powell's BOBYQA and LINCOA -! code. +! The following IF works slightly better than `IF (ANY(SCORE > 0))` from Powell's BOBYQA/LINCOA code. if (any(score > 1) .or. (ximproved .and. any(score > 0))) then ! Powell's UOBYQA and NEWUOA code. ! See (6.1) of the BOBYQA paper for the definition of KNEW in this case. - ! SCORE(K) = NaN implies DEN(K) = NaN. We exclude such K as we want DEN to be big. - knew = int(maxloc(score, mask=(.not. is_nan(score)), dim=1), kind(knew)) - !!MATLAB: [~, knew] = max(score, [], 'omitnan'); + knew = int(maxloc(score, dim=1), kind(knew)) + !!MATLAB: [~, knew] = max(score); end if ! Powell's code does not include the following instructions. With Powell's code, if DEN consists of diff --git a/fortran/cobyla/geometry.f90 b/fortran/cobyla/geometry.f90 index 0a53a672ba..8d95b0b861 100644 --- a/fortran/cobyla/geometry.f90 +++ b/fortran/cobyla/geometry.f90 @@ -8,7 +8,7 @@ module geometry_cobyla_mod ! ! Started: July 2021 ! -! Last Modified: Sunday, April 21, 2024 PM01:57:52 +! Last Modified: Sunday, April 21, 2024 PM03:16:37 !--------------------------------------------------------------------------------------------------! implicit none @@ -32,7 +32,7 @@ function setdrop_tr(ximproved, d, delta, rho, sim, simi) result(jdrop) ! Common modules use, non_intrinsic :: consts_mod, only : IK, RP, ZERO, ONE, TENTH, DEBUGGING -use, non_intrinsic :: linalg_mod, only : matprod, isinv +use, non_intrinsic :: linalg_mod, only : matprod, isinv, trueloc use, non_intrinsic :: infnan_mod, only : is_nan, is_finite use, non_intrinsic :: debug_mod, only : assert @@ -168,12 +168,14 @@ function setdrop_tr(ximproved, d, delta, rho, sim, simi) result(jdrop) score(n + 1) = -ONE end if +score(trueloc(is_nan(score))) = -ONE + jdrop = 0 ! The following IF works a bit better than `IF (ANY(SCORE > 1) .OR. ANY(SCORE > 0) .AND. XIMPROVED)` ! from Powell's UOBYQA and NEWUOA code. if (any(score > 0)) then ! Powell's BOBYQA and LINCOA code - jdrop = int(maxloc(score, mask=(.not. is_nan(score)), dim=1), kind(jdrop)) - !!MATLAB: [~, jdrop] = max(score, [], 'omitnan'); + jdrop = int(maxloc(score, dim=1), kind(jdrop)) + !!MATLAB: [~, jdrop] = max(score); end if if ((ximproved .and. jdrop == 0) .or. jdrop < 0) then ! JDROP < 0 is impossible in theory. diff --git a/fortran/lincoa/geometry.f90 b/fortran/lincoa/geometry.f90 index afdbb019c7..b01613afb9 100644 --- a/fortran/lincoa/geometry.f90 +++ b/fortran/lincoa/geometry.f90 @@ -8,7 +8,7 @@ module geometry_lincoa_mod ! ! Started: February 2022 ! -! Last Modified: Sunday, April 21, 2024 PM01:54:26 +! Last Modified: Sunday, April 21, 2024 PM03:15:36 !--------------------------------------------------------------------------------------------------! implicit none @@ -38,7 +38,7 @@ function setdrop_tr(idz, kopt, ximproved, bmat, d, delta, rho, xpt, zmat) result use, non_intrinsic :: consts_mod, only : RP, IK, ONE, TENTH, DEBUGGING use, non_intrinsic :: debug_mod, only : assert use, non_intrinsic :: infnan_mod, only : is_nan, is_finite -use, non_intrinsic :: linalg_mod, only : issymmetric +use, non_intrinsic :: linalg_mod, only : issymmetric, trueloc use, non_intrinsic :: powalg_mod, only : calden implicit none @@ -160,13 +160,15 @@ function setdrop_tr(idz, kopt, ximproved, bmat, d, delta, rho, xpt, zmat) result score(kopt) = -ONE end if +! SCORE(K) is NaN implies ABS(DEN(K)) is NaN, but we want ABS(DEN) to be big. So we exclude such K. +score(trueloc(is_nan(score))) = -ONE + knew = 0 ! The following IF works a bit better than `IF (ANY(SCORE > 1) .OR. ANY(SCORE > 0) .AND. XIMPROVED)` ! from Powell's UOBYQA and NEWUOA code. if (any(score > 0)) then ! Powell's BOBYQA and LINCOA code - ! SCORE(K) is NaN implies ABS(DEN(K)) is NaN, but we want ABS(DEN) to be big. So we exclude such K. - knew = int(maxloc(score, mask=(.not. is_nan(score)), dim=1), kind(knew)) - !!MATLAB: [~, knew] = max(score, [], 'omitnan'); + knew = int(maxloc(score, dim=1), kind(knew)) + !!MATLAB: [~, knew] = max(score); end if ! Powell's code does not include the following instructions. With Powell's code, if DEN consists of diff --git a/fortran/newuoa/geometry.f90 b/fortran/newuoa/geometry.f90 index 42b0c0c340..de89c353e5 100644 --- a/fortran/newuoa/geometry.f90 +++ b/fortran/newuoa/geometry.f90 @@ -8,7 +8,7 @@ module geometry_newuoa_mod ! ! Started: July 2020 ! -! Last Modified: Sunday, April 21, 2024 PM02:47:22 +! Last Modified: Sunday, April 21, 2024 PM03:20:57 !--------------------------------------------------------------------------------------------------! implicit none @@ -40,7 +40,7 @@ function setdrop_tr(idz, kopt, ximproved, bmat, d, delta, rho, xpt, zmat) result use, non_intrinsic :: consts_mod, only : RP, IK, ONE, TENTH, DEBUGGING use, non_intrinsic :: debug_mod, only : assert use, non_intrinsic :: infnan_mod, only : is_nan, is_finite -use, non_intrinsic :: linalg_mod, only : issymmetric +use, non_intrinsic :: linalg_mod, only : issymmetric, trueloc use, non_intrinsic :: powalg_mod, only : calden implicit none @@ -128,13 +128,15 @@ function setdrop_tr(idz, kopt, ximproved, bmat, d, delta, rho, xpt, zmat) result score(kopt) = -ONE end if +! SCORE(K) is NaN implies ABS(DEN(K)) is NaN, but we want ABS(DEN) to be big. So we exclude such K. +score(trueloc(is_nan(score))) = -ONE + knew = 0 -! The following IF works a bit better than `IF (ANY(SCORE > 0))` from Powell's BOBYQA and LINCOA code. +! The following IF works a bit better than `IF (ANY(SCORE > 0))` from Powell's BOBYQA/LINCOA code. if (any(score > 1) .or. (ximproved .and. any(score > 0))) then ! Powell's UOBYQA and NEWUOA code ! See (7.5) of the NEWUOA paper for the definition of KNEW in this case. - ! SCORE(K) is NaN implies ABS(DEN(K)) is NaN, but we want ABS(DEN) to be big. So we exclude such K. - knew = int(maxloc(score, mask=(.not. is_nan(score)), dim=1), kind(knew)) - !!MATLAB: [~, knew] = max(score, [], 'omitnan'); + knew = int(maxloc(score, dim=1), kind(knew)) + !!MATLAB: [~, knew] = max(score); end if ! Powell's code does not include the following instructions. With Powell's code, if DEN consists of diff --git a/fortran/uobyqa/geometry.f90 b/fortran/uobyqa/geometry.f90 index 1a9a5a95cd..51e541fd4d 100644 --- a/fortran/uobyqa/geometry.f90 +++ b/fortran/uobyqa/geometry.f90 @@ -8,7 +8,7 @@ module geometry_uobyqa_mod ! ! Started: February 2022 ! -! Last Modified: Sunday, April 21, 2024 PM01:52:04 +! Last Modified: Sunday, April 21, 2024 PM03:17:27 !--------------------------------------------------------------------------------------------------! implicit none @@ -41,6 +41,7 @@ function setdrop_tr(kopt, ximproved, d, pl, rho, xpt) result(knew) use, non_intrinsic :: consts_mod, only : RP, IK, ONE, DEBUGGING use, non_intrinsic :: debug_mod, only : assert use, non_intrinsic :: infnan_mod, only : is_nan, is_finite +use, non_intrinsic :: linalg_mod, only : trueloc use, non_intrinsic :: powalg_mod, only : calvlag implicit none @@ -132,13 +133,15 @@ function setdrop_tr(kopt, ximproved, d, pl, rho, xpt) result(knew) score(kopt) = -ONE end if +! SCORE(K) is NaN implies VLAG(K) is NaN, but we want ABS(VLAG) to be big. So we exclude such K. +score(trueloc(is_nan(score))) = -ONE + knew = 0 ! It makes almost no difference if we change the IF below to `IF (ANY(SCORE>0))`, which is used ! in Powell's BOBYQA and LINCOA code. if (any(score > 1) .or. (ximproved .and. any(score > 0))) then ! Powell's UOBYQA and NEWUOA code - ! SCORE(K) is NaN implies VLAG(K) is NaN, but we want ABS(VLAG) to be big. So we exclude such K. - knew = int(maxloc(score, mask=(.not. is_nan(score)), dim=1), kind(knew)) - !!MATLAB: [~, knew] = max(score, [], 'omitnan'); + knew = int(maxloc(score, dim=1), kind(knew)) + !!MATLAB: [~, knew] = max(score); end if ! Powell's code does not include the following instructions. With Powell's code, if VLAG consists of