Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function and keyword argument name deprecations #255

Merged
merged 1 commit into from
Apr 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 77 additions & 16 deletions src/Tensors/linearalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,38 @@ svd of an order-2 DenseTensor
"""
function LinearAlgebra.svd(T::DenseTensor{ElT,2,IndsT};
kwargs...) where {ElT,IndsT}
# Keyword argument deprecations
use_absolute_cutoff = false
if haskey(kwargs, :absoluteCutoff)
@warn "In svd, keyword argument absoluteCutoff is deprecated in favor of use_absolute_cutoff"
use_absolute_cutoff = get(kwargs,
:absoluteCutoff,
use_absolute_cutoff)
end
use_relative_cutoff = true
if haskey(kwargs, :doRelCutoff)
@warn "In svd, keyword argument doRelCutoff is deprecated in favor of use_relative_cutoff"
use_relative_cutoff = get(kwargs,
:doRelCutoff,
use_relative_cutoff)
end
if haskey(kwargs, :fastSVD)
@warn "In svd, keyword argument fastSVD is deprecated in favor of fastsvd"
fastsvd = get(kwargs, :fastsvd, true)
end

maxdim::Int = get(kwargs,:maxdim,minimum(dims(T)))
mindim::Int = get(kwargs,:mindim,1)
cutoff::Float64 = get(kwargs,:cutoff,0.0)
absoluteCutoff::Bool = get(kwargs,:absoluteCutoff,false)
doRelCutoff::Bool = get(kwargs,:doRelCutoff,true)
fastSVD::Bool = get(kwargs,:fastSVD,false)
use_absolute_cutoff::Bool = get(kwargs,
:use_absolute_cutoff,
use_absolute_cutoff)
use_relative_cutoff::Bool = get(kwargs,
:use_relative_cutoff,
use_relative_cutoff)
fastsvd::Bool = get(kwargs,:fastsvd,false)

if fastSVD
if fastsvd
MU,MS,MV = svd(matrix(T))
else
MU,MS,MV = svd_recursive(matrix(T))
Expand All @@ -78,8 +102,8 @@ function LinearAlgebra.svd(T::DenseTensor{ElT,2,IndsT};
truncerr,_ = truncate!(P;mindim=mindim,
maxdim=maxdim,
cutoff=cutoff,
absoluteCutoff=absoluteCutoff,
doRelCutoff=doRelCutoff)
use_absolute_cutoff=use_absolute_cutoff,
use_relative_cutoff=use_relative_cutoff)
spec = Spectrum(P,truncerr)
dS = length(P)
if dS < length(MS)
Expand All @@ -102,12 +126,32 @@ end

function LinearAlgebra.eigen(T::Hermitian{ElT,<:DenseTensor{ElT,2,IndsT}};
kwargs...) where {ElT<:Union{Real,Complex},IndsT}
# Keyword argument deprecations
use_absolute_cutoff = false
if haskey(kwargs, :absoluteCutoff)
@warn "In svd, keyword argument absoluteCutoff is deprecated in favor of use_absolute_cutoff"
use_absolute_cutoff = get(kwargs,
:absoluteCutoff,
use_absolute_cutoff)
end
use_relative_cutoff = true
if haskey(kwargs, :doRelCutoff)
@warn "In svd, keyword argument doRelCutoff is deprecated in favor of use_relative_cutoff"
use_relative_cutoff = get(kwargs,
:doRelCutoff,
use_relative_cutoff)
end

truncate = haskey(kwargs,:maxdim) || haskey(kwargs,:cutoff)
maxdim::Int = get(kwargs,:maxdim,minimum(dims(T)))
mindim::Int = get(kwargs,:mindim,1)
cutoff::Float64 = get(kwargs,:cutoff,0.0)
absoluteCutoff::Bool = get(kwargs,:absoluteCutoff,false)
doRelCutoff::Bool = get(kwargs,:doRelCutoff,true)
use_absolute_cutoff::Bool = get(kwargs,
:use_absolute_cutoff,
use_absolute_cutoff)
use_relative_cutoff::Bool = get(kwargs,
:use_relative_cutoff,
use_relative_cutoff)

DM,UM = eigen(matrix(T))

Expand All @@ -119,8 +163,8 @@ function LinearAlgebra.eigen(T::Hermitian{ElT,<:DenseTensor{ElT,2,IndsT}};
if truncate
truncerr,_ = truncate!(DM;maxdim=maxdim,
cutoff=cutoff,
absoluteCutoff=absoluteCutoff,
doRelCutoff=doRelCutoff)
use_absolute_cutoff=use_absolute_cutoff,
use_relative_cutoff=use_relative_cutoff)
dD = length(DM)
if dD < size(UM,2)
UM = UM[:,1:dD]
Expand Down Expand Up @@ -156,7 +200,6 @@ function LinearAlgebra.eigen(T::DenseTensor{ElT,2,IndsT};
return U,D
end


function qr_positive(M::AbstractMatrix)
sparseQ,R = qr(M)
Q = convert(Matrix,sparseQ)
Expand All @@ -172,14 +215,32 @@ end

function LinearAlgebra.eigen(T::DenseTensor{ElT,2,IndsT};
kwargs...) where {ElT<:Union{Real,Complex},IndsT}
#ispossemidef::Bool = get(kwargs,:ispossemidef,false)
# Keyword argument deprecations
use_absolute_cutoff = false
if haskey(kwargs, :absoluteCutoff)
@warn "In svd, keyword argument absoluteCutoff is deprecated in favor of use_absolute_cutoff"
use_absolute_cutoff = get(kwargs,
:absoluteCutoff,
use_absolute_cutoff)
end
use_relative_cutoff = true
if haskey(kwargs, :doRelCutoff)
@warn "In svd, keyword argument doRelCutoff is deprecated in favor of use_relative_cutoff"
use_relative_cutoff = get(kwargs,
:doRelCutoff,
use_relative_cutoff)
end

truncate = haskey(kwargs,:maxdim) || haskey(kwargs,:cutoff)
maxdim::Int = get(kwargs,:maxdim,minimum(dims(T)))
mindim::Int = get(kwargs,:mindim,1)
cutoff::Float64 = get(kwargs,:cutoff,0.0)
absoluteCutoff::Bool = get(kwargs,:absoluteCutoff,false)
doRelCutoff::Bool = get(kwargs,:doRelCutoff,true)
use_absolute_cutoff::Bool = get(kwargs,
:use_absolute_cutoff,
use_absolute_cutoff)
use_relative_cutoff::Bool = get(kwargs,
:use_relative_cutoff,
use_relative_cutoff)

DM,UM = eigen(matrix(T))

Expand All @@ -191,8 +252,8 @@ function LinearAlgebra.eigen(T::DenseTensor{ElT,2,IndsT};
if truncate
truncerr,_ = truncate!(DM;maxdim=maxdim,
cutoff=cutoff,
absoluteCutoff=absoluteCutoff,
doRelCutoff=doRelCutoff)
use_absolute_cutoff=use_absolute_cutoff,
use_relative_cutoff=use_relative_cutoff)
dD = length(DM)
if dD < size(UM,2)
UM = UM[:,1:dD]
Expand Down
28 changes: 24 additions & 4 deletions src/Tensors/truncate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,31 @@ export truncate!

function truncate!(P::Vector{Float64};
kwargs...)::Tuple{Float64,Float64}
# Keyword argument deprecations
use_absolute_cutoff = false
if haskey(kwargs, :absoluteCutoff)
@warn "In truncate!, keyword argument absoluteCutoff is deprecated in favor of use_absolute_cutoff"
use_absolute_cutoff = get(kwargs,
:absoluteCutoff,
use_absolute_cutoff)
end
use_relative_cutoff = true
if haskey(kwargs, :doRelCutoff)
@warn "In truncate!, keyword argument doRelCutoff is deprecated in favor of use_relative_cutoff"
use_relative_cutoff = get(kwargs,
:doRelCutoff,
use_relative_cutoff)
end

maxdim::Int = min(get(kwargs,:maxdim,length(P)), length(P))
mindim::Int = max(get(kwargs,:mindim,1), 1)
cutoff::Float64 = max(get(kwargs,:cutoff,0.0), 0.0)
absoluteCutoff::Bool = get(kwargs,:absoluteCutoff,false)
doRelCutoff::Bool = get(kwargs,:doRelCutoff,true)
use_absolute_cutoff::Bool = get(kwargs,
:use_absolute_cutoff,
use_absolute_cutoff)
use_relative_cutoff::Bool = get(kwargs,
:use_relative_cutoff,
use_relative_cutoff)

origm = length(P)
docut = 0.0
Expand Down Expand Up @@ -35,7 +55,7 @@ function truncate!(P::Vector{Float64};
n -= 1
end

if absoluteCutoff
if use_absolute_cutoff
#Test if individual prob. weights fall below cutoff
#rather than using *sum* of discarded weights
while P[n] <= cutoff && n > mindim
Expand All @@ -44,7 +64,7 @@ function truncate!(P::Vector{Float64};
end
else
scale = 1.0
if doRelCutoff
if use_relative_cutoff
scale = sum(P)
(scale==0.0) && (scale = 1.0)
end
Expand Down
4 changes: 2 additions & 2 deletions src/decomp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ arguments provided. The following keyword arguments are recognized:
* `maxdim` [Int]
* `mindim` [Int]
* `cutoff` [Float64]
* `absoluteCutoff` [Bool] Default value: false.
* `doRelCutoff` [Bool] Default value: true.
* `use_absolute_cutoff` [Bool] Default value: false.
* `use_relative_cutoff` [Bool] Default value: true.
* `utags` [String] Default value: "Link,u".
* `vtags` [String] Default value: "Link,v".
* `fastSVD` [Bool] Defaut value: false.
Expand Down
Loading