Download 44.py from TestCaseGeneration/NumFEM_Eval: direct link, hf CLI and curl.
- Browser
- Download file 938 Bytes
-
https://huggingface.co/datasets/TestCaseGeneration/NumFEM_Eval/resolve/main/44.py
- Command line
-
hf download hf://datasets/TestCaseGeneration/NumFEM_Eval/44.py
-
curl -L -o 44.py https://huggingface.co/datasets/TestCaseGeneration/NumFEM_Eval/resolve/main/44.py
938 Bytes
| import numpy as np | |
| from numpy import zeros, ndarray, array, sum, dot, maximum, tensordot | |
| from numpy.linalg import inv, norm, eig | |
| def inverse(qp_jacobis: ndarray, qp_jacobi_dets: ndarray) -> ndarray: | |
| qp_jacobi_invs = [] | |
| for A, det_A in zip(qp_jacobis, qp_jacobi_dets): | |
| if A.shape == (2, 2): | |
| qp_jacobi_invs.append(array([[A[1][1], -A[0][1]], [-A[1][0], A[0][0]]]) / det_A) | |
| elif A.shape == (3, 3): | |
| qp_jacobi_invs.append(array([[(A[1][1] * A[2][2] - A[1][2] * A[2][1]), (A[0][2] * A[2][1] - A[0][1] * A[2][2]), (A[0][1] * A[1][2] - A[0][2] * A[1][1])], [(A[1][2] * A[2][0] - A[1][0] * A[2][2]), (A[0][0] * A[2][2] - A[0][2] * A[2][0]), (A[0][2] * A[1][0] - A[0][0] * A[1][2])], [(A[1][0] * A[2][1] - A[1][1] * A[2][0]), (A[0][1] * A[2][0] - A[0][0] * A[2][1]), (A[0][0] * A[1][1] - A[0][1] * A[1][0])]]) / det_A) | |
| else: | |
| return inv(qp_jacobis) | |
| return array(qp_jacobi_invs) |