pub struct IndexRange { /* private fields */ }
Expand description
A range bounded between start
inclusive and start + length
exclusive.
§Examples
Converting between Range and IndexRange.
use std::ops::Range;
use easy_ml::matrices::views::IndexRange;
assert_eq!(IndexRange::new(3, 2), (3..5).into());
assert_eq!(IndexRange::new(1, 5), (1..6).into());
assert_eq!(IndexRange::new(0, 4), (0..4).into());
Creating a Range
use easy_ml::matrices::views::IndexRange;
let range = IndexRange::new(3, 2);
let also_range: IndexRange = (3, 2).into();
let also_also_range: IndexRange = [3, 2].into();
NB: You can construct an IndexRange where start+length exceeds isize::MAX or even usize::MAX, however matrices and tensors themselves cannot contain more than isize::MAX elements. Concerned readers should note that on a 64 bit computer this maximum value is 9,223,372,036,854,775,807 so running out of memory is likely to occur first.
Implementations§
Source§impl IndexRange
impl IndexRange
pub fn new(start: usize, length: usize) -> IndexRange
Trait Implementations§
Source§impl Clone for IndexRange
impl Clone for IndexRange
Source§fn clone(&self) -> IndexRange
fn clone(&self) -> IndexRange
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for IndexRange
impl Debug for IndexRange
Source§impl From<[usize; 2]> for IndexRange
Converts from an array of start and length to an IndexRange
impl From<[usize; 2]> for IndexRange
Converts from an array of start and length to an IndexRange
NOTE: In previous versions (<=1.8.1), this was erroneously implemented as conversion from an array of start and end, not start and length as documented.
Source§impl From<(usize, usize)> for IndexRange
Converts from a tuple of start and length to an IndexRange
impl From<(usize, usize)> for IndexRange
Converts from a tuple of start and length to an IndexRange
NOTE: In previous versions (<=1.8.1), this was erroneously implemented as conversion from a tuple of start and end, not start and length as documented.
Source§impl From<IndexRange> for Range<usize>
Converts from an IndexRange of start and length to a range of start..end
impl From<IndexRange> for Range<usize>
Converts from an IndexRange of start and length to a range of start..end
Source§impl From<Range<usize>> for IndexRange
Converts from a range of start..end to an IndexRange of start and length
impl From<Range<usize>> for IndexRange
Converts from a range of start..end to an IndexRange of start and length
NOTE: In previous versions (<=1.8.1) this did not saturate when attempting to subtract the start of the range from the end to calculate the length. It will now correctly produce an IndexRange with a length of 0 if the end is before or equal to the start.