Skip to content
Merged
5 changes: 1 addition & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "TensorAlgebra"
uuid = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a"
version = "0.10.0"
version = "0.11.0"
authors = ["ITensor developers <support@itensor.org> and contributors"]

[workspace]
Expand All @@ -15,19 +15,16 @@ StridedViews = "4db3bf67-4bd7-4b4e-b153-31dc3fb37143"
TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6"

[weakdeps]
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
TensorOperations = "6aa20fa7-93e2-5fca-9bc0-fbd0db3c71a2"

[extensions]
TensorAlgebraBlockArraysExt = "BlockArrays"
TensorAlgebraGPUArraysCoreExt = "GPUArraysCore"
TensorAlgebraMooncakeExt = "Mooncake"
TensorAlgebraTensorOperationsExt = "TensorOperations"

[compat]
BlockArrays = "1.7.2"
EllipsisNotation = "1.8"
GPUArraysCore = "0.2"
LinearAlgebra = "1.10"
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ path = ".."
Documenter = "1.8.1"
ITensorFormatter = "0.2.27"
Literate = "2.20.1"
TensorAlgebra = "0.10"
TensorAlgebra = "0.11"
2 changes: 1 addition & 1 deletion examples/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ TensorAlgebra = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a"
path = ".."

[compat]
TensorAlgebra = "0.10"
TensorAlgebra = "0.11"

This file was deleted.

99 changes: 0 additions & 99 deletions ext/TensorAlgebraBlockArraysExt/blockarrays.jl

This file was deleted.

20 changes: 0 additions & 20 deletions ext/TensorAlgebraBlockArraysExt/blockedtuple.jl

This file was deleted.

12 changes: 6 additions & 6 deletions ext/TensorAlgebraMooncakeExt/TensorAlgebraMooncakeExt.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module TensorAlgebraMooncakeExt

using Mooncake: Mooncake, @zero_derivative, DefaultCtx
using TensorAlgebra: AbstractBlockPermutation, ContractAlgorithm, allocate_output, biperm,
blockedperms, check_input, contract, contract!, contract_labels,
default_contract_algorithm, select_contract_algorithm
using TensorAlgebra: BiTuple, ContractAlgorithm, allocate_output, biperm, biperms,
check_input, contract, contract!, contract_labels, default_contract_algorithm,
select_contract_algorithm

Mooncake.tangent_type(::Type{<:AbstractBlockPermutation}) = Mooncake.NoTangent
Mooncake.tangent_type(::Type{<:BiTuple}) = Mooncake.NoTangent
Mooncake.tangent_type(::Type{<:ContractAlgorithm}) = Mooncake.NoTangent

@zero_derivative DefaultCtx Tuple{
typeof(allocate_output), typeof(contract), Any, Any, Any, Any, Any, Any, Any, Any,
}
@zero_derivative DefaultCtx Tuple{typeof(biperm), Any, Any}
@zero_derivative DefaultCtx Tuple{typeof(blockedperms), typeof(contract), Any, Any, Any}
@zero_derivative DefaultCtx Tuple{typeof(biperm), Any, Any, Any}
@zero_derivative DefaultCtx Tuple{typeof(biperms), typeof(contract), Any, Any, Any}
@zero_derivative DefaultCtx Tuple{
typeof(check_input), typeof(contract), Any, Any, Any, Any, Any, Any,
}
Expand Down
4 changes: 0 additions & 4 deletions src/BaseExtensions/BaseExtensions.jl

This file was deleted.

5 changes: 0 additions & 5 deletions src/BaseExtensions/indexin.jl

This file was deleted.

22 changes: 0 additions & 22 deletions src/BaseExtensions/permutedims.jl

This file was deleted.

12 changes: 7 additions & 5 deletions src/TensorAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ export contract, contract!, eig_full, eig_trunc, eig_vals, eigh_full, eigh_trunc
right_polar, svd_compact, svd_full, svd_trunc, svd_vals

if VERSION >= v"1.11.0-DEV.469"
eval(Meta.parse("public contractopadd!, matricizeop, zero!, scale!, permuteddims"))
eval(
Meta.parse(
"public biperm, bipartition, contractopadd!, matricizeop, zero!, scale!, permuteddims"
)
)
end

include("inplace.jl")
include("MatrixAlgebra.jl")
include("blockedtuple.jl")
include("blockedpermutation.jl")
include("BaseExtensions/BaseExtensions.jl")
include("bituple.jl")
include("permutedimsadd.jl")
include("matricize.jl")
include("contract/contractalgorithm.jl")
include("contract/contract.jl")
include("contract/contract_labels.jl")
include("contract/blockedperms.jl")
include("contract/biperms.jl")
include("contract/allocate_output.jl")
include("contract/contract_matricize.jl")
include("factorizations.jl")
Expand Down
56 changes: 56 additions & 0 deletions src/bituple.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# A bipartitioned tuple: a flat tuple carrying an extra codomain/domain split. It acts like the
# flat tuple `(t1..., t2...)` for iteration, indexing, and `length`, with the split exposed only
# through the `t1` and `t2` fields (the way `Pair` exposes its two halves through fields rather
# than a collection interface). When its entries are `Int`s forming a permutation it acts as a
# "biperm"; whether it is a valid permutation is the concern of the operation using it as one
# (e.g. `matricize`), not of the type.

unval(::Val{N}) where {N} = N

struct BiTuple{N1, N2, T1 <: NTuple{N1, Any}, T2 <: NTuple{N2, Any}}
t1::T1
t2::T2
end

# Split a flat tuple into a first group of length `N1` and the remaining second group.
function BiTuple(t::NTuple{N, Any}, ::Val{N1}) where {N, N1}
return BiTuple(ntuple(i -> t[i], Val(N1)), ntuple(i -> t[N1 + i], Val(N - N1)))
end

Base.Tuple(bt::BiTuple) = (bt.t1..., bt.t2...)
Base.length(::BiTuple{N1, N2}) where {N1, N2} = N1 + N2
Base.iterate(bt::BiTuple, args...) = iterate(Tuple(bt), args...)
Base.getindex(bt::BiTuple, i::Integer) = Tuple(bt)[i]
function Base.eltype(::Type{<:BiTuple{<:Any, <:Any, T1, T2}}) where {T1, T2}
return promote_type(eltype(T1), eltype(T2))
end

function Base.show(io::IO, bt::BiTuple)
return print(io, "BiTuple(", bt.t1, ", ", bt.t2, ")")
end

Base.:(==)(a::BiTuple, b::BiTuple) = a.t1 == b.t1 && a.t2 == b.t2
Base.hash(bt::BiTuple, h::UInt) = hash(bt.t2, hash(bt.t1, hash(:BiTuple, h)))

Base.invperm(bt::BiTuple{N1}) where {N1} = BiTuple(invperm(Tuple(bt)), Val(N1))

"""
bipartition(t::Tuple, length1::Val) -> (t1, t2)
bipartition(t::Tuple, group1::Tuple, group2::Tuple) -> (p1, p2)

Split a flat tuple into two groups, returned as a pair of tuples.

The first form splits `t` in order, taking the first `length1` entries as `t1`
and the remaining entries as `t2`. The second form gathers the entries of `t` at
the two index groups `group1` and `group2`, returning `p1 = t[group1...]` and
`p2 = t[group2...]`.
"""
function bipartition(t::Tuple, length1::Val)
bt = BiTuple(t, length1)
return bt.t1, bt.t2
end
function bipartition(t::Tuple, group1::Tuple, group2::Tuple)
return map(i -> t[i], group1), map(i -> t[i], group2)
end
# Split `t` by the two groups of a `BiTuple`.
bipartition(t::Tuple, bt::BiTuple) = bipartition(t, bt.t1, bt.t2)
Loading
Loading