-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Creating empty arrays with {} #1286
Comments
It’s definitely intentional in the sense that it’s what our parser encodes: stanc3/src/frontend/parser.mly Line 579 in c8bae8b
Now I’m not sure whether or not it’s necessary. My first guess is that you might get ambiguities between an empty array expression and an empty block, but I can try it out today and see. |
I think the main problem is type inference. It would be weirdly limiting if the type of functions {
real f(array[,] real x) {
return 1.0;
}
real f(array[] vector x) {
return 0.0;
}
real g() {
return f({}); // which overload is it?
}
} |
I think your right. We actually would disallow it in the typechecker even if it parsed, see stanc3/src/frontend/Typechecker.ml Lines 317 to 321 in c8bae8b
C++ allows empty initializer lists but only if they're unambiguous, e.g. https://godbolt.org/z/MdEKhsdMh |
Would it be possible to allow unambiguous null arrays then? Like |
That is still ambiguous in the number of dimensions. How often is this something somebody would want to have? |
Wouldn't 2d be |
I just think it seems like you should be able to construct an empty array like you can a non-empty one. At the minimum, pointing out in the docs that empty arrays cannot be initialized like this seems necessary. |
Huh, that would be a kind of expression altogether. I don't think that makes a ton of sense, since You could write Initializing an empty array is not necessary, since there is only one empty array of a given type, e.g. all |
Good example and I wouldn't want a ton of work put into this because it wouldn't be something people do that often. There's also the easy work around of creating the empty array before using the |
You can write |
Agreed. Where do you think that should go in the reference manual and/or user's guide? Would you mind opening a docs issue for this?
It's easy to think that until you consider what the type should be. While it's tempting to assign The only solution now with an expression is what @nhuure suggests---just use the array constructors transformed data {
array[0] int empty_int_array;
} |
Opened a docs issue at stan-dev/docs#621. I believe the relevant section is in the reference manual linked at the aforementioned docs issue. |
I'm going to close this in favor of the docs issue you created @spinkney |
Is it intended that {} can't be parsed as an empty arrray?
I was trying to pass an empty array into a recursive function with the first iteration and found that I needed to create it as
array[0]
.The text was updated successfully, but these errors were encountered: