For me, I think I just expect a vector from experience, and I could probably just change the way I work with a little effort.
One exception (I think) is that I often do numerical integration over a range of values, and I need the results at every value. I'm not sure if there's a way to do that with range objects only.
A range should act (for the most part) exactly like an array. For example indexing into a range is identical (syntax-wise) to indexing an array. What I am concerned about is performance. For instance if I had a range that has a large amount of elements would indexing into it be slower then indexing into an array? Wouldn't the range have to compute the value every single time instead of just doing a memory lookup? Or is the calculation of elements trivial and the memory savings make up for it?
Le mercredi 30 septembre 2015 à 08:55 +0200, Michele Zaffalon a écrit :
> Just curious: linspace returns a Range object, but logspace returns a
> vector because there is no much use case for a LogRange object?
>
> @feza: I have also seen the deprecation warning going away after a
> couple of calls, but I am not sure why. If you restart Julia, the
> deprecations reappear.
Deprecation warnings are only printed once for each call place. The
idea is that once you're aware of it, there's no point in nagging you.
Anyway, that warning is most probably not related to linspace at all,
but rather to the array concatenation syntax resulting in an effect
equivalent to collect(). If you show us a piece of code that prints the
warning, we can give you more details.
Regards
I ran into errors when trying to plot a function over a linspace of x values, since plotting libs currently expect vectors as arguments, not range objects. Easily fixed if you know Julia well, but Matlab/Python converts may be stymied.
I, on the other hand, don't understand the obsession with abstraction.Also, by your argument the following should all be special types rather than box-standard arrays.julia> typeof(ones(10))Array{Float64,1}julia> typeof(zeros(10))Array{Float64,1}
julia> typeof(eye(10))Array{Float64,2}
There can be reasons where a special read-only `Ones` array type is beneficial: http://stackoverflow.com/a/30968709/176071. It's just five lines of code, and Julia/LLVM is able to optimize it such that multiplication is totally elided. It's pretty cool. But as others said, these functions are fairly well entrenched in creating mutable arrays. The output from linspace, however, isn't typically mutated.Back to linspace, I'm still curious to hear more reasons for the strong dislike. Is it because of how it behaves? Or how it performs? Or how it's displayed (which is also valid)?
My main objection is that changing the behaviour of linspace is superfluous considering linrange already existed. If the goal was to encourage users to use a range instead of an array that should of been done through documentation through something like a best practices section (e.g. Use linrange instead of linspace).
I simply dislike is that linspace does not behave as expected, and I expect that this is the main reason for other as well. To give an extreme analogy, we don't go around and start defining A * B = A + B either, and linspace and similar names are just so ingrained in the Matlab (and apparently also Python) community, that it trips us up when they suddenly behave differently.
Finally, I don't buy the argument that linspace should be abstracted because of memory. It always creates one-dimensional grids, and those aren't the issue. There is a much stronger argument to create an abstraction for meshgrid and I even disliked that that one was dropped.
On Wednesday, September 30, 2015 at 4:01:17 PM UTC-4, Christoph Ortner wrote:I simply dislike is that linspace does not behave as expected, and I expect that this is the main reason for other as well. To give an extreme analogy, we don't go around and start defining A * B = A + B either, and linspace and similar names are just so ingrained in the Matlab (and apparently also Python) community, that it trips us up when they suddenly behave differently.This is a bad analogy. linspace still returns an AbstractVector with the same elements. So, it's basically doing the same thing as before, and is just implemented differently.
The question is, why does this implementation detail of linspace matter to you? It still behaves the same way in nearly every context.
The cases where it behaves differently are probably mostly bugs (overly restrictive types of function parameters) that were waiting to be caught.
Finally, I don't buy the argument that linspace should be abstracted because of memory. It always creates one-dimensional grids, and those aren't the issue. There is a much stronger argument to create an abstraction for meshgrid and I even disliked that that one was dropped.We don't need an abstraction for meshgrid, since in pretty much all applications of meshgrid you can use broadcasting operations instead (far more efficiently).I used to want meshgrid too, but it was only because I wasn't used to broadcasting operations. Since then, I have never found a case in which meshgrid would have been easier than the broadcasting operations.
I think an argument for linspace returning an Array is that it makes teaching new programmers Julia a lot easier.
If it returns an Array, its sufficient to teach students the Array type. But if it returns a Range, one has to teach an extra data type before the students can use it.
Ranges check bounds when you index them with x[i], but not when you use `for y
in x`. Someone could submit a PR for the appropriate change in base/ops.jl.
In matlab x = linspace(0,1,n) creates a vector of floats of length n. In julia it seems like the only way to do this is to use x = collect( linspace(0,1,n) ) . Is there a nicer syntax? I do mainly numeric computing and I find this quite common in my code.
julia> 0:4
5-element UnitRange{Int64}:
0,1,2,3,4
julia> 0:10
11-element UnitRange{Int64}:
0,1,2,…,9,10
julia> 0:2:20
11-element StepRange{Int64,Int64}:
0,2,4,…,18,20
julia> linspace(0,4,7)
7-element LinSpace{Float64}:
0.0,0.666667,1.33333,…,3.33333,4.0
I've coded up a simple replacement to the show() function for ranges. The idea is to give the user information more likely to be what they are wondering. Here are some examples of its output:
Any thoughts on this arrangement? The output differs from collect() in that I've arranged elements in a compact row. Also I've assumed that it's sufficient to print out only the first three elements, and the last two, because the user should be able to figure it out from there. A possible point of confusion is "7-element" which isn't actually true of the Range object. Would it be better to output "7-length" or something else?
Sorry to dredge up this issue again but was there any reason for the return type of linspace to be LinSpace instead of FloatRange. They are seemingly indistinguishable.
julia> 0:4
5-element UnitRange{Int64}:
0,1,2,3,4
julia> 0:100
101-element UnitRange{Int64}:
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,…,89,90,91,92,93,94,95,96,97,98,99,100
julia> linspace(0,2.5,4)
4-element LinSpace{Float64}:
0.0,0.833333,1.66667,2.5
Another downvote on linspace returning a range object. It seems odd for linspace and logspace to return different types, and linrange provides the low-memory option where needed. Numpy's `linspace` also returns an array object.
I ran into errors when trying to plot a function over a linspace of x values, since plotting libs currently expect vectors as arguments, not range objects. Easily fixed if you know Julia well, but Matlab/Python converts may be stymied.
On Wednesday, September 30, 2015 at 12:19:22 PM UTC-5, J Luis wrote:I want to add my voice to the dislikers. Those are the type of surprises that are not welcome mainly for matlab users.
quarta-feira, 30 de Setembro de 2015 às 16:53:57 UTC+1, Christoph Ortner escreveu:I also strongly dislike the `linspace` change; I like the idea though of having `linspace` and `linrange`, where the former should give the array.Christoph
On Wednesday, 30 September 2015 10:21:36 UTC+1, Michele Zaffalon wrote:I just realize that the thread is about 0.3.11 and I am showing output for 0.4.0-rc2. Sorry for the noise.On Wed, Sep 30, 2015 at 11:17 AM, Michele Zaffalon <michele....@gmail.com> wrote:On Wed, Sep 30, 2015 at 9:50 AM, Milan Bouchet-Valat <nali...@club.fr> wrote:Le mercredi 30 septembre 2015 à 08:55 +0200, Michele Zaffalon a écrit :
> Just curious: linspace returns a Range object, but logspace returns a
> vector because there is no much use case for a LogRange object?
>
> @feza: I have also seen the deprecation warning going away after a
> couple of calls, but I am not sure why. If you restart Julia, the
> deprecations reappear.
Deprecation warnings are only printed once for each call place. The
idea is that once you're aware of it, there's no point in nagging you.
Anyway, that warning is most probably not related to linspace at all,
but rather to the array concatenation syntax resulting in an effect
equivalent to collect(). If you show us a piece of code that prints the
warning, we can give you more details.
RegardsSorry, you are right, I was referring to the concatenation.It prints it exaclty twice if I type it in the REPL, it always prints it if I define it within a function e.g. a() = [1:3].C:\Users\michele.zaffalon>julia__ _ _(_)_ | A fresh approach to technical computing(_) | (_) (_) | Documentation: http://docs.julialang.org_ _ _| |_ __ _ | Type "?help" for help.| | | | | | |/ _` | || | |_| | | | (_| | | Version 0.4.0-rc2 (2015-09-18 17:51 UTC)_/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release|__/ | x86_64-w64-mingw32julia> [1:3]WARNING: [a] concatenation is deprecated; use collect(a) insteadin depwarn at deprecated.jl:73in oldstyle_vcat_warning at abstractarray.jl:29in vect at abstractarray.jl:32while loading no file, in expression starting on line 03-element Array{Int64,1}:123julia> [1:3]WARNING: [a] concatenation is deprecated; use collect(a) insteadin depwarn at deprecated.jl:73in oldstyle_vcat_warning at abstractarray.jl:29in vect at abstractarray.jl:32while loading no file, in expression starting on line 03-element Array{Int64,1}:123julia> [1:3]3-element Array{Int64,1}:123julia> a() = [1:3]a (generic function with 1 method)julia> a()WARNING: [a] concatenation is deprecated; use collect(a) insteadin depwarn at deprecated.jl:73in oldstyle_vcat_warning at abstractarray.jl:29in a at none:1while loading no file, in expression starting on line 03-element Array{Int64,1}:123julia> a()WARNING: [a] concatenation is deprecated; use collect(a) insteadin depwarn at deprecated.jl:73in oldstyle_vcat_warning at abstractarray.jl:29in a at none:1while loading no file, in expression starting on line 03-element Array{Int64,1}:123julia> a()WARNING: [a] concatenation is deprecated; use collect(a) insteadin depwarn at deprecated.jl:73in oldstyle_vcat_warning at abstractarray.jl:29in a at none:1while loading no file, in expression starting on line 03-element Array{Int64,1}:123
> On Wed, Sep 30, 2015 at 5:40 AM, feza <moham...@gmail.com> wrote:
> > Strange it *was* giving me an error saying deprecated and that I
> > should use collect, but now it's fine.
> >
> >
> > On Tuesday, September 29, 2015 at 10:28:12 PM UTC-4, Sheehan Olver
> > wrote:
> > > fez, I'm pretty sure the code works fine without the collect:
> > > when exp is called on linspace it converts it to a vector.
> > > Though the returned t will be linspace object.
> > >
> > > On Wednesday, September 30, 2015 at 12:10:55 PM UTC+10, feza
> > > wrote:
> > > > Here's the code I was using where I needed to use collect (I've
> > > > been playing around with Julia, so any suggestions on this code
> > > > for perf is welcome ;) ) . In general linspace (or the :
> > > > notation) is also used commonly to lay a grid in space for
> > > > solving a PDE for some other use cases.
> > > >
> > > > function gp(n)
> > > > n = convert(Int,n)
> > > > t0 = 0
> > > > tf = 5
> > > > t = collect( linspace(t0, tf, n+1) )
> > > > sigma = exp( -(t - t[1]) )
> > > >
> > > > c = [sigma; sigma[(end-1):-1:2]]
> > > > lambda = fft(c)
> > > > eta = sqrt(lambda./(2*n))
> > > >
> > > > Z = randn(2*n) + im*randn(2*n)
> > > > x = real( fft( Z.*eta ) )
> > > > return (x, t)
> > > > end
> > > >
> > > >
> > > > On Tuesday, September 29, 2015 at 8:59:52 PM UTC-4, Stefan
> > > > Karpinski wrote:
> > > > > I'm curious why you need a vector rather than an object. Do
> > > > > you mutate it after creating it? Having linspace return an
> > > > > object instead of a vector was a bit of a unclear judgement
> > > > > call so getting feedback would be good.
> > > > >
> > > > > On Tuesday, September 29, 2015, Patrick Kofod Mogensen <
> > > > > patrick....@gmail.com> wrote:
> > > > > > No:
> > > > > >
> > > > > > julia> logspace(0,3,5)
> > > > > > 5-element Array{Float64,1}:
> > > > > > 1.0
> > > > > > 5.62341
> > > > > > 31.6228
> > > > > > 177.828
> > > > > > 1000.0
> > > > > >
> > > > > > On Tuesday, September 29, 2015 at 8:50:47 PM UTC-4, Luke
> > > > > > Stagner wrote:
> > > > > > > Thats interesting. Does logspace also return a range?
> > > > > > >
> > > > > > > On Tuesday, September 29, 2015 at 5:43:28 PM UTC-7, Chris
> > > > > > > wrote:
> > > > > > > > In 0.4 the linspace function returns a range object,
> > > > > > > > and you need to use collect() to expand it. I'm also
> > > > > > > > interested in nicer syntax.