Skip to content

Commit

Permalink
Some updates to docstrings, tiny cleanups (#20)
Browse files Browse the repository at this point in the history
* Docstring of simulate.
* Update pre-commit hooks.
* Use better name for loop variable.
* Apply nbstripout.
  • Loading branch information
hmgaudecker authored Jul 20, 2023
1 parent 25bef85 commit 278d918
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 1,151 deletions.
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,27 @@ repos:
hooks:
- id: yamllint
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black
language_version: python3.10
- repo: https://github.com/asottile/blacken-docs
rev: 1.14.0
rev: 1.15.0
hooks:
- id: blacken-docs
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.276
rev: v0.0.278
hooks:
- id: ruff
# args:
# - --verbose
# - repo: https://github.com/kynan/nbstripout
# rev: 0.6.1
# hooks:
# - id: nbstripout
# args:
# - --extra-keys
# - metadata.kernelspec metadata.language_info.version metadata.vscode
- repo: https://github.com/kynan/nbstripout
rev: 0.6.1
hooks:
- id: nbstripout
args:
- --extra-keys
- metadata.kernelspec metadata.language_info.version metadata.vscode
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.7.0
hooks:
Expand Down
8 changes: 4 additions & 4 deletions src/lcm/function_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ def get_function_evaluator(
# ==================================================================================
# wrap the indexers and put them it into funcs
# ==================================================================================
for indexer in space_info.indexer_infos:
funcs[f"__{indexer.out_name}_pos__"] = _get_lookup_function(
array_name=indexer.name,
axis_names=[f"__{var}_pos__" for var in indexer.axis_names],
for indexer_info in space_info.indexer_infos:
funcs[f"__{indexer_info.out_name}_pos__"] = _get_lookup_function(
array_name=indexer_info.name,
axis_names=[f"__{var}_pos__" for var in indexer_info.axis_names],
)

# ==================================================================================
Expand Down
155 changes: 20 additions & 135 deletions src/lcm/sandbox/interpolation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 180,
"execution_count": null,
"id": "da0bbbc9",
"metadata": {},
"outputs": [],
Expand All @@ -23,7 +23,7 @@
},
{
"cell_type": "code",
"execution_count": 181,
"execution_count": null,
"id": "1c31af18",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -54,7 +54,7 @@
},
{
"cell_type": "code",
"execution_count": 182,
"execution_count": null,
"id": "86f352f5",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -101,18 +101,10 @@
},
{
"cell_type": "code",
"execution_count": 183,
"execution_count": null,
"id": "46e61c87",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"752 µs ± 15.9 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"outputs": [],
"source": [
"func, args = get_1d_inputs(target=\"scipy\")\n",
"%timeit func(*args)\n",
Expand All @@ -121,18 +113,10 @@
},
{
"cell_type": "code",
"execution_count": 184,
"execution_count": null,
"id": "8f9062cb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"58.6 µs ± 1.55 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n"
]
}
],
"outputs": [],
"source": [
"func, args = get_1d_inputs(target=\"jax_linspace\")\n",
"%timeit func(*args).block_until_ready()\n",
Expand All @@ -141,18 +125,10 @@
},
{
"cell_type": "code",
"execution_count": 185,
"execution_count": null,
"id": "55bc8605",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"50.7 µs ± 870 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)\n"
]
}
],
"outputs": [],
"source": [
"func, args = get_1d_inputs(target=\"jax\")\n",
"%timeit func(*args).block_until_ready()\n",
Expand All @@ -161,7 +137,7 @@
},
{
"cell_type": "code",
"execution_count": 186,
"execution_count": null,
"id": "62bb0133",
"metadata": {},
"outputs": [],
Expand All @@ -180,7 +156,7 @@
},
{
"cell_type": "code",
"execution_count": 187,
"execution_count": null,
"id": "7db8a854",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -222,18 +198,10 @@
},
{
"cell_type": "code",
"execution_count": 188,
"execution_count": null,
"id": "ff7b5ed0",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"753 µs ± 5.34 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"outputs": [],
"source": [
"func, args = get_2d_inputs(target=\"scipy\")\n",
"scipy_res = func(*args)\n",
Expand All @@ -242,18 +210,10 @@
},
{
"cell_type": "code",
"execution_count": 189,
"execution_count": null,
"id": "1a8a6787",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"281 µs ± 16.3 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"outputs": [],
"source": [
"func, args = get_2d_inputs(target=\"jax_linspace\")\n",
"linspace_res = func(*args)\n",
Expand All @@ -262,18 +222,10 @@
},
{
"cell_type": "code",
"execution_count": 190,
"execution_count": null,
"id": "5401c149",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"282 µs ± 11.7 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)\n"
]
}
],
"outputs": [],
"source": [
"jax_res = get_2d_inputs(target=\"jax\")\n",
"jax_res = func(*args)\n",
Expand All @@ -282,71 +234,10 @@
},
{
"cell_type": "code",
"execution_count": 191,
"execution_count": null,
"id": "216b4e52",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>scipy</th>\n",
" <th>linspace</th>\n",
" <th>jax</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>scipy</th>\n",
" <td>1.00000</td>\n",
" <td>0.96638</td>\n",
" <td>0.96638</td>\n",
" </tr>\n",
" <tr>\n",
" <th>linspace</th>\n",
" <td>0.96638</td>\n",
" <td>1.00000</td>\n",
" <td>1.00000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>jax</th>\n",
" <td>0.96638</td>\n",
" <td>1.00000</td>\n",
" <td>1.00000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" scipy linspace jax\n",
"scipy 1.00000 0.96638 0.96638\n",
"linspace 0.96638 1.00000 1.00000\n",
"jax 0.96638 1.00000 1.00000"
]
},
"execution_count": 191,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
Expand All @@ -367,11 +258,6 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
Expand All @@ -381,8 +267,7 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 278d918

Please sign in to comment.