Skip to content

Commit

Permalink
More special operations for Diagonal{<:Any,<:AbstractFill} (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty authored Feb 19, 2021
1 parent b51bb8a commit 0606a8c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "FillArrays"
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
version = "0.11.4"
version = "0.11.5"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
8 changes: 6 additions & 2 deletions src/FillArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,14 @@ const Eye{T,Axes} = RectOrDiagonal{T,Ones{T,1,Tuple{Axes}}}

isone(::SquareEye) = true

for f in (:permutedims, :inv, :triu, :triu!, :tril, :tril!)
@eval ($f)(IM::SquareEye) = IM
# These should actually be in StdLib, LinearAlgebra.jl, for all Diagonal
for f in (:permutedims, :triu, :triu!, :tril, :tril!)
@eval ($f)(IM::Diagonal{<:Any,<:AbstractFill}) = IM
end

inv(IM::SquareEye) = IM
inv(IM::Diagonal{<:Any,<:AbstractFill}) = Diagonal(map(inv, IM.diag))

Eye(n::Integer, m::Integer) = RectDiagonal(Ones(min(n,m)), n, m)
Eye{T}(n::Integer, m::Integer) where T = RectDiagonal{T}(Ones{T}(min(n,m)), n, m)
function Eye{T}((a,b)::NTuple{2,AbstractUnitRange{Int}}) where T
Expand Down
5 changes: 4 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -926,11 +926,14 @@ end

@testset "Eye identity ops" begin
m = Eye(10)
D = Diagonal(Fill(2,10))
for op in (permutedims, inv)
@test op(m) === m
end
@test permutedims(D) D
@test inv(D) Diagonal(Fill(1/2,10))

for m in (Eye(10), Eye(10, 10), Eye(10, 8), Eye(8, 10))
for m in (Eye(10), Eye(10, 10), Eye(10, 8), Eye(8, 10), D)
for op in (tril, triu, tril!, triu!)
@test op(m) === m
end
Expand Down

2 comments on commit 0606a8c

@dlfivefifty
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/30426

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.11.5 -m "<description of version>" 0606a8c91695c42e951f35af5b291e5548b6f1a6
git push origin v0.11.5

Please sign in to comment.