Skip to content

Commit b89fbba

Browse files
authored
Merge branch 'main' into NDTensors_excise_libraries
2 parents 69f1fd8 + a61a67b commit b89fbba

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

ext/ITensorsVectorInterfaceExt/ITensorsVectorInterfaceExt.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ function VectorInterface.scalartype(a::ITensor)
5858
return ITensors.scalartype(a)
5959
end
6060

61+
# Circumvent issue that `VectorInterface.jl` computes
62+
# the scalartype in the type domain, which isn't known
63+
# for ITensors.
64+
function VectorInterface.scalartype(a::AbstractArray{ITensor})
65+
# Like the implementation of `LinearAlgebra.promote_leaf_eltypes`:
66+
# https://github.com/JuliaLang/LinearAlgebra.jl/blob/e7da19f2764ba36bd0a9eb8ec67dddce19d87114/src/generic.jl#L1933
67+
return mapreduce(VectorInterface.scalartype, promote_type, a; init=Bool)
68+
end
69+
6170
function VectorInterface.scale(a::ITensor, α::Number)
6271
return a * α
6372
end

test/ext/ITensorsVectorInterfaceExt/runtests.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@eval module $(gensym())
2-
using ITensors: Index, dag, inds, random_itensor
2+
using ITensors: ITensor, Index, dag, inds, random_itensor
33
using Test: @test, @testset
44
using VectorInterface:
55
add,
@@ -68,6 +68,9 @@ const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
6868
# scalartype
6969
@test scalartype(a) === elt
7070
@test scalartype(b) === elt
71+
@test scalartype([a, b]) === elt
72+
@test scalartype([a, random_itensor(Float32, i, j)]) === elt
73+
@test scalartype(ITensor[]) === Bool
7174

7275
# scale
7376
@test scale(a, α) α * a

0 commit comments

Comments
 (0)