<p>Hey gophers,</p>
<p>I'm currently in the process of writing a <a href="https://github.com/MaxHalford/xgp">genetic programming lib for machine learning</a> in Go. I'm nearly done with coding bindings for Python but I just have one last problem. </p>
<p>The Python package is <a href="https://github.com/MaxHalford/xgp/tree/master/python-package">here</a>. In the <code>binding.py</code> file I'm calling an exporting function called <code>Predict</code> located in <code>main.go</code>. The problem is that <code>Predict</code> returns a <code>[]float64</code> slice. This causes the following panic when the method is called from Python: <code>panic: runtime error: cgo result has Go pointer</code>.</p>
<p>My question is thus: is there any way to return Go slices when making a call from another language?</p>
<p>I'm sorry if my question is misplaced. I wasn't too sure where to ask (I'm not used to mail groups).</p>
<p>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!</p>
<hr/>**评论:**<br/><br/>raff99: <pre><p>There is a similar answer here:
<a href="https://stackoverflow.com/questions/41492071/how-do-i-convert-a-go-array-of-strings-to-a-c-array-of-strings" rel="nofollow">https://stackoverflow.com/questions/41492071/how-do-i-convert-a-go-array-of-strings-to-a-c-array-of-strings</a></p>
<p>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.</p></pre>recurrency: <pre><p>very cool! I have tried your <code>gago</code> package and really liked it, the api was very elegant.</p>
<p>don't have an answer to your question – but maybe try in #cgo or #data-science on the gophers slack?</p></pre>Lemax0: <pre><p>Thanks! Glad you like it.</p>
<p>I didn't think about Slack, good call.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传