如何访问直接在星火CoordinateMatrix条目? [英] How to access CoordinateMatrix entries directly in Spark?

查看:241
本文介绍了如何访问直接在星火CoordinateMatrix条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要存储用星火大稀疏矩阵,
所以我试图用 CoordinateMatrix ,因为它是一个分布式的矩阵。

I want to store a big sparse matrix using Spark, so I tried to use CoordinateMatrix, since it is a distributed matrix.

不过,我还没有找到一种方法来访问每个条目直接像这样的方式:

However, I have not found a way to access each entry directly such as this way:

apply(int x, int y)

我只找到了功能,如:

I only found the functions like:

public RDD<MatrixEntry> entries()

在这种情况下,我不得不遍历所有的条目,以找出一个我想,这是不是有效的方法。

In this case, I have to loop over the entries to find out the one I want, which is not efficient way.

有没有人使用 CoordinateMatrix 过吗?

我应该怎么做才能得到每个条目 CoordinateMatrix 高效?

What should I do to get each entry from CoordinateMatrix efficiently?

推荐答案

简短的答案是你不知道。 RDDS和 CoordinateMatrix 或多或少是围绕包装RDD [MatrixEntry] ,不适合进行随机访问。此外RDDS是不可变的,所以你不能简单地修改一个条目。如果这是你的要求,你可能看错技术。

Short answer is you don't. RDDs, and CoordinateMatrix is more or less a wrapper around the RDD[MatrixEntry], are not well suited for random access. Moreover RDDs are immutable so you cannot simply modify a single entry. If it is your requirement you're probably looking at the wrong technology.

有对随机访问一些有限的支持,如果你使用 PairRDD 。如果这样的RDD被划分可以使用查找方法来有效地恢复单个值:

There is some limited support for random access if you use PairRDD. If such a RDD is partitioned you can use lookup method to efficiently recover a single value:

val n = ??? // Number of partitions
val pairs = mat.
    entries.
    map{case MatrixEntry(i, j, v) => ((i, j), v)}.
    partitionBy(new HashPartitioner(n))
pairs.lookup((1, 1))

这篇关于如何访问直接在星火CoordinateMatrix条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