[julia-users] Re: for loop with multiple variables

2016-05-10 Thread Vishnu Raj
Thanks :)

On Tuesday, May 10, 2016 at 4:44:18 PM UTC+5:30, Lutfullah Tomak wrote:
>
> for (i,j)=zip(0:5,6:10)
> println(i+j)
> end
> On Tuesday, May 10, 2016 at 2:02:41 PM UTC+3, Vishnu Raj wrote:
>>
>> What  if the equivalent of the C code below
>> for( i=0, j=6; i<=5, j <=10; i++, j++ ) print( "%d", i+j );
>> in julia?
>>
>

[julia-users] Re: for loop with multiple variables

2016-05-10 Thread Lutfullah Tomak
for (i,j)=zip(0:5,6:10)
println(i+j)
end
On Tuesday, May 10, 2016 at 2:02:41 PM UTC+3, Vishnu Raj wrote:
>
> What  if the equivalent of the C code below
> for( i=0, j=6; i<=5, j <=10; i++, j++ ) print( "%d", i+j );
> in julia?
>


Re: [julia-users] Re: For loop = or in?

2015-10-29 Thread Tom Breloff
Agreed with Tony.  Having lots of ways to do the same thing is fine, as
long as we had no other syntactical use for the `=`.  Anyone want to
support notation like: `for y = sin(_) in 1:10 ... end`?  Probably not, so
no big deal to keep both around.

Also I just saw Tk's post with this great example of `=` better than `in`: `a
= [ f(i,j,k) for i=1:p, j=1:q, k=1:r ]`

On Thu, Oct 29, 2015 at 9:10 AM, Tony Kelman  wrote:

> How is having multiple syntaxes for something automatically bad? I don't
> hear people complaining that for loops are redundant when you could just do
> while with a counter, or that enumerate is equivalent. Having style
> guidelines for base to say when one choice makes more sense than another is
> fine, but this thread's overblown.


Re: [julia-users] Re: For loop = or in?

2015-10-29 Thread Seth
+1

On Thursday, October 29, 2015 at 5:56:46 AM UTC-7, Tom Breloff wrote:
>
> Lets close the topic.  Keep them both.
>
> On Thu, Oct 29, 2015 at 8:47 AM, feza  
> wrote:
>
>> My only problem with `=` vs `in`
>> is that even the base julia code is inconsistent! Looking at one file ( I 
>> can't remember which now)
>> it had both
>> i = 1:nr
>> and
>> i in 1:n
>> Again this was in the same file! Please tell me I am not being pedantic 
>> when I saw this and thought this must be fixed if even the base is being 
>> inconsistent.
>>
>> On Thursday, October 29, 2015 at 8:44:03 AM UTC-4, mschauer wrote:
>>>
>>> Do we want to give up on this topic? Then we should do so in an earnest 
>>> way and close the case with a clear message, ideally after 
>>> establishing if we want to add a style recommendation about the use of 
>>> ``=`` and ``in`` to 
>>> http://docs.julialang.org/en/release-0.4/manual/style-guide/. Currently 
>>> the manual states in the control-flow chapter "In general, the for loop 
>>> construct can iterate over any container. In these cases, the alternative 
>>> (but fully equivalent) keyword in is typically used instead of =, since 
>>> it makes the code read more clearly."
>>>
>>
>

Re: [julia-users] Re: For loop = or in?

2015-10-29 Thread Tamas Papp
1. Unless there is a single syntax, the topic will inevitably come up
again and again. This does not necessarily mean that we need a single
syntax, but this is a cost of the status quo (ie having both = and in)
that has to be considered.

2. I think everyone said what they wanted to say. IMO it would be great
if the key people in Julia could make a decision about this, either
deprecate =, or in, or keep both, anything is fine, just have a clear
indication of what is going to happen so that people could submit a PR
for the documentation and the FAQ (if both are kept), or the base code
(or one is dropped).

Best,

Tamas

On Thu, Oct 29 2015, feza  wrote:

> My only problem with `=` vs `in`
> is that even the base julia code is inconsistent! Looking at one file ( I 
> can't remember which now)
> it had both
> i = 1:nr
> and
> i in 1:n
> Again this was in the same file! Please tell me I am not being pedantic 
> when I saw this and thought this must be fixed if even the base is being 
> inconsistent.
>
> On Thursday, October 29, 2015 at 8:44:03 AM UTC-4, mschauer wrote:
>>
>> Do we want to give up on this topic? Then we should do so in an earnest 
>> way and close the case with a clear message, ideally after 
>> establishing if we want to add a style recommendation about the use of 
>> ``=`` and ``in`` to 
>> http://docs.julialang.org/en/release-0.4/manual/style-guide/. Currently 
>> the manual states in the control-flow chapter "In general, the for loop 
>> construct can iterate over any container. In these cases, the alternative 
>> (but fully equivalent) keyword in is typically used instead of =, since 
>> it makes the code read more clearly."
>>



Re: [julia-users] Re: For loop = or in?

2015-10-29 Thread Tamas Papp
Maybe I was not clear: having multiple syntaxes per se is not
necessarily bad.

What is somewhat inconvenient is that since there is no good reason for
having multiple syntaxes, some newcomers to the language will be
confused, and will ask about this from time to time. Eg this is how this
thread got started; this is not the first one and of course not the
last. And of course then existing users will join in, and reason for =,
in, both, or a third syntax.

This is one of those tricky situations where it is hard to argue that
the status quo is significantly inferior to other options, but since
there is not a compelling reason for it either, the issue will be
discussed from time to time. Which is of course OK, but if both = and in
remain then the FAQ and the manual could clarify that neither is
preferred, both are fine, and there is no semantic difference. 

Best,

Tamas

On Thu, Oct 29 2015, Tony Kelman  wrote:

> How is having multiple syntaxes for something automatically bad? I don't hear 
> people complaining that for loops are redundant when you could just do while 
> with a counter, or that enumerate is equivalent. Having style guidelines for 
> base to say when one choice makes more sense than another is fine, but this 
> thread's overblown.



Re: [julia-users] Re: For loop = or in?

2015-10-29 Thread Tony Kelman
How is having multiple syntaxes for something automatically bad? I don't hear 
people complaining that for loops are redundant when you could just do while 
with a counter, or that enumerate is equivalent. Having style guidelines for 
base to say when one choice makes more sense than another is fine, but this 
thread's overblown.

Re: [julia-users] Re: For loop = or in?

2015-10-29 Thread Kristoffer Carlsson
Well then it's settled. Someone prepare a PR ;)

Re: [julia-users] Re: For loop = or in?

2015-10-29 Thread Glen O
But that's true of just about every instance where there are multiple ways 
of doing things. vcat vs [;], for instance. In some cases, there are 
distinct reasons; in others, there's no functional difference, and it only 
exists for the purposes of making it easier to read, for instance. Like 
f(x) and x |> f. I'm sure there will be people who ask if there's any 
benefit to x|>f over f(x). And the answer, as in this case, is 
"readability".

If the question really comes up over and over again, a FAQ should be 
created to answer it. Changing the way the language works because some 
people will ask questions is, in my opinion, a bad reason to change it.

On Thursday, 29 October 2015 23:44:07 UTC+10, Tamas Papp wrote:
>
> Maybe I was not clear: having multiple syntaxes per se is not 
> necessarily bad. 
>
> What is somewhat inconvenient is that since there is no good reason for 
> having multiple syntaxes, some newcomers to the language will be 
> confused, and will ask about this from time to time. Eg this is how this 
> thread got started; this is not the first one and of course not the 
> last. And of course then existing users will join in, and reason for =, 
> in, both, or a third syntax. 
>
> This is one of those tricky situations where it is hard to argue that 
> the status quo is significantly inferior to other options, but since 
> there is not a compelling reason for it either, the issue will be 
> discussed from time to time. Which is of course OK, but if both = and in 
> remain then the FAQ and the manual could clarify that neither is 
> preferred, both are fine, and there is no semantic difference. 
>
> Best, 
>
> Tamas 
>


Re: [julia-users] Re: For loop = or in?

2015-10-29 Thread feza
My only problem with `=` vs `in`
is that even the base julia code is inconsistent! Looking at one file ( I 
can't remember which now)
it had both
i = 1:nr
and
i in 1:n
Again this was in the same file! Please tell me I am not being pedantic 
when I saw this and thought this must be fixed if even the base is being 
inconsistent.

On Thursday, October 29, 2015 at 8:44:03 AM UTC-4, mschauer wrote:
>
> Do we want to give up on this topic? Then we should do so in an earnest 
> way and close the case with a clear message, ideally after 
> establishing if we want to add a style recommendation about the use of 
> ``=`` and ``in`` to 
> http://docs.julialang.org/en/release-0.4/manual/style-guide/. Currently 
> the manual states in the control-flow chapter "In general, the for loop 
> construct can iterate over any container. In these cases, the alternative 
> (but fully equivalent) keyword in is typically used instead of =, since 
> it makes the code read more clearly."
>


Re: [julia-users] Re: For loop = or in?

2015-10-29 Thread Tom Breloff
Lets close the topic.  Keep them both.

On Thu, Oct 29, 2015 at 8:47 AM, feza  wrote:

> My only problem with `=` vs `in`
> is that even the base julia code is inconsistent! Looking at one file ( I
> can't remember which now)
> it had both
> i = 1:nr
> and
> i in 1:n
> Again this was in the same file! Please tell me I am not being pedantic
> when I saw this and thought this must be fixed if even the base is being
> inconsistent.
>
> On Thursday, October 29, 2015 at 8:44:03 AM UTC-4, mschauer wrote:
>>
>> Do we want to give up on this topic? Then we should do so in an earnest
>> way and close the case with a clear message, ideally after
>> establishing if we want to add a style recommendation about the use of
>> ``=`` and ``in`` to
>> http://docs.julialang.org/en/release-0.4/manual/style-guide/. Currently
>> the manual states in the control-flow chapter "In general, the for loop
>> construct can iterate over any container. In these cases, the alternative
>> (but fully equivalent) keyword in is typically used instead of =, since
>> it makes the code read more clearly."
>>
>


[julia-users] Re: For loop = or in?

2015-10-29 Thread Tk
Hi,

Before closing (this thread?), I would like to write one more thing. First, 
because I am not a native English speaker, it doesn't
actually matter how 1:n etc "reads" (simply because I don't pronounce them 
in mind :) Second, when I started
learning Julia half a year ago (sorry for a slow starter...), I also felt 
awkward that I have two kinds of syntax for the same
thing. So I tried to use "in" only for the time being (to mimic Python). 
But after a while I got back to "=", because it is gives  more concise (and 
IMO more readable) expressions, particularly in array comprehension. For 
example,

a = [ f(i,j,k) for i=1:p, j=1:q, k=1:r ]

a = [ f(i,j,k) for i in 1:p, j in 1:q, k in 1:r ]

# In this sense \in (greek letter) is as concise as =, but typing in the 
greek character takes a bit more time... (though I may be
able to customize Emacs if necessary).

As for Python-like, "there should be only one syntax for one purpose 
(semantic?)" policy (sorry if my English is strange), there seem to be many 
counter examples in Julia. For example, vcat() and [ a; b ] seem 
essentially the same, while the latter is probably there for brevity. I 
think it is not bad to have a shorter way to write it unless there are 
serious problems.

Btw, apart from the = vs in stuff, I really like this language because it 
allows multiple for-loops to be written concisely as

for i = 1:p,
 j = 1:q,
 k = 1:r
 (do something)
end

Indeed, I used to use a macro like this in C++ before that allows to write

For( i, 1, p,
   j, 1, p,
   k, 1, r ) {
 (do something)
}

so Julia has become one of my most favorite languages :)
Sorry for a long post...


Re: [julia-users] Re: For loop = or in?

2015-10-29 Thread mschauer
Do we want to give up on this topic? Then we should do so in an earnest way 
and close the case with a clear message, ideally after 
establishing if we want to add a style recommendation about the use of 
``=`` and ``in`` to 
http://docs.julialang.org/en/release-0.4/manual/style-guide/. Currently the 
manual states in the control-flow chapter "In general, the for loop 
construct can iterate over any container. In these cases, the alternative 
(but fully equivalent) keyword in is typically used instead of =, since it 
makes the code read more clearly."


Re: [julia-users] Re: For loop = or in?

2015-10-29 Thread Tk
> `=` better than `in`: `a = [ f(i,j,k) for i=1:p, j=1:q, k=1:r ]`

Please note that I am not trying to claim "=" is better universally (i.e. 
for everyone) based on this example,
because some people prefer more English like syntax for clarity of meaning 
(even when a bit longer).

So anyway, it would be nice if the official document will be updated to 
emphasize that there is no distinction
between in and = (used with for-loops, as of v0.4), and that if one 
prefers, one could use "in" everywhere (this is
a great point). Then we can just cite that explanation when a question 
arises for a while :)


On Thursday, October 29, 2015 at 10:41:19 PM UTC+9, Tom Breloff wrote:
>
> Agreed with Tony.  Having lots of ways to do the same thing is fine, as 
> long as we had no other syntactical use for the `=`.  Anyone want to 
> support notation like: `for y = sin(_) in 1:10 ... end`?  Probably not, so 
> no big deal to keep both around.
>
> Also I just saw Tk's post with this great example of `=` better than `in`: 
> `a = [ f(i,j,k) for i=1:p, j=1:q, k=1:r ]`
>
> On Thu, Oct 29, 2015 at 9:10 AM, Tony Kelman  > wrote:
>
>> How is having multiple syntaxes for something automatically bad? I don't 
>> hear people complaining that for loops are redundant when you could just do 
>> while with a counter, or that enumerate is equivalent. Having style 
>> guidelines for base to say when one choice makes more sense than another is 
>> fine, but this thread's overblown.
>
>
>

Re: [julia-users] Re: For loop = or in?

2015-10-29 Thread Steven G. Johnson
See https://github.com/JuliaLang/julia/issues/8487

On Wednesday, October 28, 2015 at 10:16:37 AM UTC-4, Stefan Karpinski wrote:
>
> No, it's just a matter of changing the parser to accept that – and 
> convincing people that it's a good idea.
>
> On Wed, Oct 28, 2015 at 9:39 AM, DNF  
> wrote:
>
>> On Wednesday, October 28, 2015 at 2:29:54 PM UTC+1, Stefan Karpinski 
>> wrote:
>>>
>>> I think we're getting into Parkinson's law territory here. First off, I 
>>> don't think this causes all that much confusion. Second, since this is pure 
>>> syntax involving a keyword no less, this is one of the easiest things to 
>>> mechanically fix should we chose to do so in the future.
>>>
>>
>> Fair enough. Could I just ask a question out of curiosity (not to try to 
>> convince anyone of anything)?
>>
>> Are there any technical problems (or other problems) associated with 
>> getting '∈' to work as a keyword, such as 
>> for i ∈ etc...
>> ?
>>
>
>

Re: [julia-users] Re: For loop = or in?

2015-10-29 Thread Tomas Lycken
I read 1:n that way. And even if I didn't, I prefer to think about a looping 
construct as "do this for each element in that collection" - and regardless of 
how I pronounce 1:n, I see it as a collection since it inherits AbstractArray. 

But I can also see how other mental models work for you. There's a lot of talk 
in this thread along the lines of "my mental model of this construct is better 
than yours, and therefore my syntax preference is better than yours." I find 
this ridiculously inconstructive - bordering on children arguing in the 
sandbox... To me, this just indicates that both mental models are valid that 
both syntaxes should, at least for the time being, stay. The fact that no clear 
winner can be found by counting usages in base further supports this. 

There is a suggestion in this thread worth keeping, though - supporting unicode 
\in would be a nice addition for those of us who embrace supersets of ascii.

// Tomas 

[julia-users] Re: For loop = or in?

2015-10-29 Thread Alireza Nejati
I'm with Tomas here - if anything this thread is testimony to the fact that 
both '=' and 'in' should be left in.


Re: [julia-users] Re: For loop = or in?

2015-10-29 Thread Pontus Stenetorp
I have to agree with Stefan that this is turning into
bikeshedding [1].  My personal bias is towards `in`, probably due to
my many years of Python, but I am convinced that both keeping the
current duality or picking one of them will not lead to a mental
overload.  In fact, in order for us to stop spending brain cycles on
this, it would even seem sane to me to take the hash of the next
commit after this e-mail has been sent, apply modulo 10, if the number
is 1-3, preserve the status quo, for 4-6, switch to using `=`, for
7-9, switch to using `in`, for 0, discard the number and use the next
commit instead.

Pontus

[1]: https://en.wikipedia.org/wiki/Parkinson's_law_of_triviality


Re: [julia-users] Re: For loop = or in?

2015-10-29 Thread Tony Kelman
Pontus, you're awesome. Technically the first commit here was merged 4 
minutes before your post, but funny anyway:

julia> mod(big"0xdfe0cc00e3ae91cd981d0b4243498f8321992fbc",10)
0

julia> mod(big"0xf8a4340548e7d6be31fede13cdc4e0f5f434f33f",10)
7

My opinion would be to leave it since Julia isn't Python and we're not too 
militaristic about "one way to do it" zen nonsense when things aren't 
actively harmful or confusing, but Pontus just about wins me over with that.


On Thursday, October 29, 2015 at 2:38:33 AM UTC-7, Pontus Stenetorp wrote:
>
> I have to agree with Stefan that this is turning into 
> bikeshedding [1].  My personal bias is towards `in`, probably due to 
> my many years of Python, but I am convinced that both keeping the 
> current duality or picking one of them will not lead to a mental 
> overload.  In fact, in order for us to stop spending brain cycles on 
> this, it would even seem sane to me to take the hash of the next 
> commit after this e-mail has been sent, apply modulo 10, if the number 
> is 1-3, preserve the status quo, for 4-6, switch to using `=`, for 
> 7-9, switch to using `in`, for 0, discard the number and use the next 
> commit instead. 
>
> Pontus 
>
> [1]: https://en.wikipedia.org/wiki/Parkinson's_law_of_triviality 
>


Re: [julia-users] Re: For loop = or in?

2015-10-28 Thread DNF


On Wednesday, October 28, 2015 at 9:51:10 AM UTC+1, Tamas Papp wrote:
>
> I am probably old-fashined, but I always prefer to stick to ASCII unless 
> there is a compelling reason. If I want something to stick out, I can 
> always customize Emacs to do it. 
>
 
Well, both 'in' and '=' are ASCII, so that shouldn't be a problem either 
way. 

Also, I don't think it is ideal to have two (or more) operators that are 
> interchangeable as far as the language is concerned, but have stylistic 
> differences assigned to them by convention. If that convention is 
> useful and justified, it should be merged into the language per se; if 
> not, then it just borders on confusing.
>

Admittedly, I understand only about half of this paragraph, but it sounds 
like an argument against having both 'in' and '=' notation in loops. As for 
unicode aliases, I think that ship has sailed. There are lots of those, and 
I don't think they're going anywhere. I don't even know if it's most 
correct to say that '∈' is an alias for 'in', or if 'in' is the English 
transcription of '∈'. They are one and the same as far as I can tell. The 
same cannot really be said about 'in' and '='.

The worst thing, I think, though, is having two different aliases for 'in': 
'∈' in one context, and '=' in the other. Especially since '=' is used in 
the infix position
where '∈' would be natural. 


[julia-users] Re: For loop = or in?

2015-10-28 Thread STAR0SS
I think people grossly exaggerate the "mental cost" of having both = and 
in. It's really not that complicated, well explained in the docs and can 
never cause bugs.

On the other hand the depreciation cost will big quite large, given it 
seems both are used 50/50. Plus the numerous complain posts on this forum. 
Don't fix what's not broken.





Re: [julia-users] Re: For loop = or in?

2015-10-28 Thread Tamas Papp
On Wed, Oct 28 2015, feza  wrote:

> But really this seems like a fundamental enough language construct that 
> there should be only one correct way; but on the other hand my brain 
> doesn't have a problem with `=` and it seems natural since I have been 
> using matlab for a while, even though `in` seems actually to make more 
> sense here.

I think that even simply tossing a coin between = and in and just
picking one would improve on the current situation. Either Matlab or R
users will have to learn a new syntax, but I doubt that this is the
biggest hurdle they will encounter in Julia.

This would resolve the uncertainty, stop "why = or in" questions (they
come up frequently), and also stop further bikeshedding about this.

Best,

Tamas


[julia-users] Re: For loop = or in?

2015-10-28 Thread DNF
You are right, of course. It's just one of those minor cosmetic things you 
fix in a pre-1.0 version, or then maybe never. And it's good not to have 
too many of those.

Also
for i ∈ 1:N
just looks incredibly awesome. 


On Wednesday, October 28, 2015 at 1:38:57 PM UTC+1, STAR0SS wrote:
>
> I think people grossly exaggerate the "mental cost" of having both = and 
> in. It's really not that complicated, well explained in the docs and can 
> never cause bugs.
>
> On the other hand the depreciation cost will big quite large, given it 
> seems both are used 50/50. Plus the numerous complain posts on this forum. 
> Don't fix what's not broken.
>
>
>
>

Re: [julia-users] Re: For loop = or in?

2015-10-28 Thread DNF
On Wednesday, October 28, 2015 at 2:29:54 PM UTC+1, Stefan Karpinski wrote:
>
> I think we're getting into Parkinson's law territory here. First off, I 
> don't think this causes all that much confusion. Second, since this is pure 
> syntax involving a keyword no less, this is one of the easiest things to 
> mechanically fix should we chose to do so in the future.
>

Fair enough. Could I just ask a question out of curiosity (not to try to 
convince anyone of anything)?

Are there any technical problems (or other problems) associated with 
getting '∈' to work as a keyword, such as 
for i ∈ etc...
?


[julia-users] Re: For loop = or in?

2015-10-28 Thread feza
actually its more about simple confusion rather than mental cost @DNF. 
Starting out you either use = or in then you see some other code and they 
use something else and wonder, what is right, is one notation faster or 
better, what's going on? Of course, it's not the simplest thing to try and 
search for in the documents (for someone not familiar with iterator 
terminology, searching for `in` or `=` is useless). Hence Fang's original 
post's concern (and others as evident from this post).

But really this seems like a fundamental enough language construct that 
there should be only one correct way; but on the other hand my brain 
doesn't have a problem with `=` and it seems natural since I have been 
using matlab for a while, even though `in` seems actually to make more 
sense here.

I don't think that this metaphor is actually relevant:

i=1:5
A[i]=B[i].*C[i]

or, you could write it as a loop...

for i=1:5
 A[i]=B[i]*C[i]
end

since the `for` changes meaning completely
i = 1:10
a[i] = b[i].*c[i]

and  the above only makes sense when indexing, not for other iterables


 
In any case, someone should collect the arguments and file an issue on 
github to at least get some additional opinions.

On Wednesday, October 28, 2015 at 8:45:16 AM UTC-4, DNF wrote:
>
> You are right, of course. It's just one of those minor cosmetic things you 
> fix in a pre-1.0 version, or then maybe never. And it's good not to have 
> too many of those.
>
> Also
> for i ∈ 1:N
> just looks incredibly awesome. 
>
>
> On Wednesday, October 28, 2015 at 1:38:57 PM UTC+1, STAR0SS wrote:
>>
>> I think people grossly exaggerate the "mental cost" of having both = and 
>> in. It's really not that complicated, well explained in the docs and can 
>> never cause bugs.
>>
>> On the other hand the depreciation cost will big quite large, given it 
>> seems both are used 50/50. Plus the numerous complain posts on this forum. 
>> Don't fix what's not broken.
>>
>>
>>
>>

Re: [julia-users] Re: For loop = or in?

2015-10-28 Thread Stefan Karpinski
I think we're getting into Parkinson's law territory here. First off, I
don't think this causes all that much confusion. Second, since this is pure
syntax involving a keyword no less, this is one of the easiest things to
mechanically fix should we chose to do so in the future.

On Wed, Oct 28, 2015 at 9:18 AM, Tamas Papp  wrote:

> On Wed, Oct 28 2015, feza  wrote:
>
> > But really this seems like a fundamental enough language construct that
> > there should be only one correct way; but on the other hand my brain
> > doesn't have a problem with `=` and it seems natural since I have been
> > using matlab for a while, even though `in` seems actually to make more
> > sense here.
>
> I think that even simply tossing a coin between = and in and just
> picking one would improve on the current situation. Either Matlab or R
> users will have to learn a new syntax, but I doubt that this is the
> biggest hurdle they will encounter in Julia.
>
> This would resolve the uncertainty, stop "why = or in" questions (they
> come up frequently), and also stop further bikeshedding about this.
>
> Best,
>
> Tamas
>


Re: [julia-users] Re: For loop = or in?

2015-10-28 Thread DNF


On Wednesday, October 28, 2015 at 10:22:45 AM UTC+1, Glen O wrote:
>
> The thing is, it IS an assignment that's going on. In the case of a range, 
> especially, "for i=1:5" says "loop 5 times, with i=1, then i=2, then i=3, 
> then i=4, then i=5". "i' is being assigned to on each iteration. Think of 
> it this way - suppose you were using elementwise operations. You could write
>
> i=1:5
> A[i]=B[i].*C[i]
>
> or, you could write it as a loop...
>
> for i=1:5
>  A[i]=B[i]*C[i]
> end
>

I buy that argument. Both 'in' and '=' make good metaphors for thinking 
about loops. It's that they are different metaphors, while 'in' and '∈' are 
identical in meaning and (arguably) in pronunciation.

Choosing either of them for loops would be fine, but having two different 
synonyms for 'in' is just a bit jarring.
 

> The two pieces of code are doing exactly the same thing; one is just 
> explicitly writing the loop. In what way does restricting to "in" help, in 
> this situation?
>

I don't know about this situation in particular, but I think in general it 
is helping in 
a) simplifying; no more three-way aliasing stuff.
b) consistency; 'in' and '∈' become interchangeable in both contexts.


Re: [julia-users] Re: For loop = or in?

2015-10-28 Thread Stefan Karpinski
No, it's just a matter of changing the parser to accept that – and
convincing people that it's a good idea.

On Wed, Oct 28, 2015 at 9:39 AM, DNF  wrote:

> On Wednesday, October 28, 2015 at 2:29:54 PM UTC+1, Stefan Karpinski wrote:
>>
>> I think we're getting into Parkinson's law territory here. First off, I
>> don't think this causes all that much confusion. Second, since this is pure
>> syntax involving a keyword no less, this is one of the easiest things to
>> mechanically fix should we chose to do so in the future.
>>
>
> Fair enough. Could I just ask a question out of curiosity (not to try to
> convince anyone of anything)?
>
> Are there any technical problems (or other problems) associated with
> getting '∈' to work as a keyword, such as
> for i ∈ etc...
> ?
>


Re: [julia-users] Re: For loop = or in?

2015-10-28 Thread Gabor
My vote is for keeping '='.
It is very readable for counters as is 'in' for other containers.

Confusion?
Considering the investment into learning all the new and powerful Julia 
language constructs,
I don't see why exactly this elegant duality would be a problem for anyone.

It is not even a documentation issue, 
the documentation is already crystal clear:

"In general, the for loop construct can iterate over any container. 
In these cases, the alternative (but fully equivalent) keyword in is 
typically used
instead of =, since it makes the code read more clearly"

On Tuesday, October 27, 2015 at 10:55:23 PM UTC+1, Hai Nguyen wrote:
>
>
>
> On Tue, Oct 27, 2015 at 10:04 AM, Stefan Karpinski  > wrote:
>
>> My general approach is to only use = when the RHS is an explicit range, 
>> as in `for i = 1:n`. For everything else I use `for i in v`. I would be ok 
>> with dropping the = syntax at some point, but it seems pretty harmless to 
>> have it.
>>
>>
> I have 1 vote for removing '='. It is harmless but it introduces confusion.
>
> Hai
>  
>
>> On Tue, Oct 27, 2015 at 8:56 AM, FANG Colin > > wrote:
>>
>>> Thank you. In that case I will happily stick with `in`.
>>>
>>>
>>> On Monday, October 26, 2015 at 8:43:22 PM UTC, Alireza Nejati wrote:

 There is no difference, as far as I know.

 '=' seems to be used more for explicit ranges (i = 1:5) and 'in' seems 
 to be used more for variables (i in mylist). But using 'in' for everything 
 is ok too.

 The '=' is there for familiarity with matlab. Remember that julia's 
 syntax was in part designed to be familiar to matlab users.

 On Tuesday, October 27, 2015 at 8:26:07 AM UTC+13, FANG Colin wrote:
>
> Hi All
>
> I have got a stupid question:
>
> Are there any difference in "for i in 1:5" and "for i = 1:5"?
>
> Does the julia community prefer one to the other? I see use of both in 
> the documentations and source code.
>
> Personally I haven't seen much use of "for i = 1:5" in other 
> languages.
>
> Thanks.
>

>>
>

Re: [julia-users] Re: For loop = or in?

2015-10-28 Thread DNF


On Wednesday, October 28, 2015 at 8:56:44 AM UTC+1, DNF wrote:
>
> I don't think = and in represent an elegant duality. They seem a very odd 
> couple to me (even though I have been using = in Matlab for 15 years.) On 
> the other hand, = and ∈ do seem to offer an elegant duality,
>

Sorry, of course I meant ∈ and 'in' are dually elegant, not ∈ and =. 


Re: [julia-users] Re: For loop = or in?

2015-10-28 Thread DNF
On Wednesday, October 28, 2015 at 7:56:54 AM UTC+1, Gabor wrote:
>
> Confusion?
> Considering the investment into learning all the new and powerful Julia 
> language constructs,
> I don't see why exactly this elegant duality would be a problem for anyone.
>

I don't think = and in represent an elegant duality. They seem a very odd 
couple to me (even though I have been using = in Matlab for 15 years.) On 
the other hand, = and ∈ do seem to offer an elegant duality, since they are 
already synonyms in other contexts. The concept of 'in' also seems more 
logical than '=', which is an assignment operator.

One advantage of = over 'in' is that it sticks out more visually. That is 
solved by ∈, though.


Re: [julia-users] Re: For loop = or in?

2015-10-28 Thread Tamas Papp
On Wed, Oct 28 2015, DNF  wrote:

> On Wednesday, October 28, 2015 at 7:56:54 AM UTC+1, Gabor wrote:
>>
>> Confusion?
>> Considering the investment into learning all the new and powerful Julia 
>> language constructs,
>> I don't see why exactly this elegant duality would be a problem for anyone.
>>
>
> I don't think = and in represent an elegant duality. They seem a very odd 
> couple to me (even though I have been using = in Matlab for 15 years.) On 
> the other hand, = and ∈ do seem to offer an elegant duality, since they are 
> already synonyms in other contexts. The concept of 'in' also seems more 
> logical than '=', which is an assignment operator.
>
> One advantage of = over 'in' is that it sticks out more visually. That is 
> solved by ∈, though.

I am probably old-fashined, but I always prefer to stick to ASCII unless
there is a compelling reason. If I want something to stick out, I can
always customize Emacs to do it.

Also, I don't think it is ideal to have two (or more) operators that are
interchangeable as far as the language is concerned, but have stylistic
differences assigned to them by convention. If that convention is
useful and justified, it should be merged into the language per se; if
not, then it just borders on confusing.

Best,

Tamas


Re: [julia-users] Re: For loop = or in?

2015-10-28 Thread Glen O
The thing is, it IS an assignment that's going on. In the case of a range, 
especially, "for i=1:5" says "loop 5 times, with i=1, then i=2, then i=3, 
then i=4, then i=5". "i' is being assigned to on each iteration. Think of 
it this way - suppose you were using elementwise operations. You could write

i=1:5
A[i]=B[i].*C[i]

or, you could write it as a loop...

for i=1:5
 A[i]=B[i]*C[i]
end

The two pieces of code are doing exactly the same thing; one is just 
explicitly writing the loop. In what way does restricting to "in" help, in 
this situation?

On Wednesday, 28 October 2015 17:56:44 UTC+10, DNF wrote:
>
> On Wednesday, October 28, 2015 at 7:56:54 AM UTC+1, Gabor wrote:
>>
>> Confusion?
>> Considering the investment into learning all the new and powerful Julia 
>> language constructs,
>> I don't see why exactly this elegant duality would be a problem for 
>> anyone.
>>
>
> I don't think = and in represent an elegant duality. They seem a very odd 
> couple to me (even though I have been using = in Matlab for 15 years.) On 
> the other hand, = and ∈ do seem to offer an elegant duality, since they 
> are already synonyms in other contexts. The concept of 'in' also seems more 
> logical than '=', which is an assignment operator.
>
> One advantage of = over 'in' is that it sticks out more visually. That is 
> solved by ∈, though.
>


[julia-users] Re: For loop = or in?

2015-10-27 Thread FANG Colin
Thank you. In that case I will happily stick with `in`.

On Monday, October 26, 2015 at 8:43:22 PM UTC, Alireza Nejati wrote:
>
> There is no difference, as far as I know.
>
> '=' seems to be used more for explicit ranges (i = 1:5) and 'in' seems to 
> be used more for variables (i in mylist). But using 'in' for everything is 
> ok too.
>
> The '=' is there for familiarity with matlab. Remember that julia's syntax 
> was in part designed to be familiar to matlab users.
>
> On Tuesday, October 27, 2015 at 8:26:07 AM UTC+13, FANG Colin wrote:
>>
>> Hi All
>>
>> I have got a stupid question:
>>
>> Are there any difference in "for i in 1:5" and "for i = 1:5"?
>>
>> Does the julia community prefer one to the other? I see use of both in 
>> the documentations and source code.
>>
>> Personally I haven't seen much use of "for i = 1:5" in other languages.
>>
>> Thanks.
>>
>

Re: [julia-users] Re: For loop = or in?

2015-10-27 Thread feza
+1 @Tom Breloff .  
I was confused about this when starting out. Comparing   `for i in 1:3` vs 
 `for i = 1:3`, even though I regularly use matlab if you think about it 
for `i = 1:10` doesn't really make a lot of sense. It would be nice if it 
was just one way as opposed to the confusion about whether = or in should 
be used.

On Tuesday, October 27, 2015 at 10:26:44 AM UTC-4, Tom Breloff wrote:
>
> It's harmless, sure, but I would prefer that everyone uses "in" 
> exclusively so that there's one less thing to waste brainpower on.  You 
> don't say "for each x equals the range 1 to n", you say "for each x in the 
> range 1 to n".  I don't think "=" has a place here at all except to allow 
> copy/pasting of Matlab code (which creates other performance problems 
> anyways).
>
> On Tue, Oct 27, 2015 at 10:04 AM, Stefan Karpinski  > wrote:
>
>> My general approach is to only use = when the RHS is an explicit range, 
>> as in `for i = 1:n`. For everything else I use `for i in v`. I would be ok 
>> with dropping the = syntax at some point, but it seems pretty harmless to 
>> have it.
>>
>> On Tue, Oct 27, 2015 at 8:56 AM, FANG Colin > > wrote:
>>
>>> Thank you. In that case I will happily stick with `in`.
>>>
>>>
>>> On Monday, October 26, 2015 at 8:43:22 PM UTC, Alireza Nejati wrote:

 There is no difference, as far as I know.

 '=' seems to be used more for explicit ranges (i = 1:5) and 'in' seems 
 to be used more for variables (i in mylist). But using 'in' for everything 
 is ok too.

 The '=' is there for familiarity with matlab. Remember that julia's 
 syntax was in part designed to be familiar to matlab users.

 On Tuesday, October 27, 2015 at 8:26:07 AM UTC+13, FANG Colin wrote:
>
> Hi All
>
> I have got a stupid question:
>
> Are there any difference in "for i in 1:5" and "for i = 1:5"?
>
> Does the julia community prefer one to the other? I see use of both in 
> the documentations and source code.
>
> Personally I haven't seen much use of "for i = 1:5" in other 
> languages.
>
> Thanks.
>

>>
>

Re: [julia-users] Re: For loop = or in?

2015-10-27 Thread Glen O
An alternative way to read it is "for x equals 1 through 5". It definitely 
makes sense for a range. And I don't think anyone has any difficulty 
intuitively understanding a for loop using =, even if "in" reads slightly 
better.

Incidentally, it's not just Matlab that does it. Most variants of Basic use 
it, as does Delphi, Fortran, Lua, Pascal, and Scilab. One thing you might 
notice about most of the languages on the list is that they're languages 
that were more oriented towards scientific computing, or languages designed 
to teach programming concepts. It's a more intuitive notation when applied 
to basic for loops (that is, where the variable is simply being incremented 
a fixed number of times), with "in" really being of use when you want to 
iterate over a data structure, rather than to iterate with a counting 
variable.

I agree with Stefan's approach of using "=" for explicit ranges (which 
represent the phrasing "for x equals 1 through 5") and "in" for application 
to other structures ("for each x in the vector A"), with the other notation 
being usable but somewhat discouraged. Besides, it's not like there's any 
other natural use for = in that context.

Incidentally, it would be nice if ∈ could be used as another option - it's 
just another way of saying "in", but it would look nicer in certain 
mathematical contexts, and it's not like the symbol would be used in 
another way in that position.

On Wednesday, 28 October 2015 00:26:44 UTC+10, Tom Breloff wrote:
>
> It's harmless, sure, but I would prefer that everyone uses "in" 
> exclusively so that there's one less thing to waste brainpower on.  You 
> don't say "for each x equals the range 1 to n", you say "for each x in the 
> range 1 to n".  I don't think "=" has a place here at all except to allow 
> copy/pasting of Matlab code (which creates other performance problems 
> anyways).
>
> On Tue, Oct 27, 2015 at 10:04 AM, Stefan Karpinski  > wrote:
>
>> My general approach is to only use = when the RHS is an explicit range, 
>> as in `for i = 1:n`. For everything else I use `for i in v`. I would be ok 
>> with dropping the = syntax at some point, but it seems pretty harmless to 
>> have it.
>>
>> On Tue, Oct 27, 2015 at 8:56 AM, FANG Colin > > wrote:
>>
>>> Thank you. In that case I will happily stick with `in`.
>>>
>>>
>>> On Monday, October 26, 2015 at 8:43:22 PM UTC, Alireza Nejati wrote:

 There is no difference, as far as I know.

 '=' seems to be used more for explicit ranges (i = 1:5) and 'in' seems 
 to be used more for variables (i in mylist). But using 'in' for everything 
 is ok too.

 The '=' is there for familiarity with matlab. Remember that julia's 
 syntax was in part designed to be familiar to matlab users.

 On Tuesday, October 27, 2015 at 8:26:07 AM UTC+13, FANG Colin wrote:
>
> Hi All
>
> I have got a stupid question:
>
> Are there any difference in "for i in 1:5" and "for i = 1:5"?
>
> Does the julia community prefer one to the other? I see use of both in 
> the documentations and source code.
>
> Personally I haven't seen much use of "for i = 1:5" in other 
> languages.
>
> Thanks.
>

>>
>

Re: [julia-users] Re: For loop = or in?

2015-10-27 Thread Glen O
"When calculating a Fibonacci number, we have to apply F_n=F_(n-1)+F_(n-2) 
repeatedly. So to find F_6, we apply the equation for n equals 3 through 
6". Writing it as "for n in 3 through 6" or "for n in the range 3 through 
6" wouldn't make nearly as much sense.

As I said, for general iterables, like vectors, the "in" keyword makes more 
sense. But when you're talking about a counter variable, equals makes a 
much more natural expression - you're not really constructing the range 
object, you're just telling the program you want the counter to start at 
the first value, and increment until it reaches the second value.

On Wednesday, 28 October 2015 02:23:54 UTC+10, Tom Breloff wrote:
>
> It definitely makes sense for a range.
>
>
> Sorry... gotta disagree... mathematical set notation is more appropriate, 
> especially for scientific computing.  This is coming from a former matlab 
> user, btw, so it's not like I was confused by the syntax.   The "for i = 
> 1:5" syntax is actually more reminiscent of C:  "for (int i=1; i<=5; i++)", 
> and I'm guessing that the syntax originated more from that rather than 
> scientific concepts.
>
> On Tue, Oct 27, 2015 at 11:58 AM, feza  
> wrote:
>
>> +1 @Tom Breloff .  
>> I was confused about this when starting out. Comparing   `for i in 
>> 1:3` vs  `for i = 1:3`, even though I regularly use matlab if you think 
>> about it for `i = 1:10` doesn't really make a lot of sense. It would be 
>> nice if it was just one way as opposed to the confusion about whether = or 
>> in should be used.
>>
>> On Tuesday, October 27, 2015 at 10:26:44 AM UTC-4, Tom Breloff wrote:
>>>
>>> It's harmless, sure, but I would prefer that everyone uses "in" 
>>> exclusively so that there's one less thing to waste brainpower on.  You 
>>> don't say "for each x equals the range 1 to n", you say "for each x in the 
>>> range 1 to n".  I don't think "=" has a place here at all except to allow 
>>> copy/pasting of Matlab code (which creates other performance problems 
>>> anyways).
>>>
>>> On Tue, Oct 27, 2015 at 10:04 AM, Stefan Karpinski >> > wrote:
>>>
 My general approach is to only use = when the RHS is an explicit range, 
 as in `for i = 1:n`. For everything else I use `for i in v`. I would be ok 
 with dropping the = syntax at some point, but it seems pretty harmless to 
 have it.

 On Tue, Oct 27, 2015 at 8:56 AM, FANG Colin  wrote:

> Thank you. In that case I will happily stick with `in`.
>
>
> On Monday, October 26, 2015 at 8:43:22 PM UTC, Alireza Nejati wrote:
>>
>> There is no difference, as far as I know.
>>
>> '=' seems to be used more for explicit ranges (i = 1:5) and 'in' 
>> seems to be used more for variables (i in mylist). But using 'in' for 
>> everything is ok too.
>>
>> The '=' is there for familiarity with matlab. Remember that julia's 
>> syntax was in part designed to be familiar to matlab users.
>>
>> On Tuesday, October 27, 2015 at 8:26:07 AM UTC+13, FANG Colin wrote:
>>>
>>> Hi All
>>>
>>> I have got a stupid question:
>>>
>>> Are there any difference in "for i in 1:5" and "for i = 1:5"?
>>>
>>> Does the julia community prefer one to the other? I see use of both 
>>> in the documentations and source code.
>>>
>>> Personally I haven't seen much use of "for i = 1:5" in other 
>>> languages.
>>>
>>> Thanks.
>>>
>>

>>>
>

Re: [julia-users] Re: For loop = or in?

2015-10-27 Thread Tom Breloff
>
> It definitely makes sense for a range.


Sorry... gotta disagree... mathematical set notation is more appropriate,
especially for scientific computing.  This is coming from a former matlab
user, btw, so it's not like I was confused by the syntax.   The "for i =
1:5" syntax is actually more reminiscent of C:  "for (int i=1; i<=5; i++)",
and I'm guessing that the syntax originated more from that rather than
scientific concepts.

On Tue, Oct 27, 2015 at 11:58 AM, feza  wrote:

> +1 @Tom Breloff .
> I was confused about this when starting out. Comparing   `for i in 1:3` vs
>  `for i = 1:3`, even though I regularly use matlab if you think about it
> for `i = 1:10` doesn't really make a lot of sense. It would be nice if it
> was just one way as opposed to the confusion about whether = or in should
> be used.
>
> On Tuesday, October 27, 2015 at 10:26:44 AM UTC-4, Tom Breloff wrote:
>>
>> It's harmless, sure, but I would prefer that everyone uses "in"
>> exclusively so that there's one less thing to waste brainpower on.  You
>> don't say "for each x equals the range 1 to n", you say "for each x in the
>> range 1 to n".  I don't think "=" has a place here at all except to allow
>> copy/pasting of Matlab code (which creates other performance problems
>> anyways).
>>
>> On Tue, Oct 27, 2015 at 10:04 AM, Stefan Karpinski 
>> wrote:
>>
>>> My general approach is to only use = when the RHS is an explicit range,
>>> as in `for i = 1:n`. For everything else I use `for i in v`. I would be ok
>>> with dropping the = syntax at some point, but it seems pretty harmless to
>>> have it.
>>>
>>> On Tue, Oct 27, 2015 at 8:56 AM, FANG Colin  wrote:
>>>
 Thank you. In that case I will happily stick with `in`.


 On Monday, October 26, 2015 at 8:43:22 PM UTC, Alireza Nejati wrote:
>
> There is no difference, as far as I know.
>
> '=' seems to be used more for explicit ranges (i = 1:5) and 'in' seems
> to be used more for variables (i in mylist). But using 'in' for everything
> is ok too.
>
> The '=' is there for familiarity with matlab. Remember that julia's
> syntax was in part designed to be familiar to matlab users.
>
> On Tuesday, October 27, 2015 at 8:26:07 AM UTC+13, FANG Colin wrote:
>>
>> Hi All
>>
>> I have got a stupid question:
>>
>> Are there any difference in "for i in 1:5" and "for i = 1:5"?
>>
>> Does the julia community prefer one to the other? I see use of both
>> in the documentations and source code.
>>
>> Personally I haven't seen much use of "for i = 1:5" in other
>> languages.
>>
>> Thanks.
>>
>
>>>
>>


Re: [julia-users] Re: For loop = or in?

2015-10-27 Thread J Luis
Please, leave the '=' alone. It's very well as is.

terça-feira, 27 de Outubro de 2015 às 18:20:19 UTC, FANG Colin escreveu:
>
> Julia tries to attract people from Python & R, which use `in`. As for 
> matlab, it is not a direct competitor.
>
> Anyway, I think we only need 1 of the 2. "There should be one-- and 
> preferably only one --obvious way to do it."
>
> Maybe enhance the documentation for the time being.
>
>
> On 27 October 2015 at 16:38, Glen O  
> wrote:
>
>> "When calculating a Fibonacci number, we have to apply 
>> F_n=F_(n-1)+F_(n-2) repeatedly. So to find F_6, we apply the equation for n 
>> equals 3 through 6". Writing it as "for n in 3 through 6" or "for n in the 
>> range 3 through 6" wouldn't make nearly as much sense.
>>
>> As I said, for general iterables, like vectors, the "in" keyword makes 
>> more sense. But when you're talking about a counter variable, equals makes 
>> a much more natural expression - you're not really constructing the range 
>> object, you're just telling the program you want the counter to start at 
>> the first value, and increment until it reaches the second value.
>>
>> On Wednesday, 28 October 2015 02:23:54 UTC+10, Tom Breloff wrote:
>>>
>>> It definitely makes sense for a range.
>>>
>>>
>>> Sorry... gotta disagree... mathematical set notation is more 
>>> appropriate, especially for scientific computing.  This is coming from a 
>>> former matlab user, btw, so it's not like I was confused by the syntax.   
>>> The "for i = 1:5" syntax is actually more reminiscent of C:  "for (int i=1; 
>>> i<=5; i++)", and I'm guessing that the syntax originated more from that 
>>> rather than scientific concepts.
>>>
>>> On Tue, Oct 27, 2015 at 11:58 AM, feza  wrote:
>>>
 +1 @Tom Breloff .  
 I was confused about this when starting out. Comparing   `for i in 
 1:3` vs  `for i = 1:3`, even though I regularly use matlab if you think 
 about it for `i = 1:10` doesn't really make a lot of sense. It would be 
 nice if it was just one way as opposed to the confusion about whether = or 
 in should be used.

 On Tuesday, October 27, 2015 at 10:26:44 AM UTC-4, Tom Breloff wrote:
>
> It's harmless, sure, but I would prefer that everyone uses "in" 
> exclusively so that there's one less thing to waste brainpower on.  You 
> don't say "for each x equals the range 1 to n", you say "for each x in 
> the 
> range 1 to n".  I don't think "=" has a place here at all except to allow 
> copy/pasting of Matlab code (which creates other performance problems 
> anyways).
>
> On Tue, Oct 27, 2015 at 10:04 AM, Stefan Karpinski <
> ste...@karpinski.org> wrote:
>
>> My general approach is to only use = when the RHS is an explicit 
>> range, as in `for i = 1:n`. For everything else I use `for i in v`. I 
>> would 
>> be ok with dropping the = syntax at some point, but it seems pretty 
>> harmless to have it.
>>
>> On Tue, Oct 27, 2015 at 8:56 AM, FANG Colin  
>> wrote:
>>
>>> Thank you. In that case I will happily stick with `in`.
>>>
>>>
>>> On Monday, October 26, 2015 at 8:43:22 PM UTC, Alireza Nejati wrote:

 There is no difference, as far as I know.

 '=' seems to be used more for explicit ranges (i = 1:5) and 'in' 
 seems to be used more for variables (i in mylist). But using 'in' for 
 everything is ok too.

 The '=' is there for familiarity with matlab. Remember that julia's 
 syntax was in part designed to be familiar to matlab users.

 On Tuesday, October 27, 2015 at 8:26:07 AM UTC+13, FANG Colin wrote:
>
> Hi All
>
> I have got a stupid question:
>
> Are there any difference in "for i in 1:5" and "for i = 1:5"?
>
> Does the julia community prefer one to the other? I see use of 
> both in the documentations and source code.
>
> Personally I haven't seen much use of "for i = 1:5" in other 
> languages.
>
> Thanks.
>

>>
>
>>>
>

RE: [julia-users] Re: For loop = or in?

2015-10-27 Thread David Anthoff
If something like this were to change, it would be good to do it sooner rather 
than later -> less code that depends on the syntax that would go would have 
been written. So maybe the right way forward for this is to open an issue 
suggesting to drop the = variant, discuss it, make a decision and then live 
with it, all for the 0.5 cycle.

 

I don’t feel strongly about this, but for what it’s worth, I’m also a fan of 
having only one way to do something like this.

 

Cheers,

David 

 

From: julia-users@googlegroups.com [mailto:julia-users@googlegroups.com] On 
Behalf Of FANG Colin
Sent: Tuesday, October 27, 2015 11:20 AM
To: julia-users@googlegroups.com
Subject: Re: [julia-users] Re: For loop = or in?

 

Julia tries to attract people from Python & R, which use `in`. As for matlab, 
it is not a direct competitor.

 

Anyway, I think we only need 1 of the 2. "There should be one-- and preferably 
only one --obvious way to do it."

 

Maybe enhance the documentation for the time being.

 

 

On 27 October 2015 at 16:38, Glen O <gjo1...@gmail.com 
<mailto:gjo1...@gmail.com> > wrote:

"When calculating a Fibonacci number, we have to apply F_n=F_(n-1)+F_(n-2) 
repeatedly. So to find F_6, we apply the equation for n equals 3 through 6". 
Writing it as "for n in 3 through 6" or "for n in the range 3 through 6" 
wouldn't make nearly as much sense.

 

As I said, for general iterables, like vectors, the "in" keyword makes more 
sense. But when you're talking about a counter variable, equals makes a much 
more natural expression - you're not really constructing the range object, 
you're just telling the program you want the counter to start at the first 
value, and increment until it reaches the second value.

On Wednesday, 28 October 2015 02:23:54 UTC+10, Tom Breloff wrote:

It definitely makes sense for a range.

 

Sorry... gotta disagree... mathematical set notation is more appropriate, 
especially for scientific computing.  This is coming from a former matlab user, 
btw, so it's not like I was confused by the syntax.   The "for i = 1:5" syntax 
is actually more reminiscent of C:  "for (int i=1; i<=5; i++)", and I'm 
guessing that the syntax originated more from that rather than scientific 
concepts.

 

On Tue, Oct 27, 2015 at 11:58 AM, feza <moham...@gmail.com 
<mailto:moham...@gmail.com> > wrote:

+1 @Tom Breloff .  
I was confused about this when starting out. Comparing   `for i in 1:3` vs  
`for i = 1:3`, even though I regularly use matlab if you think about it for `i 
= 1:10` doesn't really make a lot of sense. It would be nice if it was just one 
way as opposed to the confusion about whether = or in should be used.

On Tuesday, October 27, 2015 at 10:26:44 AM UTC-4, Tom Breloff wrote:

It's harmless, sure, but I would prefer that everyone uses "in" exclusively so 
that there's one less thing to waste brainpower on.  You don't say "for each x 
equals the range 1 to n", you say "for each x in the range 1 to n".  I don't 
think "=" has a place here at all except to allow copy/pasting of Matlab code 
(which creates other performance problems anyways).

 

On Tue, Oct 27, 2015 at 10:04 AM, Stefan Karpinski <ste...@karpinski.org 
<mailto:ste...@karpinski.org> > wrote:

My general approach is to only use = when the RHS is an explicit range, as in 
`for i = 1:n`. For everything else I use `for i in v`. I would be ok with 
dropping the = syntax at some point, but it seems pretty harmless to have it.

 

On Tue, Oct 27, 2015 at 8:56 AM, FANG Colin <coli...@gmail.com 
<mailto:coli...@gmail.com> > wrote:

Thank you. In that case I will happily stick with `in`.



On Monday, October 26, 2015 at 8:43:22 PM UTC, Alireza Nejati wrote:

There is no difference, as far as I know.

 

'=' seems to be used more for explicit ranges (i = 1:5) and 'in' seems to be 
used more for variables (i in mylist). But using 'in' for everything is ok too.

 

The '=' is there for familiarity with matlab. Remember that julia's syntax was 
in part designed to be familiar to matlab users.


On Tuesday, October 27, 2015 at 8:26:07 AM UTC+13, FANG Colin wrote:

Hi All

 

I have got a stupid question:

 

Are there any difference in "for i in 1:5" and "for i = 1:5"?

 

Does the julia community prefer one to the other? I see use of both in the 
documentations and source code.

 

Personally I haven't seen much use of "for i = 1:5" in other languages.

 

Thanks.

 

 

 

 



Re: [julia-users] Re: For loop = or in?

2015-10-27 Thread DNF
On Tuesday, October 27, 2015 at 4:56:12 PM UTC+1, Glen O wrote:
>
> Incidentally, it would be nice if ∈ could be used as another option - it's 
> just another way of saying "in", but it would look nicer in certain 
> mathematical contexts, and it's not like the symbol would be used in 
> another way in that position.
>

I very much like the idea of using for ∈ 1:n. In fact, as ∈ is a direct 
synonym for the function in, would it not make sense to let it be a synonym 
also in this context? Would it be problematic in some way? What is the 
difference in the meanings of in that prevents this from already being the 
case?


Re: [julia-users] Re: For loop = or in?

2015-10-27 Thread Hai Nguyen
On Tue, Oct 27, 2015 at 10:04 AM, Stefan Karpinski 
wrote:

> My general approach is to only use = when the RHS is an explicit range, as
> in `for i = 1:n`. For everything else I use `for i in v`. I would be ok
> with dropping the = syntax at some point, but it seems pretty harmless to
> have it.
>
>
I have 1 vote for removing '='. It is harmless but it introduces confusion.

Hai


> On Tue, Oct 27, 2015 at 8:56 AM, FANG Colin  wrote:
>
>> Thank you. In that case I will happily stick with `in`.
>>
>>
>> On Monday, October 26, 2015 at 8:43:22 PM UTC, Alireza Nejati wrote:
>>>
>>> There is no difference, as far as I know.
>>>
>>> '=' seems to be used more for explicit ranges (i = 1:5) and 'in' seems
>>> to be used more for variables (i in mylist). But using 'in' for everything
>>> is ok too.
>>>
>>> The '=' is there for familiarity with matlab. Remember that julia's
>>> syntax was in part designed to be familiar to matlab users.
>>>
>>> On Tuesday, October 27, 2015 at 8:26:07 AM UTC+13, FANG Colin wrote:

 Hi All

 I have got a stupid question:

 Are there any difference in "for i in 1:5" and "for i = 1:5"?

 Does the julia community prefer one to the other? I see use of both in
 the documentations and source code.

 Personally I haven't seen much use of "for i = 1:5" in other languages.

 Thanks.

>>>
>


Re: [julia-users] Re: For loop = or in?

2015-10-27 Thread Tk
As far as I can understand, Julia also seems trying to attract people from 
Matlab,
because there are so many similarities in the syntax (.* and ./ etc) and 
the names of functions.

Also I often see questions from Matlab users posted in StackOverflow. Their 
codes are
rather Matlab-like, but it works anyway. I guess this helps people to try a 
new language
with lower barrier. (Though, personally, I don't like ".*" notation very 
much. But I can live with it.)

As for =, I also prefer using = for counters (for i = 1:n) and "in" for 
other containers.
I use Fortran and Python most often for research work, but I feel "=" is 
quite natural for indicating
that the index goes from 1 to n. On the other hand, with "in", I feel like 
the entity is just
somewhere inside the container, with no particular order enforced (even if 
it has a definite order).
My familiarity with "=" is probably coming from old languages (including 
C-like ones),
but that aside, I hope "=" remains a valid symbol for this.

So anyway, +1 for the comments from Glen O.

On Wednesday, October 28, 2015 at 3:20:19 AM UTC+9, FANG Colin wrote:
>
> Julia tries to attract people from Python & R, which use `in`. As for 
> matlab, it is not a direct competitor.
>
> Anyway, I think we only need 1 of the 2. "There should be one-- and 
> preferably only one --obvious way to do it."
>
> Maybe enhance the documentation for the time being.
>
>
> On 27 October 2015 at 16:38, Glen O  
> wrote:
>
>> "When calculating a Fibonacci number, we have to apply 
>> F_n=F_(n-1)+F_(n-2) repeatedly. So to find F_6, we apply the equation for n 
>> equals 3 through 6". Writing it as "for n in 3 through 6" or "for n in the 
>> range 3 through 6" wouldn't make nearly as much sense.
>>
>> As I said, for general iterables, like vectors, the "in" keyword makes 
>> more sense. But when you're talking about a counter variable, equals makes 
>> a much more natural expression - you're not really constructing the range 
>> object, you're just telling the program you want the counter to start at 
>> the first value, and increment until it reaches the second value.
>>
>> On Wednesday, 28 October 2015 02:23:54 UTC+10, Tom Breloff wrote:
>>>
>>> It definitely makes sense for a range.
>>>
>>>
>>> Sorry... gotta disagree... mathematical set notation is more 
>>> appropriate, especially for scientific computing.  This is coming from a 
>>> former matlab user, btw, so it's not like I was confused by the syntax.   
>>> The "for i = 1:5" syntax is actually more reminiscent of C:  "for (int i=1; 
>>> i<=5; i++)", and I'm guessing that the syntax originated more from that 
>>> rather than scientific concepts.
>>>
>>> On Tue, Oct 27, 2015 at 11:58 AM, feza  wrote:
>>>
 +1 @Tom Breloff .  
 I was confused about this when starting out. Comparing   `for i in 
 1:3` vs  `for i = 1:3`, even though I regularly use matlab if you think 
 about it for `i = 1:10` doesn't really make a lot of sense. It would be 
 nice if it was just one way as opposed to the confusion about whether = or 
 in should be used.

 On Tuesday, October 27, 2015 at 10:26:44 AM UTC-4, Tom Breloff wrote:
>
> It's harmless, sure, but I would prefer that everyone uses "in" 
> exclusively so that there's one less thing to waste brainpower on.  You 
> don't say "for each x equals the range 1 to n", you say "for each x in 
> the 
> range 1 to n".  I don't think "=" has a place here at all except to allow 
> copy/pasting of Matlab code (which creates other performance problems 
> anyways).
>
> On Tue, Oct 27, 2015 at 10:04 AM, Stefan Karpinski <
> ste...@karpinski.org> wrote:
>
>> My general approach is to only use = when the RHS is an explicit 
>> range, as in `for i = 1:n`. For everything else I use `for i in v`. I 
>> would 
>> be ok with dropping the = syntax at some point, but it seems pretty 
>> harmless to have it.
>>
>> On Tue, Oct 27, 2015 at 8:56 AM, FANG Colin  
>> wrote:
>>
>>> Thank you. In that case I will happily stick with `in`.
>>>
>>>
>>> On Monday, October 26, 2015 at 8:43:22 PM UTC, Alireza Nejati wrote:

 There is no difference, as far as I know.

 '=' seems to be used more for explicit ranges (i = 1:5) and 'in' 
 seems to be used more for variables (i in mylist). But using 'in' for 
 everything is ok too.

 The '=' is there for familiarity with matlab. Remember that julia's 
 syntax was in part designed to be familiar to matlab users.

 On Tuesday, October 27, 2015 at 8:26:07 AM UTC+13, FANG Colin wrote:
>
> Hi All
>
> I have got a stupid question:
>
> Are there any difference in "for i in 1:5" and "for i = 1:5"?
>
> Does the julia community prefer one to the other? I see use of 

Re: [julia-users] Re: For loop = or in?

2015-10-27 Thread Tom Breloff
It's harmless, sure, but I would prefer that everyone uses "in" exclusively
so that there's one less thing to waste brainpower on.  You don't say "for
each x equals the range 1 to n", you say "for each x in the range 1 to n".
I don't think "=" has a place here at all except to allow copy/pasting of
Matlab code (which creates other performance problems anyways).

On Tue, Oct 27, 2015 at 10:04 AM, Stefan Karpinski 
wrote:

> My general approach is to only use = when the RHS is an explicit range, as
> in `for i = 1:n`. For everything else I use `for i in v`. I would be ok
> with dropping the = syntax at some point, but it seems pretty harmless to
> have it.
>
> On Tue, Oct 27, 2015 at 8:56 AM, FANG Colin  wrote:
>
>> Thank you. In that case I will happily stick with `in`.
>>
>>
>> On Monday, October 26, 2015 at 8:43:22 PM UTC, Alireza Nejati wrote:
>>>
>>> There is no difference, as far as I know.
>>>
>>> '=' seems to be used more for explicit ranges (i = 1:5) and 'in' seems
>>> to be used more for variables (i in mylist). But using 'in' for everything
>>> is ok too.
>>>
>>> The '=' is there for familiarity with matlab. Remember that julia's
>>> syntax was in part designed to be familiar to matlab users.
>>>
>>> On Tuesday, October 27, 2015 at 8:26:07 AM UTC+13, FANG Colin wrote:

 Hi All

 I have got a stupid question:

 Are there any difference in "for i in 1:5" and "for i = 1:5"?

 Does the julia community prefer one to the other? I see use of both in
 the documentations and source code.

 Personally I haven't seen much use of "for i = 1:5" in other languages.

 Thanks.

>>>
>


Re: [julia-users] Re: For loop = or in?

2015-10-27 Thread Stefan Karpinski
My general approach is to only use = when the RHS is an explicit range, as
in `for i = 1:n`. For everything else I use `for i in v`. I would be ok
with dropping the = syntax at some point, but it seems pretty harmless to
have it.

On Tue, Oct 27, 2015 at 8:56 AM, FANG Colin  wrote:

> Thank you. In that case I will happily stick with `in`.
>
>
> On Monday, October 26, 2015 at 8:43:22 PM UTC, Alireza Nejati wrote:
>>
>> There is no difference, as far as I know.
>>
>> '=' seems to be used more for explicit ranges (i = 1:5) and 'in' seems to
>> be used more for variables (i in mylist). But using 'in' for everything is
>> ok too.
>>
>> The '=' is there for familiarity with matlab. Remember that julia's
>> syntax was in part designed to be familiar to matlab users.
>>
>> On Tuesday, October 27, 2015 at 8:26:07 AM UTC+13, FANG Colin wrote:
>>>
>>> Hi All
>>>
>>> I have got a stupid question:
>>>
>>> Are there any difference in "for i in 1:5" and "for i = 1:5"?
>>>
>>> Does the julia community prefer one to the other? I see use of both in
>>> the documentations and source code.
>>>
>>> Personally I haven't seen much use of "for i = 1:5" in other languages.
>>>
>>> Thanks.
>>>
>>


[julia-users] Re: For loop = or in?

2015-10-26 Thread Alireza Nejati
There is no difference, as far as I know.

'=' seems to be used more for explicit ranges (i = 1:5) and 'in' seems to 
be used more for variables (i in mylist). But using 'in' for everything is 
ok too.

The '=' is there for familiarity with matlab. Remember that julia's syntax 
was in part designed to be familiar to matlab users.

On Tuesday, October 27, 2015 at 8:26:07 AM UTC+13, FANG Colin wrote:
>
> Hi All
>
> I have got a stupid question:
>
> Are there any difference in "for i in 1:5" and "for i = 1:5"?
>
> Does the julia community prefer one to the other? I see use of both in the 
> documentations and source code.
>
> Personally I haven't seen much use of "for i = 1:5" in other languages.
>
> Thanks.
>


Re: [julia-users] Re: Parallel loop, what wroong ? Parallel is slower then normal

2015-01-31 Thread Jameson Nash
How many worker threads did you start? Can you make D a SharedArray or
DArray?

On Sat Jan 31 2015 at 10:55:51 AM Paul Analyst paul.anal...@mail.com
wrote:

 Realy ? Is imposibly smoething like :
   take 1. column and copmute on 1. core, wihout waiting for end of 1.
 oparation take 2. column and copmpute on 2. cores .etc ?
 Paul

 W dniu 2015-01-31 o 16:32, Tim Holy pisze:
  Paul, until the threads branch gets merged, I recommend that you just
 accept
  the fact that you'll only have 1 core active for most operations.
 
  --Tim
 
  On Saturday, January 31, 2015 07:15:25 AM paul analyst wrote:
  Thx, but, no.
  For sparse matrix 10^5,10^4,0.002 is the same . Time for both whiles is
  about 48 sek, only 11% o cores is used. I vave 8 cores, 7 sleeps:/
  Paul
 
  W dniu sobota, 31 stycznia 2015 15:50:02 UTC+1 użytkownik Sam Kaplan
 
  napisał:
  Hi Paul,
 
  If D is allocated on the master, then Julia will need to pass D from
 the
  master to the workers.  I'm guessing that this communication might be
 more
  expensive than the compute in your loops.  It may be useful to take a
 look
  at distributed arrays in the parallel section of the Julia docs.
 
  Hope it helps.
 
  Sam
 
  On Saturday, January 31, 2015 at 7:38:22 AM UTC-6, paul analyst wrote:
  Parallel loop, what wroong ? Parallel is slower then normal
 
  julia @time for i=1:l
 
  w[i]=var(D[:,i])
  end
 
  elapsed time: 4.443197509 seconds (14074576 bytes allocated)
 
 
  julia @time ww=@parallel (hcat) for i=1:l
 
  var(D[:,i])
  end
 
  elapsed time: 5.287007403 seconds (435449580 bytes allocated, 5.00% gc
  time)
  1x1 Array{Float64,2}:
 
  Paul
 
  julia @time for i=1:l
 
  w[i]=var(D[:,i])
  end
 
  elapsed time: 4.331569152 seconds (8637464 bytes allocated)
 
  julia @time ww=@parallel (hcat) for i=1:l
 
  var(D[:,i])
  end
 
  elapsed time: 4.908234336 seconds (422121448 bytes allocated, 4.85% gc
  time)
 
  1x1 Array{Float64,2}:
0.000703737  0.000731674  0.000582672  0.000803880.000759479
 
  0.000402509  0.0007118  0.000989408
 
  julia size(D)
  (1,1)




[julia-users] Re: Parallel loop, what wroong ? Parallel is slower then normal

2015-01-31 Thread Sam Kaplan
Hi Paul,

If D is allocated on the master, then Julia will need to pass D from the 
master to the workers.  I'm guessing that this communication might be more 
expensive than the compute in your loops.  It may be useful to take a look 
at distributed arrays in the parallel section of the Julia docs.

Hope it helps.

Sam

On Saturday, January 31, 2015 at 7:38:22 AM UTC-6, paul analyst wrote:


 Parallel loop, what wroong ? Parallel is slower then normal 

 julia @time for i=1:l
w[i]=var(D[:,i])
end
 elapsed time: 4.443197509 seconds (14074576 bytes allocated)


 julia @time ww=@parallel (hcat) for i=1:l
var(D[:,i])
end
 elapsed time: 5.287007403 seconds (435449580 bytes allocated, 5.00% gc 
 time)
 1x1 Array{Float64,2}:

 Paul

 julia @time for i=1:l
w[i]=var(D[:,i])
end
 elapsed time: 4.331569152 seconds (8637464 bytes allocated)

 julia @time ww=@parallel (hcat) for i=1:l
var(D[:,i])
end
 elapsed time: 4.908234336 seconds (422121448 bytes allocated, 4.85% gc 
 time)
 1x1 Array{Float64,2}:
  0.000703737  0.000731674  0.000582672  0.000803880.000759479  
 0.000402509  0.0007118  0.000989408

 julia size(D)
 (1,1)



Re: [julia-users] Re: Parallel loop, what wroong ? Parallel is slower then normal

2015-01-31 Thread Paul Analyst

Nash, big thx
julia procs()
1-element Array{Int64,1}:
 1

julia addprocs(7)
7-element Array{Any,1}:
 2
 3
 4
 5
 6
 7
 8
Now is 3-4 times faster !!!
Paul


W dniu 2015-01-31 o 17:00, Jameson Nash pisze:
How many worker threads did you start? Can you make D a SharedArray or 
DArray?


On Sat Jan 31 2015 at 10:55:51 AM Paul Analyst paul.anal...@mail.com 
mailto:paul.anal...@mail.com wrote:


Realy ? Is imposibly smoething like :
  take 1. column and copmute on 1. core, wihout waiting for end of 1.
oparation take 2. column and copmpute on 2. cores .etc ?
Paul

W dniu 2015-01-31 o 16:32, Tim Holy pisze:
 Paul, until the threads branch gets merged, I recommend that
you just accept
 the fact that you'll only have 1 core active for most operations.

 --Tim

 On Saturday, January 31, 2015 07:15:25 AM paul analyst wrote:
 Thx, but, no.
 For sparse matrix 10^5,10^4,0.002 is the same . Time for both
whiles is
 about 48 sek, only 11% o cores is used. I vave 8 cores, 7 sleeps:/
 Paul

 W dniu sobota, 31 stycznia 2015 15:50:02 UTC+1 użytkownik Sam
Kaplan

 napisał:
 Hi Paul,

 If D is allocated on the master, then Julia will need to pass
D from the
 master to the workers.  I'm guessing that this communication
might be more
 expensive than the compute in your loops.  It may be useful to
take a look
 at distributed arrays in the parallel section of the Julia docs.

 Hope it helps.

 Sam

 On Saturday, January 31, 2015 at 7:38:22 AM UTC-6, paul
analyst wrote:
 Parallel loop, what wroong ? Parallel is slower then normal

 julia @time for i=1:l

 w[i]=var(D[:,i])
 end

 elapsed time: 4.443197509 seconds (14074576 bytes allocated)


 julia @time ww=@parallel (hcat) for i=1:l

 var(D[:,i])
 end

 elapsed time: 5.287007403 seconds (435449580 bytes allocated,
5.00% gc
 time)
 1x1 Array{Float64,2}:

 Paul

 julia @time for i=1:l

 w[i]=var(D[:,i])
 end

 elapsed time: 4.331569152 seconds (8637464 bytes allocated)

 julia @time ww=@parallel (hcat) for i=1:l

 var(D[:,i])
 end

 elapsed time: 4.908234336 seconds (422121448 bytes allocated,
4.85% gc
 time)

 1x1 Array{Float64,2}:
   0.000703737  0.000731674  0.000582672 0.000803880.000759479

 0.000402509  0.0007118  0.000989408

 julia size(D)
 (1,1)





Re: [julia-users] Re: Parallel loop, what wroong ? Parallel is slower then normal

2015-01-31 Thread Tim Holy
Paul, until the threads branch gets merged, I recommend that you just accept 
the fact that you'll only have 1 core active for most operations.

--Tim

On Saturday, January 31, 2015 07:15:25 AM paul analyst wrote:
 Thx, but, no.
 For sparse matrix 10^5,10^4,0.002 is the same . Time for both whiles is
 about 48 sek, only 11% o cores is used. I vave 8 cores, 7 sleeps:/
 Paul
 
 W dniu sobota, 31 stycznia 2015 15:50:02 UTC+1 użytkownik Sam Kaplan
 
 napisał:
  Hi Paul,
  
  If D is allocated on the master, then Julia will need to pass D from the
  master to the workers.  I'm guessing that this communication might be more
  expensive than the compute in your loops.  It may be useful to take a look
  at distributed arrays in the parallel section of the Julia docs.
  
  Hope it helps.
  
  Sam
  
  On Saturday, January 31, 2015 at 7:38:22 AM UTC-6, paul analyst wrote:
  Parallel loop, what wroong ? Parallel is slower then normal
  
  julia @time for i=1:l
  
 w[i]=var(D[:,i])
 end
  
  elapsed time: 4.443197509 seconds (14074576 bytes allocated)
  
  
  julia @time ww=@parallel (hcat) for i=1:l
  
 var(D[:,i])
 end
  
  elapsed time: 5.287007403 seconds (435449580 bytes allocated, 5.00% gc
  time)
  1x1 Array{Float64,2}:
  
  Paul
  
  julia @time for i=1:l
  
 w[i]=var(D[:,i])
 end
  
  elapsed time: 4.331569152 seconds (8637464 bytes allocated)
  
  julia @time ww=@parallel (hcat) for i=1:l
  
 var(D[:,i])
 end
  
  elapsed time: 4.908234336 seconds (422121448 bytes allocated, 4.85% gc
  time)
  
  1x1 Array{Float64,2}:
   0.000703737  0.000731674  0.000582672  0.000803880.000759479
  
  0.000402509  0.0007118  0.000989408
  
  julia size(D)
  (1,1)



[julia-users] Re: Parallel loop, what wroong ? Parallel is slower then normal

2015-01-31 Thread paul analyst
Thx, but, no. 
For sparse matrix 10^5,10^4,0.002 is the same . Time for both whiles is 
about 48 sek, only 11% o cores is used. I vave 8 cores, 7 sleeps:/
Paul

W dniu sobota, 31 stycznia 2015 15:50:02 UTC+1 użytkownik Sam Kaplan 
napisał:

 Hi Paul,

 If D is allocated on the master, then Julia will need to pass D from the 
 master to the workers.  I'm guessing that this communication might be more 
 expensive than the compute in your loops.  It may be useful to take a look 
 at distributed arrays in the parallel section of the Julia docs.

 Hope it helps.

 Sam

 On Saturday, January 31, 2015 at 7:38:22 AM UTC-6, paul analyst wrote:


 Parallel loop, what wroong ? Parallel is slower then normal 

 julia @time for i=1:l
w[i]=var(D[:,i])
end
 elapsed time: 4.443197509 seconds (14074576 bytes allocated)


 julia @time ww=@parallel (hcat) for i=1:l
var(D[:,i])
end
 elapsed time: 5.287007403 seconds (435449580 bytes allocated, 5.00% gc 
 time)
 1x1 Array{Float64,2}:

 Paul

 julia @time for i=1:l
w[i]=var(D[:,i])
end
 elapsed time: 4.331569152 seconds (8637464 bytes allocated)

 julia @time ww=@parallel (hcat) for i=1:l
var(D[:,i])
end
 elapsed time: 4.908234336 seconds (422121448 bytes allocated, 4.85% gc 
 time)
 1x1 Array{Float64,2}:
  0.000703737  0.000731674  0.000582672  0.000803880.000759479  
 0.000402509  0.0007118  0.000989408

 julia size(D)
 (1,1)



[julia-users] Re: For Loop over set of vector names

2014-09-09 Thread Alex
Thanks for the tips! As an academic trying to move lots of code over from 
other languages my lack of knowledge in coding fundamentals is being 
exposed a bit.

Alex

On Sunday, September 7, 2014 3:03:01 PM UTC-7, Alex wrote:

 Hi Everyone, 

 I've been having some trouble using a for loop to perform tasks over 
 similarly named vectors. This simple example below illustrates my problem 
 pretty well. I would like to create two 5x5 arrays of zeros, but with 
 dynamic names. In this case x_foo and x_bar would be the names. When I run 
 this code, it clearly is looping over the string set, but it is not 
 actually creating the array. I have had similar problem trying to call 
 arrays into functions dynamically based on their names. Clearly I am just 
 incorrectly referencing i, but I cannot figure it where the error is. I am 
 trying to port a complicated version of this code from Stata, where this is 
 quite easy to do by referencing i in your code as `i'. Sorry for such a 
 novice question, but this has been driving me nuts all day!

 Thanks in advance!

 Alex

 n=5
 for i in [foo,bar]
 x_$i=zeros(n,n)
 println(x_$i)
 end
 x_bar



