123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790(* File: io.ml
Copyright (C) 2005-
Markus Mottl
email: markus.mottl@gmail.com
WWW: http://www.ocaml.info
Jane Street Holding, LLC
Author: Markus Mottl
email: markus.mottl@gmail.com
WWW: http://www.ocaml.info
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.1 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*)openFormatopenBigarrayopenComplexletfrom_col_vecv=reshape_2(genarray_of_array1v)(Array1.dimv)1letfrom_row_vecv=reshape_2(genarray_of_array1v)1(Array1.dimv)letpp_openppf=pp_open_boxppf0letpp_closeppf=pp_close_boxppf()letpp_newlineppf=pp_force_newlineppf()letpp_spaceppf=pp_print_stringppf" "letpp_end_row_newlineppf_=pp_newlineppfletpp_end_row_spaceppf_=pp_spaceppfletpp_end_col_spaceppf~row:_~col:_=pp_spaceppfletpad_strpad_cmax_lenstr=letstr_len=String.lengthstrinletdiff=max_len-str_leninifdiff=0thenstrelseletres=Bytes.makemax_lenpad_cinBytes.blit_stringstr0resdiffstr_len;Bytes.unsafe_to_stringresletpp_padded_strppfpad_cmax_lenstr=pp_print_stringppf(pad_strpad_cmax_lenstr)letsome_space=Some' 'letextract_bufbufbuf_ppf=pp_print_flushbuf_ppf();letstr=Buffer.contentsbufinBuffer.clearbuf;str,String.lengthstrletpp_el_bufpp_elbufbuf_ppfel=pp_elbuf_ppfel;extract_bufbufbuf_ppfletpp_bufppbufbuf_ppf=ppbuf_ppf;extract_bufbufbuf_ppfletignore2__=()moduleContext=structtypet=intletcreaten=ifn<1thenfailwith"Lacaml.Io.Context.create: n < 1"elsenletellipsis_default=ref"..."letvertical_default,horizontal_default=letcontext=if!Sys.interactivethenSome3elseNoneinrefcontext,refcontextletset_dim_defaultsopt_n=vertical_default:=opt_n;horizontal_default:=opt_nletget_dispreal=function|None->real,real|Somevirt->minreal(2*virt),virtendletpp_mat_gen?(pp_open=pp_open)?(pp_close=pp_close)?pp_head?pp_foot?(pp_end_row=pp_end_row_newline)?(pp_end_col=pp_end_col_space)?pp_left?pp_right?(pad=some_space)?(ellipsis=!Context.ellipsis_default)?(vertical_context=!Context.vertical_default)?(horizontal_context=!Context.horizontal_default)pp_elppfmat=letm=Array2.dim1matinifm>0then(letn=Array2.dim2matinifn>0then(letdisp_m,vertical_context=Context.get_dispmvertical_contextinletdisp_n,horizontal_context=Context.get_dispnhorizontal_contextinpp_openppf;letdo_pp_right=matchpp_rightwith|None->ignore2|Somepp_right->letbuf=Buffer.create32inletbuf_ppf=formatter_of_bufferbufin(funppfrow->letstr,n_str=pp_buf(funppf->pp_rightppfrow)bufbuf_ppfinifn_str<>0then(pp_end_colppf~row~col:n;pp_print_stringppfstr))inlethas_ver=disp_m<minletver_stop=ifhas_verthenvertical_context-1elsem-1inlethas_hor=disp_n<ninlethor_stop=ifhas_horthenhorizontal_context-1elsen-1inletsrc_col_ofs=n-horizontal_context+1inletdst_col_ofs=horizontal_contextinletsrc_row_ofs=m-vertical_context+1inletdst_row_ofs=vertical_contextinletgen_fmt_row_body~pp_nth?(ellipsis=ellipsis)?(dst_col_ofs=dst_col_ofs)src_r=pp_nth0;forc=1tohor_stopdopp_end_colppf~row:src_r~col:c;pp_nthc;done;ifhas_horthenbeginpp_end_colppf~row:src_r~col:horizontal_context;pp_print_stringppfellipsis;forc=0tohorizontal_context-1dopp_end_colppf~row:src_r~col:(src_col_ofs+c);pp_nth(dst_col_ofs+c)doneendinletfmt_label~src_rlabel=pp_print_stringppflabel;pp_end_colppf~row:src_r~col:0in(matchpadwith|Somepad_c->letbuf=Buffer.create32inletbuf_ppf=formatter_of_bufferbufinletellipsis_len=String.lengthellipsisinletmax_lens=Array.makedisp_n(ifhas_verthenellipsis_lenelse0)inletfmt_head_footpp=letheads_foots=Array.makedisp_n""inletfmt_col~src_ofs~dst_ofsc=lethead_foot,head_foot_len=pp_buf(funppf->ppppf(src_ofs+c))bufbuf_ppfinletdst_ofs_c=dst_ofs+cinheads_foots.(dst_ofs_c)<-head_foot;max_lens.(dst_ofs_c)<-maxmax_lens.(dst_ofs_c)head_foot_len;inforc=0tohor_stopdofmt_col~src_ofs:1~dst_ofs:0cdone;ifhas_horthenbeginletsrc_ofs=n-horizontal_context+1inletdst_ofs=horizontal_contextinforc=0tohorizontal_context-1dofmt_col~src_ofs~dst_ofscdone;end;heads_footsinletheads,foots=matchpp_head,pp_footwith|None,None->[||],[||]|Somepp_head,None->fmt_head_footpp_head,[||]|None,Somepp_foot->[||],fmt_head_footpp_foot|Somepp_head,Somepp_foot->fmt_head_footpp_head,fmt_head_footpp_footinletmany_strs=Array.make_matrixdisp_mdisp_n""inletfmt_strs~src_row_ofs~dst_row_ofsr=letrow=many_strs.(dst_row_ofs+r)inletsrc_r=src_row_ofs+rinletfmt_col~src_col_ofs~dst_col_ofsc=letstr,str_len=pp_el_bufpp_elbufbuf_ppfmat.{src_r,src_col_ofs+c}inletdst_c=dst_col_ofs+cinrow.(dst_c)<-str;ifstr_len>max_lens.(dst_c)thenmax_lens.(dst_c)<-str_leninforc=0tohor_stopdofmt_col~src_col_ofs:1~dst_col_ofs:0cdone;ifhas_horthenbeginforc=0tohorizontal_context-1dofmt_col~src_col_ofs~dst_col_ofscdoneendinforr=0tover_stopdofmt_strs~src_row_ofs:1~dst_row_ofs:0rdone;ifhas_verthenbeginforr=0tovertical_context-1dofmt_strs~src_row_ofs~dst_row_ofsrdoneend;lethead_label,row_labels,foot_label=matchpp_leftwith|None->"",[||],""|Somepp_left->letmax_len_row_labels_ref=ref0inletrow_labels=Array.makedisp_m""inletget_labeli=letlabel,len=pp_buf(funppf->pp_leftppfi)bufbuf_ppfinmax_len_row_labels_ref:=max!max_len_row_labels_reflen;labelinletset_labels~src_r~dst_r=fori=0tover_stopdorow_labels.(dst_r+i)<-get_label(src_r+i)doneinset_labels~src_r:1~dst_r:0;ifhas_verthenset_labels~src_r:src_row_ofs~dst_r:vertical_context;lethead0=ifpp_head<>Nonethenget_label0else""inletfoot0=ifpp_foot<>Nonethenget_label(m+1)else""inletmax_len_row_labels=!max_len_row_labels_refinletpadded_row_labels=Array.map(pad_strpad_cmax_len_row_labels)row_labelsinletpadded_head0=pad_strpad_cmax_len_row_labelshead0inletpadded_foot0=pad_strpad_cmax_len_row_labelsfoot0inpadded_head0,padded_row_labels,padded_foot0inletfmt_row_body?ellipsis~src_rrow=letpp_nthc=pp_padded_strppfpad_cmax_lens.(c)row.(c)ingen_fmt_row_body~pp_nth?ellipsissrc_rinletfmt_row_label?ellipsis~src_rrowlabel=ifpp_left<>Nonethenfmt_label~src_rlabel;fmt_row_body?ellipsis~src_rrowinletfmt_row_labels?ellipsis~src_rrowslabelsi=ifpp_left<>Nonethenfmt_label~src_rlabels.(i);fmt_row_body?ellipsis~src_rrows.(i)inlethead_foot_ellipsis=String.make(String.lengthellipsis)pad_cinifpp_head<>Nonethen(fmt_row_label~ellipsis:head_foot_ellipsis~src_r:0headshead_label;do_pp_rightppf0;pp_end_rowppf0);fmt_row_labels~src_r:1many_strsrow_labels0;forr=1tover_stopdopp_end_rowppfr;letsrc_r=r+1infmt_row_labels~src_rmany_strsrow_labelsr;do_pp_rightppfsrc_r;done;ifhas_verthenbeginpp_end_rowppfvertical_context;letv1=vertical_context+1infmt_row_label~src_r:v1(Array.makedisp_nellipsis)(String.make(String.lengthhead_label)pad_c);forr=0tovertical_context-1doletsrc_r=src_row_ofs+rinpp_end_rowppf(src_r-1);letdst_r=dst_row_ofs+rinfmt_row_labels~src_rmany_strsrow_labelsdst_r;do_pp_rightppfsrc_r;done;end;ifpp_foot<>Nonethen(pp_end_rowppfm;letm1=m+1infmt_row_label~ellipsis:head_foot_ellipsis~src_r:m1footsfoot_label;do_pp_rightppfm1)|None->letmaybe_pp_labelrow=matchpp_leftwith|None->()|Somepp_left->pp_leftppfrow;pp_end_colppf~row~col:0inletfmt_head_foot~src_rpp_head_foot=maybe_pp_labelsrc_r;letpp_nthc=pp_head_footppfcingen_fmt_row_body~pp_nth~ellipsis:""src_r;do_pp_rightppfsrc_rin(matchpp_headwith|None->()|Somepp_head->fmt_head_foot~src_r:0pp_head;pp_end_rowppf0);letfmt_row_bodysrc_r=maybe_pp_labelsrc_r;letpp_nthc=pp_elppfmat.{src_r,c+1}ingen_fmt_row_body~dst_col_ofs:(src_col_ofs-1)~pp_nthsrc_rinforr=0tover_stopdoletsrc_r=r+1infmt_row_bodysrc_r;do_pp_rightppfsrc_r;done;ifhas_verthenbeginpp_end_rowppfvertical_context;letv1=vertical_context+1inforc=0tohorizontal_context-1dopp_print_stringppfellipsis;pp_end_colppf~row:v1~col:(src_col_ofs+c);done;forr=0tovertical_context-1doletsrc_r=src_row_ofs+rinpp_end_rowppf(src_r-1);fmt_row_bodysrc_r;do_pp_rightppfsrc_r;done;end;matchpp_footwith|None->()|Somepp_foot->pp_end_rowppfm;fmt_head_foot~src_r:(m+1)pp_foot);pp_closeppf))(* Pretty-printing elements *)type'elpp_el_default=(formatter->'el->unit)refletpp_float_el_default_funppfel=fprintfppf"%G"elletpp_float_el_default=refpp_float_el_default_funletpp_complex_el_default_funppfel=fprintfppf"(%G, %Gi)"el.reel.imletpp_complex_el_default=refpp_complex_el_default_funletpp_float_elppfel=!pp_float_el_defaultppfelletpp_complex_elppfel=!pp_complex_el_defaultppfelletpp_int32_elppfn=fprintfppf"%ld"n(* Pretty-printing in standard style *)(* Vectors *)type('el,'elt)pp_vec=formatter->('el,'elt,fortran_layout)Array1.t->unitletpp_fvecppfvec=pp_mat_genpp_float_elppf(from_col_vecvec)letpp_cvecppfvec=pp_mat_genpp_complex_elppf(from_col_vecvec)letpp_ivecppfvec=pp_mat_genpp_int32_elppf(from_col_vecvec)letpp_rfvecppfvec=letmat=from_row_vecvecinpp_mat_gen~pp_end_row:pp_end_row_space~pad:Nonepp_float_elppfmatletpp_rcvecppfvec=letmat=from_row_vecvecinpp_mat_gen~pp_end_row:pp_end_row_space~pad:Nonepp_complex_elppfmatletpp_rivecppfvec=letmat=from_row_vecvecinpp_mat_gen~pp_end_row:pp_end_row_space~pad:Nonepp_int32_elppfmat(* Matrices *)type('el,'elt)pp_mat=formatter->('el,'elt,fortran_layout)Array2.t->unitletpp_fmatppfmat=pp_mat_genpp_float_elppfmatletpp_cmatppfmat=pp_mat_genpp_complex_elppfmatletpp_imatppfmat=pp_mat_genpp_int32_elppfmat(* Labeled pretty-printing *)(* Labeled matrices *)type('el,'elt)pp_labeled_mat=?pp_head:(formatter->int->unit)option->?pp_foot:(formatter->int->unit)option->?pp_left:(formatter->int->unit)option->?pp_right:(formatter->int->unit)option->?pad:charoption->?ellipsis:string->?vertical_context:Context.toption->?horizontal_context:Context.toption->unit->formatter->('el,'elt,fortran_layout)Array2.t->unitletget_pp_head_foot_mat=function|None->Somepp_print_int|Somepp_head->pp_headletget_some_pp_left_rightm=Some(funppfrow_col->ifrow_col>0&&row_col<=mthenpp_print_intppfrow_col)letget_pp_left_rightm=function|None->get_some_pp_left_rightm|Somepp_left->pp_leftletpp_labeled_mat_genpp_el?pp_head?pp_foot?pp_left?pp_right?pad?ellipsis?vertical_context?horizontal_context()ppfmat=letpp_head=get_pp_head_foot_matpp_headinletpp_foot=get_pp_head_foot_matpp_footinletm=Array2.dim1matinletpp_left=get_pp_left_rightmpp_leftinletpp_right=get_pp_left_rightmpp_rightinpp_mat_gen?pp_head?pp_foot?pp_left?pp_right?pad?ellipsis?vertical_context?horizontal_contextpp_elppfmatletpp_labeled_fmat?pp_head=pp_labeled_mat_genpp_float_el?pp_headletpp_labeled_cmat?pp_head=pp_labeled_mat_genpp_complex_el?pp_headletpp_labeled_imat?pp_head=pp_labeled_mat_genpp_int32_el?pp_head(* String-labeled matrices *)type('el,'elt)pp_lmat=?print_head:bool->?print_foot:bool->?print_left:bool->?print_right:bool->?row_labels:stringarray->?col_labels:stringarray->?pad:charoption->?ellipsis:string->?vertical_context:Context.toption->?horizontal_context:Context.toption->unit->formatter->('el,'elt,fortran_layout)Array2.t->unitletget_some_pp_head_foot_matcol_labels=Some(funppfcol->pp_print_stringppfcol_labels.(col-1))letget_pp_left_right_matprintmrow_labels=ifprintthenSome(funppfrow->ifrow>0&&row<=mthenpp_print_stringppfrow_labels.(row-1))elseNoneletpp_lmat_gen(pp_labeled_mat:('el,'elt)pp_labeled_mat)?(print_head=true)?(print_foot=true)?(print_left=true)?(print_right=true)?row_labels?col_labels?pad?ellipsis?vertical_context?horizontal_context()ppfmat=letpp_head,pp_foot=matchcol_labelswith|Somecol_labelswhenprint_head->ifArray.lengthcol_labels<>Array2.dim2mattheninvalid_arg"Io.pp_lmat_gen: dim(col_labels) <> dim2(mat)";letpp_head=get_some_pp_head_foot_matcol_labelsinletpp_foot=ifprint_footthenpp_headelseNoneinpp_head,pp_foot|Somecol_labelswhenprint_foot->None,get_some_pp_head_foot_matcol_labels|_->None,Noneinletpp_left,pp_right=matchrow_labelswith|Somerow_labels->letm=Array2.dim1matinifArray.lengthrow_labels<>mtheninvalid_arg"Io.pp_lmat_gen: dim(row_labels) <> dim1(mat)";letpp_left=get_pp_left_right_matprint_leftmrow_labelsinletpp_right=get_pp_left_right_matprint_rightmrow_labelsinpp_left,pp_right|None->None,Noneinpp_labeled_mat~pp_head~pp_foot~pp_left~pp_right?pad?ellipsis?vertical_context?horizontal_context()ppfmatletpp_lfmat?print_head=pp_lmat_genpp_labeled_fmat?print_headletpp_lcmat?print_head=pp_lmat_genpp_labeled_cmat?print_headletpp_limat?print_head=pp_lmat_genpp_labeled_imat?print_head(* Labeled vectors *)type('el,'elt)pp_labeled_vec=?pp_head:(formatter->int->unit)->?pp_foot:(formatter->int->unit)->?pp_left:(formatter->int->unit)option->?pp_right:(formatter->int->unit)->?pad:charoption->?ellipsis:string->?vertical_context:Context.toption->?horizontal_context:Context.toption->unit->formatter->('el,'elt,fortran_layout)Array1.t->unitletpp_labeled_vec_genpp_el?pp_head?pp_foot?pp_left?pp_right?pad?ellipsis?vertical_context?horizontal_context()ppfvec=letm=Array1.dimvecinletpp_left=matchpp_leftwith|None->get_some_pp_left_rightm|SomeNone->None|Some(Somepp_left)->Somepp_leftinletmat=from_col_vecvecinpp_mat_gen?pp_head?pp_foot?pp_left?pp_right?pad?ellipsis?vertical_context?horizontal_contextpp_elppfmatletpp_labeled_fvec?pp_head=pp_labeled_vec_genpp_float_el?pp_headletpp_labeled_cvec?pp_head=pp_labeled_vec_genpp_complex_el?pp_headletpp_labeled_ivec?pp_head=pp_labeled_vec_genpp_int32_el?pp_headletsome_pp_print_int=Somepp_print_intletpp_labeled_rvec_genpp_el?pp_head:this_pp_head?pp_foot:this_pp_foot?pp_left:this_pp_left?pp_right:this_pp_right?pad?ellipsis?vertical_context?horizontal_context()ppfvec=letpp_head=matchthis_pp_leftwith|None->some_pp_print_int|SomeNone->None|Some(Somethis_pp_left)->Somethis_pp_leftinletpp_foot=this_pp_rightinletpp_left=this_pp_headinletpp_right=this_pp_footinletmat=from_row_vecvecinpp_mat_gen?pp_head?pp_foot?pp_left?pp_right?pad?ellipsis?vertical_context?horizontal_contextpp_elppfmatletpp_labeled_rfvec?pp_head=pp_labeled_rvec_genpp_float_el?pp_headletpp_labeled_rcvec?pp_head=pp_labeled_rvec_genpp_complex_el?pp_headletpp_labeled_rivec?pp_head=pp_labeled_rvec_genpp_int32_el?pp_head(* String-labeled vectors *)type('el,'elt)pp_lvec=?print_head:bool->?print_foot:bool->?print_left:bool->?print_right:bool->?labels:stringarray->?name:string->?pad:charoption->?ellipsis:string->?vertical_context:Context.toption->?horizontal_context:Context.toption->unit->formatter->('el,'elt,fortran_layout)Array1.t->unitletget_lvec_name=function|None->None|Somename->Some[|name|]letpp_lvec_gen(pp_lmat:('el,'elt)pp_lmat)?print_head?print_foot?print_left?(print_right=false)?labels:row_labels?name?pad?ellipsis?vertical_context?horizontal_context()ppfvec=letmat=from_col_vecvecinletcol_labels=get_lvec_namenameinpp_lmat?print_head?print_foot?print_left~print_right?row_labels?col_labels?pad?ellipsis?vertical_context?horizontal_context()ppfmatletpp_lfvec?print_head=pp_lvec_genpp_lfmat?print_headletpp_lcvec?print_head=pp_lvec_genpp_lcmat?print_headletpp_livec?print_head=pp_lvec_genpp_limat?print_headletpp_rlvec_gen(pp_lmat:('el,'elt)pp_lmat)?print_head:print_left?print_foot:print_right?print_left:print_head?print_right:this_print_right?labels:col_labels?name?pad?ellipsis?vertical_context?horizontal_context()ppfvec=letmat=from_row_vecvecinletrow_labels=get_lvec_namenameinletprint_foot=matchthis_print_rightwith|None->false|Somethis_print_right->this_print_rightinpp_lmat?print_head~print_foot?print_left?print_right?row_labels?col_labels?pad?ellipsis?vertical_context?horizontal_context()ppfmatletpp_rlfvec?print_head=pp_rlvec_genpp_lfmat?print_headletpp_rlcvec?print_head=pp_rlvec_genpp_lcmat?print_headletpp_rlivec?print_head=pp_rlvec_genpp_limat?print_head(* Pretty-printing in OCaml-style *)(* Vectors *)type('el,'elt)pp_el_ovec=formatter->(formatter->'el->unit)->('el,'elt,fortran_layout)Array1.t->unittype('el,'elt)pp_ovec=formatter->('el,'elt,fortran_layout)Array1.t->unitletpp_ocaml_open_vecppf=pp_open_boxppf2;pp_print_stringppf"[|";pp_force_newlineppf()letpp_ocaml_close_vecppf=pp_print_stringppf";";pp_close_boxppf();pp_force_newlineppf();pp_print_stringppf"|]"letpp_end_row_semippf_=pp_print_stringppf";";pp_force_newlineppf()letpp_ovecppfpp_elvec=ifArray1.dimvec=0thenpp_print_stringppf"[||]"elsepp_mat_gen~pp_open:pp_ocaml_open_vec~pp_close:pp_ocaml_close_vec~pp_end_row:pp_end_row_semipp_elppf(from_col_vecvec)letpp_ocaml_open_rvecppf=pp_open_boxppf2;pp_print_stringppf"[| "letpp_ocaml_close_rvecppf=pp_print_stringppf" |]";pp_close_boxppf()letpp_end_row_semi_spaceppf_=pp_print_stringppf"; "letpp_rovecppfpp_elvec=ifArray1.dimvec=0thenpp_print_stringppf"[||]"elsepp_mat_gen~pp_open:pp_ocaml_open_rvec~pp_close:pp_ocaml_close_rvec~pp_end_row:pp_end_row_semi_space~pad:Nonepp_elppf(from_col_vecvec)letpp_ofvecppfvec=pp_ovecppfpp_float_elvecletpp_ocvecppfvec=pp_ovecppfpp_complex_elvecletpp_oivecppfvec=pp_ovecppfpp_int32_elvecletpp_rofvecppfvec=pp_rovecppfpp_float_elvecletpp_rocvecppfvec=pp_rovecppfpp_complex_elvecletpp_roivecppfvec=pp_rovecppfpp_int32_elvec(* Matrices *)type('el,'elt)pp_omat=formatter->('el,'elt,fortran_layout)Array2.t->unitletpp_ocaml_open_matppf=pp_open_boxppf2;pp_print_stringppf"[|";pp_force_newlineppf();pp_print_stringppf"[| "letpp_ocaml_close_matppf=pp_print_stringppf" |];";pp_close_boxppf();pp_force_newlineppf();pp_print_stringppf"|]"letpp_ocaml_end_row_matppf_=pp_print_stringppf" |];";pp_force_newlineppf();pp_print_stringppf"[| "letpp_end_col_semi_spaceppf~row:_~col:_=pp_print_stringppf"; "letpp_omatppfpp_elmat=ifArray2.dim1mat=0||Array2.dim2mat=0thenpp_print_stringppf"[||]"elsepp_mat_gen~pp_open:pp_ocaml_open_mat~pp_close:pp_ocaml_close_mat~pp_end_row:pp_ocaml_end_row_mat~pp_end_col:pp_end_col_semi_spacepp_elppfmatletpp_ofmatppfmat=pp_omatppfpp_float_elmatletpp_ocmatppfmat=pp_omatppfpp_complex_elmatletpp_oimatppfmat=pp_omatppfpp_int32_elmat(* Good pretty-printers for toplevels *)moduleToplevel=struct(* Vectors *)letpp_labeled_colppfc=ifc>0thenfprintfppf"C%d"cletpp_labeled_rowppfr=ifr>0thenfprintfppf"R%d"rletgen_pp_vecpp_elppfvec=pp_mat_gen~pp_left:pp_labeled_rowpp_elppf(from_col_vecvec)letpp_fvecppfvec=gen_pp_vecpp_float_elppfvecletpp_cvecppfvec=gen_pp_vecpp_complex_elppfvecletpp_ivecppfvec=gen_pp_vecpp_int32_elppfvecletgen_pp_rvecpp_elppfvec=pp_mat_gen~pp_head:pp_labeled_rowpp_elppf(from_row_vecvec)letpp_rfvecppfvec=gen_pp_rvecpp_float_elppfvecletpp_rcvecppfvec=gen_pp_rvecpp_complex_elppfvecletpp_rivecppfvec=gen_pp_rvecpp_int32_elppfvec(* Matrices *)letgen_pp_matpp_elppfmat=pp_mat_gen~pp_head:pp_labeled_col~pp_left:pp_labeled_rowpp_elppfmatletpp_fmatppfmat=gen_pp_matpp_float_elppfmatletpp_cmatppfmat=gen_pp_matpp_complex_elppfmatletpp_imatppfmat=gen_pp_matpp_int32_elppfmatletlscn=Context.set_dim_defaults(Some(Context.createn))end