Re: [julia-users] Got an exception of type ErrorException outside of a @test: type DataType has no field FactorMargin

2016-11-17 Thread David P. Sanders
If you can produce a minimal working example (the *shortest* piece of code that 
produces the problem and that people can run), you will be more likely to get 
help. This probably involves removing a lot of stuff from your code that I'd 
not relevant to this particular problem.  

Re: [julia-users] problem when include code in Julia

2016-11-17 Thread David P. Sanders
How did you save the .jl file? 
It seems your editor added the extra
.txt suffix. You might want to try a different editor that is designed for 
editing code, e.g. Atom.

[julia-users] Graphs.jl to plot graphs in Jupyter notebooks?

2016-11-11 Thread David P. Sanders
Use LightGraphs.jl

I believe that Graphs.jl is deprecated. 

[julia-users] Re: Value assignment of compound expression

2016-11-10 Thread David P. Sanders


El jueves, 10 de noviembre de 2016, 0:43:19 (UTC-5), 
wan...@terpmail.umd.edu escribió:
>
>
>
> Hi guys,
>
> I am new to Julia and learning from scratch. I ran into the compound 
> expression like this:
>
>
> tri=base=5;height=10;1/2*base*height
>
>
> This is to calculate the triangle area. The result is right. But I am 
> concerned about the value of "tri". What is it after the calculation. 
> Shouldn't it be 25? Julia told me it is 5!!
>
> Can anybody help me with this?
>

If you actually want the result assigned to tri, you can do it by adding 
parentheses to what you wrote:

julia> tri1 = (base = 5; height = 10; 0.5 * base * height)
25.0

julia> tri1
25.0

(Note that the code is more readable with more space.)

However, what you are really trying to do is make something that, given a 
base and a height, calculates the area,
i.e. a function. So it is more natural (and reusable) to do something like 
this:


julia> triangle_area(base, height) = 0.5 * base * height
tri (generic function with 1 method)

julia> base, height = 5, 10
(5,10)

julia> triangle_area(base, height)
25.0

This has the advantage that you can also reuse the variables base and 
height later. 

(Note also that `base` is a function defined in the Julia standard library 
(which itself is called `Base`!)
and this code overwrites it when run in global scope.)
 


[julia-users] Re: How to built an array with some keys of a dictionary ?

2016-11-09 Thread David P. Sanders


El lunes, 7 de noviembre de 2016, 9:18:03 (UTC-5), Steven G. Johnson 
escribió:
>
>
>
> On Monday, November 7, 2016 at 9:02:44 AM UTC-5, Fred wrote:
>>
>> Hi,
>>
>> I have many problems to build arrays with the keys of a dictionary except 
>> for the simple situation :
>>
>> a = [uppercase(key) for key in keys(dict)]# works fine
>>
>> If I try to select the keys with more complex criteria like :
>>
>> dict = Dict("a" => 1, "b" => 2, "c" => 3, "d" => 4, "e" => 5)
>>
>> a = Array{String}
>>
>
> This is a mistake: you just assigned "a" to an array *type*, not an array 
> *instance*.  It should be a = Array{String}(). 
>
> In Julia 0.5, you can also just do:
>
> [k for k in keys(dict) if dict[k] < 2]
>
>
An alternative syntax is

[k for (k,v) in dict if v < 2]

which iterates over (key, value) pairs in the dictionary.
 


Re: [julia-users] Re: converting binary string into integer

2016-11-06 Thread David P. Sanders


El domingo, 6 de noviembre de 2016, 15:18:03 (UTC-5), Alberto Barradas 
escribió:
>
> Hi guys,
> Now that `parseint()` got removed for version 0.5, Is `parse()` the only 
> way to do this?
>  How could I parse binary into a BigInt? More specifically, I want to see 
> the integer number of the arecibo message. (73x23 so 1679 binary digits 
> into a big int)
>

julia> s = join(rand(0:1, 64))
"100101100011100010000010100100011010010100100111"

julia> parse(Int64, s, 2)
-- OverflowError --- Stacktrace (most recent call last)

julia> parse(BigInt, s, 2)   # the 2 at the end is the base (here, binary)
10824412573101347815 


[julia-users] Root finding package

2016-10-15 Thread David P. Sanders
https://github.com/giordano/PolynomialRoots.jl

Re: [julia-users] Re: Julia-i18n logo proposal

2016-10-03 Thread David P. Sanders
Or just remove the J and put the three characters from the other scripts? 

[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

>
>

Re: [julia-users] Re: Visualizing a Julia AST (abstract syntax tree) as a tree

2016-09-22 Thread David P. Sanders


El jueves, 22 de septiembre de 2016, 10:29:11 (UTC-4), Tom Breloff escribió:
>
> Hi David this is very cool and useful!  I'd be happy to have it in 
> PlotRecipes if you don't find a better home for it.  If there's a generic 
> function to produce an adjacency list then we could use my graph recipes.  
> When I have the time (i.e. soonish when I really want nicer graphs) I plan 
> on incorporating the new GraphLayout into the recipes.  Let me know.
>

Hi Tom,

That sounds like a pretty good idea, though I have to say I haven't grokked 
PlotRecipes yet.

Since LightGraphs.jl doesn't support labelled graphs, maybe 

https://github.com/JuliaGraphs/Networks.jl

is the right solution? Do you have any suggestions about this?


 

>
> Tom
>
> On Thu, Sep 22, 2016 at 10:12 AM, David P. Sanders <dpsa...@gmail.com 
> > wrote:
>
>>
>>
>> <https://lh3.googleusercontent.com/-mtiBFUuqKww/V-Pmryhi8ZI/F6g/Gt-E1jDC_sECP6JTp1NIjWnoi1Gd6gOpgCLcB/s1600/Screen%2BShot%2B2016-09-21%2Bat%2B5.25.35%2BPM.png>
>>
>> Here's an example of the output.
>>
>>
>> El miércoles, 21 de septiembre de 2016, 17:24:52 (UTC-4), David P. 
>> Sanders escribió:
>>>
>>> Hi,
>>>
>>> In case it's useful for anybody, the following notebook shows how to use 
>>> the LightGraphs and TikzGraphs packages
>>> to visualize a Julia abstract syntax tree (Expression object) as an 
>>> actual tree:
>>>
>>> https://gist.github.com/dpsanders/5cc1acff2471d27bc583916e00d43387
>>>
>>> Currently it requires the master branch of TikzGraphs.jl.
>>>
>>> It would be great to have some kind of Julia snippet repository for this 
>>> kind of thing that is less than a package but
>>> provides some kind of useful functionality. 
>>>
>>> David.
>>>
>>>
>>>
>

[julia-users] Re: Visualizing a Julia AST (abstract syntax tree) as a tree

2016-09-22 Thread David P. Sanders



<https://lh3.googleusercontent.com/-mtiBFUuqKww/V-Pmryhi8ZI/F6g/Gt-E1jDC_sECP6JTp1NIjWnoi1Gd6gOpgCLcB/s1600/Screen%2BShot%2B2016-09-21%2Bat%2B5.25.35%2BPM.png>

Here's an example of the output.


El miércoles, 21 de septiembre de 2016, 17:24:52 (UTC-4), David P. Sanders 
escribió:
>
> Hi,
>
> In case it's useful for anybody, the following notebook shows how to use 
> the LightGraphs and TikzGraphs packages
> to visualize a Julia abstract syntax tree (Expression object) as an actual 
> tree:
>
> https://gist.github.com/dpsanders/5cc1acff2471d27bc583916e00d43387
>
> Currently it requires the master branch of TikzGraphs.jl.
>
> It would be great to have some kind of Julia snippet repository for this 
> kind of thing that is less than a package but
> provides some kind of useful functionality. 
>
> David.
>
>
>

[julia-users] Visualizing a Julia AST (abstract syntax tree) as a tree

2016-09-21 Thread David P. Sanders
Hi,

In case it's useful for anybody, the following notebook shows how to use 
the LightGraphs and TikzGraphs packages
to visualize a Julia abstract syntax tree (Expression object) as an actual 
tree:

https://gist.github.com/dpsanders/5cc1acff2471d27bc583916e00d43387

Currently it requires the master branch of TikzGraphs.jl.

It would be great to have some kind of Julia snippet repository for this 
kind of thing that is less than a package but
provides some kind of useful functionality. 

David.




[julia-users] What is the best way to element-wise right shift an array?

2016-09-18 Thread David P. Sanders
You should also benchmark the simple for loop. Please report back with the 
results. 

[julia-users] Re: Pkg.add() works fine while Pkg.update() doesn't over https instead of git

2016-09-14 Thread David P. Sanders

I am a fan of deleting the entire .julia directory in your home directory 
and reinstalling your packages.

You can also just keep the REQUIRE file from .julia/v0.4 somewhere, do 
Pkg.init(), then copy the REQUIRE file back and do
Pkg.resolve()  to reinstall everything you previously had installed.

El martes, 13 de septiembre de 2016, 10:54:43 (UTC-4), Rahul Mourya 
escribió:
>
> Hi,
> I'm using Julia-0.4.6. My machine is behind a firewall, thus configured 
> git to use https: git config --global url."https://".insteadOf git://.
> Under this setting, I'm able to install packages using Pkg.add(), however, 
> when I use Pkg.update(), I get following error:
>
> INFO: Updating METADATA...
> Cannot pull with rebase: You have unstaged changes.
> Please commit or stash them.
> ERROR: failed process: Process(`git pull --rebase -q`, ProcessExited(1)) 
> [1]
>  in pipeline_error at process.jl:555
>  in run at process.jl:531
>  in anonymous at pkg/entry.jl:283
>  in withenv at env.jl:160
>  in anonymous at pkg/entry.jl:282
>  in cd at ./file.jl:22
>  in update at ./pkg/entry.jl:272
>  in anonymous at pkg/dir.jl:31
>  in cd at file.jl:22
>  in cd at pkg/dir.jl:31
>  in update at ./pkg.jl:45
>
> what could be the reason? Any workaround this?
>
> Thanks!
>


[julia-users] Re: online (streaming) statistics?

2016-09-14 Thread David P. Sanders
Apparently the problem was using "julialang" instead of just "julia" in the 
search.
julialang will, I guess, mainly pick up things on the Julia language home 
page,
whereas you were looking for an external package.

El miércoles, 14 de septiembre de 2016, 12:12:06 (UTC-4), David P. Sanders 
escribió:
>
>
>
> El miércoles, 14 de septiembre de 2016, 12:02:32 (UTC-4), Neal Becker 
> escribió:
>>
>> David P. Sanders wrote: 
>>
>> > 
>> > 
>> > 
>> > El miércoles, 14 de septiembre de 2016, 11:45:00 (UTC-4), Neal Becker 
>> > escribió: 
>> >> 
>> >> Is there a package for online (streaming) statistics? 
>> >> 
>> > 
>> > Please use Google before posting questions like this. 
>> > Googling "online streaming statistics Julia" gives the answer as the 
>> first 
>> > link. 
>> > 
>>
>> I apologize for the noise, I tried googling "julialang online statistics" 
>> but that produced no useful result (at least on the 1st page) 
>>
>
> OK, fair enough, sorry! 
>


[julia-users] Re: online (streaming) statistics?

2016-09-14 Thread David P. Sanders


El miércoles, 14 de septiembre de 2016, 12:02:32 (UTC-4), Neal Becker 
escribió:
>
> David P. Sanders wrote: 
>
> > 
> > 
> > 
> > El miércoles, 14 de septiembre de 2016, 11:45:00 (UTC-4), Neal Becker 
> > escribió: 
> >> 
> >> Is there a package for online (streaming) statistics? 
> >> 
> > 
> > Please use Google before posting questions like this. 
> > Googling "online streaming statistics Julia" gives the answer as the 
> first 
> > link. 
> > 
>
> I apologize for the noise, I tried googling "julialang online statistics" 
> but that produced no useful result (at least on the 1st page) 
>

OK, fair enough, sorry! 


[julia-users] Re: Curious parsing behavior

2016-09-14 Thread David P. Sanders


El miércoles, 14 de septiembre de 2016, 11:12:52 (UTC-4), David Gleich 
escribió:
>
> Ahah! That explains it.
>
> Is there a better way to create floating point literals that avoid this?
>

I think using 1782.0 instead of 1782. (without the 0) will solve this?
I seem to remember there was an issue to deprecate the style without the 0.
 

>
> David
>
> On Wednesday, September 14, 2016 at 9:26:42 AM UTC-4, Steven G. Johnson 
> wrote:
>>
>>
>>
>> On Wednesday, September 14, 2016 at 9:18:11 AM UTC-4, David Gleich wrote:
>>>
>>> Can anyone give me a quick explanation for why these statements seem to 
>>> parse differently?
>>>
>>> julia> 1782.^12. + 1841.^12.
>>>
>>
>> .^ and .+ are (elementwise/broadcasting) operators in Julia, and there is 
>> a parsing ambiguity here because it is not clear whether the . goes with 
>> the operator or the number.
>>
>> See also the discussion at
>>
>>  https://github.com/JuliaLang/julia/issues/15731
>>  https://github.com/JuliaLang/julia/pull/11529
>>
>> for possible ways that this might be made less surprising in the future.
>>
>

[julia-users] Re: online (streaming) statistics?

2016-09-14 Thread David P. Sanders


El miércoles, 14 de septiembre de 2016, 11:45:00 (UTC-4), Neal Becker 
escribió:
>
> Is there a package for online (streaming) statistics? 
>

Please use Google before posting questions like this.
Googling "online streaming statistics Julia" gives the answer as the first 
link.



 

>
> This would be an object that could be called repeatedly with new data, and 
> would produce stats on the accumulated results (without actually having to 
> collect all the results at 1 time) 
>
> I have made a package for python which wraps some of 
> http://www.boost.org/doc/libs/1_61_0/doc/html/accumulators.html 
>
> but have no clue how to do this for Julia (hopefully someone else already 
> has) 
>
>

[julia-users] Re: Priority queue - peek versus dequeue!

2016-09-13 Thread David P. Sanders


El martes, 13 de septiembre de 2016, 17:16:19 (UTC-4), Júlio Hoffimann 
escribió:
>
> Hi,
>
> Could you explain why "peek" returns the pair (key,value) whereas 
> "dequeue!" only returns the key?
>
> using Base.Collections
> pq = PriorityQueue()
> enqueue!(pq, key, value)
> key, value = Collections.peek(pq)
> key = dequeue!(pq)
>
> I wanted to have a single line in which I retrieve both (key,value) and at 
> the same time remove the pair from the collection:
>
> key, value = dequeue!(pq)
>
> Should I open an issue on GitHub?
>


I also wondered that at some point. Yes please to an issue.
It also seems to me that for consistency, this should be called pop! rather 
than dequeue!, and enqueue! should be push!

 

>
> -Júlio
>


[julia-users] Re: Pkg.update() does not pull latest version?

2016-09-06 Thread David P. Sanders



El martes, 6 de septiembre de 2016, 14:17:28 (UTC-4), Tony Kelman escribió:
>
> I hate to have to say "RTFM" about this so often, but see 
> http://docs.julialang.org/en/release-0.4/manual/strings/#version-number-literals.
>  
> The trailing dash means including prereleases of the given version. 
> (Considering how unintuitive this is we should probably transition to 
> something clearer when we redesign Pkg.) The first number given is an 
> inclusive lower bound, and if a second number is given then it's an 
> exclusive upper bound.
>

How about replacing the "-" by "pre":  0.5pre instead of 0.5-. That seems 
clearer.
 

>
> I see a few packages applying upper bounds to ForwardDiff, and a few to 
> MathProgBase and ReverseDiffSparse. I may have missed something (were these 
> taken from METADATA or the package directory? It should be the former, 
> sorry if I didn't say as much - METADATA can be changed after-the-fact but 
> tagged package content can't) but those don't look like they would conflict.
>
> On Tuesday, September 6, 2016 at 10:03:27 AM UTC-7, Tim Wheeler wrote:
>>
>> I wrote the script  and put the output in the attached file.
>>
>> I assume that the '-' at the end of a dep is an upperbound?
>>
>> On Tuesday, September 6, 2016 at 9:35:46 AM UTC-7, Tim Wheeler wrote:
>>>
>>> Ok, will do!
>>>
>>> On Tuesday, September 6, 2016 at 9:31:25 AM UTC-7, Tony Kelman wrote:

 There's a bug somewhere with that error message, I've seen it points at 
 the wrong package. If we can come up with a reproducible test case here 
 it'll help for fixing the bug and making that message more useful.

 It's almost certainly not Compat (I don't think anyone has ever added 
 an upper bound to a Compat dependency). Perhaps loop over Pkg.installed() 
 and display the contents of the REQUIRE file for the specific tags you 
 have 
 currently installed, see who is upper-bounding each other? We do need 
 better tools for debugging this kind of thing to make it easier to figure 
 out what the dependency resolver is doing, which bound constraints are 
 active etc.


 On Tuesday, September 6, 2016 at 9:25:53 AM UTC-7, Tim Wheeler wrote:
>
> Okay - I removed GaussianMixtures and now it is complaining about 
> Compat. 
>
> ERROR: unsatisfiable package requirements detected: no feasible 
> version could be found for package: Compat
>
> I wrote a script to run through all package REQUIRE files and print 
> out the Compat line, if any. None of these found anything specifying an 
> upper-bound.
>
> I would like to find the offending packages. Is there a good way to go 
> about doing this?
>
> Thank you.
>
> ArgParse:  Compat 0.7.3
> ArrayViews:Compat
> AutomotiveDrivingModels:   Compat 0.8
> AxisAlgorithms:Compat 0.8
> BayesNets: Compat
> BinDeps:   Compat 0.8.4
> Blink: Compat 0.8.6
> Blosc: Compat 0.8
> BufferedStreams:   Compat 0.8.4
> Cairo: Compat 0.8.0
> Calculus:  Compat 0.4.0
> Codecs:Compat 0.7.20
> Colors:Compat 0.8.0
> Compose:   Compat 0.8.0
> Conda: Compat 0.8
> ConjugatePriors:   Compat 0.4.0
> Contour:   Compat 0.8.0
> DataArrays:Compat 0.8.6
> DataFrames:Compat 0.8
> Debug: Compat
> Discretizers:  Compat
> Distances: Compat 0.8.4
> Distributions: Compat 0.4.0
> Docile:Compat 0.7.1
> FastAnonymous: Compat
> FileIO:Compat 0.7.19
> FixedPointNumbers: Compat 0.7.14
> FixedSizeArrays:   Compat 0.8.7
> Formatting:Compat
> ForwardDiff:   Compat 0.8.6
> Gadfly:Compat 0.8.5
> Glob:  Compat
> Graphs:Compat 0.7.16
> Gtk:   Compat 0.8.0
> GtkUtilities:  Compat 0.7.16
> GZip:  Compat 0.8.0
> HDF5:  Compat 0.8.0
> Hexagons:  Compat
> Hiccup:Compat 0.8.2
> HttpCommon:Compat 0.7.20
> HttpParser:Compat 0.7.20
> HttpServer:Compat 0.7.16
> IJulia:Compat 0.7.20
> ImageMagick:   Compat 0.7.7
> Images:Compat 0.8.4
> ImageView: 

[julia-users] printf format for round-trip Floats

2016-09-02 Thread David P. Sanders
The simple solutions are often the most elusive! 

[julia-users] printf format for round-trip Floats

2016-09-02 Thread David P. Sanders
Can't you just use string(x) where x is the Float64? 

[julia-users] Re: BigInt / BigFloat / Bitshift

2016-08-10 Thread David P. Sanders


El miércoles, 10 de agosto de 2016, 18:20:11 (UTC-4), digxx escribió:
>
> As far as I understand Julia adjusts the bitsize of an integer when I use 
> BigInt.
> For example n=big(10)^1 is as many bits as needed.
> Now 2*n is still an integer though dividing makes a bigfloat out of it. 
> How big is the bigfloat? does it "resolve" up to the last integer? Does it 
> increase with size like bigint would?
>

When you create a BigFloat, it has the current default precision. You can 
ask Julia this kind of thing directly:

julia> a = big(10)^1;

julia> a / 3
3.63e+

julia> precision(ans)
256

julia> set_bigfloat_precision(1000)
1000

julia> a / 3
3.32e+

julia> precision(ans)
1000

(That was Julia 0.4. In Julia 0.5, use setprecision instead of 
set_bigfloat_precision.)

Please read the manual:

http://docs.julialang.org/en/release-0.4/manual/integers-and-floating-point-numbers/#arbitrary-precision-arithmetic




 

> for example (n/2)^10 is still legid up to the last digit (neglecting the 
> fact that these would be zero in this case anyway)
> When dividing n by an integer and the result is an an integer, how would I 
> achieve this?
> Is there already a simple way?
> For example I could represent n in some basis b and look where the right 
> most digit is zero and then bitshift, but the bitshift I found in the 
> manual mainly << >> .>> etc.. do not work or I'm too stupid
> how am I supposed to use these?
> 3 << ?
>


[julia-users] Anonymous Functions in 0.5 - Performance

2016-08-01 Thread David P. Sanders
Don't do benchmarks in global scope. Wrap everything in a function. 

[julia-users] Re: How to make a variable length tuple with inferred type

2016-07-31 Thread David P. Sanders


El domingo, 31 de julio de 2016, 20:16:04 (UTC-4), Sheehan Olver escribió:
>
> I'm doing the following:
>
>
> immutable FooIterator{d} end
>
> Base.start(::FooIterator{d}) = tuple(zeros(Int,d)...)::NTuple{d,Int}
>


You can use the `ntuple` function, which constructs a tuple from a function:

julia> ntuple( x -> 0, 3)
(0,0,0)

julia> typeof(ans)
Tuple{Int64,Int64,Int64}
 

>
>
> But is there a more elegant way of getting the type inferred?  I suppose I 
> can override low order d directly:
>
> Base.start(::FooIterator{2}) = (0,0)
> Base.start(::FooIterator{3}) = (0,0,0)
>


[julia-users] Re: Tuple type to tuple of types

2016-07-24 Thread David P. Sanders


El domingo, 24 de julio de 2016, 7:52:47 (UTC-4), jw3126 escribió:
>
> I need a function, which accepts an arbitrary tuple type and returns the 
> types of the components of the tuple. For example
> ```
> f(Tuple{Int64, Float64})--> (Int64, Float64)
> f(Tuple{Int64, MyType, Float32}) --> (Int64, MyType, Float32)
> f(NTuple{3})  --> (Any, Any, Any)
> f(Tuple) --> Some error since 
> length is unknown
> ```
>

This information is stored inside the tuple type:

julia> t = Tuple{Int64, Float64}
Tuple{Int64,Float64}

julia> t.parameters
svec(Int64,Float64)

julia> t.parameters[1]
Int64
 

>
> How to accomplish this?
>


[julia-users] Re: JuliaCon schedule announced

2016-07-21 Thread David P. Sanders
Thanks!

El jueves, 21 de julio de 2016, 17:26:09 (UTC+2), Viral Shah escribió:
>
> Both these tutorials are up now. The others seem are there. 
>
> -viral
>
> On Sunday, July 17, 2016 at 1:00:17 AM UTC-4, Tony Kelman wrote:
>>
>> I don't see the tutorial that David Sanders gave, or the one that I gave. 
>> Might be others missing too?
>
>

[julia-users] Re: Fast higher order differentiation

2016-07-17 Thread David P. Sanders
Here is how to use TaylorSeries.jl. In the next version, the syntax 
taylor1_variable will change to just Taylor1:

julia> t = taylor1_variable(40)
 1.0 t + 풪(t⁴¹)

julia> f(x) = sin(exp(x))
f (generic function with 1 method)

julia> f(t)
 0.8414709848078965 + 0.5403023058681398 t - 0.15058433946987837 t² - 
0.4207354924039483 t³ - 0.3229307265911699 t⁴ - 0.13861923299172246 t⁵ - 
0.016963650188307994 t⁶ + 0.027151311649628966 t⁷ + 0.028082409487798127 t⁸ 
+ 0.016534675299332297 t⁹ + 0.006744265666861196 t¹⁰ + 
0.0016199249536140723 t¹¹ - 0.00020257707395350685 t¹² - 
0.0005026787959383626 t¹³ - 0.00034829060136926197 t¹⁴ - 
0.00016780164241401782 t¹⁵ - 6.0803736936094484e-5 t¹⁶ - 
1.4645171902851875e-5 t¹⁷ - 1.1346823483603049e-8 t¹⁸ + 
2.515198118591517e-6 t¹⁹ + 1.817031683619697e-6 t²⁰ + 8.873827219817266e-7 
t²¹ + 3.383697539084375e-7 t²² + 9.90873953752995e-8 t²³ + 
1.7331465080481204e-8 t²⁴ - 2.8377431603022023e-9 t²⁵ - 
4.478125328289587e-9 t²⁶ - 2.633876550034189e-9 t²⁷ - 1.1444925030062194e-9 
t²⁸ - 4.013808037099447e-10 t²⁹ - 1.1102527569232767e-10 t³⁰ - 
1.95623844080032e-11 t³¹ + 1.8017173073914597e-12 t³² + 
3.715400951669623e-12 t³³ + 2.1778749843678503e-12 t³⁴ + 
9.347841028230405e-13 t³⁵ + 3.279923193009391e-13 t³⁶ + 
9.423306246867712e-14 t³⁷ + 1.99707334423e-14 t³⁸ + 
1.3114196619133462e-15 t³⁹ - 1.5394356646368331e-15 t⁴⁰ + 풪(t⁴¹)

julia> get_coeff(f(t), 40)
-1.5394356646368331e-15

Note that this coefficient is the 40th derivative divided by 40!.  (The nth 
Taylor coefficient is f^{(n)} / n!. )



El domingo, 17 de julio de 2016, 21:15:33 (UTC+2), David P. Sanders 
escribió:
>
>
>
> El domingo, 17 de julio de 2016, 17:13:38 (UTC+2), Young Chun escribió:
>>
>> I have an optimization problem that involves series of high order 
>> derivatives of f(x). 
>> So, to get a decent value, I need to calculate higher order derivative at 
>> least to 40~50th order. 
>>
>
> I suggest you use TaylorSeries.jl.
>
> Note that ForwardDiff from version 0.2 removed ForwardDiff.derivative(f); 
> this must now be written as the anonymous function x -> 
> ForwardDiff.derivative(f, x).
>  
>
>>
>> Initially, I tried to use ForwardDiff package with automatic 
>> differentiation but kept facing the following error message
>>
>> using 
>> DualNumbers using ForwardDiff f(x::Vector) = sum(sin, x) + prod(tan, x) * 
>> sum(sqrt, x); x = rand(5) g = ForwardDiff.derivative(f);
>>
>> using DualNumbers
>>
>> using ForwardDiff
>>
>> f(x::Vector) = sum(sin, x) + prod(tan, x) * sum(sqrt, x);
>>
>> x = rand(5)
>>
>> g = ForwardDiff.derivative(f);
>>
>> LoadError: MethodError: `derivative` has no method matching 
>> derivative(::Function)
>> Closest candidates are:
>>   derivative(::Any, !Matched::Any)
>> while loading In[28], in expression starting on line 4
>>
>>
>>
>> So, I moved on to D(f) instead from Root package and it works quite well 
>> for a small order (like 10th order derivative)
>>
>> using 
>> DualNumbers using ForwardDiff using Roots using ForwardDiff using JuMP # 
>> Need to say it whenever we use JuMP using Gadfly function hder(f, n::Real) 
>> # subroutine to calculate higher order derivative temp = f; if n==0 return 
>> temp else for i=1:1:n temp = D(temp) end return temp end end
>>
>> using DualNumbers
>>
>> using ForwardDiff
>>
>> using Roots
>>
>> using ForwardDiff
>>
>> ​
>>
>> using JuMP  
>>
>> using Gadfly
>>
>> ​
>>
>> function hder(f, n::Real) # subroutine to calculate n-th order derivative 
>>
>> temp = f;
>>
>> if n==0
>>
>> return temp 
>>
>> else
>>
>> for i=1:1:n
>>
>> temp = D(temp)
>>
>> end
>>
>> return temp
>>
>> end
>>
>> end
>>
>> Out[7]:
>>
>> hder (generic function with 1 method)
>>
>> f(x) = (cos(x)) * exp(-1/5 * x)
>> g0 = hder(f, 0)
>> g1 = hder(f, 1)
>> g2 = hder(f, 2)
>> g3 = hder(f, 3)
>> g4 = hder(f, 4)
>> g5 = hder(f, 5)
>> g6 = hder(f, 6)
>> g7 = hder(f, 7)
>> g8 = hder(f, 8)
>>
>> plot([g0, g1, g2, g3, g4, g5, g6, g7, g8], 0, 5pi)
>>
>>
>> <https://lh3.googleusercontent.com/-RCrcnLVFPhE/V4tfcG9uSEI/GUU/unxjN7x60jgPaEcCmcRlykx8WpbMxJBnACLcB/s1600/Screen%2BShot%2B2016-07-17%2Bat%2B11.35.09.png>
>> However, if I push the limit and ask to calculate, like 30th order 
>> derivative, the program never ends and keep calculating for hours.
>> Is there a better way to do this type of task? either by using 
>> ForwardDiff package or by modifying my function?
>> I just learned Julia last week, so please understand if my question 
>> sounds stupid. 
>>
>>
>>
>>

[julia-users] Re: Fast higher order differentiation

2016-07-17 Thread David P. Sanders


El domingo, 17 de julio de 2016, 17:13:38 (UTC+2), Young Chun escribió:
>
> I have an optimization problem that involves series of high order 
> derivatives of f(x). 
> So, to get a decent value, I need to calculate higher order derivative at 
> least to 40~50th order. 
>

I suggest you use TaylorSeries.jl.

Note that ForwardDiff from version 0.2 removed ForwardDiff.derivative(f); 
this must now be written as the anonymous function x -> 
ForwardDiff.derivative(f, x).
 

>
> Initially, I tried to use ForwardDiff package with automatic 
> differentiation but kept facing the following error message
>
> using 
> DualNumbers using ForwardDiff f(x::Vector) = sum(sin, x) + prod(tan, x) * 
> sum(sqrt, x); x = rand(5) g = ForwardDiff.derivative(f);
>
> using DualNumbers
>
> using ForwardDiff
>
> f(x::Vector) = sum(sin, x) + prod(tan, x) * sum(sqrt, x);
>
> x = rand(5)
>
> g = ForwardDiff.derivative(f);
>
> LoadError: MethodError: `derivative` has no method matching 
> derivative(::Function)
> Closest candidates are:
>   derivative(::Any, !Matched::Any)
> while loading In[28], in expression starting on line 4
>
>
>
> So, I moved on to D(f) instead from Root package and it works quite well 
> for a small order (like 10th order derivative)
>
> using 
> DualNumbers using ForwardDiff using Roots using ForwardDiff using JuMP # 
> Need to say it whenever we use JuMP using Gadfly function hder(f, n::Real) 
> # subroutine to calculate higher order derivative temp = f; if n==0 return 
> temp else for i=1:1:n temp = D(temp) end return temp end end
>
> using DualNumbers
>
> using ForwardDiff
>
> using Roots
>
> using ForwardDiff
>
> ​
>
> using JuMP  
>
> using Gadfly
>
> ​
>
> function hder(f, n::Real) # subroutine to calculate n-th order derivative 
>
> temp = f;
>
> if n==0
>
> return temp 
>
> else
>
> for i=1:1:n
>
> temp = D(temp)
>
> end
>
> return temp
>
> end
>
> end
>
> Out[7]:
>
> hder (generic function with 1 method)
>
> f(x) = (cos(x)) * exp(-1/5 * x)
> g0 = hder(f, 0)
> g1 = hder(f, 1)
> g2 = hder(f, 2)
> g3 = hder(f, 3)
> g4 = hder(f, 4)
> g5 = hder(f, 5)
> g6 = hder(f, 6)
> g7 = hder(f, 7)
> g8 = hder(f, 8)
>
> plot([g0, g1, g2, g3, g4, g5, g6, g7, g8], 0, 5pi)
>
>
> 
> However, if I push the limit and ask to calculate, like 30th order 
> derivative, the program never ends and keep calculating for hours.
> Is there a better way to do this type of task? either by using ForwardDiff 
> package or by modifying my function?
> I just learned Julia last week, so please understand if my question sounds 
> stupid. 
>
>
>
>

[julia-users] Re: Suddenly PyPlot giving me grief

2016-07-12 Thread David P. Sanders
As a quick solution, I would suggest deleting or renaming ~/.julia/v0.4 and 
reinstalling all the packages.


El martes, 12 de julio de 2016, 8:11:53 (UTC-4), Ed Scheinerman escribió:
>
> I've suddenly been having a great deal of trouble with PyPlot on Julia 
> 0.4.6 on Mac. 
>
> Here's one sort of problem I've gotten:
>
> julia> plot([1,2],[1,3])
>
> ERROR: ArgumentError: haskey of NULL PyObject
>
>  in haskey at /Users/ers/.julia/v0.4/PyCall/src/PyCall.jl:292
>
>  in plot at /Users/ers/.julia/v0.4/PyPlot/src/PyPlot.jl:381
>
>
> I tried reinstalling PyPlot, PyCall, Conda and I get this:
>
>
> julia> using PyPlot
>
> objc[75453]: Class TKApplication is implemented in both 
> /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and 
> /Users/ers/.julia/v0.4/Conda/deps/usr/lib/libtk8.5.dylib. One of the two 
> will be used. Which one is undefined.
>
> objc[75453]: Class TKMenu is implemented in both 
> /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and 
> /Users/ers/.julia/v0.4/Conda/deps/usr/lib/libtk8.5.dylib. One of the two 
> will be used. Which one is undefined.
>
> objc[75453]: Class TKContentView is implemented in both 
> /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and 
> /Users/ers/.julia/v0.4/Conda/deps/usr/lib/libtk8.5.dylib. One of the two 
> will be used. Which one is undefined.
>
> objc[75453]: Class TKWindow is implemented in both 
> /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk and 
> /Users/ers/.julia/v0.4/Conda/deps/usr/lib/libtk8.5.dylib. One of the two 
> will be used. Which one is undefined.
>
> /Users/ers/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/font_manager.py:273:
>  
> UserWarning: Matplotlib is building the font cache using fc-list. This may 
> take a moment.
>
>   warnings.warn('Matplotlib is building the font cache using fc-list. This 
> may take a moment.')
>
>
> julia> plot([1,2],[1,3])
>
> Exception in Tkinter callback
>
> Traceback (most recent call last):
>
>   File 
> "/Users/ers/.julia/v0.4/Conda/deps/usr/lib/python2.7/lib-tk/Tkinter.py", 
> line 1537, in __call__
>
> return self.func(*args)
>
>   File 
> "/Users/ers/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py",
>  
> line 283, in resize
>
> self.show()
>
>   File 
> "/Users/ers/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py",
>  
> line 355, in draw
>
> tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
>
>   File 
> "/Users/ers/.julia/v0.4/Conda/deps/usr/lib/python2.7/site-packages/matplotlib/backends/tkagg.py",
>  
> line 30, in blit
>
> id(data), colormode, id(bbox_array))
>
> TclError
>
> julia(75453,0x7fff7ce8a000) malloc: *** error for object 0x7ff91bd574d0: 
> pointer being freed was not allocated
>
> *** set a breakpoint in malloc_error_break to debug
>
>
> signal (6): Abort trap: 6
>
> __pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
>
> Abort trap: 6
>
>
> I can't plot anything now. 
>
>
> Help! 
>
>
> Thanks.
>


[julia-users] Docs unavailable?

2016-07-11 Thread David P. Sanders
Seems to be working now. 

[julia-users] Recover lost script from active command line session

2016-07-11 Thread David P. Sanders
Type ctrl-R in the repl and start to type include. This will give you the last 
command by that name that you typed and will show you which file you included. 
You can do pwd()  to show which directory you are working in. 

[julia-users] Re: how to hide deprecated warning ?

2016-06-30 Thread David P. Sanders


El jueves, 30 de junio de 2016, 10:20:49 (UTC-4), Henri Girard escribió:
>
> I am not a developper, I can't help to correct 
> these warning (unfortunatly) but that's 
> quiet annoying if one wants to make a clean
> worksheet, this one is not too big but 
> sometimes it's half a page !
>
>
> using ODE,Plots
> pyplot(size=(300,200),leg=false,
> guidefont=font(7), titlefont=font(7));
> function oscillator(t, y)
> y[2] = - 3* + y[1] - y[2] / 10
> end
> oscillator(t, y) = [y[2], - 3* + y[1] - y[2] / 10]
> initial = [1.0,0.0];   # Initial conditions
> t = float([0:0.01:50]);   
>
>
Replace this with
t = 0:0.01:50

You do not need to convert this to an array.

Rather than ignoring the deprecation warnings, you should follow the 
instructions they give to update 
your code to use the latest Julia syntax.

 

> t,y = ode23(oscillator, initial, t)
> y=hcat(y...).';
>
> WARNING: [a] concatenation is deprecated; use collect(a) instead
>  in depwarn at ./deprecated.jl:73
> while loading In[2], in expression starting on line 9
>
>

[julia-users] Speeding up Matrix .^ transpose(Vector)

2016-06-30 Thread David P. Sanders
Have you tried rewriting with explicit loops? 

[julia-users] Re: JuliaCon schedule announced

2016-06-25 Thread David P. Sanders


El viernes, 24 de junio de 2016, 13:44:32 (UTC-4), Alex Coventry escribió:
>
> I would like to attend the hackathon tomorrow (Sat Jun 25.)  I'd be 
> grateful for a pointer to where / when it's going to be.
>

It will be at the Stata Center at MIT -- see http://juliacon.org/#location

starting at 8:45am, I believe.



 

>
> Best,
> Alex
>
> On Thursday, June 9, 2016 at 5:34:18 PM UTC-4, Viral Shah wrote:
>>
>> The JuliaCon talks and workshop schedule has now been announced.
>>
>> http://juliacon.org/schedule.html
>>
>> Please buy your tickets if you have been procrastinating. We have seen 
>> tickets going much faster this year, and waiting until the day before is 
>> unlikely to work this year. Please also spread the message to your friends 
>> and colleagues and relevant mailing lists. Here's the conference poster for 
>> emailing and printing:
>>
>> http://juliacon.org/pdf/juliacon2016poster3.pdf
>>
>> -viral
>>
>

Re: [julia-users] Re: PyPlot: LineCollection help needed

2016-06-14 Thread David P. Sanders
Great stuff, Tom! 

[julia-users] Re: PyPlot: LineCollection help needed

2016-06-11 Thread David P. Sanders
After looking at some matplotlib examples, it seems that the data structure 
needed by LineCollection in Python
is a list of lists, with the inner lists being lists of (x,y) pairs. 

After playing around for a while, the following works for me
for drawing a pair of lines in Julia:
xs = [1., 3., 5., 0.]
ys = [2., 4., .06, 0.]
lines = Any[collect(zip(xs, ys))]

xs = [3., 4]
ys = [5., 6]
push!(lines, collect(zip(xs, ys)))
#lines = Vector{Float64}[[1.0, 2.0], [3.0 4.0], 5.0 .06]];Any[[0.0 0.0]]] # 
Points
#c = Any[Any[1 0 0];Any[0 1 0];Any[0 0 1]] # Color
c = Vector{Int}[[1,0,0], [0,1,0], [0,0,1]]

line_segments = matplotlib[:collections][:LineCollection](lines, colors=c)

fig = figure("Line Collection Example")
ax = gca()
ax[:add_collection](line_segments)
axis("image")


El viernes, 10 de junio de 2016, 10:29:25 (UTC-4), NotSoRecentConvert 
escribió:
>
> I'm trying to do a plot using LineCollection in PyPlot however am having a 
> hard time converting an example (1 
>  or 2 
> ).
>
> lines = Any[Any[[1.0 2.0]];Any[[3.0 4.0]];Any[[5.0 .06]];Any[[0.0 0.0]]] # 
> Points
> c = Any[Any[1 0 0];Any[0 1 0];Any[0 0 1]] # Color
>
> line_segments = matplotlib[:collections][:LineCollection](lines,colors=c)
>
> fig = figure("Line Collection Example")
> ax = axes()
> ax[:add_collection](line_segments)
> axis("tight")
>
> It doesn't return an errors but I don't see any lines. Any idea what could 
> be wrong?
>


[julia-users] PyPlot: LineCollection help needed

2016-06-10 Thread David P. Sanders
Does it work with ax=gca() instead? 

[julia-users] Re: How to get the particular value from the table

2016-06-07 Thread David P. Sanders


El martes, 7 de junio de 2016, 11:57:16 (UTC-4), tann...@gmail.com escribió:
>
> Hello,
>
> If I have this kind of table attached here. How can I access the 
> particular value to use in problem after importing in the julia. Thank you 
>


How do you import the data into Julia? 


[julia-users] Re: given two strings, find the index of the first nonmatching character

2016-06-06 Thread David P. Sanders
Wrapped in a function, obviously.

El lunes, 6 de junio de 2016, 19:41:10 (UTC-4), David P. Sanders escribió:
>
>
>
> El lunes, 6 de junio de 2016, 18:53:46 (UTC-4), Jeffrey Sarnoff escribió:
>>
>> ```
>> indexOfFirstNonmatching("abcd","abcd") == 0 
>> indexOfFirstNonmatching("abcd","abdc") == 3
>> ```
>> what is a fast way to do this with strings of 50-1000 characters?
>>
>
> How about 
>
> s1 = "abcd"
> s2 = "abdc"
>
>  for (i, (c, d)) in enumerate(zip(s1, s2))
>c != d && return i
>  end 
>


[julia-users] Re: given two strings, find the index of the first nonmatching character

2016-06-06 Thread David P. Sanders


El lunes, 6 de junio de 2016, 18:53:46 (UTC-4), Jeffrey Sarnoff escribió:
>
> ```
> indexOfFirstNonmatching("abcd","abcd") == 0 
> indexOfFirstNonmatching("abcd","abdc") == 3
> ```
> what is a fast way to do this with strings of 50-1000 characters?
>

How about 

s1 = "abcd"
s2 = "abdc"

 for (i, (c, d)) in enumerate(zip(s1, s2))
   c != d && return i
 end 


[julia-users] Re: Help creating user-defined types and constructors

2016-06-04 Thread David P. Sanders


El sábado, 4 de junio de 2016, 18:18:00 (UTC-4), Christopher Fisher 
escribió:
>
> Ok. I didn't anticipate this would be a drawn out process.  I just Ford's 
> suggestion fixed the issue of changing values but recreated the problem of 
> accessing an individual's information like so:  population[2] . 
> population[:,2] did not work either. I tried other changes to the syntax 
> but to no avail. It fails at the last line.  Any ideas would be 
> appreciated. 
>
> type Person
> infected::Bool
> vaccinated::Bool
> dead::Bool
> history::Vector{Int}
> end
>
> type Population <: AbstractArray
> individuals::Vector{Person}
> 
> end
>
>
> Population() = Population(Person[])
> Base.push!(p::Population, x::Person) = push!(p.individuals, x)
>
>
> function Base.getindex(pop::Population, field::Symbol)
> [getfield(x, field) for x in pop.individuals]
> end
>
> setindex!(p::Population, value, field::Symbol, index...) = 
> p.individuals[index...].(field) = value
> getindex(p::Population, field::Symbol, index...) = 
> p.individuals[index...].(field)
>
> Base.show(io::IO, p::Person) = print(io, "Person(infected=", p.infected, 
> ", vaccinated=", p.vaccinated, ", dead=", p.dead, ", history=", p.history)
>
>
> population = Population()
> push!(population, Person(true, false, true, [3,4,5]))
> push!(population, Person(false, true, false, Int64[3,4,5]))
>
> #Show that it works
> population[:infected]
> population[:infected,1]
> population[2]
>

The syntax `population[x]` calls  `getindex(population, x)`.
You are using two different *types* of object x here: integers and symbols.
If you really want to do this, you would thus need to define both

getindex(p::Population, n::Integer)

to return the nth individual,

and

getindex(p::Population, s::Symbol)

to return the list of those with status s.

However, this does not seem like a very good idea to me.

What it sounds like you want to do is something like "find the first 
healthy individual and infect it".
For this, you are better off writing a function called something like 
infect!(p::Population)
which will choose an individual to infect. 

If you are planning to make this into an individual-based simulator, then 
you probably want to go back
to just thinking of a vector of individuals, and maintain separately a list 
of those which are currently infected for example.
Even though this will be extra book-keeping when an individual becomes 
infected or stops being infected, it will almost certainly
be much faster. 

I suggest you try fleshing out your model a bit just thinking of functions 
that operate on the population as I have suggested.

 

>
> LoadError: MethodError: `size` has no method matching size(::Population)
> Closest candidates are:
>   size(::Any, !Matched::Integer, !Matched::Integer, !Matched::Integer...)
> while loading In[1], in expression starting on line 36
>
>  in getindex at abstractarray.jl:488
>
>
>
> On Saturday, June 4, 2016 at 3:11:18 PM UTC-4, Ford O. wrote:
>>
>> I would like to discourage you from passing symbols as an array index but 
>> I guess you gonna do it anyway...
>>
>>
>> So if you really want it, here it is:
>> setindex!(p::Population, value, field::Symbol, index...) = p.individuals[
>> index...].(field) = value
>> getindex(p::Population, field::Symbol, index...) = p.individuals[index
>> ...].(field)
>>
>> Usage
>> population[:infected, 1]
>> population[:infected, 1] = false
>>
>>
>>
>>
>> On Saturday, June 4, 2016 at 2:19:02 PM UTC+2, Christopher Fisher wrote:
>>>
>>> I was wondering if someone would be willing to help me with creating 
>>> user-defined types. I've been using Julia for about two years now but I am 
>>> new to the idea of creating custom types. I'm trying to create a population 
>>> of agents/individuals in a simple epidemiological simulation. I would like 
>>> the population of individuals to be structured as a  2 dimensional array 
>>> with rows as individuals and columns as properties. This would be somewhat 
>>> similar to a DataFrame, but potentially more flexible. I want to be able to 
>>> index an individual like so: population[1]. This woud list all of the 
>>> information for individual 1.  I would also like to be able to look at an 
>>> attribute across individuals: population.infected or population[:infected]. 
>>> At the same time, I would like to have to flexibility of using an array to 
>>> keep track of individuals: typeof(population.history[1]) is Array{Int64,1}. 
>>> Based on existing documentation and examples, I have only been able to 
>>> create individuals but cannot figure out how to create a population as 
>>> described above:
>>>
>>> type Person
>>> infected::Int64
>>> vaccinated::Int64
>>> dead::Int64
>>>history::Array{Int64,1}
>>> end
>>>
>>> Any help would be greatly appreciated. 
>>>
>>

[julia-users] Re: ANN: PkgSearch - a REPL utility for package discovery

2016-06-04 Thread David P. Sanders


El viernes, 3 de junio de 2016, 16:40:50 (UTC-4), Adrian Salceanu escribió:
>
> Hi, 
>
> I have released PkgSearch, a small REPL utility for package discovery. 
>
>
Very nice work!
 

> Package discovery seemed to be a recurring issue, with many related 
> questions - and I can still remember how difficult was for me too, when I 
> started. So it might be a useful tool. 
> I've been using it for a few days and it's kind of neat, being able to 
> quickly search through all the publicly available packages without leaving 
> the REPL :) I hope you'll enjoy it! 
>
> It works in conjunction with an API which powers the actual search. On the 
> server side, a full text search is performed against the README files. It 
> covers both official packages and unofficial ones, searching for them on 
> GitHub (not in real time, the data is imported regularly). This GitHub 
> search is a bit naive still, so false positives might come up. 
>
> More details in the README, at https://github.com/essenciary/PkgSearch
>
> ===
>
> On a related note, the API providing the search results and all the 
> tooling for importing and processing the data is done with Genie (formerly 
> Jinnie) - the Julia web framework I've been working on for many months now. 
> It's not ready for prime time yet but this is definitely a major milestone! 
>
> With this occasion I've also added a very comprehensive README to give you 
> an idea about what it does, how it works and where it's heading. 
>
> You can find it here https://github.com/essenciary/genie - and if you 
> like it, please star it :) 
>
> Cheers,
> Adrian
>


