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

Vectorised versions of composed functions #1683

Closed
avehtari opened this issue Nov 11, 2015 · 3 comments
Closed

Vectorised versions of composed functions #1683

avehtari opened this issue Nov 11, 2015 · 3 comments
Assignees
Milestone

Comments

@avehtari
Copy link
Collaborator

Version

2.8.0

Category

improved functions

Description

Stan reference section 31.13 lists several composed functions, which accept only real argument and return value is real. It would be useful if they would accept also vector argument and return vector. And same for array, row_vector and matrix...

Example

For example, in addition to

real log1p(real x);

it would be useful to have also the following defined pointwise

vector log1p(vector x)
row_vector log1p(row_vector x);
matrix log1p(matrix x);
real[] log1p(real[]);

We could also extend this so that it handled arbitrary containers, so arrays of vectors or matrices, 2D arrays, etc. The main issue is going to be checking that the shapes are the same for functions of more than one argument.

Example Stan model can be found in
https://groups.google.com/forum/#!topic/stan-users/C6IxqRU1Cuw
This Stan model includes user defined function

vector log1pv(vector y)

which is used in user defined functions gpareto_log and gpareto_ccdf.

Multi-argument functions, shape matching, and broadcasting

  • Allow any number of arguments with matching shapes
  • Broadcast lower-dimensional up to higher-dimensional

Thus if we have a function of signature

foo(real, real) : real

and v is a vector of size N and c is a scalar, then

foo(v, a)  =def=  { foo(v[1], a), foo(v[2], a), ..., foo(v[N], a) }
@bob-carpenter bob-carpenter added this to the v3 milestone Nov 11, 2015
@bob-carpenter bob-carpenter self-assigned this Nov 11, 2015
@bob-carpenter
Copy link
Contributor

Thanks, Aki. I'm assigning myself to this at least temporarily and targeting v3.

  1. We need to scope out which functions to vectorize. We should really do them all.
  2. I think this should be done via class static template functions which we can easily pass in via generic template functions to do this for 1, 2, and 3 arguments. I'll code up examples.

@bob-carpenter
Copy link
Contributor

This first has to be done in stan-dev/math; see stan-dev/math#202

@bob-carpenter
Copy link
Contributor

This is already finished for unary functions and underway for binary functions working up from stan-dev/math, so I'm closing this issue.

@syclik syclik modified the milestones: v3, v2.13.0 Nov 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants