From 6bce1dde239e288df1eeaa10507c12d7dbf00274 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 17:13:55 +0000 Subject: [PATCH 1/3] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.6.0 → v5.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.6.0...v5.0.0) - [github.com/astral-sh/ruff-pre-commit: v0.5.0 → v0.6.9](https://github.com/astral-sh/ruff-pre-commit/compare/v0.5.0...v0.6.9) --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3c61cb2..e372f3b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ ci: # TODO: Add mypy repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: 'v4.6.0' + rev: 'v5.0.0' hooks: - id: end-of-file-fixer exclude: 'setup.cfg' @@ -17,7 +17,7 @@ repos: - id: debug-statements - id: requirements-txt-fixer - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.0 + rev: v0.6.9 hooks: - id: ruff args: ["--fix"] From 28712eb5e8ff798a1d75bd2434fa9a6983c74fb9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 17:15:52 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- benchmarks/Benchmarks.ipynb | 209 +++++++++++++++++++----------------- 1 file changed, 113 insertions(+), 96 deletions(-) diff --git a/benchmarks/Benchmarks.ipynb b/benchmarks/Benchmarks.ipynb index a1358e1..ed06206 100644 --- a/benchmarks/Benchmarks.ipynb +++ b/benchmarks/Benchmarks.ipynb @@ -7,10 +7,10 @@ "outputs": [], "source": [ "import timeit\n", - "import tqdm\n", - "import pprint\n", + "\n", "import numpy as np\n", "import pandas as pd\n", + "import tqdm\n", "from matplotlib import pyplot as plt" ] }, @@ -20,10 +20,10 @@ "metadata": {}, "outputs": [], "source": [ - "plt.rcParams['text.usetex'] = True\n", - "plt.rcParams['axes.labelsize'] = 16\n", - "plt.rcParams['font.size'] = 16\n", - "plt.rcParams['legend.fontsize'] = 'large'" + "plt.rcParams[\"text.usetex\"] = True\n", + "plt.rcParams[\"axes.labelsize\"] = 16\n", + "plt.rcParams[\"font.size\"] = 16\n", + "plt.rcParams[\"legend.fontsize\"] = \"large\"" ] }, { @@ -48,9 +48,10 @@ } ], "source": [ - "import pyquaternion # pip install pyquaternion --user\n", - "import quaternion # pip install numpy_quaternion --user\n", - "import rowan # pip install rowan --user" + "import pyquaternion # pip install pyquaternion --user\n", + "import quaternion # pip install numpy_quaternion --user\n", + "\n", + "import rowan # pip install rowan --user" ] }, { @@ -61,16 +62,18 @@ "source": [ "def arr_to_pyquat(arr):\n", " if len(arr.shape) > 1:\n", - " pq_arr = np.empty(arr.shape[:-1], dtype='object')\n", + " pq_arr = np.empty(arr.shape[:-1], dtype=\"object\")\n", " for i, x in enumerate(arr):\n", " pq_arr[i] = pyquaternion.Quaternion(x)\n", " else:\n", " pq_arr = np.array([pyquaternion.Quaternion(arr)])\n", " return pq_arr\n", "\n", + "\n", "def arr_to_npquat(arr):\n", " return quaternion.as_quat_array(arr)\n", "\n", + "\n", "pyquat_times = {}\n", "quat_times = {}\n", "rowan_times = {}\n", @@ -107,33 +110,31 @@ } ], "source": [ - "pyquat_times['Multiply'] = []\n", - "quat_times['Multiply'] = []\n", - "rowan_times['Multiply'] = []\n", + "pyquat_times[\"Multiply\"] = []\n", + "quat_times[\"Multiply\"] = []\n", + "rowan_times[\"Multiply\"] = []\n", "for N in tqdm.tqdm_notebook(Ns):\n", " x = rowan.random.rand(N)\n", " y = rowan.random.rand(N)\n", "\n", " if N < pqlim:\n", - " pyquat_times['Multiply'].append(\n", + " pyquat_times[\"Multiply\"].append(\n", " timeit.timeit(\n", " \"x*y\",\n", " setup=\"from __main__ import x, y, arr_to_pyquat; x = arr_to_pyquat(x); y = arr_to_pyquat(y)\",\n", - " number = num\n", + " number=num,\n", " )\n", " )\n", - " quat_times['Multiply'].append(\n", + " quat_times[\"Multiply\"].append(\n", " timeit.timeit(\n", " \"x*y\",\n", " setup=\"from __main__ import x, y, arr_to_npquat; x = arr_to_npquat(x); y = arr_to_npquat(y)\",\n", - " number = num\n", + " number=num,\n", " )\n", " )\n", - " rowan_times['Multiply'].append(\n", + " rowan_times[\"Multiply\"].append(\n", " timeit.timeit(\n", - " \"rowan.multiply(x, y)\",\n", - " setup=\"from __main__ import x, y, rowan\",\n", - " number = num\n", + " \"rowan.multiply(x, y)\", setup=\"from __main__ import x, y, rowan\", number=num\n", " )\n", " )" ] @@ -166,33 +167,29 @@ } ], "source": [ - "pyquat_times['Exponential'] = []\n", - "quat_times['Exponential'] = []\n", - "rowan_times['Exponential'] = []\n", + "pyquat_times[\"Exponential\"] = []\n", + "quat_times[\"Exponential\"] = []\n", + "rowan_times[\"Exponential\"] = []\n", "for N in tqdm.tqdm_notebook(Ns):\n", " x = rowan.random.rand(N)\n", "\n", " if N < pqlim:\n", - " pyquat_times['Exponential'].append(\n", + " pyquat_times[\"Exponential\"].append(\n", " timeit.timeit(\n", " \"for i in range(len(x)): pyquaternion.Quaternion.exp(x[i])\",\n", " setup=\"from __main__ import x, pyquaternion, arr_to_pyquat; x = arr_to_pyquat(x);\",\n", - " number = num\n", + " number=num,\n", " )\n", " )\n", - " quat_times['Exponential'].append(\n", + " quat_times[\"Exponential\"].append(\n", " timeit.timeit(\n", " \"np.exp(x)\",\n", " setup=\"from __main__ import x, arr_to_npquat, np; x = arr_to_npquat(x);\",\n", - " number = num\n", + " number=num,\n", " )\n", " )\n", - " rowan_times['Exponential'].append(\n", - " timeit.timeit(\n", - " \"rowan.exp(x)\",\n", - " setup=\"from __main__ import x, rowan\",\n", - " number = num\n", - " )\n", + " rowan_times[\"Exponential\"].append(\n", + " timeit.timeit(\"rowan.exp(x)\", setup=\"from __main__ import x, rowan\", number=num)\n", " )" ] }, @@ -224,32 +221,30 @@ } ], "source": [ - "pyquat_times['Conjugate'] = []\n", - "quat_times['Conjugate'] = []\n", - "rowan_times['Conjugate'] = []\n", + "pyquat_times[\"Conjugate\"] = []\n", + "quat_times[\"Conjugate\"] = []\n", + "rowan_times[\"Conjugate\"] = []\n", "for N in tqdm.tqdm_notebook(Ns):\n", " x = rowan.random.rand(N)\n", "\n", " if N < pqlim:\n", - " pyquat_times['Conjugate'].append(\n", + " pyquat_times[\"Conjugate\"].append(\n", " timeit.timeit(\n", " \"for i in range(len(x)): x.conjugate\",\n", " setup=\"from __main__ import x, arr_to_pyquat; x = arr_to_pyquat(x);\",\n", - " number = num\n", + " number=num,\n", " )\n", " )\n", - " quat_times['Conjugate'].append(\n", + " quat_times[\"Conjugate\"].append(\n", " timeit.timeit(\n", " \"x.conjugate()\",\n", " setup=\"from __main__ import x, arr_to_npquat; x = arr_to_npquat(x);\",\n", - " number = num\n", + " number=num,\n", " )\n", " )\n", - " rowan_times['Conjugate'].append(\n", + " rowan_times[\"Conjugate\"].append(\n", " timeit.timeit(\n", - " \"rowan.conjugate(x)\",\n", - " setup=\"from __main__ import x, rowan\",\n", - " number = num\n", + " \"rowan.conjugate(x)\", setup=\"from __main__ import x, rowan\", number=num\n", " )\n", " )" ] @@ -282,32 +277,30 @@ } ], "source": [ - "pyquat_times['Norm'] = []\n", - "quat_times['Norm'] = []\n", - "rowan_times['Norm'] = []\n", + "pyquat_times[\"Norm\"] = []\n", + "quat_times[\"Norm\"] = []\n", + "rowan_times[\"Norm\"] = []\n", "for N in tqdm.tqdm_notebook(Ns):\n", " x = rowan.random.rand(N)\n", "\n", " if N < pqlim:\n", - " pyquat_times['Norm'].append(\n", + " pyquat_times[\"Norm\"].append(\n", " timeit.timeit(\n", " \"for i in range(len(x)): x[i].norm\",\n", " setup=\"from __main__ import x, arr_to_pyquat; x = arr_to_pyquat(x);\",\n", - " number = num\n", + " number=num,\n", " )\n", " )\n", - " quat_times['Norm'].append(\n", + " quat_times[\"Norm\"].append(\n", " timeit.timeit(\n", " \"np.abs(x)\",\n", " setup=\"from __main__ import x, np, arr_to_npquat; x = arr_to_npquat(x);\",\n", - " number = num\n", + " number=num,\n", " )\n", " )\n", - " rowan_times['Norm'].append(\n", + " rowan_times[\"Norm\"].append(\n", " timeit.timeit(\n", - " \"rowan.norm(x)\",\n", - " setup=\"from __main__ import x, rowan\",\n", - " number = num\n", + " \"rowan.norm(x)\", setup=\"from __main__ import x, rowan\", number=num\n", " )\n", " )" ] @@ -340,32 +333,30 @@ } ], "source": [ - "pyquat_times['To Matrix'] = []\n", - "quat_times['To Matrix'] = []\n", - "rowan_times['To Matrix'] = []\n", + "pyquat_times[\"To Matrix\"] = []\n", + "quat_times[\"To Matrix\"] = []\n", + "rowan_times[\"To Matrix\"] = []\n", "for N in tqdm.tqdm_notebook(Ns):\n", " x = rowan.random.rand(N)\n", "\n", " if N < pqlim:\n", - " pyquat_times['To Matrix'].append(\n", + " pyquat_times[\"To Matrix\"].append(\n", " timeit.timeit(\n", " \"for i in range(len(x)): x[i].rotation_matrix\",\n", " setup=\"from __main__ import x, arr_to_pyquat; x = arr_to_pyquat(x);\",\n", - " number = num\n", + " number=num,\n", " )\n", " )\n", - " quat_times['To Matrix'].append(\n", + " quat_times[\"To Matrix\"].append(\n", " timeit.timeit(\n", " \"quaternion.as_rotation_matrix(x)\",\n", " setup=\"from __main__ import x, quaternion, arr_to_npquat; x = arr_to_npquat(x);\",\n", - " number = num\n", + " number=num,\n", " )\n", " )\n", - " rowan_times['To Matrix'].append(\n", + " rowan_times[\"To Matrix\"].append(\n", " timeit.timeit(\n", - " \"rowan.to_matrix(x)\",\n", - " setup=\"from __main__ import x, rowan\",\n", - " number = num\n", + " \"rowan.to_matrix(x)\", setup=\"from __main__ import x, rowan\", number=num\n", " )\n", " )" ] @@ -376,9 +367,9 @@ "metadata": {}, "outputs": [], "source": [ - "pyquat_times['N'] = list(np.array(Ns)[np.array(Ns) < pqlim])\n", - "quat_times['N'] = Ns\n", - "rowan_times['N'] = Ns" + "pyquat_times[\"N\"] = list(np.array(Ns)[np.array(Ns) < pqlim])\n", + "quat_times[\"N\"] = Ns\n", + "rowan_times[\"N\"] = Ns" ] }, { @@ -387,18 +378,24 @@ "metadata": {}, "outputs": [], "source": [ - "df_pq = pd.DataFrame(pyquat_times).melt(id_vars=\"N\", var_name=\"operation\", value_name=\"pyquaternion\")\n", - "df_nq = pd.DataFrame(quat_times).melt(id_vars=\"N\", var_name=\"operation\", value_name=\"npquaternion\")\n", - "df_r = pd.DataFrame(rowan_times).melt(id_vars=\"N\", var_name=\"operation\", value_name=\"rowan\")\n", - "df = df_r.merge(df_nq, on =[\"N\", \"operation\"])\n", - "df = df.merge(df_pq, on =[\"N\", \"operation\"], how = \"left\")\n", + "df_pq = pd.DataFrame(pyquat_times).melt(\n", + " id_vars=\"N\", var_name=\"operation\", value_name=\"pyquaternion\"\n", + ")\n", + "df_nq = pd.DataFrame(quat_times).melt(\n", + " id_vars=\"N\", var_name=\"operation\", value_name=\"npquaternion\"\n", + ")\n", + "df_r = pd.DataFrame(rowan_times).melt(\n", + " id_vars=\"N\", var_name=\"operation\", value_name=\"rowan\"\n", + ")\n", + "df = df_r.merge(df_nq, on=[\"N\", \"operation\"])\n", + "df = df.merge(df_pq, on=[\"N\", \"operation\"], how=\"left\")\n", "df.fillna(0, inplace=True)\n", - "df['pyquaternion'] /= df['N']\n", - "df['pyquaternion'] *= 1e6\n", - "df['npquaternion'] /= df['N']\n", - "df['npquaternion'] *= 1e6\n", - "df['rowan'] /= df['N']\n", - "df['rowan'] *= 1e6" + "df[\"pyquaternion\"] /= df[\"N\"]\n", + "df[\"pyquaternion\"] *= 1e6\n", + "df[\"npquaternion\"] /= df[\"N\"]\n", + "df[\"npquaternion\"] *= 1e6\n", + "df[\"rowan\"] /= df[\"N\"]\n", + "df[\"rowan\"] *= 1e6" ] }, { @@ -566,8 +563,8 @@ ], "source": [ "view = df.groupby([\"N\", \"operation\"]).mean()\n", - "view['rowan vs. npq'] = view['rowan']/view['npquaternion']\n", - "view['pyq vs. rowan'] = view['pyquaternion']/view['rowan']\n", + "view[\"rowan vs. npq\"] = view[\"rowan\"] / view[\"npquaternion\"]\n", + "view[\"pyq vs. rowan\"] = view[\"pyquaternion\"] / view[\"rowan\"]\n", "view" ] }, @@ -591,23 +588,43 @@ } ], "source": [ - "cols = list(col['color'] for col in plt.rcParams['axes.prop_cycle'])\n", + "cols = list(col[\"color\"] for col in plt.rcParams[\"axes.prop_cycle\"])\n", "fig, axes = plt.subplots(2, 1, figsize=(8, 15))\n", - "ax = df[df['N'] == Ns[0]].drop(['N'], axis=1).groupby(\n", - " [\"operation\"]).mean().plot.barh(ax=axes[0], logx=True, color = cols[0:3],\n", - " title=\"$\\log_{{\\,10}}(N) = {}$\".format(int(np.log10(Ns[0]))),\n", - " xlim=(10**-2, 10**3), legend=False)\n", - "ax = df[df['N'] == Ns[1]].drop(['N'], axis=1).groupby(\n", - " [\"operation\"]).mean().plot.barh(ax=axes[1], logx=True, color = cols[0:3],\n", - " title=\"$\\log_{{\\,10}}(N) = {}$\".format(int(np.log10(Ns[1]))),\n", - " xlim=(10**-2, 10**3), legend=False)\n", - "ax.set_xlabel(\"$\\log_{\\,10}(sec)$\", fontsize=18)\n", + "ax = (\n", + " df[df[\"N\"] == Ns[0]]\n", + " .drop([\"N\"], axis=1)\n", + " .groupby([\"operation\"])\n", + " .mean()\n", + " .plot.barh(\n", + " ax=axes[0],\n", + " logx=True,\n", + " color=cols[0:3],\n", + " title=rf\"$\\log_{{\\,10}}(N) = {int(np.log10(Ns[0]))}$\",\n", + " xlim=(10**-2, 10**3),\n", + " legend=False,\n", + " )\n", + ")\n", + "ax = (\n", + " df[df[\"N\"] == Ns[1]]\n", + " .drop([\"N\"], axis=1)\n", + " .groupby([\"operation\"])\n", + " .mean()\n", + " .plot.barh(\n", + " ax=axes[1],\n", + " logx=True,\n", + " color=cols[0:3],\n", + " title=rf\"$\\log_{{\\,10}}(N) = {int(np.log10(Ns[1]))}$\",\n", + " xlim=(10**-2, 10**3),\n", + " legend=False,\n", + " )\n", + ")\n", + "ax.set_xlabel(r\"$\\log_{\\,10}(sec)$\", fontsize=18)\n", "for ax in axes.flatten():\n", " ax.set_ylabel(\"\")\n", - " ax.legend(loc='best', fontsize=15)\n", + " ax.legend(loc=\"best\", fontsize=15)\n", " ax.title.set_fontsize(20)\n", - " #ax.tick_params(axis='both', which='major', labelsize=16)\n", - " \n", + " # ax.tick_params(axis='both', which='major', labelsize=16)\n", + "\n", "fig.subplots_adjust(left=0.2)\n", "plt.show()\n", "fig.savefig(\"Performance.pdf\")" From a378aad3462780b0d41e7af83e4ee92362415a08 Mon Sep 17 00:00:00 2001 From: "Joshua A. Anderson" Date: Mon, 28 Oct 2024 11:23:12 -0400 Subject: [PATCH 3/3] Ignore lints in benchmark notebooks. --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index b9f0d92..6f018c6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -51,3 +51,4 @@ convention = "google" [tool.ruff.lint.per-file-ignores] "tests/*" = ["S101"] +"benchmarks/*.ipynb" = ["D103", "E501", "C400"]