Generated by Cython 0.26
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: containers.cpp
+001: """Data types for chart items, edges, &c."""
__pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(1, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
002: from __future__ import print_function
+003: import io
__pyx_t_1 = __Pyx_Import(__pyx_n_s_io, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_io, __pyx_t_1) < 0) __PYX_ERR(1, 3, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+004: import os
__pyx_t_1 = __Pyx_Import(__pyx_n_s_os, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_1) < 0) __PYX_ERR(1, 4, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+005: import re
__pyx_t_1 = __Pyx_Import(__pyx_n_s_re, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_re, __pyx_t_1) < 0) __PYX_ERR(1, 5, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+006: import mmap
__pyx_t_1 = __Pyx_Import(__pyx_n_s_mmap, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_mmap, __pyx_t_1) < 0) __PYX_ERR(1, 6, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+007: import logging
__pyx_t_1 = __Pyx_Import(__pyx_n_s_logging, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 7, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_logging, __pyx_t_1) < 0) __PYX_ERR(1, 7, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+008: import numpy as np
__pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 8, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(1, 8, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+009: from array import array
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 9, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_n_s_array); __Pyx_GIVEREF(__pyx_n_s_array); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_array); __pyx_t_2 = __Pyx_Import(__pyx_n_s_array, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 9, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+010: from math import isinf, fsum
__pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_isinf); __Pyx_GIVEREF(__pyx_n_s_isinf); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_isinf); __Pyx_INCREF(__pyx_n_s_fsum); __Pyx_GIVEREF(__pyx_n_s_fsum); PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_fsum); __pyx_t_1 = __Pyx_Import(__pyx_n_s_math, __pyx_t_2, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_isinf); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_isinf, __pyx_t_2) < 0) __PYX_ERR(1, 10, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_fsum); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 10, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_fsum, __pyx_t_2) < 0) __PYX_ERR(1, 10, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+011: from roaringbitmap import RoaringBitmap, MultiRoaringBitmap
__pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_n_s_RoaringBitmap); __Pyx_GIVEREF(__pyx_n_s_RoaringBitmap); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_RoaringBitmap); __Pyx_INCREF(__pyx_n_s_MultiRoaringBitmap); __Pyx_GIVEREF(__pyx_n_s_MultiRoaringBitmap); PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_MultiRoaringBitmap); __pyx_t_2 = __Pyx_Import(__pyx_n_s_roaringbitmap, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_RoaringBitmap); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_RoaringBitmap, __pyx_t_1) < 0) __PYX_ERR(1, 11, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_MultiRoaringBitmap); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 11, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_MultiRoaringBitmap, __pyx_t_1) < 0) __PYX_ERR(1, 11, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+012: from .tree import escape, unescape
__pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_escape); __Pyx_GIVEREF(__pyx_n_s_escape); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_escape); __Pyx_INCREF(__pyx_n_s_unescape); __Pyx_GIVEREF(__pyx_n_s_unescape); PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_unescape); __pyx_t_1 = __Pyx_Import(__pyx_n_s_tree, __pyx_t_2, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_escape); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_escape, __pyx_t_2) < 0) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_unescape); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_unescape, __pyx_t_2) < 0) __PYX_ERR(1, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+013: from .util import readbytes
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_n_s_readbytes); __Pyx_GIVEREF(__pyx_n_s_readbytes); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_readbytes); __pyx_t_2 = __Pyx_Import(__pyx_n_s_util, __pyx_t_1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_readbytes); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_readbytes, __pyx_t_1) < 0) __PYX_ERR(1, 13, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+014: from .tree import Tree
__pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_Tree); __Pyx_GIVEREF(__pyx_n_s_Tree); PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_Tree); __pyx_t_1 = __Pyx_Import(__pyx_n_s_tree, __pyx_t_2, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_Tree); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_Tree, __pyx_t_2) < 0) __PYX_ERR(1, 14, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
015: cimport cython
016: from cython.operator cimport dereference
017: from libc.string cimport strchr
018: include "constants.pxi"
019:
+020: cdef array chararray = array('b')
__pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7cpython_5array_array), __pyx_tuple__63, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 20, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XGOTREF(((PyObject *)__pyx_v_8discodop_10containers_chararray)); __Pyx_DECREF_SET(__pyx_v_8discodop_10containers_chararray, ((arrayobject *)__pyx_t_1)); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; /* … */ __pyx_tuple__63 = PyTuple_Pack(1, __pyx_n_u_b); if (unlikely(!__pyx_tuple__63)) __PYX_ERR(1, 20, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__63); __Pyx_GIVEREF(__pyx_tuple__63);
+021: cdef array dblarray = array('d')
__pyx_t_1 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_7cpython_5array_array), __pyx_tuple__64, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 21, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XGOTREF(((PyObject *)__pyx_v_8discodop_10containers_dblarray)); __Pyx_DECREF_SET(__pyx_v_8discodop_10containers_dblarray, ((arrayobject *)__pyx_t_1)); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; /* … */ __pyx_tuple__64 = PyTuple_Pack(1, __pyx_n_u_d); if (unlikely(!__pyx_tuple__64)) __PYX_ERR(1, 21, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__64); __Pyx_GIVEREF(__pyx_tuple__64);
+022: cdef int maxbitveclen = SLOTS * sizeof(uint64_t) * 8
__pyx_v_8discodop_10containers_maxbitveclen = ((2 * (sizeof(uint64_t))) * 8);
023:
024: include "_grammar.pxi"
025:
026:
+027: cdef SmallChartItem CFGtoSmallChartItem(Label label, Idx start, Idx end):
static SmallChartItem __pyx_f_8discodop_10containers_CFGtoSmallChartItem(Label __pyx_v_label, __pyx_t_8discodop_10containers_Idx __pyx_v_start, __pyx_t_8discodop_10containers_Idx __pyx_v_end) {
SmallChartItem __pyx_v_result;
SmallChartItem __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("CFGtoSmallChartItem", 0);
/* … */
/* function exit code */
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+028: cdef SmallChartItem result = SmallChartItem(
__pyx_v_result = SmallChartItem(__pyx_v_label, ((1UL << __pyx_v_end) - (1UL << __pyx_v_start)));
029: label, (1UL << end) - (1UL << start))
+030: return result
__pyx_r = __pyx_v_result; goto __pyx_L0;
031:
032:
+033: cdef FatChartItem CFGtoFatChartItem(Label label, Idx start, Idx end):
static FatChartItem __pyx_f_8discodop_10containers_CFGtoFatChartItem(Label __pyx_v_label, __pyx_t_8discodop_10containers_Idx __pyx_v_start, __pyx_t_8discodop_10containers_Idx __pyx_v_end) {
FatChartItem __pyx_v_fci;
short __pyx_v_n;
FatChartItem __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("CFGtoFatChartItem", 0);
/* … */
/* function exit code */
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+034: cdef FatChartItem fci = FatChartItem(label)
__pyx_v_fci = FatChartItem(__pyx_v_label);
035: cdef short n
+036: if BITSLOT(start) == BITSLOT(end):
__pyx_t_1 = ((BITSLOT(__pyx_v_start) == BITSLOT(__pyx_v_end)) != 0);
if (__pyx_t_1) {
/* … */
goto __pyx_L3;
}
+037: fci.vec[BITSLOT(start)] = (1UL << end) - (1UL << start)
(__pyx_v_fci.vec[BITSLOT(__pyx_v_start)]) = ((1UL << __pyx_v_end) - (1UL << __pyx_v_start));
038: else:
+039: fci.vec[BITSLOT(start)] = ~0UL << (start % BITSIZE)
/*else*/ {
(__pyx_v_fci.vec[BITSLOT(__pyx_v_start)]) = ((~0UL) << (__pyx_v_start % BITSIZE));
+040: for n in range(BITSLOT(start) + 1, BITSLOT(end)):
__pyx_t_2 = BITSLOT(__pyx_v_end);
for (__pyx_t_3 = (BITSLOT(__pyx_v_start) + 1); __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
__pyx_v_n = __pyx_t_3;
+041: fci.vec[n] = ~0UL
(__pyx_v_fci.vec[__pyx_v_n]) = (~0UL);
}
+042: fci.vec[BITSLOT(end)] = BITMASK(end) - 1
(__pyx_v_fci.vec[BITSLOT(__pyx_v_end)]) = (BITMASK(__pyx_v_end) - 1); } __pyx_L3:;
+043: return fci
__pyx_r = __pyx_v_fci; goto __pyx_L0;
044:
045:
+046: cdef class Chart:
struct __pyx_vtabstruct_8discodop_10containers_Chart {
int (*lexidx)(struct __pyx_obj_8discodop_10containers_Chart *, Edge);
Prob (*subtreeprob)(struct __pyx_obj_8discodop_10containers_Chart *, ItemNo);
Prob (*lexprob)(struct __pyx_obj_8discodop_10containers_Chart *, ItemNo, Edge);
PyObject *(*edgestr)(struct __pyx_obj_8discodop_10containers_Chart *, ItemNo, Edge);
ItemNo (*_left)(struct __pyx_obj_8discodop_10containers_Chart *, ItemNo, Edge);
ItemNo (*_right)(struct __pyx_obj_8discodop_10containers_Chart *, ItemNo, Edge);
ItemNo (*left)(struct __pyx_obj_8discodop_10containers_Chart *, RankedEdge);
ItemNo (*right)(struct __pyx_obj_8discodop_10containers_Chart *, RankedEdge);
Label (*label)(struct __pyx_obj_8discodop_10containers_Chart *, ItemNo);
ItemNo (*getitemidx)(struct __pyx_obj_8discodop_10containers_Chart *, uint64_t);
SmallChartItem (*asSmallChartItem)(struct __pyx_obj_8discodop_10containers_Chart *, ItemNo);
FatChartItem (*asFatChartItem)(struct __pyx_obj_8discodop_10containers_Chart *, ItemNo);
size_t (*asCFGspan)(struct __pyx_obj_8discodop_10containers_Chart *, ItemNo);
};
static struct __pyx_vtabstruct_8discodop_10containers_Chart *__pyx_vtabptr_8discodop_10containers_Chart;
047: """Base class for charts. Provides methods available on all charts.
048:
049: The subclass hierarchy for charts has three levels:
050:
051: (0) base class, methods for chart traversal.
052: (1) formalism, methods specific to CFG vs. LCFRS parsers.
053: (2) data structures optimized for short/long sentences, small/large
054: grammars.
055:
056: Level 1/2 defines a type for labeled spans referred to as ``item``."""
+057: def root(self):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_5Chart_1root(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_8discodop_10containers_5Chart_root[] = "Chart.root(self)\nReturn item with root label spanning the whole sentence.";
static PyObject *__pyx_pw_8discodop_10containers_5Chart_1root(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("root (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_5Chart_root(((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_5Chart_root(CYTHON_UNUSED struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("root", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_AddTraceback("discodop.containers.Chart.root", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
058: """Return item with root label spanning the whole sentence."""
+059: raise NotImplementedError
__Pyx_Raise(__pyx_builtin_NotImplementedError, 0, 0, 0);
__PYX_ERR(1, 59, __pyx_L1_error)
060:
+061: cdef ItemNo _left(self, ItemNo itemidx, Edge edge):
static ItemNo __pyx_f_8discodop_10containers_5Chart__left(CYTHON_UNUSED struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self, CYTHON_UNUSED ItemNo __pyx_v_itemidx, CYTHON_UNUSED Edge __pyx_v_edge) {
ItemNo __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("_left", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_WriteUnraisable("discodop.containers.Chart._left", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
__pyx_r = 0;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
062: """Return the left item that edge points to."""
+063: raise NotImplementedError
__Pyx_Raise(__pyx_builtin_NotImplementedError, 0, 0, 0);
__PYX_ERR(1, 63, __pyx_L1_error)
064:
+065: cdef ItemNo _right(self, ItemNo itemidx, Edge edge):
static ItemNo __pyx_f_8discodop_10containers_5Chart__right(CYTHON_UNUSED struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self, CYTHON_UNUSED ItemNo __pyx_v_itemidx, CYTHON_UNUSED Edge __pyx_v_edge) {
ItemNo __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("_right", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_WriteUnraisable("discodop.containers.Chart._right", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
__pyx_r = 0;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
066: """Return the right item that edge points to."""
+067: raise NotImplementedError
__Pyx_Raise(__pyx_builtin_NotImplementedError, 0, 0, 0);
__PYX_ERR(1, 67, __pyx_L1_error)
068:
+069: cdef Label label(self, ItemNo itemidx):
static Label __pyx_f_8discodop_10containers_5Chart_label(CYTHON_UNUSED struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self, CYTHON_UNUSED ItemNo __pyx_v_itemidx) {
Label __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("label", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_WriteUnraisable("discodop.containers.Chart.label", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
__pyx_r = 0;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+070: raise NotImplementedError
__Pyx_Raise(__pyx_builtin_NotImplementedError, 0, 0, 0);
__PYX_ERR(1, 70, __pyx_L1_error)
071:
+072: cdef Prob subtreeprob(self, ItemNo itemidx):
static Prob __pyx_f_8discodop_10containers_5Chart_subtreeprob(CYTHON_UNUSED struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self, CYTHON_UNUSED ItemNo __pyx_v_itemidx) {
Prob __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("subtreeprob", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_WriteUnraisable("discodop.containers.Chart.subtreeprob", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
__pyx_r = 0;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
073: """Return probability of subtree headed by item."""
+074: raise NotImplementedError
__Pyx_Raise(__pyx_builtin_NotImplementedError, 0, 0, 0);
__PYX_ERR(1, 74, __pyx_L1_error)
075:
+076: cdef ItemNo left(self, RankedEdge rankededge):
static ItemNo __pyx_f_8discodop_10containers_5Chart_left(struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self, RankedEdge __pyx_v_rankededge) {
ItemNo __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("left", 0);
/* … */
/* function exit code */
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
077: """Given a ranked edge, return the left item it points to."""
+078: return self._left(rankededge.head, rankededge.edge)
__pyx_r = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_self->__pyx_vtab)->_left(__pyx_v_self, __pyx_v_rankededge.head, __pyx_v_rankededge.edge); goto __pyx_L0;
079:
+080: cdef ItemNo right(self, RankedEdge rankededge):
static ItemNo __pyx_f_8discodop_10containers_5Chart_right(struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self, RankedEdge __pyx_v_rankededge) {
ItemNo __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("right", 0);
/* … */
/* function exit code */
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
081: """Given a ranked edge, return the right item it points to."""
+082: return self._right(rankededge.head, rankededge.edge)
__pyx_r = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_self->__pyx_vtab)->_right(__pyx_v_self, __pyx_v_rankededge.head, __pyx_v_rankededge.edge); goto __pyx_L0;
083:
+084: cdef ItemNo getitemidx(self, uint64_t n):
static ItemNo __pyx_f_8discodop_10containers_5Chart_getitemidx(CYTHON_UNUSED struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self, uint64_t __pyx_v_n) {
ItemNo __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("getitemidx", 0);
/* … */
/* function exit code */
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
085: """Get itemidx of n'th item."""
+086: return n
__pyx_r = __pyx_v_n; goto __pyx_L0;
087:
+088: cdef SmallChartItem asSmallChartItem(self, ItemNo itemidx):
static SmallChartItem __pyx_f_8discodop_10containers_5Chart_asSmallChartItem(CYTHON_UNUSED struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self, CYTHON_UNUSED ItemNo __pyx_v_itemidx) {
SmallChartItem __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("asSmallChartItem", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_WriteUnraisable("discodop.containers.Chart.asSmallChartItem", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
__Pyx_pretend_to_initialize(&__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
089: """Convert/copy item to SmallChartItem instance."""
+090: raise NotImplementedError
__Pyx_Raise(__pyx_builtin_NotImplementedError, 0, 0, 0);
__PYX_ERR(1, 90, __pyx_L1_error)
091:
+092: cdef FatChartItem asFatChartItem(self, ItemNo itemidx):
static FatChartItem __pyx_f_8discodop_10containers_5Chart_asFatChartItem(CYTHON_UNUSED struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self, CYTHON_UNUSED ItemNo __pyx_v_itemidx) {
FatChartItem __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("asFatChartItem", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_WriteUnraisable("discodop.containers.Chart.asFatChartItem", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
__Pyx_pretend_to_initialize(&__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
093: """Convert/copy item to FatChartItem instance."""
+094: raise NotImplementedError
__Pyx_Raise(__pyx_builtin_NotImplementedError, 0, 0, 0);
__PYX_ERR(1, 94, __pyx_L1_error)
095:
+096: cdef size_t asCFGspan(self, ItemNo itemidx):
static size_t __pyx_f_8discodop_10containers_5Chart_asCFGspan(CYTHON_UNUSED struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self, CYTHON_UNUSED ItemNo __pyx_v_itemidx) {
size_t __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("asCFGspan", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_WriteUnraisable("discodop.containers.Chart.asCFGspan", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
__pyx_r = 0;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
097: """Convert item for chart to compact span."""
+098: raise NotImplementedError
__Pyx_Raise(__pyx_builtin_NotImplementedError, 0, 0, 0);
__PYX_ERR(1, 98, __pyx_L1_error)
099:
+100: def indices(self, item):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_5Chart_3indices(PyObject *__pyx_v_self, PyObject *__pyx_v_item); /*proto*/
static char __pyx_doc_8discodop_10containers_5Chart_2indices[] = "Chart.indices(self, item)\nReturn a list of indices dominated by ``item``.";
static PyObject *__pyx_pw_8discodop_10containers_5Chart_3indices(PyObject *__pyx_v_self, PyObject *__pyx_v_item) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("indices (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_5Chart_2indices(((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_self), ((PyObject *)__pyx_v_item));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_5Chart_2indices(CYTHON_UNUSED struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_item) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("indices", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_AddTraceback("discodop.containers.Chart.indices", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
101: """Return a list of indices dominated by ``item``."""
+102: raise NotImplementedError
__Pyx_Raise(__pyx_builtin_NotImplementedError, 0, 0, 0);
__PYX_ERR(1, 102, __pyx_L1_error)
103:
+104: cdef int lexidx(self, Edge edge) except -1:
static int __pyx_f_8discodop_10containers_5Chart_lexidx(struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self, Edge __pyx_v_edge) {
short __pyx_v_result;
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("lexidx", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_AddTraceback("discodop.containers.Chart.lexidx", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -1;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
105: """Return sentence index of the terminal child given a lexical edge."""
+106: cdef short result = edge.pos.mid - 1
__pyx_v_result = (__pyx_v_edge.pos.mid - 1);
+107: assert 0 <= result < self.lensent, (result, self.lensent)
#ifndef CYTHON_WITHOUT_ASSERTIONS
if (unlikely(!Py_OptimizeFlag)) {
__pyx_t_1 = (0 <= __pyx_v_result);
if (__pyx_t_1) {
__pyx_t_1 = (__pyx_v_result < __pyx_v_self->lensent);
}
if (unlikely(!(__pyx_t_1 != 0))) {
__pyx_t_2 = __Pyx_PyInt_From_short(__pyx_v_result); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 107, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = __Pyx_PyInt_From_short(__pyx_v_self->lensent); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 107, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 107, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_GIVEREF(__pyx_t_2);
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3);
__pyx_t_2 = 0;
__pyx_t_3 = 0;
__pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 107, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_GIVEREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
__pyx_t_4 = 0;
PyErr_SetObject(PyExc_AssertionError, __pyx_t_3);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__PYX_ERR(1, 107, __pyx_L1_error)
}
}
#endif
+108: return result
__pyx_r = __pyx_v_result; goto __pyx_L0;
109:
+110: cdef Prob lexprob(self, ItemNo itemidx, Edge edge) except -1:
static Prob __pyx_f_8discodop_10containers_5Chart_lexprob(struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self, ItemNo __pyx_v_itemidx, Edge __pyx_v_edge) {
Label __pyx_v_label;
std::string __pyx_v_word;
Prob __pyx_v_prob;
spp::sparse_hash_map<Label,spp::sparse_hash_map<std::string,uint32_t> > ::iterator __pyx_v_it;
spp::sparse_hash_map<std::string,uint32_t> ::iterator __pyx_v_it2;
Prob __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("lexprob", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_AddTraceback("discodop.containers.Chart.lexprob", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -1.0;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
111: """Return lexical probability given a lexical edge."""
+112: cdef Label label = self.label(itemidx)
__pyx_v_label = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_self->__pyx_vtab)->label(__pyx_v_self, __pyx_v_itemidx);
+113: cdef string word = self.sent[self.lexidx(edge)].encode('utf8')
if (unlikely(__pyx_v_self->sent == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(1, 113, __pyx_L1_error)
}
__pyx_t_1 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_self->__pyx_vtab)->lexidx(__pyx_v_self, __pyx_v_edge); if (unlikely(__pyx_t_1 == -1)) __PYX_ERR(1, 113, __pyx_L1_error)
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(PyList_GET_ITEM(__pyx_v_self->sent, __pyx_t_1), __pyx_n_s_encode); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 113, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 113, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_4 = __pyx_convert_string_from_py_std__in_string(__pyx_t_3); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 113, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_v_word = __pyx_t_4;
/* … */
__pyx_tuple__26 = PyTuple_Pack(1, __pyx_n_u_utf8); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(1, 113, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__26);
__Pyx_GIVEREF(__pyx_tuple__26);
114: cdef Prob prob
+115: it = self.grammar.lexicalbylhs.find(label)
__pyx_v_it = __pyx_v_self->grammar->lexicalbylhs.find(__pyx_v_label);
+116: if it != self.grammar.lexicalbylhs.end():
__pyx_t_5 = ((__pyx_v_it != __pyx_v_self->grammar->lexicalbylhs.end()) != 0);
if (__pyx_t_5) {
/* … */
}
+117: it2 = dereference(it).second.find(word)
__pyx_v_it2 = (*__pyx_v_it).second.find(__pyx_v_word);
+118: if it2 != dereference(it).second.end():
__pyx_t_5 = ((__pyx_v_it2 != (*__pyx_v_it).second.end()) != 0);
if (__pyx_t_5) {
/* … */
}
+119: prob = self.grammar.lexical[dereference(it2).second].prob
__pyx_t_6 = (__pyx_v_self->grammar->lexical[(*__pyx_v_it2).second]).prob;
__pyx_v_prob = __pyx_t_6;
+120: return exp(-prob) if self.logprob else prob
if ((__pyx_v_self->logprob != 0)) {
__pyx_t_6 = exp((-__pyx_v_prob));
} else {
__pyx_t_6 = __pyx_v_prob;
}
__pyx_r = __pyx_t_6;
goto __pyx_L0;
+121: return 0 if self.logprob else 1
if ((__pyx_v_self->logprob != 0)) {
__pyx_t_6 = 0.0;
} else {
__pyx_t_6 = 1.0;
}
__pyx_r = __pyx_t_6;
goto __pyx_L0;
122:
+123: def numitems(self):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_5Chart_5numitems(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_8discodop_10containers_5Chart_4numitems[] = "Chart.numitems(self)\nNumber of items in chart; NB: this includes 1 sentinel item.";
static PyObject *__pyx_pw_8discodop_10containers_5Chart_5numitems(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("numitems (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_5Chart_4numitems(((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_5Chart_4numitems(struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("numitems", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("discodop.containers.Chart.numitems", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
124: """Number of items in chart; NB: this includes 1 sentinel item."""
+125: return self.parseforest.size()
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyInt_FromSize_t(__pyx_v_self->parseforest.size()); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
126:
+127: def hasnode(self, node, Whitelist whitelist=None):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_5Chart_7hasnode(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8discodop_10containers_5Chart_6hasnode[] = "Chart.hasnode(self, node, Whitelist whitelist=None)\nCheck if Tree node with integer indices is in the chart.";
static PyObject *__pyx_pw_8discodop_10containers_5Chart_7hasnode(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
CYTHON_UNUSED PyObject *__pyx_v_node = 0;
CYTHON_UNUSED struct __pyx_obj_8discodop_10containers_Whitelist *__pyx_v_whitelist = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("hasnode (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_node,&__pyx_n_s_whitelist,0};
PyObject* values[2] = {0,0};
values[1] = (PyObject *)((struct __pyx_obj_8discodop_10containers_Whitelist *)Py_None);
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_node)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_whitelist);
if (value) { values[1] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "hasnode") < 0)) __PYX_ERR(1, 127, __pyx_L3_error)
}
} else {
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
break;
default: goto __pyx_L5_argtuple_error;
}
}
__pyx_v_node = values[0];
__pyx_v_whitelist = ((struct __pyx_obj_8discodop_10containers_Whitelist *)values[1]);
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("hasnode", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 127, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("discodop.containers.Chart.hasnode", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_whitelist), __pyx_ptype_8discodop_10containers_Whitelist, 1, "whitelist", 0))) __PYX_ERR(1, 127, __pyx_L1_error)
__pyx_r = __pyx_pf_8discodop_10containers_5Chart_6hasnode(((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_self), __pyx_v_node, __pyx_v_whitelist);
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_5Chart_6hasnode(CYTHON_UNUSED struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_node, CYTHON_UNUSED struct __pyx_obj_8discodop_10containers_Whitelist *__pyx_v_whitelist) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("hasnode", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_AddTraceback("discodop.containers.Chart.hasnode", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
128: """Check if Tree node with integer indices is in the chart."""
+129: raise NotImplementedError
__Pyx_Raise(__pyx_builtin_NotImplementedError, 0, 0, 0);
__PYX_ERR(1, 129, __pyx_L1_error)
130:
+131: def __bool__(self):
/* Python wrapper */
static int __pyx_pw_8discodop_10containers_5Chart_9__bool__(PyObject *__pyx_v_self); /*proto*/
static int __pyx_pw_8discodop_10containers_5Chart_9__bool__(PyObject *__pyx_v_self) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__bool__ (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_5Chart_8__bool__(((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static int __pyx_pf_8discodop_10containers_5Chart_8__bool__(struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__bool__", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_AddTraceback("discodop.containers.Chart.__bool__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -1;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
132: """Return true when the root item is in the chart.
133:
134: i.e., test whether sentence has been parsed successfully."""
+135: return self.root() in self
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 135, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } if (__pyx_t_3) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 135, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 135, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_t_1, ((PyObject *)__pyx_v_self), Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(1, 135, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_4; goto __pyx_L0;
136:
+137: def __contains__(self, item):
/* Python wrapper */
static int __pyx_pw_8discodop_10containers_5Chart_11__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_item); /*proto*/
static char __pyx_doc_8discodop_10containers_5Chart_10__contains__[] = "Return true when item is in the chart.";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_8discodop_10containers_5Chart_10__contains__;
#endif
static int __pyx_pw_8discodop_10containers_5Chart_11__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_item) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__contains__ (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_5Chart_10__contains__(((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_self), ((PyObject *)__pyx_v_item));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static int __pyx_pf_8discodop_10containers_5Chart_10__contains__(struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self, PyObject *__pyx_v_item) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__contains__", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_AddTraceback("discodop.containers.Chart.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -1;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
138: """Return true when item is in the chart."""
+139: return (item is not None
__pyx_t_2 = (__pyx_v_item != Py_None);
if (__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L3_bool_binop_done;
}
+140: and item < self.parseforest.size()
__pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_v_self->parseforest.size()); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 140, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyObject_RichCompare(__pyx_v_item, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 140, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(1, 140, __pyx_L1_error) if (__pyx_t_2) { __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 140, __pyx_L1_error) __pyx_t_1 = __pyx_t_5; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L3_bool_binop_done; }
+141: and self.parseforest[item].size() != 0)
__pyx_t_6 = __Pyx_PyInt_As_size_t(__pyx_v_item); if (unlikely((__pyx_t_6 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 141, __pyx_L1_error) __pyx_t_2 = ((__pyx_v_self->parseforest[__pyx_t_6]).size() != 0); __pyx_t_1 = __pyx_t_2; __pyx_L3_bool_binop_done:; __pyx_r = __pyx_t_1; goto __pyx_L0;
142:
+143: def filter(self):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_5Chart_13filter(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_8discodop_10containers_5Chart_12filter[] = "Chart.filter(self)\nDrop edges not part of a derivation headed by root of chart.";
static PyObject *__pyx_pw_8discodop_10containers_5Chart_13filter(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("filter (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_5Chart_12filter(((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_5Chart_12filter(struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self) {
PyObject *__pyx_v_itemstokeep = 0;
ItemNo __pyx_v_item;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("filter", 0);
/* … */
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_AddTraceback("discodop.containers.Chart.filter", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_itemstokeep);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
144: """Drop edges not part of a derivation headed by root of chart."""
+145: cdef set itemstokeep = set()
__pyx_t_1 = PySet_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 145, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_itemstokeep = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
146: cdef ItemNo item
+147: _filtersubtree(self, self.root(), itemstokeep)
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_root); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 147, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } if (__pyx_t_3) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 147, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 147, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_f_8discodop_10containers__filtersubtree(__pyx_v_self, __pyx_t_1, __pyx_v_itemstokeep); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+148: for item in {self.getitemidx(n) for n in range(1, self.numitems())
{ /* enter inner scope */
PyObject *__pyx_9genexpr11__pyx_v_n = NULL;
__pyx_t_1 = PySet_New(NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 148, __pyx_L7_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_numitems); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 148, __pyx_L7_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
__pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
if (likely(__pyx_t_4)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
__Pyx_INCREF(__pyx_t_4);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_3, function);
}
}
if (__pyx_t_4) {
__pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 148, __pyx_L7_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
} else {
__pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 148, __pyx_L7_error)
}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 148, __pyx_L7_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_INCREF(__pyx_int_1);
__Pyx_GIVEREF(__pyx_int_1);
PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_int_1);
__Pyx_GIVEREF(__pyx_t_2);
PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
__pyx_t_2 = 0;
__pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 148, __pyx_L7_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
__pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_5 = 0;
__pyx_t_6 = NULL;
} else {
__pyx_t_5 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 148, __pyx_L7_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_6 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 148, __pyx_L7_error)
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
for (;;) {
if (likely(!__pyx_t_6)) {
if (likely(PyList_CheckExact(__pyx_t_3))) {
if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_3)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(1, 148, __pyx_L7_error)
#else
__pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 148, __pyx_L7_error)
__Pyx_GOTREF(__pyx_t_2);
#endif
} else {
if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(1, 148, __pyx_L7_error)
#else
__pyx_t_2 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 148, __pyx_L7_error)
__Pyx_GOTREF(__pyx_t_2);
#endif
}
} else {
__pyx_t_2 = __pyx_t_6(__pyx_t_3);
if (unlikely(!__pyx_t_2)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(1, 148, __pyx_L7_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_2);
}
__Pyx_XDECREF_SET(__pyx_9genexpr11__pyx_v_n, __pyx_t_2);
__pyx_t_2 = 0;
__pyx_t_7 = __Pyx_PyInt_As_uint64_t(__pyx_9genexpr11__pyx_v_n); if (unlikely((__pyx_t_7 == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 148, __pyx_L7_error)
__pyx_t_2 = __Pyx_PyInt_From_uint32_t(((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_self->__pyx_vtab)->getitemidx(__pyx_v_self, __pyx_t_7)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 148, __pyx_L7_error)
__Pyx_GOTREF(__pyx_t_2);
if (unlikely(PySet_Add(__pyx_t_1, (PyObject*)__pyx_t_2))) __PYX_ERR(1, 148, __pyx_L7_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_XDECREF(__pyx_9genexpr11__pyx_v_n);
goto __pyx_L10_exit_scope;
__pyx_L7_error:;
__Pyx_XDECREF(__pyx_9genexpr11__pyx_v_n);
goto __pyx_L1_error;
__pyx_L10_exit_scope:;
} /* exit inner scope */
/* … */
if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
__pyx_t_1 = __pyx_t_3; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
__pyx_t_6 = NULL;
} else {
__pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 148, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 148, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
for (;;) {
if (likely(!__pyx_t_6)) {
if (likely(PyList_CheckExact(__pyx_t_1))) {
if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(1, 148, __pyx_L1_error)
#else
__pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 148, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
#endif
} else {
if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(1, 148, __pyx_L1_error)
#else
__pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 148, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
#endif
}
} else {
__pyx_t_3 = __pyx_t_6(__pyx_t_1);
if (unlikely(!__pyx_t_3)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(1, 148, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_3);
}
__pyx_t_8 = __Pyx_PyInt_As_uint32_t(__pyx_t_3); if (unlikely((__pyx_t_8 == ((ItemNo)-1)) && PyErr_Occurred())) __PYX_ERR(1, 148, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_v_item = __pyx_t_8;
/* … */
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+149: } - itemstokeep:
__pyx_t_3 = PyNumber_Subtract(__pyx_t_1, __pyx_v_itemstokeep); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 149, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+150: self.parseforest[item].clear()
(__pyx_v_self->parseforest[__pyx_v_item]).clear();
151:
+152: cdef edgestr(self, ItemNo itemidx, Edge edge):
static PyObject *__pyx_f_8discodop_10containers_5Chart_edgestr(struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self, ItemNo __pyx_v_itemidx, Edge __pyx_v_edge) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("edgestr", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_XDECREF(__pyx_t_9);
__Pyx_XDECREF(__pyx_t_10);
__Pyx_AddTraceback("discodop.containers.Chart.edgestr", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
153: """Return string representation of item and edge belonging to it."""
+154: if edge.rule is NULL:
__pyx_t_1 = ((__pyx_v_edge.rule == NULL) != 0);
if (__pyx_t_1) {
/* … */
}
+155: return "'%s' %g" % (
__Pyx_XDECREF(__pyx_r); /* … */ __pyx_t_4 = PyUnicode_Format(__pyx_kp_u_s_g, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 155, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+156: self.sent[self.lexidx(edge)],
if (unlikely(__pyx_v_self->sent == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(1, 156, __pyx_L1_error)
}
__pyx_t_2 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_self->__pyx_vtab)->lexidx(__pyx_v_self, __pyx_v_edge); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(1, 156, __pyx_L1_error)
/* … */
__pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 156, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_INCREF(PyList_GET_ITEM(__pyx_v_self->sent, __pyx_t_2));
__Pyx_GIVEREF(PyList_GET_ITEM(__pyx_v_self->sent, __pyx_t_2));
PyTuple_SET_ITEM(__pyx_t_5, 0, PyList_GET_ITEM(__pyx_v_self->sent, __pyx_t_2));
__Pyx_GIVEREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
__pyx_t_4 = 0;
+157: self.lexprob(itemidx, edge))
__pyx_t_3 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_self->__pyx_vtab)->lexprob(__pyx_v_self, __pyx_v_itemidx, __pyx_v_edge); if (unlikely(__pyx_t_3 == -1.0)) __PYX_ERR(1, 157, __pyx_L1_error)
__pyx_t_4 = PyFloat_FromDouble(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 157, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
158: else:
+159: return '%s %s %g' % (
/*else*/ {
__Pyx_XDECREF(__pyx_r);
/* … */
__pyx_t_8 = PyUnicode_Format(__pyx_kp_u_s_s_g, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 159, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_r = __pyx_t_8;
__pyx_t_8 = 0;
goto __pyx_L0;
}
+160: self.itemstr(self._left(itemidx, edge)),
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itemstr); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 160, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = __Pyx_PyInt_From_uint32_t(((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_self->__pyx_vtab)->_left(__pyx_v_self, __pyx_v_itemidx, __pyx_v_edge)); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 160, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = NULL; if (CYTHON_UNPACK_METHODS && likely(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); } } if (!__pyx_t_7) { __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 160, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_4); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_6}; __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 160, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) { PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_6}; __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 160, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else #endif { __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 160, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL; __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_6); __pyx_t_6 = 0; __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 160, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; /* … */ __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 160, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_8); __pyx_t_4 = 0; __pyx_t_5 = 0; __pyx_t_8 = 0;
+161: self.itemstr(self._right(itemidx, edge))
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itemstr); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = __Pyx_PyInt_From_uint32_t(((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_self->__pyx_vtab)->_right(__pyx_v_self, __pyx_v_itemidx, __pyx_v_edge)); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_9 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_6); if (likely(__pyx_t_9)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); __Pyx_INCREF(__pyx_t_9); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_6, function); } } if (!__pyx_t_9) { __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 161, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_8); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_6)) { PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_7}; __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 161, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_7}; __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 161, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } else #endif { __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL; __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_7); __pyx_t_7 = 0; __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_10, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } } __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_5 = __pyx_t_8; __pyx_t_8 = 0; } else { __Pyx_INCREF(__pyx_kp_u__11); __pyx_t_5 = __pyx_kp_u__11; }
+162: if edge.rule.rhs2 else '',
if ((__pyx_v_edge.rule->rhs2 != 0)) {
+163: exp(-edge.rule.prob)
__pyx_t_6 = PyFloat_FromDouble(exp((-__pyx_v_edge.rule->prob))); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 163, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_8 = __pyx_t_6; __pyx_t_6 = 0; } else {
+164: if self.grammar.logprob else edge.rule.prob)
if ((__pyx_v_self->grammar->logprob != 0)) {
/* … */
__pyx_t_6 = PyFloat_FromDouble(__pyx_v_edge.rule->prob); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 164, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_8 = __pyx_t_6;
__pyx_t_6 = 0;
}
165:
+166: def __str__(self):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_5Chart_15__str__(PyObject *__pyx_v_self); /*proto*/
static char __pyx_doc_8discodop_10containers_5Chart_14__str__[] = "Pretty-print chart and *k*-best derivations.";
#if CYTHON_COMPILING_IN_CPYTHON
struct wrapperbase __pyx_wrapperbase_8discodop_10containers_5Chart_14__str__;
#endif
static PyObject *__pyx_pw_8discodop_10containers_5Chart_15__str__(PyObject *__pyx_v_self) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__str__ (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_5Chart_14__str__(((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_5Chart_14__str__(struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self) {
RankedEdge __pyx_v_rankededge;
Edge __pyx_v_edge;
std::pair<RankedEdge,Prob> __pyx_v_entry;
uint64_t __pyx_v_n;
uint64_t __pyx_v_m;
ItemNo __pyx_v_item;
PyObject *__pyx_v_result = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__str__", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_AddTraceback("discodop.containers.Chart.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_result);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
167: """Pretty-print chart and *k*-best derivations."""
168: cdef RankedEdge rankededge
169: cdef Edge edge
170: cdef pair[RankedEdge, Prob] entry
171: cdef uint64_t n, m
172: cdef ItemNo item
+173: result = []
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 173, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+174: for n in range(1, self.numitems()):
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_numitems); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 174, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } if (__pyx_t_3) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 174, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 174, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_4 = __Pyx_PyInt_As_long(__pyx_t_1); if (unlikely((__pyx_t_4 == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 174, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; for (__pyx_t_5 = 1; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { __pyx_v_n = __pyx_t_5;
+175: item = self.getitemidx(n)
__pyx_v_item = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_self->__pyx_vtab)->getitemidx(__pyx_v_self, __pyx_v_n);
+176: result.append(' '.join((
__pyx_t_6 = PyUnicode_Join(__pyx_kp_u__27, __pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 176, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_6); if (unlikely(__pyx_t_9 == -1)) __PYX_ERR(1, 176, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+177: self.itemstr(item).ljust(20),
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itemstr); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 177, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_item); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 177, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_6)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } if (!__pyx_t_6) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 177, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_3}; __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 177, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_3}; __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 177, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else #endif { __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 177, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_3); __pyx_t_3 = 0; __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 177, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_ljust); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 177, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 177, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* … */ __pyx_tuple__28 = PyTuple_Pack(1, __pyx_int_20); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(1, 177, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__28); __Pyx_GIVEREF(__pyx_tuple__28); /* … */ __pyx_t_8 = PyTuple_New(4); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 177, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_8, 3, __pyx_t_6); __pyx_t_1 = 0; __pyx_t_7 = 0; __pyx_t_2 = 0; __pyx_t_6 = 0;
+178: ('vitprob=%g' % (
__pyx_t_7 = PyUnicode_Format(__pyx_kp_u_vitprob_g, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 178, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+179: exp(-self.subtreeprob(item)) if self.logprob
if ((__pyx_v_self->logprob != 0)) {
__pyx_t_7 = PyFloat_FromDouble(exp((-((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_self->__pyx_vtab)->subtreeprob(__pyx_v_self, __pyx_v_item)))); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 179, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_2 = __pyx_t_7;
__pyx_t_7 = 0;
} else {
+180: else self.subtreeprob(item))).ljust(17),
__pyx_t_7 = PyFloat_FromDouble(((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_self->__pyx_vtab)->subtreeprob(__pyx_v_self, __pyx_v_item)); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 180, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_2 = __pyx_t_7; __pyx_t_7 = 0; } /* … */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_ljust); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 180, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 180, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* … */ __pyx_tuple__29 = PyTuple_Pack(1, __pyx_int_17); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(1, 180, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__29); __Pyx_GIVEREF(__pyx_tuple__29);
+181: ((' ins=%g' % self.inside[item]).ljust(14)
__pyx_t_3 = PyFloat_FromDouble((__pyx_v_self->inside[__pyx_v_item])); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 181, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_6 = PyUnicode_Format(__pyx_kp_u_ins_g, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 181, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_ljust); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 181, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 181, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_2 = __pyx_t_6; __pyx_t_6 = 0; } else { __Pyx_INCREF(__pyx_kp_u__11); __pyx_t_2 = __pyx_kp_u__11; } /* … */ __pyx_tuple__30 = PyTuple_Pack(1, __pyx_int_14); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(1, 181, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__30); __Pyx_GIVEREF(__pyx_tuple__30);
+182: if self.inside.size() else ''),
if ((__pyx_v_self->inside.size() != 0)) {
+183: ((' out=%g' % self.outside[item]).ljust(14)
__pyx_t_3 = PyFloat_FromDouble((__pyx_v_self->outside[__pyx_v_item])); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 183, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_8 = PyUnicode_Format(__pyx_kp_u_out_g, __pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 183, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_ljust); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 183, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 183, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_6 = __pyx_t_8; __pyx_t_8 = 0; } else { __Pyx_INCREF(__pyx_kp_u__11); __pyx_t_6 = __pyx_kp_u__11; } /* … */ __pyx_tuple__31 = PyTuple_Pack(1, __pyx_int_14); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(1, 183, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__31); __Pyx_GIVEREF(__pyx_tuple__31);
+184: if self.outside.size() else ''))))
if ((__pyx_v_self->outside.size() != 0)) {
+185: for edge in self.parseforest[item]:
__pyx_t_11 = &(__pyx_v_self->parseforest[__pyx_v_item]);
__pyx_t_10 = __pyx_t_11->begin();
for (;;) {
if (!(__pyx_t_10 != __pyx_t_11->end())) break;
__pyx_t_12 = *__pyx_t_10;
++__pyx_t_10;
__pyx_v_edge = __pyx_t_12;
/* … */
}
}
+186: result.append('\t=> %s' % self.edgestr(item, edge))
__pyx_t_6 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_self->__pyx_vtab)->edgestr(__pyx_v_self, __pyx_v_item, __pyx_v_edge); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 186, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_8 = PyUnicode_Format(__pyx_kp_u_s_2, __pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 186, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_8); if (unlikely(__pyx_t_9 == -1)) __PYX_ERR(1, 186, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+187: if self.rankededges.size():
__pyx_t_13 = (__pyx_v_self->rankededges.size() != 0);
if (__pyx_t_13) {
/* … */
}
+188: result.append('\nranked edges:')
__pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_kp_u_ranked_edges); if (unlikely(__pyx_t_9 == -1)) __PYX_ERR(1, 188, __pyx_L1_error)
+189: for n in range(1, self.numitems()):
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_numitems); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 189, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_2 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6); if (likely(__pyx_t_2)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_6, function); } } if (__pyx_t_2) { __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 189, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 189, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_4 = __Pyx_PyInt_As_long(__pyx_t_8); if (unlikely((__pyx_t_4 == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 189, __pyx_L1_error) __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; for (__pyx_t_5 = 1; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { __pyx_v_n = __pyx_t_5;
+190: item = self.getitemidx(n)
__pyx_v_item = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_self->__pyx_vtab)->getitemidx(__pyx_v_self, __pyx_v_n);
+191: if self.rankededges[item].size() == 0:
__pyx_t_13 = (((__pyx_v_self->rankededges[__pyx_v_item]).size() == 0) != 0);
if (__pyx_t_13) {
/* … */
}
+192: continue
goto __pyx_L8_continue;
+193: result.append(self.itemstr(item))
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_itemstr); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 193, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_2 = __Pyx_PyInt_From_uint32_t(__pyx_v_item); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 193, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_7 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) { __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); if (likely(__pyx_t_7)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); __Pyx_INCREF(__pyx_t_7); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_6, function); } } if (!__pyx_t_7) { __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 193, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_8); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_6)) { PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_2}; __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 193, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) { PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_2}; __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 193, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else #endif { __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 193, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_7); __pyx_t_7 = NULL; __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_t_2); __pyx_t_2 = 0; __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_1, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 193, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } } __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_8); if (unlikely(__pyx_t_9 == -1)) __PYX_ERR(1, 193, __pyx_L1_error) __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+194: m = 0
__pyx_v_m = 0;
+195: for entry in self.rankededges[item]:
__pyx_t_15 = &(__pyx_v_self->rankededges[__pyx_v_item]);
__pyx_t_14 = __pyx_t_15->begin();
for (;;) {
if (!(__pyx_t_14 != __pyx_t_15->end())) break;
__pyx_t_16 = *__pyx_t_14;
++__pyx_t_14;
__pyx_v_entry = __pyx_t_16;
/* … */
}
__pyx_L8_continue:;
}
+196: rankededge = entry.first
__pyx_t_17 = __pyx_v_entry.first;
__pyx_v_rankededge = __pyx_t_17;
+197: result.append('\t%d: %10g, %s %d %d' % (
__pyx_t_7 = PyUnicode_Format(__pyx_kp_u_d_10g_s_d_d, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 197, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_7); if (unlikely(__pyx_t_9 == -1)) __PYX_ERR(1, 197, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+198: m, exp(-entry.second) if self.logprob
__pyx_t_8 = __Pyx_PyInt_From_uint64_t(__pyx_v_m); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 198, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
if ((__pyx_v_self->logprob != 0)) {
__pyx_t_1 = PyFloat_FromDouble(exp((-__pyx_v_entry.second))); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 198, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_6 = __pyx_t_1;
__pyx_t_1 = 0;
} else {
/* … */
__pyx_t_3 = PyTuple_New(5); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 198, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_GIVEREF(__pyx_t_8);
PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8);
__Pyx_GIVEREF(__pyx_t_6);
PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_6);
__Pyx_GIVEREF(__pyx_t_1);
PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_1);
__Pyx_GIVEREF(__pyx_t_2);
PyTuple_SET_ITEM(__pyx_t_3, 3, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_7);
PyTuple_SET_ITEM(__pyx_t_3, 4, __pyx_t_7);
__pyx_t_8 = 0;
__pyx_t_6 = 0;
__pyx_t_1 = 0;
__pyx_t_2 = 0;
__pyx_t_7 = 0;
+199: else entry.second,
__pyx_t_1 = PyFloat_FromDouble(__pyx_v_entry.second); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 199, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __pyx_t_1; __pyx_t_1 = 0; }
+200: self.edgestr(item, rankededge.edge),
__pyx_t_1 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_self->__pyx_vtab)->edgestr(__pyx_v_self, __pyx_v_item, __pyx_v_rankededge.edge); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 200, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
+201: rankededge.left, rankededge.right))
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_rankededge.left); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 201, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_rankededge.right); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 201, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7);
+202: m += 1
__pyx_v_m = (__pyx_v_m + 1);
+203: return '\n'.join(result)
__Pyx_XDECREF(__pyx_r); __pyx_t_7 = PyUnicode_Join(__pyx_kp_u__24, __pyx_v_result); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 203, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_r = __pyx_t_7; __pyx_t_7 = 0; goto __pyx_L0;
204:
+205: def stats(self):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_5Chart_17stats(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_8discodop_10containers_5Chart_16stats[] = "Chart.stats(self)\nReturn a short string with counts of items, edges.";
static PyObject *__pyx_pw_8discodop_10containers_5Chart_17stats(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("stats (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_5Chart_16stats(((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_5Chart_16stats(struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("stats", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_AddTraceback("discodop.containers.Chart.stats", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
206: """Return a short string with counts of items, edges."""
+207: return 'items %d, edges %d' % (
__Pyx_XDECREF(__pyx_r); /* … */ __pyx_t_1 = PyUnicode_Format(__pyx_kp_u_items_d_edges_d, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 207, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
+208: self.numitems() - 1,
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_numitems); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 208, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } if (__pyx_t_3) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 208, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 208, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_t_1, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 208, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* … */ __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 208, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1); __pyx_t_2 = 0; __pyx_t_1 = 0;
+209: sum([self.parseforest[self.getitemidx(n)].size()
{ /* enter inner scope */
PyObject *__pyx_9genexpr12__pyx_v_n = NULL;
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 209, __pyx_L5_error)
__Pyx_GOTREF(__pyx_t_1);
/* … */
__pyx_t_8 = __Pyx_PyInt_As_uint64_t(__pyx_9genexpr12__pyx_v_n); if (unlikely((__pyx_t_8 == ((uint64_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 209, __pyx_L5_error)
__pyx_t_3 = __Pyx_PyInt_FromSize_t((__pyx_v_self->parseforest[((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_self->__pyx_vtab)->getitemidx(__pyx_v_self, __pyx_t_8)]).size()); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 209, __pyx_L5_error)
__Pyx_GOTREF(__pyx_t_3);
if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_3))) __PYX_ERR(1, 209, __pyx_L5_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
/* … */
__pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 209, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_GIVEREF(__pyx_t_1);
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
__pyx_t_1 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 209, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+210: for n in range(1, self.numitems())]))
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_numitems); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 210, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); } } if (__pyx_t_5) { __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 210, __pyx_L5_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else { __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 210, __pyx_L5_error) } __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 210, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_int_1); __Pyx_GIVEREF(__pyx_int_1); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_int_1); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 210, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) { __pyx_t_4 = __pyx_t_3; __Pyx_INCREF(__pyx_t_4); __pyx_t_6 = 0; __pyx_t_7 = NULL; } else { __pyx_t_6 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 210, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_7 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 210, __pyx_L5_error) } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; for (;;) { if (likely(!__pyx_t_7)) { if (likely(PyList_CheckExact(__pyx_t_4))) { if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_4)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(1, 210, __pyx_L5_error) #else __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 210, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_3); #endif } else { if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_4)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_6); __Pyx_INCREF(__pyx_t_3); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(1, 210, __pyx_L5_error) #else __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 210, __pyx_L5_error) __Pyx_GOTREF(__pyx_t_3); #endif } } else { __pyx_t_3 = __pyx_t_7(__pyx_t_4); if (unlikely(!__pyx_t_3)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); else __PYX_ERR(1, 210, __pyx_L5_error) } break; } __Pyx_GOTREF(__pyx_t_3); } __Pyx_XDECREF_SET(__pyx_9genexpr12__pyx_v_n, __pyx_t_3); __pyx_t_3 = 0; /* … */ } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_9genexpr12__pyx_v_n); goto __pyx_L8_exit_scope; __pyx_L5_error:; __Pyx_XDECREF(__pyx_9genexpr12__pyx_v_n); goto __pyx_L1_error; __pyx_L8_exit_scope:; } /* exit inner scope */
211: # more stats:
212: # labels: len({self.label(item) for item in range(1, self.numitems())}),
213: # spans: ...
214:
215:
+216: cdef void _filtersubtree(Chart chart, item, set items):
static void __pyx_f_8discodop_10containers__filtersubtree(struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, PyObject *__pyx_v_item, PyObject *__pyx_v_items) {
Edge __pyx_v_edge;
ItemNo __pyx_v_leftitem;
ItemNo __pyx_v_rightitem;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("_filtersubtree", 0);
/* … */
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_8);
__Pyx_WriteUnraisable("discodop.containers._filtersubtree", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
__pyx_L0:;
__Pyx_RefNannyFinishContext();
}
217: """Recursively collect items that lead to a complete derivation."""
218: cdef Edge edge
+219: items.add(item)
if (unlikely(__pyx_v_items == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "add");
__PYX_ERR(1, 219, __pyx_L1_error)
}
__pyx_t_1 = PySet_Add(__pyx_v_items, __pyx_v_item); if (unlikely(__pyx_t_1 == -1)) __PYX_ERR(1, 219, __pyx_L1_error)
+220: for edge in chart.parseforest[item]:
__pyx_t_2 = __Pyx_PyInt_As_size_t(__pyx_v_item); if (unlikely((__pyx_t_2 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 220, __pyx_L1_error) __pyx_t_4 = &(__pyx_v_chart->parseforest[__pyx_t_2]); __pyx_t_3 = __pyx_t_4->begin(); for (;;) { if (!(__pyx_t_3 != __pyx_t_4->end())) break; __pyx_t_5 = *__pyx_t_3; ++__pyx_t_3; __pyx_v_edge = __pyx_t_5; /* … */ __pyx_L3_continue:; }
+221: if edge.rule is NULL:
__pyx_t_6 = ((__pyx_v_edge.rule == NULL) != 0);
if (__pyx_t_6) {
/* … */
}
+222: continue
goto __pyx_L3_continue;
+223: leftitem = chart._left(item, edge)
__pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_v_item); if (unlikely((__pyx_t_7 == ((ItemNo)-1)) && PyErr_Occurred())) __PYX_ERR(1, 223, __pyx_L1_error)
__pyx_v_leftitem = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->_left(__pyx_v_chart, __pyx_t_7, __pyx_v_edge);
+224: if leftitem not in items:
__pyx_t_8 = __Pyx_PyInt_From_uint32_t(__pyx_v_leftitem); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 224, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_t_8, __pyx_v_items, Py_NE)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(1, 224, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
__pyx_t_9 = (__pyx_t_6 != 0);
if (__pyx_t_9) {
/* … */
}
+225: _filtersubtree(chart, leftitem, items)
__pyx_t_8 = __Pyx_PyInt_From_uint32_t(__pyx_v_leftitem); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 225, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__pyx_f_8discodop_10containers__filtersubtree(__pyx_v_chart, __pyx_t_8, __pyx_v_items);
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+226: if edge.rule.rhs2 == 0:
__pyx_t_9 = ((__pyx_v_edge.rule->rhs2 == 0) != 0);
if (__pyx_t_9) {
/* … */
}
+227: continue
goto __pyx_L3_continue;
+228: rightitem = chart._right(item, edge)
__pyx_t_7 = __Pyx_PyInt_As_uint32_t(__pyx_v_item); if (unlikely((__pyx_t_7 == ((ItemNo)-1)) && PyErr_Occurred())) __PYX_ERR(1, 228, __pyx_L1_error)
__pyx_v_rightitem = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->_right(__pyx_v_chart, __pyx_t_7, __pyx_v_edge);
+229: if rightitem not in items:
__pyx_t_8 = __Pyx_PyInt_From_uint32_t(__pyx_v_rightitem); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 229, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__pyx_t_9 = (__Pyx_PySequence_ContainsTF(__pyx_t_8, __pyx_v_items, Py_NE)); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(1, 229, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
__pyx_t_6 = (__pyx_t_9 != 0);
if (__pyx_t_6) {
/* … */
}
+230: _filtersubtree(chart, rightitem, items)
__pyx_t_8 = __Pyx_PyInt_From_uint32_t(__pyx_v_rightitem); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 230, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__pyx_f_8discodop_10containers__filtersubtree(__pyx_v_chart, __pyx_t_8, __pyx_v_items);
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
231:
232:
233: @cython.final
234: cdef class StringList(object):
235: """Proxy class to expose vector<string> with read-only list interface.
236:
237: Decodes utf8 to unicode."""
+238: def __len__(self):
/* Python wrapper */
static Py_ssize_t __pyx_pw_8discodop_10containers_10StringList_1__len__(PyObject *__pyx_v_self); /*proto*/
static Py_ssize_t __pyx_pw_8discodop_10containers_10StringList_1__len__(PyObject *__pyx_v_self) {
Py_ssize_t __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__len__ (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_10StringList___len__(((struct __pyx_obj_8discodop_10containers_StringList *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static Py_ssize_t __pyx_pf_8discodop_10containers_10StringList___len__(struct __pyx_obj_8discodop_10containers_StringList *__pyx_v_self) {
Py_ssize_t __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__len__", 0);
/* … */
/* function exit code */
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+239: return self.ob.size()
__pyx_r = __pyx_v_self->ob.size(); goto __pyx_L0;
240:
+241: def __getitem__(self, size_t i):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_10StringList_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_i); /*proto*/
static PyObject *__pyx_pw_8discodop_10containers_10StringList_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_i) {
size_t __pyx_v_i;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0);
assert(__pyx_arg_i); {
__pyx_v_i = __Pyx_PyInt_As_size_t(__pyx_arg_i); if (unlikely((__pyx_v_i == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 241, __pyx_L3_error)
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L3_error:;
__Pyx_AddTraceback("discodop.containers.StringList.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_8discodop_10containers_10StringList_2__getitem__(((struct __pyx_obj_8discodop_10containers_StringList *)__pyx_v_self), ((size_t)__pyx_v_i));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_10StringList_2__getitem__(struct __pyx_obj_8discodop_10containers_StringList *__pyx_v_self, size_t __pyx_v_i) {
std::string __pyx_v_result;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__getitem__", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_AddTraceback("discodop.containers.StringList.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
242: cdef string result
+243: if i >= self.ob.size():
__pyx_t_1 = ((__pyx_v_i >= __pyx_v_self->ob.size()) != 0);
if (__pyx_t_1) {
/* … */
}
+244: raise IndexError('index %d out of bounds (len=%d)' % (
__pyx_t_3 = PyUnicode_Format(__pyx_kp_u_index_d_out_of_bounds_len_d, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 244, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 244, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_IndexError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 244, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __PYX_ERR(1, 244, __pyx_L1_error)
+245: i, self.ob.size()))
__pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 245, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyInt_FromSize_t(__pyx_v_self->ob.size()); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 245, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 245, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); __pyx_t_2 = 0; __pyx_t_3 = 0;
+246: result = self.ob[i]
__pyx_v_result = (__pyx_v_self->ob[__pyx_v_i]);
+247: return result.decode('utf8')
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = __Pyx_decode_cpp_string(__pyx_v_result, 0, PY_SSIZE_T_MAX, NULL, NULL, PyUnicode_DecodeUTF8); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 247, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
248:
249:
250: @cython.final
251: cdef class StringIntDict(object):
252: """Proxy class to expose sparse_hash_map with read-only dict interface.
253:
254: Decodes utf8 to unicode."""
+255: def __len__(self):
/* Python wrapper */
static Py_ssize_t __pyx_pw_8discodop_10containers_13StringIntDict_1__len__(PyObject *__pyx_v_self); /*proto*/
static Py_ssize_t __pyx_pw_8discodop_10containers_13StringIntDict_1__len__(PyObject *__pyx_v_self) {
Py_ssize_t __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__len__ (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_13StringIntDict___len__(((struct __pyx_obj_8discodop_10containers_StringIntDict *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static Py_ssize_t __pyx_pf_8discodop_10containers_13StringIntDict___len__(struct __pyx_obj_8discodop_10containers_StringIntDict *__pyx_v_self) {
Py_ssize_t __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__len__", 0);
/* … */
/* function exit code */
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+256: return self.ob.size()
__pyx_r = __pyx_v_self->ob.size(); goto __pyx_L0;
257:
+258: def __getitem__(self, str key):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_13StringIntDict_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static PyObject *__pyx_pw_8discodop_10containers_13StringIntDict_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0);
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_key), (&PyUnicode_Type), 1, "key", 1))) __PYX_ERR(1, 258, __pyx_L1_error)
__pyx_r = __pyx_pf_8discodop_10containers_13StringIntDict_2__getitem__(((struct __pyx_obj_8discodop_10containers_StringIntDict *)__pyx_v_self), ((PyObject*)__pyx_v_key));
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_13StringIntDict_2__getitem__(struct __pyx_obj_8discodop_10containers_StringIntDict *__pyx_v_self, PyObject *__pyx_v_key) {
std::string __pyx_v_cppkey;
spp::sparse_hash_map<std::string,Label> ::iterator __pyx_v_it;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__getitem__", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_AddTraceback("discodop.containers.StringIntDict.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+259: cdef string cppkey = key.encode('utf8')
if (unlikely(__pyx_v_key == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "encode");
__PYX_ERR(1, 259, __pyx_L1_error)
}
__pyx_t_1 = PyUnicode_AsUTF8String(__pyx_v_key); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 259, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = __pyx_convert_string_from_py_std__in_string(__pyx_t_1); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 259, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_cppkey = __pyx_t_2;
+260: it = self.ob.find(cppkey)
__pyx_v_it = __pyx_v_self->ob.find(__pyx_v_cppkey);
+261: if it == self.ob.end():
__pyx_t_3 = ((__pyx_v_it == __pyx_v_self->ob.end()) != 0);
if (__pyx_t_3) {
/* … */
}
+262: raise KeyError(key)
__pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 262, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_key); __Pyx_GIVEREF(__pyx_v_key); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_key); __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 262, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __PYX_ERR(1, 262, __pyx_L1_error)
+263: return dereference(it).second
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyInt_From_uint32_t((*__pyx_v_it).second); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 263, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
264:
+265: def get(self, str key, default=None):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_13StringIntDict_5get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8discodop_10containers_13StringIntDict_4get[] = "StringIntDict.get(self, unicode key, default=None)";
static PyObject *__pyx_pw_8discodop_10containers_13StringIntDict_5get(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_key = 0;
PyObject *__pyx_v_default = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("get (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_key,&__pyx_n_s_default,0};
PyObject* values[2] = {0,0};
values[1] = ((PyObject *)Py_None);
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_key)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_default);
if (value) { values[1] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(1, 265, __pyx_L3_error)
}
} else {
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
break;
default: goto __pyx_L5_argtuple_error;
}
}
__pyx_v_key = ((PyObject*)values[0]);
__pyx_v_default = values[1];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 265, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("discodop.containers.StringIntDict.get", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_key), (&PyUnicode_Type), 1, "key", 1))) __PYX_ERR(1, 265, __pyx_L1_error)
__pyx_r = __pyx_pf_8discodop_10containers_13StringIntDict_4get(((struct __pyx_obj_8discodop_10containers_StringIntDict *)__pyx_v_self), __pyx_v_key, __pyx_v_default);
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_13StringIntDict_4get(struct __pyx_obj_8discodop_10containers_StringIntDict *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_default) {
std::string __pyx_v_cppkey;
spp::sparse_hash_map<std::string,Label> ::iterator __pyx_v_it;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("get", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("discodop.containers.StringIntDict.get", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+266: cdef string cppkey = key.encode('utf8')
if (unlikely(__pyx_v_key == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "encode");
__PYX_ERR(1, 266, __pyx_L1_error)
}
__pyx_t_1 = PyUnicode_AsUTF8String(__pyx_v_key); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 266, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = __pyx_convert_string_from_py_std__in_string(__pyx_t_1); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 266, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_cppkey = __pyx_t_2;
+267: it = self.ob.find(cppkey)
__pyx_v_it = __pyx_v_self->ob.find(__pyx_v_cppkey);
+268: if it == self.ob.end():
__pyx_t_3 = ((__pyx_v_it == __pyx_v_self->ob.end()) != 0);
if (__pyx_t_3) {
/* … */
}
+269: return default
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_default); __pyx_r = __pyx_v_default; goto __pyx_L0;
+270: return dereference(it).second
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyInt_From_uint32_t((*__pyx_v_it).second); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 270, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
271:
+272: def __contains__(self, str key):
/* Python wrapper */
static int __pyx_pw_8discodop_10containers_13StringIntDict_7__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static int __pyx_pw_8discodop_10containers_13StringIntDict_7__contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__contains__ (wrapper)", 0);
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_key), (&PyUnicode_Type), 1, "key", 1))) __PYX_ERR(1, 272, __pyx_L1_error)
__pyx_r = __pyx_pf_8discodop_10containers_13StringIntDict_6__contains__(((struct __pyx_obj_8discodop_10containers_StringIntDict *)__pyx_v_self), ((PyObject*)__pyx_v_key));
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = -1;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static int __pyx_pf_8discodop_10containers_13StringIntDict_6__contains__(struct __pyx_obj_8discodop_10containers_StringIntDict *__pyx_v_self, PyObject *__pyx_v_key) {
std::string __pyx_v_cppkey;
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__contains__", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("discodop.containers.StringIntDict.__contains__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -1;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_gb_8discodop_10containers_13StringIntDict_10generator(__pyx_CoroutineObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */
+273: cdef string cppkey = key.encode('utf8')
if (unlikely(__pyx_v_key == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "encode");
__PYX_ERR(1, 273, __pyx_L1_error)
}
__pyx_t_1 = PyUnicode_AsUTF8String(__pyx_v_key); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 273, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = __pyx_convert_string_from_py_std__in_string(__pyx_t_1); if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 273, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_cppkey = __pyx_t_2;
+274: return self.ob.find(cppkey) != self.ob.end()
__pyx_r = (__pyx_v_self->ob.find(__pyx_v_cppkey) != __pyx_v_self->ob.end()); goto __pyx_L0;
275:
+276: def __iter__(self):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_13StringIntDict_9__iter__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_8discodop_10containers_13StringIntDict_9__iter__(PyObject *__pyx_v_self) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__iter__ (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_13StringIntDict_8__iter__(((struct __pyx_obj_8discodop_10containers_StringIntDict *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_13StringIntDict_8__iter__(struct __pyx_obj_8discodop_10containers_StringIntDict *__pyx_v_self) {
struct __pyx_obj_8discodop_10containers___pyx_scope_struct_1___iter__ *__pyx_cur_scope;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__iter__", 0);
__pyx_cur_scope = (struct __pyx_obj_8discodop_10containers___pyx_scope_struct_1___iter__ *)__pyx_tp_new_8discodop_10containers___pyx_scope_struct_1___iter__(__pyx_ptype_8discodop_10containers___pyx_scope_struct_1___iter__, __pyx_empty_tuple, NULL);
if (unlikely(!__pyx_cur_scope)) {
__pyx_cur_scope = ((struct __pyx_obj_8discodop_10containers___pyx_scope_struct_1___iter__ *)Py_None);
__Pyx_INCREF(Py_None);
__PYX_ERR(1, 276, __pyx_L1_error)
} else {
__Pyx_GOTREF(__pyx_cur_scope);
}
__pyx_cur_scope->__pyx_v_self = __pyx_v_self;
__Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
__Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self);
{
__pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_8discodop_10containers_13StringIntDict_10generator, (PyObject *) __pyx_cur_scope, __pyx_n_s_iter, __pyx_n_s_StringIntDict___iter, __pyx_n_s_discodop_containers); if (unlikely(!gen)) __PYX_ERR(1, 276, __pyx_L1_error)
__Pyx_DECREF(__pyx_cur_scope);
__Pyx_RefNannyFinishContext();
return (PyObject *) gen;
}
/* function exit code */
__pyx_L1_error:;
__Pyx_AddTraceback("discodop.containers.StringIntDict.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__Pyx_DECREF(((PyObject *)__pyx_cur_scope));
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_gb_8discodop_10containers_13StringIntDict_10generator(__pyx_CoroutineObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("None", 0);
__pyx_L3_first_run:;
if (unlikely(!__pyx_sent_value)) __PYX_ERR(1, 276, __pyx_L1_error)
/* … */
/* function exit code */
PyErr_SetNone(PyExc_StopIteration);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_4);
__Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_L0:;
__Pyx_XDECREF(__pyx_r); __pyx_r = 0;
__pyx_generator->resume_label = -1;
__Pyx_Coroutine_clear((PyObject*)__pyx_generator);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
struct __pyx_obj_8discodop_10containers___pyx_scope_struct_1___iter__ {
PyObject_HEAD
std::pair<std::string,Label> __pyx_v_it;
struct __pyx_obj_8discodop_10containers_StringIntDict *__pyx_v_self;
spp::sparse_hash_map<std::string,Label> ::iterator __pyx_t_0;
spp::sparse_hash_map<std::string,Label> *__pyx_t_1;
};
+277: for it in self.ob:
__pyx_t_2 = &__pyx_cur_scope->__pyx_v_self->ob;
__pyx_t_1 = __pyx_t_2->begin();
for (;;) {
if (!(__pyx_t_1 != __pyx_t_2->end())) break;
__pyx_t_3 = *__pyx_t_1;
++__pyx_t_1;
__pyx_cur_scope->__pyx_v_it = __pyx_t_3;
/* … */
}
CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);
+278: yield it.first.decode('utf8')
__pyx_t_4 = __Pyx_decode_cpp_string(__pyx_cur_scope->__pyx_v_it.first, 0, PY_SSIZE_T_MAX, NULL, NULL, PyUnicode_DecodeUTF8); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 278, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_r = __pyx_t_4;
__pyx_t_4 = 0;
__pyx_cur_scope->__pyx_t_0 = __pyx_t_1;
__pyx_cur_scope->__pyx_t_1 = __pyx_t_2;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
/* return from generator, yielding value */
__pyx_generator->resume_label = 1;
return __pyx_r;
__pyx_L6_resume_from_yield:;
__pyx_t_1 = __pyx_cur_scope->__pyx_t_0;
__pyx_t_2 = __pyx_cur_scope->__pyx_t_1;
if (unlikely(!__pyx_sent_value)) __PYX_ERR(1, 278, __pyx_L1_error)
279:
280:
281: @cython.final
+282: cdef class Ctrees:
struct __pyx_vtabstruct_8discodop_10containers_Ctrees {
PyObject *(*alloc)(struct __pyx_obj_8discodop_10containers_Ctrees *, int, long, int __pyx_skip_dispatch);
PyObject *(*realloc)(struct __pyx_obj_8discodop_10containers_Ctrees *, int, int);
PyObject *(*addnodes)(struct __pyx_obj_8discodop_10containers_Ctrees *, struct __pyx_t_8discodop_10containers_Node *, int, int);
};
static struct __pyx_vtabstruct_8discodop_10containers_Ctrees *__pyx_vtabptr_8discodop_10containers_Ctrees;
static PyObject *__pyx_f_8discodop_10containers_6Ctrees_alloc(struct __pyx_obj_8discodop_10containers_Ctrees *, int, long, int __pyx_skip_dispatch);
static PyObject *__pyx_f_8discodop_10containers_6Ctrees_realloc(struct __pyx_obj_8discodop_10containers_Ctrees *, int, int);
static PyObject *__pyx_f_8discodop_10containers_6Ctrees_addnodes(struct __pyx_obj_8discodop_10containers_Ctrees *, struct __pyx_t_8discodop_10containers_Node *, int, int);
283: """An indexed, binarized treebank stored as array.
284:
285: Indexing depends on an external Vocabulary object that maps
286: productions and labels to unique integers across different sets of trees.
287: First call the alloc() method with (estimated) number of nodes & trees.
288: Then add trees one by one using the addnodes() method."""
+289: def __cinit__(self):
/* Python wrapper */
static int __pyx_pw_8discodop_10containers_6Ctrees_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_8discodop_10containers_6Ctrees_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
__Pyx_RaiseArgtupleInvalid("__cinit__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__cinit__", 0))) return -1;
__pyx_r = __pyx_pf_8discodop_10containers_6Ctrees___cinit__(((struct __pyx_obj_8discodop_10containers_Ctrees *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static int __pyx_pf_8discodop_10containers_6Ctrees___cinit__(struct __pyx_obj_8discodop_10containers_Ctrees *__pyx_v_self) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__cinit__", 0);
/* … */
/* function exit code */
__pyx_r = 0;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+290: self.trees = self.nodes = NULL
__pyx_v_self->trees = NULL; __pyx_v_self->nodes = NULL;
291:
+292: def __init__(self):
/* Python wrapper */
static int __pyx_pw_8discodop_10containers_6Ctrees_3__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_8discodop_10containers_6Ctrees_3__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
__Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1;
__pyx_r = __pyx_pf_8discodop_10containers_6Ctrees_2__init__(((struct __pyx_obj_8discodop_10containers_Ctrees *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static int __pyx_pf_8discodop_10containers_6Ctrees_2__init__(struct __pyx_obj_8discodop_10containers_Ctrees *__pyx_v_self) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__init__", 0);
/* … */
/* function exit code */
__pyx_r = 0;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+293: self.len = self.max = 0
__pyx_v_self->len = 0; __pyx_v_self->max = 0;
+294: self.numnodes = self.maxnodes = self.nodesleft = self.numwords = 0
__pyx_v_self->numnodes = 0; __pyx_v_self->maxnodes = 0; __pyx_v_self->nodesleft = 0; __pyx_v_self->numwords = 0;
+295: self._state = None
__Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GOTREF(__pyx_v_self->_state); __Pyx_DECREF(__pyx_v_self->_state); __pyx_v_self->_state = Py_None;
296:
+297: cpdef alloc(self, int numtrees, long numnodes):
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_5alloc(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_8discodop_10containers_6Ctrees_alloc(struct __pyx_obj_8discodop_10containers_Ctrees *__pyx_v_self, int __pyx_v_numtrees, long __pyx_v_numnodes, CYTHON_UNUSED int __pyx_skip_dispatch) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("alloc", 0);
/* … */
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_3);
__Pyx_AddTraceback("discodop.containers.Ctrees.alloc", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_5alloc(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8discodop_10containers_6Ctrees_4alloc[] = "Ctrees.alloc(self, int numtrees, long numnodes)\nInitialize an array of trees of nodes structs.";
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_5alloc(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
int __pyx_v_numtrees;
long __pyx_v_numnodes;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("alloc (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_numtrees,&__pyx_n_s_numnodes,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_numtrees)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_numnodes)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("alloc", 1, 2, 2, 1); __PYX_ERR(1, 297, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "alloc") < 0)) __PYX_ERR(1, 297, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_numtrees = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_numtrees == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 297, __pyx_L3_error)
__pyx_v_numnodes = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v_numnodes == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 297, __pyx_L3_error)
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("alloc", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 297, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("discodop.containers.Ctrees.alloc", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_8discodop_10containers_6Ctrees_4alloc(((struct __pyx_obj_8discodop_10containers_Ctrees *)__pyx_v_self), __pyx_v_numtrees, __pyx_v_numnodes);
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_6Ctrees_4alloc(struct __pyx_obj_8discodop_10containers_Ctrees *__pyx_v_self, int __pyx_v_numtrees, long __pyx_v_numnodes) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("alloc", 0);
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __pyx_f_8discodop_10containers_6Ctrees_alloc(__pyx_v_self, __pyx_v_numtrees, __pyx_v_numnodes, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 297, __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("discodop.containers.Ctrees.alloc", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
298: """Initialize an array of trees of nodes structs."""
+299: self.max = numtrees
__pyx_v_self->max = __pyx_v_numtrees;
+300: self.trees = <NodeArray *>malloc(numtrees * sizeof(NodeArray))
__pyx_v_self->trees = ((struct __pyx_t_8discodop_10containers_NodeArray *)malloc((__pyx_v_numtrees * (sizeof(struct __pyx_t_8discodop_10containers_NodeArray)))));
+301: self.nodes = <Node *>malloc(numnodes * sizeof(Node))
__pyx_v_self->nodes = ((struct __pyx_t_8discodop_10containers_Node *)malloc((__pyx_v_numnodes * (sizeof(struct __pyx_t_8discodop_10containers_Node)))));
+302: if self.trees is NULL or self.nodes is NULL:
__pyx_t_2 = ((__pyx_v_self->trees == NULL) != 0);
if (!__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L4_bool_binop_done;
}
__pyx_t_2 = ((__pyx_v_self->nodes == NULL) != 0);
__pyx_t_1 = __pyx_t_2;
__pyx_L4_bool_binop_done:;
if (__pyx_t_1) {
/* … */
}
+303: raise MemoryError('allocation error')
__pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 303, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __PYX_ERR(1, 303, __pyx_L1_error) /* … */ __pyx_tuple__32 = PyTuple_Pack(1, __pyx_kp_u_allocation_error); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(1, 303, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__32); __Pyx_GIVEREF(__pyx_tuple__32);
+304: self.nodesleft = numnodes
__pyx_v_self->nodesleft = __pyx_v_numnodes;
305:
+306: cdef realloc(self, int numtrees, int extranodes):
static PyObject *__pyx_f_8discodop_10containers_6Ctrees_realloc(struct __pyx_obj_8discodop_10containers_Ctrees *__pyx_v_self, int __pyx_v_numtrees, int __pyx_v_extranodes) {
PyObject *__pyx_v_numnodes = 0;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("realloc", 0);
/* … */
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_AddTraceback("discodop.containers.Ctrees.realloc", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_numnodes);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
307: """Increase size of array (handy with incremental binarization)."""
308: # based on Python's listobject.c list_resize()
309: cdef numnodes
+310: if numtrees > self.max:
__pyx_t_1 = ((__pyx_v_numtrees > __pyx_v_self->max) != 0);
if (__pyx_t_1) {
/* … */
}
311: # overallocate to get linear-time amortized behavior
+312: numtrees += (numtrees >> 3) + (3 if numtrees < 9 else 6)
if (((__pyx_v_numtrees < 9) != 0)) {
__pyx_t_2 = 3;
} else {
__pyx_t_2 = 6;
}
__pyx_v_numtrees = (__pyx_v_numtrees + ((__pyx_v_numtrees >> 3) + __pyx_t_2));
+313: self.trees = <NodeArray *>realloc(self.trees,
__pyx_v_self->trees = ((struct __pyx_t_8discodop_10containers_NodeArray *)realloc(__pyx_v_self->trees, (__pyx_v_numtrees * (sizeof(struct __pyx_t_8discodop_10containers_NodeArray)))));
314: numtrees * sizeof(NodeArray))
+315: if self.trees is NULL:
__pyx_t_1 = ((__pyx_v_self->trees == NULL) != 0);
if (__pyx_t_1) {
/* … */
}
+316: raise MemoryError('allocation error')
__pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__33, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 316, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __PYX_ERR(1, 316, __pyx_L1_error) /* … */ __pyx_tuple__33 = PyTuple_Pack(1, __pyx_kp_u_allocation_error); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(1, 316, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__33); __Pyx_GIVEREF(__pyx_tuple__33);
+317: self.max = numtrees
__pyx_v_self->max = __pyx_v_numtrees;
+318: if extranodes > self.nodesleft:
__pyx_t_1 = ((__pyx_v_extranodes > __pyx_v_self->nodesleft) != 0);
if (__pyx_t_1) {
/* … */
}
+319: numnodes = self.numnodes + extranodes
__pyx_t_3 = __Pyx_PyInt_FromSize_t((__pyx_v_self->numnodes + __pyx_v_extranodes)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 319, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_numnodes = __pyx_t_3; __pyx_t_3 = 0;
320: # estimate how many new nodes will be needed
321: # self.nodesleft += (self.max - self.len) * (self.numnodes / self.len)
322: # overallocate to get linear-time amortized behavior
+323: numnodes += (numnodes >> 3) + (3 if numnodes < 9 else 6)
__pyx_t_3 = __Pyx_PyInt_RshiftObjC(__pyx_v_numnodes, __pyx_int_3, 3, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 323, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = PyObject_RichCompare(__pyx_v_numnodes, __pyx_int_9, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 323, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 323, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_1) { __Pyx_INCREF(__pyx_int_3); __pyx_t_4 = __pyx_int_3; } else { __Pyx_INCREF(__pyx_int_6); __pyx_t_4 = __pyx_int_6; } __pyx_t_5 = PyNumber_Add(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 323, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_numnodes, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 323, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF_SET(__pyx_v_numnodes, __pyx_t_4); __pyx_t_4 = 0;
+324: self.nodes = <Node *>realloc(self.nodes, numnodes * sizeof(Node))
__pyx_t_4 = __Pyx_PyInt_FromSize_t((sizeof(struct __pyx_t_8discodop_10containers_Node))); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 324, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyNumber_Multiply(__pyx_v_numnodes, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 324, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_6 = __Pyx_PyInt_As_size_t(__pyx_t_5); if (unlikely((__pyx_t_6 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 324, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_self->nodes = ((struct __pyx_t_8discodop_10containers_Node *)realloc(__pyx_v_self->nodes, __pyx_t_6));
+325: if self.nodes is NULL:
__pyx_t_1 = ((__pyx_v_self->nodes == NULL) != 0);
if (__pyx_t_1) {
/* … */
}
+326: raise MemoryError('allocation error')
__pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_MemoryError, __pyx_tuple__34, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 326, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __PYX_ERR(1, 326, __pyx_L1_error) /* … */ __pyx_tuple__34 = PyTuple_Pack(1, __pyx_kp_u_allocation_error); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(1, 326, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__34); __Pyx_GIVEREF(__pyx_tuple__34);
+327: self.nodesleft = numnodes - self.numnodes
__pyx_t_5 = __Pyx_PyInt_FromSize_t(__pyx_v_self->numnodes); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 327, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = PyNumber_Subtract(__pyx_v_numnodes, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 327, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_2 = __Pyx_PyInt_As_long(__pyx_t_4); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 327, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_self->nodesleft = __pyx_t_2;
328:
+329: cdef addnodes(self, Node *source, int cnt, int root):
static PyObject *__pyx_f_8discodop_10containers_6Ctrees_addnodes(struct __pyx_obj_8discodop_10containers_Ctrees *__pyx_v_self, struct __pyx_t_8discodop_10containers_Node *__pyx_v_source, int __pyx_v_cnt, int __pyx_v_root) {
PyObject *__pyx_v_prodsintree = 0;
PyObject *__pyx_v_sortidx = 0;
int __pyx_v_n;
int __pyx_v_m;
int __pyx_v_lensent;
struct __pyx_t_8discodop_10containers_Node *__pyx_v_dest;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("addnodes", 0);
/* … */
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_AddTraceback("discodop.containers.Ctrees.addnodes", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_prodsintree);
__Pyx_XDECREF(__pyx_v_sortidx);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
330: """Incrementally add tree to the node array.
331:
332: Copies a tree that has already been converted to an array of nodes."""
333: cdef dict prodsintree, sortidx
+334: cdef int n, m, lensent = 0
__pyx_v_lensent = 0;
335: cdef Node *dest
+336: if not self.max:
__pyx_t_1 = ((!(__pyx_v_self->max != 0)) != 0);
if (__pyx_t_1) {
/* … */
}
+337: raise ValueError('alloc() has not been called (max=0).')
__pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__35, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 337, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __PYX_ERR(1, 337, __pyx_L1_error) /* … */ __pyx_tuple__35 = PyTuple_Pack(1, __pyx_kp_u_alloc_has_not_been_called_max_0); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(1, 337, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__35); __Pyx_GIVEREF(__pyx_tuple__35);
+338: if self.len >= self.max or self.nodesleft < cnt:
__pyx_t_3 = ((__pyx_v_self->len >= __pyx_v_self->max) != 0);
if (!__pyx_t_3) {
} else {
__pyx_t_1 = __pyx_t_3;
goto __pyx_L5_bool_binop_done;
}
__pyx_t_3 = ((__pyx_v_self->nodesleft < __pyx_v_cnt) != 0);
__pyx_t_1 = __pyx_t_3;
__pyx_L5_bool_binop_done:;
if (__pyx_t_1) {
/* … */
}
+339: self.realloc(self.len + 1, cnt)
__pyx_t_2 = __pyx_f_8discodop_10containers_6Ctrees_realloc(__pyx_v_self, (__pyx_v_self->len + 1), __pyx_v_cnt); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 339, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+340: prodsintree = {n: source[n].prod for n in range(cnt)}
{ /* enter inner scope */
int __pyx_9genexpr13__pyx_v_n;
__pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 340, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_4 = __pyx_v_cnt;
for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
__pyx_9genexpr13__pyx_v_n = __pyx_t_5;
__pyx_t_6 = __Pyx_PyInt_From_int(__pyx_9genexpr13__pyx_v_n); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 340, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_7 = __Pyx_PyInt_From_int32_t((__pyx_v_source[__pyx_9genexpr13__pyx_v_n]).prod); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 340, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
if (unlikely(PyDict_SetItem(__pyx_t_2, (PyObject*)__pyx_t_6, (PyObject*)__pyx_t_7))) __PYX_ERR(1, 340, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
}
} /* exit inner scope */
__pyx_v_prodsintree = ((PyObject*)__pyx_t_2);
__pyx_t_2 = 0;
+341: sortidx = {m: n for n, m in enumerate(
{ /* enter inner scope */
int __pyx_9genexpr14__pyx_v_n;
int __pyx_9genexpr14__pyx_v_m;
__pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 341, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_4 = 0;
/* … */
if (likely(PyList_CheckExact(__pyx_t_8)) || PyTuple_CheckExact(__pyx_t_8)) {
__pyx_t_7 = __pyx_t_8; __Pyx_INCREF(__pyx_t_7); __pyx_t_9 = 0;
__pyx_t_10 = NULL;
} else {
__pyx_t_9 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 341, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_10 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 341, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
for (;;) {
if (likely(!__pyx_t_10)) {
if (likely(PyList_CheckExact(__pyx_t_7))) {
if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_7)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_8 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_9); __Pyx_INCREF(__pyx_t_8); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(1, 341, __pyx_L1_error)
#else
__pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 341, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
#endif
} else {
if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_9); __Pyx_INCREF(__pyx_t_8); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(1, 341, __pyx_L1_error)
#else
__pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 341, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
#endif
}
} else {
__pyx_t_8 = __pyx_t_10(__pyx_t_7);
if (unlikely(!__pyx_t_8)) {
PyObject* exc_type = PyErr_Occurred();
if (exc_type) {
if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
else __PYX_ERR(1, 341, __pyx_L1_error)
}
break;
}
__Pyx_GOTREF(__pyx_t_8);
}
__pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_8); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 341, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
__pyx_9genexpr14__pyx_v_m = __pyx_t_5;
__pyx_9genexpr14__pyx_v_n = __pyx_t_4;
__pyx_t_4 = (__pyx_t_4 + 1);
__pyx_t_8 = __Pyx_PyInt_From_int(__pyx_9genexpr14__pyx_v_m); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 341, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__pyx_t_6 = __Pyx_PyInt_From_int(__pyx_9genexpr14__pyx_v_n); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 341, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
if (unlikely(PyDict_SetItem(__pyx_t_2, (PyObject*)__pyx_t_8, (PyObject*)__pyx_t_6))) __PYX_ERR(1, 341, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
}
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
} /* exit inner scope */
__pyx_v_sortidx = ((PyObject*)__pyx_t_2);
__pyx_t_2 = 0;
+342: sorted(range(cnt), key=prodsintree.get))}
__pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_cnt); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 342, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 342, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); __pyx_t_7 = 0; __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_6, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 342, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 342, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); __pyx_t_7 = 0; __pyx_t_7 = PyDict_New(); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 342, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_prodsintree, __pyx_n_s_get); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 342, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_key, __pyx_t_8) < 0) __PYX_ERR(1, 342, __pyx_L1_error) __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_sorted, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 342, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
343: # copy nodes to allocated array, while translating indices
+344: dest = &self.nodes[self.numnodes]
__pyx_v_dest = (&(__pyx_v_self->nodes[__pyx_v_self->numnodes]));
+345: for n, m in sortidx.items():
__pyx_t_9 = 0; __pyx_t_7 = __Pyx_dict_iterator(__pyx_v_sortidx, 1, __pyx_n_s_items, (&__pyx_t_11), (&__pyx_t_4)); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 345, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = __pyx_t_7; __pyx_t_7 = 0; while (1) { __pyx_t_5 = __Pyx_dict_iter_next(__pyx_t_2, __pyx_t_11, &__pyx_t_9, &__pyx_t_7, &__pyx_t_6, NULL, __pyx_t_4); if (unlikely(__pyx_t_5 == 0)) break; if (unlikely(__pyx_t_5 == -1)) __PYX_ERR(1, 345, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_GOTREF(__pyx_t_6); __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 345, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 345, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_v_n = __pyx_t_5; __pyx_v_m = __pyx_t_12;
+346: dest[m] = source[n]
(__pyx_v_dest[__pyx_v_m]) = (__pyx_v_source[__pyx_v_n]);
+347: if dest[m].left >= 0:
__pyx_t_1 = (((__pyx_v_dest[__pyx_v_m]).left >= 0) != 0);
if (__pyx_t_1) {
/* … */
goto __pyx_L13;
}
+348: dest[m].left = sortidx[source[n].left]
__pyx_t_6 = __Pyx_PyInt_From_int16_t((__pyx_v_source[__pyx_v_n]).left); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 348, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_sortidx, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 348, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_13 = __Pyx_PyInt_As_int16_t(__pyx_t_7); if (unlikely((__pyx_t_13 == ((int16_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 348, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
(__pyx_v_dest[__pyx_v_m]).left = __pyx_t_13;
349: else:
+350: lensent += 1
/*else*/ {
__pyx_v_lensent = (__pyx_v_lensent + 1);
}
__pyx_L13:;
+351: if dest[m].right >= 0:
__pyx_t_1 = (((__pyx_v_dest[__pyx_v_m]).right >= 0) != 0);
if (__pyx_t_1) {
/* … */
}
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+352: dest[m].right = sortidx[source[n].right]
__pyx_t_7 = __Pyx_PyInt_From_int16_t((__pyx_v_source[__pyx_v_n]).right); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 352, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_6 = __Pyx_PyDict_GetItem(__pyx_v_sortidx, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 352, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_13 = __Pyx_PyInt_As_int16_t(__pyx_t_6); if (unlikely((__pyx_t_13 == ((int16_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 352, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
(__pyx_v_dest[__pyx_v_m]).right = __pyx_t_13;
+353: self.trees[self.len].offset = self.numnodes
__pyx_t_14 = __pyx_v_self->numnodes; (__pyx_v_self->trees[__pyx_v_self->len]).offset = __pyx_t_14;
+354: self.trees[self.len].root = sortidx[root]
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_root); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 354, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = __Pyx_PyDict_GetItem(__pyx_v_sortidx, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 354, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_13 = __Pyx_PyInt_As_int16_t(__pyx_t_6); if (unlikely((__pyx_t_13 == ((int16_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 354, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; (__pyx_v_self->trees[__pyx_v_self->len]).root = __pyx_t_13;
+355: self.trees[self.len].len = cnt
(__pyx_v_self->trees[__pyx_v_self->len]).len = __pyx_v_cnt;
+356: self.len += 1
__pyx_v_self->len = (__pyx_v_self->len + 1);
+357: self.nodesleft -= cnt
__pyx_v_self->nodesleft = (__pyx_v_self->nodesleft - __pyx_v_cnt);
+358: self.numnodes += cnt
__pyx_v_self->numnodes = (__pyx_v_self->numnodes + __pyx_v_cnt);
+359: if cnt > self.maxnodes:
__pyx_t_1 = ((__pyx_v_cnt > __pyx_v_self->maxnodes) != 0);
if (__pyx_t_1) {
/* … */
}
+360: self.maxnodes = cnt
__pyx_v_self->maxnodes = __pyx_v_cnt;
+361: self.numwords += lensent
__pyx_v_self->numwords = (__pyx_v_self->numwords + __pyx_v_lensent);
362:
+363: def indextrees(self, Vocabulary vocab):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_7indextrees(PyObject *__pyx_v_self, PyObject *__pyx_v_vocab); /*proto*/
static char __pyx_doc_8discodop_10containers_6Ctrees_6indextrees[] = "Ctrees.indextrees(self, Vocabulary vocab)\nCreate index from productions to trees containing that production.\n\n\t\tProductions are represented as integer IDs, trees are given as sets of\n\t\tinteger indices.";
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_7indextrees(PyObject *__pyx_v_self, PyObject *__pyx_v_vocab) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("indextrees (wrapper)", 0);
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_vocab), __pyx_ptype_8discodop_10containers_Vocabulary, 1, "vocab", 0))) __PYX_ERR(1, 363, __pyx_L1_error)
__pyx_r = __pyx_pf_8discodop_10containers_6Ctrees_6indextrees(((struct __pyx_obj_8discodop_10containers_Ctrees *)__pyx_v_self), ((struct __pyx_obj_8discodop_10containers_Vocabulary *)__pyx_v_vocab));
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_6Ctrees_6indextrees(struct __pyx_obj_8discodop_10containers_Ctrees *__pyx_v_self, struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_vocab) {
PyObject *__pyx_v_prodindex = 0;
struct __pyx_t_8discodop_10containers_Node *__pyx_v_nodes;
int __pyx_v_n;
int __pyx_v_m;
PyObject *__pyx_v_rb = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("indextrees", 0);
/* … */
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_9);
__Pyx_XDECREF(__pyx_t_10);
__Pyx_XDECREF(__pyx_t_11);
__Pyx_XDECREF(__pyx_t_12);
__Pyx_AddTraceback("discodop.containers.Ctrees.indextrees", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_prodindex);
__Pyx_XDECREF(__pyx_v_rb);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
364: """Create index from productions to trees containing that production.
365:
366: Productions are represented as integer IDs, trees are given as sets of
367: integer indices."""
368: cdef:
+369: list prodindex = [None] * len(vocab.prods)
__pyx_t_1 = __pyx_v_vocab->prods; __Pyx_INCREF(__pyx_t_1); if (unlikely(__pyx_t_1 == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); __PYX_ERR(1, 369, __pyx_L1_error) } __pyx_t_2 = PyDict_Size(__pyx_t_1); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(1, 369, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyList_New(1 * ((__pyx_t_2<0) ? 0:__pyx_t_2)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 369, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < __pyx_t_2; __pyx_temp++) { __Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); PyList_SET_ITEM(__pyx_t_1, __pyx_temp, Py_None); } } __pyx_v_prodindex = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
370: Node *nodes
371: int n, m
+372: for n in range(self.len):
__pyx_t_3 = __pyx_v_self->len;
for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
__pyx_v_n = __pyx_t_4;
+373: nodes = &self.nodes[self.trees[n].offset]
__pyx_v_nodes = (&(__pyx_v_self->nodes[(__pyx_v_self->trees[__pyx_v_n]).offset]));
+374: for m in range(self.trees[n].len):
__pyx_t_5 = (__pyx_v_self->trees[__pyx_v_n]).len;
for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
__pyx_v_m = __pyx_t_6;
+375: if nodes[m].prod >= 0:
__pyx_t_7 = (((__pyx_v_nodes[__pyx_v_m]).prod >= 0) != 0);
if (__pyx_t_7) {
/* … */
}
}
}
376: # Add to production index
+377: rb = prodindex[nodes[m].prod]
__pyx_t_1 = PyList_GET_ITEM(__pyx_v_prodindex, (__pyx_v_nodes[__pyx_v_m]).prod); __Pyx_INCREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_rb, __pyx_t_1); __pyx_t_1 = 0;
+378: if rb is None:
__pyx_t_7 = (__pyx_v_rb == Py_None);
__pyx_t_8 = (__pyx_t_7 != 0);
if (__pyx_t_8) {
/* … */
}
+379: rb = prodindex[nodes[m].prod] = RoaringBitmap()
__pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_RoaringBitmap); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 379, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_10 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9); if (likely(__pyx_t_10)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); __Pyx_INCREF(__pyx_t_10); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_9, function); } } if (__pyx_t_10) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 379, __pyx_L1_error) __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } else { __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 379, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_INCREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_rb, __pyx_t_1); if (unlikely(__Pyx_SetItemInt(__pyx_v_prodindex, (__pyx_v_nodes[__pyx_v_m]).prod, __pyx_t_1, int32_t, 1, __Pyx_PyInt_From_int32_t, 1, 0, 0) < 0)) __PYX_ERR(1, 379, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+380: rb.add(n)
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_rb, __pyx_n_s_add); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 380, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_10 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 380, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_11 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) { __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_9); if (likely(__pyx_t_11)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); __Pyx_INCREF(__pyx_t_11); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_9, function); } } if (!__pyx_t_11) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 380, __pyx_L1_error) __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_9)) { PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_t_10}; __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 380, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_t_10}; __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 380, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } else #endif { __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(1, 380, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL; __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_t_10); __pyx_t_10 = 0; __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_12, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 380, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; } } __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+381: self.prodindex = MultiRoaringBitmap(prodindex)
__pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_MultiRoaringBitmap); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 381, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_12 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) { __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_9); if (likely(__pyx_t_12)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); __Pyx_INCREF(__pyx_t_12); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_9, function); } } if (!__pyx_t_12) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_prodindex); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 381, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_9)) { PyObject *__pyx_temp[2] = {__pyx_t_12, __pyx_v_prodindex}; __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 381, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_GOTREF(__pyx_t_1); } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) { PyObject *__pyx_temp[2] = {__pyx_t_12, __pyx_v_prodindex}; __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 381, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_GOTREF(__pyx_t_1); } else #endif { __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 381, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_12); __pyx_t_12 = NULL; __Pyx_INCREF(__pyx_v_prodindex); __Pyx_GIVEREF(__pyx_v_prodindex); PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_v_prodindex); __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 381, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } } __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->prodindex); __Pyx_DECREF(__pyx_v_self->prodindex); __pyx_v_self->prodindex = __pyx_t_1; __pyx_t_1 = 0;
382:
+383: def extract(self, int n, Vocabulary vocab, bint disc=True, int node=-1):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_9extract(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8discodop_10containers_6Ctrees_8extract[] = "Ctrees.extract(self, int n, Vocabulary vocab, bool disc=True, int node=-1)\nReturn given tree in discbracket format.\n\n\t\t:param node: if given, extract specific subtree instead of whole tree.\n\t\t";
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_9extract(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
int __pyx_v_n;
struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_vocab = 0;
int __pyx_v_disc;
int __pyx_v_node;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("extract (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_n,&__pyx_n_s_vocab,&__pyx_n_s_disc,&__pyx_n_s_node,0};
PyObject* values[4] = {0,0,0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_n)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_vocab)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("extract", 0, 2, 4, 1); __PYX_ERR(1, 383, __pyx_L3_error)
}
CYTHON_FALLTHROUGH;
case 2:
if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_disc);
if (value) { values[2] = value; kw_args--; }
}
CYTHON_FALLTHROUGH;
case 3:
if (kw_args > 0) {
PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_node);
if (value) { values[3] = value; kw_args--; }
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "extract") < 0)) __PYX_ERR(1, 383, __pyx_L3_error)
}
} else {
switch (PyTuple_GET_SIZE(__pyx_args)) {
case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
CYTHON_FALLTHROUGH;
case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
CYTHON_FALLTHROUGH;
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
break;
default: goto __pyx_L5_argtuple_error;
}
}
__pyx_v_n = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_n == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 383, __pyx_L3_error)
__pyx_v_vocab = ((struct __pyx_obj_8discodop_10containers_Vocabulary *)values[1]);
if (values[2]) {
__pyx_v_disc = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_disc == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 383, __pyx_L3_error)
} else {
__pyx_v_disc = ((int)1);
}
if (values[3]) {
__pyx_v_node = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_node == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 383, __pyx_L3_error)
} else {
__pyx_v_node = ((int)-1);
}
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("extract", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 383, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("discodop.containers.Ctrees.extract", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_vocab), __pyx_ptype_8discodop_10containers_Vocabulary, 1, "vocab", 0))) __PYX_ERR(1, 383, __pyx_L1_error)
__pyx_r = __pyx_pf_8discodop_10containers_6Ctrees_8extract(((struct __pyx_obj_8discodop_10containers_Ctrees *)__pyx_v_self), __pyx_v_n, __pyx_v_vocab, __pyx_v_disc, __pyx_v_node);
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_6Ctrees_8extract(struct __pyx_obj_8discodop_10containers_Ctrees *__pyx_v_self, int __pyx_v_n, struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_vocab, int __pyx_v_disc, int __pyx_v_node) {
PyObject *__pyx_v_result = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("extract", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("discodop.containers.Ctrees.extract", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_result);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
384: """Return given tree in discbracket format.
385:
386: :param node: if given, extract specific subtree instead of whole tree.
387: """
+388: result = []
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 388, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+389: if n < 0 or n >= self.len:
__pyx_t_3 = ((__pyx_v_n < 0) != 0);
if (!__pyx_t_3) {
} else {
__pyx_t_2 = __pyx_t_3;
goto __pyx_L4_bool_binop_done;
}
__pyx_t_3 = ((__pyx_v_n >= __pyx_v_self->len) != 0);
__pyx_t_2 = __pyx_t_3;
__pyx_L4_bool_binop_done:;
if (__pyx_t_2) {
/* … */
}
+390: raise IndexError
__Pyx_Raise(__pyx_builtin_IndexError, 0, 0, 0);
__PYX_ERR(1, 390, __pyx_L1_error)
+391: gettree(result, &(self.nodes[self.trees[n].offset]),
__pyx_t_1 = __pyx_f_8discodop_10containers_gettree(__pyx_v_result, (&(__pyx_v_self->nodes[(__pyx_v_self->trees[__pyx_v_n]).offset])), __pyx_v_vocab, __pyx_t_4, __pyx_v_disc); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 391, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+392: vocab, self.trees[n].root if node == -1 else node, disc)
if (((__pyx_v_node == -1L) != 0)) {
__pyx_t_4 = (__pyx_v_self->trees[__pyx_v_n]).root;
} else {
__pyx_t_4 = __pyx_v_node;
}
+393: return ''.join(result)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyUnicode_Join(__pyx_kp_u__11, __pyx_v_result); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 393, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
394:
+395: def extractsent(self, int n, Vocabulary vocab):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_11extractsent(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8discodop_10containers_6Ctrees_10extractsent[] = "Ctrees.extractsent(self, int n, Vocabulary vocab)\nReturn sentence as a list for given tree.";
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_11extractsent(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
int __pyx_v_n;
struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_vocab = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("extractsent (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_n,&__pyx_n_s_vocab,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_n)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_vocab)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("extractsent", 1, 2, 2, 1); __PYX_ERR(1, 395, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "extractsent") < 0)) __PYX_ERR(1, 395, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_n = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_n == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 395, __pyx_L3_error)
__pyx_v_vocab = ((struct __pyx_obj_8discodop_10containers_Vocabulary *)values[1]);
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("extractsent", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 395, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("discodop.containers.Ctrees.extractsent", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_vocab), __pyx_ptype_8discodop_10containers_Vocabulary, 1, "vocab", 0))) __PYX_ERR(1, 395, __pyx_L1_error)
__pyx_r = __pyx_pf_8discodop_10containers_6Ctrees_10extractsent(((struct __pyx_obj_8discodop_10containers_Ctrees *)__pyx_v_self), __pyx_v_n, __pyx_v_vocab);
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_6Ctrees_10extractsent(struct __pyx_obj_8discodop_10containers_Ctrees *__pyx_v_self, int __pyx_v_n, struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_vocab) {
PyObject *__pyx_v_sent = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("extractsent", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_AddTraceback("discodop.containers.Ctrees.extractsent", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_sent);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
396: """Return sentence as a list for given tree."""
+397: if n < 0 or n >= self.len:
__pyx_t_2 = ((__pyx_v_n < 0) != 0);
if (!__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L4_bool_binop_done;
}
__pyx_t_2 = ((__pyx_v_n >= __pyx_v_self->len) != 0);
__pyx_t_1 = __pyx_t_2;
__pyx_L4_bool_binop_done:;
if (__pyx_t_1) {
/* … */
}
+398: raise IndexError
__Pyx_Raise(__pyx_builtin_IndexError, 0, 0, 0);
__PYX_ERR(1, 398, __pyx_L1_error)
+399: sent = {termidx(self.nodes[m].left): vocab.getword(self.nodes[m].prod)
{ /* enter inner scope */
uint32_t __pyx_9genexpr15__pyx_v_m;
__pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 399, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
/* … */
__pyx_t_6 = __Pyx_PyInt_From_short(__pyx_f_8discodop_10containers_termidx((__pyx_v_self->nodes[__pyx_9genexpr15__pyx_v_m]).left)); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 399, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_7 = ((struct __pyx_vtabstruct_8discodop_10containers_Vocabulary *)__pyx_v_vocab->__pyx_vtab)->getword(__pyx_v_vocab, (__pyx_v_self->nodes[__pyx_9genexpr15__pyx_v_m]).prod); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 399, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
if (unlikely(PyDict_SetItem(__pyx_t_3, (PyObject*)__pyx_t_6, (PyObject*)__pyx_t_7))) __PYX_ERR(1, 399, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
+400: for m in range(self.trees[n].offset,
for (__pyx_t_5 = (__pyx_v_self->trees[__pyx_v_n]).offset; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) {
__pyx_9genexpr15__pyx_v_m = __pyx_t_5;
+401: self.trees[n].offset + self.trees[n].len)
__pyx_t_4 = ((__pyx_v_self->trees[__pyx_v_n]).offset + (__pyx_v_self->trees[__pyx_v_n]).len);
+402: if self.nodes[m].left < 0}
__pyx_t_1 = (((__pyx_v_self->nodes[__pyx_9genexpr15__pyx_v_m]).left < 0) != 0);
if (__pyx_t_1) {
/* … */
}
}
} /* exit inner scope */
__pyx_v_sent = ((PyObject*)__pyx_t_3);
__pyx_t_3 = 0;
+403: return [sent.get(m, None) for m in range(max(sent) + 1)]
__Pyx_XDECREF(__pyx_r); { /* enter inner scope */ PyObject *__pyx_9genexpr16__pyx_v_m = NULL; __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 403, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_7 = PyTuple_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 403, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_INCREF(__pyx_v_sent); __Pyx_GIVEREF(__pyx_v_sent); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_sent); __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_max, __pyx_t_7, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 403, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_7 = __Pyx_PyInt_AddObjC(__pyx_t_6, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 403, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 403, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); __pyx_t_7 = 0; __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_6, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 403, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) { __pyx_t_6 = __pyx_t_7; __Pyx_INCREF(__pyx_t_6); __pyx_t_8 = 0; __pyx_t_9 = NULL; } else { __pyx_t_8 = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 403, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_9 = Py_TYPE(__pyx_t_6)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 403, __pyx_L11_error) } __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; for (;;) { if (likely(!__pyx_t_9)) { if (likely(PyList_CheckExact(__pyx_t_6))) { if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_6)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_7 = PyList_GET_ITEM(__pyx_t_6, __pyx_t_8); __Pyx_INCREF(__pyx_t_7); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(1, 403, __pyx_L11_error) #else __pyx_t_7 = PySequence_ITEM(__pyx_t_6, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 403, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_7); #endif } else { if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_6)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_6, __pyx_t_8); __Pyx_INCREF(__pyx_t_7); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(1, 403, __pyx_L11_error) #else __pyx_t_7 = PySequence_ITEM(__pyx_t_6, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 403, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_7); #endif } } else { __pyx_t_7 = __pyx_t_9(__pyx_t_6); if (unlikely(!__pyx_t_7)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); else __PYX_ERR(1, 403, __pyx_L11_error) } break; } __Pyx_GOTREF(__pyx_t_7); } __Pyx_XDECREF_SET(__pyx_9genexpr16__pyx_v_m, __pyx_t_7); __pyx_t_7 = 0; __pyx_t_7 = __Pyx_PyDict_GetItemDefault(__pyx_v_sent, __pyx_9genexpr16__pyx_v_m, Py_None); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 403, __pyx_L11_error) __Pyx_GOTREF(__pyx_t_7); if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_7))) __PYX_ERR(1, 403, __pyx_L11_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF(__pyx_9genexpr16__pyx_v_m); goto __pyx_L14_exit_scope; __pyx_L11_error:; __Pyx_XDECREF(__pyx_9genexpr16__pyx_v_m); goto __pyx_L1_error; __pyx_L14_exit_scope:; } /* exit inner scope */ __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
404:
+405: def printrepr(self, int n, Vocabulary vocab):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_13printrepr(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8discodop_10containers_6Ctrees_12printrepr[] = "Ctrees.printrepr(self, int n, Vocabulary vocab)\nPrint repr of a tree for debugging purposes.";
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_13printrepr(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
int __pyx_v_n;
struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_vocab = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("printrepr (wrapper)", 0);
{
static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_n,&__pyx_n_s_vocab,0};
PyObject* values[2] = {0,0};
if (unlikely(__pyx_kwds)) {
Py_ssize_t kw_args;
const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
switch (pos_args) {
case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
CYTHON_FALLTHROUGH;
case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
CYTHON_FALLTHROUGH;
case 0: break;
default: goto __pyx_L5_argtuple_error;
}
kw_args = PyDict_Size(__pyx_kwds);
switch (pos_args) {
case 0:
if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_n)) != 0)) kw_args--;
else goto __pyx_L5_argtuple_error;
CYTHON_FALLTHROUGH;
case 1:
if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_vocab)) != 0)) kw_args--;
else {
__Pyx_RaiseArgtupleInvalid("printrepr", 1, 2, 2, 1); __PYX_ERR(1, 405, __pyx_L3_error)
}
}
if (unlikely(kw_args > 0)) {
if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "printrepr") < 0)) __PYX_ERR(1, 405, __pyx_L3_error)
}
} else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
goto __pyx_L5_argtuple_error;
} else {
values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
}
__pyx_v_n = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_n == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 405, __pyx_L3_error)
__pyx_v_vocab = ((struct __pyx_obj_8discodop_10containers_Vocabulary *)values[1]);
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("printrepr", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(1, 405, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("discodop.containers.Ctrees.printrepr", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_vocab), __pyx_ptype_8discodop_10containers_Vocabulary, 1, "vocab", 0))) __PYX_ERR(1, 405, __pyx_L1_error)
__pyx_r = __pyx_pf_8discodop_10containers_6Ctrees_12printrepr(((struct __pyx_obj_8discodop_10containers_Ctrees *)__pyx_v_self), __pyx_v_n, __pyx_v_vocab);
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_6Ctrees_12printrepr(struct __pyx_obj_8discodop_10containers_Ctrees *__pyx_v_self, int __pyx_v_n, struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_vocab) {
PyObject *__pyx_v_tree = NULL;
PyObject *__pyx_v_offset = NULL;
PyObject *__pyx_v_m = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("printrepr", 0);
/* … */
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_XDECREF(__pyx_t_9);
__Pyx_XDECREF(__pyx_t_10);
__Pyx_XDECREF(__pyx_t_11);
__Pyx_XDECREF(__pyx_t_12);
__Pyx_XDECREF(__pyx_t_13);
__Pyx_AddTraceback("discodop.containers.Ctrees.printrepr", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_tree);
__Pyx_XDECREF(__pyx_v_offset);
__Pyx_XDECREF(__pyx_v_m);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
406: """Print repr of a tree for debugging purposes."""
+407: tree = self.extract(n, vocab, disc=True)
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_extract); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 407, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 407, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 407, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_v_vocab)); __Pyx_GIVEREF(((PyObject *)__pyx_v_vocab)); PyTuple_SET_ITEM(__pyx_t_3, 1, ((PyObject *)__pyx_v_vocab)); __pyx_t_2 = 0; __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 407, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_disc, Py_True) < 0) __PYX_ERR(1, 407, __pyx_L1_error) __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 407, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_tree = __pyx_t_4; __pyx_t_4 = 0;
+408: print('tree no.:', n)
__pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_n); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 408, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 408, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_kp_u_tree_no); __Pyx_GIVEREF(__pyx_kp_u_tree_no); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_tree_no); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 408, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+409: print('complete tree:', tree)
__pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 409, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_kp_u_complete_tree); __Pyx_GIVEREF(__pyx_kp_u_complete_tree); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_complete_tree); __Pyx_INCREF(__pyx_v_tree); __Pyx_GIVEREF(__pyx_v_tree); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_tree); __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 409, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+410: offset = self.trees[n].offset
__pyx_t_2 = __Pyx_PyInt_From_uint32_t((__pyx_v_self->trees[__pyx_v_n]).offset); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 410, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_v_offset = __pyx_t_2;
__pyx_t_2 = 0;
+411: print('no. leftidx rightidx prodno lhslabel prod')
__pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_tuple__36, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 411, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* … */ __pyx_tuple__36 = PyTuple_Pack(1, __pyx_kp_u_no_leftidx_rightidx_prodno_lhsla); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(1, 411, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__36); __Pyx_GIVEREF(__pyx_tuple__36);
+412: for m in range(self.trees[n].len):
__pyx_t_2 = __Pyx_PyInt_From_int16_t((__pyx_v_self->trees[__pyx_v_n]).len); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 412, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 412, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 412, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { __pyx_t_4 = __pyx_t_2; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0; __pyx_t_6 = NULL; } else { __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 412, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 412, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { if (likely(!__pyx_t_6)) { if (likely(PyList_CheckExact(__pyx_t_4))) { if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(1, 412, __pyx_L1_error) #else __pyx_t_2 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 412, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #endif } else { if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(1, 412, __pyx_L1_error) #else __pyx_t_2 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 412, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #endif } } else { __pyx_t_2 = __pyx_t_6(__pyx_t_4); if (unlikely(!__pyx_t_2)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); else __PYX_ERR(1, 412, __pyx_L1_error) } break; } __Pyx_GOTREF(__pyx_t_2); } __Pyx_XDECREF_SET(__pyx_v_m, __pyx_t_2); __pyx_t_2 = 0; /* … */ } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+413: print('%2d. %7d %8d %6d %15s %s' % (
__pyx_t_9 = PyUnicode_Format(__pyx_kp_u_2d_7d_8d_6d_15s_s, __pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 413, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 413, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = 0; __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_t_10, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 413, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+414: m, self.nodes[offset + m].left,
__pyx_t_2 = PyNumber_Add(__pyx_v_offset, __pyx_v_m); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 414, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 414, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyInt_From_int16_t((__pyx_v_self->nodes[__pyx_t_7]).left); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 414, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); /* … */ __pyx_t_10 = PyTuple_New(6); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 414, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_INCREF(__pyx_v_m); __Pyx_GIVEREF(__pyx_v_m); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_m); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_10, 3, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 4, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 5, __pyx_t_9); __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_1 = 0; __pyx_t_8 = 0; __pyx_t_9 = 0;
+415: self.nodes[offset + m].right,
__pyx_t_3 = PyNumber_Add(__pyx_v_offset, __pyx_v_m); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 415, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_t_3); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 415, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyInt_From_int16_t((__pyx_v_self->nodes[__pyx_t_7]).right); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 415, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3);
+416: self.nodes[offset + m].prod,
__pyx_t_1 = PyNumber_Add(__pyx_v_offset, __pyx_v_m); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 416, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 416, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyInt_From_int32_t((__pyx_v_self->nodes[__pyx_t_7]).prod); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 416, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1);
+417: vocab.getlabel(self.nodes[offset + m].prod),
__pyx_t_8 = PyNumber_Add(__pyx_v_offset, __pyx_v_m); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 417, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_t_8); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 417, __pyx_L1_error) __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_8 = ((struct __pyx_vtabstruct_8discodop_10containers_Vocabulary *)__pyx_v_vocab->__pyx_vtab)->getlabel(__pyx_v_vocab, (__pyx_v_self->nodes[__pyx_t_7]).prod); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 417, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8);
+418: vocab.prodrepr(self.nodes[offset + m].prod)))
__pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_vocab), __pyx_n_s_prodrepr); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 418, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_11 = PyNumber_Add(__pyx_v_offset, __pyx_v_m); if (unlikely(!__pyx_t_11)) __PYX_ERR(1, 418, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_7 = __Pyx_PyIndex_AsSsize_t(__pyx_t_11); if (unlikely((__pyx_t_7 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 418, __pyx_L1_error) __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_t_11 = __Pyx_PyInt_From_int32_t((__pyx_v_self->nodes[__pyx_t_7]).prod); if (unlikely(!__pyx_t_11)) __PYX_ERR(1, 418, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_12 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_10); if (likely(__pyx_t_12)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10); __Pyx_INCREF(__pyx_t_12); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_10, function); } } if (!__pyx_t_12) { __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_11); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 418, __pyx_L1_error) __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_GOTREF(__pyx_t_9); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_10)) { PyObject *__pyx_temp[2] = {__pyx_t_12, __pyx_t_11}; __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 418, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { PyObject *__pyx_temp[2] = {__pyx_t_12, __pyx_t_11}; __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 418, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; } else #endif { __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 418, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_12); __pyx_t_12 = NULL; __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_t_11); __pyx_t_11 = 0; __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_13, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 418, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; } } __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
+419: print()
__pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_builtin_print); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 419, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
420: # for a, m in sorted(vocab.prods.items(), key=lambda x: x[1]):
421: # print("%d. '%s' '%s' '%s'" % (m, vocab.labels[m], vocab.words[m], a))
422: # print()
423:
+424: def __dealloc__(self):
/* Python wrapper */
static void __pyx_pw_8discodop_10containers_6Ctrees_15__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_8discodop_10containers_6Ctrees_15__dealloc__(PyObject *__pyx_v_self) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
__pyx_pf_8discodop_10containers_6Ctrees_14__dealloc__(((struct __pyx_obj_8discodop_10containers_Ctrees *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
}
static void __pyx_pf_8discodop_10containers_6Ctrees_14__dealloc__(struct __pyx_obj_8discodop_10containers_Ctrees *__pyx_v_self) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__dealloc__", 0);
/* … */
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_WriteUnraisable("discodop.containers.Ctrees.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
__pyx_L0:;
__Pyx_RefNannyFinishContext();
}
+425: if isinstance(self._state, tuple):
__pyx_t_1 = __pyx_v_self->_state; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = PyTuple_Check(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = (__pyx_t_2 != 0); if (__pyx_t_3) { /* … */ }
+426: self._state[1].close()
__pyx_t_4 = __Pyx_GetItemInt(__pyx_v_self->_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 426, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_close); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 426, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_5, function); } } if (__pyx_t_4) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 426, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 426, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+427: os.close(self._state[0])
__pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 427, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_close); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 427, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_self->_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 427, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_6)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); } } if (!__pyx_t_6) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 427, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_1); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 427, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_5}; __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 427, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif { __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 427, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5); __pyx_t_5 = 0; __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 427, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+428: self._state = None
__Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GOTREF(__pyx_v_self->_state); __Pyx_DECREF(__pyx_v_self->_state); __pyx_v_self->_state = Py_None;
+429: return
goto __pyx_L0;
+430: elif isinstance(self._state, dict):
__pyx_t_1 = __pyx_v_self->_state; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = PyDict_Check(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_2 = (__pyx_t_3 != 0); if (__pyx_t_2) { /* … */ }
+431: return
goto __pyx_L0;
+432: if self.nodes is not NULL:
__pyx_t_2 = ((__pyx_v_self->nodes != NULL) != 0);
if (__pyx_t_2) {
/* … */
}
+433: free(self.nodes)
free(__pyx_v_self->nodes);
+434: self.nodes = NULL
__pyx_v_self->nodes = NULL;
+435: if self.trees is not NULL:
__pyx_t_2 = ((__pyx_v_self->trees != NULL) != 0);
if (__pyx_t_2) {
/* … */
}
+436: free(self.trees)
free(__pyx_v_self->trees);
+437: self.trees = NULL
__pyx_v_self->trees = NULL;
438:
+439: def __len__(self):
/* Python wrapper */
static Py_ssize_t __pyx_pw_8discodop_10containers_6Ctrees_17__len__(PyObject *__pyx_v_self); /*proto*/
static Py_ssize_t __pyx_pw_8discodop_10containers_6Ctrees_17__len__(PyObject *__pyx_v_self) {
Py_ssize_t __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__len__ (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_6Ctrees_16__len__(((struct __pyx_obj_8discodop_10containers_Ctrees *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static Py_ssize_t __pyx_pf_8discodop_10containers_6Ctrees_16__len__(struct __pyx_obj_8discodop_10containers_Ctrees *__pyx_v_self) {
Py_ssize_t __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__len__", 0);
/* … */
/* function exit code */
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+440: return self.len
__pyx_r = __pyx_v_self->len; goto __pyx_L0;
441:
+442: def __reduce__(self):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_19__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_8discodop_10containers_6Ctrees_18__reduce__[] = "Ctrees.__reduce__(self)\nHelper function for pickling.";
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_19__reduce__(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__reduce__ (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_6Ctrees_18__reduce__(((struct __pyx_obj_8discodop_10containers_Ctrees *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_6Ctrees_18__reduce__(struct __pyx_obj_8discodop_10containers_Ctrees *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__reduce__", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_AddTraceback("discodop.containers.Ctrees.__reduce__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
443: """Helper function for pickling."""
+444: return (Ctrees, (),
__Pyx_XDECREF(__pyx_r); /* … */ __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 444, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_ptype_8discodop_10containers_Ctrees)); __Pyx_GIVEREF(((PyObject *)__pyx_ptype_8discodop_10containers_Ctrees)); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_ptype_8discodop_10containers_Ctrees)); __Pyx_INCREF(__pyx_empty_tuple); __Pyx_GIVEREF(__pyx_empty_tuple); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_empty_tuple); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+445: dict(nodes=<bytes>(<char *>self.nodes)[
__pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 445, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); /* … */ __pyx_t_2 = __Pyx_PyBytes_FromStringAndSize(((char *)__pyx_v_self->nodes) + 0, (__pyx_v_self->numnodes * (sizeof((__pyx_v_self->nodes[0])))) - 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 445, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); /* … */ if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_nodes, __pyx_t_2) < 0) __PYX_ERR(1, 445, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
446: :self.numnodes * sizeof(self.nodes[0])],
+447: trees=<bytes>(<char *>self.trees)[
__pyx_t_2 = __Pyx_PyBytes_FromStringAndSize(((char *)__pyx_v_self->trees) + 0, (__pyx_v_self->len * (sizeof((__pyx_v_self->trees[0])))) - 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 447, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_trees, __pyx_t_2) < 0) __PYX_ERR(1, 445, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
448: :self.len * sizeof(self.trees[0])],
+449: len=self.len,
__pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->len); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 449, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_len, __pyx_t_2) < 0) __PYX_ERR(1, 445, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+450: numnodes=self.numnodes,
__pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_self->numnodes); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 450, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_numnodes, __pyx_t_2) < 0) __PYX_ERR(1, 445, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+451: numwords=self.numwords,
__pyx_t_2 = __Pyx_PyInt_FromSize_t(__pyx_v_self->numwords); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 451, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_numwords, __pyx_t_2) < 0) __PYX_ERR(1, 445, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+452: maxnodes=self.maxnodes,
__pyx_t_2 = __Pyx_PyInt_From_short(__pyx_v_self->maxnodes); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 452, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_maxnodes, __pyx_t_2) < 0) __PYX_ERR(1, 445, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+453: prodindex=self.prodindex))
if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_prodindex, __pyx_v_self->prodindex) < 0) __PYX_ERR(1, 445, __pyx_L1_error)
454:
+455: def __setstate__(self, state):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_21__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state); /*proto*/
static char __pyx_doc_8discodop_10containers_6Ctrees_20__setstate__[] = "Ctrees.__setstate__(self, state)";
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_21__setstate__(PyObject *__pyx_v_self, PyObject *__pyx_v_state) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__setstate__ (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_6Ctrees_20__setstate__(((struct __pyx_obj_8discodop_10containers_Ctrees *)__pyx_v_self), ((PyObject *)__pyx_v_state));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_6Ctrees_20__setstate__(struct __pyx_obj_8discodop_10containers_Ctrees *__pyx_v_self, PyObject *__pyx_v_state) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__setstate__", 0);
/* … */
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("discodop.containers.Ctrees.__setstate__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+456: self.len = self.max = state['len']
__pyx_t_1 = PyObject_GetItem(__pyx_v_state, __pyx_n_u_len); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 456, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 456, __pyx_L1_error) __pyx_t_3 = __Pyx_PyInt_As_long(__pyx_t_1); if (unlikely((__pyx_t_3 == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 456, __pyx_L1_error) __pyx_v_self->len = __pyx_t_2; __pyx_v_self->max = __pyx_t_3; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+457: self.numnodes = state['numnodes']
__pyx_t_1 = PyObject_GetItem(__pyx_v_state, __pyx_n_u_numnodes); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = __Pyx_PyInt_As_size_t(__pyx_t_1); if (unlikely((__pyx_t_4 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 457, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_self->numnodes = __pyx_t_4;
+458: self.numwords = state['numwords']
__pyx_t_1 = PyObject_GetItem(__pyx_v_state, __pyx_n_u_numwords); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 458, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = __Pyx_PyInt_As_size_t(__pyx_t_1); if (unlikely((__pyx_t_4 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 458, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_self->numwords = __pyx_t_4;
+459: self.maxnodes = state['maxnodes']
__pyx_t_1 = PyObject_GetItem(__pyx_v_state, __pyx_n_u_maxnodes); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 459, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __Pyx_PyInt_As_short(__pyx_t_1); if (unlikely((__pyx_t_5 == (short)-1) && PyErr_Occurred())) __PYX_ERR(1, 459, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_self->maxnodes = __pyx_t_5;
+460: self.prodindex = state['prodindex']
__pyx_t_1 = PyObject_GetItem(__pyx_v_state, __pyx_n_u_prodindex); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 460, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->prodindex); __Pyx_DECREF(__pyx_v_self->prodindex); __pyx_v_self->prodindex = __pyx_t_1; __pyx_t_1 = 0;
461: # self.alloc(self.len, self.numnodes)
+462: self.nodesleft = 0
__pyx_v_self->nodesleft = 0;
+463: self.nodes = <Node *><char *><bytes>state['nodes']
__pyx_t_1 = PyObject_GetItem(__pyx_v_state, __pyx_n_u_nodes); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 463, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __Pyx_PyObject_AsWritableString(__pyx_t_1); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(1, 463, __pyx_L1_error) __pyx_v_self->nodes = ((struct __pyx_t_8discodop_10containers_Node *)((char *)__pyx_t_6)); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+464: self.trees = <NodeArray *><char *><bytes>state['trees']
__pyx_t_1 = PyObject_GetItem(__pyx_v_state, __pyx_n_u_trees); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 464, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __Pyx_PyObject_AsWritableString(__pyx_t_1); if (unlikely((!__pyx_t_6) && PyErr_Occurred())) __PYX_ERR(1, 464, __pyx_L1_error) __pyx_v_self->trees = ((struct __pyx_t_8discodop_10containers_NodeArray *)((char *)__pyx_t_6)); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+465: self._state = state # keep reference alive
__Pyx_INCREF(__pyx_v_state); __Pyx_GIVEREF(__pyx_v_state); __Pyx_GOTREF(__pyx_v_self->_state); __Pyx_DECREF(__pyx_v_self->_state); __pyx_v_self->_state = __pyx_v_state;
466:
+467: def tofile(self, filename):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_23tofile(PyObject *__pyx_v_self, PyObject *__pyx_v_filename); /*proto*/
static char __pyx_doc_8discodop_10containers_6Ctrees_22tofile[] = "Ctrees.tofile(self, filename)";
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_23tofile(PyObject *__pyx_v_self, PyObject *__pyx_v_filename) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("tofile (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_6Ctrees_22tofile(((struct __pyx_obj_8discodop_10containers_Ctrees *)__pyx_v_self), ((PyObject *)__pyx_v_filename));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_6Ctrees_22tofile(struct __pyx_obj_8discodop_10containers_Ctrees *__pyx_v_self, PyObject *__pyx_v_filename) {
arrayobject *__pyx_v_out = 0;
uint64_t *__pyx_v_ptr;
int __pyx_v_offset;
PyObject *__pyx_v_tmp = 0;
PyObject *__pyx_v_outfile = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("tofile", 0);
/* … */
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_10);
__Pyx_AddTraceback("discodop.containers.Ctrees.tofile", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_out);
__Pyx_XDECREF(__pyx_v_tmp);
__Pyx_XDECREF(__pyx_v_outfile);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
468: cdef array out
469: cdef uint64_t *ptr
470: cdef int offset
+471: cdef bytes tmp = self.prodindex.__getstate__()
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->prodindex, __pyx_n_s_getstate); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 471, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); } } if (__pyx_t_3) { __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 471, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 471, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (!(likely(PyBytes_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(1, 471, __pyx_L1_error) __pyx_v_tmp = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+472: out = clone(chararray,
__pyx_t_1 = ((PyObject *)__pyx_v_8discodop_10containers_chararray); __Pyx_INCREF(__pyx_t_1); /* … */ __pyx_t_2 = ((PyObject *)__pyx_f_7cpython_5array_clone(((arrayobject *)__pyx_t_1), ((((4 * (sizeof(uint64_t))) + __pyx_t_4) + (__pyx_v_self->len * (sizeof(struct __pyx_t_8discodop_10containers_NodeArray)))) + (__pyx_v_self->numnodes * (sizeof(struct __pyx_t_8discodop_10containers_Node)))), 0)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 472, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_out = ((arrayobject *)__pyx_t_2); __pyx_t_2 = 0;
473: 4 * sizeof(uint64_t)
+474: + len(tmp)
if (unlikely(__pyx_v_tmp == Py_None)) {
PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
__PYX_ERR(1, 474, __pyx_L1_error)
}
__pyx_t_4 = PyBytes_GET_SIZE(__pyx_v_tmp); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(1, 474, __pyx_L1_error)
475: + self.len * sizeof(NodeArray)
476: + self.numnodes * sizeof(Node),
477: False)
+478: ptr = <uint64_t *>out.data.as_chars
__pyx_v_ptr = ((uint64_t *)__pyx_v_out->data.as_chars);
+479: ptr[0] = self.len
__pyx_t_5 = __pyx_v_self->len; (__pyx_v_ptr[0]) = __pyx_t_5;
+480: ptr[1] = self.numnodes
__pyx_t_6 = __pyx_v_self->numnodes; (__pyx_v_ptr[1]) = __pyx_t_6;
+481: ptr[2] = self.numwords
__pyx_t_6 = __pyx_v_self->numwords; (__pyx_v_ptr[2]) = __pyx_t_6;
+482: ptr[3] = self.maxnodes
__pyx_t_7 = __pyx_v_self->maxnodes; (__pyx_v_ptr[3]) = __pyx_t_7;
+483: offset = 4 * sizeof(uint64_t)
__pyx_v_offset = (4 * (sizeof(uint64_t)));
+484: memcpy(&(out.data.as_chars[offset]), <char *>tmp, len(tmp))
__pyx_t_8 = __Pyx_PyObject_AsWritableString(__pyx_v_tmp); if (unlikely((!__pyx_t_8) && PyErr_Occurred())) __PYX_ERR(1, 484, __pyx_L1_error) if (unlikely(__pyx_v_tmp == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); __PYX_ERR(1, 484, __pyx_L1_error) } __pyx_t_4 = PyBytes_GET_SIZE(__pyx_v_tmp); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(1, 484, __pyx_L1_error) memcpy((&(__pyx_v_out->data.as_chars[__pyx_v_offset])), ((char *)__pyx_t_8), __pyx_t_4);
+485: offset += len(tmp)
if (unlikely(__pyx_v_tmp == Py_None)) {
PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
__PYX_ERR(1, 485, __pyx_L1_error)
}
__pyx_t_4 = PyBytes_GET_SIZE(__pyx_v_tmp); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(1, 485, __pyx_L1_error)
__pyx_v_offset = (__pyx_v_offset + __pyx_t_4);
+486: memcpy(&(out.data.as_chars[offset]), <char *>self.trees,
memcpy((&(__pyx_v_out->data.as_chars[__pyx_v_offset])), ((char *)__pyx_v_self->trees), (__pyx_v_self->len * (sizeof(struct __pyx_t_8discodop_10containers_NodeArray))));
487: self.len * sizeof(NodeArray))
+488: offset += self.len * sizeof(NodeArray)
__pyx_v_offset = (__pyx_v_offset + (__pyx_v_self->len * (sizeof(struct __pyx_t_8discodop_10containers_NodeArray))));
+489: memcpy(&(out.data.as_chars[offset]), <char *>self.nodes,
memcpy((&(__pyx_v_out->data.as_chars[__pyx_v_offset])), ((char *)__pyx_v_self->nodes), (__pyx_v_self->numnodes * (sizeof(struct __pyx_t_8discodop_10containers_Node))));
490: self.numnodes * sizeof(Node))
+491: with open(filename, 'wb') as outfile:
/*with:*/ {
__pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 491, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(__pyx_v_filename);
__Pyx_GIVEREF(__pyx_v_filename);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_filename);
__Pyx_INCREF(__pyx_n_u_wb);
__Pyx_GIVEREF(__pyx_n_u_wb);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_n_u_wb);
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 491, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_9 = __Pyx_PyObject_LookupSpecial(__pyx_t_1, __pyx_n_s_exit); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 491, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_9);
__pyx_t_3 = __Pyx_PyObject_LookupSpecial(__pyx_t_1, __pyx_n_s_enter); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 491, __pyx_L3_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_10 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
__pyx_t_10 = PyMethod_GET_SELF(__pyx_t_3);
if (likely(__pyx_t_10)) {
PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
__Pyx_INCREF(__pyx_t_10);
__Pyx_INCREF(function);
__Pyx_DECREF_SET(__pyx_t_3, function);
}
}
if (__pyx_t_10) {
__pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 491, __pyx_L3_error)
__Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
} else {
__pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 491, __pyx_L3_error)
}
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = __pyx_t_2;
__pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/*try:*/ {
{
/*try:*/ {
__pyx_v_outfile = __pyx_t_3;
__pyx_t_3 = 0;
/* … */
}
__Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
__Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
__Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
goto __pyx_L12_try_end;
__pyx_L7_error:;
__Pyx_PyThreadState_assign
__Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
__Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
/*except:*/ {
__Pyx_AddTraceback("discodop.containers.Ctrees.tofile", __pyx_clineno, __pyx_lineno, __pyx_filename);
if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_1, &__pyx_t_10) < 0) __PYX_ERR(1, 491, __pyx_L9_except_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_GOTREF(__pyx_t_1);
__Pyx_GOTREF(__pyx_t_10);
__pyx_t_2 = PyTuple_Pack(3, __pyx_t_3, __pyx_t_1, __pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 491, __pyx_L9_except_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_2, NULL);
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (unlikely(!__pyx_t_14)) __PYX_ERR(1, 491, __pyx_L9_except_error)
__Pyx_GOTREF(__pyx_t_14);
__pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_14);
__Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
if (__pyx_t_15 < 0) __PYX_ERR(1, 491, __pyx_L9_except_error)
__pyx_t_16 = ((!(__pyx_t_15 != 0)) != 0);
if (__pyx_t_16) {
__Pyx_GIVEREF(__pyx_t_3);
__Pyx_GIVEREF(__pyx_t_1);
__Pyx_XGIVEREF(__pyx_t_10);
__Pyx_ErrRestoreWithState(__pyx_t_3, __pyx_t_1, __pyx_t_10);
__pyx_t_3 = 0; __pyx_t_1 = 0; __pyx_t_10 = 0;
__PYX_ERR(1, 491, __pyx_L9_except_error)
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
goto __pyx_L8_exception_handled;
}
__pyx_L9_except_error:;
__Pyx_PyThreadState_assign
__Pyx_XGIVEREF(__pyx_t_11);
__Pyx_XGIVEREF(__pyx_t_12);
__Pyx_XGIVEREF(__pyx_t_13);
__Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13);
goto __pyx_L1_error;
__pyx_L8_exception_handled:;
__Pyx_PyThreadState_assign
__Pyx_XGIVEREF(__pyx_t_11);
__Pyx_XGIVEREF(__pyx_t_12);
__Pyx_XGIVEREF(__pyx_t_13);
__Pyx_ExceptionReset(__pyx_t_11, __pyx_t_12, __pyx_t_13);
__pyx_L12_try_end:;
}
}
/*finally:*/ {
/*normal exit:*/{
if (__pyx_t_9) {
__pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__37, NULL);
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
if (unlikely(!__pyx_t_13)) __PYX_ERR(1, 491, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_13);
__Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
}
goto __pyx_L6;
}
__pyx_L6:;
}
goto __pyx_L16;
__pyx_L3_error:;
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
goto __pyx_L1_error;
__pyx_L16:;
}
/* … */
__pyx_tuple__37 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(1, 491, __pyx_L1_error)
__Pyx_GOTREF(__pyx_tuple__37);
__Pyx_GIVEREF(__pyx_tuple__37);
+492: out.tofile(outfile)
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_out), __pyx_n_s_tofile); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 492, __pyx_L7_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_2)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_1, function); } } if (!__pyx_t_2) { __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_outfile); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 492, __pyx_L7_error) __Pyx_GOTREF(__pyx_t_3); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_1)) { PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_outfile}; __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 492, __pyx_L7_error) __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_outfile}; __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 492, __pyx_L7_error) __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_3); } else #endif { __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(1, 492, __pyx_L7_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_2); __pyx_t_2 = NULL; __Pyx_INCREF(__pyx_v_outfile); __Pyx_GIVEREF(__pyx_v_outfile); PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_v_outfile); __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 492, __pyx_L7_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
493:
+494: @classmethod
__pyx_t_2 = __Pyx_Method_ClassMethod(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 494, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (PyDict_SetItem((PyObject *)__pyx_ptype_8discodop_10containers_Ctrees->tp_dict, __pyx_n_s_fromfile, __pyx_t_2) < 0) __PYX_ERR(1, 495, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; PyType_Modified(__pyx_ptype_8discodop_10containers_Ctrees);
+495: def fromfile(cls, filename):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_25fromfile(PyObject *__pyx_v_cls, PyObject *__pyx_v_filename); /*proto*/
static char __pyx_doc_8discodop_10containers_6Ctrees_24fromfile[] = "Ctrees.fromfile(type cls, filename)";
static PyObject *__pyx_pw_8discodop_10containers_6Ctrees_25fromfile(PyObject *__pyx_v_cls, PyObject *__pyx_v_filename) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("fromfile (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_6Ctrees_24fromfile(((PyTypeObject*)__pyx_v_cls), ((PyObject *)__pyx_v_filename));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_6Ctrees_24fromfile(CYTHON_UNUSED PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_filename) {
struct __pyx_obj_8discodop_10containers_Ctrees *__pyx_v_ob = 0;
size_t __pyx_v_prodidxsize;
Py_buffer __pyx_v_buffer;
Py_ssize_t __pyx_v_size;
char *__pyx_v_ptr;
uint64_t *__pyx_v_header;
int __pyx_v_result;
PyObject *__pyx_v_fileno = NULL;
PyObject *__pyx_v_buf = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("fromfile", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_AddTraceback("discodop.containers.Ctrees.fromfile", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_ob);
__Pyx_XDECREF(__pyx_v_fileno);
__Pyx_XDECREF(__pyx_v_buf);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_t_1 = __Pyx_GetNameInClass((PyObject *)__pyx_ptype_8discodop_10containers_Ctrees, __pyx_n_s_fromfile); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 495, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
+496: cdef Ctrees ob = Ctrees.__new__(Ctrees)
__pyx_t_1 = __pyx_tp_new_8discodop_10containers_Ctrees(((PyTypeObject *)__pyx_ptype_8discodop_10containers_Ctrees), __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 496, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8discodop_10containers_Ctrees)))) __PYX_ERR(1, 496, __pyx_L1_error) __pyx_v_ob = ((struct __pyx_obj_8discodop_10containers_Ctrees *)__pyx_t_1); __pyx_t_1 = 0;
497: cdef size_t prodidxsize
498: cdef Py_buffer buffer
+499: cdef Py_ssize_t size = 0
__pyx_v_size = 0;
+500: cdef char *ptr = NULL
__pyx_v_ptr = NULL;
+501: cdef uint64_t *header = NULL
__pyx_v_header = NULL;
502: cdef int result
+503: fileno = os.open(filename, os.O_RDONLY)
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 503, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_open); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 503, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 503, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_O_RDONLY); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 503, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = NULL; __pyx_t_5 = 0; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_2)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); __pyx_t_5 = 1; } } #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_filename, __pyx_t_4}; __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 503, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_filename, __pyx_t_4}; __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 503, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 503, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); if (__pyx_t_2) { __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); __pyx_t_2 = NULL; } __Pyx_INCREF(__pyx_v_filename); __Pyx_GIVEREF(__pyx_v_filename); PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_filename); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_4); __pyx_t_4 = 0; __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 503, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_fileno = __pyx_t_1; __pyx_t_1 = 0;
+504: buf = mmap.mmap(fileno, 0, access=mmap.ACCESS_READ)
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_mmap); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 504, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_mmap); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 504, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 504, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_fileno); __Pyx_GIVEREF(__pyx_v_fileno); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_fileno); __Pyx_INCREF(__pyx_int_0); __Pyx_GIVEREF(__pyx_int_0); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_0); __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 504, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_mmap); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 504, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ACCESS_READ); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 504, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_access, __pyx_t_2) < 0) __PYX_ERR(1, 504, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 504, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_v_buf = __pyx_t_2; __pyx_t_2 = 0;
+505: ob._state = (fileno, buf)
__pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 505, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v_fileno); __Pyx_GIVEREF(__pyx_v_fileno); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_fileno); __Pyx_INCREF(__pyx_v_buf); __Pyx_GIVEREF(__pyx_v_buf); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_buf); __Pyx_GIVEREF(__pyx_t_2); __Pyx_GOTREF(__pyx_v_ob->_state); __Pyx_DECREF(__pyx_v_ob->_state); __pyx_v_ob->_state = __pyx_t_2; __pyx_t_2 = 0;
+506: result = getbufptr(buf, &ptr, &size, &buffer)
__pyx_v_result = __pyx_f_8discodop_10containers_getbufptr(__pyx_v_buf, (&__pyx_v_ptr), (&__pyx_v_size), (&__pyx_v_buffer));
+507: if result != 0:
__pyx_t_7 = ((__pyx_v_result != 0) != 0);
if (__pyx_t_7) {
/* … */
}
+508: raise ValueError('could not get buffer from mmap.')
__pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__38, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 508, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __PYX_ERR(1, 508, __pyx_L1_error) /* … */ __pyx_tuple__38 = PyTuple_Pack(1, __pyx_kp_u_could_not_get_buffer_from_mmap); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(1, 508, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__38); __Pyx_GIVEREF(__pyx_tuple__38);
+509: header = <uint64_t *>ptr
__pyx_v_header = ((uint64_t *)__pyx_v_ptr);
+510: ob.len = ob.max = header[0]
__pyx_v_ob->len = (__pyx_v_header[0]); __pyx_v_ob->max = (__pyx_v_header[0]);
+511: ob.numnodes, ob.numwords, ob.maxnodes = header[1], header[2], header[3]
__pyx_t_8 = (__pyx_v_header[1]); __pyx_t_9 = (__pyx_v_header[2]); __pyx_t_10 = (__pyx_v_header[3]); __pyx_v_ob->numnodes = __pyx_t_8; __pyx_v_ob->numwords = __pyx_t_9; __pyx_v_ob->maxnodes = __pyx_t_10;
+512: ob.nodesleft = 0
__pyx_v_ob->nodesleft = 0;
+513: ob.prodindex = MultiRoaringBitmap.frombuffer(buf, 4 * sizeof(uint64_t))
__pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_MultiRoaringBitmap); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 513, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_frombuffer); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 513, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = __Pyx_PyInt_FromSize_t((4 * (sizeof(uint64_t)))); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 513, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_3 = NULL; __pyx_t_5 = 0; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_1, function); __pyx_t_5 = 1; } } #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_1)) { PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_buf, __pyx_t_6}; __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 513, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) { PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_buf, __pyx_t_6}; __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 513, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else #endif { __pyx_t_4 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 513, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); if (__pyx_t_3) { __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL; } __Pyx_INCREF(__pyx_v_buf); __Pyx_GIVEREF(__pyx_v_buf); PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_5, __pyx_v_buf); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_5, __pyx_t_6); __pyx_t_6 = 0; __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 513, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_GIVEREF(__pyx_t_2); __Pyx_GOTREF(__pyx_v_ob->prodindex); __Pyx_DECREF(__pyx_v_ob->prodindex); __pyx_v_ob->prodindex = __pyx_t_2; __pyx_t_2 = 0;
+514: prodidxsize = ob.prodindex.bufsize()
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_ob->prodindex, __pyx_n_s_bufsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 514, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_1, function); } } if (__pyx_t_4) { __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 514, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 514, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_11 = __Pyx_PyInt_As_size_t(__pyx_t_2); if (unlikely((__pyx_t_11 == (size_t)-1) && PyErr_Occurred())) __PYX_ERR(1, 514, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_prodidxsize = __pyx_t_11;
+515: ob.trees = <NodeArray *>&(ptr[4 * sizeof(uint64_t) + prodidxsize])
__pyx_v_ob->trees = ((struct __pyx_t_8discodop_10containers_NodeArray *)(&(__pyx_v_ptr[((4 * (sizeof(uint64_t))) + __pyx_v_prodidxsize)])));
+516: ob.nodes = <Node *>&ob.trees[ob.len]
__pyx_v_ob->nodes = ((struct __pyx_t_8discodop_10containers_Node *)(&(__pyx_v_ob->trees[__pyx_v_ob->len])));
+517: PyBuffer_Release(&buffer)
PyBuffer_Release((&__pyx_v_buffer));
+518: return ob
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_ob)); __pyx_r = ((PyObject *)__pyx_v_ob); goto __pyx_L0;
519:
520:
+521: cdef inline getyf(tuple yf, uint32_t *args, uint32_t *lengths):
static CYTHON_INLINE PyObject *__pyx_f_8discodop_10containers_getyf(PyObject *__pyx_v_yf, uint32_t *__pyx_v_args, uint32_t *__pyx_v_lengths) {
int __pyx_v_m;
PyObject *__pyx_v_part = NULL;
PyObject *__pyx_v_a = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("getyf", 0);
/* … */
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_9);
__Pyx_AddTraceback("discodop.containers.getyf", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_part);
__Pyx_XDECREF(__pyx_v_a);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+522: cdef int m = 0
__pyx_v_m = 0;
+523: args[0] = lengths[0] = 0
(__pyx_v_args[0]) = 0; (__pyx_v_lengths[0]) = 0;
+524: for part in yf:
if (unlikely(__pyx_v_yf == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
__PYX_ERR(1, 524, __pyx_L1_error)
}
__pyx_t_1 = __pyx_v_yf; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
for (;;) {
if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
__pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(1, 524, __pyx_L1_error)
#else
__pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 524, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
#endif
__Pyx_XDECREF_SET(__pyx_v_part, __pyx_t_3);
__pyx_t_3 = 0;
/* … */
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+525: for a in part:
if (likely(PyList_CheckExact(__pyx_v_part)) || PyTuple_CheckExact(__pyx_v_part)) { __pyx_t_3 = __pyx_v_part; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; __pyx_t_5 = NULL; } else { __pyx_t_4 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_part); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 525, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 525, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_5)) { if (likely(PyList_CheckExact(__pyx_t_3))) { if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_6 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(1, 525, __pyx_L1_error) #else __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 525, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); #endif } else { if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_4); __Pyx_INCREF(__pyx_t_6); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(1, 525, __pyx_L1_error) #else __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 525, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); #endif } } else { __pyx_t_6 = __pyx_t_5(__pyx_t_3); if (unlikely(!__pyx_t_6)) { PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); else __PYX_ERR(1, 525, __pyx_L1_error) } break; } __Pyx_GOTREF(__pyx_t_6); } __Pyx_XDECREF_SET(__pyx_v_a, __pyx_t_6); __pyx_t_6 = 0; /* … */ } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+526: if a == 1:
__pyx_t_6 = __Pyx_PyInt_EqObjC(__pyx_v_a, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 526, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(1, 526, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (__pyx_t_7) { /* … */ goto __pyx_L7; }
+527: args[0] += 1 << m
__pyx_t_8 = 0;
(__pyx_v_args[__pyx_t_8]) = ((__pyx_v_args[__pyx_t_8]) + (1 << __pyx_v_m));
+528: elif a != 0:
__pyx_t_6 = PyObject_RichCompare(__pyx_v_a, __pyx_int_0, Py_NE); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 528, __pyx_L1_error) __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(1, 528, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (__pyx_t_7) { /* … */ } __pyx_L7:;
+529: raise ValueError('expected: 0 or 1; got: %r' % a)
__pyx_t_6 = PyUnicode_Format(__pyx_kp_u_expected_0_or_1_got_r, __pyx_v_a); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 529, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 529, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_9, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 529, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_Raise(__pyx_t_6, 0, 0, 0); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __PYX_ERR(1, 529, __pyx_L1_error)
+530: m += 1
__pyx_v_m = (__pyx_v_m + 1);
+531: lengths[0] |= 1 << (m - 1)
__pyx_t_8 = 0;
(__pyx_v_lengths[__pyx_t_8]) = ((__pyx_v_lengths[__pyx_t_8]) | (1 << (__pyx_v_m - 1)));
532:
533:
+534: cdef inline darray_init(DArray *self, uint8_t itemsize):
static CYTHON_INLINE PyObject *__pyx_f_8discodop_10containers_darray_init(struct __pyx_t_8discodop_10containers_DArray *__pyx_v_self, uint8_t __pyx_v_itemsize) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("darray_init", 0);
/* … */
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_AddTraceback("discodop.containers.darray_init", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+535: self.len = 0
__pyx_v_self->len = 0;
+536: self.capacity = 4
__pyx_v_self->capacity = 4;
+537: self.itemsize = itemsize
__pyx_v_self->itemsize = __pyx_v_itemsize;
+538: self.d.ptr = malloc(self.capacity * itemsize)
__pyx_v_self->d.ptr = malloc((__pyx_v_self->capacity * __pyx_v_itemsize));
+539: if self.d.ptr is NULL:
__pyx_t_1 = ((__pyx_v_self->d.ptr == NULL) != 0);
if (__pyx_t_1) {
/* … */
}
+540: raise MemoryError
PyErr_NoMemory(); __PYX_ERR(1, 540, __pyx_L1_error)
541:
542:
+543: cdef inline darray_append_uint32(DArray *self, uint32_t elem):
static CYTHON_INLINE PyObject *__pyx_f_8discodop_10containers_darray_append_uint32(struct __pyx_t_8discodop_10containers_DArray *__pyx_v_self, uint32_t __pyx_v_elem) {
void *__pyx_v_tmp;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("darray_append_uint32", 0);
/* … */
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_AddTraceback("discodop.containers.darray_append_uint32", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
544: cdef void *tmp
+545: if self.len == self.capacity:
__pyx_t_1 = ((__pyx_v_self->len == __pyx_v_self->capacity) != 0);
if (__pyx_t_1) {
/* … */
}
+546: self.capacity *= 2
__pyx_v_self->capacity = (__pyx_v_self->capacity * 2);
+547: tmp = realloc(self.d.ptr, self.capacity * self.itemsize)
__pyx_v_tmp = realloc(__pyx_v_self->d.ptr, (__pyx_v_self->capacity * __pyx_v_self->itemsize));
+548: if tmp is NULL:
__pyx_t_1 = ((__pyx_v_tmp == NULL) != 0);
if (__pyx_t_1) {
/* … */
}
+549: raise MemoryError
PyErr_NoMemory(); __PYX_ERR(1, 549, __pyx_L1_error)
+550: self.d.ptr = tmp
__pyx_v_self->d.ptr = __pyx_v_tmp;
+551: self.d.asint[self.len] = elem
(__pyx_v_self->d.asint[__pyx_v_self->len]) = __pyx_v_elem;
+552: self.len += 1
__pyx_v_self->len = (__pyx_v_self->len + 1);
553:
554:
+555: cdef inline darray_extend(DArray *self, bytes data):
static CYTHON_INLINE PyObject *__pyx_f_8discodop_10containers_darray_extend(struct __pyx_t_8discodop_10containers_DArray *__pyx_v_self, PyObject *__pyx_v_data) {
void *__pyx_v_tmp;
int __pyx_v_n;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("darray_extend", 0);
/* … */
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_AddTraceback("discodop.containers.darray_extend", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
556: cdef void *tmp
+557: cdef int n = len(data)
if (unlikely(__pyx_v_data == Py_None)) {
PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
__PYX_ERR(1, 557, __pyx_L1_error)
}
__pyx_t_1 = PyBytes_GET_SIZE(__pyx_v_data); if (unlikely(__pyx_t_1 == -1)) __PYX_ERR(1, 557, __pyx_L1_error)
__pyx_v_n = __pyx_t_1;
+558: if self.len + n >= self.capacity:
__pyx_t_2 = (((__pyx_v_self->len + __pyx_v_n) >= __pyx_v_self->capacity) != 0);
if (__pyx_t_2) {
/* … */
}
+559: self.capacity = 2 * (self.capacity + n)
__pyx_v_self->capacity = (2 * (__pyx_v_self->capacity + __pyx_v_n));
+560: tmp = realloc(self.d.ptr, self.capacity * self.itemsize)
__pyx_v_tmp = realloc(__pyx_v_self->d.ptr, (__pyx_v_self->capacity * __pyx_v_self->itemsize));
+561: if tmp is NULL:
__pyx_t_2 = ((__pyx_v_tmp == NULL) != 0);
if (__pyx_t_2) {
/* … */
}
+562: raise MemoryError
PyErr_NoMemory(); __PYX_ERR(1, 562, __pyx_L1_error)
+563: self.d.ptr = tmp
__pyx_v_self->d.ptr = __pyx_v_tmp;
+564: memcpy(&(self.d.aschar[self.len]), <char *>data, n)
__pyx_t_3 = __Pyx_PyObject_AsWritableString(__pyx_v_data); if (unlikely((!__pyx_t_3) && PyErr_Occurred())) __PYX_ERR(1, 564, __pyx_L1_error) memcpy((&(__pyx_v_self->d.aschar[__pyx_v_self->len])), ((char *)__pyx_t_3), __pyx_v_n);
+565: self.len += n
__pyx_v_self->len = (__pyx_v_self->len + __pyx_v_n);
566:
567:
+568: cdef class Vocabulary:
struct __pyx_vtabstruct_8discodop_10containers_Vocabulary {
PyObject *(*idtolabel)(struct __pyx_obj_8discodop_10containers_Vocabulary *, uint32_t);
PyObject *(*getlabel)(struct __pyx_obj_8discodop_10containers_Vocabulary *, int);
PyObject *(*getword)(struct __pyx_obj_8discodop_10containers_Vocabulary *, int);
int (*islexical)(struct __pyx_obj_8discodop_10containers_Vocabulary *, int);
int (*getprod)(struct __pyx_obj_8discodop_10containers_Vocabulary *, PyObject *, PyObject *);
int (*_getprodid)(struct __pyx_obj_8discodop_10containers_Vocabulary *, PyObject *);
int (*_getlabelid)(struct __pyx_obj_8discodop_10containers_Vocabulary *, PyObject *);
};
static struct __pyx_vtabstruct_8discodop_10containers_Vocabulary *__pyx_vtabptr_8discodop_10containers_Vocabulary;
569: """A mapping of productions, labels, words to integers.
570:
571: - Vocabulary.getprod(): get prod no and add to index (mutating).
572: - FixedVocabulary.getprod(): lookup prod no given labels/words.
573: (no mutation, but requires makeindex())
574: - .getlabel(): lookup label/word given prod no (no mutation, arrays only)
575: """
+576: def __init__(self):
/* Python wrapper */
static int __pyx_pw_8discodop_10containers_10Vocabulary_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_pw_8discodop_10containers_10Vocabulary_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
if (unlikely(PyTuple_GET_SIZE(__pyx_args) > 0)) {
__Pyx_RaiseArgtupleInvalid("__init__", 1, 0, 0, PyTuple_GET_SIZE(__pyx_args)); return -1;}
if (unlikely(__pyx_kwds) && unlikely(PyDict_Size(__pyx_kwds) > 0) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__init__", 0))) return -1;
__pyx_r = __pyx_pf_8discodop_10containers_10Vocabulary___init__(((struct __pyx_obj_8discodop_10containers_Vocabulary *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static int __pyx_pf_8discodop_10containers_10Vocabulary___init__(struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_self) {
PyObject *__pyx_v_epsilon = 0;
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__init__", 0);
/* … */
/* function exit code */
__pyx_r = 0;
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_AddTraceback("discodop.containers.Vocabulary.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -1;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_epsilon);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+577: cdef bytes epsilon = b'Epsilon'
__Pyx_INCREF(__pyx_n_b_Epsilon);
__pyx_v_epsilon = __pyx_n_b_Epsilon;
+578: self.prods = {} # bytes objects => prodno
__pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 578, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->prods); __Pyx_DECREF(__pyx_v_self->prods); __pyx_v_self->prods = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+579: self.labels = {epsilon.decode('utf8'): 0} # str => labelno
__pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 579, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_decode_bytes(__pyx_v_epsilon, 0, PY_SSIZE_T_MAX, NULL, NULL, PyUnicode_DecodeUTF8); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 579, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_1, __pyx_t_2, __pyx_int_0) < 0) __PYX_ERR(1, 579, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GIVEREF(__pyx_t_1); __Pyx_GOTREF(__pyx_v_self->labels); __Pyx_DECREF(__pyx_v_self->labels); __pyx_v_self->labels = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+580: darray_init(&self.prodbuf, sizeof(char))
__pyx_t_1 = __pyx_f_8discodop_10containers_darray_init((&__pyx_v_self->prodbuf), (sizeof(char))); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 580, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+581: darray_init(&self.labelbuf, sizeof(char))
__pyx_t_1 = __pyx_f_8discodop_10containers_darray_init((&__pyx_v_self->labelbuf), (sizeof(char))); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 581, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+582: darray_init(&self.labelidx, sizeof(uint32_t))
__pyx_t_1 = __pyx_f_8discodop_10containers_darray_init((&__pyx_v_self->labelidx), (sizeof(uint32_t))); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 582, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+583: darray_append_uint32(&self.labelidx, 0)
__pyx_t_1 = __pyx_f_8discodop_10containers_darray_append_uint32((&__pyx_v_self->labelidx), 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 583, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+584: darray_append_uint32(&self.labelidx, len(epsilon))
__pyx_t_3 = PyBytes_GET_SIZE(__pyx_v_epsilon); if (unlikely(__pyx_t_3 == -1)) __PYX_ERR(1, 584, __pyx_L1_error) __pyx_t_1 = __pyx_f_8discodop_10containers_darray_append_uint32((&__pyx_v_self->labelidx), __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 584, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+585: darray_extend(&self.labelbuf, epsilon)
__pyx_t_1 = __pyx_f_8discodop_10containers_darray_extend((&__pyx_v_self->labelbuf), __pyx_v_epsilon); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 585, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
586:
+587: def __dealloc__(self):
/* Python wrapper */
static void __pyx_pw_8discodop_10containers_10Vocabulary_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_8discodop_10containers_10Vocabulary_3__dealloc__(PyObject *__pyx_v_self) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
__pyx_pf_8discodop_10containers_10Vocabulary_2__dealloc__(((struct __pyx_obj_8discodop_10containers_Vocabulary *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
}
static void __pyx_pf_8discodop_10containers_10Vocabulary_2__dealloc__(struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_self) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__dealloc__", 0);
/* … */
/* function exit code */
__pyx_L0:;
__Pyx_RefNannyFinishContext();
}
+588: if self.prodbuf.capacity == 0: # FixedVocabulary object
__pyx_t_1 = ((__pyx_v_self->prodbuf.capacity == 0) != 0);
if (__pyx_t_1) {
/* … */
}
+589: return
goto __pyx_L0;
+590: free(self.prodbuf.d.ptr)
free(__pyx_v_self->prodbuf.d.ptr);
+591: free(self.labelbuf.d.ptr)
free(__pyx_v_self->labelbuf.d.ptr);
+592: free(self.labelidx.d.ptr)
free(__pyx_v_self->labelidx.d.ptr);
+593: self.prodbuf.d.ptr = self.labelbuf.d.ptr = self.labelidx.d.ptr = NULL
__pyx_v_self->prodbuf.d.ptr = NULL; __pyx_v_self->labelbuf.d.ptr = NULL; __pyx_v_self->labelidx.d.ptr = NULL;
594:
+595: cdef int getprod(self, tuple r, tuple yf) except -2:
static int __pyx_f_8discodop_10containers_10Vocabulary_getprod(struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_self, PyObject *__pyx_v_r, PyObject *__pyx_v_yf) {
Rule __pyx_v_rule;
char *__pyx_v_tmp;
PyObject *__pyx_v_prod = NULL;
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("getprod", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_AddTraceback("discodop.containers.Vocabulary.getprod", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -2;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_prod);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
596: """Lookup/assign production ID. Add IDs for labels/words."""
597: cdef Rule rule
+598: cdef char *tmp = <char *>&rule
__pyx_v_tmp = ((char *)(&__pyx_v_rule));
+599: rule.lhs = self._getlabelid(r[0])
if (unlikely(__pyx_v_r == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(1, 599, __pyx_L1_error)
}
if (!(likely(PyUnicode_CheckExact(PyTuple_GET_ITEM(__pyx_v_r, 0)))||((PyTuple_GET_ITEM(__pyx_v_r, 0)) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(PyTuple_GET_ITEM(__pyx_v_r, 0))->tp_name), 0))) __PYX_ERR(1, 599, __pyx_L1_error)
__pyx_t_1 = PyTuple_GET_ITEM(__pyx_v_r, 0);
__Pyx_INCREF(__pyx_t_1);
__pyx_t_2 = ((struct __pyx_vtabstruct_8discodop_10containers_Vocabulary *)__pyx_v_self->__pyx_vtab)->_getlabelid(__pyx_v_self, ((PyObject*)__pyx_t_1)); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(1, 599, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_rule.lhs = __pyx_t_2;
+600: rule.rhs1 = self._getlabelid(r[1]) if len(r) > 1 else 0
if (unlikely(__pyx_v_r == Py_None)) {
PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
__PYX_ERR(1, 600, __pyx_L1_error)
}
__pyx_t_4 = PyTuple_GET_SIZE(__pyx_v_r); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(1, 600, __pyx_L1_error)
if (((__pyx_t_4 > 1) != 0)) {
if (unlikely(__pyx_v_r == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(1, 600, __pyx_L1_error)
}
if (!(likely(PyUnicode_CheckExact(PyTuple_GET_ITEM(__pyx_v_r, 1)))||((PyTuple_GET_ITEM(__pyx_v_r, 1)) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(PyTuple_GET_ITEM(__pyx_v_r, 1))->tp_name), 0))) __PYX_ERR(1, 600, __pyx_L1_error)
__pyx_t_1 = PyTuple_GET_ITEM(__pyx_v_r, 1);
__Pyx_INCREF(__pyx_t_1);
__pyx_t_2 = ((struct __pyx_vtabstruct_8discodop_10containers_Vocabulary *)__pyx_v_self->__pyx_vtab)->_getlabelid(__pyx_v_self, ((PyObject*)__pyx_t_1)); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(1, 600, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_3 = __pyx_t_2;
} else {
__pyx_t_3 = 0;
}
__pyx_v_rule.rhs1 = __pyx_t_3;
+601: rule.rhs2 = self._getlabelid(r[2]) if len(r) > 2 else 0
if (unlikely(__pyx_v_r == Py_None)) {
PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
__PYX_ERR(1, 601, __pyx_L1_error)
}
__pyx_t_4 = PyTuple_GET_SIZE(__pyx_v_r); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(1, 601, __pyx_L1_error)
if (((__pyx_t_4 > 2) != 0)) {
if (unlikely(__pyx_v_r == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(1, 601, __pyx_L1_error)
}
if (!(likely(PyUnicode_CheckExact(PyTuple_GET_ITEM(__pyx_v_r, 2)))||((PyTuple_GET_ITEM(__pyx_v_r, 2)) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(PyTuple_GET_ITEM(__pyx_v_r, 2))->tp_name), 0))) __PYX_ERR(1, 601, __pyx_L1_error)
__pyx_t_1 = PyTuple_GET_ITEM(__pyx_v_r, 2);
__Pyx_INCREF(__pyx_t_1);
__pyx_t_2 = ((struct __pyx_vtabstruct_8discodop_10containers_Vocabulary *)__pyx_v_self->__pyx_vtab)->_getlabelid(__pyx_v_self, ((PyObject*)__pyx_t_1)); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(1, 601, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_3 = __pyx_t_2;
} else {
__pyx_t_3 = 0;
}
__pyx_v_rule.rhs2 = __pyx_t_3;
+602: if rule.rhs1 == 0 and len(r) > 1:
__pyx_t_6 = ((__pyx_v_rule.rhs1 == 0) != 0);
if (__pyx_t_6) {
} else {
__pyx_t_5 = __pyx_t_6;
goto __pyx_L4_bool_binop_done;
}
if (unlikely(__pyx_v_r == Py_None)) {
PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
__PYX_ERR(1, 602, __pyx_L1_error)
}
__pyx_t_4 = PyTuple_GET_SIZE(__pyx_v_r); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(1, 602, __pyx_L1_error)
__pyx_t_6 = ((__pyx_t_4 > 1) != 0);
__pyx_t_5 = __pyx_t_6;
__pyx_L4_bool_binop_done:;
if (__pyx_t_5) {
/* … */
goto __pyx_L3;
}
+603: rule.args = self._getlabelid(yf[0])
if (unlikely(__pyx_v_yf == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(1, 603, __pyx_L1_error)
}
if (!(likely(PyUnicode_CheckExact(PyTuple_GET_ITEM(__pyx_v_yf, 0)))||((PyTuple_GET_ITEM(__pyx_v_yf, 0)) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(PyTuple_GET_ITEM(__pyx_v_yf, 0))->tp_name), 0))) __PYX_ERR(1, 603, __pyx_L1_error)
__pyx_t_1 = PyTuple_GET_ITEM(__pyx_v_yf, 0);
__Pyx_INCREF(__pyx_t_1);
__pyx_t_2 = ((struct __pyx_vtabstruct_8discodop_10containers_Vocabulary *)__pyx_v_self->__pyx_vtab)->_getlabelid(__pyx_v_self, ((PyObject*)__pyx_t_1)); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(1, 603, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_rule.args = __pyx_t_2;
+604: rule.lengths = 0
__pyx_v_rule.lengths = 0;
605: else:
+606: getyf(yf, &rule.args, &rule.lengths)
/*else*/ {
__pyx_t_1 = __pyx_f_8discodop_10containers_getyf(__pyx_v_yf, (&__pyx_v_rule.args), (&__pyx_v_rule.lengths)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 606, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__pyx_L3:;
+607: prod = <bytes>tmp[:sizeof(Rule)]
__pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_tmp + 0, (sizeof(Rule)) - 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 607, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_7 = __pyx_t_1; __Pyx_INCREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_prod = ((PyObject*)__pyx_t_7); __pyx_t_7 = 0;
+608: return self._getprodid(prod)
__pyx_t_2 = ((struct __pyx_vtabstruct_8discodop_10containers_Vocabulary *)__pyx_v_self->__pyx_vtab)->_getprodid(__pyx_v_self, __pyx_v_prod); if (unlikely(__pyx_t_2 == -2)) __PYX_ERR(1, 608, __pyx_L1_error) __pyx_r = __pyx_t_2; goto __pyx_L0;
609:
+610: cdef int _getprodid(self, bytes prod) except -2:
static int __pyx_f_8discodop_10containers_10Vocabulary__getprodid(struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_self, PyObject *__pyx_v_prod) {
uint32_t __pyx_v_n;
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("_getprodid", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_3);
__Pyx_AddTraceback("discodop.containers.Vocabulary._getprodid", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -2;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
611: cdef uint32_t n
+612: if prod not in self.prods:
if (unlikely(__pyx_v_self->prods == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
__PYX_ERR(1, 612, __pyx_L1_error)
}
__pyx_t_1 = (__Pyx_PyDict_ContainsTF(__pyx_v_prod, __pyx_v_self->prods, Py_NE)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 612, __pyx_L1_error)
__pyx_t_2 = (__pyx_t_1 != 0);
if (__pyx_t_2) {
/* … */
}
+613: n = len(self.prods)
__pyx_t_3 = __pyx_v_self->prods;
__Pyx_INCREF(__pyx_t_3);
if (unlikely(__pyx_t_3 == Py_None)) {
PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
__PYX_ERR(1, 613, __pyx_L1_error)
}
__pyx_t_4 = PyDict_Size(__pyx_t_3); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(1, 613, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_v_n = __pyx_t_4;
+614: self.prods[prod] = n
__pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_n); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 614, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
if (unlikely(__pyx_v_self->prods == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(1, 614, __pyx_L1_error)
}
if (unlikely(PyDict_SetItem(__pyx_v_self->prods, __pyx_v_prod, __pyx_t_3) < 0)) __PYX_ERR(1, 614, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+615: darray_extend(&self.prodbuf, prod)
__pyx_t_3 = __pyx_f_8discodop_10containers_darray_extend((&__pyx_v_self->prodbuf), __pyx_v_prod); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 615, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+616: return n
__pyx_r = __pyx_v_n;
goto __pyx_L0;
+617: return self.prods[prod]
if (unlikely(__pyx_v_self->prods == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(1, 617, __pyx_L1_error)
}
__pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_self->prods, __pyx_v_prod); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 617, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 617, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_r = __pyx_t_5;
goto __pyx_L0;
618:
+619: cdef int _getlabelid(self, str label) except -1:
static int __pyx_f_8discodop_10containers_10Vocabulary__getlabelid(struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_self, PyObject *__pyx_v_label) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("_getlabelid", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_AddTraceback("discodop.containers.Vocabulary._getlabelid", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -1;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+620: if label not in self.labels:
if (unlikely(__pyx_v_self->labels == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
__PYX_ERR(1, 620, __pyx_L1_error)
}
__pyx_t_1 = (__Pyx_PyDict_ContainsTF(__pyx_v_label, __pyx_v_self->labels, Py_NE)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 620, __pyx_L1_error)
__pyx_t_2 = (__pyx_t_1 != 0);
if (__pyx_t_2) {
/* … */
}
+621: self.labels[label] = len(self.labels)
__pyx_t_3 = __pyx_v_self->labels;
__Pyx_INCREF(__pyx_t_3);
if (unlikely(__pyx_t_3 == Py_None)) {
PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
__PYX_ERR(1, 621, __pyx_L1_error)
}
__pyx_t_4 = PyDict_Size(__pyx_t_3); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(1, 621, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 621, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
if (unlikely(__pyx_v_self->labels == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(1, 621, __pyx_L1_error)
}
if (unlikely(PyDict_SetItem(__pyx_v_self->labels, __pyx_v_label, __pyx_t_3) < 0)) __PYX_ERR(1, 621, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+622: darray_extend(&self.labelbuf, label.encode('utf8'))
if (unlikely(__pyx_v_label == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "encode");
__PYX_ERR(1, 622, __pyx_L1_error)
}
__pyx_t_3 = PyUnicode_AsUTF8String(__pyx_v_label); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 622, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
if (!(likely(PyBytes_CheckExact(__pyx_t_3))||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "bytes", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(1, 622, __pyx_L1_error)
__pyx_t_5 = __pyx_f_8discodop_10containers_darray_extend((&__pyx_v_self->labelbuf), ((PyObject*)__pyx_t_3)); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 622, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+623: darray_append_uint32(&self.labelidx, self.labelbuf.len)
__pyx_t_5 = __pyx_f_8discodop_10containers_darray_append_uint32((&__pyx_v_self->labelidx), __pyx_v_self->labelbuf.len); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 623, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+624: return self.labels[label]
if (unlikely(__pyx_v_self->labels == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(1, 624, __pyx_L1_error)
}
__pyx_t_5 = __Pyx_PyDict_GetItem(__pyx_v_self->labels, __pyx_v_label); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 624, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 624, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_r = __pyx_t_6;
goto __pyx_L0;
625:
+626: cdef str idtolabel(self, uint32_t i):
static PyObject *__pyx_f_8discodop_10containers_10Vocabulary_idtolabel(struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_self, uint32_t __pyx_v_i) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("idtolabel", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("discodop.containers.Vocabulary.idtolabel", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+627: return self.labelbuf.d.aschar[self.labelidx.d.asint[i]:
__Pyx_XDECREF(__pyx_r);
+628: self.labelidx.d.asint[i + 1]].decode('utf8')
__pyx_t_1 = __Pyx_decode_c_string(__pyx_v_self->labelbuf.d.aschar, (__pyx_v_self->labelidx.d.asint[__pyx_v_i]), (__pyx_v_self->labelidx.d.asint[(__pyx_v_i + 1)]), NULL, NULL, PyUnicode_DecodeUTF8); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 628, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(1, 628, __pyx_L1_error) __pyx_r = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0;
629:
+630: cdef str getlabel(self, int prodno):
static PyObject *__pyx_f_8discodop_10containers_10Vocabulary_getlabel(struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_self, int __pyx_v_prodno) {
Rule *__pyx_v_rule;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("getlabel", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_AddTraceback("discodop.containers.Vocabulary.getlabel", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
631: cdef Rule *rule
+632: if prodno < 0:
__pyx_t_1 = ((__pyx_v_prodno < 0) != 0);
if (__pyx_t_1) {
/* … */
}
+633: return '<UNKNOWN>'
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_kp_u_UNKNOWN); __pyx_r = __pyx_kp_u_UNKNOWN; goto __pyx_L0;
+634: rule = <Rule *>(&self.prodbuf.d.aschar[
__pyx_v_rule = ((Rule *)(&(__pyx_v_self->prodbuf.d.aschar[(__pyx_v_prodno * (sizeof(Rule)))])));
635: prodno * sizeof(Rule)])
+636: return self.labelbuf.d.aschar[self.labelidx.d.asint[rule.lhs]:
__Pyx_XDECREF(__pyx_r);
+637: self.labelidx.d.asint[rule.lhs + 1]].decode('utf8')
__pyx_t_2 = __Pyx_decode_c_string(__pyx_v_self->labelbuf.d.aschar, (__pyx_v_self->labelidx.d.asint[__pyx_v_rule->lhs]), (__pyx_v_self->labelidx.d.asint[(__pyx_v_rule->lhs + 1)]), NULL, NULL, PyUnicode_DecodeUTF8); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 637, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (!(likely(PyUnicode_CheckExact(__pyx_t_2))||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(1, 637, __pyx_L1_error) __pyx_r = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L0;
638:
+639: cdef str getword(self, int prodno):
static PyObject *__pyx_f_8discodop_10containers_10Vocabulary_getword(struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_self, int __pyx_v_prodno) {
Rule *__pyx_v_rule;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("getword", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_AddTraceback("discodop.containers.Vocabulary.getword", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
640: cdef Rule *rule
+641: if prodno < 0:
__pyx_t_1 = ((__pyx_v_prodno < 0) != 0);
if (__pyx_t_1) {
/* … */
}
+642: return '<UNKNOWN>'
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_kp_u_UNKNOWN); __pyx_r = __pyx_kp_u_UNKNOWN; goto __pyx_L0;
+643: rule = <Rule *>(&self.prodbuf.d.aschar[
__pyx_v_rule = ((Rule *)(&(__pyx_v_self->prodbuf.d.aschar[(__pyx_v_prodno * (sizeof(Rule)))])));
644: prodno * sizeof(Rule)])
+645: if rule.args == 0:
__pyx_t_1 = ((__pyx_v_rule->args == 0) != 0);
if (__pyx_t_1) {
/* … */
}
+646: return None
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(Py_None); __pyx_r = ((PyObject*)Py_None); goto __pyx_L0;
+647: return self.labelbuf.d.aschar[self.labelidx.d.asint[rule.args]:
__Pyx_XDECREF(__pyx_r);
+648: self.labelidx.d.asint[rule.args + 1]].decode('utf8')
__pyx_t_2 = __Pyx_decode_c_string(__pyx_v_self->labelbuf.d.aschar, (__pyx_v_self->labelidx.d.asint[__pyx_v_rule->args]), (__pyx_v_self->labelidx.d.asint[(__pyx_v_rule->args + 1)]), NULL, NULL, PyUnicode_DecodeUTF8); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 648, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (!(likely(PyUnicode_CheckExact(__pyx_t_2))||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(1, 648, __pyx_L1_error) __pyx_r = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L0;
649:
+650: cdef bint islexical(self, int prodno):
static int __pyx_f_8discodop_10containers_10Vocabulary_islexical(struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_self, int __pyx_v_prodno) {
Rule *__pyx_v_rule;
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("islexical", 0);
/* … */
/* function exit code */
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
651: cdef Rule *rule
+652: if prodno < 0:
__pyx_t_1 = ((__pyx_v_prodno < 0) != 0);
if (__pyx_t_1) {
/* … */
}
+653: return False
__pyx_r = 0;
goto __pyx_L0;
+654: rule = <Rule *>(&self.prodbuf.d.aschar[
__pyx_v_rule = ((Rule *)(&(__pyx_v_self->prodbuf.d.aschar[(__pyx_v_prodno * (sizeof(Rule)))])));
655: prodno * sizeof(Rule)])
+656: return rule.args != 0 and rule.lengths == 0
__pyx_t_2 = ((__pyx_v_rule->args != 0) != 0);
if (__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L4_bool_binop_done;
}
__pyx_t_2 = ((__pyx_v_rule->lengths == 0) != 0);
__pyx_t_1 = __pyx_t_2;
__pyx_L4_bool_binop_done:;
__pyx_r = __pyx_t_1;
goto __pyx_L0;
657:
+658: def prodrepr(self, int prodno):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_10Vocabulary_5prodrepr(PyObject *__pyx_v_self, PyObject *__pyx_arg_prodno); /*proto*/
static char __pyx_doc_8discodop_10containers_10Vocabulary_4prodrepr[] = "Vocabulary.prodrepr(self, int prodno)";
static PyObject *__pyx_pw_8discodop_10containers_10Vocabulary_5prodrepr(PyObject *__pyx_v_self, PyObject *__pyx_arg_prodno) {
int __pyx_v_prodno;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("prodrepr (wrapper)", 0);
assert(__pyx_arg_prodno); {
__pyx_v_prodno = __Pyx_PyInt_As_int(__pyx_arg_prodno); if (unlikely((__pyx_v_prodno == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 658, __pyx_L3_error)
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L3_error:;
__Pyx_AddTraceback("discodop.containers.Vocabulary.prodrepr", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_8discodop_10containers_10Vocabulary_4prodrepr(((struct __pyx_obj_8discodop_10containers_Vocabulary *)__pyx_v_self), ((int)__pyx_v_prodno));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_10Vocabulary_4prodrepr(struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_self, int __pyx_v_prodno) {
Rule *__pyx_v_rule;
int __pyx_v_fanout;
int __pyx_v_n;
int __pyx_v_m;
PyObject *__pyx_v_yf = 0;
PyObject *__pyx_v_rhs1 = NULL;
PyObject *__pyx_v_rhs2 = NULL;
PyObject *__pyx_v_word = NULL;
PyObject *__pyx_v_lhs = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("prodrepr", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_AddTraceback("discodop.containers.Vocabulary.prodrepr", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_yf);
__Pyx_XDECREF(__pyx_v_rhs1);
__Pyx_XDECREF(__pyx_v_rhs2);
__Pyx_XDECREF(__pyx_v_word);
__Pyx_XDECREF(__pyx_v_lhs);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
659: cdef Rule *rule
+660: cdef int fanout, n, m = 0
__pyx_v_m = 0;
+661: cdef str yf = ''
__Pyx_INCREF(__pyx_kp_u__11);
__pyx_v_yf = __pyx_kp_u__11;
+662: if prodno < 0:
__pyx_t_1 = ((__pyx_v_prodno < 0) != 0);
if (__pyx_t_1) {
/* … */
}
+663: return '<UNKNOWN>'
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_kp_u_UNKNOWN); __pyx_r = __pyx_kp_u_UNKNOWN; goto __pyx_L0;
+664: rule = <Rule *>(&self.prodbuf.d.aschar[
__pyx_v_rule = ((Rule *)(&(__pyx_v_self->prodbuf.d.aschar[(__pyx_v_prodno * (sizeof(Rule)))])));
665: prodno * sizeof(Rule)])
+666: fanout = bit_popcount(<uint64_t>rule.lengths)
__pyx_v_fanout = bit_popcount(((uint64_t)__pyx_v_rule->lengths));
+667: for n in range(8 * sizeof(rule.args)):
__pyx_t_2 = (8 * (sizeof(__pyx_v_rule->args)));
for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
__pyx_v_n = __pyx_t_3;
+668: yf += '1' if (rule.args >> n) & 1 else '0'
if ((((__pyx_v_rule->args >> __pyx_v_n) & 1) != 0)) {
__Pyx_INCREF(__pyx_kp_u_1);
__pyx_t_4 = __pyx_kp_u_1;
} else {
__Pyx_INCREF(__pyx_kp_u_0);
__pyx_t_4 = __pyx_kp_u_0;
}
__pyx_t_5 = __Pyx_PyUnicode_ConcatSafe(__pyx_v_yf, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 668, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF_SET(__pyx_v_yf, ((PyObject*)__pyx_t_5));
__pyx_t_5 = 0;
+669: if (rule.lengths >> n) & 1:
__pyx_t_1 = (((__pyx_v_rule->lengths >> __pyx_v_n) & 1) != 0);
if (__pyx_t_1) {
/* … */
}
}
__pyx_L5_break:;
+670: m += 1
__pyx_v_m = (__pyx_v_m + 1);
+671: if m == fanout:
__pyx_t_1 = ((__pyx_v_m == __pyx_v_fanout) != 0);
if (__pyx_t_1) {
/* … */
}
+672: break
goto __pyx_L5_break;
673: else:
+674: yf += ','
/*else*/ {
__pyx_t_5 = __Pyx_PyUnicode_Concat(__pyx_v_yf, __pyx_kp_u__23); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 674, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF_SET(__pyx_v_yf, ((PyObject*)__pyx_t_5));
__pyx_t_5 = 0;
}
+675: rhs1 = rhs2 = word = ''
__Pyx_INCREF(__pyx_kp_u__11); __pyx_v_rhs1 = __pyx_kp_u__11; __Pyx_INCREF(__pyx_kp_u__11); __pyx_v_rhs2 = __pyx_kp_u__11; __Pyx_INCREF(__pyx_kp_u__11); __pyx_v_word = __pyx_kp_u__11;
+676: lhs = self.idtolabel(rule.lhs)
__pyx_t_5 = ((struct __pyx_vtabstruct_8discodop_10containers_Vocabulary *)__pyx_v_self->__pyx_vtab)->idtolabel(__pyx_v_self, __pyx_v_rule->lhs); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 676, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_v_lhs = ((PyObject*)__pyx_t_5);
__pyx_t_5 = 0;
+677: if rule.rhs1 == 0:
__pyx_t_1 = ((__pyx_v_rule->rhs1 == 0) != 0);
if (__pyx_t_1) {
/* … */
goto __pyx_L8;
}
+678: word = repr(self.idtolabel(rule.args) if rule.args else None)
if ((__pyx_v_rule->args != 0)) {
__pyx_t_4 = ((struct __pyx_vtabstruct_8discodop_10containers_Vocabulary *)__pyx_v_self->__pyx_vtab)->idtolabel(__pyx_v_self, __pyx_v_rule->args); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 678, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = __pyx_t_4;
__pyx_t_4 = 0;
} else {
__Pyx_INCREF(Py_None);
__pyx_t_5 = Py_None;
}
__pyx_t_4 = PyObject_Repr(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 678, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_DECREF_SET(__pyx_v_word, __pyx_t_4);
__pyx_t_4 = 0;
679: else:
+680: rhs1 = self.idtolabel(rule.rhs1)
/*else*/ {
__pyx_t_4 = ((struct __pyx_vtabstruct_8discodop_10containers_Vocabulary *)__pyx_v_self->__pyx_vtab)->idtolabel(__pyx_v_self, __pyx_v_rule->rhs1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 680, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF_SET(__pyx_v_rhs1, ((PyObject*)__pyx_t_4));
__pyx_t_4 = 0;
}
__pyx_L8:;
+681: if rule.rhs2 != 0:
__pyx_t_1 = ((__pyx_v_rule->rhs2 != 0) != 0);
if (__pyx_t_1) {
/* … */
}
+682: rhs2 = self.idtolabel(rule.rhs2)
__pyx_t_4 = ((struct __pyx_vtabstruct_8discodop_10containers_Vocabulary *)__pyx_v_self->__pyx_vtab)->idtolabel(__pyx_v_self, __pyx_v_rule->rhs2); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 682, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF_SET(__pyx_v_rhs2, ((PyObject*)__pyx_t_4));
__pyx_t_4 = 0;
+683: return '%s %s %s %s' % (yf if rhs1 else '',
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = (__pyx_v_rhs1 != Py_None) && (__Pyx_PyUnicode_IS_TRUE(__pyx_v_rhs1) != 0); if (__pyx_t_1) { __Pyx_INCREF(__pyx_v_yf); __pyx_t_4 = __pyx_v_yf; } else { __Pyx_INCREF(__pyx_kp_u__11); __pyx_t_4 = __pyx_kp_u__11; } /* … */ __pyx_t_6 = PyTuple_New(4); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 683, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4); __Pyx_INCREF(__pyx_v_lhs); __Pyx_GIVEREF(__pyx_v_lhs); PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_lhs); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_t_5); __Pyx_INCREF(__pyx_v_rhs2); __Pyx_GIVEREF(__pyx_v_rhs2); PyTuple_SET_ITEM(__pyx_t_6, 3, __pyx_v_rhs2); __pyx_t_4 = 0; __pyx_t_5 = 0; __pyx_t_5 = PyUnicode_Format(__pyx_kp_u_s_s_s_s, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 683, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
+684: lhs, rhs1 or word, rhs2)
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_rhs1); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 684, __pyx_L1_error) if (!__pyx_t_1) { } else { __Pyx_INCREF(__pyx_v_rhs1); __pyx_t_5 = __pyx_v_rhs1; goto __pyx_L10_bool_binop_done; } __Pyx_INCREF(__pyx_v_word); __pyx_t_5 = __pyx_v_word; __pyx_L10_bool_binop_done:;
685:
+686: def __repr__(self):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_10Vocabulary_7__repr__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_pw_8discodop_10containers_10Vocabulary_7__repr__(PyObject *__pyx_v_self) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__repr__ (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_10Vocabulary_6__repr__(((struct __pyx_obj_8discodop_10containers_Vocabulary *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_10Vocabulary_6__repr__(struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__repr__", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_AddTraceback("discodop.containers.Vocabulary.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+687: if self.prods is None:
__pyx_t_1 = (__pyx_v_self->prods == ((PyObject*)Py_None));
__pyx_t_2 = (__pyx_t_1 != 0);
if (__pyx_t_2) {
/* … */
}
+688: return '<Vocabulary object>'
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_kp_u_Vocabulary_object); __pyx_r = __pyx_kp_u_Vocabulary_object; goto __pyx_L0;
+689: return 'labels: %d, prods: %d' % (len(set(self.labels)), len(self.prods))
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = PySet_New(__pyx_v_self->labels); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 689, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PySet_GET_SIZE(__pyx_t_3); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(1, 689, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 689, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = __pyx_v_self->prods; __Pyx_INCREF(__pyx_t_5); if (unlikely(__pyx_t_5 == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); __PYX_ERR(1, 689, __pyx_L1_error) } __pyx_t_4 = PyDict_Size(__pyx_t_5); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(1, 689, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 689, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 689, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); __pyx_t_3 = 0; __pyx_t_5 = 0; __pyx_t_5 = PyUnicode_Format(__pyx_kp_u_labels_d_prods_d, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 689, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
690:
+691: def tofile(self, str filename):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_10Vocabulary_9tofile(PyObject *__pyx_v_self, PyObject *__pyx_v_filename); /*proto*/
static char __pyx_doc_8discodop_10containers_10Vocabulary_8tofile[] = "Vocabulary.tofile(self, unicode filename)\nHelper function for pickling.";
static PyObject *__pyx_pw_8discodop_10containers_10Vocabulary_9tofile(PyObject *__pyx_v_self, PyObject *__pyx_v_filename) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("tofile (wrapper)", 0);
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_filename), (&PyUnicode_Type), 1, "filename", 1))) __PYX_ERR(1, 691, __pyx_L1_error)
__pyx_r = __pyx_pf_8discodop_10containers_10Vocabulary_8tofile(((struct __pyx_obj_8discodop_10containers_Vocabulary *)__pyx_v_self), ((PyObject*)__pyx_v_filename));
/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_10Vocabulary_8tofile(struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_self, PyObject *__pyx_v_filename) {
FILE *__pyx_v_out;
size_t __pyx_v_written;
uint32_t __pyx_v_header[3];
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("tofile", 0);
/* … */
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("discodop.containers.Vocabulary.tofile", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
692: """Helper function for pickling."""
+693: cdef FILE *out = fopen(filename.encode('utf8'), b'wb')
if (unlikely(__pyx_v_filename == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "encode");
__PYX_ERR(1, 693, __pyx_L1_error)
}
__pyx_t_1 = PyUnicode_AsUTF8String(__pyx_v_filename); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 693, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = __Pyx_PyObject_AsString(__pyx_t_1); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(1, 693, __pyx_L1_error)
__pyx_v_out = fopen(__pyx_t_2, ((char const *)"wb"));
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+694: cdef size_t written = 0
__pyx_v_written = 0;
695: cdef uint32_t header[3]
+696: header[:] = [len(self.prods), len(self.labels) + 1, self.labelbuf.len]
__pyx_t_1 = __pyx_v_self->prods; __Pyx_INCREF(__pyx_t_1); if (unlikely(__pyx_t_1 == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); __PYX_ERR(1, 696, __pyx_L1_error) } __pyx_t_3 = PyDict_Size(__pyx_t_1); if (unlikely(__pyx_t_3 == -1)) __PYX_ERR(1, 696, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __pyx_v_self->labels; __Pyx_INCREF(__pyx_t_1); if (unlikely(__pyx_t_1 == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); __PYX_ERR(1, 696, __pyx_L1_error) } __pyx_t_4 = PyDict_Size(__pyx_t_1); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(1, 696, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_5[0] = __pyx_t_3; __pyx_t_5[1] = (__pyx_t_4 + 1); __pyx_t_5[2] = __pyx_v_self->labelbuf.len; memcpy(&(__pyx_v_header[0]), __pyx_t_5, sizeof(__pyx_v_header[0]) * (3));
+697: if out is NULL:
__pyx_t_6 = ((__pyx_v_out == NULL) != 0);
if (__pyx_t_6) {
/* … */
}
+698: raise ValueError('could not open file.')
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__39, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 698, __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(1, 698, __pyx_L1_error) /* … */ __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_u_could_not_open_file); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(1, 698, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__39); __Pyx_GIVEREF(__pyx_tuple__39);
+699: try:
/*try:*/ {
+700: written += fwrite(<void *>header, 1, sizeof(header), out)
__pyx_v_written = (__pyx_v_written + fwrite(((void *)__pyx_v_header), 1, (sizeof(__pyx_v_header)), __pyx_v_out));
+701: written += fwrite(self.prodbuf.d.ptr, 1, self.prodbuf.len, out)
__pyx_v_written = (__pyx_v_written + fwrite(__pyx_v_self->prodbuf.d.ptr, 1, __pyx_v_self->prodbuf.len, __pyx_v_out));
+702: written += fwrite(self.labelidx.d.ptr, 1,
__pyx_v_written = (__pyx_v_written + fwrite(__pyx_v_self->labelidx.d.ptr, 1, (__pyx_v_self->labelidx.len * (sizeof(uint32_t))), __pyx_v_out));
703: self.labelidx.len * sizeof(uint32_t), out)
+704: written += fwrite(self.labelbuf.d.ptr, 1, self.labelbuf.len, out)
__pyx_v_written = (__pyx_v_written + fwrite(__pyx_v_self->labelbuf.d.ptr, 1, __pyx_v_self->labelbuf.len, __pyx_v_out));
+705: if (written != sizeof(header) + self.prodbuf.len
__pyx_t_6 = ((__pyx_v_written != ((((sizeof(__pyx_v_header)) + __pyx_v_self->prodbuf.len) + (__pyx_v_self->labelidx.len * (sizeof(uint32_t)))) + __pyx_v_self->labelbuf.len)) != 0);
if (__pyx_t_6) {
/* … */
}
}
706: + self.labelidx.len * sizeof(uint32_t) + self.labelbuf.len):
+707: raise ValueError('error writing to file.')
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 707, __pyx_L5_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(1, 707, __pyx_L5_error) /* … */ __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_u_error_writing_to_file); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(1, 707, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__40); __Pyx_GIVEREF(__pyx_tuple__40);
708: finally:
+709: fclose(out)
/*finally:*/ {
/*normal exit:*/{
fclose(__pyx_v_out);
goto __pyx_L6;
}
/*exception exit:*/{
__Pyx_PyThreadState_declare
__pyx_L5_error:;
__pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0;
__Pyx_PyThreadState_assign
__Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12) < 0)) __Pyx_ErrFetch(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
__Pyx_XGOTREF(__pyx_t_10);
__Pyx_XGOTREF(__pyx_t_11);
__Pyx_XGOTREF(__pyx_t_12);
__Pyx_XGOTREF(__pyx_t_13);
__Pyx_XGOTREF(__pyx_t_14);
__Pyx_XGOTREF(__pyx_t_15);
__pyx_t_7 = __pyx_lineno; __pyx_t_8 = __pyx_clineno; __pyx_t_9 = __pyx_filename;
{
fclose(__pyx_v_out);
}
__Pyx_PyThreadState_assign
if (PY_MAJOR_VERSION >= 3) {
__Pyx_XGIVEREF(__pyx_t_13);
__Pyx_XGIVEREF(__pyx_t_14);
__Pyx_XGIVEREF(__pyx_t_15);
__Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15);
}
__Pyx_XGIVEREF(__pyx_t_10);
__Pyx_XGIVEREF(__pyx_t_11);
__Pyx_XGIVEREF(__pyx_t_12);
__Pyx_ErrRestore(__pyx_t_10, __pyx_t_11, __pyx_t_12);
__pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_12 = 0; __pyx_t_13 = 0; __pyx_t_14 = 0; __pyx_t_15 = 0;
__pyx_lineno = __pyx_t_7; __pyx_clineno = __pyx_t_8; __pyx_filename = __pyx_t_9;
goto __pyx_L1_error;
}
__pyx_L6:;
}
710:
711:
712: @cython.final
+713: cdef class FixedVocabulary(Vocabulary):
struct __pyx_vtabstruct_8discodop_10containers_FixedVocabulary {
struct __pyx_vtabstruct_8discodop_10containers_Vocabulary __pyx_base;
};
static struct __pyx_vtabstruct_8discodop_10containers_FixedVocabulary *__pyx_vtabptr_8discodop_10containers_FixedVocabulary;
+714: @classmethod
__pyx_t_1 = __Pyx_Method_ClassMethod(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 714, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (PyDict_SetItem((PyObject *)__pyx_ptype_8discodop_10containers_FixedVocabulary->tp_dict, __pyx_n_s_fromfile, __pyx_t_1) < 0) __PYX_ERR(1, 715, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; PyType_Modified(__pyx_ptype_8discodop_10containers_FixedVocabulary);
+715: def fromfile(cls, filename):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_15FixedVocabulary_1fromfile(PyObject *__pyx_v_cls, PyObject *__pyx_v_filename); /*proto*/
static char __pyx_doc_8discodop_10containers_15FixedVocabulary_fromfile[] = "FixedVocabulary.fromfile(type cls, filename)";
static PyObject *__pyx_pw_8discodop_10containers_15FixedVocabulary_1fromfile(PyObject *__pyx_v_cls, PyObject *__pyx_v_filename) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("fromfile (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_15FixedVocabulary_fromfile(((PyTypeObject*)__pyx_v_cls), ((PyObject *)__pyx_v_filename));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_15FixedVocabulary_fromfile(CYTHON_UNUSED PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_filename) {
struct __pyx_obj_8discodop_10containers_FixedVocabulary *__pyx_v_ob = 0;
size_t __pyx_v_offset;
Py_buffer __pyx_v_buffer;
Py_ssize_t __pyx_v_size;
char *__pyx_v_ptr;
uint32_t *__pyx_v_header;
int __pyx_v_result;
PyObject *__pyx_v_fileno = NULL;
PyObject *__pyx_v_buf = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("fromfile", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_AddTraceback("discodop.containers.FixedVocabulary.fromfile", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_ob);
__Pyx_XDECREF(__pyx_v_fileno);
__Pyx_XDECREF(__pyx_v_buf);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
/* … */
__pyx_t_2 = __Pyx_GetNameInClass((PyObject *)__pyx_ptype_8discodop_10containers_FixedVocabulary, __pyx_n_s_fromfile); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 715, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
+716: cdef FixedVocabulary ob = FixedVocabulary.__new__(FixedVocabulary)
__pyx_t_1 = __pyx_tp_new_8discodop_10containers_FixedVocabulary(((PyTypeObject *)__pyx_ptype_8discodop_10containers_FixedVocabulary), __pyx_empty_tuple, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 716, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8discodop_10containers_FixedVocabulary)))) __PYX_ERR(1, 716, __pyx_L1_error) __pyx_v_ob = ((struct __pyx_obj_8discodop_10containers_FixedVocabulary *)__pyx_t_1); __pyx_t_1 = 0;
+717: cdef size_t offset = 3 * sizeof(uint32_t)
__pyx_v_offset = (3 * (sizeof(uint32_t)));
718: cdef Py_buffer buffer
+719: cdef Py_ssize_t size = 0
__pyx_v_size = 0;
+720: cdef char *ptr = NULL
__pyx_v_ptr = NULL;
721: cdef uint32_t *header
722: cdef int result
+723: fileno = os.open(filename, os.O_RDONLY)
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 723, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_open); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 723, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 723, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_O_RDONLY); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 723, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = NULL; __pyx_t_5 = 0; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_2)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); __pyx_t_5 = 1; } } #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_filename, __pyx_t_4}; __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 723, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_filename, __pyx_t_4}; __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 723, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { __pyx_t_6 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 723, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); if (__pyx_t_2) { __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2); __pyx_t_2 = NULL; } __Pyx_INCREF(__pyx_v_filename); __Pyx_GIVEREF(__pyx_v_filename); PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_5, __pyx_v_filename); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_5, __pyx_t_4); __pyx_t_4 = 0; __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 723, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_fileno = __pyx_t_1; __pyx_t_1 = 0;
+724: buf = mmap.mmap(fileno, 0, access=mmap.ACCESS_READ)
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_mmap); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 724, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_mmap); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 724, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 724, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_fileno); __Pyx_GIVEREF(__pyx_v_fileno); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_fileno); __Pyx_INCREF(__pyx_int_0); __Pyx_GIVEREF(__pyx_int_0); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_0); __pyx_t_6 = PyDict_New(); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 724, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_mmap); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 724, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_ACCESS_READ); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 724, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_access, __pyx_t_2) < 0) __PYX_ERR(1, 724, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 724, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_v_buf = __pyx_t_2; __pyx_t_2 = 0;
+725: ob.state = (fileno, buf)
__pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 725, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v_fileno); __Pyx_GIVEREF(__pyx_v_fileno); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_fileno); __Pyx_INCREF(__pyx_v_buf); __Pyx_GIVEREF(__pyx_v_buf); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_buf); __Pyx_GIVEREF(__pyx_t_2); __Pyx_GOTREF(__pyx_v_ob->state); __Pyx_DECREF(__pyx_v_ob->state); __pyx_v_ob->state = __pyx_t_2; __pyx_t_2 = 0;
+726: result = getbufptr(buf, &ptr, &size, &buffer)
__pyx_v_result = __pyx_f_8discodop_10containers_getbufptr(__pyx_v_buf, (&__pyx_v_ptr), (&__pyx_v_size), (&__pyx_v_buffer));
+727: if result != 0:
__pyx_t_7 = ((__pyx_v_result != 0) != 0);
if (__pyx_t_7) {
/* … */
}
+728: raise ValueError('could not get buffer from mmap.')
__pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__41, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 728, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __PYX_ERR(1, 728, __pyx_L1_error) /* … */ __pyx_tuple__41 = PyTuple_Pack(1, __pyx_kp_u_could_not_get_buffer_from_mmap); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(1, 728, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__41); __Pyx_GIVEREF(__pyx_tuple__41);
+729: header = <uint32_t *>ptr
__pyx_v_header = ((uint32_t *)__pyx_v_ptr);
+730: ob.prodbuf.d.aschar = &(ptr[offset])
__pyx_v_ob->__pyx_base.prodbuf.d.aschar = (&(__pyx_v_ptr[__pyx_v_offset]));
+731: ob.prodbuf.len = header[0] * sizeof(Rule)
__pyx_v_ob->__pyx_base.prodbuf.len = ((__pyx_v_header[0]) * (sizeof(Rule)));
+732: ob.prodbuf.capacity = 0
__pyx_v_ob->__pyx_base.prodbuf.capacity = 0;
+733: offset += header[0] * sizeof(Rule)
__pyx_v_offset = (__pyx_v_offset + ((__pyx_v_header[0]) * (sizeof(Rule))));
+734: ob.labelidx.d.aschar = &(ptr[offset])
__pyx_v_ob->__pyx_base.labelidx.d.aschar = (&(__pyx_v_ptr[__pyx_v_offset]));
+735: ob.labelidx.len = header[1]
__pyx_v_ob->__pyx_base.labelidx.len = (__pyx_v_header[1]);
+736: ob.labelidx.capacity = 0
__pyx_v_ob->__pyx_base.labelidx.capacity = 0;
+737: offset += header[1] * sizeof(uint32_t)
__pyx_v_offset = (__pyx_v_offset + ((__pyx_v_header[1]) * (sizeof(uint32_t))));
+738: ob.labelbuf.d.aschar = &(ptr[offset])
__pyx_v_ob->__pyx_base.labelbuf.d.aschar = (&(__pyx_v_ptr[__pyx_v_offset]));
+739: ob.labelbuf.len = header[2]
__pyx_v_ob->__pyx_base.labelbuf.len = (__pyx_v_header[2]);
+740: ob.labelbuf.capacity = 0
__pyx_v_ob->__pyx_base.labelbuf.capacity = 0;
+741: PyBuffer_Release(&buffer)
PyBuffer_Release((&__pyx_v_buffer));
+742: return ob
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_ob)); __pyx_r = ((PyObject *)__pyx_v_ob); goto __pyx_L0;
743:
+744: def __dealloc__(self):
/* Python wrapper */
static void __pyx_pw_8discodop_10containers_15FixedVocabulary_3__dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_pw_8discodop_10containers_15FixedVocabulary_3__dealloc__(PyObject *__pyx_v_self) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0);
__pyx_pf_8discodop_10containers_15FixedVocabulary_2__dealloc__(((struct __pyx_obj_8discodop_10containers_FixedVocabulary *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
}
static void __pyx_pf_8discodop_10containers_15FixedVocabulary_2__dealloc__(struct __pyx_obj_8discodop_10containers_FixedVocabulary *__pyx_v_self) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__dealloc__", 0);
/* … */
/* function exit code */
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);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_WriteUnraisable("discodop.containers.FixedVocabulary.__dealloc__", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
__pyx_L0:;
__Pyx_RefNannyFinishContext();
}
+745: if self.state:
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->state); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(1, 745, __pyx_L1_error)
if (__pyx_t_1) {
/* … */
}
+746: self.state[1].close()
__pyx_t_3 = __Pyx_GetItemInt(__pyx_v_self->state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 746, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_close); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 746, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); } } if (__pyx_t_3) { __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 746, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 746, __pyx_L1_error) } __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+747: os.close(self.state[0])
__pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_os); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 747, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_close); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 747, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_self->state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 747, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); } } if (!__pyx_t_5) { __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 747, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_2); } else { #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 747, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4}; __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 747, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else #endif { __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 747, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4); __pyx_t_4 = 0; __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 747, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+748: self.state = None
__Pyx_INCREF(Py_None); __Pyx_GIVEREF(Py_None); __Pyx_GOTREF(__pyx_v_self->state); __Pyx_DECREF(__pyx_v_self->state); __pyx_v_self->state = Py_None;
749:
+750: def makeindex(self):
/* Python wrapper */
static PyObject *__pyx_pw_8discodop_10containers_15FixedVocabulary_5makeindex(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_8discodop_10containers_15FixedVocabulary_4makeindex[] = "FixedVocabulary.makeindex(self)\nBuild dictionaries; necessary for getprod().";
static PyObject *__pyx_pw_8discodop_10containers_15FixedVocabulary_5makeindex(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("makeindex (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_10containers_15FixedVocabulary_4makeindex(((struct __pyx_obj_8discodop_10containers_FixedVocabulary *)__pyx_v_self));
/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_pf_8discodop_10containers_15FixedVocabulary_4makeindex(struct __pyx_obj_8discodop_10containers_FixedVocabulary *__pyx_v_self) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("makeindex", 0);
/* … */
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_AddTraceback("discodop.containers.FixedVocabulary.makeindex", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
751: """Build dictionaries; necessary for getprod()."""
+752: self.prods = {<bytes>self.prodbuf.d.aschar[n * sizeof(Rule):
{ /* enter inner scope */
size_t __pyx_9genexpr17__pyx_v_n;
__pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 752, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
/* … */
__pyx_t_4 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_self->__pyx_base.prodbuf.d.aschar + (__pyx_9genexpr17__pyx_v_n * (sizeof(Rule))), ((__pyx_9genexpr17__pyx_v_n + 1) * (sizeof(Rule))) - (__pyx_9genexpr17__pyx_v_n * (sizeof(Rule)))); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 752, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
/* … */
__Pyx_GIVEREF(__pyx_t_1);
__Pyx_GOTREF(__pyx_v_self->__pyx_base.prods);
__Pyx_DECREF(__pyx_v_self->__pyx_base.prods);
__pyx_v_self->__pyx_base.prods = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;
753: (n + 1) * sizeof(Rule)]: n
+754: for n in range(self.prodbuf.len // sizeof(Rule))}
__pyx_t_2 = (__pyx_v_self->__pyx_base.prodbuf.len / (sizeof(Rule)));
for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
__pyx_9genexpr17__pyx_v_n = __pyx_t_3;
/* … */
__pyx_t_5 = __Pyx_PyInt_FromSize_t(__pyx_9genexpr17__pyx_v_n); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 754, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
if (unlikely(PyDict_SetItem(__pyx_t_1, (PyObject*)((PyObject*)__pyx_t_4), (PyObject*)__pyx_t_5))) __PYX_ERR(1, 752, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
}
} /* exit inner scope */
+755: self.labels = {self.labelbuf.d.aschar[self.labelidx.d.asint[n]:
{ /* enter inner scope */
long __pyx_9genexpr18__pyx_v_n;
__pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 755, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
/* … */
__Pyx_GIVEREF(__pyx_t_1);
__Pyx_GOTREF(__pyx_v_self->__pyx_base.labels);
__Pyx_DECREF(__pyx_v_self->__pyx_base.labels);
__pyx_v_self->__pyx_base.labels = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;
+756: self.labelidx.d.asint[n + 1]].decode('utf8'): n
__pyx_t_5 = __Pyx_decode_c_string(__pyx_v_self->__pyx_base.labelbuf.d.aschar, (__pyx_v_self->__pyx_base.labelidx.d.asint[__pyx_9genexpr18__pyx_v_n]), (__pyx_v_self->__pyx_base.labelidx.d.asint[(__pyx_9genexpr18__pyx_v_n + 1)]), NULL, NULL, PyUnicode_DecodeUTF8); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 756, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
+757: for n in range(self.labelidx.len - 1)}
__pyx_t_6 = (__pyx_v_self->__pyx_base.labelidx.len - 1);
for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) {
__pyx_9genexpr18__pyx_v_n = __pyx_t_7;
/* … */
__pyx_t_4 = __Pyx_PyInt_From_long(__pyx_9genexpr18__pyx_v_n); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 757, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (unlikely(PyDict_SetItem(__pyx_t_1, (PyObject*)__pyx_t_5, (PyObject*)__pyx_t_4))) __PYX_ERR(1, 756, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
}
} /* exit inner scope */
758:
+759: cdef int getprod(self, tuple r, tuple yf) except -2:
static int __pyx_f_8discodop_10containers_15FixedVocabulary_getprod(struct __pyx_obj_8discodop_10containers_FixedVocabulary *__pyx_v_self, PyObject *__pyx_v_r, PyObject *__pyx_v_yf) {
Rule __pyx_v_rule;
char *__pyx_v_tmp;
PyObject *__pyx_v_res = NULL;
PyObject *__pyx_v_prod = NULL;
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("getprod", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_AddTraceback("discodop.containers.FixedVocabulary.getprod", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -2;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_res);
__Pyx_XDECREF(__pyx_v_prod);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
760: """Lookup production ID. Return -1 when not seen before."""
761: cdef Rule rule
+762: cdef char *tmp = <char *>&rule
__pyx_v_tmp = ((char *)(&__pyx_v_rule));
+763: res = self.labels.get(r[0], None)
if (unlikely(__pyx_v_self->__pyx_base.labels == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "get");
__PYX_ERR(1, 763, __pyx_L1_error)
}
if (unlikely(__pyx_v_r == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(1, 763, __pyx_L1_error)
}
__pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->__pyx_base.labels, PyTuple_GET_ITEM(__pyx_v_r, 0), Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 763, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_res = __pyx_t_1;
__pyx_t_1 = 0;
+764: if res is None:
__pyx_t_2 = (__pyx_v_res == Py_None);
__pyx_t_3 = (__pyx_t_2 != 0);
if (__pyx_t_3) {
/* … */
}
+765: return None
__pyx_t_4 = __Pyx_PyInt_As_int(Py_None); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 765, __pyx_L1_error) __pyx_r = __pyx_t_4; goto __pyx_L0;
+766: rule.lhs = res
__pyx_t_5 = __Pyx_PyInt_As_uint32_t(__pyx_v_res); if (unlikely((__pyx_t_5 == ((Label)-1)) && PyErr_Occurred())) __PYX_ERR(1, 766, __pyx_L1_error)
__pyx_v_rule.lhs = __pyx_t_5;
+767: res = self.labels.get(r[1], None) if len(r) > 1 else 0
if (unlikely(__pyx_v_r == Py_None)) {
PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
__PYX_ERR(1, 767, __pyx_L1_error)
}
__pyx_t_6 = PyTuple_GET_SIZE(__pyx_v_r); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(1, 767, __pyx_L1_error)
if (((__pyx_t_6 > 1) != 0)) {
if (unlikely(__pyx_v_self->__pyx_base.labels == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "get");
__PYX_ERR(1, 767, __pyx_L1_error)
}
if (unlikely(__pyx_v_r == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(1, 767, __pyx_L1_error)
}
__pyx_t_7 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->__pyx_base.labels, PyTuple_GET_ITEM(__pyx_v_r, 1), Py_None); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 767, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_1 = __pyx_t_7;
__pyx_t_7 = 0;
} else {
__Pyx_INCREF(__pyx_int_0);
__pyx_t_1 = __pyx_int_0;
}
__Pyx_DECREF_SET(__pyx_v_res, __pyx_t_1);
__pyx_t_1 = 0;
+768: if res is None:
__pyx_t_3 = (__pyx_v_res == Py_None);
__pyx_t_2 = (__pyx_t_3 != 0);
if (__pyx_t_2) {
/* … */
}
+769: return None
__pyx_t_4 = __Pyx_PyInt_As_int(Py_None); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 769, __pyx_L1_error) __pyx_r = __pyx_t_4; goto __pyx_L0;
+770: rule.rhs1 = res
__pyx_t_5 = __Pyx_PyInt_As_uint32_t(__pyx_v_res); if (unlikely((__pyx_t_5 == ((Label)-1)) && PyErr_Occurred())) __PYX_ERR(1, 770, __pyx_L1_error)
__pyx_v_rule.rhs1 = __pyx_t_5;
+771: if len(r) > 2:
if (unlikely(__pyx_v_r == Py_None)) {
PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
__PYX_ERR(1, 771, __pyx_L1_error)
}
__pyx_t_6 = PyTuple_GET_SIZE(__pyx_v_r); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(1, 771, __pyx_L1_error)
__pyx_t_2 = ((__pyx_t_6 > 2) != 0);
if (__pyx_t_2) {
/* … */
goto __pyx_L5;
}
+772: res = self.labels.get(r[2], None)
if (unlikely(__pyx_v_self->__pyx_base.labels == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "get");
__PYX_ERR(1, 772, __pyx_L1_error)
}
if (unlikely(__pyx_v_r == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(1, 772, __pyx_L1_error)
}
__pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->__pyx_base.labels, PyTuple_GET_ITEM(__pyx_v_r, 2), Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 772, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF_SET(__pyx_v_res, __pyx_t_1);
__pyx_t_1 = 0;
+773: if res is None:
__pyx_t_2 = (__pyx_v_res == Py_None);
__pyx_t_3 = (__pyx_t_2 != 0);
if (__pyx_t_3) {
/* … */
}
+774: return None
__pyx_t_4 = __Pyx_PyInt_As_int(Py_None); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 774, __pyx_L1_error) __pyx_r = __pyx_t_4; goto __pyx_L0;
+775: rule.rhs2 = res
__pyx_t_5 = __Pyx_PyInt_As_uint32_t(__pyx_v_res); if (unlikely((__pyx_t_5 == ((Label)-1)) && PyErr_Occurred())) __PYX_ERR(1, 775, __pyx_L1_error)
__pyx_v_rule.rhs2 = __pyx_t_5;
776: else:
+777: rule.rhs2 = 0
/*else*/ {
__pyx_v_rule.rhs2 = 0;
}
__pyx_L5:;
+778: if rule.rhs1 == 0 and len(r) > 1:
__pyx_t_2 = ((__pyx_v_rule.rhs1 == 0) != 0);
if (__pyx_t_2) {
} else {
__pyx_t_3 = __pyx_t_2;
goto __pyx_L8_bool_binop_done;
}
if (unlikely(__pyx_v_r == Py_None)) {
PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
__PYX_ERR(1, 778, __pyx_L1_error)
}
__pyx_t_6 = PyTuple_GET_SIZE(__pyx_v_r); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(1, 778, __pyx_L1_error)
__pyx_t_2 = ((__pyx_t_6 > 1) != 0);
__pyx_t_3 = __pyx_t_2;
__pyx_L8_bool_binop_done:;
if (__pyx_t_3) {
/* … */
goto __pyx_L7;
}
+779: res = self.labels.get(yf[0], None)
if (unlikely(__pyx_v_self->__pyx_base.labels == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "get");
__PYX_ERR(1, 779, __pyx_L1_error)
}
if (unlikely(__pyx_v_yf == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(1, 779, __pyx_L1_error)
}
__pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->__pyx_base.labels, PyTuple_GET_ITEM(__pyx_v_yf, 0), Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 779, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF_SET(__pyx_v_res, __pyx_t_1);
__pyx_t_1 = 0;
+780: if res is None:
__pyx_t_3 = (__pyx_v_res == Py_None);
__pyx_t_2 = (__pyx_t_3 != 0);
if (__pyx_t_2) {
/* … */
}
+781: return None
__pyx_t_4 = __Pyx_PyInt_As_int(Py_None); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 781, __pyx_L1_error) __pyx_r = __pyx_t_4; goto __pyx_L0;
+782: rule.args = res
__pyx_t_8 = __Pyx_PyInt_As_uint32_t(__pyx_v_res); if (unlikely((__pyx_t_8 == ((uint32_t)-1)) && PyErr_Occurred())) __PYX_ERR(1, 782, __pyx_L1_error)
__pyx_v_rule.args = __pyx_t_8;
+783: rule.lengths = 0
__pyx_v_rule.lengths = 0;
784: else:
+785: getyf(yf, &rule.args, &rule.lengths)
/*else*/ {
__pyx_t_1 = __pyx_f_8discodop_10containers_getyf(__pyx_v_yf, (&__pyx_v_rule.args), (&__pyx_v_rule.lengths)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 785, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__pyx_L7:;
+786: prod = <bytes>tmp[:sizeof(Rule)]
__pyx_t_1 = __Pyx_PyBytes_FromStringAndSize(__pyx_v_tmp + 0, (sizeof(Rule)) - 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 786, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_7 = __pyx_t_1; __Pyx_INCREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_prod = ((PyObject*)__pyx_t_7); __pyx_t_7 = 0;
+787: return self.prods.get(prod, -1)
if (unlikely(__pyx_v_self->__pyx_base.prods == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "get");
__PYX_ERR(1, 787, __pyx_L1_error)
}
__pyx_t_7 = __Pyx_PyDict_GetItemDefault(__pyx_v_self->__pyx_base.prods, __pyx_v_prod, __pyx_int_neg_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 787, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 787, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_r = __pyx_t_4;
goto __pyx_L0;
788:
789:
+790: cdef inline gettree(list result, Node *tree, Vocabulary vocab, int i,
static CYTHON_INLINE PyObject *__pyx_f_8discodop_10containers_gettree(PyObject *__pyx_v_result, struct __pyx_t_8discodop_10containers_Node *__pyx_v_tree, struct __pyx_obj_8discodop_10containers_Vocabulary *__pyx_v_vocab, int __pyx_v_i, int __pyx_v_disc) {
int __pyx_v_j;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("gettree", 0);
/* … */
/* function exit code */
__pyx_r = Py_None; __Pyx_INCREF(Py_None);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_AddTraceback("discodop.containers.gettree", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
791: bint disc):
792: """Collect string of tree and sentence for a tree.
793:
794: :param result: provide an empty list for the initial call.
795: :param i: node number to start with."""
+796: cdef int j = tree[i].right
__pyx_t_1 = (__pyx_v_tree[__pyx_v_i]).right; __pyx_v_j = __pyx_t_1;
+797: result.append('(')
if (unlikely(__pyx_v_result == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "append");
__PYX_ERR(1, 797, __pyx_L1_error)
}
__pyx_t_2 = __Pyx_PyList_Append(__pyx_v_result, __pyx_kp_u__42); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(1, 797, __pyx_L1_error)
+798: result.append(vocab.getlabel(tree[i].prod))
if (unlikely(__pyx_v_result == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "append");
__PYX_ERR(1, 798, __pyx_L1_error)
}
__pyx_t_3 = ((struct __pyx_vtabstruct_8discodop_10containers_Vocabulary *)__pyx_v_vocab->__pyx_vtab)->getlabel(__pyx_v_vocab, (__pyx_v_tree[__pyx_v_i]).prod); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 798, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_2 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_3); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(1, 798, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+799: result.append(' ')
if (unlikely(__pyx_v_result == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "append");
__PYX_ERR(1, 799, __pyx_L1_error)
}
__pyx_t_2 = __Pyx_PyList_Append(__pyx_v_result, __pyx_kp_u__27); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(1, 799, __pyx_L1_error)
+800: if tree[i].left >= 0:
__pyx_t_4 = (((__pyx_v_tree[__pyx_v_i]).left >= 0) != 0);
if (__pyx_t_4) {
/* … */
goto __pyx_L3;
}
+801: gettree(result, tree, vocab, tree[i].left, disc)
__pyx_t_3 = __pyx_f_8discodop_10containers_gettree(__pyx_v_result, __pyx_v_tree, __pyx_v_vocab, (__pyx_v_tree[__pyx_v_i]).left, __pyx_v_disc); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 801, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+802: if tree[i].right >= 0:
__pyx_t_4 = (((__pyx_v_tree[__pyx_v_i]).right >= 0) != 0);
if (__pyx_t_4) {
/* … */
}
+803: result.append(' ')
if (unlikely(__pyx_v_result == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "append");
__PYX_ERR(1, 803, __pyx_L1_error)
}
__pyx_t_2 = __Pyx_PyList_Append(__pyx_v_result, __pyx_kp_u__27); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(1, 803, __pyx_L1_error)
+804: gettree(result, tree, vocab, tree[i].right, disc)
__pyx_t_3 = __pyx_f_8discodop_10containers_gettree(__pyx_v_result, __pyx_v_tree, __pyx_v_vocab, (__pyx_v_tree[__pyx_v_i]).right, __pyx_v_disc); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 804, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+805: elif disc:
__pyx_t_4 = (__pyx_v_disc != 0);
if (__pyx_t_4) {
/* … */
goto __pyx_L3;
}
+806: result.append('%d=%s' % (
if (unlikely(__pyx_v_result == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "append");
__PYX_ERR(1, 806, __pyx_L1_error)
}
/* … */
__pyx_t_5 = PyUnicode_Format(__pyx_kp_u_d_s, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 806, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_2 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_5); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(1, 806, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+807: termidx(tree[i].left),
__pyx_t_3 = __Pyx_PyInt_From_short(__pyx_f_8discodop_10containers_termidx((__pyx_v_tree[__pyx_v_i]).left)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 807, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); /* … */ __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 807, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5); __pyx_t_3 = 0; __pyx_t_5 = 0;
+808: vocab.getword(tree[i].prod) or ''))
__pyx_t_6 = ((struct __pyx_vtabstruct_8discodop_10containers_Vocabulary *)__pyx_v_vocab->__pyx_vtab)->getword(__pyx_v_vocab, (__pyx_v_tree[__pyx_v_i]).prod); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 808, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(1, 808, __pyx_L1_error)
if (!__pyx_t_4) {
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
} else {
__Pyx_INCREF(__pyx_t_6);
__pyx_t_5 = __pyx_t_6;
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
goto __pyx_L5_bool_binop_done;
}
__Pyx_INCREF(__pyx_kp_u__11);
__pyx_t_5 = __pyx_kp_u__11;
__pyx_L5_bool_binop_done:;
809: # append rest of indices in case of disc. substitution site
+810: while j >= 0:
while (1) {
__pyx_t_4 = ((__pyx_v_j >= 0) != 0);
if (!__pyx_t_4) break;
+811: result.append(' %d=' % termidx(tree[j].left))
if (unlikely(__pyx_v_result == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "append");
__PYX_ERR(1, 811, __pyx_L1_error)
}
__pyx_t_5 = __Pyx_PyInt_From_short(__pyx_f_8discodop_10containers_termidx((__pyx_v_tree[__pyx_v_j]).left)); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 811, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_6 = PyUnicode_Format(__pyx_kp_u_d_2, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 811, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_2 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_6); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(1, 811, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+812: j = tree[j].right
__pyx_t_1 = (__pyx_v_tree[__pyx_v_j]).right;
__pyx_v_j = __pyx_t_1;
}
813: else:
+814: result.append(vocab.getword(tree[i].prod) or '')
/*else*/ {
if (unlikely(__pyx_v_result == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "append");
__PYX_ERR(1, 814, __pyx_L1_error)
}
__pyx_t_5 = ((struct __pyx_vtabstruct_8discodop_10containers_Vocabulary *)__pyx_v_vocab->__pyx_vtab)->getword(__pyx_v_vocab, (__pyx_v_tree[__pyx_v_i]).prod); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 814, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(1, 814, __pyx_L1_error)
if (!__pyx_t_4) {
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
} else {
__Pyx_INCREF(__pyx_t_5);
__pyx_t_6 = __pyx_t_5;
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
goto __pyx_L9_bool_binop_done;
}
__Pyx_INCREF(__pyx_kp_u__11);
__pyx_t_6 = __pyx_kp_u__11;
__pyx_L9_bool_binop_done:;
__pyx_t_2 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_6); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(1, 814, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
}
__pyx_L3:;
+815: result.append(')')
if (unlikely(__pyx_v_result == Py_None)) {
PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "append");
__PYX_ERR(1, 815, __pyx_L1_error)
}
__pyx_t_2 = __Pyx_PyList_Append(__pyx_v_result, __pyx_kp_u__43); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(1, 815, __pyx_L1_error)
816:
817:
+818: cdef inline int getbufptr(
static CYTHON_INLINE int __pyx_f_8discodop_10containers_getbufptr(PyObject *__pyx_v_obj, char **__pyx_v_ptr, Py_ssize_t *__pyx_v_size, Py_buffer *__pyx_v_buf) {
int __pyx_v_result;
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("getbufptr", 0);
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_WriteUnraisable("discodop.containers.getbufptr", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
__pyx_r = 0;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
819: object obj, char ** ptr, Py_ssize_t * size, Py_buffer * buf):
820: """Get a pointer from bytes/buffer object ``obj``.
821:
822: On success, return 0, and set ``ptr``, ``size``, and possibly ``buf``."""
+823: cdef int result = -1
__pyx_v_result = -1;
+824: ptr[0] = NULL
(__pyx_v_ptr[0]) = NULL;
+825: size[0] = 0
(__pyx_v_size[0]) = 0;
+826: if PyObject_CheckBuffer(obj) == 1: # new-style Buffer interface
__pyx_t_1 = ((PyObject_CheckBuffer(__pyx_v_obj) == 1) != 0);
if (__pyx_t_1) {
/* … */
}
+827: result = PyObject_GetBuffer(obj, buf, PyBUF_SIMPLE)
__pyx_t_2 = PyObject_GetBuffer(__pyx_v_obj, __pyx_v_buf, PyBUF_SIMPLE); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(1, 827, __pyx_L1_error)
__pyx_v_result = __pyx_t_2;
+828: if result == 0:
__pyx_t_1 = ((__pyx_v_result == 0) != 0);
if (__pyx_t_1) {
/* … */
}
+829: ptr[0] = <char *>buf.buf
(__pyx_v_ptr[0]) = ((char *)__pyx_v_buf->buf);
+830: size[0] = buf.len
__pyx_t_3 = __pyx_v_buf->len;
(__pyx_v_size[0]) = __pyx_t_3;
+831: return result
__pyx_r = __pyx_v_result; goto __pyx_L0;
832:
833:
+834: __all__ = ['Grammar', 'Chart', 'Ctrees', 'SmallChartItem', 'FatChartItem',
__pyx_t_1 = PyList_New(9); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 834, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_n_u_Grammar); __Pyx_GIVEREF(__pyx_n_u_Grammar); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_u_Grammar); __Pyx_INCREF(__pyx_n_u_Chart); __Pyx_GIVEREF(__pyx_n_u_Chart); PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_u_Chart); __Pyx_INCREF(__pyx_n_u_Ctrees); __Pyx_GIVEREF(__pyx_n_u_Ctrees); PyList_SET_ITEM(__pyx_t_1, 2, __pyx_n_u_Ctrees); __Pyx_INCREF(__pyx_n_u_SmallChartItem); __Pyx_GIVEREF(__pyx_n_u_SmallChartItem); PyList_SET_ITEM(__pyx_t_1, 3, __pyx_n_u_SmallChartItem); __Pyx_INCREF(__pyx_n_u_FatChartItem); __Pyx_GIVEREF(__pyx_n_u_FatChartItem); PyList_SET_ITEM(__pyx_t_1, 4, __pyx_n_u_FatChartItem); __Pyx_INCREF(__pyx_n_u_Edges); __Pyx_GIVEREF(__pyx_n_u_Edges); PyList_SET_ITEM(__pyx_t_1, 5, __pyx_n_u_Edges); __Pyx_INCREF(__pyx_n_u_RankedEdge); __Pyx_GIVEREF(__pyx_n_u_RankedEdge); PyList_SET_ITEM(__pyx_t_1, 6, __pyx_n_u_RankedEdge); __Pyx_INCREF(__pyx_n_u_Vocabulary); __Pyx_GIVEREF(__pyx_n_u_Vocabulary); PyList_SET_ITEM(__pyx_t_1, 7, __pyx_n_u_Vocabulary); __Pyx_INCREF(__pyx_n_u_FixedVocabulary); __Pyx_GIVEREF(__pyx_n_u_FixedVocabulary); PyList_SET_ITEM(__pyx_t_1, 8, __pyx_n_u_FixedVocabulary); if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_1) < 0) __PYX_ERR(1, 834, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
835: 'Edges', 'RankedEdge', 'Vocabulary', 'FixedVocabulary']