-
Notifications
You must be signed in to change notification settings - Fork 133
Fix find_idx
#567
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
Fix find_idx
#567
Changes from 13 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
ee92612
Fix find_idx to allow multiple matches
jinningwang 9d3ea43
Add more test on find_idx
jinningwang 6da66ea
Update release-notes
jinningwang 1e71bf2
Minor fix
jinningwang 4d69304
Add test on GroupBase.finx_idx
jinningwang 1ae1f4e
Fix deprecateion of np.in1d
jinningwang 0443b38
[WIP] Try to fix docker error in github actions
jinningwang eb7d23f
[WIP] Undo changes to pythonapp.yml
jinningwang e099c9b
[WIP] Fix github action error, add a step to install mamba
jinningwang 71cc0e1
[WIP] Fix github action error
jinningwang 45f86d0
[WIP] Try to fix github action error, reset .yml
jinningwang 307bfae
[WIP] Try to fix github action error, use classic solver instead of l…
jinningwang f6ef1e2
[WIP] Try to fix github action error
jinningwang e5e19d4
Remove no_flatten in find_idx
jinningwang 6abf2b4
Fix tests for find_idx
jinningwang 1c489df
Typo
jinningwang bccc080
[WIP] Fix find_idx, revert changes
jinningwang 919c8a4
[WIP] Fix find_idx, add parameter allow_all=False to ModelData.find_i…
jinningwang b01fe4d
[WIP] Fix find_idx, add inner lists length check
jinningwang e1422b2
[WIP] Fix find_idx, refactor input check
jinningwang fdad124
[WIP] Fix find_idx, move input check from modeldata to utils.func
jinningwang 47e9352
[WIP] Fix find_idx
jinningwang ef34488
[WIP] Fix find_idx, minor fix
jinningwang 33c7ee9
[WIP] Fix find_idx, fix invovled tests
jinningwang 22eceeb
Restore pythonapp workflow
jinningwang 9a675f5
Update release notes
jinningwang 3adc110
Format
jinningwang 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
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
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 |
---|---|---|
|
@@ -243,31 +243,41 @@ def set(self, src: str, idx, attr, value): | |
|
||
return True | ||
|
||
def find_idx(self, keys, values, allow_none=False, default=None): | ||
def find_idx(self, keys, values, allow_none=False, default=None, | ||
no_flatten=False): | ||
|
||
""" | ||
Find indices of devices that satisfy the given `key=value` condition. | ||
|
||
This method iterates over all models in this group. | ||
""" | ||
indices_found = [] | ||
# `indices_found` contains found indices returned from all models of this group | ||
idx_mdls = [] | ||
for model in self.models.values(): | ||
indices_found.append(model.find_idx(keys, values, allow_none=True, default=default)) | ||
|
||
out = [] | ||
for idx, idx_found in enumerate(zip(*indices_found)): | ||
if not allow_none: | ||
if idx_found.count(None) == len(idx_found): | ||
missing_values = [item[idx] for item in values] | ||
raise IndexError(f'{list(keys)} = {missing_values} not found in {self.class_name}') | ||
|
||
real_idx = default | ||
for item in idx_found: | ||
if item is not None: | ||
real_idx = item | ||
break | ||
out.append(real_idx) | ||
return out | ||
idx_mdls.append(model.find_idx(keys, values, allow_none=True, default=default, | ||
no_flatten=True)) | ||
|
||
# `indices_found` contains found indices returned from all models of this group | ||
# NOTE: if the idx returned to [default] across all models, it means there is | ||
# no such idx in this group. If so, return default or raise an key error. | ||
indices_found = [] | ||
uid_missing = [] | ||
for uid, col in enumerate(zip(*idx_mdls)): | ||
if all(item == [default] for item in col): | ||
if allow_none: | ||
indices_found.append([default]) | ||
else: | ||
uid_missing.append(uid) | ||
else: | ||
col_filter = [item for item in col if item != [default]] | ||
indices_found.append(list_flatten(col_filter)) | ||
|
||
if uid_missing: | ||
miss_str = f'{keys}={[v[u] for v in values for u in uid_missing]}' | ||
raise IndexError(f'Group <{self.class_name}> does not contain device with {miss_str}') | ||
|
||
if not no_flatten: | ||
return list_flatten(indices_found) | ||
else: | ||
return indices_found | ||
|
||
def _check_src(self, src: str): | ||
""" | ||
|
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
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
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
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
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.
default=None
can be kept there to be consistent withModelData.find_idx()