Cython: convertor.pyx

Generated by Cython 3.0.7

Yellow lines hint at Python interaction.
Click on a line that starts with a "`+`" to see the C code that Cython generated for it.

Raw output: convertor.c

    +001: # cython: language_level=3

      __pyx_t_4 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_4) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

     002: # cython: boundscheck=False

     003: # cython: wraparound=False

     004: from libc.math cimport floor

     005: from libc.stdlib cimport malloc, free

    +006: import numpy as np

      __pyx_t_7 = __Pyx_ImportDottedModule(__pyx_n_s_numpy, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 6, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_7) < 0) __PYX_ERR(0, 6, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

     007: cimport numpy as np

     008:

    +009: cdef int PREC = 10

      __pyx_v_5dfpwm_9convertor_PREC = 10;

     010:

    +011: cdef short* proc_untracked(const float[:] input_data, const int sz) nogil:

    static short *__pyx_f_5dfpwm_9convertor_proc_untracked(__Pyx_memviewslice __pyx_v_input_data, int const __pyx_v_sz) {
      int __pyx_v_charge;
      int __pyx_v_strength;
      short __pyx_v_previous_bit;
      short *__pyx_v_out;
      size_t __pyx_v_i;
      size_t __pyx_v_j;
      int __pyx_v_this_byte;
      float __pyx_v_level;
      short __pyx_v_current_bit;
      int __pyx_v_next_charge;
      int __pyx_v_next_strength;
      int __pyx_v_target;
      int __pyx_v_v1;
      int __pyx_v_v2;
      long __pyx_v_z;
      long __pyx_v_v3;
      short *__pyx_r;
    /* … */
      /* function exit code */
      __pyx_L0:;
      return __pyx_r;
    }

    +012:     cdef int charge = 0

      __pyx_v_charge = 0;

    +013:     cdef int strength = 0

      __pyx_v_strength = 0;

    +014:     cdef short previous_bit = False

      __pyx_v_previous_bit = 0;

     015:

    +016:     cdef short *out = <short*>malloc(sizeof(short) * sz)

      __pyx_v_out = ((short *)malloc(((sizeof(short)) * __pyx_v_sz)));

     017:

    +018:     cdef size_t i = 0

      __pyx_v_i = 0;

    +019:     cdef size_t j = 0

      __pyx_v_j = 0;

     020:

    +021:     cdef int this_byte = 0

      __pyx_v_this_byte = 0;

     022:     cdef float level

     023:     cdef short current_bit

     024:     cdef int next_charge

     025:     cdef int next_strength

     026:     cdef int target

     027:     cdef int v1, v2

    +028:     while i < sz:

      while (1) {
        __pyx_t_1 = (__pyx_v_i < __pyx_v_sz);
        if (!__pyx_t_1) break;

    +029:         j = 0

        __pyx_v_j = 0;

    +030:         while j < 8:

        while (1) {
          __pyx_t_1 = (__pyx_v_j < 8);
          if (!__pyx_t_1) break;

    +031:             level = floor(input_data[i * 8 + j] * 127)

          __pyx_t_2 = ((__pyx_v_i * 8) + __pyx_v_j);
          __pyx_v_level = floor(((*((float const  *) ( /* dim=0 */ (__pyx_v_input_data.data + __pyx_t_2 * __pyx_v_input_data.strides[0]) ))) * 127.0));

     032:

    +033:             current_bit = level > charge or (level == charge and charge == 127)

          __pyx_t_1 = (__pyx_v_level > __pyx_v_charge);
          if (!__pyx_t_1) {
          } else {
            __pyx_t_3 = __pyx_t_1;
            goto __pyx_L7_bool_binop_done;
          }
          __pyx_t_1 = (__pyx_v_level == __pyx_v_charge);
          if (__pyx_t_1) {
          } else {
            __pyx_t_3 = __pyx_t_1;
            goto __pyx_L7_bool_binop_done;
          }
          __pyx_t_1 = (__pyx_v_charge == 0x7F);
          __pyx_t_3 = __pyx_t_1;
          __pyx_L7_bool_binop_done:;
          __pyx_v_current_bit = __pyx_t_3;

    +034:             target = (127 if current_bit else -128)

          __pyx_t_1 = (__pyx_v_current_bit != 0);
          if (__pyx_t_1) {
            __pyx_t_4 = 0x7F;
          } else {
            __pyx_t_4 = -128;
          }
          __pyx_v_target = __pyx_t_4;

     035:

    +036:             v1 = ((strength * (target - charge) + (1 << PREC - 1)) >> PREC)

          __pyx_v_v1 = (((__pyx_v_strength * (__pyx_v_target - __pyx_v_charge)) + (1 << (__pyx_v_5dfpwm_9convertor_PREC - 1))) >> __pyx_v_5dfpwm_9convertor_PREC);

     037:

    +038:             next_charge = charge + v1

          __pyx_v_next_charge = (__pyx_v_charge + __pyx_v_v1);

    +039:             if v1 == 0 and next_charge != target:

          __pyx_t_5 = (__pyx_v_v1 == 0);
          if (__pyx_t_5) {
          } else {
            __pyx_t_1 = __pyx_t_5;
            goto __pyx_L11_bool_binop_done;
          }
          __pyx_t_5 = (__pyx_v_next_charge != __pyx_v_target);
          __pyx_t_1 = __pyx_t_5;
          __pyx_L11_bool_binop_done:;
          if (__pyx_t_1) {
    /* … */
          }

    +040:                 next_charge += 1 if current_bit else -1

            __pyx_t_1 = (__pyx_v_current_bit != 0);
            if (__pyx_t_1) {
              __pyx_t_6 = 1;
            } else {
              __pyx_t_6 = -1L;
            }
            __pyx_v_next_charge = (__pyx_v_next_charge + __pyx_t_6);

     041:

    +042:             v2 = this_byte >> 1

          __pyx_v_v2 = (__pyx_v_this_byte >> 1);

     043:

    +044:             this_byte = v2 + 128 if current_bit else v2

          __pyx_t_1 = (__pyx_v_current_bit != 0);
          if (__pyx_t_1) {
            __pyx_t_6 = (__pyx_v_v2 + 0x80);
          } else {
            __pyx_t_6 = __pyx_v_v2;
          }
          __pyx_v_this_byte = __pyx_t_6;

     045:

    +046:             z = ((1 << PREC) - 1 if current_bit == previous_bit else 0)

          __pyx_t_1 = (__pyx_v_current_bit == __pyx_v_previous_bit);
          if (__pyx_t_1) {
            __pyx_t_6 = ((1 << __pyx_v_5dfpwm_9convertor_PREC) - 1);
          } else {
            __pyx_t_6 = 0;
          }
          __pyx_v_z = __pyx_t_6;

    +047:             next_strength = strength

          __pyx_v_next_strength = __pyx_v_strength;

     048:

    +049:             if strength != z:

          __pyx_t_1 = (__pyx_v_strength != __pyx_v_z);
          if (__pyx_t_1) {
    /* … */
          }

    +050:                 next_strength += 1 if current_bit == previous_bit else -1

            __pyx_t_1 = (__pyx_v_current_bit == __pyx_v_previous_bit);
            if (__pyx_t_1) {
              __pyx_t_6 = 1;
            } else {
              __pyx_t_6 = -1L;
            }
            __pyx_v_next_strength = (__pyx_v_next_strength + __pyx_t_6);

     051:

    +052:             v3 = 2 << (PREC - 8)

          __pyx_v_v3 = (2 << (__pyx_v_5dfpwm_9convertor_PREC - 8));

    +053:             if next_strength < v3:

          __pyx_t_1 = (__pyx_v_next_strength < __pyx_v_v3);
          if (__pyx_t_1) {
    /* … */
          }

    +054:                 next_strength = v3

            __pyx_v_next_strength = __pyx_v_v3;

     055:

    +056:             charge = next_charge

          __pyx_v_charge = __pyx_v_next_charge;

    +057:             strength = next_strength

          __pyx_v_strength = __pyx_v_next_strength;

    +058:             previous_bit = current_bit

          __pyx_v_previous_bit = __pyx_v_current_bit;

     059:

    +060:             j+=1

          __pyx_v_j = (__pyx_v_j + 1);
        }

     061:

    +062:         out[i] = this_byte

        (__pyx_v_out[__pyx_v_i]) = __pyx_v_this_byte;

     063:

    +064:         i += 1

        __pyx_v_i = (__pyx_v_i + 1);
      }

     065:

    +066:     return out

      __pyx_r = __pyx_v_out;
      goto __pyx_L0;

     067:

    +068: cpdef compressor(

    static PyObject *__pyx_pw_5dfpwm_9convertor_1compressor(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 PyObject *__pyx_f_5dfpwm_9convertor_compressor(PyObject *__pyx_v_in_array, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_5dfpwm_9convertor_compressor *__pyx_optional_args) {
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __PYX_XCLEAR_MEMVIEW(&__pyx_t_2, 1);
      __Pyx_XDECREF(__pyx_t_4);
      __Pyx_XDECREF(__pyx_t_5);
      __Pyx_XDECREF(__pyx_t_6);
      __Pyx_XDECREF(__pyx_t_7);
      __Pyx_XDECREF((PyObject *)__pyx_t_16);
      __Pyx_XDECREF(__pyx_t_17);
      __Pyx_AddTraceback("dfpwm.convertor.compressor", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = 0;
      __pyx_L0:;
      __PYX_XCLEAR_MEMVIEW(&__pyx_v_in_array_view, 1);
      __Pyx_XDECREF((PyObject *)__pyx_v_result);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    /* Python wrapper */
    static PyObject *__pyx_pw_5dfpwm_9convertor_1compressor(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_5dfpwm_9convertor_1compressor = {"compressor", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_5dfpwm_9convertor_1compressor, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0};
    static PyObject *__pyx_pw_5dfpwm_9convertor_1compressor(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_in_array = 0;
      PyObject *__pyx_v_tracker = 0;
      #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("compressor (wrapper)", 0);
      #if !CYTHON_METH_FASTCALL
      #if CYTHON_ASSUME_SAFE_MACROS
      __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 **__pyx_pyargnames[] = {&__pyx_n_s_in_array,&__pyx_n_s_tracker,0};
      PyObject* values[2] = {0,0};
    /* … */
      /* function exit code */
      {
        Py_ssize_t __pyx_temp;
        for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
          __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
        }
      }
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_5dfpwm_9convertor_compressor(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_in_array, PyObject *__pyx_v_tracker) {
      PyObject *__pyx_r = NULL;
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_2.__pyx_n = 1;
      __pyx_t_2.tracker = __pyx_v_tracker;
      __pyx_t_1 = __pyx_f_5dfpwm_9convertor_compressor(__pyx_v_in_array, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 68, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_r = __pyx_t_1;
      __pyx_t_1 = 0;
      goto __pyx_L0;

      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_AddTraceback("dfpwm.convertor.compressor", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }
    /* … */
      __pyx_tuple__28 = PyTuple_Pack(2, __pyx_n_s_in_array, __pyx_n_s_tracker); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 68, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_tuple__28);
      __Pyx_GIVEREF(__pyx_tuple__28);
      __pyx_codeobj__29 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_dfpwm_convertor_pyx, __pyx_n_s_compressor, 68, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__29)) __PYX_ERR(0, 68, __pyx_L1_error)
    /* … */
      __pyx_t_7 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 68, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_in_array, __pyx_kp_s_np_ndarray_np_float32) < 0) __PYX_ERR(0, 68, __pyx_L1_error)
      if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_tracker, __pyx_kp_s_typing_Callable_typing_Iterable) < 0) __PYX_ERR(0, 68, __pyx_L1_error)
      __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_5dfpwm_9convertor_1compressor, 0, __pyx_n_s_compressor, NULL, __pyx_n_s_dfpwm_convertor, __pyx_d, ((PyObject *)__pyx_codeobj__29)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 68, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_4, __pyx_tuple__30);
      __Pyx_CyFunction_SetAnnotationsDict(__pyx_t_4, __pyx_t_7);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_compressor, __pyx_t_4) < 0) __PYX_ERR(0, 68, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    /* … */
    struct __pyx_opt_args_5dfpwm_9convertor_compressor {
      int __pyx_n;
      PyObject *tracker;
    };

     069:         in_array: np.ndarray[np.float32],

    +070:         tracker: "typing.Callable"[["typing.Iterable"], "typing.Iterable"] = None

      PyObject *__pyx_v_tracker = ((PyObject *)Py_None);
      int __pyx_v_charge;
      int __pyx_v_strength;
      char __pyx_v_previous_bit;
      size_t __pyx_v_sz;
      __Pyx_memviewslice __pyx_v_in_array_view = { 0, 0, { 0 }, { 0 }, { 0 } };
      short *__pyx_v_out_array;
      size_t __pyx_v_i;
      size_t __pyx_v_j;
      float __pyx_v_level;
      short __pyx_v_this_byte;
      char __pyx_v_current_bit;
      int __pyx_v_next_charge;
      int __pyx_v_next_strength;
      int __pyx_v_target;
      int __pyx_v_v1;
      int __pyx_v_v2;
      long __pyx_v_z;
      long __pyx_v_v3;
      short *__pyx_v_array;
      PyArrayObject *__pyx_v_result = 0;
      PyObject *__pyx_r = NULL;
      if (__pyx_optional_args) {
        if (__pyx_optional_args->__pyx_n > 0) {
          __pyx_v_tracker = __pyx_optional_args->tracker;
        }
      }
    /* … */
        values[1] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None));
        if (__pyx_kwds) {
          Py_ssize_t kw_args;
          switch (__pyx_nargs) {
            case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
            CYTHON_FALLTHROUGH;
            case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds);
          switch (__pyx_nargs) {
            case  0:
            if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_in_array)) != 0)) {
              (void)__Pyx_Arg_NewRef_FASTCALL(values[0]);
              kw_args--;
            }
            else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 68, __pyx_L3_error)
            else goto __pyx_L5_argtuple_error;
            CYTHON_FALLTHROUGH;
            case  1:
            if (kw_args > 0) {
              PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_tracker);
              if (value) { values[1] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; }
              else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 68, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            const Py_ssize_t kwd_pos_args = __pyx_nargs;
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "compressor") < 0)) __PYX_ERR(0, 68, __pyx_L3_error)
          }
        } else {
          switch (__pyx_nargs) {
            case  2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1);
            CYTHON_FALLTHROUGH;
            case  1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0);
            break;
            default: goto __pyx_L5_argtuple_error;
          }
        }
        __pyx_v_in_array = values[0];
        __pyx_v_tracker = values[1];
      }
      goto __pyx_L6_skip;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("compressor", 0, 1, 2, __pyx_nargs); __PYX_ERR(0, 68, __pyx_L3_error)
      __pyx_L6_skip:;
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L3_error:;
      {
        Py_ssize_t __pyx_temp;
        for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
          __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]);
        }
      }
      __Pyx_AddTraceback("dfpwm.convertor.compressor", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return NULL;
      __pyx_L4_argument_unpacking_done:;
      __pyx_r = __pyx_pf_5dfpwm_9convertor_compressor(__pyx_self, __pyx_v_in_array, __pyx_v_tracker);

     071: ):

    +072:     cdef int charge = 0

      __pyx_v_charge = 0;

    +073:     cdef int strength = 0

      __pyx_v_strength = 0;

    +074:     cdef char previous_bit = False

      __pyx_v_previous_bit = 0;

     075:

    +076:     cdef size_t sz = len(in_array) // 8

      __pyx_t_1 = PyObject_Length(__pyx_v_in_array); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 76, __pyx_L1_error)
      __pyx_v_sz = __Pyx_div_Py_ssize_t(__pyx_t_1, 8);

    +077:     cdef const float [:] in_array_view = in_array

      __pyx_t_2 = __Pyx_PyObject_to_MemoryviewSlice_ds_float__const__(__pyx_v_in_array, 0); if (unlikely(!__pyx_t_2.memview)) __PYX_ERR(0, 77, __pyx_L1_error)
      __pyx_v_in_array_view = __pyx_t_2;
      __pyx_t_2.memview = NULL;
      __pyx_t_2.data = NULL;

     078:

    +079:     cdef short *out_array = <short*>malloc(sizeof(short) * sz)

      __pyx_v_out_array = ((short *)malloc(((sizeof(short)) * __pyx_v_sz)));

     080:

     081:     cdef size_t i

     082:     cdef size_t j

     083:     cdef float level

     084:     cdef short this_byte

     085:     cdef char current_bit

     086:     cdef int next_charge

     087:     cdef int next_strength

     088:     cdef int target

     089:     cdef int v1, v2

     090:

    +091:     if tracker:

      __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_tracker); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 91, __pyx_L1_error)
      if (__pyx_t_3) {
    /* … */
        goto __pyx_L3;
      }

    +092:         for i in tracker(range(sz)):

        __pyx_t_5 = __Pyx_PyInt_FromSize_t(__pyx_v_sz); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 92, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_builtin_range, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 92, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_INCREF(__pyx_v_tracker);
        __pyx_t_5 = __pyx_v_tracker; __pyx_t_7 = NULL;
        __pyx_t_8 = 0;
        #if CYTHON_UNPACK_METHODS
        if (unlikely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_5);
          if (likely(__pyx_t_7)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
            __Pyx_INCREF(__pyx_t_7);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_5, function);
            __pyx_t_8 = 1;
          }
        }
        #endif
        {
          PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_t_6};
          __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_8, 1+__pyx_t_8);
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 92, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        }
        if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
          __pyx_t_5 = __pyx_t_4; __Pyx_INCREF(__pyx_t_5);
          __pyx_t_1 = 0;
          __pyx_t_9 = NULL;
        } else {
          __pyx_t_1 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 92, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_9 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_5); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 92, __pyx_L1_error)
        }
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        for (;;) {
          if (likely(!__pyx_t_9)) {
            if (likely(PyList_CheckExact(__pyx_t_5))) {
              {
                Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_5);
                #if !CYTHON_ASSUME_SAFE_MACROS
                if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 92, __pyx_L1_error)
                #endif
                if (__pyx_t_1 >= __pyx_temp) break;
              }
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_4 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_1); __Pyx_INCREF(__pyx_t_4); __pyx_t_1++; if (unlikely((0 < 0))) __PYX_ERR(0, 92, __pyx_L1_error)
              #else
              __pyx_t_4 = __Pyx_PySequence_ITEM(__pyx_t_5, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 92, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_4);
              #endif
            } else {
              {
                Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_5);
                #if !CYTHON_ASSUME_SAFE_MACROS
                if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 92, __pyx_L1_error)
                #endif
                if (__pyx_t_1 >= __pyx_temp) break;
              }
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_1); __Pyx_INCREF(__pyx_t_4); __pyx_t_1++; if (unlikely((0 < 0))) __PYX_ERR(0, 92, __pyx_L1_error)
              #else
              __pyx_t_4 = __Pyx_PySequence_ITEM(__pyx_t_5, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 92, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_4);
              #endif
            }
          } else {
            __pyx_t_4 = __pyx_t_9(__pyx_t_5);
            if (unlikely(!__pyx_t_4)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 92, __pyx_L1_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_4);
          }
          __pyx_t_10 = __Pyx_PyInt_As_size_t(__pyx_t_4); if (unlikely((__pyx_t_10 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 92, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __pyx_v_i = __pyx_t_10;
    /* … */
        }
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    +093:             this_byte = 0

          __pyx_v_this_byte = 0;

     094:

    +095:             for j in range(8):

          for (__pyx_t_10 = 0; __pyx_t_10 < 8; __pyx_t_10+=1) {
            __pyx_v_j = __pyx_t_10;

    +096:                 level = floor(in_array_view[i * 8 + j] * 127)

            __pyx_t_11 = ((__pyx_v_i * 8) + __pyx_v_j);
            __pyx_v_level = floor(((*((float const  *) ( /* dim=0 */ (__pyx_v_in_array_view.data + __pyx_t_11 * __pyx_v_in_array_view.strides[0]) ))) * 127.0));

     097:

    +098:                 current_bit = level > charge or (level == charge and charge == 127)

            __pyx_t_3 = (__pyx_v_level > __pyx_v_charge);
            if (!__pyx_t_3) {
            } else {
              __pyx_t_12 = __pyx_t_3;
              goto __pyx_L8_bool_binop_done;
            }
            __pyx_t_3 = (__pyx_v_level == __pyx_v_charge);
            if (__pyx_t_3) {
            } else {
              __pyx_t_12 = __pyx_t_3;
              goto __pyx_L8_bool_binop_done;
            }
            __pyx_t_3 = (__pyx_v_charge == 0x7F);
            __pyx_t_12 = __pyx_t_3;
            __pyx_L8_bool_binop_done:;
            __pyx_v_current_bit = __pyx_t_12;

    +099:                 target = (127 if current_bit else -128)

            __pyx_t_3 = (__pyx_v_current_bit != 0);
            if (__pyx_t_3) {
              __pyx_t_8 = 0x7F;
            } else {
              __pyx_t_8 = -128;
            }
            __pyx_v_target = __pyx_t_8;

     100:

    +101:                 v1 = ((strength * (target - charge) + (1 << PREC - 1)) >> PREC)

            __pyx_v_v1 = (((__pyx_v_strength * (__pyx_v_target - __pyx_v_charge)) + (1 << (__pyx_v_5dfpwm_9convertor_PREC - 1))) >> __pyx_v_5dfpwm_9convertor_PREC);

     102:

    +103:                 next_charge = charge + v1

            __pyx_v_next_charge = (__pyx_v_charge + __pyx_v_v1);

    +104:                 if v1 == 0 and next_charge != target:

            __pyx_t_13 = (__pyx_v_v1 == 0);
            if (__pyx_t_13) {
            } else {
              __pyx_t_3 = __pyx_t_13;
              goto __pyx_L12_bool_binop_done;
            }
            __pyx_t_13 = (__pyx_v_next_charge != __pyx_v_target);
            __pyx_t_3 = __pyx_t_13;
            __pyx_L12_bool_binop_done:;
            if (__pyx_t_3) {
    /* … */
            }

    +105:                     next_charge += 1 if current_bit else -1

              __pyx_t_3 = (__pyx_v_current_bit != 0);
              if (__pyx_t_3) {
                __pyx_t_14 = 1;
              } else {
                __pyx_t_14 = -1L;
              }
              __pyx_v_next_charge = (__pyx_v_next_charge + __pyx_t_14);

     106:

    +107:                 v2 = this_byte >> 1

            __pyx_v_v2 = (__pyx_v_this_byte >> 1);

     108:

    +109:                 this_byte = v2 + 128 if current_bit else v2

            __pyx_t_3 = (__pyx_v_current_bit != 0);
            if (__pyx_t_3) {
              __pyx_t_14 = (__pyx_v_v2 + 0x80);
            } else {
              __pyx_t_14 = __pyx_v_v2;
            }
            __pyx_v_this_byte = __pyx_t_14;

     110:

    +111:                 z = ((1 << PREC) - 1 if current_bit == previous_bit else 0)

            __pyx_t_3 = (__pyx_v_current_bit == __pyx_v_previous_bit);
            if (__pyx_t_3) {
              __pyx_t_14 = ((1 << __pyx_v_5dfpwm_9convertor_PREC) - 1);
            } else {
              __pyx_t_14 = 0;
            }
            __pyx_v_z = __pyx_t_14;

    +112:                 next_strength = strength

            __pyx_v_next_strength = __pyx_v_strength;

     113:

    +114:                 if strength != z:

            __pyx_t_3 = (__pyx_v_strength != __pyx_v_z);
            if (__pyx_t_3) {
    /* … */
            }

    +115:                     next_strength += 1 if current_bit == previous_bit else -1

              __pyx_t_3 = (__pyx_v_current_bit == __pyx_v_previous_bit);
              if (__pyx_t_3) {
                __pyx_t_14 = 1;
              } else {
                __pyx_t_14 = -1L;
              }
              __pyx_v_next_strength = (__pyx_v_next_strength + __pyx_t_14);

     116:

    +117:                 v3 = 2 << (PREC - 8)

            __pyx_v_v3 = (2 << (__pyx_v_5dfpwm_9convertor_PREC - 8));

    +118:                 if next_strength < v3:

            __pyx_t_3 = (__pyx_v_next_strength < __pyx_v_v3);
            if (__pyx_t_3) {
    /* … */
            }

    +119:                     next_strength = v3

              __pyx_v_next_strength = __pyx_v_v3;

     120:

    +121:                 charge = next_charge

            __pyx_v_charge = __pyx_v_next_charge;

    +122:                 strength = next_strength

            __pyx_v_strength = __pyx_v_next_strength;

    +123:                 previous_bit = current_bit

            __pyx_v_previous_bit = __pyx_v_current_bit;
          }

     124:

    +125:             out_array[i] = this_byte

          (__pyx_v_out_array[__pyx_v_i]) = __pyx_v_this_byte;

     126:     else:

    +127:         free(<void*>out_array)

      /*else*/ {
        free(((void *)__pyx_v_out_array));

    +128:         array = proc_untracked(in_array_view, sz)

        __pyx_t_15 = __pyx_f_5dfpwm_9convertor_proc_untracked(__pyx_v_in_array_view, __pyx_v_sz); if (unlikely(__pyx_t_15 == ((short *)NULL) && PyErr_Occurred())) __PYX_ERR(0, 128, __pyx_L1_error)
        __pyx_v_array = __pyx_t_15;

    +129:         out_array = array

        __pyx_v_out_array = __pyx_v_array;
      }
      __pyx_L3:;

     130:

    +131:     cdef np.ndarray result = np.asarray(<short[:sz]>out_array).astype('int8')

      __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_np); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 131, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_asarray); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 131, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (!__pyx_v_out_array) {
        PyErr_SetString(PyExc_ValueError,"Cannot create cython.array from NULL pointer");
        __PYX_ERR(0, 131, __pyx_L1_error)
      }
      __pyx_t_17 = __pyx_format_from_typeinfo(&__Pyx_TypeInfo_short); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 131, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_17);
      __pyx_t_6 = Py_BuildValue((char*) "("  __PYX_BUILD_PY_SSIZE_T  ")", ((Py_ssize_t)__pyx_v_sz)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 131, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_16 = __pyx_array_new(__pyx_t_6, sizeof(short), PyBytes_AS_STRING(__pyx_t_17), (char *) "c", (char *) __pyx_v_out_array); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 131, __pyx_L1_error)
      __Pyx_GOTREF((PyObject *)__pyx_t_16);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      __pyx_t_17 = NULL;
      __pyx_t_8 = 0;
      #if CYTHON_UNPACK_METHODS
      if (unlikely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_17)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_17);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
          __pyx_t_8 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_17, ((PyObject *)__pyx_t_16)};
        __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_8, 1+__pyx_t_8);
        __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
        __Pyx_DECREF((PyObject *)__pyx_t_16); __pyx_t_16 = 0;
        if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 131, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_astype); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 131, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = NULL;
      __pyx_t_8 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_7))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_7, function);
          __pyx_t_8 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_n_u_int8};
        __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_8, 1+__pyx_t_8);
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 131, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
      if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 131, __pyx_L1_error)
      __pyx_v_result = ((PyArrayObject *)__pyx_t_5);
      __pyx_t_5 = 0;

    +132:     free(<void*>array)

      free(((void *)__pyx_v_array));

    +133:     return result

      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF((PyObject *)__pyx_v_result);
      __pyx_r = ((PyObject *)__pyx_v_result);
      goto __pyx_L0;