Skip to content

Commit

Permalink
Fixing code style and updating if logic on when to check for zero values
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeDittmar committed Jun 9, 2015
1 parent ee1a85a commit d5b5423
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -736,11 +736,9 @@ class SparseVector(
}

// look for inactive values in case all active node values are negative
if(size != values.size && maxValue <= 0){
if (size != values.size && maxValue <= 0){
val firstInactiveIdx = calcFirstInactiveIdx(0)
if(maxValue == 0){
if(firstInactiveIdx >= maxIdx) maxIdx else maxIdx = firstInactiveIdx
}else{
if (!(maxValue == 0 && firstInactiveIdx >= maxIdx)){
maxIdx = firstInactiveIdx
}
maxValue = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,26 @@ class VectorsSuite extends FunSuite {
val max = vec2.argmax
assert(max === 3)

val vec3 = Vectors.sparse(5,Array(2, 4),Array(1.0,-.7))
val vec3 = Vectors.sparse(5,Array(2, 3, 4),Array(1.0, 0.0, -.7))
val max2 = vec3.argmax
assert(max2 === 2)

// check for case that sparse vector is created with only negative values {0.0, 0.0,-1.0, -0.7, 0.0}
val vec4 = Vectors.sparse(5,Array(2, 3),Array(-1.0,-.7))
val vec4 = Vectors.sparse(5,Array(2, 3),Array(-1.0, -.7))
val max3 = vec4.argmax
assert(max3 === 0)

val vec5 = Vectors.sparse(11,Array(0, 3, 10),Array(-1.0,-.7,0.0))
val vec5 = Vectors.sparse(11,Array(0, 3, 10),Array(-1.0, -.7, 0.0))
val max4 = vec5.argmax
assert(max4 === 1)

val vec6 = Vectors.sparse(5,Array(0, 1, 3),Array(-1.0, 0.0, -.7))
val vec6 = Vectors.sparse(11,Array(0, 1, 2),Array(-1.0, -.7, 0.0))
val max5 = vec6.argmax
assert(max5 === 1)
assert(max5 === 2)

val vec7 = Vectors.sparse(5,Array(0, 1, 3),Array(-1.0, 0.0, -.7))
val max6 = vec7.argmax
assert(max6 === 1)

var vec8 = Vectors.sparse(5,Array(1, 2),Array(0.0, -1.0))
val max7 = vec8.argmax
Expand Down

0 comments on commit d5b5423

Please sign in to comment.