From ef188c8a597fbfbbcd84b434e953e04445426e54 Mon Sep 17 00:00:00 2001 From: "David A. van Leeuwen" Date: Thu, 16 Oct 2014 20:33:31 +0200 Subject: [PATCH] Comput unary and some binary functions faster for PooledDataArray --- src/operators.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/operators.jl b/src/operators.jl index c5a04a2..cf4ee87 100644 --- a/src/operators.jl +++ b/src/operators.jl @@ -262,6 +262,11 @@ macro dataarray_unary(f, intype, outtype, N...) end DataArray(res, copy(d.na)) end + ## For pooled data, we only need to operate on .pool + function $(f){T<:$(intype),U}(pda::$(isempty(N) ? :(PooledDataArray{T,U}) : :(PooledDataArray{T,U,$(N[1])}))) + PooledDataArray(RefArray(pda.refs), ($f)(pda.pool)) + end + ## catchall: function $(f){T<:$(intype)}(adv::$(isempty(N) ? :(AbstractDataArray{T}) : :(AbstractDataArray{T,$(N[1])}))) res = similar(adv, $(outtype)) for i = 1:length(adv) @@ -296,6 +301,11 @@ macro dataarray_binary_scalar(vectorfunc, scalarfunc, outtype, swappable) end DataArray(res, copy(a.na)) end), + ## for PooledDataArrays, we only need to operate on .pool + :(function $(vectorfunc)(a::PooledDataArray, b::$t) + ## strange that I cannot say $(vectorfunc)(a.pool, b) + PooledDataArray(RefArray(a.refs), [$(scalarfunc)(x, b) for x in a.pool]) + end), :(function $(vectorfunc)(a::AbstractDataArray, b::$t) res = similar(a, $outtype) for i = 1:length(a) @@ -670,6 +680,7 @@ end # Necessary to avoid ambiguity warnings Base.(:.^)(::MathConst{:e}, B::DataArray) = exp(B) +Base.(:.^)(::MathConst{:e}, B::PooledDataArray) = exp(B) Base.(:.^)(::MathConst{:e}, B::AbstractDataArray) = exp(B) for f in (:(Base.(:+)), :(Base.(:.+)), :(Base.(:-)), :(Base.(:.-)),