Skip to main content

RowSlice

Struct RowSlice 

Source
pub struct RowSlice<'a> { /* private fields */ }
Expand description

A borrowed view of one row’s set features.

All the read-only row operations live here, so they are written once and shared by an owned DataRow and by a row of a DataMatrix.

Implementations§

Source§

impl<'a> RowSlice<'a>

Source

pub const fn len(&self) -> usize

Number of feature columns in the row.

Source

pub const fn is_empty(&self) -> bool

Whether the row has no columns.

Source

pub const fn indices(&self) -> &'a [u32]

The set feature indices, ascending.

Source

pub fn get(&self, index: usize) -> Option<f32>

Value of the feature at index, or None if index is out of bounds.

Costs a binary search over the set features, unlike the other accessors here. Prefer RowSlice::iter_nonzero when visiting a whole row.

Source

pub fn iter(self) -> impl Iterator<Item = f32> + 'a

Iterate over every feature value, including the zeroes.

Walks the columns in step with the set features, so it costs the column count rather than a binary search per column.

Source

pub fn iter_nonzero(self) -> impl Iterator<Item = (usize, f32)> + 'a

Iterate over the index and value of the set features only.

This is the cheap way to read a row: it visits only what is present.

Source

pub const fn count_nonzero(&self) -> usize

Number of set features in the row.

Source

pub fn sum(&self) -> f32

Sum of the feature values, which for a presence row is the number set.

Source

pub fn dot(&self, weights: &[f32]) -> f32

Dot product of this row with a weight vector.

Only the set features contribute, so this reads one weight per set feature. Indices beyond the end of weights are ignored.

Source

pub fn retain_indices(&self, keep: &[usize]) -> DataRow

An owned row holding only the features at the given indices, renumbered to their positions in keep.

keep must be sorted ascending. Used to drop the features a trained model found unnecessary.

Trait Implementations§

Source§

impl<'a> Clone for RowSlice<'a>

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<'a> Copy for RowSlice<'a>

Source§

impl<'a> Debug for RowSlice<'a>

Source§

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

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

impl PartialEq for RowSlice<'_>

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 Serialize for RowSlice<'_>

Rows serialize as a flat sequence of every feature value rather than as indices, so JSON and TOML datasets stay readable and portable.

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for RowSlice<'a>

§

impl<'a> RefUnwindSafe for RowSlice<'a>

§

impl<'a> Send for RowSlice<'a>

§

impl<'a> Sync for RowSlice<'a>

§

impl<'a> Unpin for RowSlice<'a>

§

impl<'a> UnsafeUnpin for RowSlice<'a>

§

impl<'a> UnwindSafe for RowSlice<'a>

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

Source§

type Output = T

Should always be Self
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.