Skip to content
This repository was archived by the owner on May 4, 2019. It is now read-only.

Compute unary and some binary functions faster for PooledDataArray #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.(:.-)),
Expand Down