-
Notifications
You must be signed in to change notification settings - Fork 103
Fix __getitem__ in LabelTensor
#546
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
Merged
Merged
Changes from 1 commit
Commits
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 hidden or 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 |
|---|---|---|
|
|
@@ -519,15 +519,17 @@ def _update_single_label( | |
|
|
||
| :raises: ValueError: If the index type is not supported. | ||
| """ | ||
|
|
||
| old_dof = old_labels[to_update_dim]["dof"] | ||
| old_dof = old_labels[dim]["dof"] | ||
| label_name = old_labels[dim]["name"] | ||
|
Collaborator
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 do we use old_labels and don't simply pass |
||
| # Handle slicing | ||
| if isinstance(index, slice): | ||
|
dario-coscia marked this conversation as resolved.
|
||
| to_update_labels[dim] = {"dof": old_dof[index], "name": label_name} | ||
| to_update_labels[to_update_dim] = { | ||
| "dof": old_dof[index], | ||
| "name": label_name, | ||
| } | ||
| # Handle single integer index | ||
| elif isinstance(index, int): | ||
| to_update_labels[dim] = { | ||
| to_update_labels[to_update_dim] = { | ||
| "dof": [old_dof[index]], | ||
| "name": label_name, | ||
| } | ||
|
|
@@ -536,7 +538,7 @@ def _update_single_label( | |
| # Handle list of bools | ||
| if isinstance(index, torch.Tensor) and index.dtype == torch.bool: | ||
| index = index.nonzero().squeeze() | ||
| to_update_labels[dim] = { | ||
| to_update_labels[to_update_dim] = { | ||
| "dof": ( | ||
| [old_dof[i] for i in index] | ||
| if isinstance(old_dof, list) | ||
|
|
@@ -589,10 +591,14 @@ def __getitem__(self, index): | |
|
|
||
| # Update labels based on the index | ||
| offset = 0 | ||
| removed = 0 | ||
| for dim, idx in enumerate(index): | ||
| if dim in self.stored_labels: | ||
| if dim in original_labels: | ||
| if isinstance(idx, int): | ||
| selected_tensor = selected_tensor.unsqueeze(dim) | ||
| # Compute the working dimension considering the removed | ||
| # dimensions due to int index on a non labled dimension | ||
| dim_ = dim - removed | ||
| selected_tensor = selected_tensor.unsqueeze(dim_) | ||
| if idx != slice(None): | ||
| self._update_single_label( | ||
| original_labels, updated_labels, idx, dim, offset | ||
|
|
@@ -605,6 +611,7 @@ def __getitem__(self, index): | |
| key - 1 if key > dim else key: value | ||
| for key, value in updated_labels.items() | ||
| } | ||
| removed += 1 | ||
| continue | ||
| offset += 1 | ||
|
|
||
|
|
||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.