Skip to content

Commit

Permalink
Remove "large" arrays and scalars with i64 offsets (#803)
Browse files Browse the repository at this point in the history
### Change list

- Remove the `O: OffsetSizeTrait` generic from all native geometry array
and scalar structs.
- Keep the `O: OffsetSizeTrait` generic on `WKBArray` and `WKTArray`,
since those are much smaller code paths, and since those are in theory
more likely to actually be necessary with i64 offsets.

Closes #802
  • Loading branch information
kylebarron authored Sep 30, 2024
1 parent b997607 commit 1673a43
Show file tree
Hide file tree
Showing 189 changed files with 2,904 additions and 6,930 deletions.
2 changes: 1 addition & 1 deletion benches/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use geoarrow::array::{AsChunkedNativeArray, MultiPolygonArray};
use geoarrow::io::flatgeobuf::read_flatgeobuf;
use std::fs::File;

fn load_file() -> MultiPolygonArray<i32, 2> {
fn load_file() -> MultiPolygonArray<2> {
let mut file = File::open("fixtures/flatgeobuf/countries.fgb").unwrap();
let table = read_flatgeobuf(&mut file, Default::default()).unwrap();
table
Expand Down
9 changes: 3 additions & 6 deletions benches/from_geo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ pub fn criterion_benchmark(c: &mut Criterion) {

c.bench_function("convert Vec<geo::Polygon> to PolygonArray", |b| {
b.iter(|| {
let mut_arr = PolygonBuilder::<i32, 2>::from_polygons(
&data,
Default::default(),
Default::default(),
);
let _arr: PolygonArray<i32, 2> = mut_arr.into();
let mut_arr =
PolygonBuilder::<2>::from_polygons(&data, Default::default(), Default::default());
let _arr: PolygonArray<2> = mut_arr.into();
})
});
}
Expand Down
2 changes: 1 addition & 1 deletion benches/geos_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {

c.bench_function("buffer", |b| {
b.iter(|| {
let _buffered: PolygonArray<i32, 2> = point_array.buffer(1.0, 8).unwrap();
let _buffered: PolygonArray<2> = point_array.buffer(1.0, 8).unwrap();
})
});
}
Expand Down
4 changes: 2 additions & 2 deletions benches/nybb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use geoarrow::algorithm::geo::EuclideanDistance;
use geoarrow::array::{MultiPolygonArray, PointArray};
use geoarrow::trait_::ArrayAccessor;

fn load_nybb() -> MultiPolygonArray<i32, 2> {
fn load_nybb() -> MultiPolygonArray<2> {
let file = File::open("fixtures/nybb.arrow").unwrap();
let reader = FileReader::try_new(file, None).unwrap();

Expand All @@ -20,7 +20,7 @@ fn load_nybb() -> MultiPolygonArray<i32, 2> {
.position(|field| field.name() == "geometry")
.unwrap();
let arr = record_batch.column(geom_idx);
let multi_poly_arr: MultiPolygonArray<i32, 2> = arr.as_ref().try_into().unwrap();
let multi_poly_arr: MultiPolygonArray<2> = arr.as_ref().try_into().unwrap();
arrays.push(multi_poly_arr);
}

Expand Down
2 changes: 1 addition & 1 deletion benches/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use criterion::{criterion_group, criterion_main, Criterion};
use geoarrow::algorithm::geo::Translate;
use geoarrow::array::PolygonArray;

fn create_data() -> PolygonArray<i32, 2> {
fn create_data() -> PolygonArray<2> {
// An L shape
// https://github.com/georust/geo/blob/7cb7d0ffa6bf1544c5ca9922bd06100c36f815d7/README.md?plain=1#L40
let poly = polygon![
Expand Down
4 changes: 2 additions & 2 deletions benches/wkb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ pub fn criterion_benchmark(c: &mut Criterion) {

c.bench_function("parse WKBArray to geoarrow MultiPolygonArray", |b| {
b.iter(|| {
let _values: MultiPolygonArray<i32, 2> = array.clone().try_into().unwrap();
let _values: MultiPolygonArray<2> = array.clone().try_into().unwrap();
})
});
c.bench_function(
"parse WKBArray to geoarrow MultiPolygonArray then to Vec<geo::Geometry>",
|b| {
b.iter(|| {
let array: MultiPolygonArray<i32, 2> = array.clone().try_into().unwrap();
let array: MultiPolygonArray<2> = array.clone().try_into().unwrap();
let _out: Vec<geo::Geometry> = array
.iter_geo_values()
.map(geo::Geometry::MultiPolygon)
Expand Down
74 changes: 68 additions & 6 deletions js/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/src/broadcasting/linestring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use wasm_bindgen::prelude::*;

enum _BroadcastableLineString {
Scalar(geoarrow::scalar::OwnedLineString<i32>),
Array(geoarrow::array::LineStringArray<i32, 2>),
Array(geoarrow::array::LineStringArray<2>),
}

#[wasm_bindgen]
Expand Down
2 changes: 1 addition & 1 deletion js/src/broadcasting/multilinestring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use wasm_bindgen::prelude::*;

enum _BroadcastableMultiLineString {
Scalar(geoarrow::scalar::OwnedMultiLineString<i32>),
Array(geoarrow::array::MultiLineStringArray<i32, 2>),
Array(geoarrow::array::MultiLineStringArray<2>),
}

#[wasm_bindgen]
Expand Down
24 changes: 12 additions & 12 deletions js/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,37 +49,37 @@ impl_data! {
impl_data! {
/// An immutable array of LineString geometries in WebAssembly memory using GeoArrow's
/// in-memory representation.
pub struct LineStringData(pub(crate) geoarrow::array::LineStringArray<i32, 2>);
pub struct LineStringData(pub(crate) geoarrow::array::LineStringArray<2>);
}
impl_data! {
/// An immutable array of Polygon geometries in WebAssembly memory using GeoArrow's
/// in-memory representation.
pub struct PolygonData(pub(crate) geoarrow::array::PolygonArray<i32, 2>);
pub struct PolygonData(pub(crate) geoarrow::array::PolygonArray<2>);
}
impl_data! {
/// An immutable array of MultiPoint geometries in WebAssembly memory using GeoArrow's
/// in-memory representation.
pub struct MultiPointData(pub(crate) geoarrow::array::MultiPointArray<i32, 2>);
pub struct MultiPointData(pub(crate) geoarrow::array::MultiPointArray<2>);
}
impl_data! {
/// An immutable array of MultiLineString geometries in WebAssembly memory using GeoArrow's
/// in-memory representation.
pub struct MultiLineStringData(pub(crate) geoarrow::array::MultiLineStringArray<i32, 2>);
pub struct MultiLineStringData(pub(crate) geoarrow::array::MultiLineStringArray<2>);
}
impl_data! {
/// An immutable array of MultiPolygon geometries in WebAssembly memory using GeoArrow's
/// in-memory representation.
pub struct MultiPolygonData(pub(crate) geoarrow::array::MultiPolygonArray<i32, 2>);
pub struct MultiPolygonData(pub(crate) geoarrow::array::MultiPolygonArray<2>);
}
impl_data! {
/// An immutable array of Geometry geometries in WebAssembly memory using GeoArrow's
/// in-memory representation.
pub struct MixedGeometryData(pub(crate) geoarrow::array::MixedGeometryArray<i32, 2>);
pub struct MixedGeometryData(pub(crate) geoarrow::array::MixedGeometryArray<2>);
}
impl_data! {
/// An immutable array of GeometryCollection geometries in WebAssembly memory using GeoArrow's
/// in-memory representation.
pub struct GeometryCollectionData(pub(crate) geoarrow::array::GeometryCollectionArray<i32, 2>);
pub struct GeometryCollectionData(pub(crate) geoarrow::array::GeometryCollectionArray<2>);
}
impl_data! {
/// An immutable array of WKB-encoded geometries in WebAssembly memory using GeoArrow's
Expand Down Expand Up @@ -215,7 +215,7 @@ impl WKBData {
/// and the original wkb array's memory does not need to be freed manually.
#[wasm_bindgen(js_name = intoLineStringArray)]
pub fn into_line_string_array(self) -> WasmResult<LineStringData> {
let arr: geoarrow::array::LineStringArray<i32, 2> = self.0.try_into().unwrap();
let arr: geoarrow::array::LineStringArray<2> = self.0.try_into().unwrap();
Ok(arr.into())
}

Expand All @@ -227,7 +227,7 @@ impl WKBData {
/// and the original wkb array's memory does not need to be freed manually.
#[wasm_bindgen(js_name = intoPolygonArray)]
pub fn into_polygon_array(self) -> WasmResult<PolygonData> {
let arr: geoarrow::array::PolygonArray<i32, 2> = self.0.try_into().unwrap();
let arr: geoarrow::array::PolygonArray<2> = self.0.try_into().unwrap();
Ok(arr.into())
}

Expand All @@ -239,7 +239,7 @@ impl WKBData {
/// and the original wkb array's memory does not need to be freed manually.
#[wasm_bindgen(js_name = intoMultiPointArray)]
pub fn into_multi_point_array(self) -> WasmResult<MultiPointData> {
let arr: geoarrow::array::MultiPointArray<i32, 2> = self.0.try_into().unwrap();
let arr: geoarrow::array::MultiPointArray<2> = self.0.try_into().unwrap();
Ok(arr.into())
}

Expand All @@ -251,7 +251,7 @@ impl WKBData {
/// and the original wkb array's memory does not need to be freed manually.
#[wasm_bindgen(js_name = intoMultiLineStringArray)]
pub fn into_multi_line_string_array(self) -> WasmResult<MultiLineStringData> {
let arr: geoarrow::array::MultiLineStringArray<i32, 2> = self.0.try_into().unwrap();
let arr: geoarrow::array::MultiLineStringArray<2> = self.0.try_into().unwrap();
Ok(arr.into())
}

Expand All @@ -263,7 +263,7 @@ impl WKBData {
/// and the original wkb array's memory does not need to be freed manually.
#[wasm_bindgen(js_name = intoMultiPolygonArray)]
pub fn into_multi_polygon_array(self) -> WasmResult<MultiPolygonData> {
let arr: geoarrow::array::MultiPolygonArray<i32, 2> = self.0.try_into().unwrap();
let arr: geoarrow::array::MultiPolygonArray<2> = self.0.try_into().unwrap();
Ok(arr.into())
}
}
10 changes: 5 additions & 5 deletions js/src/scalar/linestring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ use geoarrow::scalar::OwnedLineString;
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub struct LineString(pub(crate) OwnedLineString<i32, 2>);
pub struct LineString(pub(crate) OwnedLineString<2>);

impl<'a> From<&'a LineString> for geoarrow::scalar::LineString<'a, i32, 2> {
impl<'a> From<&'a LineString> for geoarrow::scalar::LineString<'a, 2> {
fn from(value: &'a LineString) -> Self {
(&value.0).into()
}
}

impl From<LineString> for geoarrow::scalar::OwnedLineString<i32, 2> {
impl From<LineString> for geoarrow::scalar::OwnedLineString<2> {
fn from(value: LineString) -> Self {
value.0
}
}

impl<'a> From<geoarrow::scalar::LineString<'a, i32, 2>> for LineString {
fn from(value: geoarrow::scalar::LineString<'a, i32, 2>) -> Self {
impl<'a> From<geoarrow::scalar::LineString<'a, 2>> for LineString {
fn from(value: geoarrow::scalar::LineString<'a, 2>) -> Self {
LineString(value.into())
}
}
10 changes: 5 additions & 5 deletions js/src/scalar/multilinestring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ use geoarrow::scalar::OwnedMultiLineString;
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub struct MultiLineString(pub(crate) OwnedMultiLineString<i32, 2>);
pub struct MultiLineString(pub(crate) OwnedMultiLineString<2>);

impl<'a> From<&'a MultiLineString> for geoarrow::scalar::MultiLineString<'a, i32, 2> {
impl<'a> From<&'a MultiLineString> for geoarrow::scalar::MultiLineString<'a, 2> {
fn from(value: &'a MultiLineString) -> Self {
(&value.0).into()
}
}

impl From<MultiLineString> for geoarrow::scalar::OwnedMultiLineString<i32, 2> {
impl From<MultiLineString> for geoarrow::scalar::OwnedMultiLineString<2> {
fn from(value: MultiLineString) -> Self {
value.0
}
}

impl<'a> From<geoarrow::scalar::MultiLineString<'a, i32, 2>> for MultiLineString {
fn from(value: geoarrow::scalar::MultiLineString<'a, i32, 2>) -> Self {
impl<'a> From<geoarrow::scalar::MultiLineString<'a, 2>> for MultiLineString {
fn from(value: geoarrow::scalar::MultiLineString<'a, 2>) -> Self {
MultiLineString(value.into())
}
}
Loading

0 comments on commit 1673a43

Please sign in to comment.