Markus Mottl avatar Markus Mottl committed 3331911

Added Vec.sqrt and Vec.sqr

Comments (0)

Files changed (5)

+2009-06-01:  New vector functions:
+
+               * Vec.sqrt  (compute square roots of a vector)
+               * Vec.sqr   (compute squares of a vector)
+
 2009-05-30:  Major overhaul:
 
              Fixed too liberal transpose parameters in several
 name="lacaml"
-version="5.2.0"
+version="5.2.1"
 description="LACAML - BLAS/LAPACK-interface for OCaml"
 
 requires="lacaml.core"
 
 open Bigarray
 open Vec4_FPREC
+open Utils
 open Floatxx
 
 let random ?rnd_state ?(from = -1.) ?(range = 2.) n =
   done;
   if rnd_state = None then Random.set_state state;
   vec
+
+external direct_sqr :
+  n : int ->
+  ofsy : int ->
+  incy : int ->
+  y : vec ->
+  ofsx : int ->
+  incx : int ->
+  x : vec ->
+  unit = "lacaml_FPRECsqr_stub_bc" "lacaml_FPRECsqr_stub"
+
+let vec_sqr_str = "Vec.sqr"
+
+let get_y_params ~ofsy ~incy ~n y =
+  let min_dim_y = ofsy + (n - 1) * abs incy in
+  match y with
+  | Some y -> check_vec vec_sqr_str y_str y min_dim_y; y, ofsy, incy
+  | None -> create min_dim_y, 1, 1
+
+let sqr ?n ?ofsy ?incy ?y ?ofsx ?incx x =
+  let ofsx, incx = get_vec_geom vec_sqr_str x_str ofsx incx in
+  let ofsy, incy = get_vec_geom vec_sqr_str y_str ofsy incy in
+  let n = get_dim_vec vec_sqr_str x_str ofsx incx x n_str n in
+  let y, ofsy, incy = get_y_params ~ofsy ~incy ~n y in
+  direct_sqr ~n ~ofsy ~incy ~y ~ofsx ~incx ~x;
+  y
+
+external direct_sqrt :
+  n : int ->
+  ofsy : int ->
+  incy : int ->
+  y : vec ->
+  ofsx : int ->
+  incx : int ->
+  x : vec ->
+  unit = "lacaml_FPRECsqrt_stub_bc" "lacaml_FPRECsqrt_stub"
+
+let vec_sqrt_str = "Vec.sqrt"
+
+let sqrt ?n ?ofsy ?incy ?y ?ofsx ?incx x =
+  let ofsx, incx = get_vec_geom vec_sqrt_str x_str ofsx incx in
+  let ofsy, incy = get_vec_geom vec_sqrt_str y_str ofsy incy in
+  let n = get_dim_vec vec_sqrt_str x_str ofsx incx x n_str n in
+  let y, ofsy, incy = get_y_params ~ofsy ~incy ~n y in
+  direct_sqrt ~n ~ofsy ~incy ~y ~ofsx ~incx ~x;
+  y
     @param rnd_state default = Random.get_state ()
     @param from default = -1.0
     @param range default = 2.0 *)
+
+val sqr :
+  ?n : int ->
+  ?ofsy : int ->
+  ?incy : int ->
+  ?y : vec ->
+  ?ofsx : int ->
+  ?incx : int ->
+  vec
+  -> vec
+(** [sqr ?n ?ofsy ?incy ?y ?ofsx ?incx x] computes the square
+    of [n] elements of the vector [x] using [incx] as incremental
+    steps.   If [y] is given, the result will be stored in there
+    using increments of [incy], otherwise a fresh vector will be
+    used.  The resulting vector is returned.
+
+    @param n default = greater n s.t. [ofsx+(n-1)(abs incx) <= dim x]
+    @param ofsy default = 1
+    @param incy default = 1
+    @param y default = fresh vector with [ofsy+(n - 1)(abs incy)] rows
+    @param ofsx default = 1
+    @param incx default = 1
+*)
+
+val sqrt :
+  ?n : int ->
+  ?ofsy : int ->
+  ?incy : int ->
+  ?y : vec ->
+  ?ofsx : int ->
+  ?incx : int ->
+  vec
+  -> vec
+(** [sqrt ?n ?ofsy ?incy ?y ?ofsx ?incx x] computes the square root
+    of [n] elements of the vector [x] using [incx] as incremental
+    steps.   If [y] is given, the result will be stored in there
+    using increments of [incy], otherwise a fresh vector will be
+    used.  The resulting vector is returned.
+
+    @param n default = greater n s.t. [ofsx+(n-1)(abs incx) <= dim x]
+    @param ofsy default = 1
+    @param incy default = 1
+    @param y default = fresh vector with [ofsy+(n - 1)(abs incy)] rows
+    @param ofsx default = 1
+    @param incx default = 1
+*)
   CAMLreturn(caml_copy_double(acc));
 }
 
+#define NAME LFUN(sqr_stub)
+#define BC_NAME LFUN(sqr_stub_bc)
+#define FUNC(dst, x) *dst = x * x
+#include "vec_map.c"
+
+#define NAME LFUN(sqrt_stub)
+#define BC_NAME LFUN(sqrt_stub_bc)
+#define FUNC(dst, x) *dst = sqrt(x)
+#include "vec_map.c"
+
 #define NAME LFUN(neg_stub)
 #define BC_NAME LFUN(neg_stub_bc)
 #define FUNC(dst, x) *dst = - x
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.