Skip to content

Commit b70d060

Browse files
committed
Merge pull request #15 from 9prady9/arith
Arith
2 parents 6fa3f93 + 6c53edf commit b70d060

File tree

13 files changed

+950
-398
lines changed

13 files changed

+950
-398
lines changed

Cargo.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ build = "build.rs"
66

77
[dependencies]
88
libc = "*"
9+
num = "*"
910

1011
[build-dependencies.rustc-serialize]
1112
rustc-serialize = "*"
@@ -14,6 +15,6 @@ rustc-serialize = "*"
1415
name = "arrayfire"
1516
path = "src/lib.rs"
1617

17-
[[test]]
18+
[[example]]
1819
name = "helloworld"
19-
path = "tests/hello_world.rs"
20+
path = "examples/helloworld.rs"

README.md

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ Edit [build.conf](build.conf) to modify the build flags. The structure is a simp
1010
Currently Rust does not allow key:value pairs to be passed from the CLI.
1111
To use an existing arrayfire installation modify the first three JSON values.
1212

13-
To build:
13+
To build arrayfire:
1414

1515
```bash
1616
git submodule update --init --recursive
1717
cargo build
1818
```
1919

20-
To test:
20+
To run hello world example:
2121

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

3737
Element-wise arithmetic
38+
sin(a) + 1.5 =>
3839
[5 3 1 1]
39-
0.6744 0.4317 0.7006
40-
0.7962 0.6189 0.2905
41-
0.0390 0.1097 0.6549
42-
0.8243 0.4531 0.3509
43-
0.7987 0.4910 0.6299
40+
2.1744 1.9317 2.2006
41+
2.2962 2.1189 1.7905
42+
1.5390 1.6097 2.1549
43+
2.3243 1.9531 1.8509
44+
2.2987 1.9910 2.1299
45+
46+
sin(a) + cos(a) =>
47+
[5 3 1 1]
48+
1.4128 1.3337 1.4142
49+
1.4012 1.4044 1.2474
50+
1.0382 1.1037 1.4106
51+
1.3905 1.3446 1.2873
52+
1.4004 1.3621 1.4066
53+
54+
!a =>
55+
[5 3 1 1]
56+
1 1 1
57+
1 1 1
58+
1 1 1
59+
1 1 1
60+
1 1 1
61+
62+
a + b
63+
[5 3 1 1]
64+
2.9147 2.3780 2.9767
65+
3.2172 2.7862 2.0853
66+
1.5780 1.7196 2.8689
67+
3.2933 2.4233 2.2094
68+
3.2238 2.5042 2.8113
69+
70+
Fourier transform the result
71+
[5 3 1 1]
72+
(10.6327,0.0000) (9.6043,0.0000) (10.1267,0.0000)
73+
(0.4689,0.4640) (0.3193,0.0802) (0.1713,0.1441)
74+
(-0.3491,-0.7454) (-0.2923,-0.4018) (0.2667,0.4886)
75+
(-0.3491,0.7454) (-0.2923,0.4018) (0.2667,-0.4886)
76+
(0.4689,-0.4640) (0.3193,-0.0802) (0.1713,-0.1441)
77+
78+
Create 2-by-3 matrix from host data
79+
[2 3 1 1]
80+
1 3 5
81+
2 4 6
82+
83+
Sort A and print sorted array and corresponding indices
84+
[5 3 1 1]
85+
0.0390 0.1099 0.2948
86+
0.7402 0.4464 0.3585
87+
0.9210 0.4702 0.6814
88+
0.9251 0.5132 0.7140
89+
0.9690 0.6673 0.7762
90+
91+
[5 3 1 1]
92+
2 2 1
93+
0 0 3
94+
1 3 4
95+
4 4 2
96+
3 1 0
97+
98+
u8 constant array
99+
[5 3 1 1]
100+
1 1 1
101+
1 1 1
102+
1 1 1
103+
1 1 1
104+
1 1 1
105+
106+
Is u8_cnst array float precision type ? false
44107
```
45108

46109
## Issues

tests/hello_world.rs renamed to examples/helloworld.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ extern crate arrayfire as af;
44
use af::Dim4;
55
use af::Array;
66

7-
#[test]
87
fn main() {
98
af::set_device(0);
109
af::info();
@@ -16,8 +15,15 @@ fn main() {
1615
af::print(&a);
1716

1817
println!("Element-wise arithmetic");
19-
let b: Array = af::sin(&a) + 1.5;
20-
af::print(&b);
18+
let b: Array = &af::sin(&a) + 1.5;
19+
let b2: Array = &af::sin(&a) + &af::cos(&a);
20+
let b3: Array = ! &a;
21+
println!("sin(a) + 1.5 => "); af::print(&b);
22+
println!("sin(a) + cos(a) => "); af::print(&b2);
23+
println!("!a => "); af::print(&b3);
24+
25+
let test = &a + &b;
26+
println!("a + b"); af::print(&test);
2127

2228
// printf("Negate the first three elements of second column\n");
2329
// B(seq(0, 2), 1) = B(seq(0, 2), 1) * -1;
@@ -46,4 +52,9 @@ fn main() {
4652
let (vals, inds) = af::sort_index(&a, 0, true);
4753
af::print(&vals);
4854
af::print(&inds);
55+
56+
println!("u8 constant array");
57+
let u8_cnst = af::constant(1 as u8, dims);
58+
af::print(&u8_cnst);
59+
println!("Is u8_cnst array float precision type ? {}", u8_cnst.is_single());
4960
}

0 commit comments

Comments
 (0)