Re: [julia-users] "for" and "function" don't work in the same way in terms of scope

2015-03-11 Thread Wendell Zheng
*I cite what StefanKarpinski said in issue 423. Is it the ultimate answer?* *StefanKarpinski *commented on 22 Feb 2012 Here's an idea for how to fix this. The idea is to have "hard scope" and "soft scope". Functions introduce "

[julia-users] Why is Forward Reference possible?

2015-03-11 Thread Wendell Zheng
Consider the following function: f = ()->i "i" is used before being defined. Why is it possible? How does the compiler compile it? And then when I run f() it gives me an ERROR. Is it a compiling error or a run-time error?

Re: [julia-users] Specifying return type of a function

2015-03-11 Thread Mauro
You can use Base.return_types to see what return types are inferred. On Tue, 2015-03-10 at 23:54, Shivkumar Chandrasekaran <00s...@gmail.com> wrote: > Just documentation and readability of the functions themselves. For now I > will just stick the return type in a comment (and hope I don't forget

Re: [julia-users] "for" and "function" don't work in the same way in terms of scope

2015-03-11 Thread Wendell Zheng
I did more experiments. *Input 1:* y = 0 begin y = 10 end y *Output 1:* 10 *Input 2:* y = 0 begin local y = 10 end y *Output 2:* 0 It's the same for *if *block. May I conclude that: 1) *Function *introduces *hard scope, *where the assignment introduce new local variables; 2) Other

[julia-users] Re: Why is Forward Reference possible?

2015-03-11 Thread Yuuki Soho
I think Julia implicitly assume that i is a global variable, i.e. your function is equivalent to f = () -> begin global i return i end So it compiles but throws an error at run-time if i is not defined in the global scope.

[julia-users] Re: Function roots() in package Polynomial

2015-03-11 Thread Sheehan Olver
Thought I'd do a self-plug and mention that you can do this and other polynomial manipulations in ApproxFun.jl (which uses a colleague matrix and gets 10 digits accuracy for this example): using ApproxFun f=Fun(x->prod([1.0:20.0]-x),[0,20],21) roots(f) On Tuesday, May 6, 2014 at 6:14:44 AM UTC+

Re: [julia-users] Re: Why is Forward Reference possible?

2015-03-11 Thread Tamas Papp
I wish Julia issued a warning in this case -- maybe there is an issue about this, but I could not find it. Tamas On Wed, Mar 11 2015, Yuuki Soho wrote: > I think Julia implicitly assume that i is a global variable, i.e. your > function is equivalent to > > f = () -> begin > global i > re

Re: [julia-users] @async weirdness

2015-03-11 Thread Ben Arthur
nice catch amit. perhaps most importantly, one can demonstrate that all the commands are executed, just not printed to the REPL, with the following code. this is what i was most worried about. though the inconsistent printing does not inspire confidence. julia> @async (println("foo");println("

Re: [julia-users] Re: Julia T-shirt and Sticker

2015-03-11 Thread Ben Arthur
i have the opposite problem-- my wife is named julia, and everyone suspects i use the language julia because of an emotional attachment to my wife, not because it is such a great language :) On Wednesday, June 25, 2014 at 3:10:36 PM UTC-4, Stéphane Laurent wrote: > > My ex-girl friend suspecte

[julia-users] How to interpolate a variable as a macro argument?

2015-03-11 Thread Kaj Wiik
I have a problem in using variables as argument for macros. Consider a simple macro: macro testmacro(N) for i = 1:N println("Hello!") end end @testmacro 2 Hello! Hello! So, all is good. But if I use a variable as an argument, n = 2 @testmacro n I get an (understandable) err

[julia-users] Re: Why is Forward Reference possible?

2015-03-11 Thread Wendell Zheng
Hum, this is not exactly the case. I tried this code: *Input 1:* workspace() function foo() f = () -> i i = 1 f() end foo() *Output 1:* 1 *Input 2:* workspace() function foo() f = () -> begin global i return i end i = 1 f() end foo() *Output 2:* i not

[julia-users] permuting rows of a matrix

2015-03-11 Thread Davide Lasagna
Hi, permute!(v, p) permutes the elements of v according to the permutation vector p. Is there any equivalent built in function for permuting rows of a matrix? Given the memory layout of julia matrices it should not be too difficult to have a similar function for matrices as well. Thanks,

Re: [julia-users] @async weirdness

2015-03-11 Thread Stefan Karpinski
I'm seeing the same behavior. I wonder if this has to do with the REPL clearing the terminal or doing other funny business with it. If you printed something, and the REPL immediately cleared the line or does some other funky non-linear terminal stuff, that could explain this sort of thing. On Wed,

Re: [julia-users] Specifying return type of a function

2015-03-11 Thread Shiv
That is good to know. Thanks. On Mar 11, 2015 2:17 AM, "Mauro" wrote: > You can use Base.return_types to see what return types are inferred. > > On Tue, 2015-03-10 at 23:54, Shivkumar Chandrasekaran <00s...@gmail.com> > wrote: > > Just documentation and readability of the functions themselves. Fo

Re: [julia-users] permuting rows of a matrix

2015-03-11 Thread Mauro
Have a look at the permute! function in julia: @less permute!([1,2], [1,2]) Modifying it to function permute!!{T<:Integer}(a, i, p::AbstractVector{T}) count = 0 start = 0 while count < length(a) ptr = start = findnext(p, start+1) temp = a[i,start] next = p[star

[julia-users] Re: How to interpolate a variable as a macro argument?

2015-03-11 Thread Simon Danisch
This is most likely not the right place to use eval! You need to define your problem better. What you describe here doesn't need a macro whatsoever. Macros are for manipulating the syntax tree, which is why the arguments are not the values, but expressions. What a macro is intended to do is more

Re: [julia-users] permuting rows of a matrix

2015-03-11 Thread Davide Lasagna
Thanks, I will have a look at this. Is there some interest to have this in base? Davide On Wednesday, March 11, 2015 at 1:38:34 PM UTC, Mauro wrote: > > Have a look at the permute! function in julia: > @less permute!([1,2], [1,2]) > > Modifying it to > > function permute!!{T<:Integer}(a, i, p

Re: [julia-users] How to interpolate a variable as a macro argument?

2015-03-11 Thread Stefan Karpinski
On Wed, Mar 11, 2015 at 8:37 AM, Kaj Wiik wrote: > Is this the correct place to use eval() in macros There is no correct place to use eval in macros. Macros transform one symbolic expression into another and should generally be pure functions with no side effects. You don't get access to the va

Re: [julia-users] permuting rows of a matrix

2015-03-11 Thread Tim Holy
A[p, :] --Tim On Wednesday, March 11, 2015 05:49:47 AM Davide Lasagna wrote: > Hi, > > > permute!(v, p) permutes the elements of v according to the permutation > vector p. > > Is there any equivalent built in function for permuting rows of a matrix? > Given the memory layout of julia matrices

Re: [julia-users] permuting rows of a matrix

2015-03-11 Thread Davide Lasagna
But A[p, :] makes copies, and I want it to be in place. Davide On Wednesday, March 11, 2015 at 2:02:31 PM UTC, Tim Holy wrote: > > A[p, :] > > --Tim > > On Wednesday, March 11, 2015 05:49:47 AM Davide Lasagna wrote: > > Hi, > > > > > > permute!(v, p) permutes the elements of v according to

Re: [julia-users] permuting rows of a matrix

2015-03-11 Thread Tim Holy
Good that you clarified that, but are you aware that permute! makes a copy of the permutation? So there's no memory savings, and it's about 4x slower than an out-of-place copy. --Tim On Wednesday, March 11, 2015 07:09:38 AM Davide Lasagna wrote: > But A[p, :] makes copies, and I want it to be i

Re: [julia-users] permuting rows of a matrix

2015-03-11 Thread Davide Lasagna
Well, thanks Tim for pointing this out. Cheers, Davide On Wednesday, March 11, 2015 at 2:42:38 PM UTC, Tim Holy wrote: > > Good that you clarified that, but are you aware that permute! makes a copy > of > the permutation? So there's no memory savings, and it's about 4x slower > than > an ou

[julia-users] Type system question

2015-03-11 Thread Michael Francis
After moving some code around I get the following error - I don't have a small test case ERROR: `get` has no method matching get(::Dict{WeakRef,CalcState}, ::WeakRef, :: CalcState) It looks like the type system is getting confused ? Any pointers in how to resolve ?

[julia-users] Re: Error array could not be broadcast to a common size

2015-03-11 Thread David P. Sanders
It seems the implementation of `ode23` in Julia is still too basic, so there isn't a way of passing the parameters through to the function. In Julia 0.4 you will be able to make a type that behaves like a function which can store its own parameters to get round this problem. There is also the S

[julia-users] Saving timing results from @time

2015-03-11 Thread Patrick Kofod Mogensen
I am testing the run times of two different algorithms, solving the same problem. I know there is the @time macro, but I cannot seem to wrap my head around how I should save the printed times. Any clever way of doing this? I thought I would be able to [@time algo(input) for i = 1:500], but thi

Re: [julia-users] Saving timing results from @time

2015-03-11 Thread Andreas Noack
@elapsed is what you are looking for 2015-03-11 7:43 GMT-04:00 Patrick Kofod Mogensen : > I am testing the run times of two different algorithms, solving the same > problem. I know there is the @time macro, but I cannot seem to wrap my head > around how I should save the printed times. Any clever

Re: [julia-users] How can I convert a set to an array?

2015-03-11 Thread Jacob Quinn
a = IntSet([1,2,3]) a = [a...] On Wed, Mar 11, 2015 at 9:35 AM, Ali Rezaee wrote: > In Python I would do > > a = set([1,2]) > a = list(a) > > How can I do that in Julia? > > Thanks a lot in advance for your help >

Re: [julia-users] How can I convert a set into an array?

2015-03-11 Thread René Donner
Hi, try: a = IntSet([1,2,1,3]) collect(a) that gives you a 3-element Array{Int64,1}. This also work with ranges, like collect(1:3) Cheers, Rene Am 11.03.2015 um 17:03 schrieb Ali Rezaee : > In Python I would normally to something like this: > > a = set([1,2,1,3]) > a = list(a) > >

Re: [julia-users] Why don't copied arrays change in function calls?

2015-03-11 Thread Isaiah Norton
To assign new values in-place to the existing 'b' array, change this line: b=copy(a) to b[:] = a I've also tried with do loops, but this causes a segmentation fault. Segfaults in pure-Julia code (no user-defined ccalls) are almost always considered a bug -- could you post an example, or ideal

Re: [julia-users] how to paste png into ipython julia notebook?

2015-03-11 Thread Isaiah Norton
That is Python code, so it won't work in IJulia. You might be able to use PyCall: https://github.com/stevengj/PyCall.jl Or use the Julia Images package to load the file: https://github.com/timholy/Images.jl Once you have an image loaded, then `display(img)` should work. On Wed, Mar 11, 2015 at 9

[julia-users] Re: Type system question

2015-03-11 Thread Michael Francis
If I locally define function myget{K,V}(h::Dict{K,V}, key, default) index = Base.ht_keyindex(h, key) return (index<0) ? default : h.vals[index]::V end and change my code to use this myget it all works fine. So it looks like the function resolution on get has lost the plot ? On Wednesd

[julia-users] Re: Memory allocation in Closed loop Control Simulation

2015-03-11 Thread Iain Dunning
Hi Bartolomeo, How are you getting that 600 MB figure? That was about the peak memory consumption for me reported by Activity Monitor, but that doesn't necessarily mean its all being used. I actually ran the code (twice), and I didn't notice it really "accumulating" memory across multiple runs,

Re: [julia-users] permuting rows of a matrix

2015-03-11 Thread Kevin Squire
If you don't mind losing the original permutation (it's overwritten), you can use Base.permute!! (unexported). However, in most cases, this is still actually slower than A[p]. Not sure how that would be for sorting rows/columns. Kevin On Wed, Mar 11, 2015 at 7:49 AM, Davide Lasagna wrote: > W

Re: [julia-users] Saving timing results from @time

2015-03-11 Thread Patrick Kofod Mogensen
It is indeed, thank you. I was also told that @timeit might do something along the lines of what I am doing. On Wednesday, March 11, 2015 at 5:07:24 PM UTC+1, Andreas Noack wrote: > > @elapsed is what you are looking for > > 2015-03-11 7:43 GMT-04:00 Patrick Kofod Mogensen >: > >> I am testing

[julia-users] Re: Type system question

2015-03-11 Thread Michael Francis
The answer was a misplaced get definition in a module which was not prefixed by Base workspace() module mess get() = 1 function foo() dict = Dict{String,Float64}() dict["hello"] = 1.23 get( dict, "hello", 2.3) end export foo end using mess foo() On Wednesday, March 11, 2015 at 12:43:46 PM

Re: [julia-users] Saving timings from @time

2015-03-11 Thread Stefan Karpinski
You can use @elapsed instead of @time. On Wed, Mar 11, 2015 at 8:03 AM, Patrick Kofod Mogensen < patrick.mogen...@gmail.com> wrote: > This might be sort of a duplicate posts, but I think the other post wasn't > actually posted, so I'll try again. > > If I time a function 500 times and want to sav

Re: [julia-users] Saving timings from @time

2015-03-11 Thread Patrick Kofod Mogensen
Thank you for replying, but unfortunately I double posted, because I didn't think the first one was posted (https://groups.google.com/forum/#!topic/julia-users/yhe3fN9TTMQ). On Wednesday, March 11, 2015 at 5:52:19 PM UTC+1, Stefan Karpinski wrote: > > You can use @elapsed instead of @time. > >

Re: [julia-users] Type system question

2015-03-11 Thread Keno Fischer
Did you perhaps accidentally redefine get locally? What version of julia are you on? Do you get the nearest matching methods (I think that's only on 0.4)? Can you give the output of methods(get) at whatever point it's failing? On Wed, Mar 11, 2015 at 11:30 AM, Michael Francis wrote: > After movi

Re: [julia-users] Saving timings from @time

2015-03-11 Thread Stefan Karpinski
We filter first-time posts from users since otherwise this mailing list would have a fair amount of recruiting spam on it. On Wed, Mar 11, 2015 at 12:59 PM, Patrick Kofod Mogensen < patrick.mogen...@gmail.com> wrote: > Thank you for replying, but unfortunately I double posted, because I > didn't

Re: [julia-users] webpy equivalent

2015-03-11 Thread paul analyst
Hi Masters Hi , I try raun Medle , all is ok only cant find dir for root. Wher put my file index.html ? Paul

Re: [julia-users] Saving timing results from @time

2015-03-11 Thread Patrick Kofod Mogensen
The is true, and that is also what I wanted to do. When using @elapsed, should I then be worried about garbage collection affecting my times? On Wednesday, March 11, 2015 at 5:57:57 PM UTC+1, Stefan Karpinski wrote: > > I generally find that using a comprehension around @elapsed is pretty > ters

Re: [julia-users] How to unpack a .tar file in Julia?

2015-03-11 Thread Weijian Zhang
All right, thanks. On Tuesday, 10 March 2015 20:33:06 UTC, Stefan Karpinski wrote: > > I would just shell out to the tar command and then work with the untarred > directory. > > On Tue, Mar 10, 2015 at 4:05 PM, Weijian Zhang > wrote: > >> Hello, >> >> I have a .tar.gz file. With GZip.jl, I can w

[julia-users] Re: Saving timing results from @time

2015-03-11 Thread Simon Danisch
I'm working a little bit on a benchmarking suite. It's not available yet, but here is a piece of code which gives you some more functionality than @elapsed: https://gist.github.com/SimonDanisch/4b8f236e35cd07a58efc#file-benchmark-jl Best, Simon Am Mittwoch, 11. März 2015 17:05:07 UTC+1 schrieb

[julia-users] Re: How to interpolate a variable as a macro argument?

2015-03-11 Thread Kaj Wiik
Of course this was a simplified example to show the problem. A bad one, I admit. My question relates to the problem you (Simon) provided one answer already. I certainly have read Metaprogramming chapter and tried everything I could think of without luck. However, it could well be that I am jus

Re: [julia-users] Re: How to interpolate a variable as a macro argument?

2015-03-11 Thread Stefan Karpinski
The way to do this is by wrapping an @eval around the macro invocation and splicing $n: @eval @gentype $n UInt8 This might be necessary, e.g. if you're looping over various values of n: for n = 1:10 @eval @gentype $n UInt8 end On Wed, Mar 11, 2015 at 2:52 PM, Kaj Wiik wrote: > > Of co

Re: [julia-users] Saving timing results from @time

2015-03-11 Thread Ivar Nesje
> > The is true, and that is also what I wanted to do. When using @elapsed, > should I then be worried about garbage collection affecting my times? When making benchmarks you should worry about everything!, and make efforts to ensure that your synthetic results actually extrapolates to the cod

[julia-users] Re: Saving timing results from @time

2015-03-11 Thread Simon Danisch
Yeah, especially if you can immediately plot the results and things like this. But don't get your hopes up to high, unless something unexpected happens, I won't have much time for this :( There is johnmyleswhite/Benchmark.jl , though. But it has a

[julia-users] Return type of ./ and / on array of arrays

2015-03-11 Thread Robert Gates
Dear Julia users, while overloading ./ and / for some arrays of custom types and encountering type instability, I've noticed that the standard ./ functions behave similarly: *julia> **Base.return_types((./), (Array{Array{Float64,1},1}, Array{Array{Float64,1},1}))* *1-element Array{Any,1}:* *

[julia-users] Return type of ./ and / for array of arrays

2015-03-11 Thread Robert Gates
Dear Julia users, while overloading ./ and / for some arrays of custom types and encountering type instability, I've noticed that the standard ./ functions behave similarly: *julia> **Base.return_types((./), (Array{Array{Float64,1},1}, Float64))* *1-element Array{Any,1}:* *Array{Any,1}* *j

[julia-users] Re: webpy equivalent

2015-03-11 Thread jock . lawrie
Hi Jonathan, Uncanny timing. Here is an example of Julia working with the Mustache.jl package which I posted just a couple of hours before your post. It works fine but is not nearly as mature as webpy. Hope you find it helpful. Cheers, Jock

Re: [julia-users] Re: How to interpolate a variable as a macro argument?

2015-03-11 Thread Kaj Wiik
That was it! This is a great community, many thanks for your time all! Cheers. Kaj On Wednesday, March 11, 2015 at 8:56:26 PM UTC+2, Stefan Karpinski wrote: > > The way to do this is by wrapping an @eval around the macro invocation and > splicing $n: > > @eval @gentype $n UInt8 > > > This migh

Re: [julia-users] Re: How to interpolate a variable as a macro argument?

2015-03-11 Thread Stefan Karpinski
No problem – glad we got to the bottom of it! On Wed, Mar 11, 2015 at 4:39 PM, Kaj Wiik wrote: > That was it! > > This is a great community, many thanks for your time all! > > Cheers. > Kaj > > > On Wednesday, March 11, 2015 at 8:56:26 PM UTC+2, Stefan Karpinski wrote: >> >> The way to do this i

[julia-users] How to introduce scope inside macro

2015-03-11 Thread Johan Sigfrids
I've been playing around with creating a @map macro: indexify(s::Symbol, i, syms) = s in syms ? Expr(:ref, s, i) : s indexify(e::Expr, i, syms) = Expr(e.head, e.args[1], [indexify(a, i, syms) for a in e.args[2:end]]...) indexify(a::Any, i, syms) = a macro map(expr, args...) quote @ass

Re: [julia-users] @async weirdness

2015-03-11 Thread Ben Arthur
could indeed be the REPL. the output looks fine in juliabox.

Re: [julia-users] Memory allocation in Closed loop Control Simulation

2015-03-11 Thread Tony Kelman
The majority of the memory allocation is almost definitely coming from the problem setup here. You're using a dense block-triangular fomulation of MPC, eliminating states and only solving for inputs with inequality constraints. Since you're converting your problem data to sparse initially, you'

[julia-users] Array as function

2015-03-11 Thread Diego Tapias
Quick question: what does this mean julia> Array(Int,1) 1-element Array{Int64,1}: 139838919411184 ? And another question: Is this just used for initializing an array? Thanks. ​

[julia-users] Memory allocation questions

2015-03-11 Thread Phil Tomson
I started out by putting an '@time' macro call on the function that I figured was taking the most time, results looked like: elapsed time: 8.429919506 seconds (4275452256 bytes allocated, 37.36% gc time) ... so lots of bytes being allocated. To get a better picture of where that was happening

[julia-users] Re: Array as function

2015-03-11 Thread Phil Tomson
On Wednesday, March 11, 2015 at 4:49:06 PM UTC-7, Diego Tapias wrote: > > Quick question: what does this mean > > julia> Array(Int,1) > 1-element Array{Int64,1}: > 139838919411184 > > ? > > And another question: > > Is this just used for initializing an array? > Typically you would use someth

Re: [julia-users] Memory allocation in Closed loop Control Simulation

2015-03-11 Thread Bartolomeo Stellato
At this stage I was just trying to formulate the problem in a quick way (from the implementation point of view) to test how the low level interface with Gurobi solver works. I honestly didn't try to make it quick for the solver without eliminating the states and keeping the a block banded matri

[julia-users] Re: RFC: JuliaWeb Roadmap + Call for Contributors

2015-03-11 Thread jock . lawrie
Hi all, Here is a bare bones application that fetches some data, runs a model and produces some pretty charts. I'll flesh this out over the next few months, including documentation aimed at data scientists (I'm a statistician not a web progr

[julia-users] Re: Memory allocation questions

2015-03-11 Thread Phil Tomson
I transformed it into a single-file testcase: # type NeuralLayer w::Matrix{Float32} # weights cm::Matrix{Float32} # connection matrix b::Vector{Float32} # biases scale::Vector{Float32} # a_func::Symbol # acti

Re: [julia-users] How to introduce scope inside macro

2015-03-11 Thread Tim Holy
If your _usage_ of @map is in the global scope, then it has to compile the expressions each time you use it. That may or may not be a problem for you. As an alternative that only requires compilation on the first call, try FastAnonymous or NumericFuns. --Tim On Wednesday, March 11, 2015 02:25:

Re: [julia-users] Memory allocation in Closed loop Control Simulation

2015-03-11 Thread Tim Holy
On Wednesday, March 11, 2015 05:33:10 PM Bartolomeo Stellato wrote: > I also tried with Julia 0.4.0-dev+3752 and I encounter the same problem. Hm. If you're sure there's a leak, this should be investigated. Any chance you can try valgrind? --Tim > > Il giorno mercoledì 11 marzo 2015 22:51:18 U

Re: [julia-users] Re: Array as function

2015-03-11 Thread Diego Tapias
Hey Phil, thanks for taking the time to explain. It makes sense now. Best. Diego 2015-03-11 18:20 GMT-06:00 Phil Tomson : > > > On Wednesday, March 11, 2015 at 4:49:06 PM UTC-7, Diego Tapias wrote: >> >> Quick question: what does this mean >> >> julia> Array(Int,1) >> 1-element Array{Int64,1}:

Re: [julia-users] Creating custom IJulia widgets

2015-03-11 Thread Spencer Russell
This is super helpful, thanks for writing it up! -s On Mon, Mar 9, 2015, at 11:19 AM, Avi Ruderman wrote: > Hi all, > > I spent the last couple of days building some custom IJulia widgets. I > struggled to find a clear explanation online of how to do this. So I > thought I would put together a

[julia-users] How does Measure work at y-axis in Gadfly.jl?

2015-03-11 Thread nanaya tachibana
I wanted to contribute to Gadfly.jl and I started from looking into bar.jl. I found that the value cy of Measure in Gadfly.jl increases from bottom to top, but it increases from top to bottom in Compose.jl. What makes Measure work in that way? I really appreciate any help you can provide.

[julia-users] TSNE error related to blas

2015-03-11 Thread Arshak Navruzyan
I am running the MNIST demo for the TSNE implementation in Julia but it gives me a libopenblas.dylib error *Y = tsne(array(df[:,2:end]), 2, 500, 20, 20.0)* Initial X Shape is : (42000,784) Preprocessing the data using PCA... Computing pairwise distances... signal (10): Bus error: 10 dgemm_otc