We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 96388c5 commit 5366d31Copy full SHA for 5366d31
Project.toml
@@ -1,6 +1,6 @@
1
name = "FiniteDifferences"
2
uuid = "26cc04aa-876d-5657-8c51-4c34ba976000"
3
-version = "0.9.4"
+version = "0.9.5"
4
5
[deps]
6
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
src/to_vec.jl
@@ -6,7 +6,7 @@ transformation.
"""
7
function to_vec(x::Number)
8
function Number_from_vec(x_vec)
9
- return oftype(x, first(x_vec))
+ return first(x_vec)
10
end
11
return [x], Number_from_vec
12
@@ -61,25 +61,17 @@ function to_vec(X::Diagonal)
61
62
63
function to_vec(X::Transpose)
64
-
65
- x_vec, x_from_vec = to_vec(X.parent)
66
67
function Transpose_from_vec(x_vec)
68
- return Transpose(x_from_vec(x_vec))
+ return Transpose(permutedims(reshape(x_vec, size(X))))
69
70
71
- return x_vec, Transpose_from_vec
+ return vec(Matrix(X)), Transpose_from_vec
72
73
74
function to_vec(X::Adjoint)
75
76
77
78
function Adjoint_from_vec(x_vec)
79
- return Adjoint(x_from_vec(x_vec))
+ return Adjoint(conj!(permutedims(reshape(x_vec, size(X)))))
80
81
82
- return x_vec, Adjoint_from_vec
+ return vec(Matrix(X)), Adjoint_from_vec
83
84
85
# Non-array data structures
test/to_vec.jl
@@ -25,7 +25,6 @@ function test_to_vec(x::T) where {T}
25
x_vec, back = to_vec(x)
26
@test x_vec isa Vector
27
@test x == back(x_vec)
28
- @test back(x_vec) isa T
29
return nothing
30
31
@@ -56,6 +55,9 @@ end
56
55
test_to_vec(Op(randn(T, 4, 4)))
57
test_to_vec(Op(randn(T, 6)))
58
test_to_vec(Op(randn(T, 2, 5)))
+
59
+ A = randn(T, 3, 3)
60
+ @test reshape(first(to_vec(Op(A))), 3, 3) == Op(A)
@testset "Tuples" begin
0 commit comments