public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
* possible design weekness
@ 2007-03-09 13:58 Alxneit-Kamber Ivo
  2007-03-12 21:26 ` Brian Gough
  0 siblings, 1 reply; 2+ messages in thread
From: Alxneit-Kamber Ivo @ 2007-03-09 13:58 UTC (permalink / raw)
  To: gsl-discuss

[-- Attachment #1: Type: text/plain, Size: 2104 bytes --]

Dear all

I have recently been bitten by what seems to be a design weekness in how
the functions (function to be minimized, or system of ODE's) are
defined. These function do not return a status value but the function
value. This prevents to easily notifiy the caller (iterate) of a failure
such as e.g. a domain error of one of its arguments or a failed
malloc().

The function used in the non-linear least squares fit, however is
implemented better as it returns a status value to the caller. Other
parts of the GSL library, multi-dimensional root finding or
one-dimensional minimization, e.g., take a slightly less optimal
aprroach. Here the caller (iterate) checks, if the function value or its
derivative, if applicable, is finite and issues an error otherwise.

I think it would be worthwhile (maybe for a version 2.0) to implement
a common definition for these functions like

status = f(double *result, 'arguments', (void*) parameters);

For a status different from 'GSL_SUCCESS' let the driver either take
care of the failure (this depends on the application/algorithm) or let
it fail propagating the status from the function to the user. Then the
user can handle the situation in his main loop.

I currently have no real idea how to prevent breaking of old user code
by implementing this new interface while keeping the old in place:

- for the 'GSL_XXX_EVAL_YYY' family of macros a simple wrapper would
  do the job. (allways return GSL_SUCCESS for the old style or analyze
  the result and then assign the status to be returned).

- the fact that the new interface has one more argument could probably
  be handled by variable argument functions (never used these).

- how to deal with the fact that the new style function is of different
  type (int instead of double)?

Comments or suggestions?

-- 
Dr. Ivo Alxneit
Laboratory for Solar Technology   phone: +41 56 310 4092
Paul Scherrer Institute             fax: +41 56 310 2688
CH-5232 Villigen                   http://solar.web.psi.ch
Switzerland                   gnupg key: 0x515E30C7


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: possible design weekness
  2007-03-09 13:58 possible design weekness Alxneit-Kamber Ivo
@ 2007-03-12 21:26 ` Brian Gough
  0 siblings, 0 replies; 2+ messages in thread
From: Brian Gough @ 2007-03-12 21:26 UTC (permalink / raw)
  To: gsl-discuss

At Fri, 9 Mar 2007 14:58:39 +0100,
Alxneit-Kamber Ivo wrote:
> I have recently been bitten by what seems to be a design weekness in how
> the functions (function to be minimized, or system of ODE's) are
> defined. These function do not return a status value but the function
> value. This prevents to easily notifiy the caller (iterate) of a failure
> such as e.g. a domain error of one of its arguments or a failed
> malloc().

Hello,

For a domain error the function can return NaN, and the driver routines
should handle this (if they don't we should fix them).

For those functions that return a double there is a tradeoff between
generality and convenience.  As you point out, it is more general to
always return a status value, and the functions have been written from
the point of view that it is more convenient for the user to work with
functions that return a double, as for the standard library functions
- sin(x), log(x), etc.

Most of the time the functions do not do memory allocation or need to
signal other errors, apart from domain error, and it is convenient to
be able to write y=f(x).

I don't think there is any straightforward way to handle the two
possibilities in the same framework.  What I had in mind was that NaN
be used as an error (additional information can be passed back through
the *params argument if needed) and that the routines should return
with GSL_FAILURE if they receive a NaN.

-- 
Brian Gough

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-03-12 21:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-09 13:58 possible design weekness Alxneit-Kamber Ivo
2007-03-12 21:26 ` Brian Gough

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).