Markus Mottl avatar Markus Mottl committed 2736239

Improved printing in toplevels

Comments (0)

Files changed (4)

+2009-01-14:  Greatly improved defaults for printing in toplevels.
+
 2009-01-13:  Added context printing options to matrices.  This feature
              allows human-readable printing of huge matrices by only
              emitting specified horizontal and vertical contexts.

lib/install_printers.ml

 let printers =
   [
-    "Lacaml.Io.pp_rfvec";
-    "Lacaml.Io.pp_rcvec";
-    "Lacaml.Io.pp_rivec";
-    "Lacaml.Io.pp_fmat";
-    "Lacaml.Io.pp_cmat";
-    "Lacaml.Io.pp_imat";
+    "Lacaml.Io.pp_top_rfvec";
+    "Lacaml.Io.pp_top_rcvec";
+    "Lacaml.Io.pp_top_rivec";
+    "Lacaml.Io.pp_top_fmat";
+    "Lacaml.Io.pp_top_cmat";
+    "Lacaml.Io.pp_top_imat";
   ]
 
 let eval_string
       eval_string cmd && install_printers printers
 
 let set_contexts () =
-  let cmd = 
+  let cmd =
     "Lacaml.Io.Context.set_dim_defaults (Some (Lacaml.Io.Context.create 3));;"
   in
   eval_string cmd
           if pp_head <> None then (
             fmt_row_label
               ~ellipsis:head_foot_ellipsis ~src_r:0 heads head_label;
-            do_pp_right ppf 0);
-          for r = 0 to ver_stop do
+              do_pp_right ppf 0;
+            pp_end_row ppf 0);
+          fmt_row_labels ~src_r:1 many_strs row_labels 0;
+          for r = 1 to ver_stop do
             pp_end_row ppf r;
             let src_r = r + 1 in
             fmt_row_labels ~src_r many_strs row_labels r;
 let pp_float_el ppf el = !pp_float_el_default ppf el
 let pp_complex_el ppf el = !pp_complex_el_default ppf el
 
-let pp_print_int32 ppf n = fprintf ppf "%ld" n
+let pp_int32_el ppf n = fprintf ppf "%ld" n
 
 
 (* Pretty-printing in standard style *)
 
 let pp_fvec ppf vec = pp_mat_gen pp_float_el ppf (from_col_vec vec)
 let pp_cvec ppf vec = pp_mat_gen pp_complex_el ppf (from_col_vec vec)
-let pp_ivec ppf vec = pp_mat_gen pp_print_int32 ppf (from_col_vec vec)
+let pp_ivec ppf vec = pp_mat_gen pp_int32_el ppf (from_col_vec vec)
 
 let pp_rfvec ppf vec =
   let mat = from_row_vec vec in
 
 let pp_rivec ppf vec =
   let mat = from_row_vec vec in
-  pp_mat_gen ~pp_end_row:pp_end_row_space ~pad:None pp_print_int32 ppf mat
+  pp_mat_gen ~pp_end_row:pp_end_row_space ~pad:None pp_int32_el ppf mat
 
 (* Matrices *)
 
 
 let pp_fmat ppf mat = pp_mat_gen pp_float_el ppf mat
 let pp_cmat ppf mat = pp_mat_gen pp_complex_el ppf mat
-let pp_imat ppf mat = pp_mat_gen pp_print_int32 ppf mat
+let pp_imat ppf mat = pp_mat_gen pp_int32_el ppf mat
 
 
 (* Labeled pretty-printing *)
 
 let pp_labeled_fmat ?pp_head = pp_labeled_mat_gen pp_float_el ?pp_head
 let pp_labeled_cmat ?pp_head = pp_labeled_mat_gen pp_complex_el ?pp_head
-let pp_labeled_imat ?pp_head = pp_labeled_mat_gen pp_print_int32 ?pp_head
+let pp_labeled_imat ?pp_head = pp_labeled_mat_gen pp_int32_el ?pp_head
 
 (* String-labeled matrices *)
 
 
 let pp_labeled_fvec ?pp_head = pp_labeled_vec_gen pp_float_el ?pp_head
 let pp_labeled_cvec ?pp_head = pp_labeled_vec_gen pp_complex_el ?pp_head
-let pp_labeled_ivec ?pp_head = pp_labeled_vec_gen pp_print_int32 ?pp_head
+let pp_labeled_ivec ?pp_head = pp_labeled_vec_gen pp_int32_el ?pp_head
 
 let some_pp_print_int = Some pp_print_int
 
 
 let pp_labeled_rfvec ?pp_head = pp_labeled_rvec_gen pp_float_el ?pp_head
 let pp_labeled_rcvec ?pp_head = pp_labeled_rvec_gen pp_complex_el ?pp_head
-let pp_labeled_rivec ?pp_head = pp_labeled_rvec_gen pp_print_int32 ?pp_head
+let pp_labeled_rivec ?pp_head = pp_labeled_rvec_gen pp_int32_el ?pp_head
 
 (* String-labeled vectors *)
 
 
 let pp_ofvec ppf vec = pp_ovec ppf pp_float_el vec
 let pp_ocvec ppf vec = pp_ovec ppf pp_complex_el vec
