Skip to content

Steps tendency - #184

Open
SBlokhuizen wants to merge 3 commits into
developfrom
feature/steps-tendency
Open

Steps tendency#184
SBlokhuizen wants to merge 3 commits into
developfrom
feature/steps-tendency

Conversation

@SBlokhuizen

@SBlokhuizen SBlokhuizen commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

Introduces a new tendency type, the steps tendency. This is basically a shorthand way to write a sequence of constant tendencies.

@SBlokhuizen
SBlokhuizen marked this pull request as ready for review August 3, 2026 09:16
@SBlokhuizen
SBlokhuizen force-pushed the feature/steps-tendency branch from 890edb1 to bba2e43 Compare August 5, 2026 11:37

@maarten-ic maarten-ic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some highlevel comments, let's agree on those first

Just like the :ref:`Constant Tendency <constant-value-types>`, the ``value`` list may contain numbers or strings:
* ``duration``, ``end``: See :ref:`Common Time Parameters <available-tendencies>`.
Either may be used to specify when the last step ends.
If both are omitted, the tendency simply stops at the last point in the ``time`` list.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit misleading, since we'll do constant extrapolation at the end of the tendency regardless right?


- {type: steps, time: [0, 2, 4], value: [1, 3, 5], end: 6}

The same tendency can equivalently be written using ``duration`` instead of ``end``:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But only because the first time value is 0?

from waveform_editor.tendencies.util import validate_time_array


class PiecewiseLinearTendency(BaseTendency):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to make a single superclass for this one and the steps tendency?

The main difference is the interpolation strategy between points. Perhaps we want a "closest" interpolation strategy in the future or "pspline" or ...

The superclass could take care of most of the logic, then the concrete subclasses just provide the interpolation and derivative logic.
See maybe: https://docs.scipy.org/doc/scipy/tutorial/interpolate/1D.html#tutorial-interpolate-interp1d-replacements

Comment on lines +4 to +20
def merge_value_types(types):
"""Determine a single value type from a collection of value types. Mixing
``int`` and ``float`` is allowed and results in ``float``, any other mix of
distinct types is not allowed.

Args:
types: An iterable of ``int``, ``float``, and/or ``str`` types.

Returns:
The merged type, or None if the types cannot be merged.
"""
types = set(types)
if types <= {int, float}:
return float if float in types else int
if len(types) == 1:
return types.pop()
return None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just follow numpy behaviour for stepwise tendencies?

>>> numpy.array([1, 2, 3])
array([1, 2, 3])
>>> numpy.array([1, 2, 3.])
array([1., 2., 3.])
>>> numpy.array([1, 2, 'x'])
array(['1', '2', 'x'], dtype='<U21')

obviously you cannot use the last one with linear interpolation, but I'd be fine casting everything to strings if you have a string value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants