Skip to content

Commit

Permalink
upgrade ndarray to 0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
nmandery authored and lnicola committed Oct 16, 2024
1 parent b7ca8ad commit 5a500bd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Add a `bundled` feature for `gdal-sys` that allows to build and statically link a minimal bundled version of gdal during `cargo build`
- Add methods ``alternative_name``, ``is_nullable``, ``is_unique``, ``default_value`` to ``Field``.
- Add a `geometry_type` method to Layer.defn
- Upgraded `ndarray` dependency to 0.16.

## 0.17.1

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ libc = "0.2"
geo-types = { version = "0.7.11" }
gdal-sys = { path = "gdal-sys", version = "0.10" }
gdal-src = { path = "gdal-src", optional = true, default-features = false }
ndarray = { version = "0.15", optional = true }
ndarray = { version = "0.16", optional = true }
chrono = { version = "0.4.26", default-features = false }
bitflags = "2.4"
once_cell = "1.18"
Expand Down
23 changes: 19 additions & 4 deletions src/raster/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,11 @@ impl<T: GdalType + Copy> From<Array2<T>> for Buffer<T> {
let shape = value.shape();
let (cols, rows) = (shape[1], shape[0]);
let data: Vec<T> = if value.is_standard_layout() {
value.into_raw_vec()
let (data, offset) = value.into_raw_vec_and_offset();
match offset {
None | Some(0) => data,
Some(offset) => data[offset..].to_vec(),
}
} else {
value.iter().copied().collect()
};
Expand All @@ -233,7 +237,7 @@ impl<T: GdalType + Copy> From<Array2<T>> for Buffer<T> {
#[cfg(test)]
mod tests {
use crate::raster::Buffer;
use ndarray::{Array2, ShapeBuilder};
use ndarray::{arr2, s, Array2, ShapeBuilder};

#[test]
fn convert_to() {
Expand All @@ -258,8 +262,8 @@ mod tests {

#[test]
fn shapes() {
let s1 = (10, 5).into_shape().set_f(true);
let s2 = (10, 5).into_shape().set_f(false);
let s1 = (10, 5).set_f(true);
let s2 = (10, 5).set_f(false);

let a1 = Array2::from_shape_fn(s1, |(y, x)| y as i32 * 5 + x as i32);
let a2 = Array2::from_shape_fn(s2, |(y, x)| y as i32 * 5 + x as i32);
Expand All @@ -275,6 +279,17 @@ mod tests {
assert_eq!(b2, expected);
}

#[test]
fn offset() {
let arr = arr2(&[[0, 1, 2], [10, 11, 12]]);
let slice = arr.slice_move(s![1.., ..]);

let expected = Buffer::new((3, 1), (10..13).collect());
let buffer = Buffer::from(slice);

assert_eq!(buffer, expected);
}

#[test]
fn index() {
// Tests if there is one-to-one mapping between whole buffer, and whole range of indices
Expand Down

0 comments on commit 5a500bd

Please sign in to comment.