[yt-svn] commit/yt: 5 new changesets

Bitbucket commits-noreply at bitbucket.org
Tue Oct 16 10:46:33 PDT 2012


5 new commits in yt:


https://bitbucket.org/yt_analysis/yt/changeset/d23fa50f9c18/
changeset:   d23fa50f9c18
branch:      yt
user:        xarthisius
date:        2012-10-16 17:45:30
summary:     [decompose] don't rely on numpy's array_split, explicitly calculate array chunks instead
affected #:  1 file

diff -r 529288f3186b70dc06a2f1360e9b2e94d7a09fe9 -r d23fa50f9c18c1aceee3f2eb64d74cdbfaf1a1cb yt/utilities/decompose.py
--- a/yt/utilities/decompose.py
+++ b/yt/utilities/decompose.py
@@ -134,13 +134,17 @@
 
 
 def split_array(tab, psize):
-    """ Split array into px*py*pz subarrays using internal numpy routine. """
-    temp = [np.array_split(array, psize[1], axis=1)
-            for array in np.array_split(tab, psize[2], axis=2)]
-    temp = [item for sublist in temp for item in sublist]
-    temp = [np.array_split(array, psize[0], axis=0) for array in temp]
-    temp = [item for sublist in temp for item in sublist]
-    return temp
+    """ Split array into px*py*pz subarrays. """
+    n_d = np.array(tab.shape, dtype=np.int64)
+    slices = []
+    for i in range(psize[0]):
+        for j in range(psize[1]):
+            for k in range(psize[2]):
+                pc = np.array((i, j, k), dtype=np.int64)
+                le = n_d * pc / psize 
+                re = n_d * (pc + np.ones(3, dtype=np.int64)) / psize
+                slices.append(np.s_[le[0]:re[0], le[1]:re[1], le[2]:re[2]] )
+    return [tab[sl] for sl in slices]
 
 
 if __name__ == "__main__":



https://bitbucket.org/yt_analysis/yt/changeset/caca310b61f1/
changeset:   caca310b61f1
branch:      yt
user:        xarthisius
date:        2012-10-16 17:46:29
summary:     [decompose] improve evaluation of domain decomposition for non 3d case
affected #:  1 file

diff -r d23fa50f9c18c1aceee3f2eb64d74cdbfaf1a1cb -r caca310b61f1983fe888bd24a5f4041ffe111318 yt/utilities/decompose.py
--- a/yt/utilities/decompose.py
+++ b/yt/utilities/decompose.py
@@ -68,9 +68,11 @@
 def evaluate_domain_decomposition(n_d, pieces, ldom):
     """ Evaluate longest to shortest edge ratio
         BEWARE: lot's of magic here """
-    ideal_bsize = 3.0 * (pieces * np.product(n_d) ** 2) ** (1.0 / 3.0)
-    bsize = int(np.sum(
-        ldom / np.array(n_d, dtype=np.float64) * np.product(n_d)))
+    eff_dim = (n_d > 1).sum()
+    ideal_bsize = eff_dim * (pieces * np.product(n_d) ** (eff_dim-1)) ** (1.0 / eff_dim)
+    mask = np.where(n_d > 1)
+    nd = np.array(n_d, dtype=np.float64)[mask]
+    bsize = int(np.sum(ldom[mask] / nd * np.product(nd)))
     load_balance = float(np.product(n_d)) / \
         (float(pieces) * np.product((n_d - 1) / ldom + 1))
 



https://bitbucket.org/yt_analysis/yt/changeset/d32225d2d84c/
changeset:   d32225d2d84c
branch:      yt
user:        xarthisius
date:        2012-10-16 18:48:37
summary:     [decompose] add unit tests, pep8
affected #:  2 files

diff -r caca310b61f1983fe888bd24a5f4041ffe111318 -r d32225d2d84cbb00ee3948e9c117f57ba4d73171 yt/utilities/decompose.py
--- a/yt/utilities/decompose.py
+++ b/yt/utilities/decompose.py
@@ -69,7 +69,8 @@
     """ Evaluate longest to shortest edge ratio
         BEWARE: lot's of magic here """
     eff_dim = (n_d > 1).sum()
-    ideal_bsize = eff_dim * (pieces * np.product(n_d) ** (eff_dim-1)) ** (1.0 / eff_dim)
+    ideal_bsize = eff_dim * (pieces * np.product(n_d) ** (eff_dim - 1)
+                             ) ** (1.0 / eff_dim)
     mask = np.where(n_d > 1)
     nd = np.array(n_d, dtype=np.float64)[mask]
     bsize = int(np.sum(ldom[mask] / nd * np.product(nd)))
