77# http://arrayfire.com/licenses/BSD-3-Clause
88########################################################
99
10- import array as host
1110import inspect
1211from .library import *
1312from .util import *
14- from .data import *
1513
1614def create_array (buf , numdims , idims , dtype ):
17- out_arr = c_longlong (0 )
18- c_dims = dim4 (idims [0 ], idims [1 ], idims [2 ], idims [3 ])
19- safe_call (clib .af_create_array (pointer (out_arr ), c_longlong (buf ), numdims , pointer (c_dims ), dtype ))
15+ out_arr = ct .c_longlong (0 )
16+ ct .c_dims = dim4 (idims [0 ], idims [1 ], idims [2 ], idims [3 ])
17+ safe_call (clib .af_create_array (ct .pointer (out_arr ), ct .c_longlong (buf ),\
18+ numdims , ct .pointer (ct .c_dims ), dtype ))
2019 return out_arr
2120
2221def constant_array (val , d0 , d1 = None , d2 = None , d3 = None , dtype = f32 ):
2322
24- if not isinstance (dtype , c_int ):
23+ if not isinstance (dtype , ct . c_int ):
2524 if isinstance (dtype , int ):
26- dtype = c_int (dtype )
25+ dtype = ct . c_int (dtype )
2726 else :
2827 raise TypeError ("Invalid dtype" )
2928
30- out = c_longlong (0 )
29+ out = ct . c_longlong (0 )
3130 dims = dim4 (d0 , d1 , d2 , d3 )
3231
3332 if isinstance (val , complex ):
34- c_real = c_double (val .real )
35- c_imag = c_double (val .imag )
33+ c_real = ct . c_double (val .real )
34+ c_imag = ct . c_double (val .imag )
3635
3736 if (dtype != c32 and dtype != c64 ):
3837 dtype = c32
3938
40- safe_call (clib .af_constant_complex (pointer (out ), c_real , c_imag , 4 , pointer (dims ), dtype ))
39+ safe_call (clib .af_constant_complex (ct .pointer (out ), c_real , c_imag ,\
40+ 4 , ct .pointer (dims ), dtype ))
4141 elif dtype == s64 :
42- c_val = c_longlong (val .real )
43- safe_call (clib .af_constant_long (pointer (out ), c_val , 4 , pointer (dims )))
42+ c_val = ct . c_longlong (val .real )
43+ safe_call (clib .af_constant_long (ct . pointer (out ), c_val , 4 , ct . pointer (dims )))
4444 elif dtype == u64 :
45- c_val = c_ulonglong (val .real )
46- safe_call (clib .af_constant_ulong (pointer (out ), c_val , 4 , pointer (dims )))
45+ c_val = ct . c_ulonglong (val .real )
46+ safe_call (clib .af_constant_ulong (ct . pointer (out ), c_val , 4 , ct . pointer (dims )))
4747 else :
48- c_val = c_double (val )
49- safe_call (clib .af_constant (pointer (out ), c_val , 4 , pointer (dims ), dtype ))
48+ c_val = ct . c_double (val )
49+ safe_call (clib .af_constant (ct . pointer (out ), c_val , 4 , ct . pointer (dims ), dtype ))
5050
5151 return out
5252
@@ -63,7 +63,7 @@ def binary_func(lhs, rhs, c_func):
6363 elif not isinstance (rhs , array ):
6464 TypeError ("Invalid parameter to binary function" )
6565
66- safe_call (c_func (pointer (out .arr ), lhs .arr , other .arr , False ))
66+ safe_call (c_func (ct . pointer (out .arr ), lhs .arr , other .arr , False ))
6767
6868 return out
6969
@@ -79,15 +79,15 @@ def binary_funcr(lhs, rhs, c_func):
7979 elif not isinstance (lhs , array ):
8080 TypeError ("Invalid parameter to binary function" )
8181
82- c_func (pointer (out .arr ), other .arr , rhs .arr , False )
82+ c_func (ct . pointer (out .arr ), other .arr , rhs .arr , False )
8383
8484 return out
8585
8686class array (object ):
8787
8888 def __init__ (self , src = None , dims = (0 ,)):
8989
90- self .arr = c_longlong (0 )
90+ self .arr = ct . c_longlong (0 )
9191
9292 buf = None
9393 buf_len = 0
@@ -96,6 +96,8 @@ def __init__(self, src=None, dims=(0,)):
9696
9797 if src is not None :
9898
99+ host = __import__ ("array" )
100+
99101 if isinstance (src , host .array ):
100102 buf ,buf_len = src .buffer_info ()
101103 type_char = src .typecode
@@ -127,92 +129,92 @@ def __del__(self):
127129 clib .af_release_array (self .arr )
128130
129131 def elements (self ):
130- num = c_ulonglong (0 )
131- safe_call (clib .af_get_elements (pointer (num ), self .arr ))
132+ num = ct . c_ulonglong (0 )
133+ safe_call (clib .af_get_elements (ct . pointer (num ), self .arr ))
132134 return num .value
133135
134136 def type (self ):
135- dty = c_int (f32 .value )
136- safe_call (clib .af_get_type (pointer (dty ), self .arr ))
137+ dty = ct . c_int (f32 .value )
138+ safe_call (clib .af_get_type (ct . pointer (dty ), self .arr ))
137139 return dty .value
138140
139141 def dims (self ):
140- d0 = c_longlong (0 )
141- d1 = c_longlong (0 )
142- d2 = c_longlong (0 )
143- d3 = c_longlong (0 )
144- safe_call (clib .af_get_dims (pointer (d0 ), pointer (d1 ), pointer (d2 ), pointer (d3 ), self .arr ))
142+ d0 = ct . c_longlong (0 )
143+ d1 = ct . c_longlong (0 )
144+ d2 = ct . c_longlong (0 )
145+ d3 = ct . c_longlong (0 )
146+ safe_call (clib .af_get_dims (ct . pointer (d0 ), ct . pointer (d1 ), ct . pointer (d2 ), ct . pointer (d3 ), self .arr ))
145147 dims = (d0 .value ,d1 .value ,d2 .value ,d3 .value )
146148 return dims [:self .numdims ()]
147149
148150 def numdims (self ):
149- nd = c_uint (0 )
150- safe_call (clib .af_get_numdims (pointer (nd ), self .arr ))
151+ nd = ct . c_uint (0 )
152+ safe_call (clib .af_get_numdims (ct . pointer (nd ), self .arr ))
151153 return nd .value
152154
153155 def is_empty (self ):
154- res = c_bool (False )
155- safe_call (clib .af_is_empty (pointer (res ), self .arr ))
156+ res = ct . c_bool (False )
157+ safe_call (clib .af_is_empty (ct . pointer (res ), self .arr ))
156158 return res .value
157159
158160 def is_scalar (self ):
159- res = c_bool (False )
160- safe_call (clib .af_is_scalar (pointer (res ), self .arr ))
161+ res = ct . c_bool (False )
162+ safe_call (clib .af_is_scalar (ct . pointer (res ), self .arr ))
161163 return res .value
162164
163165 def is_row (self ):
164- res = c_bool (False )
165- safe_call (clib .af_is_row (pointer (res ), self .arr ))
166+ res = ct . c_bool (False )
167+ safe_call (clib .af_is_row (ct . pointer (res ), self .arr ))
166168 return res .value
167169
168170 def is_column (self ):
169- res = c_bool (False )
170- safe_call (clib .af_is_column (pointer (res ), self .arr ))
171+ res = ct . c_bool (False )
172+ safe_call (clib .af_is_column (ct . pointer (res ), self .arr ))
171173 return res .value
172174
173175 def is_vector (self ):
174- res = c_bool (False )
175- safe_call (clib .af_is_vector (pointer (res ), self .arr ))
176+ res = ct . c_bool (False )
177+ safe_call (clib .af_is_vector (ct . pointer (res ), self .arr ))
176178 return res .value
177179
178180 def is_complex (self ):
179- res = c_bool (False )
180- safe_call (clib .af_is_complex (pointer (res ), self .arr ))
181+ res = ct . c_bool (False )
182+ safe_call (clib .af_is_complex (ct . pointer (res ), self .arr ))
181183 return res .value
182184
183185 def is_real (self ):
184- res = c_bool (False )
185- safe_call (clib .af_is_real (pointer (res ), self .arr ))
186+ res = ct . c_bool (False )
187+ safe_call (clib .af_is_real (ct . pointer (res ), self .arr ))
186188 return res .value
187189
188190 def is_double (self ):
189- res = c_bool (False )
190- safe_call (clib .af_is_double (pointer (res ), self .arr ))
191+ res = ct . c_bool (False )
192+ safe_call (clib .af_is_double (ct . pointer (res ), self .arr ))
191193 return res .value
192194
193195 def is_single (self ):
194- res = c_bool (False )
195- safe_call (clib .af_is_single (pointer (res ), self .arr ))
196+ res = ct . c_bool (False )
197+ safe_call (clib .af_is_single (ct . pointer (res ), self .arr ))
196198 return res .value
197199
198200 def is_real_floating (self ):
199- res = c_bool (False )
200- safe_call (clib .af_is_realfloating (pointer (res ), self .arr ))
201+ res = ct . c_bool (False )
202+ safe_call (clib .af_is_realfloating (ct . pointer (res ), self .arr ))
201203 return res .value
202204
203205 def is_floating (self ):
204- res = c_bool (False )
205- safe_call (clib .af_is_floating (pointer (res ), self .arr ))
206+ res = ct . c_bool (False )
207+ safe_call (clib .af_is_floating (ct . pointer (res ), self .arr ))
206208 return res .value
207209
208210 def is_integer (self ):
209- res = c_bool (False )
210- safe_call (clib .af_is_integer (pointer (res ), self .arr ))
211+ res = ct . c_bool (False )
212+ safe_call (clib .af_is_integer (ct . pointer (res ), self .arr ))
211213 return res .value
212214
213215 def is_bool (self ):
214- res = c_bool (False )
215- safe_call (clib .af_is_bool (pointer (res ), self .arr ))
216+ res = ct . c_bool (False )
217+ safe_call (clib .af_is_bool (ct . pointer (res ), self .arr ))
216218 return res .value
217219
218220 def __add__ (self , other ):
0 commit comments