# Path: sksurv/functions.py
# class StepFunction:
#     """Callable step function.
# 
#     .. math::
# 
#         f(z) = a * y_i + b,
#         x_i \\leq z < x_{i + 1}
# 
#     Parameters
#     ----------
#     x : ndarray, shape = (n_points,)
#         Values on the x axis in ascending order.
# 
#     y : ndarray, shape = (n_points,)
#         Corresponding values on the y axis.
# 
#     a : float, optional, default: 1.0
#         Constant to multiply by.
# 
#     b : float, optional, default: 0.0
#         Constant offset term.
#     """
#     def __init__(self, x, y, a=1., b=0.):
#         check_consistent_length(x, y)
#         self.x = x
#         self.y = y
#         self.a = a
#         self.b = b
# 
#     def __call__(self, x):
#         """Evaluate step function.
# 
#         Parameters
#         ----------
#         x : float|array-like, shape=(n_values,)
#             Values to evaluate step function at.
# 
#         Returns
#         -------
#         y : float|array-like, shape=(n_values,)
#             Values of step function at `x`.
#         """
#         x = numpy.atleast_1d(x)
#         if not numpy.isfinite(x).all():
#             raise ValueError("x must be finite")
#         if numpy.min(x) < self.x[0] or numpy.max(x) > self.x[-1]:
#             raise ValueError(
#                 "x must be within [%f; %f]" % (self.x[0], self.x[-1]))
#         i = numpy.searchsorted(self.x, x, side='left')
#         not_exact = self.x[i] != x
#         i[not_exact] -= 1
#         value = self.a * self.y[i] + self.b
#         if value.shape[0] == 1:
#             return value[0]
#         return value
# 
#     def __repr__(self):
#         return "StepFunction(x=%r, y=%r, a=%r, b=%r)" % (self.x, self.y, self.a, self.b)


import numpy
import pytest
from numpy.testing import assert_array_equal
from sksurv.functions import StepFunction



@pytest.fixture()
def a_step_function():
    x = numpy.array([0, 1, 1.2, 1.75, 2, 2.1, 3, 3.94, 5.4, 9])
    y = numpy.array([11, 9, 9.12, 7.5, 7.25, 5.14, 3, 2.94, 2.4, 1.9])

# Path: sksurv/functions.py
# class StepFunction:
#     """Callable step function.
# 
#     .. math::
# 
#         f(z) = a * y_i + b,
#         x_i \\leq z < x_{i + 1}
# 
#     Parameters
#     ----------
#     x : ndarray, shape = (n_points,)
#         Values on the x axis in ascending order.
# 
#     y : ndarray, shape = (n_points,)
#         Corresponding values on the y axis.
# 
#     a : float, optional, default: 1.0
#         Constant to multiply by.
# 
#     b : float, optional, default: 0.0
#         Constant offset term.
#     """
#     def __init__(self, x, y, a=1., b=0.):
#         check_consistent_length(x, y)
#         self.x = x
#         self.y = y
#         self.a = a
#         self.b = b
# 
#     def __call__(self, x):
#         """Evaluate step function.
# 
#         Parameters
#         ----------
#         x : float|array-like, shape=(n_values,)
#             Values to evaluate step function at.
# 
#         Returns
#         -------
#         y : float|array-like, shape=(n_values,)
#             Values of step function at `x`.
#         """
#         x = numpy.atleast_1d(x)
#         if not numpy.isfinite(x).all():
#             raise ValueError("x must be finite")
#         if numpy.min(x) < self.x[0] or numpy.max(x) > self.x[-1]:
#             raise ValueError(
#                 "x must be within [%f; %f]" % (self.x[0], self.x[-1]))
#         i = numpy.searchsorted(self.x, x, side='left')
#         not_exact = self.x[i] != x
#         i[not_exact] -= 1
#         value = self.a * self.y[i] + self.b
#         if value.shape[0] == 1:
#             return value[0]
#         return value
# 
#     def __repr__(self):
#         return "StepFunction(x=%r, y=%r, a=%r, b=%r)" % (self.x, self.y, self.a, self.b)


# Path: tests/test_functions.py
import numpy
import pytest
from numpy.testing import assert_array_equal
from sksurv.functions import StepFunction




@pytest.fixture()
def a_step_function():
    x = numpy.array([0, 1, 1.2, 1.75, 2, 2.1, 3, 3.94, 5.4, 9])
    y = numpy.array([11, 9, 9.12, 7.5, 7.25, 5.14, 3, 2.94, 2.4, 1.9])

    f = StepFunction(x, y)