-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactor dimension #112
Merged
Merged
Refactor dimension #112
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
924ef8a
rfctr: add _Subtotals collection
scanny df5c569
rfctr: extract _Elements and _Element objects
scanny 652ff1b
rfctr: unify dimension type discovery
scanny e8557c2
rfctr: reimplement Dimension.labels()
scanny 4dab599
rfctr: reimplement Dimension.inserted_hs_indices
scanny 50546d8
fix: address PR comments
scanny 912ae55
Merge branch 'master' into refactor-dimension
scanny dd32932
Bump version and update readme
slobodan-ilic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -801,7 +801,7 @@ def univariate_ca_main_axis(self): | |
def valid_indices_with_selections(self, include_missing=False): | ||
"""Get all valid indices (including MR selections).""" | ||
return [ | ||
dim.valid_indices(include_missing) | ||
dim.element_indices(include_missing) | ||
for dim in self.all_dimensions | ||
] | ||
|
||
|
@@ -1033,7 +1033,7 @@ def _fix_shape(self, array, fix_valids=False): | |
0 if dim.is_mr_selections(self.all_dimensions) else slice(None) | ||
for dim, n in zip(self.all_dimensions, array.shape) | ||
) if not fix_valids else np.ix_(*[ | ||
dim.valid_indices(False) if n > 1 else [0] | ||
dim.element_indices(include_missing=False) if n > 1 else [0] | ||
for dim, n in zip(self.all_dimensions, array.shape) | ||
]) | ||
array = array[display_ind] | ||
|
@@ -1065,32 +1065,29 @@ def _inserted_dim_inds(self, transform_dims, axis): | |
return np.array(inserted_inds[dim_ind] if len(inserted_inds) else []) | ||
|
||
def _insertions(self, result, dimension, dimension_index): | ||
insertions = [] | ||
"""Return list of (idx, sum) pairs representing subtotals. | ||
|
||
for indices in dimension.hs_indices: | ||
ind_subtotal_elements = np.array(indices['inds']) | ||
|
||
if indices['anchor_ind'] == 'top': | ||
ind_insertion = -1 | ||
elif indices['anchor_ind'] == 'bottom': | ||
ind_insertion = result.shape[dimension_index] - 1 | ||
else: | ||
ind_insertion = indices['anchor_ind'] | ||
|
||
ind = tuple( | ||
[slice(None) for _ in range(dimension_index)] + | ||
[ind_subtotal_elements] | ||
) | ||
axis = dimension_index | ||
*idx* is the int offset at which to insert the ndarray subtotal | ||
in *sum*. | ||
""" | ||
|
||
# no indices are provided (should never get here) | ||
if len(indices['inds']) == 0: | ||
value = 0 | ||
else: | ||
value = np.sum(result[ind], axis=axis) | ||
insertions.append((ind_insertion, value)) | ||
def iter_insertions(): | ||
for anchor_idx, addend_idxs in dimension.hs_indices: | ||
insertion_idx = ( | ||
-1 if anchor_idx == 'top' else | ||
result.shape[dimension_index] - 1 if anchor_idx == 'bottom' | ||
else anchor_idx | ||
) | ||
addend_fancy_idx = tuple( | ||
[slice(None) for _ in range(dimension_index)] + | ||
[np.array(addend_idxs)] | ||
) | ||
yield ( | ||
insertion_idx, | ||
np.sum(result[addend_fancy_idx], axis=dimension_index) | ||
) | ||
|
||
return insertions | ||
return [insertion for insertion in iter_insertions()] | ||
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 extracted the body of the code into the local method |
||
|
||
def _intersperse_hs_in_std_res(self, hs_dims, res): | ||
for dim, inds in enumerate(self.inserted_hs_indices()): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 renamed
Dimension.valid_indices()
to.element_indices()
since it can be used to get both all and only valid indices. This eliminates a jarring contradiction in the naming.