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

Commit

Permalink
Remove bitenumerate; use itr macro from Iterators instead
Browse files Browse the repository at this point in the history
Can be merged once JuliaCollections/Iterators.jl#33 makes it into a release
  • Loading branch information
simonster committed Jul 8, 2014
1 parent aca6c87 commit 31531ab
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 27 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
julia 0.3.0-
StatsBase 0.3
Iterators 0.1.5+
2 changes: 1 addition & 1 deletion src/DataArrays.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using StatsBase

module DataArrays
using StatsBase
using StatsBase, Iterators

const DEFAULT_POOLED_REF_TYPE = Uint32

Expand Down
4 changes: 2 additions & 2 deletions src/dataarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,12 @@ Base.endof(da::DataArray) = endof(da.data) # -> Int
function Base.find(da::DataArray{Bool}) # -> Array{Int}
data = da.data
ntrue = 0
@inbounds @bitenumerate da.na i na begin
@inbounds @itr for (i, na) in enumerate(da.na)
ntrue += !na && data[i]
end
res = Array(Int, ntrue)
count = 1
@inbounds @bitenumerate da.na i na begin
@inbounds @itr for (i, na) in enumerate(da.na)
if !na && data[i]
res[count] = i
count += 1
Expand Down
26 changes: 13 additions & 13 deletions src/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ macro dataarray_unary(f, intype, outtype, N...)
function $(f){T<:$(intype)}(d::$(isempty(N) ? :(DataArray{T}) : :(DataArray{T,$(N[1])})))
data = d.data
res = similar(data, $(outtype))
@bitenumerate d.na i na begin
@itr for (i, na) in enumerate(d.na)
if !na
@inbounds res[i] = $(f)(data[i])
end
Expand Down Expand Up @@ -295,11 +295,11 @@ macro dataarray_binary_scalar(vectorfunc, scalarfunc, outtype, swappable)
:(function $(vectorfunc)(a::DataArray, b::$t)
data = a.data
res = similar(data, $outtype)
@bitenumerate a.na i na begin
@itr(for (i, na) in enumerate(a.na)
if !na
@inbounds res[i] = $(scalarfunc)(data[i], b)
end
end
end)
DataArray(res, copy(a.na))
end),
:(function $(vectorfunc)(a::AbstractDataArray, b::$t)
Expand Down Expand Up @@ -333,11 +333,11 @@ macro dataarray_binary_array(vectorfunc, scalarfunc, outtype)
data2 = $(btype == :DataArray || btype == :(DataArray{Bool}) ? :(b.data) : :b)
res = Array($outtype, promote_shape(size(a), size(b)))
resna = $narule
@bitenumerate resna i na begin
@itr(for (i, na) in enumerate(resna)
if !na
@inbounds res[i] = $(scalarfunc)(data1[i], data2[i])
end
end
end)
DataArray(res, resna)
end
end
Expand Down Expand Up @@ -399,7 +399,7 @@ for (f, elf) in ((:(Base.ctranspose), :conj), (:(Base.transpose), :identity))
data = d.data
sz = (size(data, 1), size(data, 2))
res = similar(data, size(data, 2), size(data, 1))
@bitenumerate d.na i na begin
@itr for (i, na) in enumerate(d.na)
if !na
jnew, inew = ind2sub(sz, i)
@inbounds res[inew, jnew] = $(elf)(data[i])
Expand Down Expand Up @@ -494,7 +494,7 @@ for f in (:(Base.round), :(Base.ceil), :(Base.floor), :(Base.trunc))

function $(f){T<:Real}(d::DataArray{T}, args::Integer...)
data = similar(d.data)
@bitenumerate d.na i na begin
@itr for (i, na) in enumerate(d.na)
if !na
@inbounds data[i] = $(f)(d[i], args...)
end
Expand Down Expand Up @@ -565,7 +565,7 @@ function Base.isequal(a::DataArray, b::DataArray)
if size(a) != size(b) || a.na != b.na
return false
end
@bitenumerate a.na i na begin
@itr for (i, na) in enumerate(a.na)
@inbounds if !na && !isequal(a.data[i], b.data[i])
return false
end
Expand All @@ -589,7 +589,7 @@ function Base.(:(==))(a::DataArray, b::DataArray)
bdata = b.data
bchunks = b.na.chunks
has_na = false
@bitenumerate a.na i na begin
@itr for (i, na) in enumerate(a.na)
if na || Base.unsafe_bitgetindex(bchunks, i)
has_na = true
else
Expand All @@ -607,7 +607,7 @@ end
size(a) == size(b) || return false
adata = a.data
has_na = false
@bitenumerate a.na i na begin
@itr for (i, na) in enumerate(a.na)
if na
has_na = true
else
Expand Down Expand Up @@ -828,7 +828,7 @@ for f in cumulative_vector_operators
new_data = ($f)(dv.data)
new_na = falses(length(dv))
hitna = false
@bitenumerate dv.na i na begin
@itr for (i, na) in enumerate(dv.na)
hitna |= na
if hitna
new_na[i] = true
Expand Down Expand Up @@ -879,7 +879,7 @@ end
function Base.all(dv::DataArray{Bool})
data = dv.data
has_na = false
@bitenumerate dv.na i na begin
@itr for (i, na) in enumerate(dv.na)
if !na
data[i] || return false
else
Expand All @@ -904,7 +904,7 @@ end

function Base.any(dv::DataArray{Bool})
has_na = false
@bitenumerate dv.na i na begin
@itr for (i, na) in enumerate(dv.na)
if !na
if dv.data[i]
return true
Expand Down
11 changes: 0 additions & 11 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,3 @@ function typeloop(vals)
end
return toptype
end

# Enumerate a BitArray. This is faster than using enumerate()
macro bitenumerate(ba, i, x, code)
esc(quote
$i = 1
for $x in $ba
$code
$i += 1
end
end)
end

0 comments on commit 31531ab

Please sign in to comment.