@@ -13,7 +13,7 @@ mutable struct BitArray{N} <: DenseArray{Bool, N}
1313 chunks:: Vector{UInt64}
1414 len:: Int
1515 dims:: NTuple{N,Int}
16- function BitArray {N} (dims:: Vararg{Int,N} ) where N
16+ function BitArray {N} (:: Uninitialized , dims:: Vararg{Int,N} ) where N
1717 n = 1
1818 i = 1
1919 for d in dims
3434# the first one is recognized by the help system; it would be nice
3535# to fix this.
3636"""
37- BitArray(dims::Integer...)
38- BitArray{N}(dims::NTuple{N,Int})
37+ BitArray(uninitialized, dims::Integer...)
38+ BitArray{N}(uninitialized, dims::NTuple{N,Int})
3939
4040Construct an uninitialized [`BitArray`](@ref) with the given dimensions.
41- Behaves identically to the [`Array`](@ref) constructor.
41+ Behaves identically to the [`Array`](@ref) constructor. See [`uninitialized`](@ref).
4242
4343# Examples
4444```julia-repl
45- julia> BitArray(2, 2)
45+ julia> BitArray(uninitialized, 2, 2)
46462×2 BitArray{2}:
4747 false false
4848 false true
4949
50- julia> BitArray((3, 1))
50+ julia> BitArray(uninitialized, (3, 1))
51513×1 BitArray{2}:
5252 false
5353 true
5454 false
5555```
5656"""
57- BitArray (dims:: Integer... ) = BitArray (map (Int,dims))
58- BitArray (dims:: NTuple{N,Int} ) where {N} = BitArray {N} (dims... )
57+ BitArray (:: Uninitialized , dims:: Integer... ) = BitArray (uninitialized, map (Int,dims))
58+ BitArray {N} (:: Uninitialized , dims:: Integer... ) where {N} = BitArray {N} (uninitialized, map (Int,dims))
59+ BitArray (:: Uninitialized , dims:: NTuple{N,Int} ) where {N} = BitArray {N} (uninitialized, dims... )
60+ BitArray {N} (:: Uninitialized , dims:: NTuple{N,Int} ) where {N} = BitArray {N} (uninitialized, dims... )
5961
6062const BitVector = BitArray{1 }
6163const BitMatrix = BitArray{2 }
6264
63- BitVector () = BitArray {1} (0 )
65+ BitVector () = BitArray {1} (uninitialized, 0 )
6466
6567# # utility functions ##
6668
@@ -341,15 +343,17 @@ done(B::BitArray, i::Int) = i >= length(B)
341343
342344# # similar, fill!, copy! etc ##
343345
344- similar (B:: BitArray ) = BitArray (size (B))
345- similar (B:: BitArray , dims:: Int... ) = BitArray (dims)
346- similar (B:: BitArray , dims:: Dims ) = BitArray (dims... )
346+ similar (B:: BitArray ) = BitArray (uninitialized, size (B))
347+ similar (B:: BitArray , dims:: Int... ) = BitArray (uninitialized, dims)
348+ similar (B:: BitArray , dims:: Dims ) = BitArray (uninitialized, dims... )
347349
348- similar (B:: BitArray , T:: Type{Bool} , dims:: Dims ) = BitArray (dims)
350+ similar (B:: BitArray , T:: Type{Bool} , dims:: Dims ) = BitArray (uninitialized, dims)
349351# changing type to a non-Bool returns an Array
350352# (this triggers conversions like float(bitvector) etc.)
351353similar (B:: BitArray , T:: Type , dims:: Dims ) = Array {T} (uninitialized, dims)
352354
355+ similar (:: Type{T} , shape:: Tuple ) where {T<: BitArray } = T (uninitialized, to_shape (shape))
356+
353357function fill! (B:: BitArray , x)
354358 y = convert (Bool, x)
355359 isempty (B) && return B
@@ -376,7 +380,7 @@ julia> falses(2,3)
376380 false false false
377381```
378382"""
379- falses (dims:: Dims ) = fill! (BitArray (dims), false )
383+ falses (dims:: Dims ) = fill! (BitArray (uninitialized, dims), false )
380384falses (dims:: Integer... ) = falses (map (Int,dims))
381385"""
382386 falses(A)
@@ -411,7 +415,7 @@ julia> trues(2,3)
411415 true true true
412416```
413417"""
414- trues (dims:: Dims ) = fill! (BitArray (dims), true )
418+ trues (dims:: Dims ) = fill! (BitArray (uninitialized, dims), true )
415419trues (dims:: Integer... ) = trues (map (Int,dims))
416420"""
417421 trues(A)
@@ -490,7 +494,7 @@ reshape(B::BitArray, dims::Tuple{Vararg{Int}}) = _bitreshape(B, dims)
490494function _bitreshape (B:: BitArray , dims:: NTuple{N,Int} ) where N
491495 prod (dims) == length (B) ||
492496 throw (DimensionMismatch (" new dimensions $(dims) must be consistent with array size $(length (B)) " ))
493- Br = BitArray {N} (ntuple (i-> 0 ,Val (N))... )
497+ Br = BitArray {N} (uninitialized, ntuple (i-> 0 ,Val (N))... )
494498 Br. chunks = B. chunks
495499 Br. len = prod (dims)
496500 N != 1 && (Br. dims = dims)
512516
513517convert (:: Type{BitArray} , A:: AbstractArray{T,N} ) where {T,N} = convert (BitArray{N}, A)
514518function convert (:: Type{BitArray{N}} , A:: AbstractArray{T,N} ) where N where T
515- B = BitArray (size (A))
519+ B = BitArray (uninitialized, size (A))
516520 Bc = B. chunks
517521 l = length (B)
518522 l == 0 && return B
@@ -537,7 +541,7 @@ function convert(::Type{BitArray{N}}, A::AbstractArray{T,N}) where N where T
537541end
538542
539543function convert (:: Type{BitArray{N}} , A:: Array{Bool,N} ) where N
540- B = BitArray (size (A))
544+ B = BitArray (uninitialized, size (A))
541545 Bc = B. chunks
542546 l = length (B)
543547 l == 0 && return B
@@ -595,7 +599,7 @@ gen_bitarray(isz::IteratorSize, itr) = gen_bitarray_from_itr(itr, start(itr))
595599
596600# generic iterable with known shape
597601function gen_bitarray (:: HasShape , itr)
598- B = BitArray (size (itr))
602+ B = BitArray (uninitialized, size (itr))
599603 for (I,x) in zip (CartesianRange (indices (itr)), itr)
600604 B[I] = x
601605 end
@@ -604,13 +608,12 @@ end
604608
605609# generator with known shape or length
606610function gen_bitarray (:: HasShape , itr:: Generator )
607- B = BitArray (size (itr))
611+ B = BitArray (uninitialized, size (itr))
608612 return fill_bitarray_from_itr! (B, itr, start (itr))
609613end
610614function gen_bitarray (:: HasLength , itr)
611- n = length (itr)
612- B = BitArray (n)
613- return fill_bitarray_from_itr! (B, itr, start (itr))
615+ b = BitVector (uninitialized, length (itr))
616+ return fill_bitarray_from_itr! (b, itr, start (itr))
614617end
615618
616619gen_bitarray (:: IsInfinite , itr) = throw (ArgumentError (" infinite-size iterable used in BitArray constructor" ))
@@ -619,7 +622,7 @@ gen_bitarray(::IsInfinite, itr) = throw(ArgumentError("infinite-size iterable u
619622# use a Vector{Bool} cache for performance reasons
620623
621624function gen_bitarray_from_itr (itr, st)
622- B = empty! (BitArray ( bitcache_size))
625+ B = empty! (BitVector (uninitialized, bitcache_size))
623626 C = Vector {Bool} (uninitialized, bitcache_size)
624627 Bc = B. chunks
625628 ind = 1
@@ -1050,7 +1053,7 @@ function splice!(B::BitVector, i::Integer)
10501053 return v
10511054end
10521055
1053- const _default_bit_splice = BitVector (0 )
1056+ const _default_bit_splice = BitVector ()
10541057
10551058function splice! (B:: BitVector , r:: Union{UnitRange{Int}, Integer} , ins:: AbstractArray = _default_bit_splice)
10561059 n = length (B)
@@ -1064,7 +1067,7 @@ function splice!(B::BitVector, r::Union{UnitRange{Int}, Integer}, ins::AbstractA
10641067
10651068 if (i_f > n)
10661069 append! (B, Bins)
1067- return BitVector (0 )
1070+ return BitVector ()
10681071 end
10691072
10701073 v = B[r] # TODO : change to a copy if/when subscripting becomes an ArrayView
@@ -1094,7 +1097,7 @@ function splice!(B::BitVector, r::Union{UnitRange{Int}, Integer}, ins::AbstractA
10941097end
10951098
10961099function splice! (B:: BitVector , r:: Union{UnitRange{Int}, Integer} , ins)
1097- Bins = BitArray ( length (ins))
1100+ Bins = BitVector (uninitialized, length (ins))
10981101 i = 1
10991102 for x in ins
11001103 Bins[i] = Bool (x)
@@ -1221,7 +1224,7 @@ broadcast(::typeof(xor), x::Bool, B::BitArray) = broadcast(xor, B, x)
12211224for f in (:& , :| , :xor )
12221225 @eval begin
12231226 function broadcast (:: typeof ($ f), A:: BitArray , B:: BitArray )
1224- F = BitArray (promote_shape (size (A),size (B))... )
1227+ F = BitArray (uninitialized, promote_shape (size (A),size (B))... )
12251228 Fc = F. chunks
12261229 Ac = A. chunks
12271230 Bc = B. chunks
@@ -1803,7 +1806,7 @@ function hcat(B::BitVector...)
18031806 length (B[j]) == height ||
18041807 throw (DimensionMismatch (" dimensions must match" ))
18051808 end
1806- M = BitArray ( height, length (B))
1809+ M = BitMatrix (uninitialized, height, length (B))
18071810 for j = 1 : length (B)
18081811 copy_chunks! (M. chunks, (height* (j- 1 ))+ 1 , B[j]. chunks, 1 , height)
18091812 end
@@ -1815,7 +1818,7 @@ function vcat(V::BitVector...)
18151818 for Vk in V
18161819 n += length (Vk)
18171820 end
1818- B = BitArray ( n)
1821+ B = BitVector (uninitialized, n)
18191822 j = 1
18201823 for Vk in V
18211824 copy_chunks! (B. chunks, j, Vk. chunks, 1 , length (Vk))
@@ -1837,7 +1840,7 @@ function hcat(A::Union{BitMatrix,BitVector}...)
18371840 throw (DimensionMismatch (" row lengths must match" ))
18381841 end
18391842
1840- B = BitArray ( nrows, ncols)
1843+ B = BitMatrix (uninitialized, nrows, ncols)
18411844
18421845 pos = 1
18431846 for k = 1 : nargs
@@ -1857,7 +1860,7 @@ function vcat(A::BitMatrix...)
18571860 size (A[j], 2 ) == ncols ||
18581861 throw (DimensionMismatch (" column lengths must match" ))
18591862 end
1860- B = BitArray ( nrows, ncols)
1863+ B = BitMatrix (uninitialized, nrows, ncols)
18611864 Bc = B. chunks
18621865 nrowsA = [size (a, 1 ) for a in A]
18631866 Ac = [a. chunks for a in A]
0 commit comments