Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/array_api_compat/common/_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def fft(
) -> Array:
res = xp.fft.fft(x, n=n, axis=axis, norm=norm)
if x.dtype in [xp.float32, xp.complex64]:
return res.astype(xp.complex64)
return res.astype(xp.complex64, copy=False)
return res

def ifft(
Expand All @@ -35,7 +35,7 @@ def ifft(
) -> Array:
res = xp.fft.ifft(x, n=n, axis=axis, norm=norm)
if x.dtype in [xp.float32, xp.complex64]:
return res.astype(xp.complex64)
return res.astype(xp.complex64, copy=False)
return res

def fftn(
Expand All @@ -49,7 +49,7 @@ def fftn(
) -> Array:
res = xp.fft.fftn(x, s=s, axes=axes, norm=norm)
if x.dtype in [xp.float32, xp.complex64]:
return res.astype(xp.complex64)
return res.astype(xp.complex64, copy=False)
return res

def ifftn(
Expand All @@ -63,7 +63,7 @@ def ifftn(
) -> Array:
res = xp.fft.ifftn(x, s=s, axes=axes, norm=norm)
if x.dtype in [xp.float32, xp.complex64]:
return res.astype(xp.complex64)
return res.astype(xp.complex64, copy=False)
return res

def rfft(
Expand All @@ -77,7 +77,7 @@ def rfft(
) -> Array:
res = xp.fft.rfft(x, n=n, axis=axis, norm=norm)
if x.dtype == xp.float32:
return res.astype(xp.complex64)
return res.astype(xp.complex64, copy=False)
return res

def irfft(
Expand All @@ -91,7 +91,7 @@ def irfft(
) -> Array:
res = xp.fft.irfft(x, n=n, axis=axis, norm=norm)
if x.dtype == xp.complex64:
return res.astype(xp.float32)
return res.astype(xp.float32, copy=False)
return res

def rfftn(
Expand All @@ -105,7 +105,7 @@ def rfftn(
) -> Array:
res = xp.fft.rfftn(x, s=s, axes=axes, norm=norm)
if x.dtype == xp.float32:
return res.astype(xp.complex64)
return res.astype(xp.complex64, copy=False)
return res

def irfftn(
Expand All @@ -119,7 +119,7 @@ def irfftn(
) -> Array:
res = xp.fft.irfftn(x, s=s, axes=axes, norm=norm)
if x.dtype == xp.complex64:
return res.astype(xp.float32)
return res.astype(xp.float32, copy=False)
return res

def hfft(
Expand All @@ -133,7 +133,7 @@ def hfft(
) -> Array:
res = xp.fft.hfft(x, n=n, axis=axis, norm=norm)
if x.dtype in [xp.float32, xp.complex64]:
return res.astype(xp.float32)
return res.astype(xp.float32, copy=False)
return res

def ihfft(
Expand All @@ -147,7 +147,7 @@ def ihfft(
) -> Array:
res = xp.fft.ihfft(x, n=n, axis=axis, norm=norm)
if x.dtype in [xp.float32, xp.complex64]:
return res.astype(xp.complex64)
return res.astype(xp.complex64, copy=False)
return res

def fftfreq(
Expand All @@ -163,7 +163,7 @@ def fftfreq(
raise ValueError(f"Unsupported device {device!r}")
res = xp.fft.fftfreq(n, d=d)
if dtype is not None:
return res.astype(dtype)
return res.astype(dtype, copy=False)
return res

def rfftfreq(
Expand All @@ -179,7 +179,7 @@ def rfftfreq(
raise ValueError(f"Unsupported device {device!r}")
res = xp.fft.rfftfreq(n, d=d)
if dtype is not None:
return res.astype(dtype)
return res.astype(dtype, copy=False)
return res

def fftshift(
Expand Down
Loading