-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathindex.py
More file actions
84 lines (68 loc) · 1.79 KB
/
index.py
File metadata and controls
84 lines (68 loc) · 1.79 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/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 array as host
import arrayfire as af
from . import _util
def simple_index(verbose=False):
display_func = _util.display_func(verbose)
a = af.randu(5, 5)
display_func(a)
b = af.Array(a)
display_func(b)
c = a.copy()
display_func(c)
display_func(a[0, 0])
display_func(a[0])
display_func(a[:])
display_func(a[:, :])
display_func(a[0:3, ])
display_func(a[-2:-1, -1])
display_func(a[0:5])
display_func(a[0:5:2])
idx = af.Array(host.array("i", [0, 3, 2]))
display_func(idx)
aa = a[idx]
display_func(aa)
a[0] = 1
display_func(a)
a[0] = af.randu(1, 5)
display_func(a)
a[:] = af.randu(5, 5)
display_func(a)
a[:, -1] = af.randu(5, 1)
display_func(a)
a[0:5:2] = af.randu(3, 5)
display_func(a)
a[idx, idx] = af.randu(3, 3)
display_func(a)
a = af.randu(5, 1)
b = af.randu(5, 1)
display_func(a)
display_func(b)
for ii in af.ParallelRange(1, 3):
a[ii] = b[ii]
display_func(a)
for ii in af.ParallelRange(2, 5):
b[ii] = 2
display_func(b)
a = af.randu(3, 2)
rows = af.constant(0, 1, dtype=af.Dtype.s32)
b = a[:, rows]
display_func(b)
for r in range(rows.elements()):
display_func(r)
display_func(b[:, r])
a = af.randu(3)
c = af.randu(3)
b = af.constant(1, 3, dtype=af.Dtype.b8)
display_func(a)
a[b] = c
display_func(a)
_util.tests["index"] = simple_index