-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@inline log(A::StaticMatrix) = _log(Size(A), A) | ||
|
||
@inline function _log(::Size{(0,0)}, A::StaticMatrix) | ||
T = typeof(log(one(eltype(A)))) | ||
SMT = similar_type(A,T) | ||
return SMT() | ||
end | ||
|
||
@inline function _log(::Size{(1,1)}, A::StaticMatrix) | ||
T = typeof(log(one(eltype(A)))) | ||
SMT = similar_type(A,T) | ||
return SMT((log(A[1]), )) | ||
end | ||
|
||
function _log(::Size, A::StaticMatrix) | ||
eigA = eigen(A) | ||
T = typeof(log(one(eltype(A)) * one(eltype(eigA.values)))) | ||
VT = similar_type(typeof(eigA.values),T) | ||
log_values = log.(VT(eigA.values)) | ||
log_eigA = Eigen(log_values, eigA.vectors) | ||
logA = AbstractMatrix(log_eigA) | ||
return logA | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using StaticArrays, Test, LinearAlgebra | ||
|
||
@testset "Matrix logarithm" begin | ||
@test log(SMatrix{0,0,Int}())::SMatrix == SMatrix{0,0,Bool}() | ||
@test log(@SMatrix [2])::SMatrix ≈ SMatrix{1,1}(log(2)) | ||
@test log(@SMatrix [5 2; -2 1])::SMatrix ≈ log([5 2; -2 1]) | ||
@test log(@SMatrix [4 2; -2 1])::SMatrix ≈ log([4 2; -2 1]) | ||
@test log(@SMatrix [4 2; 2 1])::SMatrix ≈ log([4 2; 2 1]) | ||
@test log(@SMatrix [ -3+1im -1+2im;-4-5im 5-2im])::SMatrix ≈ log(Complex{Float64}[ -3+1im -1+2im;-4-5im 5-2im]) | ||
# test for identity matrix | ||
@test log(SMatrix{2,2}(I))::SMatrix ≈ zeros(2,2) | ||
@test log(@SMatrix Complex{Float64}[1 2 0; 2 1 0; 0 0 1]) ≈ log([1 2 0; 2 1 0; 0 0 1]) | ||
|
||
for sz in 0:4, typ in (Float64, Complex{Float64}) | ||
A = rand(SMatrix{sz,sz,typ}) | ||
expA = exp(A) | ||
logexpA = log(expA) | ||
@test logexpA ≈ A | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters