Skip to content

Commit 5366d31

Browse files
authored
Revert some of 0.9.4 (#71)
* Relax to_vec(::Number) * Reverts adjoint / transpose to_vec * Bumps version
1 parent 96388c5 commit 5366d31

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FiniteDifferences"
22
uuid = "26cc04aa-876d-5657-8c51-4c34ba976000"
3-
version = "0.9.4"
3+
version = "0.9.5"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/to_vec.jl

+5-13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ transformation.
66
"""
77
function to_vec(x::Number)
88
function Number_from_vec(x_vec)
9-
return oftype(x, first(x_vec))
9+
return first(x_vec)
1010
end
1111
return [x], Number_from_vec
1212
end
@@ -61,25 +61,17 @@ function to_vec(X::Diagonal)
6161
end
6262

6363
function to_vec(X::Transpose)
64-
65-
x_vec, x_from_vec = to_vec(X.parent)
66-
6764
function Transpose_from_vec(x_vec)
68-
return Transpose(x_from_vec(x_vec))
65+
return Transpose(permutedims(reshape(x_vec, size(X))))
6966
end
70-
71-
return x_vec, Transpose_from_vec
67+
return vec(Matrix(X)), Transpose_from_vec
7268
end
7369

7470
function to_vec(X::Adjoint)
75-
76-
x_vec, x_from_vec = to_vec(X.parent)
77-
7871
function Adjoint_from_vec(x_vec)
79-
return Adjoint(x_from_vec(x_vec))
72+
return Adjoint(conj!(permutedims(reshape(x_vec, size(X)))))
8073
end
81-
82-
return x_vec, Adjoint_from_vec
74+
return vec(Matrix(X)), Adjoint_from_vec
8375
end
8476

8577
# Non-array data structures

test/to_vec.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ function test_to_vec(x::T) where {T}
2525
x_vec, back = to_vec(x)
2626
@test x_vec isa Vector
2727
@test x == back(x_vec)
28-
@test back(x_vec) isa T
2928
return nothing
3029
end
3130

@@ -56,6 +55,9 @@ end
5655
test_to_vec(Op(randn(T, 4, 4)))
5756
test_to_vec(Op(randn(T, 6)))
5857
test_to_vec(Op(randn(T, 2, 5)))
58+
59+
A = randn(T, 3, 3)
60+
@test reshape(first(to_vec(Op(A))), 3, 3) == Op(A)
5961
end
6062

6163
@testset "Tuples" begin

0 commit comments

Comments
 (0)