Skip to content

Instantly share code, notes, and snippets.

@spinkney
Last active December 7, 2021 00:30
Show Gist options
  • Save spinkney/b876a13ca63370364749622120fa71d6 to your computer and use it in GitHub Desktop.
Save spinkney/b876a13ca63370364749622120fa71d6 to your computer and use it in GitHub Desktop.
#!/bin/bash
# first clone the stan docs repo
# git clone https://github.com/stan-dev/docs.git
# then cd into it and run this script
grep_version=$(grep -V)
grep_=${1:-grep}
bsd='BSD'
if [[ $(grep -V) == *"$bsd"* ]] && [[ $# -eq 0 ]]
then
echo 'Trying ggrep...'
grep_=$(which ggrep)
if ! [ -z $grep_ ]
then
echo "Using ggrep!"
grep_="ggrep"
else
echo 'No GNU grep found! If on MacOS try brew install grep. Otherwise supply the grep as argument 1.'
fi
else
echo "Using input $grep_"
fi
## Uncomment this
python3 extract_function_sigs.py
stan_version=$(git rev-parse 'HEAD')
# Remove First two lines of stan-functions-2_28.txt
sed -e "1,2d" stan-functions-"$stan_version".txt > stan-functions-"$stan_version"_stripped.txt
# save distributions
distributions=$($grep_ -oP "(.*)(?=_lpdf|_lupdf|_lpmf|_lupmf|_lcdf|_lccdf|_rng|_qf|_cdf)|(.*_glm)" stan-functions-"$stan_version"_stripped.txt | sort | uniq)
# save distributions with endings
distendings=$($grep_ -P "(.*)(?=_lpdf|_lupdf|_lpmf|_lupmf|_lcdf|_lccdf|_rng|_qf|_cdf)|(.*_glm)" stan-functions-"$stan_version"_stripped.txt | cut -d ";" -f1)
# save functions
allfunctions=$(cut -d ";" -f1 stan-functions-"$stan_version"_stripped.txt | uniq | sort)
remove=("arg"
"e" "pi" "sqrt2" "log2" "log10"
"operator\\"
"operator!"
"operator!="
"operator%"
"operator%/%"
"operator&&"
"operator'"
"operator*"
"operator*="
"operator+"
"operator+="
"operator-"
"operator-="
"operator.*"
"operator.*="
"operator./"
"operator./="
"operator.^"
"operator/"
"operator/="
"operator<"
"operator<="
"operator="
"operator=="
"operator>"
"operator>="
"operator'"
"operator^"
"operator||")
functions_out=$(comm -23 <(echo "$functions") <(echo "${remove[@]}" | tr " " "\n" | sort))
# functions=$(cat <(echo $distributions | sed -e "s/ /\n/g") <(echo $distendings | sed -e "s/ /\n/g") | sort | comm -23 <(echo $allfunctions | sed -e "s/ /\n/g" | sort) - )
# now make it so it's easy for highlights.js
echo "$distributions" | sed -e "s/^/'/" | sed -e "s/$/',/" > distributions_quoted.txt
echo "$functions_out" | sed -e "s/^/'/" | sed -e "s/$/',/" > functions_quoted.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment