-
Notifications
You must be signed in to change notification settings - Fork 21
Use correct output dtype in event centric arithmetic #3278
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
c8d6480 to
baefdc9
Compare
| map_and_mul_detail::args<float, double, double, double>, | ||
| map_and_mul_detail::args<float, double, double, float>, | ||
| map_and_mul_detail::args<double, float, float, double>, | ||
| map_and_mul_detail::args<double, time_point, time_point, double>, | ||
| map_and_mul_detail::args<double, time_point, time_point, float>, | ||
| map_and_mul_detail::args<float, time_point, time_point, double>, | ||
| map_and_mul_detail::args<float, time_point, time_point, float>>, | ||
| map_and_mul_detail::args<float, time_point, time_point, double>>, |
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 have some combinations been removed?
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.
They dealt with type promotions which are now handled in Python.
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.
What about the inplace variants (which you did not change)?
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.
In place operations cannot change the dtype, can they?
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.
No they cannot, but how is that related to the code and my question?
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.
Which in-place variants do you actually mean? This is only used by dataset::buckets::scale which is always in-place.
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.
For example __imul__ in bins.py, right under the functions you changed in this PR.
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.
So unless there is some other check, this used to be able to multiply double weights onto float events and convert the doubles to floats. This is no longer possible with this changes.
We allow this in other operations, so I guess I should revert this change.
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.
And I actually removed the wrong one for the time_point overload.
src/scipp/core/bins.py
Outdated
| def __mul__(self, lut: lookup): | ||
| copy = self._obj.copy() | ||
| target_dtype = ( | ||
| scalar(1, dtype=self.constituents['data'].dtype) |
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 feel we should add self.dtype, similar to self.unit?
Can you check how expensive constituents is? I think it used to unzip the indices (allocating memory), but now it probably just returns 2 stride-2 variables for begin and end, i.e., is cheap?
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.
Well, self.unit is implemented in terms of constituents. So unless we implement dtype in C++, we'd still pay the cost.
But I agree that it would be nicer to have a dtype property on Bins.
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.
And yes, it does unzip the indices.
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.
I don't know what you want to say with this. But here is the implementation:
Lines 84 to 93 in 92717a5
| template <class T> py::dict bins_constituents(const Variable &var) { | |
| auto &&[indices, dim, buffer] = var.constituents<T>(); | |
| auto &&[begin, end] = unzip(indices); | |
| py::dict out; | |
| out["begin"] = std::forward<decltype(begin)>(begin); | |
| out["end"] = std::forward<decltype(end)>(end); | |
| out["dim"] = std::string(dim.name()); | |
| out["data"] = std::forward<decltype(buffer)>(buffer); | |
| return out; | |
| } |
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.
Probably unzip does this under the hood, i.e., it does not cause copies?
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.
It looks like it doesn't make a copy: (this messed up the binned variable, but hey ho)
import scipp as sc
da = sc.data.binned_x(10, 3)
print(da.bins.constituents['begin'])
da.bins.constituents['begin'][0] = 1
print(da.bins.constituents['begin'])->
<scipp.Variable> (x: 3) int64 <no unit> [0, 7, 7]
<scipp.Variable> (x: 3) int64 <no unit> [1, 7, 7]
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.
👍 ... then this is reasonably fast, i.e., usable for unit and dtype.
736d98f to
e2a26fe
Compare
e2a26fe to
f95556d
Compare

Fixes #3253