Github user jegonzal commented on the pull request:
https://github.com/apache/spark/pull/2996#issuecomment-61026298
The following implementation seems a bit more efficient but is needlessly
complicated.
```scala
// Count the number of empty values
var i = 1
var emptyValues = 0
while (i < items.size) {
if (items(i).isEmpty) emptyValues += 1
i += 1
}
// Determine the number of non-zero entries
val nnzs = items.size - 1 - emptyValues
// Compute the indices
val indices = new Array[Int](nnzs)
val values = new Array[Double](nnzs)
i = 1
var j = 0
while (i < items.size) {
if (!items(i).isEmpty) {
val indexAndValue = items(i).split(':')
indices(j) = indexAndValue(0).toInt - 1 // Convert 1-based
indices to 0-based.
values(j) = indexAndValue(1).toDouble
j += 1
}
i += 1
}
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]