Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions filter_functions/pulse_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,17 @@ class PulseSequence:
Due to the heavy use of NumPy's :func:`~numpy.einsum` function,
results have a floating point error of ~1e-13.
"""
__array_interface__ = {
'shape': (),
'typestr': '|O',
'version': 3
}
"""Describes to NumPy how to convert this object into an array.

Since :class:`PulseSequence` is iterable (through
:meth:`__getitem__`), NumPy would otherwise try to create an
ndarray of single-segment :class:`PulseSequence` s.
"""

def __init__(self, *args, **kwargs) -> None:
"""Initialize a PulseSequence instance."""
Expand Down
8 changes: 8 additions & 0 deletions tests/test_sequencing.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ def test_slicing(self):
with self.assertRaises(IndexError):
pulse['a']

def test_array(self):
"""Test array of PulseSequences."""
pulses = list(testutil.rand_pulse_sequence(2, 24)[::3])
array = np.array(pulses)

self.assertIs(array.dtype, np.dtype('O'))
self.assertEqual(array.shape, (8,))

def test_concatenate_without_filter_function(self):
"""Concatenate two Spin Echos without filter functions."""
tau = 10
Expand Down