[julia-users] Set PATH in windows 10

2016-05-05 Thread Yu Tony
Hello everyone!
I'm a beginner in programming; i have trouble finding the bin folder and 
setting PATH environment variales for Julia;
Can anyone please tell me where to find the bin folder and what is the 
directory to set the PATH environment variable to ?

Thankyou for your help,
Tony


Re: [julia-users] Why multiple abstract type inheritance is not possible in Julia?

2016-05-05 Thread Stefan Karpinski
No, it's just a very challenging design and implementation problem. It's
also unclear if it's even a good idea to have this feature. C++ for example
has multiple inheritance but many people consider it too complex and prone
to breakage, which is why Java does not have multiple inheritance. There is
a strong leaning towards traits-based inheritance rather than multiple
inheritance.

On Wed, May 4, 2016 at 5:57 PM, Martin Kuzma 
wrote:

> Hello everyone,
>
> I know that subtyping from more than one abstract type is not possible. I
> also found multiple issues on github with this problem.
> But i could not find enywhere a reason why it is not possible. Can
> somebody please explain to me why? Does it have something to do with how
> the multiple dispatch works?
>
> Thanks Martin
>


Re: [julia-users] Re: Reproducible research for Julia

2016-05-05 Thread Ashley Kleinhans
I'm not interested in any other program but Julia. Still not interested in
Julia-OB whatever that is.

Good for you, I'm sure that line helps with the ladies.
On Thu, 05 May 2016 at 21:59 James Fairbanks  wrote:

