Conversation
|
@bob-carpenter, I just looked at the ragged structures (and not the closures) doc. It looks great! Really great. One question: will we continue to have arrays be declared the way it currently is? As a concrete example: and should be equivalent. It seems like we'd want to keep the old syntax because it makes rectangular things pretty easy, but I can see how we might want to move the brackets before the variable instead of its current position. |
|
Yes, I still want to keep rectangular declarations for convenience. I want to deprecate and replace with so that the character sequence for the type is contiguous, i.e., |
|
This looks great. Thanks for writing this up @bob-carpenter! |
|
Definitely want to keep rectangular definitions. I'll make that
clearer.
Specifically, I want to deprecate
real x[2, 3];
in favor of keeping the types/sizes contiguous:
real[2, 3] x;
We're going to need this for tuples/structs anyway.
- Bob
… On Aug 7, 2019, at 6:49 AM, Daniel Lee ***@***.***> wrote:
@bob-carpenter, I just looked at the ragged structures (and not the closures) doc.
It looks great! Really great.
One question: will we continue to have arrays be declared the way it currently is? As a concrete example:
real x[2, 3];
and
real[{ {3}, {3} }] x;
should be equivalent. It seems like we'd want to keep the old syntax because it makes rectangular things pretty easy, but I can see how we might want to move the brackets before the variable instead of its current position.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
|
This looks great. Two questions:
Sebastian |
rok-cesnovar
left a comment
There was a problem hiding this comment.
A couple of questions and suggestions to update the doc now that we support the array[] T syntax.
| example is: | ||
|
|
||
| ``` | ||
| real[{3, 4}] x = {{a, b, c}, {d, e, f, g}}; |
There was a problem hiding this comment.
| real[{3, 4}] x = {{a, b, c}, {d, e, f, g}}; | |
| array[{3, 4}] real x = {{a, b, c}, {d, e, f, g}}; |
| We write the unsized type of `x` the same way as for rectangular two-dimensional arrays, | ||
|
|
||
| ``` | ||
| x : real[ , ] |
There was a problem hiding this comment.
| x : real[ , ] | |
| x : array[ , ] T |
| ``` | ||
|
|
||
| Declarations for ragged arrays are made up of the sizes of their | ||
| elements. Declaring `x` of type and size `real[{3, 4}]` declares `x` |
There was a problem hiding this comment.
| elements. Declaring `x` of type and size `real[{3, 4}]` declares `x` | |
| elements. Declaring `x` of type and size `array[{3, 4}] real` declares `x` |
| element in the sizing is the sizing of a ragged two-dimensional array. | ||
|
|
||
| ``` | ||
| real[{ {2, 3}, { 1, 2, 3 } }] y |
There was a problem hiding this comment.
| real[{ {2, 3}, { 1, 2, 3 } }] y | |
| array[{ {2, 3}, { 1, 2, 3 } }] real y |
| y[2] == {{h}, {i, j}, {k, l, m}} | ||
| ``` | ||
|
|
||
| The type of both `y[1]` and `y[2]` is `real[, ]`, the type of a |
There was a problem hiding this comment.
| The type of both `y[1]` and `y[2]` is `real[, ]`, the type of a | |
| The type of both `y[1]` and `y[2]` is `array[, ] real`, the type of a |
| probabilities, we can use | ||
|
|
||
| ``` | ||
| real<lower = 0, upper = 1>[{3, 4}] x = {{a, b, c}, {d, e, f, g}}; |
There was a problem hiding this comment.
| real<lower = 0, upper = 1>[{3, 4}] x = {{a, b, c}, {d, e, f, g}}; | |
| array[{3,4}] real<lower = 0, upper = 1> x = {{a, b, c}, {d, e, f, g}}; |
| We can declare a ragged array of simplexes as | ||
|
|
||
| ``` | ||
| simplex[{3, 2, 2}] theta |
There was a problem hiding this comment.
| simplex[{3, 2, 2}] theta | |
| array[3] simplex[{3, 2, 2}] theta |
| Ragged containers will play nicely with unsized local variables and | ||
| function arguments. | ||
|
|
||
| This proposal as written depends on allowing type declarations like: |
There was a problem hiding this comment.
This was implemented in Stan 2.25 where we now have array[...] real x, array[...] vector[N] a, etc. so we can remove the text below.
| cov_matrix[2][3] x | ||
| = { [[1, 0], [0, 1]], | ||
| [[3.1, -0.2], [-0.2, 3.1]], | ||
| [[15.2, 0.1], [0.1, 15.2]] }; |
There was a problem hiding this comment.
| cov_matrix[2][3] x | |
| = { [[1, 0], [0, 1]], | |
| [[3.1, -0.2], [-0.2, 3.1]], | |
| [[15.2, 0.1], [0.1, 15.2]] }; | |
| array[3] cov_matrix[2] x | |
| = { [[1, 0], [0, 1]], | |
| [[3.1, -0.2], [-0.2, 3.1]], | |
| [[15.2, 0.1], [0.1, 15.2]] }; |
There was a problem hiding this comment.
Question:
Do we also want to support
array[2] cov_matrix[{2, 2, 3}] x
= { [[1, 0], [0, 1]],
[[3.1, -0.2], [-0.2, 3.1]],
[[15.2, 0.1, 0.1], [0.1, 15.2, 0.1], [0.1, 0.1, 15.2]] };
| @@ -0,0 +1,608 @@ | |||
| - *Feature Name:* closures-fun-types | |||
There was a problem hiding this comment.
This wasnt intended for this PR I guess?
|
I also dont see any mention if Stan Math functions should support ragged arrays? array[{3, 4}] real x = {{a, b, c}, {d, e, f, g}};
array[{3, 4}] real y = sin(x);Should this work? If yes then I think adding tests for this in Stan Math should be mentioned somewhere in the docs. |
I think that's an independent question. It'd be great if we could extend unary function vectorization to them. I would not try to do arithmetic, but reductions like |
|
Ok, that does make stuff a bit easier then for Stan Math, but a bit more for stanc as we need to keep track at whats ragged and whats not. Thanks. |
|
@bob-carpenter and I just discussed this and I'd like to suggest an alternate syntax that makes the dimensionality of the final array much clearer. Based on how we do function argument typing, I think we could have a syntax like: array[3] int sizes = {3, 2, 3};
array[ , sizes] real = ...;We could even optionally allow Why? Because if I show you, |
|
I'd like to change the spec to work like @WardBrian suggests. |
|
@WardBrian I like that idea. It also clarifies the situation with And since we're likely to get tuples before ragged arrays I suggest matrix dimensions are given as 2-tuples and not two-element arrays. -matrix[{ {2, 3}, {3, 2}, {1, 2} }] v
+matrix[{ (2, 3), (3, 2), (1, 2) }] v
= { [[a, b, c], [d, e, f]],
[[g, h], [i, j], [k, l]],
[[m, n]] }; |
Ragged structures