summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2023-02-14 18:29:59 +0100
committerAnton Khirnov <anton@khirnov.net>2023-02-14 18:29:59 +0100
commit49c178d6e4804bc85c2e29bf6c9abff5fd5b4f63 (patch)
tree71d4189ce9693b3bb1109c27cd9056815dc5f9a7
parentfd5a437c1f34593031b23e5f42f69d102fc0b889 (diff)
utils: move code to the math_utils package
Nothing about this is axisymmetry-specific.
-rw-r--r--utils.py59
1 files changed, 3 insertions, 56 deletions
diff --git a/utils.py b/utils.py
index e16dca1..8d82f49 100644
--- a/utils.py
+++ b/utils.py
@@ -1,57 +1,4 @@
-import numpy as np
+import warnings
+warnings.warn('This module is deprecated, use math_utils.array_utils', DeprecationWarning)
-def matrix_invert(mat):
- """
- Pointwise matrix inversion.
-
- Given an array that stores many square matrices (e.g. the values of the
- metric tensor at spacetime points), compute the array of corresponding
- inverses.
-
- :param array_like mat: N-D array with N>2 and each mat[i0, ..., :, :] a
- square matrix to be inverted.
- :return: Array (same shape as mat) of inverses.
- """
- oldshape = mat.shape
- newshape = oldshape[:2] + (np.product(mat.shape[2:]),)
-
- mat = mat.reshape(newshape).transpose((2, 0, 1))
- inv = np.linalg.inv(mat)
- return inv.transpose((1, 2, 0)).reshape(oldshape)
-
-def matrix_det(mat):
- """
- Pointwise matrix determinant.
-
- Given an array that stores many square matrices (e.g. the values of the
- metric tensor at spacetime points), compute the array of corresponding
- determinants.
-
- :param array_like mat: N-D array with N>2 and each mat[i0, ..., :, :] a
- square matrix.
- :return: Array of determinants.
- """
- oldshape = mat.shape
- newshape = oldshape[:2] + (np.product(mat.shape[2:]),)
-
- mat = mat.reshape(newshape).transpose((2, 0, 1))
- return np.linalg.det(mat).reshape(oldshape[2:])
-
-def array_reflect(data, parity = 1.0, axis = -1):
- """
- Reflect an N-D array with respect to the specified axis. E.g. input
- [0, 1, 2, 3] becomes [3, 2, 1, 0, 1, 2, 3] with parity=1.0 and
- [-3, -2, -1, 0, 1, 2, 3] with parity=-1.0.
-
- :param array_like data: The array to reflect.
- :param float parity: The reflected portion is multiplied by this factor,
- typically 1.0 or -1.0.
- :param int axis: Index of the axis to reflect along.
- :return: Reflected array.
- """
- slices0 = [slice(None) for _ in data.shape]
- slices1 = [slice(None) for _ in data.shape]
- slices0[axis] = slice(None, None, -1)
- slices1[axis] = slice(1, None)
-
- return np.concatenate((parity * data[tuple(slices0)], data[tuple(slices1)]), axis)
+from math_utils.array_utils import matrix_invert, matrix_det, array_reflect