我一直在使用Saddle,并注意到BinOpFrame.scala中的2个鞍座帧之间没有定义dot product
。
我尝试按照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.empty[C](mul.rowIx.length)), mul.rowIx))((prev, element) => opadd(prev, element._2))
result
}
}
implicit def FrFrDotDDD[X, Y](implicit cm: ST[X], cmp: ORD[X], my: ST[Y], cmpY: ORD[Y], opmul: BinOp[Multiply, Frame[X, Y, Double], Frame[X, Y, Double], Frame[X, Y, Double]], opadd: BinOp[Add, Series[X, Double], Series[X, Double], Series[X, Double]]) = new FrFrDot[X, Y, Double, Double, Double](opmul, opadd)
implicit def FrFrDotDateStringDDD(implicit cm: ST[Date], 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](opmul, opadd)
}
当我尝试将dot product
2 Frame[Date, String, Double]
计算为
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中给出的dot product
定义执行2个向量的implicit
,并且我的实现部分基于此。我知道我在上面的实现中有很多事情可能会遗漏一些简单的事情。有人能告诉我我错过了什么吗?
感谢。
奖金问题 -
我已经为JVM寻找了一个非分布式的全功能Pandas类库,Saddle
是我能找到的最好的。为什么没有认真努力开发Scala / Java Pandas?