pyxfem.core.smallsize_tensor module
This module i s dedicated to implement faster functionnality for tensor on spaces of dim 2 and 3 than the equivalent numpy call Created on May1 2024 @author: nchevaug
- pyxfem.core.smallsize_tensor.AAT22(A: ndarray, out=None) ndarray[source]
Compute A @ A^T for batches of 2x2 matrices via Numba guvectorize.
- Parameters:
A (np.ndarray) – Array of matrices of shape (…, 2, 2).
out (np.ndarray, optional) – Destination buffer. Defaults to None.
- Returns:
Symmetric matrix products of shape (…, 2, 2).
- Return type:
np.ndarray
- pyxfem.core.smallsize_tensor.AAT22_guvec(A: ndarray, out=None) ndarray[source]
Compute A @ A^T for batches of 2x2 matrices via Numba guvectorize.
- Parameters:
A (np.ndarray) – Array of matrices of shape (…, 2, 2).
out (np.ndarray, optional) – Destination buffer. Defaults to None.
- Returns:
Symmetric matrix products of shape (…, 2, 2).
- Return type:
np.ndarray
- pyxfem.core.smallsize_tensor.AAT22_kernel(A22, out)[source]
Numba kernel computing A @ A^T for an individual 2x2 matrix.
- Parameters:
A22 (ndarray) – Single 2x2 matrix slice.
out (ndarray) – Output 2x2 buffer.
- pyxfem.core.smallsize_tensor.axpy(alpha, x, y, parallel=False)[source]
Compute the scaled vector addition y = y + alpha * x.
- Parameters:
alpha (float or scalar) – Scalar scaling factor.
x (ndarray) – Input array.
y (ndarray) – Target array modified in place.
parallel (bool, optional) – If True, executes the multithreaded Numba implementation axpy_pnjit. Defaults to False.
- pyxfem.core.smallsize_tensor.axpy_pnjit(alpha, x, y)[source]
Compute vector scale-and-add operation in parallel using Numba.
Evaluates the in-place operation y[j] += alpha * x[j] over the first axis.
- Parameters:
alpha (float or scalar) – Scalar multiplier.
x (ndarray) – Input array.
y (ndarray) – Output array modified in place.
- pyxfem.core.smallsize_tensor.check_df(f, df, x, ifshape, ixshape, verbose=False)[source]
Verify an analytical derivative against finite-difference approximation.
- Parameters:
f (Callable) – Original function.
df (Callable) – Analytical derivative function.
x (FloatArray) – Evaluation inputs.
ifshape (tuple of int) – Output shape of f for a single input item.
ixshape (tuple of int) – Input shape for a single item.
verbose (bool, optional) – If True, prints verification mismatch details. Defaults to False.
- Returns:
True if the analytical and numerical gradients agree, False otherwise.
- Return type:
bool
- pyxfem.core.smallsize_tensor.check_relerr(ref: NDArray[float64] | float64, val: NDArray[float64] | float64, innershape, reltol: float = 0.0001, abstol: float = 1e-05, checkname: str = '', verbose: bool = True) bool[source]
Compare two tensor arrays elementwise using absolute and relative error tolerances.
- Parameters:
ref (FloatArray or npfloat) – Reference ground-truth values.
val (FloatArray or npfloat) – Computed values to validate.
innershape (tuple of int) – Shape of each tensor element inside the collection.
reltol (float, optional) – Maximum allowed relative error. Defaults to 1e-4.
abstol (float, optional) – Maximum allowed absolute error. Defaults to 1e-5.
checkname (str, optional) – Name or label describing the test. Defaults to “”.
verbose (bool, optional) – If True, prints detailed diagnostics upon failure. Defaults to True.
- Returns:
True if all slices pass within error tolerances, False otherwise.
- Return type:
bool
- pyxfem.core.smallsize_tensor.cofac(A: NDArray[float64]) NDArray[float64]
compute cofac matrix for stack of 2x2 or 3x3 matrices
- pyxfem.core.smallsize_tensor.contract(A: NDArray[float64], B: NDArray[float64]) NDArray[float64][source]
Compute the double contraction (Frobenius inner product) A : B = A_{ij} B_{ij}.
- Parameters:
A (FloatArray) – First batch of tensors of shape (…, M, N).
B (FloatArray) – Second batch of tensors of matching shape (…, M, N).
- Returns:
Contracted scalar field of shape (…).
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.cross(A: NDArray[float64], B: NDArray[float64]) NDArray[float64][source]
Compute the 3D vector cross product between arrays of vectors.
- Parameters:
A (FloatArray) – First collection of 3D vectors of shape (…, 3).
B (FloatArray) – Second collection of 3D vectors of shape (…, 3).
- Returns:
Cross product vector array of shape (…, 3).
- Return type:
FloatArray
- Raises:
ValueError – If the trailing dimension of A or B is not 3.
- pyxfem.core.smallsize_tensor.cross_ijkl(A: NDArray[float64], B: NDArray[float64]) NDArray[float64]
Compute the fourth-order tensor outer product C_{ijkl} = A_{ij} * B_{kl}.
- Parameters:
A (FloatArray) – First second-order tensor batch of shape (…, N, N).
B (FloatArray) – Second second-order tensor batch of shape (…, N, N).
- Returns:
Fourth-order tensor batch of shape (…, N, N, N, N).
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.cross_ikjl(A: NDArray[float64], B: NDArray[float64]) NDArray[float64][source]
Compute the fourth-order tensor product with index permutation C_{ijkl} = A_{ik} * B_{jl}.
- Parameters:
A (FloatArray) – First second-order tensor batch of shape (…, N, N).
B (FloatArray) – Second second-order tensor batch of shape (…, N, N).
- Returns:
Fourth-order tensor batch of shape (…, N, N, N, N).
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.cross_iklj(A: NDArray[float64], B: NDArray[float64]) NDArray[float64][source]
Compute the fourth-order tensor product with index permutation C_{ijkl} = A_{ik} * B_{lj}.
- Parameters:
A (FloatArray) – First second-order tensor batch of shape (…, N, N).
B (FloatArray) – Second second-order tensor batch of shape (…, N, N).
- Returns:
Fourth-order tensor batch of shape (…, N, N, N, N).
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.cross_iljk(A: NDArray[float64], B: NDArray[float64]) NDArray[float64][source]
Compute the fourth-order tensor product with index permutation C_{ijkl} = A_{il} * B_{jk}.
- Parameters:
A (FloatArray) – First second-order tensor batch of shape (…, N, N).
B (FloatArray) – Second second-order tensor batch of shape (…, N, N).
- Returns:
Fourth-order tensor batch of shape (…, N, N, N, N).
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.cross_ilkj(A: NDArray[float64], B: NDArray[float64]) NDArray[float64][source]
Compute the fourth-order tensor product with index permutation C_{ijkl} = A_{il} * B_{kj}.
- Parameters:
A (FloatArray) – First second-order tensor batch of shape (…, N, N).
B (FloatArray) – Second second-order tensor batch of shape (…, N, N).
- Returns:
Fourth-order tensor batch of shape (…, N, N, N, N).
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.cross_likj(A: NDArray[float64], B: NDArray[float64]) NDArray[float64][source]
Compute the fourth-order tensor product with index permutation C_{ijkl} = A_{li} * B_{kj}.
- Parameters:
A (FloatArray) – First second-order tensor batch of shape (…, N, N).
B (FloatArray) – Second second-order tensor batch of shape (…, N, N).
- Returns:
Fourth-order tensor batch of shape (…, N, N, N, N).
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.d2invariants2Dto3D(invariant2D)[source]
- Compute the matrix of the second derivatives of the 3D invariants of tensor A (Hessian)
computed as a function of the 2D invariants. input invariant2D an FloatArray of shape[-1] = 3 where : invariant2D[…, 0] = I2D = trace(A2D) invariant2D[…, 1] = II2D = det(A2D) = 0.5*(trace(A2D)**2 - trace(A2D@A2D**2) invariant2D[…, 2] = A33 return dinvariant3D an FNDarray of shape (…, 3, 3, 3) where dinvariant3D[…, i, j, k] contain the derivative of the ith 3d invarariant with regard to the jth 2d invariant and the kth 2d invarariant. Note that the resuluting 27 component matrix contain only 4 non zero terms …
- Parameters:
invariant2D (ndarray) – Array of shape (…, 3) holding [I_2D, II_2D, lambda_2].
- Returns:
Second derivative tensor of shape (…, 3, 3, 3) containing d^2(I_3D, i) / (d(I_2D, j) d(I_2D, k)).
- Return type:
ndarray
- pyxfem.core.smallsize_tensor.d2metric(F: NDArray[float64]) NDArray[float64][source]
Compute the second derivative of the metric tensor m with respect to F.
Returns the constant sixth-order tensor R[…, a, b, i, c, j, d] = d^2 m_{ab} / (dF_{ic} dF_{jd}).
- Parameters:
F (FloatArray) – Transformation tensor of shape (…, dim_out, dim_in).
- Returns:
Sixth-order tensor of shape (…, dim_in, dim_in, dim_out, dim_in, dim_out, dim_in).
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.ddet(A: NDArray[float64]) NDArray[float64][source]
Compute the derivative of the determinant with respect to the matrix A.
Returns d(det(A)) / dA = cofac(A) for square matrices, or det(A) * A^{-T}.
- Parameters:
A (FloatArray) – Input tensor collection of shape (…, M, N).
- Returns:
Derivative array having the identical shape of A.
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.det(A: NDArray[float64], out: None | NDArray[float64] = None) NDArray[float64] | float64
Compute the determinant for batches of 2x2, 3x3, or 3x2 (metric surface) matrices.
- Parameters:
A (FloatArray) – Matrix or batch of matrices of shape (…, 2, 2), (…, 3, 3), or (…, 3, 2).
out (FloatArray or None, optional) – Pre-allocated output destination buffer. Defaults to None.
- Returns:
Determinants array of shape (…). For 3x2, returns sqrt(det(F^T F)).
- Return type:
FloatArray or npfloat
- Raises:
ValueError – If matrix dimensions are not supported.
- pyxfem.core.smallsize_tensor.det_invt(A: NDArray[float64]) Tuple[NDArray[float64] | float64, NDArray[float64]][source]
Compute both the determinant and the inverse-transpose A^{-T} simultaneously.
Also handles the 3x2 membrane configuration where A^{-T} is computed as A @ (A^T A)^{-1}.
- Parameters:
A (FloatArray) – Tensor array of shape (…, 2, 2), (…, 3, 3), or (…, 3, 2).
- Returns:
Tuple (detA, invAT) containing determinants and inverse-transposed matrices.
- Return type:
tuple of (FloatArray or npfloat, FloatArray)
- Raises:
ValueError – If trailing dimensions are not (2, 2), (3, 3), or (3, 2).
- pyxfem.core.smallsize_tensor.df_num(f: Callable[[NDArray[float64]], NDArray[float64] | float], A_in: NDArray[float64] | float, shape_iA: tuple[int, ...], shape_ifA: tuple[int, ...]) NDArray[float64][source]
Compute numerical Jacobian derivatives of tensor functions via finite differences.
Uses scipy.optimize.approx_fprime iteratively over batch dimensions.
- Parameters:
f (Callable[[FloatArray], FloatArray or float]) – Tensor function to differentiate.
A_in (FloatArray or float) – Evaluation point or batch of evaluation points.
shape_iA (tuple of int) – Shape of a single input argument to f.
shape_ifA (tuple of int) – Shape of a single output evaluation from f.
- Returns:
Numerical derivative tensor of shape shape_coll + shape_ifA + shape_iA.
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.dinv(A: NDArray[float64], iA: NDArray[float64] | None = None) NDArray[float64][source]
Compute the derivative of the inverse matrix with respect to A.
Returns R[…, i, j, k, l] = d(A^{-1}_{ij}) / dA_{kl}.
- Parameters:
A (FloatArray) – Tensor collection of shape (…, 2, 2), (…, 3, 3), or (…, 3, 2).
iA (FloatArray or None, optional) – Precalculated inverse of A. Defaults to None.
- Returns:
Fourth-order derivative tensor.
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.dinv_sym(A, iA=None) NDArray[float64][source]
Compute the derivative of A^{-1} with respect to A assuming A is symmetric.
- Parameters:
A (FloatArray) – Symmetric tensor collection of shape (…, 2, 2) or (…, 3, 3).
iA (FloatArray or None, optional) – Precomputed inverse of A. Defaults to None.
- Returns:
Symmetric fourth-order derivative tensor.
- Return type:
FloatArray
- Raises:
ValueError – If trailing dimensions are not (2, 2) or (3, 3).
- pyxfem.core.smallsize_tensor.dinvariants(A: NDArray[float64]) NDArray[float64][source]
Compute derivatives of principal invariants with respect to tensor A.
- Parameters:
A (FloatArray) – Square tensor collection of shape (…, 2, 2) or (…, 3, 3).
- Returns:
Derivatives tensor of shape (…, 2, 2, 2) for 2D or (…, 3, 3, 3) for 3D.
- Return type:
FloatArray
- Raises:
ValueError – If trailing dimensions are not (2, 2) or (3, 3).
- pyxfem.core.smallsize_tensor.dinvariants2Dto3D(invariant2D: NDArray[float64]) NDArray[float64][source]
- Compute the matrix of the derivatives of the 3D invariants of tensor A
computed as a function of the 2D invariant. input invariant2D an FloatArray of shape[-1] = 3 where : invariant2D[…, 0] = I2D = trace(A2D) invariant2D[…, 1] = II2D = det(A2D) = 0.5*(trace(A2D)**2 - trace(A2D@A2D**2) invariant2D[…, 2] = A33 return dinvariant3D an FNDarray of shape (…, 3, 3) where dinvariant3D[…, i, j] contain the derivative of the ith 3d invarariant with regard to the jth 2d invariant Parameters
- Returns:
Jacobian tensor of shape (…, 3, 3) where entry […, i, j] is d(I_3D, i) / d(I_2D, j).
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.dinvmetric(F)[source]
Compute the derivative of the inverse metric tensor with respect to F.
Evaluates d(m^{-1})_{ab} / dF_{ic}.
- Parameters:
F (FloatArray) – Transformation tensor of shape (…, M, N).
- Returns:
Fourth-order derivative tensor of shape (…, N, N, M, N).
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.dinvt(F, iFT=None, im=None, dimdF=None) NDArray[float64][source]
Compute the derivative of the inverse-transpose tensor F^{-T} with respect to F.
- Parameters:
F (FloatArray) – Input deformation tensor of shape (…, 2, 2), (…, 3, 3), or (…, 3, 2).
iFT (FloatArray, optional) – Precomputed F^{-T}. Defaults to None.
im (FloatArray, optional) – Precomputed inverse metric (F^T F)^{-1} for 3x2 tensors. Defaults to None.
dimdF (FloatArray, optional) – Precomputed derivative of the inverse metric. Defaults to None.
- Returns:
Fourth-order derivative tensor.
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.dmetric(F: NDArray[float64]) NDArray[float64][source]
Compute the first derivative of the metric tensor m = F^T @ F with respect to F.
Returns the fourth-order tensor R[…, a, b, i, c] = dm_{ab} / dF_{ic}.
- Parameters:
F (FloatArray) – Transformation tensor of shape (…, dim_out, dim_in).
- Returns:
Fourth-order gradient tensor collection of shape (…, dim_in, dim_in, dim_out, dim_in).
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.eigval22sym(A: NDArray[float64])[source]
Compute analytical eigenvalues for a batch of symmetric 2x2 matrices.
- Parameters:
A (FloatArray) – Collection of symmetric 2x2 matrices of shape (…, 2, 2).
- Returns:
Eigenvalues array of shape (…, 2) with entries […, 0] (max) and […, 1] (min).
- Return type:
FloatArray
- Raises:
ValueError – If trailing dimensions are not (2, 2) or matrices have negative discriminant.
- pyxfem.core.smallsize_tensor.gemm22(A: NDArray[float64], B: NDArray[float64], out: NDArray[float64] | None = None) NDArray[float64][source]
Compute matrix-matrix products C = A @ B for batches of 2x2 matrices.
Optimized for zero heap reallocations using views and in-place accumulations.
- Parameters:
A (FloatArray) – First batch of 2x2 matrices of shape (…, 2, 2).
B (FloatArray) – Second batch of 2x2 matrices of shape (…, 2, 2).
out (FloatArray, optional) – Preallocated array receiving the result. Defaults to None.
- Returns:
Matrix product array of shape (…, 2, 2).
- Return type:
FloatArray
- Raises:
ValueError – If trailing dimensions are not (2, 2).
- pyxfem.core.smallsize_tensor.gemm22_kernel_njit(A: NDArray[float64], B: NDArray[float64], out: NDArray[float64])[source]
Inlined Numba scalar kernel computing the product of two 2x2 matrices.
- Parameters:
A (FloatArray) – 2x2 left-hand matrix slice.
B (FloatArray) – 2x2 right-hand matrix slice.
out (FloatArray) – 2x2 destination buffer.
- pyxfem.core.smallsize_tensor.inv(A: NDArray[float64], detA: NDArray[float64] | float64 | None = None, out: NDArray[float64] | None = None) NDArray[float64][source]
compute inverse matrix for stack of 2x2 or 3x3 matrices
- pyxfem.core.smallsize_tensor.invariants(A: NDArray[float64]) NDArray[float64][source]
Compute principal invariants for a batch of 2D or 3D second-order tensors.
For 2D: [tr(A), det(A)]. For 3D: [tr(A), 0.5 * (tr(A)^2 - tr(A^T A)), det(A)].
- Parameters:
A (FloatArray) – Square tensor collection of shape (…, 2, 2) or (…, 3, 3).
- Returns:
Invariants array with trailing dimension 2 (for 2D) or 3 (for 3D).
- Return type:
FloatArray
- Raises:
ValueError – If trailing dimensions are not (2, 2) or (3, 3).
- pyxfem.core.smallsize_tensor.invariants2Dto3D(invariant2D)[source]
- from the invariant of a “2.5d tensor”, compute the invariants of the equivalent 3D tensor
what I mean by a 2.5d tensor is for example the gradiant of the transformation in plan stress case :
F = F2D_{a,b} e_a x e_b + l2 e_2 x e_2 , where a, b in [0,1] and e_2 = e_0 vec e_1
the invarariant 2D are strored in a (…, 3) ndarray, where invariant2D[…, 0] is an array containing I(F2D) = trace(F2D) invariant2D[…, 1] is an array containing
II(F2D) = 0.5(trace(F2D)^2 - trace(F2D.T@F2D)) = det(F2D)
invariant2D[…, 2] is an array containing l2
- Parameters:
invariant2D (ndarray) – Array of shape (…, 3) containing: - […, 0]: I_2D = trace(F_2D) - […, 1]: II_2D = det(F_2D) - […, 2]: lambda_2 (out-of-plane stretch)
- Returns:
Array of shape (…, 3) with the three corresponding 3D invariants.
- Return type:
ndarray
- pyxfem.core.smallsize_tensor.invmetric(F: NDArray[float64]) NDArray[float64][source]
Compute the inverse of the metric tensor m = F^T @ F.
- Parameters:
F (FloatArray) – Transformation tensor of shape (…, M, N).
- Returns:
Inverse metric tensor array of shape (…, N, N).
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.invt(A: NDArray[float64], detA: NDArray[float64] | float64 | None = None) NDArray[float64][source]
Compute the inverse-transpose (or pseudo-inverse transpose) of a batch of matrices.
- Parameters:
A (FloatArray) – Tensor array of shape (…, 2, 2), (…, 3, 3), or (…, 3, 2).
detA (FloatArray or npfloat, optional) – Precomputed determinant. Defaults to None.
- Returns:
Inverse transposed matrices of shape (…, N, M).
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.max_eigval22sym(A: NDArray[float64], outlmax: NDArray[float64] | None = None)[source]
Compute the maximum eigenvalue for a batch of symmetric 2x2 matrices.
- Parameters:
A (FloatArray) – Batch of symmetric 2x2 matrices of shape (…, 2, 2).
outlmax (FloatArray, optional) – Output buffer receiving eigenvalues. Defaults to None.
- Returns:
Maximum eigenvalues array of shape (…).
- Return type:
FloatArray
- Raises:
ValueError – If trailing dimensions are not (2, 2) or matrices have negative discriminant.
- pyxfem.core.smallsize_tensor.max_eigval22sym_kernel_njit(A: NDArray[float64])[source]
Numba scalar kernel computing the maximum eigenvalue of a single symmetric 2x2 matrix.
- Parameters:
A (FloatArray) – 2x2 symmetric matrix slice.
- Returns:
Maximum eigenvalue.
- Return type:
float
- Raises:
ValueError – If the discriminant is negative.
- pyxfem.core.smallsize_tensor.metric(F: NDArray[float64]) NDArray[float64][source]
Compute the right Cauchy-Green deformation tensor / Riemannian metric C = F^T @ F.
- Parameters:
F (FloatArray) – Deformation gradient or transformation tensor of shape (…, M, N).
- Returns:
Metric tensor array of shape (…, N, N).
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.random_lintransform(n: int, dim: int, random_state=Generator(PCG64) at 0x7F597B9AF300) NDArray[float64][source]
Generate a batch of random linear transformation tensors with det(F) >= 0.
Filters near-singular transformations (|det| < 1e-2) and reflects tensors with negative determinants to enforce orientation preservation.
- Parameters:
n (int) – Number of transformation matrices.
dim (int) – Matrix dimension (e.g., 2 or 3).
random_state (np.random.Generator, optional) – Random number generator instance. Defaults to np.random.default_rng().
- Returns:
Array of transformation matrices of shape (n, dim, dim).
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.random_lintransform2dto3d(n: int, random_state=Generator(PCG64) at 0x7F597B9AF220) NDArray[float64][source]
Generate random transformation matrices F mapping 2D vectors to 3D space.
- Parameters:
n (int) – Number of transformations.
random_state (np.random.Generator, optional) – Random number generator instance. Defaults to np.random.default_rng().
- Returns:
Array of matrices of shape (n, 3, 2).
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.random_orthtransform(n: int, dim: ~typing.Literal[2, 3], random_state=Generator(PCG64) at 0x7F59A8869B60) NDArray[float64][source]
Generate a batch of random orthogonal transformation matrices with det(Q) >= 0.
- Parameters:
n (int) – Number of orthogonal transformations to generate.
dim ({2, 3}) – Spatial dimension (2 for planar rotations, 3 for 3D rotations via orthonormal bases).
random_state (np.random.Generator, optional) – Random number generator instance. Defaults to np.random.default_rng().
- Returns:
Array of shape (n, dim, dim) containing proper orthogonal rotation matrices.
- Return type:
FloatArray
- pyxfem.core.smallsize_tensor.sqrt22(A, out=None)[source]
Compute square roots for a batch of 2x2 matrices (dispatcher).
- Parameters:
A (np.ndarray) – Array of matrices of shape (…, 2, 2).
out (np.ndarray, optional) – Destination buffer. Defaults to None.
- Returns:
Tensor square root array.
- Return type:
np.ndarray
- pyxfem.core.smallsize_tensor.sqrt22_guvec(A: ndarray, out=None) ndarray[source]
Compute tensor square roots of 2x2 matrices using Numba guvectorize.
- Parameters:
A (np.ndarray) – Array of matrices of shape (…, 2, 2).
out (np.ndarray, optional) – Preallocated destination array. Defaults to None.
- Returns:
Tensor square roots of shape (…, 2, 2).
- Return type:
np.ndarray
- Raises:
ValueError – If trailing dimensions are not (2, 2).
- pyxfem.core.smallsize_tensor.sqrt22_kernel(A22, out)[source]
Numba scalar kernel computing the square root of an individual 2x2 matrix.
- Parameters:
A22 (ndarray) – Single 2x2 matrix slice.
out (ndarray) – Output 2x2 buffer receiving the result.
- pyxfem.core.smallsize_tensor.sqrt22_njit(A: ndarray, out=None) ndarray[source]
Calcule la racine carrée d’un batch de tenseurs 2x2. A = B.B Compute tensor square roots of 2x2 matrices using multithreaded Numba NJIT.
- Parameters:
A (np.ndarray) – C-contiguous array of matrices of shape (…, 2, 2).
out (np.ndarray, optional) – Preallocated destination array. Defaults to None.
- Returns:
Tensor square roots of shape (…, 2, 2).
- Return type:
np.ndarray
- Raises:
ValueError – If A is not C-contiguous or its shape is not (…, 2, 2).
- pyxfem.core.smallsize_tensor.sqrt22_numpy(A: ndarray, out=None) ndarray[source]
Compute tensor square roots of 2x2 matrices using vectorized NumPy views.
- Parameters:
A (np.ndarray) – Array of 2x2 matrices of shape (…, 2, 2).
out (np.ndarray, optional) – Output buffer modified in place. Defaults to None.
- Returns:
Tensor square roots of shape (…, 2, 2).
- Return type:
np.ndarray
- Raises:
ValueError – If trailing dimensions are not (2, 2).
- pyxfem.core.smallsize_tensor.sysmv22(A: NDArray[float64], b: NDArray[float64], out: NDArray[float64] | None = None, parallel=False) NDArray[float64][source]
Solves the linear system $A x = b$ for a symmetric 2x2 matrix using explicit Cramer’s rule inversion. Math: $x = A^{-1} b$
- Parameters:
A (FloatArray) – Batch of symmetric 2x2 matrices of shape (…, 2, 2).
b (FloatArray) – Right-hand side vectors of shape (…, 2).
out (FloatArray, optional) – Preallocated output buffer. Defaults to None.
parallel (bool, optional) – If True, evaluates using multithreaded OpenMP-style execution. Defaults to False.
- Returns:
Solution vectors of shape (…, 2).
- Return type:
FloatArray
- Raises:
ValueError – If trailing dimensions of A are not (2, 2).
- pyxfem.core.smallsize_tensor.sysmv22_kernel(A: NDArray[float64], b: NDArray[float64], out: NDArray[float64])[source]
Solve a single symmetric 2x2 linear system A @ x = b via Cramer’s rule.
- Parameters:
A (FloatArray) – Symmetric 2x2 matrix.
b (FloatArray) – Right-hand side 2D vector.
out (FloatArray) – Output 2D vector receiving solution x.
- pyxfem.core.smallsize_tensor.sysmv22_pnjit(A: NDArray[float64], b: NDArray[float64], out: NDArray[float64])[source]
Parallel Numba kernel solving batches of symmetric 2x2 systems A @ x = b.
- Parameters:
A (FloatArray) – Batch of 2x2 matrices of shape (N, 2, 2).
b (FloatArray) – Batch of right-hand side vectors of shape (N, 2).
out (FloatArray) – Output buffer receiving solutions of shape (N, 2).
- pyxfem.core.smallsize_tensor.trace(A: NDArray[float64]) NDArray[float64][source]
Compute the trace of a batch of square second-order tensors.
- Parameters:
A (FloatArray) – Square tensor collection of shape (…, N, N).
- Returns:
Trace values array of shape (…).
- Return type:
FloatArray
- Raises:
ValueError – If the trailing dimensions are not square.
- pyxfem.core.smallsize_tensor.trace2(A: NDArray[float64]) NDArray[float64][source]
Compute the Frobenius squared norm / trace(A^T @ A) for a batch of tensors.
- Parameters:
A (FloatArray) – Tensor collection of shape (…, N, N).
- Returns:
Array containing the sum of squared components for each tensor.
- Return type:
FloatArray
- Raises:
ValueError – If the trailing dimensions are not square.
- pyxfem.core.smallsize_tensor.trans(A: NDArray[float64]) NDArray[float64][source]
return the transposes of the input collection of second order tensors
- pyxfem.core.smallsize_tensor.vecprodmat(n: NDArray[float64]) NDArray[float64][source]
Construct skew-symmetric cross-product matrices from 3D vectors.
For each 3D vector n, constructs the tensor Q such that Q @ x = n x x.
- Parameters:
n (FloatArray) – Array of 3D vectors with trailing dimension of length 3 (shape (…, 3)).
- Returns:
Array of skew-symmetric 3x3 matrices with shape (…, 3, 3).
- Return type:
FloatArray