saddle scala mysql_Scala Saddle - 框架的点产品/我做错了什么?

我一直在使用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熊猫?

// Contributed by Daniel Gronau import scala.annotation._ trait Func[T] { val zero: T def inc(t: T): T def dec(t: T): T def in: T def out(t: T): Unit } object ByteFunc extends Func[Byte] { override val zero: Byte = 0 override def inc(t: Byte) = ((t + 1) & 0xFF).toByte override def dec(t: Byte) = ((t - 1) & 0xFF).toByte override def in: Byte = readByte override def out(t: Byte) { print(t.toChar) } } case class Tape[T](left: List[T], cell: T, right: List[T])(implicit func: Func[T]) { private def headOf(list:List[T]) = if (list.isEmpty) func.zero else list.head private def tailOf(list:List[T]) = if (list.isEmpty) Nil else list.tail def isZero = cell == func.zero def execute(ch: Char) = (ch: @switch) match { case '+' => copy(cell = func.inc(cell)) case '-' => copy(cell = func.dec(cell)) case '<' => Tape(tailOf(left), headOf(left), cell :: right) case '>' => Tape(cell :: left, headOf(right), tailOf(right)) case '.' => func.out(cell); this case ',' => copy(cell = func.in) case '[' | ']' => this case _ => error("Unexpected token: " + ch) } } object Tape { def empty[T](func: Func[T]) = Tape(Nil, func.zero, Nil)(func) } class Brainfuck[T](func:Func[T]) { def execute(p: String) { val prog = p.replaceAll("[^\\+\\-\\[\\]\\.\\,\\>\\<]", "") @tailrec def braceMatcher(pos: Int, stack: List[Int], o2c: Map[Int, Int]): Map[Int,Int] = if(pos == prog.length) o2c else (prog(pos): @switch) match { case '[' => braceMatcher(pos + 1, pos :: stack, o2c) case ']' => braceMatcher(pos + 1, stack.tail, o2c + (stack.head -> pos)) case _ => braceMatcher(pos + 1, stack, o2c) } val open2close = braceMatcher(0, Nil, Map()) val close2open = open2close.map(_.swap) @tailrec def ex(pos:Int, tape:Tape[T]): Unit = if(pos < prog.length) ex((prog(pos): @switch) match { case '[' if tape.isZero => open2close(pos) case ']' if ! tape.isZero => close2open(pos) case _ => pos + 1 }, tape.execute(prog(pos))) println("---running---") ex(0, Tape.empty(func)) println("\n---done---") } } /* Run with: val bf = new Brainfuck(ByteFunc) bf.execute(""">+++++++++[<++++++++>-]<.>+++++++[<++ ++>-]<+.+++++++..+++.[-]>++++++++[<++++>-] <.#>+++++++++++[<+++++>-]<.>++++++++[<++ +>-]<.+++.------.--------.[-]>++++++++[<++++> -]<+.[-]++++++++++.""") */
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值