Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5355#discussion_r28042928
  
    --- Diff: python/pyspark/mllib/linalg.py ---
    @@ -687,6 +702,100 @@ def __eq__(self, other):
                     all(self.values == other.values))
     
     
    +class SparseMatrix(object):
    +    """Sparse Matrix stored in CSC format."""
    +    def __init__(self, numRows, numCols, colPtrs, rowIndices, values,
    +                 isTransposed=False):
    +        self.numRows = numRows
    +        self.numCols = numCols
    +        self.isTransposed = isTransposed
    +        if isinstance(colPtrs, basestring):
    +            self.colPtrs = np.frombuffer(colPtrs, dtype=np.uint64)
    +        else:
    +            self.colPtrs = np.asarray(colPtrs, dtype=np.uint64)
    +
    +        if self.isTransposed and self.colPtrs.size != numRows + 1:
    +            raise ValueError("Expected colPtrs of size %d, got %d."
    +                             % (numRows + 1, self.colPtrs.size))
    +        elif not self.isTransposed and self.colPtrs.size != numCols + 1:
    +            raise ValueError("Expected colPtrs of size %d, got %d."
    +                             % (numCols + 1, self.colPtrs.size))
    +        if isinstance(rowIndices, basestring):
    +            self.rowIndices = np.frombuffer(rowIndices, dtype=np.uint64)
    +        else:
    +            self.rowIndices = np.asarray(rowIndices, dtype=np.uint64)
    +        if isinstance(values, basestring):
    +            self.values = np.frombuffer(values, dtype=np.float64)
    +        else:
    +            self.values = np.asarray(values, dtype=np.float64)
    +
    --- End diff --
    
    check the lengths of rowIndices and values are equal.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to