Revision: 4323
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4323&view=rev
Author:   mdboom
Date:     2007-11-15 13:12:54 -0800 (Thu, 15 Nov 2007)

Log Message:
-----------
Don't create masked arrays unless we absolutely have to.

Modified Paths:
--------------
    branches/transforms/lib/matplotlib/scale.py

Modified: branches/transforms/lib/matplotlib/scale.py
===================================================================
--- branches/transforms/lib/matplotlib/scale.py 2007-11-15 21:06:14 UTC (rev 
4322)
+++ branches/transforms/lib/matplotlib/scale.py 2007-11-15 21:12:54 UTC (rev 
4323)
@@ -1,5 +1,6 @@
 import numpy as npy
 from matplotlib.numerix import npyma as ma
+MaskedArray = ma.MaskedArray
 
 from ticker import NullFormatter, ScalarFormatter, LogFormatterMathtext
 from ticker import NullLocator, LogLocator, AutoLocator
@@ -26,17 +27,26 @@
     
     def get_transform(self):
         return IdentityTransform()
-        
+
+def _mask_non_positives(a):
+    mask = a <= 0.0
+    if mask.any():
+        return ma.MaskedArray(a, mask=mask)
+    return a
+    
 class LogScale(ScaleBase):
     name = 'log'
-    
+
     class Log10Transform(Transform):
         input_dims = 1
         output_dims = 1
         is_separable = True
             
         def transform(self, a):
-            return ma.log10(ma.masked_where(a <= 0.0, a * 10.0))
+            a = _mask_non_positives(a * 10.0)
+            if isinstance(a, MaskedArray):
+                return ma.log10(a)
+            return npy.log10(a)
             
         def inverted(self):
             return LogScale.InvertedLog10Transform()
@@ -58,7 +68,10 @@
         is_separable = True
             
         def transform(self, a):
-            return ma.log2(ma.masked_where(a <= 0.0, a * 2.0))
+            a = _mask_non_positives(a * 2.0)
+            if isinstance(a, MaskedArray):
+                return ma.log2(a)
+            return npy.log2(a)
             
         def inverted(self):
             return LogScale.InvertedLog2Transform()
@@ -80,7 +93,10 @@
         is_separable = True
         
         def transform(self, a):
-            return ma.log(ma.masked_where(a <= 0.0, a * npy.e))
+            a = _mask_non_positives(a * npy.e)
+            if isinstance(a, MaskedArray):
+                return ma.log(a)
+            return npy.log(a)
             
         def inverted(self):
             return LogScale.InvertedNaturalLogTransform()
@@ -106,7 +122,10 @@
             self._base = base
             
         def transform(self, a):
-            return ma.log(ma.masked_where(a <= 0.0, a * self._base)) / 
npy.log(self._base)
+            a = _mask_non_positives(a * self._base)
+            if isinstance(a, MaskedArray):
+                return ma.log10(a) / npy.log(self._base)
+            return npy.log(a) / npy.log(self._base)
             
         def inverted(self):
             return LogScale.InvertedLogTransform(self._base)


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to