Created
July 6, 2023 18:21
-
-
Save aseyboldt/a49215121623feedafce84754411010a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "76685b5a-490c-4a79-886f-30c4500a8de9", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import pathlib\n", | |
"import re\n", | |
"import pandas as pd" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "e7783d49-5440-4622-a535-543b69a2120b", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"## Generate prep.cpp file\n", | |
"# g++ -E -std=c++1y -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes -I ./stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I ./stan/src -I ./stan/lib/rapidjson_1.1.0/ -I ./stan/lib/stan_math/ -I ./stan/lib/stan_math/lib/eigen_3.4.0 -I ./stan/lib/stan_math/lib/boost_1.78.0 -I ./stan/lib/stan_math/lib/sundials_6.1.1/include -I ./stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -fPIC -DBOOST_DISABLE_ASSERTS -c -x c++ -o prep.cpp test_models/logistic/logistic.hpp" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "4d8d0a8d-5c6a-46e7-a2c8-0a7b171f1504", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"content = pathlib.Path(\"/home/adr/.bridgestan/bridgestan-2.1.1/prep.cpp\").read_text()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"id": "eff870cb-a362-4588-ada7-a60748e3ea69", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"content = list(content.split(\"\\n\"))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"id": "73930510-e174-47b3-9676-044616266593", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"regex = re.compile('\\# ([0-9]*) \\\"([\\<\\>/a-zA-Z0-9\\._\\-]*)\\\"[ 0-9]*')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"id": "6b2582f1-77a7-472c-bf91-3e236b602cf4", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"line_counts = {}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"id": "8aab3d93-389c-419e-948d-41b048d9e361", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"current = None\n", | |
"for line in content:\n", | |
" match = regex.match(line)\n", | |
" if not match and current:\n", | |
" line_counts[current] += 1\n", | |
" continue\n", | |
" if not match and not current:\n", | |
" assert False\n", | |
" _, current = match.groups()\n", | |
" line_counts.setdefault(current, 0)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"id": "eb261fe0-6f1b-4a2b-b055-27d3297cce70", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"line_counts = pd.Series(line_counts)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"id": "699fbe1b-2cf0-48e5-a894-dc06c2e26766", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"counts = line_counts.rename(\"count\").to_frame().rename_axis(index=\"file\").reset_index()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"id": "d0861a7e-c276-4e03-94db-aadb69a00ae6", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"3322" | |
] | |
}, | |
"execution_count": 14, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Number of headers (more or less? What are those with zero lines?)\n", | |
"len(line_counts)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"id": "09feba5d-a08f-4247-ae7b-a203b90b0bc8", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"2911" | |
] | |
}, | |
"execution_count": 17, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"len(list(name for name, count in line_counts.items() if count > 0))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 20, | |
"id": "8a06fc04-c3d8-422f-8a9b-c18464c2c472", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"path\n", | |
"/usr/include/bits/endian.h 1\n", | |
"/usr/include/bits/endianness.h 1\n", | |
"/usr/include/bits/environments.h 1\n", | |
"/usr/include/bits/cpu-set.h 1\n", | |
"/usr/include/bits/floatn-common.h 1\n", | |
"/usr/include/bits/floatn.h 1\n", | |
"/usr/include/bits/flt-eval-method.h 1\n", | |
"/usr/include/bits/fp-fast.h 1\n", | |
"/usr/include/bits/fp-logb.h 1\n", | |
"/usr/include/bits/getopt_core.h 1\n", | |
"/usr/include/bits/getopt_posix.h 1\n", | |
"/usr/include/bits/errno.h 1\n", | |
"/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/include 10\n", | |
"./stan/lib/stan_math/lib/sundials_6.1.1/include 21\n", | |
"./stan/lib/stan_math/lib/eigen_3.4.0/unsupported 21\n", | |
"./stan/lib/stan_math/lib/tbb_2020.3/include 28\n", | |
"./stan/lib/stan_math/lib/eigen_3.4.0/Eigen 261\n", | |
"./stan/lib/stan_math/stan/math/rev 315\n", | |
"./stan/lib/stan_math/stan/math/prim 950\n", | |
"./stan/lib/stan_math/lib/boost_1.78.0/boost 1555\n", | |
"Name: count, dtype: int64" | |
] | |
}, | |
"execution_count": 20, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Number of included files by source directory\n", | |
"counts[\"path\"] = counts.file.str.split(\"/\").str.slice(0, 7).str.join(\"/\")\n", | |
"counts.groupby(\"path\")[\"count\"].count().sort_values().tail(20)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"id": "68caec11-b60a-4012-ac5c-77cfd5847276", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"path\n", | |
"/usr/include/features.h 621\n", | |
"/usr/include/bits/confname.h 658\n", | |
"/usr/include/unistd.h 660\n", | |
"./stan/src/stan/io/deserializer.hpp 711\n", | |
"/usr/include/pthread.h 1068\n", | |
"/usr/include/wchar.h 1164\n", | |
"./stan/src/stan/model/model_header.hpp 1865\n", | |
"/usr/include/stdlib.h 2298\n", | |
"./stan/src/stan/model/indexing 2525\n", | |
"./stan/lib/stan_math/lib/sundials_6.1.1 2608\n", | |
"/usr/include/bits/mathcalls.h 2670\n", | |
"/usr/include/libintl.h 3017\n", | |
"/usr/include/errno.h 4636\n", | |
"./stan/lib/stan_math/lib/tbb_2020.3 5363\n", | |
"/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1 8326\n", | |
"/usr/include/wctype.h 8507\n", | |
"/usr/include/sys/single_threaded.h 10620\n", | |
"./stan/lib/stan_math/stan/math 83223\n", | |
"./stan/lib/stan_math/lib/eigen_3.4.0 103128\n", | |
"./stan/lib/stan_math/lib/boost_1.78.0 189731\n", | |
"Name: count, dtype: int64" | |
] | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Number of lines included from different directories\n", | |
"counts[\"path\"] = counts.file.str.split(\"/\").str.slice(0, 6).str.join(\"/\")\n", | |
"counts.groupby(\"path\")[\"count\"].sum().sort_values().tail(20)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"id": "21a1184c-2cc7-423d-b2b2-f9c2c1a2f9eb", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"path\n", | |
"./stan/lib/stan_math/lib/boost_1.78.0/boost/fusion/sequence 2059\n", | |
"./stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/QR 2062\n", | |
"./stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/LU 2070\n", | |
"./stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/OrderingMethods 2077\n", | |
"./stan/lib/stan_math/stan/math/prim/core/init_threadpool_tbb.hpp 2150\n", | |
"./stan/lib/stan_math/lib/boost_1.78.0/boost/math/policies 2189\n", | |
"/usr/include/stdlib.h 2298\n", | |
"./stan/lib/stan_math/lib/boost_1.78.0/boost/function_types/detail 2324\n", | |
"./stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/SVD 2462\n", | |
"./stan/lib/stan_math/lib/boost_1.78.0/boost/type_traits/detail 2556\n", | |
"/usr/include/bits/mathcalls.h 2670\n", | |
"./stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/SparseLU 2735\n", | |
"./stan/lib/stan_math/lib/eigen_3.4.0/unsupported/Eigen/src 2774\n", | |
"./stan/lib/stan_math/lib/boost_1.78.0/boost/units/detail 2965\n", | |
"./stan/lib/stan_math/lib/boost_1.78.0/boost/fusion/functional 2972\n", | |
"/usr/include/libintl.h 3017\n", | |
"./stan/lib/stan_math/lib/boost_1.78.0/boost/lexical_cast/detail 3088\n", | |
"./stan/lib/stan_math/lib/boost_1.78.0/boost/numeric/conversion 3305\n", | |
"./stan/lib/stan_math/lib/boost_1.78.0/boost/fusion/algorithm 3694\n", | |
"./stan/lib/stan_math/stan/math/prim/functor/hcubature.hpp 3727\n", | |
"./stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/Eigenvalues 3931\n", | |
"./stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/IterativeLinearSolvers 3982\n", | |
"./stan/lib/stan_math/lib/boost_1.78.0/boost/fusion/view 4278\n", | |
"./stan/lib/stan_math/stan/math/prim/meta/holder.hpp 4379\n", | |
"/usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/include/stddef.h 4436\n", | |
"./stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/Geometry 4529\n", | |
"/usr/include/errno.h 4636\n", | |
"./stan/lib/stan_math/lib/boost_1.78.0/boost/math/tools 5101\n", | |
"./stan/lib/stan_math/lib/boost_1.78.0/boost/mpl/aux_ 6230\n", | |
"./stan/lib/stan_math/stan/math/rev/core/init_chainablestack.hpp 6331\n", | |
"./stan/lib/stan_math/lib/eigen_3.4.0/Eigen/SparseCore 8127\n", | |
"/usr/include/wctype.h 8507\n", | |
"./stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/SparseCore 10142\n", | |
"/usr/include/sys/single_threaded.h 10620\n", | |
"./stan/lib/stan_math/lib/eigen_3.4.0/Eigen/Core 11181\n", | |
"./stan/lib/stan_math/lib/boost_1.78.0/boost/function/function_template.hpp 11379\n", | |
"./stan/lib/stan_math/lib/boost_1.78.0/boost/numeric/odeint 14368\n", | |
"./stan/lib/stan_math/lib/boost_1.78.0/boost/math/special_functions 31605\n", | |
"./stan/lib/stan_math/lib/boost_1.78.0/boost/numeric/ublas 35105\n", | |
"./stan/lib/stan_math/lib/eigen_3.4.0/Eigen/src/Core 42699\n", | |
"Name: count, dtype: int64" | |
] | |
}, | |
"execution_count": 11, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# Same, just a bit more detailed\n", | |
"counts[\"path\"] = counts.file.str.split(\"/\").str.slice(0, 9).str.join(\"/\")\n", | |
"counts.groupby(\"path\")[\"count\"].sum().sort_values().tail(40)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "b70074c3-3e59-4912-bc3a-29ff7786d285", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "dev", | |
"language": "python", | |
"name": "dev" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.11.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment