Skip to content

Commit

Permalink
bitarray: default to Bool instead of Int
Browse files Browse the repository at this point in the history
only bitones and bitzeros now default to Int
  • Loading branch information
carlobaldassi committed May 6, 2012
1 parent 587dec9 commit 0310315
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions extras/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ type BitArray{T<:Integer, N} <: AbstractArray{T, N}
end

BitArray{T}(::Type{T}) = BitArray{T, 1}(0)
BitArray() = BitArray(Int, 0)
BitArray() = BitArray(Bool, 0)
BitArray{T}(::Type{T}, dims::Dims) = BitArray{T, max(length(dims), 1)}(dims...)
BitArray(dims::Dims) = BitArray(Int, dims)
BitArray(dims::Dims) = BitArray(Bool, dims)
BitArray{T}(::Type{T}, dims::Int...) = BitArray{T, max(length(dims), 1)}(dims...)
BitArray(dims::Int...) = BitArray(Int, dims...)
BitArray(dims::Int...) = BitArray(Bool, dims...)

typealias BitVector{T} BitArray{T,1}
typealias BitMatrix{T} BitArray{T,2}
Expand Down Expand Up @@ -189,10 +189,10 @@ fill{T}(B::BitArray{T}, x::(Int64...,)) = fill(B, int(x))
fill{T}(B::BitArray{T}, x) = fill(B, convert(T, x))

bitzeros{T}(::Type{T}, args...) = fill!(BitArray(T, args...), 0)
bitzeros(args...) = fill!(BitArray(args...), 0)
bitzeros(args...) = fill!(BitArray(Int, args...), 0)

bitones{T}(::Type{T}, args...) = fill!(BitArray(T, args...), 1)
bitones(args...) = fill!(BitArray(args...), 1)
bitones(args...) = fill!(BitArray(Int, args...), 1)

# XXX: temporary!?
bitfalses(args...) = bitzeros(Bool, args...)
Expand Down
2 changes: 1 addition & 1 deletion test/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ for m = 0 : v1
end

b1 = bitrand(T, v1)
for m = [randi(v1) 1 63 64 65 191 192 193 v1-1]
for m = [randi(v1) 0 1 63 64 65 191 192 193 v1-1]
@assert isequal(b1 << m, [ b1[m+1:end]; bitzeros(T, m) ])
@assert isequal(b1 >>> m, [ bitzeros(T, m); b1[1:end-m] ])
@assert isequal(rotl(b1, m), [ b1[m+1:end]; b1[1:m] ])
Expand Down

0 comments on commit 0310315

Please sign in to comment.