Skip to content

Commit 879c329

Browse files
committed
MAINT: add explanatory comments for ndarray.fill and ndarray.item
1 parent 7924195 commit 879c329

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

torch_np/_ndarray.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ def view(self, dtype):
168168

169169
@normalizer
170170
def fill(self, value: ArrayLike):
171+
# Both Pytorch and NumPy accept 0D arrays/tensors and scalars, and
172+
# error out on D > 0 arrays
171173
self.tensor.fill_(value)
172174

173175
def tolist(self):
@@ -406,6 +408,9 @@ def sort(self, axis=-1, kind=None, order=None):
406408

407409
### indexing ###
408410
def item(self, *args):
411+
# Mimic NumPy's implementation with three special cases (no arguments,
412+
# a flat index and a multi-index):
413+
# https://github.com/numpy/numpy/blob/main/numpy/core/src/multiarray/methods.c#L702
409414
if args == ():
410415
return self.tensor.item()
411416
elif len(args) == 1:

0 commit comments

Comments
 (0)