@@ -143,20 +144,7 @@
         for j in range(psize[1]):
             for k in range(psize[2]):
                 pc = np.array((i, j, k), dtype=np.int64)
-                le = n_d * pc / psize 
+                le = n_d * pc / psize
                 re = n_d * (pc + np.ones(3, dtype=np.int64)) / psize
-                slices.append(np.s_[le[0]:re[0], le[1]:re[1], le[2]:re[2]] )
+                slices.append(np.s_[le[0]:re[0], le[1]:re[1], le[2]:re[2]])
     return [tab[sl] for sl in slices]
-
-
-if __name__ == "__main__":
-
-    NPROC = 12
-    ARRAY = np.zeros((128, 128, 129))
-    BBOX = np.array([[0., 1.0], [-1.5, 1.5], [1.0, 2.5]])
-
-    PROCS = get_psize(np.array(ARRAY.shape), NPROC)
-    LE, RE, DATA = decompose_array(ARRAY, PROCS, BBOX)
-
-    for idx in range(NPROC):
-        print LE[idx, :], RE[idx, :], DATA[idx].shape


diff -r caca310b61f1983fe888bd24a5f4041ffe111318 -r d32225d2d84cbb00ee3948e9c117f57ba4d73171 yt/utilities/tests/test_decompose.py
--- /dev/null
+++ b/yt/utilities/tests/test_decompose.py
@@ -0,0 +1,93 @@
+"""
+Test suite for cartesian domain decomposition.
+
+Author: Kacper Kowalik <xarthisius.kk at gmail.com>
+Affiliation: CA UMK
+Homepage: http://yt-project.org/
+License:
+  Copyright (C) 2012 Kacper Kowalik. All Rights Reserved.
+
+  This file is part of yt.
+
+  yt is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 3 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+"""
+
+from yt.testing import *
+import yt.utilities.decompose as dec
+
+
+def setup():
+    pass
+
+
+def test_psize_2d():
+    procs = dec.get_psize(np.array([5, 1, 7]), 6)
+    assert_array_equal(procs, np.array([3, 1, 2]))
+    procs = dec.get_psize(np.array([1, 7, 5]), 6)
+    assert_array_equal(procs, np.array([1, 2, 3]))
+    procs = dec.get_psize(np.array([7, 5, 1]), 6)
+    assert_array_equal(procs, np.array([2, 3, 1]))
+
+
+def test_psize_3d():
+    procs = dec.get_psize(np.array([33, 35, 37]), 12)
+    assert_array_equal(procs, np.array([3, 2, 2]))
+
+
+def test_decomposition_2d():
+    array = np.ones((7, 5, 1))
+    bbox = np.array([[-0.7, 0.0], [1.5, 2.0], [0.0, 0.7]])
+    ledge, redge, data = dec.decompose_array(array, np.array([2, 3, 1]), bbox)
+
+    gold_le = np.array([
+                       [-0.7, 1.5, 0.0], [-0.7, 1.6, 0.0],
+                       [-0.7, 1.8, 0.0], [-0.4, 1.5, 0.0],
+                       [-0.4, 1.6, 0.0], [-0.4, 1.8, 0.0]
+                       ])
+    assert_almost_equal(ledge, gold_le, 8)
+
+    gold_re = np.array(
+        [[-0.4, 1.6, 0.7], [-0.4, 1.8, 0.7],
+         [-0.4, 2.0, 0.7], [0.0, 1.6, 0.7],
+         [0.0, 1.8, 0.7], [0.0, 2.0, 0.7]]
+    )
+    assert_almost_equal(redge, gold_re, 8)
+
+
+def test_decomposition_3d():
+    array = np.ones((33, 35, 37))
+    bbox = np.array([[0., 1.0], [-1.5, 1.5], [1.0, 2.5]])
+
+    ledge, redge, data = dec.decompose_array(array, np.array([3, 2, 2]), bbox)
+    assert_array_equal(data[0].shape, np.array([11, 17, 18]))
+
+    gold_le = np.array(
+        [[0.00000, -1.50000, 1.00000], [0.00000, -1.50000, 1.72973],
+         [0.00000, -0.04286, 1.00000], [0.00000, -0.04286, 1.72973],
+         [0.33333, -1.50000, 1.00000], [0.33333, -1.50000, 1.72973],
+         [0.33333, -0.04286, 1.00000], [0.33333, -0.04286, 1.72973],
+         [0.66667, -1.50000, 1.00000], [0.66667, -1.50000, 1.72973],
+         [0.66667, -0.04286, 1.00000], [0.66667, -0.04286, 1.72973]]
+    )
+    assert_almost_equal(ledge, gold_le, 5)
+
+    gold_re = np.array(
+        [[0.33333, -0.04286, 1.72973], [0.33333, -0.04286, 2.50000],
+         [0.33333, 1.50000, 1.72973], [0.33333, 1.50000, 2.50000],
+         [0.66667, -0.04286, 1.72973], [0.66667, -0.04286, 2.50000],
+         [0.66667, 1.50000, 1.72973], [0.66667, 1.50000, 2.50000],
+         [1.00000, -0.04286, 1.72973], [1.00000, -0.04286, 2.50000],
+         [1.00000, 1.50000, 1.72973], [1.00000, 1.50000, 2.50000]]
+    )
+    assert_almost_equal(redge, gold_re, 5)



https://bitbucket.org/yt_analysis/yt/changeset/5cd8e16ff5a6/
changeset:   5cd8e16ff5a6
branch:      yt
user:        xarthisius
date:        2012-10-16 18:54:44
summary:     [decompose] cosmetics
affected #:  1 file

diff -r d32225d2d84cbb00ee3948e9c117f57ba4d73171 -r 5cd8e16ff5a60fce04c3f7692ab65dbf8efd3eb5 yt/utilities/decompose.py
--- a/yt/utilities/decompose.py
+++ b/yt/utilities/decompose.py
@@ -72,8 +72,8 @@
     ideal_bsize = eff_dim * (pieces * np.product(n_d) ** (eff_dim - 1)
                              ) ** (1.0 / eff_dim)
     mask = np.where(n_d > 1)
-    nd = np.array(n_d, dtype=np.float64)[mask]
-    bsize = int(np.sum(ldom[mask] / nd * np.product(nd)))
+    nd_arr = np.array(n_d, dtype=np.float64)[mask]
+    bsize = int(np.sum(ldom[mask] / nd_arr * np.product(nd_arr)))
     load_balance = float(np.product(n_d)) / \
         (float(pieces) * np.product((n_d - 1) / ldom + 1))
 
@@ -143,8 +143,9 @@
     for i in range(psize[0]):
         for j in range(psize[1]):
             for k in range(psize[2]):
-                pc = np.array((i, j, k), dtype=np.int64)
-                le = n_d * pc / psize
-                re = n_d * (pc + np.ones(3, dtype=np.int64)) / psize
-                slices.append(np.s_[le[0]:re[0], le[1]:re[1], le[2]:re[2]])
-    return [tab[sl] for sl in slices]
+                piece = np.array((i, j, k), dtype=np.int64)
+                lei = n_d * piece / psize
+                rei = n_d * (piece + np.ones(3, dtype=np.int64)) / psize
+                slices.append(np.s_[lei[0]:rei[0], lei[1]:
+                                    rei[1], lei[2]:rei[2]])
+    return [tab[slc] for slc in slices]



https://bitbucket.org/yt_analysis/yt/changeset/ff017cd2c1a8/
changeset:   ff017cd2c1a8
branch:      yt
user:        xarthisius
date:        2012-10-16 18:59:29
summary:     [test_decompose] make pylint slightly more happy
affected #:  1 file

diff -r 5cd8e16ff5a60fce04c3f7692ab65dbf8efd3eb5 -r ff017cd2c1a8a85e5894d78b8bbf5745a84dc959 yt/utilities/tests/test_decompose.py
--- a/yt/utilities/tests/test_decompose.py
+++ b/yt/utilities/tests/test_decompose.py
@@ -23,7 +23,8 @@
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
 
-from yt.testing import *
+from yt.testing import assert_array_equal, assert_almost_equal
+import numpy as np
 import yt.utilities.decompose as dec
 
 
@@ -50,6 +51,8 @@
     bbox = np.array([[-0.7, 0.0], [1.5, 2.0], [0.0, 0.7]])
     ledge, redge, data = dec.decompose_array(array, np.array([2, 3, 1]), bbox)
 
+    assert_array_equal(data[1].shape, np.array([3, 2, 1]))
+
     gold_le = np.array([
                        [-0.7, 1.5, 0.0], [-0.7, 1.6, 0.0],
                        [-0.7, 1.8, 0.0], [-0.4, 1.5, 0.0],

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