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

ordinal range implementation, fixes #5585 #6326

Merged
merged 11 commits into from
Apr 1, 2014
Merged

ordinal range implementation, fixes #5585 #6326

merged 11 commits into from
Apr 1, 2014

Conversation

JeffBezanson
Copy link
Member

Adds OrdinalRange, StepRange, UnitRange, and range.

  • Supports different step and element type, and can do arithmetic in a lifted domain to handle ordinals and small integer types.
  • Overflow is checked in length, and aside from that large ranges work, except for iterating over typemin(Int):typemax(Int).
  • Ranges with a step of 0 are no longer allowed.

The requirements on an ordinal type T are D=T-T, T+D, T<T, D%D, and div(D,D) (D is the type of the difference between elements).

$fn(r::Range ) = Range($fn(r.start), $fn(r.step), r.len)
$fn(r::Range1) = Range1($fn(r.start), r.len)
$fn(r::StepRange) = $fn(r.start):$fn(r.step):$fn(last(r))
$fn(r::Range1) = $fn(r.start):$fn(last(r))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still using Range1?

@StefanKarpinski
Copy link
Member

Glad this is coming along. This branch could stand a rebase or something to get rid of all the merges.

if D<:FloatingPoint || S<:FloatingPoint
error("StepRange should not be used with floating point")
end
step == 0 && error("step cannot be zero")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally got around to trying these out with Dates. The one hiccup I ran into for getting Date/Period ranges to automatically work was the step == 0, step>0 lines in the constructor, and the step(r) == 0 in the show method for Range. I changed them to step == zero(S) and step>zero(S), along with step(r) == zero(typeof(step(r0))) in the show method and everything works like a charm!
The reason is Date/Real and Period/Real comparisons aren't allowed in the Dates code.
I'll pull out the old range tests I use to have for DateTimes and Periods and play with this some more.

…t,len

this Range1 could be the UnitRange of #5585, with Range1 deprecated

also intended to address #5469 (performance)
still not clear what to do with floating point in StepRange
It turns out there are many cases that are drastically easier this way.
Tests not passing yet, but getting there.
rename Range1 to UnitRange

allow constructing a larger class of ranges, leaving overflow to length()
export UnitRange

NEWS for range changes

remove random test for BigInt ranges, since they now have BigInt
lengths, for which we can't yet generate random numbers.
this is likely to cause too much breakage; e.g. arrays of UnitRange{Int}
are common.
it expressed a degree of freedom that was not really there, since it
really depended on the first two parameters.
JeffBezanson added a commit that referenced this pull request Apr 1, 2014
ordinal range implementation, fixes #5585
@JeffBezanson JeffBezanson merged commit c402ce9 into master Apr 1, 2014
@StefanKarpinski
Copy link
Member

slow clap picard

@StefanKarpinski StefanKarpinski deleted the jb/newrange1 branch April 1, 2014 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants