File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
mllib/src/main/scala/org/apache/spark/mllib/linalg/distributed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -509,15 +509,24 @@ class RowMatrix(
509
509
*/
510
510
def multiply (B : Matrix ): RowMatrix = {
511
511
val n = numCols().toInt
512
+ val k = B .numCols
512
513
require(n == B .numRows, s " Dimension mismatch: $n vs ${B .numRows}" )
513
514
514
515
require(B .isInstanceOf [DenseMatrix ],
515
516
s " Only support dense matrix at this time but found ${B .getClass.getName}. " )
516
517
517
- val Bb = rows.context.broadcast(B )
518
+ val Bb = rows.context.broadcast(B .toBreeze. asInstanceOf [ BDM [ Double ]].toDenseVector.toArray )
518
519
val AB = rows.mapPartitions({ iter =>
519
- val Bi = Bb .value.toBreeze.asInstanceOf [BDM [Double ]]
520
- iter.map(v => Vectors .fromBreeze(Bi .t * v.toBreeze))
520
+ val Bi = Bb .value
521
+ iter.map(row => {
522
+ val v = BDV .zeros[Double ](k)
523
+ var i = 0
524
+ while (i < k) {
525
+ v(i) = row.toBreeze.dot(new BDV (Bi , i * n, 1 , n))
526
+ i += 1
527
+ }
528
+ Vectors .fromBreeze(v)
529
+ })
521
530
}, preservesPartitioning = true )
522
531
523
532
new RowMatrix (AB , nRows, B .numCols)
You can’t perform that action at this time.
0 commit comments