예제 #1
0
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)
예제 #2
0
 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()
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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)
예제 #6
0
 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)
예제 #7
0
 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)
예제 #8
0
def _output_check_x(x: ndarray) -> None:
    assert len(x.shape) == 1
    assertNoInfNaN(x)
예제 #9
0
def _output_check(output: Trust_Region_Result) -> None:
    assertNoInfNaN(output.x)
예제 #10
0
 def __call__(self, x: ndarray) -> float:
     assertNoInfNaN(x)
     return 0.5 * float(x @ (self.__H @ x)) + float(self.__g @ x)