[julia-users] Re: PkgDev.tag issues

2016-09-24 Thread Brandon Taylor
Ok, I deleted the extraneous tags, and retagged. Same thing messages about 
no changes to commit.

So I git added the new v0.1.0 folder and then committed manually.

Then I tried PkgDev.publish() and I got this:

ERROR: GitError(Code:EAUTH, Class:None, No errors)
 in macro expansion at .\libgit2\error.jl:99 [inlined]
 in #push#53(::Bool, ::Base.LibGit2.PushOptions, ::Function, 
::Base.LibGit2.GitRemote, ::Array{String,1}) at .\libgit2\remote.jl:84
 in (::Base.LibGit2.#kw##push)(::Array{Any,1}, ::Base.LibGit2.#push, 
::Base.LibGit2.GitRemote, ::Array{String,1}) at .\:0
 in #push#94(::String, ::String, ::Array{String,1}, ::Bool, 
::Nullable{Base.LibGit2.UserPasswordCredentials}, ::Function, 
::Base.LibGit2.GitRepo) at .\libgit2\libgit2.jl:185
 in (::Base.LibGit2.#kw##push)(::Array{Any,1}, ::Base.LibGit2.#push, 
::Base.LibGit2.GitRepo) at .\:0
 in 
(::PkgDev.Entry.##6#11{Dict{String,Array{String,1}}})(::Base.LibGit2.GitRepo) 
at C:\Users\jsnot\.julia\v0.5\PkgDev\src\entry.jl:114
 in with(::PkgDev.Entry.##6#11{Dict{String,Array{String,1}}}, 
::Base.LibGit2.GitRepo) at .\libgit2\types.jl:638
 in publish(::String, ::String) at 
C:\Users\jsnot\.julia\v0.5\PkgDev\src\entry.jl:97
 in publish() at C:\Users\jsnot\.julia\v0.5\PkgDev\src\PkgDev.jl:70

So then I tried to checkout PkgDev as suggested here:
https://github.com/JuliaLang/PkgDev.jl/issues/69

and now I'm getting

INFO: Validating METADATA
INFO: Creating a personal access token for Julia Package Manager on GitHub.
You will be asked to provide credentials to your GitHub account.
Enter host password for user 'bramtayl':
INFO: Pushing ChainMap permanent tags: v0.1.0
INFO: Submitting METADATA changes
INFO: Forking JuliaLang/METADATA.jl to bramtayl
INFO: Pushing changes as branch pull-request/2ed12a90
ERROR: GitError(Code:ERROR, Class:Net, Remote error: access denied or 
repository not exported: /2/nw/29/05/c9/6106340/69147216.git)
 in macro expansion at .\libgit2\error.jl:99 [inlined]
 in #push#53(::Bool, ::Base.LibGit2.PushOptions, ::Function, 
::Base.LibGit2.GitRemote, ::Array{String,1}) at .\libgit2\remote.jl:84
 in (::Base.LibGit2.#kw##push)(::Array{Any,1}, ::Base.LibGit2.#push, 
::Base.LibGit2.GitRemote, ::Array{String,1}) at .\:0
 in #push#94(::String, ::String, ::Array{String,1}, ::Bool, 
