Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ build = "build.rs"

[dependencies]
libc = "*"
num = "*"

[build-dependencies.rustc-serialize]
rustc-serialize = "*"
Expand All @@ -14,6 +15,6 @@ rustc-serialize = "*"
name = "arrayfire"
path = "src/lib.rs"

[[test]]
[[example]]
name = "helloworld"
path = "tests/hello_world.rs"
path = "examples/helloworld.rs"
79 changes: 71 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ Edit [build.conf](build.conf) to modify the build flags. The structure is a simp
Currently Rust does not allow key:value pairs to be passed from the CLI.
To use an existing arrayfire installation modify the first three JSON values.

To build:
To build arrayfire:

```bash
git submodule update --init --recursive
cargo build
```

To test:
To run hello world example:

```bash
~/p/arrayfire_rust> cargo test
~/p/arrayfire_rust> cargo run --example helloworld
...
running 1 test
ArrayFire v3.0.0 (CUDA, 64-bit Mac OSX, build d8d4b38)
Expand All @@ -35,12 +35,75 @@ Create a 5-by-3 matrix of random floats on the GPU
0.9251 0.5132 0.6814

Element-wise arithmetic
sin(a) + 1.5 =>
[5 3 1 1]
0.6744 0.4317 0.7006
0.7962 0.6189 0.2905
0.0390 0.1097 0.6549
0.8243 0.4531 0.3509
0.7987 0.4910 0.6299
2.1744 1.9317 2.2006
2.2962 2.1189 1.7905
1.5390 1.6097 2.1549
2.3243 1.9531 1.8509
2.2987 1.9910 2.1299

sin(a) + cos(a) =>
[5 3 1 1]
1.4128 1.3337 1.4142
1.4012 1.4044 1.2474
1.0382 1.1037 1.4106
1.3905 1.3446 1.2873
1.4004 1.3621 1.4066

!a =>
[5 3 1 1]
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1

a + b
[5 3 1 1]
2.9147 2.3780 2.9767
3.2172 2.7862 2.0853
1.5780 1.7196 2.8689
3.2933 2.4233 2.2094
3.2238 2.5042 2.8113

Fourier transform the result
[5 3 1 1]
(10.6327,0.0000) (9.6043,0.0000) (10.1267,0.0000)
(0.4689,0.4640) (0.3193,0.0802) (0.1713,0.1441)
(-0.3491,-0.7454) (-0.2923,-0.4018) (0.2667,0.4886)
(-0.3491,0.7454) (-0.2923,0.4018) (0.2667,-0.4886)
(0.4689,-0.4640) (0.3193,-0.0802) (0.1713,-0.1441)

Create 2-by-3 matrix from host data
[2 3 1 1]
1 3 5
2 4 6

Sort A and print sorted array and corresponding indices
[5 3 1 1]
0.0390 0.1099 0.2948
0.7402 0.4464 0.3585
0.9210 0.4702 0.6814
0.9251 0.5132 0.7140
0.9690 0.6673 0.7762

[5 3 1 1]
2 2 1
0 0 3
1 3 4
4 4 2
3 1 0

u8 constant array
[5 3 1 1]
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1

Is u8_cnst array float precision type ? false
```

## Issues
Expand Down
17 changes: 14 additions & 3 deletions tests/hello_world.rs → examples/helloworld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ extern crate arrayfire as af;
use af::Dim4;
use af::Array;

#[test]
fn main() {
af::set_device(0);
af::info();
Expand All @@ -16,8 +15,15 @@ fn main() {
af::print(&a);

println!("Element-wise arithmetic");
let b: Array = af::sin(&a) + 1.5;
af::print(&b);
let b: Array = &af::sin(&a) + 1.5;
let b2: Array = &af::sin(&a) + &af::cos(&a);
let b3: Array = ! &a;
println!("sin(a) + 1.5 => "); af::print(&b);
println!("sin(a) + cos(a) => "); af::print(&b2);
println!("!a => "); af::print(&b3);

let test = &a + &b;
println!("a + b"); af::print(&test);

// printf("Negate the first three elements of second column\n");
// B(seq(0, 2), 1) = B(seq(0, 2), 1) * -1;
Expand Down Expand Up @@ -46,4 +52,9 @@ fn main() {
let (vals, inds) = af::sort_index(&a, 0, true);
af::print(&vals);
af::print(&inds);

println!("u8 constant array");
let u8_cnst = af::constant(1 as u8, dims);
af::print(&u8_cnst);
println!("Is u8_cnst array float precision type ? {}", u8_cnst.is_single());
}
Loading