File: index.py

package info (click to toggle)
python-arrayfire 3.3.20160624-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 764 kB
  • ctags: 826
  • sloc: python: 3,999; makefile: 205
file content (81 lines) | stat: -rw-r--r-- 1,866 bytes parent folder | download
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
#!/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
from arrayfire import ParallelRange
import array as host
from . import _util

def simple_index(verbose=False):
    display_func = _util.display_func(verbose)
    print_func   = _util.print_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 ParallelRange(1,3):
        a[ii] = b[ii]

    display_func(a)

    for ii in 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 rows:
        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