Skip to content

Adapt.adapt on views of block arrays involving : is broken #451

@mtfishman

Description

@mtfishman

For example:

julia> using Adapt: adapt

julia> using BlockArrays: BlockedArray, blockedrange

julia> a = BlockedArray(randn(4), [2, 2])
2-blocked 4-element BlockedVector{Float64}:
 -0.5044442639462945
  0.1718623778654892
 ───────────────────
 -0.8397827142096443
  0.3544223955211385

julia> b = @view a[:]
4-element view(::BlockedArray{…,::Vector{Float64}}, :) with eltype Float64 with indices BlockArrays.BlockedOneTo([2, 4]):
 -0.5044442639462945
  0.1718623778654892
 -0.8397827142096443
  0.3544223955211385

julia> adapt(Array, b)
ERROR: MethodError: no method matching Base.Slice(::Vector{Int64})
The type `Base.Slice` exists, but no method is defined for this combination of argument types when trying to construct it.

Closest candidates are:
  Base.Slice(::Base.Slice)
   @ Base indices.jl:385
  Base.Slice(::T) where T<:AbstractUnitRange
   @ Base indices.jl:383

Stacktrace:
 [1] adapt_structure(to::Type, r::Base.Slice{BlockArrays.BlockedOneTo{Int64, Vector{Int64}}})
   @ Adapt ~/.julia/packages/Adapt/0LkKU/src/base.jl:82
 [2] adapt
   @ ~/.julia/packages/Adapt/0LkKU/src/Adapt.jl:40 [inlined]
 [3] _adapt_tuple_structure
   @ ~/.julia/packages/Adapt/0LkKU/src/base.jl:17 [inlined]
 [4] adapt_structure
   @ ~/.julia/packages/Adapt/0LkKU/src/base.jl:9 [inlined]
 [5] adapt
   @ ~/.julia/packages/Adapt/0LkKU/src/Adapt.jl:40 [inlined]
 [6] adapt_structure(to::Type, A::SubArray{Float64, 1, BlockArrays.BlockedVector{Float64, Vector{…}, Tuple{…}}, Tuple{Base.Slice{…}}, false})
   @ Adapt ~/.julia/packages/Adapt/0LkKU/src/wrappers.jl:10
 [7] adapt(to::Type, x::SubArray{Float64, 1, BlockArrays.BlockedVector{Float64, Vector{…}, Tuple{…}}, Tuple{Base.Slice{…}}, false})
   @ Adapt ~/.julia/packages/Adapt/0LkKU/src/Adapt.jl:40
 [8] top-level scope
   @ REPL[16]:1
 [9] top-level scope
   @ none:1
Some type information was truncated. Use `show(err)` to see complete types.

with:

(adapt) pkg> st
Status `...`
  [79e6a3ab] Adapt v4.3.0
  [8e7c35d0] BlockArrays v1.4.0

julia> versioninfo()
Julia Version 1.11.4
Commit 8561cc3d68d (2025-03-10 11:36 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin24.0.0)
  CPU: 10 × Apple M1 Max
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions