From 6bd31171f64f0a695b5a5ccbd56f57fb9d9be133 Mon Sep 17 00:00:00 2001 From: Miha Zgubic Date: Mon, 8 Feb 2021 20:59:12 +0000 Subject: [PATCH 1/3] fix bug --- src/to_vec.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/to_vec.jl b/src/to_vec.jl index 6e3304b..a8e6f10 100644 --- a/src/to_vec.jl +++ b/src/to_vec.jl @@ -54,7 +54,7 @@ function to_vec(x::AbstractVector) end function to_vec(x::AbstractArray) - x_vec, from_vec = to_vec(vec(x)) + x_vec, from_vec = to_vec(collect(vec(x))) function Array_from_vec(x_vec) return oftype(x, reshape(from_vec(x_vec), size(x))) From 1a7d1daa7eb879b579a3a37e6b0d38f1174f0bd2 Mon Sep 17 00:00:00 2001 From: Miha Zgubic Date: Mon, 8 Feb 2021 20:59:34 +0000 Subject: [PATCH 2/3] add test --- test/to_vec.jl | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/test/to_vec.jl b/test/to_vec.jl index 18d88f2..501ac51 100644 --- a/test/to_vec.jl +++ b/test/to_vec.jl @@ -18,6 +18,9 @@ struct FillVector <: AbstractVector{Float64} len::Int end +Base.size(x::FillVector) = (x.len,) +Base.getindex(x::FillVector, n::Int) = x.x + # For testing Composite{ThreeFields} struct ThreeFields a @@ -32,8 +35,14 @@ struct Nested y::Singleton end -Base.size(x::FillVector) = (x.len,) -Base.getindex(x::FillVector, n::Int) = x.x +# for testing wrapped arrays +struct WrappedArray{T, V<:AbstractMatrix{T}} <: AbstractMatrix{T} + a::V +end + +Base.size(w::WrappedArray) = size(w.a) +Base.getindex(w::WrappedArray, i, j) = getindex(w.a, i, j) +Base.convert(::Type{WrappedArray{T, Array{T, N}}}, a::Array{T, N}) where {T, N} = WrappedArray(a) function test_to_vec(x::T; check_inferred = true) where {T} check_inferred && @inferred to_vec(x) @@ -179,4 +188,9 @@ end nested = Nested(ThreeFields(1.0, 2.0, "Three"), Singleton()) test_to_vec(nested; check_inferred=false) # map end + + @testset "WrappedArray" begin + wa = WrappedArray(rand(2, 3)) + test_to_vec(wa) + end end From e62195ed2a925309ae43088a8fafa25959d09dc8 Mon Sep 17 00:00:00 2001 From: Miha Zgubic Date: Mon, 8 Feb 2021 21:02:57 +0000 Subject: [PATCH 3/3] bump patch --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 3e5242c..fe566fb 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "FiniteDifferences" uuid = "26cc04aa-876d-5657-8c51-4c34ba976000" -version = "0.12.1" +version = "0.12.2" [deps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"