# Can I skip \`@boundscheck\` within a function

**URL:** <https://discourse.julialang.org/t/can-i-skip-boundscheck-within-a-function/65449>\
**Category:** General Usage\
**Created:** [July 28, 2021, 4:32pm UTC](https://discourse.julialang.org/t/can-i-skip-boundscheck-within-a-function/65449 "2021-07-28T16:32:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lieskjur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lieskjur/32/27611_2.png) [@lieskjur](https://discourse.julialang.org/u/lieskjur)\
**Post date:** [July 28, 2021, 4:32pm UTC](https://discourse.julialang.org/t/can-i-skip-boundscheck-within-a-function/65449/1 "2021-07-28T16:32:52Z")

</div>

Hi, suppose I am using a function

```julia
function f(x,y)
	@boundscheck size(x) == size(y) || error("sizes do not match")
	x'y
end

```

written by someone else and I want to use arguments `x = rand(2,2); y = rand(2)`. Is there a way to suppress the `@boundscheck` so that I can call the function with the aforementioned arguments without triggering the error?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [July 28, 2021, 4:36pm UTC](https://discourse.julialang.org/t/can-i-skip-boundscheck-within-a-function/65449/2 "2021-07-28T16:36:33Z")

</div>

use `@inbounds` when calling the function…

But someone is doing something wrong if this is what you have to do.

---

<div class="post-metadata">

**Author:** ![lieskjur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lieskjur/32/27611_2.png) [@lieskjur](https://discourse.julialang.org/u/lieskjur)\
**Post date:** [July 28, 2021, 4:48pm UTC](https://discourse.julialang.org/t/can-i-skip-boundscheck-within-a-function/65449/3 "2021-07-28T16:48:29Z")

</div>

I’ve tried `@inbounds f(x,y)` both in the console and as part of a file I `include(...)` and the error still appears.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [July 28, 2021, 4:56pm UTC](https://discourse.julialang.org/t/can-i-skip-boundscheck-within-a-function/65449/4 "2021-07-28T16:56:03Z")

</div>

```julia
julia> function f(x,y)
               @boundscheck size(x) == size(y) || error("sizes do not match")
               x'y
       end
f (generic function with 1 method)

julia> g(x,y) = @inbounds f(x,y)
g (generic function with 1 method)

julia> f(rand(2,2), rand(2))
ERROR: sizes do not match
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] f(x::Matrix{Float64}, y::Vector{Float64})
   @ Main ./REPL[6]:2
 [3] top-level scope
   @ REPL[8]:1

julia> g(rand(2,2), rand(2))
2-element Vector{Float64}:
 0.5974016405805198
 0.49780565668703575

```

---

<div class="post-metadata">

**Author:** ![lieskjur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lieskjur/32/27611_2.png) [@lieskjur](https://discourse.julialang.org/u/lieskjur)\
**Post date:** [July 28, 2021, 5:08pm UTC](https://discourse.julialang.org/t/can-i-skip-boundscheck-within-a-function/65449/5 "2021-07-28T17:08:27Z")

</div>

Thank you very much.
