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

    https://github.com/apache/spark/pull/6342#discussion_r30942480
  
    --- Diff: python/pyspark/mllib/linalg.py ---
    @@ -897,6 +914,33 @@ def __init__(self, numRows, numCols, colPtrs, 
rowIndices, values,
                 raise ValueError("Expected rowIndices of length %d, got %d."
                                  % (self.rowIndices.size, self.values.size))
     
    +    def __str__(self):
    +        spstr = "{0} X {1} ".format(self.numRows, self.numCols)
    +        if self.isTransposed:
    +            spstr += "CSRMatrix\n"
    +        else:
    +            spstr += "CSCMatrix\n"
    +
    +        for i, colPtr in enumerate(self.colPtrs[:-1]):
    +            endptr = self.colPtrs[i + 1]
    +            values = self.values[colPtr: endptr]
    +            rowindices = self.rowIndices[colPtr: endptr]
    +            for j, rowInd in enumerate(rowindices):
    +                if self.isTransposed:
    +                    spstr += '({0},{1}) {2}\n'.format(
    +                        i, rowInd, _format_float(values[j]))
    +                else:
    +                    spstr += '({0},{1}) {2}\n'.format(
    +                        rowInd, i, _format_float(values[j]))
    --- End diff --
    
    Great. But do you have any objection to the current method? I'll change the 
string `+=` to appending to a list, so that it become faster. If you are afraid 
of the temporary array creation in my method, those are just slices.
    
    And also this creates another array (zip) of size nnz.


---
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