Add serde deserialize to Grid
This commit is contained in:
parent
ac83a2cbca
commit
5b7f407af9
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
sbp = { path = "../sbp", features = ["rayon", "serde"] }
|
sbp = { path = "../sbp", features = ["rayon", "serde1"] }
|
||||||
euler = { path = "../euler", features = ["serde1"] }
|
euler = { path = "../euler", features = ["serde1"] }
|
||||||
hdf5 = "0.7.0"
|
hdf5 = "0.7.0"
|
||||||
rayon = "1.3.0"
|
rayon = "1.3.0"
|
||||||
|
|
|
@ -17,6 +17,7 @@ serde = { version = "1.0.115", optional = true, default-features = false, featur
|
||||||
# Use f32 as precision, default is f64
|
# Use f32 as precision, default is f64
|
||||||
f32 = []
|
f32 = []
|
||||||
sparse = ["sprs"]
|
sparse = ["sprs"]
|
||||||
|
serde1 = ["serde", "ndarray/serde"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = "0.3.2"
|
criterion = "0.3.2"
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
use super::operators::SbpOperator2d;
|
use super::operators::SbpOperator2d;
|
||||||
use crate::Float;
|
use crate::Float;
|
||||||
use ndarray::{Array2, ArrayView2};
|
use ndarray::{Array2, ArrayView2, ArrayViewMut2};
|
||||||
|
#[cfg(feature = "serde1")]
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
|
||||||
pub struct Grid {
|
pub struct Grid {
|
||||||
pub(crate) x: Array2<Float>,
|
pub(crate) x: Array2<Float>,
|
||||||
pub(crate) y: Array2<Float>,
|
pub(crate) y: Array2<Float>,
|
||||||
|
@ -30,12 +33,21 @@ impl Grid {
|
||||||
self.x.shape()[0]
|
self.x.shape()[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn x(&self) -> ndarray::ArrayView2<Float> {
|
pub fn x(&self) -> ArrayView2<Float> {
|
||||||
self.x.view()
|
self.x.view()
|
||||||
}
|
}
|
||||||
pub fn y(&self) -> ndarray::ArrayView2<Float> {
|
pub fn x_mut(&mut self) -> ArrayViewMut2<Float> {
|
||||||
|
self.x.view_mut()
|
||||||
|
}
|
||||||
|
pub fn y(&self) -> ArrayView2<Float> {
|
||||||
self.y.view()
|
self.y.view()
|
||||||
}
|
}
|
||||||
|
pub fn y_mut(&mut self) -> ArrayViewMut2<Float> {
|
||||||
|
self.y.view_mut()
|
||||||
|
}
|
||||||
|
pub fn components(&mut self) -> (ArrayViewMut2<Float>, ArrayViewMut2<Float>) {
|
||||||
|
(self.x.view_mut(), self.y.view_mut())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn metrics(&self, op: &dyn SbpOperator2d) -> Result<Metrics, ndarray::ShapeError> {
|
pub fn metrics(&self, op: &dyn SbpOperator2d) -> Result<Metrics, ndarray::ShapeError> {
|
||||||
Metrics::new(self, op)
|
Metrics::new(self, op)
|
||||||
|
|
Loading…
Reference in New Issue