Size behavior is not consistent for function arguments
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 839
- Forks
- 220
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 14
Description
Summary:
Size of a vector behaves differently from num_elements for function argument.
Description:
The variable used for size function is a function argument, declared as a vector.
Size of a vector returns error during compilation but num_elements does not.
Reproducible Steps:
The current calculation I am working with uses a function with vector type argument.
The size of this vector argument is used for further calculations.
num_elements seems to work fine but size fails.
If you have a reproducible example, please include it.
functions {
real test(vector x){
real N = size(x);
return(N)
}
}
Current Output:
The current output. Knowing what is the current behavior is useful.
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
No matches for:
size(vector)
Available argument signatures for size:
size(int[ ])
size(real[ ])
size(vector[ ])
size(row_vector[ ])
size(matrix[ ])
size(int[ , ])
size(real[ , ])
size(vector[ , ])
size(row_vector[ , ])
size(matrix[ , ])
size(int[ , , ])
size(real[ , , ])
size(vector[ , , ])
size(row_vector[ , , ])
size(matrix[ , , ])
size(int[ , , , ])
size(real[ , , , ])
size(vector[ , , , ])
size(row_vector[ , , , ])
size(matrix[ , , , ])
size(int[ , , , , ])
size(real[ , , , , ])
size(vector[ , , , , ])
size(row_vector[ , , , , ])
size(matrix[ , , , , ])
size(int[ , , , , , ])
size(real[ , , , , , ])
size(vector[ , , , , , ])
size(row_vector[ , , , , , ])
size(matrix[ , , , , , ])
size(int[ , , , , , , ])
size(real[ , , , , , , ])
size(vector[ , , , , , , ])
size(row_vector[ , , , , , , ])
size(matrix[ , , , , , , ])
error in 'model42374ed5bbb7_model_code' at line 5, column 20
-------------------------------------------------
3:
4: real test(vector x){
5: real N = size(x);
^
6: return(N)
-------------------------------------------------
Error in stanc(model_code = model_code) :
failed to parse Stan model 'model_code' due to the above error.
>
Expected Output:
No error should be generated, could match to size(vector[ ])
Additional Information:
Provide any additional information here.
Current Version:
v2.22.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied Stan function reproducer and compare how size(vector) is resolved with num_elements for function arguments. Trace the parser or signature-matching path responsible for the reported size(vector) error, then verify that the example compiles and returns the vector length without changing the existing array behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100