Repository navigation
dialects: (builtin) add get_{int/float}_values - #4367
Conversation
| def get_int_values(self) -> Sequence[int]: | ||
| """ | ||
| Return all the values of the elements in this DenseIntOrFPElementsAttr, | ||
| checking that the elements are integers. | ||
| """ | ||
| el_type = self.get_element_type() | ||
| assert isinstance(el_type, IntegerType | IndexType) | ||
| return el_type.unpack(self.data.data, len(self)) | ||
|
|
||
| def get_float_values(self) -> Sequence[float]: | ||
| """ | ||
| Return all the values of the elements in this DenseIntOrFPElementsAttr, | ||
| checking that the elements are floats. | ||
| """ | ||
| el_type = self.get_element_type() | ||
| assert isinstance(el_type, AnyFloat) | ||
| return el_type.unpack(self.data.data, len(self)) | ||
|
|
There was a problem hiding this comment.
A counter-proposal:
| def get_int_values(self) -> Sequence[int]: | |
| """ | |
| Return all the values of the elements in this DenseIntOrFPElementsAttr, | |
| checking that the elements are integers. | |
| """ | |
| el_type = self.get_element_type() | |
| assert isinstance(el_type, IntegerType | IndexType) | |
| return el_type.unpack(self.data.data, len(self)) | |
| def get_float_values(self) -> Sequence[float]: | |
| """ | |
| Return all the values of the elements in this DenseIntOrFPElementsAttr, | |
| checking that the elements are floats. | |
| """ | |
| el_type = self.get_element_type() | |
| assert isinstance(el_type, AnyFloat) | |
| return el_type.unpack(self.data.data, len(self)) | |
| @overload | |
| def get_values(self: DenseIntOrFPElementsAttr[IntegerType | IndexType]) -> Sequence[int]: | |
| ... | |
| @overload | |
| def get_values(self: DenseIntOrFPElementsAttr[AnyFloat]) -> Sequence[float]: | |
| ... |
There was a problem hiding this comment.
I'm pretty sure I tried this and it gets weird with microsoft/pyright#10232
There was a problem hiding this comment.
I agree that this is the ideal
There was a problem hiding this comment.
I have wrestled with Pyright and declare myself defeated.
There was a problem hiding this comment.
What I'm really confused by is why it works for ComplexType
| el_type = self.get_element_type() | ||
| assert isinstance(el_type, IntegerType | IndexType), el_type | ||
| return el_type.unpack(self.data.data, len(self)) |
There was a problem hiding this comment.
WDYT? It's unlikely that the function is enough of an overhead, and it keeps the number of implementations low.
| el_type = self.get_element_type() | |
| assert isinstance(el_type, IntegerType | IndexType), el_type | |
| return el_type.unpack(self.data.data, len(self)) | |
| assert isinstance(self.element_type, IntegerType | IndexType), el_type | |
| return self.get_values() |
There was a problem hiding this comment.
I'm surprised your suggestion typechecks without a cast
There was a problem hiding this comment.
I am also unsure how you plan to remove the isinstance below?
There was a problem hiding this comment.
That also didn't work when I tried it locally
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4367 +/- ##
==========================================
+ Coverage 89.09% 89.12% +0.03%
==========================================
Files 334 335 +1
Lines 45423 45409 -14
Branches 5579 5583 +4
==========================================
+ Hits 40470 40473 +3
+ Misses 3559 3537 -22
- Partials 1394 1399 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Hoping that this will make @erick-xanadu 's life easier for adding complex values. In any case these avoid a few casts. They can be eventually replaced with overloads of `get_values` if microsoft/pyright#10232 is resolved. --------- Co-authored-by: Sasha Lopoukhine <superlopuh@gmail.com>
Would like some help with the error here, seems to me that the test has a bug in line 96
Hoping that this will make @erick-xanadu 's life easier for adding complex values. In any case these avoid a few casts. They can be eventually replaced with overloads of
get_valuesif microsoft/pyright#10232 is resolved.