Re: [julia-users] What is the best way to create and store a multi-dimensional matrix in Julia?

2014-05-25 Thread yi lu
Hi Kevin, Let me explain it with an example. For example, one-dimensional heat equation. u_t-u_xx=f If I discrete time and space in t_0, t_1,...,t_m, and x_0,x_1,...,x_n respectively. We want to store these points. Then it is a matrix u(t_i, x_j). What I am concern is how to store such a big mat

Re: [julia-users] What is the best way to create and store a multi-dimensional matrix in Julia?

2014-05-25 Thread Kevin Squire
Hello Yi, Your question is rather open-ended. Can you give an example of the kind of multi-dimensional data you're interested in, and what you want to visualize about it? Cheers, Kevin On Sun, May 25, 2014 at 6:40 PM, yi lu wrote: > In scientific computing, we need multi-dimensional arrays

[julia-users] What is the best way to create and store a multi-dimensional matrix in Julia?

2014-05-25 Thread yi lu
In scientific computing, we need multi-dimensional arrays to *store* time and space grid points for computing and for plotting. So, what is best *recommended* to use in Julia for such requirement? What I mean by best is fastest, cheapest and so on. Thanks in advance. Yi

[julia-users] PEG Parser

2014-05-25 Thread Abe Schneider
I wrote a quick PEG Parser for Julia with Packrat capabilities: https://github.com/abeschneider/PEGParser It's a first draft and needs a ton of work, testing, etc., but if this is of interest to anyone else, here is a quick description. Grammars can be defined using most of the standard EBNF sy

[julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread Adam Smith
Jason, thank you for that link! After reading much of the prior discussions on the matter, it's clear Oliver Woodford and I share a similar viewpoint, and this has already been discussed heavily. I would still vote for covariance over invariance in this case, since arguments to functions map fi

[julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread Jason Merrill
See also https://groups.google.com/forum/#!searchin/julia-users/invariance$20covariance$20contravariance for discussions of different possibilities for handling inheritance with typed parameters. I was convinced by Stefan's arguments there that Julia's invariance is the least bad strategy. On

Re: [julia-users] Easy way to declare function works on array of floats

2014-05-25 Thread Kevin Squire
> The style guide at > http://julia.readthedocs.org/en/latest/manual/style-guide/#handle-excess-argument-diversity-in-the-callerseems > to encourage my approach, and > http://julia.readthedocs.org/en/latest/manual/style-guide/#don-t-use-unnecessary-static-parametersdirectly > condemns Iain's reco

[julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread Adam Smith
I agree to be as generic as possible. I should have used this second example instead, a quite common scenario where being generic doesn't make as much sense: function output(context::Context, strings::Vector{String}) context.something() # Call the single-string version of the function on

[julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread Jason Merrill
On Sunday, May 25, 2014 2:11:41 PM UTC-7, Adam Smith wrote: > > Actually, no. I'm not going to pretend this is a good thing. You're right > that it is "consistent and logical" when you're using an academic > type-correctness viewpoint. However, it is not consistent from a developer > perspective

Re: [julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread Adam Smith
Your response ignores my strong example. And "not declare types in function signatures" does not "work just fine most of the time," because multiple dispatch largely breaks if you don't type your arguments. You simply must type your function arguments for Julia to be able to resolve the right m

Re: [julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread Mauro Werder
On Sun, 25 May 2014 14:11:41 -0700 (PDT), Adam Smith wrote: > Actually, no. I'm not going to pretend this is a good thing. You're right > that it is "consistent and logical" when you're using an academic > type-correctness viewpoint. However, it is not consistent from a developer > perspective,

[julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread Adam Smith
Actually, no. I'm not going to pretend this is a good thing. You're right that it is "consistent and logical" when you're using an academic type-correctness viewpoint. However, it is not consistent from a developer perspective, and here's why. On most functions, I don't need to specify parametr

[julia-users] Re: How to speed up this code

2014-05-25 Thread Viral Shah
There are improvements planned, which should make it possible to write the code as you originally wrote. For now though, you will have to write it C style if you want the highest performance. -viral On Monday, May 26, 2014 12:00:50 AM UTC+5:30, Christoph Ortner wrote: > > > Thank you both for t

[julia-users] Re: How quickly calculate distances arrays etc.

2014-05-25 Thread Jason Merrill
There are optimized distance calculations for a number of different metrics in Distance.jl: https://github.com/JuliaStats/Distance.jl On Sunday, May 25, 2014 1:42:15 AM UTC-7, paul analyst wrote: > > How quickly calculate distances arrays etc. > > This is an array of quotients, on the diagonal mu

Re: [julia-users] How to code this trivial example in julia

2014-05-25 Thread Kevin Squire
Yep, thanks! I was a bit hasty. On Sunday, May 25, 2014, Ismael VC wrote: > It should be: > > type Person > lastname::String > firstname::String > end > > fullname(p::Person) = "$(p.firstname) $(p.lastname)" > > jan = Person("Janssen", "Jan") > > println(fullname(jan)) > > >

[julia-users] Re: How to speed up this code

2014-05-25 Thread Christoph Ortner
> Thank you both for the suggestions. I've re-written the code >> JULIA3, with > amazing results. JULIA2 was the previous "optimised" code. > > Test 1, J2: 0.751340928, J3: 0.008927998, C: 0.007420171; max-error = 0.0 Test 2, J2: 0.7136, J3: 0.009042345, C: 0.007583811; max-error = 0.0 Tes

[julia-users] Re: How to speed up this code

2014-05-25 Thread Christoph Ortner
> > Thank you both for the suggestions. I've re-written the code >> JULIA3, with > amazing results. JULIA2 was the previous "optimised" code. > > Test 1, J2: 0.751340928, J3: 0.008927998, C: 0.007420171; max-error = 0.0 Test 2, J2: 0.7136, J3: 0.009042345, C: 0.007583811; max-error = 0.0 Te

[julia-users] Re: Convert Array{Array{Float64}, 1} to Array{Float64, 2}

2014-05-25 Thread Freddy Chua
cool, thanks! On Monday, May 26, 2014 1:57:28 AM UTC+8, Ethan Anderes wrote: > > I love the ... notation. It splats the entries into separate arguments > separated by commas into the function. > > julia> y = "abcd" > "abcd" > > julia> [y...] == ['a', 'b', 'c', 'd'] > true > > On Sunday, May 25,

[julia-users] Re: Convert Array{Array{Float64}, 1} to Array{Float64, 2}

2014-05-25 Thread Ethan Anderes
I love the ... notation. It splats the entries into separate arguments separated by commas into the function. julia> y = "abcd" "abcd" julia> [y...] == ['a', 'b', 'c', 'd'] true On Sunday, May 25, 2014 10:49:05 AM UTC-7, Freddy Chua wrote: hang on, what does the "..." in hcat(a...) means >

[julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread Adam Smith
You're right, that's not bad at all. Thanks. On Sunday, May 25, 2014 12:41:04 PM UTC-4, Iain Dunning wrote: > > julia> f{T<:String}(strs::Vector{T}) = dump(strs) > f (generic function with 1 method) > > julia> f(["foo"]) > Array(ASCIIString,(1,)) ASCIIString["foo"] > > > Seems fine to me, and more

[julia-users] Re: Convert Array{Array{Float64}, 1} to Array{Float64, 2}

2014-05-25 Thread Freddy Chua
hang on, what does the "..." in hcat(a...) means On Monday, May 26, 2014 1:47:21 AM UTC+8, Ethan Anderes wrote: > > Right, hcat(a…) does that (up to a transpose since julia stores things in > column major order ). > > julia> a = Array(Array, 0) > 0-element Array{Array{T,N},1} > > julia> push!(a,

[julia-users] Re: Convert Array{Array{Float64}, 1} to Array{Float64, 2}

2014-05-25 Thread Ethan Anderes
Right, hcat(a…) does that (up to a transpose since julia stores things in column major order ). julia> a = Array(Array, 0) 0-element Array{Array{T,N},1} julia> push!(a, [1, 2]) 1-element Array{Array{T,N},1}: [1,2] julia> push!(a, [3, 4]) 2-element Array{Array{T,N},1}: [1,2] [3,4] julia> b

[julia-users] Re: Convert Array{Array{Float64}, 1} to Array{Float64, 2}

2014-05-25 Thread Freddy Chua
I mean, is there a function that allows me to take in a and return a matrix? b = convert_to_matrix(a) b[:, 2] = [2,4] On Monday, May 26, 2014 1:36:47 AM UTC+8, Freddy Chua wrote: > > For example > > a = Array(Array, 0) > > push!(a, [1, 2]) > push!(a, [3, 4]) > > Gives me an array of array. Can I

[julia-users] Convert Array{Array{Float64}, 1} to Array{Float64, 2}

2014-05-25 Thread Ethan Anderes
hcat(a...) will return the matrix form of a. Is that what you want?

Re: [julia-users] Convert Array{Array{Float64}, 1} to Array{Float64, 2}

2014-05-25 Thread John Myles White
You can, but probably not without memory allocation since your Array of Array’s isn’t a continguous block of memory. — John On May 25, 2014, at 10:36 AM, Freddy Chua wrote: > For example > > a = Array(Array, 0) > > push!(a, [1, 2]) > push!(a, [3, 4]) > > Gives me an array of array. Can I g

[julia-users] Convert Array{Array{Float64}, 1} to Array{Float64, 2}

2014-05-25 Thread Freddy Chua
For example a = Array(Array, 0) push!(a, [1, 2]) push!(a, [3, 4]) Gives me an array of array. Can I get a matrix easily in this way?

[julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread Iain Dunning
julia> f{T<:String}(strs::Vector{T}) = dump(strs) f (generic function with 1 method) julia> f(["foo"]) Array(ASCIIString,(1,)) ASCIIString["foo"] Seems fine to me, and more importantly (to me), is consistent and logical. Vector{String} is a concrete type, its a specific thing. Vector{T},T<:Str

[julia-users] Re: How to speed up this code

2014-05-25 Thread Iain Dunning
Hard to test without some way of generating data, but I'd guess the problem is dE[:, k] += dJ dE[:, n] -= dJ which (unfortunately) actually expands to dE[:, k] = dE[:, k] + dJ dE[:, n] = dE[:, n] - dJ so there is a new array being created on the right-hand-side - it isn't an inplace ope

Re: [julia-users] How to speed up this code

2014-05-25 Thread Milan Bouchet-Valat
Le dimanche 25 mai 2014 à 07:39 -0700, Christoph Ortner a écrit : > > > > I just started experimenting with Julia, as a platform for rapid > prototyping for some more exotic molecular modelling applications > where no black-box software exists. So far I like very much what I > find. To test its

[julia-users] How to speed up this code

2014-05-25 Thread Christoph Ortner
I just started experimenting with Julia, as a platform for rapid prototyping for some more exotic molecular modelling applications where no black-box software exists. So far I like very much what I find. To test its performance, I implemented a simple Lennard-Jones energy and force assembly 5

[julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread Adam Smith
I'd just like to add that this behavior is a real downer when dealing with strings, too. During testing/debugging inline strings are ASCIIStrings, but I don't want to hardcode my functions to use ASCIIStrings (or have to make Unions absolutely every place I want a vector of strings): julia> f(s

[julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread Pierre-Yves Gérardy
On Sunday, May 25, 2014 5:44:26 PM UTC+2, Pierre-Yves Gérardy wrote: > > On Sunday, May 25, 2014 5:10:49 PM UTC+2, James Crist wrote: >> >> Yeah, that's what I've been using. My issue with it is that the >> declarations get long for functions with more than 2 arrays. Was hoping >> there was a m

[julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread Pierre-Yves Gérardy
On Sunday, May 25, 2014 5:10:49 PM UTC+2, James Crist wrote: > > Yeah, that's what I've been using. My issue with it is that the > declarations get long for functions with more than 2 arrays. Was hoping > there was a more concise way. > You can use typealias Fp FloatingPoint , then function fo

Re: [julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread James Crist
Is that preferable? The function is only defined for floats (integers or complex wouldn't make any sense). Checking would have to occur inside the function then, while I thought that it was more preferable to have the type dispatch do that. On Sunday, May 25, 2014 10:20:00 AM UTC-5, Mauro wrote

Re: [julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread Mauro Werder
I think there is nothing shorter, if you need to dispatch on the type (e.g. if you also have a `foobar` function for say Intergers as well). Otherwise a function `foobar(a,b)` without type information works just as well and as fast as it will be compiled for the specific input types. On Sun,

[julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread James Crist
Yeah, that's what I've been using. My issue with it is that the declarations get long for functions with more than 2 arrays. Was hoping there was a more concise way. On Sunday, May 25, 2014 8:16:58 AM UTC-5, Steven G. Johnson wrote: > > On Sunday, May 25, 2014 9:14:46 AM UTC-4, Steven G. Johnson

Re: [julia-users] How do I get the reduced start up time for Julia 0.3-prerelease when installing from a binary package?

2014-05-25 Thread Omar Antolín Camarena
Just a quick update: the Ubuntu nightlies have had 3 updates since your post and still no sys.so. There might be plans to fix this, but in the mean time it looks like the easiest way to get the faster start up time is to compile from source. It is also possible that with a binary package there

[julia-users] Re: How to code this trivial example in julia

2014-05-25 Thread Ismael VC
It should be: type Person lastname::String firstname::String end fullname(p::Person) = "$(p.firstname) $(p.lastname)" jan = Person("Janssen", "Jan") println(fullname(jan))

[julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread Steven G. Johnson
On Sunday, May 25, 2014 9:14:46 AM UTC-4, Steven G. Johnson wrote: > > function foo{T1<:FloatingPoint, T2<:FloatingPoint)(a::Array{T2}, > b::Array{T2}) > Whoops, two typos. This should be: function foo{T1<:FloatingPoint, T2<:FloatingPoint}(a::Array{T1}, b::Array{T2})

[julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread Steven G. Johnson
On Sunday, May 25, 2014 3:39:33 AM UTC-4, gael@gmail.com wrote: > But, > function foo(a::Array{FloatingPoint}, b::Array{FloatingPoint}) > a + b > end > is unfortunately not working. I don't know whether this is a bug or a > choice. > This is not a bug, it just doesn't mean what you t

[julia-users] Re: How quickly calculate distances arrays etc.

2014-05-25 Thread Steven G. Johnson
This should be reasonably fast: function dist(F) s = sum(F,1) O = reshape(s, length(s)) ./ s for i = 1:size(O,1); O[i,i] = 0; end return O end

[julia-users] Re: Fast, robust predicates with Julia

2014-05-25 Thread Ariel Keselman
when using hulls to calculate Delaunay then you calculate everything in d+1 dimensions, which for 2D has a 4X slower predicate. Also predicates are mostly precalculated (already implemented in the updated gist above), so their repeated calculation in the "swap" method should be fast. Anyway, le

[julia-users] How quickly calculate distances arrays etc.

2014-05-25 Thread paul analyst
How quickly calculate distances arrays etc. This is an array of quotients, on the diagonal must be zero. Are there any features that quickly count this type of arrays? Data in F... k=size(F,2); O=zeros(k,k); for o=0:k-2; for i=1:k-1-o j=i+1+o; O[i,j]=sum(F[:,i])/sum(F[:,j]); O[j,i]=1/O[i,j]; en

[julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread gael . mcdon
Le dimanche 25 mai 2014 08:29:02 UTC+2, James Crist a écrit : > > I've been struggling with this for a while, and haven't found a way to do > it that I'm happy with. I'm sure there is one though. Basically, I want to > declare a function that works on an array of floats. Doesn't matter what >

[julia-users] Re: Easy way to declare function works on array of floats

2014-05-25 Thread gael . mcdon
Le dimanche 25 mai 2014 08:29:02 UTC+2, James Crist a écrit : > > I've been struggling with this for a while, and haven't found a way to do > it that I'm happy with. I'm sure there is one though. Basically, I want to > declare a function that works on an array of floats. Doesn't matter what > ki