Re: [julia-users] getindex for a real number

2015-12-03 Thread Ehsan Eftekhari
> > Sure, but it should be one way or the other, not half way between. > +100 On Wednesday, December 2, 2015 at 6:51:35 PM UTC+1, Cedric St-Jean wrote: > > There's also > > x = [1 2; 3 4] > x[:,[1]] # returns 2D array > x[:, 1] # returns 1D array > x[1, :] # AFAIK, returns 2D under Julia 0.4 and

Re: [julia-users] getindex for a real number

2015-12-02 Thread Cedric St-Jean
There's also x = [1 2; 3 4] x[:,[1]] # returns 2D array x[:, 1] # returns 1D array x[1, :] # AFAIK, returns 2D under Julia 0.4 and 1D under 0.5 I like the 0.5 behaviour a lot better. On Wednesday, December 2, 2015 at 12:21:34 PM UTC-5, Tim Holy wrote: > > Glen, that's a great list of bugs. Have

Re: [julia-users] getindex for a real number

2015-12-02 Thread Tim Holy
Glen, that's a great list of bugs. Have you considered filing them as issue(s)? Some immediate thoughts: On Wednesday, December 02, 2015 06:17:06 AM Glen O wrote: > As an example, reshape(1,1) throws an error I'm not sure that's a real problem, although indeed implementing reshape on numbers wo

Re: [julia-users] getindex for a real number

2015-12-02 Thread Tim Holy
On Wednesday, December 02, 2015 05:11:32 AM Seth wrote: > This is great. I assume it catches "for i in n" where n is a scalar, also, > right? > > I could see requiring this by default in all my packages. Might be better as a test dependency, since it works by "breaking" methods in Base. If you i

Re: [julia-users] getindex for a real number

2015-12-02 Thread Glen O
On Wednesday, 2 December 2015 11:38:50 UTC+10, Tim Holy wrote: > > Conversely, there are many people who seem to want Julia to treat scalars > and > 1-vectors indistinguishably (ala Matlab). > Sure, but it should be one way or the other, not half way between. In Matlab, scalars are literally 1-

Re: [julia-users] getindex for a real number

2015-12-02 Thread Steven G. Johnson
On Tuesday, December 1, 2015 at 9:38:46 PM UTC-5, Eric Forgy wrote: > > Then again, I wish Julia had a "strict" mode. In strict mode, the language > would be more pure mathematically, e.g. scalars have no indices, the > transpose of a vector is a covector, etc. > Not all vectors represent elemen

Re: [julia-users] getindex for a real number

2015-12-02 Thread Seth
This is great. I assume it catches "for i in n" where n is a scalar, also, right? I could see requiring this by default in all my packages. On Wednesday, December 2, 2015 at 1:49:22 AM UTC-8, Eric Forgy wrote: > > Some more improvements... > > julia> n = 5 > 5 > > julia> for i = n >print

Re: [julia-users] getindex for a real number

2015-12-02 Thread Tim Holy
Seems like this has the makings of a nice package for debugging. Best, --Tim On Wednesday, December 02, 2015 01:49:22 AM Eric Forgy wrote: > Some more improvements... > > julia> n = 5 > 5 > > julia> for i = n >println(i) >end > 5 > > julia> using strict > > julia> for i = n >

Re: [julia-users] getindex for a real number

2015-12-02 Thread Eric Forgy
Some more improvements... julia> n = 5 5 julia> for i = n println(i) end 5 julia> using strict julia> for i = n println(i) end ERROR: MethodError: `start` has no method matching start(::Type{Number}) in start at C:\Users\Eric Forgy\.julia\v0.4\strict\src\strict.jl:2

Re: [julia-users] getindex for a real number

2015-12-01 Thread Eric Forgy
It's a start :) https://github.com/EricForgy/strict.jl julia> using strict julia> a = 5 5 julia> a[1] ERROR: MethodError: `getindex` has no method matching getindex(::Type{Number }, ::Type{Integer}) Closest candidates are: getindex(::Type{T}, ::Any...) getindex{T<:Union{Char,Number}}(::Typ

Re: [julia-users] getindex for a real number

2015-12-01 Thread Tim Holy
Likewise, I do see why this is a little troublesome. It's annoying when you mean to write `for i = 1:n` but accidentally write `for i = n`; it's not always an easy bug to find. --Tim On Tuesday, December 01, 2015 06:38:46 PM Eric Forgy wrote: > It bugs me, but only a little, so I won't lose sle

Re: [julia-users] getindex for a real number

2015-12-01 Thread Eric Forgy
It bugs me, but only a little, so I won't lose sleep over it :) Then again, I wish Julia had a "strict" mode. In strict mode, the language would be more pure mathematically, e.g. scalars have no indices, the transpose of a vector is a covector, etc. This bit me recently because if T <: U, then

Re: [julia-users] getindex for a real number

2015-12-01 Thread Tim Holy
On Tuesday, December 01, 2015 03:19:33 PM Eric Forgy wrote: > A scalar is distinct from a vector so size(a) = () makes sense. getindex for > a scalar does not make sense and should probably be removed on the grounds > of mathematical elegance :) Any code that depends on referencing a scalar > via a

Re: [julia-users] getindex for a real number

2015-12-01 Thread Eric Forgy
A scalar is distinct from a vector so size(a) = () makes sense. getindex for a scalar does not make sense and should probably be removed on the grounds of mathematical elegance :) Any code that depends on referencing a scalar via an index is probably flawed in the first place.

Re: [julia-users] getindex for a real number

2015-12-01 Thread Ehsan Eftekhari
Then I remember sth else. Most probably I have tried ones(size(a)) in Julia when `a` is a real number, and it does not do what the same command does in Matlab. There are some other indexing that work in Julia, e.g., a=1.0 a[1] a[1,1] a[1,1,1,1] a[end,end,end] all return 1.0. But if I say size(a)

Re: [julia-users] getindex for a real number

2015-11-30 Thread Mauro
Your welcome. Your recollection is wrong though, this was possible in 0.2 and 0.3; I just checked (I don't have a 0.1 build but maybe I should...). On Mon, 2015-11-30 at 22:25, Ehsan Eftekhari wrote: > Thanks Mauro. As you predicted, my question was about the reasoning behind > this behavior. If

Re: [julia-users] getindex for a real number

2015-11-30 Thread Ehsan Eftekhari
Thanks Mauro. As you predicted, my question was about the reasoning behind this behavior. If I remember correctly, it was not possible to use getindex on real numbers in Julia 0.3. I was not sure why it is added to 0.4. On Monday, November 30, 2015 at 10:01:54 AM UTC+1, Mauro wrote: > > As it sa

Re: [julia-users] getindex for a real number

2015-11-30 Thread Mauro
As it says, there is no method for it. You could add it yourself: Base.getindex(f::Float64, ::Colon) = f # or whatever you like However, the philosophical question is: should you be allowed to index into a float (or int)? Julia usually puts convenience before strictness and allows this. I'm no

[julia-users] getindex for a real number

2015-11-30 Thread Ehsan Eftekhari
I have a question about this behaviour of getindex in Julia: if I say julia> a=1.0 1.0 then julia> a[1] 1.0 julia> a[end] 1.0 but julia> a[:] ERROR: MethodError: `getindex` has no method matching getindex(::Float64, ::Colon) Closest candidates are: getindex(::Number) getindex(::Number,