Skip to content

Commit

Permalink
Optimize conversion with no size change
Browse files Browse the repository at this point in the history
  • Loading branch information
green-nsk committed Jul 1, 2022
1 parent 3778fa9 commit 53e8df5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/unsafe_array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,16 @@ end
Base.deepcopy(A::UnsafeArray) = copyto!(similar(A), A)

function Base.reinterpret(::Type{DST}, A::UnsafeArray{SRC}) where {DST, SRC}
sz = size(A)
sz1, rem = divrem(sz[1] * sizeof(SRC), sizeof(DST))
@boundscheck if rem != zero(rem)
throw(ArgumentError("Resulting array would have non-integral first dimension"))
if sizeof(DST) != sizeof(SRC)
sz = size(A)
sz1, rem = divrem(sz[1] * sizeof(SRC), sizeof(DST))
@boundscheck if rem != zero(rem)
throw(ArgumentError("Resulting array would have non-integral first dimension"))
end
UnsafeArray(convert(Ptr{DST}, pointer(A)), (sz1, Base.tail(sz)...))
else
UnsafeArray(convert(Ptr{DST}, pointer(A)), size(A))
end
UnsafeArray(convert(Ptr{DST}, pointer(A)), (sz1, Base.tail(sz)...))
end

# # Defining Base.unaliascopy results in very bad broadcast performance for
Expand Down

0 comments on commit 53e8df5

Please sign in to comment.