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
Fixes #587: Improved FFT Normalization Handling in Arithmetic Operations #593
base: main
Are you sure you want to change the base?
Fixes #587: Improved FFT Normalization Handling in Arithmetic Operations #593
Conversation
Hi, and thanks for the Contribution! It's a hard to see, what you changed because there are many, many files touched. Can you please revoke the changes in |
thank you for the feedback and sorry for the confusion. I downloaded the library through pip in my virtual environment then moved the files to my fork, which was obviously a bad decision. Update coming soon. |
styling and environment settings updates
f4c6ff3
to
964cd8b
Compare
Hello, I reverted to previous version in my local environment, replaced the changes and force pushed. changed everystring to use " instead of ' and added pyfar_venv to .gitignore. maybe there are still some mistakes, are you coming to Audiotechnik class tomorrow? @f-brinkmann |
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.
Thanks for the effort, I could now see what you changed. We did not discuss this issue in the dev team yet, but I think we are looking for a different kind of solution. You relaxed the rules that we apply for arithmetics to raise a warning instead of an error of the case from #587 occurs. I assume, we rather want to adapt the checks to not neither raise an error nor a warning but still raise errors if the other rules are violated.
I'm not at Audiotechnik today, but I will be in office tomorrow and on Friday. If you want you can drop by to discuss the solution. You can call before to make sure I'm not in a meeting :)
sampling_rate : number, None | ||
Sampling rate of the signals. None, if no signal is contained in `data` | ||
n_samples : number, None | ||
Number of samples of the signals. None, if no signal is contained in | ||
`data` | ||
fft_norm : str, None | ||
FFT norm of the first signal in `data`, if all FFT norms are None. | ||
Otherwise the first FFT norm that is not None is taken. | ||
times : numpy array, None | ||
The times if a TimeData object was passed. None otherwise. | ||
frequencies : numpy array, None | ||
The frequencies if a FrequencyData object was passed. None otherwise. | ||
audio_type : type, None | ||
Type of the audio class if contained in data. Otherwise None. | ||
cshape : tuple, None | ||
Largest channel shape of the audio classes if contained in data. | ||
Otherwise empty tuple. |
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 prefer the explicit documentation with a description of each return parameter.
times = None | ||
frequencies = None | ||
audio_type = type(None) | ||
cshape = () | ||
|
||
# determine operation type based on division flag | ||
operation_type = "divide" if division else "multiply" |
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.
This is a bit misleading. The reason we check for the division is that different rules apply in this case. But the operation can be addition, subtraction or multiplication. Maybe using the division
flag as before is cleaner.
Helper function to determine the fft_norm resulting from an | ||
arithmetic operation of two audio objects. | ||
|
||
For addition, subtraction and multiplication: | ||
Either: one signal has fft_norm ``'none'`` , the results gets the other | ||
norm. | ||
Or: both have the same fft_norm, the results gets the same norm. | ||
Other combinations raise an error. | ||
|
||
For division: | ||
Either: the denominator (fft_norm_2) is ``'none'``, the result gets the | ||
fft_norm of the numerator (fft_norm_1). | ||
Or: both have the same fft_norm, the results gets the fft_norm ``'none'``. | ||
Other combinations raise an error. |
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.
This actually gives more information than the new version, which might be helpfull for debugging. We should keep the old version IMO
``True`` if arithmetic operation is division. | ||
|
||
fft_norm1 : str | ||
The FFT normalization of the first signal. Must be one of 'none', |
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.
We have a convention to show input values as code in the docstrings. Thats why we for example used ``'none'``. This should be reverted.
operation : str | ||
The arithmetic operation to be performed. Supported operations are | ||
'multiply', 'divide', 'add', or 'subtract'. |
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.
See comment above, I would be in favor of keeping the division
flag and its old description.
UserWarning | ||
Warns about the use of an invalid norm, unsupported operations, | ||
mismatched norms without override, or specific concerns | ||
about operations involving 'none' normalization. |
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.
We actually want to be strict here and raise errors, not warning in case something is not as defined in our rules for arithmetics.
Which issue(s) are closed by this pull request?
Closes #587
Summary
Improvement on the _match_fft_norm function to support a wider range of arithmetic operations and introduction of a norm_override capability. Changes aim to improve the function's flexibility and its ability to handle exceptions more gracefully.
Changes proposed in this pull request:
in classes/audio.py
_assert_match_for_arithmetic
_match_fft_norm
in pyfar/dsp.py
deconvolve
convolve
in test_audio_signal_arithmetic.py
test_signal_inversion
test_assert_match_for_arithmetic
test_convolve_mode_and_method
in test_dsp.py
test_convolve_mode_error
in test_dsp deconvolve.py
test_fft_norm
test_fft_length_error
in test_match_fft_norm.py