[julia-users] Re: Help creating user-defined types and constructors

2016-06-04 Thread David P. Sanders

You can define a `Population` type and overload `getindex` for it to do 
what you want, something like:

type Person
infected::Bool
vaccinated::Bool
dead::Bool
history::Vector{Int}
end

type Population <: AbstractArray
individuals::Vector{Person}
end


Population() = Population(Person[])
Base.push!(p::Population, x::Person) = push!(p.individuals, x)
length(p::Population) = length(p.individuals)
size(p::Population) = size(p.individuals)

function Base.getindex(pop::Population, field::Symbol)
[getfield(x, field) for x in pop.individuals]
end

population = Population()
push!(population, Person(true, false, true, [3,4,5]))
push!(population, Person(false, true, false, Int64[3,4,5]))

population[:infected]


Note that this is not very efficient; I believe the following package may 
be an alternative / better solution:

 https://github.com/simonster/StructsOfArrays.jl



El sábado, 4 de junio de 2016, 11:13:21 (UTC-4), Christopher Fisher 
escribió:
>
> Thanks for your suggestions Steven. You are correct. I could many of those 
> fields as Boolean and maybe there is a reason to prefer that rather than 
> using 1 and 0s. 
>
> Initially, I also tried to push the individuals into an empty array as you 
> suggested. This worked well, except I was not able to query across 
> individuals:
>
> type Person
> infected::Int64
> vaccinated::Int64
> dead::Int64
>history::Array{Int64,1}
> end
> population = Person[]   # create an empty population
> push!(population, Person(0, 2, 0, Int64[3,4,5]))   # add a person to the 
> population
> push!(population, Person(0, 2, 0, Int64[3,4,5]))
> population.infected
>
> LoadError: type Array has no field infected
> while loading In[16], in expression starting on line 10
>
>
>
> What I was hoping is that it would list the infection status for all 
> members of the population. Is there any way to do that?
>
>
> On Saturday, June 4, 2016 at 10:47:55 AM UTC-4, Steven G. Johnson wrote:
>>
>>
>>
>> On Saturday, June 4, 2016 at 8:19:02 AM UTC-4, Christopher Fisher wrote:
>>>
>>> I was wondering if someone would be willing to help me with creating 
>>> user-defined types. I've been using Julia for about two years now but I am 
>>> new to the idea of creating custom types. I'm trying to create a population 
>>> of agents/individuals in a simple epidemiological simulation. I would like 
>>> the population of individuals to be structured as a  2 dimensional array 
>>> with rows as individuals and columns as properties. This would be somewhat 
>>> similar to a DataFrame, but potentially more flexible. I want to be able to 
>>> index an individual like so: population[1]. This woud list all of the 
>>> information for individual 1.  I would also like to be able to look at an 
>>> attribute across individuals: population.infected or population[:infected]. 
>>> At the same time, I would like to have to flexibility of using an array to 
>>> keep track of individuals: typeof(population.history[1]) is Array{Int64,1}. 
>>> Based on existing documentation and examples, I have only been able to 
>>> create individuals but cannot figure out how to create a population as 
>>> described above:
>>>
>>> type Person
>>> infected::Int64
>>> vaccinated::Int64
>>> dead::Int64
>>>history::Array{Int64,1}
>>> end
>>>
>>
>> It sounds like you just want an array of your Person type.
>>
>> e.g.
>>
>> population = Person[]   # create an empty population
>> push!(population, Person(0, 2, 0, Int64[3,4,5]))   # add a person to the 
>> population
>> population[1].dead # access the "dead" field of the first person in the 
>> population
>> population[1].history[3]  # access history[3] from person 1
>>
>> Of course, you can make working with the Person type a lot nicer by 
>> defining more methods.   e.g. you probably want to have a "show" method to 
>> pretty-print a person, for example:
>>
>> Base.show(io::IO, p::Person) = print(io, "Person(infected=", p.infected, 
>> ", vaccinated=", p.vaccinated, ", dead=", p.dead, ", history=", p.history)
>>
>> When designing your types, you also want to think carefully about your 
>> fields.   e.g. aren't infected, dead, etc. really Boolean fields?  If you 
>> can encode "history" into a fixed-width field (e.g. a single 64-bit 
>> integer), it will be much more efficient.  And arrays of persons will be 
>> more efficient if you can make the person immutable --- you only need a 
>> (mutable) type if you need to have multiple references to the same 
>> individual, where modifying one reference's fields will change the data 
>> seen from all the references.
>>
>

