Skip to content

Commit 338b4b3

Browse files
committed
Rename py_list_to_c_array() to c_array() objectbox#24
Also, py_list_to_c_pointer() to c_array_pointer()
1 parent 800c857 commit 338b4b3

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

objectbox/c.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ def c_voidp_as_bytes(voidp, size):
330330
return memoryview(ctypes.cast(voidp, ctypes.POINTER(ctypes.c_ubyte * size))[0]).tobytes()
331331

332332

333-
def py_list_to_c_array(py_list: Union[List[Any], np.ndarray], c_type):
334-
""" Converts the given python list or ndarray into a C array. """
333+
def c_array(py_list: Union[List[Any], np.ndarray], c_type):
334+
""" Converts the given python list or ndarray into a C array of c_type. """
335335
if isinstance(py_list, np.ndarray):
336336
if py_list.ndim != 1:
337337
raise Exception(f"ndarray is expected to be 1-dimensional. Input shape: {py_list.shape}")
@@ -342,9 +342,9 @@ def py_list_to_c_array(py_list: Union[List[Any], np.ndarray], c_type):
342342
raise Exception(f"Unsupported Python list type: {type(py_list)}")
343343

344344

345-
def py_list_to_c_pointer(py_list: Union[List[Any], np.ndarray], c_type):
346-
""" Converts the given python list or ndarray into a C array, and returns a pointer type. """
347-
return ctypes.cast(py_list_to_c_array(py_list, c_type), ctypes.POINTER(c_type))
345+
def c_array_pointer(py_list: Union[List[Any], np.ndarray], c_type):
346+
""" Converts the given python list or ndarray into a C array of c_type. Returns its pointer type. """
347+
return ctypes.cast(c_array(py_list, c_type), ctypes.POINTER(c_type))
348348

349349

350350
# OBX_model* (void);

objectbox/query.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ def count(self) -> int:
9191
count = ctypes.c_uint64()
9292
obx_query_count(self._c_query, ctypes.byref(count))
9393
return int(count.value)
94-
94+
9595
def remove(self) -> int:
9696
count = ctypes.c_uint64()
9797
obx_query_remove(self._c_query, ctypes.byref(count))
9898
return int(count.value)
99-
99+
100100
def offset(self, offset: int) -> 'Query':
101101
obx_query_offset(self._c_query, offset)
102102
return self
103-
103+
104104
def limit(self, limit: int) -> 'Query':
105105
obx_query_limit(self._c_query, limit)
106106
return self
@@ -121,7 +121,7 @@ def set_parameter_vector_f32(self,
121121
if isinstance(value, np.ndarray) and value.dtype != np.float32:
122122
raise Exception(f"value dtype is expected to be np.float32, got: {value.dtype}")
123123
prop_id = self._entity.get_property_id(prop)
124-
c_value = py_list_to_c_array(value, ctypes.c_float)
124+
c_value = c_array(value, ctypes.c_float)
125125
num_el = len(value)
126126
obx_query_param_vector_float32(self._c_query, self._entity.id, prop_id, c_value, num_el)
127127
return self

objectbox/query_builder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,17 @@ def nearest_neighbors_f32(self, prop: Union[int, str, Property], query_vector: U
113113
if isinstance(query_vector, np.ndarray) and query_vector.dtype != np.float32:
114114
raise Exception(f"query_vector dtype is expected to be np.float32, got: {query_vector.dtype}")
115115
prop_id = self._entity.get_property_id(prop)
116-
c_query_vector = py_list_to_c_array(query_vector, ctypes.c_float)
116+
c_query_vector = c_array(query_vector, ctypes.c_float)
117117
cond = obx_qb_nearest_neighbors_f32(self._c_builder, prop_id, c_query_vector, element_count)
118118
return cond
119119

120120
def any(self, conditions: List[obx_qb_cond]) -> obx_qb_cond:
121-
c_conditions = py_list_to_c_pointer(conditions, obx_qb_cond)
121+
c_conditions = c_array(conditions, obx_qb_cond)
122122
cond = obx_qb_any(self._c_builder, c_conditions, len(conditions))
123123
return cond
124124

125125
def all(self, conditions: List[obx_qb_cond]) -> obx_qb_cond:
126-
c_conditions = py_list_to_c_pointer(conditions, obx_qb_cond)
126+
c_conditions = c_array_pointer(conditions, obx_qb_cond)
127127
cond = obx_qb_all(self._c_builder, c_conditions, len(conditions))
128128
return cond
129129

0 commit comments

Comments
 (0)