Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a1e7b3

Browse files
committed
Avoid memory copies with np.full
1 parent 2e9307e commit 5a1e7b3

File tree

7 files changed

+12
-12
lines changed

7 files changed

+12
-12
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4000,7 +4000,7 @@ def dopatch(xs, ys, **kwargs):
40004000
# maybe draw the fliers
40014001
if showfliers:
40024002
# fliers coords
4003-
flier_x = np.ones(len(stats['fliers'])) * pos
4003+
flier_x = np.full(len(stats['fliers']), pos)
40044004
flier_y = stats['fliers']
40054005

40064006
fliers.extend(doplot(

lib/matplotlib/hatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def __init__(self, hatch, density):
169169
self.num_rows = (hatch.count('*')) * density
170170
path = Path.unit_regular_star(5)
171171
self.shape_vertices = path.vertices
172-
self.shape_codes = np.ones(len(self.shape_vertices)) * Path.LINETO
172+
self.shape_codes = np.full(len(self.shape_vertices), Path.LINETO)
173173
self.shape_codes[0] = Path.MOVETO
174174
Shapes.__init__(self, hatch, density)
175175

lib/matplotlib/legend_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def create_artists(self, legend, orig_handle,
231231
xdata, xdata_marker = self.get_xdata(legend, xdescent, ydescent,
232232
width, height, fontsize)
233233

234-
ydata = ((height - ydescent) / 2.) * np.ones(xdata.shape, float)
234+
ydata = np.full(xdata.shape, ((height - ydescent) / 2.), float)
235235
legline = Line2D(xdata, ydata)
236236

237237
self.update_prop(legline, orig_handle, legend)

lib/matplotlib/path.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def make_compound_path_from_polys(cls, XY):
312312
stride = numsides + 1
313313
nverts = numpolys * stride
314314
verts = np.zeros((nverts, 2))
315-
codes = np.ones(nverts, int) * cls.LINETO
315+
codes = np.full(nverts, cls.LINETO, dtype=int)
316316
codes[0::stride] = cls.MOVETO
317317
codes[numsides::stride] = cls.CLOSEPOLY
318318
for i in range(numsides):
@@ -552,7 +552,7 @@ def interpolated(self, steps):
552552
vertices = simple_linear_interpolation(self.vertices, steps)
553553
codes = self.codes
554554
if codes is not None:
555-
new_codes = Path.LINETO * np.ones(((len(codes) - 1) * steps + 1, ))
555+
new_codes = np.full(((len(codes) - 1) * steps + 1, ), Path.LINETO)
556556
new_codes[0::steps] = codes
557557
else:
558558
new_codes = None
@@ -802,7 +802,7 @@ def unit_circle_righthalf(cls):
802802

803803
float)
804804

805-
codes = cls.CURVE4 * np.ones(14)
805+
codes = np.full(14, cls.CURVE4)
806806
codes[0] = cls.MOVETO
807807
codes[-1] = cls.CLOSEPOLY
808808

@@ -864,7 +864,7 @@ def arc(cls, theta1, theta2, n=None, is_wedge=False):
864864
if is_wedge:
865865
length = n * 3 + 4
866866
vertices = np.zeros((length, 2), float)
867-
codes = cls.CURVE4 * np.ones((length, ), cls.code_type)
867+
codes = np.full((length, ), cls.CURVE4, dtype=cls.code_type)
868868
vertices[1] = [xA[0], yA[0]]
869869
codes[0:2] = [cls.MOVETO, cls.LINETO]
870870
codes[-2:] = [cls.LINETO, cls.CLOSEPOLY]
@@ -873,7 +873,7 @@ def arc(cls, theta1, theta2, n=None, is_wedge=False):
873873
else:
874874
length = n * 3 + 1
875875
vertices = np.empty((length, 2), float)
876-
codes = cls.CURVE4 * np.ones((length, ), cls.code_type)
876+
codes = np.full((length, ), cls.CURVE4, dtype=cls.code_type)
877877
vertices[0] = [xA[0], yA[0]]
878878
codes[0] = cls.MOVETO
879879
vertex_offset = 1

lib/matplotlib/tri/triinterpolate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ def get_Kff_and_Ff(self, J, ecc, triangles, Uc):
959959
"""
960960
ntri = np.size(ecc, 0)
961961
vec_range = np.arange(ntri, dtype=np.int32)
962-
c_indices = -np.ones(ntri, dtype=np.int32) # for unused dofs, -1
962+
c_indices = np.full(ntri, -1, dtype=np.int32) # for unused dofs, -1
963963
f_dof = [1, 2, 4, 5, 7, 8]
964964
c_dof = [0, 3, 6]
965965

lib/matplotlib/tri/trirefine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def refine_triangulation(self, return_tri_index=False, subdiv=3):
111111
# We have to initialize found_index with -1 because some nodes
112112
# may very well belong to no triangle at all, e.g., in case of
113113
# Delaunay Triangulation with DuplicatePointWarning.
114-
found_index = - np.ones(refi_npts, dtype=np.int32)
114+
found_index = np.full(refi_npts, -1, dtype=np.int32)
115115
tri_mask = self._triangulation.mask
116116
if tri_mask is None:
117117
found_index[refi_triangles] = np.repeat(ancestors,
@@ -243,7 +243,7 @@ def _refine_triangulation_once(triangulation, ancestors=None):
243243
np.arange(ntri, dtype=np.int32)]))
244244
edge_apexes = np.ravel(np.vstack([np.zeros(ntri, dtype=np.int32),
245245
np.ones(ntri, dtype=np.int32),
246-
np.ones(ntri, dtype=np.int32)*2]))
246+
np.full(ntri, 2, dtype=np.int32)]))
247247
edge_neighbors = neighbors[edge_elems, edge_apexes]
248248
mask_masters = (edge_elems > edge_neighbors)
249249

lib/matplotlib/tri/tritools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def _total_to_compress_renum(mask, n=None):
292292
if n is None:
293293
n = np.size(mask)
294294
if mask is not None:
295-
renum = -np.ones(n, dtype=np.int32) # Default num is -1
295+
renum = np.full(n, -1, dtype=np.int32) # Default num is -1
296296
valid = np.arange(n, dtype=np.int32).compress(~mask, axis=0)
297297
renum[valid] = np.arange(np.size(valid, 0), dtype=np.int32)
298298
return renum

0 commit comments

Comments
 (0)