Define macros depending on optimization level

I would like to define the macro const var"@lvec" = const var"@turbo @." if Julia is started with optimization levels 2 or 3, and const var"@lvec" = const var"@." otherwise.

My main motivation is that I use @tturbo @. very often. However, sometimes it fails to throw an error if the dimensions of the involved arrays are not consistent, whereas @. does not fail. So, I would like to define a single macro that is either any of them depending on the optimization level.

I am facing two problems:

  1. I do not know what command I should use to get the current optimization level – I need this to define an if sentence.
  2. If I type const var"@lvec" = var"@." in the REPL, I get the error `@.` not defined, something that does not happen, e.g., if I type const var"@lvec" = var"@warn".

Any help will be appreciated.

You could also PR LV to check broadcast bounds.

What do you mean by PR LV?

I’d think, “make a pull request (PR) for LoopVectorization.jl (LV)”.

2 Likes