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

2016-11-07 Thread Dan
a = Vector{String}



is also a good option.

On Monday, November 7, 2016 at 5:27:49 PM UTC+2, Steven G. Johnson wrote:
>
>
>
> On Monday, November 7, 2016 at 9:45:37 AM UTC-5, Mauro wrote:
>>
>> On Mon, 2016-11-07 at 15:27, Fred  wrote: 
>> > Hi Steven, 
>> > 
>> > 
>> > I also tried a = Array{String}() unfortunately it produces errors as 
>> well. 
>>
>> Array{String}(0) 
>>
>
> Whoops, sorry about the typo. 
>


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

2016-11-07 Thread Dan
I meant,

a = Vector{String}()

Dan

On Tuesday, November 8, 2016 at 9:39:53 AM UTC+2, Dan wrote:
>
> a = Vector{String}
>
>
>
> is also a good option.
>
> On Monday, November 7, 2016 at 5:27:49 PM UTC+2, Steven G. Johnson wrote:
>>
>>
>>
>> On Monday, November 7, 2016 at 9:45:37 AM UTC-5, Mauro wrote:
>>>
>>> On Mon, 2016-11-07 at 15:27, Fred  wrote: 
>>> > Hi Steven, 
>>> > 
>>> > 
>>> > I also tried a = Array{String}() unfortunately it produces errors as 
>>> well. 
>>>
>>> Array{String}(0) 
>>>
>>
>> Whoops, sorry about the typo. 
>>
>

Re: [julia-users] Re: Escaped $ in Strings has a strange behavior

2016-11-07 Thread Yichao Yu
On Mon, Nov 7, 2016 at 10:55 PM, cdm  wrote:
>
>
> On Monday, November 7, 2016 at 7:51:34 PM UTC-8, Yichao Yu wrote:
>>
>> Just to be clear. print/println does not "un-decorate" anything at
>> all. It's `show`/`display`/`dump` "decorate" (escape/quote) it.
>
>
> perhaps the help docs are not clear then ... ?
>
>   print(x)
>
>   Write (to the default output stream) a canonical (un-decorated) text
> representation of a value if there is one, otherwise call show. The
> representation used
>   by print includes minimal formatting and tries to avoid Julia-specific
> details.

The doc string says that the function prints the form that is
`un-decorated` i.e. not decorated, different from show, which does
`decorate` it.


Re: [julia-users] Re: Escaped $ in Strings has a strange behavior

2016-11-07 Thread cdm


On Monday, November 7, 2016 at 7:51:34 PM UTC-8, Yichao Yu wrote:
>
> Just to be clear. print/println does not "un-decorate" anything at 
> all. It's `show`/`display`/`dump` "decorate" (escape/quote) it. 
>

perhaps the help docs are not clear then ... ?

  print(x)
 
  Write (to the default output stream) a canonical (un-decorated) text 
representation of a value if there is one, otherwise call 
show. The representation used
  by print
 includes minimal formatting and tries to avoid Julia-specific details. 


Re: [julia-users] Re: Escaped $ in Strings has a strange behavior

2016-11-07 Thread Yichao Yu
On Mon, Nov 7, 2016 at 10:48 PM, cdm  wrote:
>
> On Monday, November 7, 2016 at 7:31:52 PM UTC-8, Yichao Yu wrote:
>>
>>
>> Both? I don't see the difference. I'm only saying that `show` does not
>> simply write the string to the stream, but prints the representation
>> of the string object instead, which is the quoted string.
>
>
> julia> dump(a)
> String "i have \$100 ..."
>
>
> i hope to find a list of decorators,
> in addition to double quote and
> back slash and single quote,
> which are canonically "un-decorated"
> by print()/println() ...

Just to be clear. print/println does not "un-decorate" anything at
all. It's `show`/`display`/`dump` "decorate" (escape/quote) it.

>
> many thanks


Re: [julia-users] Re: Escaped $ in Strings has a strange behavior

2016-11-07 Thread cdm

On Monday, November 7, 2016 at 7:31:52 PM UTC-8, Yichao Yu wrote:
>
>
> Both? I don't see the difference. I'm only saying that `show` does not 
> simply write the string to the stream, but prints the representation 
> of the string object instead, which is the quoted string. 
>

julia> 
dump(a) 
  
String "i have \$100 ..." 


i hope to find a list of decorators,
in addition to double quote and
back slash and single quote,
which are canonically "un-decorated"
by print()/println() ...

many thanks


Re: [julia-users] Re: Escaped $ in Strings has a strange behavior

2016-11-07 Thread Yichao Yu
On Mon, Nov 7, 2016 at 10:31 PM, cdm  wrote:
> to your point (in the same session):
>
> julia> show(b)
> nothing