[julia-users] Re: For Loop over set of vector names

2014-09-07 Thread Alex
 

EDIT: Sorry I forgot to add the output. 

julia n=5

5

julia for i in [foo,bar]

   x_$i=zeros(n,n)

   println(x_$i)

   end

x_foo

x_bar

julia x_foo

ERROR: x_foo not defined

On Sunday, September 7, 2014 3:03:01 PM UTC-7, Alex wrote:

 Hi Everyone, 

 I've been having some trouble using a for loop to perform tasks over 
 similarly named vectors. This simple example below illustrates my problem 
 pretty well. I would like to create two 5x5 arrays of zeros, but with 
 dynamic names. In this case x_foo and x_bar would be the names. When I run 
 this code, it clearly is looping over the string set, but it is not 
 actually creating the array. I have had similar problem trying to call 
 arrays into functions dynamically based on their names. Clearly I am just 
 incorrectly referencing i, but I cannot figure it where the error is. I am 
 trying to port a complicated version of this code from Stata, where this is 
 quite easy to do by referencing i in your code as `i'. Sorry for such a 
 novice question, but this has been driving me nuts all day!

 Thanks in advance!

 Alex

 n=5
 for i in [foo,bar]
 x_$i=zeros(n,n)
 println(x_$i)
 end
 x_bar



[julia-users] Re: parallel loop with mutable types

2014-06-17 Thread Tomas Lycken


You’ll need to evaluate the type definition on all processes, using the 
macro 

@everywhere type parms
...
end

*after* adding the worker process. If I do that, I can run your code 
without error. (However, k seems to be unchanged - you might have to use a 
DArray (distributed array) in order to get the changes back to the main 
thread…)

// T
On Tuesday, June 17, 2014 12:27:52 PM UTC+2, Jon Norberg wrote:

I have: 

 type parms
   r::Float64
   K::Float64
 end

 k=Array(parms,20)

 for i =1:20 k[i]=parms(1.1,2.2) end

 addprocs(1)

 nprocs() - 2

 @parallel for i=1:20 k[i].r=2.0 end

 gives error:

 julia @parallel for i=1:20 k[i].r=2.0 end
 fatal error on 2:
 julia ERROR: parms not defined
  in deserialize at serialize.jl:470
  in handle_deserialize at serialize.jl:327
  in deserialize at serialize.jl:398
  in handle_deserialize at serialize.jl:327
  in deserialize at serialize.jl:310
  in anonymous at serialize.jl:330
  in ntuple at tuple.jl:30
  in deserialize_tuple at serialize.jl:330
  in handle_deserialize at serialize.jl:322
  in deserialize at serialize.jl:368
  in handle_deserialize at serialize.jl:327
  in deserialize at serialize.jl:310
  in anonymous at serialize.jl:330
  in ntuple at tuple.jl:30
  in deserialize_tuple at serialize.jl:330
  in handle_deserialize at serialize.jl:322
  in deserialize at serialize.jl:368
  in handle_deserialize at serialize.jl:327
  in anonymous at task.jl:835
 Worker 2 terminated.

 Do I need to share the k array or somehow let the parallel code know how 
 to handle an array of type parms?

 Thanks for any help here!

 Jon

​


[julia-users] Re: parallel loop with mutable types

2014-06-17 Thread Jon Norberg
Great, solve first problem, thanks. 

using DArray though gives

julia k=DArray(parms,20)
exception on 2: ERROR: no method parms((UnitRange{Int64},))
 in anonymous at multi.jl:840
 in run_work_thunk at multi.jl:613
 in run_work_thunk at multi.jl:622
 in anonymous at task.jl:6
ERROR: assertion failed
 in DArray at darray.jl:18
 in DArray at darray.jl:39
 in DArray at darray.jl:48




[julia-users] Re: parallel loop with mutable types

2014-06-17 Thread Jon Norberg
also this works but does not change values in b

@parallel for i=1:20 b[i]=k[i].r*k[i].K end

I tried making b=DArray{Float64,1} or b=dones(20,1) but still values in b 
are not updated

do I need to use spawn/fetch or pmap or something like this?

Sorry, not fluent in parallel programming yet, but I am trying to make my 
simple code scalable from start

//J


[julia-users] Re: parallel loop with mutable types

2014-06-17 Thread Tomas Lycken


pmap is probably useful here.

Just to make sure, you *have* read the manual section on parallel 
programming http://docs.julialang.org/en/latest/manual/parallel-computing/, 
right? There's a lot of good stuff there =)

//T

On Tuesday, June 17, 2014 1:30:36 PM UTC+2, Jon Norberg wrote:

also this works but does not change values in b

 @parallel for i=1:20 b[i]=k[i].r*k[i].K end

 I tried making b=DArray{Float64,1} or b=dones(20,1) but still values in b 
 are not updated

 do I need to use spawn/fetch or pmap or something like this?

 Sorry, not fluent in parallel programming yet, but I am trying to make my 
 simple code scalable from start

 //J

​