Fortunately there is a class called
arrayM_inline that can handle this.
I suggest that you create a
fann_api package containing two classes
fann_api and
fann_native.
In the
_native you place all the
language c as "..." declarations, and in the
_api class you place Visual Prolog friendly versions of the same predicates.
The code below shows the important details.
Code: Select all
class fann_native
open core
predicates
fann_train : (pointer Fann, pointer ArrayInput, positive SizeInput, pointer ArrayOutput, positive SizeOutput) language c as "_fann_train@12".
end class fann_native
Code: Select all
class fann_api
open core
predicates
fann_train : (pointer Fann, real* Input, positive SizeOutput) -> real* Output.
end class fann_api
Code: Select all
implement fann_api
open core
clauses
fann_train(Fann, Input) = Output :-
InArray = arrayM_inline::new_list(Input, true),
OutArraySize = InArray:size, % for the example we assume that the output array must have same size as the input array
OutArray = arrayM_inline::newAtomic(OutArraySize),
fann_native::fann_train(Fann, InArray:data, InArray:size, OutArray:data, OutArray:size),
Output = OutArray:valueList.
end implement fann_api
Some comments:
I have changed the "size" arguments from
unsigned to
positive, because that fits better with
arrayM_inline, and it makes no difference in the interfacing to the c routine.
More important: The output array is actually an "input array", which the
fann_train routine fills with values. So you have to create this array and pass it to the routine. I do not know how to set the size of this array, so I have just used the same size as the input array.