&nbsp;

In this post, we would like to introduce our latest &amp; newest language bindings for ArrayFire library: ArrayFire-Rust - Rust bindings for ArrayFire. We have been working on the wrapper and using it in daily production within the company for the last few months and now regard it stable enough for public distribution.
<h4><a id="How_to_use_arrayfire_from_cratesio_2"></a>How to use ArrayFire from <a href="http://crates.io">crates.io</a></h4>
To use the rust bindings for ArrayFire from <strong><a href="http://crates.io">crates.io</a></strong>, the following requirements are to be met first:
<ol>
	<li>Download and install ArrayFire binaries based on your operating system.</li>
	<li>If you are on Linux or OSX, set the environment variable <code>AF_PATH</code> to point to ArrayFire installation root folder. (This is automatically set for you on Windows.)</li>
	<li>Make sure you add the path to library files to your path environment variables.
<ul>
	<li>On Linux &amp; OSX: do <code>export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$AF_PATH/lib</code></li>
	<li>On Windows: Add <code>%AF_PATH%\lib</code> to your PATH environment variable.</li>
</ul>
</li>
	<li>Do <code>cargo new --bin helloworld &amp;&amp; helloworld</code></li>
	<li>Edit <code>Cargo.toml</code> to add the line <code>arrayfire = "3.2.0"</code> to the <code>[dependencies]</code> section.</li>
	<li>Add the following sample rust code to your source file <code>helloworld/src/main.rs</code> file
<pre><code class="language-rust">
extern crate arrayfire as af;
use af::*; // Ideally, you should use only names you are about to use, for example purposes * is fine.
    
fn main() {
    let num_rows: u64 = 5;
    let num_cols: u64 = 3;
    let dims = Dim4::new(&amp;[num_rows, num_cols, 1, 1]);
    println!("Create a 5-by-3 matrix of random floats on the GPU");
    let a = match randu(dims, Aftype::F32) {
        Ok(value) =&gt; value,
        Err(error) =&gt; panic!("{}", error),
    };
    print(&amp;a);
}
</code></pre>
</li>
	<li>Do <code>cargo run</code> and you should see output similar to the one below. Depending on the type of acceleration (GPU - {NVIDIA | AMD}/CPU) devices you have on your machine, the device information will vary as the default device priority is to use any CUDA compatible device available, if not use OpenCL compatbile device and fallback to CPU if no GPUs are available.
<pre><code class="language-bash">
ArrayFire v3.2.0 (CUDA, 64-bit Mac OSX, build d8d4b38)
Platform: CUDA Toolkit 7, Driver: CUDA Driver Version: 7000
[0] GeForce GT 750M, 2048 MB, CUDA Compute 3.0
Create a 5-by-3 matrix of random floats on the GPU
[5 3 1 1]
    0.7402     0.4464     0.7762
    0.9210     0.6673     0.2948
    0.0390     0.1099     0.7140
    0.9690     0.4702     0.3585
    0.9251     0.5132     0.6814
</code></pre>
</li>
</ol>
<h4><a id="Documentation_44"></a>Documentation</h4>
You can find the documentation for all the functions and macros available in the crate over <a href="http://arrayfire.github.io/arrayfire-rust/arrayfire/index.html">here</a>. You can also look at the ArrayFire C/C++ API documentation <a href="http://sandbox.arrayfire.com/docs/group__func__categories.htm">on ArrayFire.com</a> which categorizes ArrayFire functions into several specific domains.
<h4><a id="Example_Project_47"></a>Example Project</h4>
<a href="https://github.com/jramapuram/hal">hal</a> project is one of the initial adaptors of our rust wrapper for ArrayFire to enable use of GPUs from Rust via ArrayFire.
<h4><a id="Credits_50"></a>Credits</h4>
We would like to thank <a href="https://github.com/jramapuram">Jason Ramapuram</a> for helping us in writing and reviewing the rust bindings. We would also like to thank the users from rust community who provided their invaluable feedback while working on the bindings for ArrayFire.

&nbsp;