What are some guidelines for writing efficient wrappers?
Is using chained if-else efficient defining different options/methods for a function? How can I fully benefit from multiple-dispatch and compile-time optimizations?
How can I pass all the input arguments to an inner function? (multiple arguments)
Is there any way to define a new name for a Julia function?
This happens when the same functions exist in Julia and Matlab like
zeros. In my package, I use suffix
zerosMis the same as
zeros, I just want to write
zerosMsuch way that is exactly the same as
Alternatively, is there any way to display an error to use the native function name without
Mfor the functions that already exist in Julia?
Same as for writing efficient code in general. Start with https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-tips-1
if ... elseif ... else ... endbranch inside the function has nothing to do with methods, it is just a branch. May be fine, but can also be less flexible if you need to extend it. Various other design patterns are possible, see https://docs.julialang.org/en/v1/manual/methods/#Design-Patterns-with-Parametric-Methods-1
outer(args...) = inner(args...)
const zerosM = zeros
just throw an error, eg
zerosM(_...) = error("Toto, I have a feeling we're not in Matlab anymore.")
Hope this helps. However, from your questions it looks like you are just learning Julia. Consider just using it as is, instead of tailoring it to resemble Matlab.
I have this “Problem”, with entropy (thermodynamics vs stadistics) but in your case is worse, as the functions do something similar. a suffix is a good solution. i saw capitalization (Transducer.jl) as an alternative, or you can simply use the package leading (
you can add error checking in your own code if you want, see: Exception Handling
this example can help
function mysum(args...) length(args)==1 && throw(ArgumentError("I can't sum just one element")) return sum(args...) end
Thank you for your answer. It was very helpful!
Regarding my purpose, I am trying to attract all the people in universities and academia to use Julia instead of Matlab. It is not just me.
Thank you for your answers! It really helps.
I think that some library functions having different names is the easiest part of the transition from Matlab (or any other similar language) to Julia, and is someting that should be tackled from the beginning.
Otherwise, it will be more difficult to ask for help, read code written by others, and contribute to packages.