pitchtypes.spelled_array.SpelledIntervalClassArray

class pitchtypes.spelled_array.SpelledIntervalClassArray(fifths)

Bases: SpelledArray, AbstractSpelledArrayInterval, Interval, Diatonic, Chromatic

Represents an array of spelled interval classes, i.e. intervals without octave information.

__init__(fifths)

Takes a numpy array of fifths as integers.

Parameters:

fifths – the internal fifths of each interval class (numpy array of integers)

Methods

__init__(fifths)

Takes a numpy array of fifths as integers.

abs()

For downward intervals, return their upward counterpart, otherwise just return the interval itself.

alteration()

Return the number of semitones by which the interval is altered from its the perfect or major variant.

array_equal(other)

Returns True if self and other are the equal, False otherwise.

chromatic_semitone(shape)

Returns an array of the given shape filled with chromatic semitones (a1).

compare(other)

Element-wise comparison between two spelled arrays.

copy()

Returns a shallow copy of the array.

deepcopy()

Returns a deep copy of the array.

degree()

Return the "relative scale degree" (0-6) to which the interval points (unison=0, 2nd=1, octave=0, 2nd down=6, etc.).

diatonic_steps()

Return the diatonic steps of the interval (unison=0, 2nd=1, ..., octave=7, ...).

direction()

Returns the (element-wise) directions of the intervals.

embed()

For interval classes, return an embedding into the interval space in a (type-dependent) default octave.

fifths()

Return the position of the interval on the line of fifths.

from_array(intervals)

Create an interval class array from an array of interval classes.

from_onehot(onehot, fifth_low)

Create a spelled interval-class array from a one-hot tensor.

from_strings(strings)

Create an interval-class array from an array of strings.

generic()

Return the generic interval, i.e. the number of diatonic steps modulo octave.

ic()

Return the interval class that corresponds to this interval.

internal_octaves()

Return the internal octave representation of a pitch, which is dependent on the fifths.

is_step()

Return True if the interval is considered a step, False otherwise.

name()

Returns the names of the objects in the array as an array of strings of the same shape.

octave(shape)

Same as unison() since octaves are equivalent to unisons in interval-class space.

octaves()

For intervals, return the number of octaves the interval spans.

onehot(fifth_range[, dtype])

Returns a one-hot encoding of the interval classes in fifths as the innermost dimension.

parse_interval(s)

Parse a string as a spelled interval or spelled interval class.

semitones()

Return the number of semitones corresponding to the interval.

steps()

Return the number of diatonic steps corresponding to the interval.

to_class()

Alias for ic(), but also supported by pitch types.

unison(shape)

Return an array of the given shape filled with perfect unisons (P1).

__abs__()

For downward intervals, return their upward counterpart, otherwise just return the interval itself.

__add__(other)

Returns the sum of two intervals.

__contains__(item)

Returns true if the array contains the given interval/pitch.

Parameters:

item – the potential item to test

Returns:

True if the array contains item, otherwise False

__eq__(other)

Element-wise <= between two spelled arrays.

Parameters:

other – the spelled array or scalar to compare to

Returns:

a boolean array that indicates where this array is == other

__ge__(other)

Element-wise >= between two spelled arrays.

Parameters:

other – the spelled array or scalar to compare to

Returns:

a boolean array that indicates where this array is >= other

__getitem__(index)

Returns an item or a subarray of the spelled array. Supports advanced indexing as on numpy arrays.

Parameters:

index – a numpy-compatible index into the array

Returns:

a new array or a scalar value (depending on the index)

__gt__(other)

Element-wise > between two spelled arrays.

Parameters:

other – the spelled array or scalar to compare to

Returns:

a boolean array that indicates where this array is > other

__hash__ = None
__le__(other)

Element-wise <= between two spelled arrays.

Parameters:

other – the spelled array or scalar to compare to

Returns:

a boolean array that indicates where this array is <= other

__len__()

Returns the length of the array (first dimension, as in numpy).

Returns:

the length of the array (1st dimension, integer)

__lt__(other)

Element-wise < between two spelled arrays.

Parameters:

other – the spelled array or scalar to compare to

Returns:

a boolean array that indicates where this array is < other

__mul__(other)

Returns an integer multiple of the interval.

__ne__(other)

Element-wise <= between two spelled arrays.

Parameters:

other – the spelled array or scalar to compare to

Returns:

a boolean array that indicates where this array is != other

__neg__()

Returns the inversion of the interval (same size in the other direction).

__repr__()

Return repr(self).

__rmul__(other)

Returns an integer multiple of the interval.

__setitem__(index, item)

Sets the given indices to the given item(s). Supports advanced indexing as on numpy arrays.

Parameters:
  • index – a numpy-compatible index into the array

  • item – an array or a scalar to assign to the indicated sub-array

__str__()

Return str(self).

__sub__(other)

Returns the difference of two intervals.

__weakref__

list of weak references to the object (if defined)

abs()

For downward intervals, return their upward counterpart, otherwise just return the interval itself.

Returns:

the absolute interval

alteration()

Return the number of semitones by which the interval is altered from its the perfect or major variant. Positive alteration always indicates augmentation, negative alteration indicates diminution (minor or smaller) of the interval’s magnitude. For interval classes, alteration refers to the upward version of the interval (e.g. for m7/-M2 it is -1). For pitches, return the accidentals (positive=sharps, negative=flats, 0=natural).

