Markus Mottl avatar Markus Mottl committed 365919a

Added Mat.scal_cols

Comments (0)

Files changed (6)

+2009-04-22:  Added new matrix function:
+
+               * scal_cols
+
 2009-01-21:  Added Vec.sqr_nrm2, which is numerically more stable than
              Vec.ssqr.  Added nrm2 for complex numbers (BLAS-1 function).
 
 name="lacaml"
-version="4.7.6"
+version="4.7.7"
 description="LACAML - BLAS/LAPACK-interface for OCaml"
 
 requires="lacaml.core"
 
 let copy ?m ?n ?(yr = 1) ?(yc = 1) ?y ?(xr = 1) ?(xc = 1) x =
   let loc = "Lacaml.Impl.NPREC.Mat.copy" in
-  let x_name = "x" in
-  let m = get_dim1_mat loc x_name x xr "m" m in
-  let n = get_dim2_mat loc x_name x xc "n" n in
+  let m = get_dim1_mat loc x_str x xr m_str m in
+  let n = get_dim2_mat loc x_str x xc n_str n in
   let y, yr, yc =
     match y with
-    | Some y -> check_dim_mat loc "y" yr yc y m n; y, yr, yc
+    | Some y -> check_dim_mat loc y_str yr yc y m n; y, yr, yc
     | None -> create m n, 1, 1
   in
   direct_copy_mat m n yr yc y xr xc x;
 
 let transpose ?m ?n ?(ar = 1) ?(ac = 1) a =
   let loc = "Lacaml.Impl.NPREC.Mat.transpose" in
-  let x_name = "a" in
-  let m = get_dim1_mat loc x_name a ar "m" m in
-  let n = get_dim2_mat loc x_name a ac "n" n 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
   let res = create n m in
   for col = 1 to n do
     for row = 1 to m do res.{col, row} <- a.{ar + row - 1, ac + col - 1} done
 
 let detri ?(up = true) ?n ?(ar = 1) ?(ac = 1) a =
   let loc = "Lacaml.Impl.NPREC.Mat.detri" in
-  let n = get_n_of_square "a" loc ar ac a n in
+  let n = get_n_of_square a_str loc ar ac a n in
   if up then
     for c = 1 to n - 1 do
       let ar_c = ar + c in
 
 let packed ?(up = true) ?n ?(ar = 1) ?(ac = 1) a =
   let loc = "Lacaml.Impl.NPREC.Mat.packed" in
-  let n = get_n_of_square "a" loc ar ac a n in
+  let n = get_n_of_square a_str loc ar ac a n in
   let dst = Array1.create prec fortran_layout ((n * n + n) / 2) in
   let pos_ref = ref 1 in
   if up then
 
 let scal ?m ?n alpha ?(ar = 1) ?(ac = 1) a =
   let loc = "Lacaml.Impl.NPREC.Mat.scal" in
-  let a_name = "a" in
-  let m = get_dim1_mat loc a_name a ar "m" m in
-  let n = get_dim2_mat loc a_name a ac "n" n 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_scal_mat m n alpha ar ac a
 
+external direct_scal_cols :
+  int -> (* M *)
+  int -> (* N *)
+  int -> (* OFS *)
+  vec -> (* ALPHAs *)
+  int -> (* AR *)
+  int -> (* AC *)
+  mat (* A *)
+  -> unit = "lacaml_NPRECscal_cols_stub_bc" "lacaml_NPRECscal_cols_stub"
+
+let scal_cols ?m ?n ?ofs alphas ?(ar = 1) ?(ac = 1) a =
+  let loc = "Lacaml.Impl.NPREC.Mat.scal_cols" 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
+  let ofs = get_ofs loc alphas_str ofs in
+  ignore (get_dim_vec loc alphas_str ofs 1 alphas n_str (Some n));
+  direct_scal_cols m n ofs alphas ar ac a
+
 external direct_axpy_mat :
   int -> (* M *)
   int -> (* N *)
 
 let axpy ?m ?n ?(alpha = one) ?(xr = 1) ?(xc = 1) ~x ?(yr = 1) ?(yc = 1) y =
   let loc = "Lacaml.Impl.NPREC.Mat.axpy" in
-  let x_name = "x" in
-  let m = get_dim1_mat loc x_name x xr "m" m in
-  let n = get_dim2_mat loc x_name x xc "n" n in
-  check_dim_mat loc "y" yr yc y m n;
+  let m = get_dim1_mat loc x_str x xr m_str m in
+  let n = get_dim2_mat loc x_str x xc n_str n in
+  check_dim_mat loc y_str yr yc y m n;
   direct_axpy_mat m n alpha xr xc x yr yc y
 
 external direct_map :
 
 let map f ?m ?n ?(cr = 1) ?(cc = 1) ?c ?(ar = 1) ?(ac = 1) a =
   let loc = "Lacaml.Impl.NPREC.Mat.map" in
-  let m = get_dim1_mat loc "a" a ar "m" m in
-  let n = get_dim2_mat loc "a" a ac "n" n 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
   let c, cr, cc =
     match c with
     | None -> create m n, 1, 1
-    | Some c -> check_dim_mat loc "c" cr cc c m n; c, cr, cc
+    | Some c -> check_dim_mat loc c_str cr cc c m n; c, cr, cc
   in
   direct_map m n ar ac a cr cc c f;
   c
 
 let fold_cols coll ?n ?(ac = 1) acc a =
   let loc = "Lacaml.Impl.NPREC.Mat.fold_cols" in
-  let n = get_dim2_mat loc "a" a ac "n" n in
+  let n = get_dim2_mat loc a_str a ac n_str n in
   let acc_ref = ref acc in
   for i = 0 to n - 1 do
     acc_ref := coll !acc_ref (col a (ac + i))
 val copy_row : ?vec : vec -> mat -> int -> vec
 (** [copy_row ?vec mat int] @return a copy of the [n]th row of matrix [m]
     in vector [vec].
-    
-    @param vec default = fresh vector of length [dim2 mat] *)
+
+    @param vec default = fresh vector of length [dim2 mat]
+*)
 
 
 (** {6 Matrix transformations} *)
 
 val scal :
   ?m : int -> ?n : int -> num_type -> ?ar : int -> ?ac : int -> mat -> unit
-(** [scal ?m ?n alpha ?ar ?ac a] BLAS [scal] function for matrices. *)
+(** [scal ?m ?n alpha ?ar ?ac a] BLAS [scal] function for (sub-)matrices. *)
+
+val scal_cols :
+  ?m : int -> ?n : int ->
+  ?ofs : int -> vec ->
+  ?ar : int -> ?ac : int -> mat
+  -> unit
+(** [scal_cols ?m ?n ?ofs alphas ?ar ?ac a] column-wise [scal] function
+    for matrices. *)
 
 val axpy :
   ?m : int ->
     argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
 }
 
+CAMLprim value LFUN(scal_cols_stub)(
+  value vM, value vN,
+  value vOFSALPHAs,
+  value vALPHAs,
+  value vAR, value vAC, value vA)
+{
+  CAMLparam2(vALPHAs, vA);
+
+  integer GET_INT(M), GET_INT(N);
+
+  VEC_PARAMS(ALPHAs);
+  MAT_PARAMS(A);
+
+  caml_enter_blocking_section();
+    NUMBER *A_src = A_data + rows_A * (N - 1);
+    NUMBER *ALPHAs_src = ALPHAs_data + (N - 1);
+    while (A_src >= A_data) {
+      FUN(scal)(&M, ALPHAs_src, A_src, &ONE);
+      A_src -= rows_A;
+      ALPHAs_src--;
+    }
+  caml_leave_blocking_section();
+
+  CAMLreturn(Val_unit);
+}
+
+CAMLprim value LFUN(scal_cols_stub_bc)(value *argv, int argn)
+{
+  return LFUN(scal_cols_stub)(
+    argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);
+}
+
 CAMLprim value LFUN(axpy_mat_stub)(
   value vM, value vN,
   value vALPHA,
 
 (* Name information *)
 let a_str = "a"
+let alphas_str = "alphas"
 let ap_str = "ap"
 let b_str = "b"
 let c_str = "c"
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.