MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / Fingerprints_init

Function Fingerprints_init

python/stringzillas.c:1538–1602  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1536}
1537
1538static int Fingerprints_init(Fingerprints *self, PyObject *args, PyObject *kwargs) {
1539 sz_size_t ndim;
1540 PyObject *window_widths_obj = NULL;
1541 sz_size_t alphabet_size = 256;
1542 PyObject *capabilities_tuple = NULL;
1543 sz_capability_t capabilities = default_hardware_capabilities;
1544
1545 static char *kwlist[] = {"ndim", "window_widths", "alphabet_size", "capabilities", NULL};
1546 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "n|OnO", kwlist, &ndim, &window_widths_obj, &alphabet_size,
1547 &capabilities_tuple))
1548 return -1;
1549
1550 // Parse capabilities if provided
1551 if (capabilities_tuple)
1552 if (parse_and_intersect_capabilities(capabilities_tuple, &capabilities) != 0) return -1;
1553
1554 sz_size_t *window_widths = NULL;
1555 sz_size_t window_widths_count = 0;
1556
1557 // Parse window_widths if provided - require NumPy array of uint64
1558 if (window_widths_obj && window_widths_obj != Py_None) {
1559 if (!PyArray_Check(window_widths_obj)) {
1560 PyErr_SetString(PyExc_TypeError, "window_widths must be a numpy array of uint64");
1561 return -1;
1562 }
1563
1564 PyArrayObject *arr = (PyArrayObject *)window_widths_obj;
1565
1566 // Check dtype is uint64
1567 if (PyArray_TYPE(arr) != NPY_UINT64) {
1568 PyErr_SetString(PyExc_TypeError, "window_widths must have dtype uint64");
1569 return -1;
1570 }
1571
1572 // Check that it's 1D
1573 if (PyArray_NDIM(arr) != 1) {
1574 PyErr_SetString(PyExc_ValueError, "window_widths must be a 1D array");
1575 return -1;
1576 }
1577
1578 // Check that it's contiguous (no strides)
1579 if (!PyArray_IS_C_CONTIGUOUS(arr)) {
1580 PyErr_SetString(PyExc_ValueError, "window_widths must be a contiguous C-style array (no strides)");
1581 return -1;
1582 }
1583
1584 window_widths_count = PyArray_SIZE(arr);
1585 window_widths = (sz_size_t *)PyArray_DATA(arr);
1586 }
1587
1588 char const *error_detail = NULL;
1589 sz_status_t status = szs_fingerprints_init(ndim, alphabet_size, window_widths, window_widths_count, NULL,
1590 capabilities, &self->handle, &error_detail);
1591
1592 if (status != sz_success_k) {
1593 set_stringzilla_error(status, error_detail, "Fingerprints initialization");
1594 return -1;
1595 }

Callers

nothing calls this directly

Calls 2

set_stringzilla_errorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…