Joe Wood suggested that I check that single floats are being passed to
external functions properly.
I previously knew that single float arrays were passed OK. So I modified
the threshold examplein REF array, and confirmed that single floats are
passed in OK as arguments, though not returned as results.
In a file threshold.c I have this C function which replaces any
value in the image array below the limit with 0.0
void threshold(float *image, int xsize, int ysize, float limit)
{ int i, j, r, t = xsize*ysize;
for (j=0; j < t; j = r)
{ r = j+xsize;
for (i=j; i < r; i++)
if (image[i] < limit) image[i] = 0.0;
}
}
Compiled with this command to create .so file:
gcc -o threshold.so -fpic -shared threshold.c
The pop11 test is as follows (based on REF EXTERNAL)
;;; Externally load the threshould.so file
;;; Note that the <SF> specification is essential to specify
;;; that the fourth argument is passed in as a single float:
exload threshold [threshold]
(language C)
threshold(image, xsize, ysize, limit<SF>);
endexload;
;;; create an array of single floats
uses popvision;
uses newsfloatarray
vars arr = newsfloatarray([1 5 1 5], nonop *);
;;; Check the contents:
arr.arrayvector =>
** <sfloatvec 1.0 2.0 3.0 4.0 5.0 2.0 4.0 6.0 8.0 10.0 3.0 6.0 9.0 12.0
15.0 4.0 8.0 12.0 16.0 20.0 5.0 10.0 15.0 20.0 25.0>
;;; Invoke the threshold function with 10.0 as limit:
exacc threshold(arrayvector(arr), 5, 5, 10.0)
;;; Check that all values less than 10.0 have been zeroed:
arr.arrayvector =>
** <sfloatvec 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 10.0 0.0 0.0 0.0 12.0
15.0 0.0 0.0 12.0 16.0 20.0 0.0 10.0 15.0 20.0 25.0>
Perfect!
It also works if I change the C program too insert 0.1 instead of 0.0.
This seems to demonstrate that single float arguments passed to external
functions work.
The problem is getting the result back.
I hope someone with more experience of these matters than I have can
identify the trouble-spot.
Aaron
|