# Match exact \`axes\`, something more strict than broadcasting or \`map!\`

**URL:** <https://discourse.julialang.org/t/match-exact-axes-something-more-strict-than-broadcasting-or-map/41206>\
**Category:** General Usage\
**Tags:** array\
**Created:** [June 11, 2020, 3:06pm UTC](https://discourse.julialang.org/t/match-exact-axes-something-more-strict-than-broadcasting-or-map/41206 "2020-06-11T15:06:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![goretkin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goretkin/32/167_2.png) [@goretkin](https://discourse.julialang.org/u/goretkin)\
**Post date:** [June 11, 2020, 3:06pm UTC](https://discourse.julialang.org/t/match-exact-axes-something-more-strict-than-broadcasting-or-map/41206/1 "2020-06-11T15:06:04Z")

</div>

Is there an operation that is strict in the sense that the destination has to exactly equal the `axes` of the source?

```julia
using OffsetArrays
s = 1
a5_10 = fill(0, 10:15)
a5_0 = fill(1, 0:5)
a4_0 = fill(2, 0:4)

a5_10 .= s # allowed, which I don't want
map!(identity, a5_10, a5_0) # allowed, which I don't want
map!(identity, a5_0, a4_0) # allowed, which I don't want
# e.g. something more like
map(+, a5_0, a4_0) # not allowed, which I want
map(+, a5_0, a5_10) # not allowed, which I want

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [June 12, 2020, 2:57pm UTC](https://discourse.julialang.org/t/match-exact-axes-something-more-strict-than-broadcasting-or-map/41206/2 "2020-06-12T14:57:22Z")

</div>

> [@goretkin](#):
>
> `a5_10 .= _s # allowed, which I don't want`

I am not sure what `_s` is, but if you meant `s`, why not allow this? It is part of the broadcasting semantics.

> [@goretkin](#):
>
> `map!(identity, a5_10, a5_10) # allowed, which I don't want`

I am confused why you don’t want to allow this; the axes match, it’s the same array. Sorry if I missed something about the spec.

In any case, you can always

```julia
@assert axes(a) == axes(b)

```

in your code — it will be either cheap, or be a no-op. Or write something like

```julia
function strict_map!(f, a1, a_rest...)
    axes_a1 = axes(a1)
    for a in a_rest
        @assert axes(a) == axes_a1
    end
    map!(f, a1, a_rest...)
end

```

---

<div class="post-metadata">

**Author:** ![goretkin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goretkin/32/167_2.png) [@goretkin](https://discourse.julialang.org/u/goretkin)\
**Post date:** [June 12, 2020, 5:08pm UTC](https://discourse.julialang.org/t/match-exact-axes-something-more-strict-than-broadcasting-or-map/41206/3 "2020-06-12T17:08:17Z")

</div>

Oof, sorry. I made a few mistakes in the example. I fixed it now.

Your `strict_map!` is exactly what I mean (well maybe with a `DimensionMismatch` instead of `AssertionError`), and my question is about whether there already exists an operation like that. In my own I already wrote a `strict_map!` (same name even).
