]> gitweb.michael.orlitzky.com - dunshire.git/commitdiff
Add a cached method for games that returns the spectral norm of L.
authorMichael Orlitzky <michael@orlitzky.com>
Sat, 12 Nov 2016 12:34:25 +0000 (07:34 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Sun, 13 Nov 2016 20:19:27 +0000 (15:19 -0500)
dunshire/games.py

index bb808cb592d8e013d390e69ee1b6527fc64db583..a1ac0f54c2982cd59b25cc479293c4e3dc558e44 100644 (file)
@@ -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`.