Method: Numo::Pocketfft.rfftn

Defined in:
lib/numo/pocketfft.rb

.rfftn(a) ⇒ Numo::DComplex

Compute the N-dimensional discrete Fourier Transform for real input.

Parameters:

  • a (Numo::DFloat)

    Real input array with any-dimension.

Returns:

  • (Numo::DComplex)

    Transformed data.

Raises:

  • (ArgumentError)

    This error is raised if input array is not Numo::NArray or is empty.



143
144
145
146
147
148
149
150
151
152
153
# File 'lib/numo/pocketfft.rb', line 143

def rfftn(a)
  raise ArgumentError, 'Expect class of input array to be Numo::NArray.' unless a.is_a?(Numo::NArray)
  raise ArgumentError, 'Expect input array to be non-empty.' if a.empty?

  return raw_fft(a, 0, inverse: false, real: true) if a.ndim == 1

  last_axis_id = a.ndim - 1
  b = raw_fft(a, last_axis_id, inverse: false, real: true)
  (last_axis_id - 1).downto(0) { |ax_id| b = raw_fft(b, ax_id, inverse: false, real: false) }
  b
end