From 598e64268a219c3d533be43604b237aab73b7f3a Mon Sep 17 00:00:00 2001 From: Hugues Hoppe Date: Mon, 12 Feb 2024 16:37:00 -0800 Subject: [PATCH] Moved many tests from notebook to test_resampler --- resampler/__init__.py | 20 +- resampler_notebook.ipynb | 4920 +++++++++++++++----------------------- resampler_notebook.py | 544 +---- test_resampler.py | 171 +- 4 files changed, 2181 insertions(+), 3474 deletions(-) diff --git a/resampler/__init__.py b/resampler/__init__.py index 0154b5e..d8db44f 100644 --- a/resampler/__init__.py +++ b/resampler/__init__.py @@ -15,7 +15,7 @@ import functools import itertools import math -import multiprocessing +import os import sys import types import typing @@ -237,7 +237,17 @@ def func(array: _NDArray) -> _NDArray: print(f'Creating numba jit-wrapper for {signature}.') jitted_function = numba.njit(func, parallel=True, fastmath=True, cache=True) self._jitted_function[signature] = jitted_function - result = jitted_function(a) + + try: + result = jitted_function(a) + except RuntimeError: + message = ( + 'resampler: This runtime error may be due to a corrupt resampler/__pycache__;' + ' try deleting that directory.' + ) + print(message, file=sys.stderr, flush=True) + raise + return result[..., 0] if array.ndim == 2 else result @@ -439,7 +449,7 @@ def premult_with_sparse( assert self.array.ndim == sparse.ndim == 2 and sparse.shape[1] == self.array.shape[0] # Empirically faster than with default numba.config.NUMBA_NUM_THREADS (e.g., 24). if using_numba: - num_threads2 = min(6, multiprocessing.cpu_count()) if num_threads == 'auto' else num_threads + num_threads2 = min(6, os.cpu_count()) if num_threads == 'auto' else num_threads src = np.ascontiguousarray(self.array) # Like .ravel() in _mul_multivector(). dtype = np.result_type(sparse.dtype, src.dtype) dst = np.empty((sparse.shape[0], src.shape[1]), dtype) @@ -3794,14 +3804,14 @@ def _find_closest_filter(filter: str, resizer: Callable[..., Any]) -> str: skimage_transform_resize: 'box', tf_image_resize: 'trapezoid', torch_nn_resize: 'trapezoid', - }.get(resize, 'box') + }.get(resizer, 'box') case 'cubic_like': return { cv_resize: 'sharpcubic', scipy_ndimage_resize: 'cardinal3', skimage_transform_resize: 'cardinal3', torch_nn_resize: 'sharpcubic', - }.get(resize, 'cubic') + }.get(resizer, 'cubic') case 'high_quality': return { pil_image_resize: 'lanczos3', diff --git a/resampler_notebook.ipynb b/resampler_notebook.ipynb index 9fa2f28..55707cb 100644 --- a/resampler_notebook.ipynb +++ b/resampler_notebook.ipynb @@ -343,11 +343,11 @@ "execution_count": 1, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:45.859244Z", - "iopub.status.busy": "2023-12-13T19:27:45.859095Z", - "iopub.status.idle": "2023-12-13T19:27:45.977233Z", - "shell.execute_reply": "2023-12-13T19:27:45.976610Z", - "shell.execute_reply.started": "2023-12-13T19:27:45.859229Z" + "iopub.execute_input": "2024-02-13T00:33:50.817224Z", + "iopub.status.busy": "2024-02-13T00:33:50.816883Z", + "iopub.status.idle": "2024-02-13T00:33:50.937275Z", + "shell.execute_reply": "2024-02-13T00:33:50.936567Z", + "shell.execute_reply.started": "2024-02-13T00:33:50.817210Z" } }, "outputs": [], @@ -360,11 +360,11 @@ "execution_count": 2, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:45.978780Z", - "iopub.status.busy": "2023-12-13T19:27:45.978366Z", - "iopub.status.idle": "2023-12-13T19:27:47.633773Z", - "shell.execute_reply": "2023-12-13T19:27:47.633243Z", - "shell.execute_reply.started": "2023-12-13T19:27:45.978765Z" + "iopub.execute_input": "2024-02-13T00:33:50.938303Z", + "iopub.status.busy": "2024-02-13T00:33:50.938106Z", + "iopub.status.idle": "2024-02-13T00:33:52.687962Z", + "shell.execute_reply": "2024-02-13T00:33:52.687390Z", + "shell.execute_reply.started": "2024-02-13T00:33:50.938287Z" } }, "outputs": [], @@ -377,11 +377,11 @@ "execution_count": 3, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:47.634595Z", - "iopub.status.busy": "2023-12-13T19:27:47.634453Z", - "iopub.status.idle": "2023-12-13T19:27:48.705806Z", - "shell.execute_reply": "2023-12-13T19:27:48.704924Z", - "shell.execute_reply.started": "2023-12-13T19:27:47.634583Z" + "iopub.execute_input": "2024-02-13T00:33:52.688814Z", + "iopub.status.busy": "2024-02-13T00:33:52.688682Z", + "iopub.status.idle": "2024-02-13T00:33:54.323570Z", + "shell.execute_reply": "2024-02-13T00:33:54.322925Z", + "shell.execute_reply.started": "2024-02-13T00:33:52.688802Z" } }, "outputs": [], @@ -394,11 +394,11 @@ "execution_count": 4, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:48.707114Z", - "iopub.status.busy": "2023-12-13T19:27:48.706957Z", - "iopub.status.idle": "2023-12-13T19:27:50.431186Z", - "shell.execute_reply": "2023-12-13T19:27:50.430567Z", - "shell.execute_reply.started": "2023-12-13T19:27:48.707100Z" + "iopub.execute_input": "2024-02-13T00:33:54.324813Z", + "iopub.status.busy": "2024-02-13T00:33:54.324456Z", + "iopub.status.idle": "2024-02-13T00:33:56.182718Z", + "shell.execute_reply": "2024-02-13T00:33:56.182040Z", + "shell.execute_reply.started": "2024-02-13T00:33:54.324795Z" }, "tags": [] }, @@ -413,11 +413,11 @@ "execution_count": 5, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:50.432296Z", - "iopub.status.busy": "2023-12-13T19:27:50.432009Z", - "iopub.status.idle": "2023-12-13T19:27:50.444217Z", - "shell.execute_reply": "2023-12-13T19:27:50.443682Z", - "shell.execute_reply.started": "2023-12-13T19:27:50.432283Z" + "iopub.execute_input": "2024-02-13T00:33:56.183713Z", + "iopub.status.busy": "2024-02-13T00:33:56.183508Z", + "iopub.status.idle": "2024-02-13T00:33:56.196195Z", + "shell.execute_reply": "2024-02-13T00:33:56.195416Z", + "shell.execute_reply.started": "2024-02-13T00:33:56.183697Z" }, "tags": [] }, @@ -432,11 +432,11 @@ "execution_count": 6, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:50.445154Z", - "iopub.status.busy": "2023-12-13T19:27:50.444934Z", - "iopub.status.idle": "2023-12-13T19:27:55.346366Z", - "shell.execute_reply": "2023-12-13T19:27:55.345743Z", - "shell.execute_reply.started": "2023-12-13T19:27:50.445136Z" + "iopub.execute_input": "2024-02-13T00:33:56.198476Z", + "iopub.status.busy": "2024-02-13T00:33:56.198161Z", + "iopub.status.idle": "2024-02-13T00:33:59.583964Z", + "shell.execute_reply": "2024-02-13T00:33:59.583297Z", + "shell.execute_reply.started": "2024-02-13T00:33:56.198461Z" }, "tags": [] }, @@ -507,11 +507,11 @@ "execution_count": 7, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:55.348457Z", - "iopub.status.busy": "2023-12-13T19:27:55.347983Z", - "iopub.status.idle": "2023-12-13T19:27:55.382249Z", - "shell.execute_reply": "2023-12-13T19:27:55.381666Z", - "shell.execute_reply.started": "2023-12-13T19:27:55.348439Z" + "iopub.execute_input": "2024-02-13T00:33:59.585403Z", + "iopub.status.busy": "2024-02-13T00:33:59.585036Z", + "iopub.status.idle": "2024-02-13T00:33:59.615285Z", + "shell.execute_reply": "2024-02-13T00:33:59.614587Z", + "shell.execute_reply.started": "2024-02-13T00:33:59.585388Z" } }, "outputs": [], @@ -526,20 +526,29 @@ "execution_count": 8, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:55.383395Z", - "iopub.status.busy": "2023-12-13T19:27:55.383131Z", - "iopub.status.idle": "2023-12-13T19:27:55.413797Z", - "shell.execute_reply": "2023-12-13T19:27:55.413155Z", - "shell.execute_reply.started": "2023-12-13T19:27:55.383370Z" + "iopub.execute_input": "2024-02-13T00:33:59.616361Z", + "iopub.status.busy": "2024-02-13T00:33:59.616010Z", + "iopub.status.idle": "2024-02-13T00:33:59.650217Z", + "shell.execute_reply": "2024-02-13T00:33:59.649335Z", + "shell.execute_reply.started": "2024-02-13T00:33:59.616347Z" }, "tags": [] }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Controls the breadth and precision of the notebook experiments; 0 <= value <= 3.'" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "EFFORT: Literal[0, 1, 2, 3] = 1\n", - "\"\"\"Controls the breadth and precision of the notebook experiments; 0 <= value <= 3.\"\"\"\n", - "if not running_in_notebook():\n", - " EFFORT = 0 # Otherwise, invocations of doctest or pytest would recurse infinitely." + "EFFORT: Literal[0, 1, 2, 3] = hh.get_env_int('EFFORT', 1) # type: ignore[assignment]\n", + "\"\"\"Controls the breadth and precision of the notebook experiments; 0 <= value <= 3.\"\"\"" ] }, { @@ -547,11 +556,11 @@ "execution_count": 9, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:55.415105Z", - "iopub.status.busy": "2023-12-13T19:27:55.414787Z", - "iopub.status.idle": "2023-12-13T19:27:55.445393Z", - "shell.execute_reply": "2023-12-13T19:27:55.444837Z", - "shell.execute_reply.started": "2023-12-13T19:27:55.415089Z" + "iopub.execute_input": "2024-02-13T00:33:59.651614Z", + "iopub.status.busy": "2024-02-13T00:33:59.651182Z", + "iopub.status.idle": "2024-02-13T00:33:59.681775Z", + "shell.execute_reply": "2024-02-13T00:33:59.681063Z", + "shell.execute_reply.started": "2024-02-13T00:33:59.651595Z" } }, "outputs": [], @@ -566,11 +575,11 @@ "execution_count": 10, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:55.446230Z", - "iopub.status.busy": "2023-12-13T19:27:55.446081Z", - "iopub.status.idle": "2023-12-13T19:27:55.475105Z", - "shell.execute_reply": "2023-12-13T19:27:55.474517Z", - "shell.execute_reply.started": "2023-12-13T19:27:55.446218Z" + "iopub.execute_input": "2024-02-13T00:33:59.682819Z", + "iopub.status.busy": "2024-02-13T00:33:59.682626Z", + "iopub.status.idle": "2024-02-13T00:33:59.716216Z", + "shell.execute_reply": "2024-02-13T00:33:59.715388Z", + "shell.execute_reply.started": "2024-02-13T00:33:59.682804Z" } }, "outputs": [], @@ -584,11 +593,11 @@ "execution_count": 11, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:55.476266Z", - "iopub.status.busy": "2023-12-13T19:27:55.475763Z", - "iopub.status.idle": "2023-12-13T19:27:55.503793Z", - "shell.execute_reply": "2023-12-13T19:27:55.503192Z", - "shell.execute_reply.started": "2023-12-13T19:27:55.476250Z" + "iopub.execute_input": "2024-02-13T00:33:59.717719Z", + "iopub.status.busy": "2024-02-13T00:33:59.717289Z", + "iopub.status.idle": "2024-02-13T00:33:59.749971Z", + "shell.execute_reply": "2024-02-13T00:33:59.749199Z", + "shell.execute_reply.started": "2024-02-13T00:33:59.717694Z" }, "tags": [] }, @@ -603,11 +612,11 @@ "execution_count": 12, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:55.504792Z", - "iopub.status.busy": "2023-12-13T19:27:55.504509Z", - "iopub.status.idle": "2023-12-13T19:27:55.543740Z", - "shell.execute_reply": "2023-12-13T19:27:55.542962Z", - "shell.execute_reply.started": "2023-12-13T19:27:55.504777Z" + "iopub.execute_input": "2024-02-13T00:33:59.751079Z", + "iopub.status.busy": "2024-02-13T00:33:59.750869Z", + "iopub.status.idle": "2024-02-13T00:33:59.783562Z", + "shell.execute_reply": "2024-02-13T00:33:59.782653Z", + "shell.execute_reply.started": "2024-02-13T00:33:59.751065Z" } }, "outputs": [], @@ -622,11 +631,11 @@ "execution_count": 13, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:55.545232Z", - "iopub.status.busy": "2023-12-13T19:27:55.544759Z", - "iopub.status.idle": "2023-12-13T19:27:55.579713Z", - "shell.execute_reply": "2023-12-13T19:27:55.578901Z", - "shell.execute_reply.started": "2023-12-13T19:27:55.545216Z" + "iopub.execute_input": "2024-02-13T00:33:59.784847Z", + "iopub.status.busy": "2024-02-13T00:33:59.784622Z", + "iopub.status.idle": "2024-02-13T00:33:59.815415Z", + "shell.execute_reply": "2024-02-13T00:33:59.814795Z", + "shell.execute_reply.started": "2024-02-13T00:33:59.784830Z" }, "tags": [] }, @@ -641,11 +650,11 @@ "execution_count": 14, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:55.581178Z", - "iopub.status.busy": "2023-12-13T19:27:55.580725Z", - "iopub.status.idle": "2023-12-13T19:27:55.611546Z", - "shell.execute_reply": "2023-12-13T19:27:55.610987Z", - "shell.execute_reply.started": "2023-12-13T19:27:55.581160Z" + "iopub.execute_input": "2024-02-13T00:33:59.816276Z", + "iopub.status.busy": "2024-02-13T00:33:59.816090Z", + "iopub.status.idle": "2024-02-13T00:33:59.848754Z", + "shell.execute_reply": "2024-02-13T00:33:59.848075Z", + "shell.execute_reply.started": "2024-02-13T00:33:59.816262Z" }, "tags": [] }, @@ -664,11 +673,11 @@ "execution_count": 15, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:55.612376Z", - "iopub.status.busy": "2023-12-13T19:27:55.612197Z", - "iopub.status.idle": "2023-12-13T19:27:55.642500Z", - "shell.execute_reply": "2023-12-13T19:27:55.641922Z", - "shell.execute_reply.started": "2023-12-13T19:27:55.612364Z" + "iopub.execute_input": "2024-02-13T00:33:59.849984Z", + "iopub.status.busy": "2024-02-13T00:33:59.849568Z", + "iopub.status.idle": "2024-02-13T00:33:59.882430Z", + "shell.execute_reply": "2024-02-13T00:33:59.881756Z", + "shell.execute_reply.started": "2024-02-13T00:33:59.849967Z" } }, "outputs": [], @@ -685,11 +694,11 @@ "execution_count": 16, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:55.643374Z", - "iopub.status.busy": "2023-12-13T19:27:55.643196Z", - "iopub.status.idle": "2023-12-13T19:27:56.941211Z", - "shell.execute_reply": "2023-12-13T19:27:56.940643Z", - "shell.execute_reply.started": "2023-12-13T19:27:55.643362Z" + "iopub.execute_input": "2024-02-13T00:33:59.883435Z", + "iopub.status.busy": "2024-02-13T00:33:59.883222Z", + "iopub.status.idle": "2024-02-13T00:34:00.699024Z", + "shell.execute_reply": "2024-02-13T00:34:00.698467Z", + "shell.execute_reply.started": "2024-02-13T00:33:59.883419Z" } }, "outputs": [], @@ -704,11 +713,11 @@ "execution_count": 17, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:56.942195Z", - "iopub.status.busy": "2023-12-13T19:27:56.941885Z", - "iopub.status.idle": "2023-12-13T19:27:56.974150Z", - "shell.execute_reply": "2023-12-13T19:27:56.973538Z", - "shell.execute_reply.started": "2023-12-13T19:27:56.942179Z" + "iopub.execute_input": "2024-02-13T00:34:00.700014Z", + "iopub.status.busy": "2024-02-13T00:34:00.699760Z", + "iopub.status.idle": "2024-02-13T00:34:00.729924Z", + "shell.execute_reply": "2024-02-13T00:34:00.729365Z", + "shell.execute_reply.started": "2024-02-13T00:34:00.700002Z" } }, "outputs": [], @@ -730,11 +739,11 @@ "execution_count": 18, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:56.975160Z", - "iopub.status.busy": "2023-12-13T19:27:56.974863Z", - "iopub.status.idle": "2023-12-13T19:27:57.018160Z", - "shell.execute_reply": "2023-12-13T19:27:57.017580Z", - "shell.execute_reply.started": "2023-12-13T19:27:56.975148Z" + "iopub.execute_input": "2024-02-13T00:34:00.730856Z", + "iopub.status.busy": "2024-02-13T00:34:00.730616Z", + "iopub.status.idle": "2024-02-13T00:34:00.759841Z", + "shell.execute_reply": "2024-02-13T00:34:00.759238Z", + "shell.execute_reply.started": "2024-02-13T00:34:00.730840Z" } }, "outputs": [], @@ -752,11 +761,11 @@ "execution_count": 19, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:57.019082Z", - "iopub.status.busy": "2023-12-13T19:27:57.018832Z", - "iopub.status.idle": "2023-12-13T19:27:57.051558Z", - "shell.execute_reply": "2023-12-13T19:27:57.050977Z", - "shell.execute_reply.started": "2023-12-13T19:27:57.019071Z" + "iopub.execute_input": "2024-02-13T00:34:00.760937Z", + "iopub.status.busy": "2024-02-13T00:34:00.760492Z", + "iopub.status.idle": "2024-02-13T00:34:00.789701Z", + "shell.execute_reply": "2024-02-13T00:34:00.789050Z", + "shell.execute_reply.started": "2024-02-13T00:34:00.760922Z" } }, "outputs": [], @@ -771,11 +780,11 @@ "execution_count": 20, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:57.052554Z", - "iopub.status.busy": "2023-12-13T19:27:57.052358Z", - "iopub.status.idle": "2023-12-13T19:27:57.083898Z", - "shell.execute_reply": "2023-12-13T19:27:57.083275Z", - "shell.execute_reply.started": "2023-12-13T19:27:57.052541Z" + "iopub.execute_input": "2024-02-13T00:34:00.790611Z", + "iopub.status.busy": "2024-02-13T00:34:00.790409Z", + "iopub.status.idle": "2024-02-13T00:34:00.821414Z", + "shell.execute_reply": "2024-02-13T00:34:00.820843Z", + "shell.execute_reply.started": "2024-02-13T00:34:00.790600Z" } }, "outputs": [ @@ -801,11 +810,11 @@ "execution_count": 21, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:57.084909Z", - "iopub.status.busy": "2023-12-13T19:27:57.084642Z", - "iopub.status.idle": "2023-12-13T19:27:57.120087Z", - "shell.execute_reply": "2023-12-13T19:27:57.119494Z", - "shell.execute_reply.started": "2023-12-13T19:27:57.084898Z" + "iopub.execute_input": "2024-02-13T00:34:00.825669Z", + "iopub.status.busy": "2024-02-13T00:34:00.825351Z", + "iopub.status.idle": "2024-02-13T00:34:00.856386Z", + "shell.execute_reply": "2024-02-13T00:34:00.855711Z", + "shell.execute_reply.started": "2024-02-13T00:34:00.825655Z" }, "tags": [] }, @@ -828,11 +837,11 @@ "execution_count": 22, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:57.122857Z", - "iopub.status.busy": "2023-12-13T19:27:57.122528Z", - "iopub.status.idle": "2023-12-13T19:27:57.152571Z", - "shell.execute_reply": "2023-12-13T19:27:57.152005Z", - "shell.execute_reply.started": "2023-12-13T19:27:57.122842Z" + "iopub.execute_input": "2024-02-13T00:34:00.857601Z", + "iopub.status.busy": "2024-02-13T00:34:00.857187Z", + "iopub.status.idle": "2024-02-13T00:34:00.887262Z", + "shell.execute_reply": "2024-02-13T00:34:00.886356Z", + "shell.execute_reply.started": "2024-02-13T00:34:00.857586Z" } }, "outputs": [], @@ -852,11 +861,11 @@ "execution_count": 23, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:57.153330Z", - "iopub.status.busy": "2023-12-13T19:27:57.153177Z", - "iopub.status.idle": "2023-12-13T19:27:57.185474Z", - "shell.execute_reply": "2023-12-13T19:27:57.184831Z", - "shell.execute_reply.started": "2023-12-13T19:27:57.153317Z" + "iopub.execute_input": "2024-02-13T00:34:00.888244Z", + "iopub.status.busy": "2024-02-13T00:34:00.887952Z", + "iopub.status.idle": "2024-02-13T00:34:00.920151Z", + "shell.execute_reply": "2024-02-13T00:34:00.919521Z", + "shell.execute_reply.started": "2024-02-13T00:34:00.888230Z" } }, "outputs": [], @@ -877,11 +886,11 @@ "execution_count": 24, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:57.186550Z", - "iopub.status.busy": "2023-12-13T19:27:57.186252Z", - "iopub.status.idle": "2023-12-13T19:27:57.217227Z", - "shell.execute_reply": "2023-12-13T19:27:57.216571Z", - "shell.execute_reply.started": "2023-12-13T19:27:57.186538Z" + "iopub.execute_input": "2024-02-13T00:34:00.921152Z", + "iopub.status.busy": "2024-02-13T00:34:00.920911Z", + "iopub.status.idle": "2024-02-13T00:34:00.950056Z", + "shell.execute_reply": "2024-02-13T00:34:00.949468Z", + "shell.execute_reply.started": "2024-02-13T00:34:00.921139Z" } }, "outputs": [], @@ -901,11 +910,11 @@ "execution_count": 25, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:57.218421Z", - "iopub.status.busy": "2023-12-13T19:27:57.217955Z", - "iopub.status.idle": "2023-12-13T19:27:57.248259Z", - "shell.execute_reply": "2023-12-13T19:27:57.247664Z", - "shell.execute_reply.started": "2023-12-13T19:27:57.218405Z" + "iopub.execute_input": "2024-02-13T00:34:00.951102Z", + "iopub.status.busy": "2024-02-13T00:34:00.950696Z", + "iopub.status.idle": "2024-02-13T00:34:00.981950Z", + "shell.execute_reply": "2024-02-13T00:34:00.981369Z", + "shell.execute_reply.started": "2024-02-13T00:34:00.951080Z" } }, "outputs": [], @@ -932,11 +941,11 @@ "execution_count": 26, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:57.249421Z", - "iopub.status.busy": "2023-12-13T19:27:57.248967Z", - "iopub.status.idle": "2023-12-13T19:27:58.315471Z", - "shell.execute_reply": "2023-12-13T19:27:58.314950Z", - "shell.execute_reply.started": "2023-12-13T19:27:57.249406Z" + "iopub.execute_input": "2024-02-13T00:34:00.983079Z", + "iopub.status.busy": "2024-02-13T00:34:00.982663Z", + "iopub.status.idle": "2024-02-13T00:34:01.713336Z", + "shell.execute_reply": "2024-02-13T00:34:01.712749Z", + "shell.execute_reply.started": "2024-02-13T00:34:00.983061Z" }, "lines_to_next_cell": 2 }, @@ -967,11 +976,11 @@ "execution_count": 27, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:58.316569Z", - "iopub.status.busy": "2023-12-13T19:27:58.316166Z", - "iopub.status.idle": "2023-12-13T19:27:58.347519Z", - "shell.execute_reply": "2023-12-13T19:27:58.346755Z", - "shell.execute_reply.started": "2023-12-13T19:27:58.316553Z" + "iopub.execute_input": "2024-02-13T00:34:01.714106Z", + "iopub.status.busy": "2024-02-13T00:34:01.713957Z", + "iopub.status.idle": "2024-02-13T00:34:01.745652Z", + "shell.execute_reply": "2024-02-13T00:34:01.745025Z", + "shell.execute_reply.started": "2024-02-13T00:34:01.714094Z" } }, "outputs": [], @@ -1020,11 +1029,11 @@ "execution_count": 28, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:58.348352Z", - "iopub.status.busy": "2023-12-13T19:27:58.348209Z", - "iopub.status.idle": "2023-12-13T19:27:58.378678Z", - "shell.execute_reply": "2023-12-13T19:27:58.378138Z", - "shell.execute_reply.started": "2023-12-13T19:27:58.348340Z" + "iopub.execute_input": "2024-02-13T00:34:01.746621Z", + "iopub.status.busy": "2024-02-13T00:34:01.746369Z", + "iopub.status.idle": "2024-02-13T00:34:01.777069Z", + "shell.execute_reply": "2024-02-13T00:34:01.776450Z", + "shell.execute_reply.started": "2024-02-13T00:34:01.746609Z" } }, "outputs": [], @@ -1049,11 +1058,11 @@ "execution_count": 29, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:58.379775Z", - "iopub.status.busy": "2023-12-13T19:27:58.379373Z", - "iopub.status.idle": "2023-12-13T19:27:58.545298Z", - "shell.execute_reply": "2023-12-13T19:27:58.544806Z", - "shell.execute_reply.started": "2023-12-13T19:27:58.379761Z" + "iopub.execute_input": "2024-02-13T00:34:01.777971Z", + "iopub.status.busy": "2024-02-13T00:34:01.777742Z", + "iopub.status.idle": "2024-02-13T00:34:01.942086Z", + "shell.execute_reply": "2024-02-13T00:34:01.941469Z", + "shell.execute_reply.started": "2024-02-13T00:34:01.777958Z" }, "tags": [] }, @@ -1095,11 +1104,11 @@ "execution_count": 30, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:58.546290Z", - "iopub.status.busy": "2023-12-13T19:27:58.545892Z", - "iopub.status.idle": "2023-12-13T19:27:58.574090Z", - "shell.execute_reply": "2023-12-13T19:27:58.573310Z", - "shell.execute_reply.started": "2023-12-13T19:27:58.546276Z" + "iopub.execute_input": "2024-02-13T00:34:01.943073Z", + "iopub.status.busy": "2024-02-13T00:34:01.942761Z", + "iopub.status.idle": "2024-02-13T00:34:01.973381Z", + "shell.execute_reply": "2024-02-13T00:34:01.972746Z", + "shell.execute_reply.started": "2024-02-13T00:34:01.943054Z" } }, "outputs": [], @@ -1122,11 +1131,11 @@ "execution_count": 31, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:58.575063Z", - "iopub.status.busy": "2023-12-13T19:27:58.574742Z", - "iopub.status.idle": "2023-12-13T19:27:58.642711Z", - "shell.execute_reply": "2023-12-13T19:27:58.642097Z", - "shell.execute_reply.started": "2023-12-13T19:27:58.575050Z" + "iopub.execute_input": "2024-02-13T00:34:01.974553Z", + "iopub.status.busy": "2024-02-13T00:34:01.974069Z", + "iopub.status.idle": "2024-02-13T00:34:02.027722Z", + "shell.execute_reply": "2024-02-13T00:34:02.027156Z", + "shell.execute_reply.started": "2024-02-13T00:34:01.974538Z" }, "tags": [] }, @@ -1147,11 +1156,11 @@ "execution_count": 32, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:58.643533Z", - "iopub.status.busy": "2023-12-13T19:27:58.643393Z", - "iopub.status.idle": "2023-12-13T19:27:58.674500Z", - "shell.execute_reply": "2023-12-13T19:27:58.673886Z", - "shell.execute_reply.started": "2023-12-13T19:27:58.643521Z" + "iopub.execute_input": "2024-02-13T00:34:02.028832Z", + "iopub.status.busy": "2024-02-13T00:34:02.028472Z", + "iopub.status.idle": "2024-02-13T00:34:02.059028Z", + "shell.execute_reply": "2024-02-13T00:34:02.058336Z", + "shell.execute_reply.started": "2024-02-13T00:34:02.028815Z" } }, "outputs": [], @@ -1174,11 +1183,11 @@ "execution_count": 33, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:27:58.675456Z", - "iopub.status.busy": "2023-12-13T19:27:58.675250Z", - "iopub.status.idle": "2023-12-13T19:27:58.705257Z", - "shell.execute_reply": "2023-12-13T19:27:58.704667Z", - "shell.execute_reply.started": "2023-12-13T19:27:58.675442Z" + "iopub.execute_input": "2024-02-13T00:34:02.060174Z", + "iopub.status.busy": "2024-02-13T00:34:02.059710Z", + "iopub.status.idle": "2024-02-13T00:34:02.088995Z", + "shell.execute_reply": "2024-02-13T00:34:02.088390Z", + "shell.execute_reply.started": "2024-02-13T00:34:02.060158Z" }, "tags": [] }, @@ -1217,11 +1226,11 @@ "execution_count": 34, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:04.420182Z", - "iopub.status.busy": "2023-12-05T23:04:04.419806Z", - "iopub.status.idle": "2023-12-05T23:04:04.474845Z", - "shell.execute_reply": "2023-12-05T23:04:04.474244Z", - "shell.execute_reply.started": "2023-12-05T23:04:04.420168Z" + "iopub.execute_input": "2024-02-13T00:34:02.090025Z", + "iopub.status.busy": "2024-02-13T00:34:02.089764Z", + "iopub.status.idle": "2024-02-13T00:34:02.320486Z", + "shell.execute_reply": "2024-02-13T00:34:02.319871Z", + "shell.execute_reply.started": "2024-02-13T00:34:02.090007Z" }, "tags": [] }, @@ -1336,11 +1345,11 @@ "execution_count": 35, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:04.475869Z", - "iopub.status.busy": "2023-12-05T23:04:04.475593Z", - "iopub.status.idle": "2023-12-05T23:04:04.505839Z", - "shell.execute_reply": "2023-12-05T23:04:04.505221Z", - "shell.execute_reply.started": "2023-12-05T23:04:04.475853Z" + "iopub.execute_input": "2024-02-13T00:34:02.321615Z", + "iopub.status.busy": "2024-02-13T00:34:02.321266Z", + "iopub.status.idle": "2024-02-13T00:34:02.352326Z", + "shell.execute_reply": "2024-02-13T00:34:02.351711Z", + "shell.execute_reply.started": "2024-02-13T00:34:02.321598Z" }, "tags": [] }, @@ -1426,11 +1435,11 @@ "execution_count": 36, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:04.506857Z", - "iopub.status.busy": "2023-12-05T23:04:04.506576Z", - "iopub.status.idle": "2023-12-05T23:04:04.539452Z", - "shell.execute_reply": "2023-12-05T23:04:04.538852Z", - "shell.execute_reply.started": "2023-12-05T23:04:04.506841Z" + "iopub.execute_input": "2024-02-13T00:34:02.353372Z", + "iopub.status.busy": "2024-02-13T00:34:02.352999Z", + "iopub.status.idle": "2024-02-13T00:34:02.385557Z", + "shell.execute_reply": "2024-02-13T00:34:02.384951Z", + "shell.execute_reply.started": "2024-02-13T00:34:02.353353Z" }, "tags": [] }, @@ -1541,11 +1550,11 @@ "execution_count": 37, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:04.540242Z", - "iopub.status.busy": "2023-12-05T23:04:04.540102Z", - "iopub.status.idle": "2023-12-05T23:04:04.572867Z", - "shell.execute_reply": "2023-12-05T23:04:04.572297Z", - "shell.execute_reply.started": "2023-12-05T23:04:04.540229Z" + "iopub.execute_input": "2024-02-13T00:34:02.387032Z", + "iopub.status.busy": "2024-02-13T00:34:02.386353Z", + "iopub.status.idle": "2024-02-13T00:34:02.418127Z", + "shell.execute_reply": "2024-02-13T00:34:02.417530Z", + "shell.execute_reply.started": "2024-02-13T00:34:02.387002Z" }, "tags": [] }, @@ -1646,11 +1655,11 @@ "execution_count": 38, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:04.573963Z", - "iopub.status.busy": "2023-12-05T23:04:04.573627Z", - "iopub.status.idle": "2023-12-05T23:04:04.605655Z", - "shell.execute_reply": "2023-12-05T23:04:04.604954Z", - "shell.execute_reply.started": "2023-12-05T23:04:04.573947Z" + "iopub.execute_input": "2024-02-13T00:34:02.419108Z", + "iopub.status.busy": "2024-02-13T00:34:02.418812Z", + "iopub.status.idle": "2024-02-13T00:34:02.450269Z", + "shell.execute_reply": "2024-02-13T00:34:02.449597Z", + "shell.execute_reply.started": "2024-02-13T00:34:02.419095Z" }, "tags": [] }, @@ -1709,11 +1718,11 @@ "execution_count": 39, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:04.606497Z", - "iopub.status.busy": "2023-12-05T23:04:04.606330Z", - "iopub.status.idle": "2023-12-05T23:04:08.053875Z", - "shell.execute_reply": "2023-12-05T23:04:08.053235Z", - "shell.execute_reply.started": "2023-12-05T23:04:04.606484Z" + "iopub.execute_input": "2024-02-13T00:34:02.451478Z", + "iopub.status.busy": "2024-02-13T00:34:02.451045Z", + "iopub.status.idle": "2024-02-13T00:34:05.721251Z", + "shell.execute_reply": "2024-02-13T00:34:05.720576Z", + "shell.execute_reply.started": "2024-02-13T00:34:02.451463Z" }, "tags": [] }, @@ -1736,257 +1745,257 @@ "\n", " \n", " \n", - "
2570def resize(\n",
-       "2571    array: _Array,\n",
-       "2572    /,\n",
-       "2573    shape: Iterable[int],\n",
-       "2574    *,\n",
-       "2575    gridtype: str | Gridtype | None = None,\n",
-       "2576    src_gridtype: str | Gridtype | Iterable[str | Gridtype] | None = None,\n",
-       "2577    dst_gridtype: str | Gridtype | Iterable[str | Gridtype] | None = None,\n",
-       "2578    boundary: str | Boundary | Iterable[str | Boundary] = 'auto',\n",
-       "2579    cval: _ArrayLike = 0,\n",
-       "2580    filter: str | Filter | Iterable[str | Filter] = _DEFAULT_FILTER,\n",
-       "2581    prefilter: str | Filter | Iterable[str | Filter] | None = None,\n",
-       "2582    gamma: str | Gamma | None = None,\n",
-       "2583    src_gamma: str | Gamma | None = None,\n",
-       "2584    dst_gamma: str | Gamma | None = None,\n",
-       "2585    scale: float | Iterable[float] = 1.0,\n",
-       "2586    translate: float | Iterable[float] = 0.0,\n",
-       "2587    precision: _DTypeLike = None,\n",
-       "2588    dtype: _DTypeLike = None,\n",
-       "2589    dim_order: Iterable[int] | None = None,\n",
-       "2590    num_threads: int | Literal['auto'] = 'auto',\n",
-       "2591) -> _Array:\n",
-       "2592  """Resample `array` (a grid of sample values) onto a grid with resolution `shape`.\n",
-       "2593\n",
-       "2594  The source `array` is any object recognized by `ARRAYLIBS`.  It is interpreted as a grid\n",
-       "2595  with `len(shape)` domain coordinate dimensions, where each grid sample value has shape\n",
-       "2596  `array.shape[len(shape):]`.\n",
-       "2597\n",
-       "2598  Some examples:\n",
-       "2599\n",
-       "2600  - A grayscale image has `array.shape = height, width` and resizing it with `len(shape) == 2`\n",
-       "2601    produces a new image of scalar values.\n",
-       "2602  - An RGB image has `array.shape = height, width, 3` and resizing it with `len(shape) == 2`\n",
-       "2603    produces a new image of RGB values.\n",
-       "2604  - An 3D grid of 3x3 Jacobians has `array.shape = Z, Y, X, 3, 3` and resizing it with\n",
-       "2605    `len(shape) == 3` produces a new 3D grid of Jacobians.\n",
-       "2606\n",
-       "2607  This function also allows scaling and translation from the source domain to the output domain\n",
-       "2608  through the parameters `scale` and `translate`.  For more general transforms, see `resample`.\n",
-       "2609\n",
-       "2610  Args:\n",
-       "2611    array: Regular grid of source sample values, as an array object recognized by `ARRAYLIBS`.\n",
-       "2612      The array must have numeric type.  Its first `len(shape)` dimensions are the domain\n",
-       "2613      coordinate dimensions.  Each grid dimension must be at least 1 for a `'dual'` grid or\n",
-       "2614      at least 2 for a `'primal'` grid.\n",
-       "2615    shape: The number of grid samples in each coordinate dimension of the output array.  The source\n",
-       "2616      `array` must have at least as many dimensions as `len(shape)`.\n",
-       "2617    gridtype: Placement of samples on all dimensions of both the source and output domain grids,\n",
-       "2618      specified as either a name in `GRIDTYPES` or a `Gridtype` instance.  It defaults to `'dual'`\n",
-       "2619      if `gridtype`, `src_gridtype`, and `dst_gridtype` are all kept `None`.\n",
-       "2620    src_gridtype: Placement of the samples in the source domain grid for each dimension.\n",
-       "2621      Parameters `gridtype` and `src_gridtype` cannot both be set.\n",
-       "2622    dst_gridtype: Placement of the samples in the output domain grid for each dimension.\n",
-       "2623      Parameters `gridtype` and `dst_gridtype` cannot both be set.\n",
-       "2624    boundary: The reconstruction boundary rule for each dimension in `shape`, specified as either\n",
-       "2625      a name in `BOUNDARIES` or a `Boundary` instance.  The special value `'auto'` uses `'reflect'`\n",
-       "2626      for upsampling and `'clamp'` for downsampling.\n",
-       "2627    cval: Constant value used beyond the samples by some boundary rules.  It must be broadcastable\n",
-       "2628      onto `array.shape[len(shape):]`.\n",
-       "2629    filter: The reconstruction kernel for each dimension in `shape`, specified as either a filter\n",
-       "2630      name in `FILTERS` or a `Filter` instance.  It is used during upsampling (i.e., magnification).\n",
-       "2631    prefilter: The prefilter kernel for each dimension in `shape`, specified as either a filter\n",
-       "2632      name in `FILTERS` or a `Filter` instance.  It is used during downsampling\n",
-       "2633      (i.e., minification).  If `None`, it inherits the value of `filter`.  The default\n",
-       "2634      `'lanczos3'` is good for natural images.  For vector graphics images, `'trapezoid'` is better\n",
-       "2635      because it avoids ringing artifacts.\n",
-       "2636    gamma: Component transfer functions (e.g., gamma correction) applied when reading samples from\n",
-       "2637      `array` and when creating output grid samples.  It is specified as either a name in `GAMMAS`\n",
-       "2638      or a `Gamma` instance.  If both `array.dtype` and `dtype` are `uint`, the default is\n",
-       "2639      `'power2'`.  If both are non-`uint`, the default is `'identity'`.  Otherwise, `gamma` or\n",
-       "2640      `src_gamma`/`dst_gamma` must be set.   Gamma correction assumes that float values are in the\n",
-       "2641      range [0.0, 1.0].\n",
-       "2642    src_gamma: Component transfer function used to "decode" `array` samples.\n",
-       "2643      Parameters `gamma` and `src_gamma` cannot both be set.\n",
-       "2644    dst_gamma: Component transfer function used to "encode" the output samples.\n",
-       "2645      Parameters `gamma` and `dst_gamma` cannot both be set.\n",
-       "2646    scale: Scaling factor applied to each dimension of the source domain when it is mapped onto\n",
-       "2647      the destination domain.\n",
-       "2648    translate: Offset applied to each dimension of the scaled source domain when it is mapped onto\n",
-       "2649      the destination domain.\n",
-       "2650    precision: Inexact precision of intermediate computations.  If `None`, it is determined based\n",
-       "2651      on `array.dtype` and `dtype`.\n",
-       "2652    dtype: Desired data type of the output array.  If `None`, it is taken to be `array.dtype`.\n",
-       "2653      If it is a uint type, the intermediate float values are rescaled from the [0.0, 1.0] range\n",
-       "2654      to the uint range.\n",
-       "2655    dim_order: Override the automatically selected order in which the grid dimensions are resized.\n",
-       "2656      Must contain a permutation of `range(len(shape))`.\n",
-       "2657    num_threads: Used to determine multithread parallelism if `array` is from `numpy`.  If set to\n",
-       "2658      `'auto'`, it is selected automatically.  Otherwise, it must be a positive integer.\n",
-       "2659\n",
-       "2660  Returns:\n",
-       "2661    An array of the same class as the source `array`, with shape `shape + array.shape[len(shape):]`\n",
-       "2662      and data type `dtype`.\n",
-       "2663\n",
-       "2664  **Example of image upsampling:**\n",
-       "2665\n",
-       "2666  >>> array = np.random.default_rng(1).random((4, 6, 3))  # 4x6 RGB image.\n",
-       "2667  >>> upsampled = resize(array, (128, 192))  # To 128x192 resolution.\n",
-       "2668\n",
-       "2669  <center>\n",
-       "2670  <img src="https://github.com/hhoppe/resampler/raw/main/media/example_array_upsampled.png"/>\n",
-       "2671  </center>\n",
-       "2672\n",
-       "2673  **Example of image downsampling:**\n",
-       "2674\n",
-       "2675  >>> yx = (np.moveaxis(np.indices((96, 192)), 0, -1) + (0.5, 0.5)) / 96\n",
-       "2676  >>> radius = np.linalg.norm(yx - (0.75, 0.5), axis=-1)\n",
-       "2677  >>> array = np.cos((radius + 0.1) ** 0.5 * 70.0) * 0.5 + 0.5\n",
-       "2678  >>> downsampled = resize(array, (24, 48))\n",
-       "2679\n",
-       "2680  <center>\n",
-       "2681  <img src="https://github.com/hhoppe/resampler/raw/main/media/example_array_downsampled2.png"/>\n",
-       "2682  </center>\n",
-       "2683\n",
-       "2684  **Unit test:**\n",
-       "2685\n",
-       "2686  >>> result = resize([1.0, 4.0, 5.0], shape=(4,))\n",
-       "2687  >>> assert np.allclose(result, [0.74240461, 2.88088827, 4.68647155, 5.02641199])\n",
-       "2688  """\n",
-       "2689  if isinstance(array, (tuple, list)):\n",
-       "2690    array = np.asarray(array)\n",
-       "2691  arraylib = _arr_arraylib(array)\n",
-       "2692  array_dtype = _arr_dtype(array)\n",
-       "2693  if not np.issubdtype(array_dtype, np.number):\n",
-       "2694    raise ValueError(f'Type {array.dtype} is not numeric.')\n",
-       "2695  shape2 = tuple(shape)\n",
-       "2696  array_ndim = len(array.shape)\n",
-       "2697  if not 0 < len(shape2) <= array_ndim:\n",
-       "2698    raise ValueError(f'Shape {array.shape} cannot be resized to {shape2}.')\n",
-       "2699  src_shape = array.shape[: len(shape2)]\n",
-       "2700  src_gridtype2, dst_gridtype2 = _get_gridtypes(\n",
-       "2701      gridtype, src_gridtype, dst_gridtype, len(shape2), len(shape2)\n",
-       "2702  )\n",
-       "2703  boundary2 = np.broadcast_to(np.array(boundary), len(shape2))\n",
-       "2704  cval = np.broadcast_to(cval, array.shape[len(shape2) :])\n",
-       "2705  prefilter = filter if prefilter is None else prefilter\n",
-       "2706  filter2 = [_get_filter(f) for f in np.broadcast_to(np.array(filter), len(shape2))]\n",
-       "2707  prefilter2 = [_get_filter(f) for f in np.broadcast_to(np.array(prefilter), len(shape2))]\n",
-       "2708  dtype = array_dtype if dtype is None else np.dtype(dtype)\n",
-       "2709  src_gamma2, dst_gamma2 = _get_src_dst_gamma(gamma, src_gamma, dst_gamma, array_dtype, dtype)\n",
-       "2710  scale2 = np.broadcast_to(np.array(scale), len(shape2))\n",
-       "2711  translate2 = np.broadcast_to(np.array(translate), len(shape2))\n",
-       "2712  del (shape, src_gridtype, dst_gridtype, boundary, filter, prefilter)\n",
-       "2713  del (src_gamma, dst_gamma, scale, translate)\n",
-       "2714  precision = _get_precision(precision, [array_dtype, dtype], [])\n",
-       "2715  weight_precision = _real_precision(precision)\n",
-       "2716\n",
-       "2717  is_noop = (\n",
-       "2718      all(src == dst for src, dst in zip(src_shape, shape2))\n",
-       "2719      and all(gt1 == gt2 for gt1, gt2 in zip(src_gridtype2, dst_gridtype2))\n",
-       "2720      and all(f.interpolating for f in prefilter2)\n",
-       "2721      and np.all(scale2 == 1.0)\n",
-       "2722      and np.all(translate2 == 0.0)\n",
-       "2723      and src_gamma2 == dst_gamma2\n",
-       "2724  )\n",
-       "2725  if is_noop:\n",
-       "2726    return array\n",
-       "2727\n",
-       "2728  if dim_order is None:\n",
-       "2729    dim_order = _arr_best_dims_order_for_resize(array, shape2)\n",
-       "2730  else:\n",
-       "2731    dim_order = tuple(dim_order)\n",
-       "2732    if sorted(dim_order) != list(range(len(shape2))):\n",
-       "2733      raise ValueError(f'{dim_order} not a permutation of {list(range(len(shape2)))}.')\n",
-       "2734\n",
-       "2735  array = src_gamma2.decode(array, precision)\n",
-       "2736\n",
-       "2737  can_use_fast_box_downsampling = (\n",
-       "2738      using_numba\n",
-       "2739      and arraylib == 'numpy'\n",
-       "2740      and len(shape2) == 2\n",
-       "2741      and array_ndim in (2, 3)\n",
-       "2742      and all(src > dst for src, dst in zip(src_shape, shape2))\n",
-       "2743      and all(src % dst == 0 for src, dst in zip(src_shape, shape2))\n",
-       "2744      and all(gridtype.name == 'dual' for gridtype in src_gridtype2)\n",
-       "2745      and all(gridtype.name == 'dual' for gridtype in dst_gridtype2)\n",
-       "2746      and all(f.name in ('box', 'trapezoid') for f in prefilter2)\n",
-       "2747      and np.all(scale2 == 1.0)\n",
-       "2748      and np.all(translate2 == 0.0)\n",
-       "2749  )\n",
-       "2750  if can_use_fast_box_downsampling:\n",
-       "2751    assert isinstance(array, np.ndarray)  # Help mypy.\n",
-       "2752    array = _downsample_in_2d_using_box_filter(array, typing.cast(Any, shape2))\n",
-       "2753    array = dst_gamma2.encode(array, dtype)\n",
-       "2754    return array\n",
+       "            
2589def resize(\n",
+       "2590    array: _Array,\n",
+       "2591    /,\n",
+       "2592    shape: Iterable[int],\n",
+       "2593    *,\n",
+       "2594    gridtype: str | Gridtype | None = None,\n",
+       "2595    src_gridtype: str | Gridtype | Iterable[str | Gridtype] | None = None,\n",
+       "2596    dst_gridtype: str | Gridtype | Iterable[str | Gridtype] | None = None,\n",
+       "2597    boundary: str | Boundary | Iterable[str | Boundary] = 'auto',\n",
+       "2598    cval: _ArrayLike = 0,\n",
+       "2599    filter: str | Filter | Iterable[str | Filter] = _DEFAULT_FILTER,\n",
+       "2600    prefilter: str | Filter | Iterable[str | Filter] | None = None,\n",
+       "2601    gamma: str | Gamma | None = None,\n",
+       "2602    src_gamma: str | Gamma | None = None,\n",
+       "2603    dst_gamma: str | Gamma | None = None,\n",
+       "2604    scale: float | Iterable[float] = 1.0,\n",
+       "2605    translate: float | Iterable[float] = 0.0,\n",
+       "2606    precision: _DTypeLike = None,\n",
+       "2607    dtype: _DTypeLike = None,\n",
+       "2608    dim_order: Iterable[int] | None = None,\n",
+       "2609    num_threads: int | Literal['auto'] = 'auto',\n",
+       "2610) -> _Array:\n",
+       "2611  """Resample `array` (a grid of sample values) onto a grid with resolution `shape`.\n",
+       "2612\n",
+       "2613  The source `array` is any object recognized by `ARRAYLIBS`.  It is interpreted as a grid\n",
+       "2614  with `len(shape)` domain coordinate dimensions, where each grid sample value has shape\n",
+       "2615  `array.shape[len(shape):]`.\n",
+       "2616\n",
+       "2617  Some examples:\n",
+       "2618\n",
+       "2619  - A grayscale image has `array.shape = height, width` and resizing it with `len(shape) == 2`\n",
+       "2620    produces a new image of scalar values.\n",
+       "2621  - An RGB image has `array.shape = height, width, 3` and resizing it with `len(shape) == 2`\n",
+       "2622    produces a new image of RGB values.\n",
+       "2623  - An 3D grid of 3x3 Jacobians has `array.shape = Z, Y, X, 3, 3` and resizing it with\n",
+       "2624    `len(shape) == 3` produces a new 3D grid of Jacobians.\n",
+       "2625\n",
+       "2626  This function also allows scaling and translation from the source domain to the output domain\n",
+       "2627  through the parameters `scale` and `translate`.  For more general transforms, see `resample`.\n",
+       "2628\n",
+       "2629  Args:\n",
+       "2630    array: Regular grid of source sample values, as an array object recognized by `ARRAYLIBS`.\n",
+       "2631      The array must have numeric type.  Its first `len(shape)` dimensions are the domain\n",
+       "2632      coordinate dimensions.  Each grid dimension must be at least 1 for a `'dual'` grid or\n",
+       "2633      at least 2 for a `'primal'` grid.\n",
+       "2634    shape: The number of grid samples in each coordinate dimension of the output array.  The source\n",
+       "2635      `array` must have at least as many dimensions as `len(shape)`.\n",
+       "2636    gridtype: Placement of samples on all dimensions of both the source and output domain grids,\n",
+       "2637      specified as either a name in `GRIDTYPES` or a `Gridtype` instance.  It defaults to `'dual'`\n",
+       "2638      if `gridtype`, `src_gridtype`, and `dst_gridtype` are all kept `None`.\n",
+       "2639    src_gridtype: Placement of the samples in the source domain grid for each dimension.\n",
+       "2640      Parameters `gridtype` and `src_gridtype` cannot both be set.\n",
+       "2641    dst_gridtype: Placement of the samples in the output domain grid for each dimension.\n",
+       "2642      Parameters `gridtype` and `dst_gridtype` cannot both be set.\n",
+       "2643    boundary: The reconstruction boundary rule for each dimension in `shape`, specified as either\n",
+       "2644      a name in `BOUNDARIES` or a `Boundary` instance.  The special value `'auto'` uses `'reflect'`\n",
+       "2645      for upsampling and `'clamp'` for downsampling.\n",
+       "2646    cval: Constant value used beyond the samples by some boundary rules.  It must be broadcastable\n",
+       "2647      onto `array.shape[len(shape):]`.\n",
+       "2648    filter: The reconstruction kernel for each dimension in `shape`, specified as either a filter\n",
+       "2649      name in `FILTERS` or a `Filter` instance.  It is used during upsampling (i.e., magnification).\n",
+       "2650    prefilter: The prefilter kernel for each dimension in `shape`, specified as either a filter\n",
+       "2651      name in `FILTERS` or a `Filter` instance.  It is used during downsampling\n",
+       "2652      (i.e., minification).  If `None`, it inherits the value of `filter`.  The default\n",
+       "2653      `'lanczos3'` is good for natural images.  For vector graphics images, `'trapezoid'` is better\n",
+       "2654      because it avoids ringing artifacts.\n",
+       "2655    gamma: Component transfer functions (e.g., gamma correction) applied when reading samples from\n",
+       "2656      `array` and when creating output grid samples.  It is specified as either a name in `GAMMAS`\n",
+       "2657      or a `Gamma` instance.  If both `array.dtype` and `dtype` are `uint`, the default is\n",
+       "2658      `'power2'`.  If both are non-`uint`, the default is `'identity'`.  Otherwise, `gamma` or\n",
+       "2659      `src_gamma`/`dst_gamma` must be set.   Gamma correction assumes that float values are in the\n",
+       "2660      range [0.0, 1.0].\n",
+       "2661    src_gamma: Component transfer function used to "decode" `array` samples.\n",
+       "2662      Parameters `gamma` and `src_gamma` cannot both be set.\n",
+       "2663    dst_gamma: Component transfer function used to "encode" the output samples.\n",
+       "2664      Parameters `gamma` and `dst_gamma` cannot both be set.\n",
+       "2665    scale: Scaling factor applied to each dimension of the source domain when it is mapped onto\n",
+       "2666      the destination domain.\n",
+       "2667    translate: Offset applied to each dimension of the scaled source domain when it is mapped onto\n",
+       "2668      the destination domain.\n",
+       "2669    precision: Inexact precision of intermediate computations.  If `None`, it is determined based\n",
+       "2670      on `array.dtype` and `dtype`.\n",
+       "2671    dtype: Desired data type of the output array.  If `None`, it is taken to be `array.dtype`.\n",
+       "2672      If it is a uint type, the intermediate float values are rescaled from the [0.0, 1.0] range\n",
+       "2673      to the uint range.\n",
+       "2674    dim_order: Override the automatically selected order in which the grid dimensions are resized.\n",
+       "2675      Must contain a permutation of `range(len(shape))`.\n",
+       "2676    num_threads: Used to determine multithread parallelism if `array` is from `numpy`.  If set to\n",
+       "2677      `'auto'`, it is selected automatically.  Otherwise, it must be a positive integer.\n",
+       "2678\n",
+       "2679  Returns:\n",
+       "2680    An array of the same class as the source `array`, with shape `shape + array.shape[len(shape):]`\n",
+       "2681      and data type `dtype`.\n",
+       "2682\n",
+       "2683  **Example of image upsampling:**\n",
+       "2684\n",
+       "2685  >>> array = np.random.default_rng(1).random((4, 6, 3))  # 4x6 RGB image.\n",
+       "2686  >>> upsampled = resize(array, (128, 192))  # To 128x192 resolution.\n",
+       "2687\n",
+       "2688  <center>\n",
+       "2689  <img src="https://github.com/hhoppe/resampler/raw/main/media/example_array_upsampled.png"/>\n",
+       "2690  </center>\n",
+       "2691\n",
+       "2692  **Example of image downsampling:**\n",
+       "2693\n",
+       "2694  >>> yx = (np.moveaxis(np.indices((96, 192)), 0, -1) + (0.5, 0.5)) / 96\n",
+       "2695  >>> radius = np.linalg.norm(yx - (0.75, 0.5), axis=-1)\n",
+       "2696  >>> array = np.cos((radius + 0.1) ** 0.5 * 70.0) * 0.5 + 0.5\n",
+       "2697  >>> downsampled = resize(array, (24, 48))\n",
+       "2698\n",
+       "2699  <center>\n",
+       "2700  <img src="https://github.com/hhoppe/resampler/raw/main/media/example_array_downsampled2.png"/>\n",
+       "2701  </center>\n",
+       "2702\n",
+       "2703  **Unit test:**\n",
+       "2704\n",
+       "2705  >>> result = resize([1.0, 4.0, 5.0], shape=(4,))\n",
+       "2706  >>> assert np.allclose(result, [0.74240461, 2.88088827, 4.68647155, 5.02641199])\n",
+       "2707  """\n",
+       "2708  if isinstance(array, (tuple, list)):\n",
+       "2709    array = np.asarray(array)\n",
+       "2710  arraylib = _arr_arraylib(array)\n",
+       "2711  array_dtype = _arr_dtype(array)\n",
+       "2712  if not np.issubdtype(array_dtype, np.number):\n",
+       "2713    raise ValueError(f'Type {array.dtype} is not numeric.')\n",
+       "2714  shape2 = tuple(shape)\n",
+       "2715  array_ndim = len(array.shape)\n",
+       "2716  if not 0 < len(shape2) <= array_ndim:\n",
+       "2717    raise ValueError(f'Shape {array.shape} cannot be resized to {shape2}.')\n",
+       "2718  src_shape = array.shape[: len(shape2)]\n",
+       "2719  src_gridtype2, dst_gridtype2 = _get_gridtypes(\n",
+       "2720      gridtype, src_gridtype, dst_gridtype, len(shape2), len(shape2)\n",
+       "2721  )\n",
+       "2722  boundary2 = np.broadcast_to(np.array(boundary), len(shape2))\n",
+       "2723  cval = np.broadcast_to(cval, array.shape[len(shape2) :])\n",
+       "2724  prefilter = filter if prefilter is None else prefilter\n",
+       "2725  filter2 = [_get_filter(f) for f in np.broadcast_to(np.array(filter), len(shape2))]\n",
+       "2726  prefilter2 = [_get_filter(f) for f in np.broadcast_to(np.array(prefilter), len(shape2))]\n",
+       "2727  dtype = array_dtype if dtype is None else np.dtype(dtype)\n",
+       "2728  src_gamma2, dst_gamma2 = _get_src_dst_gamma(gamma, src_gamma, dst_gamma, array_dtype, dtype)\n",
+       "2729  scale2 = np.broadcast_to(np.array(scale), len(shape2))\n",
+       "2730  translate2 = np.broadcast_to(np.array(translate), len(shape2))\n",
+       "2731  del (shape, src_gridtype, dst_gridtype, boundary, filter, prefilter)\n",
+       "2732  del (src_gamma, dst_gamma, scale, translate)\n",
+       "2733  precision = _get_precision(precision, [array_dtype, dtype], [])\n",
+       "2734  weight_precision = _real_precision(precision)\n",
+       "2735\n",
+       "2736  is_noop = (\n",
+       "2737      all(src == dst for src, dst in zip(src_shape, shape2))\n",
+       "2738      and all(gt1 == gt2 for gt1, gt2 in zip(src_gridtype2, dst_gridtype2))\n",
+       "2739      and all(f.interpolating for f in prefilter2)\n",
+       "2740      and np.all(scale2 == 1.0)\n",
+       "2741      and np.all(translate2 == 0.0)\n",
+       "2742      and src_gamma2 == dst_gamma2\n",
+       "2743  )\n",
+       "2744  if is_noop:\n",
+       "2745    return array\n",
+       "2746\n",
+       "2747  if dim_order is None:\n",
+       "2748    dim_order = _arr_best_dims_order_for_resize(array, shape2)\n",
+       "2749  else:\n",
+       "2750    dim_order = tuple(dim_order)\n",
+       "2751    if sorted(dim_order) != list(range(len(shape2))):\n",
+       "2752      raise ValueError(f'{dim_order} not a permutation of {list(range(len(shape2)))}.')\n",
+       "2753\n",
+       "2754  array = src_gamma2.decode(array, precision)\n",
        "2755\n",
-       "2756  # Multidimensional resize can be expressed using einsum() with multiple per-dim resize matrices,\n",
-       "2757  # e.g., as in jax.image.resize().  A benefit is to seek the optimal order of multiplications.\n",
-       "2758  # However, efficiency often requires sparse resize matrices, which are unsupported in einsum().\n",
-       "2759  # Sparse tensors requested for tf.einsum: https://github.com/tensorflow/tensorflow/issues/43497\n",
-       "2760  # https://github.com/tensor-compiler/taco: C++ library that computes tensor algebra expressions\n",
-       "2761  # on sparse and dense tensors; however it does not interoperate with tensorflow, torch, or jax.\n",
-       "2762\n",
-       "2763  for dim in dim_order:\n",
-       "2764    skip_resize_on_this_dim = (\n",
-       "2765        shape2[dim] == array.shape[dim]\n",
-       "2766        and scale2[dim] == 1.0\n",
-       "2767        and translate2[dim] == 0.0\n",
-       "2768        and filter2[dim].interpolating\n",
-       "2769    )\n",
-       "2770    if skip_resize_on_this_dim:\n",
-       "2771      continue\n",
-       "2772\n",
-       "2773    def get_is_minification() -> bool:\n",
-       "2774      src_in_samples = src_gridtype2[dim].size_in_samples(array.shape[dim])\n",
-       "2775      dst_in_samples = dst_gridtype2[dim].size_in_samples(shape2[dim])\n",
-       "2776      return dst_in_samples / src_in_samples * scale2[dim] < 1.0\n",
-       "2777\n",
-       "2778    is_minification = get_is_minification()\n",
-       "2779    boundary_dim = boundary2[dim]\n",
-       "2780    if boundary_dim == 'auto':\n",
-       "2781      boundary_dim = 'clamp' if is_minification else 'reflect'\n",
-       "2782    boundary_dim = _get_boundary(boundary_dim)\n",
-       "2783    resize_matrix, cval_weight = _create_resize_matrix(\n",
-       "2784        array.shape[dim],\n",
-       "2785        shape2[dim],\n",
-       "2786        src_gridtype=src_gridtype2[dim],\n",
-       "2787        dst_gridtype=dst_gridtype2[dim],\n",
-       "2788        boundary=boundary_dim,\n",
-       "2789        filter=filter2[dim],\n",
-       "2790        prefilter=prefilter2[dim],\n",
-       "2791        scale=scale2[dim],\n",
-       "2792        translate=translate2[dim],\n",
-       "2793        dtype=weight_precision,\n",
-       "2794        arraylib=arraylib,\n",
-       "2795    )\n",
+       "2756  can_use_fast_box_downsampling = (\n",
+       "2757      using_numba\n",
+       "2758      and arraylib == 'numpy'\n",
+       "2759      and len(shape2) == 2\n",
+       "2760      and array_ndim in (2, 3)\n",
+       "2761      and all(src > dst for src, dst in zip(src_shape, shape2))\n",
+       "2762      and all(src % dst == 0 for src, dst in zip(src_shape, shape2))\n",
+       "2763      and all(gridtype.name == 'dual' for gridtype in src_gridtype2)\n",
+       "2764      and all(gridtype.name == 'dual' for gridtype in dst_gridtype2)\n",
+       "2765      and all(f.name in ('box', 'trapezoid') for f in prefilter2)\n",
+       "2766      and np.all(scale2 == 1.0)\n",
+       "2767      and np.all(translate2 == 0.0)\n",
+       "2768  )\n",
+       "2769  if can_use_fast_box_downsampling:\n",
+       "2770    assert isinstance(array, np.ndarray)  # Help mypy.\n",
+       "2771    array = _downsample_in_2d_using_box_filter(array, typing.cast(Any, shape2))\n",
+       "2772    array = dst_gamma2.encode(array, dtype)\n",
+       "2773    return array\n",
+       "2774\n",
+       "2775  # Multidimensional resize can be expressed using einsum() with multiple per-dim resize matrices,\n",
+       "2776  # e.g., as in jax.image.resize().  A benefit is to seek the optimal order of multiplications.\n",
+       "2777  # However, efficiency often requires sparse resize matrices, which are unsupported in einsum().\n",
+       "2778  # Sparse tensors requested for tf.einsum: https://github.com/tensorflow/tensorflow/issues/43497\n",
+       "2779  # https://github.com/tensor-compiler/taco: C++ library that computes tensor algebra expressions\n",
+       "2780  # on sparse and dense tensors; however it does not interoperate with tensorflow, torch, or jax.\n",
+       "2781\n",
+       "2782  for dim in dim_order:\n",
+       "2783    skip_resize_on_this_dim = (\n",
+       "2784        shape2[dim] == array.shape[dim]\n",
+       "2785        and scale2[dim] == 1.0\n",
+       "2786        and translate2[dim] == 0.0\n",
+       "2787        and filter2[dim].interpolating\n",
+       "2788    )\n",
+       "2789    if skip_resize_on_this_dim:\n",
+       "2790      continue\n",
+       "2791\n",
+       "2792    def get_is_minification() -> bool:\n",
+       "2793      src_in_samples = src_gridtype2[dim].size_in_samples(array.shape[dim])\n",
+       "2794      dst_in_samples = dst_gridtype2[dim].size_in_samples(shape2[dim])\n",
+       "2795      return dst_in_samples / src_in_samples * scale2[dim] < 1.0\n",
        "2796\n",
-       "2797    array_dim: _Array = _arr_moveaxis(array, dim, 0)\n",
-       "2798    array_flat = _arr_reshape(array_dim, (array_dim.shape[0], -1))\n",
-       "2799    array_flat = _arr_possibly_make_contiguous(array_flat)\n",
-       "2800    if not is_minification and filter2[dim].requires_digital_filter:\n",
-       "2801      array_flat = _apply_digital_filter_1d(\n",
-       "2802          array_flat, src_gridtype2[dim], boundary_dim, cval, filter2[dim]\n",
-       "2803      )\n",
-       "2804\n",
-       "2805    array_flat = _arr_matmul_sparse_dense(resize_matrix, array_flat, num_threads=num_threads)\n",
-       "2806    if cval_weight is not None:\n",
-       "2807      cval_flat = np.broadcast_to(cval, array_dim.shape[1:]).reshape(-1)\n",
-       "2808      if np.issubdtype(array_dtype, np.complexfloating):\n",
-       "2809        cval_weight = _arr_astype(cval_weight, array_dtype)  # (Only necessary for 'tensorflow'.)\n",
-       "2810      array_flat += cval_weight[:, None] * cval_flat\n",
-       "2811\n",
-       "2812    if is_minification and filter2[dim].requires_digital_filter:  # use prefilter2[dim]?\n",
-       "2813      array_flat = _apply_digital_filter_1d(\n",
-       "2814          array_flat, dst_gridtype2[dim], boundary_dim, cval, filter2[dim]\n",
-       "2815      )\n",
-       "2816    array_dim = _arr_reshape(array_flat, (array_flat.shape[0], *array_dim.shape[1:]))\n",
-       "2817    array = _arr_moveaxis(array_dim, 0, dim)\n",
-       "2818\n",
-       "2819  array = dst_gamma2.encode(array, dtype)\n",
-       "2820  return array\n",
+       "2797    is_minification = get_is_minification()\n",
+       "2798    boundary_dim = boundary2[dim]\n",
+       "2799    if boundary_dim == 'auto':\n",
+       "2800      boundary_dim = 'clamp' if is_minification else 'reflect'\n",
+       "2801    boundary_dim = _get_boundary(boundary_dim)\n",
+       "2802    resize_matrix, cval_weight = _create_resize_matrix(\n",
+       "2803        array.shape[dim],\n",
+       "2804        shape2[dim],\n",
+       "2805        src_gridtype=src_gridtype2[dim],\n",
+       "2806        dst_gridtype=dst_gridtype2[dim],\n",
+       "2807        boundary=boundary_dim,\n",
+       "2808        filter=filter2[dim],\n",
+       "2809        prefilter=prefilter2[dim],\n",
+       "2810        scale=scale2[dim],\n",
+       "2811        translate=translate2[dim],\n",
+       "2812        dtype=weight_precision,\n",
+       "2813        arraylib=arraylib,\n",
+       "2814    )\n",
+       "2815\n",
+       "2816    array_dim: _Array = _arr_moveaxis(array, dim, 0)\n",
+       "2817    array_flat = _arr_reshape(array_dim, (array_dim.shape[0], -1))\n",
+       "2818    array_flat = _arr_possibly_make_contiguous(array_flat)\n",
+       "2819    if not is_minification and filter2[dim].requires_digital_filter:\n",
+       "2820      array_flat = _apply_digital_filter_1d(\n",
+       "2821          array_flat, src_gridtype2[dim], boundary_dim, cval, filter2[dim]\n",
+       "2822      )\n",
+       "2823\n",
+       "2824    array_flat = _arr_matmul_sparse_dense(resize_matrix, array_flat, num_threads=num_threads)\n",
+       "2825    if cval_weight is not None:\n",
+       "2826      cval_flat = np.broadcast_to(cval, array_dim.shape[1:]).reshape(-1)\n",
+       "2827      if np.issubdtype(array_dtype, np.complexfloating):\n",
+       "2828        cval_weight = _arr_astype(cval_weight, array_dtype)  # (Only necessary for 'tensorflow'.)\n",
+       "2829      array_flat += cval_weight[:, None] * cval_flat\n",
+       "2830\n",
+       "2831    if is_minification and filter2[dim].requires_digital_filter:  # use prefilter2[dim]?\n",
+       "2832      array_flat = _apply_digital_filter_1d(\n",
+       "2833          array_flat, dst_gridtype2[dim], boundary_dim, cval, filter2[dim]\n",
+       "2834      )\n",
+       "2835    array_dim = _arr_reshape(array_flat, (array_flat.shape[0], *array_dim.shape[1:]))\n",
+       "2836    array = _arr_moveaxis(array_dim, 0, dim)\n",
+       "2837\n",
+       "2838  array = dst_gamma2.encode(array, dtype)\n",
+       "2839  return array\n",
        "
\n", "\n", "\n", @@ -2143,11 +2152,11 @@ "execution_count": 40, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:08.055445Z", - "iopub.status.busy": "2023-12-05T23:04:08.054950Z", - "iopub.status.idle": "2023-12-05T23:04:08.749112Z", - "shell.execute_reply": "2023-12-05T23:04:08.748534Z", - "shell.execute_reply.started": "2023-12-05T23:04:08.055431Z" + "iopub.execute_input": "2024-02-13T00:34:05.722405Z", + "iopub.status.busy": "2024-02-13T00:34:05.722100Z", + "iopub.status.idle": "2024-02-13T00:34:06.429030Z", + "shell.execute_reply": "2024-02-13T00:34:06.428423Z", + "shell.execute_reply.started": "2024-02-13T00:34:05.722389Z" }, "tags": [] }, @@ -2170,10 +2179,10 @@ "\n", "
\n", " \n", - "
2826def resize_in_arraylib(array: _NDArray, /, *args: Any, arraylib: str, **kwargs: Any) -> _NDArray:\n",
-       "2827  """Evaluate the `resize()` operation using the specified array library from `ARRAYLIBS`."""\n",
-       "2828  _check_eq(_arr_arraylib(array), 'numpy')\n",
-       "2829  return _arr_numpy(_original_resize(_make_array(array, arraylib), *args, **kwargs))\n",
+       "            
2845def resize_in_arraylib(array: _NDArray, /, *args: Any, arraylib: str, **kwargs: Any) -> _NDArray:\n",
+       "2846  """Evaluate the `resize()` operation using the specified array library from `ARRAYLIBS`."""\n",
+       "2847  _check_eq(_arr_arraylib(array), 'numpy')\n",
+       "2848  return _arr_numpy(_original_resize(_make_array(array, arraylib), *args, **kwargs))\n",
        "
\n", "\n", "\n", @@ -2206,11 +2215,11 @@ "execution_count": 41, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:08.750114Z", - "iopub.status.busy": "2023-12-05T23:04:08.749878Z", - "iopub.status.idle": "2023-12-05T23:04:09.209363Z", - "shell.execute_reply": "2023-12-05T23:04:09.208726Z", - "shell.execute_reply.started": "2023-12-05T23:04:08.750098Z" + "iopub.execute_input": "2024-02-13T00:34:06.429975Z", + "iopub.status.busy": "2024-02-13T00:34:06.429755Z", + "iopub.status.idle": "2024-02-13T00:34:07.120072Z", + "shell.execute_reply": "2024-02-13T00:34:07.119459Z", + "shell.execute_reply.started": "2024-02-13T00:34:06.429962Z" }, "tags": [] }, @@ -2233,9 +2242,9 @@ "\n", "
\n", " \n", - "
2874def jaxjit_resize(array: _Array, /, *args: Any, **kwargs: Any) -> _Array:\n",
-       "2875  """Compute `resize` but with resize function jitted using Jax."""\n",
-       "2876  return _create_jaxjit_resize()(array, *args, **kwargs)\n",
+       "            
2893def jaxjit_resize(array: _Array, /, *args: Any, **kwargs: Any) -> _Array:\n",
+       "2894  """Compute `resize` but with resize function jitted using Jax."""\n",
+       "2895  return _create_jaxjit_resize()(array, *args, **kwargs)\n",
        "
\n", "\n", "\n", @@ -2268,11 +2277,11 @@ "execution_count": 42, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:09.210475Z", - "iopub.status.busy": "2023-12-05T23:04:09.210077Z", - "iopub.status.idle": "2023-12-05T23:04:09.238759Z", - "shell.execute_reply": "2023-12-05T23:04:09.238140Z", - "shell.execute_reply.started": "2023-12-05T23:04:09.210462Z" + "iopub.execute_input": "2024-02-13T00:34:07.121230Z", + "iopub.status.busy": "2024-02-13T00:34:07.120754Z", + "iopub.status.idle": "2024-02-13T00:34:07.150443Z", + "shell.execute_reply": "2024-02-13T00:34:07.149808Z", + "shell.execute_reply.started": "2024-02-13T00:34:07.121216Z" }, "tags": [] }, @@ -2286,11 +2295,11 @@ "execution_count": 43, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:09.239895Z", - "iopub.status.busy": "2023-12-05T23:04:09.239498Z", - "iopub.status.idle": "2023-12-05T23:04:09.267119Z", - "shell.execute_reply": "2023-12-05T23:04:09.266462Z", - "shell.execute_reply.started": "2023-12-05T23:04:09.239881Z" + "iopub.execute_input": "2024-02-13T00:34:07.151508Z", + "iopub.status.busy": "2024-02-13T00:34:07.151209Z", + "iopub.status.idle": "2024-02-13T00:34:07.182067Z", + "shell.execute_reply": "2024-02-13T00:34:07.181177Z", + "shell.execute_reply.started": "2024-02-13T00:34:07.151494Z" }, "tags": [] }, @@ -2309,11 +2318,11 @@ "execution_count": 44, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:09.268385Z", - "iopub.status.busy": "2023-12-05T23:04:09.267892Z", - "iopub.status.idle": "2023-12-05T23:04:09.298051Z", - "shell.execute_reply": "2023-12-05T23:04:09.297437Z", - "shell.execute_reply.started": "2023-12-05T23:04:09.268369Z" + "iopub.execute_input": "2024-02-13T00:34:07.183395Z", + "iopub.status.busy": "2024-02-13T00:34:07.183018Z", + "iopub.status.idle": "2024-02-13T00:34:07.215646Z", + "shell.execute_reply": "2024-02-13T00:34:07.215045Z", + "shell.execute_reply.started": "2024-02-13T00:34:07.183380Z" }, "tags": [] }, @@ -2341,11 +2350,11 @@ "execution_count": 45, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:09.299227Z", - "iopub.status.busy": "2023-12-05T23:04:09.298756Z", - "iopub.status.idle": "2023-12-05T23:04:09.790140Z", - "shell.execute_reply": "2023-12-05T23:04:09.789470Z", - "shell.execute_reply.started": "2023-12-05T23:04:09.299211Z" + "iopub.execute_input": "2024-02-13T00:34:07.216784Z", + "iopub.status.busy": "2024-02-13T00:34:07.216374Z", + "iopub.status.idle": "2024-02-13T00:34:07.445610Z", + "shell.execute_reply": "2024-02-13T00:34:07.444811Z", + "shell.execute_reply.started": "2024-02-13T00:34:07.216766Z" }, "tags": [] }, @@ -2637,11 +2646,11 @@ "execution_count": 46, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:09.791269Z", - "iopub.status.busy": "2023-12-05T23:04:09.791023Z", - "iopub.status.idle": "2023-12-05T23:04:10.328053Z", - "shell.execute_reply": "2023-12-05T23:04:10.327462Z", - "shell.execute_reply.started": "2023-12-05T23:04:09.791253Z" + "iopub.execute_input": "2024-02-13T00:34:07.447178Z", + "iopub.status.busy": "2024-02-13T00:34:07.446562Z", + "iopub.status.idle": "2024-02-13T00:34:08.247749Z", + "shell.execute_reply": "2024-02-13T00:34:08.247112Z", + "shell.execute_reply.started": "2024-02-13T00:34:07.447156Z" }, "tags": [] }, @@ -2664,312 +2673,312 @@ "\n", "
\n", " \n", - "
2957def resample(\n",
-       "2958    array: _Array,\n",
-       "2959    /,\n",
-       "2960    coords: _ArrayLike,\n",
-       "2961    *,\n",
-       "2962    gridtype: str | Gridtype | Iterable[str | Gridtype] = 'dual',\n",
-       "2963    boundary: str | Boundary | Iterable[str | Boundary] = 'auto',\n",
-       "2964    cval: _ArrayLike = 0,\n",
-       "2965    filter: str | Filter | Iterable[str | Filter] = _DEFAULT_FILTER,\n",
-       "2966    prefilter: str | Filter | Iterable[str | Filter] | None = None,\n",
-       "2967    gamma: str | Gamma | None = None,\n",
-       "2968    src_gamma: str | Gamma | None = None,\n",
-       "2969    dst_gamma: str | Gamma | None = None,\n",
-       "2970    jacobian: _ArrayLike | None = None,\n",
-       "2971    precision: _DTypeLike = None,\n",
-       "2972    dtype: _DTypeLike = None,\n",
-       "2973    max_block_size: int = 40_000,\n",
-       "2974    debug: bool = False,\n",
-       "2975) -> _Array:\n",
-       "2976  """Interpolate `array` (a grid of samples) at specified unit-domain coordinates `coords`.\n",
-       "2977\n",
-       "2978  The last dimension of `coords` contains unit-domain coordinates at which to interpolate the\n",
-       "2979  domain grid samples in `array`.\n",
-       "2980\n",
-       "2981  The number of coordinates (`coords.shape[-1]`) determines how to interpret `array`: its first\n",
-       "2982  `coords.shape[-1]` dimensions define the grid, and the remaining dimensions describe each grid\n",
-       "2983  sample (e.g., scalar, vector, tensor).\n",
-       "2984\n",
-       "2985  Concretely, the grid has shape `array.shape[:coords.shape[-1]]` and each grid sample has shape\n",
-       "2986  `array.shape[coords.shape[-1]:]`.\n",
-       "2987\n",
-       "2988  Examples include:\n",
-       "2989\n",
-       "2990  - Resample a grayscale image with `array.shape = height, width` onto a new grayscale image with\n",
-       "2991    `new.shape = height2, width2` by using `coords.shape = height2, width2, 2`.\n",
-       "2992\n",
-       "2993  - Resample an RGB image with `array.shape = height, width, 3` onto a new RGB image with\n",
-       "2994    `new.shape = height2, width2, 3` by using `coords.shape = height2, width2, 2`.\n",
-       "2995\n",
-       "2996  - Sample an RGB image at `num` 2D points along a line segment by using `coords.shape = num, 2`.\n",
-       "2997\n",
-       "2998  - Sample an RGB image at a single 2D point by using `coords.shape = (2,)`.\n",
+       "            
2976def resample(\n",
+       "2977    array: _Array,\n",
+       "2978    /,\n",
+       "2979    coords: _ArrayLike,\n",
+       "2980    *,\n",
+       "2981    gridtype: str | Gridtype | Iterable[str | Gridtype] = 'dual',\n",
+       "2982    boundary: str | Boundary | Iterable[str | Boundary] = 'auto',\n",
+       "2983    cval: _ArrayLike = 0,\n",
+       "2984    filter: str | Filter | Iterable[str | Filter] = _DEFAULT_FILTER,\n",
+       "2985    prefilter: str | Filter | Iterable[str | Filter] | None = None,\n",
+       "2986    gamma: str | Gamma | None = None,\n",
+       "2987    src_gamma: str | Gamma | None = None,\n",
+       "2988    dst_gamma: str | Gamma | None = None,\n",
+       "2989    jacobian: _ArrayLike | None = None,\n",
+       "2990    precision: _DTypeLike = None,\n",
+       "2991    dtype: _DTypeLike = None,\n",
+       "2992    max_block_size: int = 40_000,\n",
+       "2993    debug: bool = False,\n",
+       "2994) -> _Array:\n",
+       "2995  """Interpolate `array` (a grid of samples) at specified unit-domain coordinates `coords`.\n",
+       "2996\n",
+       "2997  The last dimension of `coords` contains unit-domain coordinates at which to interpolate the\n",
+       "2998  domain grid samples in `array`.\n",
        "2999\n",
-       "3000  - Sample a 3D grid of 3x3 Jacobians with `array.shape = nz, ny, nx, 3, 3` along a 2D plane by\n",
-       "3001    using `coords.shape = height, width, 3`.\n",
-       "3002\n",
-       "3003  - Map a grayscale image through a color map by using `array.shape = 256, 3` and\n",
-       "3004    `coords.shape = height, width`.\n",
-       "3005\n",
-       "3006  Args:\n",
-       "3007    array: Regular grid of source sample values, as an array object recognized by `ARRAYLIBS`.\n",
-       "3008      The array must have numeric type.  The coordinate dimensions appear first, and\n",
-       "3009      each grid sample may have an arbitrary shape.  Each grid dimension must be at least 1 for\n",
-       "3010      a `'dual'` grid or at least 2 for a `'primal'` grid.\n",
-       "3011    coords: Grid of points at which to resample `array`.  The point coordinates are in the last\n",
-       "3012      dimension of `coords`.  The domain associated with the source grid is a unit hypercube,\n",
-       "3013      i.e. with a range [0, 1] on each coordinate dimension.  The output grid has shape\n",
-       "3014      `coords.shape[:-1]` and each of its grid samples has shape `array.shape[coords.shape[-1]:]`.\n",
-       "3015    gridtype: Placement of the samples in the source domain grid for each dimension, specified as\n",
-       "3016      either a name in `GRIDTYPES` or a `Gridtype` instance.  It defaults to `'dual'`.\n",
-       "3017    boundary: The reconstruction boundary rule for each dimension in `coords.shape[-1]`, specified\n",
-       "3018      as either a name in `BOUNDARIES` or a `Boundary` instance.  The special value `'auto'` uses\n",
-       "3019      `'reflect'` for upsampling and `'clamp'` for downsampling.\n",
-       "3020    cval: Constant value used beyond the samples by some boundary rules.  It must be broadcastable\n",
-       "3021      onto the shape `array.shape[coords.shape[-1]:]`.\n",
-       "3022    filter: The reconstruction kernel for each dimension in `coords.shape[-1]`, specified as either\n",
-       "3023      a filter name in `FILTERS` or a `Filter` instance.\n",
-       "3024    prefilter: The prefilter kernel for each dimension in `coords.shape[:-1]`, specified as either\n",
-       "3025      a filter name in `FILTERS` or a `Filter` instance.  It is used during downsampling\n",
-       "3026      (i.e., minification).  If `None`, it inherits the value of `filter`.\n",
-       "3027    gamma: Component transfer functions (e.g., gamma correction) applied when reading samples\n",
-       "3028      from `array` and when creating output grid samples.  It is specified as either a name in\n",
-       "3029      `GAMMAS` or a `Gamma` instance.  If both `array.dtype` and `dtype` are `uint`, the default\n",
-       "3030      is `'power2'`.  If both are non-`uint`, the default is `'identity'`.  Otherwise, `gamma` or\n",
-       "3031      `src_gamma`/`dst_gamma` must be set.   Gamma correction assumes that float values are in the\n",
-       "3032      range [0.0, 1.0].\n",
-       "3033    src_gamma: Component transfer function used to "decode" `array` samples.\n",
-       "3034      Parameters `gamma` and `src_gamma` cannot both be set.\n",
-       "3035    dst_gamma: Component transfer function used to "encode" the output samples.\n",
-       "3036      Parameters `gamma` and `dst_gamma` cannot both be set.\n",
-       "3037    jacobian: Optional array, which must be broadcastable onto the shape\n",
-       "3038      `coords.shape[:-1] + (coords.shape[-1], coords.shape[-1])`, storing for each point in the\n",
-       "3039      output grid the Jacobian matrix of the map from the unit output domain to the unit source\n",
-       "3040      domain.  If omitted, it is estimated by computing finite differences on `coords`.\n",
-       "3041    precision: Inexact precision of intermediate computations.  If `None`, it is determined based\n",
-       "3042      on `array.dtype`, `coords.dtype`, and `dtype`.\n",
-       "3043    dtype: Desired data type of the output array.  If `None`, it is taken to be `array.dtype`.\n",
-       "3044      If it is a uint type, the intermediate float values are rescaled from the [0.0, 1.0] range\n",
-       "3045      to the uint range.\n",
-       "3046    max_block_size: If nonzero, maximum number of grid points in `coords` before the resampling\n",
-       "3047      evaluation gets partitioned into smaller blocks for reduced memory usage and better caching.\n",
-       "3048    debug: Show internal information.\n",
-       "3049\n",
-       "3050  Returns:\n",
-       "3051    A new sample grid of shape `coords.shape[:-1]`, represented as an array of shape\n",
-       "3052    `coords.shape[:-1] + array.shape[coords.shape[-1]:]`, of the same array library type as\n",
-       "3053    the source array.\n",
-       "3054\n",
-       "3055  **Example of resample operation:**\n",
-       "3056\n",
-       "3057  <center>\n",
-       "3058  <img src="https://github.com/hhoppe/resampler/raw/main/media/example_warp_coords.png"/>\n",
-       "3059  </center>\n",
-       "3060\n",
-       "3061  For reference, the identity resampling for a scalar-valued grid with the default grid-type\n",
-       "3062  `'dual'` is:\n",
-       "3063\n",
-       "3064  >>> array = np.random.default_rng(0).random((5, 7, 3))\n",
-       "3065  >>> coords = (np.moveaxis(np.indices(array.shape), 0, -1) + 0.5) / array.shape\n",
-       "3066  >>> new_array = resample(array, coords)\n",
-       "3067  >>> assert np.allclose(new_array, array)\n",
+       "3000  The number of coordinates (`coords.shape[-1]`) determines how to interpret `array`: its first\n",
+       "3001  `coords.shape[-1]` dimensions define the grid, and the remaining dimensions describe each grid\n",
+       "3002  sample (e.g., scalar, vector, tensor).\n",
+       "3003\n",
+       "3004  Concretely, the grid has shape `array.shape[:coords.shape[-1]]` and each grid sample has shape\n",
+       "3005  `array.shape[coords.shape[-1]:]`.\n",
+       "3006\n",
+       "3007  Examples include:\n",
+       "3008\n",
+       "3009  - Resample a grayscale image with `array.shape = height, width` onto a new grayscale image with\n",
+       "3010    `new.shape = height2, width2` by using `coords.shape = height2, width2, 2`.\n",
+       "3011\n",
+       "3012  - Resample an RGB image with `array.shape = height, width, 3` onto a new RGB image with\n",
+       "3013    `new.shape = height2, width2, 3` by using `coords.shape = height2, width2, 2`.\n",
+       "3014\n",
+       "3015  - Sample an RGB image at `num` 2D points along a line segment by using `coords.shape = num, 2`.\n",
+       "3016\n",
+       "3017  - Sample an RGB image at a single 2D point by using `coords.shape = (2,)`.\n",
+       "3018\n",
+       "3019  - Sample a 3D grid of 3x3 Jacobians with `array.shape = nz, ny, nx, 3, 3` along a 2D plane by\n",
+       "3020    using `coords.shape = height, width, 3`.\n",
+       "3021\n",
+       "3022  - Map a grayscale image through a color map by using `array.shape = 256, 3` and\n",
+       "3023    `coords.shape = height, width`.\n",
+       "3024\n",
+       "3025  Args:\n",
+       "3026    array: Regular grid of source sample values, as an array object recognized by `ARRAYLIBS`.\n",
+       "3027      The array must have numeric type.  The coordinate dimensions appear first, and\n",
+       "3028      each grid sample may have an arbitrary shape.  Each grid dimension must be at least 1 for\n",
+       "3029      a `'dual'` grid or at least 2 for a `'primal'` grid.\n",
+       "3030    coords: Grid of points at which to resample `array`.  The point coordinates are in the last\n",
+       "3031      dimension of `coords`.  The domain associated with the source grid is a unit hypercube,\n",
+       "3032      i.e. with a range [0, 1] on each coordinate dimension.  The output grid has shape\n",
+       "3033      `coords.shape[:-1]` and each of its grid samples has shape `array.shape[coords.shape[-1]:]`.\n",
+       "3034    gridtype: Placement of the samples in the source domain grid for each dimension, specified as\n",
+       "3035      either a name in `GRIDTYPES` or a `Gridtype` instance.  It defaults to `'dual'`.\n",
+       "3036    boundary: The reconstruction boundary rule for each dimension in `coords.shape[-1]`, specified\n",
+       "3037      as either a name in `BOUNDARIES` or a `Boundary` instance.  The special value `'auto'` uses\n",
+       "3038      `'reflect'` for upsampling and `'clamp'` for downsampling.\n",
+       "3039    cval: Constant value used beyond the samples by some boundary rules.  It must be broadcastable\n",
+       "3040      onto the shape `array.shape[coords.shape[-1]:]`.\n",
+       "3041    filter: The reconstruction kernel for each dimension in `coords.shape[-1]`, specified as either\n",
+       "3042      a filter name in `FILTERS` or a `Filter` instance.\n",
+       "3043    prefilter: The prefilter kernel for each dimension in `coords.shape[:-1]`, specified as either\n",
+       "3044      a filter name in `FILTERS` or a `Filter` instance.  It is used during downsampling\n",
+       "3045      (i.e., minification).  If `None`, it inherits the value of `filter`.\n",
+       "3046    gamma: Component transfer functions (e.g., gamma correction) applied when reading samples\n",
+       "3047      from `array` and when creating output grid samples.  It is specified as either a name in\n",
+       "3048      `GAMMAS` or a `Gamma` instance.  If both `array.dtype` and `dtype` are `uint`, the default\n",
+       "3049      is `'power2'`.  If both are non-`uint`, the default is `'identity'`.  Otherwise, `gamma` or\n",
+       "3050      `src_gamma`/`dst_gamma` must be set.   Gamma correction assumes that float values are in the\n",
+       "3051      range [0.0, 1.0].\n",
+       "3052    src_gamma: Component transfer function used to "decode" `array` samples.\n",
+       "3053      Parameters `gamma` and `src_gamma` cannot both be set.\n",
+       "3054    dst_gamma: Component transfer function used to "encode" the output samples.\n",
+       "3055      Parameters `gamma` and `dst_gamma` cannot both be set.\n",
+       "3056    jacobian: Optional array, which must be broadcastable onto the shape\n",
+       "3057      `coords.shape[:-1] + (coords.shape[-1], coords.shape[-1])`, storing for each point in the\n",
+       "3058      output grid the Jacobian matrix of the map from the unit output domain to the unit source\n",
+       "3059      domain.  If omitted, it is estimated by computing finite differences on `coords`.\n",
+       "3060    precision: Inexact precision of intermediate computations.  If `None`, it is determined based\n",
+       "3061      on `array.dtype`, `coords.dtype`, and `dtype`.\n",
+       "3062    dtype: Desired data type of the output array.  If `None`, it is taken to be `array.dtype`.\n",
+       "3063      If it is a uint type, the intermediate float values are rescaled from the [0.0, 1.0] range\n",
+       "3064      to the uint range.\n",
+       "3065    max_block_size: If nonzero, maximum number of grid points in `coords` before the resampling\n",
+       "3066      evaluation gets partitioned into smaller blocks for reduced memory usage and better caching.\n",
+       "3067    debug: Show internal information.\n",
        "3068\n",
-       "3069  It is more efficient to use the function `resize` for the special case where the `coords` are\n",
-       "3070  obtained as simple scaling and translation of a new regular grid over the source domain:\n",
-       "3071\n",
-       "3072  >>> scale, translate, new_shape = (1.1, 1.2), (0.1, -0.2), (6, 8)\n",
-       "3073  >>> coords = (np.moveaxis(np.indices(new_shape), 0, -1) + 0.5) / new_shape\n",
-       "3074  >>> coords = (coords - translate) / scale\n",
-       "3075  >>> resampled = resample(array, coords)\n",
-       "3076  >>> resized = resize(array, new_shape, scale=scale, translate=translate)\n",
-       "3077  >>> assert np.allclose(resampled, resized)\n",
-       "3078  """\n",
-       "3079  if isinstance(array, (tuple, list)):\n",
-       "3080    array = np.asarray(array)\n",
-       "3081  arraylib = _arr_arraylib(array)\n",
-       "3082  if len(array.shape) == 0:\n",
-       "3083    array = array[None]\n",
-       "3084  coords = np.atleast_1d(coords)\n",
-       "3085  if not np.issubdtype(_arr_dtype(array), np.number):\n",
-       "3086    raise ValueError(f'Type {array.dtype} is not numeric.')\n",
-       "3087  if not np.issubdtype(coords.dtype, np.floating):\n",
-       "3088    raise ValueError(f'Type {coords.dtype} is not floating.')\n",
-       "3089  array_ndim = len(array.shape)\n",
-       "3090  if coords.ndim == 1 and coords.shape[0] > 1 and array_ndim == 1:\n",
-       "3091    coords = coords[:, None]\n",
-       "3092  grid_ndim = coords.shape[-1]\n",
-       "3093  grid_shape = array.shape[:grid_ndim]\n",
-       "3094  sample_shape = array.shape[grid_ndim:]\n",
-       "3095  resampled_ndim = coords.ndim - 1\n",
-       "3096  resampled_shape = coords.shape[:-1]\n",
-       "3097  if grid_ndim > array_ndim:\n",
-       "3098    raise ValueError(\n",
-       "3099        f'There are more coordinate dimensions ({grid_ndim}) in {coords=} than in {array.shape=}.'\n",
-       "3100    )\n",
-       "3101  gridtype2 = [_get_gridtype(g) for g in np.broadcast_to(np.array(gridtype), grid_ndim)]\n",
-       "3102  boundary2 = np.broadcast_to(np.array(boundary), grid_ndim).tolist()\n",
-       "3103  cval = np.broadcast_to(cval, sample_shape)\n",
-       "3104  prefilter = filter if prefilter is None else prefilter\n",
-       "3105  filter2 = [_get_filter(f) for f in np.broadcast_to(np.array(filter), grid_ndim)]\n",
-       "3106  prefilter2 = [_get_filter(f) for f in np.broadcast_to(np.array(prefilter), resampled_ndim)]\n",
-       "3107  dtype = _arr_dtype(array) if dtype is None else np.dtype(dtype)\n",
-       "3108  src_gamma2, dst_gamma2 = _get_src_dst_gamma(gamma, src_gamma, dst_gamma, _arr_dtype(array), dtype)\n",
-       "3109  del gridtype, boundary, filter, prefilter, src_gamma, dst_gamma\n",
-       "3110  if jacobian is not None:\n",
-       "3111    jacobian = np.broadcast_to(jacobian, resampled_shape + (coords.shape[-1],) * 2)\n",
-       "3112  precision = _get_precision(precision, [_arr_dtype(array), dtype], [coords.dtype])\n",
-       "3113  weight_precision = _real_precision(precision)\n",
-       "3114  coords = coords.astype(weight_precision, copy=False)\n",
-       "3115  is_minification = False  # Current limitation; no prefiltering!\n",
-       "3116  assert max_block_size >= 0 or max_block_size == _MAX_BLOCK_SIZE_RECURSING\n",
-       "3117  for dim in range(grid_ndim):\n",
-       "3118    if boundary2[dim] == 'auto':\n",
-       "3119      boundary2[dim] = 'clamp' if is_minification else 'reflect'\n",
-       "3120    boundary2[dim] = _get_boundary(boundary2[dim])\n",
-       "3121\n",
-       "3122  if max_block_size != _MAX_BLOCK_SIZE_RECURSING:\n",
-       "3123    array = src_gamma2.decode(array, precision)\n",
-       "3124    for dim in range(grid_ndim):\n",
-       "3125      assert not is_minification\n",
-       "3126      if filter2[dim].requires_digital_filter:\n",
-       "3127        array = _apply_digital_filter_1d(\n",
-       "3128            array, gridtype2[dim], boundary2[dim], cval, filter2[dim], axis=dim\n",
-       "3129        )\n",
-       "3130\n",
-       "3131  if math.prod(resampled_shape) > max_block_size > 0:\n",
-       "3132    block_shape = _block_shape_with_min_size(resampled_shape, max_block_size)\n",
-       "3133    if debug:\n",
-       "3134      print(f'(resample: splitting coords into blocks {block_shape}).')\n",
-       "3135    coord_blocks = _split_array_into_blocks(coords, block_shape)\n",
-       "3136\n",
-       "3137    def process_block(coord_block: _NDArray) -> _Array:\n",
-       "3138      return resample(\n",
-       "3139          array,\n",
-       "3140          coord_block,\n",
-       "3141          gridtype=gridtype2,\n",
-       "3142          boundary=boundary2,\n",
-       "3143          cval=cval,\n",
-       "3144          filter=filter2,\n",
-       "3145          prefilter=prefilter2,\n",
-       "3146          src_gamma='identity',\n",
-       "3147          dst_gamma=dst_gamma2,\n",
-       "3148          jacobian=jacobian,\n",
-       "3149          precision=precision,\n",
-       "3150          dtype=dtype,\n",
-       "3151          max_block_size=_MAX_BLOCK_SIZE_RECURSING,\n",
-       "3152      )\n",
-       "3153\n",
-       "3154    result_blocks = _map_function_over_blocks(coord_blocks, process_block)\n",
-       "3155    array = _merge_array_from_blocks(result_blocks)\n",
-       "3156    return array\n",
-       "3157\n",
-       "3158  # A concrete example of upsampling:\n",
-       "3159  #   array = np.ones((5, 7, 3))  # source RGB image has height=5 width=7\n",
-       "3160  #   coords = np.random.default_rng(0).random((8, 9, 2))  # output RGB image has height=8 width=9\n",
-       "3161  #   resample(array, coords, filter=('cubic', 'lanczos3'))\n",
-       "3162  #   grid_shape = 5, 7  grid_ndim = 2\n",
-       "3163  #   resampled_shape = 8, 9  resampled_ndim = 2\n",
-       "3164  #   sample_shape = (3,)\n",
-       "3165  #   src_float_index.shape = 8, 9\n",
-       "3166  #   src_first_index.shape = 8, 9\n",
-       "3167  #   sample_index.shape = (4,) for dim == 0, then (6,) for dim == 1\n",
-       "3168  #   weight = [shape(8, 9, 4), shape(8, 9, 6)]\n",
-       "3169  #   src_index = [shape(8, 9, 4), shape(8, 9, 6)]\n",
-       "3170\n",
-       "3171  # Both:[shape(8, 9, 4), shape(8, 9, 6)]\n",
-       "3172  weight: list[_NDArray] = [np.array([]) for _ in range(grid_ndim)]\n",
-       "3173  src_index: list[_NDArray] = [np.array([]) for _ in range(grid_ndim)]\n",
-       "3174  uses_cval = False\n",
-       "3175  all_num_samples = []  # will be [4, 6]\n",
+       "3069  Returns:\n",
+       "3070    A new sample grid of shape `coords.shape[:-1]`, represented as an array of shape\n",
+       "3071    `coords.shape[:-1] + array.shape[coords.shape[-1]:]`, of the same array library type as\n",
+       "3072    the source array.\n",
+       "3073\n",
+       "3074  **Example of resample operation:**\n",
+       "3075\n",
+       "3076  <center>\n",
+       "3077  <img src="https://github.com/hhoppe/resampler/raw/main/media/example_warp_coords.png"/>\n",
+       "3078  </center>\n",
+       "3079\n",
+       "3080  For reference, the identity resampling for a scalar-valued grid with the default grid-type\n",
+       "3081  `'dual'` is:\n",
+       "3082\n",
+       "3083  >>> array = np.random.default_rng(0).random((5, 7, 3))\n",
+       "3084  >>> coords = (np.moveaxis(np.indices(array.shape), 0, -1) + 0.5) / array.shape\n",
+       "3085  >>> new_array = resample(array, coords)\n",
+       "3086  >>> assert np.allclose(new_array, array)\n",
+       "3087\n",
+       "3088  It is more efficient to use the function `resize` for the special case where the `coords` are\n",
+       "3089  obtained as simple scaling and translation of a new regular grid over the source domain:\n",
+       "3090\n",
+       "3091  >>> scale, translate, new_shape = (1.1, 1.2), (0.1, -0.2), (6, 8)\n",
+       "3092  >>> coords = (np.moveaxis(np.indices(new_shape), 0, -1) + 0.5) / new_shape\n",
+       "3093  >>> coords = (coords - translate) / scale\n",
+       "3094  >>> resampled = resample(array, coords)\n",
+       "3095  >>> resized = resize(array, new_shape, scale=scale, translate=translate)\n",
+       "3096  >>> assert np.allclose(resampled, resized)\n",
+       "3097  """\n",
+       "3098  if isinstance(array, (tuple, list)):\n",
+       "3099    array = np.asarray(array)\n",
+       "3100  arraylib = _arr_arraylib(array)\n",
+       "3101  if len(array.shape) == 0:\n",
+       "3102    array = array[None]\n",
+       "3103  coords = np.atleast_1d(coords)\n",
+       "3104  if not np.issubdtype(_arr_dtype(array), np.number):\n",
+       "3105    raise ValueError(f'Type {array.dtype} is not numeric.')\n",
+       "3106  if not np.issubdtype(coords.dtype, np.floating):\n",
+       "3107    raise ValueError(f'Type {coords.dtype} is not floating.')\n",
+       "3108  array_ndim = len(array.shape)\n",
+       "3109  if coords.ndim == 1 and coords.shape[0] > 1 and array_ndim == 1:\n",
+       "3110    coords = coords[:, None]\n",
+       "3111  grid_ndim = coords.shape[-1]\n",
+       "3112  grid_shape = array.shape[:grid_ndim]\n",
+       "3113  sample_shape = array.shape[grid_ndim:]\n",
+       "3114  resampled_ndim = coords.ndim - 1\n",
+       "3115  resampled_shape = coords.shape[:-1]\n",
+       "3116  if grid_ndim > array_ndim:\n",
+       "3117    raise ValueError(\n",
+       "3118        f'There are more coordinate dimensions ({grid_ndim}) in {coords=} than in {array.shape=}.'\n",
+       "3119    )\n",
+       "3120  gridtype2 = [_get_gridtype(g) for g in np.broadcast_to(np.array(gridtype), grid_ndim)]\n",
+       "3121  boundary2 = np.broadcast_to(np.array(boundary), grid_ndim).tolist()\n",
+       "3122  cval = np.broadcast_to(cval, sample_shape)\n",
+       "3123  prefilter = filter if prefilter is None else prefilter\n",
+       "3124  filter2 = [_get_filter(f) for f in np.broadcast_to(np.array(filter), grid_ndim)]\n",
+       "3125  prefilter2 = [_get_filter(f) for f in np.broadcast_to(np.array(prefilter), resampled_ndim)]\n",
+       "3126  dtype = _arr_dtype(array) if dtype is None else np.dtype(dtype)\n",
+       "3127  src_gamma2, dst_gamma2 = _get_src_dst_gamma(gamma, src_gamma, dst_gamma, _arr_dtype(array), dtype)\n",
+       "3128  del gridtype, boundary, filter, prefilter, src_gamma, dst_gamma\n",
+       "3129  if jacobian is not None:\n",
+       "3130    jacobian = np.broadcast_to(jacobian, resampled_shape + (coords.shape[-1],) * 2)\n",
+       "3131  precision = _get_precision(precision, [_arr_dtype(array), dtype], [coords.dtype])\n",
+       "3132  weight_precision = _real_precision(precision)\n",
+       "3133  coords = coords.astype(weight_precision, copy=False)\n",
+       "3134  is_minification = False  # Current limitation; no prefiltering!\n",
+       "3135  assert max_block_size >= 0 or max_block_size == _MAX_BLOCK_SIZE_RECURSING\n",
+       "3136  for dim in range(grid_ndim):\n",
+       "3137    if boundary2[dim] == 'auto':\n",
+       "3138      boundary2[dim] = 'clamp' if is_minification else 'reflect'\n",
+       "3139    boundary2[dim] = _get_boundary(boundary2[dim])\n",
+       "3140\n",
+       "3141  if max_block_size != _MAX_BLOCK_SIZE_RECURSING:\n",
+       "3142    array = src_gamma2.decode(array, precision)\n",
+       "3143    for dim in range(grid_ndim):\n",
+       "3144      assert not is_minification\n",
+       "3145      if filter2[dim].requires_digital_filter:\n",
+       "3146        array = _apply_digital_filter_1d(\n",
+       "3147            array, gridtype2[dim], boundary2[dim], cval, filter2[dim], axis=dim\n",
+       "3148        )\n",
+       "3149\n",
+       "3150  if math.prod(resampled_shape) > max_block_size > 0:\n",
+       "3151    block_shape = _block_shape_with_min_size(resampled_shape, max_block_size)\n",
+       "3152    if debug:\n",
+       "3153      print(f'(resample: splitting coords into blocks {block_shape}).')\n",
+       "3154    coord_blocks = _split_array_into_blocks(coords, block_shape)\n",
+       "3155\n",
+       "3156    def process_block(coord_block: _NDArray) -> _Array:\n",
+       "3157      return resample(\n",
+       "3158          array,\n",
+       "3159          coord_block,\n",
+       "3160          gridtype=gridtype2,\n",
+       "3161          boundary=boundary2,\n",
+       "3162          cval=cval,\n",
+       "3163          filter=filter2,\n",
+       "3164          prefilter=prefilter2,\n",
+       "3165          src_gamma='identity',\n",
+       "3166          dst_gamma=dst_gamma2,\n",
+       "3167          jacobian=jacobian,\n",
+       "3168          precision=precision,\n",
+       "3169          dtype=dtype,\n",
+       "3170          max_block_size=_MAX_BLOCK_SIZE_RECURSING,\n",
+       "3171      )\n",
+       "3172\n",
+       "3173    result_blocks = _map_function_over_blocks(coord_blocks, process_block)\n",
+       "3174    array = _merge_array_from_blocks(result_blocks)\n",
+       "3175    return array\n",
        "3176\n",
-       "3177  for dim in range(grid_ndim):\n",
-       "3178    src_size = grid_shape[dim]  # scalar\n",
-       "3179    coords_dim = coords[..., dim]  # (8, 9)\n",
-       "3180    radius = filter2[dim].radius  # scalar\n",
-       "3181    num_samples = int(np.ceil(radius * 2))  # scalar\n",
-       "3182    all_num_samples.append(num_samples)\n",
-       "3183\n",
-       "3184    boundary_dim = boundary2[dim]\n",
-       "3185    coords_dim = boundary_dim.preprocess_coordinates(coords_dim)\n",
-       "3186\n",
-       "3187    # Sample positions mapped back to source unit domain [0, 1].\n",
-       "3188    src_float_index = gridtype2[dim].index_from_point(coords_dim, src_size)  # (8, 9)\n",
-       "3189    src_first_index = (\n",
-       "3190        np.floor(src_float_index + (0.5 if num_samples % 2 == 1 else 0.0)).astype(np.int32)\n",
-       "3191        - (num_samples - 1) // 2\n",
-       "3192    )  # (8, 9)\n",
-       "3193\n",
-       "3194    sample_index = np.arange(num_samples, dtype=np.int32)  # (4,) then (6,)\n",
-       "3195    src_index[dim] = src_first_index[..., None] + sample_index  # (8, 9, 4) then (8, 9, 6)\n",
-       "3196    if filter2[dim].name == 'trapezoid':\n",
-       "3197      # (It might require changing the filter radius at every sample.)\n",
-       "3198      raise ValueError('resample() cannot use adaptive `trapezoid` filter.')\n",
-       "3199    if filter2[dim].name == 'impulse':\n",
-       "3200      weight[dim] = np.ones_like(src_index[dim], weight_precision)\n",
-       "3201    else:\n",
-       "3202      x = src_float_index[..., None] - src_index[dim].astype(weight_precision)\n",
-       "3203      weight[dim] = filter2[dim](x).astype(weight_precision, copy=False)\n",
-       "3204      if filter2[dim].name != 'narrowbox' and (\n",
-       "3205          is_minification or not filter2[dim].partition_of_unity\n",
-       "3206      ):\n",
-       "3207        weight[dim] = weight[dim] / weight[dim].sum(axis=-1)[..., None]\n",
-       "3208\n",
-       "3209    src_index[dim], weight[dim] = boundary_dim.apply(\n",
-       "3210        src_index[dim], weight[dim], coords_dim, src_size, gridtype2[dim]\n",
-       "3211    )\n",
-       "3212    if boundary_dim.uses_cval or filter2[dim].name == 'narrowbox':\n",
-       "3213      uses_cval = True\n",
-       "3214\n",
-       "3215  # Gather the samples.\n",
-       "3216\n",
-       "3217  # Recall that src_index = [shape(8, 9, 4), shape(8, 9, 6)].\n",
-       "3218  src_index_expanded = []\n",
-       "3219  for dim in range(grid_ndim):\n",
-       "3220    src_index_dim = np.moveaxis(\n",
-       "3221        src_index[dim].reshape(src_index[dim].shape + (1,) * (grid_ndim - 1)),\n",
-       "3222        resampled_ndim,\n",
-       "3223        resampled_ndim + dim,\n",
-       "3224    )\n",
-       "3225    src_index_expanded.append(src_index_dim)\n",
-       "3226  indices = tuple(src_index_expanded)  # (shape(8, 9, 4, 1), shape(8, 9, 1, 6))\n",
-       "3227  samples = _arr_getitem(array, indices)  # (8, 9, 4, 6, 3)\n",
-       "3228\n",
-       "3229  # Indirectly derive samples.ndim (which is unavailable during Tensorflow grad computation).\n",
-       "3230  samples_ndim = resampled_ndim + grid_ndim + len(sample_shape)\n",
-       "3231\n",
-       "3232  # Compute an Einstein summation over the samples and each of the per-dimension weights.\n",
+       "3177  # A concrete example of upsampling:\n",
+       "3178  #   array = np.ones((5, 7, 3))  # source RGB image has height=5 width=7\n",
+       "3179  #   coords = np.random.default_rng(0).random((8, 9, 2))  # output RGB image has height=8 width=9\n",
+       "3180  #   resample(array, coords, filter=('cubic', 'lanczos3'))\n",
+       "3181  #   grid_shape = 5, 7  grid_ndim = 2\n",
+       "3182  #   resampled_shape = 8, 9  resampled_ndim = 2\n",
+       "3183  #   sample_shape = (3,)\n",
+       "3184  #   src_float_index.shape = 8, 9\n",
+       "3185  #   src_first_index.shape = 8, 9\n",
+       "3186  #   sample_index.shape = (4,) for dim == 0, then (6,) for dim == 1\n",
+       "3187  #   weight = [shape(8, 9, 4), shape(8, 9, 6)]\n",
+       "3188  #   src_index = [shape(8, 9, 4), shape(8, 9, 6)]\n",
+       "3189\n",
+       "3190  # Both:[shape(8, 9, 4), shape(8, 9, 6)]\n",
+       "3191  weight: list[_NDArray] = [np.array([]) for _ in range(grid_ndim)]\n",
+       "3192  src_index: list[_NDArray] = [np.array([]) for _ in range(grid_ndim)]\n",
+       "3193  uses_cval = False\n",
+       "3194  all_num_samples = []  # will be [4, 6]\n",
+       "3195\n",
+       "3196  for dim in range(grid_ndim):\n",
+       "3197    src_size = grid_shape[dim]  # scalar\n",
+       "3198    coords_dim = coords[..., dim]  # (8, 9)\n",
+       "3199    radius = filter2[dim].radius  # scalar\n",
+       "3200    num_samples = int(np.ceil(radius * 2))  # scalar\n",
+       "3201    all_num_samples.append(num_samples)\n",
+       "3202\n",
+       "3203    boundary_dim = boundary2[dim]\n",
+       "3204    coords_dim = boundary_dim.preprocess_coordinates(coords_dim)\n",
+       "3205\n",
+       "3206    # Sample positions mapped back to source unit domain [0, 1].\n",
+       "3207    src_float_index = gridtype2[dim].index_from_point(coords_dim, src_size)  # (8, 9)\n",
+       "3208    src_first_index = (\n",
+       "3209        np.floor(src_float_index + (0.5 if num_samples % 2 == 1 else 0.0)).astype(np.int32)\n",
+       "3210        - (num_samples - 1) // 2\n",
+       "3211    )  # (8, 9)\n",
+       "3212\n",
+       "3213    sample_index = np.arange(num_samples, dtype=np.int32)  # (4,) then (6,)\n",
+       "3214    src_index[dim] = src_first_index[..., None] + sample_index  # (8, 9, 4) then (8, 9, 6)\n",
+       "3215    if filter2[dim].name == 'trapezoid':\n",
+       "3216      # (It might require changing the filter radius at every sample.)\n",
+       "3217      raise ValueError('resample() cannot use adaptive `trapezoid` filter.')\n",
+       "3218    if filter2[dim].name == 'impulse':\n",
+       "3219      weight[dim] = np.ones_like(src_index[dim], weight_precision)\n",
+       "3220    else:\n",
+       "3221      x = src_float_index[..., None] - src_index[dim].astype(weight_precision)\n",
+       "3222      weight[dim] = filter2[dim](x).astype(weight_precision, copy=False)\n",
+       "3223      if filter2[dim].name != 'narrowbox' and (\n",
+       "3224          is_minification or not filter2[dim].partition_of_unity\n",
+       "3225      ):\n",
+       "3226        weight[dim] = weight[dim] / weight[dim].sum(axis=-1)[..., None]\n",
+       "3227\n",
+       "3228    src_index[dim], weight[dim] = boundary_dim.apply(\n",
+       "3229        src_index[dim], weight[dim], coords_dim, src_size, gridtype2[dim]\n",
+       "3230    )\n",
+       "3231    if boundary_dim.uses_cval or filter2[dim].name == 'narrowbox':\n",
+       "3232      uses_cval = True\n",
        "3233\n",
-       "3234  def label(dims: Iterable[int]) -> str:\n",
-       "3235    return ''.join(chr(ord('a') + i) for i in dims)\n",
-       "3236\n",
-       "3237  operands = [samples]  # (8, 9, 4, 6, 3)\n",
-       "3238  assert samples_ndim < 26  # Letters 'a' through 'z'.\n",
-       "3239  labels = [label(range(samples_ndim))]  # ['abcde']\n",
-       "3240  for dim in range(grid_ndim):\n",
-       "3241    operands.append(weight[dim])  # (8, 9, 4), then (8, 9, 6)\n",
-       "3242    labels.append(label(list(range(resampled_ndim)) + [resampled_ndim + dim]))  # 'abc' then 'abd'\n",
-       "3243  output_label = label(\n",
-       "3244      list(range(resampled_ndim)) + list(range(resampled_ndim + grid_ndim, samples_ndim))\n",
-       "3245  )  # 'abe'\n",
-       "3246  subscripts = ','.join(labels) + '->' + output_label  # 'abcde,abc,abd->abe'\n",
-       "3247  array = _arr_einsum(subscripts, *operands)  # (8, 9, 3)\n",
-       "3248\n",
-       "3249  # Gathering `samples` is the memory bottleneck.  It would be ideal if the gather() and einsum()\n",
-       "3250  # computations could be fused.  In Jax, https://github.com/google/jax/issues/3206 suggests\n",
-       "3251  # that this may become possible.  In any case, for large outputs it helps to partition the\n",
-       "3252  # evaluation over output tiles (using max_block_size).\n",
-       "3253\n",
-       "3254  if uses_cval:\n",
-       "3255    cval_weight = 1.0 - np.multiply.reduce(\n",
-       "3256        [weight[dim].sum(axis=-1) for dim in range(resampled_ndim)]\n",
-       "3257    )  # (8, 9)\n",
-       "3258    cval_weight_reshaped = cval_weight.reshape(cval_weight.shape + (1,) * len(sample_shape))\n",
-       "3259    array += _make_array((cval_weight_reshaped * cval).astype(precision, copy=False), arraylib)\n",
-       "3260\n",
-       "3261  array = dst_gamma2.encode(array, dtype)\n",
-       "3262  return array\n",
+       "3234  # Gather the samples.\n",
+       "3235\n",
+       "3236  # Recall that src_index = [shape(8, 9, 4), shape(8, 9, 6)].\n",
+       "3237  src_index_expanded = []\n",
+       "3238  for dim in range(grid_ndim):\n",
+       "3239    src_index_dim = np.moveaxis(\n",
+       "3240        src_index[dim].reshape(src_index[dim].shape + (1,) * (grid_ndim - 1)),\n",
+       "3241        resampled_ndim,\n",
+       "3242        resampled_ndim + dim,\n",
+       "3243    )\n",
+       "3244    src_index_expanded.append(src_index_dim)\n",
+       "3245  indices = tuple(src_index_expanded)  # (shape(8, 9, 4, 1), shape(8, 9, 1, 6))\n",
+       "3246  samples = _arr_getitem(array, indices)  # (8, 9, 4, 6, 3)\n",
+       "3247\n",
+       "3248  # Indirectly derive samples.ndim (which is unavailable during Tensorflow grad computation).\n",
+       "3249  samples_ndim = resampled_ndim + grid_ndim + len(sample_shape)\n",
+       "3250\n",
+       "3251  # Compute an Einstein summation over the samples and each of the per-dimension weights.\n",
+       "3252\n",
+       "3253  def label(dims: Iterable[int]) -> str:\n",
+       "3254    return ''.join(chr(ord('a') + i) for i in dims)\n",
+       "3255\n",
+       "3256  operands = [samples]  # (8, 9, 4, 6, 3)\n",
+       "3257  assert samples_ndim < 26  # Letters 'a' through 'z'.\n",
+       "3258  labels = [label(range(samples_ndim))]  # ['abcde']\n",
+       "3259  for dim in range(grid_ndim):\n",
+       "3260    operands.append(weight[dim])  # (8, 9, 4), then (8, 9, 6)\n",
+       "3261    labels.append(label(list(range(resampled_ndim)) + [resampled_ndim + dim]))  # 'abc' then 'abd'\n",
+       "3262  output_label = label(\n",
+       "3263      list(range(resampled_ndim)) + list(range(resampled_ndim + grid_ndim, samples_ndim))\n",
+       "3264  )  # 'abe'\n",
+       "3265  subscripts = ','.join(labels) + '->' + output_label  # 'abcde,abc,abd->abe'\n",
+       "3266  array = _arr_einsum(subscripts, *operands)  # (8, 9, 3)\n",
+       "3267\n",
+       "3268  # Gathering `samples` is the memory bottleneck.  It would be ideal if the gather() and einsum()\n",
+       "3269  # computations could be fused.  In Jax, https://github.com/google/jax/issues/3206 suggests\n",
+       "3270  # that this may become possible.  In any case, for large outputs it helps to partition the\n",
+       "3271  # evaluation over output tiles (using max_block_size).\n",
+       "3272\n",
+       "3273  if uses_cval:\n",
+       "3274    cval_weight = 1.0 - np.multiply.reduce(\n",
+       "3275        [weight[dim].sum(axis=-1) for dim in range(resampled_ndim)]\n",
+       "3276    )  # (8, 9)\n",
+       "3277    cval_weight_reshaped = cval_weight.reshape(cval_weight.shape + (1,) * len(sample_shape))\n",
+       "3278    array += _make_array((cval_weight_reshaped * cval).astype(precision, copy=False), arraylib)\n",
+       "3279\n",
+       "3280  array = dst_gamma2.encode(array, dtype)\n",
+       "3281  return array\n",
        "
\n", "\n", "\n", @@ -3113,11 +3122,11 @@ "execution_count": 47, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:10.329153Z", - "iopub.status.busy": "2023-12-05T23:04:10.328725Z", - "iopub.status.idle": "2023-12-05T23:04:11.079043Z", - "shell.execute_reply": "2023-12-05T23:04:11.078322Z", - "shell.execute_reply.started": "2023-12-05T23:04:10.329136Z" + "iopub.execute_input": "2024-02-13T00:34:08.248739Z", + "iopub.status.busy": "2024-02-13T00:34:08.248505Z", + "iopub.status.idle": "2024-02-13T00:34:09.030756Z", + "shell.execute_reply": "2024-02-13T00:34:09.030151Z", + "shell.execute_reply.started": "2024-02-13T00:34:08.248722Z" }, "tags": [] }, @@ -3140,118 +3149,118 @@ "\n", "
\n", " \n", - "
3265def resample_affine(\n",
-       "3266    array: _Array,\n",
-       "3267    /,\n",
-       "3268    shape: Iterable[int],\n",
-       "3269    matrix: _ArrayLike,\n",
-       "3270    *,\n",
-       "3271    gridtype: str | Gridtype | None = None,\n",
-       "3272    src_gridtype: str | Gridtype | Iterable[str | Gridtype] | None = None,\n",
-       "3273    dst_gridtype: str | Gridtype | Iterable[str | Gridtype] | None = None,\n",
-       "3274    filter: str | Filter | Iterable[str | Filter] = _DEFAULT_FILTER,\n",
-       "3275    prefilter: str | Filter | Iterable[str | Filter] | None = None,\n",
-       "3276    precision: _DTypeLike = None,\n",
-       "3277    dtype: _DTypeLike = None,\n",
-       "3278    **kwargs: Any,\n",
-       "3279) -> _Array:\n",
-       "3280  """Resample a source array using an affinely transformed grid of given shape.\n",
-       "3281\n",
-       "3282  The `matrix` transformation can be linear,\n",
-       "3283    `source_point = matrix @ destination_point`,\n",
-       "3284  or it can be affine where the last matrix column is an offset vector,\n",
-       "3285    `source_point = matrix @ (destination_point, 1.0)`.\n",
-       "3286\n",
-       "3287  Args:\n",
-       "3288    array: Regular grid of source sample values, as an array object recognized by `ARRAYLIBS`.\n",
-       "3289      The array must have numeric type.  The number of grid dimensions is determined from\n",
-       "3290      `matrix.shape[0]`; the remaining dimensions are for each sample value and are all\n",
-       "3291      linearly interpolated.\n",
-       "3292    shape: Dimensions of the desired destination grid.  The number of destination grid dimensions\n",
-       "3293      may be different from that of the source grid.\n",
-       "3294    matrix: 2D array for a linear or affine transform from unit-domain destination points\n",
-       "3295      (in a space with `len(shape)` dimensions) into unit-domain source points (in a space with\n",
-       "3296      `matrix.shape[0]` dimensions).  If the matrix has `len(shape) + 1` columns, the last column\n",
-       "3297      is the affine offset (i.e., translation).\n",
-       "3298    gridtype: Placement of samples on all dimensions of both the source and output domain grids,\n",
-       "3299      specified as either a name in `GRIDTYPES` or a `Gridtype` instance.  It defaults to `'dual'`\n",
-       "3300      if `gridtype`, `src_gridtype`, and `dst_gridtype` are all kept `None`.\n",
-       "3301    src_gridtype: Placement of samples in the source domain grid for each dimension.\n",
-       "3302      Parameters `gridtype` and `src_gridtype` cannot both be set.\n",
-       "3303    dst_gridtype: Placement of samples in the output domain grid for each dimension.\n",
-       "3304      Parameters `gridtype` and `dst_gridtype` cannot both be set.\n",
-       "3305    filter: The reconstruction kernel for each dimension in `matrix.shape[0]`, specified as either\n",
-       "3306      a filter name in `FILTERS` or a `Filter` instance.\n",
-       "3307    prefilter: The prefilter kernel for each dimension in `len(shape)`, specified as either\n",
-       "3308      a filter name in `FILTERS` or a `Filter` instance.  It is used during downsampling\n",
-       "3309      (i.e., minification).  If `None`, it inherits the value of `filter`.\n",
-       "3310    precision: Inexact precision of intermediate computations.  If `None`, it is determined based\n",
-       "3311      on `array.dtype` and `dtype`.\n",
-       "3312    dtype: Desired data type of the output array.  If `None`, it is taken to be `array.dtype`.\n",
-       "3313      If it is a uint type, the intermediate float values are rescaled from the [0.0, 1.0] range\n",
-       "3314      to the uint range.\n",
-       "3315    **kwargs: Additional parameters for `resample` function.\n",
-       "3316\n",
-       "3317  Returns:\n",
-       "3318    An array of the same class as the source `array`, representing a grid with specified `shape`,\n",
-       "3319    where each grid value is resampled from `array`.  Thus the shape of the returned array is\n",
-       "3320    `shape + array.shape[matrix.shape[0]:]`.\n",
-       "3321  """\n",
-       "3322  if isinstance(array, (tuple, list)):\n",
-       "3323    array = np.asarray(array)\n",
-       "3324  shape = tuple(shape)\n",
-       "3325  matrix = np.asarray(matrix)\n",
-       "3326  dst_ndim = len(shape)\n",
-       "3327  if matrix.ndim != 2:\n",
-       "3328    raise ValueError(f'Array {matrix} is not 2D matrix.')\n",
-       "3329  src_ndim = matrix.shape[0]\n",
-       "3330  # grid_shape = array.shape[:src_ndim]\n",
-       "3331  is_affine = matrix.shape[1] == dst_ndim + 1\n",
-       "3332  if src_ndim > len(array.shape):\n",
-       "3333    raise ValueError(\n",
-       "3334        f'Matrix {matrix} has more rows ({matrix.shape[0]}) than ndim in {array.shape=}.'\n",
-       "3335    )\n",
-       "3336  if matrix.shape[1] != dst_ndim and not is_affine:\n",
-       "3337    raise ValueError(\n",
-       "3338        f'Matrix has {matrix.shape=}, but we expect either {dst_ndim} or {dst_ndim + 1} columns.'\n",
-       "3339    )\n",
-       "3340  src_gridtype2, dst_gridtype2 = _get_gridtypes(\n",
-       "3341      gridtype, src_gridtype, dst_gridtype, src_ndim, dst_ndim\n",
-       "3342  )\n",
-       "3343  prefilter = filter if prefilter is None else prefilter\n",
-       "3344  filter2 = [_get_filter(f) for f in np.broadcast_to(np.array(filter), src_ndim)]\n",
-       "3345  prefilter2 = [_get_filter(f) for f in np.broadcast_to(np.array(prefilter), dst_ndim)]\n",
-       "3346  del src_gridtype, dst_gridtype, filter, prefilter\n",
-       "3347  dtype = _arr_dtype(array) if dtype is None else np.dtype(dtype)\n",
-       "3348  precision = _get_precision(precision, [_arr_dtype(array), dtype], [])\n",
-       "3349  weight_precision = _real_precision(precision)\n",
-       "3350\n",
-       "3351  dst_position_list = []  # per dimension\n",
-       "3352  for dim in range(dst_ndim):\n",
-       "3353    dst_size = shape[dim]\n",
-       "3354    dst_index = np.arange(dst_size, dtype=weight_precision)\n",
-       "3355    dst_position_list.append(dst_gridtype2[dim].point_from_index(dst_index, dst_size))\n",
-       "3356  dst_position = np.meshgrid(*dst_position_list, indexing='ij')\n",
-       "3357\n",
-       "3358  linear_matrix = matrix[:, :-1] if is_affine else matrix\n",
-       "3359  src_position = np.tensordot(linear_matrix, dst_position, 1)\n",
-       "3360  coords = np.moveaxis(src_position, 0, -1)\n",
-       "3361  if is_affine:\n",
-       "3362    coords += matrix[:, -1]\n",
-       "3363\n",
-       "3364  # TODO: Based on grid_shape, shape, linear_matrix, and prefilter, determine a\n",
-       "3365  # convolution prefilter and apply it to bandlimit 'array', using boundary for padding.\n",
-       "3366\n",
-       "3367  return resample(\n",
-       "3368      array,\n",
-       "3369      coords,\n",
-       "3370      gridtype=src_gridtype2,\n",
-       "3371      filter=filter2,\n",
-       "3372      prefilter=prefilter2,\n",
-       "3373      precision=precision,\n",
-       "3374      dtype=dtype,\n",
-       "3375      **kwargs,\n",
-       "3376  )\n",
+       "            
3284def resample_affine(\n",
+       "3285    array: _Array,\n",
+       "3286    /,\n",
+       "3287    shape: Iterable[int],\n",
+       "3288    matrix: _ArrayLike,\n",
+       "3289    *,\n",
+       "3290    gridtype: str | Gridtype | None = None,\n",
+       "3291    src_gridtype: str | Gridtype | Iterable[str | Gridtype] | None = None,\n",
+       "3292    dst_gridtype: str | Gridtype | Iterable[str | Gridtype] | None = None,\n",
+       "3293    filter: str | Filter | Iterable[str | Filter] = _DEFAULT_FILTER,\n",
+       "3294    prefilter: str | Filter | Iterable[str | Filter] | None = None,\n",
+       "3295    precision: _DTypeLike = None,\n",
+       "3296    dtype: _DTypeLike = None,\n",
+       "3297    **kwargs: Any,\n",
+       "3298) -> _Array:\n",
+       "3299  """Resample a source array using an affinely transformed grid of given shape.\n",
+       "3300\n",
+       "3301  The `matrix` transformation can be linear,\n",
+       "3302    `source_point = matrix @ destination_point`,\n",
+       "3303  or it can be affine where the last matrix column is an offset vector,\n",
+       "3304    `source_point = matrix @ (destination_point, 1.0)`.\n",
+       "3305\n",
+       "3306  Args:\n",
+       "3307    array: Regular grid of source sample values, as an array object recognized by `ARRAYLIBS`.\n",
+       "3308      The array must have numeric type.  The number of grid dimensions is determined from\n",
+       "3309      `matrix.shape[0]`; the remaining dimensions are for each sample value and are all\n",
+       "3310      linearly interpolated.\n",
+       "3311    shape: Dimensions of the desired destination grid.  The number of destination grid dimensions\n",
+       "3312      may be different from that of the source grid.\n",
+       "3313    matrix: 2D array for a linear or affine transform from unit-domain destination points\n",
+       "3314      (in a space with `len(shape)` dimensions) into unit-domain source points (in a space with\n",
+       "3315      `matrix.shape[0]` dimensions).  If the matrix has `len(shape) + 1` columns, the last column\n",
+       "3316      is the affine offset (i.e., translation).\n",
+       "3317    gridtype: Placement of samples on all dimensions of both the source and output domain grids,\n",
+       "3318      specified as either a name in `GRIDTYPES` or a `Gridtype` instance.  It defaults to `'dual'`\n",
+       "3319      if `gridtype`, `src_gridtype`, and `dst_gridtype` are all kept `None`.\n",
+       "3320    src_gridtype: Placement of samples in the source domain grid for each dimension.\n",
+       "3321      Parameters `gridtype` and `src_gridtype` cannot both be set.\n",
+       "3322    dst_gridtype: Placement of samples in the output domain grid for each dimension.\n",
+       "3323      Parameters `gridtype` and `dst_gridtype` cannot both be set.\n",
+       "3324    filter: The reconstruction kernel for each dimension in `matrix.shape[0]`, specified as either\n",
+       "3325      a filter name in `FILTERS` or a `Filter` instance.\n",
+       "3326    prefilter: The prefilter kernel for each dimension in `len(shape)`, specified as either\n",
+       "3327      a filter name in `FILTERS` or a `Filter` instance.  It is used during downsampling\n",
+       "3328      (i.e., minification).  If `None`, it inherits the value of `filter`.\n",
+       "3329    precision: Inexact precision of intermediate computations.  If `None`, it is determined based\n",
+       "3330      on `array.dtype` and `dtype`.\n",
+       "3331    dtype: Desired data type of the output array.  If `None`, it is taken to be `array.dtype`.\n",
+       "3332      If it is a uint type, the intermediate float values are rescaled from the [0.0, 1.0] range\n",
+       "3333      to the uint range.\n",
+       "3334    **kwargs: Additional parameters for `resample` function.\n",
+       "3335\n",
+       "3336  Returns:\n",
+       "3337    An array of the same class as the source `array`, representing a grid with specified `shape`,\n",
+       "3338    where each grid value is resampled from `array`.  Thus the shape of the returned array is\n",
+       "3339    `shape + array.shape[matrix.shape[0]:]`.\n",
+       "3340  """\n",
+       "3341  if isinstance(array, (tuple, list)):\n",
+       "3342    array = np.asarray(array)\n",
+       "3343  shape = tuple(shape)\n",
+       "3344  matrix = np.asarray(matrix)\n",
+       "3345  dst_ndim = len(shape)\n",
+       "3346  if matrix.ndim != 2:\n",
+       "3347    raise ValueError(f'Array {matrix} is not 2D matrix.')\n",
+       "3348  src_ndim = matrix.shape[0]\n",
+       "3349  # grid_shape = array.shape[:src_ndim]\n",
+       "3350  is_affine = matrix.shape[1] == dst_ndim + 1\n",
+       "3351  if src_ndim > len(array.shape):\n",
+       "3352    raise ValueError(\n",
+       "3353        f'Matrix {matrix} has more rows ({matrix.shape[0]}) than ndim in {array.shape=}.'\n",
+       "3354    )\n",
+       "3355  if matrix.shape[1] != dst_ndim and not is_affine:\n",
+       "3356    raise ValueError(\n",
+       "3357        f'Matrix has {matrix.shape=}, but we expect either {dst_ndim} or {dst_ndim + 1} columns.'\n",
+       "3358    )\n",
+       "3359  src_gridtype2, dst_gridtype2 = _get_gridtypes(\n",
+       "3360      gridtype, src_gridtype, dst_gridtype, src_ndim, dst_ndim\n",
+       "3361  )\n",
+       "3362  prefilter = filter if prefilter is None else prefilter\n",
+       "3363  filter2 = [_get_filter(f) for f in np.broadcast_to(np.array(filter), src_ndim)]\n",
+       "3364  prefilter2 = [_get_filter(f) for f in np.broadcast_to(np.array(prefilter), dst_ndim)]\n",
+       "3365  del src_gridtype, dst_gridtype, filter, prefilter\n",
+       "3366  dtype = _arr_dtype(array) if dtype is None else np.dtype(dtype)\n",
+       "3367  precision = _get_precision(precision, [_arr_dtype(array), dtype], [])\n",
+       "3368  weight_precision = _real_precision(precision)\n",
+       "3369\n",
+       "3370  dst_position_list = []  # per dimension\n",
+       "3371  for dim in range(dst_ndim):\n",
+       "3372    dst_size = shape[dim]\n",
+       "3373    dst_index = np.arange(dst_size, dtype=weight_precision)\n",
+       "3374    dst_position_list.append(dst_gridtype2[dim].point_from_index(dst_index, dst_size))\n",
+       "3375  dst_position = np.meshgrid(*dst_position_list, indexing='ij')\n",
+       "3376\n",
+       "3377  linear_matrix = matrix[:, :-1] if is_affine else matrix\n",
+       "3378  src_position = np.tensordot(linear_matrix, dst_position, 1)\n",
+       "3379  coords = np.moveaxis(src_position, 0, -1)\n",
+       "3380  if is_affine:\n",
+       "3381    coords += matrix[:, -1]\n",
+       "3382\n",
+       "3383  # TODO: Based on grid_shape, shape, linear_matrix, and prefilter, determine a\n",
+       "3384  # convolution prefilter and apply it to bandlimit 'array', using boundary for padding.\n",
+       "3385\n",
+       "3386  return resample(\n",
+       "3387      array,\n",
+       "3388      coords,\n",
+       "3389      gridtype=src_gridtype2,\n",
+       "3390      filter=filter2,\n",
+       "3391      prefilter=prefilter2,\n",
+       "3392      precision=precision,\n",
+       "3393      dtype=dtype,\n",
+       "3394      **kwargs,\n",
+       "3395  )\n",
        "
\n", "\n", "\n", @@ -3331,11 +3340,11 @@ "execution_count": 48, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:11.080081Z", - "iopub.status.busy": "2023-12-05T23:04:11.079785Z", - "iopub.status.idle": "2023-12-05T23:04:11.805906Z", - "shell.execute_reply": "2023-12-05T23:04:11.805336Z", - "shell.execute_reply.started": "2023-12-05T23:04:11.080065Z" + "iopub.execute_input": "2024-02-13T00:34:09.031860Z", + "iopub.status.busy": "2024-02-13T00:34:09.031528Z", + "iopub.status.idle": "2024-02-13T00:34:09.512149Z", + "shell.execute_reply": "2024-02-13T00:34:09.511464Z", + "shell.execute_reply.started": "2024-02-13T00:34:09.031846Z" }, "tags": [] }, @@ -3358,52 +3367,52 @@ "\n", "
\n", " \n", - "
3407def rotation_about_center_in_2d(\n",
-       "3408    src_shape: _ArrayLike,\n",
-       "3409    /,\n",
-       "3410    angle: float,\n",
-       "3411    *,\n",
-       "3412    new_shape: _ArrayLike | None = None,\n",
-       "3413    scale: float = 1.0,\n",
-       "3414) -> _NDArray:\n",
-       "3415  """Return the 3x3 matrix mapping destination into a source unit domain.\n",
-       "3416\n",
-       "3417  The returned matrix accounts for the possibly non-square domain shapes.\n",
-       "3418\n",
-       "3419  Args:\n",
-       "3420    src_shape: Resolution `(ny, nx)` of the source domain grid.\n",
-       "3421    angle: Angle in radians (positive from x to y axis) applied when mapping the source domain\n",
-       "3422      onto the destination domain.\n",
-       "3423    new_shape: Resolution `(ny, nx)` of the destination domain grid; it defaults to `src_shape`.\n",
-       "3424    scale: Scaling factor applied when mapping the source domain onto the destination domain.\n",
-       "3425  """\n",
-       "3426\n",
-       "3427  def translation_matrix(vector: _NDArray) -> _NDArray:\n",
-       "3428    matrix = np.eye(len(vector) + 1)\n",
-       "3429    matrix[:-1, -1] = vector\n",
-       "3430    return matrix\n",
-       "3431\n",
-       "3432  def scaling_matrix(scale: _NDArray) -> _NDArray:\n",
-       "3433    return np.diag(tuple(scale) + (1.0,))\n",
-       "3434\n",
-       "3435  def rotation_matrix_2d(angle: float) -> _NDArray:\n",
-       "3436    cos, sin = np.cos(angle), np.sin(angle)\n",
-       "3437    return np.array([[cos, sin, 0], [-sin, cos, 0], [0, 0, 1]])\n",
-       "3438\n",
-       "3439  src_shape = np.asarray(src_shape)\n",
-       "3440  new_shape = src_shape if new_shape is None else np.asarray(new_shape)\n",
-       "3441  _check_eq(src_shape.shape, (2,))\n",
-       "3442  _check_eq(new_shape.shape, (2,))\n",
-       "3443  half = np.array([0.5, 0.5])\n",
-       "3444  matrix = (\n",
-       "3445      translation_matrix(half)\n",
-       "3446      @ scaling_matrix(min(src_shape) / src_shape)\n",
-       "3447      @ rotation_matrix_2d(angle)\n",
-       "3448      @ scaling_matrix(scale * new_shape / min(new_shape))\n",
-       "3449      @ translation_matrix(-half)\n",
-       "3450  )\n",
-       "3451  assert np.allclose(matrix[-1], [0.0, 0.0, 1.0])\n",
-       "3452  return matrix\n",
+       "            
3426def rotation_about_center_in_2d(\n",
+       "3427    src_shape: _ArrayLike,\n",
+       "3428    /,\n",
+       "3429    angle: float,\n",
+       "3430    *,\n",
+       "3431    new_shape: _ArrayLike | None = None,\n",
+       "3432    scale: float = 1.0,\n",
+       "3433) -> _NDArray:\n",
+       "3434  """Return the 3x3 matrix mapping destination into a source unit domain.\n",
+       "3435\n",
+       "3436  The returned matrix accounts for the possibly non-square domain shapes.\n",
+       "3437\n",
+       "3438  Args:\n",
+       "3439    src_shape: Resolution `(ny, nx)` of the source domain grid.\n",
+       "3440    angle: Angle in radians (positive from x to y axis) applied when mapping the source domain\n",
+       "3441      onto the destination domain.\n",
+       "3442    new_shape: Resolution `(ny, nx)` of the destination domain grid; it defaults to `src_shape`.\n",
+       "3443    scale: Scaling factor applied when mapping the source domain onto the destination domain.\n",
+       "3444  """\n",
+       "3445\n",
+       "3446  def translation_matrix(vector: _NDArray) -> _NDArray:\n",
+       "3447    matrix = np.eye(len(vector) + 1)\n",
+       "3448    matrix[:-1, -1] = vector\n",
+       "3449    return matrix\n",
+       "3450\n",
+       "3451  def scaling_matrix(scale: _NDArray) -> _NDArray:\n",
+       "3452    return np.diag(tuple(scale) + (1.0,))\n",
+       "3453\n",
+       "3454  def rotation_matrix_2d(angle: float) -> _NDArray:\n",
+       "3455    cos, sin = np.cos(angle), np.sin(angle)\n",
+       "3456    return np.array([[cos, sin, 0], [-sin, cos, 0], [0, 0, 1]])\n",
+       "3457\n",
+       "3458  src_shape = np.asarray(src_shape)\n",
+       "3459  new_shape = src_shape if new_shape is None else np.asarray(new_shape)\n",
+       "3460  _check_eq(src_shape.shape, (2,))\n",
+       "3461  _check_eq(new_shape.shape, (2,))\n",
+       "3462  half = np.array([0.5, 0.5])\n",
+       "3463  matrix = (\n",
+       "3464      translation_matrix(half)\n",
+       "3465      @ scaling_matrix(min(src_shape) / src_shape)\n",
+       "3466      @ rotation_matrix_2d(angle)\n",
+       "3467      @ scaling_matrix(scale * new_shape / min(new_shape))\n",
+       "3468      @ translation_matrix(-half)\n",
+       "3469  )\n",
+       "3470  assert np.allclose(matrix[-1], [0.0, 0.0, 1.0])\n",
+       "3471  return matrix\n",
        "
\n", "\n", "\n", @@ -3448,11 +3457,11 @@ "execution_count": 49, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:11.806848Z", - "iopub.status.busy": "2023-12-05T23:04:11.806518Z", - "iopub.status.idle": "2023-12-05T23:04:12.282660Z", - "shell.execute_reply": "2023-12-05T23:04:12.281968Z", - "shell.execute_reply.started": "2023-12-05T23:04:11.806834Z" + "iopub.execute_input": "2024-02-13T00:34:09.513160Z", + "iopub.status.busy": "2024-02-13T00:34:09.512873Z", + "iopub.status.idle": "2024-02-13T00:34:10.219213Z", + "shell.execute_reply": "2024-02-13T00:34:10.218677Z", + "shell.execute_reply.started": "2024-02-13T00:34:09.513147Z" }, "lines_to_next_cell": 2, "tags": [] @@ -3476,33 +3485,33 @@ "\n", "
\n", " \n", - "
3455def rotate_image_about_center(\n",
-       "3456    image: _NDArray,\n",
-       "3457    /,\n",
-       "3458    angle: float,\n",
-       "3459    *,\n",
-       "3460    new_shape: _ArrayLike | None = None,\n",
-       "3461    scale: float = 1.0,\n",
-       "3462    num_rotations: int = 1,\n",
-       "3463    **kwargs: Any,\n",
-       "3464) -> _NDArray:\n",
-       "3465  """Return a copy of `image` rotated about its center.\n",
-       "3466\n",
-       "3467  Args:\n",
-       "3468    image: Source grid samples; the first two dimensions are spatial (ny, nx).\n",
-       "3469    angle: Angle in radians (positive from x to y axis) applied when mapping the source domain\n",
-       "3470      onto the destination domain.\n",
-       "3471    new_shape: Resolution `(ny, nx)` of the output grid; it defaults to `image.shape[:2]`.\n",
-       "3472    scale: Scaling factor applied when mapping the source domain onto the destination domain.\n",
-       "3473    num_rotations: Number of rotations (each by `angle`).  Successive resamplings are useful in\n",
-       "3474      analyzing the filtering quality.\n",
-       "3475    **kwargs: Additional parameters for `resample_affine`.\n",
-       "3476  """\n",
-       "3477  new_shape = image.shape[:2] if new_shape is None else np.asarray(new_shape)\n",
-       "3478  matrix = rotation_about_center_in_2d(image.shape[:2], angle, new_shape=new_shape, scale=scale)\n",
-       "3479  for _ in range(num_rotations):\n",
-       "3480    image = resample_affine(image, new_shape, matrix[:-1], **kwargs)\n",
-       "3481  return image\n",
+       "            
3474def rotate_image_about_center(\n",
+       "3475    image: _NDArray,\n",
+       "3476    /,\n",
+       "3477    angle: float,\n",
+       "3478    *,\n",
+       "3479    new_shape: _ArrayLike | None = None,\n",
+       "3480    scale: float = 1.0,\n",
+       "3481    num_rotations: int = 1,\n",
+       "3482    **kwargs: Any,\n",
+       "3483) -> _NDArray:\n",
+       "3484  """Return a copy of `image` rotated about its center.\n",
+       "3485\n",
+       "3486  Args:\n",
+       "3487    image: Source grid samples; the first two dimensions are spatial (ny, nx).\n",
+       "3488    angle: Angle in radians (positive from x to y axis) applied when mapping the source domain\n",
+       "3489      onto the destination domain.\n",
+       "3490    new_shape: Resolution `(ny, nx)` of the output grid; it defaults to `image.shape[:2]`.\n",
+       "3491    scale: Scaling factor applied when mapping the source domain onto the destination domain.\n",
+       "3492    num_rotations: Number of rotations (each by `angle`).  Successive resamplings are useful in\n",
+       "3493      analyzing the filtering quality.\n",
+       "3494    **kwargs: Additional parameters for `resample_affine`.\n",
+       "3495  """\n",
+       "3496  new_shape = image.shape[:2] if new_shape is None else np.asarray(new_shape)\n",
+       "3497  matrix = rotation_about_center_in_2d(image.shape[:2], angle, new_shape=new_shape, scale=scale)\n",
+       "3498  for _ in range(num_rotations):\n",
+       "3499    image = resample_affine(image, new_shape, matrix[:-1], **kwargs)\n",
+       "3500  return image\n",
        "
\n", "\n", "\n", @@ -3548,11 +3557,11 @@ "execution_count": 50, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:12.283966Z", - "iopub.status.busy": "2023-12-05T23:04:12.283402Z", - "iopub.status.idle": "2023-12-05T23:04:12.314486Z", - "shell.execute_reply": "2023-12-05T23:04:12.313855Z", - "shell.execute_reply.started": "2023-12-05T23:04:12.283950Z" + "iopub.execute_input": "2024-02-13T00:34:10.220157Z", + "iopub.status.busy": "2024-02-13T00:34:10.220007Z", + "iopub.status.idle": "2024-02-13T00:34:10.248687Z", + "shell.execute_reply": "2024-02-13T00:34:10.248008Z", + "shell.execute_reply.started": "2024-02-13T00:34:10.220146Z" } }, "outputs": [], @@ -3573,11 +3582,11 @@ "execution_count": 51, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:12.315553Z", - "iopub.status.busy": "2023-12-05T23:04:12.315168Z", - "iopub.status.idle": "2023-12-05T23:04:12.346614Z", - "shell.execute_reply": "2023-12-05T23:04:12.345909Z", - "shell.execute_reply.started": "2023-12-05T23:04:12.315539Z" + "iopub.execute_input": "2024-02-13T00:34:10.249852Z", + "iopub.status.busy": "2024-02-13T00:34:10.249519Z", + "iopub.status.idle": "2024-02-13T00:34:10.278768Z", + "shell.execute_reply": "2024-02-13T00:34:10.278041Z", + "shell.execute_reply.started": "2024-02-13T00:34:10.249837Z" } }, "outputs": [], @@ -3600,11 +3609,11 @@ "execution_count": 52, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:12.347743Z", - "iopub.status.busy": "2023-12-05T23:04:12.347434Z", - "iopub.status.idle": "2023-12-05T23:04:12.376902Z", - "shell.execute_reply": "2023-12-05T23:04:12.376282Z", - "shell.execute_reply.started": "2023-12-05T23:04:12.347727Z" + "iopub.execute_input": "2024-02-13T00:34:10.280176Z", + "iopub.status.busy": "2024-02-13T00:34:10.279830Z", + "iopub.status.idle": "2024-02-13T00:34:10.309871Z", + "shell.execute_reply": "2024-02-13T00:34:10.309248Z", + "shell.execute_reply.started": "2024-02-13T00:34:10.280162Z" }, "lines_to_next_cell": 2 }, @@ -3622,11 +3631,11 @@ "execution_count": 53, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:12.377966Z", - "iopub.status.busy": "2023-12-05T23:04:12.377596Z", - "iopub.status.idle": "2023-12-05T23:04:12.407502Z", - "shell.execute_reply": "2023-12-05T23:04:12.406862Z", - "shell.execute_reply.started": "2023-12-05T23:04:12.377951Z" + "iopub.execute_input": "2024-02-13T00:34:10.310970Z", + "iopub.status.busy": "2024-02-13T00:34:10.310778Z", + "iopub.status.idle": "2024-02-13T00:34:10.342039Z", + "shell.execute_reply": "2024-02-13T00:34:10.341421Z", + "shell.execute_reply.started": "2024-02-13T00:34:10.310955Z" }, "tags": [] }, @@ -3662,11 +3671,11 @@ "execution_count": 54, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:12.408623Z", - "iopub.status.busy": "2023-12-05T23:04:12.408285Z", - "iopub.status.idle": "2023-12-05T23:04:12.436745Z", - "shell.execute_reply": "2023-12-05T23:04:12.436140Z", - "shell.execute_reply.started": "2023-12-05T23:04:12.408609Z" + "iopub.execute_input": "2024-02-13T00:34:10.342955Z", + "iopub.status.busy": "2024-02-13T00:34:10.342688Z", + "iopub.status.idle": "2024-02-13T00:34:10.372983Z", + "shell.execute_reply": "2024-02-13T00:34:10.372314Z", + "shell.execute_reply.started": "2024-02-13T00:34:10.342938Z" }, "lines_to_next_cell": 2, "tags": [] @@ -3693,38 +3702,11 @@ "execution_count": 55, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:12.437803Z", - "iopub.status.busy": "2023-12-05T23:04:12.437502Z", - "iopub.status.idle": "2023-12-05T23:04:12.466912Z", - "shell.execute_reply": "2023-12-05T23:04:12.466319Z", - "shell.execute_reply.started": "2023-12-05T23:04:12.437786Z" - } - }, - "outputs": [], - "source": [ - "def test_precision() -> None:\n", - " _check_eq(resampler._real_precision(np.dtype(np.float32)), np.float32)\n", - " _check_eq(resampler._real_precision(np.dtype(np.float64)), np.float64)\n", - " _check_eq(resampler._real_precision(np.dtype(np.complex64)), np.float32)\n", - " _check_eq(resampler._real_precision(np.dtype(np.complex128)), np.float64)\n", - "\n", - " t = resampler._get_precision(None, [np.dtype(np.complex64)], [np.dtype(np.float64)])\n", - " _check_eq(t, np.complex128)\n", - "\n", - "\n", - "test_precision()" - ] - }, - { - "cell_type": "code", - "execution_count": 56, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:12.468009Z", - "iopub.status.busy": "2023-12-05T23:04:12.467654Z", - "iopub.status.idle": "2023-12-05T23:04:12.503536Z", - "shell.execute_reply": "2023-12-05T23:04:12.502897Z", - "shell.execute_reply.started": "2023-12-05T23:04:12.467992Z" + "iopub.execute_input": "2024-02-13T00:34:10.374196Z", + "iopub.status.busy": "2024-02-13T00:34:10.373789Z", + "iopub.status.idle": "2024-02-13T00:34:10.410601Z", + "shell.execute_reply": "2024-02-13T00:34:10.409990Z", + "shell.execute_reply.started": "2024-02-13T00:34:10.374179Z" }, "tags": [] }, @@ -3800,47 +3782,14 @@ }, { "cell_type": "code", - "execution_count": 57, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:12.504772Z", - "iopub.status.busy": "2023-12-05T23:04:12.504397Z", - "iopub.status.idle": "2023-12-05T23:04:12.744890Z", - "shell.execute_reply": "2023-12-05T23:04:12.743262Z", - "shell.execute_reply.started": "2023-12-05T23:04:12.504756Z" - }, - "tags": [] - }, - "outputs": [], - "source": [ - "def test_downsample_in_2d_using_box_filter() -> None:\n", - " for shape in [(6, 6), (4, 4)]:\n", - " for ch in [1, 2, 3, 4]:\n", - " array = np.ones((*shape, ch), np.float32)\n", - " new = resampler._downsample_in_2d_using_box_filter(array, (2, 2))\n", - " _check_eq(new.shape, (2, 2, ch))\n", - " assert np.allclose(new, 1.0)\n", - " for shape in [(6, 6), (4, 4)]:\n", - " array = np.ones(shape, np.float32)\n", - " new = resampler._downsample_in_2d_using_box_filter(array, (2, 2))\n", - " _check_eq(new.shape, (2, 2))\n", - " assert np.allclose(new, 1.0)\n", - "\n", - "\n", - "if EFFORT >= 1 and using_numba:\n", - " test_downsample_in_2d_using_box_filter()" - ] - }, - { - "cell_type": "code", - "execution_count": 58, + "execution_count": 56, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:12.747042Z", - "iopub.status.busy": "2023-12-05T23:04:12.746806Z", - "iopub.status.idle": "2023-12-05T23:04:13.236459Z", - "shell.execute_reply": "2023-12-05T23:04:13.235901Z", - "shell.execute_reply.started": "2023-12-05T23:04:12.747024Z" + "iopub.execute_input": "2024-02-13T00:34:10.411836Z", + "iopub.status.busy": "2024-02-13T00:34:10.411308Z", + "iopub.status.idle": "2024-02-13T00:34:10.888246Z", + "shell.execute_reply": "2024-02-13T00:34:10.887649Z", + "shell.execute_reply.started": "2024-02-13T00:34:10.411818Z" }, "lines_to_next_cell": 2, "tags": [] @@ -3850,7 +3799,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "3.42 ms\n" + "3.45 ms\n" ] } ], @@ -3867,388 +3816,14 @@ }, { "cell_type": "code", - "execution_count": 59, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:13.239440Z", - "iopub.status.busy": "2023-12-05T23:04:13.238613Z", - "iopub.status.idle": "2023-12-05T23:04:13.277286Z", - "shell.execute_reply": "2023-12-05T23:04:13.276466Z", - "shell.execute_reply.started": "2023-12-05T23:04:13.239419Z" - }, - "tags": [] - }, - "outputs": [], - "source": [ - "def test_block_shape_with_min_size(debug=False, **kwargs) -> None:\n", - " shape = 2, 3, 4\n", - " for min_size in range(1, math.prod(shape) + 1):\n", - " block_shape = resampler._block_shape_with_min_size(shape, min_size, **kwargs)\n", - " if debug:\n", - " print(min_size, block_shape)\n", - " assert np.all(np.array(block_shape) >= 1)\n", - " assert np.all(block_shape <= shape)\n", - " assert min_size <= math.prod(block_shape) <= math.prod(shape)\n", - "\n", - "\n", - "test_block_shape_with_min_size(compact=True)\n", - "test_block_shape_with_min_size(compact=False)" - ] - }, - { - "cell_type": "code", - "execution_count": 60, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:13.278668Z", - "iopub.status.busy": "2023-12-05T23:04:13.278174Z", - "iopub.status.idle": "2023-12-05T23:04:13.468696Z", - "shell.execute_reply": "2023-12-05T23:04:13.468006Z", - "shell.execute_reply.started": "2023-12-05T23:04:13.278646Z" - }, - "tags": [] - }, - "outputs": [], - "source": [ - "def test_split_2d() -> None:\n", - " numpy_array = np.random.default_rng(0).choice([1, 2, 3, 4], (5, 8))\n", - " for arraylib in resampler.ARRAYLIBS:\n", - " array = resampler._make_array(numpy_array, arraylib)\n", - " blocks = resampler._split_array_into_blocks(array, [2, 3])\n", - " blocks = resampler._map_function_over_blocks(blocks, lambda x: 2 * x)\n", - " new = resampler._merge_array_from_blocks(blocks)\n", - " _check_eq(resampler._arr_arraylib(new), arraylib)\n", - " _check_eq(np.sum(resampler._map_function_over_blocks(blocks, lambda _: 1)), 9)\n", - " _check_eq(resampler._arr_numpy(new), 2 * numpy_array)\n", - "\n", - "\n", - "if EFFORT >= 1:\n", - " test_split_2d()" - ] - }, - { - "cell_type": "code", - "execution_count": 61, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:13.469789Z", - "iopub.status.busy": "2023-12-05T23:04:13.469443Z", - "iopub.status.idle": "2023-12-05T23:04:14.042827Z", - "shell.execute_reply": "2023-12-05T23:04:14.042174Z", - "shell.execute_reply.started": "2023-12-05T23:04:13.469771Z" - }, - "tags": [] - }, - "outputs": [], - "source": [ - "def test_split_3d() -> None:\n", - " shape = 4, 3, 2\n", - " numpy_array = np.random.default_rng(0).choice([1, 2, 3, 4], shape)\n", - "\n", - " for arraylib in resampler.ARRAYLIBS:\n", - " array = resampler._make_array(numpy_array, arraylib)\n", - " for min_size in range(1, math.prod(shape) + 1):\n", - " block_shape = resampler._block_shape_with_min_size(shape, min_size)\n", - " blocks = resampler._split_array_into_blocks(array, block_shape)\n", - " blocks = resampler._map_function_over_blocks(blocks, lambda x: x**2)\n", - " new = resampler._merge_array_from_blocks(blocks)\n", - " _check_eq(resampler._arr_arraylib(new), arraylib)\n", - " _check_eq(resampler._arr_numpy(new), numpy_array**2)\n", - "\n", - " def check_block_shape(block) -> None:\n", - " assert np.all(np.array(block.shape) >= 1)\n", - " assert np.all(np.array(block.shape) <= shape)\n", - "\n", - " resampler._map_function_over_blocks(blocks, check_block_shape)\n", - "\n", - "\n", - "if EFFORT >= 1:\n", - " test_split_3d()" - ] - }, - { - "cell_type": "code", - "execution_count": 62, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:14.043949Z", - "iopub.status.busy": "2023-12-05T23:04:14.043544Z", - "iopub.status.idle": "2023-12-05T23:04:14.075746Z", - "shell.execute_reply": "2023-12-05T23:04:14.074989Z", - "shell.execute_reply.started": "2023-12-05T23:04:14.043936Z" - }, - "tags": [] - }, - "outputs": [], - "source": [ - "def test_split_prefix_dims() -> None:\n", - " shape = 2, 3, 2\n", - " array = np.arange(math.prod(shape)).reshape(shape)\n", - "\n", - " for min_size in range(1, math.prod(shape[:2]) + 1):\n", - " block_shape = resampler._block_shape_with_min_size(shape[:2], min_size)\n", - " blocks = resampler._split_array_into_blocks(array, block_shape)\n", - "\n", - " new_blocks = resampler._map_function_over_blocks(blocks, lambda x: x**2)\n", - " new = resampler._merge_array_from_blocks(new_blocks)\n", - " _check_eq(new, array**2)\n", - "\n", - " new_blocks = resampler._map_function_over_blocks(blocks, lambda x: x.sum(axis=-1))\n", - " new = resampler._merge_array_from_blocks(new_blocks)\n", - " _check_eq(new, array.sum(axis=-1))\n", - "\n", - "\n", - "test_split_prefix_dims()" - ] - }, - { - "cell_type": "code", - "execution_count": 63, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:14.076889Z", - "iopub.status.busy": "2023-12-05T23:04:14.076540Z", - "iopub.status.idle": "2023-12-05T23:04:14.111679Z", - "shell.execute_reply": "2023-12-05T23:04:14.110983Z", - "shell.execute_reply.started": "2023-12-05T23:04:14.076874Z" - } - }, - "outputs": [], - "source": [ - "def test_linear_boundary() -> None:\n", - " index = np.array([[-3], [-2], [-1], [0], [1], [2], [3], [2], [3]])\n", - " weight = np.array([[1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [0.0], [0.0]])\n", - " size = 2\n", - " index, weight = resampler.LinearExtendSamples()(index, weight, size, resampler.DualGridtype())\n", - " expected_weight = [\n", - " [0, 4, -3, 0, 0],\n", - " [0, 3, -2, 0, 0],\n", - " [0, 2, -1, 0, 0],\n", - " [1, 0, 0, 0, 0],\n", - " [1, 0, 0, 0, 0],\n", - " [0, 0, 0, -1, 2],\n", - " [0, 0, 0, -2, 3],\n", - " [0, 0, 0, 0, 0],\n", - " [0, 0, 0, 0, 0],\n", - " ]\n", - " assert np.allclose(weight, expected_weight)\n", - " expected_index = [\n", - " [0, 0, 1, 0, 0],\n", - " [0, 0, 1, 0, 0],\n", - " [0, 0, 1, 0, 0],\n", - " [0, 0, 0, 0, 0],\n", - " [1, 1, 1, 1, 1],\n", - " [1, 1, 1, 0, 1],\n", - " [1, 1, 1, 0, 1],\n", - " [1, 1, 1, 1, 1],\n", - " [1, 1, 1, 1, 1],\n", - " ]\n", - " assert np.all(index == expected_index)\n", - "\n", - "\n", - "test_linear_boundary()" - ] - }, - { - "cell_type": "code", - "execution_count": 64, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:14.112700Z", - "iopub.status.busy": "2023-12-05T23:04:14.112482Z", - "iopub.status.idle": "2023-12-05T23:04:14.664524Z", - "shell.execute_reply": "2023-12-05T23:04:14.663870Z", - "shell.execute_reply.started": "2023-12-05T23:04:14.112687Z" - }, - "tags": [] - }, - "outputs": [], - "source": [ - "def test_gamma() -> None:\n", - " dtypes = 'uint8 uint16 uint32'.split()\n", - " for config1 in itertools.product(resampler.ARRAYLIBS, resampler.GAMMAS, dtypes):\n", - " arraylib, gamma_name, dtype = config1\n", - " gamma = resampler._get_gamma(gamma_name)\n", - " if arraylib == 'torch' and dtype in ['uint16', 'uint32']:\n", - " continue # \"The only supported types are: ..., int64, int32, int16, int8, uint8, and bool.\"\n", - " int_max = np.iinfo(dtype).max\n", - " precision = 'float32' if np.iinfo(dtype).bits < 32 else 'float64'\n", - " values = list(range(256)) + list(range(int_max - 255, int_max)) + [int_max]\n", - " array_numpy = np.array(values, dtype)\n", - " array = resampler._make_array(array_numpy, arraylib)\n", - " decoded = gamma.decode(array, np.dtype(precision))\n", - " _check_eq(resampler._arr_dtype(decoded), precision)\n", - " decoded_numpy = resampler._arr_numpy(decoded)\n", - " assert decoded_numpy.min() >= 0.0 and decoded_numpy.max() <= 1.0\n", - " encoded = gamma.encode(decoded, dtype)\n", - " _check_eq(resampler._arr_dtype(encoded), dtype)\n", - " encoded_numpy = resampler._arr_numpy(encoded)\n", - " _check_eq(encoded_numpy, array_numpy)\n", - "\n", - " dtypes = 'float32 float64'.split()\n", - " precisions = 'float32 float64'.split()\n", - " for config2 in itertools.product(resampler.ARRAYLIBS, resampler.GAMMAS, dtypes, precisions):\n", - " arraylib, gamma_name, dtype, precision = config2\n", - " gamma = resampler._get_gamma(gamma_name)\n", - " array_numpy = np.linspace(0.0, 1.0, 100, dtype=dtype)\n", - " array = resampler._make_array(array_numpy, arraylib)\n", - " decoded = gamma.decode(array, np.dtype(precision))\n", - " _check_eq(resampler._arr_dtype(decoded), precision)\n", - " encoded = gamma.encode(decoded, dtype)\n", - " _check_eq(resampler._arr_dtype(encoded), dtype)\n", - " assert np.allclose(resampler._arr_numpy(encoded), array_numpy)\n", - "\n", - "\n", - "if EFFORT >= 1:\n", - " test_gamma()" - ] - }, - { - "cell_type": "code", - "execution_count": 65, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:14.665749Z", - "iopub.status.busy": "2023-12-05T23:04:14.665224Z", - "iopub.status.idle": "2023-12-05T23:04:14.704891Z", - "shell.execute_reply": "2023-12-05T23:04:14.704097Z", - "shell.execute_reply.started": "2023-12-05T23:04:14.665728Z" - } - }, - "outputs": [], - "source": [ - "def test_create_resize_matrix_for_trapezoid_filter(src_size, dst_size, debug=False) -> None:\n", - " filter = resampler.TrapezoidFilter()\n", - " if 0:\n", - " scaling = dst_size / src_size\n", - " radius = 0.5 + 0.5 * min(scaling, 1.0 / scaling)\n", - " print(radius)\n", - " filter = resampler.TrapezoidFilter(radius=radius)\n", - "\n", - " resize_matrix, unused_cval_weight = resampler._create_resize_matrix(\n", - " src_size,\n", - " dst_size,\n", - " src_gridtype=resampler.DualGridtype(),\n", - " dst_gridtype=resampler.DualGridtype(),\n", - " boundary=resampler._get_boundary('reflect'),\n", - " filter=filter,\n", - " )\n", - " resize_matrix = resize_matrix.toarray()\n", - " if debug:\n", - " print(resize_matrix)\n", - " print(resize_matrix.sum(axis=0))\n", - " print(resize_matrix.sum(axis=1))\n", - " assert resize_matrix.sum(axis=0).var() < 1e-10\n", - " assert resize_matrix.sum(axis=1).var() < 1e-10\n", - "\n", - "\n", - "if 1:\n", - " test_create_resize_matrix_for_trapezoid_filter(src_size=6, dst_size=2)\n", - " test_create_resize_matrix_for_trapezoid_filter(src_size=7, dst_size=3)\n", - " test_create_resize_matrix_for_trapezoid_filter(src_size=7, dst_size=6)\n", - " test_create_resize_matrix_for_trapezoid_filter(src_size=14, dst_size=13)\n", - "if 1:\n", - " test_create_resize_matrix_for_trapezoid_filter(src_size=3, dst_size=6)\n", - " test_create_resize_matrix_for_trapezoid_filter(src_size=3, dst_size=12)\n", - " test_create_resize_matrix_for_trapezoid_filter(src_size=3, dst_size=11)\n", - " test_create_resize_matrix_for_trapezoid_filter(src_size=3, dst_size=16)" - ] - }, - { - "cell_type": "code", - "execution_count": 66, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:14.705971Z", - "iopub.status.busy": "2023-12-05T23:04:14.705775Z", - "iopub.status.idle": "2023-12-05T23:04:16.424836Z", - "shell.execute_reply": "2023-12-05T23:04:16.424240Z", - "shell.execute_reply.started": "2023-12-05T23:04:14.705958Z" - }, - "tags": [] - }, - "outputs": [], - "source": [ - "def test_that_resize_matrices_are_equal_across_arraylib() -> None:\n", - " src_sizes = range(1, 6)\n", - " dst_sizes = range(1, 6)\n", - " for config in itertools.product(src_sizes, dst_sizes):\n", - " src_size, dst_size = config\n", - "\n", - " def resize_matrix(arraylib: str) -> _TensorflowTensor:\n", - " return resampler._create_resize_matrix(\n", - " src_size,\n", - " dst_size,\n", - " src_gridtype=resampler.DualGridtype(),\n", - " dst_gridtype=resampler.DualGridtype(),\n", - " boundary=resampler._get_boundary('reflect'),\n", - " filter=resampler._get_filter('lanczos3'),\n", - " translate=0.8,\n", - " dtype=np.float32,\n", - " arraylib=arraylib,\n", - " )[0]\n", - "\n", - " numpy_array = resize_matrix('numpy').toarray()\n", - " tensorflow_array = tf.sparse.to_dense(resize_matrix('tensorflow')).numpy()\n", - " torch_array = resize_matrix('torch').to_dense().numpy()\n", - " jax_array = np.asarray(resize_matrix('jax').todense()) # to_py() deprecated.\n", - " assert np.allclose(tensorflow_array, numpy_array)\n", - " assert np.allclose(torch_array, numpy_array)\n", - " assert np.allclose(jax_array, numpy_array)\n", - "\n", - "\n", - "if EFFORT >= 1:\n", - " test_that_resize_matrices_are_equal_across_arraylib()" - ] - }, - { - "cell_type": "code", - "execution_count": 67, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:16.432141Z", - "iopub.status.busy": "2023-12-05T23:04:16.431707Z", - "iopub.status.idle": "2023-12-05T23:04:16.511812Z", - "shell.execute_reply": "2023-12-05T23:04:16.511221Z", - "shell.execute_reply.started": "2023-12-05T23:04:16.432122Z" - }, - "tags": [] - }, - "outputs": [], - "source": [ - "def test_that_resize_combinations_are_affine() -> None:\n", - " dst_sizes = 1, 2, 3, 4, 9, 20, 21, 22, 31\n", - " for config in itertools.product(resampler.BOUNDARIES, dst_sizes):\n", - " boundary, dst_size = config\n", - " resize_matrix, cval_weight = resampler._create_resize_matrix(\n", - " 21,\n", - " dst_size,\n", - " src_gridtype=resampler.DualGridtype(),\n", - " dst_gridtype=resampler.DualGridtype(),\n", - " boundary=resampler._get_boundary(boundary),\n", - " filter=resampler.TriangleFilter(),\n", - " scale=0.5,\n", - " translate=0.3,\n", - " )\n", - " if cval_weight is None:\n", - " row_sum = np.asarray(resize_matrix.sum(axis=1)).ravel()\n", - " state = config, resize_matrix.todense(), row_sum\n", - " assert np.allclose(row_sum, 1.0, rtol=0, atol=1e-6), state\n", - "\n", - "\n", - "test_that_resize_combinations_are_affine()" - ] - }, - { - "cell_type": "code", - "execution_count": 68, + "execution_count": 57, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:16.512628Z", - "iopub.status.busy": "2023-12-05T23:04:16.512462Z", - "iopub.status.idle": "2023-12-05T23:04:16.547426Z", - "shell.execute_reply": "2023-12-05T23:04:16.546807Z", - "shell.execute_reply.started": "2023-12-05T23:04:16.512613Z" + "iopub.execute_input": "2024-02-13T00:34:10.891041Z", + "iopub.status.busy": "2024-02-13T00:34:10.890335Z", + "iopub.status.idle": "2024-02-13T00:34:10.926598Z", + "shell.execute_reply": "2024-02-13T00:34:10.925692Z", + "shell.execute_reply.started": "2024-02-13T00:34:10.890997Z" } }, "outputs": [], @@ -4275,39 +3850,14 @@ }, { "cell_type": "code", - "execution_count": 69, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:16.548663Z", - "iopub.status.busy": "2023-12-05T23:04:16.548139Z", - "iopub.status.idle": "2023-12-05T23:04:16.582952Z", - "shell.execute_reply": "2023-12-05T23:04:16.582323Z", - "shell.execute_reply.started": "2023-12-05T23:04:16.548647Z" - } - }, - "outputs": [], - "source": [ - "def test_sparse_csr_matrix_duplicate_entries_are_summed() -> None:\n", - " indptr = np.array([0, 2, 3, 6])\n", - " indices = np.array([0, 2, 2, 0, 1, 0])\n", - " data = np.array([1, 2, 3, 4, 5, 3])\n", - " new = scipy.sparse.csr_matrix((data, indices, indptr), shape=(3, 3)).toarray()\n", - " _check_eq(new, [[1, 0, 2], [0, 0, 3], [7, 5, 0]])\n", - "\n", - "\n", - "test_sparse_csr_matrix_duplicate_entries_are_summed()" - ] - }, - { - "cell_type": "code", - "execution_count": 70, + "execution_count": 58, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:16.584185Z", - "iopub.status.busy": "2023-12-05T23:04:16.583633Z", - "iopub.status.idle": "2023-12-05T23:04:16.616863Z", - "shell.execute_reply": "2023-12-05T23:04:16.616208Z", - "shell.execute_reply.started": "2023-12-05T23:04:16.584170Z" + "iopub.execute_input": "2024-02-13T00:34:10.928000Z", + "iopub.status.busy": "2024-02-13T00:34:10.927610Z", + "iopub.status.idle": "2024-02-13T00:34:10.960413Z", + "shell.execute_reply": "2024-02-13T00:34:10.959667Z", + "shell.execute_reply.started": "2024-02-13T00:34:10.927980Z" }, "tags": [] }, @@ -4332,14 +3882,14 @@ }, { "cell_type": "code", - "execution_count": 71, + "execution_count": 59, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:16.618039Z", - "iopub.status.busy": "2023-12-05T23:04:16.617659Z", - "iopub.status.idle": "2023-12-05T23:04:17.080973Z", - "shell.execute_reply": "2023-12-05T23:04:17.080331Z", - "shell.execute_reply.started": "2023-12-05T23:04:16.618022Z" + "iopub.execute_input": "2024-02-13T00:34:10.961321Z", + "iopub.status.busy": "2024-02-13T00:34:10.961145Z", + "iopub.status.idle": "2024-02-13T00:34:11.572270Z", + "shell.execute_reply": "2024-02-13T00:34:11.571473Z", + "shell.execute_reply.started": "2024-02-13T00:34:10.961307Z" }, "tags": [] }, @@ -4377,115 +3927,14 @@ }, { "cell_type": "code", - "execution_count": 72, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:17.081770Z", - "iopub.status.busy": "2023-12-05T23:04:17.081638Z", - "iopub.status.idle": "2023-12-05T23:04:17.130121Z", - "shell.execute_reply": "2023-12-05T23:04:17.129494Z", - "shell.execute_reply.started": "2023-12-05T23:04:17.081758Z" - }, - "tags": [] - }, - "outputs": [], - "source": [ - "def test_linear_precision_of_1d_primal_upsampling() -> None:\n", - " array = np.arange(7.0)\n", - " new = resampler.resize(array, (13,), gridtype='primal', filter='triangle')\n", - " with np.printoptions(linewidth=300):\n", - " _check_eq(new, np.arange(13) / 2)\n", - "\n", - "\n", - "test_linear_precision_of_1d_primal_upsampling()" - ] - }, - { - "cell_type": "code", - "execution_count": 73, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:17.131097Z", - "iopub.status.busy": "2023-12-05T23:04:17.130900Z", - "iopub.status.idle": "2023-12-05T23:04:17.166011Z", - "shell.execute_reply": "2023-12-05T23:04:17.165375Z", - "shell.execute_reply.started": "2023-12-05T23:04:17.131080Z" - } - }, - "outputs": [], - "source": [ - "def test_linear_precision_of_2d_primal_upsampling() -> None:\n", - " shape = 3, 5\n", - " new_shape = 5, 9\n", - " array = np.moveaxis(np.indices(shape, np.float32), 0, -1) @ [10, 1]\n", - " new = resampler.resize(array, new_shape, gridtype='primal', filter='triangle')\n", - " with np.printoptions(linewidth=300):\n", - " expected = np.moveaxis(np.indices(new_shape, np.float32), 0, -1) @ [10, 1] / 2\n", - " _check_eq(new, expected)\n", - "\n", - "\n", - "test_linear_precision_of_2d_primal_upsampling()" - ] - }, - { - "cell_type": "code", - "execution_count": 74, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:17.167074Z", - "iopub.status.busy": "2023-12-05T23:04:17.166722Z", - "iopub.status.idle": "2023-12-05T23:04:17.289128Z", - "shell.execute_reply": "2023-12-05T23:04:17.288535Z", - "shell.execute_reply.started": "2023-12-05T23:04:17.167059Z" - }, - "tags": [] - }, - "outputs": [], - "source": [ - "def test_resize_of_complex_value_type() -> None:\n", - " for arraylib in resampler.ARRAYLIBS:\n", - " array = resampler._make_array([1 + 2j, 3 + 6j], arraylib)\n", - " new = resampler._original_resize(array, (4,), filter='triangle')\n", - " assert np.allclose(new, [1 + 2j, 1.5 + 3j, 2.5 + 5j, 3 + 6j])\n", - "\n", - "\n", - "if EFFORT >= 1:\n", - " test_resize_of_complex_value_type()" - ] - }, - { - "cell_type": "code", - "execution_count": 75, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:17.290301Z", - "iopub.status.busy": "2023-12-05T23:04:17.289845Z", - "iopub.status.idle": "2023-12-05T23:04:17.325794Z", - "shell.execute_reply": "2023-12-05T23:04:17.325106Z", - "shell.execute_reply.started": "2023-12-05T23:04:17.290283Z" - } - }, - "outputs": [], - "source": [ - "def test_resize_of_integer_type() -> None:\n", - " array = np.array([1, 6])\n", - " new = resampler.resize(array, (4,), filter='triangle')\n", - " assert np.allclose(new, [1, 2, 5, 6])\n", - "\n", - "\n", - "test_resize_of_integer_type()" - ] - }, - { - "cell_type": "code", - "execution_count": 76, + "execution_count": 60, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:17.327385Z", - "iopub.status.busy": "2023-12-05T23:04:17.326637Z", - "iopub.status.idle": "2023-12-05T23:04:18.968187Z", - "shell.execute_reply": "2023-12-05T23:04:18.967541Z", - "shell.execute_reply.started": "2023-12-05T23:04:17.327368Z" + "iopub.execute_input": "2024-02-13T00:34:11.574717Z", + "iopub.status.busy": "2024-02-13T00:34:11.573578Z", + "iopub.status.idle": "2024-02-13T00:34:13.066087Z", + "shell.execute_reply": "2024-02-13T00:34:13.065354Z", + "shell.execute_reply.started": "2024-02-13T00:34:11.574691Z" }, "tags": [] }, @@ -4529,56 +3978,14 @@ }, { "cell_type": "code", - "execution_count": 77, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:18.969183Z", - "iopub.status.busy": "2023-12-05T23:04:18.968935Z", - "iopub.status.idle": "2023-12-05T23:04:19.115358Z", - "shell.execute_reply": "2023-12-05T23:04:19.114665Z", - "shell.execute_reply.started": "2023-12-05T23:04:18.969167Z" - } - }, - "outputs": [], - "source": [ - "def test_apply_digital_filter_1d(cval=-10.0, shape=(7, 8)) -> None:\n", - " original = np.arange(math.prod(shape), dtype=np.float32).reshape(shape) + 10\n", - " array1 = original.copy()\n", - " filters = 'cardinal3 cardinal5'.split()\n", - " for config in itertools.product(resampler.GRIDTYPES, resampler.BOUNDARIES, filters):\n", - " gridtype, boundary, filter = config\n", - " if gridtype == 'primal' and boundary in ('wrap', 'tile'):\n", - " continue # Last value on each dimension is ignored and so will not match.\n", - " array2 = array1\n", - " for dim in range(array2.ndim):\n", - " array2 = resampler._apply_digital_filter_1d(\n", - " array2,\n", - " resampler._get_gridtype(gridtype),\n", - " resampler._get_boundary(boundary),\n", - " cval,\n", - " resampler._get_filter(filter),\n", - " axis=dim,\n", - " )\n", - " bspline = resampler.BsplineFilter(degree=int(filter[-1:]))\n", - " array3 = resampler.resize(\n", - " array2, array2.shape, gridtype=gridtype, boundary=boundary, cval=cval, filter=bspline\n", - " )\n", - " assert np.allclose(array3, original), config\n", - "\n", - "\n", - "test_apply_digital_filter_1d()" - ] - }, - { - "cell_type": "code", - "execution_count": 78, + "execution_count": 61, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:19.116317Z", - "iopub.status.busy": "2023-12-05T23:04:19.116018Z", - "iopub.status.idle": "2023-12-05T23:04:19.377029Z", - "shell.execute_reply": "2023-12-05T23:04:19.376423Z", - "shell.execute_reply.started": "2023-12-05T23:04:19.116301Z" + "iopub.execute_input": "2024-02-13T00:34:13.067416Z", + "iopub.status.busy": "2024-02-13T00:34:13.066968Z", + "iopub.status.idle": "2024-02-13T00:34:13.338314Z", + "shell.execute_reply": "2024-02-13T00:34:13.337735Z", + "shell.execute_reply.started": "2024-02-13T00:34:13.067403Z" }, "tags": [] }, @@ -4605,78 +4012,14 @@ }, { "cell_type": "code", - "execution_count": 79, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:19.378206Z", - "iopub.status.busy": "2023-12-05T23:04:19.377791Z", - "iopub.status.idle": "2023-12-05T23:04:19.719784Z", - "shell.execute_reply": "2023-12-05T23:04:19.719127Z", - "shell.execute_reply.started": "2023-12-05T23:04:19.378189Z" - }, - "tags": [] - }, - "outputs": [], - "source": [ - "def test_resample_small_array(arraylib: str) -> None:\n", - " shape = 2, 3\n", - " new_shape = 3, 4\n", - " array = np.arange(math.prod(shape) * 3, dtype=np.float32).reshape(shape + (3,))\n", - " coords = np.moveaxis(np.indices(new_shape) + 0.5, 0, -1) / new_shape\n", - " array = resampler._make_array(array, arraylib)\n", - " upsampled = resampler.resample(array, coords)\n", - " _check_eq(upsampled.shape, (*new_shape, 3))\n", - " coords = np.moveaxis(np.indices(shape) + 0.5, 0, -1) / shape\n", - " downsampled = resampler.resample(upsampled, coords)\n", - " rms = get_rms(array, downsampled)\n", - " assert 0.07 <= rms <= 0.08, rms\n", - "\n", - "\n", - "def test_resample_small_arrays() -> None:\n", - " for arraylib in resampler.ARRAYLIBS:\n", - " test_resample_small_array(arraylib=arraylib)\n", - "\n", - "\n", - "if EFFORT >= 1:\n", - " test_resample_small_arrays()" - ] - }, - { - "cell_type": "code", - "execution_count": 80, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:19.720914Z", - "iopub.status.busy": "2023-12-05T23:04:19.720495Z", - "iopub.status.idle": "2023-12-05T23:04:19.763312Z", - "shell.execute_reply": "2023-12-05T23:04:19.762190Z", - "shell.execute_reply.started": "2023-12-05T23:04:19.720898Z" - }, - "tags": [] - }, - "outputs": [], - "source": [ - "def test_identity_resampling_with_many_boundary_rules(filter: resampler.Filter) -> None:\n", - " for boundary in resampler.BOUNDARIES:\n", - " array = np.arange(6, dtype=np.float32).reshape(2, 3)\n", - " coords = (np.moveaxis(np.indices(array.shape), 0, -1) + 0.5) / array.shape\n", - " new_array = resampler.resample(array, coords, boundary=boundary, cval=10000, filter=filter)\n", - " assert np.allclose(new_array, array), boundary\n", - "\n", - "\n", - "test_identity_resampling_with_many_boundary_rules(resampler.LanczosFilter(radius=5, sampled=False))" - ] - }, - { - "cell_type": "code", - "execution_count": 81, + "execution_count": 62, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:19.764471Z", - "iopub.status.busy": "2023-12-05T23:04:19.764275Z", - "iopub.status.idle": "2023-12-05T23:04:19.805451Z", - "shell.execute_reply": "2023-12-05T23:04:19.804775Z", - "shell.execute_reply.started": "2023-12-05T23:04:19.764458Z" + "iopub.execute_input": "2024-02-13T00:34:13.339398Z", + "iopub.status.busy": "2024-02-13T00:34:13.339238Z", + "iopub.status.idle": "2024-02-13T00:34:13.381114Z", + "shell.execute_reply": "2024-02-13T00:34:13.380447Z", + "shell.execute_reply.started": "2024-02-13T00:34:13.339386Z" }, "tags": [] }, @@ -4744,43 +4087,16 @@ }, { "cell_type": "code", - "execution_count": 82, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:19.806498Z", - "iopub.status.busy": "2023-12-05T23:04:19.806129Z", - "iopub.status.idle": "2023-12-05T23:04:19.841257Z", - "shell.execute_reply": "2023-12-05T23:04:19.840566Z", - "shell.execute_reply.started": "2023-12-05T23:04:19.806482Z" - }, - "tags": [] - }, - "outputs": [], - "source": [ - "def test_identity_resampling() -> None:\n", - " shape = 3, 2, 5\n", - " array = np.random.default_rng(0).random(shape)\n", - " coords = (np.moveaxis(np.indices(array.shape), 0, -1) + 0.5) / array.shape\n", - " new = resampler.resample(array, coords)\n", - " assert np.allclose(new, array, rtol=0, atol=1e-6)\n", - " new = resampler.resample(array, coords, filter=resampler.LanczosFilter(radius=3, sampled=False))\n", - " assert np.allclose(new, array)\n", - "\n", - "\n", - "test_identity_resampling()" - ] - }, - { - "cell_type": "code", - "execution_count": 83, + "execution_count": 63, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:19.842337Z", - "iopub.status.busy": "2023-12-05T23:04:19.842111Z", - "iopub.status.idle": "2023-12-05T23:04:22.695836Z", - "shell.execute_reply": "2023-12-05T23:04:22.695164Z", - "shell.execute_reply.started": "2023-12-05T23:04:19.842320Z" + "iopub.execute_input": "2024-02-13T00:34:13.381951Z", + "iopub.status.busy": "2024-02-13T00:34:13.381786Z", + "iopub.status.idle": "2024-02-13T00:34:16.075684Z", + "shell.execute_reply": "2024-02-13T00:34:16.075045Z", + "shell.execute_reply.started": "2024-02-13T00:34:13.381938Z" }, + "lines_to_next_cell": 2, "tags": [] }, "outputs": [], @@ -4837,228 +4153,12 @@ " _arr_dtype = resampler._arr_dtype\n", " assert resized.dtype == _arr_dtype(resized2) == _arr_dtype(resampled2) == dtype\n", " assert np.allclose(resized2, resized, rtol=0, atol=atol), config\n", - " assert np.allclose(resampled2, resized, rtol=0, atol=atol), config\n", - "\n", - "\n", - "if EFFORT >= 1:\n", - " # hh.prun(lambda: test_that_all_resize_and_resample_agree(), mode='full')\n", - " test_that_all_resize_and_resample_agree() # ~5.5 s on 1st run due to jax compiles; then ~450 ms." - ] - }, - { - "cell_type": "code", - "execution_count": 84, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:22.696826Z", - "iopub.status.busy": "2023-12-05T23:04:22.696631Z", - "iopub.status.idle": "2023-12-05T23:04:22.727284Z", - "shell.execute_reply": "2023-12-05T23:04:22.726664Z", - "shell.execute_reply.started": "2023-12-05T23:04:22.696812Z" - } - }, - "outputs": [], - "source": [ - "def test_resample_of_complex_value_type() -> None:\n", - " array = np.array([1 + 2j, 3 + 6j])\n", - " new = resampler.resample(array, (0.125, 0.375, 0.625, 0.875), filter='triangle')\n", - " assert np.allclose(new, [1 + 2j, 1.5 + 3j, 2.5 + 5j, 3 + 6j])\n", - "\n", - "\n", - "test_resample_of_complex_value_type()" - ] - }, - { - "cell_type": "code", - "execution_count": 85, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:22.727987Z", - "iopub.status.busy": "2023-12-05T23:04:22.727844Z", - "iopub.status.idle": "2023-12-05T23:04:22.759388Z", - "shell.execute_reply": "2023-12-05T23:04:22.758386Z", - "shell.execute_reply.started": "2023-12-05T23:04:22.727976Z" - } - }, - "outputs": [], - "source": [ - "def test_resample_of_integer_type() -> None:\n", - " array = np.array([1, 6])\n", - " new = resampler.resample(array, (0.125, 0.375, 0.625, 0.875), filter='triangle')\n", - " assert np.allclose(new, [1, 2, 5, 6])\n", - "\n", - "\n", - "test_resample_of_integer_type()" - ] - }, - { - "cell_type": "code", - "execution_count": 86, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:22.760687Z", - "iopub.status.busy": "2023-12-05T23:04:22.760476Z", - "iopub.status.idle": "2023-12-05T23:04:22.803669Z", - "shell.execute_reply": "2023-12-05T23:04:22.803004Z", - "shell.execute_reply.started": "2023-12-05T23:04:22.760673Z" - } - }, - "outputs": [], - "source": [ - "def test_resample_using_coords_of_various_shapes(debug=False) -> None:\n", - " for array in [\n", - " 8,\n", - " [7],\n", - " [0, 1, 6, 6],\n", - " [[0, 1], [10, 16]],\n", - " [[0], [1], [6], [6]],\n", - " ]:\n", - " array = np.array(array, np.float64)\n", - " for shape in [(), (1,), (2,), (1, 1), (1, 2), (3, 1), (2, 2)]:\n", - " coords = np.full(shape, 0.4)\n", - " try:\n", - " new = resampler.resample(array, coords, filter='triangle', dtype=np.float32).tolist()\n", - " except ValueError:\n", - " new = None\n", - " if debug:\n", - " print(f'{array.tolist()!s:30} {coords.shape!s:8} {new!s}')\n", - " _check_eq(new is None, coords.ndim >= 2 and coords.shape[-1] > max(array.ndim, 1))\n", - "\n", - "\n", - "test_resample_using_coords_of_various_shapes()" - ] - }, - { - "cell_type": "code", - "execution_count": 87, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:22.804967Z", - "iopub.status.busy": "2023-12-05T23:04:22.804484Z", - "iopub.status.idle": "2023-12-05T23:04:22.938556Z", - "shell.execute_reply": "2023-12-05T23:04:22.937940Z", - "shell.execute_reply.started": "2023-12-05T23:04:22.804950Z" - }, - "tags": [] - }, - "outputs": [], - "source": [ - "def test_resize_using_resample(shape=(3, 2, 5), new_shape=(4, 2, 7), step=37) -> None:\n", - " assert np.all(np.array(shape) <= new_shape)\n", - " array = np.random.default_rng(0).random(shape)\n", - " scale = 1.1\n", - " translate = -0.4, -0.03, 0.4\n", - " gammas = 'identity power2'.split() # Sublist of resampler.GAMMAS.\n", - " sequences = [resampler.GRIDTYPES, resampler.BOUNDARIES, resampler.FILTERS, gammas]\n", - " assert step == 1 or all(len(sequence) % step != 0 for sequence in sequences)\n", - " configs = itertools.product(*sequences) # len(configs) = math.prod([2, 12, 19, 2]) = 912.\n", - " for config in itertools.islice(configs, 0, None, step):\n", - " gridtype, boundary, filter, gamma = config\n", - " kwargs = dict(gridtype=gridtype, boundary=boundary, filter=filter)\n", - " kwargs |= dict(gamma=gamma, scale=scale, translate=translate)\n", - " expected = resampler._original_resize(array, new_shape, **kwargs)\n", - " new_array = resampler._resize_using_resample(array, new_shape, **kwargs)\n", - " assert np.allclose(new_array, expected, rtol=0, atol=1e-7), config\n", - "\n", - "\n", - "test_resize_using_resample()" - ] - }, - { - "cell_type": "code", - "execution_count": 88, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:22.939527Z", - "iopub.status.busy": "2023-12-05T23:04:22.939245Z", - "iopub.status.idle": "2023-12-05T23:04:22.974162Z", - "shell.execute_reply": "2023-12-05T23:04:22.973555Z", - "shell.execute_reply.started": "2023-12-05T23:04:22.939514Z" - } - }, - "outputs": [], - "source": [ - "def test_resize_using_resample_of_complex_value_type() -> None:\n", - " array = np.array([1 + 2j, 3 + 6j])\n", - " new = resampler._resize_using_resample(array, (4,), filter='triangle')\n", - " assert np.allclose(new, [1 + 2j, 1.5 + 3j, 2.5 + 5j, 3 + 6j])\n", - "\n", - "\n", - "test_resize_using_resample_of_complex_value_type()" - ] - }, - { - "cell_type": "code", - "execution_count": 89, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:22.975305Z", - "iopub.status.busy": "2023-12-05T23:04:22.974882Z", - "iopub.status.idle": "2023-12-05T23:04:23.007244Z", - "shell.execute_reply": "2023-12-05T23:04:23.006638Z", - "shell.execute_reply.started": "2023-12-05T23:04:22.975291Z" - }, - "tags": [] - }, - "outputs": [], - "source": [ - "def test_resizer_produces_correct_shape(resizer, filter: str = 'lanczos3') -> None:\n", - " tol: Any = dict(rtol=0, atol=1e-7)\n", - " np.allclose(resizer(np.ones((11,)), (13,), filter=filter), np.ones((13,)), **tol)\n", - " np.allclose(resizer(np.ones((8, 8)), (5, 20), filter=filter), np.ones((5, 20)), **tol)\n", - " np.allclose(resizer(np.ones((11, 10, 3)), (13, 7), filter=filter), np.ones((13, 7, 3)), **tol)" - ] - }, - { - "cell_type": "code", - "execution_count": 90, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:23.008289Z", - "iopub.status.busy": "2023-12-05T23:04:23.007877Z", - "iopub.status.idle": "2023-12-05T23:04:23.382712Z", - "shell.execute_reply": "2023-12-05T23:04:23.382133Z", - "shell.execute_reply.started": "2023-12-05T23:04:23.008274Z" - }, - "tags": [] - }, - "outputs": [], - "source": [ - "def test_resizers_produce_correct_shape() -> None:\n", - " test_resizer_produces_correct_shape(resampler.resize)\n", - " for arraylib in resampler.ARRAYLIBS:\n", - " resizer = functools.partial(resampler.resize_in_arraylib, arraylib=arraylib)\n", - " test_resizer_produces_correct_shape(resizer)\n", - "\n", - "\n", - "if EFFORT >= 1:\n", - " test_resizers_produce_correct_shape()" - ] - }, - { - "cell_type": "code", - "execution_count": 91, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:04:23.384173Z", - "iopub.status.busy": "2023-12-05T23:04:23.383715Z", - "iopub.status.idle": "2023-12-05T23:04:24.663343Z", - "shell.execute_reply": "2023-12-05T23:04:24.662760Z", - "shell.execute_reply.started": "2023-12-05T23:04:23.384158Z" - }, - "lines_to_next_cell": 2 - }, - "outputs": [], - "source": [ - "test_resizer_produces_correct_shape(resampler.pil_image_resize)\n", - "test_resizer_produces_correct_shape(resampler.cv_resize, 'lanczos4')\n", - "test_resizer_produces_correct_shape(resampler.scipy_ndimage_resize, 'cardinal3')\n", - "test_resizer_produces_correct_shape(resampler.skimage_transform_resize, 'cardinal3')\n", - "if EFFORT >= 1:\n", - " test_resizer_produces_correct_shape(resampler.tf_image_resize)\n", - "test_resizer_produces_correct_shape(resampler.torch_nn_resize, 'sharpcubic')\n", + " assert np.allclose(resampled2, resized, rtol=0, atol=atol), config\n", + "\n", + "\n", "if EFFORT >= 1:\n", - " test_resizer_produces_correct_shape(resampler.jax_image_resize, 'lanczos3')" + " # hh.prun(lambda: test_that_all_resize_and_resample_agree(), mode='full')\n", + " test_that_all_resize_and_resample_agree() # ~5.5 s on 1st run due to jax compiles; then ~450 ms." ] }, { @@ -5077,14 +4177,14 @@ }, { "cell_type": "code", - "execution_count": 92, + "execution_count": 64, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:24.664358Z", - "iopub.status.busy": "2023-12-05T23:04:24.664068Z", - "iopub.status.idle": "2023-12-05T23:04:24.704688Z", - "shell.execute_reply": "2023-12-05T23:04:24.703613Z", - "shell.execute_reply.started": "2023-12-05T23:04:24.664339Z" + "iopub.execute_input": "2024-02-13T00:34:16.076865Z", + "iopub.status.busy": "2024-02-13T00:34:16.076473Z", + "iopub.status.idle": "2024-02-13T00:34:16.108777Z", + "shell.execute_reply": "2024-02-13T00:34:16.107818Z", + "shell.execute_reply.started": "2024-02-13T00:34:16.076850Z" }, "lines_to_next_cell": 2, "tags": [] @@ -5101,14 +4201,14 @@ }, { "cell_type": "code", - "execution_count": 93, + "execution_count": 65, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:24.706413Z", - "iopub.status.busy": "2023-12-05T23:04:24.706145Z", - "iopub.status.idle": "2023-12-05T23:04:24.780921Z", - "shell.execute_reply": "2023-12-05T23:04:24.780160Z", - "shell.execute_reply.started": "2023-12-05T23:04:24.706395Z" + "iopub.execute_input": "2024-02-13T00:34:16.109882Z", + "iopub.status.busy": "2024-02-13T00:34:16.109586Z", + "iopub.status.idle": "2024-02-13T00:34:16.489045Z", + "shell.execute_reply": "2024-02-13T00:34:16.488388Z", + "shell.execute_reply.started": "2024-02-13T00:34:16.109869Z" }, "tags": [] }, @@ -5134,14 +4234,14 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": 66, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:24.781881Z", - "iopub.status.busy": "2023-12-05T23:04:24.781699Z", - "iopub.status.idle": "2023-12-05T23:04:24.818681Z", - "shell.execute_reply": "2023-12-05T23:04:24.817968Z", - "shell.execute_reply.started": "2023-12-05T23:04:24.781867Z" + "iopub.execute_input": "2024-02-13T00:34:16.497066Z", + "iopub.status.busy": "2024-02-13T00:34:16.496720Z", + "iopub.status.idle": "2024-02-13T00:34:16.532611Z", + "shell.execute_reply": "2024-02-13T00:34:16.532001Z", + "shell.execute_reply.started": "2024-02-13T00:34:16.497049Z" }, "tags": [] }, @@ -5175,14 +4275,14 @@ }, { "cell_type": "code", - "execution_count": 95, + "execution_count": 67, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:24.819847Z", - "iopub.status.busy": "2023-12-05T23:04:24.819510Z", - "iopub.status.idle": "2023-12-05T23:04:24.852470Z", - "shell.execute_reply": "2023-12-05T23:04:24.851731Z", - "shell.execute_reply.started": "2023-12-05T23:04:24.819830Z" + "iopub.execute_input": "2024-02-13T00:34:16.533810Z", + "iopub.status.busy": "2024-02-13T00:34:16.533356Z", + "iopub.status.idle": "2024-02-13T00:34:16.567648Z", + "shell.execute_reply": "2024-02-13T00:34:16.567023Z", + "shell.execute_reply.started": "2024-02-13T00:34:16.533793Z" }, "lines_to_next_cell": 2, "tags": [] @@ -5201,14 +4301,14 @@ }, { "cell_type": "code", - "execution_count": 96, + "execution_count": 68, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:24.853618Z", - "iopub.status.busy": "2023-12-05T23:04:24.853390Z", - "iopub.status.idle": "2023-12-05T23:04:24.901061Z", - "shell.execute_reply": "2023-12-05T23:04:24.900255Z", - "shell.execute_reply.started": "2023-12-05T23:04:24.853603Z" + "iopub.execute_input": "2024-02-13T00:34:16.568807Z", + "iopub.status.busy": "2024-02-13T00:34:16.568482Z", + "iopub.status.idle": "2024-02-13T00:34:16.623569Z", + "shell.execute_reply": "2024-02-13T00:34:16.622997Z", + "shell.execute_reply.started": "2024-02-13T00:34:16.568791Z" }, "tags": [] }, @@ -5237,14 +4337,14 @@ }, { "cell_type": "code", - "execution_count": 97, + "execution_count": 69, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:24.902062Z", - "iopub.status.busy": "2023-12-05T23:04:24.901900Z", - "iopub.status.idle": "2023-12-05T23:04:24.934636Z", - "shell.execute_reply": "2023-12-05T23:04:24.934029Z", - "shell.execute_reply.started": "2023-12-05T23:04:24.902050Z" + "iopub.execute_input": "2024-02-13T00:34:16.624512Z", + "iopub.status.busy": "2024-02-13T00:34:16.624206Z", + "iopub.status.idle": "2024-02-13T00:34:16.657259Z", + "shell.execute_reply": "2024-02-13T00:34:16.656600Z", + "shell.execute_reply.started": "2024-02-13T00:34:16.624498Z" }, "tags": [] }, @@ -5277,14 +4377,14 @@ }, { "cell_type": "code", - "execution_count": 98, + "execution_count": 70, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:24.935556Z", - "iopub.status.busy": "2023-12-05T23:04:24.935373Z", - "iopub.status.idle": "2023-12-05T23:04:24.967638Z", - "shell.execute_reply": "2023-12-05T23:04:24.966972Z", - "shell.execute_reply.started": "2023-12-05T23:04:24.935542Z" + "iopub.execute_input": "2024-02-13T00:34:16.658245Z", + "iopub.status.busy": "2024-02-13T00:34:16.658033Z", + "iopub.status.idle": "2024-02-13T00:34:16.689233Z", + "shell.execute_reply": "2024-02-13T00:34:16.688604Z", + "shell.execute_reply.started": "2024-02-13T00:34:16.658228Z" }, "lines_to_next_cell": 2, "tags": [] @@ -5310,14 +4410,14 @@ }, { "cell_type": "code", - "execution_count": 99, + "execution_count": 71, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:24.968914Z", - "iopub.status.busy": "2023-12-05T23:04:24.968410Z", - "iopub.status.idle": "2023-12-05T23:04:25.033981Z", - "shell.execute_reply": "2023-12-05T23:04:25.033204Z", - "shell.execute_reply.started": "2023-12-05T23:04:24.968900Z" + "iopub.execute_input": "2024-02-13T00:34:16.690434Z", + "iopub.status.busy": "2024-02-13T00:34:16.689938Z", + "iopub.status.idle": "2024-02-13T00:34:16.749441Z", + "shell.execute_reply": "2024-02-13T00:34:16.748863Z", + "shell.execute_reply.started": "2024-02-13T00:34:16.690416Z" }, "lines_to_next_cell": 2, "tags": [] @@ -5357,14 +4457,14 @@ }, { "cell_type": "code", - "execution_count": 100, + "execution_count": 72, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:25.034929Z", - "iopub.status.busy": "2023-12-05T23:04:25.034784Z", - "iopub.status.idle": "2023-12-05T23:04:25.083045Z", - "shell.execute_reply": "2023-12-05T23:04:25.081837Z", - "shell.execute_reply.started": "2023-12-05T23:04:25.034917Z" + "iopub.execute_input": "2024-02-13T00:34:16.750673Z", + "iopub.status.busy": "2024-02-13T00:34:16.750203Z", + "iopub.status.idle": "2024-02-13T00:34:16.782318Z", + "shell.execute_reply": "2024-02-13T00:34:16.781645Z", + "shell.execute_reply.started": "2024-02-13T00:34:16.750659Z" }, "lines_to_next_cell": 2, "tags": [] @@ -5380,14 +4480,14 @@ }, { "cell_type": "code", - "execution_count": 101, + "execution_count": 73, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:25.084481Z", - "iopub.status.busy": "2023-12-05T23:04:25.084159Z", - "iopub.status.idle": "2023-12-05T23:04:25.158161Z", - "shell.execute_reply": "2023-12-05T23:04:25.157557Z", - "shell.execute_reply.started": "2023-12-05T23:04:25.084465Z" + "iopub.execute_input": "2024-02-13T00:34:16.783584Z", + "iopub.status.busy": "2024-02-13T00:34:16.783131Z", + "iopub.status.idle": "2024-02-13T00:34:16.852076Z", + "shell.execute_reply": "2024-02-13T00:34:16.851460Z", + "shell.execute_reply.started": "2024-02-13T00:34:16.783570Z" }, "tags": [] }, @@ -5428,14 +4528,14 @@ }, { "cell_type": "code", - "execution_count": 102, + "execution_count": 74, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:25.159238Z", - "iopub.status.busy": "2023-12-05T23:04:25.158936Z", - "iopub.status.idle": "2023-12-05T23:04:25.191441Z", - "shell.execute_reply": "2023-12-05T23:04:25.190846Z", - "shell.execute_reply.started": "2023-12-05T23:04:25.159223Z" + "iopub.execute_input": "2024-02-13T00:34:16.853214Z", + "iopub.status.busy": "2024-02-13T00:34:16.852819Z", + "iopub.status.idle": "2024-02-13T00:34:16.885724Z", + "shell.execute_reply": "2024-02-13T00:34:16.885088Z", + "shell.execute_reply.started": "2024-02-13T00:34:16.853199Z" }, "lines_to_next_cell": 2, "tags": [] @@ -5455,14 +4555,14 @@ }, { "cell_type": "code", - "execution_count": 103, + "execution_count": 75, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:25.192527Z", - "iopub.status.busy": "2023-12-05T23:04:25.192192Z", - "iopub.status.idle": "2023-12-05T23:04:25.267028Z", - "shell.execute_reply": "2023-12-05T23:04:25.266420Z", - "shell.execute_reply.started": "2023-12-05T23:04:25.192509Z" + "iopub.execute_input": "2024-02-13T00:34:16.886598Z", + "iopub.status.busy": "2024-02-13T00:34:16.886410Z", + "iopub.status.idle": "2024-02-13T00:34:16.960094Z", + "shell.execute_reply": "2024-02-13T00:34:16.959534Z", + "shell.execute_reply.started": "2024-02-13T00:34:16.886585Z" }, "lines_to_next_cell": 2, "tags": [] @@ -5506,14 +4606,14 @@ }, { "cell_type": "code", - "execution_count": 104, + "execution_count": 76, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:25.268257Z", - "iopub.status.busy": "2023-12-05T23:04:25.267781Z", - "iopub.status.idle": "2023-12-05T23:04:25.302531Z", - "shell.execute_reply": "2023-12-05T23:04:25.301916Z", - "shell.execute_reply.started": "2023-12-05T23:04:25.268239Z" + "iopub.execute_input": "2024-02-13T00:34:16.961208Z", + "iopub.status.busy": "2024-02-13T00:34:16.960872Z", + "iopub.status.idle": "2024-02-13T00:34:16.992527Z", + "shell.execute_reply": "2024-02-13T00:34:16.991878Z", + "shell.execute_reply.started": "2024-02-13T00:34:16.961193Z" }, "lines_to_next_cell": 2, "tags": [] @@ -5532,14 +4632,14 @@ }, { "cell_type": "code", - "execution_count": 105, + "execution_count": 77, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:25.303864Z", - "iopub.status.busy": "2023-12-05T23:04:25.303522Z", - "iopub.status.idle": "2023-12-05T23:04:25.347249Z", - "shell.execute_reply": "2023-12-05T23:04:25.346618Z", - "shell.execute_reply.started": "2023-12-05T23:04:25.303847Z" + "iopub.execute_input": "2024-02-13T00:34:16.993767Z", + "iopub.status.busy": "2024-02-13T00:34:16.993300Z", + "iopub.status.idle": "2024-02-13T00:34:17.035217Z", + "shell.execute_reply": "2024-02-13T00:34:17.034591Z", + "shell.execute_reply.started": "2024-02-13T00:34:16.993751Z" }, "tags": [] }, @@ -5568,14 +4668,14 @@ }, { "cell_type": "code", - "execution_count": 106, + "execution_count": 78, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:25.348176Z", - "iopub.status.busy": "2023-12-05T23:04:25.347917Z", - "iopub.status.idle": "2023-12-05T23:04:25.435020Z", - "shell.execute_reply": "2023-12-05T23:04:25.434428Z", - "shell.execute_reply.started": "2023-12-05T23:04:25.348163Z" + "iopub.execute_input": "2024-02-13T00:34:17.036369Z", + "iopub.status.busy": "2024-02-13T00:34:17.036000Z", + "iopub.status.idle": "2024-02-13T00:34:17.131316Z", + "shell.execute_reply": "2024-02-13T00:34:17.130708Z", + "shell.execute_reply.started": "2024-02-13T00:34:17.036353Z" }, "tags": [] }, @@ -5622,14 +4722,14 @@ }, { "cell_type": "code", - "execution_count": 107, + "execution_count": 79, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:25.436219Z", - "iopub.status.busy": "2023-12-05T23:04:25.435762Z", - "iopub.status.idle": "2023-12-05T23:04:25.469480Z", - "shell.execute_reply": "2023-12-05T23:04:25.468786Z", - "shell.execute_reply.started": "2023-12-05T23:04:25.436204Z" + "iopub.execute_input": "2024-02-13T00:34:17.132226Z", + "iopub.status.busy": "2024-02-13T00:34:17.131972Z", + "iopub.status.idle": "2024-02-13T00:34:17.164298Z", + "shell.execute_reply": "2024-02-13T00:34:17.163677Z", + "shell.execute_reply.started": "2024-02-13T00:34:17.132214Z" }, "lines_to_next_cell": 2, "tags": [] @@ -5647,14 +4747,14 @@ }, { "cell_type": "code", - "execution_count": 108, + "execution_count": 80, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:25.470319Z", - "iopub.status.busy": "2023-12-05T23:04:25.470176Z", - "iopub.status.idle": "2023-12-05T23:04:27.234747Z", - "shell.execute_reply": "2023-12-05T23:04:27.234089Z", - "shell.execute_reply.started": "2023-12-05T23:04:25.470306Z" + "iopub.execute_input": "2024-02-13T00:34:17.165497Z", + "iopub.status.busy": "2024-02-13T00:34:17.165070Z", + "iopub.status.idle": "2024-02-13T00:34:19.009166Z", + "shell.execute_reply": "2024-02-13T00:34:19.008511Z", + "shell.execute_reply.started": "2024-02-13T00:34:17.165481Z" }, "lines_to_next_cell": 2, "tags": [] @@ -5693,14 +4793,14 @@ }, { "cell_type": "code", - "execution_count": 109, + "execution_count": 81, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:27.235874Z", - "iopub.status.busy": "2023-12-05T23:04:27.235497Z", - "iopub.status.idle": "2023-12-05T23:04:27.268659Z", - "shell.execute_reply": "2023-12-05T23:04:27.267939Z", - "shell.execute_reply.started": "2023-12-05T23:04:27.235858Z" + "iopub.execute_input": "2024-02-13T00:34:19.010393Z", + "iopub.status.busy": "2024-02-13T00:34:19.009981Z", + "iopub.status.idle": "2024-02-13T00:34:19.043275Z", + "shell.execute_reply": "2024-02-13T00:34:19.042632Z", + "shell.execute_reply.started": "2024-02-13T00:34:19.010371Z" } }, "outputs": [], @@ -5713,14 +4813,14 @@ }, { "cell_type": "code", - "execution_count": 110, + "execution_count": 82, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:27.269571Z", - "iopub.status.busy": "2023-12-05T23:04:27.269399Z", - "iopub.status.idle": "2023-12-05T23:04:27.301948Z", - "shell.execute_reply": "2023-12-05T23:04:27.301314Z", - "shell.execute_reply.started": "2023-12-05T23:04:27.269558Z" + "iopub.execute_input": "2024-02-13T00:34:19.044297Z", + "iopub.status.busy": "2024-02-13T00:34:19.043974Z", + "iopub.status.idle": "2024-02-13T00:34:19.076834Z", + "shell.execute_reply": "2024-02-13T00:34:19.076113Z", + "shell.execute_reply.started": "2024-02-13T00:34:19.044280Z" }, "tags": [] }, @@ -5750,14 +4850,14 @@ }, { "cell_type": "code", - "execution_count": 111, + "execution_count": 83, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:27.302934Z", - "iopub.status.busy": "2023-12-05T23:04:27.302616Z", - "iopub.status.idle": "2023-12-05T23:04:28.952574Z", - "shell.execute_reply": "2023-12-05T23:04:28.951971Z", - "shell.execute_reply.started": "2023-12-05T23:04:27.302905Z" + "iopub.execute_input": "2024-02-13T00:34:19.077881Z", + "iopub.status.busy": "2024-02-13T00:34:19.077560Z", + "iopub.status.idle": "2024-02-13T00:34:20.824205Z", + "shell.execute_reply": "2024-02-13T00:34:20.823597Z", + "shell.execute_reply.started": "2024-02-13T00:34:19.077863Z" } }, "outputs": [ @@ -5765,10 +4865,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "# arraylib=numpy : 0.265854 1.79x\n", - "# arraylib=tensorflow: 0.323168 16.37x\n", - "# arraylib=torch : 0.248089 9.53x\n", - "# arraylib=jax : 0.775382 2.79x\n" + "# arraylib=numpy : 0.301128 1.77x\n", + "# arraylib=tensorflow: 0.344801 15.64x\n", + "# arraylib=torch : 0.255796 9.98x\n", + "# arraylib=jax : 0.804985 2.69x\n" ] } ], @@ -5795,14 +4895,14 @@ }, { "cell_type": "code", - "execution_count": 112, + "execution_count": 84, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:28.953902Z", - "iopub.status.busy": "2023-12-05T23:04:28.953349Z", - "iopub.status.idle": "2023-12-05T23:04:28.983712Z", - "shell.execute_reply": "2023-12-05T23:04:28.983014Z", - "shell.execute_reply.started": "2023-12-05T23:04:28.953887Z" + "iopub.execute_input": "2024-02-13T00:34:20.825307Z", + "iopub.status.busy": "2024-02-13T00:34:20.824985Z", + "iopub.status.idle": "2024-02-13T00:34:20.856389Z", + "shell.execute_reply": "2024-02-13T00:34:20.855757Z", + "shell.execute_reply.started": "2024-02-13T00:34:20.825294Z" }, "lines_to_next_cell": 2 }, @@ -5831,14 +4931,14 @@ }, { "cell_type": "code", - "execution_count": 113, + "execution_count": 85, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:28.984650Z", - "iopub.status.busy": "2023-12-05T23:04:28.984440Z", - "iopub.status.idle": "2023-12-05T23:04:29.059927Z", - "shell.execute_reply": "2023-12-05T23:04:29.059207Z", - "shell.execute_reply.started": "2023-12-05T23:04:28.984633Z" + "iopub.execute_input": "2024-02-13T00:34:20.857564Z", + "iopub.status.busy": "2024-02-13T00:34:20.857150Z", + "iopub.status.idle": "2024-02-13T00:34:20.913930Z", + "shell.execute_reply": "2024-02-13T00:34:20.913208Z", + "shell.execute_reply.started": "2024-02-13T00:34:20.857548Z" } }, "outputs": [ @@ -5846,8 +4946,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "numba_csr_dense_mult: 0.015453\n", - "numba_parallel_csr_dense_mult: 0.020385\n" + "numba_csr_dense_mult: 0.008921\n", + "numba_parallel_csr_dense_mult: 0.013695\n" ] } ], @@ -5868,14 +4968,14 @@ }, { "cell_type": "code", - "execution_count": 114, + "execution_count": 86, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:29.061310Z", - "iopub.status.busy": "2023-12-05T23:04:29.060966Z", - "iopub.status.idle": "2023-12-05T23:04:31.782834Z", - "shell.execute_reply": "2023-12-05T23:04:31.781933Z", - "shell.execute_reply.started": "2023-12-05T23:04:29.061295Z" + "iopub.execute_input": "2024-02-13T00:34:20.914809Z", + "iopub.status.busy": "2024-02-13T00:34:20.914664Z", + "iopub.status.idle": "2024-02-13T00:34:23.618203Z", + "shell.execute_reply": "2024-02-13T00:34:23.617271Z", + "shell.execute_reply.started": "2024-02-13T00:34:20.914796Z" } }, "outputs": [ @@ -5883,8 +4983,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "# single:105.338 ms executor: 41.294 ms numba: 39.398 ms\n", - "# single: 0.002 ms executor: 0.968 ms numba: 0.008 ms\n" + "# single:230.271 ms executor: 42.009 ms numba: 38.811 ms\n", + "# single: 0.002 ms executor: 0.949 ms numba: 0.005 ms\n" ] } ], @@ -5987,14 +5087,14 @@ }, { "cell_type": "code", - "execution_count": 115, + "execution_count": 87, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:31.784535Z", - "iopub.status.busy": "2023-12-05T23:04:31.783792Z", - "iopub.status.idle": "2023-12-05T23:04:31.834586Z", - "shell.execute_reply": "2023-12-05T23:04:31.833921Z", - "shell.execute_reply.started": "2023-12-05T23:04:31.784498Z" + "iopub.execute_input": "2024-02-13T00:34:23.620190Z", + "iopub.status.busy": "2024-02-13T00:34:23.619325Z", + "iopub.status.idle": "2024-02-13T00:34:23.661136Z", + "shell.execute_reply": "2024-02-13T00:34:23.660140Z", + "shell.execute_reply.started": "2024-02-13T00:34:23.620151Z" } }, "outputs": [], @@ -6010,14 +5110,14 @@ }, { "cell_type": "code", - "execution_count": 116, + "execution_count": 88, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:31.835853Z", - "iopub.status.busy": "2023-12-05T23:04:31.835392Z", - "iopub.status.idle": "2023-12-05T23:04:31.866836Z", - "shell.execute_reply": "2023-12-05T23:04:31.866167Z", - "shell.execute_reply.started": "2023-12-05T23:04:31.835838Z" + "iopub.execute_input": "2024-02-13T00:34:23.662375Z", + "iopub.status.busy": "2024-02-13T00:34:23.662084Z", + "iopub.status.idle": "2024-02-13T00:34:23.700457Z", + "shell.execute_reply": "2024-02-13T00:34:23.699794Z", + "shell.execute_reply.started": "2024-02-13T00:34:23.662354Z" } }, "outputs": [], @@ -6033,14 +5133,14 @@ }, { "cell_type": "code", - "execution_count": 117, + "execution_count": 89, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:31.868109Z", - "iopub.status.busy": "2023-12-05T23:04:31.867703Z", - "iopub.status.idle": "2023-12-05T23:04:31.900588Z", - "shell.execute_reply": "2023-12-05T23:04:31.899939Z", - "shell.execute_reply.started": "2023-12-05T23:04:31.868095Z" + "iopub.execute_input": "2024-02-13T00:34:23.701615Z", + "iopub.status.busy": "2024-02-13T00:34:23.701271Z", + "iopub.status.idle": "2024-02-13T00:34:23.733565Z", + "shell.execute_reply": "2024-02-13T00:34:23.732928Z", + "shell.execute_reply.started": "2024-02-13T00:34:23.701597Z" } }, "outputs": [], @@ -6052,14 +5152,14 @@ }, { "cell_type": "code", - "execution_count": 118, + "execution_count": 90, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:31.902020Z", - "iopub.status.busy": "2023-12-05T23:04:31.901592Z", - "iopub.status.idle": "2023-12-05T23:04:31.934518Z", - "shell.execute_reply": "2023-12-05T23:04:31.933821Z", - "shell.execute_reply.started": "2023-12-05T23:04:31.902004Z" + "iopub.execute_input": "2024-02-13T00:34:23.734663Z", + "iopub.status.busy": "2024-02-13T00:34:23.734345Z", + "iopub.status.idle": "2024-02-13T00:34:23.766957Z", + "shell.execute_reply": "2024-02-13T00:34:23.766306Z", + "shell.execute_reply.started": "2024-02-13T00:34:23.734648Z" } }, "outputs": [], @@ -6071,14 +5171,14 @@ }, { "cell_type": "code", - "execution_count": 119, + "execution_count": 91, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:31.935594Z", - "iopub.status.busy": "2023-12-05T23:04:31.935314Z", - "iopub.status.idle": "2023-12-05T23:04:31.967738Z", - "shell.execute_reply": "2023-12-05T23:04:31.967077Z", - "shell.execute_reply.started": "2023-12-05T23:04:31.935580Z" + "iopub.execute_input": "2024-02-13T00:34:23.767955Z", + "iopub.status.busy": "2024-02-13T00:34:23.767705Z", + "iopub.status.idle": "2024-02-13T00:34:23.799686Z", + "shell.execute_reply": "2024-02-13T00:34:23.799051Z", + "shell.execute_reply.started": "2024-02-13T00:34:23.767940Z" } }, "outputs": [], @@ -6090,14 +5190,14 @@ }, { "cell_type": "code", - "execution_count": 120, + "execution_count": 92, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:31.968719Z", - "iopub.status.busy": "2023-12-05T23:04:31.968445Z", - "iopub.status.idle": "2023-12-05T23:04:32.000886Z", - "shell.execute_reply": "2023-12-05T23:04:32.000189Z", - "shell.execute_reply.started": "2023-12-05T23:04:31.968705Z" + "iopub.execute_input": "2024-02-13T00:34:23.800799Z", + "iopub.status.busy": "2024-02-13T00:34:23.800379Z", + "iopub.status.idle": "2024-02-13T00:34:23.832191Z", + "shell.execute_reply": "2024-02-13T00:34:23.831551Z", + "shell.execute_reply.started": "2024-02-13T00:34:23.800785Z" } }, "outputs": [], @@ -6108,14 +5208,14 @@ }, { "cell_type": "code", - "execution_count": 121, + "execution_count": 93, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:32.002044Z", - "iopub.status.busy": "2023-12-05T23:04:32.001708Z", - "iopub.status.idle": "2023-12-05T23:04:32.038596Z", - "shell.execute_reply": "2023-12-05T23:04:32.037884Z", - "shell.execute_reply.started": "2023-12-05T23:04:32.002025Z" + "iopub.execute_input": "2024-02-13T00:34:23.833113Z", + "iopub.status.busy": "2024-02-13T00:34:23.832890Z", + "iopub.status.idle": "2024-02-13T00:34:23.865991Z", + "shell.execute_reply": "2024-02-13T00:34:23.865296Z", + "shell.execute_reply.started": "2024-02-13T00:34:23.833101Z" } }, "outputs": [], @@ -6147,14 +5247,14 @@ }, { "cell_type": "code", - "execution_count": 122, + "execution_count": 94, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:32.039925Z", - "iopub.status.busy": "2023-12-05T23:04:32.039677Z", - "iopub.status.idle": "2023-12-05T23:04:32.076974Z", - "shell.execute_reply": "2023-12-05T23:04:32.076094Z", - "shell.execute_reply.started": "2023-12-05T23:04:32.039910Z" + "iopub.execute_input": "2024-02-13T00:34:23.867155Z", + "iopub.status.busy": "2024-02-13T00:34:23.866863Z", + "iopub.status.idle": "2024-02-13T00:34:23.898939Z", + "shell.execute_reply": "2024-02-13T00:34:23.898250Z", + "shell.execute_reply.started": "2024-02-13T00:34:23.867142Z" }, "lines_to_next_cell": 2 }, @@ -6167,14 +5267,14 @@ }, { "cell_type": "code", - "execution_count": 123, + "execution_count": 95, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:32.078663Z", - "iopub.status.busy": "2023-12-05T23:04:32.078408Z", - "iopub.status.idle": "2023-12-05T23:04:32.114978Z", - "shell.execute_reply": "2023-12-05T23:04:32.113987Z", - "shell.execute_reply.started": "2023-12-05T23:04:32.078648Z" + "iopub.execute_input": "2024-02-13T00:34:23.900003Z", + "iopub.status.busy": "2024-02-13T00:34:23.899699Z", + "iopub.status.idle": "2024-02-13T00:34:23.929243Z", + "shell.execute_reply": "2024-02-13T00:34:23.928724Z", + "shell.execute_reply.started": "2024-02-13T00:34:23.899988Z" }, "tags": [] }, @@ -6199,14 +5299,14 @@ }, { "cell_type": "code", - "execution_count": 124, + "execution_count": 96, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:32.116230Z", - "iopub.status.busy": "2023-12-05T23:04:32.115999Z", - "iopub.status.idle": "2023-12-05T23:04:32.154815Z", - "shell.execute_reply": "2023-12-05T23:04:32.154082Z", - "shell.execute_reply.started": "2023-12-05T23:04:32.116216Z" + "iopub.execute_input": "2024-02-13T00:34:23.930178Z", + "iopub.status.busy": "2024-02-13T00:34:23.929918Z", + "iopub.status.idle": "2024-02-13T00:34:23.963468Z", + "shell.execute_reply": "2024-02-13T00:34:23.962836Z", + "shell.execute_reply.started": "2024-02-13T00:34:23.930166Z" }, "tags": [] }, @@ -6255,14 +5355,14 @@ }, { "cell_type": "code", - "execution_count": 125, + "execution_count": 97, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:32.156121Z", - "iopub.status.busy": "2023-12-05T23:04:32.155766Z", - "iopub.status.idle": "2023-12-05T23:04:32.195498Z", - "shell.execute_reply": "2023-12-05T23:04:32.194602Z", - "shell.execute_reply.started": "2023-12-05T23:04:32.156105Z" + "iopub.execute_input": "2024-02-13T00:34:23.964807Z", + "iopub.status.busy": "2024-02-13T00:34:23.964259Z", + "iopub.status.idle": "2024-02-13T00:34:24.000179Z", + "shell.execute_reply": "2024-02-13T00:34:23.999538Z", + "shell.execute_reply.started": "2024-02-13T00:34:23.964792Z" }, "lines_to_next_cell": 2, "tags": [] @@ -6329,14 +5429,14 @@ }, { "cell_type": "code", - "execution_count": 126, + "execution_count": 98, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:32.196910Z", - "iopub.status.busy": "2023-12-05T23:04:32.196675Z", - "iopub.status.idle": "2023-12-05T23:04:32.232320Z", - "shell.execute_reply": "2023-12-05T23:04:32.231351Z", - "shell.execute_reply.started": "2023-12-05T23:04:32.196895Z" + "iopub.execute_input": "2024-02-13T00:34:24.001283Z", + "iopub.status.busy": "2024-02-13T00:34:24.001066Z", + "iopub.status.idle": "2024-02-13T00:34:24.033504Z", + "shell.execute_reply": "2024-02-13T00:34:24.032759Z", + "shell.execute_reply.started": "2024-02-13T00:34:24.001267Z" }, "lines_to_next_cell": 2 }, @@ -6358,14 +5458,14 @@ }, { "cell_type": "code", - "execution_count": 127, + "execution_count": 99, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:32.233743Z", - "iopub.status.busy": "2023-12-05T23:04:32.233369Z", - "iopub.status.idle": "2023-12-05T23:04:37.122384Z", - "shell.execute_reply": "2023-12-05T23:04:37.121658Z", - "shell.execute_reply.started": "2023-12-05T23:04:32.233724Z" + "iopub.execute_input": "2024-02-13T00:34:24.034629Z", + "iopub.status.busy": "2024-02-13T00:34:24.034242Z", + "iopub.status.idle": "2024-02-13T00:34:28.848332Z", + "shell.execute_reply": "2024-02-13T00:34:28.847620Z", + "shell.execute_reply.started": "2024-02-13T00:34:24.034614Z" }, "lines_to_next_cell": 2, "tags": [] @@ -6378,18 +5478,18 @@ "# ** (2000, 4000, 3) -> (100, 200) trapezoid float32:\n", "# resize_serial : 0.004 s\n", "# resize_in_numpy : 0.004 s\n", - "# resize_in_tensorflow: 0.068 s\n", + "# resize_in_tensorflow: 0.065 s\n", "# resize_in_torch : 0.008 s\n", - "# resize_in_jax : 0.066 s\n", + "# resize_in_jax : 0.065 s\n", "# jaxjit_resize : 0.023 s\n", - "# tf_image_resize : 0.075 s\n", - "# reshape_mean : 0.113 s\n", - "# reshape2 : 0.104 s\n", - "# reshape3 : 0.115 s\n", - "# einsum : 0.045 s\n", - "# two_dots : 0.047 s\n", - "# reshape4 : 0.052 s\n", - "# reshape5 : 0.030 s\n", + "# tf_image_resize : 0.067 s\n", + "# reshape_mean : 0.112 s\n", + "# reshape2 : 0.109 s\n", + "# reshape3 : 0.113 s\n", + "# einsum : 0.041 s\n", + "# two_dots : 0.041 s\n", + "# reshape4 : 0.037 s\n", + "# reshape5 : 0.029 s\n", "# reduceat : 0.017 s\n" ] } @@ -6513,14 +5613,14 @@ }, { "cell_type": "code", - "execution_count": 128, + "execution_count": 100, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:37.123418Z", - "iopub.status.busy": "2023-12-05T23:04:37.123204Z", - "iopub.status.idle": "2023-12-05T23:04:37.154860Z", - "shell.execute_reply": "2023-12-05T23:04:37.154056Z", - "shell.execute_reply.started": "2023-12-05T23:04:37.123402Z" + "iopub.execute_input": "2024-02-13T00:34:28.849652Z", + "iopub.status.busy": "2024-02-13T00:34:28.849234Z", + "iopub.status.idle": "2024-02-13T00:34:28.881986Z", + "shell.execute_reply": "2024-02-13T00:34:28.881266Z", + "shell.execute_reply.started": "2024-02-13T00:34:28.849633Z" } }, "outputs": [], @@ -6564,14 +5664,14 @@ }, { "cell_type": "code", - "execution_count": 129, + "execution_count": 101, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:37.156044Z", - "iopub.status.busy": "2023-12-05T23:04:37.155740Z", - "iopub.status.idle": "2023-12-05T23:04:37.193024Z", - "shell.execute_reply": "2023-12-05T23:04:37.192383Z", - "shell.execute_reply.started": "2023-12-05T23:04:37.156030Z" + "iopub.execute_input": "2024-02-13T00:34:28.882948Z", + "iopub.status.busy": "2024-02-13T00:34:28.882778Z", + "iopub.status.idle": "2024-02-13T00:34:28.919276Z", + "shell.execute_reply": "2024-02-13T00:34:28.918654Z", + "shell.execute_reply.started": "2024-02-13T00:34:28.882933Z" }, "tags": [] }, @@ -6613,14 +5713,14 @@ }, { "cell_type": "code", - "execution_count": 130, + "execution_count": 102, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:37.194008Z", - "iopub.status.busy": "2023-12-05T23:04:37.193795Z", - "iopub.status.idle": "2023-12-05T23:04:40.918987Z", - "shell.execute_reply": "2023-12-05T23:04:40.918357Z", - "shell.execute_reply.started": "2023-12-05T23:04:37.193994Z" + "iopub.execute_input": "2024-02-13T00:34:28.920359Z", + "iopub.status.busy": "2024-02-13T00:34:28.920048Z", + "iopub.status.idle": "2024-02-13T00:34:33.386016Z", + "shell.execute_reply": "2024-02-13T00:34:33.385360Z", + "shell.execute_reply.started": "2024-02-13T00:34:28.920343Z" }, "tags": [] }, @@ -6630,34 +5730,34 @@ "output_type": "stream", "text": [ "# ** (1024, 1024, 1) -> (2048, 2048) lanczos3 float32:\n", - "# resize_in_numpy : 0.014 s\n", + "# resize_in_numpy : 0.013 s\n", "# Prun: tottime 0.016 overall_cumtime\n", - "# 0.010 0.010 numpy.ascontiguousarray (built-in)\n", - "# 0.002 0.002 _numba_parallel_csr_dense_mult (/mnt/c/Users/hhoppe/Dropbox/proj/resampler/resampler/__init__.py:273)\n", + "# 0.011 0.011 numpy.ascontiguousarray (built-in)\n", + "# 0.002 0.002 _numba_parallel_csr_dense_mult (/mnt/c/Users/hhoppe/Dropbox/proj/resampler/resampler/__init__.py:283)\n", "# resize_in_tensorflow: 0.012 s\n", - "# Prun: tottime 0.026 overall_cumtime\n", - "# 0.014 0.014 numpy.ndarray.copy\n", + "# Prun: tottime 0.014 overall_cumtime\n", "# 0.005 0.005 tensorflow.python._pywrap_tfe.TFE_Py_FastPathExecute (built-in)\n", - "# resize_in_torch : 0.011 s\n", - "# Prun: tottime 0.013 overall_cumtime\n", - "# 0.007 0.007 premult_with_sparse (/mnt/c/Users/hhoppe/Dropbox/proj/resampler/resampler/__init__.py:662)\n", - "# 0.002 0.002 torch._C._TensorBase.contiguous\n", - "# resize_in_jax : 0.040 s\n", - "# Prun: tottime 0.045 overall_cumtime\n", - "# 0.034 0.034 (jax/_src/dispatch.py:172)\n", - "# 0.000 0.001 issubdtype (jax/_src/dtypes.py:328)\n", - "# jaxjit_resize : 0.056 s\n", - "# Prun: tottime 0.057 overall_cumtime\n", - "# 0.057 0.057 jaxjit_resize (/mnt/c/Users/hhoppe/Dropbox/proj/resampler/resampler/__init__.py:2873)\n", - "# 0.000 0.057 (/tmp/ipykernel:14)\n", + "# 0.002 0.002 tensorflow.python._pywrap_tfe.TFE_Py_Execute (built-in)\n", + "# resize_in_torch : 0.010 s\n", + "# Prun: tottime 0.015 overall_cumtime\n", + "# 0.010 0.010 premult_with_sparse (/mnt/c/Users/hhoppe/Dropbox/proj/resampler/resampler/__init__.py:672)\n", + "# 0.002 0.002 torch._C.TensorBase.contiguous\n", + "# resize_in_jax : 0.042 s\n", + "# Prun: tottime 0.046 overall_cumtime\n", + "# 0.035 0.035 apply_primitive (jax/_src/dispatch.py:79)\n", + "# 0.000 0.001 issubdtype (jax/_src/dtypes.py:322)\n", + "# jaxjit_resize : 0.060 s\n", + "# Prun: tottime 0.061 overall_cumtime\n", + "# 0.061 0.061 jaxjit_resize (/mnt/c/Users/hhoppe/Dropbox/proj/resampler/resampler/__init__.py:2892)\n", + "# 0.000 0.061 (/tmp/ipykernel:14)\n", "# tf_image_resize : 0.052 s\n", - "# Prun: tottime 0.063 overall_cumtime\n", - "# 0.061 0.061 tensorflow.python._pywrap_tfe.TFE_Py_FastPathExecute (built-in)\n", + "# Prun: tottime 0.053 overall_cumtime\n", + "# 0.051 0.051 tensorflow.python._pywrap_tfe.TFE_Py_FastPathExecute (built-in)\n", "# 0.001 0.001 convert_to_eager_tensor (tensorflow/python/framework/constant_op.py:70)\n", "# cv_resize : 0.001 s\n", "# Prun: tottime 0.002 overall_cumtime\n", "# 0.002 0.002 resize\n", - "# 0.000 0.002 cv_resize (/mnt/c/Users/hhoppe/Dropbox/proj/resampler/resampler/__init__.py:3529)\n" + "# 0.000 0.002 cv_resize (/mnt/c/Users/hhoppe/Dropbox/proj/resampler/resampler/__init__.py:3548)\n" ] } ], @@ -6668,14 +5768,14 @@ }, { "cell_type": "code", - "execution_count": 131, + "execution_count": 103, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:40.920090Z", - "iopub.status.busy": "2023-12-05T23:04:40.919790Z", - "iopub.status.idle": "2023-12-05T23:04:40.950390Z", - "shell.execute_reply": "2023-12-05T23:04:40.949702Z", - "shell.execute_reply.started": "2023-12-05T23:04:40.920076Z" + "iopub.execute_input": "2024-02-13T00:34:33.387397Z", + "iopub.status.busy": "2024-02-13T00:34:33.386862Z", + "iopub.status.idle": "2024-02-13T00:34:33.419126Z", + "shell.execute_reply": "2024-02-13T00:34:33.418417Z", + "shell.execute_reply.started": "2024-02-13T00:34:33.387383Z" }, "tags": [] }, @@ -6704,14 +5804,14 @@ }, { "cell_type": "code", - "execution_count": 132, + "execution_count": 104, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:40.951837Z", - "iopub.status.busy": "2023-12-05T23:04:40.951500Z", - "iopub.status.idle": "2023-12-05T23:04:40.985961Z", - "shell.execute_reply": "2023-12-05T23:04:40.985288Z", - "shell.execute_reply.started": "2023-12-05T23:04:40.951821Z" + "iopub.execute_input": "2024-02-13T00:34:33.420164Z", + "iopub.status.busy": "2024-02-13T00:34:33.419866Z", + "iopub.status.idle": "2024-02-13T00:34:33.452476Z", + "shell.execute_reply": "2024-02-13T00:34:33.451865Z", + "shell.execute_reply.started": "2024-02-13T00:34:33.420150Z" } }, "outputs": [], @@ -6754,14 +5854,14 @@ }, { "cell_type": "code", - "execution_count": 133, + "execution_count": 105, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:40.987242Z", - "iopub.status.busy": "2023-12-05T23:04:40.986866Z", - "iopub.status.idle": "2023-12-05T23:04:41.086260Z", - "shell.execute_reply": "2023-12-05T23:04:41.085433Z", - "shell.execute_reply.started": "2023-12-05T23:04:40.987224Z" + "iopub.execute_input": "2024-02-13T00:34:33.453568Z", + "iopub.status.busy": "2024-02-13T00:34:33.453179Z", + "iopub.status.idle": "2024-02-13T00:34:33.540127Z", + "shell.execute_reply": "2024-02-13T00:34:33.539441Z", + "shell.execute_reply.started": "2024-02-13T00:34:33.453553Z" }, "lines_to_next_cell": 2, "tags": [] @@ -6851,14 +5951,14 @@ }, { "cell_type": "code", - "execution_count": 134, + "execution_count": 106, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:41.087625Z", - "iopub.status.busy": "2023-12-05T23:04:41.087142Z", - "iopub.status.idle": "2023-12-05T23:04:41.287610Z", - "shell.execute_reply": "2023-12-05T23:04:41.286999Z", - "shell.execute_reply.started": "2023-12-05T23:04:41.087594Z" + "iopub.execute_input": "2024-02-13T00:34:33.541380Z", + "iopub.status.busy": "2024-02-13T00:34:33.540980Z", + "iopub.status.idle": "2024-02-13T00:34:33.690401Z", + "shell.execute_reply": "2024-02-13T00:34:33.689804Z", + "shell.execute_reply.started": "2024-02-13T00:34:33.541361Z" } }, "outputs": [ @@ -6931,14 +6031,14 @@ }, { "cell_type": "code", - "execution_count": 135, + "execution_count": 107, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:41.288916Z", - "iopub.status.busy": "2023-12-05T23:04:41.288350Z", - "iopub.status.idle": "2023-12-05T23:04:41.319613Z", - "shell.execute_reply": "2023-12-05T23:04:41.318861Z", - "shell.execute_reply.started": "2023-12-05T23:04:41.288900Z" + "iopub.execute_input": "2024-02-13T00:34:33.691466Z", + "iopub.status.busy": "2024-02-13T00:34:33.691179Z", + "iopub.status.idle": "2024-02-13T00:34:33.722883Z", + "shell.execute_reply": "2024-02-13T00:34:33.722265Z", + "shell.execute_reply.started": "2024-02-13T00:34:33.691451Z" } }, "outputs": [], @@ -6958,14 +6058,14 @@ }, { "cell_type": "code", - "execution_count": 136, + "execution_count": 108, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:41.321045Z", - "iopub.status.busy": "2023-12-05T23:04:41.320716Z", - "iopub.status.idle": "2023-12-05T23:04:41.355604Z", - "shell.execute_reply": "2023-12-05T23:04:41.354839Z", - "shell.execute_reply.started": "2023-12-05T23:04:41.321029Z" + "iopub.execute_input": "2024-02-13T00:34:33.723918Z", + "iopub.status.busy": "2024-02-13T00:34:33.723572Z", + "iopub.status.idle": "2024-02-13T00:34:33.755189Z", + "shell.execute_reply": "2024-02-13T00:34:33.754588Z", + "shell.execute_reply.started": "2024-02-13T00:34:33.723905Z" } }, "outputs": [], @@ -6980,14 +6080,14 @@ }, { "cell_type": "code", - "execution_count": 137, + "execution_count": 109, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:41.356802Z", - "iopub.status.busy": "2023-12-05T23:04:41.356593Z", - "iopub.status.idle": "2023-12-05T23:04:41.882172Z", - "shell.execute_reply": "2023-12-05T23:04:41.881578Z", - "shell.execute_reply.started": "2023-12-05T23:04:41.356787Z" + "iopub.execute_input": "2024-02-13T00:34:33.756298Z", + "iopub.status.busy": "2024-02-13T00:34:33.755934Z", + "iopub.status.idle": "2024-02-13T00:34:34.252010Z", + "shell.execute_reply": "2024-02-13T00:34:34.251351Z", + "shell.execute_reply.started": "2024-02-13T00:34:33.756285Z" }, "tags": [] }, @@ -7074,14 +6174,14 @@ }, { "cell_type": "code", - "execution_count": 138, + "execution_count": 110, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:41.883415Z", - "iopub.status.busy": "2023-12-05T23:04:41.883105Z", - "iopub.status.idle": "2023-12-05T23:04:42.658791Z", - "shell.execute_reply": "2023-12-05T23:04:42.658220Z", - "shell.execute_reply.started": "2023-12-05T23:04:41.883401Z" + "iopub.execute_input": "2024-02-13T00:34:34.253139Z", + "iopub.status.busy": "2024-02-13T00:34:34.252780Z", + "iopub.status.idle": "2024-02-13T00:34:35.006080Z", + "shell.execute_reply": "2024-02-13T00:34:35.005353Z", + "shell.execute_reply.started": "2024-02-13T00:34:34.253125Z" }, "tags": [] }, @@ -7122,14 +6222,14 @@ }, { "cell_type": "code", - "execution_count": 139, + "execution_count": 111, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:42.659693Z", - "iopub.status.busy": "2023-12-05T23:04:42.659420Z", - "iopub.status.idle": "2023-12-05T23:04:43.256396Z", - "shell.execute_reply": "2023-12-05T23:04:43.255691Z", - "shell.execute_reply.started": "2023-12-05T23:04:42.659680Z" + "iopub.execute_input": "2024-02-13T00:34:35.007671Z", + "iopub.status.busy": "2024-02-13T00:34:35.007077Z", + "iopub.status.idle": "2024-02-13T00:34:35.581369Z", + "shell.execute_reply": "2024-02-13T00:34:35.580544Z", + "shell.execute_reply.started": "2024-02-13T00:34:35.007646Z" }, "tags": [] }, @@ -7201,14 +6301,14 @@ }, { "cell_type": "code", - "execution_count": 140, + "execution_count": 112, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:43.257626Z", - "iopub.status.busy": "2023-12-05T23:04:43.257229Z", - "iopub.status.idle": "2023-12-05T23:04:43.353733Z", - "shell.execute_reply": "2023-12-05T23:04:43.353063Z", - "shell.execute_reply.started": "2023-12-05T23:04:43.257611Z" + "iopub.execute_input": "2024-02-13T00:34:35.582662Z", + "iopub.status.busy": "2024-02-13T00:34:35.582270Z", + "iopub.status.idle": "2024-02-13T00:34:35.671340Z", + "shell.execute_reply": "2024-02-13T00:34:35.670697Z", + "shell.execute_reply.started": "2024-02-13T00:34:35.582646Z" }, "lines_to_next_cell": 2, "tags": [] @@ -7272,14 +6372,14 @@ }, { "cell_type": "code", - "execution_count": 141, + "execution_count": 113, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:43.355090Z", - "iopub.status.busy": "2023-12-05T23:04:43.354637Z", - "iopub.status.idle": "2023-12-05T23:04:47.173611Z", - "shell.execute_reply": "2023-12-05T23:04:47.172925Z", - "shell.execute_reply.started": "2023-12-05T23:04:43.355072Z" + "iopub.execute_input": "2024-02-13T00:34:35.672319Z", + "iopub.status.busy": "2024-02-13T00:34:35.672113Z", + "iopub.status.idle": "2024-02-13T00:34:39.528007Z", + "shell.execute_reply": "2024-02-13T00:34:39.527367Z", + "shell.execute_reply.started": "2024-02-13T00:34:35.672306Z" }, "lines_to_next_cell": 2, "tags": [] @@ -7374,14 +6474,14 @@ }, { "cell_type": "code", - "execution_count": 142, + "execution_count": 114, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:47.174582Z", - "iopub.status.busy": "2023-12-05T23:04:47.174375Z", - "iopub.status.idle": "2023-12-05T23:04:48.773710Z", - "shell.execute_reply": "2023-12-05T23:04:48.773095Z", - "shell.execute_reply.started": "2023-12-05T23:04:47.174569Z" + "iopub.execute_input": "2024-02-13T00:34:39.529293Z", + "iopub.status.busy": "2024-02-13T00:34:39.528891Z", + "iopub.status.idle": "2024-02-13T00:34:41.151855Z", + "shell.execute_reply": "2024-02-13T00:34:41.151120Z", + "shell.execute_reply.started": "2024-02-13T00:34:39.529276Z" }, "lines_to_next_cell": 2, "tags": [] @@ -7475,14 +6575,14 @@ }, { "cell_type": "code", - "execution_count": 143, + "execution_count": 115, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:48.774934Z", - "iopub.status.busy": "2023-12-05T23:04:48.774560Z", - "iopub.status.idle": "2023-12-05T23:04:48.809253Z", - "shell.execute_reply": "2023-12-05T23:04:48.808319Z", - "shell.execute_reply.started": "2023-12-05T23:04:48.774918Z" + "iopub.execute_input": "2024-02-13T00:34:41.153125Z", + "iopub.status.busy": "2024-02-13T00:34:41.152764Z", + "iopub.status.idle": "2024-02-13T00:34:41.185896Z", + "shell.execute_reply": "2024-02-13T00:34:41.185162Z", + "shell.execute_reply.started": "2024-02-13T00:34:41.153109Z" }, "lines_to_next_cell": 2 }, @@ -7575,14 +6675,14 @@ }, { "cell_type": "code", - "execution_count": 144, + "execution_count": 116, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:48.810410Z", - "iopub.status.busy": "2023-12-05T23:04:48.810089Z", - "iopub.status.idle": "2023-12-05T23:04:52.896070Z", - "shell.execute_reply": "2023-12-05T23:04:52.895386Z", - "shell.execute_reply.started": "2023-12-05T23:04:48.810396Z" + "iopub.execute_input": "2024-02-13T00:34:41.187172Z", + "iopub.status.busy": "2024-02-13T00:34:41.186770Z", + "iopub.status.idle": "2024-02-13T00:34:44.486159Z", + "shell.execute_reply": "2024-02-13T00:34:44.485477Z", + "shell.execute_reply.started": "2024-02-13T00:34:41.187154Z" } }, "outputs": [ @@ -7721,14 +6821,14 @@ }, { "cell_type": "code", - "execution_count": 145, + "execution_count": 117, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:52.897174Z", - "iopub.status.busy": "2023-12-05T23:04:52.896852Z", - "iopub.status.idle": "2023-12-05T23:04:55.130681Z", - "shell.execute_reply": "2023-12-05T23:04:55.130039Z", - "shell.execute_reply.started": "2023-12-05T23:04:52.897161Z" + "iopub.execute_input": "2024-02-13T00:34:44.487307Z", + "iopub.status.busy": "2024-02-13T00:34:44.486984Z", + "iopub.status.idle": "2024-02-13T00:34:46.677460Z", + "shell.execute_reply": "2024-02-13T00:34:46.676851Z", + "shell.execute_reply.started": "2024-02-13T00:34:44.487290Z" }, "lines_to_next_cell": 2, "tags": [] @@ -7853,14 +6953,14 @@ }, { "cell_type": "code", - "execution_count": 146, + "execution_count": 118, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:55.131967Z", - "iopub.status.busy": "2023-12-05T23:04:55.131501Z", - "iopub.status.idle": "2023-12-05T23:04:56.093639Z", - "shell.execute_reply": "2023-12-05T23:04:56.092962Z", - "shell.execute_reply.started": "2023-12-05T23:04:55.131952Z" + "iopub.execute_input": "2024-02-13T00:34:46.678393Z", + "iopub.status.busy": "2024-02-13T00:34:46.678227Z", + "iopub.status.idle": "2024-02-13T00:34:47.530769Z", + "shell.execute_reply": "2024-02-13T00:34:47.529938Z", + "shell.execute_reply.started": "2024-02-13T00:34:46.678380Z" }, "tags": [] }, @@ -7950,14 +7050,14 @@ }, { "cell_type": "code", - "execution_count": 147, + "execution_count": 119, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:56.094766Z", - "iopub.status.busy": "2023-12-05T23:04:56.094430Z", - "iopub.status.idle": "2023-12-05T23:04:56.592502Z", - "shell.execute_reply": "2023-12-05T23:04:56.591896Z", - "shell.execute_reply.started": "2023-12-05T23:04:56.094738Z" + "iopub.execute_input": "2024-02-13T00:34:47.531910Z", + "iopub.status.busy": "2024-02-13T00:34:47.531585Z", + "iopub.status.idle": "2024-02-13T00:34:48.050884Z", + "shell.execute_reply": "2024-02-13T00:34:48.050246Z", + "shell.execute_reply.started": "2024-02-13T00:34:47.531894Z" }, "lines_to_next_cell": 2, "tags": [] @@ -7993,14 +7093,14 @@ }, { "cell_type": "code", - "execution_count": 148, + "execution_count": 120, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:56.593514Z", - "iopub.status.busy": "2023-12-05T23:04:56.593223Z", - "iopub.status.idle": "2023-12-05T23:04:58.738229Z", - "shell.execute_reply": "2023-12-05T23:04:58.737660Z", - "shell.execute_reply.started": "2023-12-05T23:04:56.593500Z" + "iopub.execute_input": "2024-02-13T00:34:48.052259Z", + "iopub.status.busy": "2024-02-13T00:34:48.051673Z", + "iopub.status.idle": "2024-02-13T00:34:50.089601Z", + "shell.execute_reply": "2024-02-13T00:34:50.088899Z", + "shell.execute_reply.started": "2024-02-13T00:34:48.052243Z" }, "tags": [] }, @@ -8098,14 +7198,14 @@ }, { "cell_type": "code", - "execution_count": 149, + "execution_count": 121, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:58.739281Z", - "iopub.status.busy": "2023-12-05T23:04:58.738954Z", - "iopub.status.idle": "2023-12-05T23:04:58.774452Z", - "shell.execute_reply": "2023-12-05T23:04:58.773742Z", - "shell.execute_reply.started": "2023-12-05T23:04:58.739264Z" + "iopub.execute_input": "2024-02-13T00:34:50.090823Z", + "iopub.status.busy": "2024-02-13T00:34:50.090431Z", + "iopub.status.idle": "2024-02-13T00:34:50.125701Z", + "shell.execute_reply": "2024-02-13T00:34:50.125079Z", + "shell.execute_reply.started": "2024-02-13T00:34:50.090798Z" }, "tags": [] }, @@ -8134,14 +7234,14 @@ }, { "cell_type": "code", - "execution_count": 150, + "execution_count": 122, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:04:58.775724Z", - "iopub.status.busy": "2023-12-05T23:04:58.775381Z", - "iopub.status.idle": "2023-12-05T23:05:00.411923Z", - "shell.execute_reply": "2023-12-05T23:05:00.411260Z", - "shell.execute_reply.started": "2023-12-05T23:04:58.775708Z" + "iopub.execute_input": "2024-02-13T00:34:50.126754Z", + "iopub.status.busy": "2024-02-13T00:34:50.126406Z", + "iopub.status.idle": "2024-02-13T00:34:51.725641Z", + "shell.execute_reply": "2024-02-13T00:34:51.724968Z", + "shell.execute_reply.started": "2024-02-13T00:34:50.126738Z" }, "tags": [] }, @@ -8150,15 +7250,15 @@ "name": "stdout", "output_type": "stream", "text": [ - "233 ms\n", - "92.4 ms\n", - "92.8 ms\n", - "706 ms\n", - "71.6 ms\n", - "70.6 ms\n", - "95.5 ms\n", - "96.7 ms\n", - "94.4 ms\n" + "229 ms\n", + "92.6 ms\n", + "92.1 ms\n", + "678 ms\n", + "75.9 ms\n", + "70.8 ms\n", + "93.7 ms\n", + "93.0 ms\n", + "94.6 ms\n" ] } ], @@ -8182,14 +7282,14 @@ }, { "cell_type": "code", - "execution_count": 151, + "execution_count": 123, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:00.413095Z", - "iopub.status.busy": "2023-12-05T23:05:00.412726Z", - "iopub.status.idle": "2023-12-05T23:05:00.730370Z", - "shell.execute_reply": "2023-12-05T23:05:00.729750Z", - "shell.execute_reply.started": "2023-12-05T23:05:00.413078Z" + "iopub.execute_input": "2024-02-13T00:34:51.726937Z", + "iopub.status.busy": "2024-02-13T00:34:51.726471Z", + "iopub.status.idle": "2024-02-13T00:34:52.044703Z", + "shell.execute_reply": "2024-02-13T00:34:52.044037Z", + "shell.execute_reply.started": "2024-02-13T00:34:51.726920Z" }, "tags": [] }, @@ -8219,14 +7319,14 @@ }, { "cell_type": "code", - "execution_count": 152, + "execution_count": 124, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:00.731367Z", - "iopub.status.busy": "2023-12-05T23:05:00.731134Z", - "iopub.status.idle": "2023-12-05T23:05:00.781841Z", - "shell.execute_reply": "2023-12-05T23:05:00.780634Z", - "shell.execute_reply.started": "2023-12-05T23:05:00.731350Z" + "iopub.execute_input": "2024-02-13T00:34:52.045797Z", + "iopub.status.busy": "2024-02-13T00:34:52.045434Z", + "iopub.status.idle": "2024-02-13T00:34:52.079274Z", + "shell.execute_reply": "2024-02-13T00:34:52.078677Z", + "shell.execute_reply.started": "2024-02-13T00:34:52.045782Z" }, "lines_to_next_cell": 2, "tags": [] @@ -8257,14 +7357,14 @@ }, { "cell_type": "code", - "execution_count": 153, + "execution_count": 125, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:00.784356Z", - "iopub.status.busy": "2023-12-05T23:05:00.783396Z", - "iopub.status.idle": "2023-12-05T23:05:00.835984Z", - "shell.execute_reply": "2023-12-05T23:05:00.835075Z", - "shell.execute_reply.started": "2023-12-05T23:05:00.784330Z" + "iopub.execute_input": "2024-02-13T00:34:52.080164Z", + "iopub.status.busy": "2024-02-13T00:34:52.079939Z", + "iopub.status.idle": "2024-02-13T00:34:52.113475Z", + "shell.execute_reply": "2024-02-13T00:34:52.112865Z", + "shell.execute_reply.started": "2024-02-13T00:34:52.080151Z" }, "tags": [] }, @@ -8293,14 +7393,14 @@ }, { "cell_type": "code", - "execution_count": 154, + "execution_count": 126, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:00.837647Z", - "iopub.status.busy": "2023-12-05T23:05:00.837068Z", - "iopub.status.idle": "2023-12-05T23:05:01.818447Z", - "shell.execute_reply": "2023-12-05T23:05:01.817881Z", - "shell.execute_reply.started": "2023-12-05T23:05:00.837613Z" + "iopub.execute_input": "2024-02-13T00:34:52.114708Z", + "iopub.status.busy": "2024-02-13T00:34:52.114240Z", + "iopub.status.idle": "2024-02-13T00:34:53.149383Z", + "shell.execute_reply": "2024-02-13T00:34:53.148708Z", + "shell.execute_reply.started": "2024-02-13T00:34:52.114692Z" }, "lines_to_next_cell": 2, "tags": [] @@ -8429,14 +7529,14 @@ }, { "cell_type": "code", - "execution_count": 155, + "execution_count": 127, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:01.819743Z", - "iopub.status.busy": "2023-12-05T23:05:01.819210Z", - "iopub.status.idle": "2023-12-05T23:05:02.831807Z", - "shell.execute_reply": "2023-12-05T23:05:02.831179Z", - "shell.execute_reply.started": "2023-12-05T23:05:01.819724Z" + "iopub.execute_input": "2024-02-13T00:34:53.150734Z", + "iopub.status.busy": "2024-02-13T00:34:53.150215Z", + "iopub.status.idle": "2024-02-13T00:34:54.213042Z", + "shell.execute_reply": "2024-02-13T00:34:54.212398Z", + "shell.execute_reply.started": "2024-02-13T00:34:53.150717Z" }, "tags": [] }, @@ -8468,14 +7568,14 @@ }, { "cell_type": "code", - "execution_count": 156, + "execution_count": 128, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:02.833020Z", - "iopub.status.busy": "2023-12-05T23:05:02.832524Z", - "iopub.status.idle": "2023-12-05T23:05:02.868943Z", - "shell.execute_reply": "2023-12-05T23:05:02.868334Z", - "shell.execute_reply.started": "2023-12-05T23:05:02.833001Z" + "iopub.execute_input": "2024-02-13T00:34:54.214060Z", + "iopub.status.busy": "2024-02-13T00:34:54.213774Z", + "iopub.status.idle": "2024-02-13T00:34:54.248614Z", + "shell.execute_reply": "2024-02-13T00:34:54.247957Z", + "shell.execute_reply.started": "2024-02-13T00:34:54.214046Z" }, "tags": [] }, @@ -8578,14 +7678,14 @@ }, { "cell_type": "code", - "execution_count": 157, + "execution_count": 129, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:02.870469Z", - "iopub.status.busy": "2023-12-05T23:05:02.869727Z", - "iopub.status.idle": "2023-12-05T23:05:02.910903Z", - "shell.execute_reply": "2023-12-05T23:05:02.910241Z", - "shell.execute_reply.started": "2023-12-05T23:05:02.870425Z" + "iopub.execute_input": "2024-02-13T00:34:54.249720Z", + "iopub.status.busy": "2024-02-13T00:34:54.249395Z", + "iopub.status.idle": "2024-02-13T00:34:54.289603Z", + "shell.execute_reply": "2024-02-13T00:34:54.289009Z", + "shell.execute_reply.started": "2024-02-13T00:34:54.249705Z" }, "tags": [] }, @@ -8678,14 +7778,14 @@ }, { "cell_type": "code", - "execution_count": 158, + "execution_count": 130, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:02.911901Z", - "iopub.status.busy": "2023-12-05T23:05:02.911711Z", - "iopub.status.idle": "2023-12-05T23:05:02.945886Z", - "shell.execute_reply": "2023-12-05T23:05:02.945089Z", - "shell.execute_reply.started": "2023-12-05T23:05:02.911886Z" + "iopub.execute_input": "2024-02-13T00:34:54.290697Z", + "iopub.status.busy": "2024-02-13T00:34:54.290220Z", + "iopub.status.idle": "2024-02-13T00:34:54.323856Z", + "shell.execute_reply": "2024-02-13T00:34:54.323235Z", + "shell.execute_reply.started": "2024-02-13T00:34:54.290681Z" }, "tags": [] }, @@ -8704,14 +7804,14 @@ }, { "cell_type": "code", - "execution_count": 159, + "execution_count": 131, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:02.947349Z", - "iopub.status.busy": "2023-12-05T23:05:02.946840Z", - "iopub.status.idle": "2023-12-05T23:05:06.827172Z", - "shell.execute_reply": "2023-12-05T23:05:06.826492Z", - "shell.execute_reply.started": "2023-12-05T23:05:02.947329Z" + "iopub.execute_input": "2024-02-13T00:34:54.324768Z", + "iopub.status.busy": "2024-02-13T00:34:54.324530Z", + "iopub.status.idle": "2024-02-13T00:34:58.009039Z", + "shell.execute_reply": "2024-02-13T00:34:58.008413Z", + "shell.execute_reply.started": "2024-02-13T00:34:54.324754Z" }, "lines_to_next_cell": 2, "tags": [] @@ -8777,14 +7877,14 @@ }, { "cell_type": "code", - "execution_count": 160, + "execution_count": 132, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:06.828492Z", - "iopub.status.busy": "2023-12-05T23:05:06.827993Z", - "iopub.status.idle": "2023-12-05T23:05:06.868052Z", - "shell.execute_reply": "2023-12-05T23:05:06.866914Z", - "shell.execute_reply.started": "2023-12-05T23:05:06.828473Z" + "iopub.execute_input": "2024-02-13T00:34:58.010419Z", + "iopub.status.busy": "2024-02-13T00:34:58.009847Z", + "iopub.status.idle": "2024-02-13T00:34:58.049310Z", + "shell.execute_reply": "2024-02-13T00:34:58.048638Z", + "shell.execute_reply.started": "2024-02-13T00:34:58.010364Z" } }, "outputs": [], @@ -8853,14 +7953,14 @@ }, { "cell_type": "code", - "execution_count": 161, + "execution_count": 133, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:06.869534Z", - "iopub.status.busy": "2023-12-05T23:05:06.868985Z", - "iopub.status.idle": "2023-12-05T23:05:09.141726Z", - "shell.execute_reply": "2023-12-05T23:05:09.141071Z", - "shell.execute_reply.started": "2023-12-05T23:05:06.869493Z" + "iopub.execute_input": "2024-02-13T00:34:58.050587Z", + "iopub.status.busy": "2024-02-13T00:34:58.050247Z", + "iopub.status.idle": "2024-02-13T00:35:00.331201Z", + "shell.execute_reply": "2024-02-13T00:35:00.330447Z", + "shell.execute_reply.started": "2024-02-13T00:34:58.050572Z" }, "lines_to_next_cell": 2 }, @@ -8903,14 +8003,14 @@ }, { "cell_type": "code", - "execution_count": 162, + "execution_count": 134, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:09.143102Z", - "iopub.status.busy": "2023-12-05T23:05:09.142957Z", - "iopub.status.idle": "2023-12-05T23:05:09.175314Z", - "shell.execute_reply": "2023-12-05T23:05:09.174616Z", - "shell.execute_reply.started": "2023-12-05T23:05:09.143090Z" + "iopub.execute_input": "2024-02-13T00:35:00.332899Z", + "iopub.status.busy": "2024-02-13T00:35:00.332325Z", + "iopub.status.idle": "2024-02-13T00:35:00.365529Z", + "shell.execute_reply": "2024-02-13T00:35:00.364848Z", + "shell.execute_reply.started": "2024-02-13T00:35:00.332880Z" } }, "outputs": [], @@ -8933,14 +8033,14 @@ }, { "cell_type": "code", - "execution_count": 163, + "execution_count": 135, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:09.176290Z", - "iopub.status.busy": "2023-12-05T23:05:09.176120Z", - "iopub.status.idle": "2023-12-05T23:05:09.621909Z", - "shell.execute_reply": "2023-12-05T23:05:09.621192Z", - "shell.execute_reply.started": "2023-12-05T23:05:09.176276Z" + "iopub.execute_input": "2024-02-13T00:35:00.366910Z", + "iopub.status.busy": "2024-02-13T00:35:00.366303Z", + "iopub.status.idle": "2024-02-13T00:35:00.813320Z", + "shell.execute_reply": "2024-02-13T00:35:00.812664Z", + "shell.execute_reply.started": "2024-02-13T00:35:00.366886Z" }, "tags": [] }, @@ -8986,14 +8086,14 @@ }, { "cell_type": "code", - "execution_count": 164, + "execution_count": 136, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:09.623145Z", - "iopub.status.busy": "2023-12-05T23:05:09.622692Z", - "iopub.status.idle": "2023-12-05T23:05:11.213133Z", - "shell.execute_reply": "2023-12-05T23:05:11.212552Z", - "shell.execute_reply.started": "2023-12-05T23:05:09.623127Z" + "iopub.execute_input": "2024-02-13T00:35:00.814429Z", + "iopub.status.busy": "2024-02-13T00:35:00.814133Z", + "iopub.status.idle": "2024-02-13T00:35:02.449815Z", + "shell.execute_reply": "2024-02-13T00:35:02.449071Z", + "shell.execute_reply.started": "2024-02-13T00:35:00.814413Z" }, "tags": [] }, @@ -9051,14 +8151,14 @@ }, { "cell_type": "code", - "execution_count": 165, + "execution_count": 137, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:11.214368Z", - "iopub.status.busy": "2023-12-05T23:05:11.214011Z", - "iopub.status.idle": "2023-12-05T23:05:12.391939Z", - "shell.execute_reply": "2023-12-05T23:05:12.391264Z", - "shell.execute_reply.started": "2023-12-05T23:05:11.214352Z" + "iopub.execute_input": "2024-02-13T00:35:02.451014Z", + "iopub.status.busy": "2024-02-13T00:35:02.450575Z", + "iopub.status.idle": "2024-02-13T00:35:03.625540Z", + "shell.execute_reply": "2024-02-13T00:35:03.624801Z", + "shell.execute_reply.started": "2024-02-13T00:35:02.450997Z" }, "tags": [] }, @@ -9104,14 +8204,14 @@ }, { "cell_type": "code", - "execution_count": 166, + "execution_count": 138, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:12.393015Z", - "iopub.status.busy": "2023-12-05T23:05:12.392693Z", - "iopub.status.idle": "2023-12-05T23:05:12.430643Z", - "shell.execute_reply": "2023-12-05T23:05:12.429785Z", - "shell.execute_reply.started": "2023-12-05T23:05:12.392992Z" + "iopub.execute_input": "2024-02-13T00:35:03.626693Z", + "iopub.status.busy": "2024-02-13T00:35:03.626233Z", + "iopub.status.idle": "2024-02-13T00:35:03.662096Z", + "shell.execute_reply": "2024-02-13T00:35:03.661451Z", + "shell.execute_reply.started": "2024-02-13T00:35:03.626657Z" }, "tags": [] }, @@ -9155,14 +8255,14 @@ }, { "cell_type": "code", - "execution_count": 167, + "execution_count": 139, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:12.432168Z", - "iopub.status.busy": "2023-12-05T23:05:12.431749Z", - "iopub.status.idle": "2023-12-05T23:05:12.483437Z", - "shell.execute_reply": "2023-12-05T23:05:12.482789Z", - "shell.execute_reply.started": "2023-12-05T23:05:12.432146Z" + "iopub.execute_input": "2024-02-13T00:35:03.663062Z", + "iopub.status.busy": "2024-02-13T00:35:03.662786Z", + "iopub.status.idle": "2024-02-13T00:35:03.700742Z", + "shell.execute_reply": "2024-02-13T00:35:03.700046Z", + "shell.execute_reply.started": "2024-02-13T00:35:03.663048Z" }, "lines_to_next_cell": 2, "tags": [] @@ -9199,14 +8299,14 @@ }, { "cell_type": "code", - "execution_count": 169, + "execution_count": 140, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:12.522319Z", - "iopub.status.busy": "2023-12-05T23:05:12.522167Z", - "iopub.status.idle": "2023-12-05T23:05:12.566113Z", - "shell.execute_reply": "2023-12-05T23:05:12.565421Z", - "shell.execute_reply.started": "2023-12-05T23:05:12.522304Z" + "iopub.execute_input": "2024-02-13T00:35:03.701659Z", + "iopub.status.busy": "2024-02-13T00:35:03.701508Z", + "iopub.status.idle": "2024-02-13T00:35:03.743814Z", + "shell.execute_reply": "2024-02-13T00:35:03.743194Z", + "shell.execute_reply.started": "2024-02-13T00:35:03.701648Z" } }, "outputs": [], @@ -9286,7 +8386,7 @@ " and boundary in ['clamp', 'border']\n", " and filter not in ['box', 'triangle']\n", " ) or (resizer is resampler.scipy_ndimage_resize and boundary == 'border')\n", - " assert discrepancy == expected_discrepancy, (resizer, filter, boundary)\n", + " assert discrepancy == expected_discrepancy, (resizer, filter, boundary, discrepancy)\n", "\n", " plt.subplots_adjust(left=0.035)\n", " # text = f\"filter='{filter}'\" if row_index == 0 else f\"'{filter}'\"\n", @@ -9296,14 +8396,14 @@ }, { "cell_type": "code", - "execution_count": 170, + "execution_count": 141, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:12.567411Z", - "iopub.status.busy": "2023-12-05T23:05:12.566880Z", - "iopub.status.idle": "2023-12-05T23:05:14.554300Z", - "shell.execute_reply": "2023-12-05T23:05:14.553717Z", - "shell.execute_reply.started": "2023-12-05T23:05:12.567391Z" + "iopub.execute_input": "2024-02-13T00:35:03.744855Z", + "iopub.status.busy": "2024-02-13T00:35:03.744563Z", + "iopub.status.idle": "2024-02-13T00:35:05.724736Z", + "shell.execute_reply": "2024-02-13T00:35:05.723754Z", + "shell.execute_reply.started": "2024-02-13T00:35:03.744842Z" }, "tags": [] }, @@ -9516,14 +8616,14 @@ }, { "cell_type": "code", - "execution_count": 171, + "execution_count": 142, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:14.555812Z", - "iopub.status.busy": "2023-12-05T23:05:14.555319Z", - "iopub.status.idle": "2023-12-05T23:05:14.704054Z", - "shell.execute_reply": "2023-12-05T23:05:14.703434Z", - "shell.execute_reply.started": "2023-12-05T23:05:14.555793Z" + "iopub.execute_input": "2024-02-13T00:35:05.725930Z", + "iopub.status.busy": "2024-02-13T00:35:05.725726Z", + "iopub.status.idle": "2024-02-13T00:35:05.870319Z", + "shell.execute_reply": "2024-02-13T00:35:05.869589Z", + "shell.execute_reply.started": "2024-02-13T00:35:05.725914Z" }, "lines_to_next_cell": 2, "tags": [] @@ -9747,14 +8847,14 @@ }, { "cell_type": "code", - "execution_count": 172, + "execution_count": 143, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:14.704978Z", - "iopub.status.busy": "2023-12-05T23:05:14.704771Z", - "iopub.status.idle": "2023-12-05T23:05:17.260137Z", - "shell.execute_reply": "2023-12-05T23:05:17.259496Z", - "shell.execute_reply.started": "2023-12-05T23:05:14.704965Z" + "iopub.execute_input": "2024-02-13T00:35:05.871450Z", + "iopub.status.busy": "2024-02-13T00:35:05.871104Z", + "iopub.status.idle": "2024-02-13T00:35:08.181956Z", + "shell.execute_reply": "2024-02-13T00:35:08.181313Z", + "shell.execute_reply.started": "2024-02-13T00:35:05.871437Z" }, "lines_to_next_cell": 2, "tags": [] @@ -9927,14 +9027,14 @@ }, { "cell_type": "code", - "execution_count": 173, + "execution_count": 144, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:17.261285Z", - "iopub.status.busy": "2023-12-05T23:05:17.260986Z", - "iopub.status.idle": "2023-12-05T23:05:17.295792Z", - "shell.execute_reply": "2023-12-05T23:05:17.294963Z", - "shell.execute_reply.started": "2023-12-05T23:05:17.261265Z" + "iopub.execute_input": "2024-02-13T00:35:08.183141Z", + "iopub.status.busy": "2024-02-13T00:35:08.182776Z", + "iopub.status.idle": "2024-02-13T00:35:08.216898Z", + "shell.execute_reply": "2024-02-13T00:35:08.216217Z", + "shell.execute_reply.started": "2024-02-13T00:35:08.183125Z" } }, "outputs": [], @@ -10084,14 +9184,14 @@ }, { "cell_type": "code", - "execution_count": 174, + "execution_count": 145, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:17.296746Z", - "iopub.status.busy": "2023-12-05T23:05:17.296574Z", - "iopub.status.idle": "2023-12-05T23:05:18.587040Z", - "shell.execute_reply": "2023-12-05T23:05:18.586455Z", - "shell.execute_reply.started": "2023-12-05T23:05:17.296733Z" + "iopub.execute_input": "2024-02-13T00:35:08.217915Z", + "iopub.status.busy": "2024-02-13T00:35:08.217616Z", + "iopub.status.idle": "2024-02-13T00:35:09.433890Z", + "shell.execute_reply": "2024-02-13T00:35:09.433259Z", + "shell.execute_reply.started": "2024-02-13T00:35:08.217901Z" } }, "outputs": [ @@ -10240,14 +9340,14 @@ }, { "cell_type": "code", - "execution_count": 175, + "execution_count": 146, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:18.588057Z", - "iopub.status.busy": "2023-12-05T23:05:18.587789Z", - "iopub.status.idle": "2023-12-05T23:05:18.618390Z", - "shell.execute_reply": "2023-12-05T23:05:18.617739Z", - "shell.execute_reply.started": "2023-12-05T23:05:18.588043Z" + "iopub.execute_input": "2024-02-13T00:35:09.434842Z", + "iopub.status.busy": "2024-02-13T00:35:09.434636Z", + "iopub.status.idle": "2024-02-13T00:35:09.466860Z", + "shell.execute_reply": "2024-02-13T00:35:09.466152Z", + "shell.execute_reply.started": "2024-02-13T00:35:09.434830Z" }, "lines_to_next_cell": 2 }, @@ -10289,14 +9389,14 @@ }, { "cell_type": "code", - "execution_count": 176, + "execution_count": 147, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:18.619734Z", - "iopub.status.busy": "2023-12-05T23:05:18.619393Z", - "iopub.status.idle": "2023-12-05T23:05:19.571978Z", - "shell.execute_reply": "2023-12-05T23:05:19.571436Z", - "shell.execute_reply.started": "2023-12-05T23:05:18.619720Z" + "iopub.execute_input": "2024-02-13T00:35:09.468198Z", + "iopub.status.busy": "2024-02-13T00:35:09.467739Z", + "iopub.status.idle": "2024-02-13T00:35:11.126082Z", + "shell.execute_reply": "2024-02-13T00:35:11.125435Z", + "shell.execute_reply.started": "2024-02-13T00:35:09.468184Z" }, "lines_to_next_cell": 2, "tags": [] @@ -10436,14 +9536,14 @@ }, { "cell_type": "code", - "execution_count": 177, + "execution_count": 148, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:19.572776Z", - "iopub.status.busy": "2023-12-05T23:05:19.572639Z", - "iopub.status.idle": "2023-12-05T23:05:19.603054Z", - "shell.execute_reply": "2023-12-05T23:05:19.602434Z", - "shell.execute_reply.started": "2023-12-05T23:05:19.572764Z" + "iopub.execute_input": "2024-02-13T00:35:11.127441Z", + "iopub.status.busy": "2024-02-13T00:35:11.127110Z", + "iopub.status.idle": "2024-02-13T00:35:11.161671Z", + "shell.execute_reply": "2024-02-13T00:35:11.160945Z", + "shell.execute_reply.started": "2024-02-13T00:35:11.127427Z" } }, "outputs": [], @@ -10488,14 +9588,14 @@ }, { "cell_type": "code", - "execution_count": 178, + "execution_count": 149, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:19.604077Z", - "iopub.status.busy": "2023-12-05T23:05:19.603867Z", - "iopub.status.idle": "2023-12-05T23:05:19.754198Z", - "shell.execute_reply": "2023-12-05T23:05:19.753538Z", - "shell.execute_reply.started": "2023-12-05T23:05:19.604063Z" + "iopub.execute_input": "2024-02-13T00:35:11.162968Z", + "iopub.status.busy": "2024-02-13T00:35:11.162755Z", + "iopub.status.idle": "2024-02-13T00:35:11.315298Z", + "shell.execute_reply": "2024-02-13T00:35:11.314678Z", + "shell.execute_reply.started": "2024-02-13T00:35:11.162955Z" } }, "outputs": [ @@ -10605,14 +9705,14 @@ }, { "cell_type": "code", - "execution_count": 179, + "execution_count": 150, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:19.755335Z", - "iopub.status.busy": "2023-12-05T23:05:19.755027Z", - "iopub.status.idle": "2023-12-05T23:05:20.010848Z", - "shell.execute_reply": "2023-12-05T23:05:20.010216Z", - "shell.execute_reply.started": "2023-12-05T23:05:19.755320Z" + "iopub.execute_input": "2024-02-13T00:35:11.316402Z", + "iopub.status.busy": "2024-02-13T00:35:11.315999Z", + "iopub.status.idle": "2024-02-13T00:35:11.588875Z", + "shell.execute_reply": "2024-02-13T00:35:11.588141Z", + "shell.execute_reply.started": "2024-02-13T00:35:11.316386Z" }, "lines_to_next_cell": 2, "tags": [] @@ -10668,14 +9768,14 @@ }, { "cell_type": "code", - "execution_count": 180, + "execution_count": 151, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:20.011765Z", - "iopub.status.busy": "2023-12-05T23:05:20.011558Z", - "iopub.status.idle": "2023-12-05T23:05:20.046255Z", - "shell.execute_reply": "2023-12-05T23:05:20.045636Z", - "shell.execute_reply.started": "2023-12-05T23:05:20.011752Z" + "iopub.execute_input": "2024-02-13T00:35:11.589963Z", + "iopub.status.busy": "2024-02-13T00:35:11.589692Z", + "iopub.status.idle": "2024-02-13T00:35:11.627785Z", + "shell.execute_reply": "2024-02-13T00:35:11.627189Z", + "shell.execute_reply.started": "2024-02-13T00:35:11.589950Z" } }, "outputs": [ @@ -10711,14 +9811,14 @@ }, { "cell_type": "code", - "execution_count": 181, + "execution_count": 152, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:20.047271Z", - "iopub.status.busy": "2023-12-05T23:05:20.046987Z", - "iopub.status.idle": "2023-12-05T23:05:20.097629Z", - "shell.execute_reply": "2023-12-05T23:05:20.097022Z", - "shell.execute_reply.started": "2023-12-05T23:05:20.047256Z" + "iopub.execute_input": "2024-02-13T00:35:11.628770Z", + "iopub.status.busy": "2024-02-13T00:35:11.628482Z", + "iopub.status.idle": "2024-02-13T00:35:11.682613Z", + "shell.execute_reply": "2024-02-13T00:35:11.681948Z", + "shell.execute_reply.started": "2024-02-13T00:35:11.628756Z" }, "tags": [] }, @@ -10776,14 +9876,14 @@ }, { "cell_type": "code", - "execution_count": 182, + "execution_count": 153, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:20.098807Z", - "iopub.status.busy": "2023-12-05T23:05:20.098389Z", - "iopub.status.idle": "2023-12-05T23:05:20.411330Z", - "shell.execute_reply": "2023-12-05T23:05:20.410635Z", - "shell.execute_reply.started": "2023-12-05T23:05:20.098790Z" + "iopub.execute_input": "2024-02-13T00:35:11.684153Z", + "iopub.status.busy": "2024-02-13T00:35:11.683488Z", + "iopub.status.idle": "2024-02-13T00:35:11.964255Z", + "shell.execute_reply": "2024-02-13T00:35:11.963557Z", + "shell.execute_reply.started": "2024-02-13T00:35:11.684139Z" }, "tags": [] }, @@ -10876,14 +9976,14 @@ }, { "cell_type": "code", - "execution_count": 183, + "execution_count": 154, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:20.412449Z", - "iopub.status.busy": "2023-12-05T23:05:20.412125Z", - "iopub.status.idle": "2023-12-05T23:05:20.448571Z", - "shell.execute_reply": "2023-12-05T23:05:20.447828Z", - "shell.execute_reply.started": "2023-12-05T23:05:20.412431Z" + "iopub.execute_input": "2024-02-13T00:35:11.965522Z", + "iopub.status.busy": "2024-02-13T00:35:11.965104Z", + "iopub.status.idle": "2024-02-13T00:35:12.003761Z", + "shell.execute_reply": "2024-02-13T00:35:12.002857Z", + "shell.execute_reply.started": "2024-02-13T00:35:11.965506Z" }, "lines_to_next_cell": 2 }, @@ -10966,14 +10066,14 @@ }, { "cell_type": "code", - "execution_count": 184, + "execution_count": 155, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:20.449644Z", - "iopub.status.busy": "2023-12-05T23:05:20.449401Z", - "iopub.status.idle": "2023-12-05T23:05:23.154260Z", - "shell.execute_reply": "2023-12-05T23:05:23.153377Z", - "shell.execute_reply.started": "2023-12-05T23:05:20.449629Z" + "iopub.execute_input": "2024-02-13T00:35:12.005013Z", + "iopub.status.busy": "2024-02-13T00:35:12.004640Z", + "iopub.status.idle": "2024-02-13T00:35:14.739186Z", + "shell.execute_reply": "2024-02-13T00:35:14.738426Z", + "shell.execute_reply.started": "2024-02-13T00:35:12.004998Z" }, "lines_to_next_cell": 2, "tags": [] @@ -11083,14 +10183,14 @@ }, { "cell_type": "code", - "execution_count": 185, + "execution_count": 156, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:23.155296Z", - "iopub.status.busy": "2023-12-05T23:05:23.155006Z", - "iopub.status.idle": "2023-12-05T23:05:23.900540Z", - "shell.execute_reply": "2023-12-05T23:05:23.899860Z", - "shell.execute_reply.started": "2023-12-05T23:05:23.155282Z" + "iopub.execute_input": "2024-02-13T00:35:14.740285Z", + "iopub.status.busy": "2024-02-13T00:35:14.740072Z", + "iopub.status.idle": "2024-02-13T00:35:15.495493Z", + "shell.execute_reply": "2024-02-13T00:35:15.494864Z", + "shell.execute_reply.started": "2024-02-13T00:35:14.740269Z" }, "lines_to_next_cell": 2, "tags": [] @@ -11162,14 +10262,14 @@ }, { "cell_type": "code", - "execution_count": 186, + "execution_count": 157, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:23.901827Z", - "iopub.status.busy": "2023-12-05T23:05:23.901376Z", - "iopub.status.idle": "2023-12-05T23:05:23.975272Z", - "shell.execute_reply": "2023-12-05T23:05:23.974409Z", - "shell.execute_reply.started": "2023-12-05T23:05:23.901810Z" + "iopub.execute_input": "2024-02-13T00:35:15.496604Z", + "iopub.status.busy": "2024-02-13T00:35:15.496297Z", + "iopub.status.idle": "2024-02-13T00:35:15.566424Z", + "shell.execute_reply": "2024-02-13T00:35:15.565699Z", + "shell.execute_reply.started": "2024-02-13T00:35:15.496590Z" }, "lines_to_next_cell": 2, "tags": [] @@ -11256,14 +10356,14 @@ }, { "cell_type": "code", - "execution_count": 187, + "execution_count": 158, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:23.976398Z", - "iopub.status.busy": "2023-12-05T23:05:23.976073Z", - "iopub.status.idle": "2023-12-05T23:05:26.923061Z", - "shell.execute_reply": "2023-12-05T23:05:26.922396Z", - "shell.execute_reply.started": "2023-12-05T23:05:23.976383Z" + "iopub.execute_input": "2024-02-13T00:35:15.567653Z", + "iopub.status.busy": "2024-02-13T00:35:15.567496Z", + "iopub.status.idle": "2024-02-13T00:35:18.429816Z", + "shell.execute_reply": "2024-02-13T00:35:18.429124Z", + "shell.execute_reply.started": "2024-02-13T00:35:15.567640Z" }, "lines_to_next_cell": 2, "tags": [] @@ -11365,14 +10465,14 @@ }, { "cell_type": "code", - "execution_count": 188, + "execution_count": 159, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:26.924242Z", - "iopub.status.busy": "2023-12-05T23:05:26.923769Z", - "iopub.status.idle": "2023-12-05T23:05:26.960594Z", - "shell.execute_reply": "2023-12-05T23:05:26.959834Z", - "shell.execute_reply.started": "2023-12-05T23:05:26.924227Z" + "iopub.execute_input": "2024-02-13T00:35:18.430897Z", + "iopub.status.busy": "2024-02-13T00:35:18.430535Z", + "iopub.status.idle": "2024-02-13T00:35:18.467320Z", + "shell.execute_reply": "2024-02-13T00:35:18.466520Z", + "shell.execute_reply.started": "2024-02-13T00:35:18.430883Z" }, "tags": [] }, @@ -11409,14 +10509,14 @@ }, { "cell_type": "code", - "execution_count": 189, + "execution_count": 160, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:26.962265Z", - "iopub.status.busy": "2023-12-05T23:05:26.961688Z", - "iopub.status.idle": "2023-12-05T23:05:29.770768Z", - "shell.execute_reply": "2023-12-05T23:05:29.770039Z", - "shell.execute_reply.started": "2023-12-05T23:05:26.962221Z" + "iopub.execute_input": "2024-02-13T00:35:18.468529Z", + "iopub.status.busy": "2024-02-13T00:35:18.468272Z", + "iopub.status.idle": "2024-02-13T00:35:21.119466Z", + "shell.execute_reply": "2024-02-13T00:35:21.118741Z", + "shell.execute_reply.started": "2024-02-13T00:35:18.468515Z" }, "lines_to_next_cell": 2, "tags": [] @@ -11458,7 +10558,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "For shape = (500, 500, 3):\n", + "For shape=(500, 500, 3):\n", "scipy_convolve : 0.006 s\n", "scipy_convolve_r : 0.007 s\n", "scipy.oaconvolve : 0.008 s\n", @@ -11466,8 +10566,8 @@ "scipy.sepfir2d : 0.006 s\n", "numpy_fftconvolve : 0.022 s\n", "ndimage.convolve : 0.037 s\n", - "tf_convolve : 0.013 s\n", - "tf_convolve_r : 0.020 s\n", + "tf_convolve : 0.012 s\n", + "tf_convolve_r : 0.012 s\n", "torch_convolve_r : 0.003 s\n" ] } @@ -11662,14 +10762,14 @@ }, { "cell_type": "code", - "execution_count": 190, + "execution_count": 161, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:29.772239Z", - "iopub.status.busy": "2023-12-05T23:05:29.771809Z", - "iopub.status.idle": "2023-12-05T23:05:29.817906Z", - "shell.execute_reply": "2023-12-05T23:05:29.817254Z", - "shell.execute_reply.started": "2023-12-05T23:05:29.772223Z" + "iopub.execute_input": "2024-02-13T00:35:21.120959Z", + "iopub.status.busy": "2024-02-13T00:35:21.120447Z", + "iopub.status.idle": "2024-02-13T00:35:21.166167Z", + "shell.execute_reply": "2024-02-13T00:35:21.165504Z", + "shell.execute_reply.started": "2024-02-13T00:35:21.120931Z" }, "tags": [] }, @@ -11827,14 +10927,14 @@ }, { "cell_type": "code", - "execution_count": 191, + "execution_count": 162, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:29.818910Z", - "iopub.status.busy": "2023-12-05T23:05:29.818751Z", - "iopub.status.idle": "2023-12-05T23:05:32.997465Z", - "shell.execute_reply": "2023-12-05T23:05:32.996978Z", - "shell.execute_reply.started": "2023-12-05T23:05:29.818897Z" + "iopub.execute_input": "2024-02-13T00:35:21.167518Z", + "iopub.status.busy": "2024-02-13T00:35:21.167133Z", + "iopub.status.idle": "2024-02-13T00:35:24.372217Z", + "shell.execute_reply": "2024-02-13T00:35:24.371743Z", + "shell.execute_reply.started": "2024-02-13T00:35:21.167501Z" }, "tags": [] }, @@ -11843,13 +10943,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "5.68 ms\n", - "6.53 ms\n", - "general : 0.011 s (max_error: 2.98e-07)\n", + "5.58 ms\n", + "6.37 ms\n", + "general : 0.012 s (max_error: 2.98e-07)\n", "spline_filter1d : 0.009 s (max_error: 1.19e-07)\n", "solveh_banded : 0.009 s (max_error: 2.98e-07)\n", - "splu : 0.021 s (max_error: 2.38e-07)\n", - "filtfilt : 0.074 s (max_error: 5.96e-07)\n" + "splu : 0.019 s (max_error: 2.38e-07)\n", + "filtfilt : 0.076 s (max_error: 5.96e-07)\n" ] } ], @@ -12074,14 +11174,14 @@ }, { "cell_type": "code", - "execution_count": 192, + "execution_count": 163, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:33.000194Z", - "iopub.status.busy": "2023-12-05T23:05:32.999143Z", - "iopub.status.idle": "2023-12-05T23:05:33.133785Z", - "shell.execute_reply": "2023-12-05T23:05:33.133075Z", - "shell.execute_reply.started": "2023-12-05T23:05:33.000176Z" + "iopub.execute_input": "2024-02-13T00:35:24.374902Z", + "iopub.status.busy": "2024-02-13T00:35:24.373941Z", + "iopub.status.idle": "2024-02-13T00:35:24.502968Z", + "shell.execute_reply": "2024-02-13T00:35:24.502370Z", + "shell.execute_reply.started": "2024-02-13T00:35:24.374884Z" }, "lines_to_next_cell": 2 }, @@ -12143,14 +11243,14 @@ }, { "cell_type": "code", - "execution_count": 193, + "execution_count": 164, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:33.135171Z", - "iopub.status.busy": "2023-12-05T23:05:33.134684Z", - "iopub.status.idle": "2023-12-05T23:05:33.167877Z", - "shell.execute_reply": "2023-12-05T23:05:33.167124Z", - "shell.execute_reply.started": "2023-12-05T23:05:33.135156Z" + "iopub.execute_input": "2024-02-13T00:35:24.504447Z", + "iopub.status.busy": "2024-02-13T00:35:24.504009Z", + "iopub.status.idle": "2024-02-13T00:35:24.538425Z", + "shell.execute_reply": "2024-02-13T00:35:24.537531Z", + "shell.execute_reply.started": "2024-02-13T00:35:24.504430Z" } }, "outputs": [], @@ -12160,14 +11260,14 @@ }, { "cell_type": "code", - "execution_count": 194, + "execution_count": 165, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:33.169058Z", - "iopub.status.busy": "2023-12-05T23:05:33.168700Z", - "iopub.status.idle": "2023-12-05T23:05:33.217438Z", - "shell.execute_reply": "2023-12-05T23:05:33.216479Z", - "shell.execute_reply.started": "2023-12-05T23:05:33.169042Z" + "iopub.execute_input": "2024-02-13T00:35:24.539900Z", + "iopub.status.busy": "2024-02-13T00:35:24.539248Z", + "iopub.status.idle": "2024-02-13T00:35:24.572945Z", + "shell.execute_reply": "2024-02-13T00:35:24.572312Z", + "shell.execute_reply.started": "2024-02-13T00:35:24.539868Z" }, "lines_to_next_cell": 2 }, @@ -12179,14 +11279,14 @@ }, { "cell_type": "code", - "execution_count": 195, + "execution_count": 166, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:33.218800Z", - "iopub.status.busy": "2023-12-05T23:05:33.218405Z", - "iopub.status.idle": "2023-12-05T23:05:33.379484Z", - "shell.execute_reply": "2023-12-05T23:05:33.378740Z", - "shell.execute_reply.started": "2023-12-05T23:05:33.218775Z" + "iopub.execute_input": "2024-02-13T00:35:24.573938Z", + "iopub.status.busy": "2024-02-13T00:35:24.573596Z", + "iopub.status.idle": "2024-02-13T00:35:24.716762Z", + "shell.execute_reply": "2024-02-13T00:35:24.716048Z", + "shell.execute_reply.started": "2024-02-13T00:35:24.573923Z" }, "tags": [] }, @@ -12222,14 +11322,14 @@ }, { "cell_type": "code", - "execution_count": 196, + "execution_count": 167, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:33.380492Z", - "iopub.status.busy": "2023-12-05T23:05:33.380216Z", - "iopub.status.idle": "2023-12-05T23:05:33.417869Z", - "shell.execute_reply": "2023-12-05T23:05:33.417151Z", - "shell.execute_reply.started": "2023-12-05T23:05:33.380479Z" + "iopub.execute_input": "2024-02-13T00:35:24.717940Z", + "iopub.status.busy": "2024-02-13T00:35:24.717496Z", + "iopub.status.idle": "2024-02-13T00:35:24.751432Z", + "shell.execute_reply": "2024-02-13T00:35:24.750772Z", + "shell.execute_reply.started": "2024-02-13T00:35:24.717926Z" }, "tags": [] }, @@ -12256,14 +11356,14 @@ }, { "cell_type": "code", - "execution_count": 197, + "execution_count": 168, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:33.418961Z", - "iopub.status.busy": "2023-12-05T23:05:33.418741Z", - "iopub.status.idle": "2023-12-05T23:05:33.483334Z", - "shell.execute_reply": "2023-12-05T23:05:33.482345Z", - "shell.execute_reply.started": "2023-12-05T23:05:33.418946Z" + "iopub.execute_input": "2024-02-13T00:35:24.752585Z", + "iopub.status.busy": "2024-02-13T00:35:24.752126Z", + "iopub.status.idle": "2024-02-13T00:35:24.809567Z", + "shell.execute_reply": "2024-02-13T00:35:24.808948Z", + "shell.execute_reply.started": "2024-02-13T00:35:24.752569Z" }, "tags": [] }, @@ -12321,14 +11421,14 @@ }, { "cell_type": "code", - "execution_count": 198, + "execution_count": 169, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:33.484586Z", - "iopub.status.busy": "2023-12-05T23:05:33.484257Z", - "iopub.status.idle": "2023-12-05T23:05:33.733863Z", - "shell.execute_reply": "2023-12-05T23:05:33.733239Z", - "shell.execute_reply.started": "2023-12-05T23:05:33.484568Z" + "iopub.execute_input": "2024-02-13T00:35:24.810648Z", + "iopub.status.busy": "2024-02-13T00:35:24.810336Z", + "iopub.status.idle": "2024-02-13T00:35:25.059173Z", + "shell.execute_reply": "2024-02-13T00:35:25.058567Z", + "shell.execute_reply.started": "2024-02-13T00:35:24.810634Z" }, "lines_to_next_cell": 2, "tags": [] @@ -12394,14 +11494,14 @@ }, { "cell_type": "code", - "execution_count": 199, + "execution_count": 170, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:33.735036Z", - "iopub.status.busy": "2023-12-05T23:05:33.734646Z", - "iopub.status.idle": "2023-12-05T23:05:33.783640Z", - "shell.execute_reply": "2023-12-05T23:05:33.782994Z", - "shell.execute_reply.started": "2023-12-05T23:05:33.735018Z" + "iopub.execute_input": "2024-02-13T00:35:25.059990Z", + "iopub.status.busy": "2024-02-13T00:35:25.059828Z", + "iopub.status.idle": "2024-02-13T00:35:25.108326Z", + "shell.execute_reply": "2024-02-13T00:35:25.107619Z", + "shell.execute_reply.started": "2024-02-13T00:35:25.059977Z" }, "lines_to_next_cell": 2, "tags": [] @@ -12464,14 +11564,14 @@ }, { "cell_type": "code", - "execution_count": 200, + "execution_count": 171, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:33.784808Z", - "iopub.status.busy": "2023-12-05T23:05:33.784428Z", - "iopub.status.idle": "2023-12-05T23:05:34.210205Z", - "shell.execute_reply": "2023-12-05T23:05:34.209360Z", - "shell.execute_reply.started": "2023-12-05T23:05:33.784793Z" + "iopub.execute_input": "2024-02-13T00:35:25.109487Z", + "iopub.status.busy": "2024-02-13T00:35:25.109091Z", + "iopub.status.idle": "2024-02-13T00:35:25.520096Z", + "shell.execute_reply": "2024-02-13T00:35:25.519181Z", + "shell.execute_reply.started": "2024-02-13T00:35:25.109471Z" }, "lines_to_next_cell": 2, "tags": [] @@ -12529,14 +11629,14 @@ }, { "cell_type": "code", - "execution_count": 201, + "execution_count": 172, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:34.211820Z", - "iopub.status.busy": "2023-12-05T23:05:34.211347Z", - "iopub.status.idle": "2023-12-05T23:05:34.250290Z", - "shell.execute_reply": "2023-12-05T23:05:34.249607Z", - "shell.execute_reply.started": "2023-12-05T23:05:34.211801Z" + "iopub.execute_input": "2024-02-13T00:35:25.521169Z", + "iopub.status.busy": "2024-02-13T00:35:25.520841Z", + "iopub.status.idle": "2024-02-13T00:35:25.554191Z", + "shell.execute_reply": "2024-02-13T00:35:25.553522Z", + "shell.execute_reply.started": "2024-02-13T00:35:25.521155Z" } }, "outputs": [], @@ -12549,14 +11649,14 @@ }, { "cell_type": "code", - "execution_count": 202, + "execution_count": 173, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:34.259910Z", - "iopub.status.busy": "2023-12-05T23:05:34.259478Z", - "iopub.status.idle": "2023-12-05T23:05:34.292000Z", - "shell.execute_reply": "2023-12-05T23:05:34.291367Z", - "shell.execute_reply.started": "2023-12-05T23:05:34.259893Z" + "iopub.execute_input": "2024-02-13T00:35:25.554968Z", + "iopub.status.busy": "2024-02-13T00:35:25.554820Z", + "iopub.status.idle": "2024-02-13T00:35:25.587488Z", + "shell.execute_reply": "2024-02-13T00:35:25.586831Z", + "shell.execute_reply.started": "2024-02-13T00:35:25.554957Z" } }, "outputs": [], @@ -12614,14 +11714,14 @@ }, { "cell_type": "code", - "execution_count": 203, + "execution_count": 174, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:34.292945Z", - "iopub.status.busy": "2023-12-05T23:05:34.292739Z", - "iopub.status.idle": "2023-12-05T23:05:39.577305Z", - "shell.execute_reply": "2023-12-05T23:05:39.576618Z", - "shell.execute_reply.started": "2023-12-05T23:05:34.292932Z" + "iopub.execute_input": "2024-02-13T00:35:25.588530Z", + "iopub.status.busy": "2024-02-13T00:35:25.588330Z", + "iopub.status.idle": "2024-02-13T00:35:30.821133Z", + "shell.execute_reply": "2024-02-13T00:35:30.820413Z", + "shell.execute_reply.started": "2024-02-13T00:35:25.588518Z" }, "lines_to_next_cell": 2, "tags": [] @@ -12641,53 +11741,53 @@ "
\n", "
original psnr:200.00 dB (0.00 ms)
\n", "
\n", - "
resize lanczos5 psnr:33.54 dB (2.49 ms)
\n", + "
resize lanczos5 psnr:33.54 dB (2.40 ms)
\n", "
\n", - "
resize lanczos3 psnr:33.39 dB (2.46 ms)
\n", + "
resize lanczos3 psnr:33.39 dB (2.88 ms)
\n", "
\n", - "
resize cardinal3 psnr:33.38 dB (5.71 ms)
\n", + "
resize cardinal3 psnr:33.38 dB (7.01 ms)
\n", "
\n", - "
resize sharpcubic psnr:33.19 dB (2.27 ms)
\n", + "
resize sharpcubic psnr:33.19 dB (2.69 ms)
\n", "
\n", - "
resize cubic psnr:33.06 dB (2.28 ms)
\n", + "
resize cubic psnr:33.06 dB (2.70 ms)
\n", "
\n", - "
resize triangle psnr:32.31 dB (2.11 ms)
\n", + "
resize triangle psnr:32.31 dB (2.50 ms)
\n", "
\n", - "
resize_in_tf lanczos3 psnr:33.39 dB (4.02 ms)
\n", + "
resize_in_tf lanczos3 psnr:33.39 dB (4.28 ms)
\n", "
\n", - "
resize_in_torch lanczos3 psnr:33.39 dB (2.15 ms)
\n", + "
resize_in_torch lanczos3 psnr:33.39 dB (2.11 ms)
\n", "
\n", - "
resize_in_jax lanczos3 psnr:33.39 dB (9.32 ms)
\n", + "
resize_in_jax lanczos3 psnr:33.39 dB (9.45 ms)
\n", "
\n", - "
jaxjit_resize lanczos3 psnr:33.39 dB (2.34 ms)
\n", + "
jaxjit_resize lanczos3 psnr:33.39 dB (2.21 ms)
\n", "
\n", - "
jaxjit_resize cubic psnr:33.06 dB (1.98 ms)
\n", + "
jaxjit_resize cubic psnr:33.06 dB (1.31 ms)
\n", "
\n", - "
resample lanczos3 psnr:33.39 dB (286.42 ms)
\n", + "
resample lanczos3 psnr:33.39 dB (241.14 ms)
\n", "
\n", - "
PIL.Image.resize lanczos3 psnr:33.33 dB (5.75 ms)
\n", + "
PIL.Image.resize lanczos3 psnr:33.33 dB (6.26 ms)
\n", "
\n", - "
PIL.Image.resize cubic psnr:33.05 dB (4.15 ms)
\n", + "
PIL.Image.resize cubic psnr:33.05 dB (4.71 ms)
\n", "
\n", - "
map_coordinates order=3 psnr:33.38 dB (274.42 ms)
\n", + "
map_coordinates order=3 psnr:33.38 dB (272.18 ms)
\n", "
\n", - "
skimage.transform.resize psnr:33.38 dB (266.94 ms)
\n", + "
skimage.transform.resize psnr:33.38 dB (267.39 ms)
\n", "
\n", - "
tf.resize lanczos5 psnr:33.44 dB (8.15 ms)
\n", + "
tf.resize lanczos5 psnr:33.44 dB (8.36 ms)
\n", "
\n", - "
tf.resize lanczos3 psnr:33.33 dB (5.50 ms)
\n", + "
tf.resize lanczos3 psnr:33.33 dB (5.74 ms)
\n", "
\n", - "
tf.resize cubic (aa False) psnr:33.05 dB (1.24 ms)
\n", + "
tf.resize cubic (aa False) psnr:33.05 dB (1.42 ms)
\n", "
\n", - "
torch.nn.interp sharpcubic psnr:33.17 dB (1.29 ms)
\n", + "
torch.nn.interp sharpcubic psnr:33.17 dB (0.98 ms)
\n", "
\n", "
torch.nn.interpolate triangle psnr:32.31 dB (0.60 ms)
\n", "
\n", - "
jax.image.resize lanczos3 psnr:33.33 dB (10.19 ms)
\n", + "
jax.image.resize lanczos3 psnr:33.33 dB (9.80 ms)
\n", "
\n", - "
jax.image.resize triangle psnr:32.31 dB (5.96 ms)
\n", + "
jax.image.resize triangle psnr:32.31 dB (5.72 ms)
\n", "
\n", - "
cv.resize lanczos4 psnr:33.41 dB (0.78 ms)
\n", + "
cv.resize lanczos4 psnr:33.41 dB (0.42 ms)
\n", "
\n", "
cv.resize sharpcubic psnr:33.17 dB (0.13 ms)
" ], @@ -12779,14 +11879,14 @@ }, { "cell_type": "code", - "execution_count": 204, + "execution_count": 175, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:39.578318Z", - "iopub.status.busy": "2023-12-05T23:05:39.578141Z", - "iopub.status.idle": "2023-12-05T23:05:39.610389Z", - "shell.execute_reply": "2023-12-05T23:05:39.609616Z", - "shell.execute_reply.started": "2023-12-05T23:05:39.578304Z" + "iopub.execute_input": "2024-02-13T00:35:30.822352Z", + "iopub.status.busy": "2024-02-13T00:35:30.822167Z", + "iopub.status.idle": "2024-02-13T00:35:30.859845Z", + "shell.execute_reply": "2024-02-13T00:35:30.859067Z", + "shell.execute_reply.started": "2024-02-13T00:35:30.822336Z" } }, "outputs": [], @@ -12819,14 +11919,14 @@ }, { "cell_type": "code", - "execution_count": 205, + "execution_count": 176, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:39.611626Z", - "iopub.status.busy": "2023-12-05T23:05:39.611268Z", - "iopub.status.idle": "2023-12-05T23:05:46.060538Z", - "shell.execute_reply": "2023-12-05T23:05:46.059901Z", - "shell.execute_reply.started": "2023-12-05T23:05:39.611611Z" + "iopub.execute_input": "2024-02-13T00:35:30.861114Z", + "iopub.status.busy": "2024-02-13T00:35:30.860911Z", + "iopub.status.idle": "2024-02-13T00:35:37.730632Z", + "shell.execute_reply": "2024-02-13T00:35:37.729905Z", + "shell.execute_reply.started": "2024-02-13T00:35:30.861101Z" }, "tags": [] }, @@ -12843,59 +11943,59 @@ "text/html": [ "
\n", "
\n", - "
resize lanczos3 psnr:26.12 dB (4.00 ms)
\n", + "
resize lanczos3 psnr:26.12 dB (4.68 ms)
\n", "
\n", - "
resize cardinal3 psnr:25.89 dB (8.74 ms)
\n", + "
resize cardinal3 psnr:25.89 dB (9.38 ms)
\n", "
\n", - "
resize cubic psnr:26.04 dB (3.56 ms)
\n", + "
resize cubic psnr:26.04 dB (5.23 ms)
\n", "
\n", - "
resize triangle psnr:25.78 dB (2.64 ms)
\n", + "
resize triangle psnr:25.78 dB (4.10 ms)
\n", "
\n", - "
resize trapezoid psnr:25.97 dB (0.31 ms)
\n", + "
resize trapezoid psnr:25.97 dB (0.42 ms)
\n", "
\n", - "
resize box psnr:25.97 dB (0.30 ms)
\n", + "
resize box psnr:25.97 dB (0.53 ms)
\n", "
\n", - "
resize_in_tf lanczos3 psnr:26.12 dB (11.31 ms)
\n", + "
resize_in_tf lanczos3 psnr:26.12 dB (16.72 ms)
\n", "
\n", - "
resize_in_tf trapezoid psnr:25.97 dB (10.62 ms)
\n", + "
resize_in_tf trapezoid psnr:25.97 dB (6.58 ms)
\n", "
\n", - "
resize_in_torch lanczos3 psnr:26.12 dB (7.16 ms)
\n", + "
resize_in_torch lanczos3 psnr:26.12 dB (6.23 ms)
\n", "
\n", - "
resize_in_torch trapezoid psnr:25.97 dB (2.90 ms)
\n", + "
resize_in_torch trapezoid psnr:25.97 dB (2.64 ms)
\n", "
\n", - "
resize_in_jax lanczos3 psnr:26.12 dB (46.62 ms)
\n", + "
resize_in_jax lanczos3 psnr:26.12 dB (40.91 ms)
\n", "
\n", - "
resize_in_jax trapezoid psnr:25.97 dB (18.51 ms)
\n", + "
resize_in_jax trapezoid psnr:25.97 dB (18.80 ms)
\n", "
\n", - "
jaxjit_resize lanczos3 psnr:26.12 dB (32.26 ms)
\n", + "
jaxjit_resize lanczos3 psnr:26.12 dB (28.51 ms)
\n", "
\n", - "
jaxjit_resize trapezoid psnr:25.97 dB (4.26 ms)
\n", + "
jaxjit_resize trapezoid psnr:25.97 dB (3.42 ms)
\n", "
\n", - "
resample lanczos3 psnr:23.89 dB (14.12 ms)
\n", + "
resample lanczos3 psnr:23.89 dB (13.28 ms)
\n", "
\n", - "
PIL.Image.resize lanczos3 psnr:26.10 dB (36.22 ms)
\n", + "
PIL.Image.resize lanczos3 psnr:26.10 dB (36.56 ms)
\n", "
\n", - "
PIL.Image.resize box psnr:25.97 dB (20.24 ms)
\n", + "
PIL.Image.resize box psnr:25.97 dB (20.16 ms)
\n", "
\n", - "
map_coordinates order=3 psnr:23.96 dB (147.51 ms)
\n", + "
map_coordinates order=3 psnr:23.96 dB (142.56 ms)
\n", "
\n", - "
skimage.transform.resize psnr:25.72 dB (256.47 ms)
\n", + "
skimage.transform.resize psnr:25.72 dB (264.16 ms)
\n", "
\n", - "
tf.resize lanczos3 psnr:26.10 dB (15.46 ms)
\n", + "
tf.resize lanczos3 psnr:26.10 dB (9.30 ms)
\n", "
\n", - "
tf.resize trapezoid psnr:25.97 dB (4.78 ms)
\n", + "
tf.resize trapezoid psnr:25.97 dB (8.35 ms)
\n", "
\n", - "
torch.nn.interp cubic AA psnr:26.02 dB (2.95 ms)
\n", + "
torch.nn.interp cubic AA psnr:26.02 dB (2.98 ms)
\n", "
\n", - "
torch.nn.interp triangle AA psnr:25.78 dB (1.48 ms)
\n", + "
torch.nn.interp triangle AA psnr:25.78 dB (1.41 ms)
\n", "
\n", - "
torch.nn.interp trapezoid psnr:25.97 dB (3.24 ms)
\n", + "
torch.nn.interp trapezoid psnr:25.97 dB (3.36 ms)
\n", "
\n", - "
jax.image.resize lanczos3 psnr:26.10 dB (15.85 ms)
\n", + "
jax.image.resize lanczos3 psnr:26.10 dB (12.85 ms)
\n", "
\n", - "
jax.image.resize triangle psnr:25.78 dB (14.06 ms)
\n", + "
jax.image.resize triangle psnr:25.78 dB (8.24 ms)
\n", "
\n", - "
cv.resize lanczos4 psnr:23.84 dB (1.06 ms)
\n", + "
cv.resize lanczos4 psnr:23.84 dB (1.04 ms)
\n", "
\n", "
cv.resize trapezoid psnr:25.97 dB (1.20 ms)
" ], @@ -12990,14 +12090,14 @@ }, { "cell_type": "code", - "execution_count": 206, + "execution_count": 177, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:46.061454Z", - "iopub.status.busy": "2023-12-05T23:05:46.061252Z", - "iopub.status.idle": "2023-12-05T23:05:46.092636Z", - "shell.execute_reply": "2023-12-05T23:05:46.091592Z", - "shell.execute_reply.started": "2023-12-05T23:05:46.061442Z" + "iopub.execute_input": "2024-02-13T00:35:37.731766Z", + "iopub.status.busy": "2024-02-13T00:35:37.731466Z", + "iopub.status.idle": "2024-02-13T00:35:37.764178Z", + "shell.execute_reply": "2024-02-13T00:35:37.763497Z", + "shell.execute_reply.started": "2024-02-13T00:35:37.731750Z" } }, "outputs": [], @@ -13009,14 +12109,14 @@ }, { "cell_type": "code", - "execution_count": 207, + "execution_count": 178, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:46.093987Z", - "iopub.status.busy": "2023-12-05T23:05:46.093528Z", - "iopub.status.idle": "2023-12-05T23:05:46.128042Z", - "shell.execute_reply": "2023-12-05T23:05:46.127372Z", - "shell.execute_reply.started": "2023-12-05T23:05:46.093973Z" + "iopub.execute_input": "2024-02-13T00:35:37.765061Z", + "iopub.status.busy": "2024-02-13T00:35:37.764863Z", + "iopub.status.idle": "2024-02-13T00:35:37.798766Z", + "shell.execute_reply": "2024-02-13T00:35:37.798140Z", + "shell.execute_reply.started": "2024-02-13T00:35:37.765048Z" }, "tags": [] }, @@ -13029,14 +12129,14 @@ }, { "cell_type": "code", - "execution_count": 208, + "execution_count": 179, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:46.129463Z", - "iopub.status.busy": "2023-12-05T23:05:46.129019Z", - "iopub.status.idle": "2023-12-05T23:05:46.443466Z", - "shell.execute_reply": "2023-12-05T23:05:46.442718Z", - "shell.execute_reply.started": "2023-12-05T23:05:46.129441Z" + "iopub.execute_input": "2024-02-13T00:35:37.799864Z", + "iopub.status.busy": "2024-02-13T00:35:37.799640Z", + "iopub.status.idle": "2024-02-13T00:35:38.050382Z", + "shell.execute_reply": "2024-02-13T00:35:38.049555Z", + "shell.execute_reply.started": "2024-02-13T00:35:37.799849Z" }, "lines_to_next_cell": 2, "tags": [] @@ -13046,12 +12146,12 @@ "name": "stdout", "output_type": "stream", "text": [ - "float32 (1000, 2000, 3) (24000, 12, 4) : 7.00 ms\n", - "float32 (900, 1800, 3) (12, 10800, 4) : 6.03 ms\n", - "float32 (800, 1600, 3) (12, 9600, 4) : 4.67 ms\n", - "float32 (1000, 2000, 3) (24000, 12, 4) : 6.36 ms\n", - "float32 (900, 1800, 3) (21600, 12, 4) : 8.72 ms\n", - "float32 (800, 1600, 3) (19200, 12, 4) : 7.68 ms\n" + "float32 (1000, 2000, 3) (24000, 12, 4) : 5.35 ms\n", + "float32 (900, 1800, 3) (12, 10800, 4) : 4.82 ms\n", + "float32 (800, 1600, 3) (12, 9600, 4) : 4.19 ms\n", + "float32 (1000, 2000, 3) (24000, 12, 4) : 6.05 ms\n", + "float32 (900, 1800, 3) (21600, 12, 4) : 6.18 ms\n", + "float32 (800, 1600, 3) (19200, 12, 4) : 5.07 ms\n" ] } ], @@ -13111,14 +12211,14 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 180, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:55:01.858070Z", - "iopub.status.busy": "2023-12-13T19:55:01.857742Z", - "iopub.status.idle": "2023-12-13T19:55:01.890977Z", - "shell.execute_reply": "2023-12-13T19:55:01.889602Z", - "shell.execute_reply.started": "2023-12-13T19:55:01.858054Z" + "iopub.execute_input": "2024-02-13T00:35:38.051591Z", + "iopub.status.busy": "2024-02-13T00:35:38.051262Z", + "iopub.status.idle": "2024-02-13T00:35:38.086061Z", + "shell.execute_reply": "2024-02-13T00:35:38.085396Z", + "shell.execute_reply.started": "2024-02-13T00:35:38.051577Z" } }, "outputs": [], @@ -13151,14 +12251,14 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 181, "metadata": { "execution": { - "iopub.execute_input": "2023-12-13T19:55:18.245465Z", - "iopub.status.busy": "2023-12-13T19:55:18.245122Z", - "iopub.status.idle": "2023-12-13T19:55:18.274626Z", - "shell.execute_reply": "2023-12-13T19:55:18.273838Z", - "shell.execute_reply.started": "2023-12-13T19:55:18.245451Z" + "iopub.execute_input": "2024-02-13T00:35:38.087099Z", + "iopub.status.busy": "2024-02-13T00:35:38.086795Z", + "iopub.status.idle": "2024-02-13T00:35:38.119813Z", + "shell.execute_reply": "2024-02-13T00:35:38.119189Z", + "shell.execute_reply.started": "2024-02-13T00:35:38.087083Z" } }, "outputs": [], @@ -13178,14 +12278,14 @@ }, { "cell_type": "code", - "execution_count": 209, + "execution_count": 182, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:46.445066Z", - "iopub.status.busy": "2023-12-05T23:05:46.444499Z", - "iopub.status.idle": "2023-12-05T23:05:48.575847Z", - "shell.execute_reply": "2023-12-05T23:05:48.575129Z", - "shell.execute_reply.started": "2023-12-05T23:05:46.445039Z" + "iopub.execute_input": "2024-02-13T00:35:38.120925Z", + "iopub.status.busy": "2024-02-13T00:35:38.120589Z", + "iopub.status.idle": "2024-02-13T00:35:39.766578Z", + "shell.execute_reply": "2024-02-13T00:35:39.765844Z", + "shell.execute_reply.started": "2024-02-13T00:35:38.120910Z" } }, "outputs": [ @@ -13407,14 +12507,14 @@ }, { "cell_type": "code", - "execution_count": 210, + "execution_count": 183, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:48.576792Z", - "iopub.status.busy": "2023-12-05T23:05:48.576519Z", - "iopub.status.idle": "2023-12-05T23:05:50.422014Z", - "shell.execute_reply": "2023-12-05T23:05:50.421195Z", - "shell.execute_reply.started": "2023-12-05T23:05:48.576778Z" + "iopub.execute_input": "2024-02-13T00:35:39.767655Z", + "iopub.status.busy": "2024-02-13T00:35:39.767359Z", + "iopub.status.idle": "2024-02-13T00:35:41.588775Z", + "shell.execute_reply": "2024-02-13T00:35:41.588122Z", + "shell.execute_reply.started": "2024-02-13T00:35:39.767641Z" } }, "outputs": [ @@ -13628,14 +12728,14 @@ }, { "cell_type": "code", - "execution_count": 211, + "execution_count": 184, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:50.422967Z", - "iopub.status.busy": "2023-12-05T23:05:50.422637Z", - "iopub.status.idle": "2023-12-05T23:05:50.453716Z", - "shell.execute_reply": "2023-12-05T23:05:50.453038Z", - "shell.execute_reply.started": "2023-12-05T23:05:50.422953Z" + "iopub.execute_input": "2024-02-13T00:35:41.589797Z", + "iopub.status.busy": "2024-02-13T00:35:41.589499Z", + "iopub.status.idle": "2024-02-13T00:35:41.622855Z", + "shell.execute_reply": "2024-02-13T00:35:41.622177Z", + "shell.execute_reply.started": "2024-02-13T00:35:41.589783Z" } }, "outputs": [], @@ -13649,14 +12749,14 @@ }, { "cell_type": "code", - "execution_count": 212, + "execution_count": 185, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:50.454821Z", - "iopub.status.busy": "2023-12-05T23:05:50.454477Z", - "iopub.status.idle": "2023-12-05T23:05:50.486298Z", - "shell.execute_reply": "2023-12-05T23:05:50.485631Z", - "shell.execute_reply.started": "2023-12-05T23:05:50.454804Z" + "iopub.execute_input": "2024-02-13T00:35:41.624170Z", + "iopub.status.busy": "2024-02-13T00:35:41.623544Z", + "iopub.status.idle": "2024-02-13T00:35:41.656028Z", + "shell.execute_reply": "2024-02-13T00:35:41.655366Z", + "shell.execute_reply.started": "2024-02-13T00:35:41.624122Z" } }, "outputs": [], @@ -13678,46 +12778,14 @@ }, { "cell_type": "code", - "execution_count": 213, - "metadata": { - "execution": { - "iopub.execute_input": "2023-12-05T23:05:50.487592Z", - "iopub.status.busy": "2023-12-05T23:05:50.487086Z", - "iopub.status.idle": "2023-12-05T23:05:51.656517Z", - "shell.execute_reply": "2023-12-05T23:05:51.655511Z", - "shell.execute_reply.started": "2023-12-05T23:05:50.487577Z" - }, - "tags": [] - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m.\u001b[0m\u001b[32m [100%]\u001b[0m\n" - ] - } - ], - "source": [ - "def run_pytest_command() -> None: # (This function name cannot end in 'test', else recursion.)\n", - " assert running_in_notebook()\n", - " hh.run('pytest -qq || true')\n", - "\n", - "\n", - "if EFFORT >= 1:\n", - " run_pytest_command()" - ] - }, - { - "cell_type": "code", - "execution_count": 214, + "execution_count": 186, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:51.657707Z", - "iopub.status.busy": "2023-12-05T23:05:51.657338Z", - "iopub.status.idle": "2023-12-05T23:05:51.692254Z", - "shell.execute_reply": "2023-12-05T23:05:51.691502Z", - "shell.execute_reply.started": "2023-12-05T23:05:51.657684Z" + "iopub.execute_input": "2024-02-13T00:35:41.657066Z", + "iopub.status.busy": "2024-02-13T00:35:41.656804Z", + "iopub.status.idle": "2024-02-13T00:35:41.692510Z", + "shell.execute_reply": "2024-02-13T00:35:41.691861Z", + "shell.execute_reply.started": "2024-02-13T00:35:41.657049Z" }, "lines_to_next_cell": 2, "tags": [] @@ -13750,14 +12818,14 @@ }, { "cell_type": "code", - "execution_count": 215, + "execution_count": 187, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:51.693541Z", - "iopub.status.busy": "2023-12-05T23:05:51.693189Z", - "iopub.status.idle": "2023-12-05T23:05:51.727864Z", - "shell.execute_reply": "2023-12-05T23:05:51.727184Z", - "shell.execute_reply.started": "2023-12-05T23:05:51.693525Z" + "iopub.execute_input": "2024-02-13T00:35:41.693463Z", + "iopub.status.busy": "2024-02-13T00:35:41.693238Z", + "iopub.status.idle": "2024-02-13T00:35:41.727219Z", + "shell.execute_reply": "2024-02-13T00:35:41.726584Z", + "shell.execute_reply.started": "2024-02-13T00:35:41.693435Z" }, "tags": [] }, @@ -13787,14 +12855,14 @@ }, { "cell_type": "code", - "execution_count": 216, + "execution_count": 188, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:51.728931Z", - "iopub.status.busy": "2023-12-05T23:05:51.728720Z", - "iopub.status.idle": "2023-12-05T23:05:51.764499Z", - "shell.execute_reply": "2023-12-05T23:05:51.763843Z", - "shell.execute_reply.started": "2023-12-05T23:05:51.728914Z" + "iopub.execute_input": "2024-02-13T00:35:41.728245Z", + "iopub.status.busy": "2024-02-13T00:35:41.727912Z", + "iopub.status.idle": "2024-02-13T00:35:41.760802Z", + "shell.execute_reply": "2024-02-13T00:35:41.760173Z", + "shell.execute_reply.started": "2024-02-13T00:35:41.728232Z" }, "tags": [] }, @@ -13830,14 +12898,14 @@ }, { "cell_type": "code", - "execution_count": 217, + "execution_count": 189, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:51.765781Z", - "iopub.status.busy": "2023-12-05T23:05:51.765235Z", - "iopub.status.idle": "2023-12-05T23:05:51.799658Z", - "shell.execute_reply": "2023-12-05T23:05:51.798753Z", - "shell.execute_reply.started": "2023-12-05T23:05:51.765764Z" + "iopub.execute_input": "2024-02-13T00:35:41.762079Z", + "iopub.status.busy": "2024-02-13T00:35:41.761566Z", + "iopub.status.idle": "2024-02-13T00:35:41.795136Z", + "shell.execute_reply": "2024-02-13T00:35:41.794515Z", + "shell.execute_reply.started": "2024-02-13T00:35:41.762061Z" }, "tags": [] }, @@ -13857,14 +12925,14 @@ }, { "cell_type": "code", - "execution_count": 218, + "execution_count": 190, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:51.800762Z", - "iopub.status.busy": "2023-12-05T23:05:51.800575Z", - "iopub.status.idle": "2023-12-05T23:05:51.839498Z", - "shell.execute_reply": "2023-12-05T23:05:51.838785Z", - "shell.execute_reply.started": "2023-12-05T23:05:51.800748Z" + "iopub.execute_input": "2024-02-13T00:35:41.796101Z", + "iopub.status.busy": "2024-02-13T00:35:41.795901Z", + "iopub.status.idle": "2024-02-13T00:35:41.832107Z", + "shell.execute_reply": "2024-02-13T00:35:41.831419Z", + "shell.execute_reply.started": "2024-02-13T00:35:41.796085Z" }, "tags": [] }, @@ -13891,14 +12959,14 @@ }, { "cell_type": "code", - "execution_count": 219, + "execution_count": 191, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:51.840732Z", - "iopub.status.busy": "2023-12-05T23:05:51.840367Z", - "iopub.status.idle": "2023-12-05T23:05:51.874813Z", - "shell.execute_reply": "2023-12-05T23:05:51.874130Z", - "shell.execute_reply.started": "2023-12-05T23:05:51.840716Z" + "iopub.execute_input": "2024-02-13T00:35:41.833493Z", + "iopub.status.busy": "2024-02-13T00:35:41.832956Z", + "iopub.status.idle": "2024-02-13T00:35:41.867082Z", + "shell.execute_reply": "2024-02-13T00:35:41.866439Z", + "shell.execute_reply.started": "2024-02-13T00:35:41.833478Z" }, "tags": [] }, @@ -13908,27 +12976,27 @@ "output_type": "stream", "text": [ "# EFFORT=1\n", - "# Total time: 103.06 s\n", - "# In[205] def experiment_compare_downsampling_with_other_libraries( 6.411 s\n", - "# In[203] def experiment_compare_upsampling_with_other_libraries( 5.247 s\n", - "# In[127] def test_profile_downsampling(\\n shape, new_shape, 4.845 s\n", - "# In[144] def experiment_shear_image(\\n downscale=4, degrees=30, 4.050 s\n", - "# In[159] if EFFORT >= 1:\\n visualize_filters({f\"\\'{name}\\'\": 3.849 s\n", - "# In[141] def experiment_zoom_image(original_image, num_frames=60) -> 3.785 s\n", - "# In[130] if EFFORT >= 1:\\n test_profile_upsampling((1024, 1024, 1), 3.693 s\n", - "# In[ 39] hh.pdoc_help(resampler.resize)\\nmedia.set_max_output_ 3.416 s\n", - "# In[191] def test_inverse_convolution_2d(\\n gridscale=2.0, 3.136 s\n", - "# In[187] def visualize_prefiltering_as_scale_is_varied(\\n shape=( 2.913 s\n", - "# In[ 83] def test_that_all_resize_and_resample_agree(shape=(3, 2, 2) 2.820 s\n", - "# In[189] def experiment_with_convolution() -> None:\\n # https:// 2.764 s\n", - "# In[114] # This analysis is only for 1D resize; it fails to account 2.685 s\n", - "# In[184] def get_text_image(shape=(200,) * 2) -> _NDArray:\\n image 2.670 s\n", - "# In[172] def compare_boundary_rules_on_cropped_windows_of_images(\\n 2.518 s\n", - "# In[161] if EFFORT >= 1:\\n visualize_filter_frequency_response(\\n 2.232 s\n", - "# In[145] def test_tensorflow_optimize_image_for_desired_upsampling( 2.201 s\n", - "# In[148] def test_jax_optimize_image_for_desired_upsampling(\\n 2.110 s\n", - "# In[209] def visualize_boundary_rules_across_libraries(*, filter=\\' 2.097 s\n", - "# In[170] def visualize_all_boundary_rules_in_1d() -> None:\\n \"\"\" 1.954 s\n" + "# Total time: 96.02 s\n", + "# In[176] def experiment_compare_downsampling_with_other_libraries( 6.831 s\n", + "# In[174] def experiment_compare_upsampling_with_other_libraries( 5.196 s\n", + "# In[ 99] def test_profile_downsampling(\\n shape, new_shape, 4.776 s\n", + "# In[102] if EFFORT >= 1:\\n test_profile_upsampling((1024, 1024, 1), 4.435 s\n", + "# In[113] def experiment_zoom_image(original_image, num_frames=60) -> 3.822 s\n", + "# In[131] if EFFORT >= 1:\\n visualize_filters({f\"\\'{name}\\'\": 3.652 s\n", + "# In[116] def experiment_shear_image(\\n downscale=4, degrees=30, 3.264 s\n", + "# In[ 39] hh.pdoc_help(resampler.resize)\\nhh.no_vertical_scroll() 3.242 s\n", + "# In[162] def test_inverse_convolution_2d(\\n gridscale=2.0, 3.164 s\n", + "# In[158] def visualize_prefiltering_as_scale_is_varied(\\n shape=( 2.829 s\n", + "# In[155] def get_text_image(shape=(200,) * 2) -> _NDArray:\\n image 2.696 s\n", + "# In[ 86] # This analysis is only for 1D resize; it fails to account 2.664 s\n", + "# In[ 63] def test_that_all_resize_and_resample_agree(shape=(3, 2, 2) 2.660 s\n", + "# In[160] def experiment_with_convolution() -> None:\\n # https:// 2.608 s\n", + "# In[143] def compare_boundary_rules_on_cropped_windows_of_images(\\n 2.274 s\n", + "# In[133] if EFFORT >= 1:\\n visualize_filter_frequency_response(\\n 2.242 s\n", + "# In[117] def test_tensorflow_optimize_image_for_desired_upsampling( 2.157 s\n", + "# In[120] def test_jax_optimize_image_for_desired_upsampling(\\n 2.002 s\n", + "# In[141] def visualize_all_boundary_rules_in_1d() -> None:\\n \"\"\" 1.946 s\n", + "# In[ 80] def test_jax_image_resize() -> None:\\n at_boundaries = [ 1.810 s\n" ] } ], @@ -13945,14 +13013,14 @@ }, { "cell_type": "code", - "execution_count": 220, + "execution_count": 192, "metadata": { "execution": { - "iopub.execute_input": "2023-12-05T23:05:51.875750Z", - "iopub.status.busy": "2023-12-05T23:05:51.875579Z", - "iopub.status.idle": "2023-12-05T23:05:51.911924Z", - "shell.execute_reply": "2023-12-05T23:05:51.910883Z", - "shell.execute_reply.started": "2023-12-05T23:05:51.875735Z" + "iopub.execute_input": "2024-02-13T00:35:41.868572Z", + "iopub.status.busy": "2024-02-13T00:35:41.868036Z", + "iopub.status.idle": "2024-02-13T00:35:41.901612Z", + "shell.execute_reply": "2024-02-13T00:35:41.900951Z", + "shell.execute_reply.started": "2024-02-13T00:35:41.868551Z" }, "lines_to_next_cell": 2 }, diff --git a/resampler_notebook.py b/resampler_notebook.py index 277b20f..5f6e4b9 100644 --- a/resampler_notebook.py +++ b/resampler_notebook.py @@ -378,10 +378,8 @@ def running_in_notebook() -> bool: # %% -EFFORT: Literal[0, 1, 2, 3] = 1 +EFFORT: Literal[0, 1, 2, 3] = hh.get_env_int('EFFORT', 1) # type: ignore[assignment] """Controls the breadth and precision of the notebook experiments; 0 <= value <= 3.""" -if not running_in_notebook(): - EFFORT = 0 # Otherwise, invocations of doctest or pytest would recurse infinitely. # %% _ORIGINAL_GLOBALS = list(globals()) @@ -1004,20 +1002,6 @@ def run(src_shape, dst_shape) -> None: # # Tests -# %% -def test_precision() -> None: - _check_eq(resampler._real_precision(np.dtype(np.float32)), np.float32) - _check_eq(resampler._real_precision(np.dtype(np.float64)), np.float64) - _check_eq(resampler._real_precision(np.dtype(np.complex64)), np.float32) - _check_eq(resampler._real_precision(np.dtype(np.complex128)), np.float64) - - t = resampler._get_precision(None, [np.dtype(np.complex64)], [np.dtype(np.float64)]) - _check_eq(t, np.complex128) - - -test_precision() - - # %% def test_cached_sampling_of_1d_function(radius=2.0) -> None: def func(x: _ArrayLike) -> _NDArray: # Lanczos kernel @@ -1087,25 +1071,6 @@ def evaluate(array: _NDArray) -> _NDArray: test_cached_sampling_of_1d_function() -# %% -def test_downsample_in_2d_using_box_filter() -> None: - for shape in [(6, 6), (4, 4)]: - for ch in [1, 2, 3, 4]: - array = np.ones((*shape, ch), np.float32) - new = resampler._downsample_in_2d_using_box_filter(array, (2, 2)) - _check_eq(new.shape, (2, 2, ch)) - assert np.allclose(new, 1.0) - for shape in [(6, 6), (4, 4)]: - array = np.ones(shape, np.float32) - new = resampler._downsample_in_2d_using_box_filter(array, (2, 2)) - _check_eq(new.shape, (2, 2)) - assert np.allclose(new, 1.0) - - -if EFFORT >= 1 and using_numba: - test_downsample_in_2d_using_box_filter() - - # %% def test_profile_downsample_in_2d_using_box_filter(shape=(512, 512)) -> None: array = np.ones((4096, 4096)) @@ -1117,256 +1082,6 @@ def test_profile_downsample_in_2d_using_box_filter(shape=(512, 512)) -> None: # 3.43 ms -# %% -def test_block_shape_with_min_size(debug=False, **kwargs) -> None: - shape = 2, 3, 4 - for min_size in range(1, math.prod(shape) + 1): - block_shape = resampler._block_shape_with_min_size(shape, min_size, **kwargs) - if debug: - print(min_size, block_shape) - assert np.all(np.array(block_shape) >= 1) - assert np.all(block_shape <= shape) - assert min_size <= math.prod(block_shape) <= math.prod(shape) - - -test_block_shape_with_min_size(compact=True) -test_block_shape_with_min_size(compact=False) - - -# %% -def test_split_2d() -> None: - numpy_array = np.random.default_rng(0).choice([1, 2, 3, 4], (5, 8)) - for arraylib in resampler.ARRAYLIBS: - array = resampler._make_array(numpy_array, arraylib) - blocks = resampler._split_array_into_blocks(array, [2, 3]) - blocks = resampler._map_function_over_blocks(blocks, lambda x: 2 * x) - new = resampler._merge_array_from_blocks(blocks) - _check_eq(resampler._arr_arraylib(new), arraylib) - _check_eq(np.sum(resampler._map_function_over_blocks(blocks, lambda _: 1)), 9) - _check_eq(resampler._arr_numpy(new), 2 * numpy_array) - - -if EFFORT >= 1: - test_split_2d() - - -# %% -def test_split_3d() -> None: - shape = 4, 3, 2 - numpy_array = np.random.default_rng(0).choice([1, 2, 3, 4], shape) - - for arraylib in resampler.ARRAYLIBS: - array = resampler._make_array(numpy_array, arraylib) - for min_size in range(1, math.prod(shape) + 1): - block_shape = resampler._block_shape_with_min_size(shape, min_size) - blocks = resampler._split_array_into_blocks(array, block_shape) - blocks = resampler._map_function_over_blocks(blocks, lambda x: x**2) - new = resampler._merge_array_from_blocks(blocks) - _check_eq(resampler._arr_arraylib(new), arraylib) - _check_eq(resampler._arr_numpy(new), numpy_array**2) - - def check_block_shape(block) -> None: - assert np.all(np.array(block.shape) >= 1) - assert np.all(np.array(block.shape) <= shape) - - resampler._map_function_over_blocks(blocks, check_block_shape) - - -if EFFORT >= 1: - test_split_3d() - - -# %% -def test_split_prefix_dims() -> None: - shape = 2, 3, 2 - array = np.arange(math.prod(shape)).reshape(shape) - - for min_size in range(1, math.prod(shape[:2]) + 1): - block_shape = resampler._block_shape_with_min_size(shape[:2], min_size) - blocks = resampler._split_array_into_blocks(array, block_shape) - - new_blocks = resampler._map_function_over_blocks(blocks, lambda x: x**2) - new = resampler._merge_array_from_blocks(new_blocks) - _check_eq(new, array**2) - - new_blocks = resampler._map_function_over_blocks(blocks, lambda x: x.sum(axis=-1)) - new = resampler._merge_array_from_blocks(new_blocks) - _check_eq(new, array.sum(axis=-1)) - - -test_split_prefix_dims() - - -# %% -def test_linear_boundary() -> None: - index = np.array([[-3], [-2], [-1], [0], [1], [2], [3], [2], [3]]) - weight = np.array([[1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [1.0], [0.0], [0.0]]) - size = 2 - index, weight = resampler.LinearExtendSamples()(index, weight, size, resampler.DualGridtype()) - expected_weight = [ - [0, 4, -3, 0, 0], - [0, 3, -2, 0, 0], - [0, 2, -1, 0, 0], - [1, 0, 0, 0, 0], - [1, 0, 0, 0, 0], - [0, 0, 0, -1, 2], - [0, 0, 0, -2, 3], - [0, 0, 0, 0, 0], - [0, 0, 0, 0, 0], - ] - assert np.allclose(weight, expected_weight) - expected_index = [ - [0, 0, 1, 0, 0], - [0, 0, 1, 0, 0], - [0, 0, 1, 0, 0], - [0, 0, 0, 0, 0], - [1, 1, 1, 1, 1], - [1, 1, 1, 0, 1], - [1, 1, 1, 0, 1], - [1, 1, 1, 1, 1], - [1, 1, 1, 1, 1], - ] - assert np.all(index == expected_index) - - -test_linear_boundary() - - -# %% -def test_gamma() -> None: - dtypes = 'uint8 uint16 uint32'.split() - for config1 in itertools.product(resampler.ARRAYLIBS, resampler.GAMMAS, dtypes): - arraylib, gamma_name, dtype = config1 - gamma = resampler._get_gamma(gamma_name) - if arraylib == 'torch' and dtype in ['uint16', 'uint32']: - continue # "The only supported types are: ..., int64, int32, int16, int8, uint8, and bool." - int_max = np.iinfo(dtype).max - precision = 'float32' if np.iinfo(dtype).bits < 32 else 'float64' - values = list(range(256)) + list(range(int_max - 255, int_max)) + [int_max] - array_numpy = np.array(values, dtype) - array = resampler._make_array(array_numpy, arraylib) - decoded = gamma.decode(array, np.dtype(precision)) - _check_eq(resampler._arr_dtype(decoded), precision) - decoded_numpy = resampler._arr_numpy(decoded) - assert decoded_numpy.min() >= 0.0 and decoded_numpy.max() <= 1.0 - encoded = gamma.encode(decoded, dtype) - _check_eq(resampler._arr_dtype(encoded), dtype) - encoded_numpy = resampler._arr_numpy(encoded) - _check_eq(encoded_numpy, array_numpy) - - dtypes = 'float32 float64'.split() - precisions = 'float32 float64'.split() - for config2 in itertools.product(resampler.ARRAYLIBS, resampler.GAMMAS, dtypes, precisions): - arraylib, gamma_name, dtype, precision = config2 - gamma = resampler._get_gamma(gamma_name) - array_numpy = np.linspace(0.0, 1.0, 100, dtype=dtype) - array = resampler._make_array(array_numpy, arraylib) - decoded = gamma.decode(array, np.dtype(precision)) - _check_eq(resampler._arr_dtype(decoded), precision) - encoded = gamma.encode(decoded, dtype) - _check_eq(resampler._arr_dtype(encoded), dtype) - assert np.allclose(resampler._arr_numpy(encoded), array_numpy) - - -if EFFORT >= 1: - test_gamma() - - -# %% -def test_create_resize_matrix_for_trapezoid_filter(src_size, dst_size, debug=False) -> None: - filter = resampler.TrapezoidFilter() - if 0: - scaling = dst_size / src_size - radius = 0.5 + 0.5 * min(scaling, 1.0 / scaling) - print(radius) - filter = resampler.TrapezoidFilter(radius=radius) - - resize_matrix, unused_cval_weight = resampler._create_resize_matrix( - src_size, - dst_size, - src_gridtype=resampler.DualGridtype(), - dst_gridtype=resampler.DualGridtype(), - boundary=resampler._get_boundary('reflect'), - filter=filter, - ) - resize_matrix = resize_matrix.toarray() - if debug: - print(resize_matrix) - print(resize_matrix.sum(axis=0)) - print(resize_matrix.sum(axis=1)) - assert resize_matrix.sum(axis=0).var() < 1e-10 - assert resize_matrix.sum(axis=1).var() < 1e-10 - - -if 1: - test_create_resize_matrix_for_trapezoid_filter(src_size=6, dst_size=2) - test_create_resize_matrix_for_trapezoid_filter(src_size=7, dst_size=3) - test_create_resize_matrix_for_trapezoid_filter(src_size=7, dst_size=6) - test_create_resize_matrix_for_trapezoid_filter(src_size=14, dst_size=13) -if 1: - test_create_resize_matrix_for_trapezoid_filter(src_size=3, dst_size=6) - test_create_resize_matrix_for_trapezoid_filter(src_size=3, dst_size=12) - test_create_resize_matrix_for_trapezoid_filter(src_size=3, dst_size=11) - test_create_resize_matrix_for_trapezoid_filter(src_size=3, dst_size=16) - - -# %% -def test_that_resize_matrices_are_equal_across_arraylib() -> None: - src_sizes = range(1, 6) - dst_sizes = range(1, 6) - for config in itertools.product(src_sizes, dst_sizes): - src_size, dst_size = config - - def resize_matrix(arraylib: str) -> _TensorflowTensor: - return resampler._create_resize_matrix( - src_size, - dst_size, - src_gridtype=resampler.DualGridtype(), - dst_gridtype=resampler.DualGridtype(), - boundary=resampler._get_boundary('reflect'), - filter=resampler._get_filter('lanczos3'), - translate=0.8, - dtype=np.float32, - arraylib=arraylib, - )[0] - - numpy_array = resize_matrix('numpy').toarray() - tensorflow_array = tf.sparse.to_dense(resize_matrix('tensorflow')).numpy() - torch_array = resize_matrix('torch').to_dense().numpy() - jax_array = np.asarray(resize_matrix('jax').todense()) # to_py() deprecated. - assert np.allclose(tensorflow_array, numpy_array) - assert np.allclose(torch_array, numpy_array) - assert np.allclose(jax_array, numpy_array) - - -if EFFORT >= 1: - test_that_resize_matrices_are_equal_across_arraylib() - - -# %% -def test_that_resize_combinations_are_affine() -> None: - dst_sizes = 1, 2, 3, 4, 9, 20, 21, 22, 31 - for config in itertools.product(resampler.BOUNDARIES, dst_sizes): - boundary, dst_size = config - resize_matrix, cval_weight = resampler._create_resize_matrix( - 21, - dst_size, - src_gridtype=resampler.DualGridtype(), - dst_gridtype=resampler.DualGridtype(), - boundary=resampler._get_boundary(boundary), - filter=resampler.TriangleFilter(), - scale=0.5, - translate=0.3, - ) - if cval_weight is None: - row_sum = np.asarray(resize_matrix.sum(axis=1)).ravel() - state = config, resize_matrix.todense(), row_sum - assert np.allclose(row_sum, 1.0, rtol=0, atol=1e-6), state - - -test_that_resize_combinations_are_affine() - - # %% def test_that_very_large_cval_causes_numerical_noise_to_appear(debug: bool = False) -> None: resize_matrix, _ = resampler._create_resize_matrix( @@ -1388,18 +1103,6 @@ def test_that_very_large_cval_causes_numerical_noise_to_appear(debug: bool = Fal test_that_very_large_cval_causes_numerical_noise_to_appear() -# %% -def test_sparse_csr_matrix_duplicate_entries_are_summed() -> None: - indptr = np.array([0, 2, 3, 6]) - indices = np.array([0, 2, 2, 0, 1, 0]) - data = np.array([1, 2, 3, 4, 5, 3]) - new = scipy.sparse.csr_matrix((data, indices, indptr), shape=(3, 3)).toarray() - _check_eq(new, [[1, 0, 2], [0, 0, 3], [7, 5, 0]]) - - -test_sparse_csr_matrix_duplicate_entries_are_summed() - - # %% def test_jax_jit_digital_filter() -> None: jitted = jax.jit(resampler._apply_digital_filter_1d, static_argnums=(1, 2, 3, 4, 5, 6)) @@ -1449,53 +1152,6 @@ def inverse_convolution(array: resampler._Array) -> resampler._Array: test_apply_digital_filter_1d_quick() -# %% -def test_linear_precision_of_1d_primal_upsampling() -> None: - array = np.arange(7.0) - new = resampler.resize(array, (13,), gridtype='primal', filter='triangle') - with np.printoptions(linewidth=300): - _check_eq(new, np.arange(13) / 2) - - -test_linear_precision_of_1d_primal_upsampling() - - -# %% -def test_linear_precision_of_2d_primal_upsampling() -> None: - shape = 3, 5 - new_shape = 5, 9 - array = np.moveaxis(np.indices(shape, np.float32), 0, -1) @ [10, 1] - new = resampler.resize(array, new_shape, gridtype='primal', filter='triangle') - with np.printoptions(linewidth=300): - expected = np.moveaxis(np.indices(new_shape, np.float32), 0, -1) @ [10, 1] / 2 - _check_eq(new, expected) - - -test_linear_precision_of_2d_primal_upsampling() - - -# %% -def test_resize_of_complex_value_type() -> None: - for arraylib in resampler.ARRAYLIBS: - array = resampler._make_array([1 + 2j, 3 + 6j], arraylib) - new = resampler._original_resize(array, (4,), filter='triangle') - assert np.allclose(new, [1 + 2j, 1.5 + 3j, 2.5 + 5j, 3 + 6j]) - - -if EFFORT >= 1: - test_resize_of_complex_value_type() - - -# %% -def test_resize_of_integer_type() -> None: - array = np.array([1, 6]) - new = resampler.resize(array, (4,), filter='triangle') - assert np.allclose(new, [1, 2, 5, 6]) - - -test_resize_of_integer_type() - - # %% def test_order_of_dimensions_does_not_affect_resize_results(step=3) -> None: shapes = [(3, 4, 5), (3, 2, 4), (6, 2, 2), (1, 1, 1)] @@ -1533,35 +1189,6 @@ def test_order_of_dimensions_does_not_affect_resize_results(step=3) -> None: test_order_of_dimensions_does_not_affect_resize_results() -# %% -def test_apply_digital_filter_1d(cval=-10.0, shape=(7, 8)) -> None: - original = np.arange(math.prod(shape), dtype=np.float32).reshape(shape) + 10 - array1 = original.copy() - filters = 'cardinal3 cardinal5'.split() - for config in itertools.product(resampler.GRIDTYPES, resampler.BOUNDARIES, filters): - gridtype, boundary, filter = config - if gridtype == 'primal' and boundary in ('wrap', 'tile'): - continue # Last value on each dimension is ignored and so will not match. - array2 = array1 - for dim in range(array2.ndim): - array2 = resampler._apply_digital_filter_1d( - array2, - resampler._get_gridtype(gridtype), - resampler._get_boundary(boundary), - cval, - resampler._get_filter(filter), - axis=dim, - ) - bspline = resampler.BsplineFilter(degree=int(filter[-1:])) - array3 = resampler.resize( - array2, array2.shape, gridtype=gridtype, boundary=boundary, cval=cval, filter=bspline - ) - assert np.allclose(array3, original), config - - -test_apply_digital_filter_1d() - - # %% def test_apply_resize_to_batch_of_images( num_images=10, shape=(32, 32), new_shape=(128, 128), debug=False @@ -1582,42 +1209,6 @@ def test_apply_resize_to_batch_of_images( test_apply_resize_to_batch_of_images() -# %% -def test_resample_small_array(arraylib: str) -> None: - shape = 2, 3 - new_shape = 3, 4 - array = np.arange(math.prod(shape) * 3, dtype=np.float32).reshape(shape + (3,)) - coords = np.moveaxis(np.indices(new_shape) + 0.5, 0, -1) / new_shape - array = resampler._make_array(array, arraylib) - upsampled = resampler.resample(array, coords) - _check_eq(upsampled.shape, (*new_shape, 3)) - coords = np.moveaxis(np.indices(shape) + 0.5, 0, -1) / shape - downsampled = resampler.resample(upsampled, coords) - rms = get_rms(array, downsampled) - assert 0.07 <= rms <= 0.08, rms - - -def test_resample_small_arrays() -> None: - for arraylib in resampler.ARRAYLIBS: - test_resample_small_array(arraylib=arraylib) - - -if EFFORT >= 1: - test_resample_small_arrays() - - -# %% -def test_identity_resampling_with_many_boundary_rules(filter: resampler.Filter) -> None: - for boundary in resampler.BOUNDARIES: - array = np.arange(6, dtype=np.float32).reshape(2, 3) - coords = (np.moveaxis(np.indices(array.shape), 0, -1) + 0.5) / array.shape - new_array = resampler.resample(array, coords, boundary=boundary, cval=10000, filter=filter) - assert np.allclose(new_array, array), boundary - - -test_identity_resampling_with_many_boundary_rules(resampler.LanczosFilter(radius=5, sampled=False)) - - # %% def test_resample_scenario1() -> None: """Resample a grayscale image with `array.shape = height, width` onto a new grayscale image @@ -1679,20 +1270,6 @@ def test_resample_scenario6() -> None: test_resample_scenario6() -# %% -def test_identity_resampling() -> None: - shape = 3, 2, 5 - array = np.random.default_rng(0).random(shape) - coords = (np.moveaxis(np.indices(array.shape), 0, -1) + 0.5) / array.shape - new = resampler.resample(array, coords) - assert np.allclose(new, array, rtol=0, atol=1e-6) - new = resampler.resample(array, coords, filter=resampler.LanczosFilter(radius=3, sampled=False)) - assert np.allclose(new, array) - - -test_identity_resampling() - - # %% def test_that_all_resize_and_resample_agree(shape=(3, 2, 2), new_shape=(4, 2, 4)) -> None: assert np.all(np.array(new_shape) >= np.array(shape)) @@ -1754,113 +1331,6 @@ def test_that_all_resize_and_resample_agree(shape=(3, 2, 2), new_shape=(4, 2, 4) test_that_all_resize_and_resample_agree() # ~5.5 s on 1st run due to jax compiles; then ~450 ms. -# %% -def test_resample_of_complex_value_type() -> None: - array = np.array([1 + 2j, 3 + 6j]) - new = resampler.resample(array, (0.125, 0.375, 0.625, 0.875), filter='triangle') - assert np.allclose(new, [1 + 2j, 1.5 + 3j, 2.5 + 5j, 3 + 6j]) - - -test_resample_of_complex_value_type() - - -# %% -def test_resample_of_integer_type() -> None: - array = np.array([1, 6]) - new = resampler.resample(array, (0.125, 0.375, 0.625, 0.875), filter='triangle') - assert np.allclose(new, [1, 2, 5, 6]) - - -test_resample_of_integer_type() - - -# %% -def test_resample_using_coords_of_various_shapes(debug=False) -> None: - for array in [ - 8, - [7], - [0, 1, 6, 6], - [[0, 1], [10, 16]], - [[0], [1], [6], [6]], - ]: - array = np.array(array, np.float64) - for shape in [(), (1,), (2,), (1, 1), (1, 2), (3, 1), (2, 2)]: - coords = np.full(shape, 0.4) - try: - new = resampler.resample(array, coords, filter='triangle', dtype=np.float32).tolist() - except ValueError: - new = None - if debug: - print(f'{array.tolist()!s:30} {coords.shape!s:8} {new!s}') - _check_eq(new is None, coords.ndim >= 2 and coords.shape[-1] > max(array.ndim, 1)) - - -test_resample_using_coords_of_various_shapes() - - -# %% -def test_resize_using_resample(shape=(3, 2, 5), new_shape=(4, 2, 7), step=37) -> None: - assert np.all(np.array(shape) <= new_shape) - array = np.random.default_rng(0).random(shape) - scale = 1.1 - translate = -0.4, -0.03, 0.4 - gammas = 'identity power2'.split() # Sublist of resampler.GAMMAS. - sequences = [resampler.GRIDTYPES, resampler.BOUNDARIES, resampler.FILTERS, gammas] - assert step == 1 or all(len(sequence) % step != 0 for sequence in sequences) - configs = itertools.product(*sequences) # len(configs) = math.prod([2, 12, 19, 2]) = 912. - for config in itertools.islice(configs, 0, None, step): - gridtype, boundary, filter, gamma = config - kwargs = dict(gridtype=gridtype, boundary=boundary, filter=filter) - kwargs |= dict(gamma=gamma, scale=scale, translate=translate) - expected = resampler._original_resize(array, new_shape, **kwargs) - new_array = resampler._resize_using_resample(array, new_shape, **kwargs) - assert np.allclose(new_array, expected, rtol=0, atol=1e-7), config - - -test_resize_using_resample() - - -# %% -def test_resize_using_resample_of_complex_value_type() -> None: - array = np.array([1 + 2j, 3 + 6j]) - new = resampler._resize_using_resample(array, (4,), filter='triangle') - assert np.allclose(new, [1 + 2j, 1.5 + 3j, 2.5 + 5j, 3 + 6j]) - - -test_resize_using_resample_of_complex_value_type() - - -# %% -def test_resizer_produces_correct_shape(resizer, filter: str = 'lanczos3') -> None: - tol: Any = dict(rtol=0, atol=1e-7) - np.allclose(resizer(np.ones((11,)), (13,), filter=filter), np.ones((13,)), **tol) - np.allclose(resizer(np.ones((8, 8)), (5, 20), filter=filter), np.ones((5, 20)), **tol) - np.allclose(resizer(np.ones((11, 10, 3)), (13, 7), filter=filter), np.ones((13, 7, 3)), **tol) - - -# %% -def test_resizers_produce_correct_shape() -> None: - test_resizer_produces_correct_shape(resampler.resize) - for arraylib in resampler.ARRAYLIBS: - resizer = functools.partial(resampler.resize_in_arraylib, arraylib=arraylib) - test_resizer_produces_correct_shape(resizer) - - -if EFFORT >= 1: - test_resizers_produce_correct_shape() - -# %% -test_resizer_produces_correct_shape(resampler.pil_image_resize) -test_resizer_produces_correct_shape(resampler.cv_resize, 'lanczos4') -test_resizer_produces_correct_shape(resampler.scipy_ndimage_resize, 'cardinal3') -test_resizer_produces_correct_shape(resampler.skimage_transform_resize, 'cardinal3') -if EFFORT >= 1: - test_resizer_produces_correct_shape(resampler.tf_image_resize) -test_resizer_produces_correct_shape(resampler.torch_nn_resize, 'sharpcubic') -if EFFORT >= 1: - test_resizer_produces_correct_shape(resampler.jax_image_resize, 'lanczos3') - - # %% [markdown] # # Other libs (PIL, cv, tf, torch, ...) @@ -4064,7 +3534,7 @@ def visualize_boundary_rules_in_1d( and boundary in ['clamp', 'border'] and filter not in ['box', 'triangle'] ) or (resizer is resampler.scipy_ndimage_resize and boundary == 'border') - assert discrepancy == expected_discrepancy, (resizer, filter, boundary) + assert discrepancy == expected_discrepancy, (resizer, filter, boundary, discrepancy) plt.subplots_adjust(left=0.035) # text = f"filter='{filter}'" if row_index == 0 else f"'{filter}'" @@ -6138,16 +5608,6 @@ def visualize_boundary_rules_across_libraries(*, filter='triangle', cval=0.0) -> # # Run external tools -# %% -def run_pytest_command() -> None: # (This function name cannot end in 'test', else recursion.) - assert running_in_notebook() - hh.run('pytest -qq || true') - - -if EFFORT >= 1: - run_pytest_command() - - # %% def run_lint() -> None: """Run checks on *.py notebook code (saved using jupytext or from menu).""" diff --git a/test_resampler.py b/test_resampler.py index 4c6b64a..6ba3960 100644 --- a/test_resampler.py +++ b/test_resampler.py @@ -7,6 +7,7 @@ from __future__ import annotations from collections.abc import Callable +import functools import itertools import math import os @@ -23,7 +24,7 @@ _NDArray = Any _TensorflowTensor = Any -# pylint: disable=protected-access, missing-function-docstring +# pylint: disable=protected-access, missing-function-docstring, too-many-public-methods # Silence "WARNING:absl:No GPU/TPU found, falling back to CPU". os.environ['JAX_PLATFORM_NAME'] = 'cpu' @@ -259,6 +260,13 @@ def test_create_resize_matrix_for_trapezoid_filter(self) -> None: assert resize_matrix.sum(axis=0).var() < 1e-10 assert resize_matrix.sum(axis=1).var() < 1e-10 + def test_sparse_csr_matrix_duplicate_entries_are_summed(self) -> None: + indptr = np.array([0, 2, 3, 6]) + indices = np.array([0, 2, 2, 0, 1, 0]) + data = np.array([1, 2, 3, 4, 5, 3]) + new = scipy.sparse.csr_matrix((data, indices, indptr), shape=(3, 3)).toarray() + _check_eq(new, [[1, 0, 2], [0, 0, 3], [7, 5, 0]]) + def test_that_resize_matrices_are_equal_across_arraylib(self) -> None: src_sizes = range(1, 6) dst_sizes = range(1, 6) @@ -318,6 +326,167 @@ def test_that_resize_combinations_are_affine(self) -> None: row_sum = np.asarray(resize_matrix.sum(axis=1)).ravel() assert np.allclose(row_sum, 1.0, rtol=0, atol=1e-6), (resize_matrix.todense(), row_sum) + def test_linear_precision_of_1d_primal_upsampling(self) -> None: + array = np.arange(7.0) + new = resampler.resize(array, (13,), gridtype='primal', filter='triangle') + with np.printoptions(linewidth=300): + _check_eq(new, np.arange(13) / 2) + + def test_linear_precision_of_2d_primal_upsampling(self) -> None: + shape = 3, 5 + new_shape = 5, 9 + array = np.moveaxis(np.indices(shape, np.float32), 0, -1) @ [10, 1] + new = resampler.resize(array, new_shape, gridtype='primal', filter='triangle') + with np.printoptions(linewidth=300): + expected = np.moveaxis(np.indices(new_shape, np.float32), 0, -1) @ [10, 1] / 2 + _check_eq(new, expected) + + def test_resize_of_complex_value_type(self) -> None: + for arraylib in resampler.ARRAYLIBS: + array = resampler._make_array([1 + 2j, 3 + 6j], arraylib) + new = resampler._original_resize(array, (4,), filter='triangle') + assert np.allclose(new, [1 + 2j, 1.5 + 3j, 2.5 + 5j, 3 + 6j]) + + def test_resize_of_integer_type(self) -> None: + array = np.array([1, 6]) + new = resampler.resize(array, (4,), filter='triangle') + assert np.allclose(new, [1, 2, 5, 6]) + + def test_apply_digital_filter_1d(self) -> None: + cval = -10.0 + shape = 7, 8 + original = np.arange(math.prod(shape), dtype=np.float32).reshape(shape) + 10 + array1 = original.copy() + filters = 'cardinal3 cardinal5'.split() + for config in itertools.product(resampler.GRIDTYPES, resampler.BOUNDARIES, filters): + gridtype, boundary, filter = config + with self.subTest(config=config): + if gridtype == 'primal' and boundary in ('wrap', 'tile'): + continue # Last value on each dimension is ignored and so will not match. + array2 = array1 + for dim in range(array2.ndim): + array2 = resampler._apply_digital_filter_1d( + array2, + resampler._get_gridtype(gridtype), + resampler._get_boundary(boundary), + cval, + resampler._get_filter(filter), + axis=dim, + ) + bspline = resampler.BsplineFilter(degree=int(filter[-1:])) + array3 = resampler.resize( + array2, array2.shape, gridtype=gridtype, boundary=boundary, cval=cval, filter=bspline + ) + assert np.allclose(array3, original) + + def test_resample_small_arrays(self) -> None: + shape = 2, 3 + new_shape = 3, 4 + for arraylib in resampler.ARRAYLIBS: + with self.subTest(arraylib=arraylib): + array = np.arange(math.prod(shape) * 3, dtype=np.float32).reshape(shape + (3,)) + coords = np.moveaxis(np.indices(new_shape) + 0.5, 0, -1) / new_shape + array = resampler._make_array(array, arraylib) + upsampled = resampler.resample(array, coords) + _check_eq(upsampled.shape, (*new_shape, 3)) + coords = np.moveaxis(np.indices(shape) + 0.5, 0, -1) / shape + downsampled = resampler.resample(upsampled, coords) + rms = np.sqrt(np.mean(np.square(np.array(array) - np.array(downsampled)))).item() + assert 0.07 <= rms <= 0.08, rms + + def test_identity_resampling_with_many_boundary_rules(self) -> None: + filter = resampler.LanczosFilter(radius=5, sampled=False) + for boundary in resampler.BOUNDARIES: + with self.subTest(boundary=boundary): + array = np.arange(6, dtype=np.float32).reshape(2, 3) + coords = (np.moveaxis(np.indices(array.shape), 0, -1) + 0.5) / array.shape + new_array = resampler.resample(array, coords, boundary=boundary, cval=10000, filter=filter) + assert np.allclose(new_array, array), boundary + + def test_identity_resampling(self) -> None: + shape = 3, 2, 5 + array = np.random.default_rng(0).random(shape) + coords = (np.moveaxis(np.indices(array.shape), 0, -1) + 0.5) / array.shape + new = resampler.resample(array, coords) + assert np.allclose(new, array, rtol=0, atol=1e-6) + new = resampler.resample(array, coords, filter=resampler.LanczosFilter(radius=3, sampled=False)) + assert np.allclose(new, array) + + def test_resample_of_complex_value_type(self) -> None: + array = np.array([1 + 2j, 3 + 6j]) + new = resampler.resample(array, (0.125, 0.375, 0.625, 0.875), filter='triangle') + assert np.allclose(new, [1 + 2j, 1.5 + 3j, 2.5 + 5j, 3 + 6j]) + + def test_resample_of_integer_type(self) -> None: + array = np.array([1, 6]) + new = resampler.resample(array, (0.125, 0.375, 0.625, 0.875), filter='triangle') + assert np.allclose(new, [1, 2, 5, 6]) + + def test_resample_using_coords_of_various_shapes(self) -> None: + for array in [ + 8, + [7], + [0, 1, 6, 6], + [[0, 1], [10, 16]], + [[0], [1], [6], [6]], + ]: + with self.subTest(array=array): + array = np.array(array, np.float64) + for shape in [(), (1,), (2,), (1, 1), (1, 2), (3, 1), (2, 2)]: + coords = np.full(shape, 0.4) + try: + new = resampler.resample(array, coords, filter='triangle', dtype=np.float32).tolist() + except ValueError: + new = None + # print(f'{array.tolist()!s:30} {coords.shape!s:8} {new!s}') + _check_eq(new is None, coords.ndim >= 2 and coords.shape[-1] > max(array.ndim, 1)) + + def test_resize_using_resample(self) -> None: + shape = 3, 2, 5 + new_shape = 4, 2, 7 + step = 37 + assert np.all(np.array(shape) <= new_shape) + array = np.random.default_rng(0).random(shape) + scale = 1.1 + translate = -0.4, -0.03, 0.4 + gammas = 'identity power2'.split() # Sublist of resampler.GAMMAS. + sequences = [resampler.GRIDTYPES, resampler.BOUNDARIES, resampler.FILTERS, gammas] + assert step == 1 or all(len(sequence) % step != 0 for sequence in sequences) + configs = itertools.product(*sequences) # len(configs) = math.prod([2, 12, 19, 2]) = 912. + for config in itertools.islice(configs, 0, None, step): + gridtype, boundary, filter, gamma = config + with self.subTest(config=config): + kwargs = dict(gridtype=gridtype, boundary=boundary, filter=filter) + kwargs |= dict(gamma=gamma, scale=scale, translate=translate) + expected = resampler._original_resize(array, new_shape, **kwargs) + new_array = resampler._resize_using_resample(array, new_shape, **kwargs) + assert np.allclose(new_array, expected, rtol=0, atol=1e-7) + + def test_resize_using_resample_of_complex_value_type(self) -> None: + array = np.array([1 + 2j, 3 + 6j]) + new = resampler._resize_using_resample(array, (4,), filter='triangle') + assert np.allclose(new, [1 + 2j, 1.5 + 3j, 2.5 + 5j, 3 + 6j]) + + def test_resizers_produce_correct_shape(self) -> None: + configs: list[tuple[Callable[..., Any], str]] = [(resampler.resize, 'lanczos3')] + for arraylib in resampler.ARRAYLIBS: + resizer0 = functools.partial(resampler.resize_in_arraylib, arraylib=arraylib) + configs.append((resizer0, 'lanczos3')) + configs.append((resampler.pil_image_resize, 'lanczos3')) + configs.append((resampler.cv_resize, 'lanczos4')) + configs.append((resampler.scipy_ndimage_resize, 'cardinal3')) + configs.append((resampler.skimage_transform_resize, 'cardinal3')) + configs.append((resampler.tf_image_resize, 'lanczos3')) + configs.append((resampler.torch_nn_resize, 'sharpcubic')) + configs.append((resampler.jax_image_resize, 'lanczos3')) + for config in configs: + resizer, filter = config + with self.subTest(config=config): + tol: Any = dict(rtol=0, atol=1e-7) + np.allclose(resizer(np.ones((11,)), (13,), filter=filter), np.ones((13,)), **tol) + np.allclose(resizer(np.ones((8, 8)), (5, 20), filter=filter), np.ones((5, 20)), **tol) + np.allclose(resizer(np.ones((9, 8, 3)), (13, 7), filter=filter), np.ones((13, 7, 3)), **tol) + if __name__ == '__main__': unittest.main()