# Elegant way to implement a rotating convolution filter without using \`rot90\` etc

**URL:** <https://discourse.julialang.org/t/elegant-way-to-implement-a-rotating-convolution-filter-without-using-rot90-etc/65180>\
**Category:** General Usage\
**Created:** [July 23, 2021, 1:46pm UTC](https://discourse.julialang.org/t/elegant-way-to-implement-a-rotating-convolution-filter-without-using-rot90-etc/65180 "2021-07-23T13:46:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [July 23, 2021, 1:46pm UTC](https://discourse.julialang.org/t/elegant-way-to-implement-a-rotating-convolution-filter-without-using-rot90-etc/65180/1 "2021-07-23T13:46:34Z")

</div>

I am looking to implement a simple rotational convolutional filter to be used with Flux.jl see post describing the filter [deep learning - Does a rotational convolutional filter exist in neural networks? - Data Science Stack Exchange](https://datascience.stackexchange.com/questions/97934/does-a-rotational-convolutional-filter-exist-in-neural-networks/98228#98228)

Basically, instead of sweeping across left to right and up and down like a normal convolutional filter, I want to instead rotate the filter as well. So I can apply it to a 4x4 grid and end up with a 2x2 grid. The 4x4 grid is intended to be the game 2048.

```julia
using Flux
bb = rand(Int8, 4, 4) # the 2048 game board
weights = rand(Float32, 2, 2)

function transpose_conv(bb)    
    sum(rotl90(@view(bb[1:2, 3:4])) .* weights) # see if I can differentiate through the top right corner
end

gs = gradient(()->transpose_conv(bb), params(weights))

gs[weights]

```

The above will give error as `ERROR: Mutating arrays is not supported -- called setindex!(::Matrix{Int8}, `

So seems like Zygote.jl doesn’t like `rotl90` as well.

Is there a better way to implement this? The best I can think of is to just write it out in full. But I wish to implement group CNN more generally which can do rotation.
