diff options
author | Matei Zaharia <matei@eecs.berkeley.edu> | 2013-02-23 15:55:06 -0800 |
---|---|---|
committer | Matei Zaharia <matei@eecs.berkeley.edu> | 2013-02-23 15:55:06 -0800 |
commit | 8a0ca6f05c379fdf6e8286047a409e865b8da53f (patch) | |
tree | 8e0b62a7126b9fe675f8bdc5adeee6cd9883adaf | |
parent | d942d3907241d50b693a316785af56023ec218b4 (diff) | |
parent | 931f439be9048fde244b81e3eae4ad5ff9de4adf (diff) | |
download | spark-8a0ca6f05c379fdf6e8286047a409e865b8da53f.tar.gz spark-8a0ca6f05c379fdf6e8286047a409e865b8da53f.tar.bz2 spark-8a0ca6f05c379fdf6e8286047a409e865b8da53f.zip |
Merge pull request #491 from pwendell/java-vector
Adding Java-accessible methods to Vector.scala
-rw-r--r-- | core/src/main/scala/spark/util/Vector.scala | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/core/src/main/scala/spark/util/Vector.scala b/core/src/main/scala/spark/util/Vector.scala index 03559751bc..835822edb2 100644 --- a/core/src/main/scala/spark/util/Vector.scala +++ b/core/src/main/scala/spark/util/Vector.scala @@ -11,12 +11,16 @@ class Vector(val elements: Array[Double]) extends Serializable { return Vector(length, i => this(i) + other(i)) } + def add(other: Vector) = this + other + def - (other: Vector): Vector = { if (length != other.length) throw new IllegalArgumentException("Vectors of different length") return Vector(length, i => this(i) - other(i)) } + def subtract(other: Vector) = this - other + def dot(other: Vector): Double = { if (length != other.length) throw new IllegalArgumentException("Vectors of different length") @@ -61,10 +65,16 @@ class Vector(val elements: Array[Double]) extends Serializable { this } + def addInPlace(other: Vector) = this +=other + def * (scale: Double): Vector = Vector(length, i => this(i) * scale) + def multiply (d: Double) = this * d + def / (d: Double): Vector = this * (1 / d) + def divide (d: Double) = this / d + def unary_- = this * -1 def sum = elements.reduceLeft(_ + _) |