-
Notifications
You must be signed in to change notification settings - Fork 4
add several ndarray method/properties #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
from . import _binary_ufuncs, _dtypes, _funcs, _helpers, _unary_ufuncs | ||
from ._detail import _dtypes_impl, _util | ||
from ._normalizations import ArrayLike, normalizer | ||
|
||
newaxis = None | ||
|
||
|
@@ -117,6 +118,14 @@ def flags(self): | |
} | ||
) | ||
|
||
@property | ||
def data(self): | ||
return self.tensor.data_ptr() | ||
|
||
@property | ||
def nbytes(self): | ||
return self.tensor.storage().nbytes() | ||
|
||
@property | ||
def T(self): | ||
return self.transpose() | ||
|
@@ -157,7 +166,8 @@ def view(self, dtype): | |
tview = self.tensor.view(torch_dtype) | ||
return ndarray(tview) | ||
|
||
def fill(self, value): | ||
@normalizer | ||
def fill(self, value: ArrayLike): | ||
self.tensor.fill_(value) | ||
|
||
def tolist(self): | ||
|
@@ -395,6 +405,15 @@ def sort(self, axis=-1, kind=None, order=None): | |
cumprod = _funcs.cumprod | ||
|
||
### indexing ### | ||
def item(self, *args): | ||
if args == (): | ||
return self.tensor.item() | ||
elif len(args) == 1: | ||
# int argument | ||
return self.ravel()[args[0]] | ||
else: | ||
return self.__getitem__(args) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have tests for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not at the moment. Don't see numpy tests in numpy proper either. Behavior with arrays seems legacy TBH, so I'd prefer to put it to the priority queue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you pulled this from the NumPy implementation, let's just add a link to it and roll with it. |
||
@staticmethod | ||
def _upcast_int_indices(index): | ||
if isinstance(index, torch.Tensor): | ||
|
Uh oh!
There was an error while loading. Please reload this page.