refactor: 深度优化空间数据处理性能
This commit is contained in:
@@ -52,6 +52,37 @@ class SpatialNameIndexTest(unittest.TestCase):
|
||||
index = (STRtree(geometries), geometries, ["小建筑", "大建筑"])
|
||||
self.assertEqual(main.match_building_info_name(index, box(0, 0, 1.5, 1.5)), "大建筑")
|
||||
|
||||
def test_batch_matching_matches_scalar_results(self):
|
||||
info_geometries = [box(0, 0, 1, 1), box(0, 0, 2, 2), box(5, 5, 6, 6)]
|
||||
index = (STRtree(info_geometries), info_geometries, ["小建筑", "大建筑", "远端建筑"])
|
||||
buildings = [box(0, 0, 1.5, 1.5), box(5.2, 5.2, 5.8, 5.8), box(10, 10, 11, 11)]
|
||||
expected = [main.match_building_info_name(index, geometry) for geometry in buildings]
|
||||
self.assertEqual(main.match_building_info_names(index, buildings), expected)
|
||||
|
||||
|
||||
class GaussianBlurTest(unittest.TestCase):
|
||||
def test_batch_convolution_matches_scalar_reference(self):
|
||||
array = np.arange(30, dtype=np.float32).reshape(5, 6)
|
||||
kernel = main.gaussian_kernel(2)
|
||||
radius = kernel.size // 2
|
||||
padded = np.pad(array, ((radius, radius), (0, 0)), mode="edge")
|
||||
moved = np.moveaxis(padded, 0, 0)
|
||||
expected = np.empty_like(array)
|
||||
for index in range(expected.shape[0]):
|
||||
expected[index] = np.tensordot(kernel, moved[index:index + kernel.size], axes=(0, 0))
|
||||
|
||||
actual = main.convolve_axis(array, kernel, axis=0)
|
||||
np.testing.assert_allclose(actual, expected, rtol=1e-6, atol=1e-6)
|
||||
|
||||
padded = np.pad(array, ((0, 0), (radius, radius)), mode="edge")
|
||||
moved = np.moveaxis(padded, 1, 0)
|
||||
expected = np.empty_like(np.moveaxis(array, 1, 0))
|
||||
for index in range(expected.shape[0]):
|
||||
expected[index] = np.tensordot(kernel, moved[index:index + kernel.size], axes=(0, 0))
|
||||
|
||||
actual = main.convolve_axis(array, kernel, axis=1)
|
||||
np.testing.assert_allclose(actual, np.moveaxis(expected, 0, 1), rtol=1e-6, atol=1e-6)
|
||||
|
||||
|
||||
class OutputSafetyTest(unittest.TestCase):
|
||||
def test_raster_layout_respects_pixel_limit(self):
|
||||
|
||||
Reference in New Issue
Block a user