Skip to content

Commit 37a0453

Browse files
authored
Merge pull request #100 from qutech/feature/array_interface
Add array interface to define how arrays of PulseSequences are created
2 parents cd800a8 + cad3f68 commit 37a0453

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

filter_functions/pulse_sequence.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,17 @@ class PulseSequence:
237237
Due to the heavy use of NumPy's :func:`~numpy.einsum` function,
238238
results have a floating point error of ~1e-13.
239239
"""
240+
__array_interface__ = {
241+
'shape': (),
242+
'typestr': '|O',
243+
'version': 3
244+
}
245+
"""Describes to NumPy how to convert this object into an array.
246+
247+
Since :class:`PulseSequence` is iterable (through
248+
:meth:`__getitem__`), NumPy would otherwise try to create an
249+
ndarray of single-segment :class:`PulseSequence` s.
250+
"""
240251

241252
def __init__(self, *args, **kwargs) -> None:
242253
"""Initialize a PulseSequence instance."""

tests/test_sequencing.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ def test_slicing(self):
100100
with self.assertRaises(IndexError):
101101
pulse['a']
102102

103+
def test_array(self):
104+
"""Test array of PulseSequences."""
105+
pulses = list(testutil.rand_pulse_sequence(2, 24)[::3])
106+
array = np.array(pulses)
107+
108+
self.assertIs(array.dtype, np.dtype('O'))
109+
self.assertEqual(array.shape, (8,))
110+
103111
def test_concatenate_without_filter_function(self):
104112
"""Concatenate two Spin Echos without filter functions."""
105113
tau = 10

0 commit comments

Comments
 (0)