molgri.assertions

All boolean/assertion helper functions.

This module implements helper functions that can be used by different test/other functions. The determining characteristics of all functions in this module is that they operate with booleans (either return a boolean answer or assert that a condition is true.

Example functions that belong to this module:
  • check if two quaternion sets represent the same rotation

  • check if all norms of vectors in the array are similar

  • check if given points form a square/a cube …

Functions

all_row_norms_equal_k(my_array, k[, atol, rtol])

Same as all_row_norms_similar, but also test that the norm equals k.

all_row_norms_similar(my_array[, atol, rtol])

Assert that in an 2D array each row has the same norm (up to the floating point tolerance).

all_rows_unique(my_array[, tol])

Check if all rows of the array are unique up to tol number of decimal places.

assert_two_sets_of_eulers_equal(euler1, euler2)

check_equality(arr1, arr2[, atol, rtol])

Use the numpy function np.allclose to compare two arrays and return True if they are all equal.

form_cube(my_array[, test_angles])

Similarly to form_square, check if the 8 points supplied as rows in an array form a cube.

form_square_array(my_array[, dec_places])

From an array of exactly 4 points, determine if they form a square (can be in space and not on a 2D plane).

is_array_with_d_dim_r_rows_c_columns(my_array)

Assert that the object is an array.

quaternion_in_array(quat, quat_array)

Check if a quaternion q or its equivalent complement -q is present in the quaternion array quat_array.

two_sets_of_quaternions_equal(quat1, quat2)

This test is necessary because for quaternions, q and -q represent the same rotation.

molgri.assertions.check_equality(arr1: ndarray[Any, dtype[ScalarType]], arr2: ndarray[Any, dtype[ScalarType]], atol: float | None = None, rtol: float | None = None) bool

Use the numpy function np.allclose to compare two arrays and return True if they are all equal. This function is a wrapper where I can set my preferred absolute and relative tolerance

molgri.assertions.all_row_norms_similar(my_array: ndarray[Any, dtype[ScalarType]], atol: float | None = None, rtol: float | None = None) ndarray[Any, dtype[ScalarType]]

Assert that in an 2D array each row has the same norm (up to the floating point tolerance).

Returns:

the array of norms in the same shape as my_array

molgri.assertions.all_row_norms_equal_k(my_array: ndarray[Any, dtype[ScalarType]], k: float, atol: float | None = None, rtol: float | None = None) ndarray[Any, dtype[ScalarType]]

Same as all_row_norms_similar, but also test that the norm equals k.

molgri.assertions.is_array_with_d_dim_r_rows_c_columns(my_array: ndarray[Any, dtype[ScalarType]], d: int | None = None, r: int | None = None, c: int | None = None)

Assert that the object is an array. If you specify d, r, c, it will check if this number of dimensions, rows, and/or columns are present.

molgri.assertions.all_rows_unique(my_array: ndarray[Any, dtype[ScalarType]], tol: int = 5)

Check if all rows of the array are unique up to tol number of decimal places.

molgri.assertions.form_square_array(my_array: ndarray[Any, dtype[ScalarType]], dec_places=7) bool

From an array of exactly 4 points, determine if they form a square (can be in space and not on a 2D plane).

Args:

my_array: array of shape (4, d) where d is the number of dimensions. dec_places: to how many decimal places to round when determining uniqueness

Returns:

True if points form a square, else False

molgri.assertions.form_cube(my_array: ndarray[Any, dtype[ScalarType]], test_angles=False) bool

Similarly to form_square, check if the 8 points supplied as rows in an array form a cube. The points may have >= 3 dimensions.

Args:
my_array: 2-dimensional array with 8 rows and at least 3 columns. It should be checked if the points form a

3D cube

test_angles: select True if you want a more precise test that also looks at angles

Returns:

True if points form a cube, else False

molgri.assertions.quaternion_in_array(quat: ndarray[Any, dtype[ScalarType]], quat_array: ndarray[Any, dtype[ScalarType]]) bool

Check if a quaternion q or its equivalent complement -q is present in the quaternion array quat_array.

molgri.assertions.two_sets_of_quaternions_equal(quat1: ndarray[Any, dtype[ScalarType]], quat2: ndarray[Any, dtype[ScalarType]]) bool

This test is necessary because for quaternions, q and -q represent the same rotation. You therefore cannot simply use np.allclose to check if two sets of rotations represented with quaternions are the same. This function checks if all rows of two arrays are the same up to a flipped sign.

molgri.assertions.assert_two_sets_of_eulers_equal(euler1: ndarray[Any, dtype[ScalarType]], euler2: ndarray[Any, dtype[ScalarType]])