summaryrefslogtreecommitdiff
path: root/python/src/vectors.pxi
diff options
context:
space:
mode:
authorKenneth Heafield <github@kheafield.com>2012-10-22 12:07:20 +0100
committerKenneth Heafield <github@kheafield.com>2012-10-22 12:07:20 +0100
commit5f98fe5c4f2a2090eeb9d30c030305a70a8347d1 (patch)
tree9b6002f850e6dea1e3400c6b19bb31a9cdf3067f /python/src/vectors.pxi
parentcf9994131993b40be62e90e213b1e11e6b550143 (diff)
parent21825a09d97c2e0afd20512f306fb25fed55e529 (diff)
Merge remote branch 'upstream/master'
Conflicts: Jamroot bjam decoder/Jamfile decoder/cdec.cc dpmert/Jamfile jam-files/sanity.jam klm/lm/Jamfile klm/util/Jamfile mira/Jamfile
Diffstat (limited to 'python/src/vectors.pxi')
-rw-r--r--python/src/vectors.pxi10
1 files changed, 8 insertions, 2 deletions
diff --git a/python/src/vectors.pxi b/python/src/vectors.pxi
index 87780556..46f58fd4 100644
--- a/python/src/vectors.pxi
+++ b/python/src/vectors.pxi
@@ -5,6 +5,7 @@ cdef class DenseVector:
cdef bint owned # if True, do not manage memory
def __init__(self):
+ """DenseVector() -> Dense weight/feature vector."""
self.vector = new vector[weight_t]()
self.owned = False
@@ -22,7 +23,7 @@ cdef class DenseVector:
raise KeyError(fname)
def __setitem__(self, char* fname, float value):
- cdef int fid = FDConvert(<char *>fname)
+ cdef int fid = FDConvert(fname)
if fid < 0: raise KeyError(fname)
if self.vector.size() <= fid:
self.vector.resize(fid + 1)
@@ -34,9 +35,11 @@ cdef class DenseVector:
yield str(FDConvert(fid).c_str()), self.vector[0][fid]
def dot(self, SparseVector other):
+ """vector.dot(SparseVector other) -> Dot product of the two vectors."""
return other.dot(self)
def tosparse(self):
+ """vector.tosparse() -> Equivalent SparseVector."""
cdef SparseVector sparse = SparseVector.__new__(SparseVector)
sparse.vector = new FastSparseVector[weight_t]()
InitSparseVector(self.vector[0], sparse.vector)
@@ -46,12 +49,14 @@ cdef class SparseVector:
cdef FastSparseVector[weight_t]* vector
def __init__(self):
+ """SparseVector() -> Sparse feature/weight vector."""
self.vector = new FastSparseVector[weight_t]()
def __dealloc__(self):
del self.vector
def copy(self):
+ """vector.copy() -> SparseVector copy."""
return self * 1
def __getitem__(self, char* fname):
@@ -60,7 +65,7 @@ cdef class SparseVector:
return self.vector.value(fid)
def __setitem__(self, char* fname, float value):
- cdef int fid = FDConvert(<char *>fname)
+ cdef int fid = FDConvert(fname)
if fid < 0: raise KeyError(fname)
self.vector.set_value(fid, value)
@@ -75,6 +80,7 @@ cdef class SparseVector:
del it
def dot(self, other):
+ """vector.dot(SparseVector/DenseVector other) -> Dot product of the two vectors."""
if isinstance(other, DenseVector):
return self.vector.dot((<DenseVector> other).vector[0])
elif isinstance(other, SparseVector):