Scala Breeze zipValues 问题
Scala Breeze zipValues issue
假设我有以下 Scala 代码。我是 运行 Scala 2.11.8 和 Breeze 0.13.
val a: DenseVector[Double] = DenseVector(1.1, 1.2, 1.3)
val b: DenseVector[Double] = DenseVector(1.1, 1.2, 1.3)
val v: DenseVector[Double] = zipValues(a, b) ((ai: Double, bi: Double) => ai + bi)
我得到一个类型不匹配的编译错误,它被翻译成:
[error] /Users/luishreis/Documents/projects/scala/sbt/GA/src/main/scala/ga_class.scala:119: type mismatch;
[error] found : (Double, Double) => Double
[error] required: breeze.linalg.zipValues.Impl2[breeze.linalg.DenseVector[Double],breeze.linalg.DenseVector[Double],?]
[error] (which expands to) breeze.generic.UFunc.UImpl2[breeze.linalg.zipValues.type,breeze.linalg.DenseVector[Double],breeze.linalg.DenseVector[Double],?]
[error] val v: DenseVector[Double] = zipValues(a, b) ((ai: Double, bi: Double) => ai + bi)
我试过不同的类型等等,但没有成功。有人愿意了解 zipValue 的内部工作原理吗?如有任何帮助,我们将不胜感激。
如果您 search the repository for zipValues
,您会发现它通常用作 zipValues(a, b).foreach(...)
。您的情况可能需要 zipValues(a, b).map((ai, bi) => ai + bi)
,但遗憾的是,目前尚未定义:
/**
* Usually used as the return type from zipValues
* @tparam V1
* @tparam V2
*/
trait ZippedValues[@specialized(Double) V1, @specialized(Double) V2] {
def foreach(f: (V1,V2) => Unit)
def exists(f: (V1, V2)=>Boolean):Boolean = {
foreach((a,b) => if (f(a,b)) return true)
false
}
def forall(f: (V1, V2)=>Boolean):Boolean = {
foreach((a,b) => if (!f(a,b)) return false)
true
}
// TODO: define map for this.
// def map[A](a: Coll1, b: Coll2, f: (V1,V2)=>A)(implicit canZipMapValues)
}
假设我有以下 Scala 代码。我是 运行 Scala 2.11.8 和 Breeze 0.13.
val a: DenseVector[Double] = DenseVector(1.1, 1.2, 1.3)
val b: DenseVector[Double] = DenseVector(1.1, 1.2, 1.3)
val v: DenseVector[Double] = zipValues(a, b) ((ai: Double, bi: Double) => ai + bi)
我得到一个类型不匹配的编译错误,它被翻译成:
[error] /Users/luishreis/Documents/projects/scala/sbt/GA/src/main/scala/ga_class.scala:119: type mismatch;
[error] found : (Double, Double) => Double
[error] required: breeze.linalg.zipValues.Impl2[breeze.linalg.DenseVector[Double],breeze.linalg.DenseVector[Double],?]
[error] (which expands to) breeze.generic.UFunc.UImpl2[breeze.linalg.zipValues.type,breeze.linalg.DenseVector[Double],breeze.linalg.DenseVector[Double],?]
[error] val v: DenseVector[Double] = zipValues(a, b) ((ai: Double, bi: Double) => ai + bi)
我试过不同的类型等等,但没有成功。有人愿意了解 zipValue 的内部工作原理吗?如有任何帮助,我们将不胜感激。
如果您 search the repository for zipValues
,您会发现它通常用作 zipValues(a, b).foreach(...)
。您的情况可能需要 zipValues(a, b).map((ai, bi) => ai + bi)
,但遗憾的是,目前尚未定义:
/**
* Usually used as the return type from zipValues
* @tparam V1
* @tparam V2
*/
trait ZippedValues[@specialized(Double) V1, @specialized(Double) V2] {
def foreach(f: (V1,V2) => Unit)
def exists(f: (V1, V2)=>Boolean):Boolean = {
foreach((a,b) => if (f(a,b)) return true)
false
}
def forall(f: (V1, V2)=>Boolean):Boolean = {
foreach((a,b) => if (!f(a,b)) return false)
true
}
// TODO: define map for this.
// def map[A](a: Coll1, b: Coll2, f: (V1,V2)=>A)(implicit canZipMapValues)
}