[yt-svn] commit/yt: 6 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed May 18 11:29:09 PDT 2016
6 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/aeb657a4f10e/
Changeset: aeb657a4f10e
Branch: yt
User: ngoldbaum
Date: 2016-05-17 02:01:45+00:00
Summary: [opt] performance improvement for YTArray addition
Affected #: 2 files
diff -r 06b1bf872faa352183a5f8ec91d72937b9c43523 -r aeb657a4f10e24c8565c8b2e2b6f0a46efd2c421 yt/units/unit_object.py
--- a/yt/units/unit_object.py
+++ b/yt/units/unit_object.py
@@ -389,6 +389,9 @@
def same_dimensions_as(self, other_unit):
""" Test if dimensions are the same. """
+ # test first for 'is' equality to avoid expensive sympy operation
+ if self.dimensions is other_unit.dimensions:
+ return True
return (self.dimensions / other_unit.dimensions) == sympy_one
@property
diff -r 06b1bf872faa352183a5f8ec91d72937b9c43523 -r aeb657a4f10e24c8565c8b2e2b6f0a46efd2c421 yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -526,8 +526,7 @@
new_units = self._unit_repr_check_same(units)
(conversion_factor, offset) = self.units.get_conversion_factor(new_units)
- new_array = self * conversion_factor
- new_array.units = new_units
+ new_array = type(self)(self.value * conversion_factor, new_units)
if offset:
np.subtract(new_array, offset*new_array.uq, new_array)
https://bitbucket.org/yt_analysis/yt/commits/3d078499006c/
Changeset: 3d078499006c
Branch: yt
User: ngoldbaum
Date: 2016-05-17 14:56:25+00:00
Summary: refactor so _unit_repr_check_same is not a member function
Affected #: 1 file
diff -r aeb657a4f10e24c8565c8b2e2b6f0a46efd2c421 -r 3d078499006ccfb35edf40f8af56786d22da217c yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -174,6 +174,30 @@
return other
+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
+
unary_operators = (
negative, absolute, rint, ones_like, sign, conj, exp, exp2, log, log2,
log10, expm1, log1p, sqrt, square, reciprocal, sin, cos, tan, arcsin,
@@ -430,30 +454,6 @@
# Start unit conversion methods
#
- def _unit_repr_check_same(self, 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(units, Unit):
- units = Unit(units, registry=self.units.registry)
-
- equiv_dims = em_dimensions.get(self.units.dimensions,None)
- if equiv_dims == units.dimensions:
- if current_mks in equiv_dims.free_symbols:
- base = "SI"
- else:
- base = "CGS"
- raise YTEquivalentDimsError(self.units, units, base)
-
- if not self.units.same_dimensions_as(units):
- raise YTUnitConversionError(
- self.units, self.units.dimensions, units, units.dimensions)
-
- return units
-
def convert_to_units(self, units):
"""
Convert the array and units to the given units.
@@ -464,7 +464,7 @@
The units you want to convert to.
"""
- new_units = self._unit_repr_check_same(units)
+ new_units = _unit_repr_check_same(self.units, units)
(conversion_factor, offset) = self.units.get_conversion_factor(new_units)
self.units = new_units
@@ -523,7 +523,7 @@
YTArray
"""
- new_units = self._unit_repr_check_same(units)
+ new_units = _unit_repr_check_same(self.units, units)
(conversion_factor, offset) = self.units.get_conversion_factor(new_units)
new_array = type(self)(self.value * conversion_factor, new_units)
https://bitbucket.org/yt_analysis/yt/commits/2764e1874862/
Changeset: 2764e1874862
Branch: yt
User: ngoldbaum
Date: 2016-05-17 14:57:23+00:00
Summary: decorate _unit_repr_check_same with an LRU cache
Affected #: 1 file
diff -r 3d078499006ccfb35edf40f8af56786d22da217c -r 2764e1874862750e6d72e6a865bbe02b621ea02e yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -174,6 +174,7 @@
return other
+ at 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
https://bitbucket.org/yt_analysis/yt/commits/6956889c0a1e/
Changeset: 6956889c0a1e
Branch: yt
User: ngoldbaum
Date: 2016-05-17 15:17:29+00:00
Summary: optimize Unit.__ne__ to sometimes avoid sympy comparisons
Affected #: 1 file
diff -r 2764e1874862750e6d72e6a865bbe02b621ea02e -r 6956889c0a1eea6a95bffa4f13ca9d7ec80c334f yt/units/unit_object.py
--- a/yt/units/unit_object.py
+++ b/yt/units/unit_object.py
@@ -366,8 +366,12 @@
""" Test unit inequality. """
if not isinstance(u, Unit):
return True
- return \
- (self.base_value != u.base_value or self.dimensions != u.dimensions)
+ 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
def copy(self):
return copy.deepcopy(self)
https://bitbucket.org/yt_analysis/yt/commits/fa1066ce57a8/
Changeset: fa1066ce57a8
Branch: yt
User: ngoldbaum
Date: 2016-05-17 23:45:10+00:00
Summary: use a view to avoid copying in addition
Affected #: 1 file
diff -r 6956889c0a1eea6a95bffa4f13ca9d7ec80c334f -r fa1066ce57a878a16810149c9edbd98e4f8e8e96 yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -527,7 +527,7 @@
new_units = _unit_repr_check_same(self.units, units)
(conversion_factor, offset) = self.units.get_conversion_factor(new_units)
- new_array = type(self)(self.value * conversion_factor, new_units)
+ new_array = type(self)(self.ndview * conversion_factor, new_units)
if offset:
np.subtract(new_array, offset*new_array.uq, new_array)
https://bitbucket.org/yt_analysis/yt/commits/de4aaa4344b2/
Changeset: de4aaa4344b2
Branch: yt
User: jzuhone
Date: 2016-05-18 18:28:56+00:00
Summary: Merged in ngoldbaum/yt (pull request #2179)
[opt] performance improvement for YTArray addition
Affected #: 2 files
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 @@
""" Test unit inequality. """
if not isinstance(u, Unit):
return True
- return \
- (self.base_value != u.base_value or self.dimensions != u.dimensions)
+ 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
def copy(self):
return copy.deepcopy(self)
@@ -389,6 +393,9 @@
def same_dimensions_as(self, other_unit):
""" Test if dimensions are the same. """
+ # test first for 'is' equality to avoid expensive sympy operation
+ if self.dimensions is other_unit.dimensions:
+ return True
return (self.dimensions / other_unit.dimensions) == sympy_one
@property
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 @@
return other
+ at 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
+
unary_operators = (
negative, absolute, rint, ones_like, sign, conj, exp, exp2, log, log2,
log10, expm1, log1p, sqrt, square, reciprocal, sin, cos, tan, arcsin,
@@ -430,30 +455,6 @@
# Start unit conversion methods
#
- def _unit_repr_check_same(self, 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(units, Unit):
- units = Unit(units, registry=self.units.registry)
-
- equiv_dims = em_dimensions.get(self.units.dimensions,None)
- if equiv_dims == units.dimensions:
- if current_mks in equiv_dims.free_symbols:
- base = "SI"
- else:
- base = "CGS"
- raise YTEquivalentDimsError(self.units, units, base)
-
- if not self.units.same_dimensions_as(units):
- raise YTUnitConversionError(
- self.units, self.units.dimensions, units, units.dimensions)
-
- return units
-
def convert_to_units(self, units):
"""
Convert the array and units to the given units.
@@ -464,7 +465,7 @@
The units you want to convert to.
"""
- new_units = self._unit_repr_check_same(units)
+ new_units = _unit_repr_check_same(self.units, units)
(conversion_factor, offset) = self.units.get_conversion_factor(new_units)
self.units = new_units
@@ -523,11 +524,10 @@
YTArray
"""
- new_units = self._unit_repr_check_same(units)
+ new_units = _unit_repr_check_same(self.units, units)
(conversion_factor, offset) = self.units.get_conversion_factor(new_units)
- new_array = self * conversion_factor
- new_array.units = new_units
+ new_array = type(self)(self.ndview * conversion_factor, new_units)
if offset:
np.subtract(new_array, offset*new_array.uq, new_array)
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-svn-spacepope.org/attachments/20160518/8ec05eda/attachment.html>
More information about the yt-svn
mailing list