Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 74af5e7

Browse filesBrowse files
committed
Updated examples to use static imports
1 parent 73caf44 commit 74af5e7
Copy full SHA for 74af5e7

File tree

3 files changed

+32
-28
lines changed
Filter options

3 files changed

+32
-28
lines changed

‎examples/HelloWorld.java

Copy file name to clipboardExpand all lines: examples/HelloWorld.java
+22-20Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import java.util.Random;
22
import com.arrayfire.*;
3+
import static com.arrayfire.ArrayFire.*;
34

45
public 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.");

‎examples/MonteCarloPi.java

Copy file name to clipboardExpand all lines: examples/MonteCarloPi.java
+8-7Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import java.util.Random;
22
import com.arrayfire.*;
3+
import static com.arrayfire.ArrayFire.*;
34

45
public class MonteCarloPi {
56

@@ -22,16 +23,16 @@ public static double deviceCalcPi(int size) throws Exception {
2223
try {
2324

2425
int[] dims = new int[] { size, 1 };
25-
Data.randu(x, dims, Array.Type.Float);
26-
Data.randu(y, dims, Array.Type.Float);
26+
randu(x, dims, Type.Float);
27+
randu(y, dims, Type.Float);
2728

28-
Arith.mul(x, x, x);
29-
Arith.mul(y, y, y);
29+
mul(x, x, x);
30+
mul(y, y, y);
3031

31-
Arith.add(res, x, y);
32-
Arith.lt(res, res, 1);
32+
add(res, x, y);
33+
lt(res, res, 1);
3334

34-
double count = Algorithm.sumAll(res);
35+
double count = sumAll(res);
3536
return 4.0 * ((double) (count)) / size;
3637

3738
} catch (Exception e) {

‎examples/WindowEx.java

Copy file name to clipboardExpand all lines: examples/WindowEx.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import static com.arrayfire.ArrayFire.*;
12
import com.arrayfire.*;
23

34
public class WindowEx {
45
public static void main(String[] args) {
56
System.out.println("Creating window");
67
try {
78
Array img = new Array();
8-
Data.randu(img, new int[] { 200, 200 }, Array.Type.Int);
9+
randu(img, new int[] { 200, 200 }, Type.Int);
910
Window window = new Window();
1011
while (!window.closeWindow()) {
1112
window.image(img, "Image");

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.