From ce1aeb324d45a745a4b5b7313741249b7197e363 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 20 May 2022 19:57:01 +0200 Subject: [PATCH] Change point API to make it consistent for Python --- org/examples.org | 6 +++--- org/qmckl_electron.org | 2 +- org/qmckl_point.org | 20 +++++++++++++++----- python/src/qmckl.i | 4 ++++ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/org/examples.org b/org/examples.org index c1002b2..eef87b4 100644 --- a/org/examples.org +++ b/org/examples.org @@ -101,10 +101,10 @@ point = [] for x in linspace[0]: for y in linspace[1]: for z in linspace[2]: - point += [x, y, z] + point += [ [x, y, z] ] -#point = np.array(point) -qmckl.set_point(context, 'N', point, len(point)/3) +point = np.array(point) +qmckl.set_point(context, 'N', len(point), point) #+end_src #+RESULTS: diff --git a/org/qmckl_electron.org b/org/qmckl_electron.org index c0c0254..a4736cc 100644 --- a/org/qmckl_electron.org +++ b/org/qmckl_electron.org @@ -718,7 +718,7 @@ qmckl_set_electron_coord(qmckl_context context, ctx->electron.coord_old = ctx->electron.coord_new ; qmckl_exit_code rc; - rc = qmckl_set_point(context, transp, coord, size_max/3); + rc = qmckl_set_point(context, transp, size_max/3, coord, size_max); assert (rc == QMCKL_SUCCESS); ctx->electron.coord_new = ctx->point.coord ; diff --git a/org/qmckl_point.org b/org/qmckl_point.org index 74a1e6a..306502f 100644 --- a/org/qmckl_point.org +++ b/org/qmckl_point.org @@ -263,8 +263,9 @@ end interface #+begin_src c :comments org :tangle (eval h_func) qmckl_exit_code qmckl_set_point (qmckl_context context, const char transp, + const int64_t num, const double* coord, - const int64_t num); + const int64_t size_max); #+end_src Copy a sequence of ~num~ points $(x,y,z)$ into the context. @@ -273,14 +274,22 @@ qmckl_exit_code qmckl_set_point (qmckl_context context, qmckl_exit_code qmckl_set_point (qmckl_context context, const char transp, + const int64_t num, const double* coord, - const int64_t num) + const int64_t size_max) { if (qmckl_context_check(context) == QMCKL_NULL_CONTEXT) { return QMCKL_NULL_CONTEXT; } + if (size_max < 3*num) { + return qmckl_failwith( context, + QMCKL_INVALID_ARG_4, + "qmckl_set_point", + "Array too small"); + } + if (transp != 'N' && transp != 'T') { return qmckl_failwith( context, QMCKL_INVALID_ARG_2, @@ -349,7 +358,7 @@ qmckl_set_point (qmckl_context context, #+begin_src f90 :comments org :tangle (eval fh_func) :noweb yes interface integer(c_int32_t) function qmckl_set_point(context, & - transp, coord, num) bind(C) + transp, num, coord, size_max) bind(C) use, intrinsic :: iso_c_binding import implicit none @@ -358,6 +367,7 @@ interface character(c_char) , intent(in) , value :: transp real (c_double ) , intent(in) :: coord(*) integer (c_int64_t) , intent(in) , value :: num + integer (c_int64_t) , intent(in) , value :: size_max end function end interface #+end_src @@ -380,7 +390,7 @@ double coord3[point_num*3]; rc = qmckl_get_point (context, 'N', coord2, (point_num*3)); assert(rc == QMCKL_NOT_PROVIDED); -rc = qmckl_set_point (context, 'N', coord, point_num); +rc = qmckl_set_point (context, 'N', point_num, coord, (point_num*3)); assert(rc == QMCKL_SUCCESS); int64_t n; @@ -404,7 +414,7 @@ for (int64_t i=0 ; i