Skip to content

Commit 54e351c

Browse files
authored
Merge pull request #468 from Nin17/fft-astype-copy
BUG: unnecessary copy in `.astype` if the output array is already the…
2 parents 76ad14a + b5c2df1 commit 54e351c

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

src/array_api_compat/common/_fft.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def fft(
2121
) -> Array:
2222
res = xp.fft.fft(x, n=n, axis=axis, norm=norm)
2323
if x.dtype in [xp.float32, xp.complex64]:
24-
return res.astype(xp.complex64)
24+
return res.astype(xp.complex64, copy=False)
2525
return res
2626

2727
def ifft(
@@ -35,7 +35,7 @@ def ifft(
3535
) -> Array:
3636
res = xp.fft.ifft(x, n=n, axis=axis, norm=norm)
3737
if x.dtype in [xp.float32, xp.complex64]:
38-
return res.astype(xp.complex64)
38+
return res.astype(xp.complex64, copy=False)
3939
return res
4040

4141
def fftn(
@@ -49,7 +49,7 @@ def fftn(
4949
) -> Array:
5050
res = xp.fft.fftn(x, s=s, axes=axes, norm=norm)
5151
if x.dtype in [xp.float32, xp.complex64]:
52-
return res.astype(xp.complex64)
52+
return res.astype(xp.complex64, copy=False)
5353
return res
5454

5555
def ifftn(
@@ -63,7 +63,7 @@ def ifftn(
6363
) -> Array:
6464
res = xp.fft.ifftn(x, s=s, axes=axes, norm=norm)
6565
if x.dtype in [xp.float32, xp.complex64]:
66-
return res.astype(xp.complex64)
66+
return res.astype(xp.complex64, copy=False)
6767
return res
6868

6969
def rfft(
@@ -77,7 +77,7 @@ def rfft(
7777
) -> Array:
7878
res = xp.fft.rfft(x, n=n, axis=axis, norm=norm)
7979
if x.dtype == xp.float32:
80-
return res.astype(xp.complex64)
80+
return res.astype(xp.complex64, copy=False)
8181
return res
8282

8383
def irfft(
@@ -91,7 +91,7 @@ def irfft(
9191
) -> Array:
9292
res = xp.fft.irfft(x, n=n, axis=axis, norm=norm)
9393
if x.dtype == xp.complex64:
94-
return res.astype(xp.float32)
94+
return res.astype(xp.float32, copy=False)
9595
return res
9696

9797
def rfftn(
@@ -105,7 +105,7 @@ def rfftn(
105105
) -> Array:
106106
res = xp.fft.rfftn(x, s=s, axes=axes, norm=norm)
107107
if x.dtype == xp.float32:
108-
return res.astype(xp.complex64)
108+
return res.astype(xp.complex64, copy=False)
109109
return res
110110

111111
def irfftn(
@@ -119,7 +119,7 @@ def irfftn(
119119
) -> Array:
120120
res = xp.fft.irfftn(x, s=s, axes=axes, norm=norm)
121121
if x.dtype == xp.complex64:
122-
return res.astype(xp.float32)
122+
return res.astype(xp.float32, copy=False)
123123
return res
124124

125125
def hfft(
@@ -133,7 +133,7 @@ def hfft(
133133
) -> Array:
134134
res = xp.fft.hfft(x, n=n, axis=axis, norm=norm)
135135
if x.dtype in [xp.float32, xp.complex64]:
136-
return res.astype(xp.float32)
136+
return res.astype(xp.float32, copy=False)
137137
return res
138138

139139
def ihfft(
@@ -147,7 +147,7 @@ def ihfft(
147147
) -> Array:
148148
res = xp.fft.ihfft(x, n=n, axis=axis, norm=norm)
149149
if x.dtype in [xp.float32, xp.complex64]:
150-
return res.astype(xp.complex64)
150+
return res.astype(xp.complex64, copy=False)
151151
return res
152152

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

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

185185
def fftshift(

0 commit comments

Comments
 (0)