Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf674236

Browse files
authored
(feat): usenp.zeros for buffer creation withfill_value=0 (#3082)
* (feat): use `np.zeros` for buffer creation when possible* (fix): add comment and check* (chore): relnote
1 parent481550a commitf674236

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

‎changes/3082.feature.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use:py:func:`numpy.zeros` instead of:py:func:`np.full` for a performance speedup when creating a `zarr.core.buffer.NDBuffer` with `fill_value=0`.

‎src/zarr/core/buffer/cpu.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ def create(
154154
order:Literal["C","F"]="C",
155155
fill_value:Any|None=None,
156156
)->Self:
157-
iffill_valueisNone:
157+
# np.zeros is much faster than np.full, and therefore using it when possible is better.
158+
iffill_valueisNoneor (isinstance(fill_value,int)andfill_value==0):
158159
returncls(np.zeros(shape=tuple(shape),dtype=dtype,order=order))
159160
else:
160161
returncls(np.full(shape=tuple(shape),fill_value=fill_value,dtype=dtype,order=order))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp