|
11 | 11 |
|
12 | 12 | import arrayfire as af
|
13 | 13 |
|
14 |
| -# Display backend information |
15 |
| -af.info() |
| 14 | +try: |
| 15 | + # Display backend information |
| 16 | + af.info() |
16 | 17 |
|
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) |
19 | 21 |
|
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) |
22 | 25 |
|
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