Skip to content

Commit

Permalink
Merge pull request #723 from rapidsai/branch-22.10
Browse files Browse the repository at this point in the history
[gpuCI] Forward-merge branch-22.10 to branch-22.12 [skip gpuci]
  • Loading branch information
GPUtester authored Oct 3, 2022
2 parents a1d225c + 849231b commit 91b9ef0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
14 changes: 14 additions & 0 deletions python/cuspatial/cuspatial/core/_column/geocolumn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) 2021-2022 NVIDIA CORPORATION
from functools import cached_property
from typing import Tuple, TypeVar

import cupy as cp
Expand Down Expand Up @@ -218,3 +219,16 @@ def _from_points_xy(cls, points_xy: ColumnBase):
),
meta,
)

@cached_property
def memory_usage(self) -> int:
"""
Outputs how much memory is used by the underlying geometries.
"""
final_size = self._meta.input_types.memory_usage()
final_size = final_size + self._meta.union_offsets.memory_usage()
final_size = final_size + self.points._column.memory_usage
final_size = final_size + self.mpoints._column.memory_usage
final_size = final_size + self.lines._column.memory_usage
final_size = final_size + self.polygons._column.memory_usage
return final_size
1 change: 1 addition & 0 deletions python/cuspatial/cuspatial/core/geoseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ def to_arrow(self):
-- child 3 type: list<item: null>
[]
"""

points = self._column.points
mpoints = self._column.mpoints
lines = self._column.lines
Expand Down
10 changes: 10 additions & 0 deletions python/cuspatial/cuspatial/tests/test_geodataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,16 @@ def test_boolmask(gpdf, df_boolmask):
assert_eq_geo_df(gi[df_boolmask], cugpdf_back[df_boolmask])


def test_memory_usage(gs):
assert gs.memory_usage() == 224
host_dataframe = gpd.read_file(
gpd.datasets.get_path("naturalearth_lowres")
)
gpu_dataframe = cuspatial.from_geopandas(host_dataframe)
# The df size is 8kb of cudf rows and 217kb of the geometry column
assert gpu_dataframe.memory_usage().sum() == 225173


def test_from_dict():
p1 = Point([0, 1])
p2 = Point([2, 3])
Expand Down
14 changes: 14 additions & 0 deletions python/cuspatial/cuspatial/tests/test_geoseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,3 +580,17 @@ def test_shapefile_constructor_reversed():

reversed_gs = gpd.GeoSeries([polygon.orient(p, 1) for p in gs])
assert_eq_geo(reversed_gs, cus.to_geopandas())


def test_memory_usage_simple(gs):
cugs = cuspatial.from_geopandas(gs)
assert cugs.memory_usage() == 1616


def test_memory_usage_large():
host_dataframe = gpd.read_file(
gpd.datasets.get_path("naturalearth_lowres")
)
geometry = cuspatial.from_geopandas(host_dataframe)["geometry"]
# the geometry column from naturalearth_lowres is 217kb of coordinates
assert geometry.memory_usage() == 217021

0 comments on commit 91b9ef0

Please sign in to comment.