[yt-svn] commit/yt-3.0: 8 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Jul 16 04:32:35 PDT 2013


8 new commits in yt-3.0:

https://bitbucket.org/yt_analysis/yt-3.0/commits/8be9d757c3ed/
Changeset:   8be9d757c3ed
Branch:      yt-3.0
User:        drudd
Date:        2013-07-10 20:54:30
Summary:     Added type consistency and precision promotion in TotalQuantity
Affected #:  1 file

diff -r ce576a114f133a73ea16ae6cc7c705bf444f8833 -r 8be9d757c3edcaebc0cc16a207f299682d0040d6 yt/data_objects/derived_quantities.py
--- a/yt/data_objects/derived_quantities.py
+++ b/yt/data_objects/derived_quantities.py
@@ -679,9 +679,16 @@
     totals = []
     for field in fields:
         if data[field].size < 1:
-            totals.append(0.0)
+            totals.append(np.zeros(1,dtype=data[field].dtype)[0])
             continue
-        totals.append(data[field].sum())
+        if data[field].dtype in (np.int,np.int8,np.int16,np.int32,np.int64):
+            totals.append(data[field].sum(dtype=np.int64))
+        elif data[field].dtype in (np.uint8,np.uint16,np.uint32,np.uint64):
+            totals.append(data[field].sum(dtype=np.uint64))
+        elif data[field].dtype in (np.float,np.float16,np.float32,np.float64):
+            totals.append(data[field].sum(dtype=np.float64))
+        else:
+            totals.append(data[field].sum())
     return len(fields), totals
 def _combTotalQuantity(data, n_fields, totals):
     totals = np.atleast_2d(totals)


https://bitbucket.org/yt_analysis/yt-3.0/commits/324a98f34e1c/
Changeset:   324a98f34e1c
Branch:      yt-3.0
User:        drudd
Date:        2013-07-10 21:42:19
Summary:     Updated all sums in derived_quantities to use float64, moved TotalQuantity precision to dictionary
Affected #:  1 file

diff -r 8be9d757c3edcaebc0cc16a207f299682d0040d6 -r 324a98f34e1c64b1303e007ad8d0048786f7d81a yt/data_objects/derived_quantities.py
--- a/yt/data_objects/derived_quantities.py
+++ b/yt/data_objects/derived_quantities.py
@@ -119,12 +119,15 @@
     This function takes no arguments and returns the sum of cell masses and
     particle masses in the object.
     """
-    baryon_mass = data["CellMassMsun"].sum()
     try:
-        particle_mass = data["ParticleMassMsun"].sum()
-        total_mass = baryon_mass + particle_mass
+        cell_mass = _TotalQuantity(data,["CellMassMsun"])
     except KeyError:
-        total_mass = baryon_mass
+        cell_mass = 0.0
+    try:
+        particle_mass = _TotalQuantity(data,["ParticleMassMsun"])
+    except KeyError:
+        particle_mass = 0.0
+    total_mass = cell_mass + particle_mass
     return [total_mass]
 def _combTotalMass(data, total_mass):
     return total_mass.sum()
@@ -146,15 +149,15 @@
     """
     x = y = z = den = 0
     if use_cells: 
-        x += (data["x"] * data["CellMassMsun"]).sum()
-        y += (data["y"] * data["CellMassMsun"]).sum()
-        z += (data["z"] * data["CellMassMsun"]).sum()
-        den += data["CellMassMsun"].sum()
+        x += (data["x"] * data["CellMassMsun"]).sum(dtype=np.float64)
+        y += (data["y"] * data["CellMassMsun"]).sum(dtype=np.float64)
+        z += (data["z"] * data["CellMassMsun"]).sum(dtype=np.float64)
+        den += data["CellMassMsun"].sum(dtype=np.float64)
     if use_particles:
-        x += (data["particle_position_x"] * data["ParticleMassMsun"]).sum()
-        y += (data["particle_position_y"] * data["ParticleMassMsun"]).sum()
-        z += (data["particle_position_z"] * data["ParticleMassMsun"]).sum()
-        den += data["ParticleMassMsun"].sum()
+        x += (data["particle_position_x"] * data["ParticleMassMsun"]).sum(dtype=np.float64)
+        y += (data["particle_position_y"] * data["ParticleMassMsun"]).sum(dtype=np.float64)
+        z += (data["particle_position_z"] * data["ParticleMassMsun"]).sum(dtype=np.float64)
+        den += data["ParticleMassMsun"].sum(dtype=np.float64)
 
     return x,y,z, den
 def _combCenterOfMass(data, x,y,z, den):
@@ -169,8 +172,8 @@
     :param field: The field to average
     :param weight: The field to weight by
     """
-    num = (data[field] * data[weight]).sum()
-    den = data[weight].sum()
+    num = (data[field] * data[weight]).sum(dtype=np.float64)
+    den = data[weight].sum(dtype=np.float64)
     return num, den
 def _combWeightedAverageQuantity(data, field, weight):
     return field.sum()/weight.sum()
@@ -186,11 +189,11 @@
 
     Returns the weighted variance and the weighted mean.
     """
-    my_weight = data[weight].sum()
+    my_weight = data[weight].sum(dtype=np.float64)
     if my_weight == 0:
         return 0.0, 0.0, 0.0
-    my_mean = (data[field] * data[weight]).sum() / my_weight
-    my_var2 = (data[weight] * (data[field] - my_mean)**2).sum() / my_weight
+    my_mean = (data[field] * data[weight]).sum(dtype=np.float64) / my_weight
+    my_var2 = (data[weight] * (data[field] - my_mean)**2).sum(dtype=np.float64) / my_weight
     return my_weight, my_mean, my_var2
 def _combWeightedVariance(data, my_weight, my_mean, my_var2):
     all_weight = my_weight.sum()
@@ -204,10 +207,10 @@
     """
     This function returns the mass-weighted average velocity in the object.
     """
-    xv = (data["x-velocity"] * data["CellMassMsun"]).sum()
-    yv = (data["y-velocity"] * data["CellMassMsun"]).sum()
-    zv = (data["z-velocity"] * data["CellMassMsun"]).sum()
-    w = data["CellMassMsun"].sum()
+    xv = (data["x-velocity"] * data["CellMassMsun"]).sum(dtype=np.float64)
+    yv = (data["y-velocity"] * data["CellMassMsun"]).sum(dtype=np.float64)
+    zv = (data["z-velocity"] * data["CellMassMsun"]).sum(dtype=np.float64)
+    w = data["CellMassMsun"].sum(dtype=np.float64)
     return xv, yv, zv, w
 def _combBulkVelocity(data, xv, yv, zv, w):
     w = w.sum()
@@ -225,7 +228,7 @@
     amx = data["SpecificAngularMomentumX"]*data["CellMassMsun"]
     amy = data["SpecificAngularMomentumY"]*data["CellMassMsun"]
     amz = data["SpecificAngularMomentumZ"]*data["CellMassMsun"]
-    j_mag = [amx.sum(), amy.sum(), amz.sum()]
+    j_mag = [amx.sum(dtype=np.float64), amy.sum(dtype=np.float64), amz.sum(dtype=np.float64)]
     return [j_mag]
 
 def _StarAngularMomentumVector(data):
@@ -241,13 +244,13 @@
     amx = sLx * star_mass
     amy = sLy * star_mass
     amz = sLz * star_mass
-    j_mag = [amx.sum(), amy.sum(), amz.sum()]
+    j_mag = [amx.sum(dtype=np.float64), amy.sum(dtype=np.float64), amz.sum(dtype=np.float64)]
     return [j_mag]
 
 def _combAngularMomentumVector(data, j_mag):
     if len(j_mag.shape) < 2: j_mag = np.expand_dims(j_mag, 0)
-    L_vec = j_mag.sum(axis=0)
-    L_vec_norm = L_vec / np.sqrt((L_vec**2.0).sum())
+    L_vec = j_mag.sum(axis=0,dtype=np.float64)
+    L_vec_norm = L_vec / np.sqrt((L_vec**2.0).sum(dtype=np.float64))
     return L_vec_norm
 add_quantity("AngularMomentumVector", function=_AngularMomentumVector,
              combine_function=_combAngularMomentumVector, n_ret=1)
@@ -260,13 +263,13 @@
     This function returns the spin parameter for the baryons, but it uses
     the particles in calculating enclosed mass.
     """
-    m_enc = data["CellMassMsun"].sum() + data["ParticleMassMsun"].sum()
+    m_enc = _TotalMass(data)
     amx = data["SpecificAngularMomentumX"]*data["CellMassMsun"]
     amy = data["SpecificAngularMomentumY"]*data["CellMassMsun"]
     amz = data["SpecificAngularMomentumZ"]*data["CellMassMsun"]
-    j_mag = np.array([amx.sum(), amy.sum(), amz.sum()])
-    e_term_pre = np.sum(data["CellMassMsun"]*data["VelocityMagnitude"]**2.0)
-    weight=data["CellMassMsun"].sum()
+    j_mag = np.array([amx.sum(dtype=np.float64), amy.sum(dtype=np.float64), amz.sum(dtype=np.float64)])
+    e_term_pre = np.sum(data["CellMassMsun"]*data["VelocityMagnitude"]**2.0,dtype=np.float64)
+    weight=data["CellMassMsun"].sum(dtype=np.float64)
     return j_mag, m_enc, e_term_pre, weight
 def _combBaryonSpinParameter(data, j_mag, m_enc, e_term_pre, weight):
     # Because it's a vector field, we have to ensure we have enough dimensions
@@ -285,15 +288,15 @@
     This function returns the spin parameter for the baryons, but it uses
     the particles in calculating enclosed mass.
     """
-    m_enc = data["CellMassMsun"].sum() + data["ParticleMassMsun"].sum()
+    m_enc = _TotalMass(data)
     amx = data["ParticleSpecificAngularMomentumX"]*data["ParticleMassMsun"]
-    if amx.size == 0: return (np.zeros((3,), dtype='float64'), m_enc, 0, 0)
+    if amx.size == 0: return (np.zeros((3,), dtype=np.float64), m_enc, 0, 0)
     amy = data["ParticleSpecificAngularMomentumY"]*data["ParticleMassMsun"]
     amz = data["ParticleSpecificAngularMomentumZ"]*data["ParticleMassMsun"]
-    j_mag = np.array([amx.sum(), amy.sum(), amz.sum()])
+    j_mag = np.array([amx.sum(dtype=np.float64), amy.sum(dtype=np.float64), amz.sum(dtype=np.float64)])
     e_term_pre = np.sum(data["ParticleMassMsun"]
-                       *data["ParticleVelocityMagnitude"]**2.0)
-    weight=data["ParticleMassMsun"].sum()
+                       *data["ParticleVelocityMagnitude"]**2.0,dtype=np.float64)
+    weight=data["ParticleMassMsun"].sum(dtype=np.float64)
     return j_mag, m_enc, e_term_pre, weight
 add_quantity("ParticleSpinParameter", function=_ParticleSpinParameter,
              combine_function=_combBaryonSpinParameter, n_ret=4)
@@ -340,19 +343,19 @@
     kinetic = 0.5 * (data["CellMass"] * 
                      ((data["x-velocity"] - bv_x)**2 + 
                       (data["y-velocity"] - bv_y)**2 +
-                      (data["z-velocity"] - bv_z)**2)).sum()
+                      (data["z-velocity"] - bv_z)**2)).sum(dtype=np.float64)
 
     if (include_particles):
-	mass_to_use = data["TotalMass"]
+        mass_to_use = data["TotalMass"]
         kinetic += 0.5 * (data["Dark_Matter_Mass"] *
                           ((data["cic_particle_velocity_x"] - bv_x)**2 +
                            (data["cic_particle_velocity_y"] - bv_y)**2 +
-                           (data["cic_particle_velocity_z"] - bv_z)**2)).sum()
+                           (data["cic_particle_velocity_z"] - bv_z)**2)).sum(dtype=np.float64)
     else:
-	mass_to_use = data["CellMass"]
+        mass_to_use = data["CellMass"]
     # Add thermal energy to kinetic energy
     if (include_thermal_energy):
-        thermal = (data["ThermalEnergy"] * mass_to_use).sum()
+        thermal = (data["ThermalEnergy"] * mass_to_use).sum(dtype=np.float64)
         kinetic += thermal
     if periodic_test:
         kinetic = np.ones_like(kinetic)
@@ -681,14 +684,7 @@
         if data[field].size < 1:
             totals.append(np.zeros(1,dtype=data[field].dtype)[0])
             continue
-        if data[field].dtype in (np.int,np.int8,np.int16,np.int32,np.int64):
-            totals.append(data[field].sum(dtype=np.int64))
-        elif data[field].dtype in (np.uint8,np.uint16,np.uint32,np.uint64):
-            totals.append(data[field].sum(dtype=np.uint64))
-        elif data[field].dtype in (np.float,np.float16,np.float32,np.float64):
-            totals.append(data[field].sum(dtype=np.float64))
-        else:
-            totals.append(data[field].sum())
+        totals.append(data[field].sum(dtype=prec_accum(data[field].dtype))
     return len(fields), totals
 def _combTotalQuantity(data, n_fields, totals):
     totals = np.atleast_2d(totals)
@@ -705,7 +701,7 @@
     pos = [data[(particle_type,"particle_position_%s"%ax)] for ax in "xyz"]
     pos = np.array(pos).T
     mas = data[(particle_type,"particle_mass")]
-    calc_radius= lambda x,y:np.sqrt(np.sum((x-y)**2.0,axis=1))
+    calc_radius= lambda x,y:np.sqrt(np.sum((x-y)**2.0,axis=1,dtype=np.float64))
     density = 0
     if pos.shape[0]==0:
         return -1.0,[-1.,-1.,-1.]
@@ -722,7 +718,7 @@
         center = 0.5*(le+re)
         idx = calc_radius(pos,center)<bin_size
         pos, mas = pos[idx],mas[idx]
-        density = max(density,mas.sum()/bin_size**3.0)
+        density = max(density,mas.sum(dtype=np.float64)/bin_size**3.0)
     return density, center
 def _combParticleDensityCenter(data,densities,centers):
     i = np.argmax(densities)


https://bitbucket.org/yt_analysis/yt-3.0/commits/838a9f3a292e/
Changeset:   838a9f3a292e
Branch:      yt-3.0
User:        drudd
Date:        2013-07-10 21:44:11
Summary:     Added import of prec_accum
Affected #:  1 file

diff -r 324a98f34e1c64b1303e007ad8d0048786f7d81a -r 838a9f3a292e4e4e5db54d88fa471bd4a09f71b3 yt/data_objects/derived_quantities.py
--- a/yt/data_objects/derived_quantities.py
+++ b/yt/data_objects/derived_quantities.py
@@ -40,7 +40,7 @@
     gravitational_constant_cgs, \
     mass_sun_cgs, \
     HUGE
-
+from yt.utilities.math_utils import prec_accum
 
 __CUDA_BLOCK_SIZE = 256
 


https://bitbucket.org/yt_analysis/yt-3.0/commits/d65802f854da/
Changeset:   d65802f854da
Branch:      yt-3.0
User:        drudd
Date:        2013-07-10 21:46:43
Summary:     Added missing change to math_utils.py
Affected #:  1 file

diff -r 838a9f3a292e4e4e5db54d88fa471bd4a09f71b3 -r d65802f854dad49b1204c6092f8e7a76ac72bbcc yt/utilities/math_utils.py
--- a/yt/utilities/math_utils.py
+++ b/yt/utilities/math_utils.py
@@ -30,6 +30,25 @@
 import numpy as np
 import math
 
+prec_accum = {
+    np.int:        np.int64,
+    np.int8:       np.int64,
+    np.int16:      np.int64,
+    np.int32:      np.int64,
+    np.int64:      np.int64,
+    np.uint8:      np.uint64,
+    np.uint16:     np.uint64,
+    np.uint32:     np.uint64,
+    np.uint64:     np.uint64,
+    np.float:      np.float64,
+    np.float16:    np.float64,
+    np.float32:    np.float64,
+    np.float64:    np.float64,
+    np.complex:    np.complex128,
+    np.complex64:  np.complex128,
+    np.complex128: np.complex128,
+}
+
 def periodic_position(pos, pf):
     r"""Assuming periodicity, find the periodic position within the domain.
 


https://bitbucket.org/yt_analysis/yt-3.0/commits/a2fc616c08c3/
Changeset:   a2fc616c08c3
Branch:      yt-3.0
User:        drudd
Date:        2013-07-10 22:14:42
Summary:     Fixed typo in TotalQuantities
Affected #:  1 file

diff -r d65802f854dad49b1204c6092f8e7a76ac72bbcc -r a2fc616c08c345eed3dd64d879a899acec9479ba yt/data_objects/derived_quantities.py
--- a/yt/data_objects/derived_quantities.py
+++ b/yt/data_objects/derived_quantities.py
@@ -684,7 +684,7 @@
         if data[field].size < 1:
             totals.append(np.zeros(1,dtype=data[field].dtype)[0])
             continue
-        totals.append(data[field].sum(dtype=prec_accum(data[field].dtype))
+        totals.append(data[field].sum(dtype=prec_accum(data[field].dtype)))
     return len(fields), totals
 def _combTotalQuantity(data, n_fields, totals):
     totals = np.atleast_2d(totals)


https://bitbucket.org/yt_analysis/yt-3.0/commits/9ca676914b73/
Changeset:   9ca676914b73
Branch:      yt-3.0
User:        drudd
Date:        2013-07-10 23:01:22
Summary:     Passes local nose tests
Affected #:  2 files

diff -r a2fc616c08c345eed3dd64d879a899acec9479ba -r 9ca676914b7358e894660ddc0aa9924fe7bd7c5d yt/data_objects/derived_quantities.py
--- a/yt/data_objects/derived_quantities.py
+++ b/yt/data_objects/derived_quantities.py
@@ -684,7 +684,7 @@
         if data[field].size < 1:
             totals.append(np.zeros(1,dtype=data[field].dtype)[0])
             continue
-        totals.append(data[field].sum(dtype=prec_accum(data[field].dtype)))
+        totals.append(data[field].sum(dtype=prec_accum[data[field].dtype]))
     return len(fields), totals
 def _combTotalQuantity(data, n_fields, totals):
     totals = np.atleast_2d(totals)

diff -r a2fc616c08c345eed3dd64d879a899acec9479ba -r 9ca676914b7358e894660ddc0aa9924fe7bd7c5d yt/utilities/math_utils.py
--- a/yt/utilities/math_utils.py
+++ b/yt/utilities/math_utils.py
@@ -31,22 +31,38 @@
 import math
 
 prec_accum = {
-    np.int:        np.int64,
-    np.int8:       np.int64,
-    np.int16:      np.int64,
-    np.int32:      np.int64,
-    np.int64:      np.int64,
-    np.uint8:      np.uint64,
-    np.uint16:     np.uint64,
-    np.uint32:     np.uint64,
-    np.uint64:     np.uint64,
-    np.float:      np.float64,
-    np.float16:    np.float64,
-    np.float32:    np.float64,
-    np.float64:    np.float64,
-    np.complex:    np.complex128,
-    np.complex64:  np.complex128,
-    np.complex128: np.complex128,
+    np.int:                 np.int64,
+    np.int8:                np.int64,
+    np.int16:               np.int64,
+    np.int32:               np.int64,
+    np.int64:               np.int64,
+    np.uint8:               np.uint64,
+    np.uint16:              np.uint64,
+    np.uint32:              np.uint64,
+    np.uint64:              np.uint64,
+    np.float:               np.float64,
+    np.float16:             np.float64,
+    np.float32:             np.float64,
+    np.float64:             np.float64,
+    np.complex:             np.complex128,
+    np.complex64:           np.complex128,
+    np.complex128:          np.complex128,
+    np.dtype('int'):        np.int64,
+    np.dtype('int8'):       np.int64,
+    np.dtype('int16'):      np.int64,
+    np.dtype('int32'):      np.int64,
+    np.dtype('int64'):      np.int64,
+    np.dtype('uint8'):      np.uint64,
+    np.dtype('uint16'):     np.uint64,
+    np.dtype('uint32'):     np.uint64,
+    np.dtype('uint64'):     np.uint64,
+    np.dtype('float'):      np.float64,
+    np.dtype('float16'):    np.float64,
+    np.dtype('float32'):    np.float64,
+    np.dtype('float64'):    np.float64,
+    np.dtype('complex'):    np.complex128,
+    np.dtype('complex64'):  np.complex128,
+    np.dtype('complex128'): np.complex128,
 }
 
 def periodic_position(pos, pf):


https://bitbucket.org/yt_analysis/yt-3.0/commits/0d573a384092/
Changeset:   0d573a384092
Branch:      yt-3.0
User:        drudd
Date:        2013-07-16 01:02:56
Summary:     Promoted empty totals
Affected #:  1 file

diff -r 9ca676914b7358e894660ddc0aa9924fe7bd7c5d -r 0d573a3840921bf7ad3437e45a1db6985b7cea47 yt/data_objects/derived_quantities.py
--- a/yt/data_objects/derived_quantities.py
+++ b/yt/data_objects/derived_quantities.py
@@ -682,7 +682,7 @@
     totals = []
     for field in fields:
         if data[field].size < 1:
-            totals.append(np.zeros(1,dtype=data[field].dtype)[0])
+            totals.append(np.zeros(1,dtype=prec_accum[data[field].dtype])[0])
             continue
         totals.append(data[field].sum(dtype=prec_accum[data[field].dtype]))
     return len(fields), totals


https://bitbucket.org/yt_analysis/yt-3.0/commits/9eaa5e6f93ff/
Changeset:   9eaa5e6f93ff
Branch:      yt-3.0
User:        MatthewTurk
Date:        2013-07-16 13:32:29
Summary:     Merged in drudd/yt-3.0-precision (pull request #63)

Added type consistency and precision promotion in TotalQuantity
Affected #:  2 files

diff -r 44637ca2b97b0a33b3986163ed4f1bfa7d3a3cbf -r 9eaa5e6f93fff270c80ae725f510d586567351c0 yt/data_objects/derived_quantities.py
--- a/yt/data_objects/derived_quantities.py
+++ b/yt/data_objects/derived_quantities.py
@@ -40,7 +40,7 @@
     gravitational_constant_cgs, \
     mass_sun_cgs, \
     HUGE
-
+from yt.utilities.math_utils import prec_accum
 
 __CUDA_BLOCK_SIZE = 256
 
@@ -119,12 +119,15 @@
     This function takes no arguments and returns the sum of cell masses and
     particle masses in the object.
     """
-    baryon_mass = data["CellMassMsun"].sum()
     try:
-        particle_mass = data["ParticleMassMsun"].sum()
-        total_mass = baryon_mass + particle_mass
+        cell_mass = _TotalQuantity(data,["CellMassMsun"])
     except KeyError:
-        total_mass = baryon_mass
+        cell_mass = 0.0
+    try:
+        particle_mass = _TotalQuantity(data,["ParticleMassMsun"])
+    except KeyError:
+        particle_mass = 0.0
+    total_mass = cell_mass + particle_mass
     return [total_mass]
 def _combTotalMass(data, total_mass):
     return total_mass.sum()
@@ -146,15 +149,15 @@
     """
     x = y = z = den = 0
     if use_cells: 
-        x += (data["x"] * data["CellMassMsun"]).sum()
-        y += (data["y"] * data["CellMassMsun"]).sum()
-        z += (data["z"] * data["CellMassMsun"]).sum()
-        den += data["CellMassMsun"].sum()
+        x += (data["x"] * data["CellMassMsun"]).sum(dtype=np.float64)
+        y += (data["y"] * data["CellMassMsun"]).sum(dtype=np.float64)
+        z += (data["z"] * data["CellMassMsun"]).sum(dtype=np.float64)
+        den += data["CellMassMsun"].sum(dtype=np.float64)
     if use_particles:
-        x += (data["particle_position_x"] * data["ParticleMassMsun"]).sum()
-        y += (data["particle_position_y"] * data["ParticleMassMsun"]).sum()
-        z += (data["particle_position_z"] * data["ParticleMassMsun"]).sum()
-        den += data["ParticleMassMsun"].sum()
+        x += (data["particle_position_x"] * data["ParticleMassMsun"]).sum(dtype=np.float64)
+        y += (data["particle_position_y"] * data["ParticleMassMsun"]).sum(dtype=np.float64)
+        z += (data["particle_position_z"] * data["ParticleMassMsun"]).sum(dtype=np.float64)
+        den += data["ParticleMassMsun"].sum(dtype=np.float64)
 
     return x,y,z, den
 def _combCenterOfMass(data, x,y,z, den):
@@ -169,8 +172,8 @@
     :param field: The field to average
     :param weight: The field to weight by
     """
-    num = (data[field] * data[weight]).sum()
-    den = data[weight].sum()
+    num = (data[field] * data[weight]).sum(dtype=np.float64)
+    den = data[weight].sum(dtype=np.float64)
     return num, den
 def _combWeightedAverageQuantity(data, field, weight):
     return field.sum()/weight.sum()
@@ -186,11 +189,11 @@
 
     Returns the weighted variance and the weighted mean.
     """
-    my_weight = data[weight].sum()
+    my_weight = data[weight].sum(dtype=np.float64)
     if my_weight == 0:
         return 0.0, 0.0, 0.0
-    my_mean = (data[field] * data[weight]).sum() / my_weight
-    my_var2 = (data[weight] * (data[field] - my_mean)**2).sum() / my_weight
+    my_mean = (data[field] * data[weight]).sum(dtype=np.float64) / my_weight
+    my_var2 = (data[weight] * (data[field] - my_mean)**2).sum(dtype=np.float64) / my_weight
     return my_weight, my_mean, my_var2
 def _combWeightedVariance(data, my_weight, my_mean, my_var2):
     all_weight = my_weight.sum()
@@ -204,10 +207,10 @@
     """
     This function returns the mass-weighted average velocity in the object.
     """
-    xv = (data["x-velocity"] * data["CellMassMsun"]).sum()
-    yv = (data["y-velocity"] * data["CellMassMsun"]).sum()
-    zv = (data["z-velocity"] * data["CellMassMsun"]).sum()
-    w = data["CellMassMsun"].sum()
+    xv = (data["x-velocity"] * data["CellMassMsun"]).sum(dtype=np.float64)
+    yv = (data["y-velocity"] * data["CellMassMsun"]).sum(dtype=np.float64)
+    zv = (data["z-velocity"] * data["CellMassMsun"]).sum(dtype=np.float64)
+    w = data["CellMassMsun"].sum(dtype=np.float64)
     return xv, yv, zv, w
 def _combBulkVelocity(data, xv, yv, zv, w):
     w = w.sum()
@@ -225,7 +228,7 @@
     amx = data["SpecificAngularMomentumX"]*data["CellMassMsun"]
     amy = data["SpecificAngularMomentumY"]*data["CellMassMsun"]
     amz = data["SpecificAngularMomentumZ"]*data["CellMassMsun"]
-    j_mag = [amx.sum(), amy.sum(), amz.sum()]
+    j_mag = [amx.sum(dtype=np.float64), amy.sum(dtype=np.float64), amz.sum(dtype=np.float64)]
     return [j_mag]
 
 def _StarAngularMomentumVector(data):
@@ -241,13 +244,13 @@
     amx = sLx * star_mass
     amy = sLy * star_mass
     amz = sLz * star_mass
-    j_mag = [amx.sum(), amy.sum(), amz.sum()]
+    j_mag = [amx.sum(dtype=np.float64), amy.sum(dtype=np.float64), amz.sum(dtype=np.float64)]
     return [j_mag]
 
 def _combAngularMomentumVector(data, j_mag):
     if len(j_mag.shape) < 2: j_mag = np.expand_dims(j_mag, 0)
-    L_vec = j_mag.sum(axis=0)
-    L_vec_norm = L_vec / np.sqrt((L_vec**2.0).sum())
+    L_vec = j_mag.sum(axis=0,dtype=np.float64)
+    L_vec_norm = L_vec / np.sqrt((L_vec**2.0).sum(dtype=np.float64))
     return L_vec_norm
 add_quantity("AngularMomentumVector", function=_AngularMomentumVector,
              combine_function=_combAngularMomentumVector, n_ret=1)
@@ -260,13 +263,13 @@
     This function returns the spin parameter for the baryons, but it uses
     the particles in calculating enclosed mass.
     """
-    m_enc = data["CellMassMsun"].sum() + data["ParticleMassMsun"].sum()
+    m_enc = _TotalMass(data)
     amx = data["SpecificAngularMomentumX"]*data["CellMassMsun"]
     amy = data["SpecificAngularMomentumY"]*data["CellMassMsun"]
     amz = data["SpecificAngularMomentumZ"]*data["CellMassMsun"]
-    j_mag = np.array([amx.sum(), amy.sum(), amz.sum()])
-    e_term_pre = np.sum(data["CellMassMsun"]*data["VelocityMagnitude"]**2.0)
-    weight=data["CellMassMsun"].sum()
+    j_mag = np.array([amx.sum(dtype=np.float64), amy.sum(dtype=np.float64), amz.sum(dtype=np.float64)])
+    e_term_pre = np.sum(data["CellMassMsun"]*data["VelocityMagnitude"]**2.0,dtype=np.float64)
+    weight=data["CellMassMsun"].sum(dtype=np.float64)
     return j_mag, m_enc, e_term_pre, weight
 def _combBaryonSpinParameter(data, j_mag, m_enc, e_term_pre, weight):
     # Because it's a vector field, we have to ensure we have enough dimensions
@@ -285,15 +288,15 @@
     This function returns the spin parameter for the baryons, but it uses
     the particles in calculating enclosed mass.
     """
-    m_enc = data["CellMassMsun"].sum() + data["ParticleMassMsun"].sum()
+    m_enc = _TotalMass(data)
     amx = data["ParticleSpecificAngularMomentumX"]*data["ParticleMassMsun"]
-    if amx.size == 0: return (np.zeros((3,), dtype='float64'), m_enc, 0, 0)
+    if amx.size == 0: return (np.zeros((3,), dtype=np.float64), m_enc, 0, 0)
     amy = data["ParticleSpecificAngularMomentumY"]*data["ParticleMassMsun"]
     amz = data["ParticleSpecificAngularMomentumZ"]*data["ParticleMassMsun"]
-    j_mag = np.array([amx.sum(), amy.sum(), amz.sum()])
+    j_mag = np.array([amx.sum(dtype=np.float64), amy.sum(dtype=np.float64), amz.sum(dtype=np.float64)])
     e_term_pre = np.sum(data["ParticleMassMsun"]
-                       *data["ParticleVelocityMagnitude"]**2.0)
-    weight=data["ParticleMassMsun"].sum()
+                       *data["ParticleVelocityMagnitude"]**2.0,dtype=np.float64)
+    weight=data["ParticleMassMsun"].sum(dtype=np.float64)
     return j_mag, m_enc, e_term_pre, weight
 add_quantity("ParticleSpinParameter", function=_ParticleSpinParameter,
              combine_function=_combBaryonSpinParameter, n_ret=4)
@@ -340,19 +343,19 @@
     kinetic = 0.5 * (data["CellMass"] * 
                      ((data["x-velocity"] - bv_x)**2 + 
                       (data["y-velocity"] - bv_y)**2 +
-                      (data["z-velocity"] - bv_z)**2)).sum()
+                      (data["z-velocity"] - bv_z)**2)).sum(dtype=np.float64)
 
     if (include_particles):
-	mass_to_use = data["TotalMass"]
+        mass_to_use = data["TotalMass"]
         kinetic += 0.5 * (data["Dark_Matter_Mass"] *
                           ((data["cic_particle_velocity_x"] - bv_x)**2 +
                            (data["cic_particle_velocity_y"] - bv_y)**2 +
-                           (data["cic_particle_velocity_z"] - bv_z)**2)).sum()
+                           (data["cic_particle_velocity_z"] - bv_z)**2)).sum(dtype=np.float64)
     else:
-	mass_to_use = data["CellMass"]
+        mass_to_use = data["CellMass"]
     # Add thermal energy to kinetic energy
     if (include_thermal_energy):
-        thermal = (data["ThermalEnergy"] * mass_to_use).sum()
+        thermal = (data["ThermalEnergy"] * mass_to_use).sum(dtype=np.float64)
         kinetic += thermal
     if periodic_test:
         kinetic = np.ones_like(kinetic)
@@ -679,9 +682,9 @@
     totals = []
     for field in fields:
         if data[field].size < 1:
-            totals.append(0.0)
+            totals.append(np.zeros(1,dtype=prec_accum[data[field].dtype])[0])
             continue
-        totals.append(data[field].sum())
+        totals.append(data[field].sum(dtype=prec_accum[data[field].dtype]))
     return len(fields), totals
 def _combTotalQuantity(data, n_fields, totals):
     totals = np.atleast_2d(totals)
@@ -698,7 +701,7 @@
     pos = [data[(particle_type,"particle_position_%s"%ax)] for ax in "xyz"]
     pos = np.array(pos).T
     mas = data[(particle_type,"particle_mass")]
-    calc_radius= lambda x,y:np.sqrt(np.sum((x-y)**2.0,axis=1))
+    calc_radius= lambda x,y:np.sqrt(np.sum((x-y)**2.0,axis=1,dtype=np.float64))
     density = 0
     if pos.shape[0]==0:
         return -1.0,[-1.,-1.,-1.]
@@ -715,7 +718,7 @@
         center = 0.5*(le+re)
         idx = calc_radius(pos,center)<bin_size
         pos, mas = pos[idx],mas[idx]
-        density = max(density,mas.sum()/bin_size**3.0)
+        density = max(density,mas.sum(dtype=np.float64)/bin_size**3.0)
     return density, center
 def _combParticleDensityCenter(data,densities,centers):
     i = np.argmax(densities)

diff -r 44637ca2b97b0a33b3986163ed4f1bfa7d3a3cbf -r 9eaa5e6f93fff270c80ae725f510d586567351c0 yt/utilities/math_utils.py
--- a/yt/utilities/math_utils.py
+++ b/yt/utilities/math_utils.py
@@ -30,6 +30,41 @@
 import numpy as np
 import math
 
+prec_accum = {
+    np.int:                 np.int64,
+    np.int8:                np.int64,
+    np.int16:               np.int64,
+    np.int32:               np.int64,
+    np.int64:               np.int64,
+    np.uint8:               np.uint64,
+    np.uint16:              np.uint64,
+    np.uint32:              np.uint64,
+    np.uint64:              np.uint64,
+    np.float:               np.float64,
+    np.float16:             np.float64,
+    np.float32:             np.float64,
+    np.float64:             np.float64,
+    np.complex:             np.complex128,
+    np.complex64:           np.complex128,
+    np.complex128:          np.complex128,
+    np.dtype('int'):        np.int64,
+    np.dtype('int8'):       np.int64,
+    np.dtype('int16'):      np.int64,
+    np.dtype('int32'):      np.int64,
+    np.dtype('int64'):      np.int64,
+    np.dtype('uint8'):      np.uint64,
+    np.dtype('uint16'):     np.uint64,
+    np.dtype('uint32'):     np.uint64,
+    np.dtype('uint64'):     np.uint64,
+    np.dtype('float'):      np.float64,
+    np.dtype('float16'):    np.float64,
+    np.dtype('float32'):    np.float64,
+    np.dtype('float64'):    np.float64,
+    np.dtype('complex'):    np.complex128,
+    np.dtype('complex64'):  np.complex128,
+    np.dtype('complex128'): np.complex128,
+}
+
 def periodic_position(pos, pf):
     r"""Assuming periodicity, find the periodic position within the domain.

Repository URL: https://bitbucket.org/yt_analysis/yt-3.0/

--

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