From ad0adec8e80b4315a31f5c7ebad527c9cbc815f7 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 29 Jul 2024 02:37:48 -0700 Subject: [PATCH] numpy.array(..., copy=False) -> numpy.asarray(...) For numpy 2.0 --- masque/file/svg.py | 2 +- masque/library.py | 2 +- masque/shapes/path.py | 4 ++-- masque/shapes/polygon.py | 4 ++-- masque/utils/pack2d.py | 10 +++++----- masque/utils/vertices.py | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/masque/file/svg.py b/masque/file/svg.py index 8c4b43d..148f6d4 100644 --- a/masque/file/svg.py +++ b/masque/file/svg.py @@ -154,7 +154,7 @@ def poly2path(vertices: ArrayLike) -> str: Returns: SVG path-string. """ - verts = numpy.array(vertices, copy=False) + verts = numpy.asarray(vertices) commands = 'M{:g},{:g} '.format(verts[0][0], verts[0][1]) # noqa: UP032 for vertex in verts[1:]: commands += 'L{:g},{:g}'.format(vertex[0], vertex[1]) # noqa: UP032 diff --git a/masque/library.py b/masque/library.py index 9771eaf..11a3c1e 100644 --- a/masque/library.py +++ b/masque/library.py @@ -460,7 +460,7 @@ class ILibraryView(Mapping[str, 'Pattern'], metaclass=ABCMeta): if transform is None or transform is True: transform = numpy.zeros(4) elif transform is not False: - transform = numpy.array(transform, dtype=float, copy=False) + transform = numpy.asarray(transform, dtype=float) original_pattern = pattern diff --git a/masque/shapes/path.py b/masque/shapes/path.py index dfd89f1..7412ca5 100644 --- a/masque/shapes/path.py +++ b/masque/shapes/path.py @@ -34,7 +34,7 @@ class Path(Shape): and an offset. Note that the setter for `Path.vertices` may (but may not) create a copy of the - passed vertex coordinates. See `numpy.array(..., copy=False)` for details. + passed vertex coordinates. See `numpy.asarray()` for details. A normalized_form(...) is available, but can be quite slow with lots of vertices. """ @@ -119,7 +119,7 @@ class Path(Shape): Vertices of the path (Nx2 ndarray: `[[x0, y0], [x1, y1], ...]` When setting, note that a copy of the provided vertices may or may not be made, - following the rules from `numpy.array(.., copy=False)`. + following the rules from `numpy.asarray()`. """ return self._vertices diff --git a/masque/shapes/polygon.py b/masque/shapes/polygon.py index f6add4d..ea71b09 100644 --- a/masque/shapes/polygon.py +++ b/masque/shapes/polygon.py @@ -21,7 +21,7 @@ class Polygon(Shape): implicitly-closed boundary, and an offset. Note that the setter for `Polygon.vertices` may (but may not) create a copy of the - passed vertex coordinates. See `numpy.array(..., copy=False)` for details. + passed vertex coordinates. See `numpy.asarray() for details. A `normalized_form(...)` is available, but can be quite slow with lots of vertices. """ @@ -41,7 +41,7 @@ class Polygon(Shape): Vertices of the polygon (Nx2 ndarray: `[[x0, y0], [x1, y1], ...]`) When setting, note that a copy of the provided vertices may or may not be made, - following the rules from `numpy.array(.., copy=False)`. + following the rules from `numpy.asarray()`. """ return self._vertices diff --git a/masque/utils/pack2d.py b/masque/utils/pack2d.py index 5de9728..ce6b006 100644 --- a/masque/utils/pack2d.py +++ b/masque/utils/pack2d.py @@ -38,8 +38,8 @@ def maxrects_bssf( Raises: MasqueError if `allow_rejects` is `True` but some `rects` could not be placed. """ - regions = numpy.array(containers, copy=False, dtype=float) - rect_sizes = numpy.array(rects, copy=False, dtype=float) + regions = numpy.asarray(containers, dtype=float) + rect_sizes = numpy.asarray(rects, dtype=float) rect_locs = numpy.zeros_like(rect_sizes) rejected_inds = set() @@ -139,8 +139,8 @@ def guillotine_bssf_sas( Raises: MasqueError if `allow_rejects` is `True` but some `rects` could not be placed. """ - regions = numpy.array(containers, copy=False, dtype=float) - rect_sizes = numpy.array(rects, copy=False, dtype=float) + regions = numpy.asarray(containers, dtype=float) + rect_sizes = numpy.asarray(rects, dtype=float) rect_locs = numpy.zeros_like(rect_sizes) rejected_inds = set() @@ -227,7 +227,7 @@ def pack_patterns( MasqueError if `allow_rejects` is `True` but some `rects` could not be placed. """ - half_spacing = numpy.array(spacing, copy=False, dtype=float) / 2 + half_spacing = numpy.asarray(spacing, dtype=float) / 2 bounds = [library[pp].get_bounds() for pp in patterns] sizes = [bb[1] - bb[0] + spacing if bb is not None else spacing for bb in bounds] diff --git a/masque/utils/vertices.py b/masque/utils/vertices.py index 0c5f03b..b6497bd 100644 --- a/masque/utils/vertices.py +++ b/masque/utils/vertices.py @@ -73,8 +73,8 @@ def poly_contains_points( Returns: ndarray of booleans, [point0_is_in_shape, point1_is_in_shape, ...] """ - points = numpy.array(points, copy=False) - vertices = numpy.array(vertices, copy=False) + points = numpy.asarray(points, dtype=float) + vertices = numpy.asarray(vertices, dtype=float) if points.size == 0: return numpy.zeros(0, dtype=numpy.int8)