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