Skip to content
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

regular array and vector constructor functions #838

Closed
bob-carpenter opened this issue Apr 13, 2018 · 6 comments
Closed

regular array and vector constructor functions #838

bob-carpenter opened this issue Apr 13, 2018 · 6 comments

Comments

@bob-carpenter
Copy link
Contributor

Summary:

Create functions to create regular arrays.

Here's one from MATLAB (also related to Python range):

/**
 * Return vector of evenly spaced elements with given minimum and maximum.  Behavior for size = 0 and size = 1 to be determined.  Requires min <= max.
 */
vector linspace_vector(real min, real max, int size);

There could also be linspace_array and linspace_row_vector versions. It might be possible to call the vector or array version just linspace.

Python provides range, which is a bit different.

/**
 * Return sequence of numbers min, min + by, min + 2*by, ...
 * up to but not including max.  Requires min <= max and by > 0.
 */
vector range_vector(real min, real max, real by);

In R, there's a function seq that allows either of these parameterizations, but we don't want to follow that redundant pattern.

This one's a suggestion from peterzh on http://discourse.mc-stan.org/t/create-vector-from-a-number-range/3760.

This will then get pushed through to Stan.

Current Version:

v2.17.0

@bob-carpenter bob-carpenter added this to the v3.0.0 milestone Apr 13, 2018
@bob-carpenter bob-carpenter changed the title regular array creation functions regular array and vector constructor functions Apr 13, 2018
@linwangidd
Copy link

function for creating regular arrays is still not available?

@bob-carpenter
Copy link
Contributor Author

Correct. It's easy to write one yourself and Stan gets compiled to efficient code, so we haven't prioritized this. If someone builds it, we'll accept a PR for this.

@mcol
Copy link
Contributor

mcol commented Feb 1, 2020

In #1636 we have added spaced_vector and friends, but I now think that linspace_vector could be a better name, as it matches what matlab, numpy and Eigen use. This will allow us to add a logspace_vector if we ever wanted. @bob-carpenter do you have an opinion?

@bob-carpenter
Copy link
Contributor Author

bob-carpenter commented Feb 2, 2020 via email

@mcol
Copy link
Contributor

mcol commented Feb 2, 2020

These are not exposed yet, so we are free to pick what we want. I also think 'linspaced_vector would work well, so we could go with that.

@mcol
Copy link
Contributor

mcol commented Feb 3, 2020

The range function as described here (with size of the resulting vector deduced rather than predeclared) would limit the uses of this function to only some contexts (see #1666 (comment), and #1666 (comment)).

@mcol mcol closed this as completed Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants