Implemented SliceRange for RangeInclusive (#911)

This commit is contained in:
Violeta Hernández 2021-06-17 02:42:47 -05:00 committed by GitHub
parent 2287e5088a
commit 885bbdaf97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use std::ops::{Range, RangeFrom, RangeFull, RangeTo}; use std::ops::{Range, RangeFrom, RangeFull, RangeInclusive, RangeTo};
use std::slice; use std::slice;
use crate::base::allocator::Allocator; use crate::base::allocator::Allocator;
@ -806,6 +806,25 @@ impl<D: Dim> SliceRange<D> for RangeFull {
} }
} }
impl<D: Dim> SliceRange<D> for RangeInclusive<usize> {
type Size = Dynamic;
#[inline(always)]
fn begin(&self, _: D) -> usize {
*self.start()
}
#[inline(always)]
fn end(&self, _: D) -> usize {
*self.end() + 1
}
#[inline(always)]
fn size(&self, _: D) -> Self::Size {
Dynamic::new(*self.end() + 1 - *self.start())
}
}
// TODO: see how much of this overlaps with the general indexing // TODO: see how much of this overlaps with the general indexing
// methods from indexing.rs. // methods from indexing.rs.
impl<T: Scalar, R: Dim, C: Dim, S: Storage<T, R, C>> Matrix<T, R, C, S> { impl<T: Scalar, R: Dim, C: Dim, S: Storage<T, R, C>> Matrix<T, R, C, S> {