Skip to content
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

Logic error in smooth[_units] function argument parsing #628

Open
nickbattam-tessella opened this issue Mar 18, 2021 · 2 comments
Open

Logic error in smooth[_units] function argument parsing #628

nickbattam-tessella opened this issue Mar 18, 2021 · 2 comments
Assignees
Labels
bug Something isn't working Medium Priority Medium Priority Tasks

Comments

@nickbattam-tessella
Copy link
Member

nickbattam-tessella commented Mar 18, 2021

The sqw/dnd functions smooth and smooth_units call smooth_dnd.

The argument parsing logic in this function means it's impossible to call with the resolution shape function without an error being raised:

if strcmp(shape,'resolution') && ~(ndim==2 && numel(width)==3)
    error ('Smoothing option ''resolution'' only available for 2D data sets with three width parameters')
elseif ~(isa_size(width,[1,ndim],'double') || isa_size(width,[1,1],'double'))
    error ('ERROR: argument ''width'' must be a scalar or vector with length equal to the dimensions of the dataset')

The first if requires that the data is 2d with 3 width parameters (for resolution), the second if requires that width is an array of size [1, 2], or scalar for all shape functions in the 2d case.

These are mutually exclusive requirements.


update CM:22/09/2023: confirmed that this issue continues. The test test_dnd_class/test_smooth::test_smooth_resolution_shape_arg fails due to this issue and is currently skipped. PR #1291 has been made to fix the need to replace the d2d call with a read_dnd call. With this fix the call to smooth_dnd_ (via d2d.smooth) fails as described above.
smooth_dnd_ is a private function of @DnDBase and contains the above code for if strcmp(shape,'resolution') . As described above, it is called from smooth and other places. Note that the method declaration for smooth_dnd in SQWDnDBase.m (without the underscore) is not defined; only the private method with the underscore has an implementation.
For the elseif branch of the error detection above, this error is deliberately set off at L.126 of test_smooth.m in an AssertExceptionThrown. Otherwise the other tests in test_smooth, mostly hats with one gaussian, do not have either of these errors.
The failure caused by the problem described above occurs with shape=='resolution'. ndim==2 (it is a d2d) and numel(width)==3 (as is apparently required for resolution) so the first error does not occur. But as numel(width) is neither ==2 or ==1 the second error does. The problem described above is real.
My suspicion is that the second error should also be triggered if ~strcmp('resolution') (obviously there are better ways of packaging the if structure). At this point an expert on smooth and its arguments should have a look; I have assigned Toby and Alex and will @ them below.

@nickbattam-tessella nickbattam-tessella added the bug Something isn't working label Mar 18, 2021
@oerc0122 oerc0122 added the MVP label Jun 20, 2023
@cmarooney-stfc cmarooney-stfc mentioned this issue Sep 17, 2023
10 tasks
@cmarooney-stfc cmarooney-stfc self-assigned this Sep 19, 2023
@cmarooney-stfc
Copy link
Collaborator

@cmarooney-stfc check if this code is still present

@cmarooney-stfc
Copy link
Collaborator

@abuts @tgperring Toby, Alex - I was charged to see if this problem still exists - it does. I have proposed a fix above, but need a smoothing expert to verify - could you both have a look please? thanks Chris

@oerc0122 oerc0122 added the Medium Priority Medium Priority Tasks label Oct 18, 2023
@abuts abuts removed the MVP label Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Medium Priority Medium Priority Tasks
Projects
None yet
Development

No branches or pull requests

5 participants