From 057e97cc47b7e58bac7814907fdb5e634f9d9395 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Fri, 1 Dec 2023 22:27:52 +0100 Subject: [PATCH] Show put/get ndarray in docs --- netcdf/src/lib.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/netcdf/src/lib.rs b/netcdf/src/lib.rs index 5929b04..486bb11 100644 --- a/netcdf/src/lib.rs +++ b/netcdf/src/lib.rs @@ -49,6 +49,12 @@ //! let data = var.values_arr::(([40, 0 ,0], [1, 100, 100]))?; //! # #[cfg(feature = "ndarray")] //! let data = var.values_arr::((40, ..100, ..100))?; +//! +//! // You can read into an ndarray to reuse an allocation +//! # #[cfg(feature = "ndarray")] +//! let mut data = ndarray::Array::::zeros((100, 100)); +//! # #[cfg(feature = "ndarray")] +//! var.values_arr_into((0, .., ..), data.view_mut())?; //! # Ok(()) } //! ``` //! @@ -69,7 +75,8 @@ //! "crab_coolness_level", //! &["time", "ncrabs"], //! )?; -//! // Metadata can be added to the variable +//! // Metadata can be added to the variable, but will not be used when +//! // writing or reading data //! var.add_attribute("units", "Kelvin")?; //! var.add_attribute("add_offset", 273.15_f32)?; //! @@ -80,6 +87,12 @@ //! // Values can be added along the unlimited dimension, which //! // resizes along the `time` axis //! var.put_values(&data, (11, ..))?; +//! +//! // Using the ndarray feature you can also use +//! # #[cfg(feature = "ndarray")] +//! let values = ndarray::Array::from_shape_fn((5, 10), |(j, i)| (j * 10 + i) as f32); +//! # #[cfg(feature = "ndarray")] +//! var.put_values_arr((11.., ..), values.view())?; //! # Ok(()) } //! ```