Skip to content

Commit 00e3a9f

Browse files
authored
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.
1 parent f48283e commit 00e3a9f

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,13 @@ Deprecated or removed
435435
* `whos` has been renamed `varinfo`, and now returns a markdown table instead of printing
436436
output ([#12131]).
437437

438+
* Uninitialized `RowVector` constructors of the form `RowVector{T}(shape...)` have been
439+
deprecated in favor of equivalents accepting `uninitialized` (an alias for
440+
`Uninitialized()`) as their first argument, as in
441+
`RowVector{T}(uninitialized, shape...)`. For example, `RowVector{Int}(3)` is now
442+
`RowVector{Int}(uninitialized, 3)`, and `RowVector{Float32}((1, 4))` is now
443+
`RowVector{Float32}(uninitialized, (1, 4))` ([#24786]).
444+
438445
* `writecsv(io, a; opts...)` has been deprecated in favor of
439446
`writedlm(io, a, ','; opts...)` ([#23529]).
440447

base/deprecated.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,6 +2114,12 @@ end
21142114
@deprecate chol!(x::Number, uplo) chol(x) false
21152115
end
21162116

2117+
# deprecate RowVector{T}(shape...) constructors to RowVector{T}(uninitialized, shape...) equivalents
2118+
@deprecate RowVector{T}(n::Int) where {T} RowVector{T}(uninitialized, n)
2119+
@deprecate RowVector{T}(n1::Int, n2::Int) where {T} RowVector{T}(uninitialized, n1, n2)
2120+
@deprecate RowVector{T}(n::Tuple{Int}) where {T} RowVector{T}(uninitialized, n)
2121+
@deprecate RowVector{T}(n::Tuple{Int,Int}) where {T} RowVector{T}(uninitialized, n)
2122+
21172123
@deprecate cumsum(A::AbstractArray) cumsum(A, 1)
21182124
@deprecate cumsum_kbn(A::AbstractArray) cumsum_kbn(A, 1)
21192125
@deprecate cumprod(A::AbstractArray) cumprod(A, 1)

base/linalg/rowvector.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,16 @@ const ConjRowVector{T,CV<:ConjVector} = RowVector{T,CV}
3535
@inline RowVector{T}(vec::AbstractVector{T}) where {T} = RowVector{T,typeof(vec)}(vec)
3636

3737
# Constructors that take a size and default to Array
38-
@inline RowVector{T}(n::Int) where {T} = RowVector{T}(Vector{transpose_type(T)}(uninitialized, n))
39-
@inline RowVector{T}(n1::Int, n2::Int) where {T} = n1 == 1 ?
40-
RowVector{T}(Vector{transpose_type(T)}(uninitialized, n2)) :
41-
error("RowVector expects 1×N size, got ($n1,$n2)")
42-
@inline RowVector{T}(n::Tuple{Int}) where {T} = RowVector{T}(Vector{transpose_type(T)}(uninitialized, n[1]))
43-
@inline RowVector{T}(n::Tuple{Int,Int}) where {T} = n[1] == 1 ?
44-
RowVector{T}(Vector{transpose_type(T)}(uninitialized, n[2])) :
45-
error("RowVector expects 1×N size, got $n")
38+
@inline RowVector{T}(::Uninitialized, n::Int) where {T} =
39+
RowVector{T}(Vector{transpose_type(T)}(uninitialized, n))
40+
@inline RowVector{T}(::Uninitialized, n1::Int, n2::Int) where {T} =
41+
n1 == 1 ? RowVector{T}(Vector{transpose_type(T)}(uninitialized, n2)) :
42+
error("RowVector expects 1×N size, got ($n1,$n2)")
43+
@inline RowVector{T}(::Uninitialized, n::Tuple{Int}) where {T} =
44+
RowVector{T}(Vector{transpose_type(T)}(uninitialized, n[1]))
45+
@inline RowVector{T}(::Uninitialized, n::Tuple{Int,Int}) where {T} =
46+
n[1] == 1 ? RowVector{T}(Vector{transpose_type(T)}(uninitialized, n[2])) :
47+
error("RowVector expects 1×N size, got $n")
4648

4749
# Conversion of underlying storage
4850
convert(::Type{RowVector{T,V}}, rowvec::RowVector) where {T,V<:AbstractVector} =

test/linalg/rowvector.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
@test RowVector(v) == [1 2 3]
88
@test RowVector{Int}(v) == [1 2 3]
9-
@test size(RowVector{Int}(3)) === (1,3)
10-
@test size(RowVector{Int}(1,3)) === (1,3)
11-
@test size(RowVector{Int}((3,))) === (1,3)
12-
@test size(RowVector{Int}((1,3))) === (1,3)
9+
@test size(RowVector{Int}(uninitialized, 3)) === (1,3)
10+
@test size(RowVector{Int}(uninitialized, 1,3)) === (1,3)
11+
@test size(RowVector{Int}(uninitialized, (3,))) === (1,3)
12+
@test size(RowVector{Int}(uninitialized, (1,3))) === (1,3)
1313
@test_throws ErrorException RowVector{Float64, Vector{Int}}(v)
1414

1515
@test (v.')::RowVector == [1 2 3]

0 commit comments

Comments
 (0)