[yt-svn] commit/yt: 5 new changesets
Bitbucket
commits-noreply at bitbucket.org
Fri Oct 12 12:45:32 PDT 2012
5 new commits in yt:
https://bitbucket.org/yt_analysis/yt/changeset/703e12b8ae1b/
changeset: 703e12b8ae1b
branch: yt
user: sskory
date: 2012-10-11 23:03:59
summary: Adding a couple simple kdtree tests.
affected #: 1 file
diff -r 71fc69a95b0d9b68723ebec67a7e4684f9eab725 -r 703e12b8ae1b7ac6daedf1f8f552ac1f386d7644 yt/utilities/tests/test_kdtrees.py
--- /dev/null
+++ b/yt/utilities/tests/test_kdtrees.py
@@ -0,0 +1,91 @@
+"""
+Unit test the kD trees in yt.
+
+Author: Stephen Skory <s at skory.us>
+Affiliation: U of Colorado
+Homepage: http://yt-project.org/
+License:
+ Copyright (C) 2008-2011 Stephen Skory. 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 *
+
+try:
+ from yt.utilities.kdtree import \
+ chainHOP_tags_dens, \
+ create_tree, fKD, find_nn_nearest_neighbors, \
+ free_tree, find_chunk_nearest_neighbors
+except ImportError:
+ mylog.debug("The Fortran kD-Tree did not import correctly.")
+
+from yt.utilities.spatial import cKDTree
+
+def setup():
+ pass
+
+def test_fortran_tree():
+ # This test makes sure that the fortran kdtree is finding the correct
+ # nearest neighbors.
+ # Four points.
+ fKD.pos = np.empty((3, 4), dtype='float64', order='F')
+ # Make four points by hand that, in particular, will allow us to test
+ # the periodicity of the kdtree.
+ points = np.array([0.01, 0.5, 0.98, 0.99])
+ fKD.pos[0, :] = points
+ fKD.pos[1, :] = points
+ fKD.pos[2, :] = points
+ fKD.qv = np.empty(3, dtype='float64')
+ fKD.dist = np.empty(4, dtype='float64')
+ fKD.tags = np.empty(4, dtype='int64')
+ fKD.nn = 4
+ fKD.sort = True
+ create_tree(0)
+ # Now we check to make sure that we find the correct nearest neighbors,
+ # which get stored in dist and tags.
+ fKD.qv[:] = 0.999
+ find_nn_nearest_neighbors()
+ # Fix fortran counting.
+ fKD.tags -= 1
+ # Clean up before the tests.
+ free_tree(0)
+ # What the answers should be.
+ dist = np.array([2.43e-04, 3.63e-04, 1.083e-03, 7.47003e-01])
+ tags = np.array([3, 0, 2, 1], dtype='int64')
+ assert_array_almost_equal(fKD.dist, dist)
+ assert_array_almost_equal(fKD.tags, tags)
+
+def test_cython_tree():
+ # This test makes sure that the fortran kdtree is finding the correct
+ # nearest neighbors.
+ # Four points.
+ pos = np.empty((4, 3), dtype='float64')
+ # Make four points by hand that, in particular, will allow us to test
+ # the periodicity of the kdtree.
+ points = np.array([0.01, 0.5, 0.98, 0.99])
+ pos[:, 0] = points
+ pos[:, 1] = points
+ pos[:, 2] = points
+ kdtree = cKDTree(pos, leafsize = 2)
+ qv = np.array([0.999]*3)
+ res = kdtree.query(qv, 4, period=[1.,1.,1])
+ # What the answers should be.
+ dist = np.array([2.43e-04, 3.63e-04, 1.083e-03, 7.47003e-01])
+ tags = np.array([3, 0, 2, 1], dtype='int64')
+ assert_array_almost_equal(res[0], dist)
+ assert_array_almost_equal(res[1], tags)
+
https://bitbucket.org/yt_analysis/yt/changeset/f7efbe35f121/
changeset: f7efbe35f121
branch: yt
user: sskory
date: 2012-10-11 23:06:20
summary: These asserts really should test for perfect match.
affected #: 1 file
diff -r 703e12b8ae1b7ac6daedf1f8f552ac1f386d7644 -r f7efbe35f121bfd31c9c24a8c7284ed0bb291b41 yt/utilities/tests/test_kdtrees.py
--- a/yt/utilities/tests/test_kdtrees.py
+++ b/yt/utilities/tests/test_kdtrees.py
@@ -67,7 +67,7 @@
dist = np.array([2.43e-04, 3.63e-04, 1.083e-03, 7.47003e-01])
tags = np.array([3, 0, 2, 1], dtype='int64')
assert_array_almost_equal(fKD.dist, dist)
- assert_array_almost_equal(fKD.tags, tags)
+ assert_array_equal(fKD.tags, tags)
def test_cython_tree():
# This test makes sure that the fortran kdtree is finding the correct
@@ -87,5 +87,5 @@
dist = np.array([2.43e-04, 3.63e-04, 1.083e-03, 7.47003e-01])
tags = np.array([3, 0, 2, 1], dtype='int64')
assert_array_almost_equal(res[0], dist)
- assert_array_almost_equal(res[1], tags)
+ assert_array_equal(res[1], tags)
https://bitbucket.org/yt_analysis/yt/changeset/76ab79a5ae9a/
changeset: 76ab79a5ae9a
branch: yt
user: sskory
date: 2012-10-11 23:09:21
summary: Typo.
affected #: 1 file
diff -r f7efbe35f121bfd31c9c24a8c7284ed0bb291b41 -r 76ab79a5ae9af5a5b062b49907bf85fc95e6bf0c yt/utilities/tests/test_kdtrees.py
--- a/yt/utilities/tests/test_kdtrees.py
+++ b/yt/utilities/tests/test_kdtrees.py
@@ -70,7 +70,7 @@
assert_array_equal(fKD.tags, tags)
def test_cython_tree():
- # This test makes sure that the fortran kdtree is finding the correct
+ # This test makes sure that the cython kdtree is finding the correct
# nearest neighbors.
# Four points.
pos = np.empty((4, 3), dtype='float64')
https://bitbucket.org/yt_analysis/yt/changeset/060e5f55da16/
changeset: 060e5f55da16
branch: yt
user: sskory
date: 2012-10-12 16:34:57
summary: Updating kdtree test.
affected #: 2 files
diff -r 76ab79a5ae9af5a5b062b49907bf85fc95e6bf0c -r 060e5f55da1631db50f96a6f2bc251026d6dc70f yt/testing.py
--- a/yt/testing.py
+++ b/yt/testing.py
@@ -24,7 +24,9 @@
import numpy as np
from yt.funcs import *
-from numpy.testing import assert_array_equal
+from numpy.testing import assert_array_equal, assert_almost_equal, \
+ assert_approx_equal, assert_array_almost_equal, assert_equal, \
+ assert_string_equal
def amrspace(extent, levels=7, cells=8):
"""Creates two numpy arrays representing the left and right bounds of
diff -r 76ab79a5ae9af5a5b062b49907bf85fc95e6bf0c -r 060e5f55da1631db50f96a6f2bc251026d6dc70f yt/utilities/tests/test_kdtrees.py
--- a/yt/utilities/tests/test_kdtrees.py
+++ b/yt/utilities/tests/test_kdtrees.py
@@ -39,10 +39,14 @@
pass
def test_fortran_tree():
- # This test makes sure that the fortran kdtree is finding the correct
- # nearest neighbors.
+ r"""This test makes sure that the fortran kdtree is finding the correct
+ nearest neighbors.
+ """
# Four points.
- fKD.pos = np.empty((3, 4), dtype='float64', order='F')
+ try:
+ fKD.pos = np.empty((3, 4), dtype='float64', order='F')
+ except NameError:
+ retur1n
# Make four points by hand that, in particular, will allow us to test
# the periodicity of the kdtree.
points = np.array([0.01, 0.5, 0.98, 0.99])
@@ -70,8 +74,9 @@
assert_array_equal(fKD.tags, tags)
def test_cython_tree():
- # This test makes sure that the cython kdtree is finding the correct
- # nearest neighbors.
+ r"""This test makes sure that the cython kdtree is finding the correct
+ nearest neighbors.
+ """
# Four points.
pos = np.empty((4, 3), dtype='float64')
# Make four points by hand that, in particular, will allow us to test
https://bitbucket.org/yt_analysis/yt/changeset/c3d373a809fd/
changeset: c3d373a809fd
branch: yt
user: sskory
date: 2012-10-12 16:37:09
summary: Typo.
affected #: 1 file
diff -r 060e5f55da1631db50f96a6f2bc251026d6dc70f -r c3d373a809fd0b21e02a229bc645e122d7ee4cf2 yt/utilities/tests/test_kdtrees.py
--- a/yt/utilities/tests/test_kdtrees.py
+++ b/yt/utilities/tests/test_kdtrees.py
@@ -46,7 +46,7 @@
try:
fKD.pos = np.empty((3, 4), dtype='float64', order='F')
except NameError:
- retur1n
+ return
# Make four points by hand that, in particular, will allow us to test
# the periodicity of the kdtree.
points = np.array([0.01, 0.5, 0.98, 0.99])
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