@@ -352,7 +352,13 @@ function _concretise_eltype!!(pa::PartialArray)
352352 if isconcretetype (eltype (pa))
353353 return pa
354354 end
355- new_et = promote_type ((typeof (pa. data[i]) for i in eachindex (pa. mask) if pa. mask[i]). .. )
355+ # We could use promote_type here, instead of typejoin. However, that would e.g.
356+ # cause Ints to be converted to Float64s, since
357+ # promote_type(Int, Float64) == Float64, which can cause problems. See
358+ # https://github.com/TuringLang/DynamicPPL.jl/pull/1098#discussion_r2472636188.
359+ # Base.promote_typejoin would be like typejoin, but creates Unions out of Nothing
360+ # and Missing, rather than falling back on Any. However, it's not exported.
361+ new_et = typejoin ((typeof (pa. data[i]) for i in eachindex (pa. mask) if pa. mask[i]). .. )
356362 # TODO (mhauru) Should we check as below, or rather isconcretetype(new_et)?
357363 # In other words, does it help to be more concrete, even if we aren't fully concrete?
358364 if new_et === eltype (pa)
@@ -588,8 +594,8 @@ function _setindex!!(pa::PartialArray, value, inds::Vararg{INDEX_TYPES})
588594 if size (value) != inds_size
589595 throw (
590596 DimensionMismatch (
591- " Assigned value has size $(size (value)) , which does not match the size " *
592- " implied by the indices $(map (x -> _length_needed (x), inds)) ." ,
597+ " Assigned value has size $(size (value)) , which does not match the " *
598+ " size implied by the indices $(map (x -> _length_needed (x), inds)) ." ,
593599 ),
594600 )
595601 end
@@ -659,7 +665,14 @@ function _merge_recursive(pa1::PartialArray, pa2::PartialArray)
659665 result
660666 else
661667 # Neither is strictly bigger than the other.
662- et = promote_type (eltype (pa1), eltype (pa2))
668+ # We could use promote_type here, instead of typejoin. However, that would e.g.
669+ # cause Ints to be converted to Float64s, since
670+ # promote_type(Int, Float64) == Float64, which can cause problems. See
671+ # https://github.com/TuringLang/DynamicPPL.jl/pull/1098#discussion_r2472636188.
672+ # Base.promote_typejoin would be like typejoin, but creates Unions out of
673+ # Nothing and Missing, rather than falling back on Any. However, it's not
674+ # exported.
675+ et = typejoin (eltype (pa1), eltype (pa2))
663676 new_data = Array {et,num_dims} (undef, merge_size)
664677 new_mask = fill (false , merge_size)
665678 result = PartialArray (new_data, new_mask)
0 commit comments