def _input_check(t: Tuple[ndarray, ndarray]) -> None: direct1, direct2 = t assert len(direct1.shape) == 1 assert len(direct2.shape) == 1 assert direct1.shape == direct2.shape assertNoInfNaN(direct1) assertNoInfNaN(direct2)
def __init__(self, *, g: ndarray, H: ndarray) -> None: (n, ) = g.shape assert H.shape == (n, n) assert numpy.all(H.T == H) assertNoInfNaN(g) assertNoInfNaN(H) self.__g = g.copy() self.__H = H.copy()
def make_status( x: ndarray, angle: float, flag: Flag, delta: float, qpval: QuadEvaluator, ) -> Status: assertNoInfNaN(x) size = norm_l2(x) assert size / delta < 1.0 + 1e-6 return Status(x=x, fval=qpval(x), angle=angle, flag=flag, size=size)
def constraint_check(constraints: Tuple[ndarray, ndarray, ndarray, ndarray], *, theta: Optional[ndarray] = None) -> None: A, b, lb, ub = constraints if theta is not None: assertNoInfNaN(theta) assertNoInfNaN(A) assertNoInfNaN(b) assertNoNaN(lb) assertNoNaN(ub)
def _input_check( t: Tuple[ndarray, ndarray, ndarray, Tuple[ndarray, ndarray, ndarray, ndarray], float] ) -> None: x, g, H, _, delta = t assert len(x.shape) == 2 n, _ = x.shape assert g.shape == (n, ) assert H.shape == (n, n) assertNoInfNaN(x) assertNoInfNaN(g) assertNoInfNaN(H) assertNoInfNaN_float(delta)
def test_输入负无穷(self) -> None: ss = "出现了Inf或NaN" assert (cap_except(lambda: shortcuts.assertNoInfNaN( numpy.array([-numpy.inf]))).args[0][0] == ss) assert (cap_except(lambda: shortcuts.assertNoInfNaN( numpy.array([-math.inf]))).args[0][0] == ss)
def test_输入NaN(self) -> None: ss = "出现了Inf或NaN" assert (cap_except(lambda: shortcuts.assertNoInfNaN( numpy.array([numpy.nan]))).args[0][0] == ss) assert (cap_except(lambda: shortcuts.assertNoInfNaN( numpy.array([math.nan]))).args[0][0] == ss)
def _output_check_x(x: ndarray) -> None: assert len(x.shape) == 1 assertNoInfNaN(x)
def _output_check(output: Trust_Region_Result) -> None: assertNoInfNaN(output.x)
def __call__(self, x: ndarray) -> float: assertNoInfNaN(x) return 0.5 * float(x @ (self.__H @ x)) + float(self.__g @ x)