Hey gophers,
I'm currently in the process of writing a genetic programming lib for machine learning in Go. I'm nearly done with coding bindings for Python but I just have one last problem.
The Python package is here. In the binding.py
file I'm calling an exporting function called Predict
located in main.go
. The problem is that Predict
returns a []float64
slice. This causes the following panic when the method is called from Python: panic: runtime error: cgo result has Go pointer
.
My question is thus: is there any way to return Go slices when making a call from another language?
I'm sorry if my question is misplaced. I wasn't too sure where to ask (I'm not used to mail groups).
By the way I'm looking for contributors, there's a lot of work to be done and I'm getting promising results on real world datasets!
评论:
raff99:
recurrency:There is a similar answer here: https://stackoverflow.com/questions/41492071/how-do-i-convert-a-go-array-of-strings-to-a-c-array-of-strings
It's for array of strings, but it's the same for array of floats. Your Go code needs to allocate (with C.malloc) the return array and copy the Go values into.
Lemax0:very cool! I have tried your
gago
package and really liked it, the api was very elegant.don't have an answer to your question – but maybe try in #cgo or #data-science on the gophers slack?
Thanks! Glad you like it.
I didn't think about Slack, good call.
