SF.net SVN: matplotlib:[6166] trunk/matplotlib/lib/matplotlib/units.py

This isn't quite what I was suggesting (and seems to be equivalent to the code as before). In the common case where there are no units in the data, this will still traverse the entire list.

I think replacing the whole loop with:

  converter = self.get_converter(iter(x).next())

would be even better. (Since lists of data should not be heterogeneous anyway...)

Mike

jdh2358@...189... wrote:

···

Revision: 6166
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6166&view=rev
Author: jdh2358
Date: 2008-10-07 15:13:53 +0000 (Tue, 07 Oct 2008)

Log Message:
-----------
added michaels unit detection optimization for arrays

Modified Paths:
--------------
    trunk/matplotlib/lib/matplotlib/units.py

Modified: trunk/matplotlib/lib/matplotlib/units.py

--- trunk/matplotlib/lib/matplotlib/units.py 2008-10-07 15:13:13 UTC (rev 6165)
+++ trunk/matplotlib/lib/matplotlib/units.py 2008-10-07 15:13:53 UTC (rev 6166)
@@ -135,7 +135,7 @@
              for thisx in x:
                 converter = self.get_converter( thisx )
- if converter: break
+ return converter
          #DISABLED self._cached[idx] = converter
         return converter

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 the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Hmm, I don't see how it would traverse the entire list

            for thisx in x:
                converter = self.get_converter( thisx )
                return converter

since it will return after the first element in the loop. I have no
problem with the iter approach, but am not seeing what the problem is
with this usage.

JDH

···

On Tue, Oct 7, 2008 at 11:26 AM, Michael Droettboom <mdroe@...31...> wrote:

This isn't quite what I was suggesting (and seems to be equivalent to
the code as before). In the common case where there are no units in the
data, this will still traverse the entire list.

I think replacing the whole loop with:

converter = self.get_converter(iter(x).next())

would be even better. (Since lists of data should not be heterogeneous
anyway...)

Sorry. I didn't read carefully enough. That's right -- the "if converter: break" was replaced with "return converter".

You're right. This is fine.

Mike

John Hunter wrote:

···

On Tue, Oct 7, 2008 at 11:26 AM, Michael Droettboom <mdroe@...31...> wrote:
  

This isn't quite what I was suggesting (and seems to be equivalent to
the code as before). In the common case where there are no units in the
data, this will still traverse the entire list.

I think replacing the whole loop with:

converter = self.get_converter(iter(x).next())

would be even better. (Since lists of data should not be heterogeneous
anyway...)
    
Hmm, I don't see how it would traverse the entire list

            for thisx in x:
                converter = self.get_converter( thisx )
                return converter

since it will return after the first element in the loop. I have no
problem with the iter approach, but am not seeing what the problem is
with this usage.

JDH
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA