Repository: JuliaDiff/FiniteDifferences.jl
Pull request #83 (2020-05-03 19:44:24)

Create CompatHelper.yml


Patch:
diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml
new file mode 100644
index 0000000..ce8d353
--- /dev/null
+++ b/.github/workflows/CompatHelper.yml
@@ -0,0 +1,16 @@
+name: CompatHelper
+
+on:
+  schedule:
+    - cron: '00 00 * * *'
+
+jobs:
+  CompatHelper:
+    runs-on: ubuntu-latest
+    steps:
+      - name: Pkg.add("CompatHelper")
+        run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
+      - name: CompatHelper.main()
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        run: julia -e 'using CompatHelper; CompatHelper.main()'
diff --git a/Project.toml b/Project.toml
index eeb5ea8..e937326 100644
--- a/Project.toml
+++ b/Project.toml
@@ -1,6 +1,6 @@
 name = "FiniteDifferences"
 uuid = "26cc04aa-876d-5657-8c51-4c34ba976000"
-version = "0.10.0"
+version = "0.10.2"
 
 [deps]
 LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
diff --git a/src/to_vec.jl b/src/to_vec.jl
index b42feb3..120e49c 100644
--- a/src/to_vec.jl
+++ b/src/to_vec.jl
@@ -53,32 +53,36 @@ function to_vec(x::T) where {T<:LinearAlgebra.AbstractTriangular}
     return x_vec, AbstractTriangular_from_vec
 end
 
-function to_vec(x::Symmetric)
-    function Symmetric_from_vec(x_vec)
-        return Symmetric(reshape(x_vec, size(x)))
+function to_vec(x::T) where {T<:LinearAlgebra.HermOrSym}
+    x_vec, back = to_vec(Matrix(x))
+    function HermOrSym_from_vec(x_vec)
+        return T(back(x_vec), x.uplo)
     end
-    return vec(Matrix(x)), Symmetric_from_vec
+    return x_vec, HermOrSym_from_vec
 end
 
 function to_vec(X::Diagonal)
+    x_vec, back = to_vec(Matrix(X))
     function Diagonal_from_vec(x_vec)
-        return Diagonal(reshape(x_vec, size(X)...))
+        return Diagonal(back(x_vec))
     end
-    return vec(Matrix(X)), Diagonal_from_vec
+    return x_vec, Diagonal_from_vec
 end
 
 function to_vec(X::Transpose)
+    x_vec, back = to_vec(Matrix(X))
     function Transpose_from_vec(x_vec)
-        return Transpose(permutedims(reshape(x_vec, size(X))))
+        return Transpose(permutedims(back(x_vec)))
     end
-    return vec(Matrix(X)), Transpose_from_vec
+    return x_vec, Transpose_from_vec
 end
 
 function to_vec(X::Adjoint)
+    x_vec, back = to_vec(Matrix(X))
     function Adjoint_from_vec(x_vec)
-        return Adjoint(conj!(permutedims(reshape(x_vec, size(X)))))
+        return Adjoint(conj!(permutedims(back(x_vec))))
     end
-    return vec(Matrix(X)), Adjoint_from_vec
+    return x_vec, Adjoint_from_vec
 end
 
 # Non-array data structures


Test patch:
diff --git a/test/to_vec.jl b/test/to_vec.jl
index 8e3406c..b19076c 100644
--- a/test/to_vec.jl
+++ b/test/to_vec.jl
@@ -24,6 +24,7 @@ Base.getindex(x::FillVector, n::Int) = x.x
 function test_to_vec(x::T) where {T}
     x_vec, back = to_vec(x)
     @test x_vec isa Vector
+    @test all(s -> s isa Real, x_vec)
     @test x == back(x_vec)
     return nothing
 end
@@ -45,19 +46,25 @@ end
         test_to_vec([randn(T, 5, 4, 3), (5, 4, 3), 2.0])
         test_to_vec(reshape([1.0, randn(T, 5, 4, 3), randn(T, 4, 3), 2.0], 2, 2))
         test_to_vec(UpperTriangular(randn(T, 13, 13)))
-        test_to_vec(Symmetric(randn(T, 11, 11)))
         test_to_vec(Diagonal(randn(T, 7)))
         test_to_vec(DummyType(randn(T, 2, 9)))
         test_to_vec(SVector{2, T}(1.0, 2.0))
         test_to_vec(SMatrix{2, 2, T}(1.0, 2.0, 3.0, 4.0))
 
+        @testset "$Op" for Op in (Symmetric, Hermitian)
+            test_to_vec(Op(randn(T, 11, 11)))
+            @testset "$uplo" for uplo in (:L, :U)
+                A = Op(randn(T, 11, 11), uplo)
+                test_to_vec(A)
+                x_vec, back = to_vec(A)
+                @test back(x_vec).uplo == A.uplo
+            end
+        end
+
         @testset "$Op" for Op in (Adjoint, Transpose)
             test_to_vec(Op(randn(T, 4, 4)))
             test_to_vec(Op(randn(T, 6)))
             test_to_vec(Op(randn(T, 2, 5)))
-
-            A = randn(T, 3, 3)
-            @test reshape(first(to_vec(Op(A))), 3, 3) == Op(A)
         end
 
         @testset "Tuples" begin