Skip to content

Commit

Permalink
Merge pull request #34 from MSeeker1340/undef-copy
Browse files Browse the repository at this point in the history
Allow copying uninitialized LArrays
  • Loading branch information
ChrisRackauckas authored Nov 16, 2018
2 parents d1b23c1 + a0849cd commit 3e272be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/larray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ function Base.similar(x::LArray{T,K,Syms},::Type{S},dims::NTuple{N,Int}) where {
LArray{S,N,Syms}(tmp)
end

# Allow copying LArray of uninitialized data, as with regular Array
Base.copy(x::LArray) = typeof(x)(copy(getfield(x,:__x)))
Base.deepcopy(x::LArray) = typeof(x)(deepcopy(getfield(x,:__x)))

# enable the usage of LAPACK
Base.unsafe_convert(::Type{Ptr{T}}, a::LArray{T,N,S}) where {T,N,S} = Base.unsafe_convert(Ptr{T}, getfield(a,:__x))

Expand Down
5 changes: 5 additions & 0 deletions test/larrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ z .= w
@test z[:b] == w[2,1]
@test z[:c] == w[1,2]
@test z[:d] == w[2,2]

t = similar(z, String) # t's elements are uninitialized
@test_throws UndefRefError t[1]
copy(t) # should be ok
deepcopy(t) # should also be ok

0 comments on commit 3e272be

Please sign in to comment.