Skip to content

Commit

Permalink
Merge pull request #128 from Marco-Congedo/dev
Browse files Browse the repository at this point in the history
updated function `tr1`
  • Loading branch information
Marco-Congedo committed Jan 8, 2020
2 parents 2d58a08 + 858a98d commit 1858d44
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PosDefManifold"
uuid = "f45a3650-5c51-11e9-1e9a-133aa5e309cf"
authors = ["Marco Congedo <marco.congedo@gmail.com>"]
version = "0.4.4"
version = "0.4.5"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
authors = ["Marco Congedo <marco.congedo@gmail.com>"]
version = "0.4.4"
version = "0.4.5"

[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Expand Down
2 changes: 1 addition & 1 deletion src/PosDefManifold.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Main Module of the PosDefManifold Package for julia language
# v0.4.3 last update 1st of December 2020
# v0.4.5 last update 8th of January 2020

# MIT License
# Copyright (c) 2019, Marco Congedo, CNRS, Grenobe, France:
Expand Down
37 changes: 29 additions & 8 deletions src/linearAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ dim(vector₂::AnyMatrixVector₂) =
``X`` can be a real or complex `Diagonal`, `LowerTriangular`,
`Matrix`, or `Hermitian` matrix. (see [AnyMatrix type](@ref))
If the determinant is not greater to `tol` (which defalts to zero)
If the determinant is not greater than `tol` (which defalts to zero)
a warning is printed and ``X`` is returned.
!!! note "Nota Bene"
Expand Down Expand Up @@ -303,29 +303,50 @@ det1Msg="function det1 in LinearAlgebra.jl of PosDefMaifold package: the determi
``X`` can be a real or complex `Diagonal`, `LowerTriangular`,
`Matrix` or `Hermitian` matrix (see [AnyMatrix type](@ref)).
If the trace is not greater to `tol`
(which defalts to zero) a warning is printed and ``X`` is returned.
Its trace must be real. If the absolute value of its imaginary part
is greater than `tol` (which defalts to zero) a warning is printed
and ``X`` is returned.
Also, if the trace is not greater than `tol`
a warning is printed and ``X`` is returned.
**See**: [Julia trace function](https://bit.ly/2HoOLiM).
**See also**: [`tr`](@ref), [`det1`](@ref).
## Examples
using LinearAlgebra, PosDefManifold
P=randP(5) # generate a random real positive definite matrix 5x5
Q=tr1(P)
tr(Q) # must be 1
# using a tolerance
Q=tr1(P; tol=1e-12)
Pc=randP(ComplexF64, 5) # generate a random real positive definite matrix 5x5
Qc=tr1(Pc)
tr(Qc) # must be 1
"""
function tr1(X::AnyMatrix; tol::Real=0.)
tol>=0. ? tolerance=tol : tolerance = 0.
trace = tr(X)
if trace>tolerance X/trace else @warn tr1Msg trace tolerance; X end
imagtr = imag(trace)
if abs(imagtr)>tolerance
@warn tr1Msg2 imagtr tolerance
return X
else
trace=real(trace)
end
if trace>tolerance
return X/trace
else
@warn tr1Msg1 trace tolerance
return X
end
end
tr1Msg="function tr1 in LinearAlgebra.jl of PosDefMaifold package: the trace of the input matrix is not greater than the tolerance."
tr1Msg1="function tr1 in LinearAlgebra.jl of PosDefMaifold package: the trace of the input matrix is not greater than the tolerance."
tr1Msg2="function tr1 in LinearAlgebra.jl of PosDefMaifold package: the imaginary part of the trace of the input matrix is greater than the tolerance."


"""
Expand Down Expand Up @@ -385,11 +406,11 @@ end
(see [AnyMatrix type](@ref)).
This is given by
``UV^T``,
``UV^H``,
where
``\\textrm(SVD)=UΛV^T``.
``\\textrm(SVD)=UΛV^H``.
If `X` is `Diagonal`, return `X`.
Expand Down
2 changes: 1 addition & 1 deletion src/signalProcessing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ randPosDefMat(n::Int;

randPosDefMat(::Type{Complex{T}}, n::Int;
df::Int=2,
eigvalsSNR::Real=10e3) where {T<:AbstractFloat} =
eigvalsSNR::Real=10e3) where {T<:AbstractFloat} =
congruence(randU(ComplexF64, n), randΛ(n, df=df, eigvalsSNR=eigvalsSNR), ℍ)


Expand Down

0 comments on commit 1858d44

Please sign in to comment.