[julia-users] Re: range bug in 0.4.1?

2015-12-05 Thread Gabor
I am also surprised at this behaviour, but it is certainly not a bug.
Have a look at the help:

help?> range
  range(start, [step], length)
  Construct a range by length, given a starting value and optional step 
(defaults to 1).

help?> colon
  ..  \:(start, [step], stop)
  Range operator. ``a:b`` constructs a range from ``a`` to ``b`` with a 
step size of 1, 
  and ``a:s:b`` is similar but uses a step size of ``s``. 
  These syntaxes call the function ``colon``.
  The colon is also used in indexing to select whole dimensions.
  colon(start, [step], stop)
  Called by : syntax for constructing ranges.


On Sunday, December 6, 2015 at 8:41:34 AM UTC+1, Jürgen Bohnert wrote:
>
>
>
> Hi everyone,
>
> I found some really strange behaviour of the 'range' function
>
> range(1,5)
> > 1:5
> everything is OK
>
> range(2,5)
> > 2:6
> NOT OK!
>
> range(10,20)
> > 10:29
> NOT OK!
>
> However, if I define the range like so
> 10:20
> > 10:20
> OK and obviously works for all you guys as well.
>
> Am I missing some syntax or is this a bug?
>
>
>
> Also: is there a way to redefine the default behaviour of the 
> range-syntax? It's really annoying having to 'Int' everything when I'm just 
> specifying limits that get coerced to 'Float' because of division but are 
> otherwise 'X.0'
> N=2^3 -1
> > 7
> imid = (N+1)/2
> > 4.0
> range(imid-2, imid+2)
> > ERROR: MethodError: 'range' has no method matching range(::Float64, ::
> Float64)
>
> Thanks for helping,
> Juergen
>
> julia build:
> Version 0.4.1 (2015-11-08 10:33 UTC)
> both:
>
>- x86_64-w64-mingw32
>- x86_64-linux-gnu
>
>
>
>
>
>
>
>

[julia-users] range bug in 0.4.1?

2015-12-05 Thread Jürgen Bohnert


Hi everyone,

I found some really strange behaviour of the 'range' function

range(1,5)
> 1:5
everything is OK

range(2,5)
> 2:6
NOT OK!

range(10,20)
> 10:29
NOT OK!

However, if I define the range like so
10:20
> 10:20
OK and obviously works for all you guys as well.

Am I missing some syntax or is this a bug?



Also: is there a way to redefine the default behaviour of the range-syntax? 
It's really annoying having to 'Int' everything when I'm just specifying 
limits that get coerced to 'Float' because of division but are otherwise 
'X.0'
N=2^3 -1
> 7
imid = (N+1)/2
> 4.0
range(imid-2, imid+2)
> ERROR: MethodError: 'range' has no method matching range(::Float64, ::
Float64)

Thanks for helping,
Juergen

julia build:
Version 0.4.1 (2015-11-08 10:33 UTC)
both:

   - x86_64-w64-mingw32
   - x86_64-linux-gnu
   








[julia-users] Calling Julia from C

2015-12-05 Thread Robert Mudyn
Hello,

I've been working for a while on my project that which GUI application for 
my Julia module.
I stuck at the point, when I need to invoke it. I been searching around for 
some helpful information about my problem, but without success.

I've been able to workaround issue with loading modules:
jl_eval_string("include(\"module.jl\")");
jl_value_t* mod = jl_eval_string(module_name);
jl_value_t* mod2 = jl_eval_string(module_in_module);

And it seems to be fine (at least there are some data).
However now my problem is, that I cannot create type in that module. I've 
tried several functions without success.
I've tried something like:
jl_new_struct(func2, argument);
or
jl_call1(func2, argument);
or even normal
jl_eval_string("type(argument)");
None seems to work for me.

It's crucial part in my application.
I've hope, that someone will be able to help me.

Best wishes,
Robert.


[julia-users] can't load any package

2015-12-05 Thread bbd 666
I've just installed Julia 0.3.12
I can't install any package.
same message, every time :
INFO : Initializing package repository c:..
INFO : cloning METADATA from git//github.com/JuliaLang/METADATA.jl
fatal : unable to connect to github.com:
github.com:[192.30.252.130]: errno=No error
ERROR:failed process blablabla...


[julia-users] can't load any packages

2015-12-05 Thread bbd 666
this is what happens when I try


INFO: Initializing package repository C:\Users\myname\.julia\v0.3
INFO: Cloning METADATA from git://github.com/JuliaLang/METADATA.jl
fatal: unable to connect to github.com:
github.com[0: 192.30.252.130]: errno=No error

ERROR: failed process: Process(`git clone -q -b metadata-v2 
git://github.com/Jul
iaLang/METADATA.jl METADATA`, ProcessExited(128)) [128]
 in error at error.jl:22 (repeats 2 times)


[julia-users] What happens to a task on close socket?

2015-12-05 Thread Colin Beckingham
Say I have a connection to a socket with an @sync infinite loop task 
running (write messages from socket to stdout) and close the socket.
Does this automatically remove the task? It's not causing problems, just 
curious.


[julia-users] Re: Array of matrices

2015-12-05 Thread Lex
Thanks Eric!

On Saturday, December 5, 2015 at 6:21:13 PM UTC-8, Lex wrote:
>
> Hi 
>
> I am not sure how to create an array of fixed size which may store 
> matrices of different dimensions for later applying algebraic operations. 
> Any help is appreciated.
> Some of the things I tried:
>
> x = [Matrix{} for i=1:5]
>
>
> x = [Any for i=1:5]
> for i in 1:5
>   x[i] = Any
> end
>
>
>
>
>

Re: [julia-users] Adding 1 to an Array{Array{Int64,1},1}

2015-12-05 Thread Erik Schnetter
Right. The shortest I could come up with to circumvent this problem is:

*map(x->x+1, copy([[1,1] for i in 1:5]))*


-erik

On Sat, Dec 5, 2015 at 5:37 AM, James Gilbert  wrote:

> You're making a 2D array, for which there is a dot add method. Chris, the
> OP, is making an array of arrays. I wonder if that is really what he wants?
>
> *julia> **a = fill(1, 5,2)*
>
> *5x2 Array{Int64,2}:*
>
> * 1  1*
>
> * 1  1*
>
> * 1  1*
>
> * 1  1*
>
> * 1  1*
>
>
> *julia> **a + 1*
>
> *5x2 Array{Int64,2}:*
>
> * 2  2*
>
> * 2  2*
>
> * 2  2*
>
> * 2  2*
>
> * 2  2*
>
>


-- 
Erik Schnetter 
http://www.perimeterinstitute.ca/personal/eschnetter/


[julia-users] Re: Array of matrices

2015-12-05 Thread Eric Forgy
Close :)

You can try:

julia> x = [Matrix() for i=1:5]
5-element Array{Array{Any,2},1}:
 0x0 Array{Any,2}
 0x0 Array{Any,2}
 0x0 Array{Any,2}
 0x0 Array{Any,2}
 0x0 Array{Any,2}

Also:

julia> x = [rand(i,i) for i=1:5]
5-element Array{Array{Float64,2},1}:
 1x1 Array{Float64,2}:
 0.518641   



 2x2 Array{Float64,2}:
 0.219756  0.753237
 0.294669  0.718687 



 3x3 Array{Float64,2}:
 0.951481  0.114902  0.632999
 0.934798  0.528655  0.759751
 0.695776  0.013846  0.568784   



 4x4 Array{Float64,2}:
 0.0338033  0.999119  0.914414  0.114614
 0.947484   0.16535   0.512054  0.115579
 0.135501   0.317845  0.832064  0.16373
 0.365693   0.879762  0.313289  0.0339317   


 5x5 Array{Float64,2}:
 0.181271   0.68545   0.749937   0.116528  0.193043
 0.545848   0.787693  0.793377   0.405328  0.797003
 0.0121521  0.476136  0.0411077  0.200597  0.496779
 0.503430.32037   0.455482   0.260218  0.308114
 0.855837   0.471426  0.723162   0.591161  0.128503



On Sunday, December 6, 2015 at 10:21:13 AM UTC+8, Lex wrote:
>
> Hi 
>
> I am not sure how to create an array of fixed size which may store 
> matrices of different dimensions for later applying algebraic operations. 
> Any help is appreciated.
> Some of the things I tried:
>
> x = [Matrix{} for i=1:5]
>
>
> x = [Any for i=1:5]
> for i in 1:5
>   x[i] = Any
> end
>
>
>
>
>

[julia-users] Array of matrices

2015-12-05 Thread Lex
Hi 

