so_magic.utils.linear_mapping module

This module exposes the MapOnLinearSpace class and the ‘universal_constructor’ method to create instances of it. Instances of MapOnLinearSpace can be used to project a number from one linear space to another.

class so_magic.utils.linear_mapping.LinearScale(lower_bound: int, upper_bound: int)[source]

Bases: object

A numerical linear scale (range between 2 numbers) where numbers fall in between.

Raises

ValueError – in case the lower bound is not smaller than the upper

Parameters
  • lower_bound (int) – the minimum value a number can take on the scale

  • upper_bound (int) – the maximum value a number can take on the scale

classmethod create(two_element_list_like)[source]
class so_magic.utils.linear_mapping.MapOnLinearSpace(from_scale: so_magic.utils.linear_mapping.LinearScale, target_scale: so_magic.utils.linear_mapping.LinearScale, reverse: bool = False)[source]

Bases: object

Projection of a number from one linear scale to another.

Instances of this class can transform an input number and map it from an initial scale to a target scale.

Parameters
  • _from_scale (LinearScale) – the scale where the number is initially mapped

  • _target_scale (LinearScale) – the (target) scale where the number should be finally transformed/mapped to

  • _reverse (bool) – whether the target scale is inverted or not

property from_scale
property reverse
property target_scale
transform(number)[source]

Transform the input number to a different linear scale.

classmethod universal_constructor(from_scale, target_scale, reverse=False)[source]