示例#1
0
    def test__call__(self):
        """
        Tests :func:`colour.algebra.interpolation.NullInterpolator.__call__`
        method.
        """

        x = np.arange(len(POINTS_DATA_A))
        null_interpolator = NullInterpolator(x, POINTS_DATA_A)
        np.testing.assert_almost_equal(
            null_interpolator(np.array([0.75, 2.0, 3.0, 4.75])),
            np.array([np.nan, 12.46, 9.51, np.nan]))

        null_interpolator = NullInterpolator(x, POINTS_DATA_A, 0.25, 0.25)
        np.testing.assert_almost_equal(
            null_interpolator(np.array([0.75, 2.0, 3.0, 4.75])),
            np.array([12.32, 12.46, 9.51, 4.33]))
示例#2
0
    def test_default(self):
        """
        Tests :func:`colour.algebra.interpolation.NullInterpolator.\
    default` property.
        """

        x = y = np.linspace(0, 1, 10)
        null_interpolator = NullInterpolator(x, y, default=0)

        np.testing.assert_equal(null_interpolator.default, 0)
示例#3
0
    def test_relative_tolerance(self):
        """
        Tests :func:`colour.algebra.interpolation.NullInterpolator.\
    relative_tolerance` property.
        """

        x = y = np.linspace(0, 1, 10)
        null_interpolator = NullInterpolator(x, y, relative_tolerance=0.1)

        np.testing.assert_equal(null_interpolator.relative_tolerance, 0.1)
示例#4
0
    def test_y(self):
        """
        Tests :func:`colour.algebra.interpolation.NullInterpolator.y`
        property.
        """

        x = y = np.linspace(0, 1, 10)
        null_interpolator = NullInterpolator(x, y)

        np.testing.assert_equal(null_interpolator.y, y)
示例#5
0
    def test_absolute_tolerance(self):
        """
        Test :attr:`colour.algebra.interpolation.NullInterpolator.\
absolute_tolerance` property.
        """

        x = y = np.linspace(0, 1, 10)
        null_interpolator = NullInterpolator(x, y, absolute_tolerance=0.1)

        np.testing.assert_equal(null_interpolator.absolute_tolerance, 0.1)
示例#6
0
    def test_x(self):
        """
        Test :attr:`colour.algebra.interpolation.NullInterpolator.x`
        property.
        """

        x = y = np.linspace(0, 1, 10)
        null_interpolator = NullInterpolator(x, y)

        np.testing.assert_equal(null_interpolator.x, x)
示例#7
0
    def test_raise_exception___call__(self):
        """
        Tests :func:`colour.algebra.interpolation.NullInterpolator.__call__`
        method raised exception.
        """

        x = y = np.linspace(0, 1, 10)
        null_interpolator = NullInterpolator(x, y)

        self.assertRaises(ValueError, null_interpolator, -1)

        self.assertRaises(ValueError, null_interpolator, 11)
示例#8
0
    def __init__(
        self,
        interpolator: Optional[TypeInterpolator] = None,
        method: Union[Literal["Linear", "Constant"], str] = "Linear",
        left: Optional[Number] = None,
        right: Optional[Number] = None,
        dtype: Optional[Type[DTypeNumber]] = None,
    ):
        dtype = cast(Type[DTypeNumber], optional(dtype, DEFAULT_FLOAT_DTYPE))

        self._interpolator: TypeInterpolator = NullInterpolator(
            np.array([-np.inf, np.inf]), np.array([-np.inf, np.inf]))
        self.interpolator = optional(interpolator, self._interpolator)
        self._method: Union[Literal["Linear", "Constant"], str] = "Linear"
        self.method = cast(
            Union[Literal["Linear", "Constant"], str],
            optional(method, self._method),
        )
        self._right: Optional[Number] = None
        self.right = right
        self._left: Optional[Number] = None
        self.left = left

        self._dtype: Type[DTypeNumber] = dtype