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

LazyArray(@~ dot.(a,a)) fails with custom array type #171

Open
roflmaostc opened this issue Apr 7, 2021 · 0 comments
Open

LazyArray(@~ dot.(a,a)) fails with custom array type #171

roflmaostc opened this issue Apr 7, 2021 · 0 comments

Comments

@roflmaostc
Copy link

Hey,

I encountered issues with a custom array type. I tried to reduce it to a MWE 😕
I'm using Julia 1.6.0 and LazyArrays 0.21.3.

The dot.(a,a) works itself, but wrapped in the LazyArray constructors, it seems to fail. Using a common array with the same content, it works also.

Does anybody know why or can you help me fixing that?

Thanks a lot!

Felix

julia> using LinearAlgebra, LazyArrays

julia> struct Foo{T, N} <: AbstractArray{T, N}
           size::NTuple{N, Int}
       end

julia> Base.getindex(A::Foo{T,N}, I::Vararg{B, N}) where {T,N, B} = Tuple(I)

julia> Base.size(A::Foo) = A.size

julia> a = Foo{NTuple{1, Int}, 1}((5,))
5-element Foo{Tuple{Int64}, 1}:
 (1,)
 (2,)
 (3,)
 (4,)
 (5,)

julia> dot.(a,a)
5-element Vector{Int64}:
  1
  4
  9
 16
 25

julia> @time LazyArray(@~ (dot.(a,a)))
  0.017648 seconds (34.23 k allocations: 2.129 MiB, 99.50% compilation time)
dot.(5-element Foo{Tuple{Int64}, 1}, 5-element Foo{Tuple{Int64}, 1}):
Error showing value of type BroadcastVector{Int64, typeof(dot), Tuple{Foo{Tuple{Int64}, 1}, Foo{Tuple{Int64}, 1}}}:
ERROR: iteration is deliberately unsupported for CartesianIndex. Use `I` rather than `I...`, or use `Tuple(I)...`
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:33
  [2] iterate(#unused#::CartesianIndex{1})
    @ Base.IteratorsMD ./multidimensional.jl:167
  [3] dot(x::CartesianIndex{1}, y::CartesianIndex{1})
    @ LinearAlgebra /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/generic.jl:876
  [4] dot(x::Tuple{CartesianIndex{1}}, y::Tuple{CartesianIndex{1}})
    @ LinearAlgebra /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/generic.jl:889
  [5] _broadcast_getindex_evalf
    @ ./broadcast.jl:648 [inlined]
  [6] _broadcast_getindex
    @ ./broadcast.jl:621 [inlined]
  [7] getindex
    @ ./broadcast.jl:575 [inlined]
  [8] getindex
    @ ~/.julia/packages/LazyArrays/lAt5J/src/lazybroadcasting.jl:88 [inlined]
  [9] _getindex
    @ ./abstractarray.jl:1209 [inlined]
 [10] getindex
    @ ./abstractarray.jl:1170 [inlined]
 [11] isassigned(::BroadcastVector{Int64, typeof(dot), Tuple{Foo{Tuple{Int64}, 1}, Foo{Tuple{Int64}, 1}}}, ::Int64, ::Int64)
    @ Base ./abstractarray.jl:513
 [12] alignment(io::IOContext{Base.TTY}, X::BroadcastVector{Int64, typeof(dot), Tuple{Foo{Tuple{Int64}, 1}, Foo{Tuple{Int64}, 1}}}, rows::UnitRange{Int64}, cols::UnitRange{Int64}, cols_if_complete::Int64, cols_otherwise::Int64, sep::Int64)
    @ Base ./arrayshow.jl:67
 [13] _print_matrix(io::IOContext{Base.TTY}, X::AbstractVecOrMat{T} where T, pre::String, sep::String, post::String, hdots::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64, rowsA::UnitRange{Int64}, colsA::UnitRange{Int64})
    @ Base ./arrayshow.jl:201
 [14] #invokelatest#2
    @ ./essentials.jl:708 [inlined]
 [15] invokelatest
    @ ./essentials.jl:706 [inlined]
 [16] print_matrix(io::IOContext{Base.TTY}, X::AbstractVecOrMat{T} where T, pre::String, sep::String, post::String, hdots::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64) (repeats 2 times)
    @ Base ./arrayshow.jl:170
 [17] print_array
    @ ./arrayshow.jl:327 [inlined]
 [18] show(io::IOContext{Base.TTY}, #unused#::MIME{Symbol("text/plain")}, X::BroadcastVector{Int64, typeof(dot), Tuple{Foo{Tuple{Int64}, 1}, Foo{Tuple{Int64}, 1}}})
    @ Base ./arrayshow.jl:368
 [19] display(d::REPL.REPLDisplay{REPL.LineEditREPL}, mime::MIME{Symbol("text/plain")}, x::BroadcastVector{Int64, typeof(dot), Tuple{Foo{Tuple{Int64}, 1}, Foo{Tuple{Int64}, 1}}})
    @ OhMyREPL ~/.julia/packages/OhMyREPL/07uNa/src/output_prompt_overwrite.jl:8
 [20] display(d::REPL.REPLDisplay, x::Any)
    @ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:225
 [21] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:328
 [22] #invokelatest#2
    @ ./essentials.jl:708 [inlined]
 [23] invokelatest
    @ ./essentials.jl:706 [inlined]
 [24] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
    @ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:247
 [25] (::REPL.var"#40#41"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:231
 [26] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:462
 [27] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:229
 [28] (::REPL.var"#do_respond#61"{Bool, Bool, REPL.var"#72#82"{REPL.LineEditREPL, REPL.REPLHistoryProvider}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:798
 [29] #invokelatest#2
    @ ./essentials.jl:708 [inlined]
 [30] invokelatest
    @ ./essentials.jl:706 [inlined]
 [31] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/LineEdit.jl:2441
 [32] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:1126
 [33] (::REPL.var"#44#49"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL ./task.jl:406

julia> b = [(1,), (2,), (3,), (4,), (5,)]
5-element Vector{Tuple{Int64}}:
 (1,)
 (2,)
 (3,)
 (4,)
 (5,)

julia> a == b
true

julia> @time LazyArray(@~ (dot.(b,b)))
  0.027901 seconds (60.52 k allocations: 3.896 MiB, 99.12% compilation time)
dot.(5-element Vector{Tuple{Int64}}, 5-element Vector{Tuple{Int64}}):
  1
  4
  9
 16
 25

julia> @time LazyArray(@~ sum.(a) .* 1)
  0.033343 seconds (132.34 k allocations: 8.729 MiB, 98.92% compilation time)
(sum.(5-element Foo{Tuple{Int64}, 1})) .* (Int64):
Error showing value of type BroadcastVector{Int64, typeof(*), Tuple{BroadcastVector{Int64, typeof(sum), Tuple{Foo{Tuple{Int64}, 1}}}, Int64}}:
ERROR: MethodError: no method matching +(::CartesianIndex{1})
Closest candidates are:
  +(::CartesianIndex{N}, ::CartesianIndex{N}) where N at multidimensional.jl:114
  +(::Any, ::Any, ::Any, ::Any...) at operators.jl:560
  +(::T, ::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8} at int.jl:87
  ...
Stacktrace:
  [1] sum(x::Tuple{CartesianIndex{1}})
    @ Base ./tuple.jl:474
  [2] _broadcast_getindex_evalf
    @ ./broadcast.jl:648 [inlined]
  [3] _broadcast_getindex
    @ ./broadcast.jl:621 [inlined]
  [4] _getindex
    @ ./broadcast.jl:644 [inlined]
  [5] _broadcast_getindex
    @ ./broadcast.jl:620 [inlined]
  [6] getindex
    @ ./broadcast.jl:575 [inlined]
  [7] getindex
    @ ~/.julia/packages/LazyArrays/lAt5J/src/lazybroadcasting.jl:88 [inlined]
  [8] _getindex
    @ ./abstractarray.jl:1209 [inlined]
  [9] getindex
    @ ./abstractarray.jl:1170 [inlined]
 [10] isassigned(::BroadcastVector{Int64, typeof(*), Tuple{BroadcastVector{Int64, typeof(sum), Tuple{Foo{Tuple{Int64}, 1}}}, Int64}}, ::Int64, ::Int64)
    @ Base ./abstractarray.jl:513
 [11] alignment(io::IOContext{Base.TTY}, X::BroadcastVector{Int64, typeof(*), Tuple{BroadcastVector{Int64, typeof(sum), Tuple{Foo{Tuple{Int64}, 1}}}, Int64}}, rows::UnitRange{Int64}, cols::UnitRange{Int64}, cols_if_complete::Int64, cols_otherwise::Int64, sep::Int64)
    @ Base ./arrayshow.jl:67
 [12] _print_matrix(io::IOContext{Base.TTY}, X::AbstractVecOrMat{T} where T, pre::String, sep::String, post::String, hdots::String, vdots::String, ddots::String, hmod::Int64, vmod::Int64, rowsA::UnitRange{Int64}, colsA::UnitRange{Int64})
    @ Base ./arrayshow.jl:201
 [13] #invokelatest#2
    @ ./essentials.jl:708 [inlined]
 [14] invokelatest
    @ ./essentials.jl:706 [inlined]
 [15] print_matrix (repeats 2 times)
    @ ./arrayshow.jl:170 [inlined]
 [16] print_array
    @ ./arrayshow.jl:327 [inlined]
 [17] show(io::IOContext{Base.TTY}, #unused#::MIME{Symbol("text/plain")}, X::BroadcastVector{Int64, typeof(*), Tuple{BroadcastVector{Int64, typeof(sum), Tuple{Foo{Tuple{Int64}, 1}}}, Int64}})
    @ Base ./arrayshow.jl:368
 [18] display(d::REPL.REPLDisplay{REPL.LineEditREPL}, mime::MIME{Symbol("text/plain")}, x::BroadcastVector{Int64, typeof(*), Tuple{BroadcastVector{Int64, typeof(sum), Tuple{Foo{Tuple{Int64}, 1}}}, Int64}})
    @ OhMyREPL ~/.julia/packages/OhMyREPL/07uNa/src/output_prompt_overwrite.jl:8
 [19] display(d::REPL.REPLDisplay, x::Any)
    @ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:225
 [20] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:328
 [21] #invokelatest#2
    @ ./essentials.jl:708 [inlined]
 [22] invokelatest
    @ ./essentials.jl:706 [inlined]
 [23] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{Nothing, AbstractDisplay})
    @ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:247
 [24] (::REPL.var"#40#41"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:231
 [25] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:462
 [26] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:229
 [27] (::REPL.var"#do_respond#61"{Bool, Bool, REPL.var"#72#82"{REPL.LineEditREPL, REPL.REPLHistoryProvider}, REPL.LineEditREPL, REPL.LineEdit.Prompt})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:798
 [28] #invokelatest#2
    @ ./essentials.jl:708 [inlined]
 [29] invokelatest
    @ ./essentials.jl:706 [inlined]
 [30] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/LineEdit.jl:2441
 [31] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/REPL/src/REPL.jl:1126
 [32] (::REPL.var"#44#49"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL ./task.jl:406

julia> @time LazyArray(@~ sum.(b) .* 1)
  0.000017 seconds (8 allocations: 224 bytes)
(sum.(5-element Vector{Tuple{Int64}})) .* (Int64):
 1
 2
 3
 4
 5
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

No branches or pull requests

1 participant