Skip to content

Commit 2540fe2

Browse files
committed
[Python] Expose new C API into python bridge
1 parent 0e23933 commit 2540fe2

File tree

3 files changed

+191
-14
lines changed

3 files changed

+191
-14
lines changed

python/pycubool/bridge.py

Lines changed: 143 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
_hint_log_all = 128
3737
_hint_no_duplicates = 256
3838
_hint_time_check = 512
39+
_hint_transpose = 1024
3940

4041

4142
def get_log_hints(default=True, error=False, warning=False):
@@ -136,7 +137,10 @@ def load_and_configure(cubool_lib_path: str):
136137
index_t = ctypes.c_uint
137138
hints_t = ctypes.c_uint
138139
matrix_p = ctypes.c_void_p
140+
vector_p = ctypes.c_void_p
141+
139142
p_to_matrix_p = ctypes.POINTER(matrix_p)
143+
p_to_vector_p = ctypes.POINTER(vector_p)
140144

141145
lib.cuBool_SetupLogging.restype = status_t
142146
lib.cuBool_SetupLogging.argtypes = [
@@ -155,8 +159,8 @@ def load_and_configure(cubool_lib_path: str):
155159
lib.cuBool_Matrix_New.restype = status_t
156160
lib.cuBool_Matrix_New.argtypes = [
157161
p_to_matrix_p,
158-
ctypes.c_uint,
159-
ctypes.c_uint
162+
index_t,
163+
index_t
160164
]
161165

162166
lib.cuBool_Matrix_Free.restype = status_t
@@ -167,17 +171,17 @@ def load_and_configure(cubool_lib_path: str):
167171
lib.cuBool_Matrix_Build.restype = status_t
168172
lib.cuBool_Matrix_Build.argtypes = [
169173
matrix_p,
170-
ctypes.POINTER(ctypes.c_uint),
171-
ctypes.POINTER(ctypes.c_uint),
172-
ctypes.c_uint,
174+
ctypes.POINTER(index_t),
175+
ctypes.POINTER(index_t),
176+
index_t,
173177
hints_t
174178
]
175179

176180
lib.cuBool_Matrix_SetElement.restype = status_t
177181
lib.cuBool_Matrix_SetElement.argtypes = [
178182
matrix_p,
179-
ctypes.c_uint,
180-
ctypes.c_uint
183+
index_t,
184+
index_t
181185
]
182186

183187
lib.cuBool_Matrix_SetMarker.restype = status_t
@@ -190,15 +194,15 @@ def load_and_configure(cubool_lib_path: str):
190194
lib.cuBool_Matrix_Marker.argtypes = [
191195
matrix_p,
192196
ctypes.POINTER(ctypes.c_char),
193-
ctypes.POINTER(ctypes.c_uint)
197+
ctypes.POINTER(index_t)
194198
]
195199

196200
lib.cuBool_Matrix_ExtractPairs.restype = status_t
197201
lib.cuBool_Matrix_ExtractPairs.argtypes = [
198202
matrix_p,
199-
ctypes.POINTER(ctypes.c_uint),
200-
ctypes.POINTER(ctypes.c_uint),
201-
ctypes.POINTER(ctypes.c_uint)
203+
ctypes.POINTER(index_t),
204+
ctypes.POINTER(index_t),
205+
ctypes.POINTER(index_t)
202206
]
203207

204208
lib.cuBool_Matrix_ExtractSubMatrix.restype = status_t
@@ -212,6 +216,22 @@ def load_and_configure(cubool_lib_path: str):
212216
hints_t
213217
]
214218

219+
lib.cuBool_Matrix_ExtractRow.restype = status_t
220+
lib.cuBool_Matrix_ExtractRow.argtypes = [
221+
vector_p,
222+
matrix_p,
223+
index_t,
224+
hints_t
225+
]
226+
227+
lib.cuBool_Matrix_ExtractCol.restype = status_t
228+
lib.cuBool_Matrix_ExtractCol.argtypes = [
229+
vector_p,
230+
matrix_p,
231+
index_t,
232+
hints_t
233+
]
234+
215235
lib.cuBool_Matrix_Duplicate.restype = status_t
216236
lib.cuBool_Matrix_Duplicate.argtypes = [
217237
matrix_p,
@@ -228,13 +248,13 @@ def load_and_configure(cubool_lib_path: str):
228248
lib.cuBool_Matrix_Nrows.restype = status_t
229249
lib.cuBool_Matrix_Nrows.argtype = [
230250
matrix_p,
231-
ctypes.POINTER(ctypes.c_uint)
251+
ctypes.POINTER(index_t)
232252
]
233253

234254
lib.cuBool_Matrix_Ncols.restype = status_t
235255
lib.cuBool_Matrix_Ncols.argtype = [
236256
matrix_p,
237-
ctypes.POINTER(ctypes.c_uint)
257+
ctypes.POINTER(index_t)
238258
]
239259

240260
lib.cuBool_Matrix_Nvals.restype = status_t
@@ -243,6 +263,13 @@ def load_and_configure(cubool_lib_path: str):
243263
ctypes.POINTER(ctypes.c_size_t)
244264
]
245265

