Re: [julia-users] Ambiguity error when dispatching on Union types

2016-07-09 Thread Darwin Darakananda
Thanks Tim!  That was really helpful, especially the trick with adding an 
extra layer of functions with a different name.

On Saturday, July 9, 2016 at 2:56:49 AM UTC-7, Tim Holy wrote:
>
> Ambiguities are often a bit tricky. Two tips I've adopted: 
>
> - Have as few methods as possible, and declare types on their arguments 
> only 
> when absolutely necessary. These measures greatly reduce your exposure to 
> the 
> risk of ambiguities. To achieve this, it sometimes takes a fair bit of 
> thought 
> to design your API. 
>
> - Use one layer of indirection per argument you want to specialize. There 
> are 
> a couple of ways to pull this off, and the best way to do it usually 
> depends 
> on the specific goal you're trying to achieve. But here one approach might 
> be 
> to decide that `f` will only be specialized on argument 2, and will 
> otherwise 
> dispatch to `f1` (which you can specialize for argument 1). 
>
> f(a, b) = f1(a, b) 
> f(a, b::A) = "from A" 
> f1(a::Int, b) = "Int" 
> f1(a, b) = "other" 
>
> Best, 
> --Tim 
>
> On Friday, July 8, 2016 8:27:30 PM CDT Darwin Darakananda wrote: 
> > Is there a recommended way to getting around that?  The example above 
> had a 
> > union of only two types, but in the actual code I'm working on there are 
> a 
> > couple more.  Would I have to copying the code over and over with just 
> > small changes to the type signature? I guess you could use a macro to 
> > splice the types in. 
> > 
> > On Friday, July 8, 2016 at 7:58:02 PM UTC-7, Yichao Yu wrote: 
> > > On Fri, Jul 8, 2016 at 10:32 PM, Darwin Darakananda 
> > > 
> > > > wrote: 
> > > > Hi everyone, 
> > > > 
> > > > I have some code where multiple types share the same implementation 
> of a 
> > > > method, for example: 
> > > > 
> > > > abstract MyType 
> > > > 
> > > > 
> > > > type A <: MyType end 
> > > > type B <: MyType end 
> > > > 
> > > > 
> > > > f(target::MyType, source::MyType) = "fallback" 
> > > > 
> > > > 
> > > > f(target::Int,source::A) = "from A" 
> > > > f(target::MyType, source::A) = "from A" 
> > > > 
> > > > a = A() 
> > > > b = B() 
> > > > 
> > > > f(b, b) # fallback 
> > > > f(b, a) # from A 
> > > > f(a, a) # from A 
> > > > 
> > > > I was hoping that I could replace the "from A" function using a 
> union 
> > > 
> > > type, 
> > > 
> > > > but I'm running into ambiguity errors: 
> > > > 
> > > > f(target::Union{Int, MyType}, source::A) = "from A" 
> > > > 
> > > > f(b, b) # fallback 
> > > > f(b, a) # Ambiguity error 
> > > > f(a, a) # Ambiguity error 
> > > > 
> > > > Is this an expected behavior? 
> > > 
> > > Yes. 
> > > 
> > > > I thought that (::Union{Int, MyType}, ::A) 
> > > > would be a more specific match to (::B, ::A) than (::MyType, 
> ::MyType). 
> > > 
> > > There's basically nothing as a "more specific match". The two methods 
> > > are ambiguous and anything in their intersection cannot be dispatched 
> > > to either of them. 
> > > 
> > > > Any ideas/suggestions? 
> > > > 
> > > > Thanks, 
> > > > 
> > > > Darwin 
>
>
>

Re: [julia-users] Ambiguity error when dispatching on Union types

2016-07-08 Thread Darwin Darakananda
Is there a recommended way to getting around that?  The example above had a 
union of only two types, but in the actual code I'm working on there are a 
couple more.  Would I have to copying the code over and over with just 
small changes to the type signature? I guess you could use a macro to 
splice the types in.

On Friday, July 8, 2016 at 7:58:02 PM UTC-7, Yichao Yu wrote:
>
> On Fri, Jul 8, 2016 at 10:32 PM, Darwin Darakananda 
> > wrote: 
> > Hi everyone, 
> > 
> > I have some code where multiple types share the same implementation of a 
> > method, for example: 
> > 
> > abstract MyType 
> > 
> > 
> > type A <: MyType end 
> > type B <: MyType end 
> > 
> > 
> > f(target::MyType, source::MyType) = "fallback" 
> > 
> > 
> > f(target::Int,source::A) = "from A" 
> > f(target::MyType, source::A) = "from A" 
> > 
> > a = A() 
> > b = B() 
> > 
> > f(b, b) # fallback 
> > f(b, a) # from A 
> > f(a, a) # from A 
> > 
> > I was hoping that I could replace the "from A" function using a union 
> type, 
> > but I'm running into ambiguity errors: 
> > 
> > f(target::Union{Int, MyType}, source::A) = "from A" 
> > 
> > f(b, b) # fallback 
> > f(b, a) # Ambiguity error 
> > f(a, a) # Ambiguity error 
> > 
> > Is this an expected behavior? 
>
> Yes. 
>
> > I thought that (::Union{Int, MyType}, ::A) 
> > would be a more specific match to (::B, ::A) than (::MyType, ::MyType). 
>
> There's basically nothing as a "more specific match". The two methods 
> are ambiguous and anything in their intersection cannot be dispatched 
> to either of them. 
>
> > 
> > Any ideas/suggestions? 
> > 
> > Thanks, 
> > 
> > Darwin 
>


[julia-users] Ambiguity error when dispatching on Union types

