Skip to content

Commit

Permalink
Minimal scipy.fft.dct stub
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Dec 19, 2023
1 parent 97d7267 commit 1a1bd0a
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/compare.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from math import sqrt
from typing import cast

import cv2
import numpy as np
import numpy._typing as npt
import scipy.fft
from cv2.typing import MatLike
from scipy import fft

from utils import BGRA_CHANNEL_COUNT, MAXBYTE, ColorChannel, ImageShape, is_valid_image

Expand Down Expand Up @@ -98,7 +96,7 @@ def __cv2_phash(image: MatLike, hash_size: int = 8, highfreq_factor: int = 4):
img_size = hash_size * highfreq_factor
image = cv2.cvtColor(image, cv2.COLOR_BGRA2GRAY)
image = cv2.resize(image, (img_size, img_size), interpolation=cv2.INTER_AREA)
dct = cast(npt.NDArray[np.float64], scipy.fft.dct(scipy.fft.dct(image, axis=0), axis=1))
dct = fft.dct(fft.dct(image, axis=0), axis=1)
dct_low_frequency = dct[:hash_size, :hash_size]
median = np.median(dct_low_frequency)
return dct_low_frequency > median
Expand Down
55 changes: 55 additions & 0 deletions typings/scipy/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

from numpy.fft import ifft as ifft
from numpy.random import rand as rand, randn as randn
from scipy import (
cluster,
constants,
datasets,
fft,
fftpack,
integrate,
interpolate,
io,
linalg,
misc,
ndimage,
odr,
optimize,
signal,
sparse,
spatial,
special,
stats,
)
from scipy.__config__ import show as show_config
from scipy._lib._ccallback import LowLevelCallable
from scipy._lib._testutils import PytestTester
from scipy.version import version as __version__

__all__ = [
"cluster",
"constants",
"datasets",
"fft",
"fftpack",
"integrate",
"interpolate",
"io",
"linalg",
"misc",
"ndimage",
"odr",
"optimize",
"signal",
"sparse",
"spatial",
"special",
"stats",
"LowLevelCallable",
"test",
"show_config",
"__version__",
]

test: PytestTester
def __dir__() -> list[str]: ...
72 changes: 72 additions & 0 deletions typings/scipy/fft/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from numpy.fft import fftfreq, fftshift, ifftshift, rfftfreq
from scipy._lib._testutils import PytestTester
from scipy.fft._backend import register_backend, set_backend, set_global_backend, skip_backend
from scipy.fft._basic import (
fft,
fft2,
fftn,
hfft,
hfft2,
hfftn,
ifft,
ifft2,
ifftn,
ihfft,
ihfft2,
ihfftn,
irfft,
irfft2,
irfftn,
rfft,
rfft2,
rfftn,
)
from scipy.fft._fftlog import fhtoffset
from scipy.fft._fftlog_multimethods import fht, ifht
from scipy.fft._helper import next_fast_len
from scipy.fft._pocketfft.helper import get_workers, set_workers
from scipy.fft._realtransforms import dct, dctn, dst, dstn, idct, idctn, idst, idstn

__all__ = [
"fft",
"ifft",
"fft2",
"ifft2",
"fftn",
"ifftn",
"rfft",
"irfft",
"rfft2",
"irfft2",
"rfftn",
"irfftn",
"hfft",
"ihfft",
"hfft2",
"ihfft2",
"hfftn",
"ihfftn",
"fftfreq",
"rfftfreq",
"fftshift",
"ifftshift",
"next_fast_len",
"dct",
"idct",
"dst",
"idst",
"dctn",
"idctn",
"dstn",
"idstn",
"fht",
"ifht",
"fhtoffset",
"set_backend",
"skip_backend",
"set_global_backend",
"register_backend",
"get_workers",
"set_workers",
]
test: PytestTester
102 changes: 102 additions & 0 deletions typings/scipy/fft/_realtransforms.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
from _typeshed import Incomplete
from numpy import float64, generic
from numpy.typing import NDArray

__all__ = ["dct", "idct", "dst", "idst", "dctn", "idctn", "dstn", "idstn"]


def dctn(
x,
type=2,
s=None,
axes=None,
norm=None,
overwrite_x=False,
workers=None,
*,
orthogonalize=None,
): ...


def idctn(
x,
type=2,
s=None,
axes=None,
norm=None,
overwrite_x=False,
workers=None,
orthogonalize=None,
): ...


def dstn(
x,
type=2,
s=None,
axes=None,
norm=None,
overwrite_x=False,
workers=None,
orthogonalize=None,
): ...


def idstn(
x,
type=2,
s=None,
axes=None,
norm=None,
overwrite_x=False,
workers=None,
orthogonalize=None,
): ...


def dct(
x: NDArray[generic],
type: int = 2,
n: Incomplete | None = None,
axis: int = -1,
norm: Incomplete | None = None,
overwrite_x: bool = False,
workers: Incomplete | None = None,
orthogonalize: Incomplete | None = None,
) -> NDArray[float64]: ...


def idct(
x,
type=2,
n=None,
axis=-1,
norm=None,
overwrite_x=False,
workers=None,
orthogonalize=None,
): ...


def dst(
x,
type=2,
n=None,
axis=-1,
norm=None,
overwrite_x=False,
workers=None,
orthogonalize=None,
): ...


def idst(
x,
type=2,
n=None,
axis=-1,
norm=None,
overwrite_x=False,
workers=None,
orthogonalize=None,
): ...
1 change: 1 addition & 0 deletions typings/scipy/py.typed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
partial

0 comments on commit 1a1bd0a

Please sign in to comment.