fix some cython code

This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-03-29 21:18:18 +03:00
parent ad5530b9ef
commit 6269a7485c
32 changed files with 17108 additions and 2728 deletions
+5 -2
View File
@@ -1,6 +1,6 @@
---
description: "Python coding conventions: PEP 8, type hints, pydantic, pytest, async patterns, project structure"
globs: ["**/*.py", "**/pyproject.toml", "**/requirements*.txt"]
globs: ["**/*.py", "**/*.pyx", "**/*.pxd", "**/pyproject.toml", "**/requirements*.txt"]
---
# Python
@@ -12,5 +12,8 @@ globs: ["**/*.py", "**/pyproject.toml", "**/requirements*.txt"]
- Catch specific exceptions, never bare `except:`; use custom exception classes
- Use `async`/`await` with `asyncio` for I/O-bound concurrency
- Use `pytest` for testing (not `unittest`); fixtures for setup/teardown
- Use virtual environments (`venv` or `poetry`); pin dependencies
- **NEVER install packages globally** (`pip install` / `pip3 install` without a venv). ALWAYS use a virtual environment (`venv`, `poetry`, or `conda env`). If no venv exists for the project, create one first (`python3 -m venv .venv && source .venv/bin/activate`) before installing anything. Pin dependencies.
- Format with `black`; lint with `ruff` or `flake8`
## Cython
- In `cdef class` methods, prefer `cdef` over `cpdef` unless the method must be callable from Python. `cdef` = C-only (fastest), `cpdef` = C + Python, `def` = Python-only. Check all call sites before choosing.
+2
View File
@@ -42,6 +42,8 @@ coverage.xml
*.JPG
*.jpeg
*.png
*.mlpackage
*.mlmodel
# Standalone skill output (ephemeral, not part of project)
_standalone/
Binary file not shown.
+9 -8
View File
@@ -2,10 +2,10 @@
## Current Step
flow: existing-code
step: 5
step: 6
name: Run Tests
status: in_progress
sub_step: 2 — Run Tests
sub_step: 2 — running tests
retry_count: 0
## Completed Steps
@@ -14,8 +14,9 @@ retry_count: 0
|------|------|-----------|-------------|
| 1 | Document | 2026-03-21 | 10 modules, 4 components, full _docs/ generated from existing codebase |
| 2 | Test Spec | 2026-03-21 | 39 test scenarios (16 positive, 8 negative, 11 non-functional), 85% total coverage, 5 artifacts produced |
| 3 | Decompose Tests | 2026-03-23 | 11 tasks (AZ-138..AZ-148), 35 complexity points, 3 batches. Phase 3 test data gate PASSED: 39/39 scenarios validated, 12 data files provided. |
| 4 | Implement Tests | 2026-03-23 | 11 tasks implemented across 4 batches, 38 tests (2 skipped), all code reviews PASS_WITH_WARNINGS. Commits: 5418bd7, a469579, 861d4f0, f0e3737. |
| 3 | Code Testability Rev. | 2026-03-29 | Engine factory refactoring completed: polymorphic EngineClass pattern (TensorRT/CoreML/ONNX) with auto-detection. Hardcoded values aligned with Docker compose. |
| 4 | Decompose Tests | 2026-03-23 | 11 tasks (AZ-138..AZ-148), 35 complexity points, 3 batches. Phase 3 test data gate PASSED: 39/39 scenarios validated, 12 data files provided. |
| 5 | Implement Tests | 2026-03-23 | 11 tasks implemented across 4 batches, 38 tests (2 skipped), all code reviews PASS_WITH_WARNINGS. Commits: 5418bd7, a469579, 861d4f0, f0e3737. |
## Key Decisions
- User chose to document existing codebase before proceeding
@@ -34,10 +35,10 @@ retry_count: 0
- Jira MCP auth skipped — tickets not transitioned to In Testing
## Last Session
date: 2026-03-24
ended_at: Step 4 Implement Tests — COMPLETE. All 11 tasks, 38 tests, 4 batches.
reason: step completed, context limit approaching
notes: All integration tests implemented and committed. Next step: 5 Run Tests — verify tests pass before proceeding to refactor. Recommend fresh conversation for better context management.
date: 2026-03-29
ended_at: Step 5 completed, Step 6 (Run Tests) next
reason: state file cross-check corrected — steps 1-5 confirmed done from folder structure
notes: Engine factory refactoring (polymorphic EngineClass) completed in code. State file had stale Current Step pointer at step 3 — corrected to step 6.
## Blockers
- none
+341 -459
View File
@@ -1543,7 +1543,7 @@ struct __pyx_obj_13constants_inf_AnnotationClass {
struct __pyx_obj_22ai_availability_status_AIAvailabilityStatus {
PyObject_HEAD
struct __pyx_vtabstruct_22ai_availability_status_AIAvailabilityStatus *__pyx_vtab;
enum __pyx_t_22ai_availability_status_AIAvailabilityEnum status;
int status;
PyObject *error_message;
PyObject *_lock;
};
@@ -1553,7 +1553,7 @@ struct __pyx_obj_22ai_availability_status_AIAvailabilityStatus {
struct __pyx_vtabstruct_22ai_availability_status_AIAvailabilityStatus {
PyObject *(*serialize)(struct __pyx_obj_22ai_availability_status_AIAvailabilityStatus *);
PyObject *(*set_status)(struct __pyx_obj_22ai_availability_status_AIAvailabilityStatus *, enum __pyx_t_22ai_availability_status_AIAvailabilityEnum, struct __pyx_opt_args_22ai_availability_status_20AIAvailabilityStatus_set_status *__pyx_optional_args);
PyObject *(*set_status)(struct __pyx_obj_22ai_availability_status_AIAvailabilityStatus *, int, struct __pyx_opt_args_22ai_availability_status_20AIAvailabilityStatus_set_status *__pyx_optional_args);
};
static struct __pyx_vtabstruct_22ai_availability_status_AIAvailabilityStatus *__pyx_vtabptr_22ai_availability_status_AIAvailabilityStatus;
/* #### Code section: utility_code_proto ### */
@@ -2258,10 +2258,13 @@ static int __Pyx_VectorcallBuilder_AddArgStr(const char *key, PyObject *value, P
#endif
/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyLong_From_enum____pyx_t_22ai_availability_status_AIAvailabilityEnum(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum value);
static CYTHON_INLINE PyObject* __Pyx_PyLong_From_int(int value);
/* CIntFromPy.proto */
static CYTHON_INLINE enum __pyx_t_22ai_availability_status_AIAvailabilityEnum __Pyx_PyLong_As_enum____pyx_t_22ai_availability_status_AIAvailabilityEnum(PyObject *);
static CYTHON_INLINE int __Pyx_PyLong_As_int(PyObject *);
/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyLong_From_enum____pyx_t_22ai_availability_status_AIAvailabilityEnum(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum value);
/* CIntFromPy.proto */
static CYTHON_INLINE long __Pyx_PyLong_As_long(PyObject *);
@@ -2286,9 +2289,6 @@ typedef const char *__Pyx_TypeName;
#define __Pyx_DECREF_TypeName(obj)
#endif
/* CIntFromPy.proto */
static CYTHON_INLINE int __Pyx_PyLong_As_int(PyObject *);
/* FastTypeChecks.proto */
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type)
@@ -2373,7 +2373,7 @@ static int __Pyx_State_RemoveModule(void*);
#define __PYX_TYPE_MODULE_PREFIX __PYX_ABI_MODULE_NAME "."
static PyObject *__pyx_f_22ai_availability_status_20AIAvailabilityStatus_serialize(struct __pyx_obj_22ai_availability_status_AIAvailabilityStatus *__pyx_v_self); /* proto*/
static PyObject *__pyx_f_22ai_availability_status_20AIAvailabilityStatus_set_status(struct __pyx_obj_22ai_availability_status_AIAvailabilityStatus *__pyx_v_self, enum __pyx_t_22ai_availability_status_AIAvailabilityEnum __pyx_v_status, struct __pyx_opt_args_22ai_availability_status_20AIAvailabilityStatus_set_status *__pyx_optional_args); /* proto*/
static PyObject *__pyx_f_22ai_availability_status_20AIAvailabilityStatus_set_status(struct __pyx_obj_22ai_availability_status_AIAvailabilityStatus *__pyx_v_self, int __pyx_v_status, struct __pyx_opt_args_22ai_availability_status_20AIAvailabilityStatus_set_status *__pyx_optional_args); /* proto*/
/* Module declarations from "constants_inf" */
static PyObject **__pyx_vp_13constants_inf_CONFIG_FILE = 0;
@@ -2861,7 +2861,7 @@ static PyObject *__pyx_pf_22ai_availability_status_20AIAvailabilityStatus_2__str
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_get); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 24, __pyx_L4_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = __Pyx_PyLong_From_enum____pyx_t_22ai_availability_status_AIAvailabilityEnum(__pyx_v_self->status); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 24, __pyx_L4_error)
__pyx_t_4 = __Pyx_PyLong_From_int(__pyx_v_self->status); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 24, __pyx_L4_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_3 = 1;
#if CYTHON_UNPACK_METHODS
@@ -3057,7 +3057,7 @@ static PyObject *__pyx_f_22ai_availability_status_20AIAvailabilityStatus_seriali
__pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 34, __pyx_L4_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_6 = __Pyx_PyLong_From_enum____pyx_t_22ai_availability_status_AIAvailabilityEnum(__pyx_v_self->status); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 34, __pyx_L4_error)
__pyx_t_6 = __Pyx_PyLong_From_int(__pyx_v_self->status); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 34, __pyx_L4_error)
__Pyx_GOTREF(__pyx_t_6);
if (PyDict_SetItem(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_s, __pyx_t_6) < 0) __PYX_ERR(0, 34, __pyx_L4_error)
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
@@ -3183,7 +3183,7 @@ static PyObject *__pyx_f_22ai_availability_status_20AIAvailabilityStatus_seriali
}
static PyObject *__pyx_f_22ai_availability_status_20AIAvailabilityStatus_set_status(struct __pyx_obj_22ai_availability_status_AIAvailabilityStatus *__pyx_v_self, enum __pyx_t_22ai_availability_status_AIAvailabilityEnum __pyx_v_status, struct __pyx_opt_args_22ai_availability_status_20AIAvailabilityStatus_set_status *__pyx_optional_args) {
static PyObject *__pyx_f_22ai_availability_status_20AIAvailabilityStatus_set_status(struct __pyx_obj_22ai_availability_status_AIAvailabilityStatus *__pyx_v_self, int __pyx_v_status, struct __pyx_opt_args_22ai_availability_status_20AIAvailabilityStatus_set_status *__pyx_optional_args) {
PyObject *__pyx_v_error_message = ((PyObject*)Py_None);
PyObject *__pyx_v_log_message = NULL;
PyObject *__pyx_v_status_text = NULL;
@@ -3247,7 +3247,7 @@ static PyObject *__pyx_f_22ai_availability_status_20AIAvailabilityStatus_set_sta
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_get); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 46, __pyx_L4_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = __Pyx_PyLong_From_enum____pyx_t_22ai_availability_status_AIAvailabilityEnum(__pyx_v_self->status); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 46, __pyx_L4_error)
__pyx_t_4 = __Pyx_PyLong_From_int(__pyx_v_self->status); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 46, __pyx_L4_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_3 = 1;
#if CYTHON_UNPACK_METHODS
@@ -3468,7 +3468,7 @@ static PyObject *__pyx_pf_22ai_availability_status_20AIAvailabilityStatus_4__red
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("__reduce_cython__", 0);
__pyx_t_1 = __Pyx_PyLong_From_enum____pyx_t_22ai_availability_status_AIAvailabilityEnum(__pyx_v_self->status); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
__pyx_t_1 = __Pyx_PyLong_From_int(__pyx_v_self->status); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
@@ -3909,7 +3909,7 @@ static PyObject *__pyx_f_22ai_availability_status___pyx_unpickle_AIAvailabilityS
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
enum __pyx_t_22ai_availability_status_AIAvailabilityEnum __pyx_t_2;
int __pyx_t_2;
int __pyx_t_3;
Py_ssize_t __pyx_t_4;
int __pyx_t_5;
@@ -3948,7 +3948,7 @@ static PyObject *__pyx_f_22ai_availability_status___pyx_unpickle_AIAvailabilityS
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(1, 12, __pyx_L1_error)
}
__pyx_t_2 = ((enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)__Pyx_PyLong_As_enum____pyx_t_22ai_availability_status_AIAvailabilityEnum(__Pyx_PyTuple_GET_ITEM(__pyx_v___pyx_state, 2))); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
__pyx_t_2 = __Pyx_PyLong_As_int(__Pyx_PyTuple_GET_ITEM(__pyx_v___pyx_state, 2)); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error)
__pyx_v___pyx_result->status = __pyx_t_2;
if (unlikely(__pyx_v___pyx_state == Py_None)) {
@@ -4229,7 +4229,7 @@ static int __Pyx_modinit_type_init_code(__pyx_mstatetype *__pyx_mstate) {
/*--- Type init code ---*/
__pyx_vtabptr_22ai_availability_status_AIAvailabilityStatus = &__pyx_vtable_22ai_availability_status_AIAvailabilityStatus;
__pyx_vtable_22ai_availability_status_AIAvailabilityStatus.serialize = (PyObject *(*)(struct __pyx_obj_22ai_availability_status_AIAvailabilityStatus *))__pyx_f_22ai_availability_status_20AIAvailabilityStatus_serialize;
__pyx_vtable_22ai_availability_status_AIAvailabilityStatus.set_status = (PyObject *(*)(struct __pyx_obj_22ai_availability_status_AIAvailabilityStatus *, enum __pyx_t_22ai_availability_status_AIAvailabilityEnum, struct __pyx_opt_args_22ai_availability_status_20AIAvailabilityStatus_set_status *__pyx_optional_args))__pyx_f_22ai_availability_status_20AIAvailabilityStatus_set_status;
__pyx_vtable_22ai_availability_status_AIAvailabilityStatus.set_status = (PyObject *(*)(struct __pyx_obj_22ai_availability_status_AIAvailabilityStatus *, int, struct __pyx_opt_args_22ai_availability_status_20AIAvailabilityStatus_set_status *__pyx_optional_args))__pyx_f_22ai_availability_status_20AIAvailabilityStatus_set_status;
#if CYTHON_USE_TYPE_SPECS
__pyx_mstate->__pyx_ptype_22ai_availability_status_AIAvailabilityStatus = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_22ai_availability_status_AIAvailabilityStatus_spec, NULL); if (unlikely(!__pyx_mstate->__pyx_ptype_22ai_availability_status_AIAvailabilityStatus)) __PYX_ERR(0, 15, __pyx_L1_error)
if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_22ai_availability_status_AIAvailabilityStatus_spec, __pyx_mstate->__pyx_ptype_22ai_availability_status_AIAvailabilityStatus) < 0) __PYX_ERR(0, 15, __pyx_L1_error)
@@ -9419,6 +9419,331 @@ CYTHON_UNUSED static int __Pyx_VectorcallBuilder_AddArg_Check(PyObject *key, PyO
}
#endif
/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyLong_From_int(int value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
const int is_unsigned = neg_one > const_zero;
if (is_unsigned) {
if (sizeof(int) < sizeof(long)) {
return PyLong_FromLong((long) value);
} else if (sizeof(int) <= sizeof(unsigned long)) {
return PyLong_FromUnsignedLong((unsigned long) value);
#if defined(HAVE_LONG_LONG) && !CYTHON_COMPILING_IN_PYPY
} else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
}
} else {
if (sizeof(int) <= sizeof(long)) {
return PyLong_FromLong((long) value);
#ifdef HAVE_LONG_LONG
} else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
}
}
{
unsigned char *bytes = (unsigned char *)&value;
#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4
if (is_unsigned) {
return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1);
} else {
return PyLong_FromNativeBytes(bytes, sizeof(value), -1);
}
#elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000
int one = 1; int little = (int)*(unsigned char *)&one;
return _PyLong_FromByteArray(bytes, sizeof(int),
little, !is_unsigned);
#else
int one = 1; int little = (int)*(unsigned char *)&one;
PyObject *from_bytes, *result = NULL, *kwds = NULL;
PyObject *py_bytes = NULL, *order_str = NULL;
from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes");
if (!from_bytes) return NULL;
py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof(int));
if (!py_bytes) goto limited_bad;
order_str = PyUnicode_FromString(little ? "little" : "big");
if (!order_str) goto limited_bad;
{
PyObject *args[3+(CYTHON_VECTORCALL ? 1 : 0)] = { NULL, py_bytes, order_str };
if (!is_unsigned) {
kwds = __Pyx_MakeVectorcallBuilderKwds(1);
if (!kwds) goto limited_bad;
if (__Pyx_VectorcallBuilder_AddArgStr("signed", __Pyx_NewRef(Py_True), kwds, args+3, 0) < 0) goto limited_bad;
}
result = __Pyx_Object_Vectorcall_CallFromBuilder(from_bytes, args+1, 2 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET, kwds);
}
limited_bad:
Py_XDECREF(kwds);
Py_XDECREF(order_str);
Py_XDECREF(py_bytes);
Py_XDECREF(from_bytes);
return result;
#endif
}
}
/* CIntFromPy */
static CYTHON_INLINE int __Pyx_PyLong_As_int(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
const int is_unsigned = neg_one > const_zero;
if (unlikely(!PyLong_Check(x))) {
int val;
PyObject *tmp = __Pyx_PyNumber_Long(x);
if (!tmp) return (int) -1;
val = __Pyx_PyLong_As_int(tmp);
Py_DECREF(tmp);
return val;
}
if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
if (unlikely(__Pyx_PyLong_IsNeg(x))) {
goto raise_neg_overflow;
} else if (__Pyx_PyLong_IsCompact(x)) {
__PYX_VERIFY_RETURN_INT(int, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
} else {
const digit* digits = __Pyx_PyLong_Digits(x);
assert(__Pyx_PyLong_DigitCount(x) > 1);
switch (__Pyx_PyLong_DigitCount(x)) {
case 2:
if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(int) >= 2 * PyLong_SHIFT)) {
return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
}
}
break;
case 3:
if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(int) >= 3 * PyLong_SHIFT)) {
return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
}
}
break;
case 4:
if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(int) >= 4 * PyLong_SHIFT)) {
return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
}
}
break;
}
}
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
if (unlikely(Py_SIZE(x) < 0)) {
goto raise_neg_overflow;
}
#else
{
int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
if (unlikely(result < 0))
return (int) -1;
if (unlikely(result == 1))
goto raise_neg_overflow;
}
#endif
if ((sizeof(int) <= sizeof(unsigned long))) {
__PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
} else if ((sizeof(int) <= sizeof(unsigned PY_LONG_LONG))) {
__PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
}
} else {
#if CYTHON_USE_PYLONG_INTERNALS
if (__Pyx_PyLong_IsCompact(x)) {
__PYX_VERIFY_RETURN_INT(int, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
} else {
const digit* digits = __Pyx_PyLong_Digits(x);
assert(__Pyx_PyLong_DigitCount(x) > 1);
switch (__Pyx_PyLong_SignedDigitCount(x)) {
case -2:
if ((8 * sizeof(int) - 1 > 1 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
}
}
break;
case 2:
if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
}
}
break;
case -3:
if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
}
}
break;
case 3:
if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
}
}
break;
case -4:
if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
}
}
break;
case 4:
if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
}
}
break;
}
}
#endif
if ((sizeof(int) <= sizeof(long))) {
__PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
} else if ((sizeof(int) <= sizeof(PY_LONG_LONG))) {
__PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
}
}
{
int val;
int ret = -1;
#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
if (unlikely(bytes_copied == -1)) {
} else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
goto raise_overflow;
} else {
ret = 0;
}
#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
int one = 1; int is_little = (int)*(unsigned char *)&one;
unsigned char *bytes = (unsigned char *)&val;
ret = _PyLong_AsByteArray((PyLongObject *)x,
bytes, sizeof(val),
is_little, !is_unsigned);
#else
PyObject *v;
PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
int bits, remaining_bits, is_negative = 0;
int chunk_size = (sizeof(long) < 8) ? 30 : 62;
if (likely(PyLong_CheckExact(x))) {
v = __Pyx_NewRef(x);
} else {
v = PyNumber_Long(x);
if (unlikely(!v)) return (int) -1;
assert(PyLong_CheckExact(v));
}
{
int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
if (unlikely(result < 0)) {
Py_DECREF(v);
return (int) -1;
}
is_negative = result == 1;
}
if (is_unsigned && unlikely(is_negative)) {
Py_DECREF(v);
goto raise_neg_overflow;
} else if (is_negative) {
stepval = PyNumber_Invert(v);
Py_DECREF(v);
if (unlikely(!stepval))
return (int) -1;
} else {
stepval = v;
}
v = NULL;
val = (int) 0;
mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
for (bits = 0; bits < (int) sizeof(int) * 8 - chunk_size; bits += chunk_size) {
PyObject *tmp, *digit;
long idigit;
digit = PyNumber_And(stepval, mask);
if (unlikely(!digit)) goto done;
idigit = PyLong_AsLong(digit);
Py_DECREF(digit);
if (unlikely(idigit < 0)) goto done;
val |= ((int) idigit) << bits;
tmp = PyNumber_Rshift(stepval, shift);
if (unlikely(!tmp)) goto done;
Py_DECREF(stepval); stepval = tmp;
}
Py_DECREF(shift); shift = NULL;
Py_DECREF(mask); mask = NULL;
{
long idigit = PyLong_AsLong(stepval);
if (unlikely(idigit < 0)) goto done;
remaining_bits = ((int) sizeof(int) * 8) - bits - (is_unsigned ? 0 : 1);
if (unlikely(idigit >= (1L << remaining_bits)))
goto raise_overflow;
val |= ((int) idigit) << bits;
}
if (!is_unsigned) {
if (unlikely(val & (((int) 1) << (sizeof(int) * 8 - 1))))
goto raise_overflow;
if (is_negative)
val = ~val;
}
ret = 0;
done:
Py_XDECREF(shift);
Py_XDECREF(mask);
Py_XDECREF(stepval);
#endif
if (unlikely(ret))
return (int) -1;
return val;
}
raise_overflow:
PyErr_SetString(PyExc_OverflowError,
"value too large to convert to int");
return (int) -1;
raise_neg_overflow:
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to int");
return (int) -1;
}
/* CIntToPy */
static CYTHON_INLINE PyObject* __Pyx_PyLong_From_enum____pyx_t_22ai_availability_status_AIAvailabilityEnum(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum value) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
@@ -9490,195 +9815,6 @@ static CYTHON_INLINE PyObject* __Pyx_PyLong_From_enum____pyx_t_22ai_availability
}
}
/* CIntFromPy */
static CYTHON_INLINE enum __pyx_t_22ai_availability_status_AIAvailabilityEnum __Pyx_PyLong_As_enum____pyx_t_22ai_availability_status_AIAvailabilityEnum(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
const enum __pyx_t_22ai_availability_status_AIAvailabilityEnum neg_one = (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) -1, const_zero = (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
const int is_unsigned = neg_one > const_zero;
if (unlikely(!PyLong_Check(x))) {
enum __pyx_t_22ai_availability_status_AIAvailabilityEnum val;
PyObject *tmp = __Pyx_PyNumber_Long(x);
if (!tmp) return (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) -1;
val = __Pyx_PyLong_As_enum____pyx_t_22ai_availability_status_AIAvailabilityEnum(tmp);
Py_DECREF(tmp);
return val;
}
if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
if (unlikely(__Pyx_PyLong_IsNeg(x))) {
goto raise_neg_overflow;
} else if (__Pyx_PyLong_IsCompact(x)) {
__PYX_VERIFY_RETURN_INT(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
} else {
const digit* digits = __Pyx_PyLong_Digits(x);
assert(__Pyx_PyLong_DigitCount(x) > 1);
switch (__Pyx_PyLong_DigitCount(x)) {
case 2:
if ((8 * sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) > 1 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) >= 2 * PyLong_SHIFT)) {
return (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) (((((enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[0]));
}
}
break;
case 3:
if ((8 * sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) > 2 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) >= 3 * PyLong_SHIFT)) {
return (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) (((((((enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[0]));
}
}
break;
case 4:
if ((8 * sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) > 3 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) >= 4 * PyLong_SHIFT)) {
return (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) (((((((((enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[0]));
}
}
break;
}
}
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
if (unlikely(Py_SIZE(x) < 0)) {
goto raise_neg_overflow;
}
#else
{
int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
if (unlikely(result < 0))
return (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) -1;
if (unlikely(result == 1))
goto raise_neg_overflow;
}
#endif
if ((sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) <= sizeof(unsigned long))) {
__PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
} else if ((sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) <= sizeof(unsigned PY_LONG_LONG))) {
__PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
}
} else {
#if CYTHON_USE_PYLONG_INTERNALS
if (__Pyx_PyLong_IsCompact(x)) {
__PYX_VERIFY_RETURN_INT(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
} else {
const digit* digits = __Pyx_PyLong_Digits(x);
assert(__Pyx_PyLong_DigitCount(x) > 1);
switch (__Pyx_PyLong_SignedDigitCount(x)) {
case -2:
if ((8 * sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) - 1 > 1 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) - 1 > 2 * PyLong_SHIFT)) {
return (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) (((enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)-1)*(((((enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[0])));
}
}
break;
case 2:
if ((8 * sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) > 1 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) - 1 > 2 * PyLong_SHIFT)) {
return (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) ((((((enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[0])));
}
}
break;
case -3:
if ((8 * sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) - 1 > 2 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) - 1 > 3 * PyLong_SHIFT)) {
return (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) (((enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)-1)*(((((((enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[0])));
}
}
break;
case 3:
if ((8 * sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) > 2 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) - 1 > 3 * PyLong_SHIFT)) {
return (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) ((((((((enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[0])));
}
}
break;
case -4:
if ((8 * sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) - 1 > 3 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) - 1 > 4 * PyLong_SHIFT)) {
return (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) (((enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)-1)*(((((((((enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[0])));
}
}
break;
case 4:
if ((8 * sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) > 3 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) - 1 > 4 * PyLong_SHIFT)) {
return (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) ((((((((((enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[3]) << PyLong_SHIFT) | (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[2]) << PyLong_SHIFT) | (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[1]) << PyLong_SHIFT) | (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum)digits[0])));
}
}
break;
}
}
#endif
if ((sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) <= sizeof(long))) {
__PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
} else if ((sizeof(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) <= sizeof(PY_LONG_LONG))) {
__PYX_VERIFY_RETURN_INT_EXC(enum __pyx_t_22ai_availability_status_AIAvailabilityEnum, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
}
}
{
enum __pyx_t_22ai_availability_status_AIAvailabilityEnum val;
int ret = -1;
#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
if (unlikely(bytes_copied == -1)) {
} else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
goto raise_overflow;
} else {
ret = 0;
}
#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
int one = 1; int is_little = (int)*(unsigned char *)&one;
unsigned char *bytes = (unsigned char *)&val;
ret = _PyLong_AsByteArray((PyLongObject *)x,
bytes, sizeof(val),
is_little, !is_unsigned);
#else
PyErr_SetString(PyExc_RuntimeError,
"_PyLong_AsByteArray() or PyLong_AsNativeBytes() not available, cannot convert large enums");
val = (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) -1;
#endif
if (unlikely(ret))
return (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) -1;
return val;
}
raise_overflow:
PyErr_SetString(PyExc_OverflowError,
"value too large to convert to enum __pyx_t_22ai_availability_status_AIAvailabilityEnum");
return (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) -1;
raise_neg_overflow:
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to enum __pyx_t_22ai_availability_status_AIAvailabilityEnum");
return (enum __pyx_t_22ai_availability_status_AIAvailabilityEnum) -1;
}
/* CIntFromPy */
static CYTHON_INLINE long __Pyx_PyLong_As_long(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
@@ -10043,260 +10179,6 @@ __Pyx_PyType_GetFullyQualifiedName(PyTypeObject* tp)
}
#endif
/* CIntFromPy */
static CYTHON_INLINE int __Pyx_PyLong_As_int(PyObject *x) {
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif
const int neg_one = (int) -1, const_zero = (int) 0;
#ifdef __Pyx_HAS_GCC_DIAGNOSTIC
#pragma GCC diagnostic pop
#endif
const int is_unsigned = neg_one > const_zero;
if (unlikely(!PyLong_Check(x))) {
int val;
PyObject *tmp = __Pyx_PyNumber_Long(x);
if (!tmp) return (int) -1;
val = __Pyx_PyLong_As_int(tmp);
Py_DECREF(tmp);
return val;
}
if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
if (unlikely(__Pyx_PyLong_IsNeg(x))) {
goto raise_neg_overflow;
} else if (__Pyx_PyLong_IsCompact(x)) {
__PYX_VERIFY_RETURN_INT(int, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x))
} else {
const digit* digits = __Pyx_PyLong_Digits(x);
assert(__Pyx_PyLong_DigitCount(x) > 1);
switch (__Pyx_PyLong_DigitCount(x)) {
case 2:
if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(int) >= 2 * PyLong_SHIFT)) {
return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
}
}
break;
case 3:
if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(int) >= 3 * PyLong_SHIFT)) {
return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
}
}
break;
case 4:
if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(int) >= 4 * PyLong_SHIFT)) {
return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
}
}
break;
}
}
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7
if (unlikely(Py_SIZE(x) < 0)) {
goto raise_neg_overflow;
}
#else
{
int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
if (unlikely(result < 0))
return (int) -1;
if (unlikely(result == 1))
goto raise_neg_overflow;
}
#endif
if ((sizeof(int) <= sizeof(unsigned long))) {
__PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
} else if ((sizeof(int) <= sizeof(unsigned PY_LONG_LONG))) {
__PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
}
} else {
#if CYTHON_USE_PYLONG_INTERNALS
if (__Pyx_PyLong_IsCompact(x)) {
__PYX_VERIFY_RETURN_INT(int, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x))
} else {
const digit* digits = __Pyx_PyLong_Digits(x);
assert(__Pyx_PyLong_DigitCount(x) > 1);
switch (__Pyx_PyLong_SignedDigitCount(x)) {
case -2:
if ((8 * sizeof(int) - 1 > 1 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
}
}
break;
case 2:
if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
}
}
break;
case -3:
if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
}
}
break;
case 3:
if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
}
}
break;
case -4:
if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
}
}
break;
case 4:
if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) {
if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) {
__PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
} else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) {
return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
}
}
break;
}
}
#endif
if ((sizeof(int) <= sizeof(long))) {
__PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
} else if ((sizeof(int) <= sizeof(PY_LONG_LONG))) {
__PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
}
}
{
int val;
int ret = -1;
#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API
Py_ssize_t bytes_copied = PyLong_AsNativeBytes(
x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0));
if (unlikely(bytes_copied == -1)) {
} else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) {
goto raise_overflow;
} else {
ret = 0;
}
#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray)
int one = 1; int is_little = (int)*(unsigned char *)&one;
unsigned char *bytes = (unsigned char *)&val;
ret = _PyLong_AsByteArray((PyLongObject *)x,
bytes, sizeof(val),
is_little, !is_unsigned);
#else
PyObject *v;
PyObject *stepval = NULL, *mask = NULL, *shift = NULL;
int bits, remaining_bits, is_negative = 0;
int chunk_size = (sizeof(long) < 8) ? 30 : 62;
if (likely(PyLong_CheckExact(x))) {
v = __Pyx_NewRef(x);
} else {
v = PyNumber_Long(x);
if (unlikely(!v)) return (int) -1;
assert(PyLong_CheckExact(v));
}
{
int result = PyObject_RichCompareBool(v, Py_False, Py_LT);
if (unlikely(result < 0)) {
Py_DECREF(v);
return (int) -1;
}
is_negative = result == 1;
}
if (is_unsigned && unlikely(is_negative)) {
Py_DECREF(v);
goto raise_neg_overflow;
} else if (is_negative) {
stepval = PyNumber_Invert(v);
Py_DECREF(v);
if (unlikely(!stepval))
return (int) -1;
} else {
stepval = v;
}
v = NULL;
val = (int) 0;
mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done;
shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done;
for (bits = 0; bits < (int) sizeof(int) * 8 - chunk_size; bits += chunk_size) {
PyObject *tmp, *digit;
long idigit;
digit = PyNumber_And(stepval, mask);
if (unlikely(!digit)) goto done;
idigit = PyLong_AsLong(digit);
Py_DECREF(digit);
if (unlikely(idigit < 0)) goto done;
val |= ((int) idigit) << bits;
tmp = PyNumber_Rshift(stepval, shift);
if (unlikely(!tmp)) goto done;
Py_DECREF(stepval); stepval = tmp;
}
Py_DECREF(shift); shift = NULL;
Py_DECREF(mask); mask = NULL;
{
long idigit = PyLong_AsLong(stepval);
if (unlikely(idigit < 0)) goto done;
remaining_bits = ((int) sizeof(int) * 8) - bits - (is_unsigned ? 0 : 1);
if (unlikely(idigit >= (1L << remaining_bits)))
goto raise_overflow;
val |= ((int) idigit) << bits;
}
if (!is_unsigned) {
if (unlikely(val & (((int) 1) << (sizeof(int) * 8 - 1))))
goto raise_overflow;
if (is_negative)
val = ~val;
}
ret = 0;
done:
Py_XDECREF(shift);
Py_XDECREF(mask);
Py_XDECREF(stepval);
#endif
if (unlikely(ret))
return (int) -1;
return val;
}
raise_overflow:
PyErr_SetString(PyExc_OverflowError,
"value too large to convert to int");
return (int) -1;
raise_neg_overflow:
PyErr_SetString(PyExc_OverflowError,
"can't convert negative value to int");
return (int) -1;
}
/* FastTypeChecks */
#if CYTHON_COMPILING_IN_CPYTHON
static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) {
+2 -2
View File
@@ -8,9 +8,9 @@ cdef enum AIAvailabilityEnum:
ERROR = 500
cdef class AIAvailabilityStatus:
cdef AIAvailabilityEnum status
cdef int status
cdef str error_message
cdef object _lock
cdef bytes serialize(self)
cdef set_status(self, AIAvailabilityEnum status, str error_message=*)
cdef set_status(self, int status, str error_message=*)
+1 -1
View File
@@ -37,7 +37,7 @@ cdef class AIAvailabilityStatus:
finally:
self._lock.release()
cdef set_status(self, AIAvailabilityEnum status, str error_message=None):
cdef set_status(self, int status, str error_message=None):
log_message = ""
self._lock.acquire()
try:
+3
View File
@@ -20,3 +20,6 @@ cdef class AIRecognitionConfig:
@staticmethod
cdef from_msgpack(bytes data)
@staticmethod
cdef AIRecognitionConfig from_dict(dict data)
+1 -1
View File
@@ -75,7 +75,7 @@ cdef class AIRecognitionConfig:
)
@staticmethod
def from_dict(dict data):
cdef AIRecognitionConfig from_dict(dict data):
return AIRecognitionConfig(
data.get("frame_period_recognition", 4),
data.get("frame_recognition_seconds", 2),
+7 -17
View File
@@ -1561,7 +1561,7 @@ struct __pyx_obj_10annotation___pyx_scope_struct__genexpr {
struct __pyx_vtabstruct_10annotation_Detection {
PyObject *(*overlaps)(struct __pyx_obj_10annotation_Detection *, struct __pyx_obj_10annotation_Detection *, float);
int (*overlaps)(struct __pyx_obj_10annotation_Detection *, struct __pyx_obj_10annotation_Detection *, float);
};
static struct __pyx_vtabstruct_10annotation_Detection *__pyx_vtabptr_10annotation_Detection;
@@ -2585,7 +2585,7 @@ static int __Pyx_State_RemoveModule(void*);
#define __PYX_ABI_MODULE_NAME "_cython_" CYTHON_ABI
#define __PYX_TYPE_MODULE_PREFIX __PYX_ABI_MODULE_NAME "."
PyObject *__pyx_f_10annotation_9Detection_overlaps(struct __pyx_obj_10annotation_Detection *__pyx_v_self, struct __pyx_obj_10annotation_Detection *__pyx_v_det2, float __pyx_v_confidence_threshold); /* proto*/
static int __pyx_f_10annotation_9Detection_overlaps(struct __pyx_obj_10annotation_Detection *__pyx_v_self, struct __pyx_obj_10annotation_Detection *__pyx_v_det2, float __pyx_v_confidence_threshold); /* proto*/
static PyObject *__pyx_f_10annotation_10Annotation_serialize(struct __pyx_obj_10annotation_Annotation *__pyx_v_self); /* proto*/
/* Module declarations from "constants_inf" */
@@ -3471,23 +3471,20 @@ static PyObject *__pyx_pf_10annotation_9Detection_4__eq__(struct __pyx_obj_10ann
}
PyObject *__pyx_f_10annotation_9Detection_overlaps(struct __pyx_obj_10annotation_Detection *__pyx_v_self, struct __pyx_obj_10annotation_Detection *__pyx_v_det2, float __pyx_v_confidence_threshold) {
static int __pyx_f_10annotation_9Detection_overlaps(struct __pyx_obj_10annotation_Detection *__pyx_v_self, struct __pyx_obj_10annotation_Detection *__pyx_v_det2, float __pyx_v_confidence_threshold) {
double __pyx_v_overlap_x;
double __pyx_v_overlap_y;
double __pyx_v_overlap_area;
double __pyx_v_min_area;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
int __pyx_r;
double __pyx_t_1;
double __pyx_t_2;
double __pyx_t_3;
int __pyx_t_4;
double __pyx_t_5;
PyObject *__pyx_t_6 = NULL;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
__Pyx_RefNannySetupContext("overlaps", 0);
__pyx_t_1 = fabs((__pyx_v_self->x - __pyx_v_det2->x));
__pyx_v_overlap_x = ((0.5 * (__pyx_v_self->w + __pyx_v_det2->w)) - __pyx_t_1);
@@ -3511,7 +3508,7 @@ PyObject *__pyx_f_10annotation_9Detection_overlaps(struct __pyx_obj_10annotation
} else {
__pyx_t_5 = __pyx_t_2;
}
__pyx_v_overlap_area = (__pyx_t_3 * __pyx_t_5);
__pyx_v_overlap_area = ((double)(__pyx_t_3 * __pyx_t_5));
__pyx_t_5 = (__pyx_v_det2->w * __pyx_v_det2->h);
__pyx_t_3 = (__pyx_v_self->w * __pyx_v_self->h);
@@ -3523,26 +3520,19 @@ PyObject *__pyx_f_10annotation_9Detection_overlaps(struct __pyx_obj_10annotation
}
__pyx_v_min_area = __pyx_t_1;
__Pyx_XDECREF(__pyx_r);
if (unlikely(__pyx_v_min_area == 0)) {
PyErr_SetString(PyExc_ZeroDivisionError, "float division");
__PYX_ERR(0, 34, __pyx_L1_error)
}
__pyx_t_6 = __Pyx_PyBool_FromLong(((__pyx_v_overlap_area / __pyx_v_min_area) > __pyx_v_confidence_threshold)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 34, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_r = __pyx_t_6;
__pyx_t_6 = 0;
__pyx_r = ((__pyx_v_overlap_area / __pyx_v_min_area) > __pyx_v_confidence_threshold);
goto __pyx_L0;
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_6);
__Pyx_AddTraceback("annotation.Detection.overlaps", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
@@ -7169,7 +7159,7 @@ static int __Pyx_modinit_type_init_code(__pyx_mstatetype *__pyx_mstate) {
__Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0);
/*--- Type init code ---*/
__pyx_vtabptr_10annotation_Detection = &__pyx_vtable_10annotation_Detection;
__pyx_vtable_10annotation_Detection.overlaps = (PyObject *(*)(struct __pyx_obj_10annotation_Detection *, struct __pyx_obj_10annotation_Detection *, float))__pyx_f_10annotation_9Detection_overlaps;
__pyx_vtable_10annotation_Detection.overlaps = (int (*)(struct __pyx_obj_10annotation_Detection *, struct __pyx_obj_10annotation_Detection *, float))__pyx_f_10annotation_9Detection_overlaps;
#if CYTHON_USE_TYPE_SPECS
__pyx_mstate->__pyx_ptype_10annotation_Detection = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_10annotation_Detection_spec, NULL); if (unlikely(!__pyx_mstate->__pyx_ptype_10annotation_Detection)) __PYX_ERR(0, 4, __pyx_L1_error)
if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_10annotation_Detection_spec, __pyx_mstate->__pyx_ptype_10annotation_Detection) < 0) __PYX_ERR(0, 4, __pyx_L1_error)
+3 -1
View File
@@ -3,7 +3,8 @@ cdef class Detection:
cdef public str annotation_name
cdef public int cls
cdef public overlaps(self, Detection det2, float confidence_threshold)
def __init__(self, double x, double y, double w, double h, int cls, double confidence): ...
cdef bint overlaps(self, Detection det2, float confidence_threshold)
cdef class Annotation:
cdef public str name
@@ -12,4 +13,5 @@ cdef class Annotation:
cdef public list[Detection] detections
cdef public bytes image
def __init__(self, str name, str original_media_name, long ms, list[Detection] detections): ...
cdef bytes serialize(self)
+3 -3
View File
@@ -25,13 +25,13 @@ cdef class Detection:
return False
return True
cdef overlaps(self, Detection det2, float confidence_threshold):
cdef bint overlaps(self, Detection det2, float confidence_threshold):
cdef double overlap_x = 0.5 * (self.w + det2.w) - abs(self.x - det2.x)
cdef double overlap_y = 0.5 * (self.h + det2.h) - abs(self.y - det2.y)
cdef double overlap_area = max(0.0, overlap_x) * max(0.0, overlap_y)
cdef double overlap_area = <double>(max(0.0, overlap_x) * max(0.0, overlap_y))
cdef double min_area = min(self.w * self.h, det2.w * det2.h)
return overlap_area / min_area > confidence_threshold
return <bint>(overlap_area / min_area > confidence_threshold)
cdef class Annotation:
def __init__(self, str name, str original_media_name, long ms, list[Detection] detections):
+22
View File
@@ -0,0 +1,22 @@
name: detections-mocks
services:
mock-loader:
build: ./mocks/loader
ports:
- "18080:8080"
volumes:
- ./fixtures:/models
networks:
- mocks-net
mock-annotations:
build: ./mocks/annotations
ports:
- "18081:8081"
networks:
- mocks-net
networks:
mocks-net:
driver: bridge
+1 -1
View File
@@ -69,7 +69,7 @@ services:
- ./results:/results
networks:
- e2e-net
command: ["pytest", "--csv=/results/report.csv", "-v", "-x"]
command: ["pytest", "--csv=/results/report.csv", "-v"]
networks:
e2e-net:
+5 -1
View File
@@ -68,7 +68,11 @@ source "$VENV_DIR/bin/activate"
echo "--- Installing dependencies..."
pip install -q --upgrade pip setuptools wheel
pip install -q -r "$PROJECT_DIR/requirements.txt"
if [[ "$(uname -s)" == "Darwin" && -f "$PROJECT_DIR/requirements-macos.txt" ]]; then
pip install -q -r "$PROJECT_DIR/requirements-macos.txt"
else
pip install -q -r "$PROJECT_DIR/requirements.txt"
fi
pip install -q -r "$SCRIPT_DIR/requirements.txt" 2>/dev/null || true
pip install -q flask gunicorn
+1 -1
View File
@@ -98,7 +98,7 @@ def test_ft_n04_duplicate_media_id_409(
warm_engine, http_client, jwt_token
):
media_id = "dup-test"
body = _ai_config_video()
body = _ai_config_image()
headers = {"Authorization": f"Bearer {jwt_token}"}
r1 = http_client.post(f"/detect/{media_id}", json=body, headers=headers)
assert r1.status_code == 200
+23 -3
View File
@@ -1,3 +1,7 @@
import platform
import sys
def _check_tensor_gpu_index():
try:
import pynvml
@@ -21,12 +25,28 @@ def _check_tensor_gpu_index():
pass
def _is_apple_silicon():
if sys.platform != "darwin" or platform.machine() != "arm64":
return False
try:
import coremltools
return True
except ImportError:
return False
tensor_gpu_index = _check_tensor_gpu_index()
def create_engine(model_bytes: bytes, batch_size: int = 1):
def _select_engine_class():
if tensor_gpu_index > -1:
from engines.tensorrt_engine import TensorRTEngine
return TensorRTEngine(model_bytes, batch_size)
return TensorRTEngine
if _is_apple_silicon():
from engines.coreml_engine import CoreMLEngine
return CoreMLEngine
from engines.onnx_engine import OnnxEngine
return OnnxEngine(model_bytes, batch_size)
return OnnxEngine
EngineClass = _select_engine_class()
+2812 -630
View File
File diff suppressed because it is too large Load Diff
+56 -3
View File
@@ -1,6 +1,10 @@
from engines.inference_engine cimport InferenceEngine
cimport constants_inf
import numpy as np
import io
import os
import tempfile
import zipfile
cdef class CoreMLEngine(InferenceEngine):
@@ -11,9 +15,7 @@ cdef class CoreMLEngine(InferenceEngine):
model_path = kwargs.get('model_path')
if model_path is None:
raise ValueError(
"CoreMLEngine requires model_path kwarg "
"pointing to a .mlpackage or .mlmodel")
model_path = self._extract_from_zip(model_bytes)
self.model = ct.models.MLModel(
model_path, compute_units=ct.ComputeUnit.ALL)
@@ -32,6 +34,57 @@ cdef class CoreMLEngine(InferenceEngine):
constants_inf.log(<str>f'CoreML model: input={self.input_name} shape={self.input_shape}')
constants_inf.log(<str>f'CoreML outputs: {self._output_names}')
@property
def engine_name(self):
return "coreml"
@staticmethod
def get_engine_filename():
return "azaion_coreml.zip"
@staticmethod
def convert_from_onnx(bytes onnx_bytes):
import coremltools as ct
with tempfile.NamedTemporaryFile(suffix='.onnx', delete=False) as f:
f.write(onnx_bytes)
onnx_path = f.name
try:
constants_inf.log(<str>'Converting ONNX to CoreML...')
model = ct.convert(
onnx_path,
compute_units=ct.ComputeUnit.ALL,
minimum_deployment_target=ct.target.macOS13,
)
with tempfile.TemporaryDirectory() as tmpdir:
pkg_path = os.path.join(tmpdir, "azaion.mlpackage")
model.save(pkg_path)
buf = io.BytesIO()
with zipfile.ZipFile(buf, 'w', zipfile.ZIP_DEFLATED) as zf:
for root, dirs, files in os.walk(pkg_path):
for fname in files:
file_path = os.path.join(root, fname)
arcname = os.path.relpath(file_path, tmpdir)
zf.write(file_path, arcname)
constants_inf.log(<str>'CoreML conversion done!')
return buf.getvalue()
finally:
os.unlink(onnx_path)
@staticmethod
def _extract_from_zip(model_bytes):
tmpdir = tempfile.mkdtemp()
buf = io.BytesIO(model_bytes)
with zipfile.ZipFile(buf, 'r') as zf:
zf.extractall(tmpdir)
for item in os.listdir(tmpdir):
if item.endswith('.mlpackage') or item.endswith('.mlmodel'):
return os.path.join(tmpdir, item)
raise ValueError("No .mlpackage or .mlmodel found in zip")
cdef tuple get_input_shape(self):
return self.input_shape[2], self.input_shape[3]
+436 -103
View File
@@ -4,7 +4,7 @@
{
"distutils": {
"include_dirs": [
"/Users/obezdienie001/dev/azaion/suite/detections/.venv-e2e/lib/python3.13/site-packages/numpy/_core/include"
"/Users/obezdienie001/dev/azaion/suite/detections/.venv/lib/python3.13/site-packages/numpy/_core/include"
],
"name": "engines.inference_engine",
"sources": [
@@ -1838,12 +1838,12 @@ static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact,
__Pyx__ArgTypeTest(obj, type, name, exact))
static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact);
/* RaiseException.proto */
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);
/* RejectKeywords.proto */
static void __Pyx_RejectKeywords(const char* function_name, PyObject *kwds);
/* RaiseException.proto */
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);
/* GetAttr3.proto */
static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *);
@@ -2095,6 +2095,10 @@ static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml,
PyObject *module, PyObject *globals,
PyObject* code);
/* GetNameInClass.proto */
#define __Pyx_GetNameInClass(var, nmspace, name) (var) = __Pyx__GetNameInClass(nmspace, name)
static PyObject *__Pyx__GetNameInClass(PyObject *nmspace, PyObject *name);
/* CLineInTraceback.proto */
#if CYTHON_CLINE_IN_TRACEBACK && CYTHON_CLINE_IN_TRACEBACK_RUNTIME
static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line);
@@ -2271,11 +2275,13 @@ int __pyx_module_is_main_engines__inference_engine = 0;
/* Implementation of "engines.inference_engine" */
/* #### Code section: global_var ### */
static PyObject *__pyx_builtin_staticmethod;
static PyObject *__pyx_builtin_NotImplementedError;
/* #### Code section: string_decls ### */
static const char __pyx_k_[] = ".";
static const char __pyx_k__2[] = "?";
static const char __pyx_k_gc[] = "gc";
static const char __pyx_k_A_q[] = "\200A\340\010\017\210q";
static const char __pyx_k_QfA[] = "\200\001\330\004-\250Q\250f\260A";
static const char __pyx_k_new[] = "__new__";
static const char __pyx_k_pop[] = "pop";
@@ -2283,6 +2289,7 @@ static const char __pyx_k_dict[] = "__dict__";
static const char __pyx_k_func[] = "__func__";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_name[] = "__name__";
static const char __pyx_k_onnx[] = "onnx";
static const char __pyx_k_self[] = "self";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_state[] = "state";
@@ -2303,37 +2310,47 @@ static const char __pyx_k_isenabled[] = "isenabled";
static const char __pyx_k_pyx_state[] = "__pyx_state";
static const char __pyx_k_reduce_ex[] = "__reduce_ex__";
static const char __pyx_k_batch_size[] = "batch_size";
static const char __pyx_k_onnx_bytes[] = "onnx_bytes";
static const char __pyx_k_pyx_result[] = "__pyx_result";
static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
static const char __pyx_k_PickleError[] = "PickleError";
static const char __pyx_k_model_bytes[] = "model_bytes";
static const char __pyx_k_is_coroutine[] = "_is_coroutine";
static const char __pyx_k_pyx_checksum[] = "__pyx_checksum";
static const char __pyx_k_staticmethod[] = "staticmethod";
static const char __pyx_k_stringsource[] = "<stringsource>";
static const char __pyx_k_use_setstate[] = "use_setstate";
static const char __pyx_k_reduce_cython[] = "__reduce_cython__";
static const char __pyx_k_InferenceEngine[] = "InferenceEngine";
static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError";
static const char __pyx_k_setstate_cython[] = "__setstate_cython__";
static const char __pyx_k_convert_from_onnx[] = "convert_from_onnx";
static const char __pyx_k_asyncio_coroutines[] = "asyncio.coroutines";
static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
static const char __pyx_k_NotImplementedError[] = "NotImplementedError";
static const char __pyx_k_get_engine_filename[] = "get_engine_filename";
static const char __pyx_k_engines_inference_engine[] = "engines.inference_engine";
static const char __pyx_k_hk_A_1_uuwwx_1_7_1_2DNRS_1[] = "\200\001\360\006\000\005\010\200\177\220h\230k\250\033\260A\330\010\r\210^\2301\330\010\016\320\016!\320!u\320uw\320wx\330\004\023\220?\240(\250!\2501\330\004\007\200|\2207\230!\330\0101\260\021\3202D\300N\320RS\330\004\013\2101";
static const char __pyx_k_Subclass_must_implement_run[] = "Subclass must implement run";
static const char __pyx_k_engines_inference_engine_pyx[] = "engines/inference_engine.pyx";
static const char __pyx_k_pyx_unpickle_InferenceEngine[] = "__pyx_unpickle_InferenceEngine";
static const char __pyx_k_InferenceEngine___reduce_cython[] = "InferenceEngine.__reduce_cython__";
static const char __pyx_k_T_G1F_a_vWA_q_q_q_0_AWKwa_0_AWK[] = "\200\001\360\010\000\005\016\210T\220\021\330\004\014\210G\2201\220F\230,\240a\330\004\007\200v\210W\220A\330\010\022\220!\330\010\027\220q\340\010\027\220q\330\004\007\200q\330\010\017\320\0170\260\004\260A\260W\270K\300w\310a\340\010\017\320\0170\260\004\260A\260W\270K\300q";
static const char __pyx_k_Incompatible_checksums_0x_x_vs_0[] = "Incompatible checksums (0x%x vs (0x37a72fb, 0x763015b, 0xe11ccd4) = (batch_size))";
static const char __pyx_k_InferenceEngine___setstate_cytho[] = "InferenceEngine.__setstate_cython__";
static const char __pyx_k_InferenceEngine_convert_from_onn[] = "InferenceEngine.convert_from_onnx";
static const char __pyx_k_InferenceEngine_get_engine_filen[] = "InferenceEngine.get_engine_filename";
static const char __pyx_k_Note_that_Cython_is_deliberately[] = "Note that Cython is deliberately stricter than PEP-484 and rejects subclasses of builtin types. If you need to pass subclasses then set the 'annotation_typing' directive to False.";
static const char __pyx_k_Subclass_must_implement_get_inpu[] = "Subclass must implement get_input_shape";
/* #### Code section: decls ### */
static int __pyx_pf_7engines_16inference_engine_15InferenceEngine___init__(struct __pyx_obj_7engines_16inference_engine_InferenceEngine *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_model_bytes, PyObject *__pyx_v_batch_size, CYTHON_UNUSED PyObject *__pyx_v_kwargs); /* proto */
static PyObject *__pyx_pf_7engines_16inference_engine_15InferenceEngine_11engine_name___get__(CYTHON_UNUSED struct __pyx_obj_7engines_16inference_engine_InferenceEngine *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7engines_16inference_engine_15InferenceEngine_2get_engine_filename(void); /* proto */
static PyObject *__pyx_pf_7engines_16inference_engine_15InferenceEngine_4convert_from_onnx(PyObject *__pyx_v_onnx_bytes); /* proto */
static PyObject *__pyx_pf_7engines_16inference_engine_15InferenceEngine_10batch_size___get__(struct __pyx_obj_7engines_16inference_engine_InferenceEngine *__pyx_v_self); /* proto */
static int __pyx_pf_7engines_16inference_engine_15InferenceEngine_10batch_size_2__set__(struct __pyx_obj_7engines_16inference_engine_InferenceEngine *__pyx_v_self, PyObject *__pyx_v_value); /* proto */
static PyObject *__pyx_pf_7engines_16inference_engine_15InferenceEngine_2__reduce_cython__(struct __pyx_obj_7engines_16inference_engine_InferenceEngine *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7engines_16inference_engine_15InferenceEngine_4__setstate_cython__(struct __pyx_obj_7engines_16inference_engine_InferenceEngine *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */
static PyObject *__pyx_pf_7engines_16inference_engine_15InferenceEngine_6__reduce_cython__(struct __pyx_obj_7engines_16inference_engine_InferenceEngine *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_7engines_16inference_engine_15InferenceEngine_8__setstate_cython__(struct __pyx_obj_7engines_16inference_engine_InferenceEngine *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */
static PyObject *__pyx_pf_7engines_16inference_engine___pyx_unpickle_InferenceEngine(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */
static PyObject *__pyx_tp_new_7engines_16inference_engine_InferenceEngine(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
/* #### Code section: late_includes ### */
@@ -2378,8 +2395,8 @@ typedef struct {
PyTypeObject *__pyx_ptype_7engines_16inference_engine_InferenceEngine;
__Pyx_CachedCFunction __pyx_umethod_PyDict_Type_pop;
PyObject *__pyx_tuple[1];
PyObject *__pyx_codeobj_tab[3];
PyObject *__pyx_string_tab[52];
PyObject *__pyx_codeobj_tab[5];
PyObject *__pyx_string_tab[60];
PyObject *__pyx_int_1;
PyObject *__pyx_int_58356475;
PyObject *__pyx_int_123928923;
@@ -2426,53 +2443,61 @@ static __pyx_mstatetype * const __pyx_mstate_global = &__pyx_mstate_global_stati
#define __pyx_n_u_InferenceEngine __pyx_string_tab[2]
#define __pyx_n_u_InferenceEngine___reduce_cython __pyx_string_tab[3]
#define __pyx_n_u_InferenceEngine___setstate_cytho __pyx_string_tab[4]
#define __pyx_n_u_NotImplementedError __pyx_string_tab[5]
#define __pyx_kp_u_Note_that_Cython_is_deliberately __pyx_string_tab[6]
#define __pyx_n_u_PickleError __pyx_string_tab[7]
#define __pyx_kp_u_Subclass_must_implement_get_inpu __pyx_string_tab[8]
#define __pyx_kp_u_Subclass_must_implement_run __pyx_string_tab[9]
#define __pyx_kp_u__2 __pyx_string_tab[10]
#define __pyx_kp_u_add_note __pyx_string_tab[11]
#define __pyx_n_u_asyncio_coroutines __pyx_string_tab[12]
#define __pyx_n_u_batch_size __pyx_string_tab[13]
#define __pyx_n_u_cline_in_traceback __pyx_string_tab[14]
#define __pyx_n_u_dict __pyx_string_tab[15]
#define __pyx_n_u_dict_2 __pyx_string_tab[16]
#define __pyx_kp_u_disable __pyx_string_tab[17]
#define __pyx_kp_u_enable __pyx_string_tab[18]
#define __pyx_n_u_engines_inference_engine __pyx_string_tab[19]
#define __pyx_n_u_func __pyx_string_tab[20]
#define __pyx_kp_u_gc __pyx_string_tab[21]
#define __pyx_n_u_getstate __pyx_string_tab[22]
#define __pyx_n_u_is_coroutine __pyx_string_tab[23]
#define __pyx_kp_u_isenabled __pyx_string_tab[24]
#define __pyx_n_u_main __pyx_string_tab[25]
#define __pyx_n_u_model_bytes __pyx_string_tab[26]
#define __pyx_n_u_module __pyx_string_tab[27]
#define __pyx_n_u_name __pyx_string_tab[28]
#define __pyx_n_u_new __pyx_string_tab[29]
#define __pyx_n_u_pickle __pyx_string_tab[30]
#define __pyx_n_u_pop __pyx_string_tab[31]
#define __pyx_n_u_pyx_PickleError __pyx_string_tab[32]
#define __pyx_n_u_pyx_checksum __pyx_string_tab[33]
#define __pyx_n_u_pyx_result __pyx_string_tab[34]
#define __pyx_n_u_pyx_state __pyx_string_tab[35]
#define __pyx_n_u_pyx_type __pyx_string_tab[36]
#define __pyx_n_u_pyx_unpickle_InferenceEngine __pyx_string_tab[37]
#define __pyx_n_u_pyx_vtable __pyx_string_tab[38]
#define __pyx_n_u_qualname __pyx_string_tab[39]
#define __pyx_n_u_reduce __pyx_string_tab[40]
#define __pyx_n_u_reduce_cython __pyx_string_tab[41]
#define __pyx_n_u_reduce_ex __pyx_string_tab[42]
#define __pyx_n_u_self __pyx_string_tab[43]
#define __pyx_n_u_set_name __pyx_string_tab[44]
#define __pyx_n_u_setstate __pyx_string_tab[45]
#define __pyx_n_u_setstate_cython __pyx_string_tab[46]
#define __pyx_n_u_state __pyx_string_tab[47]
#define __pyx_kp_u_stringsource __pyx_string_tab[48]
#define __pyx_n_u_test __pyx_string_tab[49]
#define __pyx_n_u_update __pyx_string_tab[50]
#define __pyx_n_u_use_setstate __pyx_string_tab[51]
#define __pyx_n_u_InferenceEngine_convert_from_onn __pyx_string_tab[5]
#define __pyx_n_u_InferenceEngine_get_engine_filen __pyx_string_tab[6]
#define __pyx_n_u_NotImplementedError __pyx_string_tab[7]
#define __pyx_kp_u_Note_that_Cython_is_deliberately __pyx_string_tab[8]
#define __pyx_n_u_PickleError __pyx_string_tab[9]
#define __pyx_kp_u_Subclass_must_implement_get_inpu __pyx_string_tab[10]
#define __pyx_kp_u_Subclass_must_implement_run __pyx_string_tab[11]
#define __pyx_kp_u__2 __pyx_string_tab[12]
#define __pyx_kp_u_add_note __pyx_string_tab[13]
#define __pyx_n_u_asyncio_coroutines __pyx_string_tab[14]
#define __pyx_n_u_batch_size __pyx_string_tab[15]
#define __pyx_n_u_cline_in_traceback __pyx_string_tab[16]
#define __pyx_n_u_convert_from_onnx __pyx_string_tab[17]
#define __pyx_n_u_dict __pyx_string_tab[18]
#define __pyx_n_u_dict_2 __pyx_string_tab[19]
#define __pyx_kp_u_disable __pyx_string_tab[20]
#define __pyx_kp_u_enable __pyx_string_tab[21]
#define __pyx_n_u_engines_inference_engine __pyx_string_tab[22]
#define __pyx_kp_u_engines_inference_engine_pyx __pyx_string_tab[23]
#define __pyx_n_u_func __pyx_string_tab[24]
#define __pyx_kp_u_gc __pyx_string_tab[25]
#define __pyx_n_u_get_engine_filename __pyx_string_tab[26]
#define __pyx_n_u_getstate __pyx_string_tab[27]
#define __pyx_n_u_is_coroutine __pyx_string_tab[28]
#define __pyx_kp_u_isenabled __pyx_string_tab[29]
#define __pyx_n_u_main __pyx_string_tab[30]
#define __pyx_n_u_model_bytes __pyx_string_tab[31]
#define __pyx_n_u_module __pyx_string_tab[32]
#define __pyx_n_u_name __pyx_string_tab[33]
#define __pyx_n_u_new __pyx_string_tab[34]
#define __pyx_n_u_onnx __pyx_string_tab[35]
#define __pyx_n_u_onnx_bytes __pyx_string_tab[36]
#define __pyx_n_u_pickle __pyx_string_tab[37]
#define __pyx_n_u_pop __pyx_string_tab[38]
#define __pyx_n_u_pyx_PickleError __pyx_string_tab[39]
#define __pyx_n_u_pyx_checksum __pyx_string_tab[40]
#define __pyx_n_u_pyx_result __pyx_string_tab[41]
#define __pyx_n_u_pyx_state __pyx_string_tab[42]
#define __pyx_n_u_pyx_type __pyx_string_tab[43]
#define __pyx_n_u_pyx_unpickle_InferenceEngine __pyx_string_tab[44]
#define __pyx_n_u_pyx_vtable __pyx_string_tab[45]
#define __pyx_n_u_qualname __pyx_string_tab[46]
#define __pyx_n_u_reduce __pyx_string_tab[47]
#define __pyx_n_u_reduce_cython __pyx_string_tab[48]
#define __pyx_n_u_reduce_ex __pyx_string_tab[49]
#define __pyx_n_u_self __pyx_string_tab[50]
#define __pyx_n_u_set_name __pyx_string_tab[51]
#define __pyx_n_u_setstate __pyx_string_tab[52]
#define __pyx_n_u_setstate_cython __pyx_string_tab[53]
#define __pyx_n_u_state __pyx_string_tab[54]
#define __pyx_n_u_staticmethod __pyx_string_tab[55]
#define __pyx_kp_u_stringsource __pyx_string_tab[56]
#define __pyx_n_u_test __pyx_string_tab[57]
#define __pyx_n_u_update __pyx_string_tab[58]
#define __pyx_n_u_use_setstate __pyx_string_tab[59]
/* #### Code section: module_state_clear ### */
#if CYTHON_USE_MODULE_STATE
static CYTHON_SMALL_CODE int __pyx_m_clear(PyObject *m) {
@@ -2496,8 +2521,8 @@ static CYTHON_SMALL_CODE int __pyx_m_clear(PyObject *m) {
Py_CLEAR(clear_module_state->__pyx_ptype_7engines_16inference_engine_InferenceEngine);
Py_CLEAR(clear_module_state->__pyx_type_7engines_16inference_engine_InferenceEngine);
for (int i=0; i<1; ++i) { Py_CLEAR(clear_module_state->__pyx_tuple[i]); }
for (int i=0; i<3; ++i) { Py_CLEAR(clear_module_state->__pyx_codeobj_tab[i]); }
for (int i=0; i<52; ++i) { Py_CLEAR(clear_module_state->__pyx_string_tab[i]); }
for (int i=0; i<5; ++i) { Py_CLEAR(clear_module_state->__pyx_codeobj_tab[i]); }
for (int i=0; i<60; ++i) { Py_CLEAR(clear_module_state->__pyx_string_tab[i]); }
Py_CLEAR(clear_module_state->__pyx_int_1);
Py_CLEAR(clear_module_state->__pyx_int_58356475);
Py_CLEAR(clear_module_state->__pyx_int_123928923);
@@ -2525,8 +2550,8 @@ static CYTHON_SMALL_CODE int __pyx_m_traverse(PyObject *m, visitproc visit, void
Py_VISIT(traverse_module_state->__pyx_ptype_7engines_16inference_engine_InferenceEngine);
Py_VISIT(traverse_module_state->__pyx_type_7engines_16inference_engine_InferenceEngine);
for (int i=0; i<1; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_tuple[i]); }
for (int i=0; i<3; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_codeobj_tab[i]); }
for (int i=0; i<52; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_string_tab[i]); }
for (int i=0; i<5; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_codeobj_tab[i]); }
for (int i=0; i<60; ++i) { __Pyx_VISIT_CONST(traverse_module_state->__pyx_string_tab[i]); }
__Pyx_VISIT_CONST(traverse_module_state->__pyx_int_1);
__Pyx_VISIT_CONST(traverse_module_state->__pyx_int_58356475);
__Pyx_VISIT_CONST(traverse_module_state->__pyx_int_123928923);
@@ -2656,6 +2681,214 @@ static int __pyx_pf_7engines_16inference_engine_15InferenceEngine___init__(struc
}
/* Python wrapper */
static PyObject *__pyx_pw_7engines_16inference_engine_15InferenceEngine_11engine_name_1__get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_7engines_16inference_engine_15InferenceEngine_11engine_name_1__get__(PyObject *__pyx_v_self) {
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__get__ (wrapper)", 0);
__pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
__pyx_r = __pyx_pf_7engines_16inference_engine_15InferenceEngine_11engine_name___get__(((struct __pyx_obj_7engines_16inference_engine_InferenceEngine *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7engines_16inference_engine_15InferenceEngine_11engine_name___get__(CYTHON_UNUSED struct __pyx_obj_7engines_16inference_engine_InferenceEngine *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__get__", 0);
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_onnx);
__pyx_r = __pyx_mstate_global->__pyx_n_u_onnx;
goto __pyx_L0;
/* function exit code */
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* Python wrapper */
static PyObject *__pyx_pw_7engines_16inference_engine_15InferenceEngine_3get_engine_filename(CYTHON_UNUSED PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyMethodDef __pyx_mdef_7engines_16inference_engine_15InferenceEngine_3get_engine_filename = {"get_engine_filename", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7engines_16inference_engine_15InferenceEngine_3get_engine_filename, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_7engines_16inference_engine_15InferenceEngine_3get_engine_filename(CYTHON_UNUSED PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
#if !CYTHON_METH_FASTCALL
CYTHON_UNUSED Py_ssize_t __pyx_nargs;
#endif
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("get_engine_filename (wrapper)", 0);
#if !CYTHON_METH_FASTCALL
#if CYTHON_ASSUME_SAFE_SIZE
__pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
#else
__pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
#endif
#endif
__pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
if (unlikely(__pyx_nargs > 0)) { __Pyx_RaiseArgtupleInvalid("get_engine_filename", 1, 0, 0, __pyx_nargs); return NULL; }
const Py_ssize_t __pyx_kwds_len = unlikely(__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
if (unlikely(__pyx_kwds_len < 0)) return NULL;
if (unlikely(__pyx_kwds_len > 0)) {__Pyx_RejectKeywords("get_engine_filename", __pyx_kwds); return NULL;}
__pyx_r = __pyx_pf_7engines_16inference_engine_15InferenceEngine_2get_engine_filename();
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7engines_16inference_engine_15InferenceEngine_2get_engine_filename(void) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("get_engine_filename", 0);
__Pyx_XDECREF(__pyx_r);
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
/* function exit code */
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* Python wrapper */
static PyObject *__pyx_pw_7engines_16inference_engine_15InferenceEngine_5convert_from_onnx(CYTHON_UNUSED PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyMethodDef __pyx_mdef_7engines_16inference_engine_15InferenceEngine_5convert_from_onnx = {"convert_from_onnx", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7engines_16inference_engine_15InferenceEngine_5convert_from_onnx, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_7engines_16inference_engine_15InferenceEngine_5convert_from_onnx(CYTHON_UNUSED PyObject *__pyx_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
PyObject *__pyx_v_onnx_bytes = 0;
#if !CYTHON_METH_FASTCALL
CYTHON_UNUSED Py_ssize_t __pyx_nargs;
#endif
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
PyObject* values[1] = {0};
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("convert_from_onnx (wrapper)", 0);
#if !CYTHON_METH_FASTCALL
#if CYTHON_ASSUME_SAFE_SIZE
__pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
#else
__pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
#endif
#endif
__pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs);
{
PyObject ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_onnx_bytes,0};
const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 13, __pyx_L3_error)
if (__pyx_kwds_len > 0) {
switch (__pyx_nargs) {
case 1:
values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 13, __pyx_L3_error)
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
const Py_ssize_t kwd_pos_args = __pyx_nargs;
if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "convert_from_onnx", 0) < 0) __PYX_ERR(0, 13, __pyx_L3_error)
for (Py_ssize_t i = __pyx_nargs; i < 1; i++) {
if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("convert_from_onnx", 1, 1, 1, i); __PYX_ERR(0, 13, __pyx_L3_error) }
}
} else if (unlikely(__pyx_nargs != 1)) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0);
if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 13, __pyx_L3_error)
}
__pyx_v_onnx_bytes = ((PyObject*)values[0]);
}
goto __pyx_L6_skip;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("convert_from_onnx", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 13, __pyx_L3_error)
__pyx_L6_skip:;
goto __pyx_L4_argument_unpacking_done;
__pyx_L3_error:;
for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
Py_XDECREF(values[__pyx_temp]);
}
__Pyx_AddTraceback("engines.inference_engine.InferenceEngine.convert_from_onnx", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_onnx_bytes), (&PyBytes_Type), 1, "onnx_bytes", 1))) __PYX_ERR(0, 14, __pyx_L1_error)
__pyx_r = __pyx_pf_7engines_16inference_engine_15InferenceEngine_4convert_from_onnx(__pyx_v_onnx_bytes);
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
Py_XDECREF(values[__pyx_temp]);
}
goto __pyx_L7_cleaned_up;
__pyx_L0:;
for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
Py_XDECREF(values[__pyx_temp]);
}
__pyx_L7_cleaned_up:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7engines_16inference_engine_15InferenceEngine_4convert_from_onnx(PyObject *__pyx_v_onnx_bytes) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("convert_from_onnx", 0);
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(__pyx_v_onnx_bytes);
__pyx_r = __pyx_v_onnx_bytes;
goto __pyx_L0;
/* function exit code */
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_f_7engines_16inference_engine_15InferenceEngine_get_input_shape(CYTHON_UNUSED struct __pyx_obj_7engines_16inference_engine_InferenceEngine *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
@@ -2677,12 +2910,12 @@ static PyObject *__pyx_f_7engines_16inference_engine_15InferenceEngine_get_input
__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6, __pyx_L1_error)
if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 18, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
}
__Pyx_Raise(__pyx_t_1, 0, 0, 0);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__PYX_ERR(0, 6, __pyx_L1_error)
__PYX_ERR(0, 18, __pyx_L1_error)
/* function exit code */
@@ -2732,12 +2965,12 @@ static PyObject *__pyx_f_7engines_16inference_engine_15InferenceEngine_run(CYTHO
__pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 12, __pyx_L1_error)
if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 24, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
}
__Pyx_Raise(__pyx_t_1, 0, 0, 0);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__PYX_ERR(0, 12, __pyx_L1_error)
__PYX_ERR(0, 24, __pyx_L1_error)
/* function exit code */
@@ -2830,15 +3063,15 @@ static int __pyx_pf_7engines_16inference_engine_15InferenceEngine_10batch_size_2
/* Python wrapper */
static PyObject *__pyx_pw_7engines_16inference_engine_15InferenceEngine_3__reduce_cython__(PyObject *__pyx_v_self,
static PyObject *__pyx_pw_7engines_16inference_engine_15InferenceEngine_7__reduce_cython__(PyObject *__pyx_v_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyMethodDef __pyx_mdef_7engines_16inference_engine_15InferenceEngine_3__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7engines_16inference_engine_15InferenceEngine_3__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_7engines_16inference_engine_15InferenceEngine_3__reduce_cython__(PyObject *__pyx_v_self,
static PyMethodDef __pyx_mdef_7engines_16inference_engine_15InferenceEngine_7__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7engines_16inference_engine_15InferenceEngine_7__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_7engines_16inference_engine_15InferenceEngine_7__reduce_cython__(PyObject *__pyx_v_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
@@ -2864,14 +3097,14 @@ PyObject *__pyx_args, PyObject *__pyx_kwds
const Py_ssize_t __pyx_kwds_len = unlikely(__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0;
if (unlikely(__pyx_kwds_len < 0)) return NULL;
if (unlikely(__pyx_kwds_len > 0)) {__Pyx_RejectKeywords("__reduce_cython__", __pyx_kwds); return NULL;}
__pyx_r = __pyx_pf_7engines_16inference_engine_15InferenceEngine_2__reduce_cython__(((struct __pyx_obj_7engines_16inference_engine_InferenceEngine *)__pyx_v_self));
__pyx_r = __pyx_pf_7engines_16inference_engine_15InferenceEngine_6__reduce_cython__(((struct __pyx_obj_7engines_16inference_engine_InferenceEngine *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_7engines_16inference_engine_15InferenceEngine_2__reduce_cython__(struct __pyx_obj_7engines_16inference_engine_InferenceEngine *__pyx_v_self) {
static PyObject *__pyx_pf_7engines_16inference_engine_15InferenceEngine_6__reduce_cython__(struct __pyx_obj_7engines_16inference_engine_InferenceEngine *__pyx_v_self) {
PyObject *__pyx_v_state = 0;
PyObject *__pyx_v__dict = 0;
int __pyx_v_use_setstate;
@@ -3004,15 +3237,15 @@ static PyObject *__pyx_pf_7engines_16inference_engine_15InferenceEngine_2__reduc
/* Python wrapper */
static PyObject *__pyx_pw_7engines_16inference_engine_15InferenceEngine_5__setstate_cython__(PyObject *__pyx_v_self,
static PyObject *__pyx_pw_7engines_16inference_engine_15InferenceEngine_9__setstate_cython__(PyObject *__pyx_v_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static PyMethodDef __pyx_mdef_7engines_16inference_engine_15InferenceEngine_5__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7engines_16inference_engine_15InferenceEngine_5__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_7engines_16inference_engine_15InferenceEngine_5__setstate_cython__(PyObject *__pyx_v_self,
static PyMethodDef __pyx_mdef_7engines_16inference_engine_15InferenceEngine_9__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7engines_16inference_engine_15InferenceEngine_9__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_7engines_16inference_engine_15InferenceEngine_9__setstate_cython__(PyObject *__pyx_v_self,
#if CYTHON_METH_FASTCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
@@ -3078,7 +3311,7 @@ PyObject *__pyx_args, PyObject *__pyx_kwds
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_7engines_16inference_engine_15InferenceEngine_4__setstate_cython__(((struct __pyx_obj_7engines_16inference_engine_InferenceEngine *)__pyx_v_self), __pyx_v___pyx_state);
__pyx_r = __pyx_pf_7engines_16inference_engine_15InferenceEngine_8__setstate_cython__(((struct __pyx_obj_7engines_16inference_engine_InferenceEngine *)__pyx_v_self), __pyx_v___pyx_state);
/* function exit code */
for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
@@ -3088,7 +3321,7 @@ PyObject *__pyx_args, PyObject *__pyx_kwds
return __pyx_r;
}
static PyObject *__pyx_pf_7engines_16inference_engine_15InferenceEngine_4__setstate_cython__(struct __pyx_obj_7engines_16inference_engine_InferenceEngine *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
static PyObject *__pyx_pf_7engines_16inference_engine_15InferenceEngine_8__setstate_cython__(struct __pyx_obj_7engines_16inference_engine_InferenceEngine *__pyx_v_self, PyObject *__pyx_v___pyx_state) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
@@ -3423,6 +3656,10 @@ static void __pyx_tp_dealloc_7engines_16inference_engine_InferenceEngine(PyObjec
#endif
}
static PyObject *__pyx_getprop_7engines_16inference_engine_15InferenceEngine_engine_name(PyObject *o, CYTHON_UNUSED void *x) {
return __pyx_pw_7engines_16inference_engine_15InferenceEngine_11engine_name_1__get__(o);
}
static PyObject *__pyx_getprop_7engines_16inference_engine_15InferenceEngine_batch_size(PyObject *o, CYTHON_UNUSED void *x) {
return __pyx_pw_7engines_16inference_engine_15InferenceEngine_10batch_size_1__get__(o);
}
@@ -3438,12 +3675,15 @@ static int __pyx_setprop_7engines_16inference_engine_15InferenceEngine_batch_siz
}
static PyMethodDef __pyx_methods_7engines_16inference_engine_InferenceEngine[] = {
{"__reduce_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7engines_16inference_engine_15InferenceEngine_3__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0},
{"__setstate_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7engines_16inference_engine_15InferenceEngine_5__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0},
{"get_engine_filename", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7engines_16inference_engine_15InferenceEngine_3get_engine_filename, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0},
{"convert_from_onnx", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7engines_16inference_engine_15InferenceEngine_5convert_from_onnx, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0},
{"__reduce_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7engines_16inference_engine_15InferenceEngine_7__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0},
{"__setstate_cython__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_7engines_16inference_engine_15InferenceEngine_9__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0},
{0, 0, 0, 0}
};
static struct PyGetSetDef __pyx_getsets_7engines_16inference_engine_InferenceEngine[] = {
{"engine_name", __pyx_getprop_7engines_16inference_engine_15InferenceEngine_engine_name, 0, 0, 0},
{"batch_size", __pyx_getprop_7engines_16inference_engine_15InferenceEngine_batch_size, __pyx_setprop_7engines_16inference_engine_15InferenceEngine_batch_size, 0, 0},
{0, 0, 0, 0, 0}
};
@@ -3830,6 +4070,10 @@ static CYTHON_SMALL_CODE int __pyx_pymod_exec_inference_engine(PyObject *__pyx_p
__pyx_mstatetype *__pyx_mstate = NULL;
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
size_t __pyx_t_6;
int __pyx_lineno = 0;
const char *__pyx_filename = NULL;
int __pyx_clineno = 0;
@@ -3936,17 +4180,61 @@ __Pyx_RefNannySetupContext("PyInit_inference_engine", 0);
(void)__Pyx_modinit_function_import_code(__pyx_mstate);
/*--- Execution code ---*/
__pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7engines_16inference_engine_15InferenceEngine_3__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_InferenceEngine___reduce_cython, NULL, __pyx_mstate_global->__pyx_n_u_engines_inference_engine, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[0])); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1, __pyx_L1_error)
__pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7engines_16inference_engine_15InferenceEngine_3get_engine_filename, __Pyx_CYFUNCTION_STATICMETHOD | __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_InferenceEngine_get_engine_filen, NULL, __pyx_mstate_global->__pyx_n_u_engines_inference_engine, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[0])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 9, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_7engines_16inference_engine_InferenceEngine, __pyx_mstate_global->__pyx_n_u_get_engine_filename, __pyx_t_2) < 0) __PYX_ERR(0, 9, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_3 = NULL;
__Pyx_INCREF(__pyx_builtin_staticmethod);
__pyx_t_4 = __pyx_builtin_staticmethod;
__Pyx_GetNameInClass(__pyx_t_5, (PyObject*)__pyx_mstate_global->__pyx_ptype_7engines_16inference_engine_InferenceEngine, __pyx_mstate_global->__pyx_n_u_get_engine_filename); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 9, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_6 = 1;
{
PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_5};
__pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 9, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
}
if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_7engines_16inference_engine_InferenceEngine, __pyx_mstate_global->__pyx_n_u_get_engine_filename, __pyx_t_2) < 0) __PYX_ERR(0, 9, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7engines_16inference_engine_15InferenceEngine_5convert_from_onnx, __Pyx_CYFUNCTION_STATICMETHOD | __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_InferenceEngine_convert_from_onn, NULL, __pyx_mstate_global->__pyx_n_u_engines_inference_engine, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[1])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 13, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_7engines_16inference_engine_InferenceEngine, __pyx_mstate_global->__pyx_n_u_convert_from_onnx, __pyx_t_2) < 0) __PYX_ERR(0, 13, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_4 = NULL;
__Pyx_INCREF(__pyx_builtin_staticmethod);
__pyx_t_5 = __pyx_builtin_staticmethod;
__Pyx_GetNameInClass(__pyx_t_3, (PyObject*)__pyx_mstate_global->__pyx_ptype_7engines_16inference_engine_InferenceEngine, __pyx_mstate_global->__pyx_n_u_convert_from_onnx); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 13, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_6 = 1;
{
PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_t_3};
__pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 13, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
}
if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_7engines_16inference_engine_InferenceEngine, __pyx_mstate_global->__pyx_n_u_convert_from_onnx, __pyx_t_2) < 0) __PYX_ERR(0, 13, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7engines_16inference_engine_15InferenceEngine_7__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_InferenceEngine___reduce_cython, NULL, __pyx_mstate_global->__pyx_n_u_engines_inference_engine, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[2])); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_7engines_16inference_engine_InferenceEngine, __pyx_mstate_global->__pyx_n_u_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(2, 1, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7engines_16inference_engine_15InferenceEngine_5__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_InferenceEngine___setstate_cytho, NULL, __pyx_mstate_global->__pyx_n_u_engines_inference_engine, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[1])); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 16, __pyx_L1_error)
__pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7engines_16inference_engine_15InferenceEngine_9__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_InferenceEngine___setstate_cytho, NULL, __pyx_mstate_global->__pyx_n_u_engines_inference_engine, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[3])); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 16, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_7engines_16inference_engine_InferenceEngine, __pyx_mstate_global->__pyx_n_u_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(2, 16, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7engines_16inference_engine_1__pyx_unpickle_InferenceEngine, 0, __pyx_mstate_global->__pyx_n_u_pyx_unpickle_InferenceEngine, NULL, __pyx_mstate_global->__pyx_n_u_engines_inference_engine, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[2])); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1, __pyx_L1_error)
__pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_7engines_16inference_engine_1__pyx_unpickle_InferenceEngine, 0, __pyx_mstate_global->__pyx_n_u_pyx_unpickle_InferenceEngine, NULL, __pyx_mstate_global->__pyx_n_u_engines_inference_engine, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[4])); if (unlikely(!__pyx_t_2)) __PYX_ERR(2, 1, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_pyx_unpickle_InferenceEngine, __pyx_t_2) < 0) __PYX_ERR(2, 1, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
@@ -3961,6 +4249,9 @@ __Pyx_RefNannySetupContext("PyInit_inference_engine", 0);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
if (__pyx_m) {
if (__pyx_mstate->__pyx_d && stringtab_initialized) {
__Pyx_AddTraceback("init engines.inference_engine", __pyx_clineno, __pyx_lineno, __pyx_filename);
@@ -4019,6 +4310,8 @@ static const __Pyx_StringTabEntry __pyx_string_tab[] = {
{__pyx_k_InferenceEngine, sizeof(__pyx_k_InferenceEngine), 0, 1, 1}, /* PyObject cname: __pyx_n_u_InferenceEngine */
{__pyx_k_InferenceEngine___reduce_cython, sizeof(__pyx_k_InferenceEngine___reduce_cython), 0, 1, 1}, /* PyObject cname: __pyx_n_u_InferenceEngine___reduce_cython */
{__pyx_k_InferenceEngine___setstate_cytho, sizeof(__pyx_k_InferenceEngine___setstate_cytho), 0, 1, 1}, /* PyObject cname: __pyx_n_u_InferenceEngine___setstate_cytho */
{__pyx_k_InferenceEngine_convert_from_onn, sizeof(__pyx_k_InferenceEngine_convert_from_onn), 0, 1, 1}, /* PyObject cname: __pyx_n_u_InferenceEngine_convert_from_onn */
{__pyx_k_InferenceEngine_get_engine_filen, sizeof(__pyx_k_InferenceEngine_get_engine_filen), 0, 1, 1}, /* PyObject cname: __pyx_n_u_InferenceEngine_get_engine_filen */
{__pyx_k_NotImplementedError, sizeof(__pyx_k_NotImplementedError), 0, 1, 1}, /* PyObject cname: __pyx_n_u_NotImplementedError */
{__pyx_k_Note_that_Cython_is_deliberately, sizeof(__pyx_k_Note_that_Cython_is_deliberately), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_Note_that_Cython_is_deliberately */
{__pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 1, 1}, /* PyObject cname: __pyx_n_u_PickleError */
@@ -4029,13 +4322,16 @@ static const __Pyx_StringTabEntry __pyx_string_tab[] = {
{__pyx_k_asyncio_coroutines, sizeof(__pyx_k_asyncio_coroutines), 0, 1, 1}, /* PyObject cname: __pyx_n_u_asyncio_coroutines */
{__pyx_k_batch_size, sizeof(__pyx_k_batch_size), 0, 1, 1}, /* PyObject cname: __pyx_n_u_batch_size */
{__pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 1, 1}, /* PyObject cname: __pyx_n_u_cline_in_traceback */
{__pyx_k_convert_from_onnx, sizeof(__pyx_k_convert_from_onnx), 0, 1, 1}, /* PyObject cname: __pyx_n_u_convert_from_onnx */
{__pyx_k_dict, sizeof(__pyx_k_dict), 0, 1, 1}, /* PyObject cname: __pyx_n_u_dict */
{__pyx_k_dict_2, sizeof(__pyx_k_dict_2), 0, 1, 1}, /* PyObject cname: __pyx_n_u_dict_2 */
{__pyx_k_disable, sizeof(__pyx_k_disable), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_disable */
{__pyx_k_enable, sizeof(__pyx_k_enable), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_enable */
{__pyx_k_engines_inference_engine, sizeof(__pyx_k_engines_inference_engine), 0, 1, 1}, /* PyObject cname: __pyx_n_u_engines_inference_engine */
{__pyx_k_engines_inference_engine_pyx, sizeof(__pyx_k_engines_inference_engine_pyx), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_engines_inference_engine_pyx */
{__pyx_k_func, sizeof(__pyx_k_func), 0, 1, 1}, /* PyObject cname: __pyx_n_u_func */
{__pyx_k_gc, sizeof(__pyx_k_gc), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_gc */
{__pyx_k_get_engine_filename, sizeof(__pyx_k_get_engine_filename), 0, 1, 1}, /* PyObject cname: __pyx_n_u_get_engine_filename */
{__pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 1, 1}, /* PyObject cname: __pyx_n_u_getstate */
{__pyx_k_is_coroutine, sizeof(__pyx_k_is_coroutine), 0, 1, 1}, /* PyObject cname: __pyx_n_u_is_coroutine */
{__pyx_k_isenabled, sizeof(__pyx_k_isenabled), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_isenabled */
@@ -4044,6 +4340,8 @@ static const __Pyx_StringTabEntry __pyx_string_tab[] = {
{__pyx_k_module, sizeof(__pyx_k_module), 0, 1, 1}, /* PyObject cname: __pyx_n_u_module */
{__pyx_k_name, sizeof(__pyx_k_name), 0, 1, 1}, /* PyObject cname: __pyx_n_u_name */
{__pyx_k_new, sizeof(__pyx_k_new), 0, 1, 1}, /* PyObject cname: __pyx_n_u_new */
{__pyx_k_onnx, sizeof(__pyx_k_onnx), 0, 1, 1}, /* PyObject cname: __pyx_n_u_onnx */
{__pyx_k_onnx_bytes, sizeof(__pyx_k_onnx_bytes), 0, 1, 1}, /* PyObject cname: __pyx_n_u_onnx_bytes */
{__pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 1, 1}, /* PyObject cname: __pyx_n_u_pickle */
{__pyx_k_pop, sizeof(__pyx_k_pop), 0, 1, 1}, /* PyObject cname: __pyx_n_u_pop */
{__pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 1, 1}, /* PyObject cname: __pyx_n_u_pyx_PickleError */
@@ -4062,6 +4360,7 @@ static const __Pyx_StringTabEntry __pyx_string_tab[] = {
{__pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 1, 1}, /* PyObject cname: __pyx_n_u_setstate */
{__pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 1, 1}, /* PyObject cname: __pyx_n_u_setstate_cython */
{__pyx_k_state, sizeof(__pyx_k_state), 0, 1, 1}, /* PyObject cname: __pyx_n_u_state */
{__pyx_k_staticmethod, sizeof(__pyx_k_staticmethod), 0, 1, 1}, /* PyObject cname: __pyx_n_u_staticmethod */
{__pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 1, 0}, /* PyObject cname: __pyx_kp_u_stringsource */
{__pyx_k_test, sizeof(__pyx_k_test), 0, 1, 1}, /* PyObject cname: __pyx_n_u_test */
{__pyx_k_update, sizeof(__pyx_k_update), 0, 1, 1}, /* PyObject cname: __pyx_n_u_update */
@@ -4075,7 +4374,8 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry const *t, PyObject **target, c
static int __Pyx_InitCachedBuiltins(__pyx_mstatetype *__pyx_mstate) {
CYTHON_UNUSED_VAR(__pyx_mstate);
__pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_mstate->__pyx_n_u_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(0, 6, __pyx_L1_error)
__pyx_builtin_staticmethod = __Pyx_GetBuiltinName(__pyx_mstate->__pyx_n_u_staticmethod); if (!__pyx_builtin_staticmethod) __PYX_ERR(0, 9, __pyx_L1_error)
__pyx_builtin_NotImplementedError = __Pyx_GetBuiltinName(__pyx_mstate->__pyx_n_u_NotImplementedError); if (!__pyx_builtin_NotImplementedError) __PYX_ERR(0, 18, __pyx_L1_error)
return 0;
__pyx_L1_error:;
return -1;
@@ -4136,20 +4436,30 @@ static PyObject* __Pyx_PyCode_New(
static int __Pyx_CreateCodeObjects(__pyx_mstatetype *__pyx_mstate) {
PyObject* tuple_dedup_map = PyDict_New();
if (unlikely(!tuple_dedup_map)) return -1;
{
const __Pyx_PyCode_New_function_description descr = {0, 0, 0, 0, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 9, 7};
PyObject* const varnames[] = {0};
__pyx_mstate_global->__pyx_codeobj_tab[0] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_engines_inference_engine_pyx, __pyx_mstate->__pyx_n_u_get_engine_filename, __pyx_k_A_q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[0])) goto bad;
}
{
const __Pyx_PyCode_New_function_description descr = {1, 0, 0, 1, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 13, 7};
PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_onnx_bytes};
__pyx_mstate_global->__pyx_codeobj_tab[1] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_engines_inference_engine_pyx, __pyx_mstate->__pyx_n_u_convert_from_onnx, __pyx_k_A_q, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[1])) goto bad;
}
{
const __Pyx_PyCode_New_function_description descr = {1, 0, 0, 4, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 1, 87};
PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self, __pyx_mstate->__pyx_n_u_state, __pyx_mstate->__pyx_n_u_dict_2, __pyx_mstate->__pyx_n_u_use_setstate};
__pyx_mstate_global->__pyx_codeobj_tab[0] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_stringsource, __pyx_mstate->__pyx_n_u_reduce_cython, __pyx_k_T_G1F_a_vWA_q_q_q_0_AWKwa_0_AWK, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[0])) goto bad;
__pyx_mstate_global->__pyx_codeobj_tab[2] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_stringsource, __pyx_mstate->__pyx_n_u_reduce_cython, __pyx_k_T_G1F_a_vWA_q_q_q_0_AWKwa_0_AWK, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[2])) goto bad;
}
{
const __Pyx_PyCode_New_function_description descr = {2, 0, 0, 2, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 16, 11};
PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_self, __pyx_mstate->__pyx_n_u_pyx_state};
__pyx_mstate_global->__pyx_codeobj_tab[1] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_stringsource, __pyx_mstate->__pyx_n_u_setstate_cython, __pyx_k_QfA, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[1])) goto bad;
__pyx_mstate_global->__pyx_codeobj_tab[3] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_stringsource, __pyx_mstate->__pyx_n_u_setstate_cython, __pyx_k_QfA, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[3])) goto bad;
}
{
const __Pyx_PyCode_New_function_description descr = {3, 0, 0, 5, (unsigned int)(CO_OPTIMIZED|CO_NEWLOCALS), 1, 77};
PyObject* const varnames[] = {__pyx_mstate->__pyx_n_u_pyx_type, __pyx_mstate->__pyx_n_u_pyx_checksum, __pyx_mstate->__pyx_n_u_pyx_state, __pyx_mstate->__pyx_n_u_pyx_PickleError, __pyx_mstate->__pyx_n_u_pyx_result};
__pyx_mstate_global->__pyx_codeobj_tab[2] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_stringsource, __pyx_mstate->__pyx_n_u_pyx_unpickle_InferenceEngine, __pyx_k_hk_A_1_uuwwx_1_7_1_2DNRS_1, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[2])) goto bad;
__pyx_mstate_global->__pyx_codeobj_tab[4] = __Pyx_PyCode_New(descr, varnames, __pyx_mstate->__pyx_kp_u_stringsource, __pyx_mstate->__pyx_n_u_pyx_unpickle_InferenceEngine, __pyx_k_hk_A_1_uuwwx_1_7_1_2DNRS_1, tuple_dedup_map); if (unlikely(!__pyx_mstate_global->__pyx_codeobj_tab[4])) goto bad;
}
Py_DECREF(tuple_dedup_map);
return 0;
@@ -5446,6 +5756,27 @@ static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *nam
return 0;
}
/* RejectKeywords */
static void __Pyx_RejectKeywords(const char* function_name, PyObject *kwds) {
PyObject *key = NULL;
if (CYTHON_METH_FASTCALL && likely(PyTuple_Check(kwds))) {
key = __Pyx_PySequence_ITEM(kwds, 0);
} else {
Py_ssize_t pos = 0;
#if !CYTHON_COMPILING_IN_PYPY || defined(PyArg_ValidateKeywordArguments)
if (unlikely(!PyArg_ValidateKeywordArguments(kwds))) return;
#endif
PyDict_Next(kwds, &pos, &key, NULL);
Py_INCREF(key);
}
if (likely(key)) {
PyErr_Format(PyExc_TypeError,
"%s() got an unexpected keyword argument '%U'",
function_name, key);
Py_DECREF(key);
}
}
/* RaiseException */
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
PyObject* owned_instance = NULL;
@@ -5554,27 +5885,6 @@ bad:
return;
}
/* RejectKeywords */
static void __Pyx_RejectKeywords(const char* function_name, PyObject *kwds) {
PyObject *key = NULL;
if (CYTHON_METH_FASTCALL && likely(PyTuple_Check(kwds))) {
key = __Pyx_PySequence_ITEM(kwds, 0);
} else {
Py_ssize_t pos = 0;
#if !CYTHON_COMPILING_IN_PYPY || defined(PyArg_ValidateKeywordArguments)
if (unlikely(!PyArg_ValidateKeywordArguments(kwds))) return;
#endif
PyDict_Next(kwds, &pos, &key, NULL);
Py_INCREF(key);
}
if (likely(key)) {
PyErr_Format(PyExc_TypeError,
"%s() got an unexpected keyword argument '%U'",
function_name, key);
Py_DECREF(key);
}
}
/* GetAttr3 */
#if __PYX_LIMITED_VERSION_HEX < 0x030d0000
static PyObject *__Pyx_GetAttr3Default(PyObject *d) {
@@ -7815,6 +8125,29 @@ static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, int flags, PyObject* qual
return op;
}
/* GetNameInClass */
static PyObject *__Pyx__GetNameInClass(PyObject *nmspace, PyObject *name) {
PyObject *result;
PyObject *dict;
assert(PyType_Check(nmspace));
#if CYTHON_USE_TYPE_SLOTS
dict = ((PyTypeObject*)nmspace)->tp_dict;
Py_XINCREF(dict);
#else
dict = PyObject_GetAttr(nmspace, __pyx_mstate_global->__pyx_n_u_dict);
#endif
if (likely(dict)) {
result = PyObject_GetItem(dict, name);
Py_DECREF(dict);
if (result) {
return result;
}
}
PyErr_Clear();
__Pyx_GetModuleGlobalNameUncached(result, name);
return result;
}
/* CLineInTraceback */
#if CYTHON_CLINE_IN_TRACEBACK && CYTHON_CLINE_IN_TRACEBACK_RUNTIME
static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line) {
+12
View File
@@ -2,6 +2,18 @@ cdef class InferenceEngine:
def __init__(self, model_bytes: bytes, batch_size: int = 1, **kwargs):
self.batch_size = batch_size
@property
def engine_name(self):
return "onnx"
@staticmethod
def get_engine_filename():
return None
@staticmethod
def convert_from_onnx(bytes onnx_bytes):
return onnx_bytes
cdef tuple get_input_shape(self):
raise NotImplementedError("Subclass must implement get_input_shape")
+1 -1
View File
@@ -4,7 +4,7 @@
{
"distutils": {
"include_dirs": [
"/Users/obezdienie001/dev/azaion/suite/detections/.venv-e2e/lib/python3.13/site-packages/numpy/_core/include"
"/Users/obezdienie001/dev/azaion/suite/detections/.venv/lib/python3.13/site-packages/numpy/_core/include"
],
"name": "engines.onnx_engine",
"sources": [
+7 -2
View File
@@ -72,10 +72,15 @@ cdef class TensorRTEngine(InferenceEngine):
pass
return 2 * 1024 * 1024 * 1024 if total_memory is None else total_memory # default 2 Gb
@property
def engine_name(self):
return "tensorrt"
@staticmethod
def get_engine_filename(int device_id):
def get_engine_filename():
try:
device = cuda.Device(device_id)
from engines import tensor_gpu_index
device = cuda.Device(max(tensor_gpu_index, 0))
sm_count = device.multiprocessor_count
cc_major, cc_minor = device.compute_capability()
return f"azaion.cc_{cc_major}.{cc_minor}_sm_{sm_count}.engine"
+1383 -1412
View File
File diff suppressed because it is too large Load Diff
-46
View File
@@ -1,46 +0,0 @@
from ai_availability_status cimport AIAvailabilityStatus
from annotation cimport Annotation, Detection
from ai_config cimport AIRecognitionConfig
from engines.inference_engine cimport InferenceEngine
cdef class Inference:
cdef object loader_client
cdef InferenceEngine engine
cdef object _annotation_callback
cdef object _status_callback
cdef Annotation _previous_annotation
cdef dict[str, list(Detection)] _tile_detections
cdef dict[str, int] detection_counts
cdef AIRecognitionConfig ai_config
cdef bint stop_signal
cdef public AIAvailabilityStatus ai_availability_status
cdef str model_input
cdef int model_width
cdef int model_height
cdef bytes _converted_model_bytes
cdef bytes get_onnx_engine_bytes(self)
cdef convert_and_upload_model(self, bytes onnx_engine_bytes, str engine_filename)
cdef init_ai(self)
cdef bint is_building_engine
cdef bint is_video(self, str filepath)
cpdef run_detect(self, dict config_dict, object annotation_callback, object status_callback=*)
cpdef list detect_single_image(self, bytes image_bytes, dict config_dict)
cdef _process_video(self, AIRecognitionConfig ai_config, str video_name)
cdef _process_images(self, AIRecognitionConfig ai_config, list[str] image_paths)
cdef _process_images_inner(self, AIRecognitionConfig ai_config, list frame_data, double ground_sampling_distance)
cdef on_annotation(self, Annotation annotation, int frame_count=*, int total_frames=*)
cdef split_to_tiles(self, frame, path, tile_size, overlap_percent)
cpdef stop(self)
cdef preprocess(self, frames)
cdef send_detection_status(self)
cdef remove_overlapping_detections(self, list[Detection] detections, float confidence_threshold=?)
cdef postprocess(self, output, ai_config)
cdef split_list_extend(self, lst, chunk_size)
cdef bint is_valid_video_annotation(self, Annotation annotation, AIRecognitionConfig ai_config)
cdef bint is_valid_image_annotation(self, Annotation annotation, double ground_sampling_distance, frame_shape)
cdef remove_tiled_duplicates(self, Annotation annotation)
+43 -26
View File
@@ -8,28 +8,42 @@ cimport constants_inf
from ai_availability_status cimport AIAvailabilityEnum, AIAvailabilityStatus
from annotation cimport Detection, Annotation
from ai_config cimport AIRecognitionConfig
from engines.inference_engine cimport InferenceEngine
from loader_http_client cimport LoaderHttpClient
from threading import Thread
from engines import tensor_gpu_index, create_engine
if tensor_gpu_index > -1:
from engines.tensorrt_engine import TensorRTEngine
from engines import EngineClass
cdef class Inference:
cdef LoaderHttpClient loader_client
cdef InferenceEngine engine
cdef object _annotation_callback
cdef object _status_callback
cdef Annotation _previous_annotation
cdef dict[str, list[Detection]] _tile_detections
cdef dict[str, int] detection_counts
cdef AIRecognitionConfig ai_config
cdef bint stop_signal
cdef public AIAvailabilityStatus ai_availability_status
cdef str model_input
cdef int model_width
cdef int model_height
cdef bytes _converted_model_bytes
cdef bint is_building_engine
def __init__(self, loader_client):
self.loader_client = loader_client
self._annotation_callback = None
self._status_callback = None
self.stop_signal = False
self.model_input = None
self.stop_signal = <bint>False
self.model_input = <str>None
self.model_width = 0
self.model_height = 0
self.detection_counts = {}
self.engine = None
self.is_building_engine = False
self.engine = <InferenceEngine>None
self.is_building_engine = <bint>False
self.ai_availability_status = AIAvailabilityStatus()
self._converted_model_bytes = None
self._converted_model_bytes = <bytes>None
self.init_ai()
@property
@@ -49,7 +63,7 @@ cdef class Inference:
try:
self.ai_availability_status.set_status(AIAvailabilityEnum.CONVERTING)
models_dir = constants_inf.MODELS_FOLDER
model_bytes = TensorRTEngine.convert_from_onnx(onnx_engine_bytes)
model_bytes = EngineClass.convert_from_onnx(onnx_engine_bytes)
self.ai_availability_status.set_status(AIAvailabilityEnum.UPLOADING)
res = self.loader_client.upload_big_small_resource(model_bytes, engine_filename, models_dir)
@@ -60,9 +74,9 @@ cdef class Inference:
self.ai_availability_status.set_status(AIAvailabilityEnum.ENABLED)
except Exception as e:
self.ai_availability_status.set_status(AIAvailabilityEnum.ERROR, <str> str(e))
self._converted_model_bytes = None
self._converted_model_bytes = <bytes>None
finally:
self.is_building_engine = False
self.is_building_engine = <bint>False
cdef init_ai(self):
constants_inf.log(<str> 'init AI...')
@@ -74,24 +88,24 @@ cdef class Inference:
if self._converted_model_bytes is not None:
try:
self.engine = TensorRTEngine(self._converted_model_bytes)
self.engine = EngineClass(self._converted_model_bytes)
self.ai_availability_status.set_status(AIAvailabilityEnum.ENABLED)
self.model_height, self.model_width = self.engine.get_input_shape()
except Exception as e:
self.ai_availability_status.set_status(AIAvailabilityEnum.ERROR, <str> str(e))
finally:
self._converted_model_bytes = None # Consume the bytes
self._converted_model_bytes = <bytes>None
return
models_dir = constants_inf.MODELS_FOLDER
if tensor_gpu_index > -1:
engine_filename = EngineClass.get_engine_filename()
if engine_filename is not None:
try:
engine_filename = TensorRTEngine.get_engine_filename(0)
self.ai_availability_status.set_status(AIAvailabilityEnum.DOWNLOADING)
res = self.loader_client.load_big_small_resource(engine_filename, models_dir)
if res.err is not None:
raise Exception(res.err)
self.engine = TensorRTEngine(res.data)
self.engine = EngineClass(res.data)
self.ai_availability_status.set_status(AIAvailabilityEnum.ENABLED)
except Exception as e:
self.ai_availability_status.set_status(AIAvailabilityEnum.WARNING, <str>str(e))
@@ -103,7 +117,8 @@ cdef class Inference:
thread.start()
return
else:
self.engine = create_engine(<bytes>self.get_onnx_engine_bytes())
self.engine = EngineClass(<bytes>self.get_onnx_engine_bytes())
self.ai_availability_status.set_status(AIAvailabilityEnum.ENABLED)
self.is_building_engine = False
self.model_height, self.model_width = self.engine.get_input_shape()
@@ -178,7 +193,7 @@ cdef class Inference:
cdef bint is_video(self, str filepath):
mime_type, _ = mimetypes.guess_type(<str>filepath)
return mime_type and mime_type.startswith("video")
return <bint>(mime_type and mime_type.startswith("video"))
cdef split_list_extend(self, lst, chunk_size):
chunks = [lst[i:i + chunk_size] for i in range(0, len(lst), chunk_size)]
@@ -200,7 +215,7 @@ cdef class Inference:
self._annotation_callback = annotation_callback
self._status_callback = status_callback
self.stop_signal = False
self.stop_signal = <bint>False
self.init_ai()
if self.engine is None:
constants_inf.log(<str> "AI engine not available. Conversion may be in progress. Skipping inference.")
@@ -246,9 +261,9 @@ cdef class Inference:
cdef int frame_count = 0
cdef int batch_count = 0
cdef list batch_frames = []
cdef list[int] batch_timestamps = []
cdef list[long] batch_timestamps = []
cdef Annotation annotation
self._previous_annotation = None
self._previous_annotation = <Annotation>None
v_input = cv2.VideoCapture(<str>video_name)
if not v_input.isOpened():
@@ -267,7 +282,7 @@ cdef class Inference:
frame_count += 1
if frame_count % ai_config.frame_period_recognition == 0:
batch_frames.append(frame)
batch_timestamps.append(int(v_input.get(cv2.CAP_PROP_POS_MSEC)))
batch_timestamps.append(<long>v_input.get(cv2.CAP_PROP_POS_MSEC))
if len(batch_frames) == self.engine.get_batch_size():
batch_count += 1
@@ -308,7 +323,8 @@ cdef class Inference:
self.detection_counts[annotation.original_media_name] = self.detection_counts.get(annotation.original_media_name, 0) + 1
if self._annotation_callback is not None:
percent = int(frame_count * 100 / total_frames) if total_frames > 0 else 0
self._annotation_callback(annotation, percent)
cb = self._annotation_callback
cb(annotation, percent)
cdef _process_images(self, AIRecognitionConfig ai_config, list[str] image_paths):
cdef list frame_data
@@ -343,8 +359,9 @@ cdef class Inference:
cdef send_detection_status(self):
if self._status_callback is not None:
cb = self._status_callback
for media_name in self.detection_counts.keys():
self._status_callback(media_name, self.detection_counts[media_name])
cb(media_name, self.detection_counts[media_name])
self.detection_counts.clear()
cdef split_to_tiles(self, frame, path, tile_size, overlap_percent):
+11909
View File
File diff suppressed because it is too large Load Diff
+9
View File
@@ -0,0 +1,9 @@
cdef class LoadResult:
cdef public object err
cdef public object data
cdef class LoaderHttpClient:
cdef str base_url
cdef LoadResult load_big_small_resource(self, str filename, str directory)
cdef LoadResult upload_big_small_resource(self, bytes content, str filename, str directory)
cdef stop(self)
@@ -2,17 +2,17 @@ import requests
from loguru import logger
class LoadResult:
cdef class LoadResult:
def __init__(self, err, data=None):
self.err = err
self.data = data
class LoaderHttpClient:
cdef class LoaderHttpClient:
def __init__(self, base_url: str):
self.base_url = base_url.rstrip("/")
def load_big_small_resource(self, filename: str, directory: str) -> LoadResult:
cdef LoadResult load_big_small_resource(self, str filename, str directory):
try:
response = requests.post(
f"{self.base_url}/load/{filename}",
@@ -25,7 +25,7 @@ class LoaderHttpClient:
logger.error(f"LoaderHttpClient.load_big_small_resource failed: {e}")
return LoadResult(str(e))
def upload_big_small_resource(self, content: bytes, filename: str, directory: str) -> LoadResult:
cdef LoadResult upload_big_small_resource(self, bytes content, str filename, str directory):
try:
response = requests.post(
f"{self.base_url}/upload/{filename}",
@@ -38,5 +38,5 @@ class LoaderHttpClient:
logger.error(f"LoaderHttpClient.upload_big_small_resource failed: {e}")
return LoadResult(str(e))
def stop(self):
cdef stop(self):
pass
+3
View File
@@ -89,6 +89,7 @@ class DetectionEvent(BaseModel):
class HealthResponse(BaseModel):
status: str
aiAvailability: str
engineType: Optional[str] = None
errorMessage: Optional[str] = None
@@ -128,9 +129,11 @@ def health() -> HealthResponse:
status = inf.ai_availability_status
status_str = str(status).split()[0] if str(status).strip() else "None"
error_msg = status.error_message if hasattr(status, 'error_message') else None
engine_type = inf.engine.engine_name if inf.engine is not None else None
return HealthResponse(
status="healthy",
aiAvailability=status_str,
engineType=engine_type,
errorMessage=error_msg,
)
except Exception:
+2
View File
@@ -0,0 +1,2 @@
-r requirements.txt
coremltools==9.0
+1
View File
@@ -7,6 +7,7 @@ extensions = [
Extension('ai_availability_status', ['ai_availability_status.pyx']),
Extension('annotation', ['annotation.pyx']),
Extension('ai_config', ['ai_config.pyx']),
Extension('loader_http_client', ['loader_http_client.pyx']),
Extension('engines.inference_engine', ['engines/inference_engine.pyx'], include_dirs=[np.get_include()]),
Extension('engines.onnx_engine', ['engines/onnx_engine.pyx'], include_dirs=[np.get_include()]),
Extension('engines.coreml_engine', ['engines/coreml_engine.pyx'], include_dirs=[np.get_include()]),