summaryrefslogtreecommitdiff
path: root/python/src/vectors.pxi
diff options
context:
space:
mode:
authorVictor Chahuneau <vchahune@cs.cmu.edu>2012-07-05 16:53:26 -0400
committerVictor Chahuneau <vchahune@cs.cmu.edu>2012-07-05 16:53:26 -0400
commit757f56e391bd2e1d7442ab38fc98aff00d064d38 (patch)
treedb07405a8e182655fe182757ff76859b4008dba1 /python/src/vectors.pxi
parent32a8d92affae91094f2348b73dd26be800e10abd (diff)
[python] Add convenience methods
Diffstat (limited to 'python/src/vectors.pxi')
-rw-r--r--python/src/vectors.pxi6
1 files changed, 6 insertions, 0 deletions
diff --git a/python/src/vectors.pxi b/python/src/vectors.pxi
index fc0c365f..ce95968c 100644
--- a/python/src/vectors.pxi
+++ b/python/src/vectors.pxi
@@ -80,6 +80,12 @@ cdef class SparseVector:
def __contains__(self, char* fname):
return self.vector.nonzero(FDConvert(fname))
+
+ def __neg__(self):
+ cdef SparseVector result = SparseVector()
+ result.vector = new FastSparseVector[weight_t](self.vector[0])
+ result.vector[0] *= -1.0
+ return result
def __iadd__(SparseVector self, SparseVector other):
self.vector[0] += other.vector[0]