# Clamped View

**URL:** <https://discourse.julialang.org/t/clamped-view/96717>\
**Category:** Performance\
**Tags:** arrays, views\
**Created:** [March 28, 2023, 3:21pm UTC](https://discourse.julialang.org/t/clamped-view/96717 "2023-03-28T15:21:19Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 28, 2023, 7:06pm UTC](https://discourse.julialang.org/t/clamped-view/96717/8 "2023-03-28T19:06:50Z")

</div>

> [@weymouth](#):
>
> The motivation for this is to apply stencils like finite differences and convolutions without needing padding or offsets or subarrays.

My experiences is that boundary checks inside inner loops are always going to be slow, and are inflexible as well. What if you want to change to periodic boundary conditions, for example? Better to use padding/ghost elements, which allows you to completely decouple the boundary conditions from the inner loops.

See also [Arrays with periodic boundaries - #4 by stevengj](https://discourse.julialang.org/t/arrays-with-periodic-boundaries/4015/4) or [Seemingly unnecessary allocation within for loop - #8 by stevengj](https://discourse.julialang.org/t/seemingly-unnecessary-allocation-within-for-loop/72556/8)

> [@weymouth](#):
>
> How is the shift in indices accomplished so well with views and can it be replicated here?

The shift in indices for views is not conditional — it’s just a constant offset. Indeed, the compiler can probably pull the offset completely out of an inner loop by simply offsetting the data pointer.

---

_[View the full topic](https://discourse.julialang.org/t/clamped-view/96717)._
