File: array_test.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 (63 lines) | stat: -rw-r--r-- 2,037 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
#!/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 array as host
from . import _util

def simple_array(verbose=False):
    display_func = _util.display_func(verbose)
    print_func   = _util.print_func(verbose)

    a = af.Array([1, 2, 3])
    display_func(a)
    display_func(a.T)
    display_func(a.H)
    print_func(a.shape)

    b = a.as_type(af.Dtype.s32)
    display_func(b)

    print_func(a.elements(), a.type(), a.dims(), a.numdims())
    print_func(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row())
    print_func(a.is_complex(), a.is_real(), a.is_double(), a.is_single())
    print_func(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool())


    a = af.Array(host.array('i', [4, 5, 6]))
    display_func(a)
    print_func(a.elements(), a.type(), a.dims(), a.numdims())
    print_func(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row())
    print_func(a.is_complex(), a.is_real(), a.is_double(), a.is_single())
    print_func(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool())

    a = af.Array(host.array('I', [7, 8, 9] * 3), (3,3))
    display_func(a)
    print_func(a.elements(), a.type(), a.dims(), a.numdims())
    print_func(a.is_empty(), a.is_scalar(), a.is_column(), a.is_row())
    print_func(a.is_complex(), a.is_real(), a.is_double(), a.is_single())
    print_func(a.is_real_floating(), a.is_floating(), a.is_integer(), a.is_bool())

    c = a.to_ctype()
    for n in range(a.elements()):
        print_func(c[n])

    c,s = a.to_ctype(True, True)
    for n in range(a.elements()):
        print_func(c[n])
    print_func(s)

    arr = a.to_array()
    lst = a.to_list(True)

    print_func(arr)
    print_func(lst)

_util.tests['array'] = simple_array