From 60f232a1669856e3b061632ede2509789be1e1d8 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sat, 12 Nov 2016 07:34:25 -0500 Subject: [PATCH] Add a cached method for games that returns the spectral norm of L. --- dunshire/games.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/dunshire/games.py b/dunshire/games.py index bb808cb..a1ac0f5 100644 --- a/dunshire/games.py +++ b/dunshire/games.py @@ -322,6 +322,8 @@ class SymmetricLinearGame: if not self._e2 in K: raise ValueError('the point e2 must lie in the interior of K') + # Initial value of cached method. + self._L_specnorm_value = None def __str__(self): @@ -821,7 +823,7 @@ class SymmetricLinearGame: """ p = self.e2() / (norm(self.e2()) ** 2) dist = self.K().ball_radius(self.e1()) - nu = - specnorm(self.L())/(dist*norm(self.e2())) + nu = - self._L_specnorm()/(dist*norm(self.e2())) x = matrix([nu, p], (self.dimension() + 1, 1)) s = - self._G()*x @@ -834,7 +836,7 @@ class SymmetricLinearGame: """ q = self.e1() / (norm(self.e1()) ** 2) dist = self.K().ball_radius(self.e2()) - omega = specnorm(self.L())/(dist*norm(self.e1())) + omega = self._L_specnorm()/(dist*norm(self.e1())) y = matrix([omega]) z2 = q z1 = y*self.e2() - self.L().trans()*z2 @@ -843,6 +845,14 @@ class SymmetricLinearGame: return {'y': y, 'z': z} + def _L_specnorm(self): + """ + Compute the spectral norm of ``L`` and cache it. + """ + if self._L_specnorm_value is None: + self._L_specnorm_value = specnorm(self.L()) + return self._L_specnorm_value + def solution(self): """ Solve this linear game and return a :class:`Solution`. -- 2.44.2