Re: [julia-users] linspace question; bug?

2016-10-15 Thread Stefan Karpinski
On Fri, Oct 14, 2016 at 8:17 PM, Páll Haraldsson 
wrote:

>
> Nobody makes a one element linspace intentionally, but would it be bad to
> allow it?
>

Yes, it's better to raise an error when asked to do something that makes no
sense than to do some arbitrary wrong thing.

I wouldn't have posted if not for seeing "Real" that is the real question
> (bug?).
>

There's a discussion about this somewhere. The linspace type is likely to
change in 0.6 anyway.


Re: [julia-users] linspace question; bug?

2016-10-14 Thread Páll Haraldsson
2016-10-14 22:58 GMT+00:00 Stefan Karpinski :

> I'll answer your question with a riddle: How can you have a length-one
> collection whose first and last value are different?
>

I know that; yes, it's a degenerate case, and as I said "may not matter too
much"

[Nobody makes a one element linspace intentionally, but would it be bad to
allow it? I'm not sure it would happen, usefully anywhere, but if it does,
then your code errors out; that may be intentional.]

I wouldn't have posted if not for seeing "Real" that is the real question
(bug?).


Re: [julia-users] linspace question; bug?

2016-10-14 Thread Stefan Karpinski
I'll answer your question with a riddle: How can you have a length-one
collection whose first and last value are different?

On Fri, Oct 14, 2016 at 6:25 PM, Páll Haraldsson 
wrote:

>
> I mistook third param for step, and got confusing error:
>
>
> julia> linspace(1, 2, 1)
> ERROR: linspace(1.0, 2.0, 1.0): endpoints differ
>  in linspace(::Float64, ::Float64, ::Float64) at ./range.jl:212
>  in linspace(::Float64, ::Float64, ::Int64) at ./range.jl:251
>  in linspace(::Int64, ::Int64, ::Int64) at ./range.jl:253
>
> julia> linspace(1.0, 2.0, 1)
> ERROR: linspace(1.0, 2.0, 1.0): endpoints differ
>  in linspace(::Float64, ::Float64, ::Float64) at ./range.jl:212
>  in linspace(::Float64, ::Float64, ::Int64) at ./range.jl:251
>
>
> It may not matter too much to get this to work (or give helpful error); I
> went to debug and found (should num/len be Integer? see inline comments):
>
>
> immutable LinSpace{T<:AbstractFloat} <: Range{T}
> start::T
> stop::T
> len::T # len::Integer, only countable..
> divisor::T
> end
>
> function linspace{T<:AbstractFloat}(start::T, stop::T, len::T)
>
> #long function omitted
>
> function linspace{T<:AbstractFloat}(start::T, stop::T, len::Real) #
> change to len::Integer, is this for type stability reasons, or to handle
> Rationals somehow?
> T_len = convert(T, len)
> T_len == len || throw(InexactError())
> linspace(start, stop, T_len)
> end
> linspace(start::Real, stop::Real, len::Real=50) =  # change to
> len::Integer=50
> linspace(promote(AbstractFloat(start), AbstractFloat(stop))..., len)
>
>


[julia-users] linspace question; bug?

2016-10-14 Thread Páll Haraldsson

I mistook third param for step, and got confusing error:


julia> linspace(1, 2, 1)
ERROR: linspace(1.0, 2.0, 1.0): endpoints differ
 in linspace(::Float64, ::Float64, ::Float64) at ./range.jl:212
 in linspace(::Float64, ::Float64, ::Int64) at ./range.jl:251
 in linspace(::Int64, ::Int64, ::Int64) at ./range.jl:253

julia> linspace(1.0, 2.0, 1)
ERROR: linspace(1.0, 2.0, 1.0): endpoints differ
 in linspace(::Float64, ::Float64, ::Float64) at ./range.jl:212
 in linspace(::Float64, ::Float64, ::Int64) at ./range.jl:251


It may not matter too much to get this to work (or give helpful error); I 
went to debug and found (should num/len be Integer? see inline comments):


immutable LinSpace{T<:AbstractFloat} <: Range{T}
start::T
stop::T
len::T # len::Integer, only countable..
divisor::T
end

function linspace{T<:AbstractFloat}(start::T, stop::T, len::T)

#long function omitted

function linspace{T<:AbstractFloat}(start::T, stop::T, len::Real) # change 
to len::Integer, is this for type stability reasons, or to handle Rationals 
somehow?
T_len = convert(T, len)
T_len == len || throw(InexactError())
linspace(start, stop, T_len)
end
linspace(start::Real, stop::Real, len::Real=50) =  # change to 
len::Integer=50
linspace(promote(AbstractFloat(start), AbstractFloat(stop))..., len)