Skip to main content

NumericTable

Struct NumericTable 

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

A table whose cells have all been validated as numeric (RFC-034 §4.4).

Produced by Table::try_numeric. Holds row-major f64 data ready to become a matten::Tensor via NumericTable::to_tensor.

Implementations§

Source§

impl NumericTable

Source

pub fn row_count(&self) -> usize

Number of rows.

Source

pub fn column_count(&self) -> usize

Number of columns.

Source

pub fn column_names(&self) -> &[String]

Column names, in column order.

Source

pub fn to_tensor(&self) -> Result<Tensor, MattenDataError>

Build a numeric matten::Tensor with shape [rows, columns], row-major.

Errors with MattenDataError::EmptySelection if there are no columns, and wraps any core construction failure (for example a zero-length dimension when there are no rows) as MattenDataError::Matten.

Examples found in repository?
examples/csv_to_tensor.rs (line 38)
19fn main() -> Result<(), matten_data::MattenDataError> {
20    // A small, messy table: a text column and one missing numeric cell.
21    let csv = "\
22region,sales,cost,quantity
23north,100,40,5
24south,150,,7
25east,120,55,6";
26
27    let table = Table::from_csv_str(csv)?;
28
29    // Inspect what we have before converting anything.
30    println!("{}", table.schema_summary());
31
32    // Select only the numeric columns we want, fill the one missing cost with 0,
33    // convert explicitly, and produce a [rows, columns] f64 tensor.
34    let tensor = table
35        .select_columns(["sales", "cost", "quantity"])?
36        .fill_missing(0.0)?
37        .try_numeric()?
38        .to_tensor()?;
39
40    println!("tensor shape: {:?}", tensor.shape());
41    println!("tensor data : {:?}", tensor.as_slice());
42
43    // 3 rows x 3 columns; the missing south/cost became 0.0.
44    assert_eq!(tensor.shape(), &[3, 3]);
45    assert_eq!(
46        tensor.as_slice(),
47        &[100.0, 40.0, 5.0, 150.0, 0.0, 7.0, 120.0, 55.0, 6.0]
48    );
49    println!("csv_to_tensor: OK");
50    Ok(())
51}

Trait Implementations§

Source§

impl Clone for NumericTable

Source§

fn clone(&self) -> NumericTable

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 NumericTable

Source§

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

Formats the value using the given formatter. Read more

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> 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.