I am not sure how to create an array of fixed size which may store matrices 
of different dimensions for later applying algebraic operations. Any help 
is appreciated.
Some of the things I tried:

x = [Matrix{} for i=1:5]


x = [Any for i=1:5]
for i in 1:5
  x[i] = Any
end






[julia-users] Re: Overwriting Functions

2015-12-05 Thread Eric Davies
This took a while to show up and may have been missed.

On Saturday, 28 November 2015 12:19:29 UTC-5, Curtis Vogt wrote:
>
> I've been working on a package Mocking.jl 
>  which allows developers to 
> temporarily overwrite a method in order to facilitate testing. I've got 
> everything working pretty well with the exception of the creation of a new 
> macro which is suppose to ensure that Julia doesn't inline or optimize the 
> call in such a way that the originally specified call can be overwritten:
>
> julia> function myfunc(filename)
>
>readall(open(filename))
>
>end
>
> myfunc (generic function with 1 method)
>
>
> julia> myfunc("foo")
>
> ERROR: SystemError: opening file foo: No such file or directory
>
>  in open at ./iostream.jl:90
>
>  in myfunc at none:2
>
>
> julia> Base.open(name::AbstractString) = IOBuffer("bar")
>
> WARNING: Method definition open(AbstractString) in module Base at 
> iostream.jl:99 overwritten in module Main at none:1.
>
> open (generic function with 8 methods)
>
>
> julia> myfunc("foo")  # Open call within `myfunc` is not overwritten
>
> ERROR: SystemError: opening file foo: No such file or directory
>
>  in open at ./iostream.jl:90
>
>  in myfunc at none:2
>
>
> I can get this to work correctly with by adjusting the myfunc slightly:
>
>
> julia> function myfunc(filename)
>
>readall([open([filename]...)]...)
>
>end
>
> myfunc (generic function with 1 method)
>
>
> julia> myfunc("foo")
>
> ERROR: SystemError: opening file foo: No such file or directory
>
>  in open at ./iostream.jl:90
>
>  in open at iostream.jl:99
>
>  in myfunc at none:2
>
>
> julia> Base.open(name::AbstractString) = IOBuffer("bar")
>
> WARNING: Method definition open(AbstractString) in module Base at 
> iostream.jl:99 overwritten in module Main at none:1.
>
> open (generic function with 8 methods)
>
>
> julia> myfunc("foo")
>
> "bar"
>
>
> But this makes forces people to change their code and make it harder to 
> read. Not to mention that this is just fooling the compiler into getting 
> the behaviour I want. I would prefer to use a macro to get this behaviour 
> and I managed to get the following horrible macro to work:
>
>
>
> julia> macro fix(ex)
>
>name = gensym()
>
>:(@generated function $name() $ex end; $name())
>
>end
>
>
> julia> function myfunc(filename)
>
>@fix readall(open(filename))
>
>end
>
> myfunc (generic function with 1 method)
>
>
> julia> myfunc("foo")
>
> ERROR: SystemError: opening file foo: No such file or directory
>
>  in open at ./iostream.jl:90
>
>  in open at iostream.jl:99
>
>  in #2###6995 at none:3
>
>  in myfunc at none:2
>
>
> julia> Base.open(name::AbstractString) = IOBuffer("bar")
>
> WARNING: Method definition open(AbstractString) in module Base at 
> iostream.jl:99 overwritten in module Main at none:1.
>
> open (generic function with 8 methods)
>
>
> julia> myfunc("foo")
>
> "bar"
>
>
> Does anyone have any suggestions on how I can improve this macro and get 
> this behaviour? Bonus points if someone can tell me a good way of 
> determining if the macro is being called from within a `Pkg.test(...)` 
> process.
>


[julia-users] How to read an external program's STDOUT using open()

2015-12-05 Thread Miguel Bazdresch
I need to run an external program and write to its STDIN, and read from its
STDOUT. I'm trying to do this using open(). Writing to its STDIN works fine
with the method below, but I cannot read from its STDOUT.

To simplify my tests, I wrote a simple C program called 'stdo' that
constantly generates data on its STDOUT:

#include 
#include 

int main(int argc, char** argv) {
 while (1) {
printf("Hello\n");
fflush(stdout);
  sleep(1);
  }
  return 0;
}

In Julia (0.4.1, Linux) I run this program like this:

julia> si=STDIN;
julia> (r,w)=redirect_stdin();

