[julia-users] Using append! with types Array{Int64,1}

2014-07-22 Thread Frederico Novaes
Hi,

I started using Julia last week, so newbie. Here is the issue I'm having:

- I want to store a certain unknown number of elements like [1,2] ( type 
Array{Int64,1} ).

- I first create an array to store them, using:

julia> c_zero = Array(Array{Int64,1},0)

- But then, when I try to append! a new element, I get an error:

julia> append!(c_zero,[1,2]) 

MethodError(convert,(Array{Int64,1},1))


Thanks for any help.

Frederico.






[julia-users] Re: Using append! with types Array{Int64,1}

2014-07-22 Thread Frederico Novaes
Thank you for the solution and explanation !

Frederico.

On Tuesday, July 22, 2014 11:40:24 AM UTC-3, Ivar Nesje wrote:
>
> You must use push!
>
> Julia is very careful about the meaning of a function (partially because 
> multiple dispatch makes it much more important than in other languages).
>
> push! : appends a single element to a collection
> append! : pushes all the elements of a container into another container.
>
> c_zero is an array of arrays, and thus you will have to insert the whole 
> array [1,2] into c_zero, not all the elements of the array.
>
> Ivar
>
> kl. 16:17:19 UTC+2 tirsdag 22. juli 2014 skrev Frederico Novaes følgende:
>>
>> Hi,
>>
>> I started using Julia last week, so newbie. Here is the issue I'm having:
>>
>> - I want to store a certain unknown number of elements like [1,2] ( type 
>> Array{Int64,1} ).
>>
>> - I first create an array to store them, using:
>>
>> julia> c_zero = Array(Array{Int64,1},0)
>>
>> - But then, when I try to append! a new element, I get an error:
>>
>> julia> append!(c_zero,[1,2]) 
>>
>> MethodError(convert,(Array{Int64,1},1))
>>
>>
>> Thanks for any help.
>>
>> Frederico.
>>
>>
>>
>>
>>

[julia-users] Manipulate Shapefiles

2014-07-25 Thread Frederico Novaes
Hi,

Anyone can give some help, like example code, on loading/manipulating and 
possibly plotting shapefiles ? I know there is the Shapefile module, but 
since I'm new to Julia, I don't know yet how to find out how to use it just 
by loading or looking at the code.

Thanks in advance.

Frederico


Re: [julia-users] Manipulate Shapefiles

2014-08-04 Thread Frederico Novaes
Thanks Keno.

I am getting the following error when reading a .shp file:

read! not defined
at In[18]:3
 in read at C:\"INSTALLDIR"\.julia\Shapefile\src\Shapefile.jl:95
 in read at io.jl:389

As indicated, there is a call to the read! function at line 95 of Shapefile.jl, 
I could not find the read! function. Should I import some other pkg or 
something else ?



On Friday, July 25, 2014 11:49:56 AM UTC-3, Keno Fischer wrote:
>
> Here's two usage examples that might get you started: 
>
> http://nbviewer.ipython.org/github/jiahao/ijulia-notebooks/blob/master/2014-06-30-world-of-julia.ipynb
>  
> http://nbviewer.ipython.org/github/JuliaX/iap2014/blob/master/GeoData.ipynb 
>
> To install the ShapeFile package, you can just do Pkg.add("ShapeFile") 
>
> On Fri, Jul 25, 2014 at 10:04 AM, Frederico Novaes 
> > wrote: 
> > Hi, 
> > 
> > Anyone can give some help, like example code, on loading/manipulating 
> and 
> > possibly plotting shapefiles ? I know there is the Shapefile module, but 
> > since I'm new to Julia, I don't know yet how to find out how to use it 
> just 
> > by loading or looking at the code. 
> > 
> > Thanks in advance. 
> > 
> > Frederico 
>


Re: [julia-users] Manipulate Shapefiles

2014-08-04 Thread Frederico Novaes
So far I've been using the one that comes with Julia Studio, which is 
0.2.0, and the available compiled version, 0.2.1. I guess I'll have to (try 
to) compile the more recent versions. 

On Monday, August 4, 2014 5:46:40 PM UTC-3, Keno Fischer wrote:
>
> What version of julia do you have? read! may have been introduced 
> recently. 
>
> On Mon, Aug 4, 2014 at 4:41 PM, Frederico Novaes 
> > wrote: 
> > Thanks Keno. 
> > 
> > I am getting the following error when reading a .shp file: 
> > 
> > read! not defined 
> > at In[18]:3 
> >  in read at C:\"INSTALLDIR"\.julia\Shapefile\src\Shapefile.jl:95 
> >  in read at io.jl:389 
> > 
> > As indicated, there is a call to the read! function at line 95 of 
> > Shapefile.jl, I could not find the read! function. Should I import some 
> > other pkg or something else ? 
> > 
> > 
> > 
> > On Friday, July 25, 2014 11:49:56 AM UTC-3, Keno Fischer wrote: 
> >> 
> >> Here's two usage examples that might get you started: 
> >> 
> >> 
> http://nbviewer.ipython.org/github/jiahao/ijulia-notebooks/blob/master/2014-06-30-world-of-julia.ipynb
>  
> >> 
> >> 
> http://nbviewer.ipython.org/github/JuliaX/iap2014/blob/master/GeoData.ipynb 
> >> 
> >> To install the ShapeFile package, you can just do Pkg.add("ShapeFile") 
> >> 
> >> On Fri, Jul 25, 2014 at 10:04 AM, Frederico Novaes 
> >>  wrote: 
> >> > Hi, 
> >> > 
> >> > Anyone can give some help, like example code, on loading/manipulating 
> >> > and 
> >> > possibly plotting shapefiles ? I know there is the Shapefile module, 
> but 
> >> > since I'm new to Julia, I don't know yet how to find out how to use 
> it 
> >> > just 
> >> > by loading or looking at the code. 
> >> > 
> >> > Thanks in advance. 
> >> > 
> >> > Frederico 
>


[julia-users] character encoding

2014-08-12 Thread Frederico Novaes
Hi,

I'm using ODBC to query a DB. As part of the returned query, I get objects 
of type UTF8String. The problem is that characters like   "ã" are printed 
as "\u8f". How can I properly handle character encoding ?

Thanks.

Frederico.


[julia-users] Re: character encoding

2014-08-12 Thread Frederico Novaes


On Tuesday, August 12, 2014 2:14:00 PM UTC-3, Steven G. Johnson wrote:
>
> On Tuesday, August 12, 2014 9:47:31 AM UTC-4, Frederico Novaes wrote:
>>
>> I'm using ODBC to query a DB. As part of the returned query, I get 
>> objects of type UTF8String. The problem is that characters like   "ã" are 
>> printed as "\u8f". How can I properly handle character encoding ?
>>
>
> Probably that means that your query is not actually returning UTF-8 
> encoded data.   You need to figure out what encoding your data is actually 
> using.
>

I'm not sure yet, it may be Cp1252. If this is the case, how can I set that 
this is the encoding to be used ?

Thanks. 


[julia-users] Re: character encoding

2014-08-13 Thread Frederico Novaes


On Tuesday, August 12, 2014 11:20:58 PM UTC-3, Keith Campbell wrote:
>
> This might be easier to do on  the server side.
> Many DBMS, including MySQL and PostGreSQL, support encoding conversions.  
>
> eg convert('my_string', 'UTF8', 'ISO_8859_2')
>   SELECT CAST(_latin1'test' AS CHAR CHARACTER SET utf8)
>
>
Thanks, it works ! For the record, the character encoding of our oracle DB 
was WE8MSWIN1252, and to convert I just had to use:

SELECT CONVERT(col_name,'UTF8','WE8MSWIN1252') from ...

in the query. 


[julia-users] .xlsx (excel)

2014-08-15 Thread Frederico Novaes
Hi,

Any package/function to read .xlsx files ?

Frederico.


[julia-users] machinefile format

2014-08-20 Thread Frederico Novaes
Hi,

Can I use the IP instead of the hostname to launch a process on a remote 
machine at the 'machinefile' file ? I mean, if I put in a machinefile.txt 
file, the line:

xxx.xxx.xxx.xxx

and try to start a process with

julia --machinefile machinefile.txt

I get an error: "Master process (id 1) could not connect within 60.0 
seconds".

I can run Julia on the remote machine with:

ssh xxx.xxx.xxx.xxx 'julia'

and get the hostname for example by typing run(`hostname`). 

The problem is that I'll be performing some tests, and the IP of the remote 
machine is not fixed but dynamic.

Thanks.

Frederico.


[julia-users] Re: machinefile format

2014-08-20 Thread Frederico Novaes


On Wednesday, August 20, 2014 10:06:49 PM UTC-3, gael@gmail.com wrote:
>
> I can't test right now. Did you setup passwordless ssh?


Yes, I can ssh passwordless ( typing: ssh "hostname_of_remote_machine" 
'julia' starts a julia session on the remote machine). 

I also added the hostname and IP at /etc/hosts. 

I tried launching Julia locally, and, using: 

addprocs({"hostname_of_remote_machine"})

I got the same error. The same command using "hostname_of_local_machine" 
works.




[julia-users] Re: machinefile format

2014-08-21 Thread Frederico Novaes
Thanks !

sudo ufw allow 9009
sudo ufw enable

solved the problem !

On Wednesday, August 20, 2014 11:49:58 PM UTC-3, gael@gmail.com wrote:
>
> To be more precise...
>
> SSH is only used to launch Julia on the worker nodes. Afterwards, Julia 
> sets up a socket on both nodes and passes messages through that. If the 
> sockets can't be bound, because of a restrictive firewall for instance, 
> Julia would try for 60 seconds and then time out.
>
> At first, I was wondering if Julia would erroneously try to resolve any 
> machine name it finds. But since you tried to add the hostname and the IP 
> in /etc/hosts, without any improvement, that certainly means that the 
> resolution is OK (not sure though : dig do no check /etc/hosts).
>
> But whatever, by accessing the node, you can see if a socket has been set 
> up by Julia.
>
>

[julia-users] error when launching two workers on remote machine

2014-08-21 Thread Frederico Novaes


Hi,

I'm trying to launch a parallel julia session with 4 processes (workers): 2 
in host01 and 2 in host02 (launching from host01) but it's not working and 
it's kind of weird.

I can start two workers, one in host01 and one in host02, with the 
following machinefile.txt

host02
host01

and typing:

$ julia --machinefile machinefile.txt

Then, for example:

julia> @everywhere run(`hostname`)
host01
From worker 2:  host01
From worker 3:  host02

I can also add 2 workers in host01, wher machinefile.txt now is:

host01
host02
host01
host01


and typing:

julia> @everywhere run(`hostname`)
host01
From worker 3:  host02
From worker 2:  host01
From worker 5:  host01
From worker 4:  host01


However, if I want to start 2 workers on each machine, with the following 
machinefile.txt:

host01
host01
host02
host02

Then it hangs, and after a while I get an error:

Master process (id 1) could not connect within 60.0 seconds.
exiting.
Master process (id 1) could not connect within 60.0 seconds.
exiting.
Master process (id 1) could not connect within 60.0 seconds.
exiting.
Master process (id 1) could not connect within 60.0 seconds.
exiting.
ERROR: connect: connection timed out (ETIMEDOUT)
 in wait at ./task.jl:284
 in wait at ./task.jl:194
 in stream_wait at stream.jl:263
 in wait_connected at stream.jl:301
 in Worker at multi.jl:113
 in create_worker at multi.jl:1064
 in start_cluster_workers at multi.jl:1028
 in addprocs_internal at multi.jl:1234
 in addprocs at multi.jl:1244
 in process_options at ./client.jl:240
 in _start at ./client.jl:354
 in _start_3B_1716 at /usr/bin/../lib/x86_64-linux-gnu/julia/sys.so

Is it my network/system ???

Thanks.


[julia-users] help with performance

2015-02-03 Thread Frederico Novaes
Hi,

I'm trying to write better (faster) code in Julia, and here's an example 
that I would like to understand where the difference in performance comes 
from:

function test_1(μ,Δσ) 

ub = int(μ+Δσ)
lb = int(μ-Δσ)

n_el = ub - lb

disc_dist = Array(Float64,n_el)

n = lb
for i = 1:n_el 
disc_dist[i] = μ*σ*n 
n += 1
end


# Return
return disc_dist
end


function test_2(μ,σ,x_σ) 

ub = int(μ+x_σ*σ)
lb = int(μ-x_σ*σ)

n_el = ub - lb

disc_dist = Array(Float64,n_el)

n = lb
for i = 1:n_el 
disc_dist[i] = μ*σ*n
n += 1
end

# Return
return disc_dist
end

function loop_states_1(n_states,μ,Δσ)
for i_state = 1:n_states
result = test_1(μ,Δσ)
end
end

function loop_states_2(n_states,μ,σ,x_σ)
for i_state = 1:n_states
result = test_2(μ,σ,x_σ)
end
end

# Parameters
σ = 4
μ = 22.3
x_σ = 2.0
Δσ = x_σ*σ
n_states = 50


And then, when benchmarking:
@time test_1(μ,Δσ);

elapsed time: 2.4147e-5 seconds (1024 bytes allocated)

@time test_2(μ,σ,x_σ);
elapsed time: 1.382e-5 seconds (256 bytes allocated)

@time loop_states_1(n_states,μ,Δσ)
elapsed time: 1.598021522 seconds (47296 bytes allocated, 32.01% gc time)

@time loop_states_2(n_states,μ,σ,x_σ)
elapsed time: 0.122917637 seconds (8880 bytes allocated, 56.84% gc time)


The only difference between functions test_1 and test_2 is that the first one 
takes as arguments (μ,Δσ) and the latter (μ,σ,x_σ). 
Also the definitions for lb and ub. The output is the same. I've been reading 
about type instability, annotations, ... but I can't see where the difference 
in performance comes from. 

Any help ? 





[julia-users] Re: help with performance

2015-02-03 Thread Frederico Novaes
Sorry, it was a silly mistake, I never meant to have a global variable. I 
simplified the code I was working on to benchmark and post and ended up 
introducing this "bug". Thanks for the answers, I don't think I'll use 
global variables, but if I do, I'll declare them as const.

Best.

On Tuesday, February 3, 2015 at 2:15:40 PM UTC-2, Yuuki Soho wrote:
>
> The reason why test_1 is slower than test_2 is that you forgot to pass σ 
> as a parameter in test_1 definition, so Julia looks for a global variable 
> instead. 
>
> In general don't hesitate to add type annotation to your functions, it 
> often helps to prevent types problems (e.g. function 
> test_1(μ::Float64,Δσ::Float64,σ::Float64) 
> ).
>
>
>
>

[julia-users] Error when using Interact (in IJulia)

2014-09-26 Thread Frederico Novaes
Hi,

I'm getting an error when trying to use Interact from IJulia, on Windows 7 
and julia 0.3.1. 

After typing "using Interact", I get:

Javascript error adding output!
ReferenceError: _ is not defined
See your browser Javascript console for more details.

Any help ?


Re: [julia-users] Error when using Interact (in IJulia)

2014-09-27 Thread Frederico Novaes
Worked for me too. Thanks !

On Saturday, September 27, 2014 12:56:36 PM UTC-3, Kevin Squire wrote:
>
> Hi Fredrick,
>
> Try upgrading to a newer version of IPython. That fixed the same problem 
> for me. 
>
> Cheers,
>Kevin 
>
> On Friday, September 26, 2014, Frederico Novaes  > wrote:
>
>> Hi,
>>
>> I'm getting an error when trying to use Interact from IJulia, on Windows 
>> 7 and julia 0.3.1. 
>>
>> After typing "using Interact", I get:
>>
>> Javascript error adding output!
>> ReferenceError: _ is not defined
>> See your browser Javascript console for more details.
>>
>> Any help ?
>>
>

[julia-users] DataFrame groupby error

2014-10-08 Thread Frederico Novaes
Hi,

I have a DataFrame with 10 "columns", say :c1 to :c10. I need to do a 
groupby, grouping by 4 of these columns. When I try,

$ groupby(df,[:c1,:c3,:c4,:c7])

I get the following error:

MemoryError()
while loading In[13], in expression starting on line 1

 in groupsort_indexer at 
/home/cloudopen/.julia/v0.3/DataArrays/src/grouping.jl:7
 in groupsort_indexer at 
/home/cloudopen/.julia/v0.3/DataArrays/src/grouping.jl:5
 in groupby at 
/home/cloudopen/.julia/v0.3/DataFrames/src/groupeddataframe/grouping.jl:44


Any help ?

Thanks.