From 99c78ec0b917a6ccf0ee5a9a8f7425b7f68ad45e Mon Sep 17 00:00:00 2001 From: Yuichi Motoyama Date: Mon, 25 Mar 2024 15:59:30 +0900 Subject: [PATCH] update --- src/py2dmat/util/limitation.py | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/py2dmat/util/limitation.py b/src/py2dmat/util/limitation.py index 5a1f03e4..bc352fe6 100644 --- a/src/py2dmat/util/limitation.py +++ b/src/py2dmat/util/limitation.py @@ -2,41 +2,31 @@ import numpy as np -import py2dmat - -# for type hints -from pathlib import Path -from typing import List, Optional, Dict class LimitationBase(metaclass=ABCMeta): @abstractmethod - def __init__ (self, a: np.ndarray, b: np.ndarray, is_limitary: bool): - + def __init__(self, a: np.ndarray, b: np.ndarray, is_limitary: bool): + self.islimitary = is_limitary if self.islimitary: self.a = a - self.b = b + self.minusb = -b self.n_formura = a.shape[0] self.ndim = a.shape[1] - + @abstractmethod def judge(self, x: np.ndarray) -> bool: pass + class Inequality(LimitationBase): - def __init__ (self, a: np.ndarray, b: np.ndarray, is_limitary: bool): + def __init__(self, a: np.ndarray, b: np.ndarray, is_limitary: bool): super().__init__(a, b, is_limitary) def judge(self, x: np.ndarray) -> bool: - if self.islimitary : - judge_formula = [] - for formula_index in range(self.n_formura): - value_formula = 0 - for dim_index in range(self.ndim): - value_formula += self.a[formula_index, dim_index]*x[dim_index] - value_formula += self.b[formula_index] - judge_formula.append(value_formula>0) - judge_result = all(judge_formula) + if self.islimitary: + Ax = np.einsum("ij,j->i", self.a, x) + judge_result = all(Ax > self.minusb) else: judge_result = True return judge_result