summaryrefslogtreecommitdiff
path: root/python/src/_cdec.pyx
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2012-07-28 12:11:44 -0400
committerChris Dyer <cdyer@cs.cmu.edu>2012-07-28 12:11:44 -0400
commit306e0ba4754c6c4f460536cfe8c3f118dc1cc175 (patch)
treead5ea3b0a5370ac613d1bad715fe0f5ab8c91c11 /python/src/_cdec.pyx
parent934e55dc12c3f374684bc6a0797e6f85c7abb85a (diff)
parentee5e376e263d9aeabdeee6968b4457f53d3fc772 (diff)
Merge branch 'master' of github.com:redpony/cdec
Diffstat (limited to 'python/src/_cdec.pyx')
-rw-r--r--python/src/_cdec.pyx10
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: