From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id UAA07596; Thu, 21 Oct 2004 20:17:15 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA08419 for ; Thu, 21 Oct 2004 20:17:13 +0200 (MET DST) Received: from smtp.istop.com (smtp.istop.com [66.11.167.126]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i9LIHCaj014006 for ; Thu, 21 Oct 2004 20:17:13 +0200 Received: from fanshawe.localdomain (annalee.tor.istop.com [66.11.182.16]) by smtp.istop.com (Postfix) with ESMTP id F42072B3EE; Thu, 21 Oct 2004 14:19:42 -0400 (EDT) Received: by fanshawe.localdomain (Postfix, from userid 500) id B7E167A1; Thu, 21 Oct 2004 14:17:10 -0400 (EDT) Date: Thu, 21 Oct 2004 14:17:10 -0400 From: Liam Stewart To: caml-list@inria.fr Cc: Jon Harrop Subject: Re: [Caml-list] Big arrays and the top level Message-ID: <20041021181710.GA11358@ualberta.net> References: <200410211844.11551.jon@jdh30.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200410211844.11551.jon@jdh30.plus.com> User-Agent: Mutt/1.4.1i X-Miltered: at nez-perce with ID 4177FD28.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 2004:99 bug:01 faq:01 faq:01 beginner's:01 beginners:01 lacaml:01 vectors:01 fprintf:01 fprintf:01 arrays:01 arrays:01 bin:01 mat:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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