Skip to content

Commit dd0d26b

Browse files
author
Miha Zgubic
committed
add the test for an array with a custom constructor
1 parent 4d30c43 commit dd0d26b

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

test/to_vec.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ end
4444
Base.size(a::WrapperArray) = size(a.data)
4545
Base.getindex(a::WrapperArray, inds...) = getindex(a.data, inds...)
4646

47+
# can not construct it from: cca = CustomConstructorArray(rand(2, 2))
48+
# T = typeof(cca) # CustomConstructorArray{Float64, 2, Matrix{Float64}}
49+
# T(rand(2, 3)) # errors
50+
struct CustomConstructorArray{T, N, A<:AbstractArray{T, N}} <: AbstractArray{T, N}
51+
data::A
52+
function CustomConstructorArray(data::A) where {T, N, A<:AbstractArray{T, N}}
53+
return new{T, N, A}(data)
54+
end
55+
end
56+
Base.size(a::CustomConstructorArray) = size(a.data)
57+
Base.getindex(a::CustomConstructorArray, inds...) = getindex(a.data, inds...)
58+
4759
function test_to_vec(x::T; check_inferred=true) where {T}
4860
check_inferred && @inferred to_vec(x)
4961
x_vec, back = to_vec(x)
@@ -195,4 +207,9 @@ end
195207
wa = WrapperArray(rand(4, 5))
196208
test_to_vec(wa; check_inferred=false)
197209
end
210+
211+
@testset "CustomConstructorArray" begin
212+
cca = CustomConstructorArray(rand(2, 3))
213+
test_to_vec(cca; check_inferred=false)
214+
end
198215
end

0 commit comments

Comments
 (0)