including functions from external files

123 views
Skip to first unread message

David

unread,
Oct 24, 2014, 2:56:44 PM10/24/14
to stan-...@googlegroups.com
I love the ability to create user-defined functions.

I don't think the manual mentions an ability to include functions from a separate file. It seems like that would be pretty helpful. Is it in the plans?

Thanks,

Bob Carpenter

unread,
Oct 24, 2014, 3:51:57 PM10/24/14
to stan-...@googlegroups.com
Yes, it's on our medium term to-do list, so we're hoping we
can do something in a six to nine month time frame.

The plan's to just apply the C++ pre-processor to the Stan
program itself, which will support includes as well as macros
and ifdef (not that we'll be encouraging people to use those).

It introduces a headache in error reporting because we have
to keep track of the file and line number that we're in.
The preprocessor supports that but we need to figure out how
integrate it.

- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Bob Carpenter

unread,
Oct 24, 2014, 3:53:44 PM10/24/14
to stan-...@googlegroups.com
Oh, we also want to include a testing framework for
functions, which would make most sense for functions
defined in their own files.

The alternative plan would be to have some external
way to compile and link function includes that didn't
involve the preprocessor. But we definitely need to figure
this out. Among other things we want to supply a built-in
library of functions, and we'll need include to do that
efficiently and not drag down compile times.

- Bob

On Oct 24, 2014, at 2:56 PM, David <dch...@gmail.com> wrote:

David

unread,
Oct 24, 2014, 4:19:28 PM10/24/14
to stan-...@googlegroups.com
That's great. Thanks!

Gary Schultz

unread,
Aug 30, 2016, 2:41:12 PM8/30/16
to Stan users mailing list
Bob:

The C preprocessor would be really helpful for building real models. I'm finding I am repeating a lot of code, despite knowing that is bad form. 

I understand the earlier estimate was not a promise, but are you able to give an update on timing?

Thanks,
Gary

Ben Goodrich

unread,
Aug 30, 2016, 2:53:34 PM8/30/16
to Stan users mailing list
On Tuesday, August 30, 2016 at 2:41:12 PM UTC-4, Gary Schultz wrote:
The C preprocessor would be really helpful for building real models. I'm finding I am repeating a lot of code, despite knowing that is bad form. 

I understand the earlier estimate was not a promise, but are you able to give an update on timing?

#includes are supported by the stanc_builder function in rstan. Doing it in the Stan language generally is perhaps 6 to 9 months away.

Ben

Daniel Lee

unread,
Aug 30, 2016, 2:53:57 PM8/30/16
to stan-users mailing list
Hi Gary,

There's actually no reason you can't use the C preprocessor now to generate Stan files, if you were good at hooking together C tools. From RStan, there are includes (which isn't the general answer, but it works).


Daniel


To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+unsubscribe@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.

Gary Schultz

unread,
Aug 30, 2016, 5:05:12 PM8/30/16
to stan-...@googlegroups.com
Thanks for the update and suggestion, Ben. I'm using cmd stan. 

--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/ss5muNI3wDY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+unsubscribe@googlegroups.com.

To post to this group, send email to stan-...@googlegroups.com.

Gary Schultz

unread,
Aug 30, 2016, 5:11:06 PM8/30/16
to stan-...@googlegroups.com
Yes, but it is a little messy, especially if you like to use line numbers to find errors that the compiler finds. 
I was really hoping that the "right' way of doing it would come out soon and save me from inventing another layer of indirection in my code. Sounds like it is a ways off yet.

Thanks for your response.

Gary

--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/ss5muNI3wDY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages