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
[hail] Promote localize_entries to public & tested #5247
Changes from 1 commit
887b9ec
6e38e6a
af99b15
ba8a800
0c6b63c
3867a07
045fb3e
00b833d
d31aa61
ad7c0ae
83691c1
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 |
---|---|---|
|
@@ -2533,6 +2533,63 @@ def _localize_entries(self, entries_field_name, cols_field_name) -> 'Table': | |
return Table(CastMatrixToTable( | ||
self._mir, entries_field_name, cols_field_name)) | ||
|
||
@typecheck_method(entries_array_field_name=nullable(str), | ||
columns_array_field_name=nullable(str)) | ||
def localize_entries(self, | ||
entries_array_field_name=None, | ||
columns_array_field_name=None) -> 'Table': | ||
"""Represent this matrix as a table of entry-rows. | ||
|
||
Examples | ||
-------- | ||
Build a numpy ndarray from a small :class:`.MatrixTable`: | ||
|
||
>>> mt = hl.utils.range_matrix_table(3,3) | ||
>>> mt = mt.select_entries(x = mt.row_idx * mt.col_idx) | ||
>>> mt.x.show() | ||
+---------+---------+-------+ | ||
| row_idx | col_idx | x | | ||
+---------+---------+-------+ | ||
| int32 | int32 | int32 | | ||
+---------+---------+-------+ | ||
| 0 | 2 | 0 | | ||
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. why are the col indices in reverse order? 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. doctest also flagged this. I must've had a buggy version of hail locally when I ran this. |
||
| 0 | 0 | 0 | | ||
| 0 | 1 | 0 | | ||
| 1 | 0 | 0 | | ||
| 1 | 1 | 1 | | ||
| 1 | 2 | 2 | | ||
| 2 | 2 | 4 | | ||
| 2 | 1 | 2 | | ||
| 2 | 0 | 0 | | ||
+---------+---------+-------+ | ||
>>> t = mt.localize_entries('entry_structs', 'columns') | ||
>>> t = t.select(entries = t.entry_structs.map(lambda entry: entry.x)) | ||
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. add a |
||
>>> np.array(t.entries.collect()) | ||
array([[0, 0, 0], | ||
[0, 1, 2], | ||
[0, 2, 4]]) | ||
|
||
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. add a note that filtered entries are represented as a missing struct? 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. I ditched the struct on the second to last line so this would blow up without latest numpy, I assume, b/c you can't represent a missing value in a numpy ndarray. I think this is doctested, no? 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. I mean add a "Notes" section to the docs, and describe that the array of entries always contains Ncols elements (structs), with filtered entries appearing as missing structs. 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. This is the second comment. 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. I still want a notes section with a description of the type! |
||
Parameters | ||
---------- | ||
entries_array_field_name : :obj:`str` | ||
The name of the table field containing the array of entry structs | ||
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. oh, you added it in the parameter description. Can we move the last sentence of both of these up? 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. I think I'm generally a bit allergic to the proliferation of Notes that we have in the docs. Seems like the parameters or returns section is the right place to put this information, right? |
||
for the given row | ||
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. style: periods at the end of parameter descriptions |
||
columns_array_field_name : :obj:`str` | ||
The name of the global field containing the array of column structs | ||
|
||
Returns | ||
------- | ||
:class:`.Table` | ||
""" | ||
entries = entries_array_field_name or Env.get_uid() | ||
cols = columns_array_field_name or Env.get_uid() | ||
t = self._localize_entries(self, entries, cols) | ||
if entries_array_field_name is None: | ||
t = t.drop(entries) | ||
if columns_array_field_name is None: | ||
t = t.drop_globals(cols) | ||
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. drop_globals isn't a thing. Just |
||
return t | ||
|
||
def _unfilter_entries(self): | ||
entry_ir = hl.cond(hl.is_defined(self.entry), self.entry, hl.struct(**self.entry))._ir | ||
return MatrixTable(MatrixMapEntries(self._mir, entry_ir)) | ||
|
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.
This is a very confusing sentence. How about:
"Convert the matrix table to a table with entries localized as an array of structs."