From e0211e21f3db0bb27a04490d712dabe04c0fed26 Mon Sep 17 00:00:00 2001 From: mdroe Date: Fri, 13 Jun 2014 22:04:04 +0000 Subject: More speedups. git-svn-id: http://svn.stsci.edu/svn/ssb/stsci_python/stsci.sphere/trunk@32541 fe389314-cf27-0410-b35b-8c050e845b92 Former-commit-id: 36e70c1cac043d59089f386a6b6d730c4887fa84 --- stsci/sphere/graph.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'stsci/sphere/graph.py') diff --git a/stsci/sphere/graph.py b/stsci/sphere/graph.py index 0fbc9a7..bae1c60 100644 --- a/stsci/sphere/graph.py +++ b/stsci/sphere/graph.py @@ -270,11 +270,17 @@ class Graph: # Don't add nodes that already exist. Update the existing # node's source_polygons list to include the new polygon. - point = vector.normalize_vector(*point) + point = vector.normalize_vector(point) - # TODO: Vectorize this - for node in self._nodes: - if np.all(np.abs(node._point - point) < 2 ** -32): + if len(self._nodes): + nodes = list(self._nodes) + node_array = np.array([node._point for node in nodes]) + + diff = np.all(np.abs(point - node_array) < 2 ** -32, axis=-1) + + indices = np.nonzero(diff)[0] + if len(indices): + node = nodes[indices[0]] node._source_polygons.update(source_polygons) return node -- cgit