Skip to content

Commit

Permalink
Use unsafe_convert instead of pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
mbauman committed Apr 28, 2020
1 parent a9a8af7 commit 9819783
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions stdlib/LinearAlgebra/src/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ Base.strides(A::Transpose{<:Any, <:StridedVector}) = (stride(A.parent, 2), strid
Base.strides(A::Adjoint{<:Real, <:StridedMatrix}) = reverse(strides(A.parent))
Base.strides(A::Transpose{<:Any, <:StridedMatrix}) = reverse(strides(A.parent))

Base.pointer(A::Adjoint{<:Real, <:Union{StridedVector,StridedMatrix}}) = pointer(A.parent)
Base.pointer(A::Transpose{<:Any, <:Union{StridedVector,StridedMatrix}}) = pointer(A.parent)
Base.unsafe_convert(::Type{Ptr{T}}, A::Adjoint{<:Real, <:StridedVecOrMat}) where {T} = Base.unsafe_convert(Ptr{T}, A.parent)
Base.unsafe_convert(::Type{Ptr{T}}, A::Transpose{<:Any, <:StridedVecOrMat}) where {T} = Base.unsafe_convert(Ptr{T}, A.parent)

# for vectors, the semantics of the wrapped and unwrapped types differ
# so attempt to maintain both the parent and wrapper type insofar as possible
Expand Down
4 changes: 2 additions & 2 deletions stdlib/LinearAlgebra/test/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,10 @@ end
@test strides(Transpose(rand(3, 2) .+ rand(3, 2).*im)) == (3, 1)

C = rand(3) .+ rand(3).*im
@test_throws MethodError pointer(Adjoint(C))
@test_throws ErrorException pointer(Adjoint(C))
@test pointer(Transpose(C)) === pointer(C)
D = rand(3,2) .+ rand(3,2).*im
@test_throws MethodError pointer(Adjoint(D))
@test_throws ErrorException pointer(Adjoint(D))
@test pointer(Transpose(D)) === pointer(D)
end

Expand Down

0 comments on commit 9819783

Please sign in to comment.