It doesn't directly answer your question, but one thought is to not force 
many of these ranges to become vectors. For instance, the line
t = t0 + [0:Ns-1;]*Ts;

could also have been written
t = t0 + (0:Ns-1)*Ts;

and that would still be valid input to functions like sin, cos, exp, etc...


On Wednesday, October 21, 2015 at 3:11:44 AM UTC-4, Gabriel Gellner wrote:
>
> I find the way that you need to use `linspace` and `range` objects a bit 
> jarring for when you want to write vectorized code, or when I want to pass 
> an array to a function that requires an Array. I get how nice the iterators 
> are when writing loops and that you can use `collect(iter)` to get a array 
> (and that it is possible to write polymorphic code that takes LinSpace 
> types and uses them like Arrays … but this hurts my small brain). But I 
> find I that I often want to write code that uses an actual array and having 
> to use `collect` all the time seems like a serious wart for an otherwise 
> stunning language for science. (
> https://github.com/JuliaLang/julia/issues/9637 gives the evolution I 
> think of making these iterators)
>
>  
>
> For example recently the following code was posted/refined on this mailing 
> list:
>
>  
>
> function Jakes_Flat( fd, Ts, Ns, t0 = 0, E0 = 1, phi_N = 0 )
>
> # Inputs:
>
> #
>
> # Outputs:
>
>   N0  = 8;                  # As suggested by Jakes
>
>   N   = 4*N0+2;             # An accurate approximation
>
>   wd  = 2*pi*fd;            # Maximum Doppler frequency
>
>   t   = t0 + [0:Ns-1;]*Ts;
>
>   tf  = t[end] + Ts;
>
>   coswt = [ sqrt(2)*cos(wd*t'); 2*cos(wd*cos(2*pi/N*[1:N0;])*t') ]
>
>   temp = zeros(1,N0+1)
>
>   temp[1,2:end] = pi/(N0+1)*[1:N0;]'
>
>   temp[1,1] = phi_N
>
>   h = E0/sqrt(2*N0+1)*exp(im*temp ) * coswt
>
>   return h, tf;
>
> end
>
>  
>
> From <https://groups.google.com/forum/#!topic/julia-users/_lIVpV0e_WI> 
>
>  
>
> Notice all the horrible [<blah>;] notations to make these arrays … and it 
> seems like the devs want to get rid of this notation as well (which they 
> should it is way too subtle in my opinion). So imagine the above code with 
> `collect` statements. Is this the way people work? I find the `collect` 
> statements in mathematical expressions to really break me out of the 
> abstraction (that I am just writing math).
>
>  
>
> I get that this could be written as an explicit loop, and this would 
> likely make it faster as well (man I love looping in Julia). That being 
> said in this case I don't find the vectorized version a performance issue, 
> rather I prefer how this reads as it feels closer to the math to me. 
>
>  
>
> So my question: what is the Juilan way of making explicit arrays using 
> either `range (:)` or `linspace`? Is it to pollute everything with 
> `collect`? Would it be worth having versions of linspace that return an 
> actual array? (something like alinspace or whatnot)
>
>
> Thanks for any tips, comments etc
>

Reply via email to