Skip to content

Commit

Permalink
Initial work fixing bug that was made clear in pr
Browse files Browse the repository at this point in the history
  • Loading branch information
dittmarg committed May 22, 2015
1 parent eeda560 commit af17981
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -724,11 +724,12 @@ class SparseVector(
if (size == 0) {
-1
} else {
var maxIdx = indices(0)
var maxValue = values(0)

var maxIdx = 0
var maxValue = if(indices(0) != 0) 0 else values(0)

foreachActive { (i, v) =>
if(v != 0.0 && v > maxValue){
if(v > maxValue){
maxIdx = i
maxValue = v
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ class VectorsSuite extends FunSuite {
val max = vec2.argmax
assert(max === 3)

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

test("vector equals") {
Expand Down

0 comments on commit af17981

Please sign in to comment.