forked from mesham/epython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.py
More file actions
76 lines (67 loc) · 1.96 KB
/
array.py
File metadata and controls
76 lines (67 loc) · 1.96 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
def array(a,b=none,c=none,d=none,e=none,f=none,g=none):
if (b is none):
return native rtl_allocatearray(a)
elif (c is none):
return native rtl_allocatearray(a,b)
elif (d is none):
return native rtl_allocatearray(a,b,c)
elif (e is none):
return native rtl_allocatearray(a,b,c,d)
elif (f is none):
return native rtl_allocatearray(a,b,c,d,e)
elif (g is none):
return native rtl_allocatearray(a,b,c,d,e,f)
else:
return native rtl_allocatearray(a,b,c,d,e,f,g)
def shared_mem_array(a,b=none,c=none,d=none,e=none,f=none,g=none):
if (b is none):
return native rtl_allocatesharedarray(a)
elif (c is none):
return native rtl_allocatesharedarray(a,b)
elif (d is none):
return native rtl_allocatesharedarray(a,b,c)
elif (e is none):
return native rtl_allocatesharedarray(a,b,c,d)
elif (f is none):
return native rtl_allocatesharedarray(a,b,c,d,e)
elif (g is none):
return native rtl_allocatesharedarray(a,b,c,d,e,f)
else:
return native rtl_allocatesharedarray(a,b,c,d,e,f,g)
def flatten(arr):
native rtl_flatten(arr, size(arr))
return arr
def arraycopy(target, source):
if (len(target) != len(source)):
print "Error, array copy overall sizes must match"
exit()
else:
native rtl_arraycopy(target, source, ndim(target), ndim(source), len(target))
def size(arr):
dims=ndim(arr)
if dims > 0:
s=shape(arr)
arraylength=1
i=0
while i<dims:
arraylength*=s[i]
i+=1
return arraylength
else:
return 0
def freearray(arr):
native rtl_free(arr)
def len(arr):
return size(arr)
def ndim(arr):
return native rtl_numdims(arr)
def shape(arr):
i=ndim(arr)
shape_val=[0]*i
j=0
while j<i:
shape_val[j]=native rtl_dsize(arr, j)
j+=1
return shape_val
def nbytes(arr):
return size(arr) * 4