Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/scipy/fft/_realtransforms.py: 71%

28 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-12 06:31 +0000

1from ._basic import _dispatch 

2from scipy._lib.uarray import Dispatchable 

3import numpy as np 

4 

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

6 

7 

8@_dispatch 

9def dctn(x, type=2, s=None, axes=None, norm=None, overwrite_x=False, 

10 workers=None, *, orthogonalize=None): 

11 """ 

12 Return multidimensional Discrete Cosine Transform along the specified axes. 

13 

14 Parameters 

15 ---------- 

16 x : array_like 

17 The input array. 

18 type : {1, 2, 3, 4}, optional 

19 Type of the DCT (see Notes). Default type is 2. 

20 s : int or array_like of ints or None, optional 

21 The shape of the result. If both `s` and `axes` (see below) are None, 

22 `s` is ``x.shape``; if `s` is None but `axes` is not None, then `s` is 

23 ``numpy.take(x.shape, axes, axis=0)``. 

24 If ``s[i] > x.shape[i]``, the ith dimension is padded with zeros. 

25 If ``s[i] < x.shape[i]``, the ith dimension is truncated to length 

26 ``s[i]``. 

27 If any element of `s` is -1, the size of the corresponding dimension of 

28 `x` is used. 

29 axes : int or array_like of ints or None, optional 

30 Axes over which the DCT is computed. If not given, the last ``len(s)`` 

31 axes are used, or all axes if `s` is also not specified. 

32 norm : {"backward", "ortho", "forward"}, optional 

33 Normalization mode (see Notes). Default is "backward". 

34 overwrite_x : bool, optional 

35 If True, the contents of `x` can be destroyed; the default is False. 

36 workers : int, optional 

37 Maximum number of workers to use for parallel computation. If negative, 

38 the value wraps around from ``os.cpu_count()``. 

39 See :func:`~scipy.fft.fft` for more details. 

40 orthogonalize : bool, optional 

41 Whether to use the orthogonalized DCT variant (see Notes). 

42 Defaults to ``True`` when ``norm="ortho"`` and ``False`` otherwise. 

43 

44 .. versionadded:: 1.8.0 

45 

46 Returns 

47 ------- 

48 y : ndarray of real 

49 The transformed input array. 

50 

51 See Also 

52 -------- 

53 idctn : Inverse multidimensional DCT 

54 

55 Notes 

56 ----- 

57 For full details of the DCT types and normalization modes, as well as 

58 references, see `dct`. 

59 

60 Examples 

61 -------- 

62 >>> import numpy as np 

63 >>> from scipy.fft import dctn, idctn 

64 >>> rng = np.random.default_rng() 

65 >>> y = rng.standard_normal((16, 16)) 

66 >>> np.allclose(y, idctn(dctn(y))) 

67 True 

68 

69 """ 

70 return (Dispatchable(x, np.ndarray),) 

71 

72 

73@_dispatch 

74def idctn(x, type=2, s=None, axes=None, norm=None, overwrite_x=False, 

75 workers=None, orthogonalize=None): 

76 """ 

77 Return multidimensional Inverse Discrete Cosine Transform along the specified axes. 

78 

79 Parameters 

80 ---------- 

81 x : array_like 

82 The input array. 

83 type : {1, 2, 3, 4}, optional 

84 Type of the DCT (see Notes). Default type is 2. 

85 s : int or array_like of ints or None, optional 

86 The shape of the result. If both `s` and `axes` (see below) are 

87 None, `s` is ``x.shape``; if `s` is None but `axes` is 

88 not None, then `s` is ``numpy.take(x.shape, axes, axis=0)``. 

89 If ``s[i] > x.shape[i]``, the ith dimension is padded with zeros. 

90 If ``s[i] < x.shape[i]``, the ith dimension is truncated to length 

91 ``s[i]``. 

92 If any element of `s` is -1, the size of the corresponding dimension of 

93 `x` is used. 

94 axes : int or array_like of ints or None, optional 

95 Axes over which the IDCT is computed. If not given, the last ``len(s)`` 

96 axes are used, or all axes if `s` is also not specified. 

97 norm : {"backward", "ortho", "forward"}, optional 

98 Normalization mode (see Notes). Default is "backward". 

99 overwrite_x : bool, optional 

100 If True, the contents of `x` can be destroyed; the default is False. 

101 workers : int, optional 

102 Maximum number of workers to use for parallel computation. If negative, 

103 the value wraps around from ``os.cpu_count()``. 

104 See :func:`~scipy.fft.fft` for more details. 

105 orthogonalize : bool, optional 

106 Whether to use the orthogonalized IDCT variant (see Notes). 

107 Defaults to ``True`` when ``norm="ortho"`` and ``False`` otherwise. 

108 

109 .. versionadded:: 1.8.0 

110 

111 Returns 

112 ------- 

113 y : ndarray of real 

114 The transformed input array. 

115 

116 See Also 

117 -------- 

118 dctn : multidimensional DCT 

119 

120 Notes 

121 ----- 

122 For full details of the IDCT types and normalization modes, as well as 

123 references, see `idct`. 

124 

125 Examples 

126 -------- 

127 >>> import numpy as np 

128 >>> from scipy.fft import dctn, idctn 

129 >>> rng = np.random.default_rng() 

130 >>> y = rng.standard_normal((16, 16)) 

131 >>> np.allclose(y, idctn(dctn(y))) 

132 True 

133 

134 """ 

