Skip to content

Commit

Permalink
Generalize so labels don't have to be Tuple (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman authored Jan 16, 2025
1 parent 11f8157 commit 4453f64
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TensorAlgebra"
uuid = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.1.5"
version = "0.1.6"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
8 changes: 4 additions & 4 deletions src/BaseExtensions/indexin.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# `Base.indexin` doesn't handle tuples
indexin(x, y) = Base.indexin(x, y)
indexin(x, y::Tuple) = Base.indexin(x, collect(y))
indexin(x::Tuple, y) = Tuple{Vararg{Any,length(x)}}(Base.indexin(x, y))
indexin(x::Tuple, y::Tuple) = Tuple{Vararg{Any,length(x)}}(Base.indexin(x, collect(y)))
indexin(x, y::AbstractArray) = Base.indexin(x, y)
indexin(x, y) = Base.indexin(x, collect(y))
indexin(x::Tuple, y::AbstractArray) = Tuple{Vararg{Any,length(x)}}(Base.indexin(x, y))
indexin(x::Tuple, y) = Tuple{Vararg{Any,length(x)}}(Base.indexin(x, collect(y)))
46 changes: 23 additions & 23 deletions src/contract/contract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ end

function contract(
a1::AbstractArray,
labels1::Tuple,
labels1,
a2::AbstractArray,
labels2::Tuple,
α::Number=true;
labels2,
α::Number=one(Bool);
alg=default_contract_alg(),
kwargs...,
)
Expand All @@ -39,23 +39,23 @@ end
function contract(
alg::Algorithm,
a1::AbstractArray,
labels1::Tuple,
labels1,
a2::AbstractArray,
labels2::Tuple,
α::Number=true;
labels2,
α::Number=one(Bool);
kwargs...,
)
labels_dest = output_labels(contract, alg, a1, labels1, a2, labels2, α; kwargs...)
return contract(alg, labels_dest, a1, labels1, a2, labels2, α; kwargs...), labels_dest
end

function contract(
labels_dest::Tuple,
labels_dest,
a1::AbstractArray,
labels1::Tuple,
labels1,
a2::AbstractArray,
labels2::Tuple,
α::Number=true;
labels2,
α::Number=one(Bool);
alg=default_contract_alg(),
kwargs...,
)
Expand All @@ -64,13 +64,13 @@ end

function contract!(
a_dest::AbstractArray,
labels_dest::Tuple,
labels_dest,
a1::AbstractArray,
labels1::Tuple,
labels1,
a2::AbstractArray,
labels2::Tuple,
α::Number=true,
β::Number=false;
labels2,
α::Number=one(Bool),
β::Number=zero(Bool);
alg=default_contract_alg(),
kwargs...,
)
Expand All @@ -80,12 +80,12 @@ end

function contract(
alg::Algorithm,
labels_dest::Tuple,
labels_dest,
a1::AbstractArray,
labels1::Tuple,
labels1,
a2::AbstractArray,
labels2::Tuple,
α::Number=true;
labels2,
α::Number=one(Bool);
kwargs...,
)
biperm_dest, biperm1, biperm2 = blockedperms(contract, labels_dest, labels1, labels2)
Expand All @@ -95,11 +95,11 @@ end
function contract!(
alg::Algorithm,
a_dest::AbstractArray,
labels_dest::Tuple,
labels_dest,
a1::AbstractArray,
labels1::Tuple,
labels1,
a2::AbstractArray,
labels2::Tuple,
labels2,
α::Number,
β::Number;
kwargs...,
Expand All @@ -119,6 +119,6 @@ function contract(
kwargs...,
)
a_dest = allocate_output(contract, biperm_dest, a1, biperm1, a2, biperm2, α)
contract!(alg, a_dest, biperm_dest, a1, biperm1, a2, biperm2, α, false; kwargs...)
contract!(alg, a_dest, biperm_dest, a1, biperm1, a2, biperm2, α, zero(Bool); kwargs...)
return a_dest
end

0 comments on commit 4453f64

Please sign in to comment.