I am trying Julia after years with MATLAB and Python/NumPy.  When I want to 
scale by a power of 2, I use pow2() in MATLAB and np.ldexp() in Python.  
This maximizes speed and accuracy because it just adds the second argument 
to the floating-point exponent of the first argument (and leaves the 
mantissa alone).  What surprised me about Julia v0.3.5 (advertized as being 
speedy) is that there are no methods for ldexp() supporting vectors or 
arrays.

Using map(ldexp,...) is awkward when I want to iterate on the first 
argument of ldexp() and not the second.  In general, how do I know which 
functions support vectors/arrays and which only support scalers?  If I 
create custom vectorized functions, then I lose forward compatibility with 
the language when (faster) vectorized versions become available in the 
future.  I really want to use the same syntax for scalers and vectors and 
then create vector-optimized methods when speed is important.  I see that 
this is a highly-controversial subject, not planned to be resolved until 
Julia 0.5:
https://github.com/JuliaLang/julia/issues/8450

Since I ran into problems adding new methods to base functions (with an 
implied `using`), I am considering creating custom vectorized functions for 
the types I need in each module (adding a "v" prefix):
`vldexp(x::Array{Float64,1}, e::Int) = [ldexp(x[i], e) for i=1:length(x)]`
`vldexp(x::Array{Float64,2}, e::Int) = [ldexp(x[i,j], e) for i=1:size(x,1), 
j=1:size(x,2)]`
One feature of these methods is user-friendly error messages if the parent 
code calls vldexp() with types not supported by ldexp().  Another feature 
is the speed gained by using specific instead of abstract types.

I assume that Julia will evolve to support the same syntax for scalers and 
vectors (like MATLAB and Python).  Is there a way that I can add new 
vectorized methods with the same name as the base (scaler) methods?  What 
are other community members doing to write fast, vectorized code in Julia 
v0.3 and deal with readability and minimizing code rewrite for future Julia 
versions?

Reply via email to