Skip to content

Commit 7c2b305

Browse files
author
davidcorteso
committed
Changed NEBM old numpy declarations to the most efficient Cython typed memoryviews
1 parent 6b3583a commit 7c2b305

File tree

5 files changed

+31
-47
lines changed

5 files changed

+31
-47
lines changed

fidimag/atomistic/lib/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ double skyrmion_number(double *spin, double *charge,
8181
*
8282
*/
8383

84-
int i, j;
84+
int i;
8585
int index, id;
8686

8787
double sum = 0;

fidimag/common/neb_method/nebm_cartesian_clib.pyx

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
import numpy
2-
cimport numpy as np
3-
np.import_array()
4-
5-
61
cdef extern from "nebm_cartesian_lib.h":
72

83
double compute_distance_cartesian(double * A, double * B, int n_dofs_image,
@@ -51,9 +46,9 @@ cdef extern from "nebm_lib.h":
5146
void normalise_images_C(double * y, int n_images,
5247
int n_dofs_image)
5348

54-
def compute_tangents(np.ndarray[double, ndim=1, mode="c"] tangents,
55-
np.ndarray[double, ndim=1, mode="c"] y,
56-
np.ndarray[double, ndim=1, mode="c"] energies,
49+
def compute_tangents(double [:] tangents,
50+
double [:] y,
51+
double [:] energies,
5752
n_dofs_image,
5853
n_images
5954
):
@@ -62,13 +57,13 @@ def compute_tangents(np.ndarray[double, ndim=1, mode="c"] tangents,
6257
n_dofs_image, n_images
6358
)
6459

65-
def compute_spring_force(np.ndarray[double, ndim=1, mode="c"] spring_force,
66-
np.ndarray[double, ndim=1, mode="c"] y,
67-
np.ndarray[double, ndim=1, mode="c"] tangents,
60+
def compute_spring_force(double [:] spring_force,
61+
double [:] y,
62+
double [:] tangents,
6863
k,
6964
n_images,
7065
n_dofs_image,
71-
np.ndarray[int, ndim=1, mode="c"] material,
66+
int [:] material,
7267
n_dofs_image_material
7368
):
7469

@@ -78,10 +73,10 @@ def compute_spring_force(np.ndarray[double, ndim=1, mode="c"] spring_force,
7873
&material[0], n_dofs_image_material
7974
)
8075

81-
def compute_effective_force(np.ndarray[double, ndim=1, mode="c"] G,
82-
np.ndarray[double, ndim=1, mode="c"] tangents,
83-
np.ndarray[double, ndim=1, mode="c"] gradientE,
84-
np.ndarray[double, ndim=1, mode="c"] spring_force,
76+
def compute_effective_force(double [:] G,
77+
double [:] tangents,
78+
double [:] gradientE,
79+
double [:] spring_force,
8580
climbing_image,
8681
n_images,
8782
n_dofs_image
@@ -93,25 +88,25 @@ def compute_effective_force(np.ndarray[double, ndim=1, mode="c"] G,
9388
n_images, n_dofs_image
9489
)
9590

96-
def project_images(np.ndarray[double, ndim=1, mode="c"] vector,
97-
np.ndarray[double, ndim=1, mode="c"] y,
91+
def project_images(double [:] vector,
92+
double [:] y,
9893
n_images, n_dofs_image
9994
):
10095

10196
project_images_C(&vector[0], &y[0],
10297
n_images, n_dofs_image
10398
)
10499

105-
def normalise_images(np.ndarray[double, ndim=1, mode="c"] y,
100+
def normalise_images(double [:] y,
106101
n_images, n_dofs_image
107102
):
108103

109104
normalise_images_C(&y[0], n_images, n_dofs_image)
110105

111-
def compute_dYdt(np.ndarray[double, ndim=1, mode="c"] y,
112-
np.ndarray[double, ndim=1, mode="c"] G,
113-
np.ndarray[double, ndim=1, mode="c"] dYdt,
114-
np.ndarray[int, ndim=1, mode="c"] pins,
106+
def compute_dYdt(double [:] y,
107+
double [:] G,
108+
double [:] dYdt,
109+
int [:] pins,
115110
n_images,
116111
n_dofs_image
117112
):

fidimag/common/neb_method/nebm_clib.pyx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
import numpy
2-
cimport numpy as np
3-
np.import_array()
4-
5-
61
cdef extern from "nebm_lib.h":
72

83
void compute_tangents_C(double *tangents,
@@ -20,9 +15,9 @@ cdef extern from "nebm_lib.h":
2015
int n_images,
2116
int n_dofs_image)
2217

23-
def compute_tangents(np.ndarray[double, ndim=1, mode="c"] tangents,
24-
np.ndarray[double, ndim=1, mode="c"] y,
25-
np.ndarray[double, ndim=1, mode="c"] energies,
18+
def compute_tangents(double [:] tangents,
19+
double [:] y,
20+
double [:] energies,
2621
n_dofs_image,
2722
n_images
2823
):
@@ -31,10 +26,10 @@ def compute_tangents(np.ndarray[double, ndim=1, mode="c"] tangents,
3126
n_dofs_image, n_images
3227
)
3328

34-
def compute_effective_force(np.ndarray[double, ndim=1, mode="c"] G,
35-
np.ndarray[double, ndim=1, mode="c"] tangents,
36-
np.ndarray[double, ndim=1, mode="c"] gradientE,
37-
np.ndarray[double, ndim=1, mode="c"] spring_force,
29+
def compute_effective_force(double [:] G,
30+
double [:] tangents,
31+
double [:] gradientE,
32+
double [:] spring_force,
3833
climbing_image,
3934
n_images,
4035
n_dofs_image

fidimag/common/neb_method/nebm_geodesic_lib.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ double compute_distance_geodesic(double * A, double * B, int n_dofs_image,
4040
*
4141
*/
4242

43-
int i, j;
4443
int spin_i;
4544
double A_cross_B[3];
4645
double A_cross_B_norm;

fidimag/common/neb_method/nebm_spherical_clib.pyx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
import numpy
2-
cimport numpy as np
3-
np.import_array()
4-
5-
61
cdef extern from "nebm_spherical_lib.h":
72

83
void normalise_spherical(double * a, int n)
@@ -44,20 +39,20 @@ cdef extern from "nebm_lib.h":
4439
int n_images,
4540
int n_dofs_image)
4641

47-
def normalise_images(np.ndarray[double, ndim=1, mode="c"] y,
42+
def normalise_images(double [:] y,
4843
n_images,
4944
n_dofs_image
5045
):
5146

5247
normalise_images_spherical_C(&y[0], n_images, n_dofs_image)
5348

54-
def compute_spring_force(np.ndarray[double, ndim=1, mode="c"] spring_force,
55-
np.ndarray[double, ndim=1, mode="c"] y,
56-
np.ndarray[double, ndim=1, mode="c"] tangents,
49+
def compute_spring_force(double [:] spring_force,
50+
double [:] y,
51+
double [:] tangents,
5752
k,
5853
n_images,
5954
n_dofs_image,
60-
np.ndarray[int, ndim=1, mode="c"] material,
55+
int [:] material,
6156
n_dofs_image_material
6257
):
6358

0 commit comments

Comments
 (0)