2016-07-08 Thread Darwin Darakananda
Hi everyone,

I have some code where multiple types share the same implementation of a 
method, for example:

abstract MyType


type A <: MyType end
type B <: MyType end


f(target::MyType, source::MyType) = "fallback"


f(target::Int,source::A) = "from A"
f(target::MyType, source::A) = "from A"

a = A()
b = B()

f(b, b) # fallback
f(b, a) # from A
f(a, a) # from A

I was hoping that I could replace the "from A" function using a union type, 
but I'm running into ambiguity errors:

f(target::Union{Int, MyType}, source::A) = "from A"

f(b, b) # fallback
f(b, a) # Ambiguity error
f(a, a) # Ambiguity error

Is this an expected behavior?  I thought that (::Union{Int, MyType}, 
::A) would be a more specific match to (::B, ::A) than (::MyType, ::MyType).

Any ideas/suggestions?

Thanks,

Darwin


Re: [julia-users] Segfault when defining generated method

2016-06-29 Thread Darwin Darakananda
Fixed in 16b2de1!

Re: [julia-users] Segfault when defining generated method

2016-06-26 Thread Darwin Darakananda
That example seems to work on the version I'm using (commit c20199e). 
 Could they be separate issues?

On Sunday, June 26, 2016 at 5:47:36 PM UTC-7, Yichao Yu wrote:
>
> On Sun, Jun 26, 2016 at 8:15 PM, Darwin Darakananda 
> > wrote: 
> > Hi All, 
> > 
>
> Note that this is not related to generated function but the function 
> signature (the segfault is in `jl_method_def`) 
>
> Simpler repro 
>
> ``` 
> function update!(::Tuple) 
> end 
>
> function update!{N}(::Vararg{Tuple,N}) 
> end 
> ``` 
>
> Please open an issue on github. Thanks. 
>
>
> > I'm running into a problem where Julia is segfaulting when creating a 
> > generated method for an existing function. 
> > This is the first time I'm using generated functions, so I'm not sure if 
> I'm 
> > using it correctly. 
> > 
> > function update!(x::Vector{Int}, Δxs::Vector{Int}...) 
> > for i in eachindex(x), Δx in Δxs 
> > x[i] += Δx[i] 
> > end 
> > end 
> > 
> > 
> > function update!(x::Vector{Float64}, Δxs::Vector{Float64}...) 
> > for i in eachindex(x), Δx in Δxs 
> > x[i] += 2.0*Δx[i] 
> > end 
> > end 
> > 
> > 
> > function update!(sys::Tuple, Δsys::Tuple) 
> > for (s, Δs) in zip(sys, Δsys) 
> > update!(s, Δs) 
> > end 
> > end 
> > 
> > # x = rand(Int, 100); Δx₁ = similar(x), Δx₁ = similar(x) 
> > # y = rand(100); Δy₁ = similar(y), Δy₁ = similar(y) 
> > 
> > # update!(x, Δx₁, Δx₂) 
> > # update!(y, Δy₁, Δy₂) 
> > # update!((x,y), (Δx₁, Δy₁)) 
> > 
> > # Want something to handle update!((x,y), (Δx₁, Δy₁), (Δx₂, Δy₂)) 
> > 
> > @generated function update!{N}(sys::Tuple, Δsys::Vararg{Tuple, N}) 
> > # (Δs1, Δs2, ..., ΔsN) 
> > el  = [Symbol("Δs" * string(i)) for i in 1:N] 
> > # zip(Δsys[1], Δsys[2], ..., Δsys[N]) 
> > src = Expr(:call, :zip, :sys, [Expr(:ref, :Δsys, i) for i in 
> 1:N]...) 
> > 
> > quote 
> > for $(Expr(:tuple, :s, el...)) in $src 
> > # update!(s, Δs1, Δs2, ..., ΔsN) 
> > $(Expr(:call, :update!, :s, el...)) 
> > end 
> > nothing 
> > end 
> > end 
> > 
> > signal (11): Segmentation fault 
> > while loading no file, in expression starting on line 0 
> > inst_tuple_w_ at /home/darwin/.local/julia/src/jltypes.c:2352 
> > inst_type_w_ at /home/darwin/.local/julia/src/jltypes.c:2437 
> > inst_tuple_w_ at /home/darwin/.local/julia/src/jltypes.c:2383 
> > inst_type_w_ at /home/darwin/.local/julia/src/jltypes.c:2437 
> > jl_instantiate_type_with at /home/darwin/.local/julia/src/jltypes.c:2480 
> > jl_args_morespecific at /home/darwin/.local/julia/src/jltypes.c:3096 
> > jl_typemap_list_insert_sorted at 
> > /home/darwin/.local/julia/src/typemap.c:1033 
> > jl_typemap_insert_generic at /home/darwin/.local/julia/src/typemap.c:886 
> > jl_typemap_insert at /home/darwin/.local/julia/src/typemap.c:1006 
> > jl_method_table_insert at /home/darwin/.local/julia/src/gf.c:1069 
> > 
> > ⋮ 
> > 
> > 
> > It works fine if I change the name of the generated function to 
> something 
> > else.  Is this the expected behavior? 
> > 
> > Thanks, 
> > 
> > Darwin 
>


[julia-users] Segfault when defining generated method

2016-06-26 Thread Darwin Darakananda
Hi All,

I'm running into a problem where Julia is segfaulting when creating a 
generated method for an existing function.
This is the first time I'm using generated functions, so I'm not sure if 
I'm using it correctly.

function update!(x::Vector{Int}, Δxs::Vector{Int}...)
for i in eachindex(x), Δx in Δxs
x[i] += Δx[i]
end
end


