Github user dusenberrymw commented on a diff in the pull request:
https://github.com/apache/spark/pull/7554#discussion_r36034619
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/api/python/PythonMLLibAPI.scala ---
@@ -1096,6 +1097,56 @@ private[python] class PythonMLLibAPI extends
Serializable {
Statistics.kolmogorovSmirnovTest(data, distName, paramsSeq: _*)
}
+ /**
+ * Wrapper around RowMatrix constructor.
+ */
+ def createRowMatrix(rows: JavaRDD[Vector], numRows: Long, numCols: Int):
RowMatrix = {
+ new RowMatrix(rows.rdd, numRows, numCols)
+ }
+
+ /**
+ * Wrapper around IndexedRowMatrix constructor.
+ */
+ def createIndexedRowMatrix(rows: DataFrame, numRows: Long, numCols:
Int): IndexedRowMatrix = {
+ // We use DataFrames for serialization of IndexedRows from Python,
+ // so map each Row in the DataFrame back to an IndexedRow.
+ val indexedRows = rows.map {
+ case Row(index: Long, vector: Vector) => IndexedRow(index, vector)
+ }
+ new IndexedRowMatrix(indexedRows, numRows, numCols)
+ }
+
+ /**
+ * Wrapper around CoordinateMatrix constructor.
+ */
+ def createCoordinateMatrix(rows: DataFrame, numRows: Long, numCols:
Long): CoordinateMatrix = {
+ // We use DataFrames for serialization of MatrixEntry entries from
+ // Python, so map each Row in the DataFrame back to a MatrixEntry.
+ val entries = rows.map {
+ case Row(i: Long, j: Long, value: Double) => MatrixEntry(i, j, value)
+ }
+ new CoordinateMatrix(entries, numRows, numCols)
+ }
+
+ /**
+ * Return the rows of an IndexedRowMatrix.
+ */
+ def getIndexedRows(indexedRowMatrix: IndexedRowMatrix): DataFrame = {
+ // We use DataFrames for serialization of IndexedRows to Python,
+ // so return a DataFrame.
+ val sqlContext = SQLContext.getOrCreate(SparkContext.getOrCreate())
--- End diff --
Great, I'll change that.
---
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]