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

    https://github.com/apache/spark/pull/117#discussion_r10860087
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/linalg/Vectors.scala 
---
    @@ -0,0 +1,179 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.mllib.linalg
    +
    +import java.lang.{Iterable => JavaIterable}
    +
    +import scala.annotation.varargs
    +import scala.collection.JavaConverters._
    +
    +import breeze.linalg.{Vector => BV, DenseVector => BDV, SparseVector => 
BSV}
    +
    +/**
    + * Represents a numeric vector, whose index type is Int and value type is 
Double.
    + */
    +trait Vector extends Serializable {
    +
    +  /**
    +   * Size of the vector.
    +   */
    +  def size: Int
    +
    +  /**
    +   * Converts the instance to a double array.
    +   */
    +  def toArray: Array[Double]
    +
    +  override def equals(other: Any): Boolean = {
    +    other match {
    +      case v: Vector =>
    +        this.toArray.view.equals(v.toArray.view)
    +      case _ => false
    +    }
    +  }
    +
    +  override def hashCode(): Int = toArray.view.hashCode()
    +
    +  /**
    +   * Converts the instance to a breeze vector.
    +   */
    +  private[mllib] def toBreeze: BV[Double]
    +}
    +
    +/**
    + * Represents a vector with random access to its elements.
    + *
    + */
    +trait RandomAccessVector extends Vector {
    +  // empty
    +}
    +
    +/**
    + * Factory methods for [[org.apache.spark.mllib.linalg.Vector]].
    + */
    +object Vectors {
    +
    +  /**
    +   * Creates a dense vector.
    +   */
    +  @varargs
    +  def dense(values: Double*): Vector = new DenseVector(values.toArray)
    +
    +  // A dummy implicit is used to avoid signature collision with the one 
generated by @varargs.
    +  /**
    +   * Creates a dense vector from a double array.
    +   */
    +  def dense(values: Array[Double])(implicit d: DummyImplicit): Vector = 
new DenseVector(values)
    --- End diff --
    
    This will be problematic to call from Java. The right workaround is this:
    ```
    def dense(values: Array[Double]) { ... }
    def dense(firstValue: Double, otherValues: Double*) { ... }
    ```
    I believe it should work in Java too but you should try it (add Java unit 
tests for this)


---
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.
---

Reply via email to