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

Add Template class #1982

Merged
merged 34 commits into from
Nov 15, 2023
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
513a344
add basic instance and numpy behavior
h-mayorquin Sep 12, 2023
c242446
add pickability
h-mayorquin Sep 12, 2023
4ca9ec6
add json test
h-mayorquin Sep 12, 2023
107bdf9
test fancy indices
h-mayorquin Sep 12, 2023
1585f11
Merge branch 'main' into add_template_data_class
h-mayorquin Sep 13, 2023
078e605
Merge branch 'main' into add_template_data_class
h-mayorquin Sep 13, 2023
383e7d8
Merge branch 'main' into add_template_data_class
h-mayorquin Sep 20, 2023
aae0ef4
Merge branch 'main' into add_template_data_class
h-mayorquin Sep 20, 2023
d2c6ec7
alessio and samuel requests
h-mayorquin Sep 20, 2023
961d269
remove slicing
h-mayorquin Sep 20, 2023
ad4185e
Merge remote-tracking branch 'refs/remotes/me/add_template_data_class…
h-mayorquin Sep 20, 2023
9ee3a1d
passing tests
h-mayorquin Sep 20, 2023
9d7c9ac
add densification and sparsification methods
h-mayorquin Sep 20, 2023
e4e5736
Merge branch 'main' into add_template_data_class
h-mayorquin Sep 25, 2023
6e1027b
adding tests for sparsity and density
h-mayorquin Sep 25, 2023
cb8107a
Merge remote-tracking branch 'refs/remotes/me/add_template_data_class…
h-mayorquin Sep 25, 2023
d05e67d
prohibit dense templates when passing sparsity mask
h-mayorquin Sep 28, 2023
cc8a523
add docstring
h-mayorquin Sep 28, 2023
13d7e9f
Merge branch 'main' into add_template_data_class
h-mayorquin Sep 28, 2023
73e9562
alessio remark about nafter definition
h-mayorquin Sep 28, 2023
52c333b
fix mistake
h-mayorquin Sep 28, 2023
3368b0a
Merge branch 'main' into add_template_data_class
h-mayorquin Sep 28, 2023
2fb79cc
Update src/spikeinterface/core/sparsity.py
h-mayorquin Oct 24, 2023
437695c
changes
h-mayorquin Oct 24, 2023
c2727ee
Merge remote-tracking branch 'refs/remotes/me/add_template_data_class…
h-mayorquin Oct 24, 2023
600f20f
modify docstring
h-mayorquin Oct 24, 2023
8b78386
Merge branch 'main' into add_template_data_class
h-mayorquin Oct 24, 2023
a1e6eae
remove tests for get_sparse_templates
h-mayorquin Oct 24, 2023
3c38d15
Merge remote-tracking branch 'refs/remotes/me/add_template_data_class…
h-mayorquin Oct 24, 2023
aa08f1b
Update src/spikeinterface/core/template.py
h-mayorquin Oct 24, 2023
ea2a8a0
Update src/spikeinterface/core/template.py
h-mayorquin Oct 24, 2023
afc04da
Merge branch 'main' into add_template_data_class
h-mayorquin Nov 2, 2023
4f8bd73
Update src/spikeinterface/core/template.py
h-mayorquin Nov 2, 2023
e52dd28
docstring compliance
h-mayorquin Nov 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove slicing
h-mayorquin committed Sep 20, 2023
commit 961d26979cf339b8799d9f045f20f477589171c4
20 changes: 0 additions & 20 deletions src/spikeinterface/core/template.py
Original file line number Diff line number Diff line change
@@ -66,23 +66,3 @@ def from_dict(cls, data):

def to_json(self):
return json.dumps(self.to_dict())
h-mayorquin marked this conversation as resolved.
Show resolved Hide resolved

@classmethod
def from_json(cls, json_str):
return cls.from_dict(json.loads(json_str))

# Implementing the slicing/indexing behavior as numpy
def __getitem__(self, index):
return self.templates_array[index]

def __array__(self):
return self.templates_array

def __array_ufunc__(self, ufunc, method, *inputs, **kwargs) -> np.ndarray:
# Replace any Templates instances with their ndarray representation
inputs = tuple(inp.templates_array if isinstance(inp, Templates) else inp for inp in inputs)

# Apply the ufunc on the transformed inputs
result = getattr(ufunc, method)(*inputs, **kwargs)

return result
41 changes: 0 additions & 41 deletions src/spikeinterface/core/tests/test_template_class.py
Original file line number Diff line number Diff line change
@@ -51,44 +51,3 @@ def test_json_serialization(template_obj):
loaded_obj_from_json = Templates.from_json(json_str)

assert np.array_equal(obj.templates_array, loaded_obj_from_json.templates_array)


# @pytest.fixture
# def dense_templates():
# num_units = 2
# num_samples = 4
# num_channels = 3
# templates_shape = (num_units, num_samples, num_channels)
# templates_array = np.arange(num_units * num_samples * num_channels).reshape(templates_shape)

# return Templates(templates_array=templates_array)


# def test_pickle(dense_templates):
# templates = dense_templates

# # Serialize and deserialize the object
# serialized = pickle.dumps(templates)
# deserialized_templates = pickle.loads(serialized)

# assert np.array_equal(templates.templates_array, deserialized_templates.templates_array)
# assert templates.sparsity == deserialized_templates.sparsity
# assert templates.num_units == deserialized_templates.num_units
# assert templates.num_samples == deserialized_templates.num_samples
# assert templates.num_channels == deserialized_templates.num_channels


# def test_jsonification(dense_templates):
# templates = dense_templates
# # Serialize to JSON string
# serialized = templates.to_json()

# # Deserialize back to object
# deserialized = Templates.from_json(serialized)

# # Check if deserialized object matches original
# assert np.array_equal(templates.templates_array, deserialized.templates_array)
# assert templates.sparsity == deserialized.sparsity
# assert templates.num_units == deserialized.num_units
# assert templates.num_samples == deserialized.num_samples
# assert templates.num_channels == deserialized.num_channels