-
Notifications
You must be signed in to change notification settings - Fork 0
/
eigsym3d.pyx
45 lines (35 loc) · 1.08 KB
/
eigsym3d.pyx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
Eigen decomposition of 3x3 symmetric matrices.
Author: Alexis Mignon (c)
e-mail: [email protected]
"""
import numpy as np
cimport numpy as np
cdef extern :
int eigen_sym_3D(double* A, double* w, double* U)
def eigh(np.ndarray[np.float_t, ndim = 2] A):
"""
Eigen decomposition of 3x3 symmetric matrices.
arguments:
- A: a 3x3 array of np.float
returns:
- w: array of eigen-values sorted in decreasing order
- u: array of eigen-vectors where u[:,i] is the eigen-vector
corresponding to w[i]
"""
cdef :
np.ndarray[np.float_t, ndim = 2] A_ = np.zeros((3,3),'float')
np.ndarray[np.float_t, ndim = 1] w = np.zeros(3,'float')
np.ndarray[np.float_t, ndim = 2] U = np.zeros((3,3),'float')
double *dA
double *dw = <double*>w.data
double *dU = <double*>U.data
int res
if (<object>A).flags.c_contiguous and (<object>A).dtype == "float64" :
A_ = A
else :
A_ = A.copy()
dA = <double*>A_.data
res = eigen_sym_3D(dA, dw, dU)
if res != 0 : raise ValueError("An error occured, probably due to some bad properties of the matrix A")
return w,U