Distinguishing between scalar rvars and arrays-of-size-1
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
Línea de trabajo
Comienza revisando las funciones de conversión de rvar, el manejo de dim() y draws_of(), y los helpers para aplanar y desaplanar índices de arrays descritos en el issue. Primero determina si debe preservarse la identidad entre un escalar y un array de tamaño uno; se considera terminado cuando el comportamiento elegido está documentado y los round trips de conversión distinguen estos casos de forma coherente o los unifican intencionadamente.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Copying @martinmodrak's post from discourse here since it should probably be resolved in some way:
Hi,
it appears that the rvar interface in posterior cannot distinguish between a scalar and array of size 1, i.e.scalar <- draws_matrix("y" = 1:10) array1 <- draws_matrix("y[1]" = 1:10) all.equal(scalar, array1) # Correctly unequal # [1] "Attributes: < Component “dimnames”: Component “variable”: 1 string mismatch >" all.equal(as_draws_rvars(scalar), as_draws_rvars(array1)) # Incorrectly equal # [1] TRUE all.equal(as_draws_matrix(as_draws_rvars(array1)), array1) # Incorrectly unequal # [1] "Attributes: < Component “dimnames”: Component “variable”: 1 string mismatch >"Is this the desired/expected behaviour? Or is this a bug?
Also copying my thoughts from later in the thread:
Hmm. One behavior that base R vectors do that I did not mimic in rvars because it creates many corner cases in code is that vectors do not require a dim attribute (i.e.
dim(x)can beNULL), whereas rvars will always return a numeric vector for dim (sometimes it's just the length of the vector). I did this because otherwise a bunch of code has to check forNULLdims and use length instead, which at the time did not seem useful.That said, one way to distinguish between a "scalar" in base R and an array of size 1 is if
dim(x) == NULLordim(x) == 1. So one option would be to have the conversion functions recognize this convention. It will be slightly annoying to fix since we'd have to check all uses ofdim()on rvars in the code that assumedim()is guaranteed non-null, and other functions that assume the internal array always has at least two dimensions (since currently this is also guaranteed). This would also mean the value ofdraws_of()returned to a user would not be guaranteed to have at least two dimensions. I'm also not sure if this would make some other operations on rvars kind of annoying to use if they are returning values that the user would expect to be treated as scalar when converted to other formats but which are actually 1-element arrays.The other option would be a more focused solution that just uses an attribute, as you suggest. It might be an attribute for array-ness rather than scalar-ness; then 1-element arrays that get converted to rvars from another format could retain their array-ness through this attribute. Would be curious what folks think. (I'm not sure either solution sounds great to me at the moment, at least from the perspective of implementing it :) )
Another idea that occurred to me if we don't want to change how rvars treat scalars versus arrays-of-1 would be to instead expose the helper functions for flattening/unflattening array indices, since it sounds (maybe) like that's what you were intending to use the rvar stuff for @martinmodrak?
- Lenguaje dominante
- R
- Estrellas
- 172
- Forks
- 27
- Merge medio
- 5 d 12 h
- PR fusionados (30 d)
- 5
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de stan-dev/posterior
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
-
Use testthat 3ePosiblemente ocupada @mcol la tomó hace 7 días. Abiertogood first issue test
Dificultad 3/5 1-2 días Aptitud para principiantes 65/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
Todos los issues de stan-dev/posterior
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 68/100
cran-task-views/Spatial#127 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Add two cautions to the `simulate_dyad_responses()` helpPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertodocumentation priority: low
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Pascal-Kueng/dyadMLM#179 ·
Los mantenedores suelen responder en 1 día
-
Consider changesAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
OHDSI/OmopSketch#618 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
GSK-Biostatistics/tfrmt#854 ·