Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ class SparseVector @Since("2.0.0") (
override def argmax: Int = {
if (size == 0) {
-1
} else if (numActives == 0) {
0
} else {
// Find the max active entry.
var maxIdx = indices(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ class VectorsSuite extends SparkMLFunSuite {

val vec8 = Vectors.sparse(5, Array(1, 2), Array(0.0, -1.0))
assert(vec8.argmax === 0)

// Check for case when sparse vector is non-empty but the values are empty
val vec9 = Vectors.sparse(100, Array.empty[Int], Array.empty[Double]).asInstanceOf[SparseVector]
assert(vec9.argmax === 0)

val vec10 = Vectors.sparse(1, Array.empty[Int], Array.empty[Double]).asInstanceOf[SparseVector]
assert(vec10.argmax === 0)
}

test("vector equals") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,8 @@ class SparseVector @Since("1.0.0") (
override def argmax: Int = {
if (size == 0) {
-1
} else if (numActives == 0) {
0
} else {
// Find the max active entry.
var maxIdx = indices(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ class VectorsSuite extends SparkFunSuite with Logging {

val vec8 = Vectors.sparse(5, Array(1, 2), Array(0.0, -1.0))
assert(vec8.argmax === 0)

// Check for case when sparse vector is non-empty but the values are empty
val vec9 = Vectors.sparse(100, Array.empty[Int], Array.empty[Double]).asInstanceOf[SparseVector]
assert(vec9.argmax === 0)

val vec10 = Vectors.sparse(1, Array.empty[Int], Array.empty[Double]).asInstanceOf[SparseVector]
assert(vec10.argmax === 0)
}

test("vector equals") {
Expand Down