From 213e50f7a337bcccddf71a98b5a796ba0b79e665 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Mon, 12 Aug 2024 10:34:35 +0200 Subject: [PATCH 1/4] Update ndarray --- Cargo.lock | 10 +++++----- Cargo.toml | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f266c89..54c475f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -642,7 +642,7 @@ dependencies = [ "libdeflater", "log", "lru", - "ndarray 0.15.6", + "ndarray 0.16.0", "netcdf", "numpy", "pyo3", @@ -998,7 +998,6 @@ dependencies = [ "num-integer", "num-traits", "rawpointer", - "rayon", ] [[package]] @@ -1014,17 +1013,18 @@ dependencies = [ "portable-atomic", "portable-atomic-util", "rawpointer", + "rayon", ] [[package]] name = "netcdf" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9162dca8a5ca1d10bb6c797b2f9f1a43a00dc97e830577031c255695b0790d6" +checksum = "84b45ab011b86e2c99be97dfd089a79c4c5b78c54d20bb9ad8a245c5bf18a331" dependencies = [ "bitflags 2.6.0", "libc", - "ndarray 0.15.6", + "ndarray 0.16.0", "netcdf-sys", "semver", ] diff --git a/Cargo.toml b/Cargo.toml index 8fad909..942f5a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,10 +35,10 @@ hdf5 = { package = "hdf5-metno", version = "0.9.1" } hdf5-sys = { package = "hdf5-metno-sys", version = "0.9.1" } log = "0.4" rayon = "1.10" -ndarray = { version = "0.15", features = [ "rayon" ] } +ndarray = { version = "0.16", features = [ "rayon" ] } pyo3 = { version = "0.21", optional = true, features = ["anyhow", "auto-initialize", "abi3-py39"] } numpy = { version = "0.21.0", optional = true } -netcdf = { version = "0.10.1", optional = true } +netcdf = { version = "0.10.4", optional = true } [dependencies.serde] features = ["derive"] From 376775693fbbdd1322910c6998b8612d6344fa1d Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Mon, 12 Aug 2024 10:36:10 +0200 Subject: [PATCH 2/4] Remove cow_is_borrowed --- src/idx/serde.rs | 3 +-- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/idx/serde.rs b/src/idx/serde.rs index 02d291f..55f59b9 100644 --- a/src/idx/serde.rs +++ b/src/idx/serde.rs @@ -92,8 +92,7 @@ pub mod chunks_u64s { let chunks: &'a [Chunk] = Chunk::::slice_from_u64s(slice); let chunks = Cow::<'a, [Chunk]>::from(chunks); - #[cfg(feature = "unstable")] - debug_assert!(chunks.is_borrowed()); + debug_assert!(matches!(chunks, Cow::Borrowed(_))); Ok(chunks) } diff --git a/src/lib.rs b/src/lib.rs index 6b222ef..1dfbcb7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -85,7 +85,7 @@ //! hdf5-src = { git = "https://github.com/magnusuMET/hdf5-rust", branch = "hidefix_jul_2023" } //! ``` -#![cfg_attr(feature = "unstable", feature(new_uninit, cow_is_borrowed))] +#![cfg_attr(feature = "unstable", feature(new_uninit))] pub mod extent; pub mod filters; From 0681685026d74cb22d9221efc28f937c0bcecada Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Mon, 12 Aug 2024 11:15:09 +0200 Subject: [PATCH 3/4] Use mapv_inplace in python code --- src/python/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python/mod.rs b/src/python/mod.rs index 279043f..c5847f4 100644 --- a/src/python/mod.rs +++ b/src/python/mod.rs @@ -15,7 +15,7 @@ use crate::idx; use crate::prelude::*; #[pymodule] -fn hidefix(_py: Python, m: &PyModule) -> PyResult<()> { +fn hidefix(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; Ok(()) } @@ -164,7 +164,7 @@ impl Dataset { let arr = arr.downcast::>().unwrap(); let mut v = unsafe { arr.as_array_mut() }; - v.par_mapv_inplace(|v| if v == cond { fv } else { v }); + v.mapv_inplace(|v| if v == cond { fv } else { v }); } } From a9906e85888e699fac09f855fa1dcb423cdaef09 Mon Sep 17 00:00:00 2001 From: Magnus Ulimoen Date: Mon, 12 Aug 2024 13:48:48 +0200 Subject: [PATCH 4/4] Force ndarray 0.15 to have rayon feature enabled --- Cargo.lock | 2 ++ Cargo.toml | 2 ++ src/python/mod.rs | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 54c475f..3751de2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -642,6 +642,7 @@ dependencies = [ "libdeflater", "log", "lru", + "ndarray 0.15.6", "ndarray 0.16.0", "netcdf", "numpy", @@ -998,6 +999,7 @@ dependencies = [ "num-integer", "num-traits", "rawpointer", + "rayon", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 942f5a4..e1bf2a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,8 @@ hdf5-sys = { package = "hdf5-metno-sys", version = "0.9.1" } log = "0.4" rayon = "1.10" ndarray = { version = "0.16", features = [ "rayon" ] } +# Remove when https://github.com/PyO3/rust-numpy/pull/439 is addressed +ndarray_0_15 = { package = "ndarray", version = "0.15", features = ["rayon"] } pyo3 = { version = "0.21", optional = true, features = ["anyhow", "auto-initialize", "abi3-py39"] } numpy = { version = "0.21.0", optional = true } netcdf = { version = "0.10.4", optional = true } diff --git a/src/python/mod.rs b/src/python/mod.rs index c5847f4..430cb1b 100644 --- a/src/python/mod.rs +++ b/src/python/mod.rs @@ -164,7 +164,7 @@ impl Dataset { let arr = arr.downcast::>().unwrap(); let mut v = unsafe { arr.as_array_mut() }; - v.mapv_inplace(|v| if v == cond { fv } else { v }); + v.par_mapv_inplace(|v| if v == cond { fv } else { v }); } }