Skip to content

bobyqa: replace trueloc indexing with allocation-free where/masked sum - #315

Open
pawlenartowicz wants to merge 1 commit into
libprima:mainfrom
pawlenartowicz:main
Open

pawlenartowicz wants to merge 1 commit into
libprima:mainfrom
pawlenartowicz:main

Conversation

@pawlenartowicz

Copy link
Copy Markdown

Every y(trueloc(mask)) in fortran/bobyqa/ becomes where(mask) y = ... or sum(..., mask=mask). Same floating-point operations in the same order; trajectories and all internal states are bit-identical to the previous commit. Removes 3-4 heap allocations per call site from the trsbox and geostep hot loops; 1.7x-2.1x faster per solve with gfortran 15 -O3.

Every y(trueloc(mask)) in fortran/bobyqa/ becomes where(mask) y = ... or
sum(..., mask=mask). Same floating-point operations in the same order;
trajectories and all internal states are bit-identical to the previous
commit. Removes 3-4 heap allocations per call site from the trsbox and
geostep hot loops; 1.7x-2.1x faster per solve with gfortran 15 -O3.
@zaikunzhang

zaikunzhang commented Sep 11, 2026

Copy link
Copy Markdown
Member

Thank you for the PR.

However, trueloc was introduced on purpose.

  1. PRIMA is supposed to be a reference implementation. Therefore, I purposefully minimised the use of Fortran-specific constructions like where. In addition, trueloc facilitates the translation to other languages such as MATLAB and Python. See the comments below the definition of this function for more information: https://github.com/libprima/prima/blob/main/fortran/common/linalg.f90#L2224-L2234

  2. The solvers in PRIMA are designed for derivative-free optimization problems, where the cost of function evaluation is dominant (for example, several seconds or minutes per function value, if not longer ), and the running time of the solver itself (excluding the time spent on function evaluation) is (assumed to be) negligible. See https://github.com/orgs/libprima/discussions/145

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants