简体   繁体   English

如何将Arrayfire阵列转换为Rust Vec?

[英]How do I convert an Arrayfire Array to a Rust Vec?

I'm new to Rust (and Arrayfire) and working on a small project. 我是Rust(和Arrayfire)的新手,正在从事一个小项目。 I'm trying to convert an Arrayfire Array (only real) back to a Rust Vec. 我正在尝试将Arrayfire阵列(仅真实)转换回Rust Vec。

After some research, I wasn't able to find a solution. 经过一番研究,我找不到解决方案。 The Rust Arrayfire documentation section to indexing only shows (as far as I can see) methods which return another Array. Rust Arrayfire文档的索引部分仅显示(据我所知)返回另一个Array的方法。

I found this post talking about the C++ Arrayfire but the Rust Arrayfire Array does not implement the indexing trait. 我发现这篇文章是关于C ++ Arrayfire的,但是Rust Arrayfire Array并没有实现索引特性。

Is there a way to convert an an Arrayfire Array to a Rust Vec or a method to index an Array returning one element (for example one i64) like v[0] does? 有没有一种方法可以将Arrayfire数组转换为Rust Vec,还是可以像v [0]一样为返回一个元素(例如一个i64)的数组建立索引的方法?

You use the host function of Array . 您使用Arrayhost函数。 Something like this should work: 这样的事情应该起作用:

let mut buffer = Vec::<f64>::new();
buffer.resize(ar.elements());
ar.host(&mut buffer);
// Buffer now contains a copy of the data.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM