"for $X$, where $A$, $X$ and $Y$ are matrices. \"Conventional\" linear systems can then be solved by taking $X$ and $Y$ as matrices with only a single column.\n",

"for $X$, where $A$, $X$ and $Y$ are matrices. \"Conventional\" linear systems can then be solved by taking $X$ and $Y$ as matrices with only a single column.\n",

"\n",

"\n",

"In order to actually use the parallelisation, this exercise should not be done in the notebook interface. You should also test your program on the 1d Poisson example from lecture 21 and examine its behaviour in ThreadScope. HMatrix matrices can be converted to Repa `DIM2` arrays using `matrixToRepa` from `Data.Packed.Repa`."

"In order to actually use the parallelisation, this exercise should not be done in the notebook interface. You should also test your program on the 1d Poisson example from lecture 22 and examine its behaviour in ThreadScope."

]

]

},

},

{

{

...

@@ -295,7 +290,49 @@

...

@@ -295,7 +290,49 @@

"collapsed": false

"collapsed": false

},

},

"outputs": [],

"outputs": [],

"source": []

"source": [

"{-# LANGUAGE BangPatterns #-}\n",

"\n",

"import Data.Array.Repa as R\n",

"import Data.Array.Repa.Algorithms.Matrix\n",

"import Numeric.LinearAlgebra.Helpers\n",

"\n",

"jacobi :: Monad m => Array U DIM2 Double -> Array U DIM2 Double -> m (Array U DIM2 Double)\n",

"-- simple stopping rule: always do 500 iterations\n",

"jacobi a y = jacobi' 500 $ computeUnboxedS $ zeros (extent y)\n",

" where\n",

" d = fromFunction (extent y) $ \\(Z:.(!j):._) -> unsafeIndex a (Z:.j:.j)\n",

" r = computeUnboxedS $ R.traverse a id $ \\get idx@(Z:.(!j):.(!k)) ->\n",

The module `Data.Array.Repa.FFTW` provides functions for Fast Fourier Transforms (FFT) for Repa arrays of up to three dimensions. Use the 1-d version to implement a simple low-pass filter that works as follows:

The module `Data.Array.Repa.FFTW` provides functions for Fast Fourier Transforms (FFT) for Repa arrays of up to three dimensions. Use the 1-d version to implement a simple low-pass filter that works as follows:

- First, an FFT is applied to the input signal.

- First, an FFT is applied to the input signal.

- The coefficients corresponding to frequencies over some pre-determined cutoff are set to 0, the other ones are left untouched.

- The coefficients corresponding to frequencies over some pre-determined cutoff are set to 0, the other ones are left untouched.

- Then an inverse FFT is performed.

- Then an inverse FFT is performed.

The map from index `k` of the resulting array to the corresponding frequency for an FFT of length `n` is

The map from index `k` of the resulting array to the corresponding frequency for an FFT of length `n` is

```haskell

```haskell

frqnk

frqnk

|2*k<n=k

|2*k<n=k

|otherwise=k-n

|otherwise=k-n

```

```

Use the low-pass filter to denoise a signal created by adding uniformly distributed noise between $-0.03$ and $0.03$ to the function $x \mapsto exp(-x^2)$ for $x$ sampled on 200 points between $-2$ and $2$ and plot the results.

Use the low-pass filter to denoise a signal created by adding uniformly distributed noise between $-0.03$ and $0.03$ to the function $x \mapsto exp(-x^2)$ for $x$ sampled on 200 points between $-2$ and $2$ and plot the results.

Note:

Note:

- The function, its noisy version and the filtered version should be real, but the FFT functions require and return `Complex Double` arrays.

- The function, its noisy version and the filtered version should be real, but the FFT functions require and return `Complex Double` arrays.

- The FFT functions work with arrays in representation `F` (foreign). To convert from and to `D` or `U`, `copyS` can be used.

- The FFT functions work with arrays in representation `F` (foreign). To convert from and to `D` or `U`, `copyS` can be used.

- A simple way to generate a list of `n` random numbers without using `IO` is

- A simple way to generate a list of `n` random numbers without using `IO` is

Implement a parallel Jacobi solver for linear systems using Repa arrays. Since Repa's `mmultP` (from `Data.Array.Repa.Algorithms.Matrix`) only works on `DIM2` arrays, the right hand side should be a matrix as well, i.e. you should effectively solve

Implement a parallel Jacobi solver for linear systems using Repa arrays. Since Repa's `mmultP` (from `Data.Array.Repa.Algorithms.Matrix`) only works on `DIM2` arrays, the right hand side should be a matrix as well, i.e. you should effectively solve

$$A X = Y$$

$$A X = Y$$

for $X$, where $A$, $X$ and $Y$ are matrices. "Conventional" linear systems can then be solved by taking $X$ and $Y$ as matrices with only a single column.

for $X$, where $A$, $X$ and $Y$ are matrices. "Conventional" linear systems can then be solved by taking $X$ and $Y$ as matrices with only a single column.

In order to actually use the parallelisation, this exercise should not be done in the notebook interface. You should also test your program on the 1d Poisson example from lecture 21 and examine its behaviour in ThreadScope. HMatrix matrices can be converted to Repa `DIM2` arrays using `matrixToRepa` from `Data.Packed.Repa`.

In order to actually use the parallelisation, this exercise should not be done in the notebook interface. You should also test your program on the 1d Poisson example from lecture 22 and examine its behaviour in ThreadScope.