Skip to content

Commit 420a6b2

Browse files
committed
Remove redundant code, improve documentation
1 parent 4cb49e1 commit 420a6b2

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/varnamedtuple.jl

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,12 +528,20 @@ function BangBang.delete!!(pa::PartialArray, inds::Vararg{INDEX_TYPES})
528528
else
529529
pa.mask[inds...] = false
530530
end
531-
return _concretise_eltype!!(pa)
531+
return pa
532532
end
533533

534534
_ensure_range(r::UnitRange) = r
535535
_ensure_range(i::Integer) = i:i
536536

537+
"""
538+
_remove_partial_blocks!!(pa::PartialArray, inds::Vararg{INDEX_TYPES})
539+
540+
Remove any ArrayLikeBlocks that overlap with the given indices from the PartialArray.
541+
542+
Note that this removes the whole block, even the parts that are within `inds`, to avoid
543+
partially indexing into ArrayLikeBlocks.
544+
"""
537545
function _remove_partial_blocks!!(pa::PartialArray, inds::Vararg{INDEX_TYPES})
538546
et = eltype(pa)
539547
if !(et <: ArrayLikeBlock || ArrayLikeBlock <: et)
@@ -552,6 +560,13 @@ function _remove_partial_blocks!!(pa::PartialArray, inds::Vararg{INDEX_TYPES})
552560
return pa
553561
end
554562

563+
"""
564+
_needs_arraylikeblock(value, inds::Vararg{INDEX_TYPES})
565+
566+
Check if the given value needs to be wrapped in an `ArrayLikeBlock` when being set at inds.
567+
568+
The value only depends on the types of the arguments, and should be constant propagated.
569+
"""
555570
function _needs_arraylikeblock(value, inds::Vararg{INDEX_TYPES})
556571
return _is_multiindex(inds) &&
557572
!isa(value, AbstractArray) &&
@@ -569,9 +584,6 @@ function _setindex!!(pa::PartialArray, value, inds::Vararg{INDEX_TYPES})
569584

570585
new_data = pa.data
571586
if _needs_arraylikeblock(value, inds...)
572-
if !hasmethod(size, Tuple{typeof(value)})
573-
throw(ArgumentError("Cannot assign a scalar value to a range."))
574-
end
575587
inds_size = reduce((x, y) -> tuple(x..., y...), map(size, inds))
576588
if size(value) != inds_size
577589
throw(
@@ -584,7 +596,7 @@ function _setindex!!(pa::PartialArray, value, inds::Vararg{INDEX_TYPES})
584596
# At this point we know we have a value that is not an AbstractArray, but it has
585597
# some notion of size, and that size matches the indices that are being set. In this
586598
# case we wrap the value in an ArrayLikeBlock, and set all the individual indices
587-
# point to that.
599+
# to point to that.
588600
alb = ArrayLikeBlock(value, inds)
589601
new_data = setindex!!(new_data, fill(alb, inds_size...), inds...)
590602
else

0 commit comments

Comments
 (0)