<html><body>
<p>1 new commit in yt:</p>
<p><a href="https://bitbucket.org/yt_analysis/yt/commits/de4aaa4344b2/">https://bitbucket.org/yt_analysis/yt/commits/de4aaa4344b2/</a> Changeset:   de4aaa4344b2 Branch:      yt User:        jzuhone Date:        2016-05-18 18:28:56+00:00 Summary:     Merged in ngoldbaum/yt (pull request #2179)</p>
<p>[opt] performance improvement for YTArray addition Affected #:  2 files</p>
<p>diff -r d39510be50625c14c6ee0ecb2d0195ff72a76dd8 -r de4aaa4344b2ffd78d9e4411074b9b398f5e6ad4 yt/units/unit_object.py --- a/yt/units/unit_object.py +++ b/yt/units/unit_object.py @@ -366,8 +366,12 @@</p>
<pre>         """ Test unit inequality. """
         if not isinstance(u, Unit):
return True</pre>
<ul><li><p>return \</p></li>
<li><p>(self.base_value != u.base_value or self.dimensions != u.dimensions)</p></li></ul>
<p>+        if self.base_value != u.base_value: +            return True +        # use ‘is’ comparison dimensions to avoid expensive sympy operation +        if self.dimensions is u.dimensions: +            return False +        return self.dimensions != u.dimensions</p>
<pre>def copy(self):
    return copy.deepcopy(self)</pre>
<p>@@ -389,6 +393,9 @@</p>
<pre>def same_dimensions_as(self, other_unit):
    """ Test if dimensions are the same. """</pre>
<p>+        # test first for ‘is’ equality to avoid expensive sympy operation +        if self.dimensions is other_unit.dimensions: +            return True</p>
<pre>        return (self.dimensions / other_unit.dimensions) == sympy_one

    @property</pre>
<p>diff -r d39510be50625c14c6ee0ecb2d0195ff72a76dd8 -r de4aaa4344b2ffd78d9e4411074b9b398f5e6ad4 yt/units/yt_array.py --- a/yt/units/yt_array.py +++ b/yt/units/yt_array.py @@ -174,6 +174,31 @@</p>
<pre>    return other
</pre>
<p>+@lru_cache(maxsize=128, typed=False) +def _unit_repr_check_same(my_units, other_units): +    """ +    Takes a Unit object, or string of known unit symbol, and check that it +    is compatible with this quantity. Returns Unit object. + +    """ +    # let Unit() handle units arg if it's not already a Unit obj. +    if not isinstance(other_units, Unit): +        other_units = Unit(other_units, registry=my_units.registry) + +    equiv_dims = em_dimensions.get(my_units.dimensions, None) +    if equiv_dims == other_units.dimensions: +        if current_mks in equiv_dims.free_symbols: +            base = “SI” +        else: +            base = “CGS” +        raise YTEquivalentDimsError(my_units, other_units, base) + +    if not my_units.same_dimensions_as(other_units): +        raise YTUnitConversionError( +            my_units, my_units.dimensions, other_units, other_units.dimensions) + +    return other_units +</p>
<pre>unary_operators = (
    negative, absolute, rint, ones_like, sign, conj, exp, exp2, log, log2,
    log10, expm1, log1p, sqrt, square, reciprocal, sin, cos, tan, arcsin,</pre>
<p>@@ -430,30 +455,6 @@</p>
<pre>    # Start unit conversion methods
    #
</pre>
<ul><li><p>def _unit_repr_check_same(self, units):</p></li>
<li><p>"""</p></li>
<li><p>Takes a Unit object, or string of known unit symbol, and check that it</p></li>
<li><p>is compatible with this quantity. Returns Unit object.</p></li></ul>
<p>–</p>
<ul><li><p>"""</p></li>
<li><p># let Unit() handle units arg if it's not already a Unit obj.</p></li>
<li><p>if not isinstance(units, Unit):</p></li>
<li><p>units = Unit(units, registry=self.units.registry)</p></li></ul>
<p>–</p>
<ul><li><p>equiv_dims = em_dimensions.get(self.units.dimensions,None)</p></li>
<li><p>if equiv_dims == units.dimensions:</p></li>
<li><p>if current_mks in equiv_dims.free_symbols:</p></li>
<li><p>base = “SI”</p></li>
<li><p>else:</p></li>
<li><p>base = “CGS”</p></li>
<li><p>raise YTEquivalentDimsError(self.units, units, base)</p></li></ul>
<p>–</p>
<ul><li><p>if not self.units.same_dimensions_as(units):</p></li>
<li><p>raise YTUnitConversionError(</p></li>
<li><p>self.units, self.units.dimensions, units, units.dimensions)</p></li></ul>
<p>–</p>
<ul><li><p>return units</p></li></ul>
<p>–</p>
<pre>def convert_to_units(self, units):
    """
    Convert the array and units to the given units.</pre>
<p>@@ -464,7 +465,7 @@</p>
<pre>            The units you want to convert to.

        """</pre>
<ul><li><p>new_units = self._unit_repr_check_same(units)</p></li></ul>
<p>+        new_units = _unit_repr_check_same(self.units, units)</p>
<pre>        (conversion_factor, offset) = self.units.get_conversion_factor(new_units)

        self.units = new_units</pre>
<p>@@ -523,11 +524,10 @@</p>
<pre>        YTArray

        """</pre>
<ul><li><p>new_units = self._unit_repr_check_same(units)</p></li></ul>
<p>+        new_units = _unit_repr_check_same(self.units, units)</p>
<pre>        (conversion_factor, offset) = self.units.get_conversion_factor(new_units)
</pre>
<ul><li><p>new_array = self * conversion_factor</p></li>
<li><p>new_array.units = new_units</p></li></ul>
<p>+        new_array = type(self)(self.ndview * conversion_factor, new_units)</p>
<pre>         if offset:
np.subtract(new_array, offset*new_array.uq, new_array)</pre>
<p>Repository URL: <a href="https://bitbucket.org/yt_analysis/yt/">https://bitbucket.org/yt_analysis/yt/</a></p>
<p>—</p>
<p>This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.</p>

<img src="http://link.bitbucket.org/wf/open?upn=ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27DJ7nue7eJkGsbD-2BaTpwGHZJqQ8c2TMPwFgI63Mg6RIV9cdJTMG26FJPiDksD7x0GQtSihTqXtVbHEJ0hls8-2BUzAkhSx-2F6b9X897dpn1MH0uwfk5uRK5UNcw5AeR5KMuif9-2FDkPp5HpXkUwbIKZNvrH2A0s0eDLZCosI-2F5Y6KE6t-2Bynx1uxGtiJ65aar41T7O0-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;"/>
</body></html>