Skip to content

Commit 8beb68b

Browse files
Merge pull request #174 from CarloLucibello/master
fix restructure
2 parents 768548b + 649019e commit 8beb68b

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/ArrayInterface.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ a matching `ArrayPartition`.
393393
function restructure(x, y)
394394
out = similar(x, eltype(y))
395395
vec(out) .= vec(y)
396+
out
396397
end
397398

398399
function restructure(x::Array, y)

test/arrayinterface.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@testset "restructure" begin
2+
x = rand(Float32, 2, 2)
3+
y = rand(4)
4+
yr = ArrayInterface.restructure(x, y)
5+
@test yr isa Matrix{Float64}
6+
@test size(yr) == (2,2)
7+
@test vec(yr) == vec(y)
8+
9+
@testset "views" begin
10+
x = @view rand(4)[1:2]
11+
y = rand(2)
12+
yr = ArrayInterface.restructure(x, y)
13+
@test yr isa Vector{Float64}
14+
@test size(yr) == (2,)
15+
@test yr == y
16+
17+
x = @view rand(4,4)[1:2,1:2]
18+
y = rand(2,2)
19+
yr = ArrayInterface.restructure(x, y)
20+
@test yr isa Matrix{Float64}
21+
@test size(yr) == (2,2)
22+
@test yr == y
23+
24+
25+
x = @view rand(4,4)[1]
26+
y = @view rand(2,2)[1]
27+
yr = ArrayInterface.restructure(x, y)
28+
@test yr isa Array{Float64,0}
29+
@test size(yr) == ()
30+
@test yr == y
31+
end
32+
end

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,9 @@ end
900900
@test @inferred(ArrayInterface.axes(Array{Float64}(undef, 4, 3)')) === (Base.OneTo(3),Base.OneTo(4))
901901
end
902902

903+
@testset "arrayinterface" begin
904+
include("arrayinterface.jl")
905+
end
903906
include("indexing.jl")
904907
include("dimensions.jl")
905908

0 commit comments

Comments
 (0)