forked from arrayfire/arrayfire-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_algorithm.py
More file actions
executable file
·70 lines (53 loc) · 1.69 KB
/
Copy pathsimple_algorithm.py
File metadata and controls
executable file
·70 lines (53 loc) · 1.69 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
62
63
64
65
66
67
68
69
70
#!/usr/bin/python
#######################################################
# Copyright (c) 2015, 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
a = af.randu(3, 3)
print(af.sum(a), af.product(a), af.min(a), af.max(a), af.count(a), af.any_true(a), af.all_true(a))
af.display(af.sum(a, 0))
af.display(af.sum(a, 1))
af.display(af.product(a, 0))
af.display(af.product(a, 1))
af.display(af.min(a, 0))
af.display(af.min(a, 1))
af.display(af.max(a, 0))
af.display(af.max(a, 1))
af.display(af.count(a, 0))
af.display(af.count(a, 1))
af.display(af.any_true(a, 0))
af.display(af.any_true(a, 1))
af.display(af.all_true(a, 0))
af.display(af.all_true(a, 1))
af.display(af.accum(a, 0))
af.display(af.accum(a, 1))
af.display(af.sort(a, is_ascending=True))
af.display(af.sort(a, is_ascending=False))
val,idx = af.sort_index(a, is_ascending=True)
af.display(val)
af.display(idx)
val,idx = af.sort_index(a, is_ascending=False)
af.display(val)
af.display(idx)
b = af.randu(3,3)
keys,vals = af.sort_by_key(a, b, is_ascending=True)
af.display(keys)
af.display(vals)
keys,vals = af.sort_by_key(a, b, is_ascending=False)
af.display(keys)
af.display(vals)
c = af.randu(5,1)
d = af.randu(5,1)
cc = af.set_unique(c, is_sorted=False)
dd = af.set_unique(af.sort(d), is_sorted=True)
af.display(cc)
af.display(dd)
af.display(af.set_union(cc, dd, is_unique=True))
af.display(af.set_union(cc, dd, is_unique=False))
af.display(af.set_intersect(cc, cc, is_unique=True))
af.display(af.set_intersect(cc, cc, is_unique=False))