summaryrefslogtreecommitdiff
path: root/python/src/_cdec.pyx
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2012-07-06 11:45:32 +0200
committerPatrick Simianer <p@simianer.de>2012-07-06 11:45:32 +0200
commit45a1af0ff9c164978f91b2734fb24c45551aa25c (patch)
treea3cb13ccc47386b2e51e1fb50fa9a96d5d7fa905 /python/src/_cdec.pyx
parent4ec3625b3a1aa9cb417f8a551ad6723626a4c656 (diff)
parent757f56e391bd2e1d7442ab38fc98aff00d064d38 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'python/src/_cdec.pyx')
-rw-r--r--python/src/_cdec.pyx18
1 files changed, 17 insertions, 1 deletions
diff --git a/python/src/_cdec.pyx b/python/src/_cdec.pyx
index 6fafbbc0..cccfec0b 100644
--- a/python/src/_cdec.pyx
+++ b/python/src/_cdec.pyx
@@ -14,7 +14,7 @@ class ParseFailed(Exception): pass
cdef class Decoder:
cdef decoder.Decoder* dec
- cdef public DenseVector weights
+ cdef DenseVector weights
def __cinit__(self, char* config):
decoder.register_feature_functions()
@@ -27,6 +27,22 @@ cdef class Decoder:
def __dealloc__(self):
del self.dec
+ property weights:
+ def __get__(self):
+ return self.weights
+
+ def __set__(self, weights):
+ if isinstance(weights, DenseVector):
+ self.weights.vector[0] = (<DenseVector> weights).vector[0]
+ elif isinstance(weights, SparseVector):
+ self.weights.vector.clear()
+ ((<SparseVector> weights).vector[0]).init_vector(self.weights.vector)
+ elif isinstance(weights, dict):
+ for fname, fval in weights.items():
+ self.weights[fname] = fval
+ else:
+ raise TypeError('cannot initialize weights with %s' % type(weights))
+
def read_weights(self, cfg):
with open(cfg) as fp:
for line in fp: