Chris_T avatar Chris_T committed 864ea07

Added Vec.neg (unary negation).

Comments (0)

Files changed (7)

+~$
 (^|/)\.hg($|/)
 (^|/)\.hgtags($|/)
 \.(cm(i|o|x|a|xa)|o|so|annot|a)$
 lib/fold_col.c       - These C-files contain generic implementations of
 lib/fold2_col.c        vector functions. They can be parameterized with
 lib/vec_combine.c      macros for special cases.
+lib/vec_map.c
 
 lib/mat_SDCZ.mli     - Implementation of commonly useful matrix operations.
 lib/mat_SDCZ.ml
   CAMLreturn(copy_two_doubles(acc.r, acc.i));
 }
 
+#define NAME LFUN(neg_stub)
+#define BC_NAME LFUN(neg_stub_bc)
+#define FUNC(dst, x) \
+  dst->r = - x.r; \
+  dst->i = - x.i
+#include "vec_map.c"
+
 #define NAME LFUN(add_stub)
 #define BC_NAME LFUN(add_stub_bc)
 #define FUNC(dst, x, y) \
       if c = zero then direct_ssqr_zero n ofsx incx x
       else direct_ssqr n c ofsx incx x
 
-(* MAP *)
 (* SORT *)
 
 
+(* NEG *)
+
+external direct_neg :
+  int -> (* N *)
+  int -> (* OFSY *)
+  int -> (* INCY *)
+  vec -> (* Y *)
+  int -> (* OFSX *)
+  int -> (* INCX *)
+  vec -> (* X *)
+  unit = "lacaml_NPRECneg_stub_bc" "lacaml_NPRECneg_stub"
+
+let vec_neg_str = "Vec.neg"
+
+let neg ?n ?ofsy ?incy ?y ?ofsx ?incx x =
+  let ofsy, incy = get_vec_geom vec_neg_str y_str ofsy incy
+  and ofsx, incx = get_vec_geom vec_neg_str x_str ofsx incx in
+  let n = get_dim_vec vec_neg_str x_str ofsx incx x n_str n in
+  let y, ofsy, incy =
+    let min_dim_y = ofsy + (n - 1) * abs incy in
+    match y with
+    | Some y -> check_vec vec_map_str y_str y min_dim_y; y, ofsy, incy
+    | None -> create min_dim_y, 1, 1 in
+  direct_neg n ofsy incy y ofsx incx x;
+  y
+
 (* Operations on two vectors *)
 
 (* ADD *)
 
 (** {6 Operations on two vectors} *)
 
+val neg :
+  ?n : int ->
+  ?ofsy : int ->
+  ?incy : int ->
+  ?y : vec ->
+  ?ofsx : int ->
+  ?incx : int ->
+  vec
+  -> vec
+(** [neg ?n ?ofsy ?incy ?y ?ofsx ?incx x] negates [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 add :
   ?n : int ->
   ?ofsz : int ->
   CAMLreturn(caml_copy_double(acc));
 }
 
+#define NAME LFUN(neg_stub)
+#define BC_NAME LFUN(neg_stub_bc)
+#define FUNC(dst, x) *dst = - x
+#include "vec_map.c"
+
 #define NAME LFUN(add_stub)
 #define BC_NAME LFUN(add_stub_bc)
 #define FUNC(dst, x, y) *dst = x + y
+/* File: vec_map.c
+
+   Copyright (C) 2009-
+
+     Markus Mottl
+     email: markus.mottl@gmail.com
+     WWW: http://www.ocaml.info
+
+     Christophe Troestler
+     email: Christophe.Troestler@umons.ac.be
+     WWW: http://math.umh.ac.be/an/
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include "lacaml_macros.h"
+#include "f2c.h"
+
+CAMLprim value NAME(
+  value vN,
+  value vOFSY, value vINCY, value vY,
+  value vOFSX, value vINCX, value vX)
+{
+  CAMLparam2(vX, vY);
+  int GET_INT(N),
+      GET_INT(INCX),
+      GET_INT(INCY);
+  VEC_PARAMS(X);
+  VEC_PARAMS(Y);
+
+  NUMBER *start1, *last1, *dst;
+
+  caml_enter_blocking_section();  /* Allow other threads */
+
+  if (INCX > 0) {
+    start1 = X_data;
+    last1 = start1 + N*INCX;
+  }
+  else {
+    start1 = X_data - (N - 1)*INCX;
+    last1 = X_data + INCX;
+  };
+
+  if (INCY > 0) dst = Y_data;
+  else dst = Y_data - (N - 1)*INCY;
+
+  while (start1 != last1) {
+    NUMBER x = *start1;
+    FUNC(dst, x);
+
+    start1 += INCX;
+    dst += INCY;
+  };
+
+  caml_leave_blocking_section();  /* Disallow other threads */
+
+  CAMLreturn(Val_unit);
+}
+
+CAMLprim value BC_NAME(value *argv, int argn)
+{
+  return NAME(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);
+}
+
+#undef NAME
+#undef BC_NAME
+#undef FUNC
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.