TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Allowing Matlab to Talk to Rust

64 点作者 smitec超过 9 年前

4 条评论

jblazevic超过 9 年前
Great stuff!<p>One minor suggestion, completely beside the point so please forgive me: a safer and perhaps more idiomatic way to implement the multiply_safe function would be with a functional-style one-liner:<p><pre><code> fn multiply_safe(a : Vec&lt;f64&gt;, b : Vec&lt;f64&gt;) -&gt; Vec&lt;f64&gt; { if a.len() != b.len() { panic!(&quot;The two vectors differ in length!&quot;); } return a.iter().zip(b.iter()).map(|(x, y)| x * y).collect() } </code></pre> Safer because you don&#x27;t manipulate indices and lengths directly like you would in C, so there is no opportunity of an off-by-one bug or things like that. Surprisingly, rustc optimizer makes sure that this performs as well as the index-wrangling implementation (according to some simple tests I just ran).
评论 #11048105 未加载
评论 #11043131 未加载
ampron超过 9 年前
Well explained! Here are some more examples using the calllib function to access the rust code, although I think the mex interface is probably the better way to go. <a href="https:&#x2F;&#x2F;github.com&#x2F;ampron&#x2F;rustlab" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ampron&#x2F;rustlab</a>
评论 #11033436 未加载
marmaduke超过 9 年前
Interesting, though the C middleman isn&#x27;t necessary if you can describe to Rust&#x27;s FFI that mxArray is an opaque struct (I imagine the other regular functions in the MEX API are cakewalk for an FFI worth it&#x27;s weight).<p>A while ago I wrote a mexFunction purely in Cython, and it was wondeful because Python was immediately available to work with (instead of C). The problem was that the numerical libraries on which NumPy builds often shared symbol names with MATLAB (such as svd, or hdf5) that differ in implementation resulting segfaults or corrupted data.
评论 #11043078 未加载
bluejekyll超过 9 年前
One thing that jumped out to me, and I haven&#x27;t worked with Rust FFI enough to know this answer. Is the C library necessary? Since Rust is exporting the C interfaces directly, couldn&#x27;t Matlab link directly against that?
评论 #11042305 未加载