266+
lib.cuBool_Matrix_Reduce.restype = status_t
267+
lib.cuBool_Matrix_Reduce.argtype = [
268+
vector_p,
269+
matrix_p,
270+
hints_t
271+
]
272+
246273
lib.cuBool_Matrix_Reduce2.restype = status_t
247274
lib.cuBool_Matrix_Reduce2.argtype = [
248275
matrix_p,
@@ -258,6 +285,93 @@ def load_and_configure(cubool_lib_path: str):
258285
hints_t
259286
]
260287

288+
lib.cuBool_Vector_New.restype = status_t
289+
lib.cuBool_Vector_New.argtypes = [
290+
p_to_vector_p,
291+
index_t
292+
]
293+
294+
lib.cuBool_Vector_Build.restype = status_t
295+
lib.cuBool_Vector_Build.argtypes = [
296+
vector_p,
297+
ctypes.POINTER(index_t),
298+
index_t,
299+
hints_t
300+
]
301+
302+
lib.cuBool_Vector_SetElement.restype = status_t
303+
lib.cuBool_Vector_SetElement.argtypes = [
304+
vector_p,
305+
index_t
306+
]
307+
308+
lib.cuBool_Vector_SetMarker.restype = status_t
309+
lib.cuBool_Vector_SetMarker.argtypes = [
310+
vector_p,
311+
ctypes.POINTER(ctypes.c_char)
312+
]
313+
314+
lib.cuBool_Vector_Marker.restype = status_t
315+
lib.cuBool_Vector_Marker.argtypes = [
316+
vector_p,
317+
ctypes.POINTER(ctypes.c_char),
318+
ctypes.POINTER(index_t)
319+
]
320+
321+
lib.cuBool_Vector_ExtractValues.restype = status_t
322+
lib.cuBool_Vector_ExtractValues.argtypes = [
323+
vector_p,
324+
ctypes.POINTER(index_t),
325+
ctypes.POINTER(index_t)
326+
]
327+
328+
lib.cuBool_Vector_ExtractSubVector.restype = status_t
329+
lib.cuBool_Vector_ExtractSubVector.argtypes = [
330+
vector_p,
331+
vector_p,
332+
index_t,
333+
index_t,
334+
hints_t
335+
]
336+
337+
lib.cuBool_Vector_Duplicate.restype = status_t
338+
lib.cuBool_Vector_Duplicate.argtypes = [
339+
vector_p,
340+
p_to_vector_p
341+
]
342+
343+
lib.cuBool_Vector_Nvals.restype = status_t
344+
lib.cuBool_Vector_Nvals.argtypes = [
345+
vector_p,
346+
ctypes.POINTER(index_t)
347+
]
348+
349+
lib.cuBool_Vector_Nrows.restype = status_t
350+
lib.cuBool_Vector_Nrows.argtypes = [
351+
vector_p,
352+
ctypes.POINTER(index_t)
353+
]
354+
355+
lib.cuBool_Vector_Free.restype = status_t
356+
lib.cuBool_Vector_Free.argtypes = [
357+
vector_p
358+
]
359+
360+
lib.cuBool_Vector_Reduce.restype = status_t
361+
lib.cuBool_Vector_Reduce.argtypes = [
362+
ctypes.POINTER(index_t),
363+
vector_p,
364+
hints_t
365+
]
366+
367+
lib.cuBool_Vector_EWiseAdd.restype = status_t
368+
lib.cuBool_Vector_EWiseAdd.argtypes = [
369+
vector_p,
370+
vector_p,
371+
vector_p,
372+
hints_t
373+
]
374+
261375
lib.cuBool_MxM.restype = status_t
262376
lib.cuBool_MxM.argtypes = [
263377
matrix_p,
@@ -266,6 +380,22 @@ def load_and_configure(cubool_lib_path: str):
266380
hints_t
267381
]
268382

383+
lib.cuBool_MxV.restype = status_t
384+
lib.cuBool_MxV.argtypes = [
385+
vector_p,
386+
matrix_p,
387+
vector_p,
388+
hints_t
389+
]
390+
391+
lib.cuBool_VxM.restype = status_t
392+
lib.cuBool_VxM.argtypes = [
393+
vector_p,
394+
vector_p,
395+
matrix_p,
396+
hints_t
397+
]
398+
269399
lib.cuBool_Kronecker.restype = status_t
270400
lib.cuBool_Kronecker.argtypes = [
271401
matrix_p,

python/pycubool/matrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Matrix:
4040
- equality check
4141
4242
Debug features:
43-
- String markers
43+
- string markers
4444
"""
4545

4646
__slots__ = ["hnd"]

python/pycubool/vector.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
Vector primitive.
3+
"""
4+
5+
import ctypes
6+
import random
7+
8+
from . import wrapper
9+
from . import bridge
10+
11+
12+
__all__ = [
13+
"Vector"
14+
]
15+
16+
17+
class Vector:
18+
"""
19+
Wrapper for cuBool sparse boolean vector type.
20+
21+
Vector class supports all cuBool C API Vector functions.
22+
Also Vector class provides additional fancy functions/operations for better user experience.
23+
24+
Vector creation:
25+
- empty
26+
- from list data
27+
- random generated
28+
29+
Vector operations:
30+
- vxm
31+
- ewiseadd
32+
- reduce
33+
- vector extraction
34+
35+
Vector functions:
36+
- to string
37+
- values iterating
38+
- equality check
39+
40+
Debug features:
41+
- string markers
42+
"""
43+
44+
__slots__ = ["hnd"]
45+
46+
def __init__(self, hnd):
47+
self.hnd = hnd

0 commit comments

Comments
 (0)