Skip to content

Commit bbcfa7d

Browse files
committed
Preserve wrapper in AbstractMatrix constructor for Adjoint/Transpose
1 parent 9b9ab75 commit bbcfa7d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/adjtrans.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ wrapperop(::Transpose) = transpose
332332
_wrapperop(x) = wrapperop(x)
333333
_wrapperop(::Adjoint{<:Real}) = transpose
334334

335+
# equivalent to wrapperop, but returns the type of the wrapper
336+
wrappertype(::Adjoint) = Adjoint
337+
wrappertype(::Transpose) = Transpose
338+
335339
# the following fallbacks can be removed if Adjoint/Transpose are restricted to AbstractVecOrMat
336340
size(A::AdjOrTrans) = reverse(size(A.parent))
337341
axes(A::AdjOrTrans) = reverse(axes(A.parent))
@@ -391,7 +395,7 @@ similar(A::AdjOrTrans, ::Type{T}) where {T} = similar(A.parent, T, axes(A))
391395
similar(A::AdjOrTrans, ::Type{T}, dims::Dims{N}) where {T,N} = similar(A.parent, T, dims)
392396

393397
# AbstractMatrix{T} constructor for adjtrans vector: preserve wrapped type
394-
AbstractMatrix{T}(A::AdjOrTransAbsVec) where {T} = wrapperop(A)(AbstractVector{T}(A.parent))
398+
AbstractMatrix{T}(A::AdjOrTransAbsVec) where {T} = wrappertype(A)(AbstractVector{T}(A.parent))
395399

396400
# sundry basic definitions
397401
parent(A::AdjOrTrans) = A.parent

0 commit comments

Comments
 (0)