Thanks for reformatting. Is there a way I can preview my posts for cleanliness before posting (like in GitHub) so that you don’t have to cleanup behind me ?
I understand the definition of undef
- but I am asking a different question… For instance, let’s say,
julia> c = vcat(a, b...)
2-element Array{Any,1}:
#undef
array initializer with undefined values
From a user’s perspective, there are two undefined entries… one is #undef
, and the other is UndefInitializer
. But, from that perspective, the elements are treated differently.
julia> c[1]
ERROR: UndefRefError: access to undefined reference
Stacktrace:
[1] getindex(::Array{Any,1}, ::Int64) at ./array.jl:731
[2] top-level scope at none:0
julia> c[2]
array initializer with undefined values
julia> typeof(c[1])
ERROR: UndefRefError: access to undefined reference
Stacktrace:
[1] getindex(::Array{Any,1}, ::Int64) at ./array.jl:731
[2] top-level scope at none:0
julia> typeof(c[2])
UndefInitializer
To defensively program, testing with isassigned
for every element seems more expensive than testing for undef
(it might not really be… I’m just trying to understand here)
julia> @code_llvm c[2] == undef
; Function ==
; Location: operators.jl:83
define i8 @"julia_==_35430"() {
top:
ret i8 1
}
julia> @code_llvm isassigned(c, 1)
; Function isassigned
; Location: array.jl:204
define i8 @julia_isassigned_35332(%jl_value_t addrspace(10)* nonnull align 16 dereferenceable(40), i64) {
top:
; Location: array.jl:205
; Function -; {
; Location: int.jl:803
; Function -; {
; Location: int.jl:52
%2 = add i64 %1, -1
;}}
; Location: array.jl:206
; Function length; {
; Location: array.jl:199
%3 = addrspacecast %jl_value_t addrspace(10)* %0 to %jl_value_t addrspace(11)*
%4 = bitcast %jl_value_t addrspace(11)* %3 to %jl_array_t addrspace(11)*
%5 = getelementptr inbounds %jl_array_t, %jl_array_t addrspace(11)* %4, i64 0, i32 1
%6 = load i64, i64 addrspace(11)* %5, align 8
;}
; Function <; {
; Location: int.jl:427
%7 = icmp ult i64 %2, %6
;}
br i1 %7, label %L17, label %L16
L16: ; preds = %top
ret i8 0
L17: ; preds = %top
; Location: array.jl:207
%8 = bitcast %jl_value_t addrspace(11)* %3 to %jl_value_t* addrspace(13)* addrspace(11)*
%9 = load %jl_value_t* addrspace(13)*, %jl_value_t* addrspace(13)* addrspace(11)* %8, align 8
%10 = getelementptr %jl_value_t*, %jl_value_t* addrspace(13)* %9, i64 %2
%11 = load %jl_value_t*, %jl_value_t* addrspace(13)* %10, align 8
%12 = icmp ne %jl_value_t* %11, null
; Function ==; {
; Location: promotion.jl:350
; Function ==; {
; Location: promotion.jl:425
%13 = zext i1 %12 to i8
;}}
ret i8 %13
}