Skip to content

Commit 81a2b57

Browse files
committed
change factorization calling syntax; bump patch
1 parent 5ae3811 commit 81a2b57

File tree

4 files changed

+60
-49
lines changed

4 files changed

+60
-49
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TensorKit"
22
uuid = "07d1fe3e-3e46-537d-9eac-e9e13d0d4cec"
33
authors = ["Jutho Haegeman"]
4-
version = "0.11.1"
4+
version = "0.11.2"
55

66
[deps]
77
HalfIntegers = "f0d1745a-41c9-11e9-1dd9-e5d34d218721"

src/auxiliary/deprecate.jl

+24
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,28 @@ import Base: eltype, transpose
66
@deprecate permute(t::AbstractTensorMap, p1::IndexTuple, p2::IndexTuple; copy::Bool=false) permute(t, (p1, p2); copy=copy)
77
@deprecate transpose(t::AbstractTensorMap, p1::IndexTuple, p2::IndexTuple; copy::Bool=false) transpose(t, (p1, p2); copy=copy)
88
@deprecate braid(t::AbstractTensorMap, p1::IndexTuple, p2::IndexTuple, levels; copy::Bool=false) braid(t, (p1, p2), levels; copy=copy)
9+
10+
11+
Base.@deprecate(svd(t::AbstractTensorMap, leftind::IndexTuple, rightind::IndexTuple;
12+
trunc::TruncationScheme=notrunc(), p::Real=2, alg::SVDAlg=SDD()),
13+
tsvd(t, (leftind, rightind); trunc=trunc, p=p, alg=alg))
14+
Base.@deprecate(svd(t::AbstractTensorMap;
15+
trunc::TruncationScheme=notrunc(), p::Real=2, alg::SVDAlg=SDD()),
16+
tsvd(t; trunc=trunc, p=p, alg=alg))
17+
Base.@deprecate(svd!(t::AbstractTensorMap;
18+
trunc::TruncationScheme=notrunc(), p::Real=2, alg::SVDAlg=SDD()),
19+
tsvd(t; trunc=trunc, p=p, alg=alg))
20+
21+
22+
# TODO: deprecate
23+
24+
tsvd(t::AbstractTensorMap, p₁::IndexTuple, p₂::IndexTuple; kwargs...) = tsvd(t, (p₁, p₂); kwargs...)
25+
leftorth(t::AbstractTensorMap, p₁::IndexTuple, p₂::IndexTuple; kwargs...) = leftorth(t, (p₁, p₂); kwargs...)
26+
rightorth(t::AbstractTensorMap, p₁::IndexTuple, p₂::IndexTuple; kwargs...) = rightorth(t, (p₁, p₂); kwargs...)
27+
leftnull(t::AbstractTensorMap, p₁::IndexTuple, p₂::IndexTuple; kwargs...) = leftnull(t, (p₁, p₂); kwargs...)
28+
rightnull(t::AbstractTensorMap, p₁::IndexTuple, p₂::IndexTuple; kwargs...) = rightnull(t, (p₁, p₂); kwargs...)
29+
LinearAlgebra.eigen(t::AbstractTensorMap, p₁::IndexTuple, p₂::IndexTuple; kwargs...) = LinearAlgebra.eigen(t, (p₁, p₂); kwargs...)
30+
eig(t::AbstractTensorMap, p₁::IndexTuple, p₂::IndexTuple; kwargs...) = eig(t, (p₁, p₂); kwargs...)
31+
eigh(t::AbstractTensorMap, p₁::IndexTuple, p₂::IndexTuple; kwargs...) = eigh(t, (p₁, p₂); kwargs...)
32+
933
#! format: on

src/tensors/factorizations.jl

+28-41
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,8 @@ const OFA = OrthogonalFactorizationAlgorithm
55
import LinearAlgebra: svd!, svd
66
const SVDAlg = Union{SVD,SDD}
77

8-
Base.@deprecate(svd(t::AbstractTensorMap, leftind::IndexTuple, rightind::IndexTuple;
9-
trunc::TruncationScheme=notrunc(), p::Real=2, alg::SVDAlg=SDD()),
10-
tsvd(t, leftind, rightind; trunc=trunc, p=p, alg=alg))
11-
Base.@deprecate(svd(t::AbstractTensorMap;
12-
trunc::TruncationScheme=notrunc(), p::Real=2, alg::SVDAlg=SDD()),
13-
tsvd(t; trunc=trunc, p=p, alg=alg))
14-
Base.@deprecate(svd!(t::AbstractTensorMap;
15-
trunc::TruncationScheme=notrunc(), p::Real=2, alg::SVDAlg=SDD()),
16-
tsvd(t; trunc=trunc, p=p, alg=alg))
17-
188
"""
19-
tsvd(t::AbstractTensorMap, leftind::Tuple, rightind::Tuple;
9+
tsvd(t::AbstractTensorMap, (leftind, rightind)::Index2Tuple;
2010
trunc::TruncationScheme = notrunc(), p::Real = 2, alg::Union{SVD, SDD} = SDD())
2111
-> U, S, V, ϵ
2212
@@ -47,12 +37,12 @@ algorithm that computes the decomposition (`_gesvd` or `_gesdd`).
4737
Orthogonality requires `InnerProductStyle(t) <: HasInnerProduct`, and `tsvd(!)`
4838
is currently only implemented for `InnerProductStyle(t) === EuclideanProduct()`.
4939
"""
50-
function tsvd(t::AbstractTensorMap, p1::IndexTuple, p2::IndexTuple; kwargs...)
51-
return tsvd!(permute(t, (p1, p2); copy=true); kwargs...)
40+
function tsvd(t::AbstractTensorMap, (p₁, p₂)::Index2Tuple; kwargs...)
41+
return tsvd!(permute(t, (p₁, p₂); copy=true); kwargs...)
5242
end
5343

5444
"""
55-
leftorth(t::AbstractTensorMap, leftind::Tuple, rightind::Tuple;
45+
leftorth(t::AbstractTensorMap, (leftind, rightind)::Index2Tuple;
5646
alg::OrthogonalFactorizationAlgorithm = QRpos()) -> Q, R
5747
5848
Create orthonormal basis `Q` for indices in `leftind`, and remainder `R` such that
@@ -73,12 +63,12 @@ Orthogonality requires `InnerProductStyle(t) <: HasInnerProduct`, and
7363
`leftorth(!)` is currently only implemented for
7464
`InnerProductStyle(t) === EuclideanProduct()`.
7565
"""
76-
function leftorth(t::AbstractTensorMap, p1::IndexTuple, p2::IndexTuple; kwargs...)
77-
return leftorth!(permute(t, (p1, p2); copy=true); kwargs...)
66+
function leftorth(t::AbstractTensorMap, (p₁, p₂)::Index2Tuple; kwargs...)
67+
return leftorth!(permute(t, (p₁, p₂); copy=true); kwargs...)
7868
end
7969

8070
"""
81-
rightorth(t::AbstractTensorMap, leftind::Tuple, rightind::Tuple;
71+
rightorth(t::AbstractTensorMap, (leftind, rightind)::Index2Tuple;
8272
alg::OrthogonalFactorizationAlgorithm = LQpos()) -> L, Q
8373
8474
Create orthonormal basis `Q` for indices in `rightind`, and remainder `L` such that
@@ -101,12 +91,12 @@ Orthogonality requires `InnerProductStyle(t) <: HasInnerProduct`, and
10191
`rightorth(!)` is currently only implemented for
10292
`InnerProductStyle(t) === EuclideanProduct()`.
10393
"""
104-
function rightorth(t::AbstractTensorMap, p1::IndexTuple, p2::IndexTuple; kwargs...)
105-
return rightorth!(permute(t, (p1, p2); copy=true); kwargs...)
94+
function rightorth(t::AbstractTensorMap, (p₁, p₂)::Index2Tuple; kwargs...)
95+
return rightorth!(permute(t, (p₁, p₂); copy=true); kwargs...)
10696
end
10797

10898
"""
109-
leftnull(t::AbstractTensor, leftind::Tuple, rightind::Tuple;
99+
leftnull(t::AbstractTensor, (leftind, rightind)::Index2Tuple;
110100
alg::OrthogonalFactorizationAlgorithm = QRpos()) -> N
111101
112102
Create orthonormal basis for the orthogonal complement of the support of the indices in
@@ -127,12 +117,12 @@ Orthogonality requires `InnerProductStyle(t) <: HasInnerProduct`, and
127117
`leftnull(!)` is currently only implemented for
128118
`InnerProductStyle(t) === EuclideanProduct()`.
129119
"""
130-
function leftnull(t::AbstractTensorMap, p1::IndexTuple, p2::IndexTuple; kwargs...)
131-
return leftnull!(permute(t, (p1, p2); copy=true); kwargs...)
120+
function leftnull(t::AbstractTensorMap, (p₁, p₂)::Index2Tuple; kwargs...)
121+
return leftnull!(permute(t, (p₁, p₂); copy=true); kwargs...)
132122
end
133123

134124
"""
135-
rightnull(t::AbstractTensor, leftind::Tuple, rightind::Tuple;
125+
rightnull(t::AbstractTensor, (leftind, rightind)::Index2Tuple;
136126
alg::OrthogonalFactorizationAlgorithm = LQ(),
137127
atol::Real = 0.0,
138128
rtol::Real = eps(real(float(one(scalartype(t)))))*iszero(atol)) -> N
@@ -155,12 +145,12 @@ Orthogonality requires `InnerProductStyle(t) <: HasInnerProduct`, and
155145
`rightnull(!)` is currently only implemented for
156146
`InnerProductStyle(t) === EuclideanProduct()`.
157147
"""
158-
function rightnull(t::AbstractTensorMap, p1::IndexTuple, p2::IndexTuple; kwargs...)
159-
return rightnull!(permute(t, (p1, p2); copy=true); kwargs...)
148+
function rightnull(t::AbstractTensorMap, (p₁, p₂)::Index2Tuple; kwargs...)
149+
return rightnull!(permute(t, (p₁, p₂); copy=true); kwargs...)
160150
end
161151

162152
"""
163-
eigen(t::AbstractTensor, leftind::Tuple, rightind::Tuple; kwargs...) -> D, V
153+
eigen(t::AbstractTensor, (leftind, rightind)::Index2Tuple; kwargs...) -> D, V
164154
165155
Compute eigenvalue factorization of tensor `t` as linear map from `rightind` to `leftind`.
166156
@@ -178,13 +168,13 @@ matrices. See the corresponding documentation for more information.
178168
179169
See also `eig` and `eigh`
180170
"""
181-
function LinearAlgebra.eigen(t::AbstractTensorMap, p1::IndexTuple, p2::IndexTuple;
171+
function LinearAlgebra.eigen(t::AbstractTensorMap, (p₁, p₂)::Index2Tuple;
182172
kwargs...)
183-
return eigen!(permute(t, (p1, p2); copy=true); kwargs...)
173+
return eigen!(permute(t, (p₁, p₂); copy=true); kwargs...)
184174
end
185175

186176
"""
187-
eig(t::AbstractTensor, leftind::Tuple, rightind::Tuple; kwargs...) -> D, V
177+
eig(t::AbstractTensor, (leftind, rightind)::Index2Tuple; kwargs...) -> D, V
188178
189179
Compute eigenvalue factorization of tensor `t` as linear map from `rightind` to `leftind`.
190180
The function `eig` assumes that the linear map is not hermitian and returns type stable
@@ -204,12 +194,12 @@ Accepts the same keyword arguments `scale`, `permute` and `sortby` as `eigen` of
204194
205195
See also `eigen` and `eigh`.
206196
"""
207-
function eig(t::AbstractTensorMap, p1::IndexTuple, p2::IndexTuple; kwargs...)
208-
return eig!(permute(t, (p1, p2); copy=true); kwargs...)
197+
function eig(t::AbstractTensorMap, (p₁, p₂)::Index2Tuple; kwargs...)
198+
return eig!(permute(t, (p₁, p₂); copy=true); kwargs...)
209199
end
210200

211201
"""
212-
eigh(t::AbstractTensorMap, leftind::Tuple, rightind::Tuple) -> D, V
202+
eigh(t::AbstractTensorMap, (leftind, rightind)::Index2Tuple) -> D, V
213203
214204
Compute eigenvalue factorization of tensor `t` as linear map from `rightind` to `leftind`.
215205
The function `eigh` assumes that the linear map is hermitian and `D` and `V` tensors with
@@ -228,26 +218,23 @@ permute(t, (leftind, rightind)) * V = V * D
228218
229219
See also `eigen` and `eig`.
230220
"""
231-
function eigh(t::AbstractTensorMap, p1::IndexTuple, p2::IndexTuple)
232-
return eigh!(permute(t, (p1, p2); copy=true))
221+
function eigh(t::AbstractTensorMap, (p₁, p₂)::Index2Tuple)
222+
return eigh!(permute(t, (p₁, p₂); copy=true))
233223
end
234224

235225
"""
236-
isposdef(t::AbstractTensor, leftind::Tuple, rightind::Tuple) -> ::Bool
226+
isposdef(t::AbstractTensor, (leftind, rightind)::Index2Tuple) -> ::Bool
237227
238228
Test whether a tensor `t` is positive definite as linear map from `rightind` to `leftind`.
239229
240230
If `leftind` and `rightind` are not specified, the current partition of left and right
241231
indices of `t` is used. In that case, less memory is allocated if one allows the data in
242232
`t` to be destroyed/overwritten, by using `isposdef!(t)`. Note that the permuted tensor on
243233
which `isposdef!` is called should have equal domain and codomain, as otherwise it is
244-
meaningless
245-
246-
Accepts the same keyword arguments `scale`, `permute` and `sortby` as `eigen` of dense
247-
matrices. See the corresponding documentation for more information.
234+
meaningless.
248235
"""
249-
function LinearAlgebra.isposdef(t::AbstractTensorMap, p1::IndexTuple, p2::IndexTuple)
250-
return isposdef!(permute(t, (p1, p2); copy=true))
236+
function LinearAlgebra.isposdef(t::AbstractTensorMap, (p₁, p₂)::Index2Tuple)
237+
return isposdef!(permute(t, (p₁, p₂); copy=true))
251238
end
252239

253240
function tsvd(t::AbstractTensorMap; trunc::TruncationScheme=NoTruncation(),

test/tensors.jl

+7-7
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ for V in spacelist
347347
TensorKit.QL(), TensorKit.QLpos(),
348348
TensorKit.Polar(), TensorKit.SVD(),
349349
TensorKit.SDD())
350-
Q, R = @constinferred leftorth(t, (3, 4, 2), (1, 5); alg=alg)
350+
Q, R = @constinferred leftorth(t, ((3, 4, 2), (1, 5)); alg=alg)
351351
QdQ = Q' * Q
352352
@test QdQ one(QdQ)
353353
@test Q * R permute(t, ((3, 4, 2), (1, 5)))
@@ -359,7 +359,7 @@ for V in spacelist
359359
@testset "leftnull with $alg" for alg in
360360
(TensorKit.QR(), TensorKit.SVD(),
361361
TensorKit.SDD())
362-
N = @constinferred leftnull(t, (3, 4, 2), (1, 5); alg=alg)
362+
N = @constinferred leftnull(t, ((3, 4, 2), (1, 5)); alg=alg)
363363
NdN = N' * N
364364
@test NdN one(NdN)
365365
@test norm(N' * permute(t, ((3, 4, 2), (1, 5)))) <
@@ -370,7 +370,7 @@ for V in spacelist
370370
TensorKit.LQ(), TensorKit.LQpos(),
371371
TensorKit.Polar(), TensorKit.SVD(),
372372
TensorKit.SDD())
373-
L, Q = @constinferred rightorth(t, (3, 4), (2, 1, 5); alg=alg)
373+
L, Q = @constinferred rightorth(t, ((3, 4), (2, 1, 5)); alg=alg)
374374
QQd = Q * Q'
375375
@test QQd one(QQd)
376376
@test L * Q permute(t, ((3, 4), (2, 1, 5)))
@@ -382,14 +382,14 @@ for V in spacelist
382382
@testset "rightnull with $alg" for alg in
383383
(TensorKit.LQ(), TensorKit.SVD(),
384384
TensorKit.SDD())
385-
M = @constinferred rightnull(t, (3, 4), (2, 1, 5); alg=alg)
385+
M = @constinferred rightnull(t, ((3, 4), (2, 1, 5)); alg=alg)
386386
MMd = M * M'
387387
@test MMd one(MMd)
388388
@test norm(permute(t, ((3, 4), (2, 1, 5))) * M') <
389389
100 * eps(norm(t))
390390
end
391391
@testset "tsvd with $alg" for alg in (TensorKit.SVD(), TensorKit.SDD())
392-
U, S, V = @constinferred tsvd(t, (3, 4, 2), (1, 5); alg=alg)
392+
U, S, V = @constinferred tsvd(t, ((3, 4, 2), (1, 5)); alg=alg)
393393
UdU = U' * U
394394
@test UdU one(UdU)
395395
VVd = V * V'
@@ -440,8 +440,8 @@ for V in spacelist
440440

441441
t = Tensor(rand, T, V1 V1' V2 V2')
442442
@testset "eig and isposdef" begin
443-
D, V = eigen(t, (1, 3), (2, 4))
444-
D̃, Ṽ = @constinferred eig(t, (1, 3), (2, 4))
443+
D, V = eigen(t, ((1, 3), (2, 4)))
444+
D̃, Ṽ = @constinferred eig(t, ((1, 3), (2, 4)))
445445
@test D
446446
@test V
447447
VdV = V' * V

0 commit comments

Comments
 (0)