Skip to main content

Owned

Struct Owned 

Source
pub struct Owned<T> { /* private fields */ }
Expand description

A Matrix/MatrixMut that owns its data.

Implementations§

Source§

impl<T> Owned<T>

Source

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.

Source

pub fn row_vector(data: Box<[T]>) -> Self

Construct a row vector directly from data.

Source

pub fn column_vector(data: Box<[T]>) -> Self

Construct a column vector directly from data.

Source

pub fn from_fn<F>(nrows: usize, ncols: usize, init: F) -> Self
where F: FnMut(RowCol) -> T,

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.

Source

pub fn try_from_fn<F>( nrows: usize, ncols: usize, init: F, ) -> Result<Self, LayoutError>
where F: FnMut(RowCol) -> T,

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.

Source

pub fn from_element(nrows: usize, ncols: usize, element: T) -> Self
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::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.

Source

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.

Source

pub fn from_fn_with_layout<F>(layout: Layout<T>, init: F) -> Self
where F: FnMut(RowCol) -> T,

Construct a new matrix using init.

Elements are initialized in memory order.

Source

pub fn from_element_with_layout(layout: Layout<T>, element: T) -> Self
where T: Clone,

Construct a new matrix by cloning element.

Elements are initialized in memory order.

Source

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> Clone for Owned<T>
where T: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Owned<T>

Source§

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

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

impl<T> Drop for Owned<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T> Matrix for Owned<T>

Source§

type Element = T

The type of the element stored in the matrix.
Source§

fn as_nonnull(&self) -> NonNull<T>

Return the base pointer for the matrix.
Source§

fn layout(&self) -> Layout<T>

Return the Layout for the matrix.
Source§

fn nrows(&self) -> usize

Return the number of rows in the matrix.
Source§

fn ncols(&self) -> usize

Return the number of columns in the matrix.
Source§

unsafe fn row_unchecked(&self, row: usize) -> &[Self::Element]

Returns the requested row without bounds checking. Read more
Source§

fn as_ptr(&self) -> *const Self::Element

Return a pointer to the base of the matrix.
Source§

fn as_slice(&self) -> &[Self::Element]

Return the underlying data as a slice.
Source§

fn row(&self, row: usize) -> &[Self::Element]

Return row row as a slice. Read more
Source§

fn get_row(&self, row: usize) -> Option<&[Self::Element]>

Return row row if row < self.nrows(). Otherwise, return None.
Source§

fn rows(&self) -> Rows<'_, Self::Element> ⓘ

Return a iterator over all rows in the matrix. Read more
Source§

unsafe fn element_unchecked(&self, row: usize, col: usize) -> &Self::Element

Returns a reference to an element without bounds checking. Read more
Source§

fn get_element(&self, row: usize, col: usize) -> Option<&Self::Element>

Return the value at the specified row and col. Read more
Source§

fn element(&self, row: usize, col: usize) -> &Self::Element

Return the value at the specified row and col. Read more
Source§

fn as_view(&self) -> Ref<'_, Self::Element>

Return a view over the matrix.
Source§

fn subview(&self, rows: Range<usize>) -> Option<Ref<'_, Self::Element>>

Return a view over the rows in rows, or None when the range is invalid.
Source§

fn window_iter(&self, batchsize: NonZeroUsize) -> Windows<'_, Self::Element> ⓘ

Return an iterator that divides the matrix into sub-matrices with (up to) batchsize rows with self.ncols() columns. Read more
Source§

fn to_rowmajor_owned(&self) -> Owned<Self::Element>
where Self::Element: Clone,

Return an Owned with the same shape as self and cloned contents.
Source§

fn try_map<F, R>(&self, f: F) -> Result<Owned<R>, LayoutError>
where F: FnMut(&Self::Element) -> R,

Create a new Matrix by applying the closure f to each element. Read more
Source§

fn map<F, R>(&self, f: F) -> Owned<R>
where F: FnMut(&Self::Element) -> R,

