From 00e3a9faeb894d0e06b7daf0800dbb75f0d25165 Mon Sep 17 00:00:00 2001 From: Sacha Verweij Date: Tue, 28 Nov 2017 20:12:29 -0800 Subject: [PATCH] replace RowVector(shape...) constructors/calls with RowVector(uninitialized, shape...) (#24786) * Replace primitive RowVector{T}(shape...) constructors with RowVector{T}(uninitialized, shape...) etc. * Replace RowVector{...}(shape...)-like calls everywhere (base,test,stdlib,doc). * Deprecate RowVector{T}(shape...) constructors to RowVector{T}(uninitialized, shape...) equivalents. --- NEWS.md | 7 +++++++ base/deprecated.jl | 6 ++++++ base/linalg/rowvector.jl | 18 ++++++++++-------- test/linalg/rowvector.jl | 8 ++++---- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/NEWS.md b/NEWS.md index a9d2533299cf2..63bb3e15f67c9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -435,6 +435,13 @@ Deprecated or removed * `whos` has been renamed `varinfo`, and now returns a markdown table instead of printing output ([#12131]). + * Uninitialized `RowVector` constructors of the form `RowVector{T}(shape...)` have been + deprecated in favor of equivalents accepting `uninitialized` (an alias for + `Uninitialized()`) as their first argument, as in + `RowVector{T}(uninitialized, shape...)`. For example, `RowVector{Int}(3)` is now + `RowVector{Int}(uninitialized, 3)`, and `RowVector{Float32}((1, 4))` is now + `RowVector{Float32}(uninitialized, (1, 4))` ([#24786]). + * `writecsv(io, a; opts...)` has been deprecated in favor of `writedlm(io, a, ','; opts...)` ([#23529]). diff --git a/base/deprecated.jl b/base/deprecated.jl index f037e84656c4e..75ad99721e6f8 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -2114,6 +2114,12 @@ end @deprecate chol!(x::Number, uplo) chol(x) false end +# deprecate RowVector{T}(shape...) constructors to RowVector{T}(uninitialized, shape...) equivalents +@deprecate RowVector{T}(n::Int) where {T} RowVector{T}(uninitialized, n) +@deprecate RowVector{T}(n1::Int, n2::Int) where {T} RowVector{T}(uninitialized, n1, n2) +@deprecate RowVector{T}(n::Tuple{Int}) where {T} RowVector{T}(uninitialized, n) +@deprecate RowVector{T}(n::Tuple{Int,Int}) where {T} RowVector{T}(uninitialized, n) + @deprecate cumsum(A::AbstractArray) cumsum(A, 1) @deprecate cumsum_kbn(A::AbstractArray) cumsum_kbn(A, 1) @deprecate cumprod(A::AbstractArray) cumprod(A, 1) diff --git a/base/linalg/rowvector.jl b/base/linalg/rowvector.jl index 3af699f7fbedb..3d37026c05c01 100644 --- a/base/linalg/rowvector.jl +++ b/base/linalg/rowvector.jl @@ -35,14 +35,16 @@ const ConjRowVector{T,CV<:ConjVector} = RowVector{T,CV} @inline RowVector{T}(vec::AbstractVector{T}) where {T} = RowVector{T,typeof(vec)}(vec) # Constructors that take a size and default to Array -@inline RowVector{T}(n::Int) where {T} = RowVector{T}(Vector{transpose_type(T)}(uninitialized, n)) -@inline RowVector{T}(n1::Int, n2::Int) where {T} = n1 == 1 ? - RowVector{T}(Vector{transpose_type(T)}(uninitialized, n2)) : - error("RowVector expects 1×N size, got ($n1,$n2)") -@inline RowVector{T}(n::Tuple{Int}) where {T} = RowVector{T}(Vector{transpose_type(T)}(uninitialized, n[1])) -@inline RowVector{T}(n::Tuple{Int,Int}) where {T} = n[1] == 1 ? - RowVector{T}(Vector{transpose_type(T)}(uninitialized, n[2])) : - error("RowVector expects 1×N size, got $n") +@inline RowVector{T}(::Uninitialized, n::Int) where {T} = + RowVector{T}(Vector{transpose_type(T)}(uninitialized, n)) +@inline RowVector{T}(::Uninitialized, n1::Int, n2::Int) where {T} = + n1 == 1 ? RowVector{T}(Vector{transpose_type(T)}(uninitialized, n2)) : + error("RowVector expects 1×N size, got ($n1,$n2)") +@inline RowVector{T}(::Uninitialized, n::Tuple{Int}) where {T} = + RowVector{T}(Vector{transpose_type(T)}(uninitialized, n[1])) +@inline RowVector{T}(::Uninitialized, n::Tuple{Int,Int}) where {T} = + n[1] == 1 ? RowVector{T}(Vector{transpose_type(T)}(uninitialized, n[2])) : + error("RowVector expects 1×N size, got $n") # Conversion of underlying storage convert(::Type{RowVector{T,V}}, rowvec::RowVector) where {T,V<:AbstractVector} = diff --git a/test/linalg/rowvector.jl b/test/linalg/rowvector.jl index bf265090d214b..28d474c27edbc 100644 --- a/test/linalg/rowvector.jl +++ b/test/linalg/rowvector.jl @@ -6,10 +6,10 @@ @test RowVector(v) == [1 2 3] @test RowVector{Int}(v) == [1 2 3] - @test size(RowVector{Int}(3)) === (1,3) - @test size(RowVector{Int}(1,3)) === (1,3) - @test size(RowVector{Int}((3,))) === (1,3) - @test size(RowVector{Int}((1,3))) === (1,3) + @test size(RowVector{Int}(uninitialized, 3)) === (1,3) + @test size(RowVector{Int}(uninitialized, 1,3)) === (1,3) + @test size(RowVector{Int}(uninitialized, (3,))) === (1,3) + @test size(RowVector{Int}(uninitialized, (1,3))) === (1,3) @test_throws ErrorException RowVector{Float64, Vector{Int}}(v) @test (v.')::RowVector == [1 2 3]