Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinyu Li authored and Xinyu Li committed Oct 24, 2024
1 parent ca0d995 commit f4796d0
Showing 1 changed file with 26 additions and 48 deletions.
74 changes: 26 additions & 48 deletions python/ionpy/Port.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def bind(self, v: Union[int, float, Buffer, List[Union[Buffer, int, float]]]):
self.bind_value.value = v

if self.type.code_ == TypeCode.Int:
if self.type.bits_ == 8 and ion_port_bind_i8_array(self.obj, ctypes.byref(self.bind_value)) != 0:
if self.type.bits_ == 8 and ion_port_bind_i8(self.obj, ctypes.byref(self.bind_value)) != 0:
raise Exception('Invalid operation')
elif self.type.bits_ == 16 and ion_port_bind_i16(self.obj, ctypes.byref(self.bind_value)) != 0:
raise Exception('Invalid operation')
Expand All @@ -112,56 +112,34 @@ def bind(self, v: Union[int, float, Buffer, List[Union[Buffer, int, float]]]):
raise Exception('Invalid operation')
else:
# scalar array
c_arr = None
ctype = np.ctypeslib.as_ctypes_type(self.type.to_dtype())
c_arr = (ctype* len(v))(*v)
self.bind_value = c_arr
if self.type.code_ == TypeCode.Int:
if self.type.bits_ == 8:
c_arr = (ctypes.c_int8 * len(v))(*v)
if ion_port_bind_i8_array(self.obj, c_arr, len(v)) != 0:
raise Exception('Invalid operation')
elif self.type.bits_ == 16:
c_arr = (ctypes.c_int16 * len(v))(*v)
if ion_port_bind_i16_array(self.obj, c_arr, len(v)) != 0:
raise Exception('Invalid operation')
elif self.type.bits_ == 32 :
c_arr = (ctypes.c_int32 * len(v))(*v)
if ion_port_bind_i32_array(self.obj, c_arr, len(v)) != 0:
raise Exception('Invalid operation')
elif self.type.bits_ == 64:
c_arr = (ctypes.c_int64 * len(v))(*v)
if ion_port_bind_i64_array(self.obj, c_arr, len(v)) != 0:
raise Exception('Invalid operation')
if self.type.bits_ == 8 and ion_port_bind_i8_array(self.obj, ctypes.byref(self.bind_value)) != 0:
raise Exception('Invalid operation')
elif self.type.bits_ == 16 and ion_port_bind_i16_array(self.obj, ctypes.byref(self.bind_value)) != 0:
raise Exception('Invalid operation')
elif self.type.bits_ == 32 and ion_port_bind_i32_array(self.obj, ctypes.byref(self.bind_value)) != 0:
raise Exception('Invalid operation')
elif self.type.bits_ == 64 and ion_port_bind_i64_array(self.obj, ctypes.byref(self.bind_value)) != 0:
raise Exception('Invalid operation')
elif self.type.code_ == TypeCode.Uint:
if self.type.bits_ == 1:
c_arr = (ctypes.c_bool * len(v))(*v)
if ion_port_bind_u1_array(self.obj, c_arr, len(v)) != 0:
raise Exception('Invalid operation')
if self.type.bits_ == 8 :
c_arr = (ctypes.c_uint8 * len(v))(*v)
if ion_port_bind_u8_array(self.obj, c_arr, len(v)) != 0:
raise Exception('Invalid operation')
if self.type.bits_ == 16:
c_arr = (ctypes.c_uint16 * len(v))(*v)
if ion_port_bind_u16_array(self.obj, c_arr, len(v)) != 0:
raise Exception('Invalid operation')
if self.type.bits_ == 32:
c_arr = (ctypes.c_uint32* len(v))(*v)
if ion_port_bind_u32_array(self.obj, c_arr, len(v)) != 0:
raise Exception('Invalid operation')
if self.type.bits_ == 64:
c_arr = (ctypes.c_uint64 * len(v))(*v)
if ion_port_bind_u64_array(self.obj, c_arr, len(v)) != 0:
raise Exception('Invalid operation')
if self.type.bits_ == 1 and ion_port_bind_u1_array(self.obj, ctypes.byref(self.bind_value)) != 0:
raise Exception('Invalid operation')
if self.type.bits_ == 8 and ion_port_bind_u8_array(self.obj, ctypes.byref(self.bind_value)) != 0:
raise Exception('Invalid operation')
if self.type.bits_ == 16 and ion_port_bind_u16_array(self.obj, ctypes.byref(self.bind_value)) != 0:
raise Exception('Invalid operation')
if self.type.bits_ == 32 and ion_port_bind_u32_array(self.obj, ctypes.byref(self.bind_value)) != 0:
raise Exception('Invalid operation')
if self.type.bits_ == 64 and ion_port_bind_u64_array(self.obj, ctypes.byref(self.bind_value)) != 0:
raise Exception('Invalid operation')
elif self.type.code_ == TypeCode.Float:
if self.type.bits_ == 32:
c_arr = (ctypes.c_float * len(v))(*v)
if ion_port_bind_f32(self.obj, c_arr, len(v)) != 0:
raise Exception('Invalid operation')
if self.type.bits_ == 64:
c_arr = (ctypes.c_double * len(v))(*v)
if ion_port_bind_f64(self.obj, c_arr, len(v)) != 0:
raise Exception('Invalid operation')

self.bind_value = c_arr
if self.type.bits_ == 32 and ion_port_bind_f32_array(self.obj, ctypes.byref(self.bind_value)) != 0:
raise Exception('Invalid operation')
if self.type.bits_ == 64 and ion_port_bind_f64_array(self.obj, ctypes.byref(self.bind_value)) != 0:
raise Exception('Invalid operation')

# vector
else:
Expand Down

0 comments on commit f4796d0

Please sign in to comment.