# tests for angular_difference from __future__ import absolute_import import pytest from common import function_implementations all_impls = pytest.mark.parametrize( 'angular_difference_impl, module_name', function_implementations('angular_difference')) @all_impls def test_sample1(angular_difference_impl, module_name): pass @all_impls def test_sample2(angular_difference_impl, module_name): pass
# tests for quat_distance from __future__ import absolute_import import pytest from common import function_implementations all_impls = pytest.mark.parametrize('quat_distance_impl, module_name', function_implementations('quat_distance')) @all_impls def test_sample1(quat_distance_impl, module_name): pass @all_impls def test_sample2(quat_distance_impl, module_name): pass
# tests for angles_to_gvec from __future__ import absolute_import import pytest from common import function_implementations all_impls = pytest.mark.parametrize('gvec_to_xy_impl, module_name', function_implementations('gvec_to_xy')) @all_impls def test_sample1(gvec_to_xy_impl, module_name): pass @all_impls def test_sample2(gvec_to_xy_impl, module_name): pass
# tests for angles_to_gvec from __future__ import absolute_import import pytest import numpy as np import numpy.testing as np_testing from common import function_implementations all_impls = pytest.mark.parametrize('angles_to_gvec_impl, module_name', function_implementations('angles_to_gvec')) @all_impls def test_simple_pair(angles_to_gvec_impl, module_name): bHat = np.r_[0.0, 0.0, -1.0] eHat = np.r_[1.0, 0.0, 0.0] angs = np.array([np.pi, 0.0], dtype=np.double) expected = np.r_[0.0, 0.0, 1.0] # single entry codepath res = angles_to_gvec_impl(angs, bHat, eHat) np_testing.assert_almost_equal(res, expected) # vector codepath (should return dimensions accordingly) res = angles_to_gvec_impl(np.atleast_2d(angs), bHat, eHat) np_testing.assert_almost_equal(res, np.atleast_2d(expected)) @all_impls
# tests for validate_angle_ranges from __future__ import absolute_import import pytest from common import function_implementations all_impls = pytest.mark.parametrize( 'validate_angle_ranges_impl, module_name', function_implementations('validate_angle_ranges')) @all_impls def test_sample1(validate_angle_ranges_impl, module_name): pass @all_impls def test_sample2(validate_angle_ranges_impl, module_name): pass
# tests for map_angle from __future__ import absolute_import import pytest from common import function_implementations all_impls = pytest.mark.parametrize('map_angle_impl, module_name', function_implementations('map_angle')) @all_impls def test_sample1(map_angle_impl, module_name): pass @all_impls def test_sample2(map_angle_impl, module_name): pass
# tests for make_sample_rmat from __future__ import absolute_import import pytest from numpy.testing import assert_allclose as np_assert_allclose from common import function_implementations from common import xf_cnst all_impls = pytest.mark.parametrize( 'make_sample_rmat_impl, module_name', function_implementations('make_sample_rmat')) @all_impls def test_make_sample_rmat_chi0_ome0(make_sample_rmat_impl, module_name): # when chi = 0.0 and ome = 0.0 the resulting sample rotation matrix should # be the identity chi = 0.0 ome = 0.0 result = make_sample_rmat_impl(0.0, 0.0) np_assert_allclose(xf_cnst.identity_3x3, result)
# tests for angles_in_range from __future__ import absolute_import import pytest from common import function_implementations all_impls = pytest.mark.parametrize('angles_in_range_impl, module_name', function_implementations('angles_in_range') ) @all_impls def test_sample1(angles_in_range_impl, module_name): pass @all_impls def test_sample2(angles_in_range_impl, module_name): pass
# tests for unit_vector from __future__ import absolute_import import pytest import numpy as np from numpy.testing import assert_allclose from common import function_implementations all_impls = pytest.mark.parametrize('unit_vector_impl, module_name', function_implementations('unit_vector')) def _get_random_vectors_array(): # return a (n,3) array with some vectors and a (n) array with the expected # result norms. arr = np.array([[42.0, 0.0, 0.0, 1.0], [12.0, 12.0, 12.0, 1.0], [0.0, 0.0, 0.0, 0.0], [0.7, -0.7, 0.0, 1.0], [-0.0, -0.0, -0.0, 0.0]]) return arr[:, 0:3], arr[:, 3] # ------------------------------------------------------------------------------ # trivial tests @all_impls def test_trivial(unit_vector_impl, module_name):
# tests for make_beam_rmat from __future__ import absolute_import import pytest import numpy as np from numpy.testing import assert_allclose from common import function_implementations from common import xf_cnst ATOL_IDENTITY = 1e-10 all_impls = pytest.mark.parametrize('make_beam_rmat_impl, module_name', function_implementations('make_beam_rmat')) # ------------------------------------------------------------------------------ # Test reference frame result @all_impls def test_reference_beam_rmat(make_beam_rmat_impl, module_name): """Building from the standard beam_vec and eta_vec should yield an identity matrix. This is somehow assumed in other parts of the code where using the default cnst.beam_vec and cnst.eta_vec implies an identity beam rotation matrix that is ellided in operations""" rmat = make_beam_rmat_impl(xf_cnst.beam_vec, xf_cnst.eta_vec)
import pytest import numpy as np from numpy.testing import assert_allclose from common import function_implementations from common import xf_cnst from common import ATOL_IDENTITY from common import convert_axis_angle_to_expmap from common import convert_axis_angle_to_rmat all_impls = pytest.mark.parametrize( 'make_rmat_of_expmap_impl, module_name', function_implementations('make_rmat_of_expmap')) @pytest.fixture(scope="module") def axes(): def parametric_point_in_sphere(t): # t going from -1.0 to 1.0 will form an spiral over a sphere alpha = 0.5 * t * np.pi beta = t * np.pi * 42.0 z = np.sin(alpha) o = np.cos(alpha) x = o * np.cos(beta) y = o * np.sin(beta)
# tests for xy_to_gvec from __future__ import absolute_import import pytest from common import function_implementations all_impls = pytest.mark.parametrize('xy_to_gvec_impl, module_name', function_implementations('xy_to_gvec')) @all_impls def test_sample1(xy_to_gvec_impl, module_name): pass @all_impls def test_sample2(xy_to_gvec_impl, module_name): pass
# tests for rotate_vecs_about_axis from __future__ import absolute_import import pytest from common import function_implementations all_impls = pytest.mark.parametrize( 'rotate_vecs_about_axis_impl, module_name', function_implementations('rotate_vecs_about_axis')) @all_impls def test_sample1(rotate_vecs_about_axis_impl, module_name): pass @all_impls def test_sample2(rotate_vecs_about_axis_impl, module_name): pass
# tests for solve_omega from __future__ import absolute_import import pytest from common import function_implementations all_impls = pytest.mark.parametrize('solve_omega_impl, module_name', function_implementations('solve_omega')) @all_impls def test_sample1(solve_omega_impl, module_name): pass @all_impls def test_sample2(solve_omega_impl, module_name): pass
# tests for quat_product_matrix from __future__ import absolute_import import pytest from common import function_implementations all_impls = pytest.mark.parametrize('quat_product_matrix_impl, module_name', function_implementations('quat_product_matrix')) @all_impls def test_sample1(quat_product_matrix_impl, module_name): pass @all_impls def test_sample2(quat_product_matrix_impl, module_name): pass
# tests for row_norm from __future__ import absolute_import import pytest import numpy as np from numpy.testing import assert_allclose from common import function_implementations all_impls = pytest.mark.parametrize('row_norm_impl, module_name', function_implementations('row_norm')) def _get_random_vectors_array(): # return a (n,3) array with some vectors and a (n) array with the expected # result norms. arr = np.array([[42.0, 0.0, 0.0], [12.0, 12.0, 12.0], [ 0.0, 0.0, 0.0], [ 0.7, -0.7, 0.0], [-0.0, -0.0, -0.0]]) return arr @all_impls def test_random_vectors(row_norm_impl, module_name): # checking against numpy.linalg.norm vecs = np.ascontiguousarray(_get_random_vectors_array())
# -*- mode: python; coding: utf-8 -*- # tests for make_binary_rmat from __future__ import absolute_import import pytest import numpy as np from numpy.testing import assert_allclose from common import function_implementations all_impls = pytest.mark.parametrize( 'make_binary_rmat_impl, module_name', function_implementations('make_binary_rmat')) def reference(axis): # make_binary_rmat is basically the formula: # 2Ĝ⊗Ĝ−𝑰 # its only argument being Ĝ. a0, a1, a2 = axis[0:3] result = np.empty((3, 3), dtype=np.double) result[0, 0] = 2.0 * a0 * a0 - 1.0 result[0, 1] = 2.0 * a0 * a1 result[0, 2] = 2.0 * a0 * a2 result[1, 0] = 2.0 * a1 * a0 result[1, 1] = 2.0 * a1 * a1 - 1.0 result[1, 2] = 2.0 * a1 * a2