numpy.array(..., copy=False) -> numpy.asarray(...)

For numpy 2.0
This commit is contained in:
Jan Petykiewicz 2024-07-29 02:37:48 -07:00
parent 8fd6896a71
commit ad0adec8e8
6 changed files with 13 additions and 13 deletions

View File

@ -154,7 +154,7 @@ def poly2path(vertices: ArrayLike) -> str:
Returns: Returns:
SVG path-string. 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 commands = 'M{:g},{:g} '.format(verts[0][0], verts[0][1]) # noqa: UP032
for vertex in verts[1:]: for vertex in verts[1:]:
commands += 'L{:g},{:g}'.format(vertex[0], vertex[1]) # noqa: UP032 commands += 'L{:g},{:g}'.format(vertex[0], vertex[1]) # noqa: UP032

View File

@ -460,7 +460,7 @@ class ILibraryView(Mapping[str, 'Pattern'], metaclass=ABCMeta):
if transform is None or transform is True: if transform is None or transform is True:
transform = numpy.zeros(4) transform = numpy.zeros(4)
elif transform is not False: elif transform is not False:
transform = numpy.array(transform, dtype=float, copy=False) transform = numpy.asarray(transform, dtype=float)
original_pattern = pattern original_pattern = pattern

View File

@ -34,7 +34,7 @@ class Path(Shape):
and an offset. and an offset.
Note that the setter for `Path.vertices` may (but may not) create a copy of the 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. 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], ...]` 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, 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 return self._vertices

View File

@ -21,7 +21,7 @@ class Polygon(Shape):
implicitly-closed boundary, and an offset. implicitly-closed boundary, and an offset.
Note that the setter for `Polygon.vertices` may (but may not) create a copy of the 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. 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], ...]`) 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, 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 return self._vertices

View File

@ -38,8 +38,8 @@ def maxrects_bssf(
Raises: Raises:
MasqueError if `allow_rejects` is `True` but some `rects` could not be placed. MasqueError if `allow_rejects` is `True` but some `rects` could not be placed.
""" """
regions = numpy.array(containers, copy=False, dtype=float) regions = numpy.asarray(containers, dtype=float)
rect_sizes = numpy.array(rects, copy=False, dtype=float) rect_sizes = numpy.asarray(rects, dtype=float)
rect_locs = numpy.zeros_like(rect_sizes) rect_locs = numpy.zeros_like(rect_sizes)
rejected_inds = set() rejected_inds = set()
@ -139,8 +139,8 @@ def guillotine_bssf_sas(
Raises: Raises:
MasqueError if `allow_rejects` is `True` but some `rects` could not be placed. MasqueError if `allow_rejects` is `True` but some `rects` could not be placed.
""" """
regions = numpy.array(containers, copy=False, dtype=float) regions = numpy.asarray(containers, dtype=float)
rect_sizes = numpy.array(rects, copy=False, dtype=float) rect_sizes = numpy.asarray(rects, dtype=float)
rect_locs = numpy.zeros_like(rect_sizes) rect_locs = numpy.zeros_like(rect_sizes)
rejected_inds = set() rejected_inds = set()
@ -227,7 +227,7 @@ def pack_patterns(
MasqueError if `allow_rejects` is `True` but some `rects` could not be placed. 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] 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] sizes = [bb[1] - bb[0] + spacing if bb is not None else spacing for bb in bounds]

View File

@ -73,8 +73,8 @@ def poly_contains_points(
Returns: Returns:
ndarray of booleans, [point0_is_in_shape, point1_is_in_shape, ...] ndarray of booleans, [point0_is_in_shape, point1_is_in_shape, ...]
""" """
points = numpy.array(points, copy=False) points = numpy.asarray(points, dtype=float)
vertices = numpy.array(vertices, copy=False) vertices = numpy.asarray(vertices, dtype=float)
if points.size == 0: if points.size == 0:
return numpy.zeros(0, dtype=numpy.int8) return numpy.zeros(0, dtype=numpy.int8)