Yes? the return value of print/println/show has nothing to do with the
object being printed.

>
>
>
> On Monday, November 7, 2016 at 7:28:38 PM UTC-8, cdm wrote:
>>
>> On Monday, November 7, 2016 at 7:23:10 PM UTC-8, Yichao Yu wrote:
>>>
>>> fwiw, show does more stuff on the string than either print or println.
>>> None of them return anything even though print and println does not do
>>> any stuff on the string.
>>
>>
>> so in the course of what was defined above,
>> was "a" defined as an "object" or a "string" ?
>>


Re: [julia-users] Re: Escaped $ in Strings has a strange behavior

2016-11-07 Thread cdm
to your point (in the same session):

julia> 
show(b) 
  
nothing



On Monday, November 7, 2016 at 7:28:38 PM UTC-8, cdm wrote:
>
> On Monday, November 7, 2016 at 7:23:10 PM UTC-8, Yichao Yu wrote:
>
>> fwiw, show does more stuff on the string than either print or println. 
>> None of them return anything even though print and println does not do 
>> any stuff on the string.
>>
>
> so in the course of what was defined above,
> was "a" defined as an "object" or a "string" ?
>  
>


Re: [julia-users] Re: Escaped $ in Strings has a strange behavior

2016-11-07 Thread Yichao Yu
On Mon, Nov 7, 2016 at 10:28 PM, cdm  wrote:
> On Monday, November 7, 2016 at 7:23:10 PM UTC-8, Yichao Yu wrote:
>>
>> fwiw, show does more stuff on the string than either print or println.
>> None of them return anything even though print and println does not do
>> any stuff on the string.
>
>
> so in the course of what was defined above,
> was "a" defined as an "object" or a "string" ?
>

Both? I don't see the difference. I'm only saying that `show` does not
simply write the string to the stream, but prints the representation
of the string object instead, which is the quoted string.


Re: [julia-users] Re: Escaped $ in Strings has a strange behavior

2016-11-07 Thread cdm
On Monday, November 7, 2016 at 7:23:10 PM UTC-8, Yichao Yu wrote:

> fwiw, show does more stuff on the string than either print or println. 
> None of them return anything even though print and println does not do 
> any stuff on the string.
>

so in the course of what was defined above,
was "a" defined as an "object" or a "string" ?
 


[julia-users] Re: Escaped $ in Strings has a strange behavior

2016-11-07 Thread cdm

in the terminal:

julia> a = "i have \$100 ..."   

 
"i have \$100 ..."
 
julia> 
aa = eval(a)
  
"i have \$100 ..."
 
julia> 
a == aa 
  
true
 
julia> 
b = println(a)  
  
i have $100 ...
 
julia> 
b == a  
  
false



so, more "stuff" is happening
within the println() function ...




Re: [julia-users] Re: Escaped $ in Strings has a strange behavior

2016-11-07 Thread Yichao Yu
On Mon, Nov 7, 2016 at 10:16 PM, cdm  wrote:
>
>
> On Monday, November 7, 2016 at 7:13:03 PM UTC-8, Yichao Yu wrote:
>>
>> > so, more "stuff" is happening
>> > within the println() function ...
>>
>> No. println/print output the string, show/display prints it as an
>> object and do so in a way that shows more detail about the string
>> itself.
>> Note that the quote isn't part of the string either so it shouldn't be
>> surprising that the character `$` is printed as `\$` when showing a
>> quoted string.
>
>
> which was my point, print() and println() are doing "stuff" to the string,
> else they would return the string as defined and as represented by
> show() ...

fwiw, show does more stuff on the string than either print or println.
None of them return anything even though print and println does not do
any stuff on the string.


Re: [julia-users] Re: Escaped $ in Strings has a strange behavior

2016-11-07 Thread cdm


On Monday, November 7, 2016 at 7:13:03 PM UTC-8, Yichao Yu wrote:
>
> > so, more "stuff" is happening 
> > within the println() function ... 
>
> No. println/print output the string, show/display prints it as an 
> object and do so in a way that shows more detail about the string 
> itself. 
> Note that the quote isn't part of the string either so it shouldn't be 
> surprising that the character `$` is printed as `\$` when showing a 
> quoted string. 
>

which was my point, print() and println() are doing "stuff" to the string,
else they would return the string as defined and as represented by
show() ... 


Re: [julia-users] Re: Escaped $ in Strings has a strange behavior

2016-11-07 Thread Yichao Yu
On Mon, Nov 7, 2016 at 10:06 PM, cdm  wrote:
>
> in the terminal:
>
> julia> a = "i have \$100 ..."
> "i have \$100 ..."
>
> julia> aa = eval(a)
> "i have \$100 ..."

