Skip to content

Commit c25cb56

Browse files
committed
Add convert() methods for Matrix from Vector and RowVector
1 parent a72aad4 commit c25cb56

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

base/array.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ oneunit(x::AbstractMatrix{T}) where {T} = _one(oneunit(T), x)
320320

321321
convert(::Type{Vector}, x::AbstractVector{T}) where {T} = convert(Vector{T}, x)
322322
convert(::Type{Matrix}, x::AbstractMatrix{T}) where {T} = convert(Matrix{T}, x)
323+
convert(::Type{Matrix}, x::Vector) = Matrix(reshape(x, :, 1))
323324

324325
convert(::Type{Array{T}}, x::Array{T,n}) where {T,n} = x
325326
convert(::Type{Array{T,n}}, x::Array{T,n}) where {T,n} = x

base/linalg/rowvector.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ const ConjRowVector{T,CV<:ConjVector} = RowVector{T,CV}
4444
RowVector{T}(Vector{transpose_type(T)}(n[2])) :
4545
error("RowVector expects 1×N size, got $n")
4646

47+
# Convenience constructor to Matrix
48+
convert(::Type{Matrix}, x::RowVector) = Matrix(reshape(x, 1, :))
49+
4750
# Conversion of underlying storage
4851
convert(::Type{RowVector{T,V}}, rowvec::RowVector) where {T,V<:AbstractVector} =
4952
RowVector{T,V}(convert(V,rowvec.vec))

0 commit comments

Comments
 (0)