[plt-scheme] Specifying a callback that takes a f64vector

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Apr 30 11:11:53 EDT 2009

On Apr 30, Noel Welsh wrote:
> Another question...
> 
> I'm attempting to wrap a fairly simple optimisation library[1] with
> the FFI. The main function, lm_minimize, optimises the parameters of a
> user supplied function (pointer). I'd like to specify this function in
> Scheme. The typedef is:
> 
> typedef void (lm_evaluate_ftype) (double *par, int m_dat, double *fvec,
> 				  void *data, int *info);

This declaration suffers from the usual header file problem: it
doesn't specify which values are inputs and which are outputs...


> The wrapping I'm using is:
> 
> (define _lm_evaluate_ftype
>   (_fun (params : (_f64vector i))
>         (n-points : _int)
>         (_f64vector i)
>         _scheme
>         (_ptr i _int)
>     -> _void))
> 
> I don't see how this can possibly work --

Which part exactly?  What looks like it's almost definitely wrong is
that this function returns void, and no other value, so it would be
pretty useless as defined.  Perhaps you're confusing input and output
annotations?  (`i' mode is for a vector that is an input to the
function.)


> the FFI won't know the size of the arrays to allocate. However the
> FFI won't let me specify the size of an input f64vector [very bad
> error message here, BTW.]  So what am I supposed to do?

It shouldn't -- because in input mode it expects a scheme vector so
there's no allocation to do.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.