Spark 矩阵中的分布式 BlockMatrix

Distributed BlockMatrix out of Spark Matrices

How to make a distributed BlockMatrix out of Matrices (of the same size)?

例如设A,B为两个2乘2mllib.linalg.Matrices如下

import org.apache.spark.mllib.linalg.{Matrix, Matrices}
import org.apache.spark.mllib.linalg.distributed.BlockMatrix

val A: Matrix = Matrices.dense(2, 2, Array(1.0, 2.0, 3.0, 4.0))
val B: Matrix = Matrices.dense(2, 2, Array(5.0, 6.0, 7.0, 8.0))
val C = new BlockMatrix(???)

我怎样才能先从 A、B 制作一个 RDD[((Int, Int), Matrix)],然后再从 A、B 制作一个分布式的 BlockMatrix

如有任何评论或提前提供帮助,我将不胜感激。

您可以通过先创建 RDD[((Int, Int), Matrix)]

来构建 BlockMatrix
val blocks: RDD[((Int, Int), Matrix)] = sc.parallelize(Seq(((0, 0), A), ((0, 1), B))

然后将其转换为 BlockMatrix

val blockMatrix: BlockMatrix = new BlockMatrix(blocks, 2, 2)

这将为您提供 BlockMatrix,其格式为 [A | B]