-
Notifications
You must be signed in to change notification settings - Fork 57
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
(Advanced) Indexing, Slicing, Masking, Reshaping and Transposition for Random Variables and Distributions #134
Conversation
I noticed that the probnum/src/probnum/prob/randomvariable.py Lines 193 to 208 in 1ddf55a
To be consistent with the numpy API, I would propose we change this to return a new random variable with the desired shape. Any thoughts @JonathanWenger, @pnkraemer, @nathanaelbosch? |
In general we should be consistent with the numpy API, so I agree that It seems to be a bit more complicated (see also: https://stackoverflow.com/questions/46574568/does-numpy-reshape-create-a-copy). While |
I agree but since we'll call numpy's resize internally, our random variables inherit the same data buffer. Actually I'm pretty sure that a view is essentially a new array which just shares the pointer to the contiguous piece of memory of the old array. |
That's also my understanding from a quick scan of the topic. |
Should I make these changes in this PR? |
Fine with me. |
Done |
23a6835
to
58624dc
Compare
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.
Great job on the PR! I saw some things that will surely changed based on the discussion surrounding the removal of Distribution
. So just keep those in mind before you invest too much time into making improvements based on my comments.
58624dc
to
3204b2a
Compare
) | ||
|
||
def _reshape_inplace(self, newshape): | ||
raise NotImplementedError |
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.
Inplace reshaping for univariate normals is actually impossible due to the fact that the attributes of numpy's array scalars are immutable. See also https://numpy.org/doc/stable/reference/arrays.scalars.html. We should overthink #130. It would be best if scalar quantities behave exactly the same as arrays. Maybe we should use arrays of shape () internally?
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.
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.
Yes i think representing everything internally as arrays makes a lot of sense. This removes quite a few annoying conditionals in the code as well.
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.
Alright, I'll rephrase #130 then?
@JonathanWenger I resolved all your comments. The PR would be ready to merge. Any objections? |
This PR enables full numpy-style indexing for random variables and distributions (currently Normal and Dirac) as in
https://numpy.org/doc/stable/reference/arrays.indexing.html
Closes #11.