Skip to content

Commit

Permalink
Fix VectorInterface.scalartype for arrays of ITensors (#1614)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman authored Feb 3, 2025
1 parent 37d1570 commit a61a67b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ITensors"
uuid = "9136182c-28ba-11e9-034c-db9fb085ebd5"
authors = ["Matthew Fishman <[email protected]>", "Miles Stoudenmire <[email protected]>"]
version = "0.7.12"
version = "0.7.13"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
9 changes: 9 additions & 0 deletions ext/ITensorsVectorInterfaceExt/ITensorsVectorInterfaceExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ function VectorInterface.scalartype(a::ITensor)
return ITensors.scalartype(a)
end

# Circumvent issue that `VectorInterface.jl` computes
# the scalartype in the type domain, which isn't known
# for ITensors.
function VectorInterface.scalartype(a::AbstractArray{ITensor})
# Like the implementation of `LinearAlgebra.promote_leaf_eltypes`:
# https://github.com/JuliaLang/LinearAlgebra.jl/blob/e7da19f2764ba36bd0a9eb8ec67dddce19d87114/src/generic.jl#L1933
return mapreduce(VectorInterface.scalartype, promote_type, a; init=Bool)
end

function VectorInterface.scale(a::ITensor, α::Number)
return a * α
end
Expand Down
5 changes: 4 additions & 1 deletion test/ext/ITensorsVectorInterfaceExt/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@eval module $(gensym())
using ITensors: Index, dag, inds, random_itensor
using ITensors: ITensor, Index, dag, inds, random_itensor
using Test: @test, @testset
using VectorInterface:
add,
Expand Down Expand Up @@ -68,6 +68,9 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
# scalartype
@test scalartype(a) === elt
@test scalartype(b) === elt
@test scalartype([a, b]) === elt
@test scalartype([a, random_itensor(Float32, i, j)]) === elt
@test scalartype(ITensor[]) === Bool

# scale
@test scale(a, α) α * a
Expand Down

2 comments on commit a61a67b

@mtfishman
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/124276

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.13 -m "<description of version>" a61a67bfd77653bbd5dc80115cc54d293b128bb4
git push origin v0.7.13

Please sign in to comment.