julia> (s,p)=open(`./stdo`,"w",w)
(Pipe(open => closed, 0 bytes waiting),Process(`./stdo`, ProcessRunning))

julia> r
Base.PipeEndpoint(open, 0 bytes waiting)

My understanding is that the C program's output is redirected to pipe 'w',
and it can be read from pipe 'r'. However, the pipe 'r' is always empty.
Obviously I'm doing something wrong, but I can't figure out what it is. Any
pointers appreciated.

-- mb


Re: [julia-users] Writing CSV

2015-12-05 Thread digxx
Yep, writing 1.0 as integer '1' still gives a double array when read by IDL


Re: [julia-users] Writing CSV

2015-12-05 Thread Milan Bouchet-Valat
Le samedi 05 décembre 2015 à 05:02 -0800, digxx a écrit :
> Hey, I had a look in it:
> Its not the '.' on its on but also the fact that in front of the '.'
> IDL expects a '0' in case the number is smaller than 1
> Then everything is read as double.
Thanks. Can you check/confirm whether writing '1.0' as '1' in a column
containing other non-integer floats is supported by IDL? In other
words, is the problem only with writing '0.5' as '.5'?


Regards


Re: [julia-users] Convert SubString{ASCIIString} to String

2015-12-05 Thread Milan Bouchet-Valat
Le vendredi 04 décembre 2015 à 23:47 +0100, Charles Novaes de Santana a
écrit :
> Hi people,
> 
> Maybe it is a trivial question for most of you, but I really could
> not find a way to solve my problem.
> 
> I am using the function quandlget(id::ASCIIString) from the library 
> https://github.com/milktrader/Quandl.jl (a great contribution, by the
> way!)
> 
> Everything works fine when I use it in a straightforward way:
> 
> julia> mydat = quandl("GOOG/NASDAQ_GOOG",rows=100,format="DataFrame")
> 100x6 DataFrames.DataFrame
> | Row | Date   | Open   | High   | Low| Close  | Volume|
> |-||||||---|
> | 1   | 2015-07-08 | 521.05 | 522.73 | 516.11 | 516.83 | 1.2967e6  |
> | 2   | 2015-07-09 | 523.12 | 523.77 | 520.35 | 520.68 | 1.84235e6 |
> | 3   | 2015-07-10 | 526.29 | 532.56 | 525.55 | 530.13 | 1.95668e6 |
> 
> 
> or when I do:
> 
> julia> myid = "GOOG/NASDAQ_GOOG"
> "GOOG/NASDAQ_GOOG"
> 
> julia> typeof(myid)
> ASCIIString
> 
> julia> mydat = quandl(myid,rows=100,format="DataFrame")
> 100x6 DataFrames.DataFrame
> | Row | Date   | Open   | High   | Low| Close  | Volume|
> |-||||||---|
> | 1   | 2015-07-08 | 521.05 | 522.73 | 516.11 | 516.83 | 1.2967e6  |
> | 2   | 2015-07-09 | 523.12 | 523.77 | 520.35 | 520.68 | 1.84235e6 |
> | 3   | 2015-07-10 | 526.29 | 532.56 | 525.55 | 530.13 | 1.95668e6 |
> 
> 
> However, I get an error when I read my data from an external file.
> Assume I have an ascii file containing only one line:
> 
> $ echo "GOOG/NASDAQ_GOOG" > portfolio.txt
> 
> $ cat portfolio.txt 
> GOOG/NASDAQ_GOOG
> 
> 
> I just read the content of this file by using readdlm and try to use
> it to call the same function quandl, but it does not work.
> 
> julia> myportfolio = readdlm("./portfolio.txt",'\n')
> 1x1 Array{Any,2}:
>  "GOOG/NASDAQ_GOOG"
> 
> julia> typeof(myportfolio[1])
> SubString{ASCIIString}
> 
> julia> mydat = quandl(myportfolio[1],rows=100,format="DataFrame")
> ERROR: MethodError: `quandlget` has no method matching
> quandlget(::SubString{ASCIIString})
Though the other posts give good solutions to your problem, you could
also file an issue against Quandl.jl to change quandlget() to accept
any AbstractString, and not only ASCIIString. That would be helpful in
legitimate cases.


Regards

