This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Parameter vectors declared as const in minimized functions


Hi,

On Tue, Jan 04, 2005 at 12:10:50PM +0100, Andrej Prsa was heard to remark:
> 
> I have a question about (multidimensional) minimization functions; why
> does a first argument to the function have to be a const gsl_vector *
> type? I understand one should not attempt to change the contents of this
> vector during unconstrained minimization, since that's minimizer's job,
> but doesn't it unnecessarily restrict the method?
> 
> To make my question a bit more practical, let me explain my motivation:
> I'm running a multidimensional NMS minimizer on a ~30D hyperspace to find
> the minimum of the chi2 value = (observed-calculated)^2. Obviously this
> dimension is very high and it is sometimes possible to find constraints
> among particular parameters, at other times perhaps boundaries of the
> hyperspace to perform semi-constrained minimization. Since these
> constraints/boundaries are changing from case to case, they cannot be
> hard-coded. So to add a simple if-clause stating: if parameter falls out
> of prescribed bounds, set its value to the boundary value, one would need
> to modify the value of the passed parameter vector within the chi2
> function. That's why it would be useful if the passed gsl_vector * wasn't
> declared as const. What do you think?

I hope I didn't understand what you are trying to say ... 

In the c programming language, a 'const' function parameter just means
that the subroutine promises not to alter the value of that parameter.
It does not mean that the caller needs to also declare it as a const.

Thus, for example:

double f(const int *);

main ()
   int x[42];

    x[3]= 5;  

    f(x);

    x[4]=33;

    f(x);

}

is perfectly valid code, and will not generate compiler warnings.


--linas


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]