-let pp_oivec ppf vec = pp_ovec ppf pp_print_int32 vec
+let pp_oivec ppf vec = pp_ovec ppf pp_int32_el vec
 
 let pp_rofvec ppf vec = pp_rovec ppf pp_float_el vec
 let pp_rocvec ppf vec = pp_rovec ppf pp_complex_el vec
-let pp_roivec ppf vec = pp_rovec ppf pp_print_int32 vec
+let pp_roivec ppf vec = pp_rovec ppf pp_int32_el vec
 
 (* Matrices *)
 
 
 let pp_ofmat ppf mat = pp_omat ppf pp_float_el mat
 let pp_ocmat ppf mat = pp_omat ppf pp_complex_el mat
-let pp_oimat ppf mat = pp_omat ppf pp_print_int32 mat
+let pp_oimat ppf mat = pp_omat ppf pp_int32_el mat
+
+
+(* Good pretty-printers for toplevels *)
+
+(* Vectors *)
+
+let pp_labeled_col ppf c = if c > 0 then fprintf ppf "C%d" c
+let pp_labeled_row ppf r = if r > 0 then fprintf ppf "R%d" r
+
+let gen_pp_top_vec pp_el ppf vec =
+  pp_mat_gen ~pp_left:pp_labeled_row pp_el ppf (from_col_vec vec)
+
+let pp_top_fvec ppf vec = gen_pp_top_vec pp_float_el ppf vec
+let pp_top_cvec ppf vec = gen_pp_top_vec pp_complex_el ppf vec
+let pp_top_ivec ppf vec = gen_pp_top_vec pp_int32_el ppf vec
+
+let gen_pp_top_rvec pp_el ppf vec =
+  pp_mat_gen ~pp_head:pp_labeled_row pp_el ppf (from_row_vec vec)
+
+let pp_top_rfvec ppf vec = gen_pp_top_rvec pp_float_el ppf vec
+let pp_top_rcvec ppf vec = gen_pp_top_rvec pp_complex_el ppf vec
+let pp_top_rivec ppf vec = gen_pp_top_rvec pp_int32_el ppf vec
+
+(* Matrices *)
+
+let gen_pp_top_mat pp_el ppf mat =
+  pp_mat_gen ~pp_head:pp_labeled_col ~pp_left:pp_labeled_row pp_el ppf mat
+
+let pp_top_fmat ppf mat = gen_pp_top_mat pp_float_el ppf mat
+let pp_top_cmat ppf mat = gen_pp_top_mat pp_complex_el ppf mat
+let pp_top_imat ppf mat = gen_pp_top_mat pp_int32_el ppf mat
 val pp_complex_el_default : Complex.t pp_el_default
 (** fprintf ppf "(%G, %Gi)" el.re el.im *)
 
-val pp_print_int32 : formatter -> int32 -> unit
+val pp_int32_el : formatter -> int32 -> unit
 (** fprintf ppf "%ld" el *)
 
 
 
     @param pp_head default = no default (= no printing)
     @param pp_foot default = no default (= no printing)
-    @param pp_left default = [Some pp_print_int32] for vector rows/cols
+    @param pp_left default = [Some pp_int32_el] for vector rows/cols
                              (= not in header/footer row/col)
     @param pp_right default = no default (= no printing)
 *)
     If [None] is passed as argument for the default printers, the
     corresponding labels will not be printed.
 
-    @param pp_head default = [Some pp_print_int32]
-    @param pp_foot default = [Some pp_print_int32]
-    @param pp_left default = [Some pp_print_int32] for matrix rows
+    @param pp_head default = [Some pp_int32_el]
+    @param pp_foot default = [Some pp_int32_el]
+    @param pp_left default = [Some pp_int32_el] for matrix rows
                              (= not in header/footer row)
-    @param pp_right default = [Some pp_print_int32] for matrix rows
+    @param pp_right default = [Some pp_int32_el] for matrix rows
                              (= not in header/footer row)
 *)
 
 val pp_ofmat : (float, 'elt) pp_omat
 val pp_ocmat : (Complex.t, 'elt) pp_omat
 val pp_oimat : (int32, 'elt) pp_omat
+
+
+(** {6 Good pretty-printers for toplevels} *)
+
+(** These pretty-printers will use index labels for easier identification
+    of rows and columns. *)
+
+val pp_top_fvec : (float, 'elt) pp_vec
+val pp_top_cvec : (Complex.t, 'elt) pp_vec
+val pp_top_ivec : (int32, 'elt) pp_vec
+val pp_top_rfvec : (float, 'elt) pp_vec
+val pp_top_rcvec : (Complex.t, 'elt) pp_vec
+val pp_top_rivec : (int32, 'elt) pp_vec
+
+val pp_top_fmat : (float, 'elt) pp_mat
+val pp_top_cmat : (Complex.t, 'elt) pp_mat
+val pp_top_imat : (int32, 'elt) pp_mat
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.