^^ FWIW, this is a no-op

>
> julia> a == aa
> true

^^ Which should make this not very surprising.

>
> julia> b = println(a)
> i have $100 ...

`println` prints it, and does not return the string it prints

>
> julia> b == a
> false
>

^^ Which is why this does not mean anything at all.

>
>
> so, more "stuff" is happening
> within the println() function ...

No. println/print output the string, show/display prints it as an
object and do so in a way that shows more detail about the string
itself.
Note that the quote isn't part of the string either so it shouldn't be
surprising that the character `$` is printed as `\$` when showing a
quoted string.

>
>


[julia-users] Escaped $ in Strings has a strange behavior

2016-11-07 Thread David Anthoff
I get 

 

julia> x = "I have \$100 in my account"

"I have \$100 in my account"

 

Shouldn't the backlash not appear in the output? If then do

 

println(x)

 

the backlash doesn't show, but I would have expected that it also doesn't
show if I just eval the string.

 

Am I missing something basic here?

 

Thanks,

David



Re: [julia-users] problems (and some fixes) for using Plots and PlotlyJS on FreeBSD

2016-11-07 Thread Kostas Oikonomou
On 2nd thought, here is more of the (long) error message:

ERROR: Cannot find Electron. Try `Blink.AtomShell.install()`.
 in electron() at /usr/home/ko/.julia/v0.5/Blink/src/AtomShell/process.jl:53
 in #init#5(::Bool, ::Function) at 
/usr/home/ko/.julia/v0.5/Blink/src/AtomShell/process.jl:71
 in (::Blink.AtomShell.#kw##init)(::Array{Any,1}, ::Blink.AtomShell.#init) 
at ./:0
 in #shell#8(::Bool, ::Function) at 
/usr/home/ko/.julia/v0.5/Blink/src/AtomShell/process.jl:114

The  in line 4 looks suspicious.  Does it give you any clue?

On Monday, November 7, 2016 at 5:27:34 PM UTC-5, Kostas Oikonomou wrote:
>
> I'm just beginning with Julia, so I don't really know how to go about 
> doing this.
>
>
>

Re: [julia-users] problems (and some fixes) for using Plots and PlotlyJS on FreeBSD

2016-11-07 Thread Kostas Oikonomou
I'm just beginning with Julia, so I don't really know how to go about doing 
this.

On Monday, November 7, 2016 at 5:14:21 PM UTC-5, Tom Breloff wrote:
>
> You should probably open issues/PRs in the individual packages then... 
> this sounds like a Blink issue.
>
> On Mon, Nov 7, 2016 at 5:09 PM, Kostas Oikonomou  > wrote:
>
>> Yes, I did.  Unfortunately it didn't help.
>>
>> On Monday, November 7, 2016 at 3:44:29 PM UTC-5, Tom Breloff wrote:
>>>
>>> I'll ask the obvious question... did you try 
>>> "Blink.AtomShell.install()"?  Nice work getting as far as you did.
>>>
>>>
>>>
>

Re: [julia-users] problems (and some fixes) for using Plots and PlotlyJS on FreeBSD

2016-11-07 Thread Tom Breloff
You should probably open issues/PRs in the individual packages then... this
sounds like a Blink issue.

On Mon, Nov 7, 2016 at 5:09 PM, Kostas Oikonomou <
kostas.oikonomo...@gmail.com> wrote:

> Yes, I did.  Unfortunately it didn't help.
>
> On Monday, November 7, 2016 at 3:44:29 PM UTC-5, Tom Breloff wrote:
>>
>> I'll ask the obvious question... did you try
>> "Blink.AtomShell.install()"?  Nice work getting as far as you did.
>>
>>
>>


Re: [julia-users] problems (and some fixes) for using Plots and PlotlyJS on FreeBSD

2016-11-07 Thread Kostas Oikonomou
Yes, I did.  Unfortunately it didn't help.

On Monday, November 7, 2016 at 3:44:29 PM UTC-5, Tom Breloff wrote:
>
> I'll ask the obvious question... did you try "Blink.AtomShell.install()"?  
> Nice work getting as far as you did.
>
>
>

[julia-users] Re: ANN: new blog post on array indexing, iteration, and multidimensional algorithms

2016-11-07 Thread Páll Haraldsson
On Monday, February 1, 2016 at 6:55:06 PM UTC, Tim Holy wrote:
>
> This new blog post 
>
> http://julialang.org/blog/2016/02/iteration/


For others to know, it's

http://julialang.org/blog/2016/02/iteration

without the /

Should servers ignore extra / ? Do some?



Re: [julia-users] problems (and some fixes) for using Plots and PlotlyJS on FreeBSD

2016-11-07 Thread Tom Breloff
I'll ask the obvious question... did you try "Blink.AtomShell.install()"?
Nice work getting as far as you did.

On Mon, Nov 7, 2016 at 3:35 PM, Kostas Oikonomou <
kostas.oikonomo...@gmail.com> wrote:

> I am using Julia 0.5.0 on FreeBSD 11.  I've had a few problems trying to
> install the Plots and PlotlyJS packages:
>
> 1. Just after installing Plots, I had to make this fix in
> ~/.julia/v0.5/Plots/src/backends/web.jl, function open_browser_window:
>
>@static if is_linux() || is_bsd()
> return run(`xdg-open $(filename)`)
>end
>
> 2. Now trying to install PlotlyJS.  HttpParser doesn't build, because in
> BinDeps.jl, function unpack_cmd(...), says
>
>elseif extension == ".zip"
>return (`unzip -x $file -d $directory`)
>
> The /usr/bin/unzip on FreeBSD doesn't understand "-x" (more precisely, it
> thinks
> it means "exclude").  GNU gunzip doesn't understand it either.  What
> "unzip" is
> this supposed to be?  I made an ugly hack to work around this.
>
>
> 3. In ~/.julia/v0.5/Blink/src/AtomShell/process.jl: I had to add is_bsd()
> to
>
> @static if is_apple()
>   const _electron = resolve("Blink", "deps/Julia.app/Contents/
> MacOS/Electron")
> elseif is_linux() || is_bsd()
>   const _electron = resolve("Blink", "deps/atom/electron")
> elseif is_windows()
>   const _electron = resolve("Blink", "deps", "atom", "electron.exe")
> end
>
> 4. After all this, I still get the error:
>
> julia> using Plots
> julia> plotlyjs()
> julia> plot(x -> x^2, rand(10))
> Error showing value of type Plots.Plot{Plots.PlotlyJSBackend}:
> ERROR: Cannot find Electron. Try `Blink.AtomShell.install()`.
>  in electron() at /usr/home/ko/.julia/v0.5/Blink/src/AtomShell/process.
> jl:53
>
>
> Thanks for any help.
>
> Kostas
>


Re: [julia-users] Rewriting this function from python to julia

2016-11-07 Thread Stefan Karpinski
Yeah, that version is considerably more concise as well. My version is the
"how you would fix the thing you were trying to do" version :)

On Mon, Nov 7, 2016 at 3:27 PM, Steven G. Johnson 
wrote:

> On Monday, November 7, 2016 at 3:17:54 PM UTC-5, Jacob Yates wrote:
>>
>> I know ^ is an exponent. The whole function is meant to xor strings the
>> strings end up being the variables s and t
>>
>
> By "xor the strings", I think you mean "xor the bytes"?   Note that chr
> and ord in Python only work for ASCII characters, so I guess you are only
> interested in ASCII data?   In that case, I would do:
>
> xorstrings(s::String, t::String) = String(s.data $ t.data)
>
> (requires Julia 0.5).   You will have to think carefully about whether you
> want to handle non-ASCII Unicode strings and what you want to do in that
> case.  (The above code will hande non-ASCII data by xor-ing their UTF-8
> representations.  It's not clear whether this is what you want.)
>


[julia-users] problems (and some fixes) for using Plots and PlotlyJS on FreeBSD

2016-11-07 Thread Kostas Oikonomou
I am using Julia 0.5.0 on FreeBSD 11.  I've had a few problems trying to 
install the Plots and PlotlyJS packages:

1. Just after installing Plots, I had to make this fix in
~/.julia/v0.5/Plots/src/backends/web.jl, function open_browser_window:

   @static if is_linux() || is_bsd()
return run(`xdg-open $(filename)`)
   end

2. Now trying to install PlotlyJS.  HttpParser doesn't build, because in
BinDeps.jl, function unpack_cmd(...), says

   elseif extension == ".zip"
   return (`unzip -x $file -d $directory`)

The /usr/bin/unzip on FreeBSD doesn't understand "-x" (more precisely, it 
thinks
it means "exclude").  GNU gunzip doesn't understand it either.  What 
"unzip" is
this supposed to be?  I made an ugly hack to work around this.


3. In ~/.julia/v0.5/Blink/src/AtomShell/process.jl: I had to add is_bsd() to

@static if is_apple()
  const _electron = resolve("Blink", 
"deps/Julia.app/Contents/MacOS/Electron")
elseif is_linux() || is_bsd()
  const _electron = resolve("Blink", "deps/atom/electron")
