From 28be896c80c2d3abf8e5c9427cca3c900c7b50d1 Mon Sep 17 00:00:00 2001 From: feature Date: Sun, 30 May 2021 17:16:48 +0300 Subject: [PATCH 1/2] Changed np.int to int as per deprecationWarning from numpy --- glymur/jp2k.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glymur/jp2k.py b/glymur/jp2k.py index 0f6f1167..4596070c 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -1081,7 +1081,7 @@ def __getitem__(self, pargs): if np.abs(np.log2(step) - np.round(np.log2(step))) > 1e-6: msg = "Row and column strides must be powers of 2." raise ValueError(msg) - rlevel = np.int(np.round(np.log2(step))) + rlevel = int(np.round(np.log2(step))) area = (0 if rows.start is None else rows.start, 0 if cols.start is None else cols.start, From 794fb35365bcc79cc0ce482736c8a2a39c881eff Mon Sep 17 00:00:00 2001 From: feature Date: Wed, 2 Jun 2021 14:26:15 +0300 Subject: [PATCH 2/2] Make rlevel calculation more efficient. proof: https://cocalc.com/8324bfc9-d3df-4304-a29c-a5ccf0283797/raw/power%20of%202.ipynb about 50 times faster. --- glymur/jp2k.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/glymur/jp2k.py b/glymur/jp2k.py index 4596070c..e3701896 100644 --- a/glymur/jp2k.py +++ b/glymur/jp2k.py @@ -1078,10 +1078,10 @@ def __getitem__(self, pargs): step = rows_step # Check if the step size is a power of 2. - if np.abs(np.log2(step) - np.round(np.log2(step))) > 1e-6: + rlevel = step.bit_length() - 1 + if step % (1 << rlevel) != 0: msg = "Row and column strides must be powers of 2." raise ValueError(msg) - rlevel = int(np.round(np.log2(step))) area = (0 if rows.start is None else rows.start, 0 if cols.start is None else cols.start,