Convert real into integer in custom-defined function

Hi,

My question is closely related to this topic.
I have a custom function defined in functions as follows:

int calculate_K(int a, int b, int m) {
    return to_int(floor((a + b) / m));
}

I would like to make sure that this returns an integer. I tried adding to_int() but it results in the following error:

A returning function was expected but an undeclared identifier ‘to_int’ was supplied.

How do I make sure that this returns an integer. I need as input in another custom defined function where I use

    int binom_coeff_a = choose(K / 2 * m, x);

Thanks

The to_int() function is only available in the most recent release of Stan (2.31), the error above indicates that you’re using an older version.

If you’re not able to update, there’s an example of a basic Stan function for doing that here: Factorial, tgamma & matrix building - #2 by andrjohns

Okay, strange I am using Pystan 3.3.0? Thanks for the link

I believe the latest Pystan version is 3.6.0 (note that the Pystan version is different from the Stan version), so you may need to update

Okay when I use pip the latest verson is 3.3.0

 pip install pystan==3.6.0
ERROR: Could not find a version that satisfies the requirement pystan==3.6.0 (from versions: 0.1.1, 0.2.0, 0.2.1, 0.2.2, 2.0.0.0, 2.0.0.1, 2.0.1.0, 2.0.1.1, 2.0.1.2, 2.0.1.3, 2.1.0.0, 2.1.0.1, 2.2.0.0, 2.2.0.1, 2.3.0.0, 2.4.0.0, 2.4.0.1, 2.4.0.2, 2.4.0.3, 2.5.0.0, 2.5.0.1, 2.5.0.2, 2.6.0.0, 2.6.3.0, 2.7.0.0, 2.7.0.1, 2.8.0.0, 2.8.0.1, 2.8.0.2, 2.9.0.0, 2.10.0.0, 2.11.0.0, 2.12.0.0, 2.14.0.0, 2.15.0.0, 2.15.0.1, 2.16.0.0, 2.17.0.0, 2.17.1.0, 2.18.0.0, 2.18.1.0, 2.19.0.0, 2.19.1.1, 3.0.0b1, 3.0.0b2, 3.0.0b3, 3.0.0b4, 3.0.0b5, 3.0.0b6, 3.0.0b7, 3.0.0b8, 3.0.0rc1, 3.0.0, 3.0.1, 3.0.2, 3.1.0, 3.1.1, 3.2.0, 3.3.0)

@ariddell Thoughts?

You can also see the 3.6.0 on pip here: pystan · PyPI

I am using Pycharm and its a hassle to download from pypi with Pycharm.

I dowloaded the pystan-3.6.0.tar.gz file on pypi and unzipped it
Pycharm → View → Tool Windows → Python Packages
Add Package → From Disk → Selected the path to the the above file

Then Pycharm started downloading and I got the following error:

Processing /Users/User/Downloads/pystan-3.6.0
Installing build dependencies: started
Installing build dependencies: finished with status ‘done’
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status ‘done’
Preparing wheel metadata: started
Preparing wheel metadata: finished with status ‘done’
Requirement already satisfied: setuptools in /Users/User/.conda/envs/darts/lib/python3.7/site-packages (from pystan==3.6.0) (58.0.4)
Requirement already satisfied: clikit<0.7,>=0.6 in /Users/User/.conda/envs/darts/lib/python3.7/site-packages (from pystan==3.6.0) (0.6.2)
Collecting numpy<2.0,>=1.19
Using cached numpy-1.21.6-cp37-cp37m-macosx_10_9_x86_64.whl (16.9 MB)
Collecting pysimdjson<6.0.0,>=5.0.2
Using cached pysimdjson-5.0.2-cp37-cp37m-macosx_10_9_x86_64.whl (192 kB)

DEPRECATION: A future pip version will change local packages to be built in-place without first copying to a temporary directory. We recommend you use --use-feature=in-tree-build to test your packages with this new behavior before it becomes the default.
pip 21.3 will remove support for this functionality. You can find discussion regarding this at https://github.com/pypa/pip/issues/7555.
ERROR: Could not find a version that satisfies the requirement httpstan<4.10,>=4.9 (from pystan) (from versions: 0.6.0, 0.6.1, 0.7.0, 0.7.1, 0.7.2, 0.7.5, 0.7.6, 0.8.0, 0.10.1, 1.0.0, 2.0.3, 2.0.4, 2.0.5, 2.1.0, 2.2.0, 2.3.0, 4.0.0, 4.1.0, 4.2.1, 4.3.0, 4.3.1, 4.3.2, 4.4.0, 4.4.1, 4.4.2, 4.5.0, 4.6.0, 4.6.1)
ERROR: No matching distribution found for httpstan<4.10,>=4.9

So pip also doesn’t recognize the latest version of httpstan

 pip install httpstan==4.9.1
ERROR: Could not find a version that satisfies the requirement httpstan==4.9.1 (from versions: 0.6.0, 0.6.1, 0.7.0, 0.7.1, 0.7.2, 0.7.5, 0.7.6, 0.8.0, 0.10.1, 1.0.0, 2.0.3, 2.0.4, 2.0.5, 2.1.0, 2.2.0, 2.3.0, 4.0.0, 4.1.0, 4.2.1, 4.3.0, 4.3.1, 4.3.2, 4.4.0, 4.4.1, 4.4.2, 4.5.0, 4.6.0, 4.6.1)
ERROR: No matching distribution found for httpstan==4.9.1

Please advice!

I solved it by repeating first the above mentioned steps for httpstan