# Tmap usage with views

**URL:** <https://discourse.julialang.org/t/tmap-usage-with-views/133556>\
**Category:** General Usage\
**Tags:** array\
**Created:** [October 30, 2025, 1:24pm UTC](https://discourse.julialang.org/t/tmap-usage-with-views/133556 "2025-10-30T13:24:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacobga](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jacobga](https://discourse.julialang.org/u/jacobga)\
**Post date:** [October 30, 2025, 1:24pm UTC](https://discourse.julialang.org/t/tmap-usage-with-views/133556/1 "2025-10-30T13:24:00Z")

</div>

Hello,

I am trying to use tmap! from OhMyThreads.jl on a view of an array. When running the code normally, it works fine, but it fails in testing when run with check\_bounds=yes, because views have cartesian index style. Is this usage of the function dangerous, or is there another way i should implement this?

```julia-auto
julia> a = [1 2;3 4]
2×2 Matrix{Int64}:
 1 2
 3 4

julia> b = [5 6;7 8]
2×2 Matrix{Int64}:
 5 6
 7 8

julia> tmap!(x->2*x, a, @view b[[2,1],:])
ERROR: The indices of the input arrays must match the indices of the output array.
Stacktrace:
 [1] error(s::String)
   @ Base .\error.jl:35
 [2] check_all_have_same_indices(Arrs::Tuple{Matrix{Int64}, SubArray{Int64, 2, Matrix{…}, Tuple{…}, false}})
   @ OhMyThreads.Implementation .julia\packages\OhMyThreads\P7uYA\src\implementation.jl:337
 [3] #tmap!#143
   @ .julia\packages\OhMyThreads\P7uYA\src\implementation.jl:554 [inlined]
 [4] tmap!(::Function, ::Matrix{Int64}, ::SubArray{Int64, 2, Matrix{Int64}, Tuple{Vector{…}, Base.Slice{…}}, false})
   @ OhMyThreads.Implementation .julia\packages\OhMyThreads\P7uYA\src\implementation.jl:542
 [5] top-level scope
   @ REPL[20]:1
Some type information was truncated. Use `show(err)` to see complete types.

julia> eachindex(@view b[[2,1],:])
CartesianIndices((2, 2))

julia> eachindex(a)
Base.OneTo(4)

```

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [October 31, 2025, 2:17am UTC](https://discourse.julialang.org/t/tmap-usage-with-views/133556/2 "2025-10-31T02:17:00Z")

</div>

you could try using `vec` to rehape the view:

```julia-auto
tmap!(x->2*x, a, vec(@view b[[2,1],:]))

```

maybe index checking of `tmap!` could be updated, noting that `map!` works with a view.

---

<div class="post-metadata">

**Author:** ![jacobga](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jacobga](https://discourse.julialang.org/u/jacobga)\
**Post date:** [October 31, 2025, 8:04am UTC](https://discourse.julialang.org/t/tmap-usage-with-views/133556/3 "2025-10-31T08:04:57Z")

</div>

Thank you Greg. I will give it a try, and also take a look at how map checks indices.
