Skip to content

Commit 0ec6da3

Browse files
mlloredapavanky
authored andcommitted
Improved helloworld example to match C++ lib.
1 parent 3d3fdab commit 0ec6da3

File tree

1 file changed

+45
-8
lines changed

1 file changed

+45
-8
lines changed

examples/helloworld/helloworld.py

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,51 @@
1111

1212
import arrayfire as af
1313

14-
# Display backend information
15-
af.info()
14+
try:
15+
# Display backend information
16+
af.info()
1617

17-
# Generate a uniform random array with a size of 5 elements
18-
a = af.randu(5, 1)
18+
print("Create a 5-by-3 matrix of random floats on the GPU\n")
19+
A = af.randu(5, 3, 1, 1, af.Dtype.f32)
20+
af.display(A)
1921

20-
# Print a and its minimum value
21-
print(a)
22+
print("Element-wise arithmetic\n")
23+
B = af.sin(A) + 1.5
24+
af.display(B)
2225

23-
# Print min and max values of a
24-
print("Minimum, Maximum: ", af.min(a), af.max(a))
26+
print("Negate the first three elements of second column\n")
27+
B[0:3, 1] = B[0:3, 1] * -1
28+
af.display(B)
29+
30+
print("Fourier transform the result\n");
31+
C = af.fft(B);
32+
af.display(C);
33+
34+
print("Grab last row\n");
35+
c = C[-1,:];
36+
af.display(c);
37+
38+
print("Scan Test\n");
39+
r = af.constant(2, 16, 4, 1, 1);
40+
af.display(r);
41+
42+
print("Scan\n");
43+
S = af.scan(r, 0, af.BINARYOP.MUL);
44+
af.display(S);
45+
46+
print("Create 2-by-3 matrix from host data\n");
47+
d = [ 1, 2, 3, 4, 5, 6 ]
48+
D = af.Array(d, (2, 3))
49+
af.display(D)
50+
51+
print("Copy last column onto first\n");
52+
D[:,0] = D[:, -1]
53+
af.display(D);
54+
55+
print("Sort A and print sorted array and corresponding indices\n");
56+
[sorted_vals, sorted_idxs] = af.sort_index(A);
57+
af.display(A)
58+
af.display(sorted_vals)
59+
af.display(sorted_idxs)
60+
except Exception as e:
61+
print("Error: " + str(e))

0 commit comments

Comments
 (0)