135 return (Dispatchable(x, np.ndarray),) 

136 

137 

138@_dispatch 

139def dstn(x, type=2, s=None, axes=None, norm=None, overwrite_x=False, 

140 workers=None, orthogonalize=None): 

141 """ 

142 Return multidimensional Discrete Sine Transform along the specified axes. 

143 

144 Parameters 

145 ---------- 

146 x : array_like 

147 The input array. 

148 type : {1, 2, 3, 4}, optional 

149 Type of the DST (see Notes). Default type is 2. 

150 s : int or array_like of ints or None, optional 

151 The shape of the result. If both `s` and `axes` (see below) are None, 

152 `s` is ``x.shape``; if `s` is None but `axes` is not None, then `s` is 

153 ``numpy.take(x.shape, axes, axis=0)``. 

154 If ``s[i] > x.shape[i]``, the ith dimension is padded with zeros. 

155 If ``s[i] < x.shape[i]``, the ith dimension is truncated to length 

156 ``s[i]``. 

157 If any element of `shape` is -1, the size of the corresponding dimension 

158 of `x` is used. 

159 axes : int or array_like of ints or None, optional 

160 Axes over which the DST is computed. If not given, the last ``len(s)`` 

161 axes are used, or all axes if `s` is also not specified. 

162 norm : {"backward", "ortho", "forward"}, optional 

163 Normalization mode (see Notes). Default is "backward". 

164 overwrite_x : bool, optional 

165 If True, the contents of `x` can be destroyed; the default is False. 

166 workers : int, optional 

167 Maximum number of workers to use for parallel computation. If negative, 

168 the value wraps around from ``os.cpu_count()``. 

169 See :func:`~scipy.fft.fft` for more details. 

170 orthogonalize : bool, optional 

171 Whether to use the orthogonalized DST variant (see Notes). 

172 Defaults to ``True`` when ``norm="ortho"`` and ``False`` otherwise. 

173 

174 .. versionadded:: 1.8.0 

175 

176 Returns 

177 ------- 

178 y : ndarray of real 

179 The transformed input array. 

180 

181 See Also 

182 -------- 

183 idstn : Inverse multidimensional DST 

184 

185 Notes 

186 ----- 

187 For full details of the DST types and normalization modes, as well as 

188 references, see `dst`. 

189 

190 Examples 

191 -------- 

192 >>> import numpy as np 

193 >>> from scipy.fft import dstn, idstn 

194 >>> rng = np.random.default_rng() 

195 >>> y = rng.standard_normal((16, 16)) 

196 >>> np.allclose(y, idstn(dstn(y))) 

197 True 

198 

199 """ 

200 return (Dispatchable(x, np.ndarray),) 

201 

202 

203@_dispatch 

204def idstn(x, type=2, s=None, axes=None, norm=None, overwrite_x=False, 

205 workers=None, orthogonalize=None): 

206 """ 

207 Return multidimensional Inverse Discrete Sine Transform along the specified axes. 

208 

209 Parameters 

210 ---------- 

211 x : array_like 

212 The input array. 

213 type : {1, 2, 3, 4}, optional 

214 Type of the DST (see Notes). Default type is 2. 

215 s : int or array_like of ints or None, optional 

216 The shape of the result. If both `s` and `axes` (see below) are None, 

217 `s` is ``x.shape``; if `s` is None but `axes` is not None, then `s` is 

218 ``numpy.take(x.shape, axes, axis=0)``. 

219 If ``s[i] > x.shape[i]``, the ith dimension is padded with zeros. 

220 If ``s[i] < x.shape[i]``, the ith dimension is truncated to length 

221 ``s[i]``. 

222 If any element of `s` is -1, the size of the corresponding dimension of 

223 `x` is used. 

224 axes : int or array_like of ints or None, optional 

225 Axes over which the IDST is computed. If not given, the last ``len(s)`` 

226 axes are used, or all axes if `s` is also not specified. 

227 norm : {"backward", "ortho", "forward"}, optional 

228 Normalization mode (see Notes). Default is "backward". 

229 overwrite_x : bool, optional 

230 If True, the contents of `x` can be destroyed; the default is False. 

231 workers : int, optional 

232 Maximum number of workers to use for parallel computation. If negative, 

233 the value wraps around from ``os.cpu_count()``. 

234 See :func:`~scipy.fft.fft` for more details. 

235 orthogonalize : bool, optional 

236 Whether to use the orthogonalized IDST variant (see Notes). 

237 Defaults to ``True`` when ``norm="ortho"`` and ``False`` otherwise. 

238 

239 .. versionadded:: 1.8.0 

240 

241 Returns 

242 ------- 

243 y : ndarray of real 

244 The transformed input array. 

245 

246 See Also 

247 -------- 

248 dstn : multidimensional DST 

249 

250 Notes 

251 ----- 

252 For full details of the IDST types and normalization modes, as well as 

253 references, see `idst`. 

254 

255 Examples 

256 -------- 

257 >>> import numpy as np 

258 >>> from scipy.fft import dstn, idstn 

259 >>> rng = np.random.default_rng() 

260 >>> y = rng.standard_normal((16, 16)) 

261 >>> np.allclose(y, idstn(dstn(y))) 

262 True 

263 

264 """ 

265 return (Dispatchable(x, np.ndarray),) 

266 

267 

268@_dispatch 

269def dct(x, type=2, n=None, axis=-1, norm=None, overwrite_x=False, workers=None, 

270 orthogonalize=None): 

