You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NOTE: On second thought, this is probably not going to be needed!
Here I draft a proposal of a TimeArray, which represented a sorted list of values (using sortedcontainers) to be used in a piecewise linear pulse specification. It includes some logic for convenience, to be reviewed. I will continue working on this together with the actual piecewise primitive itself, and update here any changes made. Feedback welcome in the meantime.
This I considered but did not add:
Force the first value to be 0.0.
Behaviour
t = TimeArray([0.0, 1.0, 2.0])
print(t)
> TimeArray([0.0, 1.0, 2.0])
Values and lists of values can be inserted to the "middle" of the array (in place).
from sortedcontainers import SortedList
from typing import Union, Iterable
Real = Union[float | int]
Numeric = Union[complex | float | int]
class TimeArray(SortedList):
"""
An array representing time values.
"""
def __init__(self, iterable: Iterable):
super().__init__([float(i) for i in iterable])
def insert(self, item: Real | Iterable):
"""Inserts a value or list of values into the time array."""
if isinstance(item, Real):
self.add(item)
elif isinstance(item, Iterable):
for val in item:
self.add(val)
else:
raise NotImplementedError
def append(self, item: Real | Iterable):
"""Appends a value or list of values to the end of the time array."""
last_value = self[-1]
if isinstance(item, Real):
self.insert(item + last_value)
elif isinstance(item, Iterable):
self.insert([val + last_value for val in item])
else:
raise NotImplementedError
def __add__(self, other: Real | Iterable):
if isinstance(other, Real):
return super().__add__([other])
if isinstance(other, Iterable):
return super().__add__(other)
def __mul__(self, other: Real):
return TimeArray([other * val for val in self])
The text was updated successfully, but these errors were encountered:
NOTE: On second thought, this is probably not going to be needed!
Here I draft a proposal of a
TimeArray
, which represented a sorted list of values (using sortedcontainers) to be used in a piecewise linear pulse specification. It includes some logic for convenience, to be reviewed. I will continue working on this together with the actual piecewise primitive itself, and update here any changes made. Feedback welcome in the meantime.This I considered but did not add:
Behaviour
Values and lists of values can be inserted to the "middle" of the array (in place).
Values and lists of values can be "forcefully" appended, which adds the last value to the new values.
The
+
operator behaves asinsert
but without changing in place:The
*
operator multiplies all valuesSource code
The text was updated successfully, but these errors were encountered: