summaryrefslogtreecommitdiff
path: root/python/src/vectors.pxi
diff options
context:
space:
mode:
authorPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-11-05 15:29:46 +0100
committerPatrick Simianer <simianer@cl.uni-heidelberg.de>2012-11-05 15:29:46 +0100
commit6f29f345dc06c1a1033475eac1d1340781d1d603 (patch)
tree6fa4cdd7aefd7d54c9585c2c6274db61bb8b159a /python/src/vectors.pxi
parentb510da2e562c695c90d565eb295c749569c59be8 (diff)
parentc615c37501fa8576584a510a9d2bfe2fdd5bace7 (diff)
merge upstream/master
Diffstat (limited to 'python/src/vectors.pxi')
-rw-r--r--python/src/vectors.pxi14
1 files changed, 10 insertions, 4 deletions
diff --git a/python/src/vectors.pxi b/python/src/vectors.pxi
index 989a6a7c..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)
@@ -31,12 +32,14 @@ cdef class DenseVector:
def __iter__(self):
cdef unsigned fid
for fid in range(1, self.vector.size()):
- yield FDConvert(fid).c_str(), self.vector[0][fid]
+ 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)
@@ -69,12 +74,13 @@ cdef class SparseVector:
cdef unsigned i
try:
for i in range(self.vector.size()):
- yield (FDConvert(it[0].ptr().first).c_str(), it[0].ptr().second)
+ yield (str(FDConvert(it[0].ptr().first).c_str()), it[0].ptr().second)
pinc(it[0]) # ++it
finally:
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):