Struct IndexRange

Source
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

Source

pub fn new(start: usize, length: usize) -> IndexRange

Trait Implementations§

Source§

impl Clone for IndexRange

Source§

fn clone(&self) -> IndexRange

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for IndexRange

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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§

fn from(range: [usize; 2]) -> IndexRange

Converts to this type from the input type.
Source§

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§

fn from(range: (usize, usize)) -> IndexRange

Converts to this type from the input type.
Source§

impl From<IndexRange> for Range<usize>

Converts from an IndexRange of start and length to a range of start..end

Source§

fn from(range: IndexRange) -> Range<usize>

Converts to this type from the input type.
Source§

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.

Source§

fn from(range: Range<usize>) -> IndexRange

Converts to this type from the input type.
Source§

impl PartialEq for IndexRange

Source§

fn eq(&self, other: &IndexRange) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for IndexRange

Source§

impl StructuralPartialEq for IndexRange

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.