::Nullable{Base.LibGit2.UserPasswordCredentials}, ::Function, 
::Base.LibGit2.GitRepo) at .\libgit2\libgit2.jl:185
 in (::Base.LibGit2.#kw##push)(::Array{Any,1}, ::Base.LibGit2.#push, 
::Base.LibGit2.GitRepo) at .\:0
 in (::PkgDev.Entry.##2#3)(::Base.LibGit2.GitRepo) at 
C:\Users\jsnot\.julia\v0.5\PkgDev\src\entry.jl:39
 in with(::PkgDev.Entry.##2#3, ::Base.LibGit2.GitRepo) at 
.\libgit2\types.jl:638
 in #pull_request#1(::String, ::String, ::String, ::Function, ::String) at 
C:\Users\jsnot\.julia\v0.5\PkgDev\src\entry.jl:15
 in (::PkgDev.Entry.#kw##pull_request)(::Array{Any,1}, 
::PkgDev.Entry.#pull_request, ::String) at .\:0
 in publish(::String, ::String) at 
C:\Users\jsnot\.julia\v0.5\PkgDev\src\entry.jl:121
 in publish() at C:\Users\jsnot\.julia\v0.5\PkgDev\src\PkgDev.jl:70


On Saturday, September 24, 2016 at 10:02:21 PM UTC-4, Tony Kelman wrote:
>
> You may have to remove the git tag from your local clone of the package 
> repo.



[julia-users] Re: if-elseif-else programmatically

2016-09-24 Thread Fengyang Wang
Oh yeah, or x[direction] += rand(-1:2:1) to avoid the need for the 
allocation in the first place.

On Sunday, September 25, 2016 at 1:01:47 AM UTC-4, Fengyang Wang wrote:
>
> You could even do x[direction] += rand([-1, 1]). The allocation can be 
> avoided by defining a global constant with [-1, 1] as its contents.
>
> On Saturday, September 24, 2016 at 6:54:47 PM UTC-4, Steven G. Johnson 
> wrote:
>>
>>
>>
>> On Saturday, September 24, 2016 at 6:09:14 PM UTC-4, David P. Sanders 
>> wrote:
>>>
>>> julia> if rand() < 0.5
>>>
>>
>> You can also do "if rand(Bool)"
>>
>

[julia-users] Re: if-elseif-else programmatically

2016-09-24 Thread Fengyang Wang
You could even do x[direction] += rand([-1, 1]). The allocation can be 
avoided by defining a global constant with [-1, 1] as its contents.

On Saturday, September 24, 2016 at 6:54:47 PM UTC-4, Steven G. Johnson 
wrote:
>
>
>
> On Saturday, September 24, 2016 at 6:09:14 PM UTC-4, David P. Sanders 
> wrote:
>>
>> julia> if rand() < 0.5
>>
>
> You can also do "if rand(Bool)"
>


[julia-users] Re: How to update a precompiled Module's data from a second module?

2016-09-24 Thread Philip Tellis
Ok, just discovered that I should put my code from External into 
`__init__()` to get it to run at compile time


[julia-users] How to update a precompiled Module's data from a second module?

2016-09-24 Thread Philip Tellis
I have two modules that are included by a julia program.  Let's call them 
Primary and External.

Primary contains a list of names in an array that's global to the module 
and a method to register new names:

module Primary

global names = AbstractString[]

function registerName(name::AbstractString)
push!(names, name)
end

end

External needs to register a name into Primary, and does that in its 
initialization code:

module External

using Primary

Primary.registerName("external")

end

This works.  If I load both modules into my program or the REPL, 
Primary.names contains "external"

However, if I add __precompile__(true) to the top of Primary, this no 
longer works.  Primary.names is now always an empty array.  However, I can 
still call Primary.registerName from the REPL or my program and it works.

Is there any way for me to get Primary.registerName to work when called 
from a second module?


[julia-users] Re: PkgDev.tag issues

2016-09-24 Thread Tony Kelman
You may have to remove the git tag from your local clone of the package repo.

[julia-users] Re: Broadcast slices

2016-09-24 Thread Brandon Taylor
Or I guess that should be

broadcast_slices(best_response_dimension, player_dimension, payoff_matrix, 
players)

On Saturday, September 24, 2016 at 9:38:55 PM UTC-4, Brandon Taylor wrote:
>
> I guess, but I'm trying to write a generic program where I don't know the 
> size of the array? I'm trying to find Nash Equilibrium for an n dimensional 
> array, where the player strategies are along dimensions 1:n-1, and the 
> players are along dimension n. So:
>
> equals_max(x) = x .== maximum(x)
>
> best_response_dimension(payoff_matrix, dimension) =
> mapslices(equals_max, payoff_matrix, dimension)
>
> I'd want to do something like this:
>
> player_dimension = ndims(payoff_matrix)
> other_dimensions = repeat([1], inner = player_dimension - 1)
> number_of_players = size(payoff_matrix)[player_dimension]
>
>
> players = reshape(1:number_of_players, other_dimensions..., 
> number_of_players)
>
> broadcast_slices(best_response_dimension, payoff_matrix, players)
>
> On Thursday, September 22, 2016 at 9:00:51 PM UTC-4, Steven G. Johnson 
> wrote:
>>
>> At some point, it is simpler to just write loops than to try and express 
>> a complicated operation in terms of higher-order functions like broadcast.
>>
>

[julia-users] Re: Broadcast slices

2016-09-24 Thread Brandon Taylor
I guess, but I'm trying to write a generic program where I don't know the 
size of the array? I'm trying to find Nash Equilibrium for an n dimensional 
array, where the player strategies are along dimensions 1:n-1, and the 
players are along dimension n. So:

equals_max(x) = x .== maximum(x)

best_response_dimension(payoff_matrix, dimension) =
mapslices(equals_max, payoff_matrix, dimension)

I'd want to do something like this:

player_dimension = ndims(payoff_matrix)
other_dimensions = repeat([1], inner = player_dimension - 1)
number_of_players = size(payoff_matrix)[player_dimension]


players = reshape(1:number_of_players, other_dimensions..., 
number_of_players)

broadcast_slices(best_response_dimension, payoff_matrix, players)

On Thursday, September 22, 2016 at 9:00:51 PM UTC-4, Steven G. Johnson 
wrote:
>
> At some point, it is simpler to just write loops than to try and express a 
> complicated operation in terms of higher-order functions like broadcast.
>


[julia-users] Re: PkgDev.tag issues

2016-09-24 Thread Brandon Taylor
Pkg.status():

julia> Pkg.status()
3 required packages:
 - IJulia1.3.2
 - PkgDev0.1.2
 - SymPy 0.3.2
62 additional packages:
 - ASTInterpreter0.0.4
 - AbstractTrees 0.0.4
 - ArgParse  0.3.1
 - Atom  0.5.2+ master
 - BinDeps   0.4.5
 - Blink 0.4.1+ master
 - Blosc 0.1.7
 - BufferedStreams   0.2.0
 - COFF  0.0.2
 - CRC   1.1.1
 - ChainMap  1.0.0  master
 - CodeTools 0.4.0
 - Codecs0.2.0
 - ColorTypes0.2.6
 - Colors0.6.7
 - Compat0.9.2  master
 - Conda 0.3.2
 - DWARF 0.1.0
 - DataStructures0.4.6
 - ELF   0.1.0
 - FileIO0.1.2
 - FixedPointNumbers 0.1.7
 - Gallium   0.0.4
 - HDF5  0.6.6
 - Hiccup0.0.3
 - HttpCommon0.2.6
 - HttpParser0.2.0
 - HttpServer0.1.6+ master
 - JLD   0.6.3
 - JSON  0.7.0
 - JuliaParser   0.7.4
 - Juno  0.2.1+ master
 - LNR   0.0.2
 - Lazy  0.11.2
 - LegacyStrings 0.1.1
 - LibExpat  0.2.1
 - Libz  0.2.0
 - MachO 0.0.4
 - MacroTools0.3.2+ master
 - MbedTLS   0.3.0
 - Media 0.2.2
 - Mustache  0.1.2
 - Mux   0.2.1+ master
 - Nettle0.2.4  master
 - NullableArrays0.0.9
 - ObjFileBase   0.0.4
 - PyCall1.7.2
 - Reactive  0.3.4
 - RecipesBase   0.0.6
 - Reexport  0.0.3
 - Requires  0.3.0  master
 - SHA   0.2.1
 - StructIO  0.0.2
 - TerminalUI0.0.2
 - TextWrap  0.1.6
 - URIParser 0.1.6
 - VT100 0.0.2
 - Weave 0.1.2+ master (dirty)
 - WebSockets0.2.1  master
 - WinRPM0.2.1
 - ZMQ   0.3.4
 - jl_8DD2.tmp   0.0.0- non-repo (unregistered)

METADATA git status

On branch metadata-v2
Your branch is up-to-date with 'origin/metadata-v2'.
Untracked files:
  (use "git add ..." to include in what will be committed)

ChainMap/versions/1.0.0/

nothing added to commit but untracked files present (use "git add" to track)

ChainMap git status:

On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

I can try git add

But first, I wanted to back to METADATA and delete all my failed attempts 
at tagging. I deleted all folders > 0.0.10 (my last published tag).

Now, I can't tag a patch, minor, or major version. I'm just getting this:

ERROR: GitError(Code:EEXISTS, Class:Tag, Tag already exists)
 in macro expansion at .\libgit2\error.jl:99 [inlined]
 in 
(::Base.LibGit2.##74#76{Base.LibGit2.GitCommit,String,Bool,Base.LibGit2.GitRepo,String,Base.RefValue{Base.LibGit2.Oid}})(::Base.LibGit2.GitSignature)
 
at .\libgit2\tag.jl:25
 in 
with(::Base.LibGit2.##74#76{Base.LibGit2.GitCommit,String,Bool,Base.LibGit2.GitRepo,String,Base.RefValue{Base.LibGit2.Oid}},
 
::Base.LibGit2.GitSignature) at .\libgit2\types.jl:638
 in 
(::Base.LibGit2.##73#75{String,Bool,Base.LibGit2.Signature,Base.LibGit2.GitRepo,String,Base.RefValue{Base.LibGit2.Oid}})(::Base.LibGit2.GitCommit)
 
at .\libgit2\tag.jl:24
 in 
with(::Base.LibGit2.##73#75{String,Bool,Base.LibGit2.Signature,Base.LibGit2.GitRepo,String,Base.RefValue{Base.LibGit2.Oid}},
 
::Base.LibGit2.GitCommit) at .\libgit2\types.jl:638
 in #tag_create#72(::String, ::Bool, ::Base.LibGit2.Signature, ::Function, 
::Base.LibGit2.GitRepo, ::String, ::String) at .\libgit2\tag.jl:22
 in (::Base.LibGit2.#kw##tag_create)(::Array{Any,1}, 
::Base.LibGit2.#tag_create, ::Base.LibGit2.GitRepo, ::String, ::String) at 
.\:0
 in (::PkgDev.Entry.##37#45{String,Bool,String})(::Base.LibGit2.GitRepo) at 
C:\Users\jsnot\.julia\v0.5\PkgDev\src\entry.jl:261
 in with(::PkgDev.Entry.##37#45{String,Bool,String}, 
::Base.LibGit2.GitRepo) at .\libgit2\types.jl:638
 in tag(::String, ::Symbol, ::Bool, ::String) at 
C:\Users\jsnot\.julia\v0.5\PkgDev\src\e

[julia-users] Re: Get the red out!

2016-09-24 Thread Simon Danisch
How about something like this:

function showtypetree(T, level=0)
println("\t" ^ level, T)
for t in subtypes(T)
(t != Any) && showtypetree(t, level+1)
end   
end

This is still not type stable, since *_subtype *seems to use untyped sets:
https://github.com/JuliaLang/julia/blob/master/base/reflection.jl#L283

Not sure if this is an oversight, or if there are actually corner cases 
making it impossible to type as Set{DataType}().
Fact is, with that change subtype is 10x faster and doesn't return 
Vector{Any} anymore.
I opened a PR:
https://github.com/JuliaLang/julia/pull/18663

Best,
Simon


Am Sonntag, 25. September 2016 00:12:16 UTC+2 schrieb Brian Rogoff:
>
> ... of @code_warntype output.
>
> I was reading 
> https://en.wikibooks.org/wiki/Introducing_Julia/Types#Investigating_types 
> and I came across the following code, described as "not very elegant":
>
> level = 0
> function showtypetree(subtype)
> global level
> subtypelist = filter(asubtype -> asubtype != Any, subtypes(subtype))
> if length(subtypelist) > 0 
>  println("\t" ^ level, subtype)
>  level += 1
>  map(showtypetree, subtypelist)
>  level -= 1
> else
>  println("\t" ^ level, subtype)
> end
> end
>
> showtypetree(Number)
>
>
> Being unable to leave well enough alone, I decided to try to make it more 
> elegant. After replacing the inelegant global variable with a nested 
> function, I first noticed that the function returns '0', which is ugly. So, 
> the increment operators return a value, which is unfortunate (any reason 
> there's no increment with doesn't do that?) and the two branches of the if 
> return different types. A special 'ignore' function patches that. map also 
> builds and returns a value that's discarded. In OCaml we'd use an 'iter' 
> instead of 'map', but Julia's 'for' can be a one-liner too. I left the 
> print alone even though there's no need to repeatedly build those strings 
> (print_nchars_before is easy)  .In the end I got here
>
> ignore{T<:Any}(value::T)::Void = return
>
> function showtypetree(subtype::DataType)::Void
> level::Int64 = 0
> function nested(st::DataType)::Void
> subtypelist = filter(asubtype -> asubtype != Any, subtypes(st))
> if length(subtypelist) > 0 
> println("\t" ^ level, st)
> level += 1
> for s in subtypelist nested(s)  end
> ignore(level -= 1)
> else
> println("\t" ^ level, st)
> end
> end
> nested(subtype)
> end
>
>
> I still notice that when I do @code_warntype showtypetree(Number), I get 
> some 'red', notably, level is shown as Core.Box, even though I explicitly 
> type it. Is there some way to reduce the red in the @code_warntype for this 
> function? Here's what I get in 0.6.0-dev.749
>
> julia> @code_warntype showtypetree(Number)
> Variables:
>   #self#::#showtypetree
>   subtype::Type{Number}
>   level::Core.Box
>   nested::Core.Box
>
> Body:
>   begin
>   level::Core.Box = $(Expr(:new, :(Core.Box)))
>   nested::Core.Box = $(Expr(:new, :(Core.Box)))
>   SSAValue(0) = Main.Void
>   (Core.setfield!)(level::Core.Box,:contents,0)::Int64 # line 3:
>   SSAValue(1) = $(Expr(:new, :(Main.#nested#2), :(level), :(nested)))
>   (Core.setfield!)(nested::Core.Box,:contents,SSAValue(1))::#nested#2 
> # line 16:
>   return 
> (Base.convert)(SSAValue(0),((Core.getfield)(nested::Core.Box,:contents)::Any)(subtype::Type{Number})::Any)::Void
>   end::Void
>
>
> and I'm not sure how to remove the red and make the code more elegant. 
> Ideas?
>
>

[julia-users] Re: if-elseif-else programmatically

2016-09-24 Thread Steven G. Johnson


On Saturday, September 24, 2016 at 6:09:14 PM UTC-4, David P. Sanders wrote:
>
> julia> if rand() < 0.5
>

You can also do "if rand(Bool)"


[julia-users] Get the red out!

2016-09-24 Thread Brian Rogoff
... of @code_warntype output.

I was reading 
https://en.wikibooks.org/wiki/Introducing_Julia/Types#Investigating_types 
and I came across the following code, described as "not very elegant":

level = 0
function showtypetree(subtype)
global level
subtypelist = filter(asubtype -> asubtype != Any, subtypes(subtype))
if length(subtypelist) > 0 
 println("\t" ^ level, subtype)
 level += 1
 map(showtypetree, subtypelist)
 level -= 1
else
 println("\t" ^ level, subtype)
end
end

showtypetree(Number)


Being unable to leave well enough alone, I decided to try to make it more 
elegant. After replacing the inelegant global variable with a nested 
function, I first noticed that the function returns '0', which is ugly. So, 
the increment operators return a value, which is unfortunate (any reason 
there's no increment with doesn't do that?) and the two branches of the if 
return different types. A special 'ignore' function patches that. map also 
builds and returns a value that's discarded. In OCaml we'd use an 'iter' 
instead of 'map', but Julia's 'for' can be a one-liner too. I left the 
print alone even though there's no need to repeatedly build those strings 
(print_nchars_before is easy)  .In the end I got here

ignore{T<:Any}(value::T)::Void = return

function showtypetree(subtype::DataType)::Void
level::Int64 = 0
function nested(st::DataType)::Void
subtypelist = filter(asubtype -> asubtype != Any, subtypes(st))
if length(subtypelist) > 0 
println("\t" ^ level, st)
level += 1
for s in subtypelist nested(s)  end
ignore(level -= 1)
else
println("\t" ^ level, st)
end
end
nested(subtype)
end


I still notice that when I do @code_warntype showtypetree(Number), I get 
some 'red', notably, level is shown as Core.Box, even though I explicitly 
type it. Is there some way to reduce the red in the @code_warntype for this 
function? Here's what I get in 0.6.0-dev.749

julia> @code_warntype showtypetree(Number)
Variables:
  #self#::#showtypetree
  subtype::Type{Number}
  level::Core.Box
  nested::Core.Box

Body:
  begin
  level::Core.Box = $(Expr(:new, :(Core.Box)))
  nested::Core.Box = $(Expr(:new, :(Core.Box)))
  SSAValue(0) = Main.Void
  (Core.setfield!)(level::Core.Box,:contents,0)::Int64 # line 3:
  SSAValue(1) = $(Expr(:new, :(Main.#nested#2), :(level), :(nested)))
  (Core.setfield!)(nested::Core.Box,:contents,SSAValue(1))::#nested#2 # 
line 16:
  return 
(Base.convert)(SSAValue(0),((Core.getfield)(nested::Core.Box,:contents)::Any)(subtype::Type{Number})::Any)::Void
  end::Void


and I'm not sure how to remove the red and make the code more elegant. 
Ideas?



[julia-users] Re: if-elseif-else programmatically

2016-09-24 Thread David P. Sanders


El sábado, 24 de septiembre de 2016, 21:26:52 (UTC+2), 
lapeyre@gmail.com escribió:
>
> I want to generate something like an if-elseif-else construct or 
> switch-case programmatically.
>
> The use I have in mind is to write an expression for taking a step in a 
> random walk in n dimensions,
> so I need 2*n branches.
>

This is not a good way to solve this problem. Since you are in n 
dimensions, just use a vector of length n,
so that x[i] is the position in direction i (rather than generating a 
variable called x1, another x2, etc.). Then do something like this:

julia> n = 10

julia> x = zeros(n)

julia> direction = rand(1:n)

julia> if rand() < 0.5
 x[direction] += 1
   else
 x[direction] -= 1
   end

>
>

[julia-users] if-elseif-else programmatically

2016-09-24 Thread lapeyre . math122a
I want to generate something like an if-elseif-else construct or 
switch-case programmatically.

The use I have in mind is to write an expression for taking a step in a 
random walk in n dimensions,
so I need 2*n branches.

The solution I found is not very readable. I wonder if there is an easier 
way to do it.

The function to generate the code is here 
https://gist.github.com/jlapeyre/66c7714f22c66123add5db0accf1f01d
The application to a random walk step is here 
https://gist.github.com/jlapeyre/b93bead293f903b6afb1cc5d4bd14d13




Re: [julia-users] Generators vs Comprehensions, Type-stability?

2016-09-24 Thread Steven G. Johnson


On Saturday, September 24, 2016 at 9:09:38 AM UTC-4, Michele Zaffalon 
wrote: 
>
> Sorry for being slow: the input array rand(10) or the output array, the 
> square of each element of rand(10)?
>
> julia> (begin;println(t);t^2;end for t=1:10)
> Base.Generator{UnitRange{Int64},##37#38}(#37,1:10)
>

Julia knows that the input to the generator is a UnitRange{Int64}, i.e. 
1:10, so the input elements are Int64.   It knows that the function being 
computed is t -> t^2.   The compiler is smart enough that it can figure out 
that if t is an Int64, then t^2 is an Int64 too, because that function is 
type stable.   So, it can figure out that the eltype of the output (i.e. 
the Generator) is Int64, all at compile time without actually evaluating 
the function.


Re: [julia-users] Why for loop slower than the vectorized operation?

2016-09-24 Thread Weicheng Zhu
OK, I see.
Thank you very much!

On Saturday, September 24, 2016 at 11:11:41 AM UTC-5, Spencer Russell wrote:
>
> Take a look at the performance tips in the manual:
> http://docs.julialang.org/en/release-0.5/manual/performance-tips/
>
> One of the main things is to avoid accessing global variables, and 
> everything declared at the top-level in the REPL is global, so you 
> generally want to put any performance-sensitive code (and variables 
> accessed in that code) inside a function.
>
> -s
>
> On Sep 24, 2016, at 12:04 PM, Weicheng Zhu > 
> wrote:
>
> Hi there,
> Could anybody tell me what's wrong with my for loop code below and how to 
> improve it? 
> I was surprised to see it performs worse than the vectorized operation.
> Thank you!
>
> ## Calculate the maximum number in vector x that is less or equal to 0.5
>> ## Method 1
>> x=rand(1)
>> @time maximum(x[x.<=0.5])
>> # 0.000205 seconds (23 allocations: 45.141 KB)
>> ## Method 2
>> u= x[1]
>> @time @inbounds for i in 2:length(x)
>> if u <  x[i] && x[i] <= 0.5
>> u = x[i]
>> end
>> end
>> # 0.001233 seconds (42.40 k allocations: 818.766 KB)
>
>
>
> Best,
> Weicheng
>
>
>
>

Re: [julia-users] Why for loop slower than the vectorized operation?

2016-09-24 Thread Weicheng Zhu
OK, I see.
Thank you very much!

On Saturday, September 24, 2016 at 11:11:41 AM UTC-5, Spencer Russell wrote:
>
> Take a look at the performance tips in the manual:
> http://docs.julialang.org/en/release-0.5/manual/performance-tips/
>
> One of the main things is to avoid accessing global variables, and 
> everything declared at the top-level in the REPL is global, so you 
> generally want to put any performance-sensitive code (and variables 
> accessed in that code) inside a function.
>
> -s
>
> On Sep 24, 2016, at 12:04 PM, Weicheng Zhu > 
> wrote:
>
> Hi there,
> Could anybody tell me what's wrong with my for loop code below and how to 
> improve it? 
> I was surprised to see it performs worse than the vectorized operation.
> Thank you!
>
> ## Calculate the maximum number in vector x that is less or equal to 0.5
>> ## Method 1
>> x=rand(1)
>> @time maximum(x[x.<=0.5])
>> # 0.000205 seconds (23 allocations: 45.141 KB)
>> ## Method 2
>> u= x[1]
>> @time @inbounds for i in 2:length(x)
>> if u <  x[i] && x[i] <= 0.5
>> u = x[i]
>> end
>> end
>> # 0.001233 seconds (42.40 k allocations: 818.766 KB)
>
>
>
> Best,
> Weicheng
>
>
>
>

[julia-users] Re: julia-i18n: Translators and reviewer needed!

2016-09-24 Thread Ismael Venegas Castelló


The Julia website is now officially also in Spanish, more languages are 
coming soon!


* http://julialang.org


There are still translations and reviews to do, if you are looking for a 
way to contribute to Julia, check the website internationalization project 
on Transifex:


* https://www.transifex.com/julialang-i18n/julialang-web


Contributing is very easy, you just need to register, explore the graphic 
interface a little bit and start translating.


Help us bring Julia internationalization to your native language ...one 
string at a time!


Cheers,

Ismael Venegas Castelló


El jueves, 22 de septiembre de 2016, 1:32:13 (UTC-5), Ismael Venegas 
Castelló escribió:
>
> Looking how to contribute to Julia? Check out the web translation project 
> on Transifex. 
> Help us bring Julia internationalization to your native language one 
> string at a time!
>
>
>- https://www.transifex.com/julialang-i18n/julialang-web
>- https://gitter.im/JuliaLangEs/julia-i18n
>- https://github.com/JuliaLang/julialang.github.com/pull/252
>
>

[julia-users] Re: PkgDev.tag issues

2016-09-24 Thread Evan Fields
I've had this problem as well so I'm eager to learn a solution. It was a 
while ago, but when this happened to me, git status in the metadata repo 
would show uncommitted changes. I think I had to reset metadata to a clean 
state, manually delete some tags in the package repository, and run the 
package commands again.


Re: [julia-users] Why for loop slower than the vectorized operation?

2016-09-24 Thread Spencer Russell
Take a look at the performance tips in the manual:
http://docs.julialang.org/en/release-0.5/manual/performance-tips/ 


One of the main things is to avoid accessing global variables, and everything 
declared at the top-level in the REPL is global, so you generally want to put 
any performance-sensitive code (and variables accessed in that code) inside a 
function.

-s

> On Sep 24, 2016, at 12:04 PM, Weicheng Zhu  wrote:
> 
> Hi there,
> Could anybody tell me what's wrong with my for loop code below and how to 
> improve it? 
> I was surprised to see it performs worse than the vectorized operation.
> Thank you!
> 
> ## Calculate the maximum number in vector x that is less or equal to 0.5
> ## Method 1
> x=rand(1)
> @time maximum(x[x.<=0.5])
> # 0.000205 seconds (23 allocations: 45.141 KB)
> ## Method 2
> u= x[1]
> @time @inbounds for i in 2:length(x)
> if u <  x[i] && x[i] <= 0.5
> u = x[i]
> end
> end
> # 0.001233 seconds (42.40 k allocations: 818.766 KB)
> 
> 
> Best,
> Weicheng
> 
> 



[julia-users] Why for loop slower than the vectorized operation?

2016-09-24 Thread Weicheng Zhu
Hi there,
Could anybody tell me what's wrong with my for loop code below and how to 
improve it? 
I was surprised to see it performs worse than the vectorized operation.
Thank you!

## Calculate the maximum number in vector x that is less or equal to 0.5
> ## Method 1
> x=rand(1)
> @time maximum(x[x.<=0.5])
> # 0.000205 seconds (23 allocations: 45.141 KB)
> ## Method 2
> u= x[1]
> @time @inbounds for i in 2:length(x)
> if u <  x[i] && x[i] <= 0.5
> u = x[i]
> end
> end
> # 0.001233 seconds (42.40 k allocations: 818.766 KB)



Best,
Weicheng




[julia-users] Re: LightXML Ubuntu 16.04 julia 0.4.5

2016-09-24 Thread Ján Adamčák
Thanks,

after installing 

sudo apt-get install libxml2-dev

is LightXML fully working.

I have another question: Why this dependency didn't resolved automatically 
by Pkg.add("LightXML") ?



Dňa sobota, 24. septembra 2016 15:07:37 UTC+2 Tony Kelman napísal(-a):
>
> You might need the -dev version to get a plain "libxml2.so" in addition to 
> the version with an soname in it. I thought Julia should be able to find 
> the soname versions too, but maybe not?
>
>
> On Saturday, September 24, 2016 at 5:34:12 AM UTC-7, Ján Adamčák wrote:
>>
>> I tried sudo apt-get install libxml2, but I got answer from ubuntu:
>>
>> libxml2 is already the newest version (2.9.3+dfsg 1-1ubuntu0.1).
>> libxml2 is tagged as manually installed.
>>
>> But from julia I got same answer:
>>
>> ERROR: error compiling call: could not load library "libxml2"
>>
>>
>>
>> Dňa sobota, 24. septembra 2016 14:18:27 UTC+2 Kaj Wiik napísal(-a):
>>>
>>> Try
>>>
>>> sudo apt install libxml2
>>>
>>>
>>>
>>> On Saturday, September 24, 2016 at 12:52:46 PM UTC+3, Ján Adamčák wrote:

 Hi Guys,

 I tried use LightXML on Ubuntu 16.04, but I got an error: 

 ERROR: error compiling call: could not load library "libxml2"

 Can You help me?

 Thanks.

 Log:

  _
   _   _ _(_)_ |  A fresh approach to technical computing
  (_) | (_) (_)|  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.4.5 (2016-03-18 00:58 UTC)
 _/ |\__'_|_|_|\__'_|  |  
 |__/   |  x86_64-linux-gnu

 julia> Pkg.status()
 No packages installed

 julia> Pkg.add("LightXML")
 INFO: Cloning cache of Compat from git://
 github.com/JuliaLang/Compat.jl.git
 INFO: Cloning cache of LightXML from git://
 github.com/JuliaIO/LightXML.jl.git
 INFO: Installing Compat v0.9.2
 INFO: Installing LightXML v0.4.0
 INFO: Building LightXML
 INFO: Package database updated
 INFO: METADATA is out-of-date — you may not have the latest version of 
 LightXML
 INFO: Use `Pkg.update()` to get the latest versions of your packages

 julia> Pkg.update()
 INFO: Updating METADATA...
 INFO: Computing changes...
 INFO: No packages to install, update or remove

 julia> using LightXML
 INFO: Precompiling module LightXML...

 julia> # create an empty XML document
   xdoc = XMLDocument()
 ERROR: error compiling call: could not load library "libxml2"






Re: [julia-users] Generators vs Comprehensions, Type-stability?

2016-09-24 Thread Michele Zaffalon
On Fri, Sep 23, 2016 at 1:14 PM, Steven G. Johnson 
wrote:

>
>
> On Friday, September 23, 2016 at 2:42:00 AM UTC-4, Michele Zaffalon wrote:
>>
>> On Fri, Sep 23, 2016 at 2:23 AM, Steven G. Johnson 
>> wrote:
>>>
>>>
>>> We could use type inference on the function t -> t^2 (which is buried in
>>> the generator) to determine a more specific eltype.
>>>
>>
>> Does this not require evaluating the function on all inputs thereby
>> losing the advantage of having a generator?
>>
>
> No, not if the eltype of the thing the generator iterates over (in this
> case, an Array{Float64}) is known.
>


Sorry for being slow: the input array rand(10) or the output array, the
square of each element of rand(10)?

julia> (begin;println(t);t^2;end for t=1:10)
Base.Generator{UnitRange{Int64},##37#38}(#37,1:10)


[julia-users] Re: LightXML Ubuntu 16.04 julia 0.4.5

2016-09-24 Thread Tony Kelman
You might need the -dev version to get a plain "libxml2.so" in addition to 
the version with an soname in it. I thought Julia should be able to find 
the soname versions too, but maybe not?


On Saturday, September 24, 2016 at 5:34:12 AM UTC-7, Ján Adamčák wrote:
>
> I tried sudo apt-get install libxml2, but I got answer from ubuntu:
>
> libxml2 is already the newest version (2.9.3+dfsg 1-1ubuntu0.1).
> libxml2 is tagged as manually installed.
>
> But from julia I got same answer:
>
> ERROR: error compiling call: could not load library "libxml2"
>
>
>
> Dňa sobota, 24. septembra 2016 14:18:27 UTC+2 Kaj Wiik napísal(-a):
>>
>> Try
>>
>> sudo apt install libxml2
>>
>>
>>
>> On Saturday, September 24, 2016 at 12:52:46 PM UTC+3, Ján Adamčák wrote:
>>>
>>> Hi Guys,
>>>
>>> I tried use LightXML on Ubuntu 16.04, but I got an error: 
>>>
>>> ERROR: error compiling call: could not load library "libxml2"
>>>
>>> Can You help me?
>>>
>>> Thanks.
>>>
>>> Log:
>>>
>>>  _
>>>   _   _ _(_)_ |  A fresh approach to technical computing
>>>  (_) | (_) (_)|  Documentation: http://docs.julialang.org
>>>   _ _   _| |_  __ _   |  Type "?help" for help.
>>>  | | | | | | |/ _` |  |
>>>  | | |_| | | | (_| |  |  Version 0.4.5 (2016-03-18 00:58 UTC)
>>> _/ |\__'_|_|_|\__'_|  |  
>>> |__/   |  x86_64-linux-gnu
>>>
>>> julia> Pkg.status()
>>> No packages installed
>>>
>>> julia> Pkg.add("LightXML")
>>> INFO: Cloning cache of Compat from git://
>>> github.com/JuliaLang/Compat.jl.git
>>> INFO: Cloning cache of LightXML from git://
>>> github.com/JuliaIO/LightXML.jl.git
>>> INFO: Installing Compat v0.9.2
>>> INFO: Installing LightXML v0.4.0
>>> INFO: Building LightXML
>>> INFO: Package database updated
>>> INFO: METADATA is out-of-date — you may not have the latest version of 
>>> LightXML
>>> INFO: Use `Pkg.update()` to get the latest versions of your packages
>>>
>>> julia> Pkg.update()
>>> INFO: Updating METADATA...
>>> INFO: Computing changes...
>>> INFO: No packages to install, update or remove
>>>
>>> julia> using LightXML
>>> INFO: Precompiling module LightXML...
>>>
>>> julia> # create an empty XML document
>>>   xdoc = XMLDocument()
>>> ERROR: error compiling call: could not load library "libxml2"
>>>
>>>
>>>
>>>
>>>

[julia-users] Re: LightXML Ubuntu 16.04 julia 0.4.5

2016-09-24 Thread Ján Adamčák
I tried sudo apt-get install libxml2, but I got answer from ubuntu:

libxml2 is already the newest version (2.9.3+dfsg 1-1ubuntu0.1).
libxml2 is tagged as manually installed.

But from julia I got same answer:

ERROR: error compiling call: could not load library "libxml2"



Dňa sobota, 24. septembra 2016 14:18:27 UTC+2 Kaj Wiik napísal(-a):
>
> Try
>
> sudo apt install libxml2
>
>
>
> On Saturday, September 24, 2016 at 12:52:46 PM UTC+3, Ján Adamčák wrote:
>>
>> Hi Guys,
>>
>> I tried use LightXML on Ubuntu 16.04, but I got an error: 
>>
>> ERROR: error compiling call: could not load library "libxml2"
>>
>> Can You help me?
>>
>> Thanks.
>>
>> Log:
>>
>>  _
>>   _   _ _(_)_ |  A fresh approach to technical computing
>>  (_) | (_) (_)|  Documentation: http://docs.julialang.org
>>   _ _   _| |_  __ _   |  Type "?help" for help.
>>  | | | | | | |/ _` |  |
>>  | | |_| | | | (_| |  |  Version 0.4.5 (2016-03-18 00:58 UTC)
>> _/ |\__'_|_|_|\__'_|  |  
>> |__/   |  x86_64-linux-gnu
>>
>> julia> Pkg.status()
>> No packages installed
>>
>> julia> Pkg.add("LightXML")
>> INFO: Cloning cache of Compat from git://
>> github.com/JuliaLang/Compat.jl.git
>> INFO: Cloning cache of LightXML from git://
>> github.com/JuliaIO/LightXML.jl.git
>> INFO: Installing Compat v0.9.2
>> INFO: Installing LightXML v0.4.0
>> INFO: Building LightXML
>> INFO: Package database updated
>> INFO: METADATA is out-of-date — you may not have the latest version of 
>> LightXML
>> INFO: Use `Pkg.update()` to get the latest versions of your packages
>>
>> julia> Pkg.update()
>> INFO: Updating METADATA...
>> INFO: Computing changes...
>> INFO: No packages to install, update or remove
>>
>> julia> using LightXML
>> INFO: Precompiling module LightXML...
>>
>> julia> # create an empty XML document
>>   xdoc = XMLDocument()
>> ERROR: error compiling call: could not load library "libxml2"
>>
>>
>>
>>
>>

[julia-users] Re: LightXML Ubuntu 16.04 julia 0.4.5

2016-09-24 Thread Kaj Wiik
Try

sudo apt install libxml2



On Saturday, September 24, 2016 at 12:52:46 PM UTC+3, Ján Adamčák wrote:
>
> Hi Guys,
>
> I tried use LightXML on Ubuntu 16.04, but I got an error: 
>
> ERROR: error compiling call: could not load library "libxml2"
>
> Can You help me?
>
> Thanks.
>
> Log:
>
>  _
>   _   _ _(_)_ |  A fresh approach to technical computing
>  (_) | (_) (_)|  Documentation: http://docs.julialang.org
>   _ _   _| |_  __ _   |  Type "?help" for help.
>  | | | | | | |/ _` |  |
>  | | |_| | | | (_| |  |  Version 0.4.5 (2016-03-18 00:58 UTC)
> _/ |\__'_|_|_|\__'_|  |  
> |__/   |  x86_64-linux-gnu
>
> julia> Pkg.status()
> No packages installed
>
> julia> Pkg.add("LightXML")
> INFO: Cloning cache of Compat from git://
> github.com/JuliaLang/Compat.jl.git
> INFO: Cloning cache of LightXML from git://
> github.com/JuliaIO/LightXML.jl.git
> INFO: Installing Compat v0.9.2
> INFO: Installing LightXML v0.4.0
> INFO: Building LightXML
> INFO: Package database updated
> INFO: METADATA is out-of-date — you may not have the latest version of 
> LightXML
> INFO: Use `Pkg.update()` to get the latest versions of your packages
>
> julia> Pkg.update()
> INFO: Updating METADATA...
> INFO: Computing changes...
> INFO: No packages to install, update or remove
>
> julia> using LightXML
> INFO: Precompiling module LightXML...
>
> julia> # create an empty XML document
>   xdoc = XMLDocument()
> ERROR: error compiling call: could not load library "libxml2"
>
>
>
>
>

[julia-users] Re: How does promote_op work?

2016-09-24 Thread Steven G. Johnson


On Friday, September 23, 2016 at 6:15:25 PM UTC-4, Pablo Zubieta wrote:
>
> The problem is empty arrays, when the type cannot be inferred broadcast 
> uses the types of each element to build the array. When there are no 
> elements it doesn't know what type to choose.
>

 (For the empty array broadcast and map rely on type inference.  If you 
have type-stable functions, and concretely typed arrays (not Any[]), then 
it should be fine.)


[julia-users] Re: Problems with Memoize in Julia 0.5.0

2016-09-24 Thread Avik Sengupta
>I would file an issue with Memoize.jl; I'm not sure why the package is 
limited to memoizing only a single method definition, but this seems like 
it would need to be fixed upstream.

https://github.com/simonster/Memoize.jl/issues/5

This is probably due to the new functions changes in 0.5. 

Regards
-
Avik

On Friday, 23 September 2016 19:47:35 UTC+1, Steven G. Johnson wrote:
>
>
>
> On Friday, September 23, 2016 at 9:08:29 AM UTC-4, Ed Scheinerman wrote:
>>
>> Hello,
>>
>> I use memoization frequently and have run into two problems with the move 
>> to Julia 0.5.0. 
>>
>> The first is not too serious and I hope can be fixed readily.  The first 
>> time I memoize a function, a warning is generated like this:
>>
>
> This kind of warning is fairly innocuous and happens when we upgrade Julia 
> versions, due to language changes; it takes a while for packages to catch 
> up with a new release.
>
> In this case, it looks like it was already fixed (
> https://github.com/simonster/Memoize.jl/pull/7), but maybe a new version 
> needs to be tagged.
>
>  
>
>> More significantly, if I want multiple dispatch on a function name, the 
>> second instance creates a problem and the definition is rejected. Here I 
>> define a factorial function that always returns a BigInt. The first 
>> function definition succeeds but the second one fails:
>>
>
> I would file an issue with Memoize.jl; I'm not sure why the package is 
> limited to memoizing only a single method definition, but this seems like 
> it would need to be fixed upstream.
>
> (Note, by the way, that you could define @memoize Factorial(n::Integer) = 
> factorial(big(n)), and it will be far more efficient because it will call 
> an optimized GMP factorial function.)
>


[julia-users] LightXML Ubuntu 16.04 julia 0.4.5

2016-09-24 Thread Ján Adamčák
Hi Guys,

I tried use LightXML on Ubuntu 16.04, but I got an error: 

ERROR: error compiling call: could not load library "libxml2"

Can You help me?

Thanks.

Log:

 _
  _   _ _(_)_ |  A fresh approach to technical computing
 (_) | (_) (_)|  Documentation: http://docs.julialang.org
  _ _   _| |_  __ _   |  Type "?help" for help.
 | | | | | | |/ _` |  |
 | | |_| | | | (_| |  |  Version 0.4.5 (2016-03-18 00:58 UTC)
_/ |\__'_|_|_|\__'_|  |  
|__/   |  x86_64-linux-gnu

julia> Pkg.status()
No packages installed

julia> Pkg.add("LightXML")
INFO: Cloning cache of Compat from git://github.com/JuliaLang/Compat.jl.git
INFO: Cloning cache of LightXML from 
git://github.com/JuliaIO/LightXML.jl.git
INFO: Installing Compat v0.9.2
INFO: Installing LightXML v0.4.0
INFO: Building LightXML
INFO: Package database updated
INFO: METADATA is out-of-date — you may not have the latest version of 
LightXML
INFO: Use `Pkg.update()` to get the latest versions of your packages

julia> Pkg.update()
INFO: Updating METADATA...
INFO: Computing changes...
INFO: No packages to install, update or remove

julia> using LightXML
INFO: Precompiling module LightXML...

julia> # create an empty XML document
  xdoc = XMLDocument()
ERROR: error compiling call: could not load library "libxml2"






Re: [julia-users] Cookbook for Julia

2016-09-24 Thread Tamas Papp
In this specific instance, it is worse: searching for "julia cookbook"
or "julia recipes" leads you to the work of Juila Child. "julia -child"
etc is only marginally better, there are apperently many cookbook
authors with the first name Julia.

Searching within Wikibooks and similar (Github) works though, which is
why I suggested contributing to an existing effort.

On Sat, Sep 24 2016, daycaster wrote:

> They used to say that you could never have too much documentation (like some 
> other things in life), but an important proviso is that it should be easy to 
> find what you're really looking for. Searching for Julia programming 
> information isn't always easy: the official documentation's search is not 
> bad, but Google searches tend to  return too many people named Julia 
> (including people named Julia Lang) unless you're lavish with the search 
> terms.


Re: [julia-users] Cookbook for Julia

2016-09-24 Thread daycaster
They used to say that you could never have too much documentation (like some 
other things in life), but an important proviso is that it should be easy to 
find what you're really looking for. Searching for Julia programming 
information isn't always easy: the official documentation's search is not bad, 
but Google searches tend to  return too many people named Julia (including 
people named Julia Lang) unless you're lavish with the search terms.