[julia-users] Re: parametrized type with inner constructor fails

2016-06-03 Thread David P. Sanders


El viernes, 3 de junio de 2016, 22:06:20 (UTC-4), xdavidliu escribió:
>
> with
>
>
> type foo
> x::Int
> foo(x) = x > 0 ? new(x) : new(-x)
> end
>
>
> type bar{T<:Integer}
> x::T
> end
>
>
> type baz{T<:Integer}
> x::T
> baz(x) = x > 0 ? new(x) : new(-x)
> end
>
>
>
> "foo(-5).x" gives 5, "bar(-5).x" gives -5, but "baz(-5).x" gives a 
> "MethodError: 'convert' has no method matching..." error. 
>
> It seems the relevant section in the manual is this 
> ,
>  
> but I only have a single field (as opposed to the examples in the link in 
> which there are almost always two or more fields), so there should be no 
> type disagreement or ambiguity here. Is this intended behavior?
>

This is rather subtle.
The inner constructor defines *only* the parametrised constructor:

julia> type baz{T<:Integer}
  x::T
  baz(x) = x > zero(x) ? new(x) : new(-x)
  end

julia> methods(baz)
2-element Array{Any,1}:
 call{T}(::Type{T}, arg) at essentials.jl:56
 call{T}(::Type{T}, args...) at essentials.jl:57

julia> baz{Int}(-5)
baz{Int64}(5)

If you want to use a non-parametrized constructor like baz(-5), you need to 
explicitly define it:

julia> baz{T}(x::T) = baz{T}(x)

Note that on the left, this means "for each T, define a function baz(x) for 
x of that type"; on the right it tells you to call the parametric 
constructor with *that particular* type T:

julia> baz(-5)
baz{Int64}(5)
 


[julia-users] Re: random number generation

2016-06-01 Thread David P. Sanders


El miércoles, 1 de junio de 2016, 14:24:01 (UTC-4), Michela Di Lullo 
escribió:
>
> How can I do to generate 6 *different* integer random numbers between 1 
> and 14?
>

This is known as "sampling without replacement" and is implemented in 
StatsBase.jl; documentation here:

http://statsbasejl.readthedocs.io/en/latest/sampling.html

Code:

julia> using StatsBase

julia> sample(1:14, 6, replace=false)
6-element Array{Int64,1}:
 10
  1
  8
  5
  6
 13



[julia-users] Re: Why these 2 functions generate very different llvm?

2016-05-30 Thread David P. Sanders


El lunes, 30 de mayo de 2016, 19:11:47 (UTC-4), FANG Colin escribió:
>
> function t1(n::Int, x::Int, a::Float64)
>x::Float64 = x
>for i in 1:n
> x += a
>end
> x
> end
> @time t1(10^6, 1, 1.0)
>
> 0.005445 seconds (1.00 M allocations: 15.259 MB)
>

In t1, x changes type during the function, from Int to Float64, so the 
function is type *un*stable, as shown by @code_warntype,
and as suggested by the huge number of allocations.

In t2, x is always a Float64, and the function is type stable.
 

>
>
>
>
> function t2(n::Int, y::Int, a::Float64)
>x::Float64 = y
>for i in 1:n
> x += a
>end
> x
> end
> @time t2(10^6, 1, 1.0)
>
> 0.001044 seconds (6 allocations: 192 bytes)
>
>
>
>
> The @code_warntype of the 2 functions are very similar. However, the llvm 
> code generated from t2 is a lot simpler.
>

The @code_warntype of the two functions is very *different*. (This is 
easier to see in the REPL than in the notebook, if
that is the problem.)
 

>
> Does it suggest that if we want to change the type of an argument, we'd 
> better create a new variable?
>


[julia-users] Re: frame

2016-05-20 Thread David P. Sanders


El viernes, 20 de mayo de 2016, 20:12:22 (UTC+1), Henri Girard escribió:
>
> Hi, 
> I would like to make a frame in julia pyplot graphic 2D
> I tried set_frame_on but nothing display idem for border=:on
> Is there a command ?
>

What is a frame? What is the matplotlib command for this?
For PyPlot.jl, you need to use the Python matplotlib documentation and then 
"translate" this across to Julia notation.
 

> Regards
> Henri
>


[julia-users] Re: Base.show(io::IO, mytype::Type) results in cluttered display for arrays

2016-05-16 Thread David P. Sanders


El lunes, 16 de mayo de 2016, 5:10:56 (UTC-4), Anonymous escribió:
>
> Wow strange, I could have sworn I tried that and it didn't do anything, 
> but now it works, thanks.
>

This could be to do with some effect of caching of previously-defined 
methods; restarting Julia would get rid of these.

 

>
> On Monday, May 16, 2016 at 1:40:06 AM UTC-7, David P. Sanders wrote:
>>
>> Change the print statement to print(io, "..."). io is the object of type 
>> IO that you need to print to. 
>
>

[julia-users] Base.show(io::IO, mytype::Type) results in cluttered display for arrays

2016-05-16 Thread David P. Sanders
Change the print statement to print(io, "..."). io is the object of type IO 
that you need to print to. 

[julia-users] Re: Julia large project example.

2016-05-12 Thread David P. Sanders
In this example you can easily create another, distinct, object of the same 
type with a2=Apple(). 

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

2016-04-29 Thread David P. Sanders


El jueves, 28 de abril de 2016, 16:09:54 (UTC-4), Mosè Giordano escribió:
>
> Hi David, 
>
> 2016-04-28 14:10 GMT+02:00 David P. Sanders <dpsa...@gmail.com 
> >: 
> > As far as I could see, the original library has an Apache license, so 
> you should be able to use MIT. 
> > 
> > I believe that you need to include a copy of the original license in 
> your package? 
>
> Original code is dual-licensed, in that case the author of derived 
> work can choose one of the two licenses or both.[1]  I went for LGPL, 
> that is weakly protective 


What is being protected, your own work? 

but perfectly compatible with MIT "Expat" 
>

No, it is only half compatible with MIT, i.e. only in one direction: you 
can take code
from my MIT-licensed package (e.g. ValidatedNumerics) and use it in yours, 
but I *cannot*
take a piece of code from your package, modify it, and re-use it in mine,
without "infecting" my package with the LGPL code, which will automatically 
mean that 
I will have to change my license to LGPL. 

(This is all only my understanding. Please do correct me if I am wrong.)

 

> license, which is the most common in Julia ecosystem, so that most of 
> Julia package can use this package.  


Again, they can only *use* it.
I cannot even *look* at your code (which I would very much like to do),
since if I find something useful, I can't reuse it in my (MIT) package.

 

> For the time being I don't plan 
> to change the license. 
>

I would urge you to reconsider that. You could, for example, license it 
with the same dual license as in the original package -- otherwise, you 
are actually restricting your users more than the original package does 
(for the reasons I discussed above). 

The end result otherwise will be that someone
who needs to use the functionality will end up going back to the original 
Fortran code
and rewriting what you have already done (which I certainly do not want to 
do), 
or using less-good code from somewhere else.
 

>
> > +1 for ComplexRoots.jl 


Steven makes a good point that PolynomialRoots.jl would be a better name.

 


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

2016-04-28 Thread David P. Sanders
As far as I could see, the original library has an Apache license, so you 
should be able to use MIT. 

I believe that you need to include a copy of the original license in your 
package? 

+1 for ComplexRoots.jl

Re: [julia-users] Re: automatic export of all enum values

2016-04-26 Thread David P. Sanders
Thanks. Tricky! 


Re: [julia-users] In these two ways to "create functions", which one is a better way?

2016-04-20 Thread David P. Sanders
If this is your actual use case, then I suggest checking out the Polynomials.jl 
package. 

In particular, there is a more efficient algorithm (Horner's algorithm) that 
you can use to actually evaluate such a function. 

[julia-users] Rounding to zero from positive or negative numbers results in positive or negative zero.

2016-04-20 Thread David P. Sanders
You can avoid the problem using

round(Int, x) 

Which returns the result as an integer. Integers do not have this situation 
(difference between +0.0 and -0.0)

Re: [julia-users] How to apply an array of functions to an array of values?

2016-02-22 Thread David P. Sanders

An alternative is a comprehension:

[f(x) for (f,x) in zip(funs, vals)]



El lunes, 22 de febrero de 2016, 16:29:21 (UTC-5), Stefan Karpinski 
escribió:
>
> Using a lambda works:
>
> julia> funs = [sin,cos,tan]
> 3-element Array{Function,1}:
>  sin
>  cos
>  tan
>
> julia> vals = rand(3)
> 3-element Array{Float64,1}:
>  0.889165
>  0.64722
>  0.997409
>
> julia> map((f,x)->f(x), funs, vals)
> 3-element Array{Float64,1}:
>  0.776546
>  0.797763
>  1.54857
>
>
> On Mon, Feb 22, 2016 at 4:22 PM, Erik Schnetter  > wrote:
>
>> I have an array of functions (`funs`) and an array of values (`vals`).
>> I want to apply the former to the latter, element-wise. When I write
>>
>> ```Julia
>> map(call, funs, vals)
>> ```
>> Julia replies with
>> ```
>> WARNING: call(f,args...) is deprecated, use f(args...) instead.
>> ```
>>
>> What is the correct syntax to use?
>>
>> -erik
>>
>> --
>> Erik Schnetter 
>> http://www.perimeterinstitute.ca/personal/eschnetter/
>>
>
>

[julia-users] Re: Json and enums

2016-02-21 Thread David P. Sanders


El domingo, 21 de febrero de 2016, 9:35:54 (UTC-5), Eric Forgy escribió:
>
> julia> @enum Test T1 T2 T3
>
> julia> JSON.json(T1)
> "{}"
>
> How can I get this to print "\"T1\""?
>
> I've been experimenting with "show" and "print", but can't seem to get it 
> to work.
>
> Thanks for any help.
>
> PS: I already filed an issue 
>  (that references this 
> post), but think this is a more basic Julia question so asking here too.
>


You can do it by just defining a new method of the `JSON.json` function. 
I've put my answer in the issue. 


[julia-users] Re: recommended graphics packages for multiple curves on a single canvas

2016-02-01 Thread David P. Sanders

With PyPlot it should be as simple as

using PyPlot

x = 0:0.01:1
plot(x, sin(x))
plot(x, cos(x))

Does this not work?


El domingo, 31 de enero de 2016, 21:53:30 (UTC-6), Michael Landis escribió:
>
> Can anyone recommend a graphics capable of plotting multiple curves on a 
> single canvas.  Python's pyplot/matplotlib multi-curve capabilities appear 
> to be unavailable within Julia (maybe I'm doing it wrong).
>


Re: [julia-users] How to construct without push! vector of vectors?

2016-01-05 Thread David P. Sanders


El martes, 5 de enero de 2016, 15:08:28 (UTC-6), Jamie Brandon escribió:
>
> julia> Vector[[1,2], [3, 4]] 
> 2-element Array{Array{T,1},1}: 
>  [1,2] 
>  [3,4] 
>
> julia> [[1,2] [3,4]] 
> 2x2 Array{Int64,2}: 
>  1  3 
>  2  4 
>
> julia> [[1,2], [3,4]] 
> WARNING: [a,b] concatenation is deprecated; use [a;b] instead 
>  in depwarn at deprecated.jl:73 
>  in oldstyle_vcat_warning at ./abstractarray.jl:29 
>  in vect at abstractarray.jl:32 
> while loading no file, in expression starting on line 0 
> 4-element Array{Int64,1}: 
>  1 
>  2 
>  3 
>  4 
>
> julia> [[1,2]; [3,4]] 
> 4-element Array{Int64,1}: 
>  1 
>  2 
>  3 
>  4 
>

This last behaviour is due to be changed in Julia v0.5 (the current 
development version) 
to do what you want, i.e. to make a vector of vectors.
 

>
> On 5 January 2016 at 19:38, Erik Schnetter  > wrote: 
> > I believe you have to first create an empty array, and then assign to 
> > each individual element. 
> > 
> > If the outer array is small, then you can take a work-around via a 
> tuple: 
> > 
> > collect(([1,2], [3,4])) 
> > 
> > -erik 
> > 
> > 
> > On Tue, Jan 5, 2016 at 2:28 PM, Alex  
> wrote: 
> >> Hello, 
> >> 
> >> How to construct without push! equivalent vector of vectors? 
> >> 
> >> a=[] 
> >> push!(a, [1,2]) 
> >> push!(a, [2,3]) 
> >> 
> >> it gives: 
> >> # 2-element Array{Any,1}: 
> >> # [1,2] 
> >> # [2,3] 
> >> 
> >> If  i type 
> >> 
> >> a=[[1,2],[2,3]] 
> >> it gives me a 4-element array. 
> > 
> > 
> > 
> > -- 
> > Erik Schnetter  
> > http://www.perimeterinstitute.ca/personal/eschnetter/ 
>


Re: [julia-users] How to: grep an Array of strings

2015-12-03 Thread David P. Sanders


El jueves, 3 de diciembre de 2015, 13:54:01 (UTC-6), Erik Schnetter 
escribió:
>
> You are looking for `filter`:
>
> filter(line->match(r"parameter", line), rLines)
>

Apparently this needs to be

filter(line->ismatch(r"3", line) != nothing, rLines)  

(replace "match" with "ismatch" to get a Boolean expression instead of a 
RegexMatch object).
 

>
> -erik
>
> On Thu, Dec 3, 2015 at 2:52 PM, Jason McConochie  > wrote:
>
>> Is there grep for an Array of AbstractStrings?  See code below
>>
>>
>> # A. Read a file into memory (nLines pre-determined)
>>
>> fID=open(fName)
>>
>> iLine=0;
>>
>> rLines=Array(ASCIIString,nLines);
>>
>> while !eof(fID)
>>
>>   iLine+=1
>>
>>   rLines[iLine]=readline(fID)
>>
>> end
>>
>>
>> # B. Find all strings in rLines with "parameter"
>>
>>  Is something like this possible?
>>
>> indices=grep(rLines,r"parameter")
>>
>>
>>
>>
>
>
> -- 
> Erik Schnetter  
> http://www.perimeterinstitute.ca/personal/eschnetter/
>


Re: [julia-users] float(X) vs. map(Float64, X)

2015-11-29 Thread David P. Sanders
NaNs are not equal to each other. 

[julia-users] Re: tip for using Julia on OS X

2015-11-28 Thread David P. Sanders


El sábado, 28 de noviembre de 2015, 15:00:50 (UTC-6), Kevin Owens escribió:
>
> tl;dr: how to make a symbolic link in OS X.
>
> So, if you don't want to build Julia from source, you can download the 
> .app on OS X. For me, this doesn't work well because it opens Terminal when 
> I double click on the .app, and I like to use Iterm. Also, there's not an 
> easy way to open or use Julia from the terminal.
>
> The solution is a symbolic link, and running something like this in a 
> terminal:
>
> sudo ln -s /Applications/Julia-0.4.1.app/Contents/Resources/julia/bin/julia 
> /usr/bin/julia
> sudo ln -s /Applications/Julia-0.4.1.app/Contents/Resources/julia/bin/
> julia-debug /usr/bin/julia-debug
>
>
>
> which creates links in /usr/bin to julia and julia-debug.
>


Or just add an alias to ".bash_profile" in your home directory: 

alias 
julia="/Applications/Julia-0.4.1.app/Contents/Resources/julia/bin/julia"
 


[julia-users] Re: Better alternative to find all permutations?

2015-11-19 Thread David P. Sanders


El jueves, 19 de noviembre de 2015, 14:45:41 (UTC-6), Ratan Sur escribió:
>
> I want to get all the unique permutations of an array of a certain length 
> and this is the only way I currently know how to do it in one line. Is 
> there a builtin function for this?
>
> julia> unique(collect(permutations([1;0;0;0;1])))
> 10-element Array{Array{Int64,1},1}:
>  [1,0,0,0,1]
>  [1,0,0,1,0]
>  [1,0,1,0,0]
>  [1,1,0,0,0]
>  [0,1,0,0,1]
>  [0,1,0,1,0]
>  [0,1,1,0,0]
>  [0,0,1,0,1]
>  [0,0,1,1,0]
>  [0,0,0,1,1]
>
>
It turns out that the following works:

unique(permutations([1, 0, 0, 0, 1]))

 


Re: [julia-users] display precision

2015-11-15 Thread David P. Sanders


El domingo, 15 de noviembre de 2015, 12:45:11 (UTC-6), Yichao Yu escribió:
>
> On Sun, Nov 15, 2015 at 1:25 PM, digxx  
> wrote: 
> > Is it possible to display the precision of a number to arbitrary 
> decimals 
> > points? 
> > For example if I want to display pi (or any other result) up to 1e6 
> > decimals?! 
>
>
Note that the BigFloat precision is given in binary digits, not decimal 
digits,
so you have to multiply the 10^6 that you want by log2(10) = 3.32...:

num_binary_digits = ceil(Int, 10^6 * log2(10))
set_bigfloat_precision(num_binary_digits)

@time s = string(big(pi))
length(s)

The results are 103 digits and

0.184317 seconds


Of course, actually *displaying* the string takes a lot longer (output is slow).





[julia-users] Re: push! performance

2015-11-15 Thread David P. Sanders


El domingo, 15 de noviembre de 2015, 18:00:09 (UTC-6), David P. Sanders 
escribió:
>
>
>
> El domingo, 15 de noviembre de 2015, 17:35:45 (UTC-6), Steven G. Johnson 
> escribió:
>>
>> function prealloc(n)
>> a = Array(Int, n)
>> for i = 1:n
>> a[i] = i
>> end
>> return a
>> end
>> function dynamic(n)
>> a = Int[]
>> for i = 1:n
>> push!(a, i)
>> end
>> return a
>> end
>> @time prealloc(10^7);
>> @time dynamic(10^7);
>>
>>
>> On my machine, the preallocated version is 2.5–3x faster.  A significant 
>> but not overwhelming margin.
>>
>
> However, if you are doing actual calculations inside the loop 
> (rather than just storing the values), then in my experience the 
> performance difference is much smaller.
>

For example,

function prealloc2(n)
a = Array(Float64, n)
   for i = 1:n
a[i] = sqrt(i)
   end
   return a
   end

function dynamic2(n)
a = Float64[]
   for i = 1:n
push!(a, sqrt(i))
   end
   return a
   end

prealloc2(1)
dynamic2(1)

N = 10^8
@time prealloc2(N);
@time dynamic2(N); 

0.973452 seconds (6 allocations: 762.940 MB, 15.12% gc time)
1.042340 seconds (33 allocations: 912.361 MB, 8.61% gc time)


>  
>


[julia-users] Re: push! performance

2015-11-15 Thread David P. Sanders


El domingo, 15 de noviembre de 2015, 17:35:45 (UTC-6), Steven G. Johnson 
escribió:
>
> function prealloc(n)
> a = Array(Int, n)
> for i = 1:n
> a[i] = i
> end
> return a
> end
> function dynamic(n)
> a = Int[]
> for i = 1:n
> push!(a, i)
> end
> return a
> end
> @time prealloc(10^7);
> @time dynamic(10^7);
>
>
> On my machine, the preallocated version is 2.5–3x faster.  A significant 
> but not overwhelming margin.
>

However, if you are doing actual calculations inside the loop 
(rather than just storing the values), then in my experience the 
performance difference is much smaller.

 


[julia-users] Re: Creating a stable version of Julia + Packages for a semester long course?

2015-11-15 Thread David P. Sanders


El domingo, 15 de noviembre de 2015, 21:05:45 (UTC-6), Sheehan Olver 
escribió:
>
>
> I'm trying to figure out the "best" way to create a stable version of 
> Julia + Gadfly + PyPlot + IJulia (+ other packages?) for a semester long 
> course.  I don't want to have the students run Pkg.add(...)/Pkg.update(), 
> as packages have a tendency to occasionally break on updates, and it's a 
> headache dealing with this during the lecture.
>
> Two possible solutions I can think of of are:
>
> 1)  Prebake a .julia folder that contains all the necessary resources, 
> with a script to reset in case the students break it with Pkg.update().
> 2)  Use system image
>
> http://docs.julialang.org/en/release-0.4/devdocs/sysimg/
>
> that includes all the necessary packages.   It's not really clear how to 
> do this from the documentation, though.   I'm also not sure how that would 
> interact with Pkg.update() though, so probably instructions to delete 
> .julia would also need to be given.
>
>
> Any other options I'm missing?  If 2 is recommended, any tutorial how to 
> do this?
>

Another option is 

https://github.com/rened/DeclarativePackages.jl 

which allows you to run Julia with a given set of versions of given 
packages.

Possibly another option would be a Docker container image.


[julia-users] Re: line numbers in Jupyter

2015-11-03 Thread David P. Sanders
You can also use Ctrl-m instead of escape. So it would be Ctrl-m, followed by 
lower case L. 

[julia-users] Re: Creating variables programmatically

2015-11-03 Thread David P. Sanders


El martes, 3 de noviembre de 2015, 10:27:27 (UTC-6), Dawid Crivelli 
escribió:
>
> How about using a dictionary instead of variables, to do something like 
> the following:
>
> images = Dict{AbstractString, Image}() # dictionary associating an 
> Image object to a string
> image["flower"] = imread("flower.png") # made up function name
>
> Accessing the dictionary won't significantly slow the access to the image 
> data stored in memory, and you can access the images by their reference 
> string, which can depend on input data (e.g. a list of files).
>

Using a dictionary is a nice solution, but usually you want the types used 
for the keys and values to be concrete types, not abstract:

images = Dict{UTF8String, Image}()


