Skip to content

Conversation

@dmbates
Copy link
Member

@dmbates dmbates commented May 24, 2012

updates to base/distributions.jl to use the libRmath C functions for pdf, etc. as discussed in issue #859

@StefanKarpinski
Copy link
Member

Wonderful! You got really far before you got tired. That was my problem the other night too and all I was doing was inserting stub definitions from wikipedia — this is much more substantial.

StefanKarpinski added a commit that referenced this pull request May 24, 2012
Actual working code for probability distributions from Doug Bates.
@StefanKarpinski StefanKarpinski merged commit f1fb16d into JuliaLang:master May 24, 2012
@StefanKarpinski
Copy link
Member

I love it:

julia> Normal()
Normal(0.0,1.0)

julia> pdf(Normal(),1.0)
0.24197072451914337

julia> pdf(Normal(),0.0)
0.3989422804014327

julia> cdf(Normal(),0.0)
0.5

julia> cdf(Normal(),1.0)
0.797939722603012

julia> ccdf(Normal(),1.0)
0.15865525393145705

ericphanson added a commit to ericphanson/julia that referenced this pull request Sep 3, 2021
```julia
julia> f(i) = (sleep(i); i == 5 && error("5"))
f (generic function with 1 method)

julia> asyncmap(f, 1:5) # master
ERROR: 5
Stacktrace:
 [1] (::Base.var"JuliaLang#881#883")(x::Task)
   @ Base ./asyncmap.jl:177
 [2] foreach(f::Base.var"JuliaLang#881#883", itr::Vector{Any})
   @ Base ./abstractarray.jl:2606
 [3] maptwice(wrapped_f::Function, chnl::Channel{Any}, worker_tasks::Vector{Any}, c::UnitRange{Int64})
   @ Base ./asyncmap.jl:177
 [4] wrap_n_exec_twice
   @ ./asyncmap.jl:153 [inlined]
 [5] async_usemap(f::typeof(f), c::UnitRange{Int64}; ntasks::Int64, batch_size::Nothing)
   @ Base ./asyncmap.jl:103
 [6] #asyncmap#865
   @ ./asyncmap.jl:81 [inlined]
 [7] asyncmap(f::Function, c::UnitRange{Int64})
   @ Base ./asyncmap.jl:81
 [8] top-level scope
   @ REPL[4]:1

julia> function Base.start_worker_task!(worker_tasks, exec_func, chnl, batch_size=nothing) # monkeypatch
           t = @async begin
               retval = nothing

               try
                   if isa(batch_size, Number)
                       while isopen(chnl)
                           # The mapping function expects an array of input args, as it processes
                           # elements in a batch.
                           batch_collection=Any[]
                           n = 0
                           for exec_data in chnl
                               push!(batch_collection, exec_data)
                               n += 1
                               (n == batch_size) && break
                           end
                           if n > 0
                               exec_func(batch_collection)
                           end
                       end
                   else
                       for exec_data in chnl
                           exec_func(exec_data...)
                       end
                   end
               catch e
                   close(chnl)
                   Base.display_error(stderr, Base.catch_stack())
                   retval = e
               end
               retval
           end
           push!(worker_tasks, t)
       end

julia> function Base.start_worker_task!(worker_tasks, exec_func, chnl, batch_size=nothing)
           t = @async begin
               retval = nothing

               try
                   if isa(batch_size, Number)
                       while isopen(chnl)
                           # The mapping function expects an array of input args, as it processes
                           # elements in a batch.
julia> function Base.start_worker_task!(worker_tasks, exec_func, chnl, batch_size=nothing)
           t = @async begin
               retval = nothing

               try
                   if isa(batch_size, Number)
                       while isopen(chnl)
                           # The mapping function expects an array of input args, as it processes
                           # elements in a batch.
julia> asyncmap(f, 1:5) # post-patch
ERROR: 5
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] f
   @ ./REPL[3]:1 [inlined]
 [3] (::Base.var"JuliaLang#871#876"{typeof(f)})(r::Base.RefValue{Any}, args::Tuple{Int64})
   @ Base ./asyncmap.jl:100
 [4] macro expansion
   @ ./REPL[5]:23 [inlined]
 [5] (::var"JuliaLang#1#2"{Base.var"JuliaLang#871#876"{typeof(f)}, Channel{Any}, Nothing})()
   @ Main ./task.jl:411
ERROR: 5
Stacktrace:
 [1] (::Base.var"JuliaLang#881#883")(x::Task)
   @ Base ./asyncmap.jl:177
 [2] foreach(f::Base.var"JuliaLang#881#883", itr::Vector{Any})
   @ Base ./abstractarray.jl:2606
 [3] maptwice(wrapped_f::Function, chnl::Channel{Any}, worker_tasks::Vector{Any}, c::UnitRange{Int64})
   @ Base ./asyncmap.jl:177
 [4] wrap_n_exec_twice
   @ ./asyncmap.jl:153 [inlined]
 [5] async_usemap(f::typeof(f), c::UnitRange{Int64}; ntasks::Int64, batch_size::Nothing)
   @ Base ./asyncmap.jl:103
 [6] #asyncmap#865
   @ ./asyncmap.jl:81 [inlined]
 [7] asyncmap(f::Function, c::UnitRange{Int64})
   @ Base ./asyncmap.jl:81
 [8] top-level scope
   @ REPL[6]:1
```
ericphanson added a commit to ericphanson/julia that referenced this pull request Dec 28, 2021
```julia
julia> f(i) = (sleep(i); i == 5 && error("5"))
f (generic function with 1 method)

julia> asyncmap(f, 1:5) # master
ERROR: 5
Stacktrace:
 [1] (::Base.var"JuliaLang#881#883")(x::Task)
   @ Base ./asyncmap.jl:177
 [2] foreach(f::Base.var"JuliaLang#881#883", itr::Vector{Any})
   @ Base ./abstractarray.jl:2606
 [3] maptwice(wrapped_f::Function, chnl::Channel{Any}, worker_tasks::Vector{Any}, c::UnitRange{Int64})
   @ Base ./asyncmap.jl:177
 [4] wrap_n_exec_twice
   @ ./asyncmap.jl:153 [inlined]
 [5] async_usemap(f::typeof(f), c::UnitRange{Int64}; ntasks::Int64, batch_size::Nothing)
   @ Base ./asyncmap.jl:103
 [6] #asyncmap#865
   @ ./asyncmap.jl:81 [inlined]
 [7] asyncmap(f::Function, c::UnitRange{Int64})
   @ Base ./asyncmap.jl:81
 [8] top-level scope
   @ REPL[4]:1

julia> function Base.start_worker_task!(worker_tasks, exec_func, chnl, batch_size=nothing) # monkeypatch
           t = @async begin
               retval = nothing

               try
                   if isa(batch_size, Number)
                       while isopen(chnl)
                           # The mapping function expects an array of input args, as it processes
                           # elements in a batch.
                           batch_collection=Any[]
                           n = 0
                           for exec_data in chnl
                               push!(batch_collection, exec_data)
                               n += 1
                               (n == batch_size) && break
                           end
                           if n > 0
                               exec_func(batch_collection)
                           end
                       end
                   else
                       for exec_data in chnl
                           exec_func(exec_data...)
                       end
                   end
               catch e
                   close(chnl)
                   Base.display_error(stderr, Base.catch_stack())
                   retval = e
               end
               retval
           end
           push!(worker_tasks, t)
       end

julia> function Base.start_worker_task!(worker_tasks, exec_func, chnl, batch_size=nothing)
           t = @async begin
               retval = nothing

               try
                   if isa(batch_size, Number)
                       while isopen(chnl)
                           # The mapping function expects an array of input args, as it processes
                           # elements in a batch.
julia> function Base.start_worker_task!(worker_tasks, exec_func, chnl, batch_size=nothing)
           t = @async begin
               retval = nothing

               try
                   if isa(batch_size, Number)
                       while isopen(chnl)
                           # The mapping function expects an array of input args, as it processes
                           # elements in a batch.
julia> asyncmap(f, 1:5) # post-patch
ERROR: 5
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] f
   @ ./REPL[3]:1 [inlined]
 [3] (::Base.var"JuliaLang#871#876"{typeof(f)})(r::Base.RefValue{Any}, args::Tuple{Int64})
   @ Base ./asyncmap.jl:100
 [4] macro expansion
   @ ./REPL[5]:23 [inlined]
 [5] (::var"JuliaLang#1#2"{Base.var"JuliaLang#871#876"{typeof(f)}, Channel{Any}, Nothing})()
   @ Main ./task.jl:411
ERROR: 5
Stacktrace:
 [1] (::Base.var"JuliaLang#881#883")(x::Task)
   @ Base ./asyncmap.jl:177
 [2] foreach(f::Base.var"JuliaLang#881#883", itr::Vector{Any})
   @ Base ./abstractarray.jl:2606
 [3] maptwice(wrapped_f::Function, chnl::Channel{Any}, worker_tasks::Vector{Any}, c::UnitRange{Int64})
   @ Base ./asyncmap.jl:177
 [4] wrap_n_exec_twice
   @ ./asyncmap.jl:153 [inlined]
 [5] async_usemap(f::typeof(f), c::UnitRange{Int64}; ntasks::Int64, batch_size::Nothing)
   @ Base ./asyncmap.jl:103
 [6] #asyncmap#865
   @ ./asyncmap.jl:81 [inlined]
 [7] asyncmap(f::Function, c::UnitRange{Int64})
   @ Base ./asyncmap.jl:81
 [8] top-level scope
   @ REPL[6]:1
```
ericphanson added a commit to ericphanson/julia that referenced this pull request Jan 4, 2022
```julia
julia> f(i) = (sleep(i); i == 5 && error("5"))
f (generic function with 1 method)

julia> asyncmap(f, 1:5) # master
ERROR: 5
Stacktrace:
 [1] (::Base.var"JuliaLang#881#883")(x::Task)
   @ Base ./asyncmap.jl:177
 [2] foreach(f::Base.var"JuliaLang#881#883", itr::Vector{Any})
   @ Base ./abstractarray.jl:2606
 [3] maptwice(wrapped_f::Function, chnl::Channel{Any}, worker_tasks::Vector{Any}, c::UnitRange{Int64})
   @ Base ./asyncmap.jl:177
 [4] wrap_n_exec_twice
   @ ./asyncmap.jl:153 [inlined]
 [5] async_usemap(f::typeof(f), c::UnitRange{Int64}; ntasks::Int64, batch_size::Nothing)
   @ Base ./asyncmap.jl:103
 [6] #asyncmap#865
   @ ./asyncmap.jl:81 [inlined]
 [7] asyncmap(f::Function, c::UnitRange{Int64})
   @ Base ./asyncmap.jl:81
 [8] top-level scope
   @ REPL[4]:1

julia> function Base.start_worker_task!(worker_tasks, exec_func, chnl, batch_size=nothing) # monkeypatch
           t = @async begin
               retval = nothing

               try
                   if isa(batch_size, Number)
                       while isopen(chnl)
                           # The mapping function expects an array of input args, as it processes
                           # elements in a batch.
                           batch_collection=Any[]
                           n = 0
                           for exec_data in chnl
                               push!(batch_collection, exec_data)
                               n += 1
                               (n == batch_size) && break
                           end
                           if n > 0
                               exec_func(batch_collection)
                           end
                       end
                   else
                       for exec_data in chnl
                           exec_func(exec_data...)
                       end
                   end
               catch e
                   close(chnl)
                   Base.display_error(stderr, Base.catch_stack())
                   retval = e
               end
               retval
           end
           push!(worker_tasks, t)
       end

julia> function Base.start_worker_task!(worker_tasks, exec_func, chnl, batch_size=nothing)
           t = @async begin
               retval = nothing

               try
                   if isa(batch_size, Number)
                       while isopen(chnl)
                           # The mapping function expects an array of input args, as it processes
                           # elements in a batch.
julia> function Base.start_worker_task!(worker_tasks, exec_func, chnl, batch_size=nothing)
           t = @async begin
               retval = nothing

               try
                   if isa(batch_size, Number)
                       while isopen(chnl)
                           # The mapping function expects an array of input args, as it processes
                           # elements in a batch.
julia> asyncmap(f, 1:5) # post-patch
ERROR: 5
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] f
   @ ./REPL[3]:1 [inlined]
 [3] (::Base.var"JuliaLang#871#876"{typeof(f)})(r::Base.RefValue{Any}, args::Tuple{Int64})
   @ Base ./asyncmap.jl:100
 [4] macro expansion
   @ ./REPL[5]:23 [inlined]
 [5] (::var"JuliaLang#1#2"{Base.var"JuliaLang#871#876"{typeof(f)}, Channel{Any}, Nothing})()
   @ Main ./task.jl:411
ERROR: 5
Stacktrace:
 [1] (::Base.var"JuliaLang#881#883")(x::Task)
   @ Base ./asyncmap.jl:177
 [2] foreach(f::Base.var"JuliaLang#881#883", itr::Vector{Any})
   @ Base ./abstractarray.jl:2606
 [3] maptwice(wrapped_f::Function, chnl::Channel{Any}, worker_tasks::Vector{Any}, c::UnitRange{Int64})
   @ Base ./asyncmap.jl:177
 [4] wrap_n_exec_twice
   @ ./asyncmap.jl:153 [inlined]
 [5] async_usemap(f::typeof(f), c::UnitRange{Int64}; ntasks::Int64, batch_size::Nothing)
   @ Base ./asyncmap.jl:103
 [6] #asyncmap#865
   @ ./asyncmap.jl:81 [inlined]
 [7] asyncmap(f::Function, c::UnitRange{Int64})
   @ Base ./asyncmap.jl:81
 [8] top-level scope
   @ REPL[6]:1
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants