|
1 | | -using DifferentiationInterface: recursive_similar, get_pattern |
| 1 | +using DifferentiationInterface: recursive_similar, get_pattern, arroftup_to_tupofarr |
2 | 2 | using SparseArrays |
3 | 3 | using Test |
| 4 | +using JLArrays, ComponentArrays |
4 | 5 |
|
5 | 6 | @testset "Recursive similar" begin |
6 | 7 | @test recursive_similar(ones(Int, 2), Float32) isa Vector{Float32} |
|
16 | 17 | @test_broken get_pattern(D) == Diagonal(trues(10)) |
17 | 18 | @test get_pattern(sparse(D)) == Diagonal(trues(10)) |
18 | 19 | end |
| 20 | + |
| 21 | +@testset "Wrong-mode array conversion" begin |
| 22 | + x = [1.0, 3.0, 5.0] |
| 23 | + xt = [(1.0, 2.0), (3.0, 4.0), (5.0, 6.0)] |
| 24 | + y = ComponentVector(a = [1.0, 3.0], b = [5.0]) |
| 25 | + yt = ComponentVector(a = [(1.0, 2.0), (3.0, 4.0)], b = [(5.0, 6.0)]) |
| 26 | + z = jl([1.0, 3.0, 5.0]) |
| 27 | + zt = jl([(1.0, 2.0), (3.0, 4.0), (5.0, 6.0)]) |
| 28 | + @test arroftup_to_tupofarr((1.0, 2.0), 1.0) == (1.0, 2.0) |
| 29 | + @test arroftup_to_tupofarr(xt, x) == ([1.0, 3.0, 5.0], [2.0, 4.0, 6.0]) |
| 30 | + @test arroftup_to_tupofarr(yt, y) == (ComponentVector(a = [1.0, 3.0], b = [5.0]), ComponentVector(a = [2.0, 4.0], b = [6.0])) |
| 31 | + @test arroftup_to_tupofarr(zt, z) == (jl([1.0, 3.0, 5.0]), jl([2.0, 4.0, 6.0])) |
| 32 | + @test arroftup_to_tupofarr(xt, x)[1] isa Vector |
| 33 | + @test arroftup_to_tupofarr(yt, y)[1] isa ComponentVector |
| 34 | + @test arroftup_to_tupofarr(zt, z)[1] isa JLVector |
| 35 | +end |
0 commit comments