From deb1e766a5d0fc2b748410909a4987027964ca10 Mon Sep 17 00:00:00 2001 From: lkdvos Date: Tue, 7 Nov 2023 11:30:47 +1100 Subject: [PATCH] improved inference of physical spaces. --- src/operators/sparsempo/sparsempo.jl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/operators/sparsempo/sparsempo.jl b/src/operators/sparsempo/sparsempo.jl index 0559a7037..d030c5d18 100644 --- a/src/operators/sparsempo/sparsempo.jl +++ b/src/operators/sparsempo/sparsempo.jl @@ -81,7 +81,7 @@ end #default constructor function SparseMPO(x::AbstractArray{Union{E,M},3}) where {M<:MPOTensor,E<:Number} - (period, numrows, numcols) = size(x) + period, numrows, numcols = size(x) Sp = spacetype(M) E == scalartype(M) || throw( @@ -175,8 +175,15 @@ function SparseMPO(x::AbstractArray{Union{E,M},3}) where {M<:MPOTensor,E<:Number end end - sum(ismissing.(pspaces)) == 0 || - throw(ArgumentError("Not all physical spaces were assigned")) + if sum(ismissing.(pspaces)) != 0 + if allequal(Iterators.filter(!ismissing, pspaces)) + V = pspaces[findfirst(!ismissing, pspaces)] + @warn "Not all physical spaces were assigned, assumed $V everywhere" + pspaces .= Ref(V) + else + throw(ArgumentError("Not all physical spaces were assigned")) + end + end # sum(ismissing.(domspaces)) == 0 || @warn "failed to deduce all domspaces" for loc in 1:period, j in 1:numrows