Skip to main content

DataRow

Struct DataRow 

Source
pub struct DataRow { /* private fields */ }
Expand description

One row of features, owning its storage.

A DataMatrix is the right choice for many rows; this is for the one-off cases, such as featurizing a single file for inference.

Implementations§

Source§

impl DataRow

Source

pub fn zeroed(len: usize) -> Self

A row of len columns with nothing set.

Source

pub fn as_slice(&self) -> RowSlice<'_>

Borrow the row.

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 fn get(&self, index: usize) -> Option<f32>

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

Source

pub fn set(&mut self, index: usize, value: f32) -> Result<()>

Set the feature at index.

Idempotent, and accepts the columns in any order — it inserts so as to keep the indices sorted, which costs a move of the tail. Prefer RowAccumulator when setting many.

§Errors

Returns an error if index is out of bounds, or if value is neither zero nor one. A row records which features are present, so it cannot hold another value.

Source

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

Iterate over every feature value, including the zeroes.

Source

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

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

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.

Source

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

Dot product of this row with a weight vector.

Source

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

A new row holding only the features at the given indices, renumbered.

Trait Implementations§

Source§

impl Clone for DataRow

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 Debug for DataRow

Source§

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

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

impl Default for DataRow

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for DataRow

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl FromIterator<DataRow> for DataMatrix

Collect owned rows into a matrix.

Rows spanning a different number of columns are skipped rather than silently corrupting the matrix; the parsers check widths explicitly instead of relying on this.

Source§

fn from_iter<I: IntoIterator<Item = DataRow>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl PartialEq for DataRow

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 DataRow

Source§

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

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for DataRow

Source§

impl TryFrom<&[f32]> for DataRow

Source§

type Error = Error

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

fn try_from(values: &[f32]) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<Vec<f32>> for DataRow

Source§

type Error = Error

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

fn try_from(values: Vec<f32>) -> Result<Self>

Performs the conversion.

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.