Github user dbtsai commented on a diff in the pull request:
https://github.com/apache/spark/pull/3288#discussion_r20688070
--- Diff:
mllib/src/test/scala/org/apache/spark/mllib/linalg/VectorsSuite.scala ---
@@ -173,4 +173,63 @@ class VectorsSuite extends FunSuite {
val v = Vectors.fromBreeze(x(::, 0))
assert(v.size === x.rows)
}
+
+ test("foreach") {
+ val dv = Vectors.dense(0.0, 1.2, 3.1, 0.0)
+ val sv = Vectors.sparse(4, Seq((1, 1.2), (2, 3.1), (3, 0.0)))
+
+ val dvMap0 = scala.collection.mutable.Map[Int, Double]()
+ dv.foreach() {
+ case (index: Int, value: Double) => dvMap0.put(index, value)
+ }
--- End diff --
Calling `foreach` without parenthesis
```scala
dv.foreach {
case (index: Int, value: Double) => dvMap0.put(index, value)
}
```
will cause
```
Error:(182, 16) missing parameter type for expanded function
The argument types of an anonymous function must be fully known. (SLS 8.5)
Expected type was: Boolean
dv.foreach {
^
```
This is scala curry function overloading issue. It seems that unless we
change the signature to
```scala
private[spark] def foreach(skippingZeros: Boolean = false, f: ((Int,
Double)) => Unit)
```
we need to explicitly call it with parenthesis when we want to call it with
default value of skippingZeros.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]