forked from arrayfire/arrayfire-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelloworld.py
More file actions
executable file
·61 lines (48 loc) · 1.47 KB
/
helloworld.py
File metadata and controls
executable file
·61 lines (48 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
#######################################################
# Copyright (c) 2019, ArrayFire
# All rights reserved.
#
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# http://arrayfire.com/licenses/BSD-3-Clause
########################################################
import arrayfire as af
try:
# Display backend information
af.info()
print("Create a 5-by-3 matrix of random floats on the GPU\n")
A = af.randu(5, 3, 1, 1, af.Dtype.f32)
af.display(A)
print("Element-wise arithmetic\n")
B = af.sin(A) + 1.5
af.display(B)
print("Negate the first three elements of second column\n")
B[0:3, 1] = B[0:3, 1] * -1
af.display(B)
print("Fourier transform the result\n")
C = af.fft(B)
af.display(C)
print("Grab last row\n")
c = C[-1, :]
af.display(c)
print("Scan Test\n")
r = af.constant(2, 16, 4, 1, 1)
af.display(r)
print("Scan\n")
S = af.scan(r, 0, af.BINARYOP.MUL)
af.display(S)
print("Create 2-by-3 matrix from host data\n")
d = [1, 2, 3, 4, 5, 6]
D = af.Array(d, (2, 3))
af.display(D)
print("Copy last column onto first\n")
D[:, 0] = D[:, -1]
af.display(D)
print("Sort A and print sorted array and corresponding indices\n")
sorted_vals, sorted_idxs = af.sort_index(A)
af.display(A)
af.display(sorted_vals)
af.display(sorted_idxs)
except Exception as e:
print("Error: " + str(e))