4

I'm new to Rust (and Arrayfire) and working on a small project. I'm trying to convert an Arrayfire Array (only real) back to a 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.

I found this post talking about the C++ Arrayfire but the Rust Arrayfire Array does not implement the indexing trait.

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?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Zwei Blali
  • 53
  • 3

1 Answers1

8

You use the host function of Array. 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.
Sebastian Redl
  • 69,373
  • 8
  • 123
  • 157