Implement a generic read_csv method (#147)
* feat: Add interface to build `Matrix` from rows. * feat: Add option to derive `RealNumber` from string. To construct a `Matrix` from csv, and therefore from string, I need to be able to deserialize a generic `RealNumber` from string. * feat: Implement `Matrix::read_csv`.
This commit is contained in:
@@ -7,6 +7,7 @@ use rand::prelude::*;
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::iter::{Product, Sum};
|
||||
use std::ops::{AddAssign, DivAssign, MulAssign, SubAssign};
|
||||
use std::str::FromStr;
|
||||
|
||||
/// Defines real number
|
||||
/// <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_CHTML"></script>
|
||||
@@ -22,6 +23,7 @@ pub trait RealNumber:
|
||||
+ SubAssign
|
||||
+ MulAssign
|
||||
+ DivAssign
|
||||
+ FromStr
|
||||
{
|
||||
/// Copy sign from `sign` - another real number
|
||||
fn copysign(self, sign: Self) -> Self;
|
||||
@@ -154,4 +156,14 @@ mod tests {
|
||||
assert_eq!(41.0.sigmoid(), 1.);
|
||||
assert_eq!((-41.0).sigmoid(), 0.);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn f32_from_string() {
|
||||
assert_eq!(f32::from_str("1.111111").unwrap(), 1.111111)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn f64_from_string() {
|
||||
assert_eq!(f64::from_str("1.111111111").unwrap(), 1.111111111)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user