Github user dbtsai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6768#discussion_r32290348
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/util/MLUtils.scala ---
    @@ -270,12 +270,28 @@ object MLUtils {
        * Returns a new vector with `1.0` (bias) appended to the input vector.
        */
       def appendBias(vector: Vector): Vector = {
    -    val vector1 = vector.toBreeze match {
    -      case dv: BDV[Double] => BDV.vertcat(dv, new BDV[Double](Array(1.0)))
    -      case sv: BSV[Double] => BSV.vertcat(sv, new BSV[Double](Array(0), 
Array(1.0), 1))
    -      case v: Any => throw new IllegalArgumentException("Do not support 
vector type " + v.getClass)
    +    vector match {
    +      case dv: DenseVector =>
    +        val inputValues = dv.values
    +        val inputLength = inputValues.length
    +        val outputValues = Array.ofDim[Double](inputLength + 1)
    +        System.arraycopy(inputValues, 0, outputValues, 0, inputLength)
    +        outputValues(inputLength) = 1.0
    +        Vectors.dense(outputValues)
    +      case sv: SparseVector =>
    +        val inputValues = sv.values
    +        val inputIndices = sv.indices
    +        val inputValuesLength = inputValues.length
    +        val dim = sv.size
    +        val outputValues = Array.ofDim[Double](inputValuesLength + 1)
    +        val outputIndices = Array.ofDim[Int](inputValuesLength + 1)
    +        System.arraycopy(inputValues, 0, outputValues, 0, 
inputValuesLength)
    +        System.arraycopy(inputIndices, 0, outputIndices, 0, 
inputValuesLength)
    +        outputValues(inputValuesLength) = 1.0
    +        outputIndices(inputValuesLength) = dim
    +        Vectors.sparse(dim + 1, outputIndices, outputValues)
    +      case _ => throw new IllegalArgumentException("Do not support vector 
type " + vector.getClass)
    --- End diff --
    
    Please use 
    ```scala
      case _ => throw new IllegalArgumentException(s"Do not support vector type 
${vector.getClass}")
    ```


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to