File tree Expand file tree Collapse file tree 1 file changed +4
-26
lines changed
mllib/src/main/scala/org/apache/spark/mllib/linalg Expand file tree Collapse file tree 1 file changed +4
-26
lines changed Original file line number Diff line number Diff line change @@ -724,7 +724,6 @@ class SparseVector(
724
724
if (size == 0 ) {
725
725
- 1
726
726
} else {
727
-
728
727
var maxIdx = indices(0 )
729
728
var maxValue = values(0 )
730
729
@@ -735,33 +734,12 @@ class SparseVector(
735
734
}
736
735
}
737
736
738
- // look for inactive values in case all active node values are negative
739
- if (size != values.size && maxValue <= 0 ) {
740
- val firstInactiveIdx = calcFirstInactiveIdx(0 )
741
- if (! (maxValue == 0 && firstInactiveIdx >= maxIdx)) {
742
- maxIdx = firstInactiveIdx
743
- }
744
- maxValue = 0
737
+ var k = 0
738
+ while (k < indices.length && indices(k) == k && values(k) != 0.0 ) {
739
+ k += 1
745
740
}
746
- maxIdx
747
- }
748
- }
749
741
750
- /**
751
- * Calculates the first instance of an inactive node in a sparse vector and returns the Idx
752
- * of the element.
753
- * @param idx starting index of computation
754
- * @return index of first inactive node
755
- */
756
- private [SparseVector ] def calcFirstInactiveIdx (idx : Int ): Int = {
757
- if (idx < size) {
758
- if (! indices.contains(idx)) {
759
- idx
760
- } else {
761
- calcFirstInactiveIdx(idx + 1 )
762
- }
763
- } else {
764
- - 1
742
+ if (maxValue <= 0.0 || k >= maxIdx) k else maxIdx
765
743
}
766
744
}
767
745
}
You can’t perform that action at this time.
0 commit comments