[yt-svn] commit/yt: 5 new changesets
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Feb 3 09:16:50 PST 2016
5 new commits in yt:
https://bitbucket.org/yt_analysis/yt/commits/35ebe2bece9b/
Changeset: 35ebe2bece9b
Branch: yt
User: dHannasch
Date: 2016-01-27 20:18:41+00:00
Summary: no creating a new array in __lt__
Affected #: 2 files
diff -r 440902ffb795b23c044a09e96c3d1f2e1539273c -r 35ebe2bece9b2afeba2365229f6aa642554326bf yt/units/tests/test_ytarray.py
--- a/yt/units/tests/test_ytarray.py
+++ b/yt/units/tests/test_ytarray.py
@@ -409,6 +409,9 @@
for op, answer in zip(ops, answers):
yield operate_and_compare, a1, a3.in_units('cm'), op, answer
+
+ # Allow comparisons with dimensionless quantities.
+ yield assert_equal, a1 < 2, [True, False, False]
def test_unit_conversions():
diff -r 440902ffb795b23c044a09e96c3d1f2e1539273c -r 35ebe2bece9b2afeba2365229f6aa642554326bf yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -1048,10 +1048,18 @@
#
# @todo: outsource to a single method with an op argument.
+ # @todo: np.array() copies memory, why are we using it here?
+ def validate_and_strip_comparison_units(self, other, op_string):
+ oth = validate_comparison_units(self, other, op_string)
+ if hasattr(oth, 'units'):
+ return oth.ndarray_view()
+ return oth
+
def __lt__(self, other):
""" Test if this is less than the object on the right. """
oth = validate_comparison_units(self, other, 'less_than')
- return np.array(self).__lt__(np.array(oth))
+ return super(YTArray, self).__lt__(oth)
+ #return np.array(self).__lt__(np.array(oth))
def __le__(self, other):
""" Test if this is less than or equal to the object on the right. """
@@ -1164,7 +1172,8 @@
unit2 = 1.0
unit_operator = self._ufunc_registry[context[0]]
if unit_operator in (preserve_units, comparison_unit, arctan2_unit):
- if unit1 != unit2:
+ # Allow comparisons with dimensionless quantities.
+ if unit1 != unit2 and not unit2.is_dimensionless:
if not unit1.same_dimensions_as(unit2):
raise YTUnitOperationError(context[0], unit1, unit2)
else:
https://bitbucket.org/yt_analysis/yt/commits/fde4c7a3c90f/
Changeset: fde4c7a3c90f
Branch: yt
User: dHannasch
Date: 2016-01-28 00:20:36+00:00
Summary: yt.run_nose() OK
Affected #: 1 file
diff -r 35ebe2bece9b2afeba2365229f6aa642554326bf -r fde4c7a3c90f03b0ae1436067df32fffcc156737 yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -1057,9 +1057,8 @@
def __lt__(self, other):
""" Test if this is less than the object on the right. """
- oth = validate_comparison_units(self, other, 'less_than')
+ oth = validate_comparison_units(self, other, 'less_than') # converts if possible
return super(YTArray, self).__lt__(oth)
- #return np.array(self).__lt__(np.array(oth))
def __le__(self, other):
""" Test if this is less than or equal to the object on the right. """
https://bitbucket.org/yt_analysis/yt/commits/40d2240e7aba/
Changeset: 40d2240e7aba
Branch: yt
User: dHannasch
Date: 2016-01-28 19:25:34+00:00
Summary: allow comparisons dimensionless < YTArray, including with operators like np.less
Affected #: 2 files
diff -r fde4c7a3c90f03b0ae1436067df32fffcc156737 -r 40d2240e7aba1b6305f075ac5b0e5eef7f3aa511 yt/units/tests/test_ytarray.py
--- a/yt/units/tests/test_ytarray.py
+++ b/yt/units/tests/test_ytarray.py
@@ -382,6 +382,7 @@
a1 = YTArray([1, 2, 3], 'cm')
a2 = YTArray([2, 1, 3], 'cm')
a3 = YTArray([.02, .01, .03], 'm')
+ dimless = np.array([2,1,3])
ops = (
np.less,
@@ -411,7 +412,13 @@
yield operate_and_compare, a1, a3.in_units('cm'), op, answer
# Allow comparisons with dimensionless quantities.
+ yield operate_and_compare, a1, dimless, np.less, [True, False, False]
+ yield operate_and_compare, a3, dimless, np.less, [True, True, True]
+ yield operate_and_compare, dimless, a3, np.less, [False, False, False]
yield assert_equal, a1 < 2, [True, False, False]
+ yield assert_equal, a1 < 2, np.less(a1, 2)
+ yield assert_equal, 2 < a1, [False, False, True]
+ yield assert_equal, 2 < a1, np.less(2, a1)
def test_unit_conversions():
diff -r fde4c7a3c90f03b0ae1436067df32fffcc156737 -r 40d2240e7aba1b6305f075ac5b0e5eef7f3aa511 yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -1048,12 +1048,8 @@
#
# @todo: outsource to a single method with an op argument.
- # @todo: np.array() copies memory, why are we using it here?
- def validate_and_strip_comparison_units(self, other, op_string):
- oth = validate_comparison_units(self, other, op_string)
- if hasattr(oth, 'units'):
- return oth.ndarray_view()
- return oth
+ # I'm guessing the reason we don't do __ne__ as np.logical_not(__eq__)
+ # is because we don't want to do more operations on large arrays than necessary?
def __lt__(self, other):
""" Test if this is less than the object on the right. """
@@ -1063,7 +1059,7 @@
def __le__(self, other):
""" Test if this is less than or equal to the object on the right. """
oth = validate_comparison_units(self, other, 'less_than or equal')
- return np.array(self).__le__(np.array(oth))
+ return super(YTArray, self).__le__(oth)
def __eq__(self, other):
""" Test if this is equal to the object on the right. """
@@ -1072,7 +1068,7 @@
# self is a YTArray, so it can't be None.
return False
oth = validate_comparison_units(self, other, 'equal')
- return np.array(self).__eq__(np.array(oth))
+ return super(YTArray, self).__eq__(oth)
def __ne__(self, other):
""" Test if this is not equal to the object on the right. """
@@ -1080,19 +1076,19 @@
if other is None:
return True
oth = validate_comparison_units(self, other, 'not equal')
- return np.array(self).__ne__(np.array(oth))
+ return super(YTArray, self).__ne__(oth)
def __ge__(self, other):
""" Test if this is greater than or equal to other. """
# Check that the other is a YTArray.
oth = validate_comparison_units(self, other, 'greater than or equal')
- return np.array(self).__ge__(np.array(oth))
+ return super(YTArray, self).__ge__(oth)
def __gt__(self, other):
""" Test if this is greater than the object on the right. """
# Check that the other is a YTArray.
oth = validate_comparison_units(self, other, 'greater than')
- return np.array(self).__gt__(np.array(oth))
+ return super(YTArray, self).__gt__(oth)
#
# End comparison operators
@@ -1172,7 +1168,8 @@
unit_operator = self._ufunc_registry[context[0]]
if unit_operator in (preserve_units, comparison_unit, arctan2_unit):
# Allow comparisons with dimensionless quantities.
- if unit1 != unit2 and not unit2.is_dimensionless:
+ if (unit1 != unit2 and
+ not unit2.is_dimensionless and not unit1.is_dimensionless):
if not unit1.same_dimensions_as(unit2):
raise YTUnitOperationError(context[0], unit1, unit2)
else:
https://bitbucket.org/yt_analysis/yt/commits/f7d78689b18e/
Changeset: f7d78689b18e
Branch: yt
User: dHannasch
Date: 2016-01-29 01:40:09+00:00
Summary: tests
Affected #: 2 files
diff -r 40d2240e7aba1b6305f075ac5b0e5eef7f3aa511 -r f7d78689b18ee8db3c7a52c2533004fd8258ee36 yt/units/tests/test_ytarray.py
--- a/yt/units/tests/test_ytarray.py
+++ b/yt/units/tests/test_ytarray.py
@@ -404,6 +404,8 @@
for op, answer in zip(ops, answers):
yield operate_and_compare, a1, a2, op, answer
+ for op, answer in zip(ops, answers):
+ yield operate_and_compare, a1, dimless, op, answer
for op in ops:
yield assert_raises, YTUfuncUnitError, op, a1, a3
@@ -411,8 +413,7 @@
for op, answer in zip(ops, answers):
yield operate_and_compare, a1, a3.in_units('cm'), op, answer
- # Allow comparisons with dimensionless quantities.
- yield operate_and_compare, a1, dimless, np.less, [True, False, False]
+ # Check that comparisons with dimensionless quantities work in both directions.
yield operate_and_compare, a3, dimless, np.less, [True, True, True]
yield operate_and_compare, dimless, a3, np.less, [False, False, False]
yield assert_equal, a1 < 2, [True, False, False]
diff -r 40d2240e7aba1b6305f075ac5b0e5eef7f3aa511 -r f7d78689b18ee8db3c7a52c2533004fd8258ee36 yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -1048,8 +1048,6 @@
#
# @todo: outsource to a single method with an op argument.
- # I'm guessing the reason we don't do __ne__ as np.logical_not(__eq__)
- # is because we don't want to do more operations on large arrays than necessary?
def __lt__(self, other):
""" Test if this is less than the object on the right. """
https://bitbucket.org/yt_analysis/yt/commits/03adb8fb971d/
Changeset: 03adb8fb971d
Branch: yt
User: ngoldbaum
Date: 2016-02-03 17:16:40+00:00
Summary: Merged in dHannasch/yt_grid_traversal (pull request #1966)
Compare YTArrays without copying them
Affected #: 2 files
diff -r 323a5fd343c253c2211eb385d8f5a87a241ad7d1 -r 03adb8fb971da512e3b17bfb39ad595eb59819ec yt/units/tests/test_ytarray.py
--- a/yt/units/tests/test_ytarray.py
+++ b/yt/units/tests/test_ytarray.py
@@ -382,6 +382,7 @@
a1 = YTArray([1, 2, 3], 'cm')
a2 = YTArray([2, 1, 3], 'cm')
a3 = YTArray([.02, .01, .03], 'm')
+ dimless = np.array([2,1,3])
ops = (
np.less,
@@ -403,12 +404,22 @@
for op, answer in zip(ops, answers):
yield operate_and_compare, a1, a2, op, answer
+ for op, answer in zip(ops, answers):
+ yield operate_and_compare, a1, dimless, op, answer
for op in ops:
yield assert_raises, YTUfuncUnitError, op, a1, a3
for op, answer in zip(ops, answers):
yield operate_and_compare, a1, a3.in_units('cm'), op, answer
+
+ # Check that comparisons with dimensionless quantities work in both directions.
+ yield operate_and_compare, a3, dimless, np.less, [True, True, True]
+ yield operate_and_compare, dimless, a3, np.less, [False, False, False]
+ yield assert_equal, a1 < 2, [True, False, False]
+ yield assert_equal, a1 < 2, np.less(a1, 2)
+ yield assert_equal, 2 < a1, [False, False, True]
+ yield assert_equal, 2 < a1, np.less(2, a1)
def test_unit_conversions():
diff -r 323a5fd343c253c2211eb385d8f5a87a241ad7d1 -r 03adb8fb971da512e3b17bfb39ad595eb59819ec yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -1048,15 +1048,16 @@
#
# @todo: outsource to a single method with an op argument.
+
def __lt__(self, other):
""" Test if this is less than the object on the right. """
- oth = validate_comparison_units(self, other, 'less_than')
- return np.array(self).__lt__(np.array(oth))
+ oth = validate_comparison_units(self, other, 'less_than') # converts if possible
+ return super(YTArray, self).__lt__(oth)
def __le__(self, other):
""" Test if this is less than or equal to the object on the right. """
oth = validate_comparison_units(self, other, 'less_than or equal')
- return np.array(self).__le__(np.array(oth))
+ return super(YTArray, self).__le__(oth)
def __eq__(self, other):
""" Test if this is equal to the object on the right. """
@@ -1065,7 +1066,7 @@
# self is a YTArray, so it can't be None.
return False
oth = validate_comparison_units(self, other, 'equal')
- return np.array(self).__eq__(np.array(oth))
+ return super(YTArray, self).__eq__(oth)
def __ne__(self, other):
""" Test if this is not equal to the object on the right. """
@@ -1073,19 +1074,19 @@
if other is None:
return True
oth = validate_comparison_units(self, other, 'not equal')
- return np.array(self).__ne__(np.array(oth))
+ return super(YTArray, self).__ne__(oth)
def __ge__(self, other):
""" Test if this is greater than or equal to other. """
# Check that the other is a YTArray.
oth = validate_comparison_units(self, other, 'greater than or equal')
- return np.array(self).__ge__(np.array(oth))
+ return super(YTArray, self).__ge__(oth)
def __gt__(self, other):
""" Test if this is greater than the object on the right. """
# Check that the other is a YTArray.
oth = validate_comparison_units(self, other, 'greater than')
- return np.array(self).__gt__(np.array(oth))
+ return super(YTArray, self).__gt__(oth)
#
# End comparison operators
@@ -1164,7 +1165,9 @@
unit2 = 1.0
unit_operator = self._ufunc_registry[context[0]]
if unit_operator in (preserve_units, comparison_unit, arctan2_unit):
- if unit1 != unit2:
+ # Allow comparisons with dimensionless quantities.
+ if (unit1 != unit2 and
+ not unit2.is_dimensionless and not unit1.is_dimensionless):
if not unit1.same_dimensions_as(unit2):
raise YTUnitOperationError(context[0], unit1, unit2)
else:
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.
More information about the yt-svn
mailing list