由於spark將breeze進行了wrapper使用其提供的線性代數等功能,但為了不影響其程序的穩定性,以及后期對Breeze的替換。因而在MLlib外部,以及用戶自己使用時,
不能將SDV與BDV進行互轉換(toBreeze, fromBreeze)
-- 封裝互轉函數如下
import breeze.linalg._
import breeze.linalg.{DenseVector => BDV}
import org.apache.spark.mllib.linalg.Vectors
import org.apache.spark.mllib.linalg.{DenseVector => SDV}
import org.apache.spark.{SparkConf, SparkContext}
import org.apache.spark.mllib.optimization.L1Updater
object lr_testing {
def SDV2BDV(vector: SDV): BDV[Double] = {
new BDV(vector.values)
}
def BDV2SDV(vector: BDV[Double]): SDV = {
new SDV(vector.data)
}
def main(args: Array[String]): Unit = {
val sc = new SparkContext(new SparkConf().setAppName("testing").setMaster("local"))
val w = new SDV(Array(1.0, 2.0, 3.0))
val g = new SDV(Array(0.0, 1.0, 1.0))
//此處將SDV轉換為BDV可以進行進一步計算!
axpy(2.0, SDV2BDV(w), SDV2BDV(g))
println(g)
}
}
