Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GradedAxes] [BlockSparseArrays] Fix ambiguity error when slicing GradedUnitRange with BlockSlice #1491

Merged
merged 6 commits into from
Jun 11, 2024

Conversation

mtfishman
Copy link
Member

Fixes the issue reported by @ogauthe in ITensor/BlockSparseArrays.jl#2.

@mtfishman mtfishman merged commit de78e9f into main Jun 11, 2024
15 of 16 checks passed
@mtfishman mtfishman deleted the BlockSparseArrays_dual_axis_blockview_bug branch June 11, 2024 14:46
@ogauthe
Copy link
Contributor

ogauthe commented Jun 11, 2024

Thank you for the quick fix.

This solved the issue for constructing the view. However there is now a display bug as of de78e9fa45af3fae8470d85de2938be77ba09540

v1 = view(m1, BlockArrays.Block(1, 1))[1:1, 1:1];  # used to display correctly
display(v1)  # MethodError
typeof(axes) = Tuple{NDTensors.LabelledNumbers.LabelledUnitRange{Int64, Base.OneTo{Int64}, U1}, NDTensors.LabelledNumbers.LabelledUnitRange{Int64, Base.OneTo{Int64}, U1}}

Warning: To temporarily circumvent a bug in printing BlockSparseArrays with mixtures of dual and non-dual axes, the types of the dual axes printed below might not be accurate. The types printed above this message are the correct ones.

1×1-blocked 1×1 NDTensors.BlockSparseArrays.BlockSparseArray{Float64, 2, Matrix{Float64}, NDTensors.SparseArrayDOKs.SparseArrayDOK{Matrix{Float64}, 2, NDTensors.BlockSparseArrays.BlockZero{Tuple{NDTensors.LabelledNumbers.LabelledUnitRange{Int64, Base.OneTo{Int64}, U1}, NDTensors.LabelledNumbers.LabelledUnitRange{Int64, Base.OneTo{Int64}, U1}}}}, Tuple{NDTensors.LabelledNumbers.LabelledUnitRange{Int64, Base.OneTo{Int64}, U1}, NDTensors.LabelledNumbers.LabelledUnitRange{Int64, Base.OneTo{Int64}, U1}}}:
ERROR: MethodError: no method matching NDTensors.LabelledNumbers.LabelledInteger{Int64, U1}(::Int64)

Closest candidates are:
  (::Type{NDTensors.LabelledNumbers.LabelledInteger{Value, Label}} where {Value<:Integer, Label})(::Any, ::Any)
   @ NDTensors ~/Documents/itensor/ITensors.jl/NDTensors/src/lib/LabelledNumbers/src/labelledinteger.jl:2
  (::Type{T})(::T) where T<:Number
   @ Core boot.jl:792
  (::Type{T})(::BigFloat) where T<:Integer
   @ Base mpfr.jl:378
  ...

Stacktrace:
  [1] convert(::Type{NDTensors.LabelledNumbers.LabelledInteger{Int64, U1}}, x::Int64)
    @ Base ./number.jl:7
  [2] cvt1
    @ ./essentials.jl:468 [inlined]
  [3] ntuple
    @ ./ntuple.jl:49 [inlined]
  [4] convert(::Type{Tuple{NDTensors.LabelledNumbers.LabelledInteger{Int64, U1}, NDTensors.LabelledNumbers.LabelledInteger{Int64, U1}}}, x::Tuple{Int64, Int64})
    @ Base ./essentials.jl:470
  [5] push!(a::Vector{Tuple{NDTensors.LabelledNumbers.LabelledInteger{Int64, U1}, NDTensors.LabelledNumbers.LabelledInteger{Int64, U1}}}, item::Tuple{Int64, Int64})
    @ Base ./array.jl:1118
  [6] alignment(io::IOContext{Base.TTY}, X::AbstractVecOrMat, rows::Vector{NDTensors.LabelledNumbers.LabelledInteger{Int64, U1}}, cols::Vector{NDTensors.LabelledNumbers.LabelledInteger{Int64, U1}}, cols_if_complete::Int64, cols_otherwise::Int64, sep::Int64, ncols::Int64)
    @ Base ./arrayshow.jl:76
  [7] _print_matrix(io::IOContext{Base.TTY}, X::AbstractVecOrMat, pre::String, sep::String, post::String, hdots::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64, rowsA::UnitRange{NDTensors.LabelledNumbers.LabelledInteger{Int64, U1}}, colsA::UnitRange{NDTensors.LabelledNumbers.LabelledInteger{Int64, U1}})
    @ Base ./arrayshow.jl:207
  [8] print_matrix(io::IOContext{Base.TTY}, X::NDTensors.BlockSparseArrays.BlockSparseArray{Float64, 2, Matrix{Float64}, NDTensors.SparseArrayDOKs.SparseArrayDOK{Matrix{Float64}, 2, NDTensors.BlockSparseArrays.BlockZero{Tuple{}}}, Tuple{NDTensors.LabelledNumbers.LabelledUnitRange{Int64, Base.OneTo{}, U1}, NDTensors.LabelledNumbers.LabelledUnitRange{Int64, Base.OneTo{}, U1}}}, pre::String, sep::String, post::String, hdots::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64)
    @ Base ./arrayshow.jl:171
  [9] print_matrix
    @ ./arrayshow.jl:171 [inlined]
 [10] print_array
    @ ./arrayshow.jl:358 [inlined]
 [11] show(io::IOContext{Base.TTY}, ::MIME{Symbol("text/plain")}, X::NDTensors.BlockSparseArrays.BlockSparseArray{Float64, 2, Matrix{Float64}, NDTensors.SparseArrayDOKs.SparseArrayDOK{Matrix{Float64}, 2, NDTensors.BlockSparseArrays.BlockZero{Tuple{}}}, Tuple{NDTensors.LabelledNumbers.LabelledUnitRange{Int64, Base.OneTo{}, U1}, NDTensors.LabelledNumbers.LabelledUnitRange{Int64, Base.OneTo{}, U1}}})
    @ Base ./arrayshow.jl:399
 [12] #blocksparse_show#9
    @ ~/Documents/itensor/ITensors.jl/NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysGradedAxesExt/src/BlockSparseArraysGradedAxesExt.jl:90 [inlined]
 [13] blocksparse_show
    @ ~/Documents/itensor/ITensors.jl/NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysGradedAxesExt/src/BlockSparseArraysGradedAxesExt.jl:82 [inlined]
 [14] #show#10
    @ ~/Documents/itensor/ITensors.jl/NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysGradedAxesExt/src/BlockSparseArraysGradedAxesExt.jl:100 [inlined]
 [15] show(io::IOContext{Base.TTY}, mime::MIME{Symbol("text/plain")}, a::NDTensors.BlockSparseArrays.BlockSparseArray{Float64, 2, Matrix{Float64}, NDTensors.SparseArrayDOKs.SparseArrayDOK{Matrix{Float64}, 2, NDTensors.BlockSparseArrays.BlockZero{Tuple{}}}, Tuple{NDTensors.LabelledNumbers.LabelledUnitRange{Int64, Base.OneTo{}, U1}, NDTensors.LabelledNumbers.LabelledUnitRange{Int64, Base.OneTo{}, U1}}})
    @ NDTensors.BlockSparseArrays.BlockSparseArraysGradedAxesExt ~/Documents/itensor/ITensors.jl/NDTensors/src/lib/BlockSparseArrays/ext/BlockSparseArraysGradedAxesExt/src/BlockSparseArraysGradedAxesExt.jl:97
 [16] (::REPL.var"#55#56"{REPL.REPLDisplay{REPL.LineEditREPL}, MIME{Symbol("text/plain")}, Base.RefValue{Any}})(io::Any)
    @ REPL ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:273
 [17] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:569
 [18] display(d::REPL.REPLDisplay, mime::MIME{Symbol("text/plain")}, x::Any)
    @ REPL ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:259
 [19] display
    @ ~/.julia/juliaup/julia-1.10.4+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:278 [inlined]
 [20] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:340
 [21] top-level scope
    @ REPL[18]:1
Some type information was truncated. Use `show(err)` to see complete types.

This seems to be a change in LabelledNumbers behavior. I can open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants