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

Labelled slice fails in Julia 1.4.0 #83

Open
dutille opened this issue Jul 23, 2020 · 14 comments
Open

Labelled slice fails in Julia 1.4.0 #83

dutille opened this issue Jul 23, 2020 · 14 comments

Comments

@dutille
Copy link

dutille commented Jul 23, 2020

Hi,

When trying the examples of Labelled slices given here:
https://github.com/SciML/LabelledArrays.jl

I get errors. Here is how it goes:

julia> ABC = @SLSliced (3,2) (:a,:b,:c), (:x, :y)
SLArray{Tuple{3,2},Tuple{(:a, :b, :c),(:x, :y)},N,L,Syms} where Syms where L where N

julia> A = ABC([1 2; 3 4; 5 6])
3×2 SLArray{Tuple{3,2},Int64,2,6,Tuple{(:a, :b, :c),(:x, :y)}} with indices SOneTo(3)×SOneTo(2):
Error showing value of type SLArray{Tuple{3,2},Int64,2,6,Tuple{(:a, :b, :c),(:x, :y)}}:
ERROR: ArgumentError: invalid index: :a of type Symbol
Stacktrace:
[1] to_index(::Symbol) at ./indices.jl:297
[2] to_index(::LinearIndices{2,Tuple{StaticArrays.SOneTo{3},StaticArrays.SOneTo{2}}}, ::Symbol) at ./indices.jl:274
[3] to_indices at ./indices.jl:325 [inlined]
[4] to_indices at ./indices.jl:321 [inlined]
[5] getindex at ./abstractarray.jl:980 [inlined]
[6] (::LabelledArrays.var"#53#54"{Tuple{Int64,Int64},LinearIndices{2,Tuple{StaticArrays.SOneTo{3},StaticArrays.SOneTo{2}}}})(::Tuple{Symbol,Symbol,Symbol}) at /Users/dutilleu/.julia/packages/LabelledArrays/74Tbn/src/LabelledArrays.jl:37
[7] findfirst(::LabelledArrays.var"#53#54"{Tuple{Int64,Int64},LinearIndices{2,Tuple{StaticArrays.SOneTo{3},StaticArrays.SOneTo{2}}}}, ::Tuple{Tuple{Symbol,Symbol,Symbol},Tuple{Symbol,Symbol}}) at ./array.jl:1776
[8] lazypair at /Users/dutilleu/.julia/packages/LabelledArrays/74Tbn/src/LabelledArrays.jl:35 [inlined]
[9] getindex at /Users/dutilleu/.julia/packages/LabelledArrays/74Tbn/src/LabelledArrays.jl:30 [inlined]
[10] isassigned(::LabelledArrays.PrintWrapper{Int64,2,typeof(LabelledArrays.lazypair),SLArray{Tuple{3,2},Int64,2,6,Tuple{(:a, :b, :c),(:x, :y)}}}, ::Int64, ::Int64) at ./abstractarray.jl:404
[11] alignment(::IOContext{REPL.Terminals.TTYTerminal}, ::LabelledArrays.PrintWrapper{Int64,2,typeof(LabelledArrays.lazypair),SLArray{Tuple{3,2},Int64,2,6,Tuple{(:a, :b, :c),(:x, :y)}}}, ::UnitRange{Int64}, ::UnitRange{Int64}, ::Int64, ::Int64, ::Int64) at ./arrayshow.jl:67
[12] print_matrix(::IOContext{REPL.Terminals.TTYTerminal}, ::LabelledArrays.PrintWrapper{Int64,2,typeof(LabelledArrays.lazypair),SLArray{Tuple{3,2},Int64,2,6,Tuple{(:a, :b, :c),(:x, :y)}}}, ::String, ::String, ::String, ::String, ::String, ::String, ::Int64, ::Int64) at ./arrayshow.jl:189
[13] print_matrix at ./arrayshow.jl:162 [inlined]
[14] print_array at ./arrayshow.jl:310 [inlined]
[15] show(::IOContext{REPL.Terminals.TTYTerminal}, ::SLArray{Tuple{3,2},Int64,2,6,Tuple{(:a, :b, :c),(:x, :y)}}) at /Users/dutilleu/.julia/packages/LabelledArrays/74Tbn/src/LabelledArrays.jl:51
[16] show(::IOContext{REPL.Terminals.TTYTerminal}, ::MIME{Symbol("text/plain")}, ::SLArray{Tuple{3,2},Int64,2,6,Tuple{(:a, :b, :c),(:x, :y)}}) at /Users/dutilleu/.julia/packages/LabelledArrays/74Tbn/src/LabelledArrays.jl:42
[17] display(::REPL.REPLDisplay{REPL.LineEditREPL}, ::MIME{Symbol("text/plain")}, ::SLArray{Tuple{3,2},Int64,2,6,Tuple{(:a, :b, :c),(:x, :y)}}) at /Users/dutilleu/.julia/packages/OhMyREPL/7qVFi/src/output_prompt_overwrite.jl:6
[18] display(::REPL.REPLDisplay, ::Any) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:141
[19] display(::Any) at ./multimedia.jl:323
[20] #invokelatest#1 at ./essentials.jl:712 [inlined]
[21] invokelatest at ./essentials.jl:711 [inlined]
[22] print_response(::IO, ::Any, ::Bool, ::Bool, ::Any) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:161
[23] print_response(::REPL.AbstractREPL, ::Any, ::Bool, ::Bool) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:146
[24] (::REPL.var"#do_respond#38"{Bool,REPL.var"#48#57"{REPL.LineEditREPL,REPL.REPLHistoryProvider},REPL.LineEditREPL,REPL.LineEdit.Prompt})(::Any, ::Any, ::Any) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:729
[25] #invokelatest#1 at ./essentials.jl:712 [inlined]
[26] invokelatest at ./essentials.jl:711 [inlined]
[27] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/LineEdit.jl:2354
[28] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:1055
[29] run_repl(::REPL.AbstractREPL, ::Any) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:206
[30] (::Base.var"#764#766"{Bool,Bool,Bool,Bool})(::Module) at ./client.jl:383
[31] #invokelatest#1 at ./essentials.jl:712 [inlined]
[32] invokelatest at ./essentials.jl:711 [inlined]
[33] run_main_repl(::Bool, ::Bool, ::Bool, ::Bool, ::Bool) at ./client.jl:367
[34] exec_options(::Base.JLOptions) at ./client.jl:305
[35] _start() at ./client.jl:484

The regular array example fails also.

I am running:

Julia Version 1.4.0
Commit b8e9a9ecc6 (2020-03-21 16:36 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin18.6.0)
CPU: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-8.0.1 (ORCJIT, haswell)

Any idea?
Kind regards,

Guillaume

@ChrisRackauckas
Copy link
Member

The regular array example fails also.

What do you mean?

Looks like a type definition is missing: https://github.com/SciML/LabelledArrays.jl/blob/master/test/lsliced.jl#L72

z = @LSliced Float64 (4,2) (:a,:b,:c,:d), (:x, :y)

@dutille
Copy link
Author

dutille commented Jul 23, 2020 via email

@ChrisRackauckas
Copy link
Member

Yes but what about with the element type like I pointed to?

@dutille
Copy link
Author

dutille commented Jul 23, 2020 via email

@ChrisRackauckas
Copy link
Member

What version are you on? Julia v1.4 and the latest LabelledArrays?

@dutille
Copy link
Author

dutille commented Jul 23, 2020 via email

@ChrisRackauckas
Copy link
Member

Oh, this never got looked at: #56 @rafaqz

For now, I'd recommend SLArrays until we work this out.

@rafaqz
Copy link
Contributor

rafaqz commented Jul 23, 2020

Sorry I never got around to this, too many other packages.

Personally I have switched to using DimensionalData.jl for this. You can pass a tuple wrapped in Val into a dimension
and it will work the same as the sliced mode does here, with zero cost indexing using symbols, and more things coming.

I've been meaning to put in a PR removing the sliced mode here, and directing people to DimentionalData.jl, which is probably a better fit for this kind of functionality as it's all about dimensional slicing, I just hadn't started writing it yet when I wrote the sliced mode here.

@ChrisRackauckas
Copy link
Member

that probably makes sense.

@rafaqz
Copy link
Contributor

rafaqz commented Jul 23, 2020

Ok, I'll need to improve the docs a little for this at DimensionalData.jl as this functionality is only a few weeks old, then I'll clean up here.

@yakir12
Copy link

yakir12 commented Sep 28, 2020

Friendly ping that this is an issue for me. I managed without it, but just saying this fine piece of machinery is useful to me as well.

@JTaets
Copy link

JTaets commented Sep 8, 2021

Like @yakir12, I friendly disagree here with the idea to remove this in favor of DimensionalData.jl

As far as i know, DimensionalData.jl only allows named dimensions (I could be wrong).
I could be wrong, but something like this is not possible

using LabelledArrays
z = @LArray [1.,2.,3.] (a = 1:2, b = 2:3)
julia> z.a
2-element view(::Vector{Float64}, 1:2) with eltype Float64:
 1.0
 2.0
julia> z.b
2-element view(::Array{Float64,1}, 2:3) with eltype Float64:
 2.0
 3.0

Why i think this is useful for SciML:
Now since the parameter vector is required to be an array, it is quite hard to know which parameter(slice) is where in the parameter vector, when they come from different sources.

For example if p = vcat(model_parameters, control_parameters). then when we need to have the control_parameters, we need to do p[length(model_parameters)+1:end], where we somehow hope that we still know the length of model_parameters by the time we want to acces the control parameters.
This is very unreadable and becomes more complex with the amount of parameters used.
Moreover, we can name each individual element of the parameter vector like p.gravity.

This package helps the syntax alot.
This would be very useful for me when #91 is fixed.

@ChrisRackauckas
Copy link
Member

Wouldn't ComponentArrays.jl do that well?

@JTaets
Copy link

JTaets commented Sep 9, 2021

Yes it does, somehow completely missed the existence of that package. Thank you very much!

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

5 participants