{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/9159","labels_url":"https://api.github.com/repos/apache/spark/issues/9159/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/9159/comments","events_url":"https://api.github.com/repos/apache/spark/issues/9159/events","html_url":"https://github.com/apache/spark/pull/9159","id":112017059,"number":9159,"title":"[SPARK-10757] [MLlib] Java friendly constructor for distributed matrices","user":{"login":"javelinjs","id":631860,"avatar_url":"https://avatars.githubusercontent.com/u/631860?v=3","gravatar_id":"","url":"https://api.github.com/users/javelinjs","html_url":"https://github.com/javelinjs","followers_url":"https://api.github.com/users/javelinjs/followers","following_url":"https://api.github.com/users/javelinjs/following{/other_user}","gists_url":"https://api.github.com/users/javelinjs/gists{/gist_id}","starred_url":"https://api.github.com/users/javelinjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/javelinjs/subscriptions","organizations_url":"https://api.github.com/users/javelinjs/orgs","repos_url":"https://api.github.com/users/javelinjs/repos","events_url":"https://api.github.com/users/javelinjs/events{/privacy}","received_events_url":"https://api.github.com/users/javelinjs/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-10-18T12:36:48Z","updated_at":"2015-10-27T15:04:24Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/9159","html_url":"https://github.com/apache/spark/pull/9159","diff_url":"https://github.com/apache/spark/pull/9159.diff","patch_url":"https://github.com/apache/spark/pull/9159.patch"},"body":"This patch allows java developers to construct BlockMatrix and RowMatrix more naturally.\r\n\r\nTake BlockMatrix as an example, the type of 'blocks' in current constructor is RDD[((Int, Int), Matrix)], while more precisely it should be RDD[((Int, Int), T<:Matrix)]. This could cause some problem. If we add a Java-friendly constructor\r\n\r\n```{scala}\r\ndef this(blocks: JavaRDD[((Integer, Integer), Matrix)],\r\n    rowsPerBlock: Int,\r\n    colsPerBlock: Int)\r\n```\r\nand then construct a BlockMatrix with RDD[(Int, Int), DenseMatrix], the complier will complain a conflict, like:\r\n\r\n```\r\nmethod constructor BlockMatrix with alternatives:\r\n(blocks: org.apache.spark.api.java.JavaRDD[((Integer, Integer), org.apache.spark.mllib.linalg.Matrix)],rowsPerBlock: Int,colsPerBlock: Int)org.apache.spark.mllib.linalg.distributed.BlockMatrix <and>\r\n(blocks: org.apache.spark.rdd.RDD[((Int, Int), org.apache.spark.mllib.linalg.Matrix)],rowsPerBlock: Int,colsPerBlock: Int)org.apache.spark.mllib.linalg.distributed.BlockMatrix\r\ncannot be applied to (org.apache.spark.rdd.RDD[((Int, Int), org.apache.spark.mllib.linalg.DenseMatrix)], Int, Int)\r\n```\r\n\r\nOn the other hand, BlockMatrix should hide the underlying implementation of sub-matrix, no matter it is dense or sparse. Thus, a class level covariant for Matrix is improper. That's why I add a companion object method to construct BlockMatrix/RowMatrix\r\n\r\nFor IndexedRowMatrix/CoordinateMatrix, since the RDD parameters for them are really simple and contain no type inheritance, I don't see necessity to add additional Java friendly apis for those two. Or do we need them to let java users construct IndexedRowMatrix/CoordinateMatrix in the same way as what they do with BlockMatrix/RowMatrix?"},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/151532262","html_url":"https://github.com/apache/spark/pull/9159#issuecomment-151532262","issue_url":"https://api.github.com/repos/apache/spark/issues/9159","id":151532262,"user":{"login":"javelinjs","id":631860,"avatar_url":"https://avatars.githubusercontent.com/u/631860?v=3","gravatar_id":"","url":"https://api.github.com/users/javelinjs","html_url":"https://github.com/javelinjs","followers_url":"https://api.github.com/users/javelinjs/followers","following_url":"https://api.github.com/users/javelinjs/following{/other_user}","gists_url":"https://api.github.com/users/javelinjs/gists{/gist_id}","starred_url":"https://api.github.com/users/javelinjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/javelinjs/subscriptions","organizations_url":"https://api.github.com/users/javelinjs/orgs","repos_url":"https://api.github.com/users/javelinjs/repos","events_url":"https://api.github.com/users/javelinjs/events{/privacy}","received_events_url":"https://api.github.com/users/javelinjs/received_events","type":"User","site_admin":false},"created_at":"2015-10-27T15:04:24Z","updated_at":"2015-10-27T15:04:24Z","body":"@yanboliang @mengxr I've added some test cases."}}