Skip to content

Commit dea9350

Browse files
committed
Remove setindex! for BitArray
1 parent f1432c3 commit dea9350

File tree

2 files changed

+1
-107
lines changed

2 files changed

+1
-107
lines changed

base/bitarray.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,7 @@ end
365365
end
366366
end
367367

368-
setindex!(B::BitArray, x) = setindex!(B, convert(Bool,x), 1)
369-
368+
setindex!(B::BitArray, x, i::Int) = setindex!(B, convert(Bool,x), i)
370369
function setindex!(B::BitArray, x::Bool, i::Int)
371370
1 <= i <= length(B) || throw(BoundsError(B, i))
372371
unsafe_bitsetindex!(B.chunks, x, i)

base/multidimensional.jl

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -681,42 +681,6 @@ end
681681

682682
## setindex!
683683

684-
# general scalar indexing with two or more indices
685-
# (uses linear indexing, which - in the safe version - performs the final
686-
# bounds check and is defined in bitarray.jl)
687-
# (code is duplicated for safe and unsafe versions for performance reasons)
688-
689-
stagedfunction unsafe_setindex!(B::BitArray, x::Bool, I_0::Int, I::Int...)
690-
N = length(I)
691-
quote
692-
stride = 1
693-
index = I_0
694-
@nexprs $N d->begin
695-
stride *= size(B,d)
696-
index += (I[d] - 1) * stride
697-
end
698-
unsafe_setindex!(B, x, index)
699-
return B
700-
end
701-
end
702-
703-
stagedfunction setindex!(B::BitArray, x::Bool, I_0::Int, I::Int...)
704-
N = length(I)
705-
quote
706-
stride = 1
707-
index = I_0
708-
@nexprs $N d->(I_d = I[d])
709-
@nexprs $N d->begin
710-
l = size(B,d)
711-
stride *= l
712-
1 <= I_{d-1} <= l || throw(BoundsError())
713-
index += (I_d - 1) * stride
714-
end
715-
B[index] = x
716-
return B
717-
end
718-
end
719-
720684
# contiguous multidimensional indexing: if the first dimension is a range,
721685
# we can get some performance from using copy_chunks!
722686

@@ -796,75 +760,6 @@ stagedfunction unsafe_setindex!(B::BitArray, x::Bool, I0::UnitRange{Int}, I::Uni
796760
end
797761
end
798762

799-
800-
# general multidimensional non-scalar indexing
801-
802-
stagedfunction unsafe_setindex!(B::BitArray, X::AbstractArray, I::Union(Int,AbstractArray{Int},Colon)...)
803-
N = length(I)
804-
quote
805-
refind = 1
806-
@nexprs $N d->(I_d = I[d])
807-
idxlens = @ncall $N index_lengths B I
808-
@nloops $N i d->(1:idxlens[d]) d->(J_d = I_d[i_d]) @inbounds begin
809-
@ncall $N unsafe_setindex! B convert(Bool,X[refind]) J
810-
refind += 1
811-
end
812-
return B
813-
end
814-
end
815-
816-
stagedfunction unsafe_setindex!(B::BitArray, x::Bool, I::Union(Int,AbstractArray{Int},Colon)...)
817-
N = length(I)
818-
quote
819-
@nexprs $N d->(I_d = I[d])
820-
idxlens = @ncall $N index_lengths B I
821-
@nloops $N i d->(1:idxlens[d]) d->(J_d = I_d[i_d]) begin
822-
@ncall $N unsafe_setindex! B x J
823-
end
824-
return B
825-
end
826-
end
827-
828-
# general versions with Real (or logical) indexing which dispatch on the appropriate method
829-
830-
# this one is for disambiguation only
831-
function setindex!(B::BitArray, x, i::Real)
832-
checkbounds(B, i)
833-
return unsafe_setindex!(B, convert(Bool,x), to_index(i))
834-
end
835-
836-
stagedfunction setindex!(B::BitArray, x, I::Union(Real,AbstractArray,Colon)...)
837-
N = length(I)
838-
quote
839-
checkbounds(B, I...)
840-
#return unsafe_setindex!(B, convert(Bool,x), to_index(I...)...) # segfaults! (???)
841-
@nexprs $N d->(J_d = to_index(I[d]))
842-
return @ncall $N unsafe_setindex! B convert(Bool,x) J
843-
end
844-
end
845-
846-
847-
# this one is for disambiguation only
848-
function setindex!(B::BitArray, X::AbstractArray, i::Real)
849-
checkbounds(B, i)
850-
j = to_index(i)
851-
setindex_shape_check(X, index_lengths(A, j)[1])
852-
return unsafe_setindex!(B, X, j)
853-
end
854-
855-
stagedfunction setindex!(B::BitArray, X::AbstractArray, I::Union(Real,AbstractArray,Colon)...)
856-
N = length(I)
857-
quote
858-
checkbounds(B, I...)
859-
@nexprs $N d->(J_d = to_index(I[d]))
860-
idxlens = @ncall $N index_lengths B J
861-
setindex_shape_check(X, idxlens...)
862-
return @ncall $N unsafe_setindex! B X J
863-
end
864-
end
865-
866-
867-
868763
## findn
869764

870765
stagedfunction findn{N}(B::BitArray{N})

0 commit comments

Comments
 (0)