271 r"""Return the Discrete Cosine Transform of arbitrary type sequence x. 

272 

273 Parameters 

274 ---------- 

275 x : array_like 

276 The input array. 

277 type : {1, 2, 3, 4}, optional 

278 Type of the DCT (see Notes). Default type is 2. 

279 n : int, optional 

280 Length of the transform. If ``n < x.shape[axis]``, `x` is 

281 truncated. If ``n > x.shape[axis]``, `x` is zero-padded. The 

282 default results in ``n = x.shape[axis]``. 

283 axis : int, optional 

284 Axis along which the dct is computed; the default is over the 

285 last axis (i.e., ``axis=-1``). 

286 norm : {"backward", "ortho", "forward"}, optional 

287 Normalization mode (see Notes). Default is "backward". 

288 overwrite_x : bool, optional 

289 If True, the contents of `x` can be destroyed; the default is False. 

290 workers : int, optional 

291 Maximum number of workers to use for parallel computation. If negative, 

292 the value wraps around from ``os.cpu_count()``. 

293 See :func:`~scipy.fft.fft` for more details. 

294 orthogonalize : bool, optional 

295 Whether to use the orthogonalized DCT variant (see Notes). 

296 Defaults to ``True`` when ``norm="ortho"`` and ``False`` otherwise. 

297 

298 .. versionadded:: 1.8.0 

299 

300 Returns 

301 ------- 

302 y : ndarray of real 

303 The transformed input array. 

304 

305 See Also 

306 -------- 

307 idct : Inverse DCT 

308 

309 Notes 

310 ----- 

311 For a single dimension array ``x``, ``dct(x, norm='ortho')`` is equal to 

312 MATLAB ``dct(x)``. 

313 

314 .. warning:: For ``type in {1, 2, 3}``, ``norm="ortho"`` breaks the direct 

315 correspondence with the direct Fourier transform. To recover 

316 it you must specify ``orthogonalize=False``. 

317 

318 For ``norm="ortho"`` both the `dct` and `idct` are scaled by the same 

319 overall factor in both directions. By default, the transform is also 

320 orthogonalized which for types 1, 2 and 3 means the transform definition is 

321 modified to give orthogonality of the DCT matrix (see below). 

322 

323 For ``norm="backward"``, there is no scaling on `dct` and the `idct` is 

324 scaled by ``1/N`` where ``N`` is the "logical" size of the DCT. For 

325 ``norm="forward"`` the ``1/N`` normalization is applied to the forward 

326 `dct` instead and the `idct` is unnormalized. 

327 

328 There are, theoretically, 8 types of the DCT, only the first 4 types are 

329 implemented in SciPy.'The' DCT generally refers to DCT type 2, and 'the' 

330 Inverse DCT generally refers to DCT type 3. 

331 

332 **Type I** 

333 

334 There are several definitions of the DCT-I; we use the following 

335 (for ``norm="backward"``) 

336 

337 .. math:: 

338 

339 y_k = x_0 + (-1)^k x_{N-1} + 2 \sum_{n=1}^{N-2} x_n \cos\left( 

340 \frac{\pi k n}{N-1} \right) 

341 

342 If ``orthogonalize=True``, ``x[0]`` and ``x[N-1]`` are multiplied by a 

343 scaling factor of :math:`\sqrt{2}`, and ``y[0]`` and ``y[N-1]`` are divided 

344 by :math:`\sqrt{2}`. When combined with ``norm="ortho"``, this makes the 

345 corresponding matrix of coefficients orthonormal (``O @ O.T = np.eye(N)``). 

346 

347 .. note:: 

348 The DCT-I is only supported for input size > 1. 

349 

350 **Type II** 

351 

352 There are several definitions of the DCT-II; we use the following 

353 (for ``norm="backward"``) 

354 

355 .. math:: 

356 

357 y_k = 2 \sum_{n=0}^{N-1} x_n \cos\left(\frac{\pi k(2n+1)}{2N} \right) 

358 

359 If ``orthogonalize=True``, ``y[0]`` is divided by :math:`\sqrt{2}` which, 

360 when combined with ``norm="ortho"``, makes the corresponding matrix of 

361 coefficients orthonormal (``O @ O.T = np.eye(N)``). 

362 

363 **Type III** 

364 

365 There are several definitions, we use the following (for 

366 ``norm="backward"``) 

367 

368 .. math:: 

369 

370 y_k = x_0 + 2 \sum_{n=1}^{N-1} x_n \cos\left(\frac{\pi(2k+1)n}{2N}\right) 

371 

372 If ``orthogonalize=True``, ``x[0]`` terms are multiplied by 

373 :math:`\sqrt{2}` which, when combined with ``norm="ortho"``, makes the 

374 corresponding matrix of coefficients orthonormal (``O @ O.T = np.eye(N)``). 

375 

376 The (unnormalized) DCT-III is the inverse of the (unnormalized) DCT-II, up 

377 to a factor `2N`. The orthonormalized DCT-III is exactly the inverse of 

378 the orthonormalized DCT-II. 

379 

380 **Type IV** 

381 

382 There are several definitions of the DCT-IV; we use the following 

383 (for ``norm="backward"``) 

384 

385 .. math:: 

386 

387 y_k = 2 \sum_{n=0}^{N-1} x_n \cos\left(\frac{\pi(2k+1)(2n+1)}{4N} \right) 

388 

389 ``orthogonalize`` has no effect here, as the DCT-IV matrix is already 

390 orthogonal up to a scale factor of ``2N``. 

391 

392 References 

393 ---------- 

394 .. [1] 'A Fast Cosine Transform in One and Two Dimensions', by J. 

395 Makhoul, `IEEE Transactions on acoustics, speech and signal 

396 processing` vol. 28(1), pp. 27-34, 

397 :doi:`10.1109/TASSP.1980.1163351` (1980). 

398 .. [2] Wikipedia, "Discrete cosine transform", 

399 https://en.wikipedia.org/wiki/Discrete_cosine_transform 

400 

401 Examples 

402 -------- 

403 The Type 1 DCT is equivalent to the FFT (though faster) for real, 

404 even-symmetrical inputs. The output is also real and even-symmetrical. 

405 Half of the FFT input is used to generate half of the FFT output: 

406 

407 >>> from scipy.fft import fft, dct 

408 >>> import numpy as np 

409 >>> fft(np.array([4., 3., 5., 10., 5., 3.])).real 

410 array([ 30., -8., 6., -2., 6., -8.]) 

411 >>> dct(np.array([4., 3., 5., 10.]), 1) 

412 array([ 30., -8., 6., -2.]) 

413 

414 """ 

415 return (Dispatchable(x, np.ndarray),) 

416 

417 

418@_dispatch 

419def idct(x, type=2, n=None, axis=-1, norm=None, overwrite_x=False, 

420 workers=None, orthogonalize=None): 

421 """ 

422 Return the Inverse Discrete Cosine Transform of an arbitrary type sequence. 

423 

424 Parameters 

425 ---------- 

426 x : array_like 

427 The input array. 

428 type : {1, 2, 3, 4}, optional 

429 Type of the DCT (see Notes). Default type is 2. 

430 n : int, optional 

431 Length of the transform. If ``n < x.shape[axis]``, `x` is 

432 truncated. If ``n > x.shape[axis]``, `x` is zero-padded. The 

433 default results in ``n = x.shape[axis]``. 

434 axis : int, optional 

435 Axis along which the idct is computed; the default is over the 

436 last axis (i.e., ``axis=-1``). 

437 norm : {"backward", "ortho", "forward"}, optional 

438 Normalization mode (see Notes). Default is "backward". 

439 overwrite_x : bool, optional 

440 If True, the contents of `x` can be destroyed; the default is False. 

441 workers : int, optional 

442 Maximum number of workers to use for parallel computation. If negative, 

443 the value wraps around from ``os.cpu_count()``. 

444 See :func:`~scipy.fft.fft` for more details. 

445 orthogonalize : bool, optional 

446 Whether to use the orthogonalized IDCT variant (see Notes). 

447 Defaults to ``True`` when ``norm="ortho"`` and ``False`` otherwise. 

448 

449 .. versionadded:: 1.8.0 

450 

451 Returns 

452 ------- 

453 idct : ndarray of real 

454 The transformed input array. 

455 

456 See Also 

457 -------- 

458 dct : Forward DCT 

459 

460 Notes 

461 ----- 

462 For a single dimension array `x`, ``idct(x, norm='ortho')`` is equal to 

463 MATLAB ``idct(x)``. 

464 

465 .. warning:: For ``type in {1, 2, 3}``, ``norm="ortho"`` breaks the direct 

466 correspondence with the inverse direct Fourier transform. To 

467 recover it you must specify ``orthogonalize=False``. 

468 

469 For ``norm="ortho"`` both the `dct` and `idct` are scaled by the same 

470 overall factor in both directions. By default, the transform is also 

471 orthogonalized which for types 1, 2 and 3 means the transform definition is 

472 modified to give orthogonality of the IDCT matrix (see `dct` for the full 

473 definitions). 

474 

475 'The' IDCT is the IDCT-II, which is the same as the normalized DCT-III. 

476 

477 The IDCT is equivalent to a normal DCT except for the normalization and 

478 type. DCT type 1 and 4 are their own inverse and DCTs 2 and 3 are each 

479 other's inverses. 

480 

481 Examples 

482 -------- 

483 The Type 1 DCT is equivalent to the DFT for real, even-symmetrical 

484 inputs. The output is also real and even-symmetrical. Half of the IFFT 

485 input is used to generate half of the IFFT output: 

486 

487 >>> from scipy.fft import ifft, idct 

488 >>> import numpy as np 

489 >>> ifft(np.array([ 30., -8., 6., -2., 6., -8.])).real 

490 array([ 4., 3., 5., 10., 5., 3.]) 

491 >>> idct(np.array([ 30., -8., 6., -2.]), 1) 

492 array([ 4., 3., 5., 10.]) 

493 

494 """ 

495 return (Dispatchable(x, np.ndarray),) 

496 

497 

498@_dispatch 

499def dst(x, type=2, n=None, axis=-1, norm=None, overwrite_x=False, workers=None, 

500 orthogonalize=None): 

501 r""" 

502 Return the Discrete Sine Transform of arbitrary type sequence x. 

503 

504 Parameters 

505 ---------- 

506 x : array_like 

507 The input array. 

508 type : {1, 2, 3, 4}, optional 

509 Type of the DST (see Notes). Default type is 2. 

510 n : int, optional 

511 Length of the transform. If ``n < x.shape[axis]``, `x` is 

512 truncated. If ``n > x.shape[axis]``, `x` is zero-padded. The 

513 default results in ``n = x.shape[axis]``. 

514 axis : int, optional 

515 Axis along which the dst is computed; the default is over the 

516 last axis (i.e., ``axis=-1``). 

517 norm : {"backward", "ortho", "forward"}, optional 

518 Normalization mode (see Notes). Default is "backward". 

519 overwrite_x : bool, optional 

520 If True, the contents of `x` can be destroyed; the default is False. 

521 workers : int, optional 

522 Maximum number of workers to use for parallel computation. If negative, 

523 the value wraps around from ``os.cpu_count()``. 

524 See :func:`~scipy.fft.fft` for more details. 

525 orthogonalize : bool, optional 

526 Whether to use the orthogonalized DST variant (see Notes). 

527 Defaults to ``True`` when ``norm="ortho"`` and ``False`` otherwise. 

528 

529 .. versionadded:: 1.8.0 

530 

531 Returns 

532 ------- 

533 dst : ndarray of reals 

534 The transformed input array. 

535 

536 See Also 

537 -------- 

538 idst : Inverse DST 

539 

540 Notes 

541 ----- 

542 .. warning:: For ``type in {2, 3}``, ``norm="ortho"`` breaks the direct 

543 correspondence with the direct Fourier transform. To recover 

544 it you must specify ``orthogonalize=False``. 

545 

546 For ``norm="ortho"`` both the `dst` and `idst` are scaled by the same 

547 overall factor in both directions. By default, the transform is also 

548 orthogonalized which for types 2 and 3 means the transform definition is 

549 modified to give orthogonality of the DST matrix (see below). 

550 

551 For ``norm="backward"``, there is no scaling on the `dst` and the `idst` is 

552 scaled by ``1/N`` where ``N`` is the "logical" size of the DST. 

553 

554 There are, theoretically, 8 types of the DST for different combinations of 

555 even/odd boundary conditions and boundary off sets [1]_, only the first 

556 4 types are implemented in SciPy. 

557 

558 **Type I** 

559 

560 There are several definitions of the DST-I; we use the following for 

561 ``norm="backward"``. DST-I assumes the input is odd around :math:`n=-1` and 

562 :math:`n=N`. 

563 

564 .. math:: 

565 

566 y_k = 2 \sum_{n=0}^{N-1} x_n \sin\left(\frac{\pi(k+1)(n+1)}{N+1}\right) 

567 

568 Note that the DST-I is only supported for input size > 1. 

569 The (unnormalized) DST-I is its own inverse, up to a factor :math:`2(N+1)`. 

570 The orthonormalized DST-I is exactly its own inverse. 

571 

572 ``orthogonalize`` has no effect here, as the DST-I matrix is already 

573 orthogonal up to a scale factor of ``2N``. 

574 

575 **Type II** 

576 

577 There are several definitions of the DST-II; we use the following for 

578 ``norm="backward"``. DST-II assumes the input is odd around :math:`n=-1/2` and 

579 :math:`n=N-1/2`; the output is odd around :math:`k=-1` and even around :math:`k=N-1` 

580 

581 .. math:: 

582 

583 y_k = 2 \sum_{n=0}^{N-1} x_n \sin\left(\frac{\pi(k+1)(2n+1)}{2N}\right) 

584 

585 If ``orthogonalize=True``, ``y[0]`` is divided :math:`\sqrt{2}` which, when 

586 combined with ``norm="ortho"``, makes the corresponding matrix of 

587 coefficients orthonormal (``O @ O.T = np.eye(N)``). 

588 

589 **Type III** 

590 

591 There are several definitions of the DST-III, we use the following (for 

592 ``norm="backward"``). DST-III assumes the input is odd around :math:`n=-1` and 

593 even around :math:`n=N-1` 

594 

595 .. math:: 

596 

597 y_k = (-1)^k x_{N-1} + 2 \sum_{n=0}^{N-2} x_n \sin\left( 

598 \frac{\pi(2k+1)(n+1)}{2N}\right) 

599 

600 If ``orthogonalize=True``, ``x[0]`` is multiplied by :math:`\sqrt{2}` 

601 which, when combined with ``norm="ortho"``, makes the corresponding matrix 

602 of coefficients orthonormal (``O @ O.T = np.eye(N)``). 

603 

604 The (unnormalized) DST-III is the inverse of the (unnormalized) DST-II, up 

605 to a factor :math:`2N`. The orthonormalized DST-III is exactly the inverse of the 

606 orthonormalized DST-II. 

607 

608 **Type IV** 

609 

610 There are several definitions of the DST-IV, we use the following (for 

611 ``norm="backward"``). DST-IV assumes the input is odd around :math:`n=-0.5` and 

612 even around :math:`n=N-0.5` 

613 

614 .. math:: 

615 

616 y_k = 2 \sum_{n=0}^{N-1} x_n \sin\left(\frac{\pi(2k+1)(2n+1)}{4N}\right) 

617 

618 ``orthogonalize`` has no effect here, as the DST-IV matrix is already 

619 orthogonal up to a scale factor of ``2N``. 

620 

621 The (unnormalized) DST-IV is its own inverse, up to a factor :math:`2N`. The 

622 orthonormalized DST-IV is exactly its own inverse. 

623 

624 References 

625 ---------- 

626 .. [1] Wikipedia, "Discrete sine transform", 

627 https://en.wikipedia.org/wiki/Discrete_sine_transform 

628 

629 """ 

630 return (Dispatchable(x, np.ndarray),) 

631 

632 

633@_dispatch 

634def idst(x, type=2, n=None, axis=-1, norm=None, overwrite_x=False, 

635 workers=None, orthogonalize=None): 

636 """ 

637 Return the Inverse Discrete Sine Transform of an arbitrary type sequence. 

638 

639 Parameters 

640 ---------- 

641 x : array_like 

642 The input array. 

643 type : {1, 2, 3, 4}, optional 

644 Type of the DST (see Notes). Default type is 2. 

645 n : int, optional 

646 Length of the transform. If ``n < x.shape[axis]``, `x` is 

647 truncated. If ``n > x.shape[axis]``, `x` is zero-padded. The 

648 default results in ``n = x.shape[axis]``. 

649 axis : int, optional 

650 Axis along which the idst is computed; the default is over the 

651 last axis (i.e., ``axis=-1``). 

652 norm : {"backward", "ortho", "forward"}, optional 

653 Normalization mode (see Notes). Default is "backward". 

654 overwrite_x : bool, optional 

655 If True, the contents of `x` can be destroyed; the default is False. 

656 workers : int, optional 

657 Maximum number of workers to use for parallel computation. If negative, 

658 the value wraps around from ``os.cpu_count()``. 

659 See :func:`~scipy.fft.fft` for more details. 

660 orthogonalize : bool, optional 

661 Whether to use the orthogonalized IDST variant (see Notes). 

662 Defaults to ``True`` when ``norm="ortho"`` and ``False`` otherwise. 

663 

664 .. versionadded:: 1.8.0 

665 

666 Returns 

667 ------- 

668 idst : ndarray of real 

669 The transformed input array. 

670 

671 See Also 

672 -------- 

673 dst : Forward DST 

674 

675 Notes 

676 ----- 

677 .. warning:: For ``type in {2, 3}``, ``norm="ortho"`` breaks the direct 

678 correspondence with the inverse direct Fourier transform. 

679 

680 For ``norm="ortho"`` both the `dst` and `idst` are scaled by the same 

681 overall factor in both directions. By default, the transform is also 

682 orthogonalized which for types 2 and 3 means the transform definition is 

683 modified to give orthogonality of the DST matrix (see `dst` for the full 

684 definitions). 

685 

686 'The' IDST is the IDST-II, which is the same as the normalized DST-III. 

687 

688 The IDST is equivalent to a normal DST except for the normalization and 

689 type. DST type 1 and 4 are their own inverse and DSTs 2 and 3 are each 

690 other's inverses. 

691 

692 """ 

693 return (Dispatchable(x, np.ndarray),)