In Repa (Haskell) is there any way to perform row operations directly?
I want to do an fft of each row of a 2D array but this does not seem to be possible. As I do not want to write my own fft algorithm, it would be nice if I can apply fft (from Repa.FFTW) to each row directly resulting in a matrix of the same size as the original.
I tried to write my own dft function but the performance was very bad. The code for this is below.
dftOnMatrix :: Array D DIM2 Complex -> Array D DIM2 Complex
dftOnMatrix arr =
let (Z :. rs :. cs) = extent arr
dftFunc :: (DIM2 -> Complex) -> Int -> Int -> Int -> Complex -> Complex
dftFunc f i j k sum = dftFuncCore k sum
where
val2 = fromIntegral j
temp = 2*pi/ fromIntegral cs
dftFuncCore k sum =
if k == cs
then sum
else let val1 = fromIntegral k
val = val1*val2*temp
cosval = ( - (cos val))
sinval = ( - (sin val))
in --cosval `seq` (sinval `seq` (dftFuncCore (k+1) (sum + ((f (Z :. i :. k))* (cos val, sin val)))))
dftFuncCore (k+1) (sum + ((f (Z :. i :. k))* (cos val, sin val)))
in R.traverse arr id (\f (Z :. i :. j) -> (1/fromIntegral cs, 0) * dftFunc f i j 0 0)
I have tried to analyze this using ghc-core but did not find anything that might affect performance. I might be completely wrong though as my knowledge of core is very limited.
Thanks,