Created
October 3, 2013 07:02
-
-
Save dlwh/6806133 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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