pub struct Owned<T> { /* private fields */ }Implementations§
Source§impl<T> Owned<T>
impl<T> Owned<T>
Sourcepub fn try_from_data(
data: Box<[T]>,
nrows: usize,
ncols: usize,
) -> Result<Self, TryFromError<Box<[T]>>>
pub fn try_from_data( data: Box<[T]>, nrows: usize, ncols: usize, ) -> Result<Self, TryFromError<Box<[T]>>>
Try to construct directly from data.
Returns an error if Layout::new fails for nrows and ncols or data.len()
is not equal to nrows * ncols.
Sourcepub fn row_vector(data: Box<[T]>) -> Self
pub fn row_vector(data: Box<[T]>) -> Self
Construct a row vector directly from data.
Sourcepub fn column_vector(data: Box<[T]>) -> Self
pub fn column_vector(data: Box<[T]>) -> Self
Construct a column vector directly from data.
Sourcepub fn from_fn<F>(nrows: usize, ncols: usize, init: F) -> Self
pub fn from_fn<F>(nrows: usize, ncols: usize, init: F) -> Self
Construct a new matrix using init.
Elements are initialized in memory order.
use diskann_utils::views::rowmajor::{self, Matrix};
let mat = rowmajor::Owned::from_fn(2, 3, |rc| 3 * rc.row + rc.col);
assert_eq!(mat.row(0), &[0, 1, 2]);
assert_eq!(mat.row(1), &[3, 4, 5]);§Panics
Panics if nrows * ncols overflows usize::MAX, or if the allocation size exceeds
isize::MAX.
Sourcepub fn try_from_fn<F>(
nrows: usize,
ncols: usize,
init: F,
) -> Result<Self, LayoutError>
pub fn try_from_fn<F>( nrows: usize, ncols: usize, init: F, ) -> Result<Self, LayoutError>
Construct a new matrix using init.
Elements are initialized in memory order.
use diskann_utils::views::rowmajor::{self, Matrix};
let mat = rowmajor::Owned::try_from_fn(2, 3, |rc| 3 * rc.row + rc.col).unwrap();
assert_eq!(mat.row(0), &[0, 1, 2]);
assert_eq!(mat.row(1), &[3, 4, 5]);§Errors
Returns an error if nrows * ncols overflows usize::MAX, or if the allocation size
exceeds isize::MAX.
Sourcepub fn from_element(nrows: usize, ncols: usize, element: T) -> Selfwhere
T: Clone,
pub fn from_element(nrows: usize, ncols: usize, element: T) -> Selfwhere
T: Clone,
Construct a new matrix by cloning element.
Elements are initialized in memory order.
use diskann_utils::views::rowmajor::{self, Matrix};
let mat = rowmajor::Owned::from_element(2, 3, 0u32);
assert_eq!(mat.row(0), &[0, 0, 0]);
assert_eq!(mat.row(1), &[0, 0, 0]);§Panics
Panics if nrows * ncols overflows usize::MAX, or if the allocation size exceeds
isize::MAX.
Sourcepub fn try_from_element(
nrows: usize,
ncols: usize,
element: T,
) -> Result<Self, LayoutError>where
T: Clone,
pub fn try_from_element(
nrows: usize,
ncols: usize,
element: T,
) -> Result<Self, LayoutError>where
T: Clone,
Construct a new matrix by cloning element.
Elements are initialized in memory order.
use diskann_utils::views::rowmajor::{self, Matrix};
let mat = rowmajor::Owned::try_from_element(2, 3, 0u32).unwrap();
assert_eq!(mat.row(0), &[0, 0, 0]);
assert_eq!(mat.row(1), &[0, 0, 0]);§Errors
Returns an error if nrows * ncols overflows usize::MAX, or if the allocation size
exceeds isize::MAX.
Sourcepub fn from_fn_with_layout<F>(layout: Layout<T>, init: F) -> Self
pub fn from_fn_with_layout<F>(layout: Layout<T>, init: F) -> Self
Construct a new matrix using init.
Elements are initialized in memory order.
Sourcepub fn from_element_with_layout(layout: Layout<T>, element: T) -> Selfwhere
T: Clone,
pub fn from_element_with_layout(layout: Layout<T>, element: T) -> Selfwhere
T: Clone,
Construct a new matrix by cloning element.
Elements are initialized in memory order.
Sourcepub fn into_inner(self) -> Box<[T]>
pub fn into_inner(self) -> Box<[T]>
Consume self, returning the unmodified contents as a boxed slice.
use diskann_utils::views::rowmajor::{Matrix, Owned};
let mat = Owned::from_fn(2, 3, |rc| rc.col);
assert_eq!(mat.row(0), &[0, 1, 2]);
assert_eq!(mat.row(1), &[0, 1, 2]);
let b: Box<[usize]> = mat.into_inner();
assert_eq!(&*b, &[0, 1, 2, 0, 1, 2]);Trait Implementations§
Source§impl<T> Matrix for Owned<T>
impl<T> Matrix for Owned<T>
Source§fn as_nonnull(&self) -> NonNull<T>
fn as_nonnull(&self) -> NonNull<T>
Source§unsafe fn row_unchecked(&self, row: usize) -> &[Self::Element]
unsafe fn row_unchecked(&self, row: usize) -> &[Self::Element]
Source§fn get_row(&self, row: usize) -> Option<&[Self::Element]>
fn get_row(&self, row: usize) -> Option<&[Self::Element]>
row if row < self.nrows(). Otherwise, return None.Source§fn rows(&self) -> Rows<'_, Self::Element> ⓘ
fn rows(&self) -> Rows<'_, Self::Element> ⓘ
Source§unsafe fn element_unchecked(&self, row: usize, col: usize) -> &Self::Element
unsafe fn element_unchecked(&self, row: usize, col: usize) -> &Self::Element
Source§fn subview(&self, rows: Range<usize>) -> Option<Ref<'_, Self::Element>>
fn subview(&self, rows: Range<usize>) -> Option<Ref<'_, Self::Element>>
rows, or None when the range is invalid.Source§fn window_iter(&self, batchsize: NonZeroUsize) -> Windows<'_, Self::Element> ⓘ
fn window_iter(&self, batchsize: NonZeroUsize) -> Windows<'_, Self::Element> ⓘ
batchsize rows with self.ncols() columns. Read moreSource§fn to_rowmajor_owned(&self) -> Owned<Self::Element>
fn to_rowmajor_owned(&self) -> Owned<Self::Element>
Owned with the same shape as self and cloned contents.Source§fn par_rows(&self) -> impl IndexedParallelIterator<Item = &[Self::Element]>
fn par_rows(&self) -> impl IndexedParallelIterator<Item = &[Self::Element]>
Source§fn par_window_iter(
&self,
batchsize: usize,
) -> impl IndexedParallelIterator<Item = Ref<'_, Self::Element>>
fn par_window_iter( &self, batchsize: usize, ) -> impl IndexedParallelIterator<Item = Ref<'_, Self::Element>>
batchsize rows with self.ncols() columns. Read moreSource§impl<T> MatrixMut for Owned<T>
impl<T> MatrixMut for Owned<T>
Source§fn as_nonnull_mut(&mut self) -> NonNull<T>
fn as_nonnull_mut(&mut self) -> NonNull<T>
Source§unsafe fn row_unchecked_mut(&mut self, row: usize) -> &mut [Self::Element]
unsafe fn row_unchecked_mut(&mut self, row: usize) -> &mut [Self::Element]
Source§fn as_mut_ptr(&mut self) -> *mut Self::Element
fn as_mut_ptr(&mut self) -> *mut Self::Element
Source§fn as_mut_slice(&mut self) -> &mut [Self::Element]
fn as_mut_slice(&mut self) -> &mut [Self::Element]
Source§fn row_mut(&mut self, row: usize) -> &mut [Self::Element]
fn row_mut(&mut self, row: usize) -> &mut [Self::Element]
row as a mutable slice. Read moreSource§fn get_row_mut(&mut self, row: usize) -> Option<&mut [Self::Element]>
fn get_row_mut(&mut self, row: usize) -> Option<&mut [Self::Element]>
row if row < self.nrows(). Otherwise, return None.Source§fn rows_mut(&mut self) -> RowsMut<'_, Self::Element> ⓘ
fn rows_mut(&mut self) -> RowsMut<'_, Self::Element> ⓘ
Source§unsafe fn element_unchecked_mut(
&mut self,
row: usize,
col: usize,
) -> &mut Self::Element
unsafe fn element_unchecked_mut( &mut self, row: usize, col: usize, ) -> &mut Self::Element
Source§fn as_view_mut(&mut self) -> Mut<'_, Self::Element>
fn as_view_mut(&mut self) -> Mut<'_, Self::Element>
Source§fn par_rows_mut(
&mut self,
) -> impl IndexedParallelIterator<Item = &mut [Self::Element]>
fn par_rows_mut( &mut self, ) -> impl IndexedParallelIterator<Item = &mut [Self::Element]>
Source§fn par_window_iter_mut(
&mut self,
batchsize: usize,
) -> impl IndexedParallelIterator<Item = Mut<'_, Self::Element>>
fn par_window_iter_mut( &mut self, batchsize: usize, ) -> impl IndexedParallelIterator<Item = Mut<'_, Self::Element>>
batchsize rows with self.ncols() columns. Read moreSource§impl<'a, T> ReborrowMut<'a> for Owned<T>
impl<'a, T> ReborrowMut<'a> for Owned<T>
impl<T> Send for Owned<T>where
T: Send,
impl<T> Sync for Owned<T>where
T: Sync,
Auto Trait Implementations§
impl<T> Freeze for Owned<T>
impl<T> RefUnwindSafe for Owned<T>
impl<T> Unpin for Owned<T>
impl<T> UnsafeUnpin for Owned<T>
impl<T> UnwindSafe for Owned<T>
Blanket Implementations§
impl<T> AsyncFriendly for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more