Skip to content

Commit 00eb107

Browse files
Jutholkdvos
andauthored
some cleanup for v0.14 (#191)
* some cleanup for v0.14 * try to remove some constprop macros * bump version * restore constprop * remove unused compat entry --------- Co-authored-by: Lukas Devos <[email protected]>
1 parent a8aa774 commit 00eb107

File tree

8 files changed

+47
-20
lines changed

8 files changed

+47
-20
lines changed

Changelog.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@ Features that are planned to be implemented before the release of v1.0.0, in no
1717

1818
## v0.14
1919

20+
### Use `DiagonalTensorMap` for singular values and eigenvalues
21+
22+
The diagonal (1,1) tensor that contains the singular values or eigenvalues of a tensor
23+
are now explicitly represented as `DiagonalTensorMap` instances.
24+
25+
### New index functionality
26+
There are is new functionality for manipulating the spaces associated with a tensor:
27+
* `flip(t, i)` changes the duality flag of the `i`th index of `t`, in such a way that flipping
28+
a pair of contracted indices in an `@tensor` contraction does not affect the result.
29+
* `insertleftunit(t, i)` and `insertrightunit(t, i)` insert a trivial unit space to the left
30+
or to right of index `i`, whereas `removeunit(t, i)` removes such a trivial unit space.
31+
32+
### SVD truncation change (breaking)
33+
There is a subtle but breaking change in the truncation mechanism in SVD, where now it is
34+
guaranteed that smaller singular values are removed first, irrespective of the (quantum)
35+
dimension of the sector to which they belong
36+
2037
### `DiagonalTensorMap` and `reduceddim`
2138

2239
This adds a `DiagonalTensorMap` type for representing tensor maps in which all of the

Project.toml

Lines changed: 1 addition & 1 deletion
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.13.2"
4+
version = "0.14"
55

66
[deps]
77
LRUCache = "8ac3fa9e-de4c-5943-b1dc-09c6b5f20637"

docs/src/lib/spaces.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ There are also specific methods for `HomSpace` instances, that are used in deter
112112
the resuling `HomSpace` after applying certain tensor operations.
113113

114114
```@docs
115+
flip(W::HomSpace{S}, I) where {S}
115116
TensorKit.permute(::HomSpace{S}, ::Index2Tuple{N₁,N₂}) where {S,N₁,N₂}
116117
TensorKit.select(::HomSpace{S}, ::Index2Tuple{N₁,N₂}) where {S,N₁,N₂}
117118
TensorKit.compose(::HomSpace{S}, ::HomSpace{S}) where {S}

docs/src/lib/tensors.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ permute(::AbstractTensorMap, ::Index2Tuple{N₁,N₂}; ::Bool) where {N₁,N₂}
174174
braid(::AbstractTensorMap, ::Index2Tuple, ::IndexTuple; ::Bool)
175175
transpose(::AbstractTensorMap, ::Index2Tuple; ::Bool)
176176
repartition(::AbstractTensorMap, ::Int, ::Int; ::Bool)
177+
flip(t::AbstractTensorMap, I)
177178
twist(::AbstractTensorMap, ::Int; ::Bool)
178179
insertleftunit(::AbstractTensorMap, ::Int)
179180
insertrightunit(::AbstractTensorMap, ::Int)

src/TensorKit.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ import TensorKitSectors: dim, BraidingStyle, FusionStyle, ⊠, ⊗
107107
import TensorKitSectors: dual, type_repr
108108
import TensorKitSectors: twist
109109

110-
using Base: @boundscheck, @propagate_inbounds, OneTo, tail, front,
110+
using Base: @boundscheck, @propagate_inbounds, @constprop,
111+
OneTo, tail, front,
111112
tuple_type_head, tuple_type_tail, tuple_type_cons,
112113
SizeUnknown, HasLength, HasShape, IsInfinite, EltypeUnknown, HasEltype
113114
using Base.Iterators: product, filter

src/auxiliary/auxiliary.jl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@ end
4444
@noinline _boundserror(P, i) = throw(BoundsError(P, i))
4545
@noinline _nontrivialspaceerror(P, i) = throw(ArgumentError(lazy"Attempting to remove a non-trivial space $(P[i])"))
4646

47-
# Compat implementation:
48-
@static if VERSION < v"1.7"
49-
macro constprop(setting, ex)
50-
return esc(ex)
51-
end
52-
else
53-
using Base: @constprop
54-
end
55-
5647
const VecOrNumber{T<:Number} = Union{DenseVector{T},T}
5748

5849
"""

src/tensors/indexmanipulations.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,9 @@ If `copy=false`, `tdst` might share data with `tsrc` whenever possible. Otherwis
303303
304304
See also [`insertrightunit`](@ref) and [`removeunit`](@ref).
305305
"""
306-
@constprop :aggressive function insertleftunit(t::AbstractTensorMap,
307-
i::Int=numind(t) + 1; copy::Bool=true,
308-
conj::Bool=false, dual::Bool=false)
306+
@constprop :aggressive function insertleftunit(t::AbstractTensorMap, i::Int=numind(t) + 1;
307+
copy::Bool=true, conj::Bool=false,
308+
dual::Bool=false)
309309
W = insertleftunit(space(t), i; conj, dual)
310310
tdst = similar(t, W)
311311
for (c, b) in blocks(t)
@@ -314,8 +314,8 @@ See also [`insertrightunit`](@ref) and [`removeunit`](@ref).
314314
return tdst
315315
end
316316
@constprop :aggressive function insertleftunit(t::TensorMap, i::Int=numind(t) + 1;
317-
copy::Bool=false,
318-
conj::Bool=false, dual::Bool=false)
317+
copy::Bool=false, conj::Bool=false,
318+
dual::Bool=false)
319319
W = insertleftunit(space(t), i; conj, dual)
320320
return TensorMap{scalartype(t)}(copy ? Base.copy(t.data) : t.data, W)
321321
end
@@ -360,8 +360,7 @@ This operation undoes the work of [`insertunit`](@ref).
360360
W = removeunit(space(t), i)
361361
return TensorMap{scalartype(t)}(copy ? Base.copy(t.data) : t.data, W)
362362
end
363-
@constprop :aggressive function removeunit(t::AbstractTensorMap, i::Int;
364-
copy::Bool=true)
363+
@constprop :aggressive function removeunit(t::AbstractTensorMap, i::Int; copy::Bool=true)
365364
W = removeunit(space(t), i)
366365
tdst = similar(t, W)
367366
for (c, b) in blocks(t)

src/tensors/vectorinterface.jl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,25 @@ function VectorInterface.inner(tx::AbstractTensorMap, ty::AbstractTensorMap)
102102
InnerProductStyle(tx) === EuclideanInnerProduct() || throw_invalid_innerproduct(:inner)
103103
T = VectorInterface.promote_inner(tx, ty)
104104
s = zero(T)
105-
for c in blocksectors(tx)
106-
s += convert(T, dim(c)) * inner(block(tx, c), block(ty, c))
105+
for ((cx, bx), (cy, by)) in zip(blocks(tx), blocks(ty))
106+
s += convert(T, dim(cx)) * inner(bx, by)
107107
end
108108
return s
109109
end
110+
function VectorInterface.inner(tx::TensorMap, ty::TensorMap)
111+
space(tx) == space(ty) || throw(SpaceMismatch("$(space(tx))$(space(ty))"))
112+
InnerProductStyle(tx) === EuclideanInnerProduct() || throw_invalid_innerproduct(:inner)
113+
if FusionStyle(sectortype(tx)) isa UniqueFusion # all quantum dimensions are one
114+
return inner(tx.data, ty.data)
115+
else
116+
T = VectorInterface.promote_inner(tx, ty)
117+
s = zero(T)
118+
for c in blocksectors(tx)
119+
bx = parent(block(tx, c)) # matrix structure (reshape) does not matter
120+
by = parent(block(ty, c)) # but does lead to slower path in inner
121+
s += convert(T, dim(c)) * inner(bx, by)
122+
end
123+
end
124+
return s
125+
end
126+
# TODO: do we need a fast path for `AdjointTensorMap` instances?

0 commit comments

Comments
 (0)