File: intro.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 (66 lines) | stat: -rw-r--r-- 1,693 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
#!/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
import sys
from array import array

if __name__ == "__main__":
    if (len(sys.argv) > 1):
        af.set_device(int(sys.argv[1]))
    af.info()

    print("\n---- Intro to ArrayFire using signed(s32) arrays ----\n")

    h_A = array('i', ( 1,  2,  4, -1,  2,  0,  4,  2,  3))
    h_B = array('i', ( 2,  3,  5,  6,  0, 10,-12,  0,  1))

    A = af.Array(h_A, (3,3))
    B = af.Array(h_B, (3,3))

    print("\n---- Sub referencing and sub assignment\n")
    af.display(A)
    af.display(A[0,:])
    af.display(A[:,0])
    A[0,0] = 11
    A[1] = 100
    af.display(A)
    af.display(B)
    A[1,:] = B[2,:]
    af.display(A)

    print("\n---- Bitwise operations\n")
    af.display(A & B)
    af.display(A | B)
    af.display(A ^ B)

    print("\n---- Transpose\n")
    af.display(A)
    af.display(af.transpose(A))

    print("\n---- Flip Vertically / Horizontally\n")
    af.display(A)
    af.display(af.flip(A, 0))
    af.display(af.flip(A, 1))

    print("\n---- Sum, Min, Max along row / columns\n")
    af.display(A)
    af.display(af.sum(A, 0))
    af.display(af.min(A, 0))
    af.display(af.max(A, 0))
    af.display(af.sum(A, 1))
    af.display(af.min(A, 1))
    af.display(af.max(A, 1))

    print("\n---- Get minimum with index\n")
    (min_val, min_idx) = af.imin(A, 0)
    af.display(min_val)
    af.display(min_idx)