ralna / RALFit

A non-linear least squares solver
Other
25 stars 6 forks source link

C <-> Box Logic #65

Closed tyronerees closed 3 years ago

tyronerees commented 4 years ago
tyronerees commented 4 years ago

This doesn't seem to be straight forward (unless I'm missing something).

Current setup

The way the C-interface currently works (in master) is described below. Note xx could be r, j, hf, etc.:

How params is used in the box-logic branch

In the box-logic branch, we extend the params_base_type to params_box_type, which holds data needed for the box logic:

  Type, Public, Extends(params_base_type) :: params_box_type
    ! See if problem has box bounds
    Integer :: iusrbox = 0
    Real(Kind=wp), Allocatable :: blx(:), bux(:), pdir(:), normFref(:), sk(:), g(:)
    ! projection changed the direction? d /= P(d)?
    Logical :: prjchd = .false.
    ! Convergence metrics
    Real(Kind=wp) :: normPD, gtd
    ! Memory for HZLS (LS)
    Real(Kind=wp) :: sksk, skyk, quad_c, quad_q, normFold
    ! Consecutive times quadratic model is accurate
    Integer       :: quad_i = 0
    ! Memory for nonmonotone LS
    Integer       :: nFref = 0
  End Type params_box_type

C interface to the box-logic

params is no longer a black box, and has values the must be allocated by both the C and the Fortran. I don't think it's currently possible to send such an object between the two languages.

Solutions?

  1. We could have an optional derived type bound_params, which would hold all the data.
  2. We could add optional arrays bux and blx, and store the rest in the workspace and/or inform types as appropriate.
  3. Handle params similarly to the workspace in the C interface to nlls_setup_bounds (as bound_params, say), and pass this as an optional argument to the Fortran wrapper nlls_solve. The file ral_nlls_ciface could then be changed so that these are wrapped together appropriately in the params that is sent to the Fortran.
  4. ???

Either 1. or 2. would still need some working around from the C side, as I don't believe optional variables are handled the same way as in Fortran, but this should be straightforward.

From a design standpoint, params is now doing multiple jobs, and it would be cleaner to keep objects have a single purpose.