Skip to content
Snippets Groups Projects
Commit f51b0f93 authored by Patrick Wendell's avatar Patrick Wendell
Browse files

Adding Java-accessible methods to Vector.scala

This is needed for the Strata machine learning tutorial (and
also is generally helpful).
parent d942d390
No related branches found
No related tags found
No related merge requests found
...@@ -10,12 +10,14 @@ class Vector(val elements: Array[Double]) extends Serializable { ...@@ -10,12 +10,14 @@ class Vector(val elements: Array[Double]) extends Serializable {
throw new IllegalArgumentException("Vectors of different length") throw new IllegalArgumentException("Vectors of different length")
return Vector(length, i => this(i) + other(i)) return Vector(length, i => this(i) + other(i))
} }
def add(other: Vector) = +(other)
def - (other: Vector): Vector = { def - (other: Vector): Vector = {
if (length != other.length) if (length != other.length)
throw new IllegalArgumentException("Vectors of different length") throw new IllegalArgumentException("Vectors of different length")
return Vector(length, i => this(i) - other(i)) return Vector(length, i => this(i) - other(i))
} }
def subtract(other: Vector) = -(other)
def dot(other: Vector): Double = { def dot(other: Vector): Double = {
if (length != other.length) if (length != other.length)
...@@ -60,10 +62,13 @@ class Vector(val elements: Array[Double]) extends Serializable { ...@@ -60,10 +62,13 @@ class Vector(val elements: Array[Double]) extends Serializable {
} }
this this
} }
def addInPlace(other: Vector) = +=(other)
def * (scale: Double): Vector = Vector(length, i => this(i) * scale) def * (scale: Double): Vector = Vector(length, i => this(i) * scale)
def multiply (d: Double) = *(d)
def / (d: Double): Vector = this * (1 / d) def / (d: Double): Vector = this * (1 / d)
def divide (d: Double) = /(d)
def unary_- = this * -1 def unary_- = this * -1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment