MLlib微风向量/矩阵是私有的org.apache.spark.mllib范围是什么? [英] MLlib to Breeze vectors/matrices are private to org.apache.spark.mllib scope?

查看:229
本文介绍了MLlib微风向量/矩阵是私有的org.apache.spark.mllib范围是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过的地方,当地MLlib向量/矩阵正在包装微风实现,但转换MLlib微风向量方法/矩阵私有org.apache.spark.mllib范围。建议来解决,这是写你的code在org.apache.spark.mllib.something包。

I have read somewhere that MLlib local vectors/matrices are currently wrapping Breeze implementation, but the methods converting MLlib to Breeze vectors/matrices are private to org.apache.spark.mllib scope. The suggestion to work around this is to write your code in org.apache.spark.mllib.something package.

有没有更好的方法来做到这一点?你能举一些相关的例子?

Is there a better way to do this? Can you cite some relevant examples?

感谢和问候,

推荐答案

我做了同样的解决方案,@dlwh建议。这里是code,它做的:

I did the same solution as @dlwh suggested. Here is the code that does it:

package org.apache.spark.mllib.linalg

object VectorPub {

  implicit class VectorPublications(val vector : Vector) extends AnyVal {
    def toBreeze : breeze.linalg.Vector[scala.Double] = vector.toBreeze

  }

  implicit class BreezeVectorPublications(val breezeVector : breeze.linalg.Vector[Double]) extends AnyVal {
    def fromBreeze : Vector = Vectors.fromBreeze(breezeVector)
  }
}

公告称,隐性类扩展到AnyVal一个新的对象prevent分配调用这些方法时,

notice that the implicit class extends AnyVal to prevent allocation of a new object when calling those methods

这篇关于MLlib微风向量/矩阵是私有的org.apache.spark.mllib范围是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