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

separation of NA and 0.0 in the SparseVector dot operation #768

Closed kmu-leeky closed 4 years ago

kmu-leeky commented 4 years ago

I am conducting a dot product operation of two sparse vectors and found out that there is no separation between NA and 0.0. For example, the below code output is 0.0

val a = new SparseVector(Array(1, 2), Array(1.0, 1.0), 3)
val b = new SparseVector(Array(1, 2), Array(1.0, -1.0), 3)
a.dot(b)

However, I feel the below output should not be 0.0, but something else that can express there is no matching element. Any consideration for this case?

val a = new SparseVector(Array(1, 2), Array(1.0, 1.0), 3)
val b = new SparseVector(Array(0), Array(1.0), 3)
a.dot(b)
dlwh commented 4 years ago

Sorry for being slow, but no, i don't like this. this would be quite different from how "normal" vectors work and I don't think other libraries do things like this?