Skip to content

Commit 1590e9f

Browse files
committed
make an array for subarray similarto
1 parent cc7e77b commit 1590e9f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/code.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ function toexpr(a::MakeArray, st)
375375
end
376376

377377
## Array
378-
@inline function _create_array(::Type{<:Array}, T, ::Val{dims}, elems...) where dims
378+
@inline function _create_array(::Union{Type{<:Array},Type{<:SubArray}}, T, ::Val{dims}, elems...) where dims
379379
arr = Array{T}(undef, dims)
380380
@assert prod(dims) == nfields(elems)
381381
@inbounds for i=1:prod(dims)
@@ -384,11 +384,11 @@ end
384384
arr
385385
end
386386

387-
@inline function create_array(A::Type{<:Array}, T, d::Val, elems...)
387+
@inline function create_array(A::Union{Type{<:Array},Type{<:SubArray}}, T, d::Val, elems...)
388388
_create_array(A, T, d, elems...)
389389
end
390390

391-
@inline function create_array(A::Type{<:Array}, ::Nothing, d::Val{dims}, elems...) where dims
391+
@inline function create_array(A::Union{Type{<:Array},Type{<:SubArray}}, ::Nothing, d::Val{dims}, elems...) where dims
392392
T = promote_type(map(typeof, elems)...)
393393
_create_array(A, T, d, elems...)
394394
end

test/code.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ test_repr(a, b) = @test repr(Base.remove_linenums!(a)) == repr(Base.remove_linen
8989
@test eval(toexpr(Let([a 1, b 2, arr [1,2]],
9090
MakeArray([a,b,a+b,a/b], arr)))) == [1, 2, 3, 1/2]
9191

92+
@test eval(toexpr(Let([a 1, b 2, arr [1,2]],
93+
MakeArray(view([a,b,a+b,a/b], :), arr)))) == [1, 2, 3, 1/2]
94+
9295
@test eval(toexpr(Let([a 1, b 2, arr [1,2]],
9396
MakeArray([a b;a+b a/b], arr)))) == [1 2; 3 1/2]
9497

0 commit comments

Comments
 (0)