Returns:

an array of alterations (integers)

array_equal(other)

Returns True if self and other are the equal, False otherwise.

Parameters:

other – another spelled array of the same type

Returns:

True if the two arrays are equal, False otherwise

classmethod chromatic_semitone(shape)

Returns an array of the given shape filled with chromatic semitones (a1).

Parameters:

shape – the shape of the resulting array (tuple of integers)

Returns:

a SpelledIntervalClassArray of shape shape filled with a1

compare(other)

Element-wise comparison between two spelled arrays.

Returns 0 where the elements are equal, 1 where the first element is greater, and -1 where the second element is greater.

Spelled interval classes use line-of-fifth ordering, for example P4 < P1 < P5 < M2.

This method can be indirectly used through binary comparison operators (including ==, < etc.). To test the overall equality of two spelled arrays, use array_equal

Parameters:

other – another SpelledIntervalClassArray or SpelledIntervalClass

Returns:

an array of -1 / 0 / 1 (integer)

copy()

Returns a shallow copy of the array. This also creates copies of the underlying numpy arrays.

Returns:

a copy of the array

deepcopy()

Returns a deep copy of the array.

Returns:

a deepcopy of the array

degree()

Return the “relative scale degree” (0-6) to which the interval points (unison=0, 2nd=1, octave=0, 2nd down=6, etc.). For pitches, return the integer that corresponds to the letter (C=0, D=1, …).

Returns:

an array of degrees (integers)

diatonic_steps()

Return the diatonic steps of the interval (unison=0, 2nd=1, …, octave=7, …). Respects both direction and octaves.

Returns:

an array of diatonic steps (integers)

direction()

Returns the (element-wise) directions of the intervals. The direction of each interval is determined by its shortest realization: m2/-M7 is upward (1) while M7/-m2 is downward (-1). Perfect unisons (P1) are neutral (0).

Returns:

an array of -1 / 0 / 1 (integer)

embed()

For interval classes, return an embedding into the interval space in a (type-dependent) default octave. For non-class intervals, return the interval itself.

Returns:

a non-class version of this interval

fifths()

Return the position of the interval on the line of fifths.

Returns:

an array of fifths (integers)

static from_array(intervals)

Create an interval class array from an array of interval classes.

Parameters:

intervals – an array-like of SpelledIntervalClass

Returns:

the corresponding interval-class array

static from_onehot(onehot, fifth_low)

Create a spelled interval-class array from a one-hot tensor. fifth_low denotes the lower bound of the fifth range used in the vector. The shape of the resulting array will be equivalent to the first n-1 dimensions of the input tensor.

Parameters:
  • onehot – a one-hot tensor representing the interval classes (numpy array)

  • fifth_low – the lowest fifth expressible in the one-hot tensor (integer)

Returns:

the corresponding interval-class array

static from_strings(strings)

Create an interval-class array from an array of strings.

Parameters:

strings – an array-like of interval-class notation strings

Returns:

the corresponding interval-class array

generic()

Return the generic interval, i.e. the number of diatonic steps modulo octave. Unlike degree(), the result respects the sign of the interval (unison=0, 2nd up=1, 2nd down=-1).

Returns:

an array of generic intervals (integers)

ic()

Return the interval class that corresponds to this interval. If the interval is already an interval class, it is returned itself.

Returns:

the interval’s corresponding interval class

internal_octaves()

Return the internal octave representation of a pitch, which is dependent on the fifths.

Only use this if you know what you are doing.

Returns:

an array of internal/dependent octaves (integers)

is_step()

Return True if the interval is considered a step, False otherwise.

Returns:

the stepness of the interval (boolean)

name()

Returns the names of the objects in the array as an array of strings of the same shape.

Returns:

an array of notation strings

classmethod octave(shape)

Same as unison() since octaves are equivalent to unisons in interval-class space.

Parameters:

shape – the shape of the resulting array (tuple of integers)

Returns:

a SpelledIntervalClassArray of shape shape filled with P1

octaves()

For intervals, return the number of octaves the interval spans. Negative intervals start with -1, decreasing. For pitches, return the absolute octave of the pitch.

Returns:

an array of external/independent octaves (integers)

onehot(fifth_range, dtype=<class 'int'>)

Returns a one-hot encoding of the interval classes in fifths as the innermost dimension. The range of fifths is given by fifth_range as a tuple (lower, upper). The outer shape of the output tensor is identical to the shape of the original array, so the resulting shape is original_shape + (n_fifths,).

Parameters:
  • fifth_range – the (inclusive) range of fifths (pair of integers)

  • dtype – dtype of the resulting array (default: int)

Returns:

a one-hot tensor (numpy array)

semitones()

Return the number of semitones corresponding to the interval.

steps()

Return the number of diatonic steps corresponding to the interval.

to_class()

Alias for ic(), but also supported by pitch types.

Returns:

the interval’s corresponding interval class

classmethod unison(shape)

Return an array of the given shape filled with perfect unisons (P1).

Parameters:

shape – the shape of the resulting array (tuple of integers)

Returns:

a SpelledIntervalClassArray of shape shape filled with P1