Ah, makes sense. Thanks! 

On Saturday, April 26, 2014 12:33:48 PM UTC-4, Tim Holy wrote:
>
> When x is of type T, convert(T,x) is a no-op: 
>
> julia> function myfunc(x) 
>            a = convert(Float64, x) 
>            return a 
>        end 
> myfunc (generic function with 1 method) 
>
> julia> code_native(myfunc, (Float32,)) 
>         .text 
> Filename: none 
> Source line: 2 
>         push    RBP 
>         mov     RBP, RSP 
> Source line: 2 
>         movabs  RAX, 140048916337192 
>         movss   DWORD PTR [RAX], XMM0 
>         movss   XMM0, DWORD PTR [RAX] 
>         cvtss2sd        XMM0, XMM0 
> Source line: 3 
>         pop     RBP 
>         ret 
>
> julia> code_native(myfunc, (Float64,)) 
>         .text 
> Filename: none 
> Source line: 3 
>         push    RBP 
>         mov     RBP, RSP 
> Source line: 3 
>         pop     RBP 
>         ret 
>
>
> --Tim 
>
> On Saturday, April 26, 2014 08:45:21 AM Jarrett Revels wrote: 
> > Hello all, 
> > 
> > I was exploring some of the base code today when I saw the 
> implementation 
> > of setindex!(): 
> > 
> > 
> > setindex!{T}(A::Array{T}, x, i0::Real) = arrayset(A, convert(T,x), 
> > to_index(i0)) 
> > 
> > I was surprised that I couldn't find setindex!() methods for elements 
> that 
> > used the type system to forego the use of convert() seen above. For 
> > example, wouldn't it be better to also define methods of the form 
> > 
> > setindex!{T}(A::Array{T}, x::T, i0::Real) = arrayset(A, x, to_index(i0)) 
> > 
> > so that conversion only occurs when necessary? 
> > 
> > I would be willing to make the changes myself, but I assume that there 
> is a 
> > reason for this design choice that I'm just seeing. 
>

Reply via email to