Skip to content

Commit af17981

Browse files
committed
Initial work fixing bug that was made clear in pr
1 parent eeda560 commit af17981

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

mllib/src/main/scala/org/apache/spark/mllib/linalg/Vectors.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,11 +724,12 @@ class SparseVector(
724724
if (size == 0) {
725725
-1
726726
} else {
727-
var maxIdx = indices(0)
728-
var maxValue = values(0)
727+
728+
var maxIdx = 0
729+
var maxValue = if(indices(0) != 0) 0 else values(0)
729730

730731
foreachActive { (i, v) =>
731-
if(v != 0.0 && v > maxValue){
732+
if(v > maxValue){
732733
maxIdx = i
733734
maxValue = v
734735
}

mllib/src/test/scala/org/apache/spark/mllib/linalg/VectorsSuite.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ class VectorsSuite extends FunSuite {
9191
val max = vec2.argmax
9292
assert(max === 3)
9393

94-
// check for case that sparse vector is created with a zero value in it by mistake
95-
val vec3 = Vectors.sparse(5,Array(0, 2, 4),Array(-1.0, 0.0, -.7))
94+
// check for case that sparse vector is created with only negative vaues {0.0,0.0,-1.0,0.0,-0.7}
95+
val vec3 = Vectors.sparse(5,Array(2, 4),Array(-1.0,-.7))
9696
val max2 = vec3.argmax
97-
assert(max2 === 4)
97+
assert(max2 === 0)
9898
}
9999

100100
test("vector equals") {

0 commit comments

Comments
 (0)