2016-08-06 2 views
0

다음과 같은 스칼라 코드가 있습니다. Scala 2.11.8 및 Breeze 0.13을 사용하고 있습니다.Scala Breeze zip 값 문제

[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) 

내가 다른 유형과 같은,하지만 성공을 시도했다 :

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) 

나는로 번역됩니다 형식 불일치 컴파일 오류가 발생합니다. zipValue의 내부 동작에 빛을 비추는 사람은 누구입니까? 어떤 도움이 절실히 받아 들여질 것입니다.

답변

1

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) 
}