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
impl NumericTable
Sourcepub fn column_count(&self) -> usize
pub fn column_count(&self) -> usize
Number of columns.
Sourcepub fn column_names(&self) -> &[String]
pub fn column_names(&self) -> &[String]
Column names, in column order.
Sourcepub fn to_tensor(&self) -> Result<Tensor, MattenDataError>
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 26)
7fn main() -> Result<(), matten_data::MattenDataError> {
8 // A small, messy table: mixed types and a missing cell.
9 let csv = "\
10region,sales,cost,quantity
11north,100,40,5
12south,150,,7
13east,120,55,6";
14
15 let table = Table::from_csv_str(csv)?;
16
17 // Inspect what we have before converting anything.
18 println!("{}", table.schema_summary());
19
20 // Select only the numeric columns we want, fill the one missing cost with 0,
21 // convert explicitly, and produce a [rows, columns] f64 tensor.
22 let tensor = table
23 .select_columns(["sales", "cost", "quantity"])?
24 .fill_missing(0.0)?
25 .try_numeric()?
26 .to_tensor()?;
27
28 println!("tensor shape: {:?}", tensor.shape());
29 println!("tensor data : {:?}", tensor.as_slice());
30
31 assert_eq!(tensor.shape(), &[3, 3]);
32 Ok(())
33}Trait Implementations§
Source§impl Clone for NumericTable
impl Clone for NumericTable
Source§fn clone(&self) -> NumericTable
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)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for NumericTable
impl RefUnwindSafe for NumericTable
impl Send for NumericTable
impl Sync for NumericTable
impl Unpin for NumericTable
impl UnsafeUnpin for NumericTable
impl UnwindSafe for NumericTable
Blanket Implementations§
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
Mutably borrows from an owned value. Read more