Uh oh!
There was an error while loading. Please reload this page.
[SPARK-16469] enhanced simulate multiply - #14068
Conversation
srowen
commented
Jul 6, 2016
uzadude
commented
Jul 7, 2016
Hi srowen, |
srowen
commented
Jul 7, 2016
I don't think this is trivial. You also need to explain the change in more detail. |
uzadude
commented
Jul 8, 2016
Sure. valleftDestinations= leftMatrix.map { case (rowIndex, colIndex) =>valrightCounterparts= rightMatrix.filter(_._1 == colIndex)
valpartitions= rightCounterparts.map(b => partitioner.getPartition((rowIndex, b._2)))
((rowIndex, colIndex), partitions.toSet)
}.toMapmore clearly this part: valrightCounterparts= rightMatrix.filter(_._1 == colIndex)So if we were to cache this check for example in a HashMap: valrightCounterpartsHelper= rightMatrix.groupBy(_._1).map { case (rowIndex, arr) =>
(rowIndex, arr.map(b => b._2))
}We can omit the inner filter and just use it: valleftDestinations= leftMatrix.map { case (rowIndex, colIndex) =>
((rowIndex, colIndex), rightCounterpartsHelper.getOrElse(colIndex, Array()).map(b =>
partitioner.getPartition((rowIndex, b))).toSet)
}.toMapAnd to put it al toghether: valrightCounterpartsHelper= rightMatrix.groupBy(_._1).map { case (rowIndex, arr) =>
(rowIndex, arr.map(b => b._2))
}
valleftDestinations= leftMatrix.map { case (rowIndex, colIndex) =>
((rowIndex, colIndex), rightCounterpartsHelper.getOrElse(colIndex, Array()).map(b =>
partitioner.getPartition((rowIndex, b))).toSet)
}.toMapAnd the same trick also for the rightDestinations. |
| val leftMatrix = blockInfo.keys.collect() // blockInfo should already be cached | ||
| val rightMatrix = other.blocks.keys.collect() | ||
| val rightCounterpartsHelper = rightMatrix.groupBy(_._1).map { case (rowIndex, arr) => |
There was a problem hiding this comment.
Nit: could this just be rightMatrix.groupBy(_._1).mapValues(_.map(_._2))
srowen
commented
Jul 8, 2016
It does make sense. Please make a JIRA and connect this though. |
uzadude
commented
Jul 10, 2016
I have opened SPARK-16469. |
srowen
commented
Jul 10, 2016
LGTM but CC @brkyvz |
| val rightCounterparts = rightMatrix.filter(_._1 == colIndex) | ||
| val partitions = rightCounterparts.map(b => partitioner.getPartition((rowIndex, b._2))) | ||
| ((rowIndex, colIndex), partitions.toSet) | ||
| ((rowIndex, colIndex), rightCounterpartsHelper.getOrElse(colIndex, Array()).map(b => |
There was a problem hiding this comment.
nit: for readability could you assign this to a variable instead of inlining it?
In addition, for multi-line expressions
.map { b =>
blah
}is more preferred
brkyvz
commented
Jul 10, 2016
LGTM, just a minor nit! Thanks for this PR |
uzadude
commented
Jul 13, 2016
Have done the requested nit changes. |
srowen
commented
Jul 13, 2016
Jenkins retest this please |
SparkQA
commented
Jul 13, 2016
Test build #62234 has finished for PR 14068 at commit
|
## What changes were proposed in this pull request? We have a use case of multiplying very big sparse matrices. we have about 1000x1000 distributed block matrices multiplication and the simulate multiply goes like O(n^4) (n being 1000). it takes about 1.5 hours. We modified it slightly with classical hashmap and now run in about 30 seconds O(n^2). ## How was this patch tested? We have added a performance test and verified the reduced time. Author: oraviv <oraviv@paypal.com> Closes#14068 from uzadude/master. (cherry picked from commit ea06e4e) Signed-off-by: Sean Owen <sowen@cloudera.com>
akaltsikis
commented
Jul 26, 2016
@uzadude hey, i am looking to multiply VERY LARGE AND VERY SPARSE matrixes using Spark. I would love some discussion over it. Can you give me a way to contact you? |
uzadude
commented
Jul 26, 2016
Sure, what size are you talking about? we had to some internal code fixes to do that. right now the support for sparse matrices is pretty poor - mainly because Breeze doesn't support it. |
akaltsikis
commented
Jul 26, 2016
@uzadude Looking forward to make it work for matrixes bigger than 1Mx1M and sparsity of 0.001-0.002. |
What changes were proposed in this pull request?
We have a use case of multiplying very big sparse matrices. we have about 1000x1000 distributed block matrices multiplication and the simulate multiply goes like O(n^4) (n being 1000). it takes about 1.5 hours. We modified it slightly with classical hashmap and now run in about 30 seconds O(n^2).
How was this patch tested?
We have added a performance test and verified the reduced time.