elseif is_windows()
  const _electron = resolve("Blink", "deps", "atom", "electron.exe")
end

4. After all this, I still get the error:

julia> using Plots
julia> plotlyjs()
julia> plot(x -> x^2, rand(10))
Error showing value of type Plots.Plot{Plots.PlotlyJSBackend}:
ERROR: Cannot find Electron. Try `Blink.AtomShell.install()`.
 in electron() at /usr/home/ko/.julia/v0.5/Blink/src/AtomShell/process.jl:53


Thanks for any help.

Kostas


Re: [julia-users] Rewriting this function from python to julia

2016-11-07 Thread Steven G. Johnson
On Monday, November 7, 2016 at 3:17:54 PM UTC-5, Jacob Yates wrote:
>
> I know ^ is an exponent. The whole function is meant to xor strings the 
> strings end up being the variables s and t
>
 
By "xor the strings", I think you mean "xor the bytes"?   Note that chr and 
ord in Python only work for ASCII characters, so I guess you are only 
interested in ASCII data?   In that case, I would do:

xorstrings(s::String, t::String) = String(s.data $ t.data)

(requires Julia 0.5).   You will have to think carefully about whether you 
want to handle non-ASCII Unicode strings and what you want to do in that 
case.  (The above code will hande non-ASCII data by xor-ing their UTF-8 
representations.  It's not clear whether this is what you want.)


Re: [julia-users] Rewriting this function from python to julia

2016-11-07 Thread Stefan Karpinski
You also need parens around (a,b):

julia> xorStrings(s,t) = join(Char(Int(a) $ Int(b)) for (a,b) in zip(s,t))
xorStrings (generic function with 1 method)

julia> xorStrings("foo","bar")
"\x04\x0e\x1d"

julia> xorStrings("foo",ans)
"bar"


On Mon, Nov 7, 2016 at 3:17 PM, blm22  wrote:

> I know ^ is an exponent. The whole function is meant to xor strings the
> strings end up being the variables s and t
>
> On Nov 7, 2016 15:12, "Stefan Karpinski"  wrote:
>
>> ^ isn't xor in Julia, it's exponentiation. You can use infix $ instead.
>>
>> On Mon, Nov 7, 2016 at 3:02 PM, Jacob Yates  wrote:
>>
>>> return "".join(chr(ord(a)^ord(b)) for a,b in zip(s,t))
>>>
>>>
>>>
>>> Now I know that chr = Char, ord = Int, and zip = tuple in julia. But
>>> while using this in that context I get a load error saying the I'm missing
>>> a ", or )"
>>>
>>>
>>> function xorStrings(s,t)
>>> global xorStr = join(Char(Int(a)^Int(b)) for a,b in tuple(s,t)
>>> exit
>>>
>>
>>


Re: [julia-users] Rewriting this function from python to julia

2016-11-07 Thread blm22
I know ^ is an exponent. The whole function is meant to xor strings the
strings end up being the variables s and t

On Nov 7, 2016 15:12, "Stefan Karpinski"  wrote:

> ^ isn't xor in Julia, it's exponentiation. You can use infix $ instead.
>
> On Mon, Nov 7, 2016 at 3:02 PM, Jacob Yates  wrote:
>
>> return "".join(chr(ord(a)^ord(b)) for a,b in zip(s,t))
>>
>>
>>
>> Now I know that chr = Char, ord = Int, and zip = tuple in julia. But
>> while using this in that context I get a load error saying the I'm missing
>> a ", or )"
>>
>>
>> function xorStrings(s,t)
>> global xorStr = join(Char(Int(a)^Int(b)) for a,b in tuple(s,t)
>> exit
>>
>
>


Re: [julia-users] Rewriting this function from python to julia

2016-11-07 Thread Stefan Karpinski
^ isn't xor in Julia, it's exponentiation. You can use infix $ instead.

On Mon, Nov 7, 2016 at 3:02 PM, Jacob Yates  wrote:

> return "".join(chr(ord(a)^ord(b)) for a,b in zip(s,t))
>
>
>
> Now I know that chr = Char, ord = Int, and zip = tuple in julia. But while
> using this in that context I get a load error saying the I'm missing a ",
> or )"
>
>
> function xorStrings(s,t)
> global xorStr = join(Char(Int(a)^Int(b)) for a,b in tuple(s,t)
> exit
>


[julia-users] Rewriting this function from python to julia

2016-11-07 Thread Jacob Yates


return "".join(chr(ord(a)^ord(b)) for a,b in zip(s,t))



Now I know that chr = Char, ord = Int, and zip = tuple in julia. But while 
using this in that context I get a load error saying the I'm missing a ", 
or )"


function xorStrings(s,t)
global xorStr = join(Char(Int(a)^Int(b)) for a,b in tuple(s,t)
exit


RE: [julia-users] Getting parameter names from Method

2016-11-07 Thread David Anthoff
Thanks!

 

I’ve now been using Base.arg_decl_parts, which also seems to work. Any word of 
wisdom which of these two approaches is “better”?

 

From: julia-users@googlegroups.com [mailto:julia-users@googlegroups.com] On 
Behalf Of Ralph Smith
Sent: Friday, November 4, 2016 8:23 PM
To: julia-users 
Subject: Re: [julia-users] Getting parameter names from Method

 

julia> mt=methods(randjump)

# 2 methods for generic function "randjump":

randjump(r::MersenneTwister, jumps::Integer) at random.jl:145

randjump(mt::MersenneTwister, jumps::Integer, jumppoly::AbstractString) at 
random.jl:137

 

julia> mt.ms[2].lambda_template.slotnames

8-element Array{Any,1}:

 Symbol("#self#")

 :mt 

 :jumps  

 :jumppoly   

 :mts

 Symbol("#temp#")

 :i  

 :cmt

 

julia> mt.ms[2].lambda_template.nargs

4

 




On Friday, November 4, 2016 at 7:00:56 PM UTC-4, David Anthoff wrote:

How do I get at this nargs field? On julia 0.5 Method doesn't seem to have a 
field with that name? 

> -Original Message- 
> From: julia...@googlegroups.com   [mailto:julia-   
> us...@googlegroups.com  ] On Behalf Of Yichao Yu 
> Sent: Friday, November 4, 2016 3:54 PM 
> To: Julia Users  
> Subject: Re: [julia-users] Getting parameter names from Method 
> 
> On Fri, Nov 4, 2016 at 6:31 PM, David Anthoff   > 
> wrote: 
> > Is there a way to get the names of the parameters of a method from a 
> > Method type instance on julia 0.5? 
> 
> Roughly: 
> 
> nargs tell you how many arguments the method accepts, the first one being 
> the object (function) being called. 
> The local variables names are available in the CodeInfo.slotnames and the 
> first nargs ones are the parameter names. 
> The CodeInfo can be found in the source field of the method for non- 
> generated functions and unspecialized.inferred for generated function. 
> 
> > 
> > 
> > 
> > Thanks, 
> > 
> > David 



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

2016-11-07 Thread Steven G. Johnson


On Monday, November 7, 2016 at 9:45:37 AM UTC-5, Mauro wrote:
>
> On Mon, 2016-11-07 at 15:27, Fred  
> wrote: 
> > Hi Steven, 
> > 
> > 
> > I also tried a = Array{String}() unfortunately it produces errors as 
> well. 
>
> Array{String}(0) 
>

Whoops, sorry about the typo. 


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

2016-11-07 Thread Fred
Thank you very much Mauro, that was the mistake ! :)


> Array{String}(0) 
>
> works.  The other creates a zero-dimensional vector (just like a scalar) 
> to which you cannot push. 
>
> > julia> a = Array{String}() 
> > WARNING: Base.String is deprecated, use AbstractString instead. 
> >  likely near no file:0 
> > 0-dimensional Array{AbstractString,0}: 
> > #undef 
> > 
> > 
> > julia> for k in keys(dict) 
> > if dict[k] < 2 
> >  continue 
> > end 
> >  push!(a, k) 
> >end 
> > ERROR: MethodError: `push!` has no method matching 
> push!(::Array{AbstractString 
> > ,0}, ::ASCIIString) 
> > Closest candidates are: 
> >  push!(::Any, ::Any, ::Any) 
> >  push!(::Any, ::Any, ::Any, ::Any...) 
> >  push!(::Array{Any,1}, ::ANY) 
> >  ... 
> > [inlined code] from none:5 
> > in anonymous at no file:0 
>


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

2016-11-07 Thread Mauro
On Mon, 2016-11-07 at 15:27, Fred  wrote:
> Hi Steven,
>
>
> I also tried a = Array{String}() unfortunately it produces errors as well.

Array{String}(0)

works.  The other creates a zero-dimensional vector (just like a scalar)
to which you cannot push.

> julia> a = Array{String}()
> WARNING: Base.String is deprecated, use AbstractString instead.
>  likely near no file:0
> 0-dimensional Array{AbstractString,0}:
> #undef
>
>
> julia> for k in keys(dict)
> if dict[k] < 2
>  continue
> end
>  push!(a, k)
>end
> ERROR: MethodError: `push!` has no method matching 
> push!(::Array{AbstractString
> ,0}, ::ASCIIString)
> Closest candidates are:
>  push!(::Any, ::Any, ::Any)
>  push!(::Any, ::Any, ::Any, ::Any...)
>  push!(::Array{Any,1}, ::ANY)
>  ...
> [inlined code] from none:5
> in anonymous at no file:0


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

2016-11-07 Thread Fred
Hi Steven,


I also tried  a = Array{String}() unfortunately it produces errors as well.



julia> a = Array{String}()
WARNING: Base.String is deprecated, use AbstractString instead.
  likely near no file:0
0-dimensional Array{AbstractString,0}:
#undef


julia> for k in keys(dict)
 if dict[k] < 2
   continue
 end
   push!(a, k)
   end
ERROR: MethodError: `push!` has no method matching push!(::Array{
AbstractString,0}, ::ASCIIString)
Closest candidates are:
  push!(::Any, ::Any, ::Any)
  push!(::Any, ::Any, ::Any, ::Any...)
  push!(::Array{Any,1}, ::ANY)
  ...
 [inlined code] from none:5
 in anonymous at no file:0






[julia-users] Re: ANN: new blog post on array indexing, iteration, and multidimensional algorithms

2016-11-07 Thread Steven G. Johnson
Would be nice to have a simple performance comparison to NumPy multi-indices 
 for some 
simple operation like the boxcar filter.


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

2016-11-07 Thread Fred
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}

for k in keys(dict)
  if dict[k] < 2
continue
  end
push!(a, k) # building array from keys produces errors
end


ERROR: MethodError: `push!` has no method matching push!(::Type{Array{
AbstractString,N}}, ::ASCIIString)




Thank you for your help !


Re: [julia-users] using or import a specific package version

2016-11-07 Thread Adrian Salceanu
I have used DeclarativePackages 
(https://github.com/rened/DeclarativePackages.jl) - it's quite all right. 
Also, a while ago I've stumbled onto Playground 
(https://github.com/Rory-Finnegan/Playground.jl) but I haven't tried it 
myself. 


sâmbătă, 5 noiembrie 2016, 15:09:50 UTC+2, Steven G. Johnson a scris:
>
>
>
> On Saturday, November 5, 2016 at 12:38:41 AM UTC-4, Tom Lee wrote:
>>
>> Project-local environments sounds like exactly what I am after. Great to 
>> hear its being worked on. I guess we will need to wait until 0.6 for Pkg3?
>>
>
> No, you can do that now.
>
> insert!(LOAD_PATH, 1, mypath)
> insert!(Base.LOAD_CACHE_PATH, 1, mypath)
>
> will add mypath to the module and cache loading path.  Then you can put 
> whatever modules you want into mypath and they will take precedence over 
> the ones in the standard path.
>


[julia-users] Re: How to stop program execution at some point

2016-11-07 Thread Tamas Papp
See quit(), and in general exit(code).

On Monday, November 7, 2016 at 11:21:14 AM UTC+1, Fred wrote:
>
> Hi,
>
> I search in Julia the equivalent of Perl 
> die;
> to stop the execution of a program.
>
> I tried "break" but it produces an error :
> ERROR: LoadError: syntax: break or continue outside loop
> I did not found "stop" as well.
>
> Thanks !
>


[julia-users] Re: How to stop program execution at some point

2016-11-07 Thread Fred
Yes Michele, "die" is able to stop execution at any point, even outside a 
loop, this is what I searched and did not found in Julia.


[julia-users] Re: How to stop program execution at some point

2016-11-07 Thread Michele Zaffalon
If I understand correctly and die raises an exception in Perl, then error() 
is the equivalent in Julia.
`break` can only be used inside a loop, for instance when a condition is 
met:

while true
  cond && break
end




On Monday, November 7, 2016 at 11:21:14 AM UTC+1, Fred wrote:
>
> Hi,
>
> I search in Julia the equivalent of Perl 
> die;
> to stop the execution of a program.
>
> I tried "break" but it produces an error :
> ERROR: LoadError: syntax: break or continue outside loop
> I did not found "stop" as well.
>
> Thanks !
>


[julia-users] How to stop program execution at some point

2016-11-07 Thread Fred
Hi,

I search in Julia the equivalent of Perl 
die;
to stop the execution of a program.

I tried "break" but it produces an error :
ERROR: LoadError: syntax: break or continue outside loop
I did not found "stop" as well.

Thanks !


Re: [julia-users] Re: Immutable type modification of SparseMatrixCSC

2016-11-07 Thread Milan Bouchet-Valat
Le dimanche 06 novembre 2016 à 15:31 -0800, Kristoffer Carlsson a écrit :
> 
> 
> > For reference, here's the long discussion that happened before making 
> > that change: 
> > https://github.com/JuliaLang/julia/pull/16371 
> > 
> > Indeed I think Tony was right that this has undesirable consequences in 
> > terms of usability. Not being able to use the same in-place API for 
> > dense and sparse matrices is a no-go IMHO. 
> > 
> 
> Please elaborate. You cannot resize dense matrices in-place either.
>
> Just create a new matrix from the fields of the old one if you want
> to change the size. How does this limit usability?
Right, I was being sloppy. That remark applies to sparse vectors, though.


Regards

 
> > 
> > Regards 
> > 
> > > > Le samedi 05 novembre 2016 à 20:11 -0700, vav...@uwaterloo.ca a 
> > écrit : 
> > > Just to clarify, you don't actually need to allocate the memory for 
> > > two large sparse matrices.  You can change colptr, rowval, and nzval 
> > > in place (as you have already done) and then create a new sparse 
> > > matrix using these modified arrays.  In this case, the arrays won't 
> > > be copied over; instead the new sparse matrix will get a pointer to 
> > > the already-allocated arrays.  This technique could lead to some 
> > > subtle program bugs (because if two sparse matrices share an nzval 
> > > array, then any change to one affects the other), but you can guard 
> > > against this by making the old matrix's name inaccessible, for 
> > > instance, by giving the new matrix the same name as the old one. 
> > > 
> > > -- Steve Vavasis 
> > > 
> > > 
> > > > I see. returning a new, smaller instance of the matrix was my 
> > > > temporary solution. Bummer that it's necessary... Is it really so 
> > > > strange to want to change the size of a  
> > > > 
> > > > Another alternative which occurs to me is to make some child class 
> > > > of SparseCSCMatrix with two more arrays, each with one element, 
> > > > which track the sizes? Since I am making the matrix smaller, not 
> > > > larger, I can't imagine that this would be an issue. However, if I 
> > > > need to allocate two large sparse matrices just to remove a row/col 
> > > > pair, then I can suddenly use half the memory I could before... 
> > > > 
> > > > 
> > > > > When a type is immutable, that means you can't modify the data in 
> > > > > the type.  If a field of a type is mutable, a reference to it is 
> > > > > stored in the type, and you cannot modify that reference.  In the 
> > > > > case of SparseMatrixCSC, that means you can't make A.colptr point 
> > > > > to a different array, for example.  You are still free to change 
> > > > > the values in A.colptr, because that does not require modifying 
> > > > > the reference.  If the field is immutable, then the value itself 
> > > > > is stored in the type, not a reference to the value, and you 
> > > > > cannot modify the value.  That's why you get the error in the 
> > > > > example. 
> > > > > 
> > > > > The best solution I can think of for your rmCol example is to 
> > > > > create a new SparseMatrixCSC that uses the same arrays as the old 
> > > > > one (to avoid increasing memory usage) and return it.  Replacing 
> > > > > the last line of rmCol with: 
> > > > > 
> > > > >   SparseMatrixCSC(m, n-1, A.colptr, A.rowval, A.nzval) 
> > > > > 
> > > > >   should do the trick.  The only sticky point is that the 
> > > > > original A now contains invalid data, so you'll have to make sure 
> > > > > only the the matrix returned from rmCol is used in the future, 
> > > > > not the original A. 
> > > > > 
> > > > >   Jared Crean 
> > > > > 
> > > > > 
> > > > > > The SparseMatrixCSC type is immutable, which I understand to 
> > > > > > mean that I must respect the types of the attributes of 
> > > > > > SparseMatrixCSC types, as well as not changing the attributes 
> > > > > > themselves. 
> > > > > > 
> > > > > > The following gives a loadError (type is immutable).  I am 
> > > > > > confused that I can modify the colptr and rowval attributes of 
> > > > > > A, but not the A.n attribute. Why is this? I am trying to 
> > > > > > change the size of a sparse matrix after removing the data from 
> > > > > > a row and column. 
> > > > > > 
> > > > > > I have checked that both A.n and A.n - 1 are type Int. 
> > > > > > 
> > > > > > function rmCol(A::SparseMatrixCSC, rmCol::Int) 
> > > > > >     colRmRange = A.colptr[rmCol]:(A.colptr[rmCol+1]-1) 
> > > > > >     filter!(e -> e != rmCol, A.colptr) 
> > > > > >      
> > > > > >     deleteat!(A.rowval, rowval[colRmRange]) 
> > > > > >     deleteat!(A.nzval, colRmRange) 
> > > > > >     A.n -= 1 # inclusion of this line throws error 
> > > > > >      
> > > > > > end 
> > > > > > 
> > > > > 
> > > >