Re: [julia-users] Re: Julia types newbie question

2016-10-23 Thread Angel de Vicente
Hi Simon, Simon Danisch writes: > There is a speed difference, which you can see beautifully like this: > > function _sum{T}(::Type{T}, A) > r = zero(T) > @inbounds for i in eachindex(A) > r += T(A[i]) > end > r > end > great, thanks. My machine seems to be way slower that yours or either I run

[julia-users] Re: Julia types newbie question

2016-10-21 Thread Simon Danisch
There is a speed difference, which you can see beautifully like this: function _sum{T}(::Type{T}, A) r = zero(T) @inbounds for i in eachindex(A) r += T(A[i]) end r end @code_llvm _sum(Int, rand(Int64, 10^6)) -> uses <4,Int64> vectors @code_llvm _sum(Int, rand(Int32, 10^6)

Re: [julia-users] Re: Julia types newbie question

2016-10-21 Thread Angel de Vicente
Hi, Ismael Venegas Castelló writes: > julia> Base.sum{T<:Real, S<:Real}(::Type{T}, xs::Range{S})::T = sum(xs) > julia> r = 1:100; sum(r), sum(Int32, r) thanks for this, but as I understand it, for my particular case in which I'm interested in working with 32bits Integers this would be similar t

[julia-users] Re: Julia types newbie question

2016-10-18 Thread Ismael Venegas Castelló
You can do something like this: C:\Users\Ismael λ julia5 _

Re: [julia-users] Re: Julia types newbie question

2016-10-17 Thread Angel de Vicente
Hi Simon, Simon Danisch writes: > I'm guessing that is done to prevent overflow. > So you need to use your own implementation. > Here are the promote rules defining this behavior: > https://github.com/JuliaLang/julia/blob/master/base/reduce.jl#L32 > So in theory you could also implement your ow

[julia-users] Re: Julia types newbie question

2016-10-17 Thread Simon Danisch
I'm guessing that is done to prevent overflow. So you need to use your own implementation. Here are the promote rules defining this behavior: https://github.com/JuliaLang/julia/blob/master/base/reduce.jl#L32 So in theory you could also implement your own Int type, that has a different promote beh