Skip to content

Commit

Permalink
Added argmax to sparse vector and added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
George authored and George committed May 12, 2015
1 parent 3cffed4 commit df9538a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -728,18 +728,11 @@ class SparseVector(
var maxValue = values(0)

foreachActive { (i, v) =>
if(values(i) > maxValue){
if(v > maxValue){
maxIdx = i
maxValue = v
}
}
// while(i < this.indices.size){
// if(values(i) > maxValue){
// maxIdx = indices(i)
// maxValue = values(i)
// }
// i += 1
// }
maxIdx
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ class VectorsSuite extends FunSuite {
val vec2 = Vectors.sparse(n,indices,values).asInstanceOf[SparseVector]
val max = vec2.argmax
assert(max === 3)

val vec3 = Vectors.sparse(5,Array(1,3,4),Array(1.0,.5,.7))
val max2 = vec3.argmax
assert(max2 === 1)
}

test("vector equals") {
Expand Down

0 comments on commit df9538a

Please sign in to comment.