Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace BitArray(shape...) constructors/calls with BitArray(uninitialized, shape...) #24785

Merged
merged 7 commits into from
Nov 29, 2017
5 changes: 4 additions & 1 deletion test/TestHelpers.jl
Original file line number Diff line number Diff line change
@@ -181,7 +181,10 @@ function Base.similar(A::AbstractArray, T::Type, inds::Tuple{UnitRange,Vararg{Un
OffsetArray(B, map(indsoffset, inds))
end

Base.similar(f::Union{Function,Type}, shape::Tuple{UnitRange,Vararg{UnitRange}}) = OffsetArray(f(map(length, shape)), map(indsoffset, shape))
Base.similar(f::Union{Function,Type}, shape::Tuple{UnitRange,Vararg{UnitRange}}) =
OffsetArray(f(map(length, shape)), map(indsoffset, shape))
Base.similar(::Type{T}, shape::Tuple{UnitRange,Vararg{UnitRange}}) where {T<:BitArray} =
OffsetArray(T(uninitialized, map(length, shape)), map(indsoffset, shape))

Base.reshape(A::AbstractArray, inds::Tuple{UnitRange,Vararg{UnitRange}}) = OffsetArray(reshape(A, map(length, inds)), map(indsoffset, inds))

30 changes: 15 additions & 15 deletions test/bitarray.jl
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ let t0 = time()
end

@testset "empty bitvector" begin
@test BitVector() == BitVector(0)
@test BitVector() == BitVector(uninitialized, 0)
end

# vectors size
@@ -156,17 +156,17 @@ timesofar("conversions")
end

@testset "sizeof (issue #7515)" begin
@test sizeof(BitArray(64)) == 8
@test sizeof(BitArray(65)) == 16
@test sizeof(BitVector(uninitialized, 64)) == 8
@test sizeof(BitVector(uninitialized, 65)) == 16
end
end

timesofar("utils")

@testset "Constructors" begin
@testset "non-Int dims constructors" begin
b1 = BitArray(Int32(v1))
b2 = BitArray(Int64(v1))
b1 = BitVector(uninitialized, Int32(v1))
b2 = BitVector(uninitialized, Int64(v1))
@test size(b1) == size(b2)

for c in [trues, falses]
@@ -187,14 +187,14 @@ timesofar("utils")
end

@testset "one" begin
@test Array(one(BitMatrix(2,2))) == Matrix(I, 2, 2)
@test_throws DimensionMismatch one(BitMatrix(2,3))
@test Array(one(BitMatrix(uninitialized, 2,2))) == Matrix(I, 2, 2)
@test_throws DimensionMismatch one(BitMatrix(uninitialized, 2,3))
end

# constructors should copy
a = trues(3)
@test BitArray(a) !== a
@test BitArray{1}(a) !== a
@test BitVector(a) !== a

# issue #24062
@test_throws InexactError BitArray([0, 1, 2, 3])
@@ -511,7 +511,7 @@ end
timesofar("indexing")

@testset "Deque Functionality" begin
b1 = BitArray(0)
b1 = BitVector()
i1 = Bool[]
for m = 1:v1
x = rand(Bool)
@@ -553,7 +553,7 @@ timesofar("indexing")

@test length(b1) == 0

b1 = BitArray(0)
b1 = BitVector()
i1 = Bool[]
for m = 1:v1
x = rand(Bool)
@@ -574,7 +574,7 @@ timesofar("indexing")
end
@test length(b1) == 0

b1 = BitArray(0)
b1 = BitVector()
@test_throws BoundsError insert!(b1, 2, false)
@test_throws BoundsError insert!(b1, 0, false)
i1 = Array(b1)
@@ -1182,7 +1182,7 @@ timesofar("nnz&find")
@test findlast(b1) == Base.findlastnot(b2) == 777
@test findfirst(b1) == Base.findfirstnot(b2) == 77

b0 = BitVector(0)
b0 = BitVector()
@test findprev(x->true, b0, -1) == 0
@test_throws BoundsError findprev(x->true, b0, 1)
@test_throws BoundsError findnext(x->true, b0, -1)
@@ -1267,7 +1267,7 @@ timesofar("reductions")
@test map(!=, b1, b2) == map((x,y)->x!=y, b1, b2) == (b1 .!= b2)

@testset "map! for length $l" begin
b = BitArray(l)
b = BitVector(uninitialized, l)
@test map!(~, b, b1) == map!(x->~x, b, b1) == broadcast(~, b1) == b
@test map!(!, b, b1) == map!(x->!x, b, b1) == broadcast(~, b1) == b
@test map!(identity, b, b1) == map!(x->x, b, b1) == b1 == b
@@ -1468,11 +1468,11 @@ end
@test_throws DimensionMismatch read!(fname, b2)
@test bitcheck(b2)

b1 = BitArray(0)
b1 = BitVector()
open(fname, "w") do f
write(f, b1)
end
b2 = BitArray(0)
b2 = BitVector()
read!(fname, b2)
@test b1 == b2
@test bitcheck(b2)
6 changes: 3 additions & 3 deletions test/distributed_exec.jl
Original file line number Diff line number Diff line change
@@ -628,9 +628,9 @@ end
testmap_equivalence(identity, (1,2,3,4))
testmap_equivalence(x->x>0 ? 1.0 : 0.0, sparse(1.0I, 5, 5))
testmap_equivalence((x,y,z)->x+y+z, 1,2,3)
testmap_equivalence(x->x ? false : true, BitArray(10,10))
testmap_equivalence(x->"foobar", BitArray(10,10))
testmap_equivalence((x,y,z)->string(x,y,z), BitArray(10), ones(10), "1234567890")
testmap_equivalence(x->x ? false : true, BitMatrix(uninitialized, 10,10))
testmap_equivalence(x->"foobar", BitMatrix(uninitialized, 10,10))
testmap_equivalence((x,y,z)->string(x,y,z), BitVector(uninitialized, 10), ones(10), "1234567890")

@test asyncmap(uppercase, "Hello World!") == map(uppercase, "Hello World!")
@test pmap(uppercase, "Hello World!") == map(uppercase, "Hello World!")
4 changes: 2 additions & 2 deletions test/random.jl
Original file line number Diff line number Diff line change
@@ -409,8 +409,8 @@ for rng in ([], [MersenneTwister(0)], [RandomDevice()])
bitrand(rng..., 5) ::BitArray{1}
bitrand(rng..., 2, 3) ::BitArray{2}
bitrand(rng..., b2, u3) ::BitArray{2}
rand!(rng..., BitArray(5)) ::BitArray{1}
rand!(rng..., BitArray(2, 3)) ::BitArray{2}
rand!(rng..., BitVector(uninitialized, 5)) ::BitArray{1}
rand!(rng..., BitMatrix(uninitialized, 2, 3)) ::BitArray{2}

# Test that you cannot call randn or randexp with non-Float types.
for r in [randn, randexp, randn!, randexp!]
2 changes: 1 addition & 1 deletion test/show.jl
Original file line number Diff line number Diff line change
@@ -118,7 +118,7 @@ end
# line meta
dims::NTuple{N,Int}
# line meta
function BitArray(dims::Int...)
function BitArray(uninitialized, dims::Int...)
# line meta
if length(dims) != N
# line meta