Known issues with VNT, part 3 -- multiindex-upon-multiindex can give wrong keys with ArrayLikeBlocks

Aperta
#1,208 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
28/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
julia
Ambito
backend

Direzione di ricerca

Riproduci l’esempio con templated_setindex!!, @varname(x[2:4][1:2]) e un ArrayLikeBlock, quindi esamina come vengono utilizzati gli indici di ArrayLikeBlock e le posizioni di PartialArray per formare le chiavi. Il lavoro è completato quando keys(vnt) segnala le posizioni effettivamente memorizzate, come x[2] e x[3], invece di x[1:2], senza alterare i dati posizionati correttamente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

data-structures enhancement
using DynamicPPL
using DynamicPPL: templated_setindex!!

struct A end
Base.size(::A) = (2,)

vnt = VarNamedTuple()
vnt = templated_setindex!!(vnt, A(), @varname(x[2:4][1:2]), randn(4))

keys(vnt)
# 1-element Vector{VarName}:
#  x[1:2]

Here, we are setting indices 2 and 3 of the parent array x. However, keys(vnt) reports [1:2].

The reason for this is because the index in the key is obtained from the ArrayLikeBlock that is used to store the sized thing. In turn, the ArrayLikeBlock's indices are obtained from the indices that were used to initially set it inside the array, which were 1:2 -- it has no way of knowing that there was a 2:4 that came before it.

If this was x[1:N][P:Q] this would actually work perfectly fine for any N,P,Q but this issue is a worst-case scenario where the first set of multiindices don't begin at 1.

The fact that the stored indices are wrong can also lead to weird results when merging two VNTs with data that is mislabelled like this.

Note that the ALBs are still stored in the correct position in the PartialArray (indices 2 and 3 are the actual thing that we stored -- the other two indices are junk data generated via undef, but are masked so will never be seen). It's just the keys that are weird.

julia> vnt.data.x.data
4-element Vector{DynamicPPL.VarNamedTuples.ArrayLikeBlock{A, Tuple{UnitRange{Int64}}, @NamedTuple{}, Tuple{Int64}}}:
 ArrayLikeBlock(A(), (4526817440:4526817488,), NamedTuple(), (4526817536,))
 ArrayLikeBlock(A(), (1:2,), NamedTuple(), (2,))
 ArrayLikeBlock(A(), (1:2,), NamedTuple(), (2,))
 ArrayLikeBlock(A(), (0:0,), NamedTuple(), (131330,))

(This is good: it means that if we store an array instead of an ALB, the keys will be correctly picked up, because they are in the right positions.)

vnt = VarNamedTuple()
vnt = templated_setindex!!(vnt, randn(2), @varname(x[2:4][1:2]), randn(4))

keys(vnt)
# 2-element Vector{VarName}:
#  x[2]
#  x[3]

I personally think this is niche enough that we shouldn't need to care about it.

Lingua principale
Julia
Stelle
291
Fork
43
Merge medio
1g 23h
PR unite (30g)
15

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TuringLang/DynamicPPL.jl

Tutte le issue di TuringLang/DynamicPPL.jl

Issue simili

Altre issue su Julia

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.