Create a new Matrix by applying the closure f to each element. Read more
Source§

fn transpose(&self) -> Owned<Self::Element>
where Self::Element: Clone,

Transpose the elements in self.
Source§

fn par_rows(&self) -> impl IndexedParallelIterator<Item = &[Self::Element]>
where Self::Element: Sync,

Return a parallel iterator over the rows of the matrix.
Source§

fn par_window_iter( &self, batchsize: usize, ) -> impl IndexedParallelIterator<Item = Ref<'_, Self::Element>>
where Self::Element: Sync,

Return a parallel iterator that divides the matrix into sub-matrices with (up to) batchsize rows with self.ncols() columns. Read more
Source§

impl<T> MatrixMut for Owned<T>

Source§

fn as_nonnull_mut(&mut self) -> NonNull<T>

Return the base pointer for the matrix. Read more
Source§

unsafe fn row_unchecked_mut(&mut self, row: usize) -> &mut [Self::Element]

Returns the requested row without bounds checking. Read more
Source§

fn as_mut_ptr(&mut self) -> *mut Self::Element

Return a pointer to the base of the matrix.
Source§

fn as_mut_slice(&mut self) -> &mut [Self::Element]

Return the underlying data as a mutable slice.
Source§

fn row_mut(&mut self, row: usize) -> &mut [Self::Element]

Return row row as a mutable slice. Read more
Source§

fn get_row_mut(&mut self, row: usize) -> Option<&mut [Self::Element]>

Return row row if row < self.nrows(). Otherwise, return None.
Source§

fn rows_mut(&mut self) -> RowsMut<'_, Self::Element> ⓘ

Return a mutable iterator over all rows in the matrix. Read more
Source§

unsafe fn element_unchecked_mut( &mut self, row: usize, col: usize, ) -> &mut Self::Element

Returns a mutable reference to an element without bounds checking. Read more
Source§

fn get_element_mut( &mut self, row: usize, col: usize, ) -> Option<&mut Self::Element>

Return the value at the specified row and col. Read more
Source§

fn element_mut(&mut self, row: usize, col: usize) -> &mut Self::Element

Return the value at the specified row and col. Read more
Source§

fn as_view_mut(&mut self) -> Mut<'_, Self::Element>

Return a view over the matrix.
Source§

fn par_rows_mut( &mut self, ) -> impl IndexedParallelIterator<Item = &mut [Self::Element]>
where Self::Element: Send,

Return a parallel iterator over the rows of the matrix. Read more
Source§

fn par_window_iter_mut( &mut self, batchsize: usize, ) -> impl IndexedParallelIterator<Item = Mut<'_, Self::Element>>
where Self::Element: Send,

Return a parallel iterator that divides the matrix into mutable sub-matrices with (up to) batchsize rows with self.ncols() columns. Read more
Source§

impl<T> PartialEq for Owned<T>
where T: PartialEq,

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<'a, T> Reborrow<'a> for Owned<T>

Source§

type Target = Ref<'a, T>

Source§

fn reborrow(&'a self) -> Self::Target

Borrow self into a generalized reference type and reborrow
Source§

impl<'a, T> ReborrowMut<'a> for Owned<T>

Source§

type Target = Mut<'a, T>

Source§

fn reborrow_mut(&'a mut self) -> Self::Target

Mutably borrow self into a generalized reference type and reborrow.
Source§

impl<T> Send for Owned<T>
where T: Send,

Source§

impl<T> Sync for Owned<T>
where T: Sync,

Auto Trait Implementations§

§

impl<T> Freeze for Owned<T>
where NonNull<T>: Freeze, Layout<T>: Freeze,

§

impl<T> RefUnwindSafe for Owned<T>

§

impl<T> Unpin for Owned<T>
where NonNull<T>: Unpin, Layout<T>: Unpin,

§

impl<T> UnsafeUnpin for Owned<T>

§

impl<T> UnwindSafe for Owned<T>

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> AsyncFriendly for T
where T: Send + Sync + 'static,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V