Skip to content

Commit

Permalink
240421.152343.HKT fix a failure of ftest: "Assertion fails: KNEW /= K…
Browse files Browse the repository at this point in the history
…OPT unless XIMPROVED = TRUE"
  • Loading branch information
zaikunzhang committed Apr 21, 2024
1 parent 7bbde9e commit c67053c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 26 deletions.
15 changes: 8 additions & 7 deletions fortran/bobyqa/geometry.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions fortran/cobyla/geometry.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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.
Expand Down
12 changes: 7 additions & 5 deletions fortran/lincoa/geometry.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions fortran/newuoa/geometry.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions fortran/uobyqa/geometry.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c67053c

Please sign in to comment.