-
Notifications
You must be signed in to change notification settings - Fork 19
raise ValueError if the the number of regression points is less than the number of parameters in _residual
#249
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bc24486
raise `ValueError` if the the number of regression points is less tha…
ycexiao f537512
test: add test for not enough shared grid points the bad case.
ycexiao 9832900
chore: fix typo
ycexiao 71f10e5
chore: more concise error message
ycexiao 935dd8e
chore: fix pre-commit
ycexiao 91fa347
fix: use a custom error to stop `leatsq`
ycexiao 5b0f30b
Revert "fix: use a custom error to stop `leatsq`"
ycexiao daf51c3
chore: fix the code indentation.
ycexiao 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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| **Added:** | ||
|
|
||
| * Raise ``ValueError`` if the number of shared grid points between morphed and target functions is less than the number of parameters. | ||
|
|
||
| **Changed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Deprecated:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Removed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Fixed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Security:** | ||
|
|
||
| * <news item> |
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 |
|---|---|---|
|
|
@@ -181,6 +181,62 @@ def stretch(x, y, stretch): | |
|
|
||
| assert res < err | ||
|
|
||
| def test_refine_grid_bad(self, user_filesystem): | ||
| grid = numpy.arange(2) | ||
| func = numpy.sin(grid) | ||
| grid1, func1, grid2, func2 = grid, func, grid, func | ||
| config = { | ||
| "stretch": 0.005, | ||
| "scale": 1.0, | ||
| "smear": 0, | ||
| } | ||
| chain = MorphChain(config) | ||
| refiner = Refiner(chain, grid1, func1, grid2, func2) | ||
| refpars = ["stretch", "scale", "smear"] | ||
| expected_error_message = ( | ||
| "\nNumber of parameters (currently 3) cannot " | ||
| "exceed the number of shared grid points " | ||
| "(currently 2). " | ||
| "Please reduce the number of morphing parameters or " | ||
| "provide new morphing and target functions with more " | ||
| "shared grid points." | ||
| ) | ||
| with pytest.raises( | ||
| ValueError, | ||
| ) as error: | ||
| refiner.refine(*refpars) | ||
| actual_error_message = str(error.value) | ||
|
Collaborator
Author
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. These two lines were skipped because of the wrong indentation. It is fixed now. |
||
| assert actual_error_message == expected_error_message | ||
|
|
||
| # call from command line | ||
ycexiao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import subprocess | ||
|
|
||
| data_dir_path = user_filesystem / "cwd_dir" | ||
| morph_file = data_dir_path / "morph_data" | ||
| morph_data_text = [ | ||
| str(grid1[i]) + " " + str(func1[i]) for i in range(len(grid1)) | ||
| ] | ||
| morph_data_text = "\n".join(morph_data_text) | ||
| morph_file.write_text(morph_data_text) | ||
| target_file = data_dir_path / "target_data" | ||
| target_data_text = [ | ||
| str(grid2[i]) + " " + str(func2[i]) for i in range(len(grid2)) | ||
| ] | ||
| target_data_text = "\n".join(target_data_text) | ||
| target_file.write_text(target_data_text) | ||
| run_cmd = ["diffpy.morph"] | ||
| for key, value in config.items(): | ||
| run_cmd.append(f"--{key}") | ||
| run_cmd.append(f"{value}") | ||
| run_cmd.extend([str(morph_file), str(target_file)]) | ||
| run_cmd.append("-n") | ||
| result = subprocess.run(run_cmd, capture_output=True, text=True) | ||
| expected_error_message = ( | ||
| "diffpy.morph: error: " + expected_error_message | ||
| ) | ||
| actual_error_message = result.stderr.strip() | ||
| assert actual_error_message == expected_error_message | ||
|
|
||
|
|
||
| # End of class TestRefine | ||
|
|
||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.