Skip to content
Snippets Groups Projects
Commit e1a69e69 authored by Federico Lolli's avatar Federico Lolli
Browse files

add conversion traits for f32

parent 86dfca9e
No related branches found
No related tags found
No related merge requests found
......@@ -42,6 +42,18 @@ impl IntoRustType<f64> for MxArray {
}
}
impl IntoRustType<f32> for MxArray {
fn into_rust(self) -> SResult<f32> {
let out = Numeric::<f32, _>::from_mx_array(self)
.mexerr(Error::InvalidMatlabType("cast to a single instead".into()))?
.data()
.first()
.mexerr(Error::Parse)?
.to_owned();
Ok(out)
}
}
impl IntoRustType<Vec<f64>> for MxArray {
fn into_rust(self) -> SResult<Vec<f64>> {
let out = Numeric::<f64, _>::from_mx_array(self)
......@@ -69,6 +81,16 @@ impl IntoMatlabType for Vec<f64> {
}
}
impl IntoMatlabType for Vec<f32> {
fn into_matlab(self) -> SResult<MxArray> {
let len = self.len();
Ok(Numeric::<f32, _>::new(self.into_boxed_slice(), &[len])
.unwrap()
.deref()
.to_owned())
}
}
/// Functions available to the user
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Mode {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment