Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented method create_array for Base.ReshapedArrays. #679

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/code.jl
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,10 @@ end
create_array(P, S, nd, d, elems...)
end

@inline function create_array(::Type{<:Base.ReshapedArray{T, N, P}}, S, nd::Val, d, elems...) where {T, N, P}
create_array(P, S, nd, d, elems...)
end

## SArray
@inline function create_array(::Type{<:SArray}, ::Nothing, nd::Val, ::Val{dims}, elems...) where dims
SArray{Tuple{dims...}}(elems...)
Expand Down
6 changes: 6 additions & 0 deletions test/code.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ nanmath_st.rewrites[:nanmath] = true
@test eval(toexpr(Let([a ← 1, b ← 2, arr ← [1,2]],
MakeArray([a b;a+b a/b], arr)))) == [1 2; 3 1/2]

@test eval(toexpr(Let([a ← 1, b ← 2, arr ← [1,2]],
MakeArray(reshape(view([a,b,a+b,a/b], :), 1, 4), arr)))) == [1 2 3 1/2]

@test eval(toexpr(Let([a ← 1, b ← 2, arr ← @SVector([1,2])],
MakeArray([a,b,a+b,a/b], arr)))) === @SVector [1, 2, 3, 1/2]

Expand All @@ -159,6 +162,9 @@ nanmath_st.rewrites[:nanmath] = true
@test eval(toexpr(Let([a ← 1, b ← 2, arr ← @SLVector((:a, :b))(@SVector[1,2])],
MakeArray([a+b,a/b], arr)))) === @SLVector((:a, :b))(@SVector [3, 1/2])

@test eval(toexpr(Let([a ← 1, b ← 2, arr ← reshape(view([1,2], :), 1, 2)],
MakeArray([a,b,a+b,a/b], arr)))) == [1, 2, 3, 1/2]

trackedarr = eval(toexpr(Let([a ← ReverseDiff.track(1.0), b ← 2, arr ← ReverseDiff.track(ones(2))],
MakeArray([a+b,a/b], arr))))
@test trackedarr isa ReverseDiff.TrackedArray
Expand Down
Loading