-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initialize Arrays with great dignity #24652
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,7 +123,7 @@ export | |
SimpleVector, AbstractArray, DenseArray, NamedTuple, | ||
# special objects | ||
Function, CodeInfo, Method, MethodTable, TypeMapEntry, TypeMapLevel, | ||
Module, Symbol, Task, Array, WeakRef, VecElement, | ||
Module, Symbol, Task, Array, Uninitialized, uninitialized, WeakRef, VecElement, | ||
# numeric types | ||
Number, Real, Integer, Bool, Ref, Ptr, | ||
AbstractFloat, Float16, Float32, Float64, | ||
|
@@ -350,25 +350,45 @@ unsafe_convert(::Type{T}, x::T) where {T} = x | |
const NTuple{N,T} = Tuple{Vararg{T,N}} | ||
|
||
|
||
# primitive array constructors | ||
Array{T,N}(d::NTuple{N,Int}) where {T,N} = | ||
ccall(:jl_new_array, Array{T,N}, (Any, Any), Array{T,N}, d) | ||
Array{T,1}(d::NTuple{1,Int}) where {T} = Array{T,1}(getfield(d,1)) | ||
Array{T,2}(d::NTuple{2,Int}) where {T} = Array{T,2}(getfield(d,1), getfield(d,2)) | ||
Array{T,3}(d::NTuple{3,Int}) where {T} = Array{T,3}(getfield(d,1), getfield(d,2), getfield(d,3)) | ||
Array{T,N}(d::Vararg{Int,N}) where {T,N} = ccall(:jl_new_array, Array{T,N}, (Any, Any), Array{T,N}, d) | ||
Array{T,1}(m::Int) where {T} = ccall(:jl_alloc_array_1d, Array{T,1}, (Any, Int), Array{T,1}, m) | ||
Array{T,2}(m::Int, n::Int) where {T} = | ||
## primitive Array constructors | ||
struct Uninitialized end | ||
const uninitialized = Uninitialized() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could perhaps use a docstring -- I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call! I will add docstrings shortly :). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docstrings live. Thanks! :) |
||
# type and dimensionality specified, accepting dims as series of Ints | ||
Array{T,1}(::Uninitialized, m::Int) where {T} = | ||
ccall(:jl_alloc_array_1d, Array{T,1}, (Any, Int), Array{T,1}, m) | ||
Array{T,2}(::Uninitialized, m::Int, n::Int) where {T} = | ||
ccall(:jl_alloc_array_2d, Array{T,2}, (Any, Int, Int), Array{T,2}, m, n) | ||
Array{T,3}(m::Int, n::Int, o::Int) where {T} = | ||
Array{T,3}(::Uninitialized, m::Int, n::Int, o::Int) where {T} = | ||
ccall(:jl_alloc_array_3d, Array{T,3}, (Any, Int, Int, Int), Array{T,3}, m, n, o) | ||
Array{T,N}(::Uninitialized, d::Vararg{Int,N}) where {T,N} = | ||
ccall(:jl_new_array, Array{T,N}, (Any, Any), Array{T,N}, d) | ||
# type and dimensionality specified, accepting dims as tuples of Ints | ||
Array{T,1}(::Uninitialized, d::NTuple{1,Int}) where {T} = Array{T,1}(uninitialized, getfield(d,1)) | ||
Array{T,2}(::Uninitialized, d::NTuple{2,Int}) where {T} = Array{T,2}(uninitialized, getfield(d,1), getfield(d,2)) | ||
Array{T,3}(::Uninitialized, d::NTuple{3,Int}) where {T} = Array{T,3}(uninitialized, getfield(d,1), getfield(d,2), getfield(d,3)) | ||
Array{T,N}(::Uninitialized, d::NTuple{N,Int}) where {T,N} = ccall(:jl_new_array, Array{T,N}, (Any, Any), Array{T,N}, d) | ||
# type but not dimensionality specified | ||
Array{T}(::Uninitialized, m::Int) where {T} = Array{T,1}(uninitialized, m) | ||
Array{T}(::Uninitialized, m::Int, n::Int) where {T} = Array{T,2}(uninitialized, m, n) | ||
Array{T}(::Uninitialized, m::Int, n::Int, o::Int) where {T} = Array{T,3}(uninitialized, m, n, o) | ||
Array{T}(::Uninitialized, d::NTuple{N,Int}) where {T,N} = Array{T,N}(uninitialized, d) | ||
# empty vector constructor | ||
Array{T,1}() where {T} = Array{T,1}(uninitialized, 0) | ||
|
||
## preexisting Array constructors, i.e. without uninitialized, to deprecate | ||
# type and dimensionality specified, accepting dims as series of Ints | ||
Array{T,1}(m::Int) where {T} = Array{T,1}(uninitialized, m) | ||
Array{T,2}(m::Int, n::Int) where {T} = Array{T,2}(uninitialized, m, n) | ||
Array{T,3}(m::Int, n::Int, o::Int) where {T} = Array{T,3}(uninitialized, m, n, o) | ||
Array{T,N}(d::Vararg{Int,N}) where {T,N} = Array{T,N}(uninitialized, d) | ||
# type and dimensionality specified, accepting dims as tuples of Ints | ||
Array{T,N}(d::NTuple{N,Int}) where {T,N} = Array{T,N}(uninitialized, d) | ||
# type but not dimensionality specified | ||
Array{T}(m::Int) where {T} = Array{T}(uninitialized, m) | ||
Array{T}(m::Int, n::Int) where {T} = Array{T}(uninitialized, m, n) | ||
Array{T}(m::Int, n::Int, o::Int) where {T} = Array{T}(uninitialized, m, n, o) | ||
Array{T}(d::NTuple{N,Int}) where {T,N} = Array{T}(uninitialized, d) | ||
|
||
Array{T}(d::NTuple{N,Int}) where {T,N} = Array{T,N}(d) | ||
Array{T}(m::Int) where {T} = Array{T,1}(m) | ||
Array{T}(m::Int, n::Int) where {T} = Array{T,2}(m, n) | ||
Array{T}(m::Int, n::Int, o::Int) where {T} = Array{T,3}(m, n, o) | ||
|
||
Array{T,1}() where {T} = Array{T,1}(0) | ||
|
||
# primitive Symbol constructors | ||
function Symbol(s::String) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should
Uninitialized
be exported? It does not seem necessary for the usageThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uninitialized
must be exported, lest Julia not build :).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uninitialized
/uninitialized
must be visible everywhere uninitialized arrays are or will be constructed; these exports makeUninitialized
/uninitialized
visible beyondCore
. The build failure absent these exports comes from the definitions usingUninitialized
/uninitialized
insysimg.jl
. Does that clarify? :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though wouldn't it be possible to export only
uninitialized
from Base (not Core)? ShouldUninitialized
be used outside of Base?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uninitialized
should see use outside Base, yes, in definitions of constructors for uninitialized arrays generally (see #24595). Additionallyuninitialized
is merely an alias forUninitialized()
, and henceuninitialized
cannot do its magic withoutUninitialized
visible. Does that clarify? :)