# Type stability around of wrapped plan fft

**URL:** <https://discourse.julialang.org/t/type-stability-around-of-wrapped-plan-fft/102582>\
**Category:** General Usage\
**Tags:** question, fftw, type-stability\
**Created:** [August 8, 2023, 1:20am UTC](https://discourse.julialang.org/t/type-stability-around-of-wrapped-plan-fft/102582 "2023-08-08T01:20:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Veenty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/veenty/32/50940_2.png) [@Veenty](https://discourse.julialang.org/u/Veenty)\
**Post date:** [August 8, 2023, 1:20am UTC](https://discourse.julialang.org/t/type-stability-around-of-wrapped-plan-fft/102582/1 "2023-08-08T01:20:52Z")

</div>

I have a simple struct wrapping a planned fft and I’m not really sure how to make it type stable

I might need to write the type of the fft, but I’m not really sure how to do it (I cannot really interpret the type of a planed fft)

```julia
using FFTW

struct wrapper
    pfft
    pifft
end

function simple_fft(x, pfft::wrapper)
    return pfft.pfft * x
end

W = wrapper(plan_fft(zeros(10)), inv(plan_fft(zeros(10))))

@code_warntype simple_fft(zeros(10), W)

```

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [August 8, 2023, 5:35am UTC](https://discourse.julialang.org/t/type-stability-around-of-wrapped-plan-fft/102582/2 "2023-08-08T05:35:09Z")

</div>

Sorry only on mobile, so can’t test stuff.

I think the issue here is that your struct has untyped fields which implicitely means `Any`. You should either put explicit types there (which you can find via `typeof(plan_fft(...))`) und generic type paramters like

```julia
struct wrapper{P,IP}
    pfft::P
    pifft::IP
end

```

---

<div class="post-metadata">

**Author:** ![Salmon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/salmon/32/22968_2.png) [@Salmon](https://discourse.julialang.org/u/Salmon)\
**Post date:** [August 8, 2023, 7:27am UTC](https://discourse.julialang.org/t/type-stability-around-of-wrapped-plan-fft/102582/3 "2023-08-08T07:27:43Z")

</div>

> [@Veenty](#):
>
> `W = wrapper(plan_fft(zeros(10)), inv(plan_fft(zeros(10))))`

By the way, depending on what you want to do you might not need to create a wrapper.  
In the [docs of AbstractFFTs](https://juliamath.github.io/AbstractFFTs.jl/stable/api/#AbstractFFTs.plan_fft) it says:

> You can compute the inverse-transform plan by `inv(P)` and apply the inverse plan with `P \ Â` (the inverse plan is cached and reused for subsequent calls to `inv` or `\`), and apply the inverse plan to a pre-allocated output array `A` with `ldiv!(A, P, Â)`.

If you want the wrapper for dispatch reasons thats fine of course.
