Skip to content

Instantly share code, notes, and snippets.

@dlwh
Created October 3, 2013 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlwh/6806133 to your computer and use it in GitHub Desktop.
Save dlwh/6806133 to your computer and use it in GitHub Desktop.
@expand
@expand.exclude(Complex, OpMod)
@expand.exclude(BigInt, OpPow)
@expand.valify
implicit def dv_dv_Op[@expand.args(Int, Double, Float, Long, BigInt, Complex) T,
@expand.args(OpAdd, OpSub, OpMulScalar, OpDiv, OpSet, OpMod, OpPow) Op <: OpType]
(implicit @expand.sequence[Op]({_ + _}, {_ - _}, {_ * _}, {_ / _}, {(a,b) => b}, {_ % _}, {_ pow _})
op: BinaryOp[T, T, Op, T]):BinaryOp[DenseVector[T], DenseVector[T], Op, DenseVector[T]] = {
new BinaryOp[DenseVector[T], DenseVector[T], Op, DenseVector[T]] {
def apply(a: DenseVector[T], b: DenseVector[T]): DenseVector[T] = {
val ad = a.data
val bd = b.data
var aoff = a.offset
var boff = b.offset
val result = DenseVector.zeros[T](a.length)
val rd = result.data
var i = 0
while(i < a.length) {
rd(i) = op(ad(aoff), bd(boff))
aoff += a.stride
boff += b.stride
i += 1
}
result
}
implicitly[BinaryRegistry[Vector[T], Vector[T], Op, Vector[T]]].register(this)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment