Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* [Caml-list] Big arrays and the top level
@ 2004-10-21 17:44 Jon Harrop
  2004-10-21 18:17 ` Liam Stewart
  0 siblings, 1 reply; 2+ messages in thread
From: Jon Harrop @ 2004-10-21 17:44 UTC (permalink / raw)
  To: caml-list


Can the top level easily be made to print the contents of big arrays? I think 
this could be quite useful...

Cheers,
Jon.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Big arrays and the top level
  2004-10-21 17:44 [Caml-list] Big arrays and the top level Jon Harrop
@ 2004-10-21 18:17 ` Liam Stewart
  0 siblings, 0 replies; 2+ messages in thread
From: Liam Stewart @ 2004-10-21 18:17 UTC (permalink / raw)
  To: caml-list; +Cc: Jon Harrop


I have some code that does that [1] - you basically need to write a
printer and then tell the top level to use it.

#install_printer printer-name;;

liam

On Thu, Oct 21, 2004 at 06:44:11PM +0100, Jon Harrop wrote:
> 
> Can the top level easily be made to print the contents of big arrays? I think 
> this could be quite useful...
> 
> Cheers,
> Jon.
> 
> -------------------
> To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
> Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

[1]

Based on some code from Markus Mottl's excellent Lacaml library. It
works for fortran float vectors and matrices. It needs work, but 
suits my current needs.

open Bigarray
open Format

let print_vec f vec =
  let r = Array1.dim vec in
  fprintf f "@[";
  for i = 1 to r do
    fprintf f "@\n";
    fprintf f "@[%#11.6g@]" vec.{i};
  done;
  fprintf f "@]@\n"

let print_mat f mat =
  let r, c = Array2.dim1 mat, Array2.dim2 mat in
  let width = (get_margin ()) / (11+1) in

  let rec print_cols start num rows cols mat =
    let next_start = start + num in
    let finish = min (next_start - 1) cols in

    if cols > num then
      if start = finish then
        fprintf f "@\n@[Column %d@]@\n" start
      else
        fprintf f "@\n@[Columns %d through %d@]@\n" start finish;
    fprintf f "@[";
    for i = 1 to rows do
      fprintf f "@\n@[@;";
      for j = start to finish do
        fprintf f "@[%#11.6g@]" mat.{i,j};
        fprintf f "@;"
      done;
      fprintf f "@]"
    done;
    fprintf f "@]@\n";

    if finish = cols then
      ()
    else
      print_cols next_start num rows cols mat
  in

  print_cols 1 width r c mat

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-10-21 18:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-21 17:44 [Caml-list] Big arrays and the top level Jon Harrop
2004-10-21 18:17 ` Liam Stewart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox