-
Notifications
You must be signed in to change notification settings - Fork 4
port scalarmath tests #16
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A general question. Can you remind me why we need to explicitly have a base
member within _ndarray
? What use cases does it cover?
return asarray(self._tensor.imag) | ||
except RuntimeError: | ||
zeros = torch.zeros_like(self._tensor) | ||
return ndarray._from_tensor_and_base(zeros, None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not simply return asarray(zeros)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point we'll need to rationalize these two forms, agree.
Basically, asarray
is anything array-like in, array out; here we explicitly construct the tensor, so my fingers naturally typed this line. The line above, with asarray(self._tensor.imag)
, should be changed to follow line 94.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, asarray(Tensor)
has the same semantics as _from_tensor_and_base(Tensor, None)
, so we can decide to always prefer the first one over the latter one for conciseness and consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not always
In [2]: a = np.zeros(3)
In [3]: np.asarray(a) is a
Out[3]: True
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that I suggested doing so when using torch.Tensor
s.
In numpy it's, AFAIU, a python side of the pointer chain for ownership of the array data:
So if |
Review comments addressed in 2b95ac2 |
About #16 (comment), sure, but this tracking also happens in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should discuss asarray
vs _from_tensor_and_base
(probably remove the latter one) and potentially removing the base
attribute from the wrapper. Now, we don't need to block this PR on that.
Thanks for the review Mario! |
Make minimal modifications to dtype/scalar type machinery to get scalar math tests run. Lots of xfails/test skips for now, but I think this is more or less it for dtypes. This PR is against the gh-12 branch, these two PRs are a single "stack", as it were.
Next up is ufuncs, esp those which are also ndarray methods.