Re: [julia-users] help with a macro to stringize high precision floating point values

2015-11-02 Thread David P. Sanders


El lunes, 2 de noviembre de 2015, 7:58:17 (UTC-6), Stefan Karpinski 
escribió:
>
> I think we should probably make it possible to access the full string of 
> a numeric literal in a macro but that is a substantial change to the parser.
>

That would be great.

Off-topic: Jeffrey, will your Float128 library be correctly-rounded?
 

>
> On Monday, November 2, 2015, David P. Sanders <dpsa...@gmail.com 
> > wrote:
>
>>
>>
>> El lunes, 2 de noviembre de 2015, 6:35:46 (UTC-6), Milan Bouchet-Valat 
>> escribió:
>>>
>>> Le lundi 02 novembre 2015 à 00:58 -0800, Jeffrey Sarnoff a écrit : 
>>> > I have many values like 
>>> >  0.6584871727288045313850172023417636020375045372547107712468813403 
>>> > that come from Maple and I would like to avoid doing this by 
>>> > copy/paste for each one: 
>>> > Float128(parse(BigFloat,"0.658487172728804531385017202341763602037504 
>>> > 5372547107712468813403")) 
>>> > 
>>> > I tried writing a macro that would put quotes around the value and 
>>> > then affix the rest -- without good result. 
>>> > julia>@fromMaple 
>>> > 0.6584871727288045313850172023417636020375045372547107712468813403 
>>> > Float128(parse(BigFloat,"0.658487172728804531385017202341763602037504 
>>> > 5372547107712468813403")) 
>>> > 
>>> > The REPL converts  the unenquoted value to a Float64 before I get at 
>>> > it. 
>>> > 
>>> > Help is appreciated. 
>>> I don't think you can work around this at the moment. The best you can 
>>> do is to define a non-standard string literal by creating a @f128_str 
>>> macro, so that you can type these numbers as 
>>> f128"0.6584871727288045313850172023417636020375045372547107712468813403 
>>> ". 
>>>
>>
>> There is already a `big` macro:
>>
>> Float128(big"0.65848717272880453138501720234176360203750453725471077124688134")
>>
>> Instead of copying and pasting in the REPL, couldn't you write these 
>> numbers to a file
>> and read them in as strings in Julia?
>>  
>> There has been some discussion in the past about forwarding strings like 
>> this to the parser
>> already wrapped in a macro (as is done for large integer values); I don't 
>> recall what the 
>> issue with this was.
>>
>

Re: [julia-users] help with a macro to stringize high precision floating point values

2015-11-02 Thread David P. Sanders


El lunes, 2 de noviembre de 2015, 6:35:46 (UTC-6), Milan Bouchet-Valat 
escribió:
>
> Le lundi 02 novembre 2015 à 00:58 -0800, Jeffrey Sarnoff a écrit : 
> > I have many values like 
> >  0.6584871727288045313850172023417636020375045372547107712468813403 
> > that come from Maple and I would like to avoid doing this by 
> > copy/paste for each one: 
> > Float128(parse(BigFloat,"0.658487172728804531385017202341763602037504 
> > 5372547107712468813403")) 
> > 
> > I tried writing a macro that would put quotes around the value and 
> > then affix the rest -- without good result. 
> > julia>@fromMaple 
> > 0.6584871727288045313850172023417636020375045372547107712468813403 
> > Float128(parse(BigFloat,"0.658487172728804531385017202341763602037504 
> > 5372547107712468813403")) 
> > 
> > The REPL converts  the unenquoted value to a Float64 before I get at 
> > it. 
> > 
> > Help is appreciated. 
> I don't think you can work around this at the moment. The best you can 
> do is to define a non-standard string literal by creating a @f128_str 
> macro, so that you can type these numbers as 
> f128"0.6584871727288045313850172023417636020375045372547107712468813403 
> ". 
>

There is already a `big` macro:
Float128(big"0.65848717272880453138501720234176360203750453725471077124688134")

Instead of copying and pasting in the REPL, couldn't you write these 
numbers to a file
and read them in as strings in Julia?
 
There has been some discussion in the past about forwarding strings like 
this to the parser
already wrapped in a macro (as is done for large integer values); I don't 
recall what the 
issue with this was.


[julia-users] Re: Anyone know how to get help with Jupyter?

2015-10-31 Thread David P. Sanders


El sábado, 31 de octubre de 2015, 14:57:01 (UTC-6), Daniel Carrera escribió:
>
> I apologize for asking a non-Julia question here, but for the life of me I 
> cannot figure out how to contact the people working on Jupyter so I can ask 
> them a question:
>
> http://jupyter.org/index.html
>

You can try the IPython Gitter chat channel:

https://gitter.im/ipython/ipython

If your question is specifically about the IOctave kernel, then you should 
probably post an issue there.

In fact, there already is one:
https://github.com/Calysto/octave_kernel/issues/18
 

>
>
> I know that some Julia people are involved in Jupyter, so I hope somebody 
> here knows. I am feeling a bit frustrated right now. You would think that 
> they would have a visible link somewhere that told you how you can contact 
> them. You would imagine that they would have a mailing list, or an IRC 
> channel. I'm guessing that they probably do. But I just cannot find that 
> information on their website, and I REALLY tried to find it.
>
> Does anyone know how I can ask a question to the Jupyter people? I just 
> want to ask them how I can have multiple lines of output from the same 
> cell. Back when it was called IPython you used to be able to write a single 
> cell with several instructions, like:
>
> -
> 5+5
> 5+6
> 5+7
> -
>
> All that in the same cell. And then output would be 10, 11, 12 (all in 
> different lines). Now I only get "12" -- the last line of output.
>
> So I am trying to find the Jupyter users mailing list, or IRC channel, or 
> whatever they use so I can ask my question. I would be grateful for any 
> pointers.
>
> Cheers,
> Daniel.
>


[julia-users] Re: array of empty arrays and data types

2015-10-30 Thread David P. Sanders


El viernes, 30 de octubre de 2015, 7:12:39 (UTC-6), Cameron Zachreson 
escribió:
>
> Hello, 
>
> Just started using Julia and I've come across an issue trying to create 
> and append values to arrays of empty arrays. 
>

If you specify a bit more precisely what you are trying to do, it will be 
easier to help you.

Note that performance will be terrible unless you completely specify the 
types of the objects -- just writing Array 
leaves some of the types unspecified, as denoted by the {T,N} when you write

julia> Array[]
0-element Array{Array{T,N},1}

The simplest solution is something like

julia> v = Vector{Int}[]
0-element Array{Array{Int64,1},1}

This specifies an empty array (the [ ] part) that contains vectors (i.e. 1D 
arrays) of Ints  (the Vector{Int} part).

You can then add vectors of integers to it with

julia> push!(v, [1, 2])
1-element Array{Array{Int64,1},1}:
 [1,2]

julia> push!(v, [3, 4, 5])
2-element Array{Array{Int64,1},1}:
 [1,2]  
 [3,4,5]
 

>
> What I want to do is create a grid of empty arrays that can be filled with 
> values associated with particle IDs for a molecular dynamics-style 
> simulation. The trouble I'm having is that it does not seem possible to 
> initialize the arrays so that they can be iteratively filled. 
>
> here is an example of the problem:
>
> julia> bins = Array(Array, 5, 5)
>
>
> 5x5 Array{Array{T,N},2}:
>
>  #undef  #undef  #undef  #undef  #undef
>
>  #undef  #undef  #undef  #undef  #undef
>
>  #undef  #undef  #undef  #undef  #undef
>
>  #undef  #undef  #undef  #undef  #undef
>
>  #undef  #undef  #undef  #undef  #undef
>
>
> julia> bins[1, 1] = 0
>
>
> ERROR: MethodError: `convert` has no method matching 
> convert(::Type{Array{T,N}}, ::Int64)
>
> This may have arisen from a call to the constructor Array{T,N}(...),
>
> since type constructors fall back to convert methods.
>
> Closest candidates are:
>
>   call{T}(::Type{T}, ::Any)
>
>   convert(::Type{Array{T,N}}, ::SharedArray{T,N})
>
>   convert{T,N}(::Type{Array{T,N}}, ::AbstractArray{T,N})
>
>   ...
>
>  in setindex! at array.jl:314
>
> I don't understand what the error message means, I have tried initializing 
> with different datatypes, but it does not work. Any help would be 
> appreciated. 
>
> Cam
>
>
>
>

[julia-users] Re: PyPlot histogram does not work (for me at least) in 0.4.0 (?)

2015-10-26 Thread David P. Sanders
Apologies, this seems to have changed recently -- PyPlot no longer 
overwrites Base.hist.

You can do 
plt[:hist]


[julia-users] Re: PyPlot histogram does not work (for me at least) in 0.4.0 (?)

2015-10-26 Thread David P. Sanders

If you do `using PyPlot` then you can just use `hist` directly:

using PyPlot

x = randn(1)
hist(x, 100)

El lunes, 26 de octubre de 2015, 10:21:59 (UTC-6), Ferran Mazzanti escribió:
>
> Oh, thnks for the info...
>
> On Monday, October 26, 2015 at 12:25:26 PM UTC+1, Kristoffer Carlsson 
> wrote:
>>
>> Read here: https://github.com/stevengj/PyCall.jl#usage 
>> 
>>
>> More specifically, this section:
>>
>> "The biggest diffence from Python is that object attributes/members are 
>> accessed with o[:attribute]rather than o.attribute, and you use get(o, 
>> key) rather than o[key]. (This is because Julia does not permit 
>> overloading the . operator yet.) See also the section on PyObject below, 
>> as well as the pywrap function to create anonymous modules that simulate 
>> . access (this is what @pyimportdoes). For example, using Biopython 
>>  we can do:
>>
>> @pyimport Bio.Seq as s
>> @pyimport Bio.Alphabet as a
>> my_dna = s.Seq("AGTACACTGGT", a.generic_dna)
>> my_dna[:find]("ACT")
>>
>> whereas in Python the last step would have been my_dna.find("ACT")"
>>
>> On Monday, October 26, 2015 at 11:38:41 AM UTC+1, Ferran Mazzanti wrote:
>>>
>>> That worked, thanks :) 
>>>
>>> But this syntax I can not understand... where can I find documentation 
>>> about how to do that? Just to avoid asking agains cuh kind of questions...
>>>
>>> Thanks again.
>>>
>>> On Monday, October 26, 2015 at 11:31:59 AM UTC+1, Kristoffer Carlsson 
>>> wrote:

 Change last line to:

 h = PyPlot.plt[:hist](x,nbins)



 On Monday, October 26, 2015 at 11:28:35 AM UTC+1, Ferran Mazzanti wrote:
>
> Hi folks,
>
> using Linux Mint 17.1 here. I upgraded to julia 0.4.0 and now this 
> simple code, taken from the web and tested on previous versions,
>
> using PyPlot
>
> x = randn(1000) # Values
> nbins = 50 # Number of bins
>
> fig = figure("pyplot_histogram",figsize=(6,6)) # Not strictly required
> ax = axes() # Not strictly required
> h = PyPlot.plt.hist(x,nbins) # Histogram, PyPlot.plt required to 
> differentiate with conflicting hist command
>
> Produces the following output
>
> LoadError: type PyObject has no field hist
> while loading In[133], in expression starting on line 6
>
>  in getindex at /home/mazzanti/.julia/v0.4/PyCall/src/PyCall.jl:240
>  in pysequence_query at 
> /home/mazzanti/.julia/v0.4/PyCall/src/conversions.jl:781
>  [inlined code] from 
> /home/mazzanti/.julia/v0.4/PyCall/src/conversions.jl:797
>  in pytype_query at 
> /home/mazzanti/.julia/v0.4/PyCall/src/conversions.jl:826
>  in convert at /home/mazzanti/.julia/v0.4/PyCall/src/conversions.jl:846
>  in pycall at /home/mazzanti/.julia/v0.4/PyCall/src/PyCall.jl:399
>  in call at /home/mazzanti/.julia/v0.4/PyCall/src/PyCall.jl:407
>  in close_queued_figs at 
> /home/mazzanti/.julia/v0.4/PyPlot/src/PyPlot.jl:401
>
> Any hint on that? Am I doing something wrong? If so, can anybody help on 
> how to do histograms in Julia 0.4.0?
>
> Thanks,
>
> Ferran. 
>
>
>

[julia-users] Re: PyPlot histogram does not work (for me at least) in 0.4.0 (?)

2015-10-26 Thread David P. Sanders
(You then must call Base.hist if you want the version from Base.)

El lunes, 26 de octubre de 2015, 23:13:23 (UTC-6), David P. Sanders 
escribió:
>
>
> If you do `using PyPlot` then you can just use `hist` directly:
>
> using PyPlot
>
> x = randn(1)
> hist(x, 100)
>
> El lunes, 26 de octubre de 2015, 10:21:59 (UTC-6), Ferran Mazzanti 
> escribió:
>>
>> Oh, thnks for the info...
>>
>> On Monday, October 26, 2015 at 12:25:26 PM UTC+1, Kristoffer Carlsson 
>> wrote:
>>>
>>> Read here: https://github.com/stevengj/PyCall.jl#usage 
>>> <https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fstevengj%2FPyCall.jl%23usage=D=1=AFQjCNH7nXL2YvYmMDRWhIqXP-0ZeHzMlQ>
>>>
>>> More specifically, this section:
>>>
>>> "The biggest diffence from Python is that object attributes/members are 
>>> accessed with o[:attribute]rather than o.attribute, and you use get(o, 
>>> key) rather than o[key]. (This is because Julia does not permit 
>>> overloading the . operator yet.) See also the section on PyObject below, 
>>> as well as the pywrap function to create anonymous modules that 
>>> simulate . access (this is what @pyimportdoes). For example, using 
>>> Biopython <http://biopython.org/wiki/Seq> we can do:
>>>
>>> @pyimport Bio.Seq as s
>>> @pyimport Bio.Alphabet as a
>>> my_dna = s.Seq("AGTACACTGGT", a.generic_dna)
>>> my_dna[:find]("ACT")
>>>
>>> whereas in Python the last step would have been my_dna.find("ACT")"
>>>
>>> On Monday, October 26, 2015 at 11:38:41 AM UTC+1, Ferran Mazzanti wrote:
>>>>
>>>> That worked, thanks :) 
>>>>
>>>> But this syntax I can not understand... where can I find documentation 
>>>> about how to do that? Just to avoid asking agains cuh kind of questions...
>>>>
>>>> Thanks again.
>>>>
>>>> On Monday, October 26, 2015 at 11:31:59 AM UTC+1, Kristoffer Carlsson 
>>>> wrote:
>>>>>
>>>>> Change last line to:
>>>>>
>>>>> h = PyPlot.plt[:hist](x,nbins)
>>>>>
>>>>>
>>>>>
>>>>> On Monday, October 26, 2015 at 11:28:35 AM UTC+1, Ferran Mazzanti 
>>>>> wrote:
>>>>>>
>>>>>> Hi folks,
>>>>>>
>>>>>> using Linux Mint 17.1 here. I upgraded to julia 0.4.0 and now this 
>>>>>> simple code, taken from the web and tested on previous versions,
>>>>>>
>>>>>> using PyPlot
>>>>>>
>>>>>> x = randn(1000) # Values
>>>>>> nbins = 50 # Number of bins
>>>>>>
>>>>>> fig = figure("pyplot_histogram",figsize=(6,6)) # Not strictly required
>>>>>> ax = axes() # Not strictly required
>>>>>> h = PyPlot.plt.hist(x,nbins) # Histogram, PyPlot.plt required to 
>>>>>> differentiate with conflicting hist command
>>>>>>
>>>>>> Produces the following output
>>>>>>
>>>>>> LoadError: type PyObject has no field hist
>>>>>> while loading In[133], in expression starting on line 6
>>>>>>
>>>>>>  in getindex at /home/mazzanti/.julia/v0.4/PyCall/src/PyCall.jl:240
>>>>>>  in pysequence_query at 
>>>>>> /home/mazzanti/.julia/v0.4/PyCall/src/conversions.jl:781
>>>>>>  [inlined code] from 
>>>>>> /home/mazzanti/.julia/v0.4/PyCall/src/conversions.jl:797
>>>>>>  in pytype_query at 
>>>>>> /home/mazzanti/.julia/v0.4/PyCall/src/conversions.jl:826
>>>>>>  in convert at /home/mazzanti/.julia/v0.4/PyCall/src/conversions.jl:846
>>>>>>  in pycall at /home/mazzanti/.julia/v0.4/PyCall/src/PyCall.jl:399
>>>>>>  in call at /home/mazzanti/.julia/v0.4/PyCall/src/PyCall.jl:407
>>>>>>  in close_queued_figs at 
>>>>>> /home/mazzanti/.julia/v0.4/PyPlot/src/PyPlot.jl:401
>>>>>>
>>>>>> Any hint on that? Am I doing something wrong? If so, can anybody help on 
>>>>>> how to do histograms in Julia 0.4.0?
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> Ferran. 
>>>>>>
>>>>>>
>>>>>>

[julia-users] Re: IJulia notebook porting from one kernel to another

2015-10-18 Thread David P. Sanders
In the Kernel menu, you can change the kernel to whichever kernel you would 
like to use. Then save the notebook, and the next time you open it, it will 
automatically open with the new kernel. 

(Note that this assumes you are using IPython / Jupyter at least version 3. If 
you are not, you should upgrade to Jupyter 4.)

[julia-users] Re: IPython keeps giving Kernel error

2015-10-07 Thread David P. Sanders
You could try with the latest Julia 0.4 release candidate. Have you tried 
deleting your whole .julia directory and reinstalling IJulia? 

[julia-users] Re: Opening Julia files on IJulia?

2015-10-05 Thread David P. Sanders
Though I should say that I also would not recommend doing this for serious 
work, and suggest using a proper editor like Atom instead.
Look here for the right packages to install (still rather alpha):

https://github.com/JunoLab/atom-julia-client/tree/master/manual

El lunes, 5 de octubre de 2015, 14:53:07 (UTC-5), David P. Sanders escribió:
>
> Actually in the latest versions of the notebook (maybe just Jupyter 4? or 
> maybe IPython 3 too), you can just open a normal file by clicking on its 
> name 
> from the Notebook dashboard. This will drop you into a CodeMirror editor 
> just as if it were a code cell, and you can edit and save the file.
> For example, this works well for Julia files (.jl).
>
> El lunes, 5 de octubre de 2015, 9:40:13 (UTC-5), Marcio Sales escribió:
>>
>> Thanks for your replies but I meant actually openning them for edition, 
>> like when you're working on contributions to a package. I know that 
>> Include() executes a .jl file but doesn't open it for edition does it?
>>
>>>
>>>
>>>
>>>

[julia-users] Re: Opening Julia files on IJulia?

2015-10-05 Thread David P. Sanders
Actually in the latest versions of the notebook (maybe just Jupyter 4? or 
maybe IPython 3 too), you can just open a normal file by clicking on its 
name 
from the Notebook dashboard. This will drop you into a CodeMirror editor 
just as if it were a code cell, and you can edit and save the file.
For example, this works well for Julia files (.jl).

El lunes, 5 de octubre de 2015, 9:40:13 (UTC-5), Marcio Sales escribió:
>
> Thanks for your replies but I meant actually openning them for edition, 
> like when you're working on contributions to a package. I know that 
> Include() executes a .jl file but doesn't open it for edition does it?
>
>>
>>
>>
>>

[julia-users] Re: Old Julia profiles in Jupyter session

2015-10-05 Thread David P. Sanders


El lunes, 5 de octubre de 2015, 16:19:51 (UTC-5), Júlio Hoffimann escribió:
>
> Hi,
>
> Whenever I update Julia I see a new profile in my Jupyter session. How to 
> delete all these old versions in the attached screenshot?
>
>
> 
>
>
> -Júlio
>

I think you have to delete the `kernels` directory in your `.ipython` 
directory. 


Re: [julia-users] Variable number of parameters types in a function

2015-10-04 Thread David P. Sanders


El domingo, 4 de octubre de 2015, 15:45:19 (UTC-5), data.pu...@gmail.com 
escribió:
>
> Hi Tom,
>
> I am looking for something analogous to a C++ variadic template function 
> where the types as well as the arguments to the function are varags. These 
> are aligned so that in my above notation T... would be a tuple/array of 
> types corresponding to the types of x... and so each T[i] could be 
> arbitrary.
>

You can just use a tuple of types:

julia> function my_fun(types, xx)
 for (T, x) in zip(types, xx)
   println(typeof(x) <: T)
 end
   end
my_fun (generic function with 1 method)

julia> my_fun((Float64, Int), (0.3, 1))
true
true
 

>
>
>
> DP
>
> On Sunday, October 4, 2015 at 4:30:19 AM UTC+1, Tom Breloff wrote:
>>
>> I think maybe the function you're looking for is something like:
>>
>> function my_fun(::Type{T}, x...)
>>   for xi in x
>> println(typeof(xi) <: T)
>>   end
>> end
>>
>> or some variation of that?
>>
>> On Sat, Oct 3, 2015 at 5:18 PM,  wrote:
>>
>>> Is it possible to specify a variable number of parameter types in Julia, 
>>> for instance something like
>>>
>>> function {T...}my_fun(x...)
>>>   for i in 1:length(x)
>>> println(typeof(x[i]) <: T[i])
>>>   end
>>> end
>>>
>>> should print true ... times
>>>
>>> Thanks
>>>
>>
>>

[julia-users] Re: Nicer syntax collect(linspace(0,1,n))?

2015-10-01 Thread David P. Sanders


El martes, 29 de septiembre de 2015, 17:44:43 (UTC-5), feza escribió:
>
> In matlab  x = linspace(0,1,n)  creates a vector of floats of length n. In 
> julia it seems like the only way to do this is to use x = collect( 
> linspace(0,1,n) ) . Is there a nicer syntax? I do mainly numeric computing 
> and I find this quite common in my code.
>

Nobody seems to have mentioned the nicer (at least shorter) syntax:

x = [linspace(0, 1, n) ;]

Note that the ; at the end (which is the concatenation operator) will be 
required starting with the next version of Julia.

Nonetheless, I find  collect(linspace(0, 1, n)) arguably clearer.


[julia-users] Default Ipython profile in Ijulia

2015-09-19 Thread David P. Sanders
Hi, 

Which version if the (ipython / jupyter)  notebook do you have? It sounds like 
it's at least 3. (The one that lets you choose between different kernels.) 

In that case, you should no longer put the --profile, i.e. Just run ipython 
notebook

David 

Re: [julia-users] Run gcc in build.jl

2015-09-18 Thread David P. Sanders


El jueves, 17 de septiembre de 2015, 17:48:52 (UTC-5), Mike Nolta escribió:
>
> The problem with 
>
>   `gcc -L. -shared -o libcrlibm.dylib $(find . -d 1 -name *.o)` 
>
> is that the stuff inside $(...) is interpreted as julia code. 
>
> I'm not sure what's the best way to do this -- maybe something like: 
>
>   pipeline(`find . -d 1 -name *.o`, `xargs gcc -L. -shared -o 
> libcrlibm.dylib`) 
>


Thanks, I think that works. It turned out that the necessary incantation 
was even worse,
needing *.o from a subdirectory, so I instead created a simple makefile 
with the relevant
command and called that instead.

The dependency now seems to be built properly on Mac OSX.
On Linux (via JuliaBox), as far as I can work out all the steps in the 
build are completed, including compiling the shared library, 
but it fails with the following error (below).

Does somebody have an idea what is happening here? The relevant commands are

Pkg.clone("http://github.com/dpsanders/CRlibm.jl;)
INFO: Cloning CRlibm from http://github.com/dpsanders/CRlibm.jl
INFO: Computing changes...
INFO: No packages to install, update or remove

julia> Pkg.build("CRlibm")

Thanks,
David


[ ERROR: CRlibm 
]

 LoadError: Provider 
BinDeps.BuildProcess failed to satisfy dependency libcrlibm
while loading /home/juser/.julia/v0.4/CRlibm/deps/build.jl, in expression 
starting on line 51

 
=

 
[ BUILD ERRORS 
]=

 WARNING: CRlibm had 
build errors.

  - packages with build 
errors remain installed in /home/juser/.julia/v0.4  
  
 - build the package(s) and all dependencies with `Pkg.build("CRlibm")` 
 
 - build a single package by running its `deps/build.jl` script   



 

>
> ? 
>
> -Mike 
>
> On Thu, Sep 17, 2015 at 5:06 PM, David P. Sanders <dpsa...@gmail.com 
> > wrote: 
> > Hi, 
> > 
> > I am almost ready to release a simple wrapper of the CRlibm library: see 
> > https://github.com/dpsanders/CRlibm.jl 
> > 
> > The last (?) step I need is to get the gcc command in the below build 
> script 
> > in deps/build.jl to work. 
> > Could somone please suggest how to do this? The problem is that *.o is 
> not 
> > expanded in Julia commands 
> > (maybe this could be added?) 
> > 
> > I found a previous discussion at 
> > https://groups.google.com/forum/#!topic/julia-users/hzBeluKU7P0 
> > 
> > I tried the solutions suggested, but the ones involving Julia code don't 
> > seem 
> > to work inside the @build_steps macro, and the one using find, 
> implemented 
> > as 
> > 
> >  `gcc -L. -shared -o libcrlibm.dylib $(find . -d 1 -name *.o)` 
> > 
> > gives 
> > ERROR: ParseError("missing separator in tuple") 
> > 
> > Thanks, 
> > David 
> > 
> > Extract from script: 
> > 
> > provides(SimpleBuild, 
> > (@build_steps begin 
> > GetSources(libcrlibm) 
> > 
> > @build_steps begin 
> > ChangeDirectory(srcdir) 
> > @build_steps begin 
> > `./configure CFLAGS=-fpic` 
> > `make` 
> > 
> > `gcc -L. -shared -o libcrlibm.dylib *.o` 
> > end 
> > end 
> > end), 
> > libcrlibm, os = :Unix 
> > ) 
> > 
> > (How is one supposed to include code here??) 
>


[julia-users] Run gcc in build.jl

2015-09-17 Thread David P. Sanders
Hi,

I am almost ready to release a simple wrapper of the CRlibm library: see
https://github.com/dpsanders/CRlibm.jl

The last (?) step I need is to get the gcc command in the below build 
script in deps/build.jl to work.
Could somone please suggest how to do this? The problem is that *.o is not 
expanded in Julia commands
(maybe this could be added?)

I found a previous discussion at
https://groups.google.com/forum/#!topic/julia-users/hzBeluKU7P0

I tried the solutions suggested, but the ones involving Julia code don't 
seem
to work inside the @build_steps macro, and the one using find, implemented 
as

 `gcc -L. -shared -o libcrlibm.dylib $(find . -d 1 -name *.o)`

gives 
ERROR: ParseError("missing separator in tuple")

Thanks,
David

Extract from script:

provides(SimpleBuild,
(@build_steps begin
GetSources(libcrlibm)

@build_steps begin
ChangeDirectory(srcdir)
@build_steps begin
`./configure CFLAGS=-fpic`
`make`

`gcc -L. -shared -o libcrlibm.dylib *.o`
end
end
end),
libcrlibm, os = :Unix
)

(How is one supposed to include code here??)


[julia-users] Re: [ANN] FixedSizeArrays

2015-09-05 Thread David P. Sanders


El sábado, 5 de septiembre de 2015, 22:09:20 (UTC+1), Simon Danisch 
escribió:
>
> Hi everyone,
>
> FixedSizeArrays offers 
> an abstract interface to turn arbitrary types into arrays of fixed size 
> with most array functionality defined.
> The types Point, Vec and Mat are already included per default.
>

This is great news, congrats!

There doesn't seem to be a version tagged. Should we do Pkg.clone()? Could 
you add this info in the repo?

David.
 

>
> Advantages are that they're stack allocated, often have less overhead than 
> Julia arrays and you can dispatch on the dimension.
> Disadvantages are, that they're still immutable (advantage?!), 0.4 only 
> and I still have some problems with compilation times for first calls of 
> the function even with precompilation.
> Also the constructor code is pretty messy, as it is currently relatively 
> hard to write constructors for abstract types.
>
> In the future I want to move this into base, by simply inheriting from 
> AbstractArray, which is currently not possible for immutable arrays. 
> Major blocking issue for this is my restricted time and #11610 
> .
> Also, we might use Ref{NTuples} for fixed size arrays in the future, which 
> would resolve quite a few issues.
> It's pretty fast but might get even faster as soon as NTuple gets 
> translated into LLVM's vector type (currently array).
>
> Here's a short code sample:
>
> immutable RGB{T} <: FixedVectorNoTuple{T, 3}
> r::T
> g::T
> b::Tendimmutable Vec{N, T} <: FixedVector{N, T} # defined in GeometryTypes.jl
> _::NTuple{N, T}end
> Vec{3, Float32}(0) # constructor with 1 argument already definedrand(Vec{3, 
> Int})+sin(Vec(0,2,2)) # a lot of array functions are already defined#There is 
> also a matrix typeeye(Mat{3,3,Float32}) * rand(Vec{3, Float32}) # will also 
> "just work"
> a = Vec(1,2,3)[1:2] # returns (1,2)
>
>
> Best,
> Simon
>


[julia-users] Re: Can't use @manipulate in jupyter

2015-08-22 Thread David P. Sanders

Which version of Jupyter / IPython are you using?
This is all going through an upheaval at the moment. My guess is that you 
need

Pkg.checkout(Interact)

to get the latest version of Interact.jl that works with version 3.0 of the 
Notebook. (But not, apparently, with the very latest version 4.0 version, 
so if you have that then you
will need to downgrade for the moment.)

David.

El sábado, 22 de agosto de 2015, 10:32:32 (UTC-5), Shubham Bhushan escribió:

 I'd really appreciate any ideas I know this is very little to go on but 
 maybe some of you can just spitball some ideas that might work. I really 
 would like to use this  functionality

 On Saturday, August 22, 2015 at 5:40:13 PM UTC+5:30, Shubham Bhushan wrote:

 Hi I tried using Gadfly and Interact and tried the example from 
 Interact.jl github notebooks.
 My code doesn't evaluate. It just keeps processing and doesn't plot 
 anything, the kernel however is shown to be busy 
 @manipulate for ϕ = 0:π/16:4π, f = [:sin = sin, :cos = cos], both = 
 false
 if both
 plot([θ - sin(θ + ϕ), θ - cos(θ + ϕ)], 0, 8)
 else
 plot(θ - f(θ + ϕ), 0, 8)
 end
 end
 I have run the code for 2hrs now still no output



[julia-users] Re: Splitting a multidimensional function

2015-08-21 Thread David P. Sanders
Here is a fun and possibly useful solution (that works only on 0.4 due to 
call overloading):

https://gist.github.com/dpsanders/d8ef239ec8c78c4debee

It introduces a `MultidimFunction` type, and a macro `@multidim` that works 
as follows:

julia @multidim f(x) = [sqrt(x[1]), 2x[2]]
MultidimFunction([(anonymous function),(anonymous function)])

julia f([1., 2.])
2-element Array{Float64,1}:
 1.0
 4.0

julia x = [1., 2.]
2-element Array{Float64,1}:
 1.0
 2.0

julia f(x)
2-element Array{Float64,1}:
 1.0
 4.0

julia f[1](x)
1.0

julia f[2](x)
4.0

julia y = [-1., 2.]
2-element Array{Float64,1}:
 -1.0
  2.0

julia f[1](y)
ERROR: DomainError:
sqrt will only return a complex result if called with a complex argument.
try sqrt (complex(x))
 in sqrt at ./math.jl:144
 in anonymous at 
/Users/dsanders/.julia/v0.3/ValidatedNumerics/src/multidim/multidim_functions.jl:49

julia f[2](y)
4.0

David.



[julia-users] Re: complex results - why not automatic type conversion?

2015-07-22 Thread David P. Sanders
How about 

mysqrt(x::Real) = sqrt(complex(x)) 
mysqrt(x::Complex) = sqrt(x) 

Re: [julia-users] Wrong number of arguments?

2015-07-15 Thread David P. Sanders


El miércoles, 15 de julio de 2015, 14:03:16 (UTC-5), Mauricio Esteban Cuak 
escribió:

 Just in case it seems a bit more transparent, this also works:

 r = rand(5)
 map( x - x[1] + x[2], enumerate(r))



I personally find the following array comprehension the most transparent 
option:

[i+v for (i,v) in enumerate(r)]

It also has the benefit of being much faster (Julia 0.3.11-pre):

julia f1(r) = [i+v for (i,v) in enumerate(r)]
f1 (generic function with 1 method)

julia f2(r) = map( x - x[1] + x[2], enumerate(r))
f2 (generic function with 1 method)

# warm-up:
r = rand(5)
f1(r)
f2(r);

r = rand(10^6)

julia @time f1(r);
elapsed time: 0.007597053 seconds (8000144 bytes allocated)

julia @time f2(r);
elapsed time: 0.313020208 seconds (160753984 bytes allocated, 35.39% gc 
time)



 


 El martes, 14 de julio de 2015, 20:20:14 (UTC-5), Yichao Yu escribió:

 On Tue, Jul 14, 2015 at 7:09 PM, Ritchie Lee ritch...@gmail.com wrote: 
  Sorry if this is a newbie question.  I am trying to get map() to work 
 with 
  with enumerate() but I am getting an error. 
  
  r=rand(5) 
  map((i,v)-i+v, enumerate(r)) 
  ERROR: wrong number of arguments 
   in anonymous at none:1 
   in map at abstractarray.jl:1207 
  
  collect(enumerate(r)) generates an array of 2-tuples as expected. 

 `map` does not splat each element of the iteration and only pass each 
 element as a single argument to the function 

 ```julia 
 julia r = rand(5) 
   map(x-((i, v) = x; i + v), enumerate(r)) 
 5-element Array{Any,1}: 
 1.6277 
 2.41751 
 3.34848 
 4.70194 
 5.89139 

 ``` 

  
  Is the syntax incorrect? 
  
  Thanks, 
  
  Ritchie 



[julia-users] Help! Trying to install IJulia on 0.3.10, ZMQ fails to load

2015-06-27 Thread David P. Sanders
I usually suggest deleting the .julia directory and installing packaged from 
scratch. 

[julia-users] ANN: ValidatedNumerics v0.1: Interval arithmetic and rigorous root finding

2015-06-25 Thread David P. Sanders

We are pleased to announce the first public release version of the 
ValidatedNumerics.jl package, a Julia package for doing rigorous 
calculations 
using floating-point based interval arithmetic. This includes methods for 
rigorously finding roots of 1D real functions.

To install the package, do

julia Pkg.add(ValidatedNumerics)

The package provides an Interval type and operations defined on it in such 
a way that the result of any mathematical operations is *guaranteed* to
contain the true result. For convenience, an `@interval` macro is defined:

julia using ValidatedNumerics

julia @interval(0.1)
[0.0, 0.1]

julia @interval sin(0.1) + cos(0.2)
[1.079844880696, 1.0798448807]

Just wrapping an operation with the `@interval` macro automatically 
provides a guaranteed rigorous interval containing the true result (an 
enclosure).

Interval arithmetic provides a means to develop new algorithms that also 
provide rigorous guaranteed results, for example for root finding.
The interval Newton method is implemented in the function `newton`, e.g.:

julia f(x) = x^2 - 2
f (generic function with 1 method)

julia newton(f, @interval(-5, 5))
2-element Array{Root{Float64},1}:
 Root([-1.4142135623730951, -1.414213562373095], :unique)
 Root([1.414213562373095, 1.4142135623730951], :unique)

 The response from this function can be considered as a *mathematically 
rigorous proof* that the function f
 has exactly two roots in the interval [-5, 5], one in the first interval 
and the other in the second.
The :unique symbol indicates that the algorithm *guarantees* that there 
exists a root in the given
interval and that it is unique.

Currently root-finding functionality is restricted to one-variable real 
functions.
Please let us know if you have particularly tricky functions whose 
(non-multiple) roots you need to find!
Multi-dimensional root finding is planned for the future.

We of course welcome comments, criticism, and pull requests at
http://github.com/dpsanders/ValidatedNumerics.jl

David Sanders  Luis Benet



[julia-users] Re: [Slightly OT] Creating JuliaCon presentation slides as a Jupyter notebook

2015-06-22 Thread David P. Sanders


El jueves, 4 de junio de 2015, 9:49:15 (UTC-5), Douglas Bates escribió:

 The JuliaCon2015 organizers have suggested preparing conference 
 proceedings in the form of Jupyter notebooks, which I think is a great 
 idea.  I have considered going further and preparing presentation slides 
 using Jupyter.  I know this can be done but many of the search engine hits 
 on the topic seem out of date.  Can anyone suggest a discussion or sample 
 notebook regarding this?


A very nice option is the RISE package:

https://github.com/damianavila/RISE

This allows to present from a *live* Jupyter notebook, i.e. you can edit on 
top of the presentation,
and go backwards and forwards (e.g. when preparing) between the notebook 
view and the slideshow view.

It was created by the same person who did the static Jupyter slideshow 
conversion (Damián Ávila)
and uses the same interface from within notebooks ('Slide', 'Sub-slide' 
etc. dropdowns).
It installs a new icon in the Jupyter toolbar that launches the slideshow.

David.


[julia-users] Re: Using composite types with many fields

2015-06-20 Thread David P. Sanders

Christoph's solution is neat.

Another possibility is to just start with an empty object, by defining an 
inner constructor that 
does not define any of the fields, and then fill it up, as you were (IIUC) 
looking for.
As far as I am aware, there is not any problem with doing this.

type MyType
a::Float64
b::Int64
c::UTF8String
d::Vector{Int}

MyType() = new()
end

t = MyType()

t.a = 17.
t.b = -3
t.c = Hello
t.d = [3, 4]

Note that an error will occur if you try to read any field that has not yet 
been defined.

David.


El sábado, 20 de junio de 2015, 14:43:03 (UTC-5), Stef Kynaston escribió:

 I feel I am missing a simpler approach to replicating the behaviour of a 
 Matlab structure. I am doing FEM, and require structure like behaviour for 
 my model initialisation and mesh generation. Currently I am using composite 
 type definitions, such as:

 type Mesh
 coords   :: Array{Float64,2}  
 elements   :: Array{Float64,2}  
 end

 but in actuality I have many required fields (20 for Mesh, for example). 
 It seems to me very impractical to initialise an instance of Mesh via

 mesh = Mesh(field1, field2, field3, ..., field20),

 as this would require a lookup of the type definition every time to ensure 
 correct ordering. None of my fields have standard default values.

 Is there an easier way to do this that I have overlooked? In Matlab I can 
 just define the fields as I compute their values, using Mesh.coords = 
 ..., and this would work here except that I need to initialise Mesh before 
 the . field referencing will work.

 First post, so apologies if I have failed to observe etiquette rules. 



Re: [julia-users] inverse function error?

2015-06-18 Thread David P. Sanders


El jueves, 18 de junio de 2015, 22:18:48 (UTC+2), Mauro escribió:

 I don't know why Y does not get its type inferred correctly.  But you 


Array comprehensions in global scope never (?) have their types inferred.
You can try putting the array comprehension inside a 
function -- this may (or may not) help.

[Note that to avoid performance problems, you should in fact avoid as much
as possible having *anything* global -- everything should be in a function.]

David.
 

 can do: 
 eltype(df[2])[df[i,2] for i in 1:size(df,1)] 

 On Thu, 2015-06-18 at 20:21, SG david...@gmail.com javascript: wrote: 
  #= This line adds functions to take   
 an AR(2) model for US inflation   
  =# 

  using DataFrames 

  function lag0(x,p) 
   R::Int32=size(x,1) 
   C::Int32=size(x,2) 

  # Take the first R-p rows of matrix x 
   x1=x[1:(R-p),:] 
   return out=[zeros(p,C); x1] 

  end 


  #load inflation datatable 
  #df=readtable(inflation.csv) 

  df=DataFrame() 
  df[:A]=1:8 
  df[:B]=10:17 

  ## 
  # Way of converting DataArray to Array  # 
  ## 
  Y=[df[i,2] for i in [1:size(df,1)]] 

  ##  type of (Y) is now Any   


  T=size(Y,1) 
  X=[ones(T,1) lag0(Y,1) lag0(Y,2)] 
  inv(X'*X) 
  
  == 
  
  Hi All, 
  
  I am posting again the issue. I found when I create an Array as shown 
  above, the type of Array 
  changed to Any which is not acceptable for the base Inverse 
 function(an 
  error occurred). 
  I am wondering why Julia does not assume the type of original data, here 
 in 
  the example, Int64. 
  
  Many thanks, 
  
  
  
  
  
  
  On Thursday, June 18, 2015 at 7:23:16 PM UTC+2, SG wrote: 
  
  Thank you, I will cut it down and post it again soon. 
  
  On Thursday, June 18, 2015 at 7:01:16 PM UTC+2, Stefan Karpinski wrote: 
  
  I think these sample programs may be too big for people to review for 
  you. If you can pare the problem down to an example that can be posted 
 in 
  an email, you've more likely to get help. 
  
  On Thu, Jun 18, 2015 at 11:11 AM, SG david...@gmail.com wrote: 
  
  
  Hi All, 
  
  I am a novice to Julia. 
  
  While I am running the attached julia program, I found inverse 
  function throws an error? 
  However it worked well in Matlab. Can you help me? Many thanks. 
  
  
  
  
  



[julia-users] Hands-on Julia workshop materials

2015-06-17 Thread David P. Sanders
Dear all,

I have just finished giving a 2-day Julia workshop in Paris for scientists 
who already had some knowledge
on scientific computing. The materials (Jupyter notebooks) are available at

https://github.com/dpsanders/hands_on_julia/

This is somewhat different from most previous materials, since I have tried 
to make it
more hands-on, in the sense that it asks the user to try things out and 
guess the syntax,
rather than just giving the answer straight away. This can be more 
frustrating, but also more
educational!

Please let me know if you find this useful; pull requests with corrections 
etc. are, of course,
more than welcome!

David.


[julia-users] How to deploy Julia

2015-06-14 Thread David P. Sanders
Out of interest, does your code use arrays (for positions if the particles 
etc?) If so, does it use standard Julia arrays? 

David

[julia-users] Re: Constructing a block diagonal matrix from an array of square matrices

2015-06-03 Thread David P. Sanders


El miércoles, 3 de junio de 2015, 19:07:19 (UTC+2), Marc Gallant escribió:

 If I have an array of square matrices of different sizes; e.g.,

 3-element Array{Array{Float64,2},1}:
  2x2 Array{Float64,2}:
  0.539932  0.429322
  0.623487  0.0397795
  2x2 Array{Float64,2}:
  0.35508   0.700551
  0.768214  0.954056
  3x3 Array{Float64,2}:
  0.953354  0.453831   0.991583
  0.159975  0.116518   0.355275
  0.791447  0.0104295  0.151609


 Where the number of elements may be much larger than 3 (e.g., 1000), how 
 do I construct a block diagonal matrix, where the blocks are the matrices 
 in the array? For the array above, this would be

 7x7 Array{Float64,2}:
  0.539932  0.429322   0.0   0.0   0.0   0.00.0
  0.623487  0.0397795  0.0   0.0   0.0   0.00.0
  0.0   0.00.35508   0.700551  0.0   0.00.0
  0.0   0.00.768214  0.954056  0.0   0.00.0
  0.0   0.00.0   0.0   0.953354  0.453831   0.991583
  0.0   0.00.0   0.0   0.159975  0.116518   0.355275
  0.0   0.00.0   0.0   0.791447  0.0104295  0.151609



One way would be to create a matrix of zeros and just insert the non-zero 
elements in the correct places, e.g.
julia A = [ 0.539932  0.429322;
0.623487  0.0397795]

julia M = zeros(4,4)
4x4 Array{Float64,2}:
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0

julia M[1:2, 1:2] = A
2x2 Array{Float64,2}:
 0.539932  0.429322 
 0.623487  0.0397795

julia M[3:4, 3:4] = A^2
2x2 Array{Float64,2}:
 0.559203  0.248883
 0.361443  0.269259

julia M
4x4 Array{Float64,2}:
 0.539932  0.429322   0.0   0.0 
 0.623487  0.0397795  0.0   0.0 
 0.0   0.00.559203  0.248883
 0.0   0.00.361443  0.269259

It would not be too hard to write a routine to take in the vector of 
matrices and keep track automatically
of where they should be inserted.


  1   2   3   >