Better Documentation of [,Dims] for Julia FFT function

question

#1

I am attempting to find the FFT of a set of vectors. In particular I have an array that is 2234 rows long with each row being a signal to perform an FFT on. The documentation on FFT states that

The optional dims argument specifies an iterable subset of dimensions (e.g. an integer, range, tuple, or array) to transform along

There are no examples or further description of this functionality however. I could of course do

for k=1:length(Array[:,1])
    FFTout[k,:]=fft(Array[k,:])
end

But I cannot tell if this could be sped up by the dims functionality (or by broadcasting FFT with some sort of input into the function e.g. FFT.(Array[1:end,:]) perhaps)


#2

You want to fft the rows (along the 2nd index dimension), so pass 2 for the dims argument.

This is similar to the dims argument to sum etc.

And if you really care about performance, use plan_fft and a preallocated output array.


#3

Ah excellent, FFTout=fft(Array,[2]) does precisely what I need and makes clear how plan_fft could be used as well as preallocation for increased performance if needed.

Being pointed to the sum function and its description of dims was very helpful as well, thanks.


#4

It is equivalent to do fft(Array,2), and it avoids allocating the temporary array [2]. (If you have multiple dimensions to transform, I would use a tuple.)