function update!(x::Vector{Float64}, Δxs::Vector{Float64}...)
for i in eachindex(x), Δx in Δxs
x[i] += 2.0*Δx[i]
end
end


function update!(sys::Tuple, Δsys::Tuple)
for (s, Δs) in zip(sys, Δsys)
update!(s, Δs)
end
end

# x = rand(Int, 100); Δx₁ = similar(x), Δx₁ = similar(x)
# y = rand(100); Δy₁ = similar(y), Δy₁ = similar(y)

# update!(x, Δx₁, Δx₂)
# update!(y, Δy₁, Δy₂)
# update!((x,y), (Δx₁, Δy₁))

# Want something to handle update!((x,y), (Δx₁, Δy₁), (Δx₂, Δy₂))

@generated function update!{N}(sys::Tuple, Δsys::Vararg{Tuple, N})
# (Δs1, Δs2, ..., ΔsN)
el  = [Symbol("Δs" * string(i)) for i in 1:N]
# zip(Δsys[1], Δsys[2], ..., Δsys[N])
src = Expr(:call, :zip, :sys, [Expr(:ref, :Δsys, i) for i in 1:N]...)

quote
for $(Expr(:tuple, :s, el...)) in $src
# update!(s, Δs1, Δs2, ..., ΔsN)
$(Expr(:call, :update!, :s, el...))
end
nothing
end
end

signal (11): Segmentation fault
while loading no file, in expression starting on line 0
inst_tuple_w_ at /home/darwin/.local/julia/src/jltypes.c:2352
inst_type_w_ at /home/darwin/.local/julia/src/jltypes.c:2437
inst_tuple_w_ at /home/darwin/.local/julia/src/jltypes.c:2383
inst_type_w_ at /home/darwin/.local/julia/src/jltypes.c:2437
jl_instantiate_type_with at /home/darwin/.local/julia/src/jltypes.c:2480
jl_args_morespecific at /home/darwin/.local/julia/src/jltypes.c:3096
jl_typemap_list_insert_sorted at 
/home/darwin/.local/julia/src/typemap.c:1033
jl_typemap_insert_generic at /home/darwin/.local/julia/src/typemap.c:886
jl_typemap_insert at /home/darwin/.local/julia/src/typemap.c:1006
jl_method_table_insert at /home/darwin/.local/julia/src/gf.c:1069

⋮


It works fine if I change the name of the generated function to something 
else.  Is this the expected behavior?

Thanks,

Darwin


[julia-users] Re: Unexpected allocations in summing an array

2016-05-20 Thread Darwin Darakananda
I see, that makes sense.  Thanks!

On Friday, May 20, 2016 at 1:29:42 AM UTC-7, Kristoffer Carlsson wrote:
>
> Note that you only pay the cost once per function call in your first case 
> and not every time you access it inside the function. When x is inside the 
> function it's type is known so everything there is fast. This is usually 
> called a "function barrier" where you shield away your performance critical 
> part from a type instability by putting it inside a function like this. 
> Upon calling the function the type will be dynamically looked up but will 
> then stay constant inside the function.



[julia-users] Re: Unexpected allocations in summing an array

2016-05-19 Thread Darwin Darakananda
Thanks! That eliminated the extra allocations.  But I'm not understanding 
why that works.  The individual functions are not using any global 
variables, the array I'm passing has a concrete type, so why would the 
function be compiled with a heap allocated accumulator at all?  

Also, would this mean that ultimately in order to have performant code, I 
would need to wrap everything in a main function that does not take in any 
arguments?  That makes it a little tricky to incrementally test and profile 
the code.

On Thursday, May 19, 2016 at 11:22:04 PM UTC-7, Kristoffer Carlsson wrote:
>
> Do your timings in a function.



[julia-users] Unexpected allocations in summing an array

2016-05-19 Thread Darwin Darakananda
Hello all,

I'm running into some unexpected memory allocations that I'm hoping someone 
can help me with.  Here's an example the demonstrates the problem:

function sum_rand(n::Int)
s = zero(Float64)
for i in 1:n
s += rand(Float64)
end
return s
end

sum_rand(x::Vector) = sum_rand(length(x))

function sum_vector{T}(x::Vector{T})
s = zero(T)
for i in 1:length(x)
s += x[i]
end
return s
end

x = rand(100);

@allocated sum_rand(100)# 0
@allocated sum_rand(length(x))  # 16
@allocated sum_rand(length(x)::Int) # 0

@allocated sum_rand(x)   # 16
@allocated sum_vector(x) # 16


For some reason adding values that are read from an array allocates memory 
for the accumulating variable while summing up random values does not.I 
would have thought that the accumulating variable would be stack allocated 
for both functions.  It's not a lot of memory per function call, but I have 
code that sums up arrays in an inner loop, so the total cost adds up.

Any suggestions?

Thanks,

Darwin


[julia-users] Re: [Gadfly] - [Possible Bug] - plotting a vector using Geom.rectbin

2015-12-27 Thread Darwin Darakananda
I think Gadfly is treating your x-values as continuous values for some 
reason.  This should do what you want

plot(x = [1;2], y = [1;2], color = [1;2],  Geom.rectbin, Scale.x_discrete)

On Sunday, December 27, 2015 at 7:49:28 AM UTC-8, Uri Patish wrote:
>
> Hi, 
>
> I'm trying the following, 
>
> plot(x = [1;1], y = [1;2], color = [1;2],  Geom.rectbin)
>
> but it produces an empty plot. On the other hand, both of the following do 
> produces meaningful plots, 
>
> plot(x = [1;1], y = [1;2], color = [1;2],  Geom.point)
> plot(x = [1;2], y = [1;2], color = [1;2],  Geom.rectbin)
>
> I suspect this might be a bug, but maybe I'm missing something. 
>
> Cheers,
> Uri
>
>

[julia-users] Re: Compose - rotation ?

2015-08-27 Thread Darwin Darakananda
This sounds like the same issue as 
https://github.com/dcjones/Compose.jl/issues/133. Try using polygon instead of 
rectangle for now.

On Wednesday, August 26, 2015 at 10:34:21 AM UTC-7, Mark wrote:
> Learning Compose. 
> 
> Trying the code below to rotate images. 
> 
> The rotate function seems to work on the line-drawn "V" but not on the 
> colored checker box. 
> 
> How do I fix this so the rotate function works for drawings like the checker 
> box?
> 
> Some outputs attached.
> 
> Thank you for your advice.
> 
> 
> 
> 
> using Compose
> using Color 
> 
> # draw a black box
> function blackbox()
>    compose(context(), rectangle(), fill("black"))
> end
> 
> # draw a blue box
> function bluebox()
>    compose(context(), rectangle(), fill("lightblue"))
> end
> 
> # join pic2 to pic1 horizontally
> function hsplice(pic1, pic2)
>    compose(context(), compose(context(0.0, 0.0, 0.5, 1.0), pic1),
>    compose(context(0.5, 0.0, 0.5, 1.0), pic2))
> end
> 
> # join pic2 to pic1 vertically
> function vsplice(pic1, pic2)
>    compose(context(), compose(context(0.0, 0.0, 1, 0.5), pic1),
>    compose(context(0.0, 0.5, 1, 0.5), pic2))
> end
> 
> # rotate pic counter-clockwise 90 degrees
> function rotate(pic)
>     compose(context(rotation=Rotation(-pi/2)), pic)
> end
> 
> # draw a checker pattern
> function checker(p1, p2)
>    compose(vsplice(hsplice(p1, p2),
>    hsplice(p2, p1)))
> end
> 
> 
> # cpic is a blue and black checker picture
> cpic = checker(bluebox(), blackbox())
> 
> # cimg receives cpic
> cimg = SVG("cpic.svg", 8cm, 8cm)
> 
> # draw cpic to cimg
> draw(cimg, cpic)
> 
> #rotate checker:
> rpic = rotate(cpic)
> rimg = SVG("rpic.svg", 8cm, 8cm)
> draw(rimg, rpic)
> 
> # check rotate function:
> 
> # points to draw a "V"
> Vpoints = [ (0.2, 0),
>     (0.5, 1),
>     (0.8, 0) ]
> 
> 
> # draw a V:
> vpic = compose(context(), stroke("black"), line(Vpoints))
> 
> # file for "V" drawing:
> vimg = SVG("vimg.svg", 8cm, 8cm)
> 
> # draw vimg:
> draw(vimg, vpic)
> 
> # rotate vpic:
> rvpic = rotate(vpic)
> rvimg = SVG("rvimg.svg", 8cm, 8cm)
> draw(rvimg, rvpic)


[julia-users] Re: Nullable parametric types

2015-07-21 Thread Darwin Darakananda
Thanks for the responses!  I wasn't not sure how I could use typealiases to 
deal with this, so I went with the macro route and ended up with 
https://gist.github.com/darwindarak/0eb5e53c21c896392938.  It converts the 
functions/type declarations into the parametric form suggested by Mauro.

On Tuesday, July 21, 2015 at 2:50:16 PM UTC-7, David Gold wrote:
>
> Or use typealiases?
>
> On Tuesday, July 21, 2015 at 4:48:31 PM UTC-4, David Gold wrote:
>>
>> My instinct is to write a macro.
>>
>> On Tuesday, July 21, 2015 at 4:37:03 PM UTC-4, Darwin Darakananda wrote:
>>>
>>> Hi all,
>>>
>>> I'm in the process of replacing my Union{Nothing, T} annotations to 
>>> Nullable{T}, but I'm getting stuck when T is a parametric type.  For 
>>> example, replacing the function
>>>
>>> function myfunc(v::Union{Nothing, Vector})
>>> ...
>>> end
>>>
>>> with
>>>
>>> function myfunc(v::Nullable{Vector})
>>> ...
>>> end
>>>
>>> makes it completely uncallable since any vector I pass in comes with an 
>>> eltype parameter and Julia's type parameters are invariant.  For functions 
>>> or types that only have a couple Nullable types, I can do something like
>>>
>>> function myfunc{T}(v::Nullable{Vector{T}})
>>> ...
>>> end
>>>
>>> type MyType{T}
>>>v::Nullable{Vector{T}
>>> end
>>>
>>> but that gets very ugly when you have a large number of nullable types. 
>>>  Does anyone know of a cleaner way to do this?
>>>
>>> Thanks,
>>>
>>> Darwin
>>>
>>

[julia-users] Nullable parametric types

2015-07-21 Thread Darwin Darakananda
Hi all,

I'm in the process of replacing my Union{Nothing, T} annotations to 
Nullable{T}, but I'm getting stuck when T is a parametric type.  For 
example, replacing the function

function myfunc(v::Union{Nothing, Vector})
...
end

with

function myfunc(v::Nullable{Vector})
...
end

makes it completely uncallable since any vector I pass in comes with an 
eltype parameter and Julia's type parameters are invariant.  For functions 
or types that only have a couple Nullable types, I can do something like

function myfunc{T}(v::Nullable{Vector{T}})
...
end

type MyType{T}
   v::Nullable{Vector{T}
end

but that gets very ugly when you have a large number of nullable types. 
 Does anyone know of a cleaner way to do this?

Thanks,

Darwin


[julia-users] Re: ANN: SingularIntegralEquations.jl release v0.0.1

2015-07-07 Thread Darwin Darakananda
This is really cool!  I was actually looking for something like Lemma 5.9 
in your preprint, and definitely did not expect to find it on julia-users. 
 Thanks for saving me the time!

On Tuesday, July 7, 2015 at 5:41:36 AM UTC-7, richard@maths.ox.ac.uk 
wrote:
>
> This is to announce the v0.0.1 release of the new package 
> SingularIntegralEquations.jl 
> 
>
> Built on top of the fast linear algebra for function approximation in 
> ApproxFun, this new package solves problems in acoustic scattering 
> (Helmholtz and gravity Helmholtz equations), potential theory (Laplace 
> equation), fracture mechanics, and Riemann--Hilbert problems.
>
> There is a preprint available on the package's readme for algorithmic 
> details.
>
> Joint work with Sheehan Olver.
>


[julia-users] Re: Newbie question; convert a hex string to base64

2015-05-18 Thread Darwin Darakananda
This probably is not the safest way to do this, but would something like 
this work for you?

s = "0xABCDE"
base64encode(parse(s))


On Monday, May 18, 2015 at 9:54:17 PM UTC-7, Martin Becze wrote:
>
> Hello I'm just starting with julia and im stuck on converting a hex string 
> to base64 encoded string. How would you do this with julia?
>
> Thanks,
> -Martin
>


[julia-users] Re: how to compute the maximum value of an object's attribute

2015-05-07 Thread Darwin Darakananda
How about :

mapreduce(t -> t.tau_max, max, TUnitS)


On Thursday, May 7, 2015 at 8:49:49 AM UTC-7, Michela Di Lullo wrote:
>
> Hello everyone, 
>
> I have to compute the maximum value of tau_max, attribute of TUnit which 
> is declared as follows:
>
> immutable TUnit
>
> Node::Int16
>
> a::Float64
>
> b::Float64
>
> c::Float64
>
> inf::Float64
>
> sup::Float64
>
> ton::Int16
>
> toff::Int16
>
> storia0::Int16
>
> pt0::Float64
>
> rampa_up::Float64
>
> rampa_dwn::Float64
>
> rampa_up_str::Float64
>
> rampa_dwn_str::Float64
>
> SUC_C::Float64
>
> tau_max::Int16
>
> end
>
>
> TUnitS = Array(TUnit,size(generators,1))
>
>
> for j in 1:size(generators,1)
>
> #println(generators[j,1:end])
>
> #FL:This call the contructor, see all the discussion in the manual 
> "Parametric Constructors" section
>
> #to understand the whole (complex story) of the syntax with "..."
>
> TUnitS[j]   = TUnit(generators[j,1:end]...)
>
> println("TUnit = ", j, "\t Node[$j]= ", TUnitS[j].Node, "\t a[$j] = ", 
> TUnitS[j].a, "\t ...", "\t tau_max[$j] = ", TUnitS[j].tau_max)
>
> end
>
>
> I tried with both maximum(TUnitS.tau_max) and maximum(TUnitS[j].tau_max, 
> j=[1:gmax]), but it doesn't work..
>
>
> Any idea about how to make it? 
>
>
> Thank you very much for any suggestion,
>
>
> Michela
>


[julia-users] Re: Package details

2015-04-29 Thread Darwin Darakananda
The `names` function might be what you're looking for, for example:

names(Base)

On Wednesday, April 29, 2015 at 7:39:49 PM UTC-7, Sibnarayan Guria wrote:
>
> how to know functions and methods available in a julia package
>
>

[julia-users] Re: Argument Placeholder

2015-04-22 Thread Darwin Darakananda
You can use underscore _ as a placeholder, for example:

_, _, x = (1, 2, 3)


On Wednesday, April 22, 2015 at 5:09:16 PM UTC-7, Ryan Li wrote:
>
> Hi,
> I was wondering if there is any argument placeholder in Julia.
> In Matlab, if we do not require one return argument, we just replace it 
> with ~, e.g., [~,R]=qr(A).
> Is there any similar behavior in Julia?
> Best,
> Yingzhou
>


[julia-users] Re: how to remove the quotation marks ?

2015-03-01 Thread Darwin Darakananda
How about something like

map(println,["abc","def"]);
abc
def



On Sunday, March 1, 2015 at 1:00:38 PM UTC-8, paul analyst wrote:
>
> I need :)
> P
>
> W dniu niedziela, 1 marca 2015 20:47:15 UTC+1 użytkownik Simon Danisch 
> napisał:
>>
>> If I'm not mistaken, that's how an array of strings gets displayed:
>> julia>["tets", "test"]
>> "test"
>> "test"
>>
>> So no need for removing them!
>>
>> Am Sonntag, 1. März 2015 19:51:40 UTC+1 schrieb paul analyst:
>>>
>>> Przetłumacz wiadomość na język polski   
>>> how to remove the quotation marks ?, like below.. 
>>>
>>> julia> (split(bytestring(r.body),"\r\n"))
>>> 180-element Array{SubString{UTF8String},1}
>>> :
>>>  ""
>>>
>>>
>>>  ""
>>>
>>>
>>>  ""
>>>
>>

[julia-users] Re: Gadfly: Text labels rather than numbers along x-axis of plot?

2015-02-04 Thread Darwin Darakananda
You can do something like

plot(x=1:12,y=rand(5), Guide.xticks(ticks=[1:12]), Scale.x_discrete(labels=
Dates.monthname))

The label argument takes in a function that outputs a label. 
 Alternatively, you can provide the set x to be the dates (either strings 
or DateTime type) directly:

x = [Dates.monthname(i) for i in 1:12]
plot(x = x, y = rand(5), Guide.xticks(ticks=[1:12]))

On Wednesday, February 4, 2015 at 2:00:33 AM UTC-8, cormu...@mac.com wrote:
>
> Given this simple graph:
>
> plot(x=1:12,y=rand(5), Guide.xticks(ticks=[1:12]))
>
> where the 12 values correspond to the months January through December.
>
> Instead of seeing 1 ..12 along the x-axis, I'd like to see the month 
> names. Is this possible?
>


[julia-users] Re: set hard view limit in Gadfly plot axis

2015-01-22 Thread Darwin Darakananda
You can use:

plot(x=rand(10), y=rand(10), Geom.line, Coord.Cartesian(ymin=-0.1,ymax=0.1))

I think applying

Scale.y_continuous(minvalue=-0.10, maxvalue=0.10)

should do the same thing, but it's currently not working the way it should.

On Wednesday, January 21, 2015 at 4:36:49 PM UTC-8, Ken B wrote:
>
> I'm trying to plot some Geom.lines with Gadfly, but some results are way 
> off, so I'd like to keep my y-axis plot between some hard limits. 
>
> The current minvalue and maxvalue arguments stretch out the graph, however 
> if there are datapoints outside these min/maxvalues, the axis will scale 
> anyway.
>
> For a simple example:
>
> plot(x=rand(10), y=rand(10), Geom.line, 
> Scale.y_continuous(minvalue=-0.10, maxvalue=0.10))
>
> here I would actually want the plot to be limited in the Y-axis to the 
> range -0.1 ; 0.1, not stretched out to any value higher than 0.1
>
> I've found a related issue (
> https://github.com/dcjones/Gadfly.jl/issues/280) but I don't understand 
> the solution.
>
> Thanks,
> Ken
>


[julia-users] Re: Constructing Expr from s-expressions

2015-01-04 Thread Darwin Darakananda
Thanks! That's exactly what I was looking for.  The show_sexpr code 
actually looks basically identical to what's in Base, I wonder why 
sexpr_to_expr 
didn't make it.

On Sunday, January 4, 2015 3:10:15 AM UTC-8, lapeyre@gmail.com wrote:
>
> Not sure, but maybe this is what you are looking for,
>
> https://gist.github.com/toivoh/4121122
>
> On Sunday, January 4, 2015 6:49:39 AM UTC+1, Darwin Darakananda wrote:
>>
>> Hi everyone,
>>
>> Is there currently a function that converts s-expressions into Expr 
>> structures (basically the reverse of Base.Meta.show_sexpr)?
>>
>> I just started playing around with metaprogramming in Julia, so I'm 
>> probably doing things wrong.  But there are a lot of times where I end up 
>> creating highly nested Expr objects, ending up with code that is 
>> indecipherable.  I've found that the output from show_sexpr is sometimes 
>> easier to read that that of dump or xdump (which only seems to display the 
>> first couple of levels).  So I'm curious to see if the reverse 
>> (s-expression -> Expr) is also true.  
>>
>> If this function does not exist, would it be something that people would 
>> find useful?
>>
>> Thanks and Happy New Years!
>>
>> Darwin
>>
>

[julia-users] Constructing Expr from s-expressions

2015-01-03 Thread Darwin Darakananda
Hi everyone,

Is there currently a function that converts s-expressions into Expr 
structures (basically the reverse of Base.Meta.show_sexpr)?

I just started playing around with metaprogramming in Julia, so I'm 
probably doing things wrong.  But there are a lot of times where I end up 
creating highly nested Expr objects, ending up with code that is 
indecipherable.  I've found that the output from show_sexpr is sometimes 
easier to read that that of dump or xdump (which only seems to display the 
first couple of levels).  So I'm curious to see if the reverse 
(s-expression -> Expr) is also true.  

If this function does not exist, would it be something that people would 
find useful?

Thanks and Happy New Years!

Darwin


[julia-users] Re: Very basic problem with Gadfly

2014-11-28 Thread Darwin Darakananda
I think Geom.rectbin  might be what 
you are looking for.  You'll need to split you data into two arrays of x 
and y positions, or four arrays of x_min, x_max, y_min, y_max positions for 
better control.  If you don't care about the exact positioning, it might be 
even easier to convert your data into a 2D matrix then use the spy() 
function.

coords = Int64[x[j] for x in L, j in 1:2]
plot(x = coords[:,1], y = coords[:,2], Geom.rectbin, Scale.x_discrete, Scale
.y_discrete)

or

x_max = Float64[x[1] + 0.5 for x in L]
x_min = Float64[x[1] - 0.5 for x in L]
y_max = Float64[x[2] + 0.5 for x in L]
y_min = Float64[x[2] - 0.5 for x in L]


plot(x_max = x_max, x_min = x_min, y_max = y_max, y_min = y_min, Geom.
rectbin)






On Thursday, November 27, 2014 8:49:36 PM UTC-8, Alexander Gruber wrote:
>
> I have a big list of rectangles I'd like to draw. What I want is to end up 
> with something that looks like ArrayPlot 
>  in Mathematica.
>
> I have it the data the form of an Array{(Int64,Int64),1}, where each entry 
> is the center of the rectangle.  I have figured out that I can get a Vector 
> of rectangles by
> map(x->rectangle(x[1],y[1],1,1))
> but I can't figure out how to actually plot these once I have them.  How 
> do I turn the array of rectangles into an image?  I've used the following 
> before (calling my list of points L)
> draw(SVG("output.svg",20cm,20cm),plot(x=map(x->x[1],L),y=map(x->x[2],L)))
> to output the points as point objects to a file, but I can't seem to 
> modify this syntax to work for the rectangle objects.
>
> (As a side note, I would also be interested in knowing how to get the 
> rasterized version of this, i.e. convert single pixels at coordinates 
> corresponding to L to black and leave the rest white.  But even the vector 
> graphics part is turning out to be harder than expected, so maybe that will 
> have to be an adventure for another day...)
>


[julia-users] Re: Plotting matrices a la imagesc() using Gadfly?

2014-11-19 Thread Darwin Darakananda
I think you can use the continuous_color_gradient scale 
 element. So 
maybe something like:

spy(rand(5,5),Scale.continuous_color(minvalue = 0.1, maxvalue = 0.9))

Values that are outside the specified range will be black.  You can also 
get more direct control over the colors by using the ContinousColorScale 
.  

On Wednesday, November 19, 2014 12:36:23 AM UTC-8, JVaz wrote:
>
> Does anyone know how to fix the colors of the legend, independently of the 
> values to plot? For example, even if all the values of the matrix to plot 
> are 0, I still want the legend to go from -1 to 1, to keep all the 
> different plots uniform.
>
> I've been reading a lot here, but didn't find it:
> http://dcjones.github.io/Gadfly.jl/geom_rectbin.html
>
> El viernes, 14 de febrero de 2014 09:38:16 UTC+9, Elliot Saba escribió:
>>
>> Hey there, I'm trying to use Gadfly's Geom.binrect to plot a matrix, but 
>> I can't figure out how to do it without going through a lot of rigamarole 
>> to generate a DataFrame like is used in the example 
>> 
>>  docs.
>>
>> I have, say, a 10x10 matrix:
>>
>> z = randn(10,10)
>>
>> In matlab, if I wanted to plot it, I would just imagesc(z).  I know that 
>> if I had a dataframe with a row for each point in z stored in a column, and 
>> the x/y coordinates recorded in their own columns, I could coerce Gadfly to 
>> plot what I want as shown in the example.  But is there a simpler way to do 
>> this?  I've tried something like:
>>
>> plot(x=1:10, y=1:10, color=z, Geom.rectbin)
>>
>> But Gadfly just plots one pixel for each x and y passed in.  I understand 
>> why it's doing that, I just don't know the easiest way to get it to treat z 
>> as a matrix, instead of a vector.
>>
>> Thanks,
>> -E
>>
>

[julia-users] Re: Gadfly: text placing

2014-10-25 Thread Darwin Darakananda
There's a Geom.label  element you can 
use.  Although I don't think it can handle different orientations yet.  So 
something like this:

using DataFrames

labels = DataFrame(x =rand(3), y = rand(3), label = ["one", "two", "three"])
plot(labels, x = "x", y = "y", label = "label", Geom.label)


On Friday, October 24, 2014 4:11:43 PM UTC-7, Keyan Ghazi-Zahedi wrote:
>
> I would like to freely place some text into my plot by giving some 
> coordinates and an orientation. Is that possible?
>
> Cheers,
> Keyan
>


[julia-users] Re: Gadfly plotting multiple lines with different colours

2014-10-22 Thread Darwin Darakananda
To specify colors with the layer approach, you can add a theme element to 
each layer:

colors = [color(c) for c in ["red", "blue", "green", ...]]
layers = Layer[]
for i=1:10
   push!(layers, layer(x=x, y=M[:,i], Geom.line, 
Theme(default_color=colors[i]))[1])
end

The only other way I'm aware of doing this is to convert the matrix to a 
DataFrame with an extra column to identify each line. So something like:

row,col = size(M)
data = vcat([DataFrame(x = x, M = M[:,i], line = i*ones(Int, row)) for i in 
1:col])
plot(data, x = :x, y = :M, color = :line, Geom.line)


On Tuesday, October 21, 2014 9:25:22 PM UTC-7, Dom Luna wrote:
>
> So I have a vector x and a matrix M.
>
> The vector x consists of the points on the x axis and the columns of M are 
> the respective y-cords for each line.
>
> I'm currently plotting all the lines using layers:
>
> layers = Layer[]
> for i=1:10
>push!(layers, layer(x=x, y=M[:,i], Geom.line)[1])
> end
>
> plot(layers)
>
> This gives me essentially what I want except all the lines are same 
> colour. What's the best way for Gadfly to uniquely colour each line?
>
> Also if the above layering approach isn't the best way to do what I'm 
> trying to do please let me know.
>
> Thanks.
>


Re: [julia-users] Re: Juila vs Mathematica (Wolfram language): high-level features

2014-07-22 Thread Darwin Darakananda
If it's possible, do you mind showing the function you were plotting that 
lead to the extra lines in Gadfly?  The current master should already be 
using the `group` aesthetic for contour lines.

On Tuesday, July 22, 2014 10:06:53 AM UTC-7, Zahirul ALAM wrote:
>
> Thanks Stefan, Tomas and Viral. 
>
> Stefan and Tomas: Contourplot definitely looks very pretty in gadfly.  
>
> Tomas: But I am afraid the plot contains extra lines which some of you 
> have already pointed to be aesthetic issue. It is not entirely clear how to 
> use the group aesthetic to fix it. I will read on. 
>
> Viral: I am currently using the PyPlot package.
>
> btw: on this regard, I am yet to  a straight forward manner to do find 
> dual Y axis or dual X axis plot in either Mathematica, Matlab, 
> Matplotlib, or Maple. May be in Gadfly this is a feature that can be built 
> in. 
>
>
> On Tuesday, 22 July 2014 03:08:26 UTC-4, Tomas Lycken wrote:
>>
>> > It is only for 2-D plotting, does not do contour or density plot ( two 
>> types I tend to use the most). I am sure it will only get improved.
>>
>> There is, actually, some functionality for contour and density plot 
>> already, but all the nuts and bolts aren't really tightened yet, and I 
>> don't know if the progress so far has been documented at all, but if you 
>> have a function `f = (x,y) -> z(x,y)`, you can do `plot(f, xmin, xmax, 
>> ymin, ymax)` to get a nice contour plot. Support for contour plots of 
>> matrices is under construction - take a look at [#293](
>> https://github.com/dcjones/Gadfly.jl/issues/293) for more details.
>>
>> Density plots is sort-of implemented through [Geom.rectbin](
>> http://dcjones.github.io/Gadfly.jl/geom_rectbin.html) which may or may 
>> not be what you need.
>>
>> // T
>>
>> On Monday, July 21, 2014 11:09:31 PM UTC+2, Zahirul ALAM wrote:
>>>
>>> Thanks Stefan. I did find out that I can type \alpha for Unicode α. 
>>> My point was more to do with the "traditional" input / output mode. 
>>>
>>> btw if I am not mistaken I think in markup mode the \alpha does not 
>>> work. I guess not even auto complete works in markup mode when pressed tab. 
>>> May be I am doing it wrong. However it works just fine once the block is 
>>> "compiled". But I think that has nothing to do with IJulia.
>>>
>>> I have indeed met Gadfly. I had Gadfly in mind when I wrote that. It is 
>>> indeed very pretty. It is only for 2-D plotting, does not do contour or 
>>> density plot ( two types I tend to use the most). I am sure it will only 
>>> get improved. 
>>>
>>> On Monday, 21 July 2014 14:48:17 UTC-4, Stefan Karpinski wrote:

 On Mon, Jul 21, 2014 at 9:55 AM, Zahirul ALAM  
 wrote:

> One feature I would like to see from IJulia may be is that the input 
> of greek and mathematical symbol in way that looks natural, e.g. using 
> subscript, in division, integration etc as way to input. This will 
> definitely be a significant improvement IMHO. 
>

 You can do Unicode input using LaTeX codes in IJulia by typing, e.g. 
 \alpha, which will be turned into a Unicode α. That's not as fancy as 
 what you can do in Mathematica, but I'm not sure we want to go there. I 
 find editing Mathematica code pretty irritating and it's not that much 
 better looking except for the "traditional" output mode, which you cannot 
 use as an input format anyway.

 second feature is to be able to plot a function in a way one can do in 
> Mathematica. Plotting packages for Julia does this in very limited way 
> (unless I am missing something)
>

 Have you met Gadfly ?

>>>

[julia-users] Re: Getting Gadfly results in IJulia to be interactive

2014-07-14 Thread Darwin Darakananda
I see. I've been using Safari.  Just tried it on Firefox and Chrome, it 
works great.  Thanks!

On Monday, July 14, 2014 11:34:33 AM UTC-7, Daniel Jones wrote:
>
>
> What browser are you using?
>
> On Monday, July 14, 2014 11:02:25 AM UTC-7, Darwin Darakananda wrote:
>>
>> My Gadfly plots seem to be static when they are made in an IJulia 
>> notebook.  However, interactive panning and zooming work when I export the 
>> IJulia notebook to HTML as well as when I call the plot function from the 
>> REPL.  Does anyone else have this problem or have an idea of what's 
>> happening?
>>
>> Thanks,
>>
>> Darwin
>>
>

[julia-users] Getting Gadfly results in IJulia to be interactive

2014-07-14 Thread Darwin Darakananda
My Gadfly plots seem to be static when they are made in an IJulia notebook. 
 However, interactive panning and zooming work when I export the IJulia 
notebook to HTML as well as when I call the plot function from the REPL. 
 Does anyone else have this problem or have an idea of what's happening?

Thanks,

Darwin


[julia-users] Re: Setting the axis scale on Gadfly

2014-07-09 Thread Darwin Darakananda
Guide.xticks might be what you're looking for.  For example:

plot(sin, 0, pi, Guide.xticks(ticks=[0:0.2:pi]))


The y-axis can be specified with Guide.yticks

On Wednesday, July 9, 2014 10:53:58 AM UTC-7, Lucas Simões wrote:
>
> I tried looking on the manual but I couldn't find anything clearly: 
> is there any way to set the scale on some aixs? More specifically I want 
> to set the division step with which the numbers should appear on the x axis
>
> Thank you and sorry about the poor english =/
>
>

[julia-users] Re: ANN: Contour.jl

2014-07-07 Thread Darwin Darakananda
For now, maybe something like:

```
cs = contours(X,Y,Z,h)

for c in cs
lvl,lines = c.level, c.lines
for line in lines
line_color = string((lvl - minimum(h))/maximum(h)); # Shades of gray
v = reinterpret(Float64, line.vertices, (2, length(line.vertices)))
plot(v[1,:][:], v[2,:][:], "-", color=line_color)
end
end
```

We're still discussing the API for extracting the vertex information into 
plot-friendly data.  Until then, the built-in `contour` function from 
PyPlot is probably the easiest way to go.

On Monday, July 7, 2014 1:02:55 PM UTC-7, Andrei Berceanu wrote:
>
> So what would be the easiest way of plotting the contours obtained with 
> contour(x, y, Z, h) using PyPlot?