Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linspace behavior with integer arguments #2575

Closed
Staross opened this issue Mar 15, 2013 · 7 comments
Closed

linspace behavior with integer arguments #2575

Staross opened this issue Mar 15, 2013 · 7 comments
Labels
needs decision A decision on this change is needed

Comments

@Staross
Copy link

Staross commented Mar 15, 2013

x = linspace(0,1,10)

Gives me:

0000011111

Which is not very linear.

@mlubin
Copy link
Member

mlubin commented Mar 15, 2013

You want linspace(0.0,1.0,10). I'll let other people comment on whether what you saw is the right behavior.

@dmbates
Copy link
Member

dmbates commented Mar 15, 2013

Check the version of Julia you are using. For me it is

julia> versioninfo()
Julia Version 0.2.0-509.rcecd.dirty
Commit cecd879dc4 2013-03-15 09:29:31*
Platform Info:
  OS_NAME: Linux
Using: (64-bit interface)
  Blas: libopenblas
  Lapack: libopenblas
  Libm: libopenlibm

Also, I think you wanted

julia> linspace(1,10,10)
10-element Int64 Array:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10

@pao
Copy link
Member

pao commented Mar 15, 2013

Title changed to reflect actual issue. Adding decision tag.

@JeffBezanson
Copy link
Member

I deliberately gave integer output for integer input. But perhaps nobody ever actually wants that?

@Staross
Copy link
Author

Staross commented Mar 16, 2013

The idea with linspace (linear space) is that it does linear interpolation between the two first arguments, which produce a line:

"Construct a vector of n linearly-spaced elements from start to stop."

The current behavior gives you a step function instead of a line.

I guess I would like the linear behavior 99% of the time, and could deal with the 1% with a round().

@JeffBezanson
Copy link
Member

That seems reasonable.

@mlubin
Copy link
Member

mlubin commented Mar 16, 2013

As long as the arguments aren't automatically converted to floating point, because the following behavior shouldn't change:

julia> linspace(0//1,1//1,5)
5-element Rational{Int64} Array:
 0//1
 1//4
 1//2
 3//4
 1//1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs decision A decision on this change is needed
Projects
None yet
Development

No branches or pull requests

5 participants