1
1
import java .util .Random ;
2
2
import com .arrayfire .*;
3
+ import static com .arrayfire .ArrayFire .*;
3
4
4
5
public class HelloWorld {
5
6
@@ -8,73 +9,73 @@ public static void main(String[] args) {
8
9
Array a = new Array (), b = new Array (), c = new Array (), d = new Array ();
9
10
Array f = new Array ();
10
11
try {
11
- Util . info ();
12
+ info ();
12
13
13
14
System .out .println ("Create a 5-by-3 matrix of random floats on the GPU" );
14
- Data . randu (a , new int [] { 5 , 3 }, Array . Type .Float );
15
+ randu (a , new int [] { 5 , 3 }, Type .Float );
15
16
System .out .println (a .toString ("a" ));
16
17
17
18
System .out .println ("Element-wise arithmetic" );
18
- Arith . sin (b , a );
19
+ sin (b , a );
19
20
System .out .println (b .toString ("b" ));
20
21
21
22
System .out .println ("Fourier transform the result" );
22
- Signal . fft (c , b );
23
+ fft (c , b );
23
24
System .out .println (c .toString ("c" ));
24
25
25
26
System .out .println ("Matmul b and c" );
26
- Arith . mul (d , b , c );
27
+ mul (d , b , c );
27
28
System .out .println (d .toString ("d" ));
28
29
29
30
System .out .println ("Calculate weighted variance." );
30
31
Array forVar = new Array ();
31
32
Array weights = new Array ();
32
- Data . randn (forVar , new int [] { 5 , 5 }, Array . Type .Double );
33
- Data . randn (weights , new int [] { 5 , 5 }, Array . Type .Double );
33
+ randn (forVar , new int [] { 5 , 5 }, Type .Double );
34
+ randn (weights , new int [] { 5 , 5 }, Type .Double );
34
35
System .out .println (forVar .toString ("forVar" ));
35
36
36
- double abc = Statistics . var (forVar , weights , Double .class );
37
+ double abc = var (forVar , weights , Double .class );
37
38
System .out .println (String .format ("Variance is: %f" , abc ));
38
39
forVar .close ();
39
40
weights .close ();
40
41
41
42
System .out .println ("Median" );
42
43
Array forMedian = new Array ();
43
- Data . randu (forMedian , new int [] { 3 , 5 }, Array . Type .Double );
44
+ randu (forMedian , new int [] { 3 , 5 }, Type .Double );
44
45
System .out .println (forMedian .toString ("forMedian" ));
45
- double median = Statistics . median (forMedian , Double .class );
46
+ double median = median (forMedian , Double .class );
46
47
System .out .printf ("Median = %f\n " , median );
47
48
forMedian .close ();
48
49
49
50
System .out .println ("Calculate standard deviation" );
50
51
Array forStdev = new Array ();
51
- Data . randu (forStdev , new int [] { 5 , 3 }, Array . Type .Double );
52
+ randu (forStdev , new int [] { 5 , 3 }, Type .Double );
52
53
System .out .println (forStdev .toString ("forStdev" ));
53
- double stdev = Statistics . stdev (forStdev , Double .class );
54
+ double stdev = stdev (forStdev , Double .class );
54
55
System .out .println (String .format ("Stdev is: %f" , stdev ));
55
56
forStdev .close ();
56
57
57
58
System .out .println ("Covariance" );
58
59
Array x = new Array ();
59
60
Array z = new Array ();
60
- Data . randu (x , new int [] { 5 , 3 }, Array . Type .Double );
61
- Data . randu (z , new int [] { 5 , 3 }, Array . Type .Double );
61
+ randu (x , new int [] { 5 , 3 }, Type .Double );
62
+ randu (z , new int [] { 5 , 3 }, Type .Double );
62
63
System .out .println (x .toString ("x" ));
63
64
System .out .println (z .toString ("z" ));
64
- Array cov = Statistics . cov (x , z , false );
65
+ Array cov = cov (x , z , false );
65
66
System .out .println (cov .toString ("cov" ));
66
67
67
68
System .out .println ("Correlation coefficient of the 2 previous arrays" );
68
- double corrcoef = Statistics . corrcoef (x , z , Double .class );
69
+ double corrcoef = corrcoef (x , z , Double .class );
69
70
System .out .printf ("Corrcoef = %f\n " , corrcoef );
70
71
x .close ();
71
72
z .close ();
72
73
73
74
System .out .println ("Topk" );
74
75
Array forTopk = new Array ();
75
- Data . randu (forTopk , new int [] { 3 , 3 }, Array . Type .Double );
76
+ randu (forTopk , new int [] { 3 , 3 }, Type .Double );
76
77
System .out .println (forTopk .toString ("forTopk" ));
77
- Array [] results = Statistics . topk (forTopk , 3 , 0 , Statistics . TopkOrder .DEFAULT );
78
+ Array [] results = topk (forTopk , 3 , 0 , TopkOrder .DEFAULT );
78
79
System .out .println (results [0 ].toString ("Indicies" ));
79
80
System .out .println (results [1 ].toString ("Values" ));
80
81
@@ -84,6 +85,7 @@ public static void main(String[] args) {
84
85
for (int dim : dims ) {
85
86
total *= dim ;
86
87
}
88
+
87
89
float [] data = new float [total ];
88
90
Random rand = new Random ();
89
91
@@ -96,8 +98,8 @@ public static void main(String[] args) {
96
98
97
99
System .out .println ("Add e and random array" );
98
100
Array randa = new Array ();
99
- Data . randu (randa , dims , Array . Type .Float );
100
- Arith . add (f , e , randa );
101
+ randu (randa , dims , Type .Float );
102
+ add (f , e , randa );
101
103
System .out .println (f .toString ("f" ));
102
104
103
105
System .out .println ("Copy result back to host." );
0 commit comments