11import ctypes
22
3- from arrayfire_wrapper ._backend import _backend
43from arrayfire_wrapper .defines import AFArray , ArrayBuffer , CDimT , CShape , CType
54from arrayfire_wrapper .dtypes import Dtype
65from arrayfire_wrapper .lib ._constants import PointerSource
7- from arrayfire_wrapper .lib ._error_handler import safe_call
6+ from arrayfire_wrapper .lib ._utility import call_from_clib
87
98
109def create_strided_array (
@@ -31,17 +30,16 @@ def create_strided_array(
3130 if len (strides ) < 4 :
3231 strides += (strides [- 1 ],) * (4 - len (strides ))
3332
34- safe_call (
35- _backend .clib .af_create_strided_array (
36- ctypes .pointer (out ),
37- ctypes .c_void_p (array_buffer .address ),
38- offset ,
39- c_shape .original_shape ,
40- ctypes .pointer (c_shape .c_array ),
41- CShape (* strides ).c_array ,
42- dtype .c_api_value ,
43- pointer_source .value ,
44- )
33+ call_from_clib (
34+ create_strided_array .__name__ ,
35+ ctypes .pointer (out ),
36+ ctypes .c_void_p (array_buffer .address ),
37+ offset ,
38+ c_shape .original_shape ,
39+ ctypes .pointer (c_shape .c_array ),
40+ CShape (* strides ).c_array ,
41+ dtype .c_api_value ,
42+ pointer_source .value ,
4543 )
4644 return out
4745
@@ -51,7 +49,7 @@ def get_offset(arr: AFArray, /) -> int:
5149 source: https://arrayfire.org/docs/group__internal__func__offset.htm#ga303cb334026bdb5cab86e038951d6a5a
5250 """
5351 out = CDimT (0 )
54- safe_call ( _backend . clib . af_get_offset ( ctypes .pointer (out ), arr ) )
52+ call_from_clib ( get_offset . __name__ , ctypes .pointer (out ), arr )
5553 return out .value
5654
5755
@@ -63,10 +61,8 @@ def get_strides(arr: AFArray) -> tuple[int, ...]:
6361 s1 = CDimT (0 )
6462 s2 = CDimT (0 )
6563 s3 = CDimT (0 )
66- safe_call (
67- _backend .clib .af_get_strides (
68- ctypes .pointer (s0 ), ctypes .pointer (s1 ), ctypes .pointer (s2 ), ctypes .pointer (s3 ), arr
69- )
64+ call_from_clib (
65+ get_strides .__name__ , ctypes .pointer (s0 ), ctypes .pointer (s1 ), ctypes .pointer (s2 ), ctypes .pointer (s3 ), arr
7066 )
7167 return (s0 .value , s1 .value , s2 .value , s3 .value )
7268
@@ -76,7 +72,7 @@ def is_linear(arr: AFArray, /) -> bool:
7672 source: https://arrayfire.org/docs/group__internal__func__linear.htm#gaef70fb8591d16522a5b05bd7467e7d8a
7773 """
7874 out = ctypes .c_bool (False )
79- safe_call ( _backend . clib . af_is_linear ( ctypes .pointer (out ), arr ) )
75+ call_from_clib ( is_linear . __name__ , ctypes .pointer (out ), arr )
8076 return bool (out .value )
8177
8278
@@ -85,5 +81,5 @@ def is_owner(arr: AFArray, /) -> bool:
8581 source: https://arrayfire.org/docs/group__internal__func__owner.htm#ga9db0eda6ffa4c49e7f66c3d53d62186a
8682 """
8783 out = ctypes .c_bool (False )
88- safe_call ( _backend . clib . af_is_owner ( ctypes .pointer (out ), arr ) )
84+ call_from_clib ( is_owner . __name__ , ctypes .pointer (out ), arr )
8985 return bool (out .value )
0 commit comments