[yt-svn] commit/yt: ngoldbaum: Merged in ngoldbaum/yt (pull request #2484)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Jan 10 07:02:28 PST 2017


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/175a73a08723/
Changeset:   175a73a08723
Branch:      yt
User:        ngoldbaum
Date:        2017-01-10 15:02:01+00:00
Summary:     Merged in ngoldbaum/yt (pull request #2484)

Improvements for numpy unit wrappers
Affected #:  3 files

diff -r ed2b7fa425ca7aeaf6f4b9174e2787b342ad2ce5 -r 175a73a087238b633f6cc92f7f28d94878cd3217 doc/source/reference/api/api.rst
--- a/doc/source/reference/api/api.rst
+++ b/doc/source/reference/api/api.rst
@@ -160,6 +160,13 @@
    ~yt.units.unit_registry.UnitRegistry
    ~yt.units.yt_array.YTArray
    ~yt.units.yt_array.YTQuantity
+   ~yt.units.yt_array.uconcatenate
+   ~yt.units.yt_array.uintersect1d
+   ~yt.units.yt_array.uunion1d
+   ~yt.units.yt_array.unorm
+   ~yt.units.yt_array.udot
+   ~yt.units.yt_array.uvstack
+   ~yt.units.yt_array.uhstack
 
 Frontends
 ---------

diff -r ed2b7fa425ca7aeaf6f4b9174e2787b342ad2ce5 -r 175a73a087238b633f6cc92f7f28d94878cd3217 yt/__init__.py
--- a/yt/__init__.py
+++ b/yt/__init__.py
@@ -104,8 +104,13 @@
     YTArray, \
     YTQuantity, \
     uconcatenate, \
+    ucross, \
     uintersect1d, \
     uunion1d, \
+    unorm, \
+    udot, \
+    uvstack, \
+    uhstack, \
     loadtxt, \
     savetxt
 

diff -r ed2b7fa425ca7aeaf6f4b9174e2787b342ad2ce5 -r 175a73a087238b633f6cc92f7f28d94878cd3217 yt/units/yt_array.py
--- a/yt/units/yt_array.py
+++ b/yt/units/yt_array.py
@@ -16,6 +16,7 @@
 import copy
 import numpy as np
 
+from distutils.version import LooseVersion
 from functools import wraps
 from numpy import \
     add, subtract, multiply, divide, logaddexp, logaddexp2, true_divide, \
@@ -1390,17 +1391,16 @@
     v = validate_numpy_wrapper_units(v, arrs)
     return v
 
-def ucross(arr1,arr2, registry=None):
+def ucross(arr1, arr2, registry=None, axisa=-1, axisb=-1, axisc=-1, axis=None):
     """Applies the cross product to two YT arrays.
 
     This wrapper around numpy.cross preserves units.
     See the documentation of numpy.cross for full
     details.
     """
-
-    v = np.cross(arr1,arr2)
+    v = np.cross(arr1, arr2, axisa=axisa, axisb=axisb, axisc=axisc, axis=axis)
     units = arr1.units * arr2.units
-    arr = YTArray(v,units, registry=registry)
+    arr = YTArray(v, units, registry=registry)
     return arr
 
 def uintersect1d(arr1, arr2, assume_unique=False):
@@ -1441,12 +1441,34 @@
     v = validate_numpy_wrapper_units(v, [arr1, arr2])
     return v
 
-def unorm(data):
+def unorm(data, ord=None, axis=None, keepdims=False):
     """Matrix or vector norm that preserves units
 
-    This is a wrapper around np.linalg.norm that preserves units.
+    This is a wrapper around np.linalg.norm that preserves units. See
+    the documentation for that function for descriptions of the keyword
+    arguments.
+
+    The keepdims argument is ignored if the version of numpy installed is
+    older than numpy 1.10.0.
     """
-    return YTArray(np.linalg.norm(data), data.units)
+    if LooseVersion(np.__version__) < LooseVersion('1.10.0'):
+        norm = np.linalg.norm(data, ord=ord, axis=axis)
+    else:
+        norm = np.linalg.norm(data, ord=ord, axis=axis, keepdims=keepdims)
+    if norm.shape == ():
+        return YTQuantity(norm, data.units)
+    return YTArray(norm, data.units)
+
+def udot(op1, op2):
+    """Matrix or vector dot product that preservs units
+
+    This is a wrapper around np.dot that preserves units.
+    """
+    dot = np.dot(op1.d, op2.d)
+    units = op1.units*op2.units
+    if dot.shape == ():
+        return YTQuantity(dot, units)
+    return YTArray(dot, units)
 
 def uvstack(arrs):
     """Stack arrays in sequence vertically (row wise) while preserving units

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