12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152(* File: block_diag.ml
OCaml-GPR - Gaussian Processes for OCaml
Copyright (C) 2009- 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
*)openCoreopenLacaml.Dtypet={data:matarray;n:int}letcheck_square(i,size)mat=letm=Mat.dim1matinletn=Mat.dim2matinifm=ntheni+1,size+nelsefailwithf"Block_diag.check_square: matrix at index %d not square: m = %d, n = %d"imn()letcreatedata={data;n=snd(Array.fold~f:check_square~init:(0,0)data)}letcopyt={twithdata=Array.map~f:(funmat->lacpymat)t.data}letreraise_exclociexc=Exn.reraisefexc"Block_diag.%s: failed at index %d"loci()letpotrf?jittert=Array.iterit.data~f:(funimat->trypotrf?jittermatwithexc->reraise_exc"potrf"iexc)letpotri?jitter?factorizet=Array.iterit.data~f:(funimat->trypotri?jitter?factorizematwithexc->reraise_exc"potri"iexc)