11import java .util .Random ;
22import com .arrayfire .*;
3+ import static com .arrayfire .ArrayFire .*;
34
45public class HelloWorld {
56
@@ -8,73 +9,73 @@ public static void main(String[] args) {
89 Array a = new Array (), b = new Array (), c = new Array (), d = new Array ();
910 Array f = new Array ();
1011 try {
11- Util . info ();
12+ info ();
1213
1314 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 );
1516 System .out .println (a .toString ("a" ));
1617
1718 System .out .println ("Element-wise arithmetic" );
18- Arith . sin (b , a );
19+ sin (b , a );
1920 System .out .println (b .toString ("b" ));
2021
2122 System .out .println ("Fourier transform the result" );
22- Signal . fft (c , b );
23+ fft (c , b );
2324 System .out .println (c .toString ("c" ));
2425
2526 System .out .println ("Matmul b and c" );
26- Arith . mul (d , b , c );
27+ mul (d , b , c );
2728 System .out .println (d .toString ("d" ));
2829
2930 System .out .println ("Calculate weighted variance." );
3031 Array forVar = new Array ();
3132 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 );
3435 System .out .println (forVar .toString ("forVar" ));
3536
36- double abc = Statistics . var (forVar , weights , Double .class );
37+ double abc = var (forVar , weights , Double .class );
3738 System .out .println (String .format ("Variance is: %f" , abc ));
3839 forVar .close ();
3940 weights .close ();
4041
4142 System .out .println ("Median" );
4243 Array forMedian = new Array ();
43- Data . randu (forMedian , new int [] { 3 , 5 }, Array . Type .Double );
44+ randu (forMedian , new int [] { 3 , 5 }, Type .Double );
4445 System .out .println (forMedian .toString ("forMedian" ));
45- double median = Statistics . median (forMedian , Double .class );
46+ double median = median (forMedian , Double .class );
4647 System .out .printf ("Median = %f\n " , median );
4748 forMedian .close ();
4849
4950 System .out .println ("Calculate standard deviation" );
5051 Array forStdev = new Array ();
51- Data . randu (forStdev , new int [] { 5 , 3 }, Array . Type .Double );
52+ randu (forStdev , new int [] { 5 , 3 }, Type .Double );
5253 System .out .println (forStdev .toString ("forStdev" ));
53- double stdev = Statistics . stdev (forStdev , Double .class );
54+ double stdev = stdev (forStdev , Double .class );
5455 System .out .println (String .format ("Stdev is: %f" , stdev ));
5556 forStdev .close ();
5657
5758 System .out .println ("Covariance" );
5859 Array x = new Array ();
5960 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 );
6263 System .out .println (x .toString ("x" ));
6364 System .out .println (z .toString ("z" ));
64- Array cov = Statistics . cov (x , z , false );
65+ Array cov = cov (x , z , false );
6566 System .out .println (cov .toString ("cov" ));
6667
6768 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 );
6970 System .out .printf ("Corrcoef = %f\n " , corrcoef );
7071 x .close ();
7172 z .close ();
7273
7374 System .out .println ("Topk" );
7475 Array forTopk = new Array ();
75- Data . randu (forTopk , new int [] { 3 , 3 }, Array . Type .Double );
76+ randu (forTopk , new int [] { 3 , 3 }, Type .Double );
7677 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 );
7879 System .out .println (results [0 ].toString ("Indicies" ));
7980 System .out .println (results [1 ].toString ("Values" ));
8081
@@ -84,6 +85,7 @@ public static void main(String[] args) {
8485 for (int dim : dims ) {
8586 total *= dim ;
8687 }
88+
8789 float [] data = new float [total ];
8890 Random rand = new Random ();
8991
@@ -96,8 +98,8 @@ public static void main(String[] args) {
9698
9799 System .out .println ("Add e and random array" );
98100 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 );
101103 System .out .println (f .toString ("f" ));
102104
103105 System .out .println ("Copy result back to host." );
0 commit comments