Can a user-defined function call another user-defined function

Is that possible for a user-defined function calling another user-defined function in Stan chunk functions? For instance, I defined two functions build_b_spline and g. My second function g is supposed to call build_b_spline inside. When I tried to complied my codes, it looks the g function is not able to find the first function build_b_spline. Could anyone help to clarify this? Thanks in advance.

functions {

 {vector **build_b_spline** {Details omitted} }

{
vector **g** (int[] t, real[] ext_knots, int ind, int order)
     {
      vector[size(t)] bs_basis;
      bs_basis=build_b_spline(t, ext_knots, ind, order);
      return bs_basis;
      }
}

} 

Can you post your full model and the full error you get when running it?

Hi Andrew,

The first used-defined function build_b_spline is in the website https://mc-stan.org/users/documentation/case-studies/splines_in_stan.html. Sorry that I cannot copy it

here since it is under license.

The second function g is wrote my my self. Please see the attached picture for the errors.

Thanks.

Yan

The error indicates that build_b_spline is expecting the first argument (t) to have type real[] (i.e., an array of reals), but you’re passing an array of integers (i.e., int[]).

You either need to change the declaration of build_b_spline to expect the first argument to have type int[], or you need to change the type of data that you’re passing to it (i.e., you need t to have type real[])

Hi Andrew,

Thank you so much for quickly pointing out the issues! It works now with no problem with your suggestion!

Thank you again. Glad it can be fixed :)

Good night.

Yan

1 Like

You can copy-paste bsd3 licence here. There shouldn’t be any problems with that.

Hi Andrew,

Thanks for pointing out this. I think I need to keep the copy right notice and the disclaimer if I need to copy-past bsd3 license here, right?

@martinmodrak do we have any rules/recommendations about this?

That’s a good technical point. I am not a copyright lawyer, so the following is an informed speculation at best.

  • It is unclear exactly at which point a piece of code becomes copyrightable. In most jurisdictions, copyright requires that there was a “creative act”. So I almost definitely can’t copyright a piece of code like real my_log(real a) { return log(a);}. The build_b_spline function in question would IMHO most likely be copyrightable, but that does not mean all code snippets we share on the forums are. There is a wide gray zone.

  • It is usually considered sufficient to link to a license or - for popular licenses - just mention the license name (instead of copying the exact license text). Note that the case study with the original code does exactly that. This hinges on a somewhat liberal interpretation of “retain the above copyright notice”, but I find it extremely unlikely this could be challenged.

  • In our Terms of service we say that all user posted content is licensed as Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. So reposting anything already licensed under almost any CC license is OK without any further comment. Practically, I think mixing and matching broadly permissive licenses, especially swapping loose license (e.g. BSD 3-clause) for more restrictive (e.g. CC BY-NC-SA) is quite OK and unlikely (though not impossible) to be challenged in practice - anyone challenging would need to show standing (i.e. it would almost certainly need to be the author of the code). Then, they should ask us to remove the offending content (e.g. a DMCA notice) and if we comply, then they would need to show actual harm caused by the differing license to ask for compensation.

To summarise: I think @ygao43 is technically right, but the requirements of “retaining” the license should be easy to satisfy. The harder problem is that our ToS says that all content is CC BY-NC-SA 3.0, and @ygao43 is definitely unable to relicense the code themselves to match our ToS.

It might be worthwhile for us to think about rewording the licensing terms in our ToS to allow people to explicitly add a different free license to (a part of) their post. This would IMHO resolve similar issues completely.

2 Likes

Hi Martin,

Glad to see your detailed explanation. It makes more sense now. I am quite new to Stan and there are so much to learn, including the copyright of the coding.

Thank you.

Yan

1 Like