summaryrefslogtreecommitdiff
path: root/python/src/hypergraph.pxi
diff options
context:
space:
mode:
authorVictor Chahuneau <vchahune@cs.cmu.edu>2012-07-27 22:25:15 -0400
committerVictor Chahuneau <vchahune@cs.cmu.edu>2012-07-27 22:25:15 -0400
commit9961abf8f756279ac6d839e0b3de2b0d83431965 (patch)
tree2defad3f49df2921ff68a48a07a9ca0693a1f0f7 /python/src/hypergraph.pxi
parent733e1b1507d27d4f53055f740e8098f56215ab8f (diff)
[python] conversion from cdec.sa.Rule to cdec.TRule
+ remove configobj dependency + re-structure packages (no more top-level library) + "const" stuff + use __new__ instead of constructor for some objects
Diffstat (limited to 'python/src/hypergraph.pxi')
-rw-r--r--python/src/hypergraph.pxi18
1 files changed, 9 insertions, 9 deletions
diff --git a/python/src/hypergraph.pxi b/python/src/hypergraph.pxi
index 86751cc9..b210f440 100644
--- a/python/src/hypergraph.pxi
+++ b/python/src/hypergraph.pxi
@@ -21,7 +21,7 @@ cdef class Hypergraph:
return (f_tree, e_tree)
def viterbi_features(self):
- cdef SparseVector fmap = SparseVector()
+ cdef SparseVector fmap = SparseVector.__new__(SparseVector)
fmap.vector = new FastSparseVector[weight_t](hypergraph.ViterbiFeatures(self.hg[0]))
return fmap
@@ -67,7 +67,7 @@ cdef class Hypergraph:
for k in range(size):
derivation = derivations.LazyKthBest(self.hg.nodes_.size() - 1, k)
if not derivation: break
- fmap = SparseVector()
+ fmap = SparseVector.__new__(SparseVector)
fmap.vector = new FastSparseVector[weight_t](derivation._yield)
yield fmap
finally:
@@ -130,12 +130,12 @@ cdef class Hypergraph:
return self.hg.NumberOfPaths()
def inside_outside(self):
- cdef FastSparseVector[LogVal[double]]* result = new FastSparseVector[LogVal[double]]()
- cdef LogVal[double] z = hypergraph.InsideOutside(self.hg[0], result)
+ cdef FastSparseVector[prob_t]* result = new FastSparseVector[prob_t]()
+ cdef prob_t z = hypergraph.InsideOutside(self.hg[0], result)
result[0] /= z
- cdef SparseVector vector = SparseVector()
+ cdef SparseVector vector = SparseVector.__new__(SparseVector)
vector.vector = new FastSparseVector[double]()
- cdef FastSparseVector[LogVal[double]].const_iterator* it = new FastSparseVector[LogVal[double]].const_iterator(result[0], False)
+ cdef FastSparseVector[prob_t].const_iterator* it = new FastSparseVector[prob_t].const_iterator(result[0], False)
cdef unsigned i
for i in range(result.size()):
vector.vector.set_value(it[0].ptr().first, log(it[0].ptr().second))
@@ -147,12 +147,12 @@ cdef class Hypergraph:
cdef class HypergraphEdge:
cdef hypergraph.Hypergraph* hg
cdef hypergraph.HypergraphEdge* edge
- cdef public BaseTRule trule
+ cdef public TRule trule
cdef init(self, hypergraph.Hypergraph* hg, unsigned i):
self.hg = hg
self.edge = &hg.edges_[i]
- self.trule = BaseTRule()
+ self.trule = TRule.__new__(TRule)
self.trule.rule = new shared_ptr[grammar.TRule](self.edge.rule_)
return self
@@ -175,7 +175,7 @@ cdef class HypergraphEdge:
property feature_values:
def __get__(self):
- cdef SparseVector vector = SparseVector()
+ cdef SparseVector vector = SparseVector.__new__(SparseVector)
vector.vector = new FastSparseVector[double](self.edge.feature_values_)
return vector