Markus Mottl avatar Markus Mottl committed b62b21d

Added Mat.sum and Mat.fill

Comments (0)

Files changed (12)

+2013-10-08:  Added new functions:
+
+               * Mat.sum
+               * Mat.fill  (more flexible than the Bigarray fill-function)
+
 2013-10-02:  Added new function:
 
                * Vec.fill  (more flexible than the Bigarray fill-function)
 OASISFormat:      0.3
 Name:             lacaml
-Version:          7.0.10
+Version:          7.0.11
 Synopsis:         OCaml-bindings to BLAS and LAPACK.
 Description:      This library interfaces the BLAS-library (Basic Linear Algebra Subroutines) and LAPACK-library (Linear Algebra routines), which are written in FORTRAN.
 Authors:          Egbert Ammicht <eammicht@lucent.com>,
 # OASIS_START
-# DO NOT EDIT (digest: 51cd27ad1b0b1c4142e276ba22d04ffa)
-version = "7.0.10"
+# DO NOT EDIT (digest: 255875c3a3c2ae7a32dd0e999390cd20)
+version = "7.0.11"
 description = "OCaml-bindings to BLAS and LAPACK."
 requires = "bigarray"
 archive(byte) = "lacaml.cma"
 archive(native, plugin) = "lacaml.cmxs"
 exists_if = "lacaml.cma"
 package "top" (
- version = "7.0.10"
+ version = "7.0.11"
  description = "Toplevel module for Lacaml."
  requires = "lacaml"
  archive(byte) = "lacaml_top.cma"
     done;
   a
 
+external direct_sum :
+  m : int ->
+  n : int ->
+  ar : int ->
+  ac : int ->
+  a : mat ->
+  num_type = "lacaml_NPRECsum_mat_stub"
+
+let sum ?m ?n ?(ar = 1) ?(ac = 1) a =
+  let loc = "Lacaml.NPREC.Mat.sum" in
+  let m = get_dim1_mat loc a_str a ar m_str m in
+  let n = get_dim2_mat loc a_str a ac n_str n in
+  direct_sum ~m ~n ~ar ~ac ~a
+
+external direct_fill :
+  m : int ->
+  n : int ->
+  ar : int ->
+  ac : int ->
+  a : mat ->
+  x : num_type ->
+  unit = "lacaml_NPRECfill_mat_stub_bc" "lacaml_NPRECfill_mat_stub"
+
+let fill ?m ?n ?(ar = 1) ?(ac = 1) a x =
+  let loc = "Lacaml.NPREC.Mat.fill" in
+  let m = get_dim1_mat loc a_str a ar m_str m in
+  let n = get_dim2_mat loc a_str a ac n_str n in
+  direct_fill ~m ~n ~ar ~ac ~a ~x
+
 let copy_diag mat =
   let m = dim1 mat in
   let n = dim2 mat in
 
 (** {6 Arithmetic and other matrix operations} *)
 
+val sum : ?m : int -> ?n : int -> ?ar : int -> ?ac : int -> mat -> num_type
+(** [sum ?m ?n ?ar ?ac a] computes the sum of all elements in
+    the [m]-by-[n] submatrix starting at row [ar] and column [ac]. *)
+
+val fill :
+  ?m : int -> ?n : int -> ?ar : int -> ?ac : int -> mat -> num_type -> unit
+(** [fill ?m ?n ?ar ?ac a x] fills the specified sub-matrix in [a] with value
+    [x]. *)
+
 val copy_diag : mat -> vec
 (** [copy_diag m] @return the diagonal of matrix [m] as a vector.
     If [m] is not a square matrix, the longest possible sequence
 static NUMBER number_minus_one = NUMBER_MINUS_ONE;
 
 
+/* sum_mat */
+
+CAMLprim value LFUN(sum_mat_stub)(
+  value vM, value vN,
+  value vAR, value vAC, value vA)
+{
+  CAMLparam1(vA);
+  integer GET_INT(M), GET_INT(N);
+
+  NUMBER res = NUMBER_ZERO;
+
+  if (M > 0 && N > 0) {
+    int i;
+    MAT_PARAMS(A);
+    NUMBER *A_last = A_data + rows_A * N;
+    caml_enter_blocking_section();
+      do {
+        for (i = 0; i < M; ++i) res = ADD_NUMBER(res, A_data[i]);
+        A_data += rows_A;
+      } while (A_data != A_last);
+    caml_leave_blocking_section();
+  }
+
+  CAMLreturn(COPY_NUMBER(res));
+}
+
+
+/* fill_mat */
+
+CAMLprim value LFUN(fill_mat_stub)(
+  value vM, value vN,
+  value vAR, value vAC, value vA,
+  value vX)
+{
+  CAMLparam1(vA);
+  integer GET_INT(M), GET_INT(N);
+
+  if (M > 0 && N > 0) {
+    int i;
+    MAT_PARAMS(A);
+    CREATE_NUMBER(X);
+    NUMBER *A_last = A_data + rows_A * N;
+    INIT_NUMBER(X);
+    caml_enter_blocking_section();
+      do {
+        for (i = 0; i < M; ++i) A_data[i] = X;
+        A_data += rows_A;
+      } while (A_data != A_last);
+    caml_leave_blocking_section();
+  }
+
+  CAMLreturn(Val_unit);
+}
+
+CAMLprim value LFUN(fill_mat_stub_bc)(value *argv, int __unused argn)
+{
+  return LFUN(fill_mat_stub)(
+    argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
+}
+
+
 /* transpose_copy */
 
 extern void FUN(copy)(
   }
 #include "fold_col.c"
 
-#define NAME LFUN(sum_stub)
+#define NAME LFUN(sum_vec_stub)
 #define INIT { 0.0, 0.0 }
 #define FUNC(acc, x) acc.r += x.r; acc.i += x.i
 #include "fold_col.c"
   incx : int ->
   x : vec ->
   a : num_type ->
-  unit = "lacaml_NPRECfill_stub"
+  unit = "lacaml_NPRECfill_vec_stub"
 
 let vec_fill_str = "Vec.fill"
 
   ofsx : int ->
   incx : int ->
   x : vec ->
-  num_type = "lacaml_NPRECsum_stub"
+  num_type = "lacaml_NPRECsum_vec_stub"
 
 let vec_sum_str = "Vec.sum"
 
 #include <math.h>
 #include "lacaml_macros.h"
 
-CAMLprim value LFUN(fill_stub)(
+CAMLprim value LFUN(fill_vec_stub)(
   value vN, value vOFSX, value vINCX, value vX, value vA)
 {
   CAMLparam1(vX);
 #define FUNC(acc, x) if (x < acc) acc = x
 #include "fold_col.c"
 
-#define NAME LFUN(sum_stub)
+#define NAME LFUN(sum_vec_stub)
 #define INIT 0.0
 #define FUNC(acc, x) acc += x
 #include "fold_col.c"
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *)
 
-let version = "7.0.10"
+let version = "7.0.11"
 (* setup.ml generated for the first time by OASIS v0.2.0 *)
 
 (* OASIS_START *)
-(* DO NOT EDIT (digest: d206e5232723bdea4c3eed633291ad84) *)
+(* DO NOT EDIT (digest: cdbb6a1ed7b066f1a2fb1b2814100858) *)
 (*
    Regenerated by OASIS v0.3.0
    Visit http://oasis.forge.ocamlcore.org for more information and
           ocaml_version = Some (OASISVersion.VGreaterEqual "3.12");
           findlib_version = Some (OASISVersion.VGreaterEqual "1.3.1");
           name = "lacaml";
-          version = "7.0.10";
+          version = "7.0.11";
           license =
             OASISLicense.DEP5License
               (OASISLicense.DEP5Unit
           };
      oasis_fn = Some "_oasis";
      oasis_version = "0.3.0";
-     oasis_digest = Some "\157%\148\133\140μ\019�+�\137th\022�";
+     oasis_digest = Some "k��\159\031�\023(\000������Q";
      oasis_exec = None;
      oasis_setup_args = [];
      setup_update = false;
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.