import breeze.linalg._import breeze.linalg.operators._import breeze.macros.expand object VectorOps {
import breeze.math.PowImplicits._
@expand @expand.valify implicit def dv_dv_Op[@expand.args(Int, Double) T, @expand.args(OpAdd, OpSub, OpDiv, OpSet, OpMod, OpPow) Op <: OpType] (implicit @expand.sequence[Op]({_ + _}, {_ - _}, {_ / _}, {(a, b) => b}, {_ % _}, {_ pow _}) op: Op.Impl2[T, T, T]): Op.Impl2[DenseVector[T], DenseVector[T], DenseVector[T]] = { new Op.Impl2[DenseVector[T], DenseVector[T], DenseVector[T]] { def apply(a: DenseVector[T], b: DenseVector[T]): DenseVector[T] = { (a.length, b.length) match { case (1, bl) => val s = a(0) val result = DenseVector.zeros[T](bl) var i = 0 while (i < bl) { result(i) = op(s, b(i)) i += 1 } result case _ => // irrelevant a } } implicitly[BinaryRegistry[Vector[T], Vector[T], Op.type, Vector[T]]].register(this) } }}
def run(): Unit = { val x = DenseVector(1.0, 2.0, 3.0) val y = DenseVector(1.0, 2.0, 3.0, 4.0, 5.0) println(x + y) }
--
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-interna...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
import breeze.linalg.DenseVectorimport breeze.linalg.operators.OpAddimport breeze.macros.expand object VectorOps { @expand implicit def dv_dv_Op[@expand.args(Int) T]: OpAdd.Impl2[DenseVector[T], DenseVector[T], DenseVector[T]] = { new OpAdd.Impl2[DenseVector[T], DenseVector[T], DenseVector[T]] {
def apply(a: DenseVector[T], b: DenseVector[T]): DenseVector[T] = {
val s = a(0) // if you remove that line it compiles ok DenseVector.zeros[T](1) } } }}
On the other hand, removing @spec(Int) for K on TensorLike and QuasiTensor (but keeping it on Tensor) seems to be ok as well.
--