Hi Alex, one more 'native' question, this time a bit more complicated: libblas.so is on my machine, the C function "idamax_" is found,which is actually a C wrapper for Fortran Code. In the Fortran docs, the parameters are described exactly, see below. Since the Parameters of the C function are input/output Parameters, I try to define the input values in the CDDR, but obviously not correctly.
How do I define an input array correctly (especially DX and INCX)? If I have in/out Parameters, how do I get the int return value too when the pil functions returns? hope these questions are not too messy ... cheers Thorsten PS when I understand how this works, I will use the input values for native as parameters for the pil wrapper, but for now I just write them inside of 'native'. *> \param[in] N 33 *> \verbatim 34 *> N is INTEGER 35 *> number of elements in input vector(s) 36 *> \endverbatim 37 *> 38 *> \param[in] DX 39 *> \verbatim 40 *> DX is DOUBLE PRECISION array, dimension ( 1 + ( N - 1 )*abs( INCX ) ) 41 *> \endverbatim 42 *> 43 *> \param[in] INCX 44 *> \verbatim 45 *> INCX is INTEGER 46 *> storage spacing between elements of DX 47 *> \endverbatim 48 * (symbols 'blas 'pico) (default *LibBlas "libblas.so") (de idamax () (use "N" "Dx" "Incx" (native `*LibBlas "idamax_" 'I '("N" (4 . 'I) 3) '("Dx" (8 . 1.0) '(1.0 1 2 3)) '("Incx" (4 . 'I) 0)) (list "N" "Dx" "Incx") ) ) ## BLAS_extern int /* IDAMAX - return the index of the element with max abs value */ ## F77_NAME(idamax)(const int *n, const double *dx, const int *incx) # when INCX = 0 : (blas~idamax) -> ('NIL 0 'NIL) # when INCX = 1 segfault Am Di., 17. Nov. 2020 um 23:45 Uhr schrieb Thorsten Jolitz < tjol...@gmail.com>: > Hi Alex, > the wrappers with primitive arguments do work now when defined like this > with transient symbols: > > (de pgamma ("X" "Y" "Z" "I" "J") > (native `*LibRmath "pgamma" 1.0 (cons "X" 1.0) (cons "Y" 1.0) (cons > "Z" 1.0) "I" "J" ) ) > ## double› pgamma(double, double, double, int, int); > > With your tips I could define wrappers for functions with pointer args too > > (de pnorm_both ("X" "I" "J") > (use "Y" "Z" > (native `*LibRmath "pnorm_both" NIL (cons "X" 1.0) '("Y" (8 . > 1.0)) '("Z" (8 . 1.0)) "I" "J" ) > (list "Y" "Z") ) ) > ## void› pnorm_both(double, double *, double *, int, int);/* both > tails */ > > does work (scl 3): > : (rmath~pnorm_both 1.2 2 3) > -> (-122 -2162) > > now I only have to understand the meaning of some of these functions. > What I find irritating is that the pointer args are not used for input but > only as a kind of return values. > > Thanks for your help! > Cheers > Thorsten > > Am So., 15. Nov. 2020 um 22:55 Uhr schrieb Alexander Burger < > a...@software-lab.de>: > >> Hi Thorsten, >> >> hmm, this is not correct: >> >> > (de pnorm_both ("X" "Y" "Z" "I" "J") >> > (! native `*LibRmath "pnorm_both" 1.0 (cons "X" 1.0) '("Y" (1.0 . >> 4)) >> > '("Z" (1.0 . 4)) "I" "J" ) ) >> >> "Z" is an argument to the function, so it is bound to some evaluated >> value. >> >> But this value is ignored, because in >> >> '("Z" (1.0 . 4)) >> >> "Z" is a *return* value. Also, (1.0 . 4) makes no sense here. A structure >> argument is >> >> '(Var (<size> . <returnSpec)) >> >> but 1.0 is no size (it is too big, something like 1000000) and 4 is no >> return >> spec. >> >> >> If you want to pass a buffer to receivea double (the double* in the C >> signature), you would do: >> >> (use MyDouble >> (native `*LibRmath "pnorm_both" 1.0 ... >> '(MyDouble (8 . 1.0)) ... ) >> ... do something with MyDouble ...) >> >> (8 . 1.0) allocates 8 bytes on the stack, passes the pointer to the C >> function, >> receives a double in this place, and stores it in the symbol MyDouble. >> >> ☺/ A!ex >> >> -- >> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe >> >