scalanlp / breeze

Breeze is/was a numerical processing library for Scala.
https://www.scalanlp.org
Apache License 2.0
3.45k stars 693 forks source link

Cannot get outer product of a sparse vector and a dense vector #779

Closed csnardi closed 4 years ago

csnardi commented 4 years ago

Attempting to get the outer product of a sparse vector and a dense vector by themselves fails. For instance:

val a = breeze.linalg.DenseVector.zeros[Double](250)
val b = breeze.linalg.SparseVector.zeros[Double](300)
a * b.t
<console>:28: error: could not find implicit value for parameter op: breeze.linalg.operators.OpMulMatrix.Impl2[breeze.linalg.DenseVector[Double],breeze.linalg.Transpose[breeze.linalg.SparseVector[Double]],That]
       a * b.t

However, this works perfectly fine when the sparse vector is converted to a dense vector first:

res14: a * b.toDenseVector.t
breeze.linalg.DenseMatrix[Double] =
0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  ... (300 total)
0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  ...
0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  ...
0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  ...
0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  ...
0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  ...
0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  ...
0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  ...
0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  ...
0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  ...
0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  ...
0.0  0.0  0...
bluesheeptoken commented 4 years ago

This is probably due to the ambiguity of this operation. Would you expect to have a Dense matrix or a Sparse Matrix ?

@dlwh Any idea on that ? Would it be better to left it unimplemented ? Calculate a Sparse Matrix ? I might have some free time to implement it if there is a decision taken

dlwh commented 4 years ago

i think calculating a sparse matrix is a great idea. If you have cycles that would be amazing

On Mon, May 18, 2020 at 5:43 AM Louis FRULEUX notifications@github.com wrote:

This is probably due to the ambiguity of this operation. Would you expect to have a Dense matrix or a Sparse Matrix ?

@dlwh https://github.com/dlwh Any idea on that ? Would it be better to left it unimplemented ? Calculate a Sparse Matrix ? I might have some free time to implement it if there is a decision taken

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/scalanlp/breeze/issues/779#issuecomment-630157418, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAACLINWGZNJLXVKJNUTLHDRSEUQRANCNFSM4MYGK2LA .