-
Notifications
You must be signed in to change notification settings - Fork 195
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
Deal with unsigned int to int conversion #1707
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3d8c1ae
Deal with unsigned int in 'astype'
alejoe91 d4a69e2
Merge branch 'main' of github.com:SpikeInterface/spikeinterface into …
alejoe91 cdd248f
UnsignedToSignedRecording
alejoe91 d076da0
Update docs
alejoe91 105abaa
Remove unused imoport
alejoe91 a491928
Make tests deterministic
alejoe91 0da642a
Fix function name
alejoe91 7791d51
Remove cache folder
alejoe91 fed0eaa
Point to unsigned_to_signed function in astype
alejoe91 d001dbf
Merge branch 'main' into astype-unsigned
alejoe91 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 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 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,42 @@ | ||
import pytest | ||
from pathlib import Path | ||
import shutil | ||
|
||
from spikeinterface import set_global_tmp_folder, NumpyRecording | ||
from spikeinterface.core import generate_recording | ||
|
||
from spikeinterface.preprocessing import astype | ||
|
||
import numpy as np | ||
|
||
|
||
if hasattr(pytest, "global_test_folder"): | ||
cache_folder = pytest.global_test_folder / "preprocessing" | ||
else: | ||
cache_folder = Path("cache_folder") / "preprocessing" | ||
|
||
set_global_tmp_folder(cache_folder) | ||
|
||
|
||
def test_astype(): | ||
traces = (np.random.rand(10000, 4) * 100).astype("float32") | ||
rec_float32 = NumpyRecording(traces, sampling_frequency=30000) | ||
traces_int16 = traces.astype("int16") | ||
np.testing.assert_array_equal(traces_int16, astype(rec_float32, "int16").get_traces()) | ||
traces_float64 = traces.astype("float64") | ||
np.testing.assert_array_equal(traces_float64, astype(rec_float32, "float64").get_traces()) | ||
|
||
|
||
def test_astype_unsigned(): | ||
traces = np.random.rand(10000, 4) * 100 + 500 | ||
traces_uint16 = traces.astype("uint16") | ||
rec_uint16 = NumpyRecording(traces_uint16, sampling_frequency=30000) | ||
traces_int16 = (traces.astype("int32") - 2**15).astype("int16") | ||
np.testing.assert_array_equal(traces_int16, astype(rec_uint16, "int16").get_traces()) | ||
traces_int32 = (traces.astype("int32") - 2**15).astype("int32") | ||
np.testing.assert_array_equal(traces_int32, astype(rec_uint16, "int32").get_traces()) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_astype() | ||
test_astype_unsigned() |
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.
I think these tests will work better with a user defined traces
Just write something like [1.0 ,3.0, 5.0, ...] or at least let's make them non-deterministic.
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 think it's ok to leave randomness here. It should work in any case since it's only casting the dtypes
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 think it is unlikely to create a problem here but I also don't see why the randomness is required. If it is meant to work as a test then it should be reproducible so you can debug it if it fails. But here, the failure is unlikely to come from randonmess so not a big concern ...
Anyway, not a big deal:
"A foolish consistency is the hobgoblin of little minds"
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'll set a seed ;)
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.
done