我一直在使用Saddle,并注意到dot product没有在BinOpFrame.scala中的两个鞍座帧之间定义。
我试图遵循BinOpFrame.scala和BinOpVec.scala的示例来编写我自己的实现,如下所示
package org.saddle.ops
import scala.{ specialized => spec }
import org.saddle._
import index._
import java.util.Date
trait BinOpFrameCustom {
final class FrFrDot[X: ST: ORD, Y: ST: ORD, @spec(Int, Long, Double) A, @spec(Int, Long, Double) B: ST, @spec(Int, Long, Double) C: ST: NUM](
val opmul: BinOp[Multiply, Frame[X, Y, A], Frame[X, Y, B], Frame[X, Y, C]],
val opadd: BinOp[Add, Series[X, C], Series[X, C], Series[X, C]])
extends BinOp[InnerProd, Frame[X, Y, A], Frame[X, Y, B], Series[X, C]] {
def apply(f1: Frame[X, Y, A], f2: Frame[X, Y, B]): Series[X, C] = {
require(f1.colIx.length == f2.colIx.length, "Frames must have the same number of columns!")
require(f1.rowIx.length == f2.rowIx.length, "Frames must have the same number of rows!")
val (l, r) = f1.align(f2, OuterJoin, OuterJoin)
val mul = opmul(l, r)
val result = mul.toColSeq.foldLeft(Series(Vec(array.emptyC), mul.rowIx))((prev, element) => opadd(prev, element._2))
result
}
}
implicit def FrFrDotDDDX, Y = new FrFrDotX, Y, Double, Double, Double
implicit def FrFrDotDateStringDDD(implicit cm: STDate], cmp: ORD[Date], my: ST[String], cmpString: ORD[String], opmul: BinOp[Multiply, Frame[Date, String, Double], Frame[Date, String, Double], Frame[Date, String, Double]], opadd: BinOp[Add, Series[Date, Double], Series[Date, Double], Series[Date, Double]]) = new FrFrDot[Date, String, Double, Double, Double
}当我尝试计算2 Frame[Date, String, Double]的dot product为
val result = frame1.dot(frame2)我收到以下编译错误
No BinOp org.saddle.ops.InnerProd instance available to operate on values of type org.saddle.Frame[java.util.Date,String,Double] and org.saddle.Frame[java.util.Date,String,Double]
not enough arguments for method dot: (implicit op: org.saddle.ops.BinOp[org.saddle.ops.InnerProd,org.saddle.Frame[java.util.Date,String,Double],org.saddle.Frame[java.util.Date,String,Double],That])That. Unspecified value parameter op.我可以使用BinOpVec.scala中给出的implicit定义执行2个矢量的dot product,并且已经部分基于我的实现。我知道我在上面的实现中有很多事情要做,可能会错过简单的东西。有人能告诉我我错过了什么吗?
谢谢。
奖金问题 -
我已经为JVM寻找了一个非分布式的全功能熊猫类库,Saddle是我能找到的最好的。为什么没有认真努力开发一个Scala / Java熊猫?