Skip to content

Commit

Permalink
Uninitialized, uninitialized and Array constructors supporting uninit…
Browse files Browse the repository at this point in the history
…ialized (#417)
  • Loading branch information
fredrikekre authored Nov 27, 2017
1 parent 3cd0bc6 commit c72b467
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* Constructors for `Matrix{T}`, `Array{T}`, and `SparseMatrixCSC{T}` from `UniformScaling` ([#24372], [#24657])

* `Uninitialized` and `uninitialized` with corresponding `Array` constructors ([#24652]).

## Renaming


Expand Down Expand Up @@ -361,4 +363,5 @@ includes this fix. Find the minimum version from there.
[#24282]: https://github.com/JuliaLang/julia/issues/24282
[#24372]: https://github.com/JuliaLang/julia/issues/24372
[#24459]: https://github.com/JuliaLang/julia/issues/24459
[#24652]: https://github.com/JuliaLang/julia/issues/24652
[#24657]: https://github.com/JuliaLang/julia/issues/24657
23 changes: 23 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,29 @@ if VERSION < v"0.7.0-DEV.2543"
(::Type{Array{T}}){T}(s::UniformScaling, m::Integer, n::Integer) = Matrix{T}(s, m, n)
end

# 0.7.0-DEV.2581
@static if !isdefined(Base, :Uninitialized)
if VERSION >= v"0.6.0"
include_string(@__MODULE__, """
struct Uninitialized end
Array{T}(::Uninitialized, args...) where {T} = Array{T}(args...)
Array{T,N}(::Uninitialized, args...) where {T,N} = Array{T,N}(args...)
Vector(::Uninitialized, args...) = Vector(args...)
Matrix(::Uninitialized, args...) = Matrix(args...)
""")
else
include_string(@__MODULE__, """
immutable Uninitialized end
(::Type{Array{T}}){T}(::Uninitialized, args...) = Array{T}(args...)
(::Type{Array{T,N}}){T,N}(::Uninitialized, args...) = Array{T,N}(args...)
(::Type{Vector})(::Uninitialized, args...) = Vector(args...)
(::Type{Matrix})(::Uninitialized, args...) = Matrix(args...)
""")
end
const uninitialized = Uninitialized()
export Uninitialized, uninitialized
end

include("deprecated.jl")

end # module Compat
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,15 @@ let a = [1 0 0; 0 1 0; 0 0 1]
@test SparseMatrixCSC{Complex128,Int8}(I, 3, 2)::SparseMatrixCSC{Complex128,Int8} == a[:,1:2]
end


# 0.7.0-DEV.2581
@test isa(Vector(uninitialized, 2), Vector{Any})
@test isa(Vector{Float64}(uninitialized, 2), Vector{Float64})
@test isa(Matrix(uninitialized, 2, 2), Matrix{Any})
@test isa(Matrix{Float64}(uninitialized, 2, 2), Matrix{Float64})
@test isa(Array{Float64}(uninitialized, 2, 2), Matrix{Float64})
@test isa(Array{Float64,3}(uninitialized, 2, 2, 2), Array{Float64,3})

if VERSION < v"0.6.0"
include("deprecated.jl")
end
Expand Down

0 comments on commit c72b467

Please sign in to comment.