diff options
author | Chris Dyer <cdyer@cs.cmu.edu> | 2012-07-28 12:11:44 -0400 |
---|---|---|
committer | Chris Dyer <cdyer@cs.cmu.edu> | 2012-07-28 12:11:44 -0400 |
commit | 9052682200365b64115f2f88eb02cb150dc7ade4 (patch) | |
tree | 8e9609daeaa93f0edf421114c5cdbed016709332 /python/src/_cdec.pyx | |
parent | 5276e368ad643434fd73527329ed70507ee49dfc (diff) | |
parent | 455ca8bc1406ec2f6554fce9be7488bb3cca75dd (diff) |
Merge branch 'master' of github.com:redpony/cdec
Diffstat (limited to 'python/src/_cdec.pyx')
-rw-r--r-- | python/src/_cdec.pyx | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/python/src/_cdec.pyx b/python/src/_cdec.pyx index c60f342f..e93474fe 100644 --- a/python/src/_cdec.pyx +++ b/python/src/_cdec.pyx @@ -3,14 +3,14 @@ from libcpp.vector cimport vector from utils cimport * cimport decoder -cdef char* as_str(data, error_msg='Cannot convert type %s to str'): +cdef char* as_str(data, char* error_msg='Cannot convert type %s to str'): cdef bytes ret if isinstance(data, unicode): ret = data.encode('utf8') elif isinstance(data, str): ret = data else: - raise TypeError(error_msg % type(data)) + raise TypeError(error_msg.format(type(data))) return ret include "vectors.pxi" @@ -55,8 +55,9 @@ cdef class Decoder: cdef istringstream* config_stream = new istringstream(config_str) self.dec = new decoder.Decoder(config_stream) del config_stream - self.weights = DenseVector() + self.weights = DenseVector.__new__(DenseVector) self.weights.vector = &self.dec.CurrentWeightVector() + self.weights.owned = True def __dealloc__(self): del self.dec @@ -72,6 +73,7 @@ cdef class Decoder: self.weights.vector.clear() ((<SparseVector> weights).vector[0]).init_vector(self.weights.vector) elif isinstance(weights, dict): + self.weights.vector.clear() for fname, fval in weights.items(): self.weights[fname] = fval else: @@ -80,7 +82,7 @@ cdef class Decoder: property formalism: def __get__(self): cdef variables_map* conf = &self.dec.GetConf() - return conf[0]['formalism'].as_str().c_str() + return conf[0]['formalism'].as_str() def read_weights(self, weights): with open(weights) as fp: |