diff options
| author | Victor Chahuneau <vchahune@cs.cmu.edu> | 2012-10-16 01:07:11 -0400 | 
|---|---|---|
| committer | Victor Chahuneau <vchahune@cs.cmu.edu> | 2012-10-16 01:07:11 -0400 | 
| commit | 501c0419200234f4ff6b8c3d9f9602596a96c28e (patch) | |
| tree | e2653fbf3eca1473f9d0fe4498700fa4a5a0f10e /python/src/vectors.pxi | |
| parent | dc435732dbe8929aac900fef8b1d454291769862 (diff) | |
[python] Fix string problems + Documentation.
- use bytes instead of char*
- add some basic docstrings to functions/constructors
Diffstat (limited to 'python/src/vectors.pxi')
| -rw-r--r-- | python/src/vectors.pxi | 10 | 
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):  | 