> org-plus-contrib has a file ob-julia.el which can be enabled by installing
> org-plus-contrib and then
>
> (setq inferior-julia-program-name "julia")
> (require 'ob-julia)   ;from package org-plus-contrib
>
>
> On Thursday, May 5, 2016 at 11:26:09 AM UTC-4, kleinsplash wrote:
>>
>> ... Sports...um.. either quidditch or ladies night at the local bar.
>>
> I was referring to the sports almanac from Back to the Future.
>
>


Re: [julia-users] Convert Method or LambdaInfo into an Expression

2016-05-05 Thread Curtis Vogt

>
> It would be easy enough to write a macro


A good idea but in my use case I want to be able to turn almost any method 
into an expression including those in Base which I can't easily add a macro 
to.

Look at code_lowered


Thanks, I'll make sure to check that out. I was looking at code_typed and 
show(::IO, 
::LambdaInfo)today which are in the ballpark of what I'm looking for. If I 
manage to figure out how to extract the information I'm after I'll make 
sure to make a documentation PR.
 

On Thursday, May 5, 2016 at 9:29:59 PM UTC-5, Steven G. Johnson wrote:
>
> Look at code_lowered
>
> f(x) = x + 1
> c = code_lowered(f, (Number,))
>
> Getting the AST out of c (an array of LambdaInfo structures) is 
> undocumented, but possible: Base.uncompressed_ast(c[1]) gives the AST (Expr 
> object), and Base.lambdainfo_slotnames(c[1]) gives the argument names.
>
> Might be nice to have a documented way to extract this information.
>


Re: [julia-users] Convert Method or LambdaInfo into an Expression

2016-05-05 Thread Steven G. Johnson
Look at code_lowered

f(x) = x + 1
c = code_lowered(f, (Number,))

Getting the AST out of c (an array of LambdaInfo structures) is 
undocumented, but possible: Base.uncompressed_ast(c[1]) gives the AST (Expr 
object), and Base.lambdainfo_slotnames(c[1]) gives the argument names.

Might be nice to have a documented way to extract this information.


Re: [julia-users] Convert Method or LambdaInfo into an Expression

2016-05-05 Thread Cedric St-Jean
It would be easy enough to write a macro

@saved_info function foo(x::Int)
   x+2
end

body_of(foo, (Int,))  # -> :(x+2)

What do you want to do?

On Thursday, May 5, 2016 at 5:18:27 PM UTC-4, Curtis Vogt wrote:
>
> What does it mean to comvert a method to a expression. 
>
>
> What I was hoping for was to get the implementation of the method back as 
> an expression, something like:
>
> julia> expr = :(foo(n::Integer) = 2*n)
> :(foo(n::Integer) = begin  # REPL[2], line 1:
> 2n
> end)
>
> julia> eval(expr)
> foo (generic function with 1 method)
>
> julia> method = first(methods(foo))
> foo(n::Integer) at REPL[2]:1
>
> julia> Expr(method) == expr  # Not reality
> true
>
> More than likely it isn't possible. I just figured it was worth asking. A 
> far more likely scenario would be to get a LambdaInfo as an Expr:
>  
> julia> foo(n::Integer) = 2*n
> foo (generic function with 1 method) 
>
> julia> method = first(methods(foo)) 
> foo(n::Integer) at REPL[1]:1 
>
> julia> method.lambda_template
> LambdaInfo for foo 
> :(begin  # REPL[1], line 1: 
> return 2 * n 
> end)
>
>
> On Thursday, May 5, 2016 at 3:59:20 PM UTC-5, Yichao Yu wrote:
>>
>> On Thu, May 5, 2016 at 3:45 PM, Curtis Vogt  wrote: 
>> > I doubt this is possible but is there a way of creating an expression 
>> from a 
>> > Method or LambaInfo? Something like: 
>> > 
>> > julia> m = first(methods(open, (AbstractString,))) 
>> > open(fname::AbstractString) at iostream.jl:99 
>> > 
>> > julia> Expr(m) 
>> > ERROR: TypeError: Expr: expected Symbol, got Method 
>> >  in Expr(::Any) at ./boot.jl:270 
>> >  in eval(::Module, ::Any) at ./boot.jl:228 
>> > 
>> > 
>> > I'm running Julia 0.5.0-dev+3898. 
>>
>> What does it mean to comvert a method to a expression. 
>>
>

[julia-users] Re: Calling a function when type field changes.

2016-05-05 Thread Yonghee Kim

Thank you for your advise! I will try this


Re: [julia-users] Re: [ANN] PolynomialRoots.jl: Fast Complex Polynomial Root Finder

2016-05-05 Thread Stefan Karpinski
Great – they obviously intended for this to be open source and used, so I'm
sure they won't mind clarifying.

On Thu, May 5, 2016 at 7:39 PM, Mosè Giordano 
wrote:

> Hi Steven and Stefan,
>
> 2016-05-05 22:29 GMT+02:00 Stefan Karpinski :
> > The phrasing of this licensing is unclear but essentially the same as the
> > original Fortran library:
> >
> >> The authors release the source codes associated with the Paper under
> terms
> >> of the GNU Lesser General Public License version 2 or any later
> version, or
> >> under the Apache License, Version 2.0 as well as under a "customary
> >> scientific license", which implies that if this code was important in
> the
> >> scientific process or for the results of your scientific work, we ask
> for
> >> the appropriate citation of the Paper (Skowron & Gould 2012).
> >
> >
> > Their wording seems to indicate dual licensing under LGPL 2 or Apache 2,
> > which would mean that following the terms of either license gives the
> right
> > to use the software. But then it throws in the "as well as under a
> > 'customary scientific license'" clause, which completely muddies the
> waters.
> > Does that mean that you may use the software if you follow the terms of
> LGPL
> > 2 AND cite them OR follow the terms of Apache 2 AND cite them? Or that
> you
> > may use the software if you follow the terms of LGPL 2 OR cite them OR
> > follow the terms of Apache 2 and cite them? Under the former
> interpretation,
> > it would be illegal to use this software as part of a derived work
> including
> > any GPL libraries (which includes Julia in its default configuration)
> since
> > the "customary scientific license" conflicts with the GPL, thereby
> making it
> > impossible to comply with all terms required to be allowed to use the
> > combined product.
> >
> > If the authors intended to require you to follow both the LGPL 2 and
> Apache
> > 2 licenses, the situation may be even worse, since, IIRC, those licenses
> > themselves conflict, so it would be impossible to satisfy the conditions
> > required to be allowed to use the software at all.
> >
> > It seems like it may be necessary to contact the authors and request
> their
> > clarification of the terms under which one may use their software.
>
> I confirm I used the same license as the original library.  Actually,
> I interpreted the "customary scientific license" as a request, not as
> a legal obligation (but I'm not a native English speaker nor a
> lawyer).  The fact that two or more people can't agree on the
> interpretation shows that probably the license requires clarification,
> I'll contact the author and ask for it.
>
> Bye,
> Mosè
>


Re: [julia-users] Re: [ANN] PolynomialRoots.jl: Fast Complex Polynomial Root Finder

2016-05-05 Thread Mosè Giordano
Hi Steven and Stefan,

2016-05-05 22:29 GMT+02:00 Stefan Karpinski :
> The phrasing of this licensing is unclear but essentially the same as the
> original Fortran library:
>
>> The authors release the source codes associated with the Paper under terms
>> of the GNU Lesser General Public License version 2 or any later version, or
>> under the Apache License, Version 2.0 as well as under a "customary
>> scientific license", which implies that if this code was important in the
>> scientific process or for the results of your scientific work, we ask for
>> the appropriate citation of the Paper (Skowron & Gould 2012).
>
>
> Their wording seems to indicate dual licensing under LGPL 2 or Apache 2,
> which would mean that following the terms of either license gives the right
> to use the software. But then it throws in the "as well as under a
> 'customary scientific license'" clause, which completely muddies the waters.
> Does that mean that you may use the software if you follow the terms of LGPL
> 2 AND cite them OR follow the terms of Apache 2 AND cite them? Or that you
> may use the software if you follow the terms of LGPL 2 OR cite them OR
> follow the terms of Apache 2 and cite them? Under the former interpretation,
> it would be illegal to use this software as part of a derived work including
> any GPL libraries (which includes Julia in its default configuration) since
> the "customary scientific license" conflicts with the GPL, thereby making it
> impossible to comply with all terms required to be allowed to use the
> combined product.
>
> If the authors intended to require you to follow both the LGPL 2 and Apache
> 2 licenses, the situation may be even worse, since, IIRC, those licenses
> themselves conflict, so it would be impossible to satisfy the conditions
> required to be allowed to use the software at all.
>
> It seems like it may be necessary to contact the authors and request their
> clarification of the terms under which one may use their software.

I confirm I used the same license as the original library.  Actually,
I interpreted the "customary scientific license" as a request, not as
a legal obligation (but I'm not a native English speaker nor a
lawyer).  The fact that two or more people can't agree on the
interpretation shows that probably the license requires clarification,
I'll contact the author and ask for it.

Bye,
Mosè


[julia-users] Re: Random Set element?

2016-05-05 Thread Steven G. Johnson
I think you have to use the internals of the Set implementation to have an 
O(1) algorithm here.   For example, the following seems to work:

import Base: GLOBAL_RNG, isslotfilled, rand
function rand(r::AbstractRNG, s::Set)
isempty(s) && throw(ArgumentError("set must be non-empty"))
n = length(s.dict.slots)
while true
i = rand(r, 1:n)
isslotfilled(s.dict, i) && return s.dict.keys[i]
end
end
rand(s::Set) = rand(Base.GLOBAL_RNG, s)


Something like this should probably be in Base.  This could make a good PR 
if you want to add a test case, documentation, etc.


[julia-users] Re: Why max and maximum?

2016-05-05 Thread Steven G. Johnson
On Thursday, May 5, 2016 at 5:43:04 PM UTC-4, Jorge Fernández de Cossío 
Díaz wrote:
>
> Why max() and maximum() are two separate functions? Cannot they be methods 
> of the same function?
>

They used to be; see the discussion in 
https://github.com/JuliaLang/julia/issues/4235 


Re: [julia-users] Too many processes for non-parallel Julia computation

2016-05-05 Thread James Fairbanks
If the code is not parallel, then you should not request multiple
processors.
The builtin BLAS are set up for multiple threads by default.
If you are doing a lot of linear algebra, then that will be parallel
already.
If you do julia -p then the BLAS are in serial.

James


[julia-users] Random Set element?

2016-05-05 Thread Jorge Fernández de Cossío Díaz
How to get a random element from a Set? Or in general, from a non-indexable 
collection?

Obviously A[rand(1:length(A))] doesn't work (where A is the Set). I tried 
this:

function rand{T}(s::Set{T})
@assert !isempty(s)
k = rand(1:length(s))
for x in s
k -= 1
if k == 0; return x end
end
end

But this is O(n), where n is the length of the set. Is there a more 
efficient way?


[julia-users] Why max and maximum?

2016-05-05 Thread Jorge Fernández de Cossío Díaz
Why max() and maximum() are two separate functions? Cannot they be methods 
of the same function?


Re: [julia-users] Too many processes for non-parallel Julia computation

2016-05-05 Thread Jorge Fernández de Cossío Díaz
If I run a julia script on a cluster, should I request more than one 
process? (My calculation is not parallel)

On Thursday, May 5, 2016 at 5:01:52 PM UTC-4, Yichao Yu wrote:
>
> On Thu, May 5, 2016 at 3:50 PM, Jorge Fernández de Cossío Díaz 
>  wrote: 
> > In my system, running julia from the console to launch the REPL launches 
> 3 
> > processes named Julia. 
> > If I execute a julia script containing no parallel code, like 
> > 
> > julia myscript.jl 
> > 
> > I also get 3 processes, and all three seem to do work. 
> > 
> > I have NOT aliased julia to julia -p 3. 
> > 
> > I am using Ubuntu 15.10, although this also happens on a system with 
> 14.04, 
> > and on a remote cluster, and with different scripts. All are x64, Julia 
> > v0.4.5. In all cases, too many processes are launched. 
> > 
> > Any ideas on what could be happening? 
>
> Those should be OpenBLAS worker thread and should not cost you any 
> trouble unless you are hitting the PID limit. 
>


[julia-users] Re: Too many processes for non-parallel Julia computation

2016-05-05 Thread Jorge Fernández de Cossío Díaz
You're right, I mean threads, not processes.

On Thursday, May 5, 2016 at 4:38:08 PM UTC-4, Penn Taylor wrote:
>
>
> How are you determining the number of processes?
>
> On Ubuntu 15.04 with Julia v0.4.5, I see *one* process if I issue
>
> $ ps ax | grep julia
>
> But I see 4 process if I look at the process table in `htop`. Htop reports 
> threads as processes though, so this is really a single process with 4 
> threads. Is this perhaps what you're seeing?
>


[julia-users] Re: Too many processes for non-parallel Julia computation

2016-05-05 Thread Jorge Fernández de Cossío Díaz
No, they are quiet. Running a script though causes all the threads to do 
work.


On Thursday, May 5, 2016 at 4:02:05 PM UTC-4, James Fairbanks wrote:
>
> If you don't run a script, do the other process still do work? I also get 
> multiple julia processes on ubuntu 15.10 juliav0.4.5 but they are all quiet 
> if no script is executed. 
>


Re: [julia-users] Convert Method or LambdaInfo into an Expression

2016-05-05 Thread Curtis Vogt

>
> What does it mean to comvert a method to a expression. 


What I was hoping for was to get the implementation of the method back as 
an expression, something like:

julia> expr = :(foo(n::Integer) = 2*n)
:(foo(n::Integer) = begin  # REPL[2], line 1:
2n
end)

julia> eval(expr)
foo (generic function with 1 method)

julia> method = first(methods(foo))
foo(n::Integer) at REPL[2]:1

julia> Expr(method) == expr  # Not reality
true

More than likely it isn't possible. I just figured it was worth asking. A 
far more likely scenario would be to get a LambdaInfo as an Expr:
 
julia> foo(n::Integer) = 2*n
foo (generic function with 1 method) 

julia> method = first(methods(foo)) 
foo(n::Integer) at REPL[1]:1 

julia> method.lambda_template
LambdaInfo for foo 
:(begin  # REPL[1], line 1: 
return 2 * n 
end)


On Thursday, May 5, 2016 at 3:59:20 PM UTC-5, Yichao Yu wrote:
>
> On Thu, May 5, 2016 at 3:45 PM, Curtis Vogt  > wrote: 
> > I doubt this is possible but is there a way of creating an expression 
> from a 
> > Method or LambaInfo? Something like: 
> > 
> > julia> m = first(methods(open, (AbstractString,))) 
> > open(fname::AbstractString) at iostream.jl:99 
> > 
> > julia> Expr(m) 
> > ERROR: TypeError: Expr: expected Symbol, got Method 
> >  in Expr(::Any) at ./boot.jl:270 
> >  in eval(::Module, ::Any) at ./boot.jl:228 
> > 
> > 
> > I'm running Julia 0.5.0-dev+3898. 
>
> What does it mean to comvert a method to a expression. 
>


Re: [julia-users] Too many processes for non-parallel Julia computation

2016-05-05 Thread Yichao Yu
On Thu, May 5, 2016 at 3:50 PM, Jorge Fernández de Cossío Díaz
 wrote:
> In my system, running julia from the console to launch the REPL launches 3
> processes named Julia.
> If I execute a julia script containing no parallel code, like
>
> julia myscript.jl
>
> I also get 3 processes, and all three seem to do work.
>
> I have NOT aliased julia to julia -p 3.
>
> I am using Ubuntu 15.10, although this also happens on a system with 14.04,
> and on a remote cluster, and with different scripts. All are x64, Julia
> v0.4.5. In all cases, too many processes are launched.
>
> Any ideas on what could be happening?

Those should be OpenBLAS worker thread and should not cost you any
trouble unless you are hitting the PID limit.


Re: [julia-users] Convert Method or LambdaInfo into an Expression

2016-05-05 Thread Yichao Yu
On Thu, May 5, 2016 at 3:45 PM, Curtis Vogt  wrote:
> I doubt this is possible but is there a way of creating an expression from a
> Method or LambaInfo? Something like:
>
> julia> m = first(methods(open, (AbstractString,)))
> open(fname::AbstractString) at iostream.jl:99
>
> julia> Expr(m)
> ERROR: TypeError: Expr: expected Symbol, got Method
>  in Expr(::Any) at ./boot.jl:270
>  in eval(::Module, ::Any) at ./boot.jl:228
>
>
> I'm running Julia 0.5.0-dev+3898.

What does it mean to comvert a method to a expression.


Re: [julia-users] Re: Too many processes for non-parallel Julia computation

2016-05-05 Thread James Fairbanks
This is my circumstance as well. ps ax shows 1 *process* htop shows ncores
*threads*.


[julia-users] Re: Too many processes for non-parallel Julia computation

2016-05-05 Thread Penn Taylor

How are you determining the number of processes?

On Ubuntu 15.04 with Julia v0.4.5, I see *one* process if I issue

$ ps ax | grep julia

But I see 4 process if I look at the process table in `htop`. Htop reports 
threads as processes though, so this is really a single process with 4 
threads. Is this perhaps what you're seeing?


Re: [julia-users] Re: [ANN] PolynomialRoots.jl: Fast Complex Polynomial Root Finder

2016-05-05 Thread Stefan Karpinski
The phrasing of this licensing is unclear but essentially the same as the
original Fortran library
:

The authors release the source codes associated with the Paper under terms
> of the GNU Lesser General Public License version 2 or any later version, or
> under the Apache License, Version 2.0 as well as under a "customary
> scientific license", which implies that if this code was important in the
> scientific process or for the results of your scientific work, we ask for
> the appropriate citation of the Paper (Skowron & Gould 2012).


Their wording seems to indicate dual licensing under LGPL 2 or Apache 2,
which would mean that following the terms of either license gives the right
to use the software. But then it throws in the "as well as under a
'customary scientific license'" clause, which completely muddies the
waters. Does that mean that you may use the software if you follow the
terms of LGPL 2 AND cite them OR follow the terms of Apache 2 AND cite
them? Or that you may use the software if you follow the terms of LGPL 2 OR
cite them OR follow the terms of Apache 2 and cite them? Under the former
interpretation, it would be illegal to use this software as part of a
derived work including any GPL libraries (which includes Julia in its
default configuration) since the "customary scientific license" conflicts
with the GPL, thereby making it impossible to comply with all terms
required to be allowed to use the combined product.

If the authors intended to require you to follow both the LGPL 2 and Apache
2 licenses, the situation may be even worse, since, IIRC, those licenses
themselves conflict, so it would be impossible to satisfy the conditions
required to be allowed to use the software at all.

It seems like it may be necessary to contact the authors and request their
clarification of the terms under which one may use their software.

On Thu, May 5, 2016 at 3:05 PM, Steven G. Johnson 
wrote:

>
>
> On Thursday, May 5, 2016 at 10:24:53 AM UTC-4, Mosè Giordano wrote:
>>
>> This package is licensed under Apache License 2.0 or GNU Lesser General
>> Public License version 3 or any later version, as well as under a
>> "customary scientific license", which implies that if this code was
>> important in the scientific process or for the results of your scientific
>> work, you are asked for the appropriate citation of the paper Skowron &
>> Gould 2012 (http://arxiv.org/abs/1203.1034).
>>
>
> It's a really bad idea to imply that citation is a legal requirement in
> the license.   Such a requirement makes your code non free/open-source
> software.
>
> The best approach is to simply make a polite request, but be explicit that
> it is not a legal requirement.   In practice, people will happily comply
> with such a request in my experience.  e.g. this is what we say for FFTW:
>
> In addition, we kindly ask you to acknowledge FFTW and its
> authors in any program or publication in which you use FFTW. (You are not
> *required* to do so; it is up to your common sense to decide whether you
> want to comply with this request or not.) For general publications, we
> suggest referencing: Matteo Frigo and Steven G. Johnson, “The design and
> implementation of FFTW3,” *Proc. IEEE* *93* (2), 216–231 (2005).
>


[julia-users] Re: Too many processes for non-parallel Julia computation

2016-05-05 Thread Jorge Fernández de Cossío Díaz
nprocs() returns 1.

I just tried this on an 8-core machine (Intel i7 quad-core with 
hyperthreading). Executing julia on the console to open the REPL spawns 8 
processes.


[julia-users] Re: Too many processes for non-parallel Julia computation

2016-05-05 Thread James Fairbanks
If you don't run a script, do the other process still do work? I also get 
multiple julia processes on ubuntu 15.10 juliav0.4.5 but they are all quiet 
if no script is executed. 


[julia-users] Re: Reproducible research for Julia

2016-05-05 Thread James Fairbanks
org-plus-contrib has a file ob-julia.el which can be enabled by installing 
org-plus-contrib and then

(setq inferior-julia-program-name "julia")
(require 'ob-julia)   ;from package org-plus-contrib


On Thursday, May 5, 2016 at 11:26:09 AM UTC-4, kleinsplash wrote:
>
> ... Sports...um.. either quidditch or ladies night at the local bar. 
>
I was referring to the sports almanac from Back to the Future.



[julia-users] Too many processes for non-parallel Julia computation

2016-05-05 Thread Jorge Fernández de Cossío Díaz
In my system, running julia from the console to launch the REPL launches 3 
processes named Julia.
If I execute a julia script containing no parallel code, like

julia myscript.jl

I also get 3 processes, and all three seem to do work.

I have NOT aliased julia to julia -p 3.

I am using Ubuntu 15.10, although this also happens on a system with 14.04, 
and on a remote cluster, and with different scripts. All are x64, Julia 
v0.4.5. In all cases, too many processes are launched.

Any ideas on what could be happening?


[julia-users] Convert Method or LambdaInfo into an Expression

2016-05-05 Thread Curtis Vogt
I doubt this is possible but is there a way of creating an expression from 
a Method or LambaInfo? Something like:

julia> m = first(methods(open, (AbstractString,)))
open(fname::AbstractString) at iostream.jl:99 

julia> Expr(m) 
ERROR: TypeError: Expr: expected Symbol, got Method 
 in Expr(::Any) at ./boot.jl:270 
 in eval(::Module, ::Any) at ./boot.jl:228


I'm running Julia 0.5.0-dev+3898.


[julia-users] Re: [ANN] PolynomialRoots.jl: Fast Complex Polynomial Root Finder

2016-05-05 Thread Steven G. Johnson


On Thursday, May 5, 2016 at 10:24:53 AM UTC-4, Mosè Giordano wrote:
>
> This package is licensed under Apache License 2.0 or GNU Lesser General 
> Public License version 3 or any later version, as well as under a 
> "customary scientific license", which implies that if this code was 
> important in the scientific process or for the results of your scientific 
> work, you are asked for the appropriate citation of the paper Skowron & 
> Gould 2012 (http://arxiv.org/abs/1203.1034).
>

It's a really bad idea to imply that citation is a legal requirement in the 
license.   Such a requirement makes your code non free/open-source software.

The best approach is to simply make a polite request, but be explicit that 
it is not a legal requirement.   In practice, people will happily comply 
with such a request in my experience.  e.g. this is what we say for FFTW:

In addition, we kindly ask you to acknowledge FFTW and its authors 
in any program or publication in which you use FFTW. (You are not *required* to 
do so; it is up to your common sense to decide whether you want to comply 
with this request or not.) For general publications, we suggest 
referencing: Matteo Frigo and Steven G. Johnson, “The design and 
implementation of FFTW3,” *Proc. IEEE* *93* (2), 216–231 (2005).


Re: [julia-users] nested macro with `let`

2016-05-05 Thread Yichao Yu
> Thank you for the careful explanation and code. It's exactly what I want. I
> have a follow-up question:
>
> 1. I thought I'd make make a (personal) cosmetic modification to your
> `value_dict`.
>
> macro value_dict(vars...)
> rebindings = [:($(esc(var)) = value($(esc(var for var in vars]
> quote
> let $(:($rebindings)...)

`$(rebindings...)` is the simplification you are looking for.
The `...` splat array as multiple argument to the expression. I
believe it is generally as if you replace it with `$(rebindings[1]),
$(rebindings[2]), ...`

> @symbol_dict($([esc(var) for var in vars]...))
> end
> end
> end
>
> It macroexpands into the same code, which is what I want. But I still have
> trouble understanding the $(:($. For example, in a not-macro environment
>
> julia> a = 2
> 2
>
> julia> quote
>$(:($a))
>end
> quote  # none, line 2:
> 2
> end
>
> julia> quote
>(($a))
>end
> quote  # none, line 2:
> 2
> end
>
> The $ evaluates an expression and : quotes an expression, so I expect
> $(:($a)) to be the same as $a, and indeed it is in this case. But if I try
> to do the same simplification in the let expression, stripping off a shell
> of $(:()),  it macroexpands to
>
> let [:($(Expr(:escape, :a)) = value($(Expr(:escape, :a,:($(Expr(:escape,
> :b)) = value($(Expr(:escape, :b]...

Seems that you replaced it with `$rebindings`, which removes the
splatting and you splice in an array as the argument to `let`, which
is invalid.

>
> which causes `ERROR: syntax: invalid let syntax`. And I don't quite get why
> they macroexpand differently.
>
> 2. Can `macroexpand` do only one layer (so to speak) of macro expansion? Can
> I do a  `macroexpand(value_dict(x,y))` that still shows the invocation of
> @symbol_dict, without expanding it recursively?

Macros are just functions with a funny name that is called by the
parser. You can call them directly

julia> macro value_dict(vars...)
   rebindings = [:($(esc(var)) = value($(esc(var for var in vars]
   quote
   let $(rebindings...)
   end
   end
   end
@value_dict (macro with 1 method)

julia> Main.(Symbol("@value_dict"))(:a, :b)
quote  # REPL[1], line 4:
let $(Expr(:escape, :a)) = value($(Expr(:escape, :a))),
$(Expr(:escape, :b)) = value($(Expr(:escape, :b)))
end
end

The result doesn't have macro hygiene stuff applied though...


>


Re: [julia-users] nested macro with `let`

2016-05-05 Thread Gustavo Goretkin


On Wednesday, May 4, 2016 at 1:05:07 PM UTC-4, Yichao Yu wrote:

> Do not use `@eval` in macro, it happens in the wrong scope and in this 
> case, the wrong time. 
>
> macro symbol_dict(symbols...) 
> :(Dict($([:($(QuoteNode(sym)) => $(esc(sym))) for sym in 
> symbols]...))) 
> end 
>
>  

> When using a macro, you want to generate the expression but not evaluate. 
>
> iiuc what you want is sth like 
>
> macro value_dict(vars...) 
> :(let $([:($(esc(var)) = value($(esc(var for var in vars]...) 
> @symbol_dict($([esc(var) for var in vars]...)) 
> end) 
> end 
>

Thank you for the careful explanation and code. It's exactly what I want. I 
have a follow-up question:

1. I thought I'd make make a (personal) cosmetic modification to your 
`value_dict`.

macro value_dict(vars...)
rebindings = [:($(esc(var)) = value($(esc(var for var in vars]
quote
let $(:($rebindings)...)
@symbol_dict($([esc(var) for var in vars]...))
end
end
end

It macroexpands into the same code, which is what I want. But I still have 
trouble understanding the $(:($. For example, in a not-macro environment

julia> a = 2
2

julia> quote
   $(:($a))
   end
quote  # none, line 2:
2
end

julia> quote
   (($a))
   end
quote  # none, line 2:
2
end

The $ evaluates an expression and : quotes an expression, so I expect 
$(:($a)) to be the same as $a, and indeed it is in this case. But if I try 
to do the same simplification in the let expression, stripping off a shell 
of $(:()),  it macroexpands to

let [:($(Expr(:escape, :a)) = value($(Expr(:escape, 
:a,:($(Expr(:escape, :b)) = value($(Expr(:escape, :b]...

which causes `ERROR: syntax: invalid let syntax`. And I don't quite get why 
they macroexpand differently.

2. Can `macroexpand` do only one layer (so to speak) of macro expansion? 
Can I do a  `macroexpand(value_dict(x,y))` that still shows the invocation 
of @symbol_dict, without expanding it recursively?
 


Re: [julia-users] Re: calling sort on a range with rev=true

2016-05-05 Thread Milan Bouchet-Valat
Le dimanche 01 mai 2016 à 19:11 -0700, 'Greg Plowman' via julia-users a
écrit :
> 
> Extending/overwriting sort in range.jl (line 686)
> 
> sort(r::Range) = issorted(r) ? r : reverse(r)
> 
> with the following worked for me.
> 
> function Base.sort(r::Range; rev::Bool=false)
>     if rev
>         issorted(r) ? reverse(r) : r
>     else
>         issorted(r) ? r : reverse(r)
>     end
> end
Makes sense, please file an issue or a pull request (if the latter, be
sure to also add tests to prevent regressions).


Regards


[julia-users] Re: Reproducible research for Julia

2016-05-05 Thread kleinsplash
@James: Guess that earns me a necro badge - in my defence I have just come 
across R and RStudio and the idea of updating images on the fly looked 
good. But then if its taken days to produce... Sports...um.. either 
quidditch or ladies night at the local bar. 
I am writing a rather large document using lyx and latex and was thinking 
of jython with a hint of markdown, maybe I will further procrastinate by 
looking at Weave. 

@tshort - Judo looks good too.. 

Thanks for the update :)

On Thursday, 9 May 2013 16:35:39 UTC+2, Stephen Eglen wrote:
>
> Hi,
>
> Coming from R, I've got used to the great Sweave/knitr system for 
> combining latex and R code in the same document, using noweb markup.  Is 
> there anything similar yet for Julia?  Or is there something similar using 
> markdown to embed Julia code into documentation?
>
> Thanks, Stephen
>


Re: [julia-users] Re: turn off warnings?

2016-05-05 Thread Ben Arthur
looks great tim, but what i had in mind was this:

https://github.com/JuliaLang/julia/pull/16213


[julia-users] Does rationalize ever round to zero?

2016-05-05 Thread James Fairbanks
Hello julia-users,

Does rationalize ever return 0//1 for nonzero inputs?

0.0+eps(Float64) is much closer to 0//1 than to 1//1.
Why can't I get 0//1 out of rationalize(x) if x != 0.0?
Is this to avoid divide by 0 errors when using a/rationalize(x) where 0 < x 
< tol?

For example on julia v0.4.5 
julia> rationalize(0.0)
0//1

julia> rationalize(0.0+eps(Float64))
1//4503599627370496

julia> rationalize(0.0+eps(Float64);tol=1e-4)
1//1

julia> rationalize(0.0+eps(Float64);tol=1e-4)
1//1

Thanks,
James


Re: [julia-users] Re: Reproducible research for Julia

2016-05-05 Thread Tom Short
Daniel's pandoc system is here:

https://github.com/dcjones/Judo.jl



On Thu, May 5, 2016 at 10:04 AM, kleinsplash 
wrote:

>
> Is there an update on these thoughts? Because that link doesnt work
> anymore..
> On Thursday, 9 May 2013 16:35:39 UTC+2, Stephen Eglen wrote:
>>
>> Hi,
>>
>> Coming from R, I've got used to the great Sweave/knitr system for
>> combining latex and R code in the same document, using noweb markup.  Is
>> there anything similar yet for Julia?  Or is there something similar using
>> markdown to embed Julia code into documentation?
>>
>> Thanks, Stephen
>>
>


[julia-users] [ANN] PolynomialRoots.jl: Fast Complex Polynomial Root Finder

2016-05-05 Thread Mosè Giordano
Hi,

a couple of days ago I released version 0.0.2 of PolynomialRoots.jl 
 (formerly known as 
CmplxRoots.jl, some people suggested to change the name to something more 
descriptive), a fast root finder of real and complex polynomials.

This is a Julia implementation of the algorithm described in

   - J. Skowron & A. Gould, 2012, "General Complex Polynomial Root Solver 
   and Its Further Optimization for Binary Microlenses", arXiv:1203.103 
   

PolynomialRoots.jl is a registered Julia package, so you can install it 
with the package manager:

Pkg.add("PolynomialRoots")

Two functions are exposed to the users:

roots(polynomial[, roots, polish=true])
roots5(polynomial[, roots])

The first function can be used to solve polynomials of any order, the 
second one is specialized and optimized for (and works only for) 
polynomials of fifth-order


This new version of PolynomialRoots.jl features support for arbitrary 
precision calculations.  This is very useful for calculating roots of 
polynomials of very large degree (some hundreds) that couldn't be solved 
using double precision calculations.  Actually, this cures inaccurate 
results also for low order polynomials, like second-order ones, where 
catastrophic cancellation is a problem.  For example, the actual roots of 
(see https://en.wikipedia.org/wiki/Loss_of_significance)


94906265.625*x^2 - 189812534*x + 94906268.375 

are

x_1 = 1.00028975958
x_2 = 1.000 

but when you try to calculate them in double-precision you get 

julia> r = roots([94906268.375, -189812534, 94906265.625]); 

julia> r[1]
1.000144879793 - 0.0im 

julia> r[2]
1.000144879788 + 0.0im

If you are interested in double-precision accuracy, you can work around 
this problem by calculating the roots with higher precision and then 
transforming the result to double-precision. What you have to do is only to 
pass BigFloat numbers to roots function:

julia> r = roots([BigFloat(94906268.375), BigFloat(-189812534), BigFloat(
94906265.625)]);

julia> Complex128(r[1])
1.000289759583 - 0.0im

julia> Complex128(r[2])
1.0 + 0.0im

as expected.

This package is licensed under Apache License 2.0 or GNU Lesser General 
Public License version 3 or any later version, as well as under a 
"customary scientific license", which implies that if this code was 
important in the scientific process or for the results of your scientific 
work, you are asked for the appropriate citation of the paper Skowron & 
Gould 2012 (http://arxiv.org/abs/1203.1034).

Cheers,
Mosè


[julia-users] Re: Reproducible research for Julia

2016-05-05 Thread James Fairbanks
Wow I just came on to the google group to ask if there was an 
org-babel-julia floating around somewhere and this thread was recently 
reawakened. There is no ob-julia in elpa.
Kleinsplash, what sports games should I bet on 14 minutes from now? :)

Weave.jl https://github.com/mpastell/Weave.jl was recently announced. 

On Thursday, May 5, 2016 at 10:04:23 AM UTC-4, kleinsplash wrote:
>
>
> Is there an update on these thoughts? Because that link doesnt work 
> anymore.. 
> On Thursday, 9 May 2013 16:35:39 UTC+2, Stephen Eglen wrote:
>>
>> Hi,
>>
>> Coming from R, I've got used to the great Sweave/knitr system for 
>> combining latex and R code in the same document, using noweb markup.  Is 
>> there anything similar yet for Julia?  Or is there something similar using 
>> markdown to embed Julia code into documentation?
>>
>> Thanks, Stephen
>>
>

[julia-users] Re: Reproducible research for Julia

2016-05-05 Thread kleinsplash

Is there an update on these thoughts? Because that link doesnt work 
anymore.. 
On Thursday, 9 May 2013 16:35:39 UTC+2, Stephen Eglen wrote:
>
> Hi,
>
> Coming from R, I've got used to the great Sweave/knitr system for 
> combining latex and R code in the same document, using noweb markup.  Is 
> there anything similar yet for Julia?  Or is there something similar using 
> markdown to embed Julia code into documentation?
>
> Thanks, Stephen
>


Re: [julia-users] what's good practice for default value in optional arguments?

2016-05-05 Thread Andras Niedermayer
In terms of type stability ( 
http://docs.julialang.org/en/release-0.4/manual/performance-tips/#avoid-changing-the-type-of-a-variable
 
), the latter is better:


f1(x::Int, y::Union{Void,Dict}) = y==nothing ? Dict() : y
@code_warntype f1(42, nothing) # shows ...end::UNION{DICT{ANY,ANY},VOID}; 
type unstable!

@code_warntype f1(42, Dict()) # shows ...end::Dict{Any,Any}





compare this to


f2(x::Int, y::Dict=Dict()) = y

@code_warntype f2(42) # shows ...end::Dict{Any,Any}; type stable
@code_warntype f2(42, Dict()) # shows ... end::Dict{Any,Any}





Whether you write f(x::Int, y=Dict()) or f(x::Int, y::Dict=Dict()) is a 
separate issue, about which Tamas and Tom made good suggestions.


On Thursday, May 5, 2016 at 1:58:42 PM UTC+2, Tom Breloff wrote:
>
> Just to extend Tamas's note... Another reason you may add the type 
> annotation is to ensure your code errors when you pass it types that are 
> not valid (but may compile and dispatch without issue). 
>
> On Thursday, May 5, 2016, Tamas Papp  
> wrote:
>
>> Hard to say without the context, but since in this case the only purpose
>> of a `nothing` seems to be to initialize with a default value, I would
>> go with y=Dict(), which does it directly.
>>
>> (Note that unless you are dispatching on them, your type declarations
>> are probably unnecessary, they won't make your code faster.)
>>
>> On Thu, May 05 2016, FANG Colin wrote:
>>
>> > For example,
>> >
>> > function f(x::Int; y::Union{Void, Dict})
>> > z = y == nothing ? Dict() : y
>> > ...
>> > end
>> >
>> >
>> > Or
>> >
>> > function f(x::Int; y::Dict=Dict())
>> > ...
>> > end
>> >
>> > Which one should I use?
>>
>

Re: [julia-users] what's good practice for default value in optional arguments?

2016-05-05 Thread Tom Breloff
Just to extend Tamas's note... Another reason you may add the type
annotation is to ensure your code errors when you pass it types that are
not valid (but may compile and dispatch without issue).

On Thursday, May 5, 2016, Tamas Papp  wrote:

> Hard to say without the context, but since in this case the only purpose
> of a `nothing` seems to be to initialize with a default value, I would
> go with y=Dict(), which does it directly.
>
> (Note that unless you are dispatching on them, your type declarations
> are probably unnecessary, they won't make your code faster.)
>
> On Thu, May 05 2016, FANG Colin wrote:
>
> > For example,
> >
> > function f(x::Int; y::Union{Void, Dict})
> > z = y == nothing ? Dict() : y
> > ...
> > end
> >
> >
> > Or
> >
> > function f(x::Int; y::Dict=Dict())
> > ...
> > end
> >
> > Which one should I use?
>


Re: [julia-users] what's good practice for default value in optional arguments?

2016-05-05 Thread Tamas Papp
Hard to say without the context, but since in this case the only purpose
of a `nothing` seems to be to initialize with a default value, I would
go with y=Dict(), which does it directly.

(Note that unless you are dispatching on them, your type declarations
are probably unnecessary, they won't make your code faster.)

On Thu, May 05 2016, FANG Colin wrote:

> For example,
>
> function f(x::Int; y::Union{Void, Dict})
> z = y == nothing ? Dict() : y
> ...
> end
>
>
> Or
>
> function f(x::Int; y::Dict=Dict())
> ...
> end
>
> Which one should I use?


[julia-users] what's good practice for default value in optional arguments?

2016-05-05 Thread FANG Colin
For example,

function f(x::Int; y::Union{Void, Dict})
z = y == nothing ? Dict() : y
...
end


Or

function f(x::Int; y::Dict=Dict())
...
end

Which one should I use?