Chris_T avatar Chris_T committed 0e48900

Allow to forget the Impl submodule. The S, D, C, Z sub-modules are generated from SD.ml, SD.mli and CZ.ml, CZ.mli files by the post-configure script.

Comments (0)

Files changed (13)

 lib/.*\.mllib$
 lib/.*\.clib$
 lib/(impl|mat|vec)(2|4)_.*$
+lib/(s|d|c|z).ml(|i)$
 lib/lacaml.mli
 examples/blas/blas$
 examples/eig/eig$
 	ocaml setup.ml -build
 
 configure: setup.data
-setup.data: setup.ml
+setup.data: setup.ml make_prec_dep.ml lib/lacaml_SDCZ.mli
 	ocaml setup.ml -configure
 
 setup.ml: _oasis
+(* File: CZ.ml
+
+   Copyright (C) 2001-
+
+     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
+*)
+
+open Bigarray
+
+(** Modules with functions specialized for simple (C) or double (Z)
+    precision complex numbers. *)
+
+include Complexxx
+
+include Complex_io
+
+include Impl2_CPREC
+include Impl4_CPREC
+
+module Vec = struct
+  include Vec2_CPREC
+  include Vec4_CPREC
+end
+
+module Mat = struct
+  include Mat2_CPREC
+  include Mat4_CPREC
+end
+(* File: CZ.mli
+
+   Copyright (C) 2010-
+
+     Christophe Troestler
+     email: Christophe.Troestler@umons.ac.be
+     WWW: http://math.umons.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
+*)
+open Bigarray
+
+type prec = complexxx_elt
+type num_type = Complex.t
+type vec = (Complex.t, complexxx_elt, fortran_layout) Array1.t
+(** Double precision vectors. *)
+type rvec = (float, floatxx_elt, fortran_layout) Array1.t
+(** Double precision vectors of reals. *)
+type mat = (Complex.t, complexxx_elt, fortran_layout) Array2.t
+(** Double precision matrices. *)
+
+type trans3 = [ `C | `N | `T ]
+val prec : (Complex.t, complexxx_elt) Bigarray.kind
+(** Precision for this submodule {!CPREC}.  Allows to write precision
+    independent code. *)
+
+module Vec : sig
+  include module type of Vec2_CPREC
+  include module type of Vec4_CPREC
+end
+
+module Mat : sig
+  include module type of Mat2_CPREC
+  include module type of Mat4_CPREC
+end
+include module type of Complex_io
+
+include module type of Impl2_CPREC
+include module type of Impl4_CPREC
+(* File: SD.ml
+
+   Copyright (C) 2010-
+
+     Christophe Troestler
+     email: Christophe.Troestler@umons.ac.be
+     WWW: http://math.umons.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
+*)
+
+(** Modules with functions specialized for simple (S) or double (D)
+    precision numbers. *)
+
+include Floatxx
+
+include Impl2_FPREC
+include Impl4_FPREC
+
+include Real_io
+
+module Vec = struct
+  include Vec2_FPREC
+  include Vec4_FPREC
+end
+
+module Mat = struct
+  include Mat2_FPREC
+  include Mat4_FPREC
+end
+(* File: SD.mli
+
+   Copyright (C) 2010-
+
+     Christophe Troestler
+     email: Christophe.Troestler@umons.ac.be
+     WWW: http://math.umons.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
+*)
+open Bigarray
+
+type prec = floatxx_elt
+type num_type = float
+type vec = (float, floatxx_elt, fortran_layout) Array1.t
+(** Double precision vectors. *)
+type rvec = vec
+type mat = (float, floatxx_elt, fortran_layout) Array2.t
+(** Double precision matrices. *)
+
+type trans3 = [ `N | `T ]
+
+val prec : (float, floatxx_elt) Bigarray.kind
+(** Precision for this submodule {!FPREC}.  Allows to write precision
+    independent code. *)
+
+module Vec : sig
+  include module type of Vec2_FPREC
+  include module type of Vec4_FPREC
+end
+
+module Mat : sig
+  include module type of Mat2_FPREC
+  include module type of Mat4_FPREC
+end
+include module type of Real_io
+
+include module type of Impl2_FPREC
+include module type of Impl4_FPREC

lib/complex_io.ml

+(* File: complex_io.ml
+
+   Copyright (C) 2001-
+
+     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
+*)
+
+open Io
+
+let pp_num ppf n = !pp_complex_el_default ppf n
+let pp_vec = pp_cvec
+let pp_mat = pp_cmat

lib/complex_io.mli

+(* File: complex_io.mli
+
+   Copyright (C) 2010-
+
+     Christophe Troestler
+     email: Christophe.Troestler@umons.ac.be
+     WWW: http://math.umons.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
+*)
+
+val pp_num : Format.formatter -> Complex.t -> unit
+(** [pp_num ppf el] is equivalent to [fprintf ppf "(%G, %Gi)"
+    el.re el.im]. *)
+val pp_vec : (Complex.t, 'a) Io.pp_vec
+(** Pretty-printer for column vectors. *)
+val pp_mat : (Complex.t, 'a) Io.pp_mat
+(** Pretty-printer for matrices. *)
 *)
 
 (** Modules with functions specialized for (S)ingle and (D)ouble
-    precision, and for (C)omplex and double complex (Z) numbers. *)
+    precision, and for (C)omplex and double complex (Z) numbers.
+
+    This module is present for backward compatibility only.
+ *)
 
 open Io
 
-module Real_io = struct
-  let pp_num ppf n = !pp_float_el_default ppf n
-  let pp_vec = pp_fvec
-  let pp_mat = pp_fmat
-end
-
-module Complex_io = struct
-  let pp_num ppf n = !pp_complex_el_default ppf n
-  let pp_vec = pp_cvec
-  let pp_mat = pp_cmat
-end
-
-module S = struct
-  include Float32
-
-  include Impl2_S
-  include Impl4_S
-
-  include Real_io
-
-  module Vec = struct
-    include Vec2_S
-    include Vec4_S
-  end
-
-  module Mat = struct
-    include Mat2_S
-    include Mat4_S
-  end
-end
-
-module D = struct
-  include Float64
-
-  include Impl2_D
-  include Impl4_D
-
-  include Real_io
-
-  module Vec = struct
-    include Vec2_D
-    include Vec4_D
-  end
-
-  module Mat = struct
-    include Mat2_D
-    include Mat4_D
-  end
-end
-
-module C = struct
-  include Complex32
-
-  include Impl2_C
-  include Impl4_C
-
-  include Complex_io
-
-  module Vec = struct
-    include Vec2_C
-    include Vec4_C
-  end
-
-  module Mat = struct
-    include Mat2_C
-    include Mat4_C
-  end
-end
-
-module Z = struct
-  include Complex64
-
-  include Complex_io
-
-  include Impl2_Z
-  include Impl4_Z
-
-  module Vec = struct
-    include Vec2_Z
-    include Vec4_Z
-  end
-
-  module Mat = struct
-    include Mat2_Z
-    include Mat4_Z
-  end
-end
+module Real_io = Real_io
+module Complex_io = Complex_io
+module S = S
+module D = D
+module C = C
+module Z = Z

lib/lacaml_SDCZ.mli

    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *)
 
-(** Binding to BLAS and LAPACK libraries. *)
-
-open Bigarray
-
-(** Pretty-printing of vector and matrices. *)
-module Io : sig
-  include Io
-end
-
-module Common : sig
-  include Common
-end
-
 (** Binding to the {{:http://www.netlib.org/blas/}BLAS} and
     {{:http://www.netlib.org/lapack/}LAPACK} libraries.  You can make
     use of this library by referring to the corresponding module you
     need for your precision and number type:
     {[
-    open Lacaml.Impl.S
-    open Lacaml.Impl.D
-    open Lacaml.Impl.C
-    open Lacaml.Impl.Z]}
+    open Lacaml.S
+    open Lacaml.D
+    open Lacaml.C
+    open Lacaml.Z]}
 
     To use this library, you should be familiar with BLAS and LAPACK.  The
     following {{:http://www.netlib.org/blas/blasqr.ps}quick reference
     {{:http://www.netlib.org/lapack/manpages.tgz}installed} them on
     your machine (if you use Linux, they should be in the packages of
     your distribution), read them with Emacs: [M-x man] (under Unix)
-    or [M-x woman] (all systems). *)
+    or [M-x woman] (all systems).
+ *)
+
+open Bigarray
+
+(** {2 Precision dependent modules} *)
+
+(** Types and functions common to all precision dependent sub-modules. *)
+module Common : sig
+  include module type of Common
+end
+
+(** Double precision real BLAS and LAPACK functions. *)
+module D : sig
+  include module type of D
+end
+
+(** Single precision real BLAS and LAPACK functions. *)
+module S : sig
+  include module type of S
+end
+
+(** Double precision complex BLAS and LAPACK functions. *)
+module Z : sig
+  include module type of Z
+end
+
+(** Single precision complex BLAS and LAPACK functions. *)
+module C : sig
+  include module type of C
+end
+
+
+(** Module for backward compatibility.  The submodules of [Impl] are
+    available directly under [Lacaml].  *)
 module Impl :
 sig
   (** Pretty printing of real vector and matrices.  See the
       {!Lacaml.Io} module for more versatile functions. *)
   module Real_io : sig
-    val pp_num : Format.formatter -> float -> unit
-    (** [pp_num ppf el] is equivalent to [fprintf ppf "%G" el]. *)
-    val pp_vec : (float, 'a) Io.pp_vec
-    (** Pretty-printer for column vectors. *)
-    val pp_mat : (float, 'a) Io.pp_mat
-    (** Pretty-printer for matrices. *)
+    include module type of Real_io
   end
 
   (** Pretty printing of complex vector and matrices.  See the
       {!Lacaml.Io} module for more versatile functions. *)
   module Complex_io : sig
-    val pp_num : Format.formatter -> Complex.t -> unit
-    (** [pp_num ppf el] is equivalent to [fprintf ppf "(%G, %Gi)"
-        el.re el.im]. *)
-    val pp_vec : (Complex.t, 'a) Io.pp_vec
-    (** Pretty-printer for column vectors. *)
-    val pp_mat : (Complex.t, 'a) Io.pp_mat
-    (** Pretty-printer for matrices. *)
+    include module type of Complex_io
   end
 
   (** Double precision real BLAS and LAPACK functions. *)
   module D : sig
-    type prec = float64_elt
-    type num_type = float
-    type vec = (float, float64_elt, fortran_layout) Array1.t
-    (** Double precision vectors. *)
-    type rvec = vec
-    type mat = (float, float64_elt, fortran_layout) Array2.t
-    (** Double precision matrices. *)
-
-    type trans3 = [ `N | `T ]
-
-    val prec : (float, float64_elt) Bigarray.kind
-    (** Precision for this submodule {!D}.  Allows to write precision
-        independent code. *)
-
-    module Vec : sig
-      include Vec2_D
-      include Vec4_D
-    end
-
-    module Mat : sig
-      include Mat2_D
-      include Mat4_D
-    end
-    include module type of Real_io
-
-    include Impl2_D
-    include Impl4_D
+    include module type of D
   end
 
   (** Single precision real BLAS and LAPACK functions. *)
   module S : sig
-    type prec = float32_elt
-    type num_type = float
-    type vec = (float, float32_elt, fortran_layout) Array1.t
-    (** Single precision vectors. *)
-    type rvec = vec
-    type mat = (float, float32_elt, fortran_layout) Array2.t
-    (** Single precision matrices. *)
-
-    type trans3 = [ `N | `T ]
-
-    val prec : (float, float32_elt) Bigarray.kind
-    (** Precision for this submodule {!S}.  Allows to write precision
-        independent code. *)
-
-    module Vec : sig
-      include Vec2_S
-      include Vec4_S
-    end
-
-    module Mat : sig
-      include Mat2_S
-      include Mat4_S
-    end
-    include module type of Real_io
-
-    include Impl2_S
-    include Impl4_S
+    include module type of S
   end
 
   (** Double precision complex BLAS and LAPACK functions. *)
   module Z : sig
-    type prec = complex64_elt
-    type num_type = Complex.t
-    type vec = (Complex.t, complex64_elt, fortran_layout) Array1.t
-    (** Double precision vectors. *)
-    type rvec = (float, float64_elt, fortran_layout) Array1.t
-    (** Double precision vectors of reals. *)
-    type mat = (Complex.t, complex64_elt, fortran_layout) Array2.t
-    (** Double precision matrices. *)
-
-    type trans3 = [ `C | `N | `T ]
-    val prec : (Complex.t, complex64_elt) Bigarray.kind
-    (** Precision for this submodule {!Z}.  Allows to write precision
-        independent code. *)
-
-    module Vec : sig
-      include Vec2_Z
-      include Vec4_Z
-    end
-
-    module Mat : sig
-      include Mat2_Z
-      include Mat4_Z
-    end
-    include module type of Complex_io
-
-    include Impl2_Z
-    include Impl4_Z
+    include module type of Z
   end
 
   (** Single precision complex BLAS and LAPACK functions. *)
   module C : sig
-    type prec = complex32_elt
-    type num_type = Complex.t
-    type vec = (Complex.t, complex32_elt, fortran_layout) Array1.t
-    (** Single precision vectors. *)
-    type rvec = (float, float32_elt, fortran_layout) Array1.t
-    (** Single precision vectors of reals. *)
-    type mat = (Complex.t, complex32_elt, fortran_layout) Array2.t
-    (** Single precision matrices. *)
-
-    type trans3 = [ `C | `N | `T ]
-    val prec : (Complex.t, complex32_elt) Bigarray.kind
-    (** Precision for this submodule {!C}.  Allows to write precision
-        independent code. *)
-
-    module Vec : sig
-      include Vec2_C
-      include Vec4_C
-    end
-
-    module Mat : sig
-      include Mat2_C
-      include Mat4_C
-    end
-    include module type of Complex_io
-
-    include Impl2_C
-    include Impl4_C
+    include module type of C
   end
 end
+
+(************************************************************************)
+
+(** {2 Pretty printing} *)
+
+(** Pretty-printing of vector and matrices. *)
+module Io : sig
+  include module type of Io
+end
+
+(** Pretty printing of real vector and matrices.  See the
+    {!Lacaml.Io} module for more versatile functions. *)
+module Real_io : sig
+  include module type of Real_io
+end
+
+(** Pretty printing of complex vector and matrices.  See the
+    {!Lacaml.Io} module for more versatile functions. *)
+module Complex_io : sig
+  include module type of Complex_io
+end
+(* File: real_io.ml
+
+   Copyright (C) 2001-
+
+     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
+*)
+
+open Io
+
+let pp_num ppf n = !pp_float_el_default ppf n
+let pp_vec = pp_fvec
+let pp_mat = pp_fmat
+(* File: real_io.mli
+
+   Copyright (C) 2010-
+
+     Christophe Troestler
+     email: Christophe.Troestler@umons.ac.be
+     WWW: http://math.umons.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
+*)
+
+val pp_num : Format.formatter -> float -> unit
+(** [pp_num ppf el] is equivalent to [fprintf ppf "%G" el]. *)
+val pp_vec : (float, 'a) Io.pp_vec
+(** Pretty-printer for column vectors. *)
+val pp_mat : (float, 'a) Io.pp_mat
+(** Pretty-printer for matrices. *)
 
 let lib = "lib"
 
-let substitute fname0 fname1 subs =
-  let fh0 = open_in fname0 in
-  let fh1 = open_out fname1 in
+(* Utils
+ ***********************************************************************)
+
+let comment_re = Str.regexp "(\\* [^*]+\\*)[ \n\r\t]*"
+
+let input_file ?(path=lib) ?(comments=true) ?(prefix="") fname =
+  let fh = open_in (Filename.concat path fname) in
+  let buf = Buffer.create 2048 in
   try
     while true do
-      let l = input_line fh0 in
-      let l = List.fold_left (fun l (r,s) -> Str.global_replace r s l) l subs in
-      output_string fh1 l;
-      output_char fh1 '\n';
-    done
+      let l = input_line fh in (* or exn *)
+      if l <> "" then (Buffer.add_string buf prefix;
+                      Buffer.add_string buf l );
+      Buffer.add_char buf '\n'
+    done;
+    assert false
   with End_of_file ->
-    close_out fh1;
-    close_in fh0
+    close_in fh;
+    let buf = Buffer.contents buf in
+    if comments then buf
+    else Str.global_replace comment_re "" buf
+
+let output_file ?(path=lib) fname ~content =
+  let fh = open_out (Filename.concat path fname) in
+  output_string fh content;
+  close_out fh
+
+let ocaml_major, ocaml_minor =
+  Scanf.sscanf Sys.ocaml_version "%i.%i" (fun v1 v2 -> v1, v2)
+
+let doesnt_have_module_type_of = ocaml_major <= 3 && ocaml_minor <= 11
+
+
+(* Generating precision dependent files & mlpack
+ ***********************************************************************)
+
+let substitute fname0 fname1 subs =
+  let ml0 = input_file fname0 in
+  let ml0 = List.fold_left (fun l (r,s) -> Str.global_replace r s l) ml0 subs in
+  output_file fname1 ~content:ml0
 
 (* [derived] is a list of (new_suffix, substitutions).  Returns the
    list of created files. *)
-let derived_files path fnames suffix derived =
-  let re = Str.regexp("\\([a-zA-Z]+\\)" ^ suffix ^ "$") in
+let derived_files fnames suffix derived =
+  let re = Str.regexp("\\([a-zA-Z]*\\)" ^ suffix ^ "$") in
   let derive l fname =
     if Str.string_match re fname 0 then (
       let seed = Str.matched_group 1 fname in
       if seed <> "lacaml" then (
-        let fname0 = Filename.concat path fname in
         let derive1 l (new_suffix, subs) =
           let fname1 = seed ^ new_suffix in
-          substitute fname0 (Filename.concat path fname1) subs;
+          substitute fname fname1 subs;
           fname1 :: l
         in
         List.fold_left derive1 l derived;
   let fnames = Sys.readdir lib in
   let mods = ref [] in
   let derive ?(add=false) suffix subs =
-    let l = derived_files lib fnames suffix subs in
+    let l = derived_files fnames suffix subs in
     if add then mods := l :: !mods in
+  let r subs = List.map (fun (r,s) -> (Str.regexp r, s)) subs in
 
-  let r subs = List.map (fun (r,s) -> (Str.regexp r, s)) subs in
   let float32 = r["FPREC", "S";  "Floatxx", "Float32";  "floatxx", "float32"]
   and float64 = r["FPREC", "D";  "Floatxx", "Float64";  "floatxx", "float64"]
   and complex32 = r["CPREC", "C";  "CBPREC", "S";
   in
   derive "_SD.mli" [("2_S.mli", float32); ("2_D.mli", float64) ];
   derive "_SD.ml"  [("2_S.ml",  float32); ("2_D.ml", float64) ] ~add:true;
+  derive "SD.ml"   [("s.ml", float32);    ("d.ml", float64)] ~add:true;
+  derive "SD.mli"  [("s.mli", float32);    ("d.mli", float64)];
   derive "_CZ.mli" [("2_C.mli", complex32); ("2_Z.mli", complex64)];
   derive "_CZ.ml"  [("2_C.ml",  complex32); ("2_Z.ml",  complex64)] ~add:true;
+  derive "CZ.ml"   [("c.ml", complex32);    ("z.ml", complex64)] ~add:true;
+  derive "CZ.mli"  [("c.mli", complex32);   ("z.mli", complex64)];
 
   let float32 = r ["NPREC", "S";  "NBPREC", "S";
                    "Numberxx", "Float32";  "numberxx", "float32"]
                     Complex32\n\
                     Complex64\n\
                     Io\n\
+                    Real_io\n\
+                    Complex_io\n\
                     Impl\n";
   List.iter (fun m ->
              let m = String.capitalize(Filename.chop_extension m) in
 (* lacaml.mli
  ***********************************************************************)
 
-let ocaml_major, ocaml_minor =
-  Scanf.sscanf Sys.ocaml_version "%i.%i" (fun v1 v2 -> v1, v2)
-
-let comment_re = Str.regexp "(\\* [^*]+\\*)[ \n\r\t]*"
-
-let input_file ?(comments=true) ?(prefix="") fname =
-  let fh = open_in fname in
-  let buf = Buffer.create 2048 in
-  try
-    while true do
-      let l = input_line fh in (* or exn *)
-      if l <> "" then (Buffer.add_string buf prefix;
-                      Buffer.add_string buf l );
-      Buffer.add_char buf '\n'
-    done;
-    assert false
-  with End_of_file ->
-    close_in fh;
-    let buf = Buffer.contents buf in
-    if comments then buf
-    else Str.global_replace comment_re "" buf
-
-
-let mli = input_file (Filename.concat lib "lacaml_SDCZ.mli")
-
+(* Replace all [include module type of] to have a self contained
+   interface that is easier to search. *)
 let include_re =
-  Str.regexp "^\\( *\\)include +\\([A-Za-z0-9]+_[SDCZ]\\|Io\\|Common\\)"
+  Str.regexp "^\\( *\\)include module type of +\\([A-Za-z0-9]+_[SDCZ]\\|\
+              Io\\|Common\\|[SDCZ]\\|Real_io\\|Complex_io\\)$"
 let open_ba_re = Str.regexp " *open Bigarray *[\n\r\t]?"
 let prec_re = Str.regexp " *open *\\(Float[0-9]+\\|Complex[0-9]+\\) *[\n\r\t]*"
-let real_io_re = Str.regexp "include module type of Real_io"
-let complex_io_re = Str.regexp "include module type of Complex_io"
 
-let mli =
-  let subst s =
-    let prefix = Str.matched_group 1 s in
-    let mname = Str.matched_group 2 s in
-    let fincl = Filename.concat lib (String.uncapitalize mname ^ ".mli") in
-    let m = input_file fincl ~prefix ~comments:false in
-    (* "open Bigarray" already present in the main file *)
-    let m = Str.global_replace open_ba_re "" m in
-    Str.global_replace prec_re "" m in
-  let mli = Str.global_substitute include_re subst mli in
-  if ocaml_major <= 3 && ocaml_minor <= 11 then
-    (* Replace the "module type" not understood before OCaml 3.12 *)
-    let mli = Str.global_replace real_io_re
-       "val pp_num : Format.formatter -> float -> unit\n    \
-	val pp_vec : (float, 'a) Io.pp_vec\n    \
-	val pp_mat : (float, 'a) Io.pp_mat" mli in
-    Str.global_replace complex_io_re
-       "val pp_num : Format.formatter -> Complex.t -> unit\n    \
-	val pp_vec : (Complex.t, 'a) Io.pp_vec\n    \
-	val pp_mat : (Complex.t, 'a) Io.pp_mat" mli
-  else mli
+let rec substitute_mli ?comments ?(prefix="") fname =
+  let content = input_file ?comments ~prefix fname in
+  Str.global_substitute include_re (subst ~prefix) content
+and subst ~prefix s =
+  let mname = Str.matched_group 2 s in
+  let fincl = String.uncapitalize mname ^ ".mli" in
+  let m = substitute_mli fincl ~comments:false
+                         ~prefix:(Str.matched_group 1 s) in
+  (* "open Bigarray" already present in the main file *)
+  let m = Str.global_replace open_ba_re "" m in
+  Str.global_replace prec_re "" m
 
+let () =
+  output_file "lacaml.mli" ~content:(substitute_mli "lacaml_SDCZ.mli")
 
-(* Output the resulting interface *)
-let () =
-  let fh = open_out (Filename.concat lib "lacaml.mli") in
-  output_string fh mli;
-  close_out fh
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.