From 3044d6d1c6d428e8d06c255e3a2d739bcd187679 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Fri, 29 Jun 2012 18:45:26 -0700 Subject: add option for entropy optimization --- minrisk/minrisk_optimize.cc | 67 +++++++++++++++++++++++++++++++++++++++------ training/Makefile.am | 1 + training/entropy.cc | 41 +++++++++++++++++++++++++++ training/entropy.h | 22 +++++++++++++++ utils/fdict.h | 2 ++ 5 files changed, 124 insertions(+), 9 deletions(-) create mode 100644 training/entropy.cc create mode 100644 training/entropy.h diff --git a/minrisk/minrisk_optimize.cc b/minrisk/minrisk_optimize.cc index 6e651994..da8b5260 100644 --- a/minrisk/minrisk_optimize.cc +++ b/minrisk/minrisk_optimize.cc @@ -17,6 +17,7 @@ #include "ns_docscorer.h" #include "candidate_set.h" #include "risk.h" +#include "entropy.h" using namespace std; namespace po = boost::program_options; @@ -28,6 +29,9 @@ void InitCommandLine(int argc, char** argv, po::variables_map* conf) { ("weights,w",po::value(), "[REQD] Weights files from current iterations") ("input,i",po::value()->default_value("-"), "Input file to map (- is STDIN)") ("evaluation_metric,m",po::value()->default_value("IBM_BLEU"), "Evaluation metric (ibm_bleu, koehn_bleu, nist_bleu, ter, meteor, etc.)") + ("temperature,T",po::value()->default_value(0.0), "Temperature parameter for objective (>0 increases the entropy)") + ("l1_strength,C",po::value()->default_value(0.0), "L1 regularization strength") + ("memory_buffers,M",po::value()->default_value(20), "Memory buffers used in LBFGS") ("kbest_repository,R",po::value(), "Accumulate k-best lists from previous iterations (parameter is path to repository)") ("kbest_size,k",po::value()->default_value(500u), "Top k-hypotheses to extract") ("help,h", "Help"); @@ -52,36 +56,80 @@ void InitCommandLine(int argc, char** argv, po::variables_map* conf) { EvaluationMetric* metric = NULL; struct RiskObjective { - explicit RiskObjective(const vector& tr) : training(tr) {} + explicit RiskObjective(const vector& tr, const double temp) : training(tr), T(temp) {} double operator()(const vector& x, double* g) const { fill(g, g + x.size(), 0.0); double obj = 0; + double h = 0; for (unsigned i = 0; i < training.size(); ++i) { training::CandidateSetRisk risk(training[i], *metric); - SparseVector tg; + training::CandidateSetEntropy entropy(training[i]); + SparseVector tg, hg; double r = risk(x, &tg); + double hh = entropy(x, &hg); + h += hh; obj += r; for (SparseVector::iterator it = tg.begin(); it != tg.end(); ++it) g[it->first] += it->second; + if (T) { + for (SparseVector::iterator it = hg.begin(); it != hg.end(); ++it) + g[it->first] += T * it->second; + } } - cerr << (1-(obj / training.size())) << endl; - return obj; + cerr << (1-(obj / training.size())) << " H=" << h << endl; + return obj - T * h; } const vector& training; + const double T; // temperature for entropy regularization }; double LearnParameters(const vector& training, + const double temp, // > 0 increases the entropy, < 0 decreases the entropy const double C1, const unsigned memory_buffers, vector* px) { - RiskObjective obj(training); + RiskObjective obj(training, temp); LBFGS lbfgs(px, obj, memory_buffers, C1); lbfgs.MinimizeFunction(); return 0; } -// runs lines 4--15 of rampion algorithm +#if 0 +struct FooLoss { + double operator()(const vector& x, double* g) const { + fill(g, g + x.size(), 0.0); + training::CandidateSet cs; + training::CandidateSetEntropy cse(cs); + cs.cs.resize(3); + cs.cs[0].fmap.set_value(FD::Convert("F1"), -1.0); + cs.cs[1].fmap.set_value(FD::Convert("F2"), 1.0); + cs.cs[2].fmap.set_value(FD::Convert("F1"), 2.0); + cs.cs[2].fmap.set_value(FD::Convert("F2"), 0.5); + SparseVector xx; + double h = cse(x, &xx); + cerr << cse(x, &xx) << endl; cerr << "G: " << xx << endl; + for (SparseVector::iterator i = xx.begin(); i != xx.end(); ++i) + g[i->first] += i->second; + return -h; + } +}; +#endif + int main(int argc, char** argv) { +#if 0 + training::CandidateSet cs; + training::CandidateSetEntropy cse(cs); + cs.cs.resize(3); + cs.cs[0].fmap.set_value(FD::Convert("F1"), -1.0); + cs.cs[1].fmap.set_value(FD::Convert("F2"), 1.0); + cs.cs[2].fmap.set_value(FD::Convert("F1"), 2.0); + cs.cs[2].fmap.set_value(FD::Convert("F2"), 0.5); + FooLoss foo; + vector ww(FD::NumFeats()); ww[FD::Convert("F1")] = 1.0; + LBFGS lbfgs(&ww, foo, 100, 0.0); + lbfgs.MinimizeFunction(); + return 1; +#endif po::variables_map conf; InitCommandLine(argc, argv, &conf); const string evaluation_metric = conf["evaluation_metric"].as(); @@ -89,8 +137,6 @@ int main(int argc, char** argv) { metric = EvaluationMetric::Instance(evaluation_metric); DocumentScorer ds(metric, conf["reference"].as >()); cerr << "Loaded " << ds.size() << " references for scoring with " << evaluation_metric << endl; - double goodsign = -1; - double badsign = -goodsign; Hypergraph hg; string last_file; @@ -141,7 +187,10 @@ int main(int argc, char** argv) { cerr << "\nHypergraphs loaded.\n"; weights.resize(FD::NumFeats()); - LearnParameters(kis, 0.0, 100, &weights); + double c1 = conf["l1_strength"].as(); + double temp = conf["temperature"].as(); + unsigned m = conf["memory_buffers"].as(); + LearnParameters(kis, temp, c1, m, &weights); Weights::WriteToFile("-", weights); return 0; } diff --git a/training/Makefile.am b/training/Makefile.am index 68ebfab4..4cef0d5b 100644 --- a/training/Makefile.am +++ b/training/Makefile.am @@ -26,6 +26,7 @@ TESTS = lbfgs_test optimize_test noinst_LIBRARIES = libtraining.a libtraining_a_SOURCES = \ candidate_set.cc \ + entropy.cc \ optimize.cc \ online_optimizer.cc \ risk.cc diff --git a/training/entropy.cc b/training/entropy.cc new file mode 100644 index 00000000..4fdbe2be --- /dev/null +++ b/training/entropy.cc @@ -0,0 +1,41 @@ +#include "entropy.h" + +#include "prob.h" +#include "candidate_set.h" + +using namespace std; + +namespace training { + +// see Mann and McCallum "Efficient Computation of Entropy Gradient ..." for +// a mostly clear derivation of: +// g = E[ F(x,y) * log p(y|x) ] + H(y | x) * E[ F(x,y) ] +double CandidateSetEntropy::operator()(const vector& params, + SparseVector* g) const { + prob_t z; + vector dps(cands_.size()); + for (unsigned i = 0; i < cands_.size(); ++i) { + dps[i] = cands_[i].fmap.dot(params); + const prob_t u(dps[i], init_lnx()); + z += u; + } + const double log_z = log(z); + + SparseVector exp_feats; + double entropy = 0; + for (unsigned i = 0; i < cands_.size(); ++i) { + const double log_prob = cands_[i].fmap.dot(params) - log_z; + const double prob = exp(log_prob); + const double e_logprob = prob * log_prob; + entropy -= e_logprob; + if (g) { + (*g) += cands_[i].fmap * e_logprob; + exp_feats += cands_[i].fmap * prob; + } + } + if (g) (*g) += exp_feats * entropy; + return entropy; +} + +} + diff --git a/training/entropy.h b/training/entropy.h new file mode 100644 index 00000000..796589ca --- /dev/null +++ b/training/entropy.h @@ -0,0 +1,22 @@ +#ifndef _CSENTROPY_H_ +#define _CSENTROPY_H_ + +#include +#include "sparse_vector.h" + +namespace training { + class CandidateSet; + + class CandidateSetEntropy { + public: + explicit CandidateSetEntropy(const CandidateSet& cs) : cands_(cs) {} + // compute the entropy (expected log likelihood) of a CandidateSet + // (optional) the gradient of the entropy with respect to params + double operator()(const std::vector& params, + SparseVector* g = NULL) const; + private: + const CandidateSet& cands_; + }; +}; + +#endif diff --git a/utils/fdict.h b/utils/fdict.h index 71547d2e..eb853fb2 100644 --- a/utils/fdict.h +++ b/utils/fdict.h @@ -33,6 +33,8 @@ struct FD { assert(dict_.max() == 0); // dictionary must not have // been added to hash_ = new PerfectHashFunction(cmph_file); +#else + (void) cmph_file; #endif } static inline int NumFeats() { -- cgit v1.2.3 From dc9e428224d95adf63da6460a2031348de295ca1 Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Sun, 1 Jul 2012 00:38:30 -0400 Subject: [python] MT evaluation --- python/cdec/__init__.py | 1 + python/cdec/score.py | 1 + python/setup.py | 7 +- python/src/_cdec.cpp | 6817 +++++++++++++++++++++++++++++++++++---------- python/src/_cdec.pyx | 4 +- python/src/hypergraph.pxi | 15 +- python/src/kbest.pxd | 2 + python/src/mteval.pxd | 47 + python/src/mteval.pxi | 116 + python/src/utils.pxd | 10 +- python/src/vectors.pxi | 34 +- python/test.py | 4 +- 12 files changed, 5501 insertions(+), 1557 deletions(-) create mode 100644 python/cdec/score.py create mode 100644 python/src/mteval.pxd create mode 100644 python/src/mteval.pxi diff --git a/python/cdec/__init__.py b/python/cdec/__init__.py index eda81194..0d7b8782 100644 --- a/python/cdec/__init__.py +++ b/python/cdec/__init__.py @@ -1 +1,2 @@ from _cdec import Decoder, Lattice +import score diff --git a/python/cdec/score.py b/python/cdec/score.py new file mode 100644 index 00000000..c107446f --- /dev/null +++ b/python/cdec/score.py @@ -0,0 +1 @@ +from _cdec import BLEU, TER diff --git a/python/setup.py b/python/setup.py index 49a1ec8f..cc8b289d 100644 --- a/python/setup.py +++ b/python/setup.py @@ -3,8 +3,8 @@ from distutils.extension import Extension from Cython.Distutils import build_ext import os -INC = ['..', 'src/', '../decoder', '../utils'] -LIB = ['../decoder', '../utils', '../mteval', '../klm/lm', '../klm/util'] +INC = ['..', 'src/', '../decoder', '../utils', '../mteval'] +LIB = ['../decoder', '../utils', '../mteval', '../training', '../klm/lm', '../klm/util'] BOOST_ROOT = os.getenv('BOOST_ROOT') if BOOST_ROOT: @@ -18,7 +18,8 @@ ext_modules = [ include_dirs=INC, library_dirs=LIB, libraries=['boost_program_options-mt', 'z', - 'cdec', 'utils', 'mteval', 'klm', 'klm_util']) + 'cdec', 'utils', 'mteval', 'training', 'klm', 'klm_util'], + extra_compile_args=['-DHAVE_CONFIG_H']), ] setup( diff --git a/python/src/_cdec.cpp b/python/src/_cdec.cpp index 0b9b9911..7d45e27f 100644 --- a/python/src/_cdec.cpp +++ b/python/src/_cdec.cpp @@ -1,4 +1,4 @@ -/* Generated by Cython 0.16 on Sat Jun 23 11:57:21 2012 */ +/* Generated by Cython 0.16 on Sun Jul 1 00:36:19 2012 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -279,11 +279,12 @@ #include "utils/wordid.h" #include "utils/small_vector.h" #include "utils/sparse_vector.h" -#include "utils/tdict.cc" +#include "utils/tdict.h" #include "utils/verbose.h" #include "utils/fdict.h" #include "utils/filelib.h" #include "utils/sampler.h" +#include #include "decoder/lattice.h" #include "decoder/hg.h" #include "decoder/viterbi.h" @@ -295,6 +296,8 @@ #include "decoder/decoder.h" #include "observer.h" #include "decoder/kbest.h" +#include "mteval/ns.h" +#include "training/candidate_set.h" #ifdef _OPENMP #include #endif /* _OPENMP */ @@ -381,37 +384,66 @@ static const char *__pyx_f[] = { "vectors.pxi", "hypergraph.pxi", "lattice.pxi", + "mteval.pxi", }; /*--- Type declarations ---*/ -struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample; +struct __pyx_obj_5_cdec_Scorer; +struct __pyx_obj_5_cdec_SufficientStats; struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__; +struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features; struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree; struct __pyx_obj_5_cdec_Decoder; +struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set; +struct __pyx_obj_5_cdec_SegmentEvaluator; struct __pyx_obj_5_cdec_SparseVector; struct __pyx_obj_5_cdec_Hypergraph; struct __pyx_obj_5_cdec_Lattice; -struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__; struct __pyx_obj_5_cdec___pyx_scope_struct____iter__; struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest; +struct __pyx_obj_5_cdec_Candidate; +struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample; struct __pyx_obj_5_cdec_DenseVector; +struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__; +struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__; +struct __pyx_opt_args_5_cdec_as_str; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":3 + * cimport mteval + * + * cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): # <<<<<<<<<<<<<< + * cdef bytes ret + * if isinstance(sentence, unicode): + */ +struct __pyx_opt_args_5_cdec_as_str { + int __pyx_n; + PyObject *error_msg; +}; + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":87 + * del cs + * + * cdef class Scorer: # <<<<<<<<<<<<<< + * cdef string* name * - * def sample(self, unsigned n): # <<<<<<<<<<<<<< - * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() - * if self.rng == NULL: */ -struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample { +struct __pyx_obj_5_cdec_Scorer { PyObject_HEAD - std::vector *__pyx_v_hypos; - unsigned int __pyx_v_k; - unsigned int __pyx_v_n; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; - PyObject *__pyx_v_sentence; - size_t __pyx_t_0; - unsigned int __pyx_t_1; + std::string *name; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":27 + * return fmap + * + * cdef class SufficientStats: # <<<<<<<<<<<<<< + * cdef mteval.SufficientStats* stats + * cdef mteval.EvaluationMetric* metric + */ +struct __pyx_obj_5_cdec_SufficientStats { + PyObject_HEAD + SufficientStats *stats; + EvaluationMetric *metric; }; @@ -433,6 +465,26 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ { }; +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 + * del derivations + * + * def kbest_features(self, size): # <<<<<<<<<<<<<< + * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) + * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal].Derivation* derivation + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features { + PyObject_HEAD + KBest::KBestDerivations,FeatureVectorTraversal>::Derivation *__pyx_v_derivation; + KBest::KBestDerivations,FeatureVectorTraversal> *__pyx_v_derivations; + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap; + unsigned int __pyx_v_k; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; + PyObject *__pyx_v_size; + unsigned int __pyx_t_0; + long __pyx_t_1; +}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":44 * del derivations * @@ -454,7 +506,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree { /* "_cdec.pyx":15 - * pass + * class ParseFailed(Exception): pass * * cdef class Decoder: # <<<<<<<<<<<<<< * cdef decoder.Decoder* dec @@ -467,6 +519,40 @@ struct __pyx_obj_5_cdec_Decoder { }; +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":75 + * return sf + * + * def candidate_set(self, Hypergraph hypergraph, unsigned k): # <<<<<<<<<<<<<< + * cdef mteval.CandidateSet* cs = new mteval.CandidateSet() + * cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set { + PyObject_HEAD + struct __pyx_obj_5_cdec_Candidate *__pyx_v_candidate; + training::CandidateSet *__pyx_v_cs; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph; + unsigned int __pyx_v_i; + unsigned int __pyx_v_k; + struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self; + unsigned int __pyx_t_0; + unsigned int __pyx_t_1; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":59 + * return result + * + * cdef class SegmentEvaluator: # <<<<<<<<<<<<<< + * cdef shared_ptr[mteval.SegmentEvaluator]* scorer + * cdef mteval.EvaluationMetric* metric + */ +struct __pyx_obj_5_cdec_SegmentEvaluator { + PyObject_HEAD + boost::shared_ptr *scorer; + EvaluationMetric *metric; +}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":32 * return sparse * @@ -507,22 +593,6 @@ struct __pyx_obj_5_cdec_Lattice { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":50 - * return hypergraph.AsPLF(self.lattice[0], True).c_str() - * - * def __iter__(self): # <<<<<<<<<<<<<< - * cdef unsigned i - * for i in range(len(self)): - */ -struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ { - PyObject_HEAD - unsigned int __pyx_v_i; - struct __pyx_obj_5_cdec_Lattice *__pyx_v_self; - Py_ssize_t __pyx_t_0; - unsigned int __pyx_t_1; -}; - - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":18 * self.vector[0][fid] = value * @@ -559,6 +629,39 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest { }; +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":13 + * return ret + * + * cdef class Candidate: # <<<<<<<<<<<<<< + * cdef mteval.Candidate* candidate + * cdef public float score + */ +struct __pyx_obj_5_cdec_Candidate { + PyObject_HEAD + const training::Candidate *candidate; + float score; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":69 + * del derivations + * + * def sample(self, unsigned n): # <<<<<<<<<<<<<< + * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() + * if self.rng == NULL: + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample { + PyObject_HEAD + std::vector *__pyx_v_hypos; + unsigned int __pyx_v_k; + unsigned int __pyx_v_n; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self; + PyObject *__pyx_v_sentence; + size_t __pyx_t_0; + unsigned int __pyx_t_1; +}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":3 * from cython.operator cimport preincrement as pinc * @@ -571,6 +674,39 @@ struct __pyx_obj_5_cdec_DenseVector { std::vector *vector; }; + +/* "/Users/vchahun/Sandbox/cdec/python/src/lattice.pxi":50 + * return hypergraph.AsPLF(self.lattice[0], True).c_str() + * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(len(self)): + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ { + PyObject_HEAD + unsigned int __pyx_v_i; + struct __pyx_obj_5_cdec_Lattice *__pyx_v_self; + Py_ssize_t __pyx_t_0; + unsigned int __pyx_t_1; +}; + + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":45 + * return self.stats.size() + * + * def __iter__(self): # <<<<<<<<<<<<<< + * for i in range(len(self)): + * yield self.stats[0][i] + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ { + PyObject_HEAD + PyObject *__pyx_v_i; + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self; + Py_ssize_t __pyx_t_0; + PyObject *__pyx_t_1; + PyObject *(*__pyx_t_2)(PyObject *); +}; + #ifndef CYTHON_REFNANNY #define CYTHON_REFNANNY 0 #endif @@ -635,6 +771,8 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, const char *name, int exact); /*proto*/ +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ + static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); /*proto*/ static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[], \ @@ -736,8 +874,6 @@ static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ -static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ - static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb); /*proto*/ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ @@ -801,6 +937,9 @@ static __pyx_GeneratorObject *__Pyx_Generator_New(__pyx_generator_body_t body, PyObject *closure); static int __pyx_Generator_init(void); +static void __Pyx_WriteUnraisable(const char *name, int clineno, + int lineno, const char *filename); /*proto*/ + static int __Pyx_check_binary_version(void); typedef struct { @@ -841,18 +980,28 @@ static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ /* Module declarations from 'kbest' */ +/* Module declarations from 'mteval' */ + /* Module declarations from '_cdec' */ static PyTypeObject *__pyx_ptype_5_cdec_DenseVector = 0; static PyTypeObject *__pyx_ptype_5_cdec_SparseVector = 0; static PyTypeObject *__pyx_ptype_5_cdec_Hypergraph = 0; static PyTypeObject *__pyx_ptype_5_cdec_Lattice = 0; +static PyTypeObject *__pyx_ptype_5_cdec_Candidate = 0; +static PyTypeObject *__pyx_ptype_5_cdec_SufficientStats = 0; +static PyTypeObject *__pyx_ptype_5_cdec_SegmentEvaluator = 0; +static PyTypeObject *__pyx_ptype_5_cdec_Scorer = 0; static PyTypeObject *__pyx_ptype_5_cdec_Decoder = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct____iter__ = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_1___iter__ = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_2_kbest = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_tree = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_4_sample = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_5___iter__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_5_sample = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_6___iter__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_7___iter__ = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_8_candidate_set = 0; +static char *__pyx_f_5_cdec_as_str(PyObject *, struct __pyx_opt_args_5_cdec_as_str *__pyx_optional_args); /*proto*/ #define __Pyx_MODULE_NAME "_cdec" int __pyx_module_is_main__cdec = 0; @@ -860,11 +1009,10 @@ int __pyx_module_is_main__cdec = 0; static PyObject *__pyx_builtin_Exception; static PyObject *__pyx_builtin_KeyError; static PyObject *__pyx_builtin_range; -static PyObject *__pyx_builtin_ValueError; +static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_NotImplemented; static PyObject *__pyx_builtin_eval; static PyObject *__pyx_builtin_enumerate; -static PyObject *__pyx_builtin_TypeError; static PyObject *__pyx_builtin_IndexError; static PyObject *__pyx_builtin_open; static PyObject *__pyx_pf_5_cdec_11DenseVector___getitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ @@ -877,7 +1025,7 @@ static int __pyx_pf_5_cdec_12SparseVector_2__setitem__(struct __pyx_obj_5_cdec_S static PyObject *__pyx_pf_5_cdec_12SparseVector_4__iter__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, PyObject *__pyx_v_other); /* proto */ static PyObject *__pyx_pf_5_cdec_12SparseVector_9todense(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other, int __pyx_v_op); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y, int __pyx_v_op); /* proto */ static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_13__len__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ static int __pyx_pf_5_cdec_12SparseVector_15__contains__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ static PyObject *__pyx_pf_5_cdec_12SparseVector_17__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ @@ -886,8 +1034,12 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_21__imul__(struct __pyx_obj_5_cd #if PY_MAJOR_VERSION < 3 static PyObject *__pyx_pf_5_cdec_12SparseVector_23__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ #endif -static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_29__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ +#if PY_MAJOR_VERSION < 3 +static PyObject *__pyx_pf_5_cdec_12SparseVector_31__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ +#endif static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_4viterbi_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ @@ -895,11 +1047,12 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_6viterbi_source_tree(struct __pyx_ static PyObject *__pyx_pf_5_cdec_10Hypergraph_8viterbi_features(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_10kbest(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_13kbest_tree(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_16sample(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, unsigned int __pyx_v_n); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_19intersect(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, struct __pyx_obj_5_cdec_Lattice *__pyx_v_lat); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_21prune(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_beam_alpha, PyObject *__pyx_v_density, PyObject *__pyx_v_kwargs); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_23lattice(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_25reweight(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_weights); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_16kbest_features(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_19sample(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, unsigned int __pyx_v_n); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_22intersect(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, struct __pyx_obj_5_cdec_Lattice *__pyx_v_lat); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_24prune(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_beam_alpha, PyObject *__pyx_v_density, PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_26lattice(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_weights); /* proto */ static int __pyx_pf_5_cdec_7Lattice___init__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, PyObject *__pyx_v_inp); /* proto */ static PyObject *__pyx_pf_5_cdec_7Lattice_2__getitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index); /* proto */ static int __pyx_pf_5_cdec_7Lattice_4__setitem__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self, int __pyx_v_index, PyObject *__pyx_v_arcs); /* proto */ @@ -907,6 +1060,23 @@ static Py_ssize_t __pyx_pf_5_cdec_7Lattice_6__len__(struct __pyx_obj_5_cdec_Latt static PyObject *__pyx_pf_5_cdec_7Lattice_8__str__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ static void __pyx_pf_5_cdec_7Lattice_13__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Lattice *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_9Candidate_4fmap___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_9Candidate_5score___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_9Candidate_5score_2__set__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self, PyObject *__pyx_v_value); /* proto */ +static void __pyx_pf_5_cdec_15SufficientStats___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_15SufficientStats_5score___get__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_15SufficientStats_6detail___get__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self); /* proto */ +static Py_ssize_t __pyx_pf_5_cdec_15SufficientStats_2__len__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__iadd__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_x, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_y); /* proto */ +static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, PyObject *__pyx_v_sentence); /* proto */ +static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph, unsigned int __pyx_v_k); /* proto */ +static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, char *__pyx_v_name); /* proto */ +static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs); /* proto */ +static PyObject *__pyx_pf_5_cdec_6Scorer_4__str__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self); /* proto */ static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, char *__pyx_v_config); /* proto */ static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Decoder *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_cfg); /* proto */ @@ -920,12 +1090,18 @@ static char __pyx_k_10[] = "csplit_preserve_full_word"; static char __pyx_k_11[] = "cannot reweight hypergraph with %s"; static char __pyx_k_13[] = "Cannot create lattice from %s"; static char __pyx_k_14[] = "lattice index out of range"; -static char __pyx_k_21[] = "Cannot translate input type %s"; +static char __pyx_k_19[] = "Cannot convert type %s to str"; +static char __pyx_k_23[] = "Cannot translate input type %s"; +static char __pyx_k__k[] = "k"; +static char __pyx_k__TER[] = "TER"; static char __pyx_k__dot[] = "dot"; static char __pyx_k__inp[] = "inp"; static char __pyx_k__plf[] = "plf"; +static char __pyx_k__BLEU[] = "BLEU"; static char __pyx_k__eval[] = "eval"; +static char __pyx_k__name[] = "name"; static char __pyx_k__open[] = "open"; +static char __pyx_k__refs[] = "refs"; static char __pyx_k__self[] = "self"; static char __pyx_k__utf8[] = "utf8"; static char __pyx_k___cdec[] = "_cdec"; @@ -937,18 +1113,20 @@ static char __pyx_k__decode[] = "decode"; static char __pyx_k__encode[] = "encode"; static char __pyx_k__density[] = "density"; static char __pyx_k__grammar[] = "grammar"; +static char __pyx_k__IBM_BLEU[] = "IBM_BLEU"; static char __pyx_k__KeyError[] = "KeyError"; static char __pyx_k____exit__[] = "__exit__"; static char __pyx_k____main__[] = "__main__"; static char __pyx_k____test__[] = "__test__"; +static char __pyx_k__encoding[] = "encoding"; static char __pyx_k__sentence[] = "sentence"; static char __pyx_k__Exception[] = "Exception"; static char __pyx_k__TypeError[] = "TypeError"; static char __pyx_k____enter__[] = "__enter__"; static char __pyx_k__enumerate[] = "enumerate"; static char __pyx_k__IndexError[] = "IndexError"; -static char __pyx_k__ValueError[] = "ValueError"; static char __pyx_k__beam_alpha[] = "beam_alpha"; +static char __pyx_k__hypergraph[] = "hypergraph"; static char __pyx_k__ParseFailed[] = "ParseFailed"; static char __pyx_k__NotImplemented[] = "NotImplemented"; static PyObject *__pyx_kp_s_1; @@ -956,15 +1134,18 @@ static PyObject *__pyx_n_s_10; static PyObject *__pyx_kp_s_11; static PyObject *__pyx_kp_s_13; static PyObject *__pyx_kp_s_14; +static PyObject *__pyx_kp_s_19; static PyObject *__pyx_kp_s_2; -static PyObject *__pyx_kp_s_21; +static PyObject *__pyx_kp_s_23; +static PyObject *__pyx_n_s__BLEU; static PyObject *__pyx_n_s__Exception; +static PyObject *__pyx_n_s__IBM_BLEU; static PyObject *__pyx_n_s__IndexError; static PyObject *__pyx_n_s__KeyError; static PyObject *__pyx_n_s__NotImplemented; static PyObject *__pyx_n_s__ParseFailed; +static PyObject *__pyx_n_s__TER; static PyObject *__pyx_n_s__TypeError; -static PyObject *__pyx_n_s__ValueError; static PyObject *__pyx_n_s____enter__; static PyObject *__pyx_n_s____exit__; static PyObject *__pyx_n_s____main__; @@ -976,13 +1157,18 @@ static PyObject *__pyx_n_s__decode; static PyObject *__pyx_n_s__density; static PyObject *__pyx_n_s__dot; static PyObject *__pyx_n_s__encode; +static PyObject *__pyx_n_s__encoding; static PyObject *__pyx_n_s__enumerate; static PyObject *__pyx_n_s__eval; static PyObject *__pyx_n_s__grammar; +static PyObject *__pyx_n_s__hypergraph; static PyObject *__pyx_n_s__inp; +static PyObject *__pyx_n_s__k; +static PyObject *__pyx_n_s__name; static PyObject *__pyx_n_s__open; static PyObject *__pyx_n_s__plf; static PyObject *__pyx_n_s__range; +static PyObject *__pyx_n_s__refs; static PyObject *__pyx_n_s__self; static PyObject *__pyx_n_s__sentence; static PyObject *__pyx_n_s__split; @@ -1002,8 +1188,11 @@ static PyObject *__pyx_k_tuple_15; static PyObject *__pyx_k_tuple_16; static PyObject *__pyx_k_tuple_17; static PyObject *__pyx_k_tuple_18; -static PyObject *__pyx_k_tuple_19; static PyObject *__pyx_k_tuple_20; +static PyObject *__pyx_k_tuple_21; +static PyObject *__pyx_k_tuple_22; +static PyObject *__pyx_k_tuple_24; +static PyObject *__pyx_k_tuple_25; /* Python wrapper */ static PyObject *__pyx_pw_5_cdec_11DenseVector_1__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ @@ -1857,7 +2046,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa * return self.vector.dot(( other).vector[0]) * elif isinstance(other, SparseVector): # <<<<<<<<<<<<<< * return self.vector.dot(( other).vector[0]) - * raise ValueError('cannot take the dot product of %s and SparseVector' % type(other)) + * raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) */ __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)); __Pyx_INCREF(__pyx_t_1); @@ -1869,7 +2058,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa * return self.vector.dot(( other).vector[0]) * elif isinstance(other, SparseVector): * return self.vector.dot(( other).vector[0]) # <<<<<<<<<<<<<< - * raise ValueError('cannot take the dot product of %s and SparseVector' % type(other)) + * raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) * */ __Pyx_XDECREF(__pyx_r); @@ -1885,7 +2074,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":56 * elif isinstance(other, SparseVector): * return self.vector.dot(( other).vector[0]) - * raise ValueError('cannot take the dot product of %s and SparseVector' % type(other)) # <<<<<<<<<<<<<< + * raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) # <<<<<<<<<<<<<< * * def todense(self): */ @@ -1896,7 +2085,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); @@ -1928,7 +2117,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_10todense(PyObject *__pyx_v_self } /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":58 - * raise ValueError('cannot take the dot product of %s and SparseVector' % type(other)) + * raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) * * def todense(self): # <<<<<<<<<<<<<< * cdef DenseVector dense = DenseVector() @@ -1980,7 +2169,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_9todense(struct __pyx_obj_5_cdec * self.vector.init_vector(dense.vector) * return dense # <<<<<<<<<<<<<< * - * def __richcmp__(SparseVector self, SparseVector other, int op): + * def __richcmp__(SparseVector x, SparseVector y, int op): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_dense)); @@ -2001,14 +2190,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_9todense(struct __pyx_obj_5_cdec } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_12__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_12__richcmp__(PyObject *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_12__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_12__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_self), __pyx_ptype_5_cdec_SparseVector, 1, "self", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_11__richcmp__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other), ((int)__pyx_v_op)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_11__richcmp__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y), ((int)__pyx_v_op)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2020,12 +2209,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_12__richcmp__(PyObject *__pyx_v_ /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":64 * return dense * - * def __richcmp__(SparseVector self, SparseVector other, int op): # <<<<<<<<<<<<<< + * def __richcmp__(SparseVector x, SparseVector y, int op): # <<<<<<<<<<<<<< * if op == 2: # == - * return self.vector[0] == other.vector[0] + * return x.vector[0] == y.vector[0] */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other, int __pyx_v_op) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y, int __pyx_v_op) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -2037,31 +2226,31 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":67 * if op == 2: # == - * return self.vector[0] == other.vector[0] + * return x.vector[0] == y.vector[0] * elif op == 3: # != # <<<<<<<<<<<<<< - * return not (self == other) + * return not (x == y) * raise NotImplemented('comparison not implemented for SparseVector') */ switch (__pyx_v_op) { /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":65 * - * def __richcmp__(SparseVector self, SparseVector other, int op): + * def __richcmp__(SparseVector x, SparseVector y, int op): * if op == 2: # == # <<<<<<<<<<<<<< - * return self.vector[0] == other.vector[0] + * return x.vector[0] == y.vector[0] * elif op == 3: # != */ case 2: /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":66 - * def __richcmp__(SparseVector self, SparseVector other, int op): + * def __richcmp__(SparseVector x, SparseVector y, int op): * if op == 2: # == - * return self.vector[0] == other.vector[0] # <<<<<<<<<<<<<< + * return x.vector[0] == y.vector[0] # <<<<<<<<<<<<<< * elif op == 3: # != - * return not (self == other) + * return not (x == y) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_self->vector[0]) == (__pyx_v_other->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_x->vector[0]) == (__pyx_v_y->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2070,22 +2259,22 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":67 * if op == 2: # == - * return self.vector[0] == other.vector[0] + * return x.vector[0] == y.vector[0] * elif op == 3: # != # <<<<<<<<<<<<<< - * return not (self == other) + * return not (x == y) * raise NotImplemented('comparison not implemented for SparseVector') */ case 3: /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":68 - * return self.vector[0] == other.vector[0] + * return x.vector[0] == y.vector[0] * elif op == 3: # != - * return not (self == other) # <<<<<<<<<<<<<< + * return not (x == y) # <<<<<<<<<<<<<< * raise NotImplemented('comparison not implemented for SparseVector') * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_self), ((PyObject *)__pyx_v_other), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; @@ -2099,7 +2288,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":69 * elif op == 3: # != - * return not (self == other) + * return not (x == y) * raise NotImplemented('comparison not implemented for SparseVector') # <<<<<<<<<<<<<< * * def __len__(self): @@ -2439,7 +2628,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_23__idiv__(struct __pyx_obj_5_cd * self.vector[0] /= scalar * return self # <<<<<<<<<<<<<< * - * def __add__(SparseVector self, SparseVector other): + * def __add__(SparseVector x, SparseVector y): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_self)); @@ -2455,14 +2644,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_23__idiv__(struct __pyx_obj_5_cd #endif /*!(#if PY_MAJOR_VERSION < 3)*/ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__add__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_self), __pyx_ptype_5_cdec_SparseVector, 1, "self", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_25__add__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_25__add__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2474,12 +2663,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_self /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":93 * return self * - * def __add__(SparseVector self, SparseVector other): # <<<<<<<<<<<<<< + * def __add__(SparseVector x, SparseVector y): # <<<<<<<<<<<<<< * cdef SparseVector result = SparseVector() - * result.vector = new FastSparseVector[weight_t](self.vector[0] + other.vector[0]) + * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -2491,9 +2680,9 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cde /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":94 * - * def __add__(SparseVector self, SparseVector other): + * def __add__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< - * result.vector = new FastSparseVector[weight_t](self.vector[0] + other.vector[0]) + * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) * return result */ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -2502,20 +2691,20 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cde __pyx_t_1 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":95 - * def __add__(SparseVector self, SparseVector other): + * def __add__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() - * result.vector = new FastSparseVector[weight_t](self.vector[0] + other.vector[0]) # <<<<<<<<<<<<<< + * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) # <<<<<<<<<<<<<< * return result * */ - __pyx_v_result->vector = new FastSparseVector(((__pyx_v_self->vector[0]) + (__pyx_v_other->vector[0]))); + __pyx_v_result->vector = new FastSparseVector(((__pyx_v_x->vector[0]) + (__pyx_v_y->vector[0]))); /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":96 * cdef SparseVector result = SparseVector() - * result.vector = new FastSparseVector[weight_t](self.vector[0] + other.vector[0]) + * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) * return result # <<<<<<<<<<<<<< * - * def __sub__(SparseVector self, SparseVector other): + * def __sub__(SparseVector x, SparseVector y): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); @@ -2536,14 +2725,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cde } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__sub__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_self), __pyx_ptype_5_cdec_SparseVector, 1, "self", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_27__sub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_27__sub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2555,12 +2744,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_self /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":98 * return result * - * def __sub__(SparseVector self, SparseVector other): # <<<<<<<<<<<<<< + * def __sub__(SparseVector x, SparseVector y): # <<<<<<<<<<<<<< * cdef SparseVector result = SparseVector() - * result.vector = new FastSparseVector[weight_t](self.vector[0] - other.vector[0]) + * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -2572,9 +2761,9 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cde /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":99 * - * def __sub__(SparseVector self, SparseVector other): + * def __sub__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< - * result.vector = new FastSparseVector[weight_t](self.vector[0] - other.vector[0]) + * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) * return result */ __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -2583,17 +2772,20 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cde __pyx_t_1 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":100 - * def __sub__(SparseVector self, SparseVector other): + * def __sub__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() - * result.vector = new FastSparseVector[weight_t](self.vector[0] - other.vector[0]) # <<<<<<<<<<<<<< + * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) # <<<<<<<<<<<<<< * return result + * */ - __pyx_v_result->vector = new FastSparseVector(((__pyx_v_self->vector[0]) - (__pyx_v_other->vector[0]))); + __pyx_v_result->vector = new FastSparseVector(((__pyx_v_x->vector[0]) - (__pyx_v_y->vector[0]))); /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":101 * cdef SparseVector result = SparseVector() - * result.vector = new FastSparseVector[weight_t](self.vector[0] - other.vector[0]) + * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) * return result # <<<<<<<<<<<<<< + * + * def __mul__(x, y): */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); @@ -2614,105 +2806,346 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cde } /* Python wrapper */ -static void __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_30__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_30__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_10Hypergraph___dealloc__(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__mul__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_29__mul__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":8 - * cdef MT19937* rng +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":103 + * return result * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.hg - * if self.rng != NULL: + * def __mul__(x, y): # <<<<<<<<<<<<<< + * cdef SparseVector vector + * cdef float scalar */ -static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_29__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_vector = 0; + float __pyx_v_scalar; + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - int __pyx_t_1; - __Pyx_RefNannySetupContext("__dealloc__", 0); + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + float __pyx_t_3; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__mul__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":9 - * - * def __dealloc__(self): - * del self.hg # <<<<<<<<<<<<<< - * if self.rng != NULL: - * del self.rng + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":106 + * cdef SparseVector vector + * cdef float scalar + * if isinstance(x, SparseVector): vector, scalar = x, y # <<<<<<<<<<<<<< + * else: vector, scalar = y, x + * cdef SparseVector result = SparseVector() */ - delete __pyx_v_self->hg; + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_v_x; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + __pyx_v_scalar = __pyx_t_3; + goto __pyx_L3; + } + /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":10 - * def __dealloc__(self): - * del self.hg - * if self.rng != NULL: # <<<<<<<<<<<<<< - * del self.rng + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":107 + * cdef float scalar + * if isinstance(x, SparseVector): vector, scalar = x, y + * else: vector, scalar = y, x # <<<<<<<<<<<<<< + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) + */ + if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_v_y; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + __pyx_v_scalar = __pyx_t_3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":108 + * if isinstance(x, SparseVector): vector, scalar = x, y + * else: vector, scalar = y, x + * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< + * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) + * return result + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":109 + * else: vector, scalar = y, x + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) # <<<<<<<<<<<<<< + * return result * */ - __pyx_t_1 = (__pyx_v_self->rng != NULL); - if (__pyx_t_1) { + __pyx_v_result->vector = new FastSparseVector(((__pyx_v_vector->vector[0]) * __pyx_v_scalar)); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":11 - * del self.hg - * if self.rng != NULL: - * del self.rng # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":110 + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) + * return result # <<<<<<<<<<<<<< * - * def viterbi(self): + * def __div__(x, y): */ - delete __pyx_v_self->rng; - goto __pyx_L3; - } - __pyx_L3:; + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + goto __pyx_L0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.SparseVector.__mul__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_vector); + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); + return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_3viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_3viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +#if PY_MAJOR_VERSION < 3 +static PyObject *__pyx_pw_5_cdec_12SparseVector_32__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_32__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("viterbi (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_2viterbi(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__div__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_31__div__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); __Pyx_RefNannyFinishContext(); return __pyx_r; } +#endif /*!(#if PY_MAJOR_VERSION < 3)*/ -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":13 - * del self.rng +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":112 + * return result * - * def viterbi(self): # <<<<<<<<<<<<<< - * cdef vector[WordID] trans - * hypergraph.ViterbiESentence(self.hg[0], &trans) + * def __div__(x, y): # <<<<<<<<<<<<<< + * cdef SparseVector vector + * cdef float scalar */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { - std::vector __pyx_v_trans; - PyObject *__pyx_v_sentence = 0; +#if PY_MAJOR_VERSION < 3 +static PyObject *__pyx_pf_5_cdec_12SparseVector_31__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_vector = 0; + float __pyx_v_scalar; + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; + int __pyx_t_2; + float __pyx_t_3; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("viterbi", 0); + __Pyx_RefNannySetupContext("__div__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":15 - * def viterbi(self): - * cdef vector[WordID] trans - * hypergraph.ViterbiESentence(self.hg[0], &trans) # <<<<<<<<<<<<<< - * cdef str sentence = GetString(trans).c_str() - * return sentence.decode('utf8') + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":115 + * cdef SparseVector vector + * cdef float scalar + * if isinstance(x, SparseVector): vector, scalar = x, y # <<<<<<<<<<<<<< + * else: vector, scalar = y, x + * cdef SparseVector result = SparseVector() */ - ViterbiESentence((__pyx_v_self->hg[0]), (&__pyx_v_trans)); + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_v_x; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + __pyx_v_scalar = __pyx_t_3; + goto __pyx_L3; + } + /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":16 - * cdef vector[WordID] trans - * hypergraph.ViterbiESentence(self.hg[0], &trans) - * cdef str sentence = GetString(trans).c_str() # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":116 + * cdef float scalar + * if isinstance(x, SparseVector): vector, scalar = x, y + * else: vector, scalar = y, x # <<<<<<<<<<<<<< + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) + */ + if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __pyx_v_y; + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + __pyx_v_scalar = __pyx_t_3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":117 + * if isinstance(x, SparseVector): vector, scalar = x, y + * else: vector, scalar = y, x + * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< + * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) + * return result + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":118 + * else: vector, scalar = y, x + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) # <<<<<<<<<<<<<< + * return result + */ + __pyx_v_result->vector = new FastSparseVector(((__pyx_v_vector->vector[0]) / __pyx_v_scalar)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":119 + * cdef SparseVector result = SparseVector() + * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) + * return result # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.SparseVector.__div__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_vector); + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +#endif /*!(#if PY_MAJOR_VERSION < 3)*/ + +/* Python wrapper */ +static void __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_10Hypergraph___dealloc__(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":8 + * cdef MT19937* rng + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.hg + * if self.rng != NULL: + */ + +static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + __Pyx_RefNannyDeclarations + int __pyx_t_1; + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":9 + * + * def __dealloc__(self): + * del self.hg # <<<<<<<<<<<<<< + * if self.rng != NULL: + * del self.rng + */ + delete __pyx_v_self->hg; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":10 + * def __dealloc__(self): + * del self.hg + * if self.rng != NULL: # <<<<<<<<<<<<<< + * del self.rng + * + */ + __pyx_t_1 = (__pyx_v_self->rng != NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":11 + * del self.hg + * if self.rng != NULL: + * del self.rng # <<<<<<<<<<<<<< + * + * def viterbi(self): + */ + delete __pyx_v_self->rng; + goto __pyx_L3; + } + __pyx_L3:; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_3viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_3viterbi(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("viterbi (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_2viterbi(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":13 + * del self.rng + * + * def viterbi(self): # <<<<<<<<<<<<<< + * cdef vector[WordID] trans + * hypergraph.ViterbiESentence(self.hg[0], &trans) + */ + +static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { + std::vector __pyx_v_trans; + PyObject *__pyx_v_sentence = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("viterbi", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":15 + * def viterbi(self): + * cdef vector[WordID] trans + * hypergraph.ViterbiESentence(self.hg[0], &trans) # <<<<<<<<<<<<<< + * cdef str sentence = GetString(trans).c_str() + * return sentence.decode('utf8') + */ + ViterbiESentence((__pyx_v_self->hg[0]), (&__pyx_v_trans)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":16 + * cdef vector[WordID] trans + * hypergraph.ViterbiESentence(self.hg[0], &trans) + * cdef str sentence = GetString(trans).c_str() # <<<<<<<<<<<<<< * return sentence.decode('utf8') * */ @@ -3338,7 +3771,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator3(__pyx_GeneratorObject * yield tree.decode('utf8') * del derivations # <<<<<<<<<<<<<< * - * def sample(self, unsigned n): + * def kbest_features(self, size): */ delete __pyx_cur_scope->__pyx_v_derivations; PyErr_SetNone(PyExc_StopIteration); @@ -3356,22 +3789,12 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator3(__pyx_GeneratorObject static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_17sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_17sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n) { - unsigned int __pyx_v_n; +static PyObject *__pyx_pw_5_cdec_10Hypergraph_17kbest_features(PyObject *__pyx_v_self, PyObject *__pyx_v_size); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_17kbest_features(PyObject *__pyx_v_self, PyObject *__pyx_v_size) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("sample (wrapper)", 0); - assert(__pyx_arg_n); { - __pyx_v_n = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_n); if (unlikely((__pyx_v_n == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.Hypergraph.sample", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_16sample(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((unsigned int)__pyx_v_n)); + __Pyx_RefNannySetupContext("kbest_features (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_16kbest_features(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_size)); __Pyx_RefNannyFinishContext(); return __pyx_r; } @@ -3379,20 +3802,20 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_17sample(PyObject *__pyx_v_self, P /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 * del derivations * - * def sample(self, unsigned n): # <<<<<<<<<<<<<< - * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() - * if self.rng == NULL: + * def kbest_features(self, size): # <<<<<<<<<<<<<< + * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) + * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal].Derivation* derivation */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_16sample(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, unsigned int __pyx_v_n) { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_10Hypergraph_16kbest_features(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_size) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("sample", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *)__pyx_ptype_5_cdec___pyx_scope_struct_4_sample->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_4_sample, __pyx_empty_tuple, NULL); + __Pyx_RefNannySetupContext("kbest_features", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)__pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -3401,7 +3824,9 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_16sample(struct __pyx_obj_5_cdec_H __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_cur_scope->__pyx_v_n = __pyx_v_n; + __pyx_cur_scope->__pyx_v_size = __pyx_v_size; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); { __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_18generator4, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); @@ -3412,7 +3837,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_16sample(struct __pyx_obj_5_cdec_H __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Hypergraph.sample", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Hypergraph.kbest_features", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); @@ -3423,13 +3848,12 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_16sample(struct __pyx_obj_5_cdec_H static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *)__pyx_generator->closure); + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)__pyx_generator->closure); PyObject *__pyx_r = NULL; - int __pyx_t_1; - size_t __pyx_t_2; - unsigned int __pyx_t_3; + unsigned int __pyx_t_1; + long __pyx_t_2; + int __pyx_t_3; PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { @@ -3444,99 +3868,298 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":57 * - * def sample(self, unsigned n): - * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() # <<<<<<<<<<<<<< - * if self.rng == NULL: - * self.rng = new MT19937() - */ - __pyx_cur_scope->__pyx_v_hypos = new std::vector(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":58 - * def sample(self, unsigned n): - * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() - * if self.rng == NULL: # <<<<<<<<<<<<<< - * self.rng = new MT19937() - * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) + * def kbest_features(self, size): + * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) # <<<<<<<<<<<<<< + * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal].Derivation* derivation + * cdef SparseVector fmap */ - __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->rng == NULL); - if (__pyx_t_1) { + __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,FeatureVectorTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":59 - * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() - * if self.rng == NULL: - * self.rng = new MT19937() # <<<<<<<<<<<<<< - * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) - * cdef str sentence + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":61 + * cdef SparseVector fmap + * cdef unsigned k + * for k in range(size): # <<<<<<<<<<<<<< + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break */ - __pyx_cur_scope->__pyx_v_self->rng = new MT19937(); - goto __pyx_L4; - } - __pyx_L4:; + __pyx_t_2 = __Pyx_PyInt_AsLong(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { + __pyx_cur_scope->__pyx_v_k = __pyx_t_1; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":60 - * if self.rng == NULL: - * self.rng = new MT19937() - * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) # <<<<<<<<<<<<<< - * cdef str sentence + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":62 * cdef unsigned k + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< + * if not derivation: break + * fmap = SparseVector() */ - HypergraphSampler::sample_hypotheses((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_cur_scope->__pyx_v_n, __pyx_cur_scope->__pyx_v_self->rng, __pyx_cur_scope->__pyx_v_hypos); + __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":63 - * cdef str sentence - * cdef unsigned k - * for k in range(hypos.size()): # <<<<<<<<<<<<<< - * sentence = GetString(hypos[0][k].words).c_str() - * yield sentence.decode('utf8') + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":63 + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break # <<<<<<<<<<<<<< + * fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) */ - __pyx_t_2 = __pyx_cur_scope->__pyx_v_hypos->size(); - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_cur_scope->__pyx_v_k = __pyx_t_3; + __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0)); + if (__pyx_t_3) { + goto __pyx_L5_break; + goto __pyx_L6; + } + __pyx_L6:; /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":64 - * cdef unsigned k - * for k in range(hypos.size()): - * sentence = GetString(hypos[0][k].words).c_str() # <<<<<<<<<<<<<< - * yield sentence.decode('utf8') - * del hypos + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break + * fmap = SparseVector() # <<<<<<<<<<<<<< + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) + * yield fmap */ - __pyx_t_4 = PyBytes_FromString(TD::GetString(((__pyx_cur_scope->__pyx_v_hypos[0])[__pyx_cur_scope->__pyx_v_k]).words).c_str()); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_4)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_4))->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); - __pyx_cur_scope->__pyx_v_sentence = ((PyObject*)__pyx_t_4); + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_cur_scope->__pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_4); __pyx_t_4 = 0; /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":65 - * for k in range(hypos.size()): - * sentence = GetString(hypos[0][k].words).c_str() - * yield sentence.decode('utf8') # <<<<<<<<<<<<<< - * del hypos + * if not derivation: break + * fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) # <<<<<<<<<<<<<< + * yield fmap + * del derivations + */ + __pyx_cur_scope->__pyx_v_fmap->vector = new FastSparseVector(__pyx_cur_scope->__pyx_v_derivation->yield); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":66 + * fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) + * yield fmap # <<<<<<<<<<<<<< + * del derivations * */ - __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_sentence), __pyx_n_s__decode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); + __pyx_r = ((PyObject *)__pyx_cur_scope->__pyx_v_fmap); + __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_L7_resume_from_yield:; - __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L5_break:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":67 + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) + * yield fmap + * del derivations # <<<<<<<<<<<<<< + * + * def sample(self, unsigned n): + */ + delete __pyx_cur_scope->__pyx_v_derivations; + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("kbest_features", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} +static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_20sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_20sample(PyObject *__pyx_v_self, PyObject *__pyx_arg_n) { + unsigned int __pyx_v_n; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("sample (wrapper)", 0); + assert(__pyx_arg_n); { + __pyx_v_n = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_n); if (unlikely((__pyx_v_n == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.Hypergraph.sample", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_19sample(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((unsigned int)__pyx_v_n)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":69 + * del derivations + * + * def sample(self, unsigned n): # <<<<<<<<<<<<<< + * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() + * if self.rng == NULL: + */ + +static PyObject *__pyx_pf_5_cdec_10Hypergraph_19sample(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, unsigned int __pyx_v_n) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("sample", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)__pyx_ptype_5_cdec___pyx_scope_struct_5_sample->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_5_sample, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __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_cur_scope->__pyx_v_n = __pyx_v_n; + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_21generator5, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Hypergraph.sample", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + int __pyx_t_1; + size_t __pyx_t_2; + unsigned int __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L7_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_RefNannyFinishContext(); + return NULL; + } + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":70 + * + * def sample(self, unsigned n): + * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() # <<<<<<<<<<<<<< + * if self.rng == NULL: + * self.rng = new MT19937() + */ + __pyx_cur_scope->__pyx_v_hypos = new std::vector(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":71 + * def sample(self, unsigned n): + * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() + * if self.rng == NULL: # <<<<<<<<<<<<<< + * self.rng = new MT19937() + * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) + */ + __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->rng == NULL); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":72 + * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() + * if self.rng == NULL: + * self.rng = new MT19937() # <<<<<<<<<<<<<< + * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) + * cdef str sentence + */ + __pyx_cur_scope->__pyx_v_self->rng = new MT19937(); + goto __pyx_L4; + } + __pyx_L4:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":73 + * if self.rng == NULL: + * self.rng = new MT19937() + * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) # <<<<<<<<<<<<<< + * cdef str sentence + * cdef unsigned k + */ + HypergraphSampler::sample_hypotheses((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_cur_scope->__pyx_v_n, __pyx_cur_scope->__pyx_v_self->rng, __pyx_cur_scope->__pyx_v_hypos); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":76 + * cdef str sentence + * cdef unsigned k + * for k in range(hypos.size()): # <<<<<<<<<<<<<< + * sentence = GetString(hypos[0][k].words).c_str() + * yield sentence.decode('utf8') + */ + __pyx_t_2 = __pyx_cur_scope->__pyx_v_hypos->size(); + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_cur_scope->__pyx_v_k = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":77 + * cdef unsigned k + * for k in range(hypos.size()): + * sentence = GetString(hypos[0][k].words).c_str() # <<<<<<<<<<<<<< + * yield sentence.decode('utf8') + * del hypos + */ + __pyx_t_4 = PyBytes_FromString(TD::GetString(((__pyx_cur_scope->__pyx_v_hypos[0])[__pyx_cur_scope->__pyx_v_k]).words).c_str()); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_4)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_4))->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __pyx_cur_scope->__pyx_v_sentence = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":78 + * for k in range(hypos.size()): + * sentence = GetString(hypos[0][k].words).c_str() + * yield sentence.decode('utf8') # <<<<<<<<<<<<<< + * del hypos + * + */ + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_sentence), __pyx_n_s__decode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L7_resume_from_yield:; + __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":66 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":79 * sentence = GetString(hypos[0][k].words).c_str() * yield sentence.decode('utf8') * del hypos # <<<<<<<<<<<<<< @@ -3558,13 +4181,13 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_20intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_20intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_23intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_23intersect(PyObject *__pyx_v_self, PyObject *__pyx_v_lat) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("intersect (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lat), __pyx_ptype_5_cdec_Lattice, 1, "lat", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_19intersect(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_lat)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lat), __pyx_ptype_5_cdec_Lattice, 1, "lat", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_22intersect(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_lat)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -3573,7 +4196,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_20intersect(PyObject *__pyx_v_self return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":70 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":83 * # TODO richer k-best/sample output (feature vectors, trees?) * * def intersect(self, Lattice lat): # <<<<<<<<<<<<<< @@ -3581,7 +4204,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_20intersect(PyObject *__pyx_v_self * */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_19intersect(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, struct __pyx_obj_5_cdec_Lattice *__pyx_v_lat) { +static PyObject *__pyx_pf_5_cdec_10Hypergraph_22intersect(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, struct __pyx_obj_5_cdec_Lattice *__pyx_v_lat) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -3590,7 +4213,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_19intersect(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("intersect", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":71 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":84 * * def intersect(self, Lattice lat): * return hypergraph.Intersect(lat.lattice[0], self.hg) # <<<<<<<<<<<<<< @@ -3598,7 +4221,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_19intersect(struct __pyx_obj_5_cde * def prune(self, beam_alpha=0, density=0, **kwargs): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(HG::Intersect((__pyx_v_lat->lattice[0]), __pyx_v_self->hg)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyBool_FromLong(HG::Intersect((__pyx_v_lat->lattice[0]), __pyx_v_self->hg)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -3617,8 +4240,8 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_19intersect(struct __pyx_obj_5_cde } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_22prune(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_22prune(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_25prune(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_25prune(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_beam_alpha = 0; PyObject *__pyx_v_density = 0; PyObject *__pyx_v_kwargs = 0; @@ -3655,7 +4278,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_22prune(PyObject *__pyx_v_self, Py } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "prune") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "prune") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -3670,20 +4293,20 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_22prune(PyObject *__pyx_v_self, Py } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("prune", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("prune", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; __Pyx_AddTraceback("_cdec.Hypergraph.prune", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_21prune(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), __pyx_v_beam_alpha, __pyx_v_density, __pyx_v_kwargs); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_24prune(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), __pyx_v_beam_alpha, __pyx_v_density, __pyx_v_kwargs); __Pyx_XDECREF(__pyx_v_kwargs); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":73 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":86 * return hypergraph.Intersect(lat.lattice[0], self.hg) * * def prune(self, beam_alpha=0, density=0, **kwargs): # <<<<<<<<<<<<<< @@ -3691,7 +4314,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_22prune(PyObject *__pyx_v_self, Py * if 'csplit_preserve_full_word' in kwargs: */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_21prune(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_beam_alpha, PyObject *__pyx_v_density, PyObject *__pyx_v_kwargs) { +static PyObject *__pyx_pf_5_cdec_10Hypergraph_24prune(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_beam_alpha, PyObject *__pyx_v_density, PyObject *__pyx_v_kwargs) { std::vector *__pyx_v_preserve_mask; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -3703,7 +4326,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_21prune(struct __pyx_obj_5_cdec_Hy int __pyx_clineno = 0; __Pyx_RefNannySetupContext("prune", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":74 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":87 * * def prune(self, beam_alpha=0, density=0, **kwargs): * cdef hypergraph.EdgeMask* preserve_mask = NULL # <<<<<<<<<<<<<< @@ -3712,17 +4335,17 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_21prune(struct __pyx_obj_5_cdec_Hy */ __pyx_v_preserve_mask = NULL; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":75 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":88 * def prune(self, beam_alpha=0, density=0, **kwargs): * cdef hypergraph.EdgeMask* preserve_mask = NULL * if 'csplit_preserve_full_word' in kwargs: # <<<<<<<<<<<<<< * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True */ - __pyx_t_1 = ((PyDict_Contains(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s_10)))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = ((PyDict_Contains(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s_10)))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":76 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":89 * cdef hypergraph.EdgeMask* preserve_mask = NULL * if 'csplit_preserve_full_word' in kwargs: * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) # <<<<<<<<<<<<<< @@ -3731,7 +4354,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_21prune(struct __pyx_obj_5_cdec_Hy */ __pyx_v_preserve_mask = new std::vector(__pyx_v_self->hg->edges_.size()); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":77 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":90 * if 'csplit_preserve_full_word' in kwargs: * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True # <<<<<<<<<<<<<< @@ -3743,15 +4366,15 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_21prune(struct __pyx_obj_5_cdec_Hy } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":78 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":91 * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) # <<<<<<<<<<<<<< * * def lattice(self): # TODO direct hg -> lattice conversion in cdec */ - __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_beam_alpha); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_density); if (unlikely((__pyx_t_3 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_beam_alpha); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_density); if (unlikely((__pyx_t_3 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_self->hg->PruneInsideOutside(__pyx_t_2, __pyx_t_3, __pyx_v_preserve_mask, 0, 1.0, 0); __pyx_r = Py_None; __Pyx_INCREF(Py_None); @@ -3766,17 +4389,17 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_21prune(struct __pyx_obj_5_cdec_Hy } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_24lattice(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_24lattice(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_27lattice(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_27lattice(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("lattice (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_23lattice(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_26lattice(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":80 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":93 * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) * * def lattice(self): # TODO direct hg -> lattice conversion in cdec # <<<<<<<<<<<<<< @@ -3784,7 +4407,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_24lattice(PyObject *__pyx_v_self, * return Lattice(eval(plf)) */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_23lattice(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_10Hypergraph_26lattice(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self) { PyObject *__pyx_v_plf = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -3796,20 +4419,20 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_23lattice(struct __pyx_obj_5_cdec_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("lattice", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":81 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":94 * * def lattice(self): # TODO direct hg -> lattice conversion in cdec * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() # <<<<<<<<<<<<<< * return Lattice(eval(plf)) * */ - __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->hg[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->hg[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_1)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_1))->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_1)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_1))->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_plf = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":82 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":95 * def lattice(self): # TODO direct hg -> lattice conversion in cdec * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() * return Lattice(eval(plf)) # <<<<<<<<<<<<<< @@ -3817,17 +4440,17 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_23lattice(struct __pyx_obj_5_cdec_ * def reweight(self, weights): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_Globals(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_Globals(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); if (((PyObject *)__pyx_v_plf)) { - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__plf), ((PyObject *)__pyx_v_plf)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__plf), ((PyObject *)__pyx_v_plf)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } if (((PyObject *)__pyx_v_self)) { - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_v_self)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_v_self)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)__pyx_v_plf)); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_plf)); @@ -3838,15 +4461,15 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_23lattice(struct __pyx_obj_5_cdec_ __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); __pyx_t_1 = 0; __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_eval, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_builtin_eval, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; @@ -3869,17 +4492,17 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_23lattice(struct __pyx_obj_5_cdec_ } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_26reweight(PyObject *__pyx_v_self, PyObject *__pyx_v_weights); /*proto*/ -static PyObject *__pyx_pw_5_cdec_10Hypergraph_26reweight(PyObject *__pyx_v_self, PyObject *__pyx_v_weights) { +static PyObject *__pyx_pw_5_cdec_10Hypergraph_29reweight(PyObject *__pyx_v_self, PyObject *__pyx_v_weights); /*proto*/ +static PyObject *__pyx_pw_5_cdec_10Hypergraph_29reweight(PyObject *__pyx_v_self, PyObject *__pyx_v_weights) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("reweight (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_10Hypergraph_25reweight(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_weights)); + __pyx_r = __pyx_pf_5_cdec_10Hypergraph_28reweight(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((PyObject *)__pyx_v_weights)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":84 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":97 * return Lattice(eval(plf)) * * def reweight(self, weights): # <<<<<<<<<<<<<< @@ -3887,7 +4510,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_26reweight(PyObject *__pyx_v_self, * self.hg.Reweight(( weights).vector[0]) */ -static PyObject *__pyx_pf_5_cdec_10Hypergraph_25reweight(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_weights) { +static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self, PyObject *__pyx_v_weights) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -3898,7 +4521,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_25reweight(struct __pyx_obj_5_cdec int __pyx_clineno = 0; __Pyx_RefNannySetupContext("reweight", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":85 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":98 * * def reweight(self, weights): * if isinstance(weights, SparseVector): # <<<<<<<<<<<<<< @@ -3911,7 +4534,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_25reweight(struct __pyx_obj_5_cdec __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":86 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":99 * def reweight(self, weights): * if isinstance(weights, SparseVector): * self.hg.Reweight(( weights).vector[0]) # <<<<<<<<<<<<<< @@ -3922,7 +4545,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_25reweight(struct __pyx_obj_5_cdec goto __pyx_L3; } - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":87 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":100 * if isinstance(weights, SparseVector): * self.hg.Reweight(( weights).vector[0]) * elif isinstance(weights, DenseVector): # <<<<<<<<<<<<<< @@ -3935,38 +4558,38 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_25reweight(struct __pyx_obj_5_cdec __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":88 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":101 * self.hg.Reweight(( weights).vector[0]) * elif isinstance(weights, DenseVector): * self.hg.Reweight(( weights).vector[0]) # <<<<<<<<<<<<<< * else: - * raise ValueError('cannot reweight hypergraph with %s' % type(weights)) + * raise TypeError('cannot reweight hypergraph with %s' % type(weights)) */ __pyx_v_self->hg->Reweight((((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_weights)->vector[0])); goto __pyx_L3; } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":90 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":103 * self.hg.Reweight(( weights).vector[0]) * else: - * raise ValueError('cannot reweight hypergraph with %s' % type(weights)) # <<<<<<<<<<<<<< + * raise TypeError('cannot reweight hypergraph with %s' % type(weights)) # <<<<<<<<<<<<<< * * # TODO get feature expectations, get partition function ("inside" score) */ - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L3:; @@ -4787,7 +5410,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_8__str__(struct __pyx_obj_5_cdec_Latti __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_7Lattice_12generator5(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5_cdec_7Lattice_12generator6(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ static PyObject *__pyx_pw_5_cdec_7Lattice_11__iter__(PyObject *__pyx_v_self); /*proto*/ @@ -4809,14 +5432,14 @@ static PyObject *__pyx_pw_5_cdec_7Lattice_11__iter__(PyObject *__pyx_v_self) { */ static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lattice *__pyx_v_self) { - struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *__pyx_cur_scope; + struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__iter__", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_5___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_5___iter__, __pyx_empty_tuple, NULL); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_6___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_6___iter__, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -4826,7 +5449,7 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lat __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Lattice_12generator5, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_7Lattice_12generator6, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -4844,9 +5467,9 @@ static PyObject *__pyx_pf_5_cdec_7Lattice_10__iter__(struct __pyx_obj_5_cdec_Lat return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_7Lattice_12generator5(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_7Lattice_12generator6(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *)__pyx_generator->closure); + struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; Py_ssize_t __pyx_t_1; unsigned int __pyx_t_2; @@ -4939,839 +5562,496 @@ static void __pyx_pf_5_cdec_7Lattice_13__dealloc__(CYTHON_UNUSED struct __pyx_ob __Pyx_RefNannyFinishContext(); } -/* Python wrapper */ -static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - char *__pyx_v_config; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__config,0}; - int __pyx_r; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); - { - PyObject* values[1] = {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 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__config); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { - goto __pyx_L5_argtuple_error; - } else { - values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - } - __pyx_v_config = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_config) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.Decoder.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return -1; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_7Decoder___cinit__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_config); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "_cdec.pyx":19 - * cdef public DenseVector weights +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":3 + * cimport mteval * - * def __cinit__(self, char* config): # <<<<<<<<<<<<<< - * decoder.register_feature_functions() - * cdef istringstream* config_stream = new istringstream(config) + * cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): # <<<<<<<<<<<<<< + * cdef bytes ret + * if isinstance(sentence, unicode): */ -static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, char *__pyx_v_config) { - std::istringstream *__pyx_v_config_stream; - int __pyx_r; +static char *__pyx_f_5_cdec_as_str(PyObject *__pyx_v_sentence, struct __pyx_opt_args_5_cdec_as_str *__pyx_optional_args) { + PyObject *__pyx_v_error_msg = ((PyObject *)__pyx_kp_s_19); + PyObject *__pyx_v_ret = 0; + char *__pyx_r; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + char *__pyx_t_4; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__cinit__", 0); + __Pyx_RefNannySetupContext("as_str", 0); + if (__pyx_optional_args) { + if (__pyx_optional_args->__pyx_n > 0) { + __pyx_v_error_msg = __pyx_optional_args->error_msg; + } + } - /* "_cdec.pyx":20 - * - * def __cinit__(self, char* config): - * decoder.register_feature_functions() # <<<<<<<<<<<<<< - * cdef istringstream* config_stream = new istringstream(config) - * self.dec = new decoder.Decoder(config_stream) + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":5 + * cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): + * cdef bytes ret + * if isinstance(sentence, unicode): # <<<<<<<<<<<<<< + * ret = sentence.encode('utf8') + * elif isinstance(sentence, str): */ - register_feature_functions(); - - /* "_cdec.pyx":21 - * def __cinit__(self, char* config): - * decoder.register_feature_functions() - * cdef istringstream* config_stream = new istringstream(config) # <<<<<<<<<<<<<< - * self.dec = new decoder.Decoder(config_stream) - * del config_stream + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":6 + * cdef bytes ret + * if isinstance(sentence, unicode): + * ret = sentence.encode('utf8') # <<<<<<<<<<<<<< + * elif isinstance(sentence, str): + * ret = sentence */ - __pyx_v_config_stream = new std::istringstream(__pyx_v_config); + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!(likely(PyBytes_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_t_3)->tp_name), 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_ret = ((PyObject*)__pyx_t_3); + __pyx_t_3 = 0; + goto __pyx_L3; + } - /* "_cdec.pyx":22 - * decoder.register_feature_functions() - * cdef istringstream* config_stream = new istringstream(config) - * self.dec = new decoder.Decoder(config_stream) # <<<<<<<<<<<<<< - * del config_stream - * self.weights = DenseVector() + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":7 + * if isinstance(sentence, unicode): + * ret = sentence.encode('utf8') + * elif isinstance(sentence, str): # <<<<<<<<<<<<<< + * ret = sentence + * else: */ - __pyx_v_self->dec = new Decoder(__pyx_v_config_stream); + __pyx_t_3 = ((PyObject *)((PyObject*)(&PyString_Type))); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_2) { - /* "_cdec.pyx":23 - * cdef istringstream* config_stream = new istringstream(config) - * self.dec = new decoder.Decoder(config_stream) - * del config_stream # <<<<<<<<<<<<<< - * self.weights = DenseVector() - * self.weights.vector = &self.dec.CurrentWeightVector() + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":8 + * ret = sentence.encode('utf8') + * elif isinstance(sentence, str): + * ret = sentence # <<<<<<<<<<<<<< + * else: + * raise TypeError(error_msg % type(sentence)) */ - delete __pyx_v_config_stream; + if (!(likely(PyBytes_CheckExact(__pyx_v_sentence))||((__pyx_v_sentence) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected bytes, got %.200s", Py_TYPE(__pyx_v_sentence)->tp_name), 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 8; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_sentence); + __pyx_v_ret = ((PyObject*)__pyx_v_sentence); + goto __pyx_L3; + } + /*else*/ { - /* "_cdec.pyx":24 - * self.dec = new decoder.Decoder(config_stream) - * del config_stream - * self.weights = DenseVector() # <<<<<<<<<<<<<< - * self.weights.vector = &self.dec.CurrentWeightVector() + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":10 + * ret = sentence + * else: + * raise TypeError(error_msg % type(sentence)) # <<<<<<<<<<<<<< + * return ret * */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_v_self->weights); - __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); - __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)__pyx_t_1); - __pyx_t_1 = 0; + __pyx_t_3 = PyNumber_Remainder(__pyx_v_error_msg, ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + {__pyx_filename = __pyx_f[4]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; - /* "_cdec.pyx":25 - * del config_stream - * self.weights = DenseVector() - * self.weights.vector = &self.dec.CurrentWeightVector() # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":11 + * else: + * raise TypeError(error_msg % type(sentence)) + * return ret # <<<<<<<<<<<<<< * - * def __dealloc__(self): + * cdef class Candidate: */ - __pyx_v_self->weights->vector = (&__pyx_v_self->dec->CurrentWeightVector()); + __pyx_t_4 = PyBytes_AsString(((PyObject *)__pyx_v_ret)); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 11; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_t_4; + goto __pyx_L0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.Decoder.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_WriteUnraisable("_cdec.as_str", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; __pyx_L0:; + __Pyx_XDECREF(__pyx_v_ret); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_9Candidate_5words_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9Candidate_5words_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_7Decoder_2__dealloc__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9Candidate_5words___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); + return __pyx_r; } -/* "_cdec.pyx":27 - * self.weights.vector = &self.dec.CurrentWeightVector() +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":18 * - * def __dealloc__(self): # <<<<<<<<<<<<<< - * del self.dec + * property words: + * def __get__(self): # <<<<<<<<<<<<<< + * return unicode(GetString(self.candidate.ewords).c_str(), encoding='utf8') * */ -static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_9Candidate_5words___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__dealloc__", 0); + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); - /* "_cdec.pyx":28 - * - * def __dealloc__(self): - * del self.dec # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":19 + * property words: + * def __get__(self): + * return unicode(GetString(self.candidate.ewords).c_str(), encoding='utf8') # <<<<<<<<<<<<<< * - * def read_weights(self, cfg): + * property fmap: */ - delete __pyx_v_self->dec; + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(TD::GetString(__pyx_v_self->candidate->ewords).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_t_1)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); + __pyx_t_1 = 0; + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + if (PyDict_SetItem(__pyx_t_1, ((PyObject *)__pyx_n_s__encoding), ((PyObject *)__pyx_n_s__utf8)) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyUnicode_Type))), ((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1)); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + __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_AddTraceback("_cdec.Candidate.words.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); + return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_cfg); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_cfg) { +static PyObject *__pyx_pw_5_cdec_9Candidate_4fmap_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9Candidate_4fmap_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("read_weights (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_4read_weights(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_cfg)); + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9Candidate_4fmap___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":30 - * del self.dec +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":22 * - * def read_weights(self, cfg): # <<<<<<<<<<<<<< - * with open(cfg) as fp: - * for line in fp: + * property fmap: + * def __get__(self): # <<<<<<<<<<<<<< + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) */ -static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_cfg) { - PyObject *__pyx_v_fp = NULL; - PyObject *__pyx_v_line = NULL; - PyObject *__pyx_v_fname = NULL; - PyObject *__pyx_v_value = NULL; +static PyObject *__pyx_pf_5_cdec_9Candidate_4fmap___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { + struct __pyx_obj_5_cdec_SparseVector *__pyx_v_fmap = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; - PyObject *__pyx_t_3 = NULL; - PyObject *__pyx_t_4 = NULL; - PyObject *__pyx_t_5 = NULL; - PyObject *__pyx_t_6 = NULL; - PyObject *__pyx_t_7 = NULL; - Py_ssize_t __pyx_t_8; - PyObject *(*__pyx_t_9)(PyObject *); - PyObject *__pyx_t_10 = NULL; - PyObject *__pyx_t_11 = NULL; - PyObject *(*__pyx_t_12)(PyObject *); - double __pyx_t_13; - int __pyx_t_14; - PyObject *__pyx_t_15 = NULL; - int __pyx_t_16; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("read_weights", 0); + __Pyx_RefNannySetupContext("__get__", 0); - /* "_cdec.pyx":31 - * - * def read_weights(self, cfg): - * with open(cfg) as fp: # <<<<<<<<<<<<<< - * for line in fp: - * fname, value = line.split() + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":23 + * property fmap: + * def __get__(self): + * cdef SparseVector fmap = SparseVector() # <<<<<<<<<<<<<< + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) + * return fmap */ - /*with:*/ { - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_cfg); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_cfg); - __Pyx_GIVEREF(__pyx_v_cfg); - __pyx_t_2 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /*try:*/ { - { - __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); - __Pyx_XGOTREF(__pyx_t_5); - __Pyx_XGOTREF(__pyx_t_6); - __Pyx_XGOTREF(__pyx_t_7); - /*try:*/ { - __Pyx_INCREF(__pyx_t_4); - __pyx_v_fp = __pyx_t_4; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); + __pyx_t_1 = 0; - /* "_cdec.pyx":32 - * def read_weights(self, cfg): - * with open(cfg) as fp: - * for line in fp: # <<<<<<<<<<<<<< - * fname, value = line.split() - * self.weights[fname.strip()] = float(value) + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":24 + * def __get__(self): + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) # <<<<<<<<<<<<<< + * return fmap + * */ - if (PyList_CheckExact(__pyx_v_fp) || PyTuple_CheckExact(__pyx_v_fp)) { - __pyx_t_4 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; - __pyx_t_9 = NULL; - } else { - __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; - } - for (;;) { - if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { - if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; - __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; - } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { - if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; - __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; - } else { - __pyx_t_2 = __pyx_t_9(__pyx_t_4); - if (unlikely(!__pyx_t_2)) { - if (PyErr_Occurred()) { - if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - break; - } - __Pyx_GOTREF(__pyx_t_2); - } - __Pyx_XDECREF(__pyx_v_line); - __pyx_v_line = __pyx_t_2; - __pyx_t_2 = 0; + __pyx_v_fmap->vector = new FastSparseVector(__pyx_v_self->candidate->fmap); - /* "_cdec.pyx":33 - * with open(cfg) as fp: - * for line in fp: - * fname, value = line.split() # <<<<<<<<<<<<<< - * self.weights[fname.strip()] = float(value) + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":25 + * cdef SparseVector fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) + * return fmap # <<<<<<<<<<<<<< * + * cdef class SufficientStats: */ - __pyx_t_2 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { - PyObject* sequence = __pyx_t_1; - if (likely(PyTuple_CheckExact(sequence))) { - if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) { - if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2); - else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); - __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); - } else { - if (unlikely(PyList_GET_SIZE(sequence) != 2)) { - if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2); - else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - } - __pyx_t_2 = PyList_GET_ITEM(sequence, 0); - __pyx_t_10 = PyList_GET_ITEM(sequence, 1); - } - __Pyx_INCREF(__pyx_t_2); - __Pyx_INCREF(__pyx_t_10); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } else { - Py_ssize_t index = -1; - __pyx_t_11 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_11); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; - index = 0; __pyx_t_2 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_2)) goto __pyx_L18_unpacking_failed; - __Pyx_GOTREF(__pyx_t_2); - index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L18_unpacking_failed; - __Pyx_GOTREF(__pyx_t_10); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - goto __pyx_L19_unpacking_done; - __pyx_L18_unpacking_failed:; - __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; - if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); - if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_L19_unpacking_done:; - } - __Pyx_XDECREF(__pyx_v_fname); - __pyx_v_fname = __pyx_t_2; - __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_v_value); - __pyx_v_value = __pyx_t_10; - __pyx_t_10 = 0; - - /* "_cdec.pyx":34 - * for line in fp: - * fname, value = line.split() - * self.weights[fname.strip()] = float(value) # <<<<<<<<<<<<<< - * - * def translate(self, sentence, grammar=None): - */ - __pyx_t_13 = __Pyx_PyObject_AsDouble(__pyx_v_value); if (unlikely(__pyx_t_13 == ((double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __pyx_t_1 = PyFloat_FromDouble(__pyx_t_13); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = PyObject_GetAttr(__pyx_v_fname, __pyx_n_s__strip); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_10); - __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; - if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_t_2, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; - goto __pyx_L14_try_end; - __pyx_L7_error:; - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; - __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - - /* "_cdec.pyx":31 - * - * def read_weights(self, cfg): - * with open(cfg) as fp: # <<<<<<<<<<<<<< - * for line in fp: - * fname, value = line.split() - */ - /*except:*/ { - __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_1, &__pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_GOTREF(__pyx_t_1); - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_10); - __Pyx_INCREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_INCREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_INCREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_2); - __pyx_t_15 = PyObject_Call(__pyx_t_3, __pyx_t_10, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __Pyx_GOTREF(__pyx_t_15); - __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_15); - __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; - if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - __pyx_t_16 = (!__pyx_t_14); - if (__pyx_t_16) { - __Pyx_GIVEREF(__pyx_t_4); - __Pyx_GIVEREF(__pyx_t_1); - __Pyx_GIVEREF(__pyx_t_2); - __Pyx_ErrRestore(__pyx_t_4, __pyx_t_1, __pyx_t_2); - __pyx_t_4 = 0; __pyx_t_1 = 0; __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} - goto __pyx_L22; - } - __pyx_L22:; - __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - goto __pyx_L8_exception_handled; - } - __pyx_L9_except_error:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - goto __pyx_L1_error; - __pyx_L8_exception_handled:; - __Pyx_XGIVEREF(__pyx_t_5); - __Pyx_XGIVEREF(__pyx_t_6); - __Pyx_XGIVEREF(__pyx_t_7); - __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); - __pyx_L14_try_end:; - } - } - /*finally:*/ { - if (__pyx_t_3) { - __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_19, NULL); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_7); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - } - goto __pyx_L23; - __pyx_L3_error:; - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - goto __pyx_L1_error; - __pyx_L23:; - } + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_fmap)); + __pyx_r = ((PyObject *)__pyx_v_fmap); + goto __pyx_L0; __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_4); - __Pyx_XDECREF(__pyx_t_10); - __Pyx_XDECREF(__pyx_t_11); - __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.Candidate.fmap.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_fp); - __Pyx_XDECREF(__pyx_v_line); - __Pyx_XDECREF(__pyx_v_fname); - __Pyx_XDECREF(__pyx_v_value); + __Pyx_XDECREF((PyObject *)__pyx_v_fmap); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - PyObject *__pyx_v_sentence = 0; - PyObject *__pyx_v_grammar = 0; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sentence,&__pyx_n_s__grammar,0}; +static PyObject *__pyx_pw_5_cdec_9Candidate_5score_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_9Candidate_5score_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("translate (wrapper)", 0); - { - PyObject* values[2] = {0,0}; + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9Candidate_5score___get__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":36 - * self.weights[fname.strip()] = float(value) +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":15 + * cdef class Candidate: + * cdef mteval.Candidate* candidate + * cdef public float score # <<<<<<<<<<<<<< * - * def translate(self, sentence, grammar=None): # <<<<<<<<<<<<<< - * if isinstance(sentence, unicode): - * inp = sentence.strip().encode('utf8') + * property words: */ - 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); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sentence); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - if (kw_args > 0) { - PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grammar); - if (value) { values[1] = value; kw_args--; } - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "translate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } else { - switch (PyTuple_GET_SIZE(__pyx_args)) { - case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - break; - default: goto __pyx_L5_argtuple_error; - } - } - __pyx_v_sentence = values[0]; - __pyx_v_grammar = values[1]; - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("translate", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename); + +static PyObject *__pyx_pf_5_cdec_9Candidate_5score___get__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->score); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.Candidate.score.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_7Decoder_6translate(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_sentence, __pyx_v_grammar); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_9Candidate_5score_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_5_cdec_9Candidate_5score_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_9Candidate_5score_2__set__(((struct __pyx_obj_5_cdec_Candidate *)__pyx_v_self), ((PyObject *)__pyx_v_value)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_sentence, PyObject *__pyx_v_grammar) { - PyObject *__pyx_v_inp = NULL; - BasicObserver __pyx_v_observer; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hg = 0; - PyObject *__pyx_r = NULL; +static int __pyx_pf_5_cdec_9Candidate_5score_2__set__(struct __pyx_obj_5_cdec_Candidate *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_t_2; - PyObject *__pyx_t_3 = NULL; - char *__pyx_t_4; + float __pyx_t_1; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("translate", 0); - - /* "_cdec.pyx":37 - * - * def translate(self, sentence, grammar=None): - * if isinstance(sentence, unicode): # <<<<<<<<<<<<<< - * inp = sentence.strip().encode('utf8') - * elif isinstance(sentence, str): - */ - __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { - - /* "_cdec.pyx":38 - * def translate(self, sentence, grammar=None): - * if isinstance(sentence, unicode): - * inp = sentence.strip().encode('utf8') # <<<<<<<<<<<<<< - * elif isinstance(sentence, str): - * inp = sentence.strip() - */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_20), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_v_inp = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3; - } - - /* "_cdec.pyx":39 - * if isinstance(sentence, unicode): - * inp = sentence.strip().encode('utf8') - * elif isinstance(sentence, str): # <<<<<<<<<<<<<< - * inp = sentence.strip() - * elif isinstance(sentence, Lattice): - */ - __pyx_t_3 = ((PyObject *)((PyObject*)(&PyString_Type))); - __Pyx_INCREF(__pyx_t_3); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_3); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - if (__pyx_t_2) { - - /* "_cdec.pyx":40 - * inp = sentence.strip().encode('utf8') - * elif isinstance(sentence, str): - * inp = sentence.strip() # <<<<<<<<<<<<<< - * elif isinstance(sentence, Lattice): - * inp = str(sentence) # PLF format - */ - __pyx_t_3 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_v_inp = __pyx_t_1; - __pyx_t_1 = 0; - goto __pyx_L3; - } + __Pyx_RefNannySetupContext("__set__", 0); + __pyx_t_1 = __pyx_PyFloat_AsFloat(__pyx_v_value); if (unlikely((__pyx_t_1 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->score = __pyx_t_1; - /* "_cdec.pyx":41 - * elif isinstance(sentence, str): - * inp = sentence.strip() - * elif isinstance(sentence, Lattice): # <<<<<<<<<<<<<< - * inp = str(sentence) # PLF format - * else: - */ - __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (__pyx_t_2) { + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Candidate.score.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":42 - * inp = sentence.strip() - * elif isinstance(sentence, Lattice): - * inp = str(sentence) # PLF format # <<<<<<<<<<<<<< - * else: - * raise TypeError('Cannot translate input type %s' % type(sentence)) - */ - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_INCREF(__pyx_v_sentence); - PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_sentence); - __Pyx_GIVEREF(__pyx_v_sentence); - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_v_inp = __pyx_t_3; - __pyx_t_3 = 0; - goto __pyx_L3; - } - /*else*/ { +/* Python wrapper */ +static void __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_15SufficientStats___dealloc__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} - /* "_cdec.pyx":44 - * inp = str(sentence) # PLF format - * else: - * raise TypeError('Cannot translate input type %s' % type(sentence)) # <<<<<<<<<<<<<< - * if grammar: - * self.dec.SetSentenceGrammarFromString(string( grammar)) +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":31 + * cdef mteval.EvaluationMetric* metric + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.stats + * */ - __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_21), ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); - __pyx_t_3 = 0; - __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_Raise(__pyx_t_3, 0, 0, 0); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - __pyx_L3:; - /* "_cdec.pyx":45 - * else: - * raise TypeError('Cannot translate input type %s' % type(sentence)) - * if grammar: # <<<<<<<<<<<<<< - * self.dec.SetSentenceGrammarFromString(string( grammar)) - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - */ - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_grammar); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__pyx_t_2) { +static void __pyx_pf_5_cdec_15SufficientStats___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "_cdec.pyx":46 - * raise TypeError('Cannot translate input type %s' % type(sentence)) - * if grammar: - * self.dec.SetSentenceGrammarFromString(string( grammar)) # <<<<<<<<<<<<<< - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - * self.dec.Decode(string(inp), &observer) + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":32 + * + * def __dealloc__(self): + * del self.stats # <<<<<<<<<<<<<< + * + * property score: */ - __pyx_t_4 = PyBytes_AsString(__pyx_v_grammar); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->dec->SetSentenceGrammarFromString(std::string(((char *)__pyx_t_4))); - goto __pyx_L4; - } - __pyx_L4:; + delete __pyx_v_self->stats; - /* "_cdec.pyx":47 - * if grammar: - * self.dec.SetSentenceGrammarFromString(string( grammar)) - * cdef decoder.BasicObserver observer = decoder.BasicObserver() # <<<<<<<<<<<<<< - * self.dec.Decode(string(inp), &observer) - * if observer.hypergraph == NULL: - */ - __pyx_v_observer = BasicObserver(); + __Pyx_RefNannyFinishContext(); +} - /* "_cdec.pyx":48 - * self.dec.SetSentenceGrammarFromString(string( grammar)) - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - * self.dec.Decode(string(inp), &observer) # <<<<<<<<<<<<<< - * if observer.hypergraph == NULL: - * raise ParseFailed() - */ - __pyx_t_4 = PyBytes_AsString(__pyx_v_inp); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->dec->Decode(std::string(((char *)__pyx_t_4)), (&__pyx_v_observer)); +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_5score_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_5score_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_5score___get__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} - /* "_cdec.pyx":49 - * cdef decoder.BasicObserver observer = decoder.BasicObserver() - * self.dec.Decode(string(inp), &observer) - * if observer.hypergraph == NULL: # <<<<<<<<<<<<<< - * raise ParseFailed() - * cdef Hypergraph hg = Hypergraph() +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":35 + * + * property score: + * def __get__(self): # <<<<<<<<<<<<<< + * return self.metric.ComputeScore(self.stats[0]) + * */ - __pyx_t_2 = (__pyx_v_observer.hypergraph == NULL); - if (__pyx_t_2) { - /* "_cdec.pyx":50 - * self.dec.Decode(string(inp), &observer) - * if observer.hypergraph == NULL: - * raise ParseFailed() # <<<<<<<<<<<<<< - * cdef Hypergraph hg = Hypergraph() - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) - */ - __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__ParseFailed); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __Pyx_Raise(__pyx_t_1, 0, 0, 0); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - goto __pyx_L5; - } - __pyx_L5:; +static PyObject *__pyx_pf_5_cdec_15SufficientStats_5score___get__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__get__", 0); - /* "_cdec.pyx":51 - * if observer.hypergraph == NULL: - * raise ParseFailed() - * cdef Hypergraph hg = Hypergraph() # <<<<<<<<<<<<<< - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) - * return hg + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":36 + * property score: + * def __get__(self): + * return self.metric.ComputeScore(self.stats[0]) # <<<<<<<<<<<<<< + * + * property detail: */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Hypergraph)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->metric->ComputeScore((__pyx_v_self->stats[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_v_hg = ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_t_1); + __pyx_r = __pyx_t_1; __pyx_t_1 = 0; - - /* "_cdec.pyx":52 - * raise ParseFailed() - * cdef Hypergraph hg = Hypergraph() - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) # <<<<<<<<<<<<<< - * return hg - */ - __pyx_v_hg->hg = new Hypergraph((__pyx_v_observer.hypergraph[0])); - - /* "_cdec.pyx":53 - * cdef Hypergraph hg = Hypergraph() - * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) - * return hg # <<<<<<<<<<<<<< - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_hg)); - __pyx_r = ((PyObject *)__pyx_v_hg); goto __pyx_L0; __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_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.SufficientStats.score.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_v_inp); - __Pyx_XDECREF((PyObject *)__pyx_v_hg); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights___get__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_6detail___get__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "_cdec.pyx":17 - * cdef class Decoder: - * cdef decoder.Decoder* dec - * cdef public DenseVector weights # <<<<<<<<<<<<<< +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":39 + * + * property detail: + * def __get__(self): # <<<<<<<<<<<<<< + * return self.metric.DetailedScore(self.stats[0]).c_str() * - * def __cinit__(self, char* config): */ -static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_15SufficientStats_6detail___get__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__get__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":40 + * property detail: + * def __get__(self): + * return self.metric.DetailedScore(self.stats[0]).c_str() # <<<<<<<<<<<<<< + * + * def __len__(self): + */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_self->weights)); - __pyx_r = ((PyObject *)__pyx_v_self->weights); + __pyx_t_1 = PyBytes_FromString(__pyx_v_self->metric->DetailedScore((__pyx_v_self->stats[0])).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_r = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.SufficientStats.detail.__get__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); @@ -5779,101 +6059,3402 @@ static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cd } /* Python wrapper */ -static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ -static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +static Py_ssize_t __pyx_pw_5_cdec_15SufficientStats_3__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_15SufficientStats_3__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_2__set__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_2__len__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_value) { - int __pyx_r; +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":42 + * return self.metric.DetailedScore(self.stats[0]).c_str() + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.stats.size() + * + */ + +static Py_ssize_t __pyx_pf_5_cdec_15SufficientStats_2__len__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":43 + * + * def __len__(self): + * return self.stats.size() # <<<<<<<<<<<<<< + * + * def __iter__(self): + */ + __pyx_r = __pyx_v_self->stats->size(); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator7(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_5__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_5__iter__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_4__iter__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":45 + * return self.stats.size() + * + * def __iter__(self): # <<<<<<<<<<<<<< + * for i in range(len(self)): + * yield self.stats[0][i] + */ + +static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *__pyx_cur_scope; + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("__set__", 0); - if (!(likely(((__pyx_v_value) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_value, __pyx_ptype_5_cdec_DenseVector))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - __Pyx_GOTREF(__pyx_v_self->weights); - __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); - __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_value); + __Pyx_RefNannySetupContext("__iter__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_7___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_7___iter__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __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_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_15SufficientStats_6generator7, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } - __pyx_r = 0; + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.Decoder.weights.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = -1; + __Pyx_AddTraceback("_cdec.SufficientStats.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } +static PyObject *__pyx_gb_5_cdec_15SufficientStats_6generator7(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + Py_ssize_t __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *(*__pyx_t_4)(PyObject *); + unsigned int __pyx_t_5; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_RefNannyFinishContext(); + return NULL; + } + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":46 + * + * def __iter__(self): + * for i in range(len(self)): # <<<<<<<<<<<<<< + * yield self.stats[0][i] + * + */ + __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_builtin_range, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + if (PyList_CheckExact(__pyx_t_2) || PyTuple_CheckExact(__pyx_t_2)) { + __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0; + __pyx_t_4 = NULL; + } else { + __pyx_t_1 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + for (;;) { + if (!__pyx_t_4 && PyList_CheckExact(__pyx_t_3)) { + if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_3)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; + } else if (!__pyx_t_4 && PyTuple_CheckExact(__pyx_t_3)) { + if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_3)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_2); __pyx_t_1++; + } else { + __pyx_t_2 = __pyx_t_4(__pyx_t_3); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_i); + __Pyx_XDECREF(__pyx_cur_scope->__pyx_v_i); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":47 + * def __iter__(self): + * for i in range(len(self)): + * yield self.stats[0][i] # <<<<<<<<<<<<<< + * + * def __iadd__(SufficientStats self, SufficientStats other): + */ + __pyx_t_5 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_i); if (unlikely((__pyx_t_5 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyFloat_FromDouble(((__pyx_cur_scope->__pyx_v_self->stats[0])[__pyx_t_5])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __Pyx_XGIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; + __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; + __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_3 = __pyx_cur_scope->__pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_t_3); + __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} + /* Python wrapper */ -static int __pyx_pw_5_cdec_7Decoder_7weights_5__del__(PyObject *__pyx_v_self); /*proto*/ -static int __pyx_pw_5_cdec_7Decoder_7weights_5__del__(PyObject *__pyx_v_self) { - int __pyx_r; +static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_8__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { + PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_4__del__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannySetupContext("__iadd__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SufficientStats, 1, "other", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_7__iadd__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_other)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_5_cdec_7Decoder_7weights_4__del__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { - int __pyx_r; +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":49 + * yield self.stats[0][i] + * + * def __iadd__(SufficientStats self, SufficientStats other): # <<<<<<<<<<<<<< + * self.stats[0] += other.stats[0] + * return self + */ + +static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__iadd__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_other) { + PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("__del__", 0); - __Pyx_INCREF(Py_None); - __Pyx_GIVEREF(Py_None); - __Pyx_GOTREF(__pyx_v_self->weights); - __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); - __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); + __Pyx_RefNannySetupContext("__iadd__", 0); - __pyx_r = 0; + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":50 + * + * def __iadd__(SufficientStats self, SufficientStats other): + * self.stats[0] += other.stats[0] # <<<<<<<<<<<<<< + * return self + * + */ + (__pyx_v_self->stats[0]) += (__pyx_v_other->stats[0]); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":51 + * def __iadd__(SufficientStats self, SufficientStats other): + * self.stats[0] += other.stats[0] + * return self # <<<<<<<<<<<<<< + * + * def __add__(SufficientStats x, SufficientStats y): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + __pyx_r = ((PyObject *)__pyx_v_self); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_10__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_15SufficientStats_10__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__add__ (wrapper)", 0); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SufficientStats, 1, "x", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SufficientStats, 1, "y", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_15SufficientStats_9__add__(((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_v_y)); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_tp_new_5_cdec_DenseVector(PyTypeObject *t, PyObject *a, PyObject *k) { +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":53 + * return self + * + * def __add__(SufficientStats x, SufficientStats y): # <<<<<<<<<<<<<< + * cdef SufficientStats result = SufficientStats() + * result.stats = new mteval.SufficientStats(mteval.add(x.stats[0], y.stats[0])) + */ + +static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_x, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_y) { + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_result = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__add__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":54 + * + * def __add__(SufficientStats x, SufficientStats y): + * cdef SufficientStats result = SufficientStats() # <<<<<<<<<<<<<< + * result.stats = new mteval.SufficientStats(mteval.add(x.stats[0], y.stats[0])) + * result.metric = x.metric + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 54; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_result = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":55 + * def __add__(SufficientStats x, SufficientStats y): + * cdef SufficientStats result = SufficientStats() + * result.stats = new mteval.SufficientStats(mteval.add(x.stats[0], y.stats[0])) # <<<<<<<<<<<<<< + * result.metric = x.metric + * return result + */ + __pyx_v_result->stats = new SufficientStats(operator+((__pyx_v_x->stats[0]), (__pyx_v_y->stats[0]))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":56 + * cdef SufficientStats result = SufficientStats() + * result.stats = new mteval.SufficientStats(mteval.add(x.stats[0], y.stats[0])) + * result.metric = x.metric # <<<<<<<<<<<<<< + * return result + * + */ + __pyx_v_result->metric = __pyx_v_x->metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":57 + * result.stats = new mteval.SufficientStats(mteval.add(x.stats[0], y.stats[0])) + * result.metric = x.metric + * return result # <<<<<<<<<<<<<< + * + * cdef class SegmentEvaluator: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_result)); + __pyx_r = ((PyObject *)__pyx_v_result); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.SufficientStats.__add__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":63 + * cdef mteval.EvaluationMetric* metric + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.scorer + * + */ + +static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":64 + * + * def __dealloc__(self): + * del self.scorer # <<<<<<<<<<<<<< + * + * def evaluate(self, sentence): + */ + delete __pyx_v_self->scorer; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence); /*proto*/ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("evaluate (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self), ((PyObject *)__pyx_v_sentence)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":66 + * del self.scorer + * + * def evaluate(self, sentence): # <<<<<<<<<<<<<< + * cdef vector[WordID] hyp + * cdef SufficientStats sf = SufficientStats() + */ + +static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, PyObject *__pyx_v_sentence) { + std::vector __pyx_v_hyp; + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sf = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("evaluate", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":68 + * def evaluate(self, sentence): + * cdef vector[WordID] hyp + * cdef SufficientStats sf = SufficientStats() # <<<<<<<<<<<<<< + * sf.metric = self.metric + * sf.stats = new mteval.SufficientStats() + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sf = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":69 + * cdef vector[WordID] hyp + * cdef SufficientStats sf = SufficientStats() + * sf.metric = self.metric # <<<<<<<<<<<<<< + * sf.stats = new mteval.SufficientStats() + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + */ + __pyx_v_sf->metric = __pyx_v_self->metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":70 + * cdef SufficientStats sf = SufficientStats() + * sf.metric = self.metric + * sf.stats = new mteval.SufficientStats() # <<<<<<<<<<<<<< + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + * self.scorer.get().Evaluate(hyp, sf.stats) + */ + __pyx_v_sf->stats = new SufficientStats(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":71 + * sf.metric = self.metric + * sf.stats = new mteval.SufficientStats() + * ConvertSentence(string(as_str(sentence.strip())), &hyp) # <<<<<<<<<<<<<< + * self.scorer.get().Evaluate(hyp, sf.stats) + * return sf + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_2, NULL)), (&__pyx_v_hyp)); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":72 + * sf.stats = new mteval.SufficientStats() + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + * self.scorer.get().Evaluate(hyp, sf.stats) # <<<<<<<<<<<<<< + * return sf + * + */ + __pyx_v_self->scorer->get()->Evaluate(__pyx_v_hyp, __pyx_v_sf->stats); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":73 + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + * self.scorer.get().Evaluate(hyp, sf.stats) + * return sf # <<<<<<<<<<<<<< + * + * def candidate_set(self, Hypergraph hypergraph, unsigned k): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_sf)); + __pyx_r = ((PyObject *)__pyx_v_sf); + goto __pyx_L0; + + __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_AddTraceback("_cdec.SegmentEvaluator.evaluate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_sf); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_5_cdec_16SegmentEvaluator_6generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph = 0; + unsigned int __pyx_v_k; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__hypergraph,&__pyx_n_s__k,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("candidate_set (wrapper)", 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); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__hypergraph); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("candidate_set", 1, 2, 2, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "candidate_set") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __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_hypergraph = ((struct __pyx_obj_5_cdec_Hypergraph *)values[0]); + __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("candidate_set", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.SegmentEvaluator.candidate_set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_hypergraph), __pyx_ptype_5_cdec_Hypergraph, 1, "hypergraph", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self), __pyx_v_hypergraph, __pyx_v_k); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":75 + * return sf + * + * def candidate_set(self, Hypergraph hypergraph, unsigned k): # <<<<<<<<<<<<<< + * cdef mteval.CandidateSet* cs = new mteval.CandidateSet() + * cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) + */ + +static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph, unsigned int __pyx_v_k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("candidate_set", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)__pyx_ptype_5_cdec___pyx_scope_struct_8_candidate_set->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_8_candidate_set, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __Pyx_RefNannyFinishContext(); + return NULL; + } + __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_cur_scope->__pyx_v_hypergraph = __pyx_v_hypergraph; + __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_hypergraph); + __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_hypergraph); + __pyx_cur_scope->__pyx_v_k = __pyx_v_k; + { + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_16SegmentEvaluator_6generator8, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.SegmentEvaluator.candidate_set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_5_cdec_16SegmentEvaluator_6generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + unsigned int __pyx_t_1; + unsigned int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("None", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L6_resume_from_yield; + default: /* CPython raises the right error here */ + __Pyx_RefNannyFinishContext(); + return NULL; + } + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":76 + * + * def candidate_set(self, Hypergraph hypergraph, unsigned k): + * cdef mteval.CandidateSet* cs = new mteval.CandidateSet() # <<<<<<<<<<<<<< + * cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) + * cdef Candidate candidate + */ + __pyx_cur_scope->__pyx_v_cs = new training::CandidateSet(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":77 + * def candidate_set(self, Hypergraph hypergraph, unsigned k): + * cdef mteval.CandidateSet* cs = new mteval.CandidateSet() + * cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) # <<<<<<<<<<<<<< + * cdef Candidate candidate + * cdef unsigned i + */ + __pyx_cur_scope->__pyx_v_cs->AddKBestCandidates((__pyx_cur_scope->__pyx_v_hypergraph->hg[0]), __pyx_cur_scope->__pyx_v_k, __pyx_cur_scope->__pyx_v_self->scorer->get()); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":80 + * cdef Candidate candidate + * cdef unsigned i + * for i in range(cs.size()): # <<<<<<<<<<<<<< + * candidate = Candidate() + * candidate.candidate = &cs[0][i] + */ + __pyx_t_1 = __pyx_cur_scope->__pyx_v_cs->size(); + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":81 + * cdef unsigned i + * for i in range(cs.size()): + * candidate = Candidate() # <<<<<<<<<<<<<< + * candidate.candidate = &cs[0][i] + * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) + */ + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Candidate)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_candidate)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_candidate)); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_candidate = ((struct __pyx_obj_5_cdec_Candidate *)__pyx_t_3); + __pyx_t_3 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 + * for i in range(cs.size()): + * candidate = Candidate() + * candidate.candidate = &cs[0][i] # <<<<<<<<<<<<<< + * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) + * yield candidate + */ + __pyx_cur_scope->__pyx_v_candidate->candidate = (&((__pyx_cur_scope->__pyx_v_cs[0])[__pyx_cur_scope->__pyx_v_i])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":83 + * candidate = Candidate() + * candidate.candidate = &cs[0][i] + * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) # <<<<<<<<<<<<<< + * yield candidate + * del cs + */ + __pyx_cur_scope->__pyx_v_candidate->score = __pyx_cur_scope->__pyx_v_self->metric->ComputeScore(((__pyx_cur_scope->__pyx_v_cs[0])[__pyx_cur_scope->__pyx_v_i]).eval_feats); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":84 + * candidate.candidate = &cs[0][i] + * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) + * yield candidate # <<<<<<<<<<<<<< + * del cs + * + */ + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_candidate)); + __pyx_r = ((PyObject *)__pyx_cur_scope->__pyx_v_candidate); + __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_filename = __pyx_f[4]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":85 + * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) + * yield candidate + * del cs # <<<<<<<<<<<<<< + * + * cdef class Scorer: + */ + delete __pyx_cur_scope->__pyx_v_cs; + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("candidate_set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + char *__pyx_v_name; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__name,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[1] = {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 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__name); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + } + __pyx_v_name = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.Scorer.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_6Scorer___cinit__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self), __pyx_v_name); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":90 + * cdef string* name + * + * def __cinit__(self, char* name): # <<<<<<<<<<<<<< + * self.name = new string(name) + * + */ + +static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, char *__pyx_v_name) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":91 + * + * def __cinit__(self, char* name): + * self.name = new string(name) # <<<<<<<<<<<<<< + * + * def __call__(self, refs): + */ + __pyx_v_self->name = new std::string(__pyx_v_name); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_6Scorer_3__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_6Scorer_3__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_refs = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__refs,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__call__ (wrapper)", 0); + { + PyObject* values[1] = {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 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__refs); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + } + __pyx_v_refs = values[0]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.Scorer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_6Scorer_2__call__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self), __pyx_v_refs); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":93 + * self.name = new string(name) + * + * def __call__(self, refs): # <<<<<<<<<<<<<< + * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) + * if isinstance(refs, unicode) or isinstance(refs, str): + */ + +static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs) { + EvaluationMetric *__pyx_v_metric; + std::vector > *__pyx_v_refsv; + std::vector *__pyx_v_refv; + PyObject *__pyx_v_ref = NULL; + struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + int __pyx_t_3; + int __pyx_t_4; + Py_ssize_t __pyx_t_5; + PyObject *(*__pyx_t_6)(PyObject *); + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__call__", 0); + __Pyx_INCREF(__pyx_v_refs); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":94 + * + * def __call__(self, refs): + * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) # <<<<<<<<<<<<<< + * if isinstance(refs, unicode) or isinstance(refs, str): + * refs = [refs] + */ + __pyx_v_metric = EvaluationMetric::Instance((__pyx_v_self->name[0])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":95 + * def __call__(self, refs): + * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) + * if isinstance(refs, unicode) or isinstance(refs, str): # <<<<<<<<<<<<<< + * refs = [refs] + * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_refs, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (!__pyx_t_2) { + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyString_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_3 = __Pyx_TypeCheck(__pyx_v_refs, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_4 = __pyx_t_3; + } else { + __pyx_t_4 = __pyx_t_2; + } + if (__pyx_t_4) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":96 + * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) + * if isinstance(refs, unicode) or isinstance(refs, str): + * refs = [refs] # <<<<<<<<<<<<<< + * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() + * cdef vector[WordID]* refv + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_refs); + PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_refs); + __Pyx_GIVEREF(__pyx_v_refs); + __Pyx_DECREF(__pyx_v_refs); + __pyx_v_refs = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":97 + * if isinstance(refs, unicode) or isinstance(refs, str): + * refs = [refs] + * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() # <<<<<<<<<<<<<< + * cdef vector[WordID]* refv + * cdef bytes ref_str + */ + __pyx_v_refsv = new std::vector >(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":100 + * cdef vector[WordID]* refv + * cdef bytes ref_str + * for ref in refs: # <<<<<<<<<<<<<< + * refv = new vector[WordID]() + * ConvertSentence(string(as_str(ref.strip())), refv) + */ + if (PyList_CheckExact(__pyx_v_refs) || PyTuple_CheckExact(__pyx_v_refs)) { + __pyx_t_1 = __pyx_v_refs; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0; + __pyx_t_6 = NULL; + } else { + __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_refs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; + } + for (;;) { + if (!__pyx_t_6 && PyList_CheckExact(__pyx_t_1)) { + if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break; + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; + } else if (!__pyx_t_6 && PyTuple_CheckExact(__pyx_t_1)) { + if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_1)) break; + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; + } else { + __pyx_t_7 = __pyx_t_6(__pyx_t_1); + if (unlikely(!__pyx_t_7)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_7); + } + __Pyx_XDECREF(__pyx_v_ref); + __pyx_v_ref = __pyx_t_7; + __pyx_t_7 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":101 + * cdef bytes ref_str + * for ref in refs: + * refv = new vector[WordID]() # <<<<<<<<<<<<<< + * ConvertSentence(string(as_str(ref.strip())), refv) + * refsv.push_back(refv[0]) + */ + __pyx_v_refv = new std::vector(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":102 + * for ref in refs: + * refv = new vector[WordID]() + * ConvertSentence(string(as_str(ref.strip())), refv) # <<<<<<<<<<<<<< + * refsv.push_back(refv[0]) + * del refv + */ + __pyx_t_7 = PyObject_GetAttr(__pyx_v_ref, __pyx_n_s__strip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_8, NULL)), __pyx_v_refv); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":103 + * refv = new vector[WordID]() + * ConvertSentence(string(as_str(ref.strip())), refv) + * refsv.push_back(refv[0]) # <<<<<<<<<<<<<< + * del refv + * cdef unsigned i + */ + __pyx_v_refsv->push_back((__pyx_v_refv[0])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":104 + * ConvertSentence(string(as_str(ref.strip())), refv) + * refsv.push_back(refv[0]) + * del refv # <<<<<<<<<<<<<< + * cdef unsigned i + * cdef SegmentEvaluator evaluator = SegmentEvaluator() + */ + delete __pyx_v_refv; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":106 + * del refv + * cdef unsigned i + * cdef SegmentEvaluator evaluator = SegmentEvaluator() # <<<<<<<<<<<<<< + * evaluator.metric = metric + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SegmentEvaluator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_evaluator = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":107 + * cdef unsigned i + * cdef SegmentEvaluator evaluator = SegmentEvaluator() + * evaluator.metric = metric # <<<<<<<<<<<<<< + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + * del refsv # in theory should not delete but store in SegmentEvaluator + */ + __pyx_v_evaluator->metric = __pyx_v_metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":108 + * cdef SegmentEvaluator evaluator = SegmentEvaluator() + * evaluator.metric = metric + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) # <<<<<<<<<<<<<< + * del refsv # in theory should not delete but store in SegmentEvaluator + * return evaluator + */ + __pyx_v_evaluator->scorer = new boost::shared_ptr(__pyx_v_metric->CreateSegmentEvaluator((__pyx_v_refsv[0]))); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":109 + * evaluator.metric = metric + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + * del refsv # in theory should not delete but store in SegmentEvaluator # <<<<<<<<<<<<<< + * return evaluator + * + */ + delete __pyx_v_refsv; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":110 + * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + * del refsv # in theory should not delete but store in SegmentEvaluator + * return evaluator # <<<<<<<<<<<<<< + * + * def __str__(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_evaluator)); + __pyx_r = ((PyObject *)__pyx_v_evaluator); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_AddTraceback("_cdec.Scorer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_ref); + __Pyx_XDECREF((PyObject *)__pyx_v_evaluator); + __Pyx_XDECREF(__pyx_v_refs); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_6Scorer_5__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_6Scorer_5__str__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_6Scorer_4__str__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":112 + * return evaluator + * + * def __str__(self): # <<<<<<<<<<<<<< + * return self.name.c_str() + * + */ + +static PyObject *__pyx_pf_5_cdec_6Scorer_4__str__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__str__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":113 + * + * def __str__(self): + * return self.name.c_str() # <<<<<<<<<<<<<< + * + * BLEU = Scorer('IBM_BLEU') + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyBytes_FromString(__pyx_v_self->name->c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_1)); + __pyx_r = ((PyObject *)__pyx_t_1); + __pyx_t_1 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.Scorer.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_7Decoder_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + char *__pyx_v_config; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__config,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[1] = {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 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__config); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + } + __pyx_v_config = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_config) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.Decoder.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_7Decoder___cinit__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_config); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":19 + * cdef public DenseVector weights + * + * def __cinit__(self, char* config): # <<<<<<<<<<<<<< + * decoder.register_feature_functions() + * cdef istringstream* config_stream = new istringstream(config) + */ + +static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, char *__pyx_v_config) { + std::istringstream *__pyx_v_config_stream; + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "_cdec.pyx":20 + * + * def __cinit__(self, char* config): + * decoder.register_feature_functions() # <<<<<<<<<<<<<< + * cdef istringstream* config_stream = new istringstream(config) + * self.dec = new decoder.Decoder(config_stream) + */ + register_feature_functions(); + + /* "_cdec.pyx":21 + * def __cinit__(self, char* config): + * decoder.register_feature_functions() + * cdef istringstream* config_stream = new istringstream(config) # <<<<<<<<<<<<<< + * self.dec = new decoder.Decoder(config_stream) + * del config_stream + */ + __pyx_v_config_stream = new std::istringstream(__pyx_v_config); + + /* "_cdec.pyx":22 + * decoder.register_feature_functions() + * cdef istringstream* config_stream = new istringstream(config) + * self.dec = new decoder.Decoder(config_stream) # <<<<<<<<<<<<<< + * del config_stream + * self.weights = DenseVector() + */ + __pyx_v_self->dec = new Decoder(__pyx_v_config_stream); + + /* "_cdec.pyx":23 + * cdef istringstream* config_stream = new istringstream(config) + * self.dec = new decoder.Decoder(config_stream) + * del config_stream # <<<<<<<<<<<<<< + * self.weights = DenseVector() + * self.weights.vector = &self.dec.CurrentWeightVector() + */ + delete __pyx_v_config_stream; + + /* "_cdec.pyx":24 + * self.dec = new decoder.Decoder(config_stream) + * del config_stream + * self.weights = DenseVector() # <<<<<<<<<<<<<< + * self.weights.vector = &self.dec.CurrentWeightVector() + * + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v_self->weights); + __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); + __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "_cdec.pyx":25 + * del config_stream + * self.weights = DenseVector() + * self.weights.vector = &self.dec.CurrentWeightVector() # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->weights->vector = (&__pyx_v_self->dec->CurrentWeightVector()); + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.Decoder.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_7Decoder_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_7Decoder_2__dealloc__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "_cdec.pyx":27 + * self.weights.vector = &self.dec.CurrentWeightVector() + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.dec + * + */ + +static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "_cdec.pyx":28 + * + * def __dealloc__(self): + * del self.dec # <<<<<<<<<<<<<< + * + * def read_weights(self, cfg): + */ + delete __pyx_v_self->dec; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_cfg); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Decoder_5read_weights(PyObject *__pyx_v_self, PyObject *__pyx_v_cfg) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("read_weights (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_4read_weights(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_cfg)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":30 + * del self.dec + * + * def read_weights(self, cfg): # <<<<<<<<<<<<<< + * with open(cfg) as fp: + * for line in fp: + */ + +static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_cfg) { + PyObject *__pyx_v_fp = NULL; + PyObject *__pyx_v_line = NULL; + PyObject *__pyx_v_fname = NULL; + PyObject *__pyx_v_value = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + Py_ssize_t __pyx_t_8; + PyObject *(*__pyx_t_9)(PyObject *); + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *(*__pyx_t_12)(PyObject *); + double __pyx_t_13; + int __pyx_t_14; + PyObject *__pyx_t_15 = NULL; + int __pyx_t_16; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("read_weights", 0); + + /* "_cdec.pyx":31 + * + * def read_weights(self, cfg): + * with open(cfg) as fp: # <<<<<<<<<<<<<< + * for line in fp: + * fname, value = line.split() + */ + /*with:*/ { + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_cfg); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_cfg); + __Pyx_GIVEREF(__pyx_v_cfg); + __pyx_t_2 = PyObject_Call(__pyx_builtin_open, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_t_3 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____exit__); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s____enter__); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + /*try:*/ { + { + __Pyx_ExceptionSave(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + /*try:*/ { + __Pyx_INCREF(__pyx_t_4); + __pyx_v_fp = __pyx_t_4; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_cdec.pyx":32 + * def read_weights(self, cfg): + * with open(cfg) as fp: + * for line in fp: # <<<<<<<<<<<<<< + * fname, value = line.split() + * self.weights[fname.strip()] = float(value) + */ + if (PyList_CheckExact(__pyx_v_fp) || PyTuple_CheckExact(__pyx_v_fp)) { + __pyx_t_4 = __pyx_v_fp; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = 0; + __pyx_t_9 = NULL; + } else { + __pyx_t_8 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_v_fp); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext; + } + for (;;) { + if (!__pyx_t_9 && PyList_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_4)) break; + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else if (!__pyx_t_9 && PyTuple_CheckExact(__pyx_t_4)) { + if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_4)) break; + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; + } else { + __pyx_t_2 = __pyx_t_9(__pyx_t_4); + if (unlikely(!__pyx_t_2)) { + if (PyErr_Occurred()) { + if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); + else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + break; + } + __Pyx_GOTREF(__pyx_t_2); + } + __Pyx_XDECREF(__pyx_v_line); + __pyx_v_line = __pyx_t_2; + __pyx_t_2 = 0; + + /* "_cdec.pyx":33 + * with open(cfg) as fp: + * for line in fp: + * fname, value = line.split() # <<<<<<<<<<<<<< + * self.weights[fname.strip()] = float(value) + * + */ + __pyx_t_2 = PyObject_GetAttr(__pyx_v_line, __pyx_n_s__split); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { + PyObject* sequence = __pyx_t_1; + if (likely(PyTuple_CheckExact(sequence))) { + if (unlikely(PyTuple_GET_SIZE(sequence) != 2)) { + if (PyTuple_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2); + else __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); + } else { + if (unlikely(PyList_GET_SIZE(sequence) != 2)) { + if (PyList_GET_SIZE(sequence) > 2) __Pyx_RaiseTooManyValuesError(2); + else __Pyx_RaiseNeedMoreValuesError(PyList_GET_SIZE(sequence)); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + } + __pyx_t_2 = PyList_GET_ITEM(sequence, 0); + __pyx_t_10 = PyList_GET_ITEM(sequence, 1); + } + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } else { + Py_ssize_t index = -1; + __pyx_t_11 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_11)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_12 = Py_TYPE(__pyx_t_11)->tp_iternext; + index = 0; __pyx_t_2 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_2)) goto __pyx_L18_unpacking_failed; + __Pyx_GOTREF(__pyx_t_2); + index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L18_unpacking_failed; + __Pyx_GOTREF(__pyx_t_10); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_11), 2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L19_unpacking_done; + __pyx_L18_unpacking_failed:; + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_StopIteration)) PyErr_Clear(); + if (!PyErr_Occurred()) __Pyx_RaiseNeedMoreValuesError(index); + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_L19_unpacking_done:; + } + __Pyx_XDECREF(__pyx_v_fname); + __pyx_v_fname = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_v_value); + __pyx_v_value = __pyx_t_10; + __pyx_t_10 = 0; + + /* "_cdec.pyx":34 + * for line in fp: + * fname, value = line.split() + * self.weights[fname.strip()] = float(value) # <<<<<<<<<<<<<< + * + * def translate(self, sentence, grammar=None): + */ + __pyx_t_13 = __Pyx_PyObject_AsDouble(__pyx_v_value); if (unlikely(__pyx_t_13 == ((double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __pyx_t_1 = PyFloat_FromDouble(__pyx_t_13); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_10 = PyObject_GetAttr(__pyx_v_fname, __pyx_n_s__strip); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_2 = PyObject_Call(__pyx_t_10, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (PyObject_SetItem(((PyObject *)__pyx_v_self->weights), __pyx_t_2, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; __pyx_clineno = __LINE__; goto __pyx_L7_error;} + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L14_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "_cdec.pyx":31 + * + * def read_weights(self, cfg): + * with open(cfg) as fp: # <<<<<<<<<<<<<< + * for line in fp: + * fname, value = line.split() + */ + /*except:*/ { + __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_1, &__pyx_t_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_10); + __Pyx_INCREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_15 = PyObject_Call(__pyx_t_3, __pyx_t_10, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_15); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(__pyx_t_14 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + __pyx_t_16 = (!__pyx_t_14); + if (__pyx_t_16) { + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_2); + __Pyx_ErrRestore(__pyx_t_4, __pyx_t_1, __pyx_t_2); + __pyx_t_4 = 0; __pyx_t_1 = 0; __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L9_except_error;} + goto __pyx_L22; + } + __pyx_L22:; + __Pyx_DECREF(((PyObject *)__pyx_t_10)); __pyx_t_10 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ExceptionReset(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_L14_try_end:; + } + } + /*finally:*/ { + if (__pyx_t_3) { + __pyx_t_7 = PyObject_Call(__pyx_t_3, __pyx_k_tuple_21, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(__pyx_t_16 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + } + goto __pyx_L23; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L23:; + } + + __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_4); + __Pyx_XDECREF(__pyx_t_10); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("_cdec.Decoder.read_weights", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_fp); + __Pyx_XDECREF(__pyx_v_line); + __Pyx_XDECREF(__pyx_v_fname); + __Pyx_XDECREF(__pyx_v_value); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Decoder_7translate(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_sentence = 0; + PyObject *__pyx_v_grammar = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__sentence,&__pyx_n_s__grammar,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("translate (wrapper)", 0); + { + PyObject* values[2] = {0,0}; + + /* "_cdec.pyx":36 + * self.weights[fname.strip()] = float(value) + * + * def translate(self, sentence, grammar=None): # <<<<<<<<<<<<<< + * if isinstance(sentence, unicode): + * inp = sentence.strip().encode('utf8') + */ + 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); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__sentence); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + if (kw_args > 0) { + PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__grammar); + if (value) { values[1] = value; kw_args--; } + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "translate") < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else { + switch (PyTuple_GET_SIZE(__pyx_args)) { + case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_sentence = values[0]; + __pyx_v_grammar = values[1]; + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("translate", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_7Decoder_6translate(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), __pyx_v_sentence, __pyx_v_grammar); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_5_cdec_7Decoder_6translate(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_sentence, PyObject *__pyx_v_grammar) { + PyObject *__pyx_v_inp = NULL; + BasicObserver __pyx_v_observer; + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hg = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + char *__pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("translate", 0); + + /* "_cdec.pyx":37 + * + * def translate(self, sentence, grammar=None): + * if isinstance(sentence, unicode): # <<<<<<<<<<<<<< + * inp = sentence.strip().encode('utf8') + * elif isinstance(sentence, str): + */ + __pyx_t_1 = ((PyObject *)((PyObject*)(&PyUnicode_Type))); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":38 + * def translate(self, sentence, grammar=None): + * if isinstance(sentence, unicode): + * inp = sentence.strip().encode('utf8') # <<<<<<<<<<<<<< + * elif isinstance(sentence, str): + * inp = sentence.strip() + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = PyObject_GetAttr(__pyx_t_3, __pyx_n_s__encode); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_22), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_inp = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3; + } + + /* "_cdec.pyx":39 + * if isinstance(sentence, unicode): + * inp = sentence.strip().encode('utf8') + * elif isinstance(sentence, str): # <<<<<<<<<<<<<< + * inp = sentence.strip() + * elif isinstance(sentence, Lattice): + */ + __pyx_t_3 = ((PyObject *)((PyObject*)(&PyString_Type))); + __Pyx_INCREF(__pyx_t_3); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":40 + * inp = sentence.strip().encode('utf8') + * elif isinstance(sentence, str): + * inp = sentence.strip() # <<<<<<<<<<<<<< + * elif isinstance(sentence, Lattice): + * inp = str(sentence) # PLF format + */ + __pyx_t_3 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_v_inp = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L3; + } + + /* "_cdec.pyx":41 + * elif isinstance(sentence, str): + * inp = sentence.strip() + * elif isinstance(sentence, Lattice): # <<<<<<<<<<<<<< + * inp = str(sentence) # PLF format + * else: + */ + __pyx_t_1 = ((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_sentence, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "_cdec.pyx":42 + * inp = sentence.strip() + * elif isinstance(sentence, Lattice): + * inp = str(sentence) # PLF format # <<<<<<<<<<<<<< + * else: + * raise TypeError('Cannot translate input type %s' % type(sentence)) + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_sentence); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_sentence); + __Pyx_GIVEREF(__pyx_v_sentence); + __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_v_inp = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L3; + } + /*else*/ { + + /* "_cdec.pyx":44 + * inp = str(sentence) # PLF format + * else: + * raise TypeError('Cannot translate input type %s' % type(sentence)) # <<<<<<<<<<<<<< + * if grammar: + * self.dec.SetSentenceGrammarFromString(string( grammar)) + */ + __pyx_t_3 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_23), ((PyObject *)Py_TYPE(__pyx_v_sentence))); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_3)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + __pyx_t_3 = 0; + __pyx_t_3 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __Pyx_Raise(__pyx_t_3, 0, 0, 0); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + } + __pyx_L3:; + + /* "_cdec.pyx":45 + * else: + * raise TypeError('Cannot translate input type %s' % type(sentence)) + * if grammar: # <<<<<<<<<<<<<< + * self.dec.SetSentenceGrammarFromString(string( grammar)) + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_grammar); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__pyx_t_2) { + + /* "_cdec.pyx":46 + * raise TypeError('Cannot translate input type %s' % type(sentence)) + * if grammar: + * self.dec.SetSentenceGrammarFromString(string( grammar)) # <<<<<<<<<<<<<< + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + * self.dec.Decode(string(inp), &observer) + */ + __pyx_t_4 = PyBytes_AsString(__pyx_v_grammar); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->dec->SetSentenceGrammarFromString(std::string(((char *)__pyx_t_4))); + goto __pyx_L4; + } + __pyx_L4:; + + /* "_cdec.pyx":47 + * if grammar: + * self.dec.SetSentenceGrammarFromString(string( grammar)) + * cdef decoder.BasicObserver observer = decoder.BasicObserver() # <<<<<<<<<<<<<< + * self.dec.Decode(string(inp), &observer) + * if observer.hypergraph == NULL: + */ + __pyx_v_observer = BasicObserver(); + + /* "_cdec.pyx":48 + * self.dec.SetSentenceGrammarFromString(string( grammar)) + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + * self.dec.Decode(string(inp), &observer) # <<<<<<<<<<<<<< + * if observer.hypergraph == NULL: + * raise ParseFailed() + */ + __pyx_t_4 = PyBytes_AsString(__pyx_v_inp); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->dec->Decode(std::string(((char *)__pyx_t_4)), (&__pyx_v_observer)); + + /* "_cdec.pyx":49 + * cdef decoder.BasicObserver observer = decoder.BasicObserver() + * self.dec.Decode(string(inp), &observer) + * if observer.hypergraph == NULL: # <<<<<<<<<<<<<< + * raise ParseFailed() + * cdef Hypergraph hg = Hypergraph() + */ + __pyx_t_2 = (__pyx_v_observer.hypergraph == NULL); + if (__pyx_t_2) { + + /* "_cdec.pyx":50 + * self.dec.Decode(string(inp), &observer) + * if observer.hypergraph == NULL: + * raise ParseFailed() # <<<<<<<<<<<<<< + * cdef Hypergraph hg = Hypergraph() + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) + */ + __pyx_t_3 = __Pyx_GetName(__pyx_m, __pyx_n_s__ParseFailed); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyObject_Call(__pyx_t_3, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_1, 0, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L5; + } + __pyx_L5:; + + /* "_cdec.pyx":51 + * if observer.hypergraph == NULL: + * raise ParseFailed() + * cdef Hypergraph hg = Hypergraph() # <<<<<<<<<<<<<< + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) + * return hg + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Hypergraph)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 51; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_hg = ((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "_cdec.pyx":52 + * raise ParseFailed() + * cdef Hypergraph hg = Hypergraph() + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) # <<<<<<<<<<<<<< + * return hg + */ + __pyx_v_hg->hg = new Hypergraph((__pyx_v_observer.hypergraph[0])); + + /* "_cdec.pyx":53 + * cdef Hypergraph hg = Hypergraph() + * hg.hg = new hypergraph.Hypergraph(observer.hypergraph[0]) + * return hg # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_hg)); + __pyx_r = ((PyObject *)__pyx_v_hg); + goto __pyx_L0; + + __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_AddTraceback("_cdec.Decoder.translate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_inp); + __Pyx_XDECREF((PyObject *)__pyx_v_hg); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_7Decoder_7weights_1__get__(PyObject *__pyx_v_self) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights___get__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "_cdec.pyx":17 + * cdef class Decoder: + * cdef decoder.Decoder* dec + * cdef public DenseVector weights # <<<<<<<<<<<<<< + * + * def __cinit__(self, char* config): + */ + +static PyObject *__pyx_pf_5_cdec_7Decoder_7weights___get__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__get__", 0); + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_self->weights)); + __pyx_r = ((PyObject *)__pyx_v_self->weights); + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value); /*proto*/ +static int __pyx_pw_5_cdec_7Decoder_7weights_3__set__(PyObject *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__set__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_2__set__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self), ((PyObject *)__pyx_v_value)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5_cdec_7Decoder_7weights_2__set__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_value) { + int __pyx_r; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__set__", 0); + if (!(likely(((__pyx_v_value) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_value, __pyx_ptype_5_cdec_DenseVector))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + __Pyx_GOTREF(__pyx_v_self->weights); + __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); + __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_value); + + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_AddTraceback("_cdec.Decoder.weights.__set__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static int __pyx_pw_5_cdec_7Decoder_7weights_5__del__(PyObject *__pyx_v_self); /*proto*/ +static int __pyx_pw_5_cdec_7Decoder_7weights_5__del__(PyObject *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_7Decoder_7weights_4__del__(((struct __pyx_obj_5_cdec_Decoder *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_5_cdec_7Decoder_7weights_4__del__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__del__", 0); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + __Pyx_GOTREF(__pyx_v_self->weights); + __Pyx_DECREF(((PyObject *)__pyx_v_self->weights)); + __pyx_v_self->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_tp_new_5_cdec_DenseVector(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + return o; +} + +static void __pyx_tp_dealloc_5_cdec_DenseVector(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_5_cdec_DenseVector(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_5_cdec_DenseVector(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_5_cdec_11DenseVector_3__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_DenseVector[] = { + {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_8dot, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("tosparse"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_10tosparse, METH_NOARGS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_DenseVector = { + 0, /*nb_add*/ + 0, /*nb_subtract*/ + 0, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_divide*/ + #endif + 0, /*nb_remainder*/ + 0, /*nb_divmod*/ + 0, /*nb_power*/ + 0, /*nb_negative*/ + 0, /*nb_positive*/ + 0, /*nb_absolute*/ + 0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_coerce*/ + #endif + 0, /*nb_int*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_long*/ + #else + 0, /*reserved*/ + #endif + 0, /*nb_float*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_oct*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*nb_hex*/ + #endif + 0, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_inplace_divide*/ + #endif + 0, /*nb_inplace_remainder*/ + 0, /*nb_inplace_power*/ + 0, /*nb_inplace_lshift*/ + 0, /*nb_inplace_rshift*/ + 0, /*nb_inplace_and*/ + 0, /*nb_inplace_xor*/ + 0, /*nb_inplace_or*/ + 0, /*nb_floor_divide*/ + 0, /*nb_true_divide*/ + 0, /*nb_inplace_floor_divide*/ + 0, /*nb_inplace_true_divide*/ + #if PY_VERSION_HEX >= 0x02050000 + 0, /*nb_index*/ + #endif +}; + +static PySequenceMethods __pyx_tp_as_sequence_DenseVector = { + 0, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5_cdec_DenseVector, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_DenseVector = { + 0, /*mp_length*/ + __pyx_pw_5_cdec_11DenseVector_1__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5_cdec_DenseVector, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_DenseVector = { + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getreadbuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getwritebuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getsegcount*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getcharbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_getbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_releasebuffer*/ + #endif +}; + +static PyTypeObject __pyx_type_5_cdec_DenseVector = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.DenseVector"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_DenseVector), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_DenseVector, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #else + 0, /*reserved*/ + #endif + 0, /*tp_repr*/ + &__pyx_tp_as_number_DenseVector, /*tp_as_number*/ + &__pyx_tp_as_sequence_DenseVector, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_DenseVector, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_DenseVector, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + __pyx_pw_5_cdec_11DenseVector_5__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_DenseVector, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5_cdec_DenseVector, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + #if PY_VERSION_HEX >= 0x02060000 + 0, /*tp_version_tag*/ + #endif +}; + +static PyObject *__pyx_tp_new_5_cdec_SparseVector(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + return o; +} + +static void __pyx_tp_dealloc_5_cdec_SparseVector(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_5_cdec_SparseVector(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_5_cdec_SparseVector(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_5_cdec_12SparseVector_3__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_SparseVector[] = { + {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_8dot, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("todense"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_10todense, METH_NOARGS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_SparseVector = { + __pyx_pw_5_cdec_12SparseVector_26__add__, /*nb_add*/ + __pyx_pw_5_cdec_12SparseVector_28__sub__, /*nb_subtract*/ + __pyx_pw_5_cdec_12SparseVector_30__mul__, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 + __pyx_pw_5_cdec_12SparseVector_32__div__, /*nb_divide*/ + #endif + 0, /*nb_remainder*/ + 0, /*nb_divmod*/ + 0, /*nb_power*/ + 0, /*nb_negative*/ + 0, /*nb_positive*/ + 0, /*nb_absolute*/ + 0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_coerce*/ + #endif + 0, /*nb_int*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_long*/ + #else + 0, /*reserved*/ + #endif + 0, /*nb_float*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_oct*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*nb_hex*/ + #endif + __pyx_pw_5_cdec_12SparseVector_18__iadd__, /*nb_inplace_add*/ + __pyx_pw_5_cdec_12SparseVector_20__isub__, /*nb_inplace_subtract*/ + __pyx_pw_5_cdec_12SparseVector_22__imul__, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + __pyx_pw_5_cdec_12SparseVector_24__idiv__, /*nb_inplace_divide*/ + #endif + 0, /*nb_inplace_remainder*/ + 0, /*nb_inplace_power*/ + 0, /*nb_inplace_lshift*/ + 0, /*nb_inplace_rshift*/ + 0, /*nb_inplace_and*/ + 0, /*nb_inplace_xor*/ + 0, /*nb_inplace_or*/ + 0, /*nb_floor_divide*/ + 0, /*nb_true_divide*/ + 0, /*nb_inplace_floor_divide*/ + 0, /*nb_inplace_true_divide*/ + #if PY_VERSION_HEX >= 0x02050000 + 0, /*nb_index*/ + #endif +}; + +static PySequenceMethods __pyx_tp_as_sequence_SparseVector = { + __pyx_pw_5_cdec_12SparseVector_14__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5_cdec_SparseVector, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + __pyx_pw_5_cdec_12SparseVector_16__contains__, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_SparseVector = { + __pyx_pw_5_cdec_12SparseVector_14__len__, /*mp_length*/ + __pyx_pw_5_cdec_12SparseVector_1__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5_cdec_SparseVector, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_SparseVector = { + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getreadbuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getwritebuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getsegcount*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getcharbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_getbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_releasebuffer*/ + #endif +}; + +static PyTypeObject __pyx_type_5_cdec_SparseVector = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.SparseVector"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_SparseVector), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_SparseVector, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #else + 0, /*reserved*/ + #endif + 0, /*tp_repr*/ + &__pyx_tp_as_number_SparseVector, /*tp_as_number*/ + &__pyx_tp_as_sequence_SparseVector, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_SparseVector, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_SparseVector, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + __pyx_pw_5_cdec_12SparseVector_12__richcmp__, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + __pyx_pw_5_cdec_12SparseVector_5__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_SparseVector, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5_cdec_SparseVector, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + #if PY_VERSION_HEX >= 0x02060000 + 0, /*tp_version_tag*/ + #endif +}; + +static PyObject *__pyx_tp_new_5_cdec_Hypergraph(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + return o; +} + +static void __pyx_tp_dealloc_5_cdec_Hypergraph(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} + +static PyMethodDef __pyx_methods_5_cdec_Hypergraph[] = { + {__Pyx_NAMESTR("viterbi"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_3viterbi, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("viterbi_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_5viterbi_tree, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("viterbi_source_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_7viterbi_source_tree, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("viterbi_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_9viterbi_features, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("kbest"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_11kbest, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("kbest_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_14kbest_tree, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("kbest_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_17kbest_features, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("sample"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_20sample, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("intersect"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_23intersect, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("prune"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_25prune, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("lattice"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_27lattice, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("reweight"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_29reweight, METH_O, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Hypergraph = { + 0, /*nb_add*/ + 0, /*nb_subtract*/ + 0, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_divide*/ + #endif + 0, /*nb_remainder*/ + 0, /*nb_divmod*/ + 0, /*nb_power*/ + 0, /*nb_negative*/ + 0, /*nb_positive*/ + 0, /*nb_absolute*/ + 0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_coerce*/ + #endif + 0, /*nb_int*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_long*/ + #else + 0, /*reserved*/ + #endif + 0, /*nb_float*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_oct*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*nb_hex*/ + #endif + 0, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_inplace_divide*/ + #endif + 0, /*nb_inplace_remainder*/ + 0, /*nb_inplace_power*/ + 0, /*nb_inplace_lshift*/ + 0, /*nb_inplace_rshift*/ + 0, /*nb_inplace_and*/ + 0, /*nb_inplace_xor*/ + 0, /*nb_inplace_or*/ + 0, /*nb_floor_divide*/ + 0, /*nb_true_divide*/ + 0, /*nb_inplace_floor_divide*/ + 0, /*nb_inplace_true_divide*/ + #if PY_VERSION_HEX >= 0x02050000 + 0, /*nb_index*/ + #endif +}; + +static PySequenceMethods __pyx_tp_as_sequence_Hypergraph = { + 0, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + 0, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_Hypergraph = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = { + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getreadbuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getwritebuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getsegcount*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getcharbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_getbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_releasebuffer*/ + #endif +}; + +static PyTypeObject __pyx_type_5_cdec_Hypergraph = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.Hypergraph"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Hypergraph), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_Hypergraph, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #else + 0, /*reserved*/ + #endif + 0, /*tp_repr*/ + &__pyx_tp_as_number_Hypergraph, /*tp_as_number*/ + &__pyx_tp_as_sequence_Hypergraph, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Hypergraph, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Hypergraph, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_Hypergraph, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5_cdec_Hypergraph, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + #if PY_VERSION_HEX >= 0x02060000 + 0, /*tp_version_tag*/ + #endif +}; + +static PyObject *__pyx_tp_new_5_cdec_Lattice(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + return o; +} + +static void __pyx_tp_dealloc_5_cdec_Lattice(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_7Lattice_14__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_5_cdec_Lattice(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static int __pyx_mp_ass_subscript_5_cdec_Lattice(PyObject *o, PyObject *i, PyObject *v) { + if (v) { + return __pyx_pw_5_cdec_7Lattice_5__setitem__(o, i, v); + } + else { + PyErr_Format(PyExc_NotImplementedError, + "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_Lattice[] = { + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Lattice = { + 0, /*nb_add*/ + 0, /*nb_subtract*/ + 0, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_divide*/ + #endif + 0, /*nb_remainder*/ + 0, /*nb_divmod*/ + 0, /*nb_power*/ + 0, /*nb_negative*/ + 0, /*nb_positive*/ + 0, /*nb_absolute*/ + 0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_coerce*/ + #endif + 0, /*nb_int*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_long*/ + #else + 0, /*reserved*/ + #endif + 0, /*nb_float*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_oct*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*nb_hex*/ + #endif + 0, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_inplace_divide*/ + #endif + 0, /*nb_inplace_remainder*/ + 0, /*nb_inplace_power*/ + 0, /*nb_inplace_lshift*/ + 0, /*nb_inplace_rshift*/ + 0, /*nb_inplace_and*/ + 0, /*nb_inplace_xor*/ + 0, /*nb_inplace_or*/ + 0, /*nb_floor_divide*/ + 0, /*nb_true_divide*/ + 0, /*nb_inplace_floor_divide*/ + 0, /*nb_inplace_true_divide*/ + #if PY_VERSION_HEX >= 0x02050000 + 0, /*nb_index*/ + #endif +}; + +static PySequenceMethods __pyx_tp_as_sequence_Lattice = { + __pyx_pw_5_cdec_7Lattice_7__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5_cdec_Lattice, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_Lattice = { + __pyx_pw_5_cdec_7Lattice_7__len__, /*mp_length*/ + __pyx_pw_5_cdec_7Lattice_3__getitem__, /*mp_subscript*/ + __pyx_mp_ass_subscript_5_cdec_Lattice, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Lattice = { + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getreadbuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getwritebuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getsegcount*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getcharbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_getbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_releasebuffer*/ + #endif +}; + +static PyTypeObject __pyx_type_5_cdec_Lattice = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.Lattice"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Lattice), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_Lattice, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #else + 0, /*reserved*/ + #endif + 0, /*tp_repr*/ + &__pyx_tp_as_number_Lattice, /*tp_as_number*/ + &__pyx_tp_as_sequence_Lattice, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Lattice, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + __pyx_pw_5_cdec_7Lattice_9__str__, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Lattice, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + __pyx_pw_5_cdec_7Lattice_11__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_Lattice, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + __pyx_pw_5_cdec_7Lattice_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5_cdec_Lattice, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + #if PY_VERSION_HEX >= 0x02060000 + 0, /*tp_version_tag*/ + #endif +}; + +static PyObject *__pyx_tp_new_5_cdec_Candidate(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + return o; +} + +static void __pyx_tp_dealloc_5_cdec_Candidate(PyObject *o) { + (*Py_TYPE(o)->tp_free)(o); +} + +static PyObject *__pyx_getprop_5_cdec_9Candidate_words(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9Candidate_5words_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_9Candidate_fmap(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9Candidate_4fmap_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_9Candidate_score(PyObject *o, void *x) { + return __pyx_pw_5_cdec_9Candidate_5score_1__get__(o); +} + +static int __pyx_setprop_5_cdec_9Candidate_score(PyObject *o, PyObject *v, void *x) { + if (v) { + return __pyx_pw_5_cdec_9Candidate_5score_3__set__(o, v); + } + else { + PyErr_SetString(PyExc_NotImplementedError, "__del__"); + return -1; + } +} + +static PyMethodDef __pyx_methods_5_cdec_Candidate[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5_cdec_Candidate[] = { + {(char *)"words", __pyx_getprop_5_cdec_9Candidate_words, 0, 0, 0}, + {(char *)"fmap", __pyx_getprop_5_cdec_9Candidate_fmap, 0, 0, 0}, + {(char *)"score", __pyx_getprop_5_cdec_9Candidate_score, __pyx_setprop_5_cdec_9Candidate_score, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Candidate = { + 0, /*nb_add*/ + 0, /*nb_subtract*/ + 0, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_divide*/ + #endif + 0, /*nb_remainder*/ + 0, /*nb_divmod*/ + 0, /*nb_power*/ + 0, /*nb_negative*/ + 0, /*nb_positive*/ + 0, /*nb_absolute*/ + 0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_coerce*/ + #endif + 0, /*nb_int*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_long*/ + #else + 0, /*reserved*/ + #endif + 0, /*nb_float*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_oct*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*nb_hex*/ + #endif + 0, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_inplace_divide*/ + #endif + 0, /*nb_inplace_remainder*/ + 0, /*nb_inplace_power*/ + 0, /*nb_inplace_lshift*/ + 0, /*nb_inplace_rshift*/ + 0, /*nb_inplace_and*/ + 0, /*nb_inplace_xor*/ + 0, /*nb_inplace_or*/ + 0, /*nb_floor_divide*/ + 0, /*nb_true_divide*/ + 0, /*nb_inplace_floor_divide*/ + 0, /*nb_inplace_true_divide*/ + #if PY_VERSION_HEX >= 0x02050000 + 0, /*nb_index*/ + #endif +}; + +static PySequenceMethods __pyx_tp_as_sequence_Candidate = { + 0, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + 0, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_Candidate = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_Candidate = { + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getreadbuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getwritebuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getsegcount*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getcharbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_getbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_releasebuffer*/ + #endif +}; + +static PyTypeObject __pyx_type_5_cdec_Candidate = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.Candidate"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Candidate), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_Candidate, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #else + 0, /*reserved*/ + #endif + 0, /*tp_repr*/ + &__pyx_tp_as_number_Candidate, /*tp_as_number*/ + &__pyx_tp_as_sequence_Candidate, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Candidate, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_Candidate, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_Candidate, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5_cdec_Candidate, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5_cdec_Candidate, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + #if PY_VERSION_HEX >= 0x02060000 + 0, /*tp_version_tag*/ + #endif +}; + +static PyObject *__pyx_tp_new_5_cdec_SufficientStats(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + return o; +} + +static void __pyx_tp_dealloc_5_cdec_SufficientStats(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_15SufficientStats_1__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} + +static PyObject *__pyx_getprop_5_cdec_15SufficientStats_score(PyObject *o, void *x) { + return __pyx_pw_5_cdec_15SufficientStats_5score_1__get__(o); +} + +static PyObject *__pyx_getprop_5_cdec_15SufficientStats_detail(PyObject *o, void *x) { + return __pyx_pw_5_cdec_15SufficientStats_6detail_1__get__(o); +} + +static PyMethodDef __pyx_methods_5_cdec_SufficientStats[] = { + {0, 0, 0, 0} +}; + +static struct PyGetSetDef __pyx_getsets_5_cdec_SufficientStats[] = { + {(char *)"score", __pyx_getprop_5_cdec_15SufficientStats_score, 0, 0, 0}, + {(char *)"detail", __pyx_getprop_5_cdec_15SufficientStats_detail, 0, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_SufficientStats = { + __pyx_pw_5_cdec_15SufficientStats_10__add__, /*nb_add*/ + 0, /*nb_subtract*/ + 0, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_divide*/ + #endif + 0, /*nb_remainder*/ + 0, /*nb_divmod*/ + 0, /*nb_power*/ + 0, /*nb_negative*/ + 0, /*nb_positive*/ + 0, /*nb_absolute*/ + 0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_coerce*/ + #endif + 0, /*nb_int*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_long*/ + #else + 0, /*reserved*/ + #endif + 0, /*nb_float*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_oct*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*nb_hex*/ + #endif + __pyx_pw_5_cdec_15SufficientStats_8__iadd__, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_inplace_divide*/ + #endif + 0, /*nb_inplace_remainder*/ + 0, /*nb_inplace_power*/ + 0, /*nb_inplace_lshift*/ + 0, /*nb_inplace_rshift*/ + 0, /*nb_inplace_and*/ + 0, /*nb_inplace_xor*/ + 0, /*nb_inplace_or*/ + 0, /*nb_floor_divide*/ + 0, /*nb_true_divide*/ + 0, /*nb_inplace_floor_divide*/ + 0, /*nb_inplace_true_divide*/ + #if PY_VERSION_HEX >= 0x02050000 + 0, /*nb_index*/ + #endif +}; + +static PySequenceMethods __pyx_tp_as_sequence_SufficientStats = { + __pyx_pw_5_cdec_15SufficientStats_3__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + 0, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_SufficientStats = { + __pyx_pw_5_cdec_15SufficientStats_3__len__, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_SufficientStats = { + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getreadbuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getwritebuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getsegcount*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getcharbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_getbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_releasebuffer*/ + #endif +}; + +static PyTypeObject __pyx_type_5_cdec_SufficientStats = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.SufficientStats"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_SufficientStats), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_SufficientStats, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #else + 0, /*reserved*/ + #endif + 0, /*tp_repr*/ + &__pyx_tp_as_number_SufficientStats, /*tp_as_number*/ + &__pyx_tp_as_sequence_SufficientStats, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_SufficientStats, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_SufficientStats, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + __pyx_pw_5_cdec_15SufficientStats_5__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_SufficientStats, /*tp_methods*/ + 0, /*tp_members*/ + __pyx_getsets_5_cdec_SufficientStats, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5_cdec_SufficientStats, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + #if PY_VERSION_HEX >= 0x02060000 + 0, /*tp_version_tag*/ + #endif +}; + +static PyObject *__pyx_tp_new_5_cdec_SegmentEvaluator(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + return o; +} + +static void __pyx_tp_dealloc_5_cdec_SegmentEvaluator(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} + +static PyMethodDef __pyx_methods_5_cdec_SegmentEvaluator[] = { + {__Pyx_NAMESTR("evaluate"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("candidate_set"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_SegmentEvaluator = { + 0, /*nb_add*/ + 0, /*nb_subtract*/ + 0, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_divide*/ + #endif + 0, /*nb_remainder*/ + 0, /*nb_divmod*/ + 0, /*nb_power*/ + 0, /*nb_negative*/ + 0, /*nb_positive*/ + 0, /*nb_absolute*/ + 0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_coerce*/ + #endif + 0, /*nb_int*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_long*/ + #else + 0, /*reserved*/ + #endif + 0, /*nb_float*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_oct*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*nb_hex*/ + #endif + 0, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_inplace_divide*/ + #endif + 0, /*nb_inplace_remainder*/ + 0, /*nb_inplace_power*/ + 0, /*nb_inplace_lshift*/ + 0, /*nb_inplace_rshift*/ + 0, /*nb_inplace_and*/ + 0, /*nb_inplace_xor*/ + 0, /*nb_inplace_or*/ + 0, /*nb_floor_divide*/ + 0, /*nb_true_divide*/ + 0, /*nb_inplace_floor_divide*/ + 0, /*nb_inplace_true_divide*/ + #if PY_VERSION_HEX >= 0x02050000 + 0, /*nb_index*/ + #endif +}; + +static PySequenceMethods __pyx_tp_as_sequence_SegmentEvaluator = { + 0, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + 0, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_SegmentEvaluator = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_SegmentEvaluator = { + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getreadbuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getwritebuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getsegcount*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getcharbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_getbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_releasebuffer*/ + #endif +}; + +static PyTypeObject __pyx_type_5_cdec_SegmentEvaluator = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.SegmentEvaluator"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_SegmentEvaluator), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_SegmentEvaluator, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #else + 0, /*reserved*/ + #endif + 0, /*tp_repr*/ + &__pyx_tp_as_number_SegmentEvaluator, /*tp_as_number*/ + &__pyx_tp_as_sequence_SegmentEvaluator, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_SegmentEvaluator, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_SegmentEvaluator, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_SegmentEvaluator, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5_cdec_SegmentEvaluator, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + #if PY_VERSION_HEX >= 0x02060000 + 0, /*tp_version_tag*/ + #endif +}; + +static PyObject *__pyx_tp_new_5_cdec_Scorer(PyTypeObject *t, PyObject *a, PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + if (__pyx_pw_5_cdec_6Scorer_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } return o; } -static void __pyx_tp_dealloc_5_cdec_DenseVector(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec_Scorer(PyObject *o) { (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_sq_item_5_cdec_DenseVector(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} - -static int __pyx_mp_ass_subscript_5_cdec_DenseVector(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_pw_5_cdec_11DenseVector_3__setitem__(o, i, v); - } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); - return -1; - } -} -static PyMethodDef __pyx_methods_5_cdec_DenseVector[] = { - {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_8dot, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("tosparse"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_10tosparse, METH_NOARGS, __Pyx_DOCSTR(0)}, +static PyMethodDef __pyx_methods_5_cdec_Scorer[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_DenseVector = { +static PyNumberMethods __pyx_tp_as_number_Scorer = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -5931,11 +9512,11 @@ static PyNumberMethods __pyx_tp_as_number_DenseVector = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_DenseVector = { +static PySequenceMethods __pyx_tp_as_sequence_Scorer = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_DenseVector, /*sq_item*/ + 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -5944,13 +9525,13 @@ static PySequenceMethods __pyx_tp_as_sequence_DenseVector = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_DenseVector = { +static PyMappingMethods __pyx_tp_as_mapping_Scorer = { 0, /*mp_length*/ - __pyx_pw_5_cdec_11DenseVector_1__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_5_cdec_DenseVector, /*mp_ass_subscript*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_DenseVector = { +static PyBufferProcs __pyx_tp_as_buffer_Scorer = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -5971,12 +9552,12 @@ static PyBufferProcs __pyx_tp_as_buffer_DenseVector = { #endif }; -static PyTypeObject __pyx_type_5_cdec_DenseVector = { +static PyTypeObject __pyx_type_5_cdec_Scorer = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.DenseVector"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_DenseVector), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.Scorer"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Scorer), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_DenseVector, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_Scorer, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -5986,24 +9567,24 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_DenseVector, /*tp_as_number*/ - &__pyx_tp_as_sequence_DenseVector, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_DenseVector, /*tp_as_mapping*/ + &__pyx_tp_as_number_Scorer, /*tp_as_number*/ + &__pyx_tp_as_sequence_Scorer, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Scorer, /*tp_as_mapping*/ 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ + __pyx_pw_5_cdec_6Scorer_3__call__, /*tp_call*/ + __pyx_pw_5_cdec_6Scorer_5__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_DenseVector, /*tp_as_buffer*/ + &__pyx_tp_as_buffer_Scorer, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ 0, /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_11DenseVector_5__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_DenseVector, /*tp_methods*/ + __pyx_methods_5_cdec_Scorer, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -6013,7 +9594,7 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_DenseVector, /*tp_new*/ + __pyx_tp_new_5_cdec_Scorer, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -6027,43 +9608,78 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_SparseVector(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec_Decoder(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec_Decoder *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + p = ((struct __pyx_obj_5_cdec_Decoder *)o); + p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + if (__pyx_pw_5_cdec_7Decoder_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } return o; } -static void __pyx_tp_dealloc_5_cdec_SparseVector(PyObject *o) { +static void __pyx_tp_dealloc_5_cdec_Decoder(PyObject *o) { + struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_7Decoder_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + Py_XDECREF(((PyObject *)p->weights)); (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_sq_item_5_cdec_SparseVector(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; + +static int __pyx_tp_traverse_5_cdec_Decoder(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; + if (p->weights) { + e = (*v)(((PyObject*)p->weights), a); if (e) return e; + } + return 0; } -static int __pyx_mp_ass_subscript_5_cdec_SparseVector(PyObject *o, PyObject *i, PyObject *v) { +static int __pyx_tp_clear_5_cdec_Decoder(PyObject *o) { + struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; + PyObject* tmp; + tmp = ((PyObject*)p->weights); + p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyObject *__pyx_getprop_5_cdec_7Decoder_weights(PyObject *o, void *x) { + return __pyx_pw_5_cdec_7Decoder_7weights_1__get__(o); +} + +static int __pyx_setprop_5_cdec_7Decoder_weights(PyObject *o, PyObject *v, void *x) { if (v) { - return __pyx_pw_5_cdec_12SparseVector_3__setitem__(o, i, v); + return __pyx_pw_5_cdec_7Decoder_7weights_3__set__(o, v); } else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); - return -1; + return __pyx_pw_5_cdec_7Decoder_7weights_5__del__(o); } } -static PyMethodDef __pyx_methods_5_cdec_SparseVector[] = { - {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_8dot, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("todense"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_10todense, METH_NOARGS, __Pyx_DOCSTR(0)}, +static PyMethodDef __pyx_methods_5_cdec_Decoder[] = { + {__Pyx_NAMESTR("read_weights"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_5read_weights, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("translate"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_7translate, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_26__add__, /*nb_add*/ - __pyx_pw_5_cdec_12SparseVector_28__sub__, /*nb_subtract*/ +static struct PyGetSetDef __pyx_getsets_5_cdec_Decoder[] = { + {(char *)"weights", __pyx_getprop_5_cdec_7Decoder_weights, __pyx_setprop_5_cdec_7Decoder_weights, 0, 0}, + {0, 0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_Decoder = { + 0, /*nb_add*/ + 0, /*nb_subtract*/ 0, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 0, /*nb_divide*/ @@ -6097,11 +9713,11 @@ static PyNumberMethods __pyx_tp_as_number_SparseVector = { #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif - __pyx_pw_5_cdec_12SparseVector_18__iadd__, /*nb_inplace_add*/ - __pyx_pw_5_cdec_12SparseVector_20__isub__, /*nb_inplace_subtract*/ - __pyx_pw_5_cdec_12SparseVector_22__imul__, /*nb_inplace_multiply*/ + 0, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 - __pyx_pw_5_cdec_12SparseVector_24__idiv__, /*nb_inplace_divide*/ + 0, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ @@ -6119,26 +9735,26 @@ static PyNumberMethods __pyx_tp_as_number_SparseVector = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_14__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence_Decoder = { + 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_SparseVector, /*sq_item*/ + 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ - __pyx_pw_5_cdec_12SparseVector_16__contains__, /*sq_contains*/ + 0, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_14__len__, /*mp_length*/ - __pyx_pw_5_cdec_12SparseVector_1__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_5_cdec_SparseVector, /*mp_ass_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping_Decoder = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_SparseVector = { +static PyBufferProcs __pyx_tp_as_buffer_Decoder = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -6159,12 +9775,12 @@ static PyBufferProcs __pyx_tp_as_buffer_SparseVector = { #endif }; -static PyTypeObject __pyx_type_5_cdec_SparseVector = { +static PyTypeObject __pyx_type_5_cdec_Decoder = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.SparseVector"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_SparseVector), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.Decoder"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_Decoder), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_SparseVector, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec_Decoder, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -6174,26 +9790,26 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_SparseVector, /*tp_as_number*/ - &__pyx_tp_as_sequence_SparseVector, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_SparseVector, /*tp_as_mapping*/ + &__pyx_tp_as_number_Decoder, /*tp_as_number*/ + &__pyx_tp_as_sequence_Decoder, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_Decoder, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_SparseVector, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer_Decoder, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - __pyx_pw_5_cdec_12SparseVector_12__richcmp__, /*tp_richcompare*/ + __pyx_tp_traverse_5_cdec_Decoder, /*tp_traverse*/ + __pyx_tp_clear_5_cdec_Decoder, /*tp_clear*/ + 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_12SparseVector_5__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_SparseVector, /*tp_methods*/ + __pyx_methods_5_cdec_Decoder, /*tp_methods*/ 0, /*tp_members*/ - 0, /*tp_getset*/ + __pyx_getsets_5_cdec_Decoder, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -6201,7 +9817,7 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_SparseVector, /*tp_new*/ + __pyx_tp_new_5_cdec_Decoder, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -6215,41 +9831,44 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Hypergraph(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct____iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o); + p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec_Hypergraph(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_10Hypergraph_1__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static PyMethodDef __pyx_methods_5_cdec_Hypergraph[] = { - {__Pyx_NAMESTR("viterbi"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_3viterbi, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("viterbi_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_5viterbi_tree, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("viterbi_source_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_7viterbi_source_tree, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("viterbi_features"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_9viterbi_features, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("kbest"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_11kbest, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("kbest_tree"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_14kbest_tree, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("sample"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_17sample, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("intersect"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_20intersect, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("prune"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_22prune, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("lattice"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_24lattice, METH_NOARGS, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("reweight"), (PyCFunction)__pyx_pw_5_cdec_10Hypergraph_26reweight, METH_O, __Pyx_DOCSTR(0)}, +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct____iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_Hypergraph = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -6307,7 +9926,7 @@ static PyNumberMethods __pyx_tp_as_number_Hypergraph = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Hypergraph = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct____iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -6320,13 +9939,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Hypergraph = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Hypergraph = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct____iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -6347,12 +9966,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Hypergraph = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Hypergraph = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Hypergraph"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Hypergraph), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct____iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct____iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Hypergraph, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -6362,24 +9981,24 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Hypergraph, /*tp_as_number*/ - &__pyx_tp_as_sequence_Hypergraph, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Hypergraph, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct____iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct____iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct____iter__, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Hypergraph, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct____iter__, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Hypergraph, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct____iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -6389,7 +10008,7 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Hypergraph, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct____iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -6403,48 +10022,52 @@ static PyTypeObject __pyx_type_5_cdec_Hypergraph = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Lattice(PyTypeObject *t, PyObject *a, PyObject *k) { +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o); + p->__pyx_v_fname = 0; + p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec_Lattice(PyObject *o) { - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_7Lattice_14__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_fname)); + Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static PyObject *__pyx_sq_item_5_cdec_Lattice(PyObject *o, Py_ssize_t i) { - PyObject *r; - PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; - r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); - Py_DECREF(x); - return r; -} -static int __pyx_mp_ass_subscript_5_cdec_Lattice(PyObject *o, PyObject *i, PyObject *v) { - if (v) { - return __pyx_pw_5_cdec_7Lattice_5__setitem__(o, i, v); +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; + if (p->__pyx_v_fname) { + e = (*v)(p->__pyx_v_fname, a); if (e) return e; } - else { - PyErr_Format(PyExc_NotImplementedError, - "Subscript deletion not supported by %s", Py_TYPE(o)->tp_name); - return -1; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } + return 0; } -static PyMethodDef __pyx_methods_5_cdec_Lattice[] = { +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; + PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_fname); + p->__pyx_v_fname = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_1___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number_Lattice = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -6502,11 +10125,11 @@ static PyNumberMethods __pyx_tp_as_number_Lattice = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Lattice = { - __pyx_pw_5_cdec_7Lattice_7__len__, /*sq_length*/ +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1___iter__ = { + 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ - __pyx_sq_item_5_cdec_Lattice, /*sq_item*/ + 0, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ @@ -6515,13 +10138,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Lattice = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Lattice = { - __pyx_pw_5_cdec_7Lattice_7__len__, /*mp_length*/ - __pyx_pw_5_cdec_7Lattice_3__getitem__, /*mp_subscript*/ - __pyx_mp_ass_subscript_5_cdec_Lattice, /*mp_ass_subscript*/ +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1___iter__ = { + 0, /*mp_length*/ + 0, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Lattice = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -6542,12 +10165,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Lattice = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Lattice = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Lattice"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Lattice), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_1___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Lattice, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -6557,24 +10180,24 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Lattice, /*tp_as_number*/ - &__pyx_tp_as_sequence_Lattice, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Lattice, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_1___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_1___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_1___iter__, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ - __pyx_pw_5_cdec_7Lattice_9__str__, /*tp_str*/ + 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Lattice, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct_1___iter__, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_7Lattice_11__iter__, /*tp_iter*/ + 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Lattice, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_1___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -6582,9 +10205,9 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { 0, /*tp_descr_get*/ 0, /*tp_descr_set*/ 0, /*tp_dictoffset*/ - __pyx_pw_5_cdec_7Lattice_1__init__, /*tp_init*/ + 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Lattice, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -6598,76 +10221,60 @@ static PyTypeObject __pyx_type_5_cdec_Lattice = { #endif }; -static PyObject *__pyx_tp_new_5_cdec_Decoder(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec_Decoder *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec_Decoder *)o); - p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); - if (__pyx_pw_5_cdec_7Decoder_1__cinit__(o, a, k) < 0) { - Py_DECREF(o); o = 0; - } + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o); + p->__pyx_v_self = 0; + p->__pyx_v_sentence = 0; + p->__pyx_v_size = 0; return o; } -static void __pyx_tp_dealloc_5_cdec_Decoder(PyObject *o) { - struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; - { - PyObject *etype, *eval, *etb; - PyErr_Fetch(&etype, &eval, &etb); - ++Py_REFCNT(o); - __pyx_pw_5_cdec_7Decoder_3__dealloc__(o); - if (PyErr_Occurred()) PyErr_WriteUnraisable(o); - --Py_REFCNT(o); - PyErr_Restore(etype, eval, etb); - } - Py_XDECREF(((PyObject *)p->weights)); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(((PyObject *)p->__pyx_v_sentence)); + Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec_Decoder(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; - if (p->weights) { - e = (*v)(((PyObject*)p->weights), a); if (e) return e; + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; + if (p->__pyx_v_self) { + e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; + } + if (p->__pyx_v_sentence) { + e = (*v)(p->__pyx_v_sentence, a); if (e) return e; + } + if (p->__pyx_v_size) { + e = (*v)(p->__pyx_v_size, a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec_Decoder(PyObject *o) { - struct __pyx_obj_5_cdec_Decoder *p = (struct __pyx_obj_5_cdec_Decoder *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; PyObject* tmp; - tmp = ((PyObject*)p->weights); - p->weights = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_self); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_sentence); + p->__pyx_v_sentence = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_size); + p->__pyx_v_size = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyObject *__pyx_getprop_5_cdec_7Decoder_weights(PyObject *o, void *x) { - return __pyx_pw_5_cdec_7Decoder_7weights_1__get__(o); -} - -static int __pyx_setprop_5_cdec_7Decoder_weights(PyObject *o, PyObject *v, void *x) { - if (v) { - return __pyx_pw_5_cdec_7Decoder_7weights_3__set__(o, v); - } - else { - return __pyx_pw_5_cdec_7Decoder_7weights_5__del__(o); - } -} - -static PyMethodDef __pyx_methods_5_cdec_Decoder[] = { - {__Pyx_NAMESTR("read_weights"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_5read_weights, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("translate"), (PyCFunction)__pyx_pw_5_cdec_7Decoder_7translate, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_2_kbest[] = { {0, 0, 0, 0} }; -static struct PyGetSetDef __pyx_getsets_5_cdec_Decoder[] = { - {(char *)"weights", __pyx_getprop_5_cdec_7Decoder_weights, __pyx_setprop_5_cdec_7Decoder_weights, 0, 0}, - {0, 0, 0, 0, 0} -}; - -static PyNumberMethods __pyx_tp_as_number_Decoder = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -6725,7 +10332,7 @@ static PyNumberMethods __pyx_tp_as_number_Decoder = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence_Decoder = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -6738,13 +10345,13 @@ static PySequenceMethods __pyx_tp_as_sequence_Decoder = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping_Decoder = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_2_kbest = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer_Decoder = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -6765,12 +10372,12 @@ static PyBufferProcs __pyx_tp_as_buffer_Decoder = { #endif }; -static PyTypeObject __pyx_type_5_cdec_Decoder = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.Decoder"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec_Decoder), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_2_kbest"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec_Decoder, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -6780,26 +10387,26 @@ static PyTypeObject __pyx_type_5_cdec_Decoder = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number_Decoder, /*tp_as_number*/ - &__pyx_tp_as_sequence_Decoder, /*tp_as_sequence*/ - &__pyx_tp_as_mapping_Decoder, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_2_kbest, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_2_kbest, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_2_kbest, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer_Decoder, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + &__pyx_tp_as_buffer___pyx_scope_struct_2_kbest, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - __pyx_tp_traverse_5_cdec_Decoder, /*tp_traverse*/ - __pyx_tp_clear_5_cdec_Decoder, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec_Decoder, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_2_kbest, /*tp_methods*/ 0, /*tp_members*/ - __pyx_getsets_5_cdec_Decoder, /*tp_getset*/ + 0, /*tp_getset*/ 0, /*tp_base*/ 0, /*tp_dict*/ 0, /*tp_descr_get*/ @@ -6807,7 +10414,7 @@ static PyTypeObject __pyx_type_5_cdec_Decoder = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec_Decoder, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -6821,44 +10428,60 @@ static PyTypeObject __pyx_type_5_cdec_Decoder = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct____iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_tree(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o); p->__pyx_v_self = 0; + p->__pyx_v_size = 0; + p->__pyx_v_tree = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_kbest_tree(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(p->__pyx_v_size); + Py_XDECREF(((PyObject *)p->__pyx_v_tree)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_kbest_tree(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } + if (p->__pyx_v_size) { + e = (*v)(p->__pyx_v_size, a); if (e) return e; + } + if (p->__pyx_v_tree) { + e = (*v)(p->__pyx_v_tree, a); if (e) return e; + } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_3_kbest_tree(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_DenseVector *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_size); + p->__pyx_v_size = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_tree); + p->__pyx_v_tree = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct____iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_3_kbest_tree[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_kbest_tree = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -6916,7 +10539,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct____iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct____iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -6929,13 +10552,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct____iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct____iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_3_kbest_tree = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_kbest_tree = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -6956,12 +10579,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct____iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct____iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct____iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_3_kbest_tree"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct____iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -6971,24 +10594,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct____iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct____iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct____iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_3_kbest_tree, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_3_kbest_tree, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer___pyx_scope_struct____iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_3_kbest_tree, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - __pyx_tp_traverse_5_cdec___pyx_scope_struct____iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct____iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct____iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -6998,7 +10621,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct____iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -7012,52 +10635,60 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct____iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_4_kbest_features(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o); - p->__pyx_v_fname = 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o); + p->__pyx_v_fmap = 0; p->__pyx_v_self = 0; + p->__pyx_v_size = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; - Py_XDECREF(((PyObject *)p->__pyx_v_fname)); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_fmap)); Py_XDECREF(((PyObject *)p->__pyx_v_self)); + Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; - if (p->__pyx_v_fname) { - e = (*v)(p->__pyx_v_fname, a); if (e) return e; + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; + if (p->__pyx_v_fmap) { + e = (*v)(((PyObject*)p->__pyx_v_fmap), a); if (e) return e; } if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } + if (p->__pyx_v_size) { + e = (*v)(p->__pyx_v_size, a); if (e) return e; + } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_4_kbest_features(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_fname); - p->__pyx_v_fname = ((PyObject*)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_v_fmap); + p->__pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_size); + p->__pyx_v_size = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_1___iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_4_kbest_features[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4_kbest_features = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -7115,7 +10746,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_1___iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1___iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4_kbest_features = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -7128,13 +10759,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_1___iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_1___iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_4_kbest_features = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4_kbest_features = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -7155,12 +10786,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_1___iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_kbest_features = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_1___iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_4_kbest_features"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -7170,24 +10801,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_1___iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_1___iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_1___iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_4_kbest_features, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_4_kbest_features, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_4_kbest_features, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer___pyx_scope_struct_1___iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_4_kbest_features, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_1___iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -7197,7 +10828,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_4_kbest_features, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -7211,42 +10842,37 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_1___iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_5_sample(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o); p->__pyx_v_self = 0; p->__pyx_v_sentence = 0; - p->__pyx_v_size = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5_sample(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); Py_XDECREF(((PyObject *)p->__pyx_v_sentence)); - Py_XDECREF(p->__pyx_v_size); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_5_sample(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } if (p->__pyx_v_sentence) { e = (*v)(p->__pyx_v_sentence, a); if (e) return e; } - if (p->__pyx_v_size) { - e = (*v)(p->__pyx_v_size, a); if (e) return e; - } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_5_sample(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); @@ -7254,17 +10880,14 @@ static int __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest(PyObject *o) { tmp = ((PyObject*)p->__pyx_v_sentence); p->__pyx_v_sentence = ((PyObject*)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_size); - p->__pyx_v_size = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_2_kbest[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_5_sample[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_5_sample = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -7322,7 +10945,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_2_kbest = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_5_sample = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -7335,13 +10958,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_2_kbest = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_2_kbest = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_5_sample = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_5_sample = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -7362,12 +10985,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_2_kbest = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5_sample = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_2_kbest"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_2_kbest), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_5_sample"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_2_kbest, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5_sample, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -7377,24 +11000,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_2_kbest, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_2_kbest, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_2_kbest, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_5_sample, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_5_sample, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_5_sample, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer___pyx_scope_struct_2_kbest, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_5_sample, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - __pyx_tp_traverse_5_cdec___pyx_scope_struct_2_kbest, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_2_kbest, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_5_sample, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_5_sample, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_2_kbest, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_5_sample, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -7404,7 +11027,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_2_kbest, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_5_sample, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -7418,60 +11041,44 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_2_kbest = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_tree(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_6___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o); p->__pyx_v_self = 0; - p->__pyx_v_size = 0; - p->__pyx_v_tree = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_kbest_tree(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_6___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(p->__pyx_v_size); - Py_XDECREF(((PyObject *)p->__pyx_v_tree)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_kbest_tree(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_6___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } - if (p->__pyx_v_size) { - e = (*v)(p->__pyx_v_size, a); if (e) return e; - } - if (p->__pyx_v_tree) { - e = (*v)(p->__pyx_v_tree, a); if (e) return e; - } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_3_kbest_tree(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_6___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ *)o; PyObject* tmp; tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_size); - p->__pyx_v_size = Py_None; Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_tree); - p->__pyx_v_tree = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Lattice *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_3_kbest_tree[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_6___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_kbest_tree = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_6___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -7529,7 +11136,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_3_kbest_tree = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_6___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -7542,13 +11149,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree = 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_3_kbest_tree = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_6___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_kbest_tree = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_6___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -7569,12 +11176,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_3_kbest_tree = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_6___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_3_kbest_tree"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_6___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_6___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -7584,24 +11191,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_3_kbest_tree, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_3_kbest_tree, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_3_kbest_tree, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_6___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_6___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_6___iter__, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer___pyx_scope_struct_3_kbest_tree, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_6___iter__, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - __pyx_tp_traverse_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_6___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_6___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_6___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -7611,7 +11218,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_3_kbest_tree, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_6___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -7625,52 +11232,60 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_4_sample(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_7___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)o); + p->__pyx_v_i = 0; p->__pyx_v_self = 0; - p->__pyx_v_sentence = 0; + p->__pyx_t_1 = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_sample(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_7___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)o; + Py_XDECREF(p->__pyx_v_i); Py_XDECREF(((PyObject *)p->__pyx_v_self)); - Py_XDECREF(((PyObject *)p->__pyx_v_sentence)); + Py_XDECREF(p->__pyx_t_1); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_4_sample(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_7___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)o; + if (p->__pyx_v_i) { + e = (*v)(p->__pyx_v_i, a); if (e) return e; + } if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } - if (p->__pyx_v_sentence) { - e = (*v)(p->__pyx_v_sentence, a); if (e) return e; + if (p->__pyx_t_1) { + e = (*v)(p->__pyx_t_1, a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_4_sample(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_7___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__ *)o; PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_i); + p->__pyx_v_i = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SufficientStats *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_sentence); - p->__pyx_v_sentence = ((PyObject*)Py_None); Py_INCREF(Py_None); + tmp = ((PyObject*)p->__pyx_t_1); + p->__pyx_t_1 = Py_None; Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_4_sample[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_7___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4_sample = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_7___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -7728,7 +11343,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_4_sample = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4_sample = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_7___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -7741,13 +11356,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_4_sample = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_4_sample = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_7___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4_sample = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_7___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -7768,12 +11383,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_4_sample = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_sample = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_4_sample"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_4_sample), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_7___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_4_sample, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_7___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -7783,24 +11398,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_sample = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_4_sample, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_4_sample, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_4_sample, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_7___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_7___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_7___iter__, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer___pyx_scope_struct_4_sample, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_7___iter__, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - __pyx_tp_traverse_5_cdec___pyx_scope_struct_4_sample, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_4_sample, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_7___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_7___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_4_sample, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_7___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -7810,7 +11425,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_sample = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_4_sample, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_7___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -7824,44 +11439,60 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_4_sample = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_5___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_8_candidate_set(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *)o); + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)o); + p->__pyx_v_candidate = 0; + p->__pyx_v_hypergraph = 0; p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *)o; +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8_candidate_set(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)o; + Py_XDECREF(((PyObject *)p->__pyx_v_candidate)); + Py_XDECREF(((PyObject *)p->__pyx_v_hypergraph)); Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_5___iter__(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_8_candidate_set(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *)o; + struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)o; + if (p->__pyx_v_candidate) { + e = (*v)(((PyObject*)p->__pyx_v_candidate), a); if (e) return e; + } + if (p->__pyx_v_hypergraph) { + e = (*v)(((PyObject*)p->__pyx_v_hypergraph), a); if (e) return e; + } if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_5___iter__(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__ *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_8_candidate_set(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)o; PyObject* tmp; + tmp = ((PyObject*)p->__pyx_v_candidate); + p->__pyx_v_candidate = ((struct __pyx_obj_5_cdec_Candidate *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->__pyx_v_hypergraph); + p->__pyx_v_hypergraph = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_Lattice *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_5___iter__[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_8_candidate_set[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_5___iter__ = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_8_candidate_set = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -7919,7 +11550,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_5___iter__ = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_5___iter__ = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_8_candidate_set = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -7932,13 +11563,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_5___iter__ = { 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_5___iter__ = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_8_candidate_set = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_5___iter__ = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_8_candidate_set = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -7959,12 +11590,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_5___iter__ = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5___iter__ = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8_candidate_set = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_5___iter__"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_5___iter__), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_8_candidate_set"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_5___iter__, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -7974,24 +11605,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5___iter__ = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_5___iter__, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_5___iter__, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_5___iter__, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_8_candidate_set, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_8_candidate_set, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_8_candidate_set, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer___pyx_scope_struct_5___iter__, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_8_candidate_set, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - __pyx_tp_traverse_5_cdec___pyx_scope_struct_5___iter__, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_5___iter__, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_5___iter__, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -8001,7 +11632,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_5___iter__ = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_5___iter__, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -8039,15 +11670,18 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_11, __pyx_k_11, sizeof(__pyx_k_11), 0, 0, 1, 0}, {&__pyx_kp_s_13, __pyx_k_13, sizeof(__pyx_k_13), 0, 0, 1, 0}, {&__pyx_kp_s_14, __pyx_k_14, sizeof(__pyx_k_14), 0, 0, 1, 0}, + {&__pyx_kp_s_19, __pyx_k_19, sizeof(__pyx_k_19), 0, 0, 1, 0}, {&__pyx_kp_s_2, __pyx_k_2, sizeof(__pyx_k_2), 0, 0, 1, 0}, - {&__pyx_kp_s_21, __pyx_k_21, sizeof(__pyx_k_21), 0, 0, 1, 0}, + {&__pyx_kp_s_23, __pyx_k_23, sizeof(__pyx_k_23), 0, 0, 1, 0}, + {&__pyx_n_s__BLEU, __pyx_k__BLEU, sizeof(__pyx_k__BLEU), 0, 0, 1, 1}, {&__pyx_n_s__Exception, __pyx_k__Exception, sizeof(__pyx_k__Exception), 0, 0, 1, 1}, + {&__pyx_n_s__IBM_BLEU, __pyx_k__IBM_BLEU, sizeof(__pyx_k__IBM_BLEU), 0, 0, 1, 1}, {&__pyx_n_s__IndexError, __pyx_k__IndexError, sizeof(__pyx_k__IndexError), 0, 0, 1, 1}, {&__pyx_n_s__KeyError, __pyx_k__KeyError, sizeof(__pyx_k__KeyError), 0, 0, 1, 1}, {&__pyx_n_s__NotImplemented, __pyx_k__NotImplemented, sizeof(__pyx_k__NotImplemented), 0, 0, 1, 1}, {&__pyx_n_s__ParseFailed, __pyx_k__ParseFailed, sizeof(__pyx_k__ParseFailed), 0, 0, 1, 1}, + {&__pyx_n_s__TER, __pyx_k__TER, sizeof(__pyx_k__TER), 0, 0, 1, 1}, {&__pyx_n_s__TypeError, __pyx_k__TypeError, sizeof(__pyx_k__TypeError), 0, 0, 1, 1}, - {&__pyx_n_s__ValueError, __pyx_k__ValueError, sizeof(__pyx_k__ValueError), 0, 0, 1, 1}, {&__pyx_n_s____enter__, __pyx_k____enter__, sizeof(__pyx_k____enter__), 0, 0, 1, 1}, {&__pyx_n_s____exit__, __pyx_k____exit__, sizeof(__pyx_k____exit__), 0, 0, 1, 1}, {&__pyx_n_s____main__, __pyx_k____main__, sizeof(__pyx_k____main__), 0, 0, 1, 1}, @@ -8059,13 +11693,18 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__density, __pyx_k__density, sizeof(__pyx_k__density), 0, 0, 1, 1}, {&__pyx_n_s__dot, __pyx_k__dot, sizeof(__pyx_k__dot), 0, 0, 1, 1}, {&__pyx_n_s__encode, __pyx_k__encode, sizeof(__pyx_k__encode), 0, 0, 1, 1}, + {&__pyx_n_s__encoding, __pyx_k__encoding, sizeof(__pyx_k__encoding), 0, 0, 1, 1}, {&__pyx_n_s__enumerate, __pyx_k__enumerate, sizeof(__pyx_k__enumerate), 0, 0, 1, 1}, {&__pyx_n_s__eval, __pyx_k__eval, sizeof(__pyx_k__eval), 0, 0, 1, 1}, {&__pyx_n_s__grammar, __pyx_k__grammar, sizeof(__pyx_k__grammar), 0, 0, 1, 1}, + {&__pyx_n_s__hypergraph, __pyx_k__hypergraph, sizeof(__pyx_k__hypergraph), 0, 0, 1, 1}, {&__pyx_n_s__inp, __pyx_k__inp, sizeof(__pyx_k__inp), 0, 0, 1, 1}, + {&__pyx_n_s__k, __pyx_k__k, sizeof(__pyx_k__k), 0, 0, 1, 1}, + {&__pyx_n_s__name, __pyx_k__name, sizeof(__pyx_k__name), 0, 0, 1, 1}, {&__pyx_n_s__open, __pyx_k__open, sizeof(__pyx_k__open), 0, 0, 1, 1}, {&__pyx_n_s__plf, __pyx_k__plf, sizeof(__pyx_k__plf), 0, 0, 1, 1}, {&__pyx_n_s__range, __pyx_k__range, sizeof(__pyx_k__range), 0, 0, 1, 1}, + {&__pyx_n_s__refs, __pyx_k__refs, sizeof(__pyx_k__refs), 0, 0, 1, 1}, {&__pyx_n_s__self, __pyx_k__self, sizeof(__pyx_k__self), 0, 0, 1, 1}, {&__pyx_n_s__sentence, __pyx_k__sentence, sizeof(__pyx_k__sentence), 0, 0, 1, 1}, {&__pyx_n_s__split, __pyx_k__split, sizeof(__pyx_k__split), 0, 0, 1, 1}, @@ -8074,14 +11713,13 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {0, 0, 0, 0, 0, 0, 0} }; static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_Exception = __Pyx_GetName(__pyx_b, __pyx_n_s__Exception); if (!__pyx_builtin_Exception) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_Exception = __Pyx_GetName(__pyx_b, __pyx_n_s__Exception); if (!__pyx_builtin_Exception) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_ValueError = __Pyx_GetName(__pyx_b, __pyx_n_s__ValueError); if (!__pyx_builtin_ValueError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_NotImplemented = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplemented); if (!__pyx_builtin_NotImplemented) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_eval = __Pyx_GetName(__pyx_b, __pyx_n_s__eval); if (!__pyx_builtin_eval) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_eval = __Pyx_GetName(__pyx_b, __pyx_n_s__eval); if (!__pyx_builtin_eval) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_open = __Pyx_GetName(__pyx_b, __pyx_n_s__open); if (!__pyx_builtin_open) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} return 0; @@ -8095,7 +11733,7 @@ static int __Pyx_InitCachedConstants(void) { /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":69 * elif op == 3: # != - * return not (self == other) + * return not (x == y) * raise NotImplemented('comparison not implemented for SparseVector') # <<<<<<<<<<<<<< * * def __len__(self): @@ -8177,14 +11815,14 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_8)); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":65 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":78 * for k in range(hypos.size()): * sentence = GetString(hypos[0][k].words).c_str() * yield sentence.decode('utf8') # <<<<<<<<<<<<<< * del hypos * */ - __pyx_k_tuple_9 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_9 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_9); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); PyTuple_SET_ITEM(__pyx_k_tuple_9, 0, ((PyObject *)__pyx_n_s__utf8)); @@ -8261,6 +11899,20 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_18)); + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":6 + * cdef bytes ret + * if isinstance(sentence, unicode): + * ret = sentence.encode('utf8') # <<<<<<<<<<<<<< + * elif isinstance(sentence, str): + * ret = sentence + */ + __pyx_k_tuple_20 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_20); + __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_20, 0, ((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20)); + /* "_cdec.pyx":31 * * def read_weights(self, cfg): @@ -8268,18 +11920,18 @@ static int __Pyx_InitCachedConstants(void) { * for line in fp: * fname, value = line.split() */ - __pyx_k_tuple_19 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_19); + __pyx_k_tuple_21 = PyTuple_New(3); if (unlikely(!__pyx_k_tuple_21)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_21); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_19, 0, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_21, 0, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_19, 1, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_21, 1, Py_None); __Pyx_GIVEREF(Py_None); __Pyx_INCREF(Py_None); - PyTuple_SET_ITEM(__pyx_k_tuple_19, 2, Py_None); + PyTuple_SET_ITEM(__pyx_k_tuple_21, 2, Py_None); __Pyx_GIVEREF(Py_None); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_19)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_21)); /* "_cdec.pyx":38 * def translate(self, sentence, grammar=None): @@ -8288,12 +11940,37 @@ static int __Pyx_InitCachedConstants(void) { * elif isinstance(sentence, str): * inp = sentence.strip() */ - __pyx_k_tuple_20 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_20)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_k_tuple_20); + __pyx_k_tuple_22 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_22); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); - PyTuple_SET_ITEM(__pyx_k_tuple_20, 0, ((PyObject *)__pyx_n_s__utf8)); + PyTuple_SET_ITEM(__pyx_k_tuple_22, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); - __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_20)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 + * return self.name.c_str() + * + * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< + * TER = Scorer('TER') + */ + __pyx_k_tuple_24 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_24); + __Pyx_INCREF(((PyObject *)__pyx_n_s__IBM_BLEU)); + PyTuple_SET_ITEM(__pyx_k_tuple_24, 0, ((PyObject *)__pyx_n_s__IBM_BLEU)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IBM_BLEU)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_24)); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":116 + * + * BLEU = Scorer('IBM_BLEU') + * TER = Scorer('TER') # <<<<<<<<<<<<<< + */ + __pyx_k_tuple_25 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_k_tuple_25); + __Pyx_INCREF(((PyObject *)__pyx_n_s__TER)); + PyTuple_SET_ITEM(__pyx_k_tuple_25, 0, ((PyObject *)__pyx_n_s__TER)); + __Pyx_GIVEREF(((PyObject *)__pyx_n_s__TER)); + __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_25)); __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -8389,6 +12066,18 @@ PyMODINIT_FUNC PyInit__cdec(void) if (PyType_Ready(&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Lattice", (PyObject *)&__pyx_type_5_cdec_Lattice) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Lattice = &__pyx_type_5_cdec_Lattice; + if (PyType_Ready(&__pyx_type_5_cdec_Candidate) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Candidate", (PyObject *)&__pyx_type_5_cdec_Candidate) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_Candidate = &__pyx_type_5_cdec_Candidate; + if (PyType_Ready(&__pyx_type_5_cdec_SufficientStats) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "SufficientStats", (PyObject *)&__pyx_type_5_cdec_SufficientStats) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_SufficientStats = &__pyx_type_5_cdec_SufficientStats; + if (PyType_Ready(&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "SegmentEvaluator", (PyObject *)&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_SegmentEvaluator = &__pyx_type_5_cdec_SegmentEvaluator; + if (PyType_Ready(&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Scorer", (PyObject *)&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_Scorer = &__pyx_type_5_cdec_Scorer; if (PyType_Ready(&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Decoder", (PyObject *)&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Decoder = &__pyx_type_5_cdec_Decoder; @@ -8400,42 +12089,69 @@ PyMODINIT_FUNC PyInit__cdec(void) __pyx_ptype_5_cdec___pyx_scope_struct_2_kbest = &__pyx_type_5_cdec___pyx_scope_struct_2_kbest; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_tree = &__pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_4_sample) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_4_sample = &__pyx_type_5_cdec___pyx_scope_struct_4_sample; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_5___iter__) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_5___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_5___iter__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_4_kbest_features) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features = &__pyx_type_5_cdec___pyx_scope_struct_4_kbest_features; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_5_sample) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_5_sample = &__pyx_type_5_cdec___pyx_scope_struct_5_sample; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_6___iter__) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_6___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_6___iter__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_7___iter__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_7___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_7___iter__; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_8_candidate_set) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_8_candidate_set = &__pyx_type_5_cdec___pyx_scope_struct_8_candidate_set; /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ /*--- Execution code ---*/ - /* "_cdec.pyx":10 - * include "lattice.pxi" + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 + * return self.name.c_str() + * + * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< + * TER = Scorer('TER') + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":116 + * + * BLEU = Scorer('IBM_BLEU') + * TER = Scorer('TER') # <<<<<<<<<<<<<< + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "_cdec.pyx":11 + * include "mteval.pxi" * * SetSilent(True) # <<<<<<<<<<<<<< * - * class ParseFailed(Exception): + * class ParseFailed(Exception): pass */ SetSilent(1); - /* "_cdec.pyx":12 + /* "_cdec.pyx":13 * SetSilent(True) * - * class ParseFailed(Exception): # <<<<<<<<<<<<<< - * pass + * class ParseFailed(Exception): pass # <<<<<<<<<<<<<< * + * cdef class Decoder: */ - __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_builtin_Exception); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_builtin_Exception); __Pyx_GIVEREF(__pyx_builtin_Exception); - __pyx_t_3 = __Pyx_CreateClass(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1), __pyx_n_s__ParseFailed, __pyx_n_s___cdec); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_CreateClass(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1), __pyx_n_s__ParseFailed, __pyx_n_s___cdec); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__ParseFailed, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__ParseFailed, __pyx_t_3) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; @@ -8673,6 +12389,18 @@ static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed return 0; } +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { + if (unlikely(!type)) { + PyErr_Format(PyExc_SystemError, "Missing type object"); + return 0; + } + if (likely(PyObject_TypeCheck(obj, type))) + return 1; + PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", + Py_TYPE(obj)->tp_name, type->tp_name); + return 0; +} + static void __Pyx_RaiseDoubleKeywordsError( const char* func_name, PyObject* kw_name) @@ -8889,18 +12617,6 @@ bad: return -1; } -static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { - if (unlikely(!type)) { - PyErr_Format(PyExc_SystemError, "Missing type object"); - return 0; - } - if (likely(PyObject_TypeCheck(obj, type))) - return 1; - PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", - Py_TYPE(obj)->tp_name, type->tp_name); - return 0; -} - static CYTHON_INLINE void __Pyx_ExceptionSave(PyObject **type, PyObject **value, PyObject **tb) { PyThreadState *tstate = PyThreadState_GET(); *type = tstate->exc_type; @@ -9693,6 +13409,25 @@ static int __pyx_Generator_init(void) return PyType_Ready(&__pyx_GeneratorType); } +static void __Pyx_WriteUnraisable(const char *name, int clineno, + int lineno, const char *filename) { + PyObject *old_exc, *old_val, *old_tb; + PyObject *ctx; + __Pyx_ErrFetch(&old_exc, &old_val, &old_tb); + #if PY_MAJOR_VERSION < 3 + ctx = PyString_FromString(name); + #else + ctx = PyUnicode_FromString(name); + #endif + __Pyx_ErrRestore(old_exc, old_val, old_tb); + if (!ctx) { + PyErr_WriteUnraisable(Py_None); + } else { + PyErr_WriteUnraisable(ctx); + Py_DECREF(ctx); + } +} + static int __Pyx_check_binary_version(void) { char ctversion[4], rtversion[4]; PyOS_snprintf(ctversion, 4, "%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION); diff --git a/python/src/_cdec.pyx b/python/src/_cdec.pyx index 698a66f6..6fafbbc0 100644 --- a/python/src/_cdec.pyx +++ b/python/src/_cdec.pyx @@ -6,11 +6,11 @@ cimport decoder include "vectors.pxi" include "hypergraph.pxi" include "lattice.pxi" +include "mteval.pxi" SetSilent(True) -class ParseFailed(Exception): - pass +class ParseFailed(Exception): pass cdef class Decoder: cdef decoder.Decoder* dec diff --git a/python/src/hypergraph.pxi b/python/src/hypergraph.pxi index c226d105..ce78b729 100644 --- a/python/src/hypergraph.pxi +++ b/python/src/hypergraph.pxi @@ -53,6 +53,19 @@ cdef class Hypergraph: yield tree.decode('utf8') del derivations + def kbest_features(self, size): + cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) + cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal].Derivation* derivation + cdef SparseVector fmap + cdef unsigned k + for k in range(size): + derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + if not derivation: break + fmap = SparseVector() + fmap.vector = new FastSparseVector[weight_t](derivation._yield) + yield fmap + del derivations + def sample(self, unsigned n): cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() if self.rng == NULL: @@ -87,6 +100,6 @@ cdef class Hypergraph: elif isinstance(weights, DenseVector): self.hg.Reweight(( weights).vector[0]) else: - raise ValueError('cannot reweight hypergraph with %s' % type(weights)) + raise TypeError('cannot reweight hypergraph with %s' % type(weights)) # TODO get feature expectations, get partition function ("inside" score) diff --git a/python/src/kbest.pxd b/python/src/kbest.pxd index f34ac5ed..cef42bd3 100644 --- a/python/src/kbest.pxd +++ b/python/src/kbest.pxd @@ -9,6 +9,8 @@ cdef extern from "decoder/viterbi.h": pass cdef cppclass FTreeTraversal: pass + cdef cppclass FeatureVectorTraversal: + pass cdef extern from "decoder/kbest.h" namespace "KBest": cdef cppclass KBestDerivations[T, Traversal]: diff --git a/python/src/mteval.pxd b/python/src/mteval.pxd new file mode 100644 index 00000000..52af6297 --- /dev/null +++ b/python/src/mteval.pxd @@ -0,0 +1,47 @@ +from libcpp.vector cimport vector +from libcpp.string cimport string +from utils cimport * +from hypergraph cimport Hypergraph + +cdef extern from "mteval/ns.h": + cdef cppclass SufficientStats: + SufficientStats() + SufficientStats(SufficientStats&) + unsigned size() + float operator[](unsigned i) + void swap(SufficientStats& other) + + SufficientStats add "operator+" (SufficientStats&, SufficientStats&) + + cdef cppclass SegmentEvaluator: + void Evaluate(vector[WordID]& hyp, SufficientStats* out) + + cdef cppclass EvaluationMetric: + string& MetricId() + bint IsErrorMetric() + float ComputeScore(SufficientStats& stats) + string DetailedScore(SufficientStats& stats) + shared_ptr[SegmentEvaluator] CreateSegmentEvaluator(vector[vector[WordID]]& refs) + ComputeSufficientStatistics(vector[WordID]& hyp, + vector[WordID]& refs, + SufficientStats* out) + +cdef extern from "mteval/ns.h" namespace "EvaluationMetric": + EvaluationMetric* Instance(string& metric_id) + EvaluationMetric* Instance() # IBM_BLEU + +cdef extern from "training/candidate_set.h" namespace "training": + cdef cppclass Candidate "const training::Candidate": + vector[WordID] ewords + FastSparseVector[weight_t] fmap + SufficientStats eval_feats + + cdef cppclass CandidateSet: + CandidateSet() + unsigned size() + Candidate& operator[](unsigned i) + void ReadFromFile(string& file) + void WriteToFile(string& file) + void AddKBestCandidates(Hypergraph& hg, + unsigned kbest_size, + SegmentEvaluator* scorer) diff --git a/python/src/mteval.pxi b/python/src/mteval.pxi new file mode 100644 index 00000000..dabdf927 --- /dev/null +++ b/python/src/mteval.pxi @@ -0,0 +1,116 @@ +cimport mteval + +cdef char* as_str(sentence, error_msg='Cannot convert type %s to str'): + cdef bytes ret + if isinstance(sentence, unicode): + ret = sentence.encode('utf8') + elif isinstance(sentence, str): + ret = sentence + else: + raise TypeError(error_msg % type(sentence)) + return ret + +cdef class Candidate: + cdef mteval.Candidate* candidate + cdef public float score + + property words: + def __get__(self): + return unicode(GetString(self.candidate.ewords).c_str(), encoding='utf8') + + property fmap: + def __get__(self): + cdef SparseVector fmap = SparseVector() + fmap.vector = new FastSparseVector[weight_t](self.candidate.fmap) + return fmap + +cdef class SufficientStats: + cdef mteval.SufficientStats* stats + cdef mteval.EvaluationMetric* metric + + def __dealloc__(self): + del self.stats + + property score: + def __get__(self): + return self.metric.ComputeScore(self.stats[0]) + + property detail: + def __get__(self): + return self.metric.DetailedScore(self.stats[0]).c_str() + + def __len__(self): + return self.stats.size() + + def __iter__(self): + for i in range(len(self)): + yield self.stats[0][i] + + def __iadd__(SufficientStats self, SufficientStats other): + self.stats[0] += other.stats[0] + return self + + def __add__(SufficientStats x, SufficientStats y): + cdef SufficientStats result = SufficientStats() + result.stats = new mteval.SufficientStats(mteval.add(x.stats[0], y.stats[0])) + result.metric = x.metric + return result + +cdef class SegmentEvaluator: + cdef shared_ptr[mteval.SegmentEvaluator]* scorer + cdef mteval.EvaluationMetric* metric + + def __dealloc__(self): + del self.scorer + + def evaluate(self, sentence): + cdef vector[WordID] hyp + cdef SufficientStats sf = SufficientStats() + sf.metric = self.metric + sf.stats = new mteval.SufficientStats() + ConvertSentence(string(as_str(sentence.strip())), &hyp) + self.scorer.get().Evaluate(hyp, sf.stats) + return sf + + def candidate_set(self, Hypergraph hypergraph, unsigned k): + cdef mteval.CandidateSet* cs = new mteval.CandidateSet() + cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) + cdef Candidate candidate + cdef unsigned i + for i in range(cs.size()): + candidate = Candidate() + candidate.candidate = &cs[0][i] + candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) + yield candidate + del cs + +cdef class Scorer: + cdef string* name + + def __cinit__(self, char* name): + self.name = new string(name) + + def __call__(self, refs): + cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) + if isinstance(refs, unicode) or isinstance(refs, str): + refs = [refs] + cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() + cdef vector[WordID]* refv + cdef bytes ref_str + for ref in refs: + refv = new vector[WordID]() + ConvertSentence(string(as_str(ref.strip())), refv) + refsv.push_back(refv[0]) + del refv + cdef unsigned i + cdef SegmentEvaluator evaluator = SegmentEvaluator() + evaluator.metric = metric + evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) + del refsv # in theory should not delete but store in SegmentEvaluator + return evaluator + + def __str__(self): + return self.name.c_str() + +BLEU = Scorer('IBM_BLEU') +TER = Scorer('TER') diff --git a/python/src/utils.pxd b/python/src/utils.pxd index 3d518524..94fab5ef 100644 --- a/python/src/utils.pxd +++ b/python/src/utils.pxd @@ -50,16 +50,19 @@ cdef extern from "utils/sparse_vector.h": FastSparseVector[weight_t] operator+(FastSparseVector[weight_t]&, FastSparseVector[weight_t]&) FastSparseVector[weight_t] operator-(FastSparseVector[weight_t]&, FastSparseVector[weight_t]&) + FastSparseVector[weight_t] operator*(FastSparseVector[weight_t]&, double&) + FastSparseVector[weight_t] operator/(FastSparseVector[weight_t]&, double&) ostream operator<<(ostream& out, FastSparseVector[weight_t]& v) cdef extern from "utils/weights.h" namespace "Weights": void InitSparseVector(vector[weight_t]& dv, FastSparseVector[weight_t]* sv) -cdef extern from "utils/tdict.cc" namespace "TD": +cdef extern from "utils/tdict.h" namespace "TD": string GetString(vector[WordID]& st) unsigned NumWords() WordID TDConvert "TD::Convert" (char*) char* TDConvert "TD::Convert" (WordID) + void ConvertSentence(string& sent, vector[WordID]* ids) cdef extern from "utils/verbose.h": void SetSilent(bint) @@ -76,3 +79,8 @@ cdef extern from "utils/filelib.h": cdef extern from "utils/sampler.h": cdef cppclass MT19937: pass + +cdef extern from "" namespace "boost": + cdef cppclass shared_ptr[T]: + shared_ptr(shared_ptr& r) + T* get() diff --git a/python/src/vectors.pxi b/python/src/vectors.pxi index 74d3a0bd..233c9530 100644 --- a/python/src/vectors.pxi +++ b/python/src/vectors.pxi @@ -53,7 +53,7 @@ cdef class SparseVector: return self.vector.dot(( other).vector[0]) elif isinstance(other, SparseVector): return self.vector.dot(( other).vector[0]) - raise ValueError('cannot take the dot product of %s and SparseVector' % type(other)) + raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) def todense(self): cdef DenseVector dense = DenseVector() @@ -61,11 +61,11 @@ cdef class SparseVector: self.vector.init_vector(dense.vector) return dense - def __richcmp__(SparseVector self, SparseVector other, int op): + def __richcmp__(SparseVector x, SparseVector y, int op): if op == 2: # == - return self.vector[0] == other.vector[0] + return x.vector[0] == y.vector[0] elif op == 3: # != - return not (self == other) + return not (x == y) raise NotImplemented('comparison not implemented for SparseVector') def __len__(self): @@ -90,12 +90,30 @@ cdef class SparseVector: self.vector[0] /= scalar return self - def __add__(SparseVector self, SparseVector other): + def __add__(SparseVector x, SparseVector y): cdef SparseVector result = SparseVector() - result.vector = new FastSparseVector[weight_t](self.vector[0] + other.vector[0]) + result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) return result - def __sub__(SparseVector self, SparseVector other): + def __sub__(SparseVector x, SparseVector y): cdef SparseVector result = SparseVector() - result.vector = new FastSparseVector[weight_t](self.vector[0] - other.vector[0]) + result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) + return result + + def __mul__(x, y): + cdef SparseVector vector + cdef float scalar + if isinstance(x, SparseVector): vector, scalar = x, y + else: vector, scalar = y, x + cdef SparseVector result = SparseVector() + result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) + return result + + def __div__(x, y): + cdef SparseVector vector + cdef float scalar + if isinstance(x, SparseVector): vector, scalar = x, y + else: vector, scalar = y, x + cdef SparseVector result = SparseVector() + result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) return result diff --git a/python/test.py b/python/test.py index 92403298..b3900eef 100644 --- a/python/test.py +++ b/python/test.py @@ -31,9 +31,11 @@ print ' FTree[0]:', forest.viterbi_source_tree().encode('utf8') print 'LgProb[0]:', forest.viterbi_features().dot(decoder.weights) # Get k-best translations -for i, (sentence, tree) in enumerate(zip(forest.kbest(5), forest.kbest_tree(5)), 1): +kbest = zip(forest.kbest(5), forest.kbest_tree(5), forest.kbest_features(5)) +for i, (sentence, tree, features) in enumerate(kbest, 1): print 'Output[%d]:' % i, sentence.encode('utf8') print ' Tree[%d]:' % i, tree.encode('utf8') + print ' FVect[%d]:' % i, dict(features) # Sample translations from the forest for sentence in forest.sample(5): -- cgit v1.2.3 From 5584ad22d3d3fae7ea195fe6cd7cf56cd0f35ba0 Mon Sep 17 00:00:00 2001 From: Waleed Ammar Date: Mon, 2 Jul 2012 16:51:21 -0400 Subject: (1) allow prefixes and separators used in feature instantiations to be configured. (2) minor refactoring. --- decoder/ff_ngrams.cc | 85 ++++++++++++++++++++++++++++++++++++++++++++-------- decoder/ff_ngrams.h | 2 +- 2 files changed, 73 insertions(+), 14 deletions(-) diff --git a/decoder/ff_ngrams.cc b/decoder/ff_ngrams.cc index d6d79f5e..9c13fdbb 100644 --- a/decoder/ff_ngrams.cc +++ b/decoder/ff_ngrams.cc @@ -48,6 +48,9 @@ struct State { namespace { string Escape(const string& x) { + if (x.find('=') == string::npos && x.find(';') == string::npos) { + return x; + } string y = x; for (int i = 0; i < y.size(); ++i) { if (y[i] == '=') y[i]='_'; @@ -57,10 +60,17 @@ namespace { } } -static bool ParseArgs(string const& in, bool* explicit_markers, unsigned* order) { +static bool ParseArgs(string const& in, bool* explicit_markers, unsigned* order, vector& prefixes, string& target_separator) { vector const& argv=SplitOnWhitespace(in); *explicit_markers = false; *order = 3; + prefixes.push_back("NOT-USED"); + prefixes.push_back("U:"); // default unigram prefix + prefixes.push_back("B:"); // default bigram prefix + prefixes.push_back("T:"); // ...etc + prefixes.push_back("4:"); // ...etc + prefixes.push_back("5:"); // max allowed! + target_separator = "_"; #define LMSPEC_NEXTARG if (i==argv.end()) { \ cerr << "Missing argument for "<<*last<<". "; goto usage; \ } else { ++i; } @@ -73,6 +83,30 @@ static bool ParseArgs(string const& in, bool* explicit_markers, unsigned* order) case 'x': *explicit_markers = true; break; + case 'U': + LMSPEC_NEXTARG; + prefixes[1] = *i; + break; + case 'B': + LMSPEC_NEXTARG; + prefixes[2] = *i; + break; + case 'T': + LMSPEC_NEXTARG; + prefixes[3] = *i; + break; + case '4': + LMSPEC_NEXTARG; + prefixes[4] = *i; + break; + case '5': + LMSPEC_NEXTARG; + prefixes[5] = *i; + break; + case 'S': + LMSPEC_NEXTARG; + target_separator = *i; + break; case 'o': LMSPEC_NEXTARG; *order=atoi((*i).c_str()); break; @@ -86,7 +120,29 @@ static bool ParseArgs(string const& in, bool* explicit_markers, unsigned* order) } return true; usage: - cerr << "NgramFeatures is incorrect!\n"; + cerr << "Wrong parameters for NgramFeatures.\n\n" + + << "NgramFeatures Usage: \n" + << " feature_function=NgramFeatures filename.lm [-x] [-o ] \n" + << " [-U ] [-B ][-T ]\n" + << " [-4 <4-gram-prefix>] [-5 <5-gram-prefix>] [-S ]\n\n" + + << "Defaults: \n" + << " = 3\n" + << " = U:\n" + << " = B:\n" + << " = T:\n" + << " <4-gram-prefix> = 4:\n" + << " <5-gram-prefix> = 5:\n" + << " = _\n" + << " -x (i.e. explicit sos/eos markers) is turned off\n\n" + + << "Example configuration: \n" + << " feature_function=NgramFeatures -o 3 -T tri: -S |\n\n" + + << "Example feature instantiation: \n" + << " tri:a|b|c \n\n"; + return false; } @@ -158,16 +214,12 @@ class NgramDetectorImpl { int& fid = ft->fids[curword]; ++n; if (!fid) { - const char* code="_UBT456789"; // prefix code (unigram, bigram, etc.) ostringstream os; - os << code[n] << ':'; + os << prefixes_[n]; for (int i = n-1; i >= 0; --i) { - os << (i != n-1 ? "_" : ""); + os << (i != n-1 ? target_separator_ : ""); const string& tok = TD::Convert(buf[i]); - if (tok.find('=') == string::npos) - os << tok; - else - os << Escape(tok); + os << Escape(tok); } fid = FD::Convert(os.str()); } @@ -297,7 +349,8 @@ class NgramDetectorImpl { } public: - explicit NgramDetectorImpl(bool explicit_markers, unsigned order) : + explicit NgramDetectorImpl(bool explicit_markers, unsigned order, + vector& prefixes, string& target_separator) : kCDEC_UNK(TD::Convert("")) , add_sos_eos_(!explicit_markers) { order_ = order; @@ -305,6 +358,8 @@ class NgramDetectorImpl { unscored_size_offset_ = (order_ - 1) * sizeof(WordID); is_complete_offset_ = unscored_size_offset_ + 1; unscored_words_offset_ = is_complete_offset_ + 1; + prefixes_ = prefixes; + target_separator_ = target_separator; // special handling of beginning / ending sentence markers dummy_state_ = new char[state_size_]; @@ -340,6 +395,8 @@ class NgramDetectorImpl { char* dummy_state_; vector dummy_ants_; TRulePtr dummy_rule_; + vector prefixes_; + string target_separator_; struct FidTree { map fids; map levels; @@ -348,11 +405,13 @@ class NgramDetectorImpl { }; NgramDetector::NgramDetector(const string& param) { - string filename, mapfile, featname; + string filename, mapfile, featname, target_separator; + vector prefixes; bool explicit_markers = false; unsigned order = 3; - ParseArgs(param, &explicit_markers, &order); - pimpl_ = new NgramDetectorImpl(explicit_markers, order); + ParseArgs(param, &explicit_markers, &order, prefixes, target_separator); + pimpl_ = new NgramDetectorImpl(explicit_markers, order, prefixes, + target_separator); SetStateSize(pimpl_->ReserveStateSize()); } diff --git a/decoder/ff_ngrams.h b/decoder/ff_ngrams.h index 82f61b33..064dbb49 100644 --- a/decoder/ff_ngrams.h +++ b/decoder/ff_ngrams.h @@ -10,7 +10,7 @@ struct NgramDetectorImpl; class NgramDetector : public FeatureFunction { public: - // param = "filename.lm [-o n]" + // param = "filename.lm [-o ] [-U ] [-B ] [-T ] [-4 <4-gram-prefix>] [-5 <5-gram-prefix>] [-S ] NgramDetector(const std::string& param); ~NgramDetector(); virtual void FinalTraversalFeatures(const void* context, -- cgit v1.2.3 From 7937972d2478a3b377930a30b77b07d2e6e902ba Mon Sep 17 00:00:00 2001 From: Victor Chahuneau Date: Mon, 2 Jul 2012 17:05:08 -0400 Subject: [python] Explicit candidate set; memory leak fixes --- python/src/_cdec.cpp | 3321 ++++++++++++++++++++++++++++----------------- python/src/hypergraph.pxi | 58 +- python/src/mteval.pxi | 47 +- python/src/vectors.pxi | 41 +- python/test.py | 3 + training/candidate_set.cc | 9 +- 6 files changed, 2215 insertions(+), 1264 deletions(-) diff --git a/python/src/_cdec.cpp b/python/src/_cdec.cpp index 7d45e27f..bc522b32 100644 --- a/python/src/_cdec.cpp +++ b/python/src/_cdec.cpp @@ -1,4 +1,4 @@ -/* Generated by Cython 0.16 on Sun Jul 1 00:36:19 2012 */ +/* Generated by Cython 0.16 on Mon Jul 2 17:01:11 2012 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -389,12 +389,12 @@ static const char *__pyx_f[] = { /*--- Type declarations ---*/ struct __pyx_obj_5_cdec_Scorer; +struct __pyx_obj_5_cdec_CandidateSet; struct __pyx_obj_5_cdec_SufficientStats; struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__; struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features; struct __pyx_obj_5_cdec___pyx_scope_struct_3_kbest_tree; struct __pyx_obj_5_cdec_Decoder; -struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set; struct __pyx_obj_5_cdec_SegmentEvaluator; struct __pyx_obj_5_cdec_SparseVector; struct __pyx_obj_5_cdec_Hypergraph; @@ -405,6 +405,7 @@ struct __pyx_obj_5_cdec_Candidate; struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample; struct __pyx_obj_5_cdec_DenseVector; struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__; +struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__; struct __pyx_obj_5_cdec___pyx_scope_struct_7___iter__; struct __pyx_opt_args_5_cdec_as_str; @@ -420,8 +421,8 @@ struct __pyx_opt_args_5_cdec_as_str { PyObject *error_msg; }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":87 - * del cs +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":109 + * return CandidateSet(self) * * cdef class Scorer: # <<<<<<<<<<<<<< * cdef string* name @@ -433,6 +434,21 @@ struct __pyx_obj_5_cdec_Scorer { }; +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":59 + * return result + * + * cdef class CandidateSet: # <<<<<<<<<<<<<< + * cdef shared_ptr[mteval.SegmentEvaluator]* scorer + * cdef mteval.EvaluationMetric* metric + */ +struct __pyx_obj_5_cdec_CandidateSet { + PyObject_HEAD + boost::shared_ptr *scorer; + EvaluationMetric *metric; + training::CandidateSet *cs; +}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":27 * return fmap * @@ -447,16 +463,15 @@ struct __pyx_obj_5_cdec_SufficientStats { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":43 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":55 * self.vector.set_value(fid, value) * * def __iter__(self): # <<<<<<<<<<<<<< * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) - * cdef str fname + * try: */ struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ { PyObject_HEAD - PyObject *__pyx_v_fname; size_t __pyx_v_i; FastSparseVector::const_iterator *__pyx_v_it; struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self; @@ -465,8 +480,8 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":60 + * del derivations * * def kbest_features(self, size): # <<<<<<<<<<<<<< * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) @@ -485,8 +500,8 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_4_kbest_features { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":44 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":46 + * del derivations * * def kbest_tree(self, size): # <<<<<<<<<<<<<< * cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ETreeTraversal](self.hg[0], size) @@ -519,28 +534,8 @@ struct __pyx_obj_5_cdec_Decoder { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":75 - * return sf - * - * def candidate_set(self, Hypergraph hypergraph, unsigned k): # <<<<<<<<<<<<<< - * cdef mteval.CandidateSet* cs = new mteval.CandidateSet() - * cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) - */ -struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set { - PyObject_HEAD - struct __pyx_obj_5_cdec_Candidate *__pyx_v_candidate; - training::CandidateSet *__pyx_v_cs; - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph; - unsigned int __pyx_v_i; - unsigned int __pyx_v_k; - struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self; - unsigned int __pyx_t_0; - unsigned int __pyx_t_1; -}; - - -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":59 - * return result +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":90 + * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) * * cdef class SegmentEvaluator: # <<<<<<<<<<<<<< * cdef shared_ptr[mteval.SegmentEvaluator]* scorer @@ -553,7 +548,7 @@ struct __pyx_obj_5_cdec_SegmentEvaluator { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":32 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":36 * return sparse * * cdef class SparseVector: # <<<<<<<<<<<<<< @@ -593,7 +588,7 @@ struct __pyx_obj_5_cdec_Lattice { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":18 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":22 * self.vector[0][fid] = value * * def __iter__(self): # <<<<<<<<<<<<<< @@ -643,8 +638,8 @@ struct __pyx_obj_5_cdec_Candidate { }; -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":69 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":75 + * del derivations * * def sample(self, unsigned n): # <<<<<<<<<<<<<< * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() @@ -666,7 +661,7 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_5_sample { * from cython.operator cimport preincrement as pinc * * cdef class DenseVector: # <<<<<<<<<<<<<< - * cdef vector[weight_t]* vector + * cdef vector[weight_t]* vector # Not owned by DenseVector * */ struct __pyx_obj_5_cdec_DenseVector { @@ -691,6 +686,22 @@ struct __pyx_obj_5_cdec___pyx_scope_struct_6___iter__ { }; +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 + * return candidate + * + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(len(self)): + */ +struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ { + PyObject_HEAD + unsigned int __pyx_v_i; + struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self; + Py_ssize_t __pyx_t_0; + unsigned int __pyx_t_1; +}; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":45 * return self.stats.size() * @@ -989,6 +1000,7 @@ static PyTypeObject *__pyx_ptype_5_cdec_Hypergraph = 0; static PyTypeObject *__pyx_ptype_5_cdec_Lattice = 0; static PyTypeObject *__pyx_ptype_5_cdec_Candidate = 0; static PyTypeObject *__pyx_ptype_5_cdec_SufficientStats = 0; +static PyTypeObject *__pyx_ptype_5_cdec_CandidateSet = 0; static PyTypeObject *__pyx_ptype_5_cdec_SegmentEvaluator = 0; static PyTypeObject *__pyx_ptype_5_cdec_Scorer = 0; static PyTypeObject *__pyx_ptype_5_cdec_Decoder = 0; @@ -1000,7 +1012,7 @@ static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_5_sample = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_6___iter__ = 0; static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_7___iter__ = 0; -static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_8_candidate_set = 0; +static PyTypeObject *__pyx_ptype_5_cdec___pyx_scope_struct_8___iter__ = 0; static char *__pyx_f_5_cdec_as_str(PyObject *, struct __pyx_opt_args_5_cdec_as_str *__pyx_optional_args); /*proto*/ #define __Pyx_MODULE_NAME "_cdec" int __pyx_module_is_main__cdec = 0; @@ -1015,30 +1027,32 @@ static PyObject *__pyx_builtin_eval; static PyObject *__pyx_builtin_enumerate; static PyObject *__pyx_builtin_IndexError; static PyObject *__pyx_builtin_open; -static PyObject *__pyx_pf_5_cdec_11DenseVector___getitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ -static int __pyx_pf_5_cdec_11DenseVector_2__setitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value); /* proto */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_4__iter__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_7dot(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_9tosparse(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector___getitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ -static int __pyx_pf_5_cdec_12SparseVector_2__setitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_4__iter__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, PyObject *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_9todense(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y, int __pyx_v_op); /* proto */ -static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_13__len__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ -static int __pyx_pf_5_cdec_12SparseVector_15__contains__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_17__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_19__isub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_21__imul__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ +static Py_ssize_t __pyx_pf_5_cdec_11DenseVector___len__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_11DenseVector_2__getitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ +static int __pyx_pf_5_cdec_11DenseVector_4__setitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value); /* proto */ +static PyObject *__pyx_pf_5_cdec_11DenseVector_6__iter__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_11DenseVector_9dot(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_11DenseVector_11tosparse(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self); /* proto */ +static void __pyx_pf_5_cdec_12SparseVector___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_2copy(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_4__getitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ +static int __pyx_pf_5_cdec_12SparseVector_6__setitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_8__iter__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, PyObject *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y, int __pyx_v_op); /* proto */ +static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_15__len__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self); /* proto */ +static int __pyx_pf_5_cdec_12SparseVector_17__contains__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_19__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_21__isub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_23__imul__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pf_5_cdec_12SparseVector_23__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_25__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar); /* proto */ #endif -static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_29__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_27__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_29__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_31__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pf_5_cdec_12SparseVector_31__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ +static PyObject *__pyx_pf_5_cdec_12SparseVector_33__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /* proto */ #endif static void __pyx_pf_5_cdec_10Hypergraph___dealloc__(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_10Hypergraph_2viterbi(struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_self); /* proto */ @@ -1071,12 +1085,19 @@ static Py_ssize_t __pyx_pf_5_cdec_15SufficientStats_2__len__(struct __pyx_obj_5_ static PyObject *__pyx_pf_5_cdec_15SufficientStats_4__iter__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_15SufficientStats_7__iadd__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_self, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_other); /* proto */ static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_x, struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_y); /* proto */ +static int __pyx_pf_5_cdec_12CandidateSet___cinit__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator); /* proto */ +static void __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self); /* proto */ +static Py_ssize_t __pyx_pf_5_cdec_12CandidateSet_4__len__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, unsigned int __pyx_v_k); /* proto */ +static PyObject *__pyx_pf_5_cdec_12CandidateSet_8__iter__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_12CandidateSet_11add_kbest(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph, unsigned int __pyx_v_k); /* proto */ static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, PyObject *__pyx_v_sentence); /* proto */ -static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph, unsigned int __pyx_v_k); /* proto */ +static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self); /* proto */ static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, char *__pyx_v_name); /* proto */ -static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs); /* proto */ -static PyObject *__pyx_pf_5_cdec_6Scorer_4__str__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self); /* proto */ +static void __pyx_pf_5_cdec_6Scorer_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Scorer *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs); /* proto */ +static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self); /* proto */ static int __pyx_pf_5_cdec_7Decoder___cinit__(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, char *__pyx_v_config); /* proto */ static void __pyx_pf_5_cdec_7Decoder_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Decoder *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_5_cdec_7Decoder_4read_weights(struct __pyx_obj_5_cdec_Decoder *__pyx_v_self, PyObject *__pyx_v_cfg); /* proto */ @@ -1124,6 +1145,7 @@ static char __pyx_k__Exception[] = "Exception"; static char __pyx_k__TypeError[] = "TypeError"; static char __pyx_k____enter__[] = "__enter__"; static char __pyx_k__enumerate[] = "enumerate"; +static char __pyx_k__evaluator[] = "evaluator"; static char __pyx_k__IndexError[] = "IndexError"; static char __pyx_k__beam_alpha[] = "beam_alpha"; static char __pyx_k__hypergraph[] = "hypergraph"; @@ -1160,6 +1182,7 @@ static PyObject *__pyx_n_s__encode; static PyObject *__pyx_n_s__encoding; static PyObject *__pyx_n_s__enumerate; static PyObject *__pyx_n_s__eval; +static PyObject *__pyx_n_s__evaluator; static PyObject *__pyx_n_s__grammar; static PyObject *__pyx_n_s__hypergraph; static PyObject *__pyx_n_s__inp; @@ -1195,14 +1218,54 @@ static PyObject *__pyx_k_tuple_24; static PyObject *__pyx_k_tuple_25; /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_11DenseVector_1__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ -static PyObject *__pyx_pw_5_cdec_11DenseVector_1__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { +static Py_ssize_t __pyx_pw_5_cdec_11DenseVector_1__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_11DenseVector_1__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_11DenseVector___len__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":6 + * cdef vector[weight_t]* vector # Not owned by DenseVector + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.vector.size() + * + */ + +static Py_ssize_t __pyx_pf_5_cdec_11DenseVector___len__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":7 + * + * def __len__(self): + * return self.vector.size() # <<<<<<<<<<<<<< + * + * def __getitem__(self, char* fname): + */ + __pyx_r = __pyx_v_self->vector->size(); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_11DenseVector_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ +static PyObject *__pyx_pw_5_cdec_11DenseVector_3__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { char *__pyx_v_fname; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); assert(__pyx_arg_fname); { - __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 6; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -1210,21 +1273,21 @@ static PyObject *__pyx_pw_5_cdec_11DenseVector_1__getitem__(PyObject *__pyx_v_se __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_11DenseVector___getitem__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); + __pyx_r = __pyx_pf_5_cdec_11DenseVector_2__getitem__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":6 - * cdef vector[weight_t]* vector +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":9 + * return self.vector.size() * * def __getitem__(self, char* fname): # <<<<<<<<<<<<<< - * cdef unsigned fid = FDConvert(fname) - * if fid <= self.vector.size(): + * cdef int fid = FDConvert(fname) + * if 0 <= fid < self.vector.size(): */ -static PyObject *__pyx_pf_5_cdec_11DenseVector___getitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname) { - unsigned int __pyx_v_fid; +static PyObject *__pyx_pf_5_cdec_11DenseVector_2__getitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname) { + int __pyx_v_fid; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; @@ -1235,34 +1298,37 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector___getitem__(struct __pyx_obj_5_cd int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__getitem__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":7 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":10 * * def __getitem__(self, char* fname): - * cdef unsigned fid = FDConvert(fname) # <<<<<<<<<<<<<< - * if fid <= self.vector.size(): + * cdef int fid = FDConvert(fname) # <<<<<<<<<<<<<< + * if 0 <= fid < self.vector.size(): * return self.vector[0][fid] */ __pyx_v_fid = FD::Convert(__pyx_v_fname); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":8 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":11 * def __getitem__(self, char* fname): - * cdef unsigned fid = FDConvert(fname) - * if fid <= self.vector.size(): # <<<<<<<<<<<<<< + * cdef int fid = FDConvert(fname) + * if 0 <= fid < self.vector.size(): # <<<<<<<<<<<<<< * return self.vector[0][fid] * raise KeyError(fname) */ - __pyx_t_1 = (__pyx_v_fid <= __pyx_v_self->vector->size()); + __pyx_t_1 = (0 <= __pyx_v_fid); + if (__pyx_t_1) { + __pyx_t_1 = (__pyx_v_fid < __pyx_v_self->vector->size()); + } if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":9 - * cdef unsigned fid = FDConvert(fname) - * if fid <= self.vector.size(): + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":12 + * cdef int fid = FDConvert(fname) + * if 0 <= fid < self.vector.size(): * return self.vector[0][fid] # <<<<<<<<<<<<<< * raise KeyError(fname) * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = PyFloat_FromDouble(((__pyx_v_self->vector[0])[__pyx_v_fid])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyFloat_FromDouble(((__pyx_v_self->vector[0])[__pyx_v_fid])); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; @@ -1271,26 +1337,26 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector___getitem__(struct __pyx_obj_5_cd } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":10 - * if fid <= self.vector.size(): + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":13 + * if 0 <= fid < self.vector.size(): * return self.vector[0][fid] * raise KeyError(fname) # <<<<<<<<<<<<<< * * def __setitem__(self, char* fname, float value): */ - __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2)); __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; @@ -1306,18 +1372,18 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector___getitem__(struct __pyx_obj_5_cd } /* Python wrapper */ -static int __pyx_pw_5_cdec_11DenseVector_3__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value); /*proto*/ -static int __pyx_pw_5_cdec_11DenseVector_3__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value) { +static int __pyx_pw_5_cdec_11DenseVector_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value); /*proto*/ +static int __pyx_pw_5_cdec_11DenseVector_5__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value) { char *__pyx_v_fname; float __pyx_v_value; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); assert(__pyx_arg_fname); { - __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } assert(__pyx_arg_value); { - __pyx_v_value = __pyx_PyFloat_AsFloat(__pyx_arg_value); if (unlikely((__pyx_v_value == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 12; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_value = __pyx_PyFloat_AsFloat(__pyx_arg_value); if (unlikely((__pyx_v_value == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -1325,38 +1391,69 @@ static int __pyx_pw_5_cdec_11DenseVector_3__setitem__(PyObject *__pyx_v_self, Py __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_11DenseVector_2__setitem__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((char *)__pyx_v_fname), ((float)__pyx_v_value)); + __pyx_r = __pyx_pf_5_cdec_11DenseVector_4__setitem__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((char *)__pyx_v_fname), ((float)__pyx_v_value)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":12 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":15 * raise KeyError(fname) * * def __setitem__(self, char* fname, float value): # <<<<<<<<<<<<<< - * cdef unsigned fid = FDConvert(fname) - * if self.vector.size() <= fid: + * cdef int fid = FDConvert(fname) + * if fid < 0: raise KeyError(fname) */ -static int __pyx_pf_5_cdec_11DenseVector_2__setitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value) { - unsigned int __pyx_v_fid; +static int __pyx_pf_5_cdec_11DenseVector_4__setitem__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value) { + int __pyx_v_fid; int __pyx_r; __Pyx_RefNannyDeclarations int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setitem__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":13 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":16 * * def __setitem__(self, char* fname, float value): - * cdef unsigned fid = FDConvert(fname) # <<<<<<<<<<<<<< + * cdef int fid = FDConvert(fname) # <<<<<<<<<<<<<< + * if fid < 0: raise KeyError(fname) * if self.vector.size() <= fid: - * self.vector.resize(fid + 1) */ __pyx_v_fid = FD::Convert(((char *)__pyx_v_fname)); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":14 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":17 * def __setitem__(self, char* fname, float value): - * cdef unsigned fid = FDConvert(fname) + * cdef int fid = FDConvert(fname) + * if fid < 0: raise KeyError(fname) # <<<<<<<<<<<<<< + * if self.vector.size() <= fid: + * self.vector.resize(fid + 1) + */ + __pyx_t_1 = (__pyx_v_fid < 0); + if (__pyx_t_1) { + __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 17; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":18 + * cdef int fid = FDConvert(fname) + * if fid < 0: raise KeyError(fname) * if self.vector.size() <= fid: # <<<<<<<<<<<<<< * self.vector.resize(fid + 1) * self.vector[0][fid] = value @@ -1364,19 +1461,19 @@ static int __pyx_pf_5_cdec_11DenseVector_2__setitem__(struct __pyx_obj_5_cdec_De __pyx_t_1 = (__pyx_v_self->vector->size() <= __pyx_v_fid); if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":15 - * cdef unsigned fid = FDConvert(fname) + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":19 + * if fid < 0: raise KeyError(fname) * if self.vector.size() <= fid: * self.vector.resize(fid + 1) # <<<<<<<<<<<<<< * self.vector[0][fid] = value * */ __pyx_v_self->vector->resize((__pyx_v_fid + 1)); - goto __pyx_L3; + goto __pyx_L4; } - __pyx_L3:; + __pyx_L4:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":16 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":20 * if self.vector.size() <= fid: * self.vector.resize(fid + 1) * self.vector[0][fid] = value # <<<<<<<<<<<<<< @@ -1386,23 +1483,30 @@ static int __pyx_pf_5_cdec_11DenseVector_2__setitem__(struct __pyx_obj_5_cdec_De ((__pyx_v_self->vector[0])[__pyx_v_fid]) = __pyx_v_value; __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec.DenseVector.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_11DenseVector_6generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5_cdec_11DenseVector_8generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_11DenseVector_5__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_11DenseVector_5__iter__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_11DenseVector_7__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_11DenseVector_7__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_11DenseVector_4__iter__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_11DenseVector_6__iter__(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":18 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":22 * self.vector[0][fid] = value * * def __iter__(self): # <<<<<<<<<<<<<< @@ -1410,7 +1514,7 @@ static PyObject *__pyx_pw_5_cdec_11DenseVector_5__iter__(PyObject *__pyx_v_self) * for fid in range(1, self.vector.size()): */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_4__iter__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_11DenseVector_6__iter__(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -1428,7 +1532,7 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_4__iter__(struct __pyx_obj_5_cdec __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_11DenseVector_6generator, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_11DenseVector_8generator, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -1446,7 +1550,7 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_4__iter__(struct __pyx_obj_5_cdec return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_11DenseVector_6generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_11DenseVector_8generator(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct____iter__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; @@ -1465,9 +1569,9 @@ static PyObject *__pyx_gb_5_cdec_11DenseVector_6generator(__pyx_GeneratorObject return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":20 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":24 * def __iter__(self): * cdef unsigned fid * for fid in range(1, self.vector.size()): # <<<<<<<<<<<<<< @@ -1478,18 +1582,18 @@ static PyObject *__pyx_gb_5_cdec_11DenseVector_6generator(__pyx_GeneratorObject for (__pyx_t_2 = 1; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_cur_scope->__pyx_v_fid = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":21 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":25 * cdef unsigned fid * for fid in range(1, self.vector.size()): * yield FDConvert(fid).c_str(), self.vector[0][fid] # <<<<<<<<<<<<<< * * def dot(self, SparseVector other): */ - __pyx_t_3 = PyBytes_FromString(FD::Convert(__pyx_cur_scope->__pyx_v_fid).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyBytes_FromString(FD::Convert(__pyx_cur_scope->__pyx_v_fid).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - __pyx_t_4 = PyFloat_FromDouble(((__pyx_cur_scope->__pyx_v_self->vector[0])[__pyx_cur_scope->__pyx_v_fid])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyFloat_FromDouble(((__pyx_cur_scope->__pyx_v_self->vector[0])[__pyx_cur_scope->__pyx_v_fid])); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_3)); __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); @@ -1509,7 +1613,7 @@ static PyObject *__pyx_gb_5_cdec_11DenseVector_6generator(__pyx_GeneratorObject __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_filename = __pyx_f[1]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 25; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; @@ -1526,13 +1630,13 @@ static PyObject *__pyx_gb_5_cdec_11DenseVector_6generator(__pyx_GeneratorObject } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_11DenseVector_8dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_11DenseVector_8dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_11DenseVector_10dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_11DenseVector_10dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("dot (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 23; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_11DenseVector_7dot(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_11DenseVector_9dot(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -1541,7 +1645,7 @@ static PyObject *__pyx_pw_5_cdec_11DenseVector_8dot(PyObject *__pyx_v_self, PyOb return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":23 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":27 * yield FDConvert(fid).c_str(), self.vector[0][fid] * * def dot(self, SparseVector other): # <<<<<<<<<<<<<< @@ -1549,7 +1653,7 @@ static PyObject *__pyx_pw_5_cdec_11DenseVector_8dot(PyObject *__pyx_v_self, PyOb * */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_7dot(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_11DenseVector_9dot(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -1560,7 +1664,7 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_7dot(struct __pyx_obj_5_cdec_Dens int __pyx_clineno = 0; __Pyx_RefNannySetupContext("dot", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":24 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":28 * * def dot(self, SparseVector other): * return other.dot(self) # <<<<<<<<<<<<<< @@ -1568,14 +1672,14 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_7dot(struct __pyx_obj_5_cdec_Dens * def tosparse(self): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_other), __pyx_n_s__dot); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_v_other), __pyx_n_s__dot); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)__pyx_v_self)); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_self)); __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); - __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 28; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; @@ -1598,17 +1702,17 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_7dot(struct __pyx_obj_5_cdec_Dens } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_11DenseVector_10tosparse(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_11DenseVector_10tosparse(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { +static PyObject *__pyx_pw_5_cdec_11DenseVector_12tosparse(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_11DenseVector_12tosparse(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("tosparse (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_11DenseVector_9tosparse(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_11DenseVector_11tosparse(((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":26 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":30 * return other.dot(self) * * def tosparse(self): # <<<<<<<<<<<<<< @@ -1616,7 +1720,7 @@ static PyObject *__pyx_pw_5_cdec_11DenseVector_10tosparse(PyObject *__pyx_v_self * sparse.vector = new FastSparseVector[weight_t]() */ -static PyObject *__pyx_pf_5_cdec_11DenseVector_9tosparse(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_11DenseVector_11tosparse(struct __pyx_obj_5_cdec_DenseVector *__pyx_v_self) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_sparse = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -1626,19 +1730,19 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_9tosparse(struct __pyx_obj_5_cdec int __pyx_clineno = 0; __Pyx_RefNannySetupContext("tosparse", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":27 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":31 * * def tosparse(self): * cdef SparseVector sparse = SparseVector() # <<<<<<<<<<<<<< * sparse.vector = new FastSparseVector[weight_t]() * InitSparseVector(self.vector[0], sparse.vector) */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_sparse = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":28 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":32 * def tosparse(self): * cdef SparseVector sparse = SparseVector() * sparse.vector = new FastSparseVector[weight_t]() # <<<<<<<<<<<<<< @@ -1647,7 +1751,7 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_9tosparse(struct __pyx_obj_5_cdec */ __pyx_v_sparse->vector = new FastSparseVector(); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":29 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":33 * cdef SparseVector sparse = SparseVector() * sparse.vector = new FastSparseVector[weight_t]() * InitSparseVector(self.vector[0], sparse.vector) # <<<<<<<<<<<<<< @@ -1656,7 +1760,7 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_9tosparse(struct __pyx_obj_5_cdec */ Weights::InitSparseVector((__pyx_v_self->vector[0]), __pyx_v_sparse->vector); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":30 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":34 * sparse.vector = new FastSparseVector[weight_t]() * InitSparseVector(self.vector[0], sparse.vector) * return sparse # <<<<<<<<<<<<<< @@ -1682,14 +1786,101 @@ static PyObject *__pyx_pf_5_cdec_11DenseVector_9tosparse(struct __pyx_obj_5_cdec } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_1__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_1__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { +static void __pyx_pw_5_cdec_12SparseVector_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_12SparseVector_1__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_12SparseVector___dealloc__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":39 + * cdef FastSparseVector[weight_t]* vector + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.vector + * + */ + +static void __pyx_pf_5_cdec_12SparseVector___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":40 + * + * def __dealloc__(self): + * del self.vector # <<<<<<<<<<<<<< + * + * def copy(self): + */ + delete __pyx_v_self->vector; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_12SparseVector_3copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_3copy(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("copy (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_2copy(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":42 + * del self.vector + * + * def copy(self): # <<<<<<<<<<<<<< + * return self * 1 + * + */ + +static PyObject *__pyx_pf_5_cdec_12SparseVector_2copy(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("copy", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":43 + * + * def copy(self): + * return self * 1 # <<<<<<<<<<<<<< + * + * def __getitem__(self, char* fname): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyNumber_Multiply(((PyObject *)__pyx_v_self), __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("_cdec.SparseVector.copy", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_12SparseVector_5__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_5__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { char *__pyx_v_fname; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); assert(__pyx_arg_fname); { - __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 35; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -1697,56 +1888,85 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_1__getitem__(PyObject *__pyx_v_s __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12SparseVector___getitem__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_4__getitem__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":35 - * cdef FastSparseVector[weight_t]* vector +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":45 + * return self * 1 * * def __getitem__(self, char* fname): # <<<<<<<<<<<<<< - * cdef unsigned fid = FDConvert(fname) - * return self.vector.value(fid) + * cdef int fid = FDConvert(fname) + * if fid < 0: raise KeyError(fname) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector___getitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname) { - unsigned int __pyx_v_fid; +static PyObject *__pyx_pf_5_cdec_12SparseVector_4__getitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname) { + int __pyx_v_fid; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__getitem__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":36 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":46 * * def __getitem__(self, char* fname): - * cdef unsigned fid = FDConvert(fname) # <<<<<<<<<<<<<< + * cdef int fid = FDConvert(fname) # <<<<<<<<<<<<<< + * if fid < 0: raise KeyError(fname) * return self.vector.value(fid) - * */ __pyx_v_fid = FD::Convert(__pyx_v_fname); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":37 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":47 * def __getitem__(self, char* fname): - * cdef unsigned fid = FDConvert(fname) + * cdef int fid = FDConvert(fname) + * if fid < 0: raise KeyError(fname) # <<<<<<<<<<<<<< + * return self.vector.value(fid) + * + */ + __pyx_t_1 = (__pyx_v_fid < 0); + if (__pyx_t_1) { + __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":48 + * cdef int fid = FDConvert(fname) + * if fid < 0: raise KeyError(fname) * return self.vector.value(fid) # <<<<<<<<<<<<<< * * def __setitem__(self, char* fname, float value): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->value(__pyx_v_fid)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_r = __pyx_t_1; - __pyx_t_1 = 0; + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_self->vector->value(__pyx_v_fid)); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; goto __pyx_L0; __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_AddTraceback("_cdec.SparseVector.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -1756,18 +1976,18 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector___getitem__(struct __pyx_obj_5_c } /* Python wrapper */ -static int __pyx_pw_5_cdec_12SparseVector_3__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value); /*proto*/ -static int __pyx_pw_5_cdec_12SparseVector_3__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value) { +static int __pyx_pw_5_cdec_12SparseVector_7__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value); /*proto*/ +static int __pyx_pw_5_cdec_12SparseVector_7__setitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname, PyObject *__pyx_arg_value) { char *__pyx_v_fname; float __pyx_v_value; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__setitem__ (wrapper)", 0); assert(__pyx_arg_fname); { - __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } assert(__pyx_arg_value); { - __pyx_v_value = __pyx_PyFloat_AsFloat(__pyx_arg_value); if (unlikely((__pyx_v_value == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 39; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_value = __pyx_PyFloat_AsFloat(__pyx_arg_value); if (unlikely((__pyx_v_value == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -1775,37 +1995,69 @@ static int __pyx_pw_5_cdec_12SparseVector_3__setitem__(PyObject *__pyx_v_self, P __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12SparseVector_2__setitem__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname), ((float)__pyx_v_value)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_6__setitem__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname), ((float)__pyx_v_value)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":39 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":50 * return self.vector.value(fid) * * def __setitem__(self, char* fname, float value): # <<<<<<<<<<<<<< - * cdef unsigned fid = FDConvert(fname) - * self.vector.set_value(fid, value) + * cdef int fid = FDConvert(fname) + * if fid < 0: raise KeyError(fname) */ -static int __pyx_pf_5_cdec_12SparseVector_2__setitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value) { - unsigned int __pyx_v_fid; +static int __pyx_pf_5_cdec_12SparseVector_6__setitem__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname, float __pyx_v_value) { + int __pyx_v_fid; int __pyx_r; __Pyx_RefNannyDeclarations + int __pyx_t_1; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__setitem__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":40 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":51 * * def __setitem__(self, char* fname, float value): - * cdef unsigned fid = FDConvert(fname) # <<<<<<<<<<<<<< + * cdef int fid = FDConvert(fname) # <<<<<<<<<<<<<< + * if fid < 0: raise KeyError(fname) * self.vector.set_value(fid, value) - * */ __pyx_v_fid = FD::Convert(((char *)__pyx_v_fname)); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":41 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":52 * def __setitem__(self, char* fname, float value): - * cdef unsigned fid = FDConvert(fname) + * cdef int fid = FDConvert(fname) + * if fid < 0: raise KeyError(fname) # <<<<<<<<<<<<<< + * self.vector.set_value(fid, value) + * + */ + __pyx_t_1 = (__pyx_v_fid < 0); + if (__pyx_t_1) { + __pyx_t_2 = PyBytes_FromString(__pyx_v_fname); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(((PyObject *)__pyx_t_2)); + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_2)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); + __pyx_t_2 = 0; + __pyx_t_2 = PyObject_Call(__pyx_builtin_KeyError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_t_2, 0, 0, 0); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + goto __pyx_L3; + } + __pyx_L3:; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":53 + * cdef int fid = FDConvert(fname) + * if fid < 0: raise KeyError(fname) * self.vector.set_value(fid, value) # <<<<<<<<<<<<<< * * def __iter__(self): @@ -1813,31 +2065,38 @@ static int __pyx_pf_5_cdec_12SparseVector_2__setitem__(struct __pyx_obj_5_cdec_S __pyx_v_self->vector->set_value(__pyx_v_fid, __pyx_v_value); __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("_cdec.SparseVector.__setitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_12SparseVector_6generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5_cdec_12SparseVector_10generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_5__iter__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_5__iter__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_9__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_9__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_4__iter__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_8__iter__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":43 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":55 * self.vector.set_value(fid, value) * * def __iter__(self): # <<<<<<<<<<<<<< * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) - * cdef str fname + * try: */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_4__iter__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_8__iter__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -1855,7 +2114,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_4__iter__(struct __pyx_obj_5_cde __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12SparseVector_6generator1, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12SparseVector_10generator1, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -1873,7 +2132,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_4__iter__(struct __pyx_obj_5_cde return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_12SparseVector_6generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_12SparseVector_10generator1(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; @@ -1881,99 +2140,133 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_6generator1(__pyx_GeneratorObjec size_t __pyx_t_2; PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L6_resume_from_yield; + case 1: goto __pyx_L9_resume_from_yield; default: /* CPython raises the right error here */ __Pyx_RefNannyFinishContext(); return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":44 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":56 * * def __iter__(self): * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) # <<<<<<<<<<<<<< - * cdef str fname - * for i in range(self.vector.size()): + * try: + * for i in range(self.vector.size()): */ __pyx_cur_scope->__pyx_v_it = new FastSparseVector::const_iterator((__pyx_cur_scope->__pyx_v_self->vector[0]), 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":46 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":57 + * def __iter__(self): * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) - * cdef str fname - * for i in range(self.vector.size()): # <<<<<<<<<<<<<< - * fname = FDConvert(it[0].ptr().first).c_str() - * yield (fname, it[0].ptr().second) + * try: # <<<<<<<<<<<<<< + * for i in range(self.vector.size()): + * yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second) */ - __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->vector->size(); - for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { - __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":47 - * cdef str fname - * for i in range(self.vector.size()): - * fname = FDConvert(it[0].ptr().first).c_str() # <<<<<<<<<<<<<< - * yield (fname, it[0].ptr().second) - * pinc(it[0]) - */ - __pyx_t_3 = PyBytes_FromString(FD::Convert((__pyx_cur_scope->__pyx_v_it[0]).operator->()->first).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_3)); - if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_3)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_3))->tp_name), 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fname)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fname)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); - __pyx_cur_scope->__pyx_v_fname = ((PyObject*)__pyx_t_3); - __pyx_t_3 = 0; + /*try:*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":48 - * for i in range(self.vector.size()): - * fname = FDConvert(it[0].ptr().first).c_str() - * yield (fname, it[0].ptr().second) # <<<<<<<<<<<<<< - * pinc(it[0]) - * - */ - __pyx_t_3 = PyFloat_FromDouble((__pyx_cur_scope->__pyx_v_it[0]).operator->()->second); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_fname)); - PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_cur_scope->__pyx_v_fname)); - __Pyx_GIVEREF(((PyObject *)__pyx_cur_scope->__pyx_v_fname)); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_t_3 = 0; - __pyx_r = ((PyObject *)__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_filename = __pyx_f[1]; __pyx_lineno = 48; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":58 + * cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) + * try: + * for i in range(self.vector.size()): # <<<<<<<<<<<<<< + * yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second) + * pinc(it[0]) # ++it + */ + __pyx_t_1 = __pyx_cur_scope->__pyx_v_self->vector->size(); + for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { + __pyx_cur_scope->__pyx_v_i = __pyx_t_2; + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":59 + * try: + * for i in range(self.vector.size()): + * yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second) # <<<<<<<<<<<<<< + * pinc(it[0]) # ++it + * finally: + */ + __pyx_t_3 = PyBytes_FromString(FD::Convert((__pyx_cur_scope->__pyx_v_it[0]).operator->()->first).c_str()); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(((PyObject *)__pyx_t_3)); + __pyx_t_4 = PyFloat_FromDouble((__pyx_cur_scope->__pyx_v_it[0]).operator->()->second); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_t_3)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_3)); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_t_3 = 0; + __pyx_t_4 = 0; + __pyx_r = ((PyObject *)__pyx_t_5); + __pyx_t_5 = 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_L9_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_filename = __pyx_f[1]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L5;} + + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":60 + * for i in range(self.vector.size()): + * yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second) + * pinc(it[0]) # ++it # <<<<<<<<<<<<<< + * finally: + * del it + */ + (++(__pyx_cur_scope->__pyx_v_it[0])); + } + } - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":49 - * fname = FDConvert(it[0].ptr().first).c_str() - * yield (fname, it[0].ptr().second) - * pinc(it[0]) # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":62 + * pinc(it[0]) # ++it + * finally: + * del it # <<<<<<<<<<<<<< * * def dot(self, other): */ - (++(__pyx_cur_scope->__pyx_v_it[0])); + /*finally:*/ { + int __pyx_why; + PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; + int __pyx_exc_lineno; + __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; + __pyx_why = 0; goto __pyx_L6; + __pyx_L5: { + __pyx_why = 4; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); + __pyx_exc_lineno = __pyx_lineno; + goto __pyx_L6; + } + __pyx_L6:; + delete __pyx_cur_scope->__pyx_v_it; + switch (__pyx_why) { + case 4: { + __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); + __pyx_lineno = __pyx_exc_lineno; + __pyx_exc_type = 0; + __pyx_exc_value = 0; + __pyx_exc_tb = 0; + goto __pyx_L1_error; + } + } } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_L0:; __Pyx_XDECREF(__pyx_r); @@ -1983,25 +2276,25 @@ static PyObject *__pyx_gb_5_cdec_12SparseVector_6generator1(__pyx_GeneratorObjec } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_8dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_8dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_12dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_12dot(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("dot (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_7dot(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((PyObject *)__pyx_v_other)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_11dot(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((PyObject *)__pyx_v_other)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":51 - * pinc(it[0]) +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":64 + * del it * * def dot(self, other): # <<<<<<<<<<<<<< * if isinstance(other, DenseVector): * return self.vector.dot(( other).vector[0]) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_11dot(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -2012,7 +2305,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa int __pyx_clineno = 0; __Pyx_RefNannySetupContext("dot", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":52 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":65 * * def dot(self, other): * if isinstance(other, DenseVector): # <<<<<<<<<<<<<< @@ -2025,7 +2318,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":53 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":66 * def dot(self, other): * if isinstance(other, DenseVector): * return self.vector.dot(( other).vector[0]) # <<<<<<<<<<<<<< @@ -2033,7 +2326,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa * return self.vector.dot(( other).vector[0]) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->dot((((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_other)->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->dot((((struct __pyx_obj_5_cdec_DenseVector *)__pyx_v_other)->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2041,7 +2334,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa goto __pyx_L3; } - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":54 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":67 * if isinstance(other, DenseVector): * return self.vector.dot(( other).vector[0]) * elif isinstance(other, SparseVector): # <<<<<<<<<<<<<< @@ -2054,7 +2347,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":55 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":68 * return self.vector.dot(( other).vector[0]) * elif isinstance(other, SparseVector): * return self.vector.dot(( other).vector[0]) # <<<<<<<<<<<<<< @@ -2062,7 +2355,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->dot((((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_self->vector->dot((((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2071,26 +2364,26 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":56 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":69 * elif isinstance(other, SparseVector): * return self.vector.dot(( other).vector[0]) * raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) # <<<<<<<<<<<<<< * - * def todense(self): + * def __richcmp__(SparseVector x, SparseVector y, int op): */ - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), ((PyObject *)Py_TYPE(__pyx_v_other))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_1), ((PyObject *)Py_TYPE(__pyx_v_other))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; @@ -2106,98 +2399,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_7dot(struct __pyx_obj_5_cdec_Spa } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_10todense(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_10todense(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { - PyObject *__pyx_r = 0; - __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("todense (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_9todense(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":58 - * raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) - * - * def todense(self): # <<<<<<<<<<<<<< - * cdef DenseVector dense = DenseVector() - * dense.vector = new vector[weight_t]() - */ - -static PyObject *__pyx_pf_5_cdec_12SparseVector_9todense(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { - struct __pyx_obj_5_cdec_DenseVector *__pyx_v_dense = 0; - PyObject *__pyx_r = NULL; - __Pyx_RefNannyDeclarations - PyObject *__pyx_t_1 = NULL; - int __pyx_lineno = 0; - const char *__pyx_filename = NULL; - int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("todense", 0); - - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":59 - * - * def todense(self): - * cdef DenseVector dense = DenseVector() # <<<<<<<<<<<<<< - * dense.vector = new vector[weight_t]() - * self.vector.init_vector(dense.vector) - */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_DenseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_v_dense = ((struct __pyx_obj_5_cdec_DenseVector *)__pyx_t_1); - __pyx_t_1 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":60 - * def todense(self): - * cdef DenseVector dense = DenseVector() - * dense.vector = new vector[weight_t]() # <<<<<<<<<<<<<< - * self.vector.init_vector(dense.vector) - * return dense - */ - __pyx_v_dense->vector = new std::vector(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":61 - * cdef DenseVector dense = DenseVector() - * dense.vector = new vector[weight_t]() - * self.vector.init_vector(dense.vector) # <<<<<<<<<<<<<< - * return dense - * - */ - __pyx_v_self->vector->init_vector(__pyx_v_dense->vector); - - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":62 - * dense.vector = new vector[weight_t]() - * self.vector.init_vector(dense.vector) - * return dense # <<<<<<<<<<<<<< - * - * def __richcmp__(SparseVector x, SparseVector y, int op): - */ - __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_dense)); - __pyx_r = ((PyObject *)__pyx_v_dense); - goto __pyx_L0; - - __pyx_r = Py_None; __Pyx_INCREF(Py_None); - goto __pyx_L0; - __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_1); - __Pyx_AddTraceback("_cdec.SparseVector.todense", __pyx_clineno, __pyx_lineno, __pyx_filename); - __pyx_r = NULL; - __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_dense); - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - return __pyx_r; -} - -/* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_12__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_12__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_14__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_14__richcmp__(PyObject *__pyx_v_x, PyObject *__pyx_v_y, int __pyx_v_op) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_11__richcmp__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y), ((int)__pyx_v_op)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_13__richcmp__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y), ((int)__pyx_v_op)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2206,15 +2415,15 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_12__richcmp__(PyObject *__pyx_v_ return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":64 - * return dense +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":71 + * raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) * * def __richcmp__(SparseVector x, SparseVector y, int op): # <<<<<<<<<<<<<< * if op == 2: # == * return x.vector[0] == y.vector[0] */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y, int __pyx_v_op) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_13__richcmp__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y, int __pyx_v_op) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -2224,7 +2433,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__richcmp__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":67 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":74 * if op == 2: # == * return x.vector[0] == y.vector[0] * elif op == 3: # != # <<<<<<<<<<<<<< @@ -2233,7 +2442,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 */ switch (__pyx_v_op) { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":65 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":72 * * def __richcmp__(SparseVector x, SparseVector y, int op): * if op == 2: # == # <<<<<<<<<<<<<< @@ -2242,7 +2451,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 */ case 2: - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":66 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":73 * def __richcmp__(SparseVector x, SparseVector y, int op): * if op == 2: # == * return x.vector[0] == y.vector[0] # <<<<<<<<<<<<<< @@ -2250,14 +2459,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 * return not (x == y) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_x->vector[0]) == (__pyx_v_y->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyBool_FromLong(((__pyx_v_x->vector[0]) == (__pyx_v_y->vector[0]))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; break; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":67 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":74 * if op == 2: # == * return x.vector[0] == y.vector[0] * elif op == 3: # != # <<<<<<<<<<<<<< @@ -2266,7 +2475,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 */ case 3: - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":68 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":75 * return x.vector[0] == y.vector[0] * elif op == 3: # != * return not (x == y) # <<<<<<<<<<<<<< @@ -2274,11 +2483,11 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 * */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_RichCompare(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y), Py_EQ); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyBool_FromLong((!__pyx_t_2)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2286,18 +2495,18 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 break; } - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":69 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":76 * elif op == 3: # != * return not (x == y) * raise NotImplemented('comparison not implemented for SparseVector') # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_t_1 = PyObject_Call(__pyx_builtin_NotImplemented, ((PyObject *)__pyx_k_tuple_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_NotImplemented, ((PyObject *)__pyx_k_tuple_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __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_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; @@ -2312,17 +2521,17 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_11__richcmp__(struct __pyx_obj_5 } /* Python wrapper */ -static Py_ssize_t __pyx_pw_5_cdec_12SparseVector_14__len__(PyObject *__pyx_v_self); /*proto*/ -static Py_ssize_t __pyx_pw_5_cdec_12SparseVector_14__len__(PyObject *__pyx_v_self) { +static Py_ssize_t __pyx_pw_5_cdec_12SparseVector_16__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_12SparseVector_16__len__(PyObject *__pyx_v_self) { Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_13__len__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_15__len__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":71 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":78 * raise NotImplemented('comparison not implemented for SparseVector') * * def __len__(self): # <<<<<<<<<<<<<< @@ -2330,12 +2539,12 @@ static Py_ssize_t __pyx_pw_5_cdec_12SparseVector_14__len__(PyObject *__pyx_v_sel * */ -static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_13__len__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { +static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_15__len__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self) { Py_ssize_t __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__len__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":72 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":79 * * def __len__(self): * return self.vector.size() # <<<<<<<<<<<<<< @@ -2352,14 +2561,14 @@ static Py_ssize_t __pyx_pf_5_cdec_12SparseVector_13__len__(struct __pyx_obj_5_cd } /* Python wrapper */ -static int __pyx_pw_5_cdec_12SparseVector_16__contains__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ -static int __pyx_pw_5_cdec_12SparseVector_16__contains__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { +static int __pyx_pw_5_cdec_12SparseVector_18__contains__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname); /*proto*/ +static int __pyx_pw_5_cdec_12SparseVector_18__contains__(PyObject *__pyx_v_self, PyObject *__pyx_arg_fname) { char *__pyx_v_fname; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__contains__ (wrapper)", 0); assert(__pyx_arg_fname); { - __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 74; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_fname = PyBytes_AsString(__pyx_arg_fname); if (unlikely((!__pyx_v_fname) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -2367,12 +2576,12 @@ static int __pyx_pw_5_cdec_12SparseVector_16__contains__(PyObject *__pyx_v_self, __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12SparseVector_15__contains__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_17__contains__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((char *)__pyx_v_fname)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":74 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":81 * return self.vector.size() * * def __contains__(self, char* fname): # <<<<<<<<<<<<<< @@ -2380,12 +2589,12 @@ static int __pyx_pw_5_cdec_12SparseVector_16__contains__(PyObject *__pyx_v_self, * */ -static int __pyx_pf_5_cdec_12SparseVector_15__contains__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname) { +static int __pyx_pf_5_cdec_12SparseVector_17__contains__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, char *__pyx_v_fname) { int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__contains__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":75 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":82 * * def __contains__(self, char* fname): * return self.vector.nonzero(FDConvert(fname)) # <<<<<<<<<<<<<< @@ -2402,13 +2611,13 @@ static int __pyx_pf_5_cdec_12SparseVector_15__contains__(struct __pyx_obj_5_cdec } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_18__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_18__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_20__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_20__iadd__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iadd__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_17__iadd__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_19__iadd__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2417,7 +2626,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_18__iadd__(PyObject *__pyx_v_sel return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":77 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":84 * return self.vector.nonzero(FDConvert(fname)) * * def __iadd__(SparseVector self, SparseVector other): # <<<<<<<<<<<<<< @@ -2425,12 +2634,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_18__iadd__(PyObject *__pyx_v_sel * return self */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_17__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_19__iadd__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__iadd__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":78 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":85 * * def __iadd__(SparseVector self, SparseVector other): * self.vector[0] += other.vector[0] # <<<<<<<<<<<<<< @@ -2439,7 +2648,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_17__iadd__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) += (__pyx_v_other->vector[0]); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":79 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":86 * def __iadd__(SparseVector self, SparseVector other): * self.vector[0] += other.vector[0] * return self # <<<<<<<<<<<<<< @@ -2459,13 +2668,13 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_17__iadd__(struct __pyx_obj_5_cd } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_20__isub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_20__isub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_22__isub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_22__isub__(PyObject *__pyx_v_self, PyObject *__pyx_v_other) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__isub__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_19__isub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_other), __pyx_ptype_5_cdec_SparseVector, 1, "other", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_21__isub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_other)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2474,7 +2683,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_20__isub__(PyObject *__pyx_v_sel return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":81 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":88 * return self * * def __isub__(SparseVector self, SparseVector other): # <<<<<<<<<<<<<< @@ -2482,12 +2691,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_20__isub__(PyObject *__pyx_v_sel * return self */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_19__isub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_21__isub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_other) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__isub__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":82 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":89 * * def __isub__(SparseVector self, SparseVector other): * self.vector[0] -= other.vector[0] # <<<<<<<<<<<<<< @@ -2496,7 +2705,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_19__isub__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) -= (__pyx_v_other->vector[0]); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":83 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":90 * def __isub__(SparseVector self, SparseVector other): * self.vector[0] -= other.vector[0] * return self # <<<<<<<<<<<<<< @@ -2516,14 +2725,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_19__isub__(struct __pyx_obj_5_cd } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_22__imul__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_22__imul__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_24__imul__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_24__imul__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar) { float __pyx_v_scalar; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__imul__ (wrapper)", 0); assert(__pyx_arg_scalar); { - __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -2531,12 +2740,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_22__imul__(PyObject *__pyx_v_sel __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12SparseVector_21__imul__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((float)__pyx_v_scalar)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_23__imul__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((float)__pyx_v_scalar)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":85 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":92 * return self * * def __imul__(SparseVector self, float scalar): # <<<<<<<<<<<<<< @@ -2544,12 +2753,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_22__imul__(PyObject *__pyx_v_sel * return self */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_21__imul__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_23__imul__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__imul__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":86 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":93 * * def __imul__(SparseVector self, float scalar): * self.vector[0] *= scalar # <<<<<<<<<<<<<< @@ -2558,7 +2767,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_21__imul__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) *= __pyx_v_scalar; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":87 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":94 * def __imul__(SparseVector self, float scalar): * self.vector[0] *= scalar * return self # <<<<<<<<<<<<<< @@ -2579,14 +2788,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_21__imul__(struct __pyx_obj_5_cd /* Python wrapper */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pw_5_cdec_12SparseVector_24__idiv__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_24__idiv__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_26__idiv__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_26__idiv__(PyObject *__pyx_v_self, PyObject *__pyx_arg_scalar) { float __pyx_v_scalar; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__idiv__ (wrapper)", 0); assert(__pyx_arg_scalar); { - __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_scalar = __pyx_PyFloat_AsFloat(__pyx_arg_scalar); if (unlikely((__pyx_v_scalar == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -2594,13 +2803,13 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_24__idiv__(PyObject *__pyx_v_sel __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_12SparseVector_23__idiv__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((float)__pyx_v_scalar)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_25__idiv__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_self), ((float)__pyx_v_scalar)); __Pyx_RefNannyFinishContext(); return __pyx_r; } #endif /*!(#if PY_MAJOR_VERSION < 3)*/ -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":89 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":96 * return self * * def __idiv__(SparseVector self, float scalar): # <<<<<<<<<<<<<< @@ -2609,12 +2818,12 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_24__idiv__(PyObject *__pyx_v_sel */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pf_5_cdec_12SparseVector_23__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_25__idiv__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_self, float __pyx_v_scalar) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__idiv__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":90 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":97 * * def __idiv__(SparseVector self, float scalar): * self.vector[0] /= scalar # <<<<<<<<<<<<<< @@ -2623,7 +2832,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_23__idiv__(struct __pyx_obj_5_cd */ (__pyx_v_self->vector[0]) /= __pyx_v_scalar; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":91 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":98 * def __idiv__(SparseVector self, float scalar): * self.vector[0] /= scalar * return self # <<<<<<<<<<<<<< @@ -2644,14 +2853,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_23__idiv__(struct __pyx_obj_5_cd #endif /*!(#if PY_MAJOR_VERSION < 3)*/ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_28__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_28__add__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__add__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_25__add__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_27__add__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2660,7 +2869,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_x, P return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":93 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":100 * return self * * def __add__(SparseVector x, SparseVector y): # <<<<<<<<<<<<<< @@ -2668,7 +2877,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_26__add__(PyObject *__pyx_v_x, P * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_27__add__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -2678,19 +2887,19 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__add__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":94 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":101 * * def __add__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 101; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":95 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":102 * def __add__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) # <<<<<<<<<<<<<< @@ -2699,7 +2908,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cde */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_x->vector[0]) + (__pyx_v_y->vector[0]))); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":96 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":103 * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](x.vector[0] + y.vector[0]) * return result # <<<<<<<<<<<<<< @@ -2725,14 +2934,14 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_25__add__(struct __pyx_obj_5_cde } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_30__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_30__sub__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__sub__ (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 98; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_12SparseVector_27__sub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_x), __pyx_ptype_5_cdec_SparseVector, 1, "x", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_y), __pyx_ptype_5_cdec_SparseVector, 1, "y", 0))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12SparseVector_29__sub__(((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_x), ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_v_y)); goto __pyx_L0; __pyx_L1_error:; __pyx_r = NULL; @@ -2741,7 +2950,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_x, P return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":98 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":105 * return result * * def __sub__(SparseVector x, SparseVector y): # <<<<<<<<<<<<<< @@ -2749,7 +2958,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_28__sub__(PyObject *__pyx_v_x, P * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_29__sub__(struct __pyx_obj_5_cdec_SparseVector *__pyx_v_x, struct __pyx_obj_5_cdec_SparseVector *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -2759,19 +2968,19 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__sub__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":99 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":106 * * def __sub__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":100 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":107 * def __sub__(SparseVector x, SparseVector y): * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) # <<<<<<<<<<<<<< @@ -2780,7 +2989,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cde */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_x->vector[0]) - (__pyx_v_y->vector[0]))); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":101 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":108 * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](x.vector[0] - y.vector[0]) * return result # <<<<<<<<<<<<<< @@ -2806,17 +3015,17 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_27__sub__(struct __pyx_obj_5_cde } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_12SparseVector_30__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_30__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_32__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_32__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__mul__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_29__mul__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_31__mul__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":103 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":110 * return result * * def __mul__(x, y): # <<<<<<<<<<<<<< @@ -2824,7 +3033,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_30__mul__(PyObject *__pyx_v_x, P * cdef float scalar */ -static PyObject *__pyx_pf_5_cdec_12SparseVector_29__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_31__mul__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_vector = 0; float __pyx_v_scalar; struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; @@ -2838,7 +3047,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_29__mul__(PyObject *__pyx_v_x, P int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__mul__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":106 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":113 * cdef SparseVector vector * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y # <<<<<<<<<<<<<< @@ -2850,10 +3059,10 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_29__mul__(PyObject *__pyx_v_x, P __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_x; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; @@ -2861,36 +3070,36 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_29__mul__(PyObject *__pyx_v_x, P } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":107 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":114 * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x # <<<<<<<<<<<<<< * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) */ - if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_y; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 114; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":108 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":115 * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 108; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":109 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":116 * else: vector, scalar = y, x * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) # <<<<<<<<<<<<<< @@ -2899,7 +3108,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_29__mul__(PyObject *__pyx_v_x, P */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_vector->vector[0]) * __pyx_v_scalar)); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":110 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":117 * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] * scalar) * return result # <<<<<<<<<<<<<< @@ -2927,18 +3136,18 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_29__mul__(PyObject *__pyx_v_x, P /* Python wrapper */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pw_5_cdec_12SparseVector_32__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ -static PyObject *__pyx_pw_5_cdec_12SparseVector_32__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pw_5_cdec_12SparseVector_34__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12SparseVector_34__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__div__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_12SparseVector_31__div__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); + __pyx_r = __pyx_pf_5_cdec_12SparseVector_33__div__(((PyObject *)__pyx_v_x), ((PyObject *)__pyx_v_y)); __Pyx_RefNannyFinishContext(); return __pyx_r; } #endif /*!(#if PY_MAJOR_VERSION < 3)*/ -/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":112 +/* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":119 * return result * * def __div__(x, y): # <<<<<<<<<<<<<< @@ -2947,7 +3156,7 @@ static PyObject *__pyx_pw_5_cdec_12SparseVector_32__div__(PyObject *__pyx_v_x, P */ #if PY_MAJOR_VERSION < 3 -static PyObject *__pyx_pf_5_cdec_12SparseVector_31__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { +static PyObject *__pyx_pf_5_cdec_12SparseVector_33__div__(PyObject *__pyx_v_x, PyObject *__pyx_v_y) { struct __pyx_obj_5_cdec_SparseVector *__pyx_v_vector = 0; float __pyx_v_scalar; struct __pyx_obj_5_cdec_SparseVector *__pyx_v_result = 0; @@ -2961,7 +3170,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_31__div__(PyObject *__pyx_v_x, P int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__div__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":115 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":122 * cdef SparseVector vector * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y # <<<<<<<<<<<<<< @@ -2973,10 +3182,10 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_31__div__(PyObject *__pyx_v_x, P __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_x, __pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_x) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_x, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_x; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_y); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 122; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; @@ -2984,36 +3193,36 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_31__div__(PyObject *__pyx_v_x, P } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":116 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":123 * cdef float scalar * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x # <<<<<<<<<<<<<< * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) */ - if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(((__pyx_v_y) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_y, __pyx_ptype_5_cdec_SparseVector))))) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = __pyx_v_y; __Pyx_INCREF(__pyx_t_1); - __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsFloat(__pyx_v_x); if (unlikely((__pyx_t_3 == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 123; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_vector = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; __pyx_v_scalar = __pyx_t_3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":117 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":124 * if isinstance(x, SparseVector): vector, scalar = x, y * else: vector, scalar = y, x * cdef SparseVector result = SparseVector() # <<<<<<<<<<<<<< * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) * return result */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 117; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 124; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":118 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":125 * else: vector, scalar = y, x * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) # <<<<<<<<<<<<<< @@ -3021,7 +3230,7 @@ static PyObject *__pyx_pf_5_cdec_12SparseVector_31__div__(PyObject *__pyx_v_x, P */ __pyx_v_result->vector = new FastSparseVector(((__pyx_v_vector->vector[0]) / __pyx_v_scalar)); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":119 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":126 * cdef SparseVector result = SparseVector() * result.vector = new FastSparseVector[weight_t](vector.vector[0] / scalar) * return result # <<<<<<<<<<<<<< @@ -3481,7 +3690,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_12generator2(__pyx_GeneratorObject __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L7_resume_from_yield; + case 1: goto __pyx_L10_resume_from_yield; default: /* CPython raises the right error here */ __Pyx_RefNannyFinishContext(); return NULL; @@ -3494,97 +3703,132 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_12generator2(__pyx_GeneratorObject * def kbest(self, size): * cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal](self.hg[0], size) # <<<<<<<<<<<<<< * cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal].Derivation* derivation - * cdef str sentence + * cdef bytes sentence */ __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 33; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,ESentenceTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":37 - * cdef str sentence + * cdef bytes sentence * cdef unsigned k - * for k in range(size): # <<<<<<<<<<<<<< - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break + * try: # <<<<<<<<<<<<<< + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) */ - __pyx_t_2 = __Pyx_PyInt_AsLong(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 37; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { - __pyx_cur_scope->__pyx_v_k = __pyx_t_1; + /*try:*/ { /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":38 * cdef unsigned k - * for k in range(size): - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< - * if not derivation: break - * sentence = GetString(derivation._yield).c_str() - */ - __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":39 - * for k in range(size): - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break # <<<<<<<<<<<<<< - * sentence = GetString(derivation._yield).c_str() - * yield sentence.decode('utf8') - */ - __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0)); - if (__pyx_t_3) { - goto __pyx_L5_break; - goto __pyx_L6; - } - __pyx_L6:; + * try: + * for k in range(size): # <<<<<<<<<<<<<< + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break + */ + __pyx_t_2 = __Pyx_PyInt_AsLong(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 38; __pyx_clineno = __LINE__; goto __pyx_L5;} + for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { + __pyx_cur_scope->__pyx_v_k = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":39 + * try: + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< + * if not derivation: break + * sentence = GetString(derivation._yield).c_str() + */ + __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":40 + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break # <<<<<<<<<<<<<< + * sentence = GetString(derivation._yield).c_str() + * yield sentence.decode('utf8') + */ + __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0)); + if (__pyx_t_3) { + goto __pyx_L8_break; + goto __pyx_L9; + } + __pyx_L9:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":40 - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break - * sentence = GetString(derivation._yield).c_str() # <<<<<<<<<<<<<< - * yield sentence.decode('utf8') - * del derivations + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":41 + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break + * sentence = GetString(derivation._yield).c_str() # <<<<<<<<<<<<<< + * yield sentence.decode('utf8') + * finally: */ - __pyx_t_4 = PyBytes_FromString(TD::GetString(__pyx_cur_scope->__pyx_v_derivation->yield).c_str()); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_4)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_4))->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 40; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); - __pyx_cur_scope->__pyx_v_sentence = ((PyObject*)__pyx_t_4); - __pyx_t_4 = 0; + __pyx_t_4 = PyBytes_FromString(TD::GetString(__pyx_cur_scope->__pyx_v_derivation->yield).c_str()); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __pyx_cur_scope->__pyx_v_sentence = __pyx_t_4; + __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":41 - * if not derivation: break - * sentence = GetString(derivation._yield).c_str() - * yield sentence.decode('utf8') # <<<<<<<<<<<<<< - * del derivations - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":42 + * if not derivation: break + * sentence = GetString(derivation._yield).c_str() + * yield sentence.decode('utf8') # <<<<<<<<<<<<<< + * finally: + * del derivations */ - __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_sentence), __pyx_n_s__decode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 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_L7_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_filename = __pyx_f[2]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_sentence), __pyx_n_s__decode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_7), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 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_L10_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_filename = __pyx_f[2]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L5;} + } + __pyx_L8_break:; } - __pyx_L5_break:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":42 - * sentence = GetString(derivation._yield).c_str() - * yield sentence.decode('utf8') - * del derivations # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":44 + * yield sentence.decode('utf8') + * finally: + * del derivations # <<<<<<<<<<<<<< * * def kbest_tree(self, size): */ - delete __pyx_cur_scope->__pyx_v_derivations; + /*finally:*/ { + int __pyx_why; + PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; + int __pyx_exc_lineno; + __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; + __pyx_why = 0; goto __pyx_L6; + __pyx_L5: { + __pyx_why = 4; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); + __pyx_exc_lineno = __pyx_lineno; + goto __pyx_L6; + } + __pyx_L6:; + delete __pyx_cur_scope->__pyx_v_derivations; + switch (__pyx_why) { + case 4: { + __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); + __pyx_lineno = __pyx_exc_lineno; + __pyx_exc_type = 0; + __pyx_exc_value = 0; + __pyx_exc_tb = 0; + goto __pyx_L1_error; + } + } + } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; @@ -3610,8 +3854,8 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_14kbest_tree(PyObject *__pyx_v_sel return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":44 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":46 + * del derivations * * def kbest_tree(self, size): # <<<<<<<<<<<<<< * cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ETreeTraversal](self.hg[0], size) @@ -3639,7 +3883,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_13kbest_tree(struct __pyx_obj_5_cd __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_15generator3, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_15generator3, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -3670,110 +3914,146 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_15generator3(__pyx_GeneratorObject __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L7_resume_from_yield; + case 1: goto __pyx_L10_resume_from_yield; default: /* CPython raises the right error here */ __Pyx_RefNannyFinishContext(); return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":45 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":47 * * def kbest_tree(self, size): * cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ETreeTraversal](self.hg[0], size) # <<<<<<<<<<<<<< * cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal].Derivation* derivation * cdef str tree */ - __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 47; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,ETreeTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":49 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":51 * cdef str tree * cdef unsigned k - * for k in range(size): # <<<<<<<<<<<<<< - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break + * try: # <<<<<<<<<<<<<< + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) */ - __pyx_t_2 = __Pyx_PyInt_AsLong(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 49; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { - __pyx_cur_scope->__pyx_v_k = __pyx_t_1; + /*try:*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":50 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":52 * cdef unsigned k - * for k in range(size): - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< - * if not derivation: break - * tree = GetString(derivation._yield).c_str() - */ - __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":51 - * for k in range(size): - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break # <<<<<<<<<<<<<< - * tree = GetString(derivation._yield).c_str() - * yield tree.decode('utf8') - */ - __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0)); - if (__pyx_t_3) { - goto __pyx_L5_break; - goto __pyx_L6; - } - __pyx_L6:; + * try: + * for k in range(size): # <<<<<<<<<<<<<< + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break + */ + __pyx_t_2 = __Pyx_PyInt_AsLong(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L5;} + for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { + __pyx_cur_scope->__pyx_v_k = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":53 + * try: + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< + * if not derivation: break + * tree = GetString(derivation._yield).c_str() + */ + __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":54 + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break # <<<<<<<<<<<<<< + * tree = GetString(derivation._yield).c_str() + * yield tree.decode('utf8') + */ + __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0)); + if (__pyx_t_3) { + goto __pyx_L8_break; + goto __pyx_L9; + } + __pyx_L9:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":52 - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break - * tree = GetString(derivation._yield).c_str() # <<<<<<<<<<<<<< - * yield tree.decode('utf8') - * del derivations + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":55 + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break + * tree = GetString(derivation._yield).c_str() # <<<<<<<<<<<<<< + * yield tree.decode('utf8') + * finally: */ - __pyx_t_4 = PyBytes_FromString(TD::GetString(__pyx_cur_scope->__pyx_v_derivation->yield).c_str()); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_4)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_4))->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 52; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_tree)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_tree)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); - __pyx_cur_scope->__pyx_v_tree = ((PyObject*)__pyx_t_4); - __pyx_t_4 = 0; + __pyx_t_4 = PyBytes_FromString(TD::GetString(__pyx_cur_scope->__pyx_v_derivation->yield).c_str()); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_4)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_4))->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_tree)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_tree)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __pyx_cur_scope->__pyx_v_tree = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":53 - * if not derivation: break - * tree = GetString(derivation._yield).c_str() - * yield tree.decode('utf8') # <<<<<<<<<<<<<< - * del derivations - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 + * if not derivation: break + * tree = GetString(derivation._yield).c_str() + * yield tree.decode('utf8') # <<<<<<<<<<<<<< + * finally: + * del derivations */ - __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_tree), __pyx_n_s__decode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 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_L7_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_filename = __pyx_f[2]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_tree), __pyx_n_s__decode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_8), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 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_L10_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_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L5;} + } + __pyx_L8_break:; } - __pyx_L5_break:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":54 - * tree = GetString(derivation._yield).c_str() - * yield tree.decode('utf8') - * del derivations # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":58 + * yield tree.decode('utf8') + * finally: + * del derivations # <<<<<<<<<<<<<< * * def kbest_features(self, size): */ - delete __pyx_cur_scope->__pyx_v_derivations; + /*finally:*/ { + int __pyx_why; + PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; + int __pyx_exc_lineno; + __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; + __pyx_why = 0; goto __pyx_L6; + __pyx_L5: { + __pyx_why = 4; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); + __pyx_exc_lineno = __pyx_lineno; + goto __pyx_L6; + } + __pyx_L6:; + delete __pyx_cur_scope->__pyx_v_derivations; + switch (__pyx_why) { + case 4: { + __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); + __pyx_lineno = __pyx_exc_lineno; + __pyx_exc_type = 0; + __pyx_exc_value = 0; + __pyx_exc_tb = 0; + goto __pyx_L1_error; + } + } + } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; @@ -3799,8 +4079,8 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_17kbest_features(PyObject *__pyx_v return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":60 + * del derivations * * def kbest_features(self, size): # <<<<<<<<<<<<<< * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) @@ -3828,7 +4108,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_16kbest_features(struct __pyx_obj_ __Pyx_INCREF(__pyx_cur_scope->__pyx_v_size); __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_size); { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_18generator4, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_18generator4, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -3858,113 +4138,148 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_18generator4(__pyx_GeneratorObject __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L7_resume_from_yield; + case 1: goto __pyx_L10_resume_from_yield; default: /* CPython raises the right error here */ __Pyx_RefNannyFinishContext(); return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":57 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":61 * * def kbest_features(self, size): * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) # <<<<<<<<<<<<<< * cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal].Derivation* derivation * cdef SparseVector fmap */ - __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyInt_AsUnsignedInt(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_1 == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_cur_scope->__pyx_v_derivations = new KBest::KBestDerivations,FeatureVectorTraversal>((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_t_1); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":61 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":65 * cdef SparseVector fmap * cdef unsigned k - * for k in range(size): # <<<<<<<<<<<<<< - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break + * try: # <<<<<<<<<<<<<< + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) */ - __pyx_t_2 = __Pyx_PyInt_AsLong(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { - __pyx_cur_scope->__pyx_v_k = __pyx_t_1; + /*try:*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":62 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":66 * cdef unsigned k - * for k in range(size): - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< - * if not derivation: break - * fmap = SparseVector() - */ - __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":63 - * for k in range(size): - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break # <<<<<<<<<<<<<< - * fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](derivation._yield) - */ - __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0)); - if (__pyx_t_3) { - goto __pyx_L5_break; - goto __pyx_L6; - } - __pyx_L6:; - - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":64 - * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - * if not derivation: break - * fmap = SparseVector() # <<<<<<<<<<<<<< - * fmap.vector = new FastSparseVector[weight_t](derivation._yield) - * yield fmap - */ - __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); - __Pyx_GIVEREF(__pyx_t_4); - __pyx_cur_scope->__pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_4); - __pyx_t_4 = 0; + * try: + * for k in range(size): # <<<<<<<<<<<<<< + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break + */ + __pyx_t_2 = __Pyx_PyInt_AsLong(__pyx_cur_scope->__pyx_v_size); if (unlikely((__pyx_t_2 == (long)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L5;} + for (__pyx_t_1 = 0; __pyx_t_1 < __pyx_t_2; __pyx_t_1+=1) { + __pyx_cur_scope->__pyx_v_k = __pyx_t_1; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":67 + * try: + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) # <<<<<<<<<<<<<< + * if not derivation: break + * fmap = SparseVector() + */ + __pyx_cur_scope->__pyx_v_derivation = __pyx_cur_scope->__pyx_v_derivations->LazyKthBest((__pyx_cur_scope->__pyx_v_self->hg->nodes_.size() - 1), __pyx_cur_scope->__pyx_v_k); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":68 + * for k in range(size): + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break # <<<<<<<<<<<<<< + * fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) + */ + __pyx_t_3 = (!(__pyx_cur_scope->__pyx_v_derivation != 0)); + if (__pyx_t_3) { + goto __pyx_L8_break; + goto __pyx_L9; + } + __pyx_L9:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":65 - * if not derivation: break - * fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](derivation._yield) # <<<<<<<<<<<<<< - * yield fmap - * del derivations + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":69 + * derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + * if not derivation: break + * fmap = SparseVector() # <<<<<<<<<<<<<< + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) + * yield fmap */ - __pyx_cur_scope->__pyx_v_fmap->vector = new FastSparseVector(__pyx_cur_scope->__pyx_v_derivation->yield); + __pyx_t_4 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SparseVector)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L5;} + __Pyx_GOTREF(__pyx_t_4); + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_cur_scope->__pyx_v_fmap = ((struct __pyx_obj_5_cdec_SparseVector *)__pyx_t_4); + __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":66 - * fmap = SparseVector() - * fmap.vector = new FastSparseVector[weight_t](derivation._yield) - * yield fmap # <<<<<<<<<<<<<< - * del derivations - * - */ - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); - __pyx_r = ((PyObject *)__pyx_cur_scope->__pyx_v_fmap); - __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_L7_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_filename = __pyx_f[2]; __pyx_lineno = 66; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":70 + * if not derivation: break + * fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) # <<<<<<<<<<<<<< + * yield fmap + * finally: + */ + __pyx_cur_scope->__pyx_v_fmap->vector = new FastSparseVector(__pyx_cur_scope->__pyx_v_derivation->yield); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":71 + * fmap = SparseVector() + * fmap.vector = new FastSparseVector[weight_t](derivation._yield) + * yield fmap # <<<<<<<<<<<<<< + * finally: + * del derivations + */ + __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_fmap)); + __pyx_r = ((PyObject *)__pyx_cur_scope->__pyx_v_fmap); + __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_L10_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_filename = __pyx_f[2]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L5;} + } + __pyx_L8_break:; } - __pyx_L5_break:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":67 - * fmap.vector = new FastSparseVector[weight_t](derivation._yield) - * yield fmap - * del derivations # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":73 + * yield fmap + * finally: + * del derivations # <<<<<<<<<<<<<< * * def sample(self, unsigned n): */ - delete __pyx_cur_scope->__pyx_v_derivations; + /*finally:*/ { + int __pyx_why; + PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; + int __pyx_exc_lineno; + __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; + __pyx_why = 0; goto __pyx_L6; + __pyx_L5: { + __pyx_why = 4; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); + __pyx_exc_lineno = __pyx_lineno; + goto __pyx_L6; + } + __pyx_L6:; + delete __pyx_cur_scope->__pyx_v_derivations; + switch (__pyx_why) { + case 4: { + __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); + __pyx_lineno = __pyx_exc_lineno; + __pyx_exc_type = 0; + __pyx_exc_value = 0; + __pyx_exc_tb = 0; + goto __pyx_L1_error; + } + } + } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; @@ -3986,7 +4301,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_20sample(PyObject *__pyx_v_self, P __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("sample (wrapper)", 0); assert(__pyx_arg_n); { - __pyx_v_n = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_n); if (unlikely((__pyx_v_n == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_n = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_n); if (unlikely((__pyx_v_n == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; @@ -3999,8 +4314,8 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_20sample(PyObject *__pyx_v_self, P return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":69 - * del derivations +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":75 + * del derivations * * def sample(self, unsigned n): # <<<<<<<<<<<<<< * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() @@ -4026,7 +4341,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_19sample(struct __pyx_obj_5_cdec_H __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_self); __pyx_cur_scope->__pyx_v_n = __pyx_v_n; { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_21generator5, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_10Hypergraph_21generator5, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -4057,15 +4372,15 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject __Pyx_RefNannySetupContext("None", 0); switch (__pyx_generator->resume_label) { case 0: goto __pyx_L3_first_run; - case 1: goto __pyx_L7_resume_from_yield; + case 1: goto __pyx_L10_resume_from_yield; default: /* CPython raises the right error here */ __Pyx_RefNannyFinishContext(); return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":70 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":76 * * def sample(self, unsigned n): * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() # <<<<<<<<<<<<<< @@ -4074,7 +4389,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject */ __pyx_cur_scope->__pyx_v_hypos = new std::vector(); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":71 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":77 * def sample(self, unsigned n): * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() * if self.rng == NULL: # <<<<<<<<<<<<<< @@ -4084,7 +4399,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject __pyx_t_1 = (__pyx_cur_scope->__pyx_v_self->rng == NULL); if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":72 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":78 * cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() * if self.rng == NULL: * self.rng = new MT19937() # <<<<<<<<<<<<<< @@ -4096,7 +4411,7 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject } __pyx_L4:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":73 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":79 * if self.rng == NULL: * self.rng = new MT19937() * hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) # <<<<<<<<<<<<<< @@ -4105,68 +4420,104 @@ static PyObject *__pyx_gb_5_cdec_10Hypergraph_21generator5(__pyx_GeneratorObject */ HypergraphSampler::sample_hypotheses((__pyx_cur_scope->__pyx_v_self->hg[0]), __pyx_cur_scope->__pyx_v_n, __pyx_cur_scope->__pyx_v_self->rng, __pyx_cur_scope->__pyx_v_hypos); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":76 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":82 * cdef str sentence * cdef unsigned k - * for k in range(hypos.size()): # <<<<<<<<<<<<<< - * sentence = GetString(hypos[0][k].words).c_str() - * yield sentence.decode('utf8') + * try: # <<<<<<<<<<<<<< + * for k in range(hypos.size()): + * sentence = GetString(hypos[0][k].words).c_str() */ - __pyx_t_2 = __pyx_cur_scope->__pyx_v_hypos->size(); - for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { - __pyx_cur_scope->__pyx_v_k = __pyx_t_3; + /*try:*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":77 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":83 * cdef unsigned k - * for k in range(hypos.size()): - * sentence = GetString(hypos[0][k].words).c_str() # <<<<<<<<<<<<<< - * yield sentence.decode('utf8') - * del hypos - */ - __pyx_t_4 = PyBytes_FromString(TD::GetString(((__pyx_cur_scope->__pyx_v_hypos[0])[__pyx_cur_scope->__pyx_v_k]).words).c_str()); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(((PyObject *)__pyx_t_4)); - if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_4)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_4))->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence)); - __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); - __pyx_cur_scope->__pyx_v_sentence = ((PyObject*)__pyx_t_4); - __pyx_t_4 = 0; + * try: + * for k in range(hypos.size()): # <<<<<<<<<<<<<< + * sentence = GetString(hypos[0][k].words).c_str() + * yield sentence.decode('utf8') + */ + __pyx_t_2 = __pyx_cur_scope->__pyx_v_hypos->size(); + for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { + __pyx_cur_scope->__pyx_v_k = __pyx_t_3; + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":84 + * try: + * for k in range(hypos.size()): + * sentence = GetString(hypos[0][k].words).c_str() # <<<<<<<<<<<<<< + * yield sentence.decode('utf8') + * finally: + */ + __pyx_t_4 = PyBytes_FromString(TD::GetString(((__pyx_cur_scope->__pyx_v_hypos[0])[__pyx_cur_scope->__pyx_v_k]).words).c_str()); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} + __Pyx_GOTREF(((PyObject *)__pyx_t_4)); + if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_4)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_4))->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L6;} + __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence)); + __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_sentence)); + __Pyx_GIVEREF(((PyObject *)__pyx_t_4)); + __pyx_cur_scope->__pyx_v_sentence = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":78 - * for k in range(hypos.size()): - * sentence = GetString(hypos[0][k].words).c_str() - * yield sentence.decode('utf8') # <<<<<<<<<<<<<< - * del hypos - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":85 + * for k in range(hypos.size()): + * sentence = GetString(hypos[0][k].words).c_str() + * yield sentence.decode('utf8') # <<<<<<<<<<<<<< + * finally: + * del hypos */ - __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_sentence), __pyx_n_s__decode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_r = __pyx_t_5; - __pyx_t_5 = 0; - __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; - __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; - __Pyx_XGIVEREF(__pyx_r); - __Pyx_RefNannyFinishContext(); - /* return from generator, yielding value */ - __pyx_generator->resume_label = 1; - return __pyx_r; - __pyx_L7_resume_from_yield:; - __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; - __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = PyObject_GetAttr(((PyObject *)__pyx_cur_scope->__pyx_v_sentence), __pyx_n_s__decode); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L6;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyObject_Call(__pyx_t_4, ((PyObject *)__pyx_k_tuple_9), NULL); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L6;} + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + __pyx_cur_scope->__pyx_t_0 = __pyx_t_2; + __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + /* return from generator, yielding value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L10_resume_from_yield:; + __pyx_t_2 = __pyx_cur_scope->__pyx_t_0; + __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L6;} + } } - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":79 - * sentence = GetString(hypos[0][k].words).c_str() - * yield sentence.decode('utf8') - * del hypos # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":87 + * yield sentence.decode('utf8') + * finally: + * del hypos # <<<<<<<<<<<<<< * * # TODO richer k-best/sample output (feature vectors, trees?) */ - delete __pyx_cur_scope->__pyx_v_hypos; + /*finally:*/ { + int __pyx_why; + PyObject *__pyx_exc_type, *__pyx_exc_value, *__pyx_exc_tb; + int __pyx_exc_lineno; + __pyx_exc_type = 0; __pyx_exc_value = 0; __pyx_exc_tb = 0; __pyx_exc_lineno = 0; + __pyx_why = 0; goto __pyx_L7; + __pyx_L6: { + __pyx_why = 4; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_ErrFetch(&__pyx_exc_type, &__pyx_exc_value, &__pyx_exc_tb); + __pyx_exc_lineno = __pyx_lineno; + goto __pyx_L7; + } + __pyx_L7:; + delete __pyx_cur_scope->__pyx_v_hypos; + switch (__pyx_why) { + case 4: { + __Pyx_ErrRestore(__pyx_exc_type, __pyx_exc_value, __pyx_exc_tb); + __pyx_lineno = __pyx_exc_lineno; + __pyx_exc_type = 0; + __pyx_exc_value = 0; + __pyx_exc_tb = 0; + goto __pyx_L1_error; + } + } + } PyErr_SetNone(PyExc_StopIteration); goto __pyx_L0; __pyx_L1_error:; @@ -4186,7 +4537,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_23intersect(PyObject *__pyx_v_self PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("intersect (wrapper)", 0); - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lat), __pyx_ptype_5_cdec_Lattice, 1, "lat", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lat), __pyx_ptype_5_cdec_Lattice, 1, "lat", 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = __pyx_pf_5_cdec_10Hypergraph_22intersect(((struct __pyx_obj_5_cdec_Hypergraph *)__pyx_v_self), ((struct __pyx_obj_5_cdec_Lattice *)__pyx_v_lat)); goto __pyx_L0; __pyx_L1_error:; @@ -4196,7 +4547,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_23intersect(PyObject *__pyx_v_self return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":83 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":91 * # TODO richer k-best/sample output (feature vectors, trees?) * * def intersect(self, Lattice lat): # <<<<<<<<<<<<<< @@ -4213,7 +4564,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_22intersect(struct __pyx_obj_5_cde int __pyx_clineno = 0; __Pyx_RefNannySetupContext("intersect", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":84 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":92 * * def intersect(self, Lattice lat): * return hypergraph.Intersect(lat.lattice[0], self.hg) # <<<<<<<<<<<<<< @@ -4221,7 +4572,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_22intersect(struct __pyx_obj_5_cde * def prune(self, beam_alpha=0, density=0, **kwargs): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_PyBool_FromLong(HG::Intersect((__pyx_v_lat->lattice[0]), __pyx_v_self->hg)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_PyBool_FromLong(HG::Intersect((__pyx_v_lat->lattice[0]), __pyx_v_self->hg)); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -4278,7 +4629,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_25prune(PyObject *__pyx_v_self, Py } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "prune") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_kwargs, values, pos_args, "prune") < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -4293,7 +4644,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_25prune(PyObject *__pyx_v_self, Py } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("prune", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("prune", 0, 0, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; __Pyx_AddTraceback("_cdec.Hypergraph.prune", __pyx_clineno, __pyx_lineno, __pyx_filename); @@ -4306,7 +4657,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_25prune(PyObject *__pyx_v_self, Py return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":86 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":94 * return hypergraph.Intersect(lat.lattice[0], self.hg) * * def prune(self, beam_alpha=0, density=0, **kwargs): # <<<<<<<<<<<<<< @@ -4326,7 +4677,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_24prune(struct __pyx_obj_5_cdec_Hy int __pyx_clineno = 0; __Pyx_RefNannySetupContext("prune", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":87 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":95 * * def prune(self, beam_alpha=0, density=0, **kwargs): * cdef hypergraph.EdgeMask* preserve_mask = NULL # <<<<<<<<<<<<<< @@ -4335,17 +4686,17 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_24prune(struct __pyx_obj_5_cdec_Hy */ __pyx_v_preserve_mask = NULL; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":88 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":96 * def prune(self, beam_alpha=0, density=0, **kwargs): * cdef hypergraph.EdgeMask* preserve_mask = NULL * if 'csplit_preserve_full_word' in kwargs: # <<<<<<<<<<<<<< * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True */ - __pyx_t_1 = ((PyDict_Contains(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s_10)))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = ((PyDict_Contains(((PyObject *)__pyx_v_kwargs), ((PyObject *)__pyx_n_s_10)))); if (unlikely(__pyx_t_1 < 0)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__pyx_t_1) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":89 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":97 * cdef hypergraph.EdgeMask* preserve_mask = NULL * if 'csplit_preserve_full_word' in kwargs: * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) # <<<<<<<<<<<<<< @@ -4354,28 +4705,50 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_24prune(struct __pyx_obj_5_cdec_Hy */ __pyx_v_preserve_mask = new std::vector(__pyx_v_self->hg->edges_.size()); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":90 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":98 * if 'csplit_preserve_full_word' in kwargs: * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True # <<<<<<<<<<<<<< * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) - * + * if preserve_mask: */ ((__pyx_v_preserve_mask[0])[CompoundSplit::GetFullWordEdgeIndex((__pyx_v_self->hg[0]))]) = 1; goto __pyx_L3; } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":91 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":99 * preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) # <<<<<<<<<<<<<< + * if preserve_mask: + * del preserve_mask + */ + __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_beam_alpha); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_density); if (unlikely((__pyx_t_3 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_self->hg->PruneInsideOutside(__pyx_t_2, __pyx_t_3, __pyx_v_preserve_mask, 0, 1.0, 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":100 + * preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True + * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) + * if preserve_mask: # <<<<<<<<<<<<<< + * del preserve_mask + * + */ + __pyx_t_1 = (__pyx_v_preserve_mask != 0); + if (__pyx_t_1) { + + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":101 + * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) + * if preserve_mask: + * del preserve_mask # <<<<<<<<<<<<<< * * def lattice(self): # TODO direct hg -> lattice conversion in cdec */ - __pyx_t_2 = __pyx_PyFloat_AsDouble(__pyx_v_beam_alpha); if (unlikely((__pyx_t_2 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_t_3 = __pyx_PyFloat_AsDouble(__pyx_v_density); if (unlikely((__pyx_t_3 == (double)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 91; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_v_self->hg->PruneInsideOutside(__pyx_t_2, __pyx_t_3, __pyx_v_preserve_mask, 0, 1.0, 0); + delete __pyx_v_preserve_mask; + goto __pyx_L4; + } + __pyx_L4:; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; @@ -4399,8 +4772,8 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_27lattice(PyObject *__pyx_v_self, return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":93 - * self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":103 + * del preserve_mask * * def lattice(self): # TODO direct hg -> lattice conversion in cdec # <<<<<<<<<<<<<< * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() @@ -4419,20 +4792,20 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_26lattice(struct __pyx_obj_5_cdec_ int __pyx_clineno = 0; __Pyx_RefNannySetupContext("lattice", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":94 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":104 * * def lattice(self): # TODO direct hg -> lattice conversion in cdec * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() # <<<<<<<<<<<<<< * return Lattice(eval(plf)) * */ - __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->hg[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(HypergraphIO::AsPLF((__pyx_v_self->hg[0]), 1).c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_1)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_1))->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (!(likely(PyString_CheckExact(((PyObject *)__pyx_t_1)))||(PyErr_Format(PyExc_TypeError, "Expected str, got %.200s", Py_TYPE(((PyObject *)__pyx_t_1))->tp_name), 0))) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 104; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_plf = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":95 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":105 * def lattice(self): # TODO direct hg -> lattice conversion in cdec * cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() * return Lattice(eval(plf)) # <<<<<<<<<<<<<< @@ -4440,17 +4813,17 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_26lattice(struct __pyx_obj_5_cdec_ * def reweight(self, weights): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __Pyx_Globals(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = __Pyx_Globals(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); if (((PyObject *)__pyx_v_plf)) { - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__plf), ((PyObject *)__pyx_v_plf)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__plf), ((PyObject *)__pyx_v_plf)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } if (((PyObject *)__pyx_v_self)) { - if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_v_self)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyDict_SetItem(__pyx_t_2, ((PyObject *)__pyx_n_s__self), ((PyObject *)__pyx_v_self)) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } - __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(((PyObject *)__pyx_v_plf)); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_v_plf)); @@ -4461,15 +4834,15 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_26lattice(struct __pyx_obj_5_cdec_ __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); __pyx_t_1 = 0; __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(__pyx_builtin_eval, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(__pyx_builtin_eval, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Lattice)), ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; @@ -4502,7 +4875,7 @@ static PyObject *__pyx_pw_5_cdec_10Hypergraph_29reweight(PyObject *__pyx_v_self, return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":97 +/* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":107 * return Lattice(eval(plf)) * * def reweight(self, weights): # <<<<<<<<<<<<<< @@ -4521,7 +4894,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec int __pyx_clineno = 0; __Pyx_RefNannySetupContext("reweight", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":98 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":108 * * def reweight(self, weights): * if isinstance(weights, SparseVector): # <<<<<<<<<<<<<< @@ -4534,7 +4907,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":99 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":109 * def reweight(self, weights): * if isinstance(weights, SparseVector): * self.hg.Reweight(( weights).vector[0]) # <<<<<<<<<<<<<< @@ -4545,7 +4918,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec goto __pyx_L3; } - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":100 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":110 * if isinstance(weights, SparseVector): * self.hg.Reweight(( weights).vector[0]) * elif isinstance(weights, DenseVector): # <<<<<<<<<<<<<< @@ -4558,7 +4931,7 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":101 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":111 * self.hg.Reweight(( weights).vector[0]) * elif isinstance(weights, DenseVector): * self.hg.Reweight(( weights).vector[0]) # <<<<<<<<<<<<<< @@ -4570,26 +4943,26 @@ static PyObject *__pyx_pf_5_cdec_10Hypergraph_28reweight(struct __pyx_obj_5_cdec } /*else*/ { - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":103 + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":113 * self.hg.Reweight(( weights).vector[0]) * else: * raise TypeError('cannot reweight hypergraph with %s' % type(weights)) # <<<<<<<<<<<<<< * * # TODO get feature expectations, get partition function ("inside" score) */ - __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyNumber_Remainder(((PyObject *)__pyx_kp_s_11), ((PyObject *)Py_TYPE(__pyx_v_weights))); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); - __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_t_1)); __Pyx_GIVEREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; - __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(__pyx_builtin_TypeError, ((PyObject *)__pyx_t_3), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_3)); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - {__pyx_filename = __pyx_f[2]; __pyx_lineno = 103; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + {__pyx_filename = __pyx_f[2]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } __pyx_L3:; @@ -6396,7 +6769,7 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(struct __pyx_obj_5_c * result.metric = x.metric * return result # <<<<<<<<<<<<<< * - * cdef class SegmentEvaluator: + * cdef class CandidateSet: */ __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)__pyx_v_result)); @@ -6417,230 +6790,308 @@ static PyObject *__pyx_pf_5_cdec_15SufficientStats_9__add__(struct __pyx_obj_5_c } /* Python wrapper */ -static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ -static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self) { +static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_5_cdec_12CandidateSet_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator = 0; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__evaluator,0}; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + { + PyObject* values[1] = {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 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__evaluator); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + } + __pyx_v_evaluator = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)values[0]); + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.CandidateSet.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_evaluator), __pyx_ptype_5_cdec_SegmentEvaluator, 1, "evaluator", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 64; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12CandidateSet___cinit__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), __pyx_v_evaluator); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":64 + * cdef mteval.CandidateSet* cs + * + * def __cinit__(self, SegmentEvaluator evaluator): # <<<<<<<<<<<<<< + * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) + * self.metric = evaluator.metric + */ + +static int __pyx_pf_5_cdec_12CandidateSet___cinit__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_evaluator) { + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":65 + * + * def __cinit__(self, SegmentEvaluator evaluator): + * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) # <<<<<<<<<<<<<< + * self.metric = evaluator.metric + * self.cs = new mteval.CandidateSet() + */ + __pyx_v_self->scorer = new boost::shared_ptr((__pyx_v_evaluator->scorer[0])); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":66 + * def __cinit__(self, SegmentEvaluator evaluator): + * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) + * self.metric = evaluator.metric # <<<<<<<<<<<<<< + * self.cs = new mteval.CandidateSet() + * + */ + __pyx_v_self->metric = __pyx_v_evaluator->metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":67 + * self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) + * self.metric = evaluator.metric + * self.cs = new mteval.CandidateSet() # <<<<<<<<<<<<<< + * + * def __dealloc__(self): + */ + __pyx_v_self->cs = new training::CandidateSet(); + + __pyx_r = 0; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(PyObject *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); - __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self)); + __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":63 - * cdef mteval.EvaluationMetric* metric +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":69 + * self.cs = new mteval.CandidateSet() * * def __dealloc__(self): # <<<<<<<<<<<<<< * del self.scorer - * + * del self.cs */ -static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self) { +static void __pyx_pf_5_cdec_12CandidateSet_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__dealloc__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":64 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":70 * * def __dealloc__(self): * del self.scorer # <<<<<<<<<<<<<< + * del self.cs * - * def evaluate(self, sentence): */ delete __pyx_v_self->scorer; + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":71 + * def __dealloc__(self): + * del self.scorer + * del self.cs # <<<<<<<<<<<<<< + * + * def __len__(self): + */ + delete __pyx_v_self->cs; + __Pyx_RefNannyFinishContext(); } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence); /*proto*/ -static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence) { +static Py_ssize_t __pyx_pw_5_cdec_12CandidateSet_5__len__(PyObject *__pyx_v_self); /*proto*/ +static Py_ssize_t __pyx_pw_5_cdec_12CandidateSet_5__len__(PyObject *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12CandidateSet_4__len__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":73 + * del self.cs + * + * def __len__(self): # <<<<<<<<<<<<<< + * return self.cs.size() + * + */ + +static Py_ssize_t __pyx_pf_5_cdec_12CandidateSet_4__len__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { + Py_ssize_t __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__len__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":74 + * + * def __len__(self): + * return self.cs.size() # <<<<<<<<<<<<<< + * + * def __getitem__(self, unsigned k): + */ + __pyx_r = __pyx_v_self->cs->size(); + goto __pyx_L0; + + __pyx_r = 0; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_k); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_7__getitem__(PyObject *__pyx_v_self, PyObject *__pyx_arg_k) { + unsigned int __pyx_v_k; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("evaluate (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self), ((PyObject *)__pyx_v_sentence)); + __Pyx_RefNannySetupContext("__getitem__ (wrapper)", 0); + assert(__pyx_arg_k); { + __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(__pyx_arg_k); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.CandidateSet.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_5_cdec_12CandidateSet_6__getitem__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), ((unsigned int)__pyx_v_k)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":66 - * del self.scorer +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":76 + * return self.cs.size() * - * def evaluate(self, sentence): # <<<<<<<<<<<<<< - * cdef vector[WordID] hyp - * cdef SufficientStats sf = SufficientStats() + * def __getitem__(self, unsigned k): # <<<<<<<<<<<<<< + * cdef Candidate candidate = Candidate() + * candidate.candidate = &self.cs[0][k] */ -static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, PyObject *__pyx_v_sentence) { - std::vector __pyx_v_hyp; - struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sf = 0; +static PyObject *__pyx_pf_5_cdec_12CandidateSet_6__getitem__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, unsigned int __pyx_v_k) { + struct __pyx_obj_5_cdec_Candidate *__pyx_v_candidate = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; - PyObject *__pyx_t_2 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("evaluate", 0); + __Pyx_RefNannySetupContext("__getitem__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":68 - * def evaluate(self, sentence): - * cdef vector[WordID] hyp - * cdef SufficientStats sf = SufficientStats() # <<<<<<<<<<<<<< - * sf.metric = self.metric - * sf.stats = new mteval.SufficientStats() + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":77 + * + * def __getitem__(self, unsigned k): + * cdef Candidate candidate = Candidate() # <<<<<<<<<<<<<< + * candidate.candidate = &self.cs[0][k] + * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 68; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Candidate)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 77; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - __pyx_v_sf = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_v_candidate = ((struct __pyx_obj_5_cdec_Candidate *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":69 - * cdef vector[WordID] hyp - * cdef SufficientStats sf = SufficientStats() - * sf.metric = self.metric # <<<<<<<<<<<<<< - * sf.stats = new mteval.SufficientStats() - * ConvertSentence(string(as_str(sentence.strip())), &hyp) - */ - __pyx_v_sf->metric = __pyx_v_self->metric; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":70 - * cdef SufficientStats sf = SufficientStats() - * sf.metric = self.metric - * sf.stats = new mteval.SufficientStats() # <<<<<<<<<<<<<< - * ConvertSentence(string(as_str(sentence.strip())), &hyp) - * self.scorer.get().Evaluate(hyp, sf.stats) - */ - __pyx_v_sf->stats = new SufficientStats(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":71 - * sf.metric = self.metric - * sf.stats = new mteval.SufficientStats() - * ConvertSentence(string(as_str(sentence.strip())), &hyp) # <<<<<<<<<<<<<< - * self.scorer.get().Evaluate(hyp, sf.stats) - * return sf + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":78 + * def __getitem__(self, unsigned k): + * cdef Candidate candidate = Candidate() + * candidate.candidate = &self.cs[0][k] # <<<<<<<<<<<<<< + * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) + * return candidate */ - __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_2, NULL)), (&__pyx_v_hyp)); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_v_candidate->candidate = (&((__pyx_v_self->cs[0])[__pyx_v_k])); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":72 - * sf.stats = new mteval.SufficientStats() - * ConvertSentence(string(as_str(sentence.strip())), &hyp) - * self.scorer.get().Evaluate(hyp, sf.stats) # <<<<<<<<<<<<<< - * return sf + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":79 + * cdef Candidate candidate = Candidate() + * candidate.candidate = &self.cs[0][k] + * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) # <<<<<<<<<<<<<< + * return candidate * */ - __pyx_v_self->scorer->get()->Evaluate(__pyx_v_hyp, __pyx_v_sf->stats); + __pyx_v_candidate->score = __pyx_v_self->metric->ComputeScore(((__pyx_v_self->cs[0])[__pyx_v_k]).eval_feats); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":73 - * ConvertSentence(string(as_str(sentence.strip())), &hyp) - * self.scorer.get().Evaluate(hyp, sf.stats) - * return sf # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":80 + * candidate.candidate = &self.cs[0][k] + * candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) + * return candidate # <<<<<<<<<<<<<< * - * def candidate_set(self, Hypergraph hypergraph, unsigned k): + * def __iter__(self): */ __Pyx_XDECREF(__pyx_r); - __Pyx_INCREF(((PyObject *)__pyx_v_sf)); - __pyx_r = ((PyObject *)__pyx_v_sf); + __Pyx_INCREF(((PyObject *)__pyx_v_candidate)); + __pyx_r = ((PyObject *)__pyx_v_candidate); goto __pyx_L0; __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_AddTraceback("_cdec.SegmentEvaluator.evaluate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.CandidateSet.__getitem__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF((PyObject *)__pyx_v_sf); + __Pyx_XDECREF((PyObject *)__pyx_v_candidate); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_16SegmentEvaluator_6generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ +static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */ /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph = 0; - unsigned int __pyx_v_k; - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__hypergraph,&__pyx_n_s__k,0}; +static PyObject *__pyx_pw_5_cdec_12CandidateSet_9__iter__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_9__iter__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations - __Pyx_RefNannySetupContext("candidate_set (wrapper)", 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); - case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); - case 0: break; - default: goto __pyx_L5_argtuple_error; - } - kw_args = PyDict_Size(__pyx_kwds); - switch (pos_args) { - case 0: - values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__hypergraph); - if (likely(values[0])) kw_args--; - else goto __pyx_L5_argtuple_error; - case 1: - values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k); - if (likely(values[1])) kw_args--; - else { - __Pyx_RaiseArgtupleInvalid("candidate_set", 1, 2, 2, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - } - if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "candidate_set") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __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_hypergraph = ((struct __pyx_obj_5_cdec_Hypergraph *)values[0]); - __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - } - goto __pyx_L4_argument_unpacking_done; - __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("candidate_set", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L3_error;} - __pyx_L3_error:; - __Pyx_AddTraceback("_cdec.SegmentEvaluator.candidate_set", __pyx_clineno, __pyx_lineno, __pyx_filename); - __Pyx_RefNannyFinishContext(); - return NULL; - __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_hypergraph), __pyx_ptype_5_cdec_Hypergraph, 1, "hypergraph", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self), __pyx_v_hypergraph, __pyx_v_k); - goto __pyx_L0; - __pyx_L1_error:; - __pyx_r = NULL; - __pyx_L0:; + __Pyx_RefNannySetupContext("__iter__ (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_12CandidateSet_8__iter__(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":75 - * return sf +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 + * return candidate * - * def candidate_set(self, Hypergraph hypergraph, unsigned k): # <<<<<<<<<<<<<< - * cdef mteval.CandidateSet* cs = new mteval.CandidateSet() - * cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) + * def __iter__(self): # <<<<<<<<<<<<<< + * cdef unsigned i + * for i in range(len(self)): */ -static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph, unsigned int __pyx_v_k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *__pyx_cur_scope; +static PyObject *__pyx_pf_5_cdec_12CandidateSet_8__iter__(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *__pyx_cur_scope; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; - __Pyx_RefNannySetupContext("candidate_set", 0); - __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)__pyx_ptype_5_cdec___pyx_scope_struct_8_candidate_set->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_8_candidate_set, __pyx_empty_tuple, NULL); + __Pyx_RefNannySetupContext("__iter__", 0); + __pyx_cur_scope = (struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *)__pyx_ptype_5_cdec___pyx_scope_struct_8___iter__->tp_new(__pyx_ptype_5_cdec___pyx_scope_struct_8___iter__, __pyx_empty_tuple, NULL); if (unlikely(!__pyx_cur_scope)) { __Pyx_RefNannyFinishContext(); return NULL; @@ -6649,12 +7100,8 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_ __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_cur_scope->__pyx_v_hypergraph = __pyx_v_hypergraph; - __Pyx_INCREF((PyObject *)__pyx_cur_scope->__pyx_v_hypergraph); - __Pyx_GIVEREF((PyObject *)__pyx_cur_scope->__pyx_v_hypergraph); - __pyx_cur_scope->__pyx_v_k = __pyx_v_k; { - __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_16SegmentEvaluator_6generator8, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_GeneratorObject *gen = __Pyx_Generator_New((__pyx_generator_body_t) __pyx_gb_5_cdec_12CandidateSet_10generator8, (PyObject *) __pyx_cur_scope); if (unlikely(!gen)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_cur_scope); __Pyx_RefNannyFinishContext(); return (PyObject *) gen; @@ -6663,7 +7110,7 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_AddTraceback("_cdec.SegmentEvaluator.candidate_set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("_cdec.CandidateSet.__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_DECREF(((PyObject *)__pyx_cur_scope)); @@ -6672,11 +7119,11 @@ static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_ return __pyx_r; } -static PyObject *__pyx_gb_5_cdec_16SegmentEvaluator_6generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ +static PyObject *__pyx_gb_5_cdec_12CandidateSet_10generator8(__pyx_GeneratorObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */ { - struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)__pyx_generator->closure); + struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *__pyx_cur_scope = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *)__pyx_generator->closure); PyObject *__pyx_r = NULL; - unsigned int __pyx_t_1; + Py_ssize_t __pyx_t_1; unsigned int __pyx_t_2; PyObject *__pyx_t_3 = NULL; __Pyx_RefNannyDeclarations @@ -6689,79 +7136,30 @@ static PyObject *__pyx_gb_5_cdec_16SegmentEvaluator_6generator8(__pyx_GeneratorO return NULL; } __pyx_L3_first_run:; - if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":76 - * - * def candidate_set(self, Hypergraph hypergraph, unsigned k): - * cdef mteval.CandidateSet* cs = new mteval.CandidateSet() # <<<<<<<<<<<<<< - * cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) - * cdef Candidate candidate - */ - __pyx_cur_scope->__pyx_v_cs = new training::CandidateSet(); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":77 - * def candidate_set(self, Hypergraph hypergraph, unsigned k): - * cdef mteval.CandidateSet* cs = new mteval.CandidateSet() - * cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) # <<<<<<<<<<<<<< - * cdef Candidate candidate - * cdef unsigned i - */ - __pyx_cur_scope->__pyx_v_cs->AddKBestCandidates((__pyx_cur_scope->__pyx_v_hypergraph->hg[0]), __pyx_cur_scope->__pyx_v_k, __pyx_cur_scope->__pyx_v_self->scorer->get()); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":80 - * cdef Candidate candidate + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":84 + * def __iter__(self): * cdef unsigned i - * for i in range(cs.size()): # <<<<<<<<<<<<<< - * candidate = Candidate() - * candidate.candidate = &cs[0][i] + * for i in range(len(self)): # <<<<<<<<<<<<<< + * yield self[i] + * */ - __pyx_t_1 = __pyx_cur_scope->__pyx_v_cs->size(); + __pyx_t_1 = PyObject_Length(((PyObject *)__pyx_cur_scope->__pyx_v_self)); if (unlikely(__pyx_t_1 == -1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) { __pyx_cur_scope->__pyx_v_i = __pyx_t_2; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":81 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":85 * cdef unsigned i - * for i in range(cs.size()): - * candidate = Candidate() # <<<<<<<<<<<<<< - * candidate.candidate = &cs[0][i] - * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) + * for i in range(len(self)): + * yield self[i] # <<<<<<<<<<<<<< + * + * def add_kbest(self, Hypergraph hypergraph, unsigned k): */ - __pyx_t_3 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Candidate)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_3 = __Pyx_GetItemInt(((PyObject *)__pyx_cur_scope->__pyx_v_self), __pyx_cur_scope->__pyx_v_i, sizeof(unsigned int)+1, PyLong_FromUnsignedLong); if (!__pyx_t_3) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); - __Pyx_XGOTREF(((PyObject *)__pyx_cur_scope->__pyx_v_candidate)); - __Pyx_XDECREF(((PyObject *)__pyx_cur_scope->__pyx_v_candidate)); - __Pyx_GIVEREF(__pyx_t_3); - __pyx_cur_scope->__pyx_v_candidate = ((struct __pyx_obj_5_cdec_Candidate *)__pyx_t_3); + __pyx_r = __pyx_t_3; __pyx_t_3 = 0; - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":82 - * for i in range(cs.size()): - * candidate = Candidate() - * candidate.candidate = &cs[0][i] # <<<<<<<<<<<<<< - * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) - * yield candidate - */ - __pyx_cur_scope->__pyx_v_candidate->candidate = (&((__pyx_cur_scope->__pyx_v_cs[0])[__pyx_cur_scope->__pyx_v_i])); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":83 - * candidate = Candidate() - * candidate.candidate = &cs[0][i] - * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) # <<<<<<<<<<<<<< - * yield candidate - * del cs - */ - __pyx_cur_scope->__pyx_v_candidate->score = __pyx_cur_scope->__pyx_v_self->metric->ComputeScore(((__pyx_cur_scope->__pyx_v_cs[0])[__pyx_cur_scope->__pyx_v_i]).eval_feats); - - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":84 - * candidate.candidate = &cs[0][i] - * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) - * yield candidate # <<<<<<<<<<<<<< - * del cs - * - */ - __Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_v_candidate)); - __pyx_r = ((PyObject *)__pyx_cur_scope->__pyx_v_candidate); __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; __Pyx_XGIVEREF(__pyx_r); @@ -6772,27 +7170,315 @@ static PyObject *__pyx_gb_5_cdec_16SegmentEvaluator_6generator8(__pyx_GeneratorO __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_filename = __pyx_f[4]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (unlikely(!__pyx_sent_value)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("__iter__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); + __pyx_generator->resume_label = -1; + __Pyx_RefNannyFinishContext(); + return NULL; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_12CandidateSet_12add_kbest(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph = 0; + unsigned int __pyx_v_k; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__hypergraph,&__pyx_n_s__k,0}; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("add_kbest (wrapper)", 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); + case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = PyDict_Size(__pyx_kwds); + switch (pos_args) { + case 0: + values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__hypergraph); + if (likely(values[0])) kw_args--; + else goto __pyx_L5_argtuple_error; + case 1: + values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__k); + if (likely(values[1])) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, 1); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + } + if (unlikely(kw_args > 0)) { + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "add_kbest") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __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_hypergraph = ((struct __pyx_obj_5_cdec_Hypergraph *)values[0]); + __pyx_v_k = __Pyx_PyInt_AsUnsignedInt(values[1]); if (unlikely((__pyx_v_k == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + } + goto __pyx_L4_argument_unpacking_done; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("add_kbest", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_L3_error:; + __Pyx_AddTraceback("_cdec.CandidateSet.add_kbest", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_hypergraph), __pyx_ptype_5_cdec_Hypergraph, 1, "hypergraph", 0))) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_r = __pyx_pf_5_cdec_12CandidateSet_11add_kbest(((struct __pyx_obj_5_cdec_CandidateSet *)__pyx_v_self), __pyx_v_hypergraph, __pyx_v_k); + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":87 + * yield self[i] + * + * def add_kbest(self, Hypergraph hypergraph, unsigned k): # <<<<<<<<<<<<<< + * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) + * + */ + +static PyObject *__pyx_pf_5_cdec_12CandidateSet_11add_kbest(struct __pyx_obj_5_cdec_CandidateSet *__pyx_v_self, struct __pyx_obj_5_cdec_Hypergraph *__pyx_v_hypergraph, unsigned int __pyx_v_k) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("add_kbest", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":88 + * + * def add_kbest(self, Hypergraph hypergraph, unsigned k): + * self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) # <<<<<<<<<<<<<< + * + * cdef class SegmentEvaluator: + */ + __pyx_v_self->cs->AddKBestCandidates((__pyx_v_hypergraph->hg[0]), __pyx_v_k, __pyx_v_self->scorer->get()); + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_16SegmentEvaluator_1__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":94 + * cdef mteval.EvaluationMetric* metric + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.scorer + * + */ + +static void __pyx_pf_5_cdec_16SegmentEvaluator___dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":95 + * + * def __dealloc__(self): + * del self.scorer # <<<<<<<<<<<<<< + * + * def evaluate(self, sentence): + */ + delete __pyx_v_self->scorer; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence); /*proto*/ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate(PyObject *__pyx_v_self, PyObject *__pyx_v_sentence) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("evaluate (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self), ((PyObject *)__pyx_v_sentence)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":97 + * del self.scorer + * + * def evaluate(self, sentence): # <<<<<<<<<<<<<< + * cdef vector[WordID] hyp + * cdef SufficientStats sf = SufficientStats() + */ + +static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_2evaluate(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self, PyObject *__pyx_v_sentence) { + std::vector __pyx_v_hyp; + struct __pyx_obj_5_cdec_SufficientStats *__pyx_v_sf = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("evaluate", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":99 + * def evaluate(self, sentence): + * cdef vector[WordID] hyp + * cdef SufficientStats sf = SufficientStats() # <<<<<<<<<<<<<< + * sf.metric = self.metric + * sf.stats = new mteval.SufficientStats() + */ + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SufficientStats)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 99; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_v_sf = ((struct __pyx_obj_5_cdec_SufficientStats *)__pyx_t_1); + __pyx_t_1 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":100 + * cdef vector[WordID] hyp + * cdef SufficientStats sf = SufficientStats() + * sf.metric = self.metric # <<<<<<<<<<<<<< + * sf.stats = new mteval.SufficientStats() + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + */ + __pyx_v_sf->metric = __pyx_v_self->metric; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":101 + * cdef SufficientStats sf = SufficientStats() + * sf.metric = self.metric + * sf.stats = new mteval.SufficientStats() # <<<<<<<<<<<<<< + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + * self.scorer.get().Evaluate(hyp, sf.stats) + */ + __pyx_v_sf->stats = new SufficientStats(); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":102 + * sf.metric = self.metric + * sf.stats = new mteval.SufficientStats() + * ConvertSentence(string(as_str(sentence.strip())), &hyp) # <<<<<<<<<<<<<< + * self.scorer.get().Evaluate(hyp, sf.stats) + * return sf + */ + __pyx_t_1 = PyObject_GetAttr(__pyx_v_sentence, __pyx_n_s__strip); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_2, NULL)), (&__pyx_v_hyp)); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":103 + * sf.stats = new mteval.SufficientStats() + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + * self.scorer.get().Evaluate(hyp, sf.stats) # <<<<<<<<<<<<<< + * return sf + * + */ + __pyx_v_self->scorer->get()->Evaluate(__pyx_v_hyp, __pyx_v_sf->stats); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":104 + * ConvertSentence(string(as_str(sentence.strip())), &hyp) + * self.scorer.get().Evaluate(hyp, sf.stats) + * return sf # <<<<<<<<<<<<<< + * + * def candidate_set(self): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(((PyObject *)__pyx_v_sf)); + __pyx_r = ((PyObject *)__pyx_v_sf); + goto __pyx_L0; + + __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_AddTraceback("_cdec.SegmentEvaluator.evaluate", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF((PyObject *)__pyx_v_sf); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyObject *__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set(PyObject *__pyx_v_self, CYTHON_UNUSED PyObject *unused) { + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("candidate_set (wrapper)", 0); + __pyx_r = __pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":106 + * return sf + * + * def candidate_set(self): # <<<<<<<<<<<<<< + * return CandidateSet(self) + * + */ + +static PyObject *__pyx_pf_5_cdec_16SegmentEvaluator_4candidate_set(struct __pyx_obj_5_cdec_SegmentEvaluator *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("candidate_set", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":85 - * candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) - * yield candidate - * del cs # <<<<<<<<<<<<<< + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":107 + * + * def candidate_set(self): + * return CandidateSet(self) # <<<<<<<<<<<<<< * * cdef class Scorer: */ - delete __pyx_cur_scope->__pyx_v_cs; - PyErr_SetNone(PyExc_StopIteration); + __Pyx_XDECREF(__pyx_r); + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)__pyx_v_self)); + PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_v_self)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_self)); + __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_CandidateSet)), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 107; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + goto __pyx_L0; + + __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; - __Pyx_XDECREF(__pyx_t_3); - __Pyx_AddTraceback("candidate_set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_AddTraceback("_cdec.SegmentEvaluator.candidate_set", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; __pyx_L0:; - __Pyx_XDECREF(__pyx_r); - __pyx_generator->resume_label = -1; + __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); - return NULL; + return __pyx_r; } /* Python wrapper */ @@ -6821,18 +7507,18 @@ static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject * else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); } - __pyx_v_name = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __pyx_v_name = PyBytes_AsString(values[0]); if (unlikely((!__pyx_v_name) && PyErr_Occurred())) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 112; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.Scorer.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -6843,7 +7529,7 @@ static int __pyx_pw_5_cdec_6Scorer_1__cinit__(PyObject *__pyx_v_self, PyObject * return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":90 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":112 * cdef string* name * * def __cinit__(self, char* name): # <<<<<<<<<<<<<< @@ -6856,12 +7542,12 @@ static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__p __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":91 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":113 * * def __cinit__(self, char* name): * self.name = new string(name) # <<<<<<<<<<<<<< * - * def __call__(self, refs): + * def __dealloc__(self): */ __pyx_v_self->name = new std::string(__pyx_v_name); @@ -6871,8 +7557,41 @@ static int __pyx_pf_5_cdec_6Scorer___cinit__(struct __pyx_obj_5_cdec_Scorer *__p } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_6Scorer_3__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_pw_5_cdec_6Scorer_3__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static void __pyx_pw_5_cdec_6Scorer_3__dealloc__(PyObject *__pyx_v_self); /*proto*/ +static void __pyx_pw_5_cdec_6Scorer_3__dealloc__(PyObject *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__ (wrapper)", 0); + __pyx_pf_5_cdec_6Scorer_2__dealloc__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self)); + __Pyx_RefNannyFinishContext(); +} + +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 + * self.name = new string(name) + * + * def __dealloc__(self): # <<<<<<<<<<<<<< + * del self.name + * + */ + +static void __pyx_pf_5_cdec_6Scorer_2__dealloc__(CYTHON_UNUSED struct __pyx_obj_5_cdec_Scorer *__pyx_v_self) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__dealloc__", 0); + + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":116 + * + * def __dealloc__(self): + * del self.name # <<<<<<<<<<<<<< + * + * def __call__(self, refs): + */ + delete __pyx_v_self->name; + + __Pyx_RefNannyFinishContext(); +} + +/* Python wrapper */ +static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_pw_5_cdec_6Scorer_5__call__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_refs = 0; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__refs,0}; PyObject *__pyx_r = 0; @@ -6896,7 +7615,7 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_3__call__(PyObject *__pyx_v_self, PyObj else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__call__") < 0)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 1) { goto __pyx_L5_argtuple_error; @@ -6907,26 +7626,26 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_3__call__(PyObject *__pyx_v_self, PyObj } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 93; __pyx_clineno = __LINE__; goto __pyx_L3_error;} + __Pyx_RaiseArgtupleInvalid("__call__", 1, 1, 1, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[4]; __pyx_lineno = 118; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("_cdec.Scorer.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_5_cdec_6Scorer_2__call__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self), __pyx_v_refs); + __pyx_r = __pyx_pf_5_cdec_6Scorer_4__call__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self), __pyx_v_refs); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":93 - * self.name = new string(name) +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":118 + * del self.name * * def __call__(self, refs): # <<<<<<<<<<<<<< * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) * if isinstance(refs, unicode) or isinstance(refs, str): */ -static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs) { +static PyObject *__pyx_pf_5_cdec_6Scorer_4__call__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self, PyObject *__pyx_v_refs) { EvaluationMetric *__pyx_v_metric; std::vector > *__pyx_v_refsv; std::vector *__pyx_v_refv; @@ -6948,7 +7667,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score __Pyx_RefNannySetupContext("__call__", 0); __Pyx_INCREF(__pyx_v_refs); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":94 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":119 * * def __call__(self, refs): * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) # <<<<<<<<<<<<<< @@ -6957,7 +7676,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_metric = EvaluationMetric::Instance((__pyx_v_self->name[0])); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":95 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":120 * def __call__(self, refs): * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) * if isinstance(refs, unicode) or isinstance(refs, str): # <<<<<<<<<<<<<< @@ -6979,14 +7698,14 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score } if (__pyx_t_4) { - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":96 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":121 * cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) * if isinstance(refs, unicode) or isinstance(refs, str): * refs = [refs] # <<<<<<<<<<<<<< * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() * cdef vector[WordID]* refv */ - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 121; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_refs); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_refs); @@ -6998,7 +7717,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score } __pyx_L3:; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":97 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":122 * if isinstance(refs, unicode) or isinstance(refs, str): * refs = [refs] * cdef vector[vector[WordID]]* refsv = new vector[vector[WordID]]() # <<<<<<<<<<<<<< @@ -7007,7 +7726,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_refsv = new std::vector >(); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":100 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":125 * cdef vector[WordID]* refv * cdef bytes ref_str * for ref in refs: # <<<<<<<<<<<<<< @@ -7018,7 +7737,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score __pyx_t_1 = __pyx_v_refs; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0; __pyx_t_6 = NULL; } else { - __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_refs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_5 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_refs); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = Py_TYPE(__pyx_t_1)->tp_iternext; } @@ -7034,7 +7753,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score if (unlikely(!__pyx_t_7)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); - else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 100; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + else {__pyx_filename = __pyx_f[4]; __pyx_lineno = 125; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } @@ -7044,7 +7763,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score __pyx_v_ref = __pyx_t_7; __pyx_t_7 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":101 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":126 * cdef bytes ref_str * for ref in refs: * refv = new vector[WordID]() # <<<<<<<<<<<<<< @@ -7053,22 +7772,22 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_refv = new std::vector(); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":102 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":127 * for ref in refs: * refv = new vector[WordID]() * ConvertSentence(string(as_str(ref.strip())), refv) # <<<<<<<<<<<<<< * refsv.push_back(refv[0]) * del refv */ - __pyx_t_7 = PyObject_GetAttr(__pyx_v_ref, __pyx_n_s__strip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_7 = PyObject_GetAttr(__pyx_v_ref, __pyx_n_s__strip); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); - __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 102; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 127; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; TD::ConvertSentence(std::string(__pyx_f_5_cdec_as_str(__pyx_t_8, NULL)), __pyx_v_refv); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":103 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":128 * refv = new vector[WordID]() * ConvertSentence(string(as_str(ref.strip())), refv) * refsv.push_back(refv[0]) # <<<<<<<<<<<<<< @@ -7077,7 +7796,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_refsv->push_back((__pyx_v_refv[0])); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":104 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":129 * ConvertSentence(string(as_str(ref.strip())), refv) * refsv.push_back(refv[0]) * del refv # <<<<<<<<<<<<<< @@ -7088,19 +7807,19 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":106 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":131 * del refv * cdef unsigned i * cdef SegmentEvaluator evaluator = SegmentEvaluator() # <<<<<<<<<<<<<< * evaluator.metric = metric * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SegmentEvaluator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 106; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_SegmentEvaluator)), ((PyObject *)__pyx_empty_tuple), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 131; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_v_evaluator = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":107 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":132 * cdef unsigned i * cdef SegmentEvaluator evaluator = SegmentEvaluator() * evaluator.metric = metric # <<<<<<<<<<<<<< @@ -7109,7 +7828,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_evaluator->metric = __pyx_v_metric; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":108 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":133 * cdef SegmentEvaluator evaluator = SegmentEvaluator() * evaluator.metric = metric * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) # <<<<<<<<<<<<<< @@ -7118,7 +7837,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score */ __pyx_v_evaluator->scorer = new boost::shared_ptr(__pyx_v_metric->CreateSegmentEvaluator((__pyx_v_refsv[0]))); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":109 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":134 * evaluator.metric = metric * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) * del refsv # in theory should not delete but store in SegmentEvaluator # <<<<<<<<<<<<<< @@ -7127,7 +7846,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score */ delete __pyx_v_refsv; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":110 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":135 * evaluator.scorer = new shared_ptr[mteval.SegmentEvaluator](metric.CreateSegmentEvaluator(refsv[0])) * del refsv # in theory should not delete but store in SegmentEvaluator * return evaluator # <<<<<<<<<<<<<< @@ -7157,17 +7876,17 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_2__call__(struct __pyx_obj_5_cdec_Score } /* Python wrapper */ -static PyObject *__pyx_pw_5_cdec_6Scorer_5__str__(PyObject *__pyx_v_self); /*proto*/ -static PyObject *__pyx_pw_5_cdec_6Scorer_5__str__(PyObject *__pyx_v_self) { +static PyObject *__pyx_pw_5_cdec_6Scorer_7__str__(PyObject *__pyx_v_self); /*proto*/ +static PyObject *__pyx_pw_5_cdec_6Scorer_7__str__(PyObject *__pyx_v_self) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); - __pyx_r = __pyx_pf_5_cdec_6Scorer_4__str__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self)); + __pyx_r = __pyx_pf_5_cdec_6Scorer_6__str__(((struct __pyx_obj_5_cdec_Scorer *)__pyx_v_self)); __Pyx_RefNannyFinishContext(); return __pyx_r; } -/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":112 +/* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":137 * return evaluator * * def __str__(self): # <<<<<<<<<<<<<< @@ -7175,7 +7894,7 @@ static PyObject *__pyx_pw_5_cdec_6Scorer_5__str__(PyObject *__pyx_v_self) { * */ -static PyObject *__pyx_pf_5_cdec_6Scorer_4__str__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self) { +static PyObject *__pyx_pf_5_cdec_6Scorer_6__str__(struct __pyx_obj_5_cdec_Scorer *__pyx_v_self) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations PyObject *__pyx_t_1 = NULL; @@ -7184,7 +7903,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__str__(struct __pyx_obj_5_cdec_Scorer int __pyx_clineno = 0; __Pyx_RefNannySetupContext("__str__", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":113 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":138 * * def __str__(self): * return self.name.c_str() # <<<<<<<<<<<<<< @@ -7192,7 +7911,7 @@ static PyObject *__pyx_pf_5_cdec_6Scorer_4__str__(struct __pyx_obj_5_cdec_Scorer * BLEU = Scorer('IBM_BLEU') */ __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = PyBytes_FromString(__pyx_v_self->name->c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyBytes_FromString(__pyx_v_self->name->c_str()); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 138; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; @@ -8129,7 +8848,7 @@ static PyObject *__pyx_sq_item_5_cdec_DenseVector(PyObject *o, Py_ssize_t i) { static int __pyx_mp_ass_subscript_5_cdec_DenseVector(PyObject *o, PyObject *i, PyObject *v) { if (v) { - return __pyx_pw_5_cdec_11DenseVector_3__setitem__(o, i, v); + return __pyx_pw_5_cdec_11DenseVector_5__setitem__(o, i, v); } else { PyErr_Format(PyExc_NotImplementedError, @@ -8139,8 +8858,8 @@ static int __pyx_mp_ass_subscript_5_cdec_DenseVector(PyObject *o, PyObject *i, P } static PyMethodDef __pyx_methods_5_cdec_DenseVector[] = { - {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_8dot, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("tosparse"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_10tosparse, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_10dot, METH_O, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("tosparse"), (PyCFunction)__pyx_pw_5_cdec_11DenseVector_12tosparse, METH_NOARGS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; @@ -8203,7 +8922,7 @@ static PyNumberMethods __pyx_tp_as_number_DenseVector = { }; static PySequenceMethods __pyx_tp_as_sequence_DenseVector = { - 0, /*sq_length*/ + __pyx_pw_5_cdec_11DenseVector_1__len__, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ __pyx_sq_item_5_cdec_DenseVector, /*sq_item*/ @@ -8216,8 +8935,8 @@ static PySequenceMethods __pyx_tp_as_sequence_DenseVector = { }; static PyMappingMethods __pyx_tp_as_mapping_DenseVector = { - 0, /*mp_length*/ - __pyx_pw_5_cdec_11DenseVector_1__getitem__, /*mp_subscript*/ + __pyx_pw_5_cdec_11DenseVector_1__len__, /*mp_length*/ + __pyx_pw_5_cdec_11DenseVector_3__getitem__, /*mp_subscript*/ __pyx_mp_ass_subscript_5_cdec_DenseVector, /*mp_ass_subscript*/ }; @@ -8272,7 +8991,7 @@ static PyTypeObject __pyx_type_5_cdec_DenseVector = { 0, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_11DenseVector_5__iter__, /*tp_iter*/ + __pyx_pw_5_cdec_11DenseVector_7__iter__, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_5_cdec_DenseVector, /*tp_methods*/ 0, /*tp_members*/ @@ -8305,6 +9024,15 @@ static PyObject *__pyx_tp_new_5_cdec_SparseVector(PyTypeObject *t, PyObject *a, } static void __pyx_tp_dealloc_5_cdec_SparseVector(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_12SparseVector_1__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } (*Py_TYPE(o)->tp_free)(o); } static PyObject *__pyx_sq_item_5_cdec_SparseVector(PyObject *o, Py_ssize_t i) { @@ -8317,7 +9045,7 @@ static PyObject *__pyx_sq_item_5_cdec_SparseVector(PyObject *o, Py_ssize_t i) { static int __pyx_mp_ass_subscript_5_cdec_SparseVector(PyObject *o, PyObject *i, PyObject *v) { if (v) { - return __pyx_pw_5_cdec_12SparseVector_3__setitem__(o, i, v); + return __pyx_pw_5_cdec_12SparseVector_7__setitem__(o, i, v); } else { PyErr_Format(PyExc_NotImplementedError, @@ -8327,17 +9055,17 @@ static int __pyx_mp_ass_subscript_5_cdec_SparseVector(PyObject *o, PyObject *i, } static PyMethodDef __pyx_methods_5_cdec_SparseVector[] = { - {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_8dot, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("todense"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_10todense, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("copy"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_3copy, METH_NOARGS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("dot"), (PyCFunction)__pyx_pw_5_cdec_12SparseVector_12dot, METH_O, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; static PyNumberMethods __pyx_tp_as_number_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_26__add__, /*nb_add*/ - __pyx_pw_5_cdec_12SparseVector_28__sub__, /*nb_subtract*/ - __pyx_pw_5_cdec_12SparseVector_30__mul__, /*nb_multiply*/ + __pyx_pw_5_cdec_12SparseVector_28__add__, /*nb_add*/ + __pyx_pw_5_cdec_12SparseVector_30__sub__, /*nb_subtract*/ + __pyx_pw_5_cdec_12SparseVector_32__mul__, /*nb_multiply*/ #if PY_MAJOR_VERSION < 3 - __pyx_pw_5_cdec_12SparseVector_32__div__, /*nb_divide*/ + __pyx_pw_5_cdec_12SparseVector_34__div__, /*nb_divide*/ #endif 0, /*nb_remainder*/ 0, /*nb_divmod*/ @@ -8368,11 +9096,11 @@ static PyNumberMethods __pyx_tp_as_number_SparseVector = { #if PY_MAJOR_VERSION < 3 0, /*nb_hex*/ #endif - __pyx_pw_5_cdec_12SparseVector_18__iadd__, /*nb_inplace_add*/ - __pyx_pw_5_cdec_12SparseVector_20__isub__, /*nb_inplace_subtract*/ - __pyx_pw_5_cdec_12SparseVector_22__imul__, /*nb_inplace_multiply*/ + __pyx_pw_5_cdec_12SparseVector_20__iadd__, /*nb_inplace_add*/ + __pyx_pw_5_cdec_12SparseVector_22__isub__, /*nb_inplace_subtract*/ + __pyx_pw_5_cdec_12SparseVector_24__imul__, /*nb_inplace_multiply*/ #if PY_MAJOR_VERSION < 3 - __pyx_pw_5_cdec_12SparseVector_24__idiv__, /*nb_inplace_divide*/ + __pyx_pw_5_cdec_12SparseVector_26__idiv__, /*nb_inplace_divide*/ #endif 0, /*nb_inplace_remainder*/ 0, /*nb_inplace_power*/ @@ -8391,21 +9119,21 @@ static PyNumberMethods __pyx_tp_as_number_SparseVector = { }; static PySequenceMethods __pyx_tp_as_sequence_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_14__len__, /*sq_length*/ + __pyx_pw_5_cdec_12SparseVector_16__len__, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ __pyx_sq_item_5_cdec_SparseVector, /*sq_item*/ 0, /*sq_slice*/ 0, /*sq_ass_item*/ 0, /*sq_ass_slice*/ - __pyx_pw_5_cdec_12SparseVector_16__contains__, /*sq_contains*/ + __pyx_pw_5_cdec_12SparseVector_18__contains__, /*sq_contains*/ 0, /*sq_inplace_concat*/ 0, /*sq_inplace_repeat*/ }; static PyMappingMethods __pyx_tp_as_mapping_SparseVector = { - __pyx_pw_5_cdec_12SparseVector_14__len__, /*mp_length*/ - __pyx_pw_5_cdec_12SparseVector_1__getitem__, /*mp_subscript*/ + __pyx_pw_5_cdec_12SparseVector_16__len__, /*mp_length*/ + __pyx_pw_5_cdec_12SparseVector_5__getitem__, /*mp_subscript*/ __pyx_mp_ass_subscript_5_cdec_SparseVector, /*mp_ass_subscript*/ }; @@ -8458,9 +9186,9 @@ static PyTypeObject __pyx_type_5_cdec_SparseVector = { 0, /*tp_doc*/ 0, /*tp_traverse*/ 0, /*tp_clear*/ - __pyx_pw_5_cdec_12SparseVector_12__richcmp__, /*tp_richcompare*/ + __pyx_pw_5_cdec_12SparseVector_14__richcmp__, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ - __pyx_pw_5_cdec_12SparseVector_5__iter__, /*tp_iter*/ + __pyx_pw_5_cdec_12SparseVector_9__iter__, /*tp_iter*/ 0, /*tp_iternext*/ __pyx_methods_5_cdec_SparseVector, /*tp_methods*/ 0, /*tp_members*/ @@ -9258,6 +9986,194 @@ static PyTypeObject __pyx_type_5_cdec_SufficientStats = { #endif }; +static PyObject *__pyx_tp_new_5_cdec_CandidateSet(PyTypeObject *t, PyObject *a, PyObject *k) { + PyObject *o = (*t->tp_alloc)(t, 0); + if (!o) return 0; + if (__pyx_pw_5_cdec_12CandidateSet_1__cinit__(o, a, k) < 0) { + Py_DECREF(o); o = 0; + } + return o; +} + +static void __pyx_tp_dealloc_5_cdec_CandidateSet(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_12CandidateSet_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } + (*Py_TYPE(o)->tp_free)(o); +} +static PyObject *__pyx_sq_item_5_cdec_CandidateSet(PyObject *o, Py_ssize_t i) { + PyObject *r; + PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0; + r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x); + Py_DECREF(x); + return r; +} + +static PyMethodDef __pyx_methods_5_cdec_CandidateSet[] = { + {__Pyx_NAMESTR("add_kbest"), (PyCFunction)__pyx_pw_5_cdec_12CandidateSet_12add_kbest, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {0, 0, 0, 0} +}; + +static PyNumberMethods __pyx_tp_as_number_CandidateSet = { + 0, /*nb_add*/ + 0, /*nb_subtract*/ + 0, /*nb_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_divide*/ + #endif + 0, /*nb_remainder*/ + 0, /*nb_divmod*/ + 0, /*nb_power*/ + 0, /*nb_negative*/ + 0, /*nb_positive*/ + 0, /*nb_absolute*/ + 0, /*nb_nonzero*/ + 0, /*nb_invert*/ + 0, /*nb_lshift*/ + 0, /*nb_rshift*/ + 0, /*nb_and*/ + 0, /*nb_xor*/ + 0, /*nb_or*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_coerce*/ + #endif + 0, /*nb_int*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_long*/ + #else + 0, /*reserved*/ + #endif + 0, /*nb_float*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_oct*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*nb_hex*/ + #endif + 0, /*nb_inplace_add*/ + 0, /*nb_inplace_subtract*/ + 0, /*nb_inplace_multiply*/ + #if PY_MAJOR_VERSION < 3 + 0, /*nb_inplace_divide*/ + #endif + 0, /*nb_inplace_remainder*/ + 0, /*nb_inplace_power*/ + 0, /*nb_inplace_lshift*/ + 0, /*nb_inplace_rshift*/ + 0, /*nb_inplace_and*/ + 0, /*nb_inplace_xor*/ + 0, /*nb_inplace_or*/ + 0, /*nb_floor_divide*/ + 0, /*nb_true_divide*/ + 0, /*nb_inplace_floor_divide*/ + 0, /*nb_inplace_true_divide*/ + #if PY_VERSION_HEX >= 0x02050000 + 0, /*nb_index*/ + #endif +}; + +static PySequenceMethods __pyx_tp_as_sequence_CandidateSet = { + __pyx_pw_5_cdec_12CandidateSet_5__len__, /*sq_length*/ + 0, /*sq_concat*/ + 0, /*sq_repeat*/ + __pyx_sq_item_5_cdec_CandidateSet, /*sq_item*/ + 0, /*sq_slice*/ + 0, /*sq_ass_item*/ + 0, /*sq_ass_slice*/ + 0, /*sq_contains*/ + 0, /*sq_inplace_concat*/ + 0, /*sq_inplace_repeat*/ +}; + +static PyMappingMethods __pyx_tp_as_mapping_CandidateSet = { + __pyx_pw_5_cdec_12CandidateSet_5__len__, /*mp_length*/ + __pyx_pw_5_cdec_12CandidateSet_7__getitem__, /*mp_subscript*/ + 0, /*mp_ass_subscript*/ +}; + +static PyBufferProcs __pyx_tp_as_buffer_CandidateSet = { + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getreadbuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getwritebuffer*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getsegcount*/ + #endif + #if PY_MAJOR_VERSION < 3 + 0, /*bf_getcharbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_getbuffer*/ + #endif + #if PY_VERSION_HEX >= 0x02060000 + 0, /*bf_releasebuffer*/ + #endif +}; + +static PyTypeObject __pyx_type_5_cdec_CandidateSet = { + PyVarObject_HEAD_INIT(0, 0) + __Pyx_NAMESTR("_cdec.CandidateSet"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec_CandidateSet), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_5_cdec_CandidateSet, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #else + 0, /*reserved*/ + #endif + 0, /*tp_repr*/ + &__pyx_tp_as_number_CandidateSet, /*tp_as_number*/ + &__pyx_tp_as_sequence_CandidateSet, /*tp_as_sequence*/ + &__pyx_tp_as_mapping_CandidateSet, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + &__pyx_tp_as_buffer_CandidateSet, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE, /*tp_flags*/ + 0, /*tp_doc*/ + 0, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + __pyx_pw_5_cdec_12CandidateSet_9__iter__, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_5_cdec_CandidateSet, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + 0, /*tp_dictoffset*/ + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_5_cdec_CandidateSet, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + #if PY_VERSION_HEX >= 0x02060000 + 0, /*tp_version_tag*/ + #endif +}; + static PyObject *__pyx_tp_new_5_cdec_SegmentEvaluator(PyTypeObject *t, PyObject *a, PyObject *k) { PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; @@ -9279,7 +10195,7 @@ static void __pyx_tp_dealloc_5_cdec_SegmentEvaluator(PyObject *o) { static PyMethodDef __pyx_methods_5_cdec_SegmentEvaluator[] = { {__Pyx_NAMESTR("evaluate"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_3evaluate, METH_O, __Pyx_DOCSTR(0)}, - {__Pyx_NAMESTR("candidate_set"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(0)}, + {__Pyx_NAMESTR("candidate_set"), (PyCFunction)__pyx_pw_5_cdec_16SegmentEvaluator_5candidate_set, METH_NOARGS, __Pyx_DOCSTR(0)}, {0, 0, 0, 0} }; @@ -9447,6 +10363,15 @@ static PyObject *__pyx_tp_new_5_cdec_Scorer(PyTypeObject *t, PyObject *a, PyObje } static void __pyx_tp_dealloc_5_cdec_Scorer(PyObject *o) { + { + PyObject *etype, *eval, *etb; + PyErr_Fetch(&etype, &eval, &etb); + ++Py_REFCNT(o); + __pyx_pw_5_cdec_6Scorer_3__dealloc__(o); + if (PyErr_Occurred()) PyErr_WriteUnraisable(o); + --Py_REFCNT(o); + PyErr_Restore(etype, eval, etb); + } (*Py_TYPE(o)->tp_free)(o); } @@ -9571,8 +10496,8 @@ static PyTypeObject __pyx_type_5_cdec_Scorer = { &__pyx_tp_as_sequence_Scorer, /*tp_as_sequence*/ &__pyx_tp_as_mapping_Scorer, /*tp_as_mapping*/ 0, /*tp_hash*/ - __pyx_pw_5_cdec_6Scorer_3__call__, /*tp_call*/ - __pyx_pw_5_cdec_6Scorer_5__str__, /*tp_str*/ + __pyx_pw_5_cdec_6Scorer_5__call__, /*tp_call*/ + __pyx_pw_5_cdec_6Scorer_7__str__, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ &__pyx_tp_as_buffer_Scorer, /*tp_as_buffer*/ @@ -10027,14 +10952,12 @@ static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_1___iter__(PyTypeObject PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o); - p->__pyx_v_fname = 0; p->__pyx_v_self = 0; return o; } static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; - Py_XDECREF(((PyObject *)p->__pyx_v_fname)); Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } @@ -10042,9 +10965,6 @@ static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__(PyObject *o, visitproc v, void *a) { int e; struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; - if (p->__pyx_v_fname) { - e = (*v)(p->__pyx_v_fname, a); if (e) return e; - } if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } @@ -10054,9 +10974,6 @@ static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_1___iter__(PyObject *o, v static int __pyx_tp_clear_5_cdec___pyx_scope_struct_1___iter__(PyObject *o) { struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_1___iter__ *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_fname); - p->__pyx_v_fname = ((PyObject*)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_self); p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SparseVector *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); @@ -11439,60 +12356,44 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_7___iter__ = { #endif }; -static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_8_candidate_set(PyTypeObject *t, PyObject *a, PyObject *k) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *p; +static PyObject *__pyx_tp_new_5_cdec___pyx_scope_struct_8___iter__(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *p; PyObject *o = (*t->tp_alloc)(t, 0); if (!o) return 0; - p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)o); - p->__pyx_v_candidate = 0; - p->__pyx_v_hypergraph = 0; + p = ((struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *)o); p->__pyx_v_self = 0; return o; } -static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8_candidate_set(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)o; - Py_XDECREF(((PyObject *)p->__pyx_v_candidate)); - Py_XDECREF(((PyObject *)p->__pyx_v_hypergraph)); +static void __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *)o; Py_XDECREF(((PyObject *)p->__pyx_v_self)); (*Py_TYPE(o)->tp_free)(o); } -static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_8_candidate_set(PyObject *o, visitproc v, void *a) { +static int __pyx_tp_traverse_5_cdec___pyx_scope_struct_8___iter__(PyObject *o, visitproc v, void *a) { int e; - struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)o; - if (p->__pyx_v_candidate) { - e = (*v)(((PyObject*)p->__pyx_v_candidate), a); if (e) return e; - } - if (p->__pyx_v_hypergraph) { - e = (*v)(((PyObject*)p->__pyx_v_hypergraph), a); if (e) return e; - } + struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *)o; if (p->__pyx_v_self) { e = (*v)(((PyObject*)p->__pyx_v_self), a); if (e) return e; } return 0; } -static int __pyx_tp_clear_5_cdec___pyx_scope_struct_8_candidate_set(PyObject *o) { - struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set *)o; +static int __pyx_tp_clear_5_cdec___pyx_scope_struct_8___iter__(PyObject *o) { + struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *p = (struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__ *)o; PyObject* tmp; - tmp = ((PyObject*)p->__pyx_v_candidate); - p->__pyx_v_candidate = ((struct __pyx_obj_5_cdec_Candidate *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); - tmp = ((PyObject*)p->__pyx_v_hypergraph); - p->__pyx_v_hypergraph = ((struct __pyx_obj_5_cdec_Hypergraph *)Py_None); Py_INCREF(Py_None); - Py_XDECREF(tmp); tmp = ((PyObject*)p->__pyx_v_self); - p->__pyx_v_self = ((struct __pyx_obj_5_cdec_SegmentEvaluator *)Py_None); Py_INCREF(Py_None); + p->__pyx_v_self = ((struct __pyx_obj_5_cdec_CandidateSet *)Py_None); Py_INCREF(Py_None); Py_XDECREF(tmp); return 0; } -static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_8_candidate_set[] = { +static PyMethodDef __pyx_methods_5_cdec___pyx_scope_struct_8___iter__[] = { {0, 0, 0, 0} }; -static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_8_candidate_set = { +static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_8___iter__ = { 0, /*nb_add*/ 0, /*nb_subtract*/ 0, /*nb_multiply*/ @@ -11550,7 +12451,7 @@ static PyNumberMethods __pyx_tp_as_number___pyx_scope_struct_8_candidate_set = { #endif }; -static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_8_candidate_set = { +static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_8___iter__ = { 0, /*sq_length*/ 0, /*sq_concat*/ 0, /*sq_repeat*/ @@ -11563,13 +12464,13 @@ static PySequenceMethods __pyx_tp_as_sequence___pyx_scope_struct_8_candidate_set 0, /*sq_inplace_repeat*/ }; -static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_8_candidate_set = { +static PyMappingMethods __pyx_tp_as_mapping___pyx_scope_struct_8___iter__ = { 0, /*mp_length*/ 0, /*mp_subscript*/ 0, /*mp_ass_subscript*/ }; -static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_8_candidate_set = { +static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_8___iter__ = { #if PY_MAJOR_VERSION < 3 0, /*bf_getreadbuffer*/ #endif @@ -11590,12 +12491,12 @@ static PyBufferProcs __pyx_tp_as_buffer___pyx_scope_struct_8_candidate_set = { #endif }; -static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8_candidate_set = { +static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8___iter__ = { PyVarObject_HEAD_INIT(0, 0) - __Pyx_NAMESTR("_cdec.__pyx_scope_struct_8_candidate_set"), /*tp_name*/ - sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_8_candidate_set), /*tp_basicsize*/ + __Pyx_NAMESTR("_cdec.__pyx_scope_struct_8___iter__"), /*tp_name*/ + sizeof(struct __pyx_obj_5_cdec___pyx_scope_struct_8___iter__), /*tp_basicsize*/ 0, /*tp_itemsize*/ - __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_dealloc*/ + __pyx_tp_dealloc_5_cdec___pyx_scope_struct_8___iter__, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ @@ -11605,24 +12506,24 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8_candidate_set = { 0, /*reserved*/ #endif 0, /*tp_repr*/ - &__pyx_tp_as_number___pyx_scope_struct_8_candidate_set, /*tp_as_number*/ - &__pyx_tp_as_sequence___pyx_scope_struct_8_candidate_set, /*tp_as_sequence*/ - &__pyx_tp_as_mapping___pyx_scope_struct_8_candidate_set, /*tp_as_mapping*/ + &__pyx_tp_as_number___pyx_scope_struct_8___iter__, /*tp_as_number*/ + &__pyx_tp_as_sequence___pyx_scope_struct_8___iter__, /*tp_as_sequence*/ + &__pyx_tp_as_mapping___pyx_scope_struct_8___iter__, /*tp_as_mapping*/ 0, /*tp_hash*/ 0, /*tp_call*/ 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - &__pyx_tp_as_buffer___pyx_scope_struct_8_candidate_set, /*tp_as_buffer*/ + &__pyx_tp_as_buffer___pyx_scope_struct_8___iter__, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ 0, /*tp_doc*/ - __pyx_tp_traverse_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_traverse*/ - __pyx_tp_clear_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_clear*/ + __pyx_tp_traverse_5_cdec___pyx_scope_struct_8___iter__, /*tp_traverse*/ + __pyx_tp_clear_5_cdec___pyx_scope_struct_8___iter__, /*tp_clear*/ 0, /*tp_richcompare*/ 0, /*tp_weaklistoffset*/ 0, /*tp_iter*/ 0, /*tp_iternext*/ - __pyx_methods_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_methods*/ + __pyx_methods_5_cdec___pyx_scope_struct_8___iter__, /*tp_methods*/ 0, /*tp_members*/ 0, /*tp_getset*/ 0, /*tp_base*/ @@ -11632,7 +12533,7 @@ static PyTypeObject __pyx_type_5_cdec___pyx_scope_struct_8_candidate_set = { 0, /*tp_dictoffset*/ 0, /*tp_init*/ 0, /*tp_alloc*/ - __pyx_tp_new_5_cdec___pyx_scope_struct_8_candidate_set, /*tp_new*/ + __pyx_tp_new_5_cdec___pyx_scope_struct_8___iter__, /*tp_new*/ 0, /*tp_free*/ 0, /*tp_is_gc*/ 0, /*tp_bases*/ @@ -11696,6 +12597,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s__encoding, __pyx_k__encoding, sizeof(__pyx_k__encoding), 0, 0, 1, 1}, {&__pyx_n_s__enumerate, __pyx_k__enumerate, sizeof(__pyx_k__enumerate), 0, 0, 1, 1}, {&__pyx_n_s__eval, __pyx_k__eval, sizeof(__pyx_k__eval), 0, 0, 1, 1}, + {&__pyx_n_s__evaluator, __pyx_k__evaluator, sizeof(__pyx_k__evaluator), 0, 0, 1, 1}, {&__pyx_n_s__grammar, __pyx_k__grammar, sizeof(__pyx_k__grammar), 0, 0, 1, 1}, {&__pyx_n_s__hypergraph, __pyx_k__hypergraph, sizeof(__pyx_k__hypergraph), 0, 0, 1, 1}, {&__pyx_n_s__inp, __pyx_k__inp, sizeof(__pyx_k__inp), 0, 0, 1, 1}, @@ -11714,11 +12616,11 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { }; static int __Pyx_InitCachedBuiltins(void) { __pyx_builtin_Exception = __Pyx_GetName(__pyx_b, __pyx_n_s__Exception); if (!__pyx_builtin_Exception) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 10; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 20; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_NotImplemented = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplemented); if (!__pyx_builtin_NotImplemented) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_builtin_eval = __Pyx_GetName(__pyx_b, __pyx_n_s__eval); if (!__pyx_builtin_eval) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_KeyError = __Pyx_GetName(__pyx_b, __pyx_n_s__KeyError); if (!__pyx_builtin_KeyError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 13; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_range = __Pyx_GetName(__pyx_b, __pyx_n_s__range); if (!__pyx_builtin_range) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 24; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_TypeError = __Pyx_GetName(__pyx_b, __pyx_n_s__TypeError); if (!__pyx_builtin_TypeError) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_NotImplemented = __Pyx_GetName(__pyx_b, __pyx_n_s__NotImplemented); if (!__pyx_builtin_NotImplemented) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_builtin_eval = __Pyx_GetName(__pyx_b, __pyx_n_s__eval); if (!__pyx_builtin_eval) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 105; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_enumerate = __Pyx_GetName(__pyx_b, __pyx_n_s__enumerate); if (!__pyx_builtin_enumerate) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_IndexError = __Pyx_GetName(__pyx_b, __pyx_n_s__IndexError); if (!__pyx_builtin_IndexError) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 21; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_builtin_open = __Pyx_GetName(__pyx_b, __pyx_n_s__open); if (!__pyx_builtin_open) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 31; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -11731,14 +12633,14 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":69 + /* "/Users/vchahun/Sandbox/cdec/python/src/vectors.pxi":76 * elif op == 3: # != * return not (x == y) * raise NotImplemented('comparison not implemented for SparseVector') # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_k_tuple_3 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_3 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_3)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 76; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_3); __Pyx_INCREF(((PyObject *)__pyx_kp_s_2)); PyTuple_SET_ITEM(__pyx_k_tuple_3, 0, ((PyObject *)__pyx_kp_s_2)); @@ -11787,42 +12689,42 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_6)); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":41 - * if not derivation: break - * sentence = GetString(derivation._yield).c_str() - * yield sentence.decode('utf8') # <<<<<<<<<<<<<< - * del derivations - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":42 + * if not derivation: break + * sentence = GetString(derivation._yield).c_str() + * yield sentence.decode('utf8') # <<<<<<<<<<<<<< + * finally: + * del derivations */ - __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 41; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_7 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_7)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_7); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); PyTuple_SET_ITEM(__pyx_k_tuple_7, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_7)); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":53 - * if not derivation: break - * tree = GetString(derivation._yield).c_str() - * yield tree.decode('utf8') # <<<<<<<<<<<<<< - * del derivations - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":56 + * if not derivation: break + * tree = GetString(derivation._yield).c_str() + * yield tree.decode('utf8') # <<<<<<<<<<<<<< + * finally: + * del derivations */ - __pyx_k_tuple_8 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 53; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_8 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_8)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_8); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); PyTuple_SET_ITEM(__pyx_k_tuple_8, 0, ((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_8)); - /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":78 - * for k in range(hypos.size()): - * sentence = GetString(hypos[0][k].words).c_str() - * yield sentence.decode('utf8') # <<<<<<<<<<<<<< - * del hypos - * + /* "/Users/vchahun/Sandbox/cdec/python/src/hypergraph.pxi":85 + * for k in range(hypos.size()): + * sentence = GetString(hypos[0][k].words).c_str() + * yield sentence.decode('utf8') # <<<<<<<<<<<<<< + * finally: + * del hypos */ - __pyx_k_tuple_9 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_9 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_9)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_9); __Pyx_INCREF(((PyObject *)__pyx_n_s__utf8)); PyTuple_SET_ITEM(__pyx_k_tuple_9, 0, ((PyObject *)__pyx_n_s__utf8)); @@ -11947,25 +12849,25 @@ static int __Pyx_InitCachedConstants(void) { __Pyx_GIVEREF(((PyObject *)__pyx_n_s__utf8)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22)); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":140 * return self.name.c_str() * * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< * TER = Scorer('TER') */ - __pyx_k_tuple_24 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_24 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_24)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_24); __Pyx_INCREF(((PyObject *)__pyx_n_s__IBM_BLEU)); PyTuple_SET_ITEM(__pyx_k_tuple_24, 0, ((PyObject *)__pyx_n_s__IBM_BLEU)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__IBM_BLEU)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_24)); - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":116 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":141 * * BLEU = Scorer('IBM_BLEU') * TER = Scorer('TER') # <<<<<<<<<<<<<< */ - __pyx_k_tuple_25 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_k_tuple_25 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_25)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_k_tuple_25); __Pyx_INCREF(((PyObject *)__pyx_n_s__TER)); PyTuple_SET_ITEM(__pyx_k_tuple_25, 0, ((PyObject *)__pyx_n_s__TER)); @@ -12057,8 +12959,8 @@ PyMODINIT_FUNC PyInit__cdec(void) if (PyType_Ready(&__pyx_type_5_cdec_DenseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "DenseVector", (PyObject *)&__pyx_type_5_cdec_DenseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 3; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_DenseVector = &__pyx_type_5_cdec_DenseVector; - if (PyType_Ready(&__pyx_type_5_cdec_SparseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "SparseVector", (PyObject *)&__pyx_type_5_cdec_SparseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_SparseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "SparseVector", (PyObject *)&__pyx_type_5_cdec_SparseVector) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 36; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_SparseVector = &__pyx_type_5_cdec_SparseVector; if (PyType_Ready(&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Hypergraph", (PyObject *)&__pyx_type_5_cdec_Hypergraph) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -12072,57 +12974,60 @@ PyMODINIT_FUNC PyInit__cdec(void) if (PyType_Ready(&__pyx_type_5_cdec_SufficientStats) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "SufficientStats", (PyObject *)&__pyx_type_5_cdec_SufficientStats) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 27; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_SufficientStats = &__pyx_type_5_cdec_SufficientStats; - if (PyType_Ready(&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "SegmentEvaluator", (PyObject *)&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_CandidateSet) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "CandidateSet", (PyObject *)&__pyx_type_5_cdec_CandidateSet) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec_CandidateSet = &__pyx_type_5_cdec_CandidateSet; + if (PyType_Ready(&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "SegmentEvaluator", (PyObject *)&__pyx_type_5_cdec_SegmentEvaluator) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_SegmentEvaluator = &__pyx_type_5_cdec_SegmentEvaluator; - if (PyType_Ready(&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - if (__Pyx_SetAttrString(__pyx_m, "Scorer", (PyObject *)&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (__Pyx_SetAttrString(__pyx_m, "Scorer", (PyObject *)&__pyx_type_5_cdec_Scorer) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Scorer = &__pyx_type_5_cdec_Scorer; if (PyType_Ready(&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} if (__Pyx_SetAttrString(__pyx_m, "Decoder", (PyObject *)&__pyx_type_5_cdec_Decoder) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec_Decoder = &__pyx_type_5_cdec_Decoder; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct____iter__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 18; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct____iter__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 22; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct____iter__ = &__pyx_type_5_cdec___pyx_scope_struct____iter__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_1___iter__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 43; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_1___iter__) < 0) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 55; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_1___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_1___iter__; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_2_kbest) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 32; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_2_kbest = &__pyx_type_5_cdec___pyx_scope_struct_2_kbest; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 44; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 46; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_3_kbest_tree = &__pyx_type_5_cdec___pyx_scope_struct_3_kbest_tree; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_4_kbest_features) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 56; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_4_kbest_features) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_4_kbest_features = &__pyx_type_5_cdec___pyx_scope_struct_4_kbest_features; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_5_sample) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_5_sample) < 0) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_5_sample = &__pyx_type_5_cdec___pyx_scope_struct_5_sample; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_6___iter__) < 0) {__pyx_filename = __pyx_f[3]; __pyx_lineno = 50; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_6___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_6___iter__; if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_7___iter__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 45; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_ptype_5_cdec___pyx_scope_struct_7___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_7___iter__; - if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_8_candidate_set) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 75; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __pyx_ptype_5_cdec___pyx_scope_struct_8_candidate_set = &__pyx_type_5_cdec___pyx_scope_struct_8_candidate_set; + if (PyType_Ready(&__pyx_type_5_cdec___pyx_scope_struct_8___iter__) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_ptype_5_cdec___pyx_scope_struct_8___iter__ = &__pyx_type_5_cdec___pyx_scope_struct_8___iter__; /*--- Type import code ---*/ /*--- Variable import code ---*/ /*--- Function import code ---*/ /*--- Execution code ---*/ - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":115 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":140 * return self.name.c_str() * * BLEU = Scorer('IBM_BLEU') # <<<<<<<<<<<<<< * TER = Scorer('TER') */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_24), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 115; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__BLEU, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 140; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":116 + /* "/Users/vchahun/Sandbox/cdec/python/src/mteval.pxi":141 * * BLEU = Scorer('IBM_BLEU') * TER = Scorer('TER') # <<<<<<<<<<<<<< */ - __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_1 = PyObject_Call(((PyObject *)((PyObject*)__pyx_ptype_5_cdec_Scorer)), ((PyObject *)__pyx_k_tuple_25), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); - if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_s__TER, __pyx_t_1) < 0) {__pyx_filename = __pyx_f[4]; __pyx_lineno = 141; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "_cdec.pyx":11 diff --git a/python/src/hypergraph.pxi b/python/src/hypergraph.pxi index ce78b729..9d09722e 100644 --- a/python/src/hypergraph.pxi +++ b/python/src/hypergraph.pxi @@ -32,39 +32,45 @@ cdef class Hypergraph: def kbest(self, size): cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal](self.hg[0], size) cdef kb.KBestDerivations[vector[WordID], kb.ESentenceTraversal].Derivation* derivation - cdef str sentence + cdef bytes sentence cdef unsigned k - for k in range(size): - derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - if not derivation: break - sentence = GetString(derivation._yield).c_str() - yield sentence.decode('utf8') - del derivations + try: + for k in range(size): + derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + if not derivation: break + sentence = GetString(derivation._yield).c_str() + yield sentence.decode('utf8') + finally: + del derivations def kbest_tree(self, size): cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal]* derivations = new kb.KBestDerivations[vector[WordID], kb.ETreeTraversal](self.hg[0], size) cdef kb.KBestDerivations[vector[WordID], kb.ETreeTraversal].Derivation* derivation cdef str tree cdef unsigned k - for k in range(size): - derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - if not derivation: break - tree = GetString(derivation._yield).c_str() - yield tree.decode('utf8') - del derivations + try: + for k in range(size): + derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + if not derivation: break + tree = GetString(derivation._yield).c_str() + yield tree.decode('utf8') + finally: + del derivations def kbest_features(self, size): cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal]* derivations = new kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal](self.hg[0], size) cdef kb.KBestDerivations[FastSparseVector[weight_t], kb.FeatureVectorTraversal].Derivation* derivation cdef SparseVector fmap cdef unsigned k - for k in range(size): - derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) - if not derivation: break - fmap = SparseVector() - fmap.vector = new FastSparseVector[weight_t](derivation._yield) - yield fmap - del derivations + try: + for k in range(size): + derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k) + if not derivation: break + fmap = SparseVector() + fmap.vector = new FastSparseVector[weight_t](derivation._yield) + yield fmap + finally: + del derivations def sample(self, unsigned n): cdef vector[hypergraph.Hypothesis]* hypos = new vector[hypergraph.Hypothesis]() @@ -73,10 +79,12 @@ cdef class Hypergraph: hypergraph.sample_hypotheses(self.hg[0], n, self.rng, hypos) cdef str sentence cdef unsigned k - for k in range(hypos.size()): - sentence = GetString(hypos[0][k].words).c_str() - yield sentence.decode('utf8') - del hypos + try: + for k in range(hypos.size()): + sentence = GetString(hypos[0][k].words).c_str() + yield sentence.decode('utf8') + finally: + del hypos # TODO richer k-best/sample output (feature vectors, trees?) @@ -89,6 +97,8 @@ cdef class Hypergraph: preserve_mask = new hypergraph.EdgeMask(self.hg.edges_.size()) preserve_mask[0][hypergraph.GetFullWordEdgeIndex(self.hg[0])] = True self.hg.PruneInsideOutside(beam_alpha, density, preserve_mask, False, 1, False) + if preserve_mask: + del preserve_mask def lattice(self): # TODO direct hg -> lattice conversion in cdec cdef str plf = hypergraph.AsPLF(self.hg[0], True).c_str() diff --git a/python/src/mteval.pxi b/python/src/mteval.pxi index dabdf927..9afb6fe1 100644 --- a/python/src/mteval.pxi +++ b/python/src/mteval.pxi @@ -56,6 +56,37 @@ cdef class SufficientStats: result.metric = x.metric return result +cdef class CandidateSet: + cdef shared_ptr[mteval.SegmentEvaluator]* scorer + cdef mteval.EvaluationMetric* metric + cdef mteval.CandidateSet* cs + + def __cinit__(self, SegmentEvaluator evaluator): + self.scorer = new shared_ptr[mteval.SegmentEvaluator](evaluator.scorer[0]) + self.metric = evaluator.metric + self.cs = new mteval.CandidateSet() + + def __dealloc__(self): + del self.scorer + del self.cs + + def __len__(self): + return self.cs.size() + + def __getitem__(self, unsigned k): + cdef Candidate candidate = Candidate() + candidate.candidate = &self.cs[0][k] + candidate.score = self.metric.ComputeScore(self.cs[0][k].eval_feats) + return candidate + + def __iter__(self): + cdef unsigned i + for i in range(len(self)): + yield self[i] + + def add_kbest(self, Hypergraph hypergraph, unsigned k): + self.cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) + cdef class SegmentEvaluator: cdef shared_ptr[mteval.SegmentEvaluator]* scorer cdef mteval.EvaluationMetric* metric @@ -72,23 +103,17 @@ cdef class SegmentEvaluator: self.scorer.get().Evaluate(hyp, sf.stats) return sf - def candidate_set(self, Hypergraph hypergraph, unsigned k): - cdef mteval.CandidateSet* cs = new mteval.CandidateSet() - cs.AddKBestCandidates(hypergraph.hg[0], k, self.scorer.get()) - cdef Candidate candidate - cdef unsigned i - for i in range(cs.size()): - candidate = Candidate() - candidate.candidate = &cs[0][i] - candidate.score = self.metric.ComputeScore(cs[0][i].eval_feats) - yield candidate - del cs + def candidate_set(self): + return CandidateSet(self) cdef class Scorer: cdef string* name def __cinit__(self, char* name): self.name = new string(name) + + def __dealloc__(self): + del self.name def __call__(self, refs): cdef mteval.EvaluationMetric* metric = mteval.Instance(self.name[0]) diff --git a/python/src/vectors.pxi b/python/src/vectors.pxi index 233c9530..fc0c365f 100644 --- a/python/src/vectors.pxi +++ b/python/src/vectors.pxi @@ -1,16 +1,20 @@ from cython.operator cimport preincrement as pinc cdef class DenseVector: - cdef vector[weight_t]* vector + cdef vector[weight_t]* vector # Not owned by DenseVector + + def __len__(self): + return self.vector.size() def __getitem__(self, char* fname): - cdef unsigned fid = FDConvert(fname) - if fid <= self.vector.size(): + cdef int fid = FDConvert(fname) + if 0 <= fid < self.vector.size(): return self.vector[0][fid] raise KeyError(fname) def __setitem__(self, char* fname, float value): - cdef unsigned fid = FDConvert(fname) + cdef int fid = FDConvert(fname) + if fid < 0: raise KeyError(fname) if self.vector.size() <= fid: self.vector.resize(fid + 1) self.vector[0][fid] = value @@ -32,21 +36,30 @@ cdef class DenseVector: cdef class SparseVector: cdef FastSparseVector[weight_t]* vector + def __dealloc__(self): + del self.vector + + def copy(self): + return self * 1 + def __getitem__(self, char* fname): - cdef unsigned fid = FDConvert(fname) + cdef int fid = FDConvert(fname) + if fid < 0: raise KeyError(fname) return self.vector.value(fid) def __setitem__(self, char* fname, float value): - cdef unsigned fid = FDConvert(fname) + cdef int fid = FDConvert(fname) + if fid < 0: raise KeyError(fname) self.vector.set_value(fid, value) def __iter__(self): cdef FastSparseVector[weight_t].const_iterator* it = new FastSparseVector[weight_t].const_iterator(self.vector[0], False) - cdef str fname - for i in range(self.vector.size()): - fname = FDConvert(it[0].ptr().first).c_str() - yield (fname, it[0].ptr().second) - pinc(it[0]) + try: + for i in range(self.vector.size()): + yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second) + pinc(it[0]) # ++it + finally: + del it def dot(self, other): if isinstance(other, DenseVector): @@ -54,12 +67,6 @@ cdef class SparseVector: elif isinstance(other, SparseVector): return self.vector.dot(( other).vector[0]) raise TypeError('cannot take the dot product of %s and SparseVector' % type(other)) - - def todense(self): - cdef DenseVector dense = DenseVector() - dense.vector = new vector[weight_t]() - self.vector.init_vector(dense.vector) - return dense def __richcmp__(SparseVector x, SparseVector y, int op): if op == 2: # == diff --git a/python/test.py b/python/test.py index b3900eef..8069aa0a 100644 --- a/python/test.py +++ b/python/test.py @@ -60,3 +60,6 @@ print forest.viterbi_source_tree() # Compare 1best and reference feature vectors fref = forest.viterbi_features() print dict(fsrc - fref) + +# Prune hypergraph +forest.prune(density=100) diff --git a/training/candidate_set.cc b/training/candidate_set.cc index 8c086ece..087efec3 100644 --- a/training/candidate_set.cc +++ b/training/candidate_set.cc @@ -4,6 +4,7 @@ #include +#include "verbose.h" #include "ns.h" #include "filelib.h" #include "wordid.h" @@ -118,7 +119,7 @@ void CandidateSet::WriteToFile(const string& file) const { } void CandidateSet::ReadFromFile(const string& file) { - cerr << "Reading candidates from " << file << endl; + if(!SILENT) cerr << "Reading candidates from " << file << endl; ReadFile rf(file); istream& in = *rf.stream(); string cand; @@ -133,11 +134,11 @@ void CandidateSet::ReadFromFile(const string& file) { ParseSparseVector(feats, 0, &cs.back().fmap); cs.back().eval_feats = SufficientStats(ss); } - cerr << " read " << cs.size() << " candidates\n"; + if(!SILENT) cerr << " read " << cs.size() << " candidates\n"; } void CandidateSet::Dedup() { - cerr << "Dedup in=" << cs.size(); + if(!SILENT) cerr << "Dedup in=" << cs.size(); tr1::unordered_set u; while(cs.size() > 0) { u.insert(cs.back()); @@ -148,7 +149,7 @@ void CandidateSet::Dedup() { cs.push_back(*it); it = u.erase(it); } - cerr << " out=" << cs.size() << endl; + if(!SILENT) cerr << " out=" << cs.size() << endl; } void CandidateSet::AddKBestCandidates(const Hypergraph& hg, size_t kbest_size, const SegmentEvaluator* scorer) { -- cgit v1.2.3