For well tested code it will be nice to have an option at the startup which disables the check bounds. According to the book JULIA HIGH PERFORMACE this is possible with the following option:
-checks-bounds=no
Nevertheless, I was not able to get it working and I will be grateful if you could let us know how to get the -checks-bounds working at startup?
Below is what is stated in the book:
"The julia runtime can use a command-line flag to set up bound-checking behavior for the entire session. The -check-bounds can take two values: yes and no These options will override any macro annotation in the source code.
Seems to be working for me.
With --check-bounds=no the @inbound
declaration is honored (Julia assumes the access is valid) and @boundscheck
code is removed.
$ julia --check-bounds=no
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.4.1 (2020-04-14)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> foo(a) = @inbounds a[1024]
foo (generic function with 1 method)
julia> bar(a) = (@boundscheck throw("out of bounds"))
bar (generic function with 1 method)
julia> foo("abc")
'\0': ASCII/Unicode U+0000 (category Cc: Other, control)
julia> bar("abc")
julia>
With --check-bounds=yes @inbounds
is ignored (Julia still checks) and @boundscheck
is left in the code.
$ julia --check-bounds=yes
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.4.1 (2020-04-14)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> foo(a) = @inbounds a[1024]
foo (generic function with 1 method)
julia> bar(a) = (@boundscheck throw("out of bounds"))
bar (generic function with 1 method)
julia> foo("abc")
ERROR: BoundsError: attempt to access String
at index [1024]
Stacktrace:
[1] checkbounds at ./strings/basic.jl:194 [inlined]
[2] codeunit at ./strings/string.jl:89 [inlined]
[3] getindex at ./strings/string.jl:210 [inlined]
[4] foo(::String) at ./REPL[1]:1
[5] top-level scope at REPL[3]:1
julia> bar("abc")
ERROR: "out of bounds"
Stacktrace:
[1] bar(::String) at ./REPL[2]:1
[2] top-level scope at REPL[4]:1
julia>
1 Like
Thanks it works but it is tedious to get it working:
julia --check-bounds=no
I am wandering if there is an easier way to get the julia --check-bounds=no steps in Windows correct?
a) Open a CMD?
b) cd C:\JULIA\Julia-1.4.1\bin
c) type julia --check-bounds=yes
This will open up the julia editor.
I believe with windows you can create a shortcut and modify it to always include the “–check-bounds=yes” when launching julia. If you browse to the bin directory and right click on the exe there should be a “create shortcut” I believe. Once that is created you can edit it to add the command line.
Or you can probably right click on the shortcut in the start menu and modify that one as well.
1 Like
How to do this in VS code?