> I suppose the easiest way to solve this problem is to convert my
> SubString{ASCIIString} variable to ASCIIString. Am I right here? How
> can I do it?
> 
> Does any of you have another suggestion? May be I could read my data
> in a different way instead of using readdlm? 
> 
> Thanks for any tip!
> 
> best,
> 
> Charles
> -- 
> Um axé! :)
> 
> --
> Charles Novaes de Santana, PhD
> http://www.imedea.uib-csic.es/~charles


[julia-users] Re: generating hex from string

2015-12-05 Thread Martin Somers
I using bit binary and hex characters and sometimes the programming is 
easier using one rather than the other - Im re-writing a cryptograph cipher 
and trying to figure out how to do so...

there isnt all that much information on the native hex functions and Im 
gradually finding out that I need ASCII to view the actual hex characters 
and not use this in the process

Finding the most efficient and least efficient means of doing is the fun of 
programming :)


[julia-users] Re: Parallel @sync @async

2015-12-05 Thread digxx
And yes, the vcat gave the wanted result, though why (as asked above) do I 
need this reduction operator?


[julia-users] Re: Parallel @sync @async

2015-12-05 Thread digxx
Though why does fetch(r[1]) not work? Wouldnt one expect it to give the 
result a specific worker calculated?
Do I always need a reduction operator? in this case vcat, right?
The other question was maybe more fundamental (and simple?):
Why is the calculation so much faster with a @async prefix?
Does this prefix also work serial? I tried it and he does sth but the 
result is: Task (done) @0x828ec710
Is an accompanied @sync begin ... end mandatory or not?
And what exactly does "completion" mean in this sense? Like the @sync waits 
for the other workers to complete ?
Say each worker has a task and then @sync makes sure that every worker 
finished his task before the next one is given to each worker?


Re: [julia-users] Adding 1 to an Array{Array{Int64,1},1}

2015-12-05 Thread Chris
James, I am specifically interested in the array of arrays case.

Steven, thanks for the insight.

On Sat, Dec 5, 2015, 05:37 James Gilbert  wrote:

> You're making a 2D array, for which there is a dot add method. Chris, the
> OP, is making an array of arrays. I wonder if that is really what he wants?
>
> *julia> **a = fill(1, 5,2)*
>
> *5x2 Array{Int64,2}:*
>
> * 1  1*
>
> * 1  1*
>
> * 1  1*
>
> * 1  1*
>
> * 1  1*
>
>
> *julia> **a + 1*
>
> *5x2 Array{Int64,2}:*
>
> * 2  2*
>
> * 2  2*
>
> * 2  2*
>
> * 2  2*
>
> * 2  2*
>
>


Re: [julia-users] Writing CSV

2015-12-05 Thread digxx
Hey, I had a look in it:
Its not the '.' on its on but also the fact that in front of the '.' IDL 
expects a '0' in case the number is smaller than 1
Then everything is read as double.


[julia-users] Re: generating hex from string

2015-12-05 Thread James Gilbert
In hexadecimal notation, each byte is represented by two ASCII characters, 
so the string must be an even length.

I'm worried that you've posted a number of questions about converting back 
and forth between strings and binary. Why do you need to do this? What is 
your application? I would expect software to operate on and store data in 
the binary domain, only converting to strings when readable output is 
required.


Re: [julia-users] Adding 1 to an Array{Array{Int64,1},1}

2015-12-05 Thread James Gilbert
You're making a 2D array, for which there is a dot add method. Chris, the 
OP, is making an array of arrays. I wonder if that is really what he wants?

*julia> **a = fill(1, 5,2)*

*5x2 Array{Int64,2}:*

* 1  1*

* 1  1*

* 1  1*

* 1  1*

* 1  1*


*julia> **a + 1*

*5x2 Array{Int64,2}:*

* 2  2*

* 2  2*

* 2  2*

* 2  2*

* 2  2*



[julia-users] Re: generating hex from string

2015-12-05 Thread Martin Somers

>
> yeh when i dummy data the y the error goes away 
>

y = [0xaa,0xbb,0xcc,0xdd]; 


[julia-users] generating hex from string

2015-12-05 Thread Martin Somers
I seem to be getting an error of an ill formed hex number 
ERROR: LoadError: ArgumentError: string length must be even: 
length("ac446e2") == 7

Im using 
parse(("0x"*bytes2hex(y))

is there a better way maybe of doing this one of my y indexs isnt in fact a 
UInt8 values

Im initialising y = [0x00,0x00,0x00,0x00];