Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

from functools import update_wrapper, lru_cache 

 

from ._pocketfft import helper as _helper 

 

 

def next_fast_len(target, real=False): 

"""Find the next fast size of input data to ``fft``, for zero-padding, etc. 

 

SciPy's FFT algorithms gain their speed by a recursive divide and conquer 

strategy. This relies on efficient functions for small prime factors of the 

input length. Thus, the transforms are fastest when using composites of the 

prime factors handled by the fft implementation. If there are efficient 

functions for all radices <= `n`, then the result will be a number `x` 

>= ``target`` with only prime factors < `n`. (Also known as `n`-smooth 

numbers) 

 

Parameters 

---------- 

target : int 

Length to start searching from. Must be a positive integer. 

real : bool, optional 

True if the FFT involves real input or output (e.g., `rfft` or `hfft` but 

not `fft`). Defaults to False. 

 

Returns 

------- 

out : int 

The smallest fast length greater than or equal to ``target``. 

 

Notes 

----- 

The result of this function may change in future as performance 

considerations change, for example, if new prime factors are added. 

 

Calling `fft` or `ifft` with real input data performs an ``'R2C'`` 

transform internally. 

 

Examples 

-------- 

On a particular machine, an FFT of prime length takes 17 ms: 

 

>>> from scipy import fft 

>>> min_len = 93059 # prime length is worst case for speed 

>>> a = np.random.randn(min_len) 

>>> b = fft.fft(a) 

 

Zero-padding to the next regular length reduces computation time to 

1.3 ms, a speedup of 13 times: 

 

>>> fft.next_fast_len(min_len) 

93312 

>>> b = fft.fft(a, 93312) 

 

Rounding up to the next power of 2 is not optimal, taking 1.9 ms to 

compute; 1.3 times longer than the size given by ``next_fast_len``: 

 

>>> b = fft.fft(a, 131072) 

 

""" 

pass 

 

 

# Directly wrap the c-function good_size but take the docstring etc., from the 

# next_fast_len function above 

next_fast_len = update_wrapper(lru_cache()(_helper.good_size), next_fast_len) 

next_fast_len.__wrapped__ = _helper.good_size 

 

 

def _init_nd_shape_and_axes(x, shape, axes): 

"""Handle shape and axes arguments for N-D transforms. 

 

Returns the shape and axes in a standard form, taking into account negative 

values and checking for various potential errors. 

 

Parameters 

---------- 

x : array_like 

The input array. 

shape : int or array_like of ints or None 

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

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

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

If `shape` is -1, the size of the corresponding dimension of `x` is 

used. 

axes : int or array_like of ints or None 

Axes along which the calculation is computed. 

The default is over all axes. 

Negative indices are automatically converted to their positive 

counterparts. 

 

Returns 

------- 

shape : array 

The shape of the result. It is a 1-D integer array. 

axes : array 

The shape of the result. It is a 1-D integer array. 

 

""" 

return _helper._init_nd_shape_and_axes(x, shape, axes)