Skip to content

Commit

Permalink
Merge pull request #237 from JuliaDiff/ox/triangle
Browse files Browse the repository at this point in the history
Support Tridiagonal in to_vec
  • Loading branch information
oxinabox authored May 31, 2024
2 parents 119bcd7 + b501fda commit 148c564
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "FiniteDifferences"
uuid = "26cc04aa-876d-5657-8c51-4c34ba976000"
version = "0.12.31"
version = "0.12.32"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
16 changes: 14 additions & 2 deletions src/to_vec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,26 @@ function to_vec(x::T) where {T<:LinearAlgebra.HermOrSym}
return x_vec, HermOrSym_from_vec
end

function to_vec(X::Diagonal)
x_vec, back = to_vec(Matrix(X))
function to_vec(x::Diagonal)
x_vec, back = to_vec(Matrix(x))
function Diagonal_from_vec(x_vec)
return Diagonal(back(x_vec))
end
return x_vec, Diagonal_from_vec
end

function to_vec(x::Tridiagonal)
x_vec, back = to_vec((x.dl, x.d, x.du))
# Other field (du2) of a Tridiagonal is not part of its value and is really a kind of cache
function Tridiagonal_from_vec(x_vec)
return Tridiagonal(back(x_vec)...)
end
return x_vec, Tridiagonal_from_vec
end




function to_vec(X::Transpose)
x_vec, back = to_vec(Matrix(X))
function Transpose_from_vec(x_vec)
Expand Down
2 changes: 2 additions & 0 deletions test/to_vec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ end
test_to_vec(reshape([1.0, randn(T, 5, 4, 3), randn(T, 4, 3), 2.0], 2, 2); check_inferred=false)
test_to_vec(UpperTriangular(randn(T, 13, 13)))
test_to_vec(Diagonal(randn(T, 7)))
test_to_vec(Tridiagonal(randn(T, 3), randn(T, 4), randn(T, 3)))

test_to_vec(DummyType(randn(T, 2, 9)))
test_to_vec(SVector{2, T}(1.0, 2.0); check_inferred=false)
test_to_vec(SMatrix{2, 2, T}(1.0, 2.0, 3.0, 4.0); check_inferred=false)
Expand Down

2 comments on commit 148c564

@oxinabox
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/108023

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.12.32 -m "<description of version>" 148c564e62b834aa80ce48da99a1ed3b64b59121
git push origin v0.12.32

Please sign in to comment.