This avoid looping over numpy arrays and creating a whole bunch of temporary arrays.
On my decent sized network of 1664323 nodes and 3314515 faces (3 and 4 sided polygons).
Old build_edge_coordinates() -> 3min 44s
New build_edge_coordinates() -> 1.24s
Peak memory usage though could be an issue as we are allocating two large arrays. The first is a 3D array (self.nodes[self.edges]) of shape (4978836, 2, 2) and the second (allocated by mean operation) (4978836, 2). However, the performance benefit I think is worth the memory cost. Perhaps there is a more memory efficient way to compute this that is also fast.
This avoid looping over numpy arrays and creating a whole bunch of temporary arrays.
On my decent sized network of 1664323 nodes and 3314515 faces (3 and 4 sided polygons). Old build_edge_coordinates() -> 3min 44s New build_edge_coordinates() -> 1.24s
Peak memory usage though could be an issue as we are allocating two large arrays. The first is a 3D array (
self.nodes[self.edges]
) of shape (4978836, 2, 2) and the second (allocated bymean
operation) (4978836, 2). However, the performance benefit I think is worth the memory cost. Perhaps there is a more memory efficient way to compute this that is also fast.