JuliaAPlavin / RectiGrids.jl

MIT License
2 stars 0 forks source link

Grid of symbolics #2

Closed jariji closed 8 months ago

jariji commented 8 months ago

Is this supposed to work?

julia> using Symbolics

julia> @variables xs[1:3]::Vector{LiteralReal} ys[1:4]::Vector{LiteralReal}
2-element Vector{Symbolics.Arr{Symbolics.Arr{Num, 1}, 1}}:
 xs[1:3]
 ys[1:4]

julia> xs[1]
(xs[1])[1:3]

julia> using RectiGrids

julia> grid(xs, ys)
2-dimensional KeyedArray(...) with keys:
↓   3-element Symbolics.Arr{Symbolics.Arr{Num,...}
→   4-element Symbolics.Arr{Symbolics.Arr{Num,...}
And data, 3×4 RectiGrids.RectiGridArr{Base.OneTo(2), Tuple{Vector{LiteralReal}, Vector{LiteralReal}}, 2, Tuple{Nothing, Nothing}, Tuple{Symbolics.Arr{Symbolics.Arr{Num, 1}, 1}, Symbolics.Arr{Symbolics.Arr{Num, 1}, 1}}}:
Error showing value of type KeyedArray{Tuple{Vector{LiteralReal}, Vector{LiteralReal}}, 2, RectiGrids.RectiGridArr{Base.OneTo(2), Tuple{Vector{LiteralReal}, Vector{LiteralReal}}, 2, Tuple{Nothing, Nothing}, Tuple{Symbolics.Arr{Symbolics.Arr{Num, 1}, 1}, Symbolics.Arr{Symbolics.Arr{Num, 1}, 1}}}, Tuple{Symbolics.Arr{Symbolics.Arr{Num, 1}, 1}, Symbolics.Arr{Symbolics.Arr{Num, 1}, 1}}}:
ERROR: axes of ((xs[Base.Slice(Base.OneTo(3))])[1]) not known

This works with Base stuff

julia> collect(Iterators.product(xs, ys))
3×4 OffsetArray(::Matrix{Tuple{Symbolics.Arr{Num, 1}, Symbolics.Arr{Num, 1}}}, 1:3, 1:4) with eltype Tuple{Symbolics.Arr{Num, 1}, Symbolics.Arr{Num, 1}} with indices 1:3×1:4:
 ((xs[1])[1:3], (ys[1])[1:4])  …  ((xs[1])[1:3], (ys[4])[1:4])
 ((xs[2])[1:3], (ys[1])[1:4])     ((xs[2])[1:3], (ys[4])[1:4])
 ((xs[3])[1:3], (ys[1])[1:4])     ((xs[3])[1:3], (ys[4])[1:4])
(@main) pkg> st RectiGrids Symbolics
Status `~/.julia/environments/main/Project.toml`
  [8ac6971d] RectiGrids v0.1.18
  [0c5d862f] Symbolics v5.19.1

julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39b (2023-12-25 18:01 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 24 × AMD Ryzen 9 3900XT 12-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, znver2)
  Threads: 17 on 24 virtual cores
Environment:
  JULIA_NUM_THREADS = 12
  JULIA_PKG_PRESERVE_TIERED_INSTALLED = true
aplavin commented 8 months ago

I see Symbolics does something extremely weird here:

julia> T = eltype(xs)
Vector{LiteralReal} (alias for Array{LiteralReal, 1})

julia> xs[1] |> typeof
Symbolics.Arr{Num, 1}

julia> xs[1] isa T
false

julia> collect(xs)[1] isa T
false

It's not feasible to expect generic code to work when these fundamental assumptions are broken. I hope it's a bug in that package, not a design decision :)