123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588(**************************************************************************)(* *)(* OCaml *)(* *)(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)(* Nicolas Ojeda Bar, LexiFi *)(* *)(* Copyright 2018 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)externalneg:float->float="%negfloat"externaladd:float->float->float="%addfloat"externalsub:float->float->float="%subfloat"externalmul:float->float->float="%mulfloat"externaldiv:float->float->float="%divfloat"externalrem:float->float->float="caml_fmod_float""fmod"[@@unboxed][@@noalloc]externalfma:float->float->float->float="caml_fma_float""caml_fma"[@@unboxed][@@noalloc]externalabs:float->float="%absfloat"letzero=0.letone=1.letminus_one=-1.letinfinity=Stdlib.infinityletneg_infinity=Stdlib.neg_infinityletnan=Stdlib.nanletquiet_nan=nanexternalfloat_of_bits:int64->float="caml_int64_float_of_bits""caml_int64_float_of_bits_unboxed"[@@unboxed][@@noalloc]letsignaling_nan=float_of_bits0x7F_F0_00_00_00_00_00_01Lletis_finite(x:float)=x-.x=0.letis_infinite(x:float)=1./.x=0.letis_nan(x:float)=x<>xletpi=0x1.921fb54442d18p+1letmax_float=Stdlib.max_floatletmin_float=Stdlib.min_floatletepsilon=Stdlib.epsilon_floatexternalof_int:int->float="%floatofint"externalto_int:float->int="%intoffloat"externalof_string:string->float="caml_float_of_string"letof_string_opt=Stdlib.float_of_string_optletto_string=Stdlib.string_of_floattypefpclass=Stdlib.fpclass=FP_normal|FP_subnormal|FP_zero|FP_infinite|FP_nanexternalclassify_float:(float[@unboxed])->fpclass="caml_classify_float""caml_classify_float_unboxed"[@@noalloc]externalpow:float->float->float="caml_power_float""pow"[@@unboxed][@@noalloc]externalsqrt:float->float="caml_sqrt_float""sqrt"[@@unboxed][@@noalloc]externalcbrt:float->float="caml_cbrt_float""caml_cbrt"[@@unboxed][@@noalloc]externalexp:float->float="caml_exp_float""exp"[@@unboxed][@@noalloc]externalexp2:float->float="caml_exp2_float""caml_exp2"[@@unboxed][@@noalloc]externallog:float->float="caml_log_float""log"[@@unboxed][@@noalloc]externallog10:float->float="caml_log10_float""log10"[@@unboxed][@@noalloc]externallog2:float->float="caml_log2_float""caml_log2"[@@unboxed][@@noalloc]externalexpm1:float->float="caml_expm1_float""caml_expm1"[@@unboxed][@@noalloc]externallog1p:float->float="caml_log1p_float""caml_log1p"[@@unboxed][@@noalloc]externalcos:float->float="caml_cos_float""cos"[@@unboxed][@@noalloc]externalsin:float->float="caml_sin_float""sin"[@@unboxed][@@noalloc]externaltan:float->float="caml_tan_float""tan"[@@unboxed][@@noalloc]externalacos:float->float="caml_acos_float""acos"[@@unboxed][@@noalloc]externalasin:float->float="caml_asin_float""asin"[@@unboxed][@@noalloc]externalatan:float->float="caml_atan_float""atan"[@@unboxed][@@noalloc]externalatan2:float->float->float="caml_atan2_float""atan2"[@@unboxed][@@noalloc]externalhypot:float->float->float="caml_hypot_float""caml_hypot"[@@unboxed][@@noalloc]externalcosh:float->float="caml_cosh_float""cosh"[@@unboxed][@@noalloc]externalsinh:float->float="caml_sinh_float""sinh"[@@unboxed][@@noalloc]externaltanh:float->float="caml_tanh_float""tanh"[@@unboxed][@@noalloc]externalacosh:float->float="caml_acosh_float""caml_acosh"[@@unboxed][@@noalloc]externalasinh:float->float="caml_asinh_float""caml_asinh"[@@unboxed][@@noalloc]externalatanh:float->float="caml_atanh_float""caml_atanh"[@@unboxed][@@noalloc]externalerf:float->float="caml_erf_float""caml_erf"[@@unboxed][@@noalloc]externalerfc:float->float="caml_erfc_float""caml_erfc"[@@unboxed][@@noalloc]externaltrunc:float->float="caml_trunc_float""caml_trunc"[@@unboxed][@@noalloc]externalround:float->float="caml_round_float""caml_round"[@@unboxed][@@noalloc]externalceil:float->float="caml_ceil_float""ceil"[@@unboxed][@@noalloc]externalfloor:float->float="caml_floor_float""floor"[@@unboxed][@@noalloc]letis_integerx=x=truncx&&is_finitexexternalnext_after:float->float->float="caml_nextafter_float""caml_nextafter"[@@unboxed][@@noalloc]letsuccx=next_afterxinfinityletpredx=next_afterxneg_infinityexternalcopy_sign:float->float->float="caml_copysign_float""caml_copysign"[@@unboxed][@@noalloc]externalsign_bit:(float[@unboxed])->bool="caml_signbit_float""caml_signbit"[@@noalloc]externalfrexp:float->float*int="caml_frexp_float"externalldexp:(float[@unboxed])->(int[@untagged])->(float[@unboxed])="caml_ldexp_float""caml_ldexp_float_unboxed"[@@noalloc]externalmodf:float->float*float="caml_modf_float"typet=floatexternalcompare:float->float->int="%compare"letequalxy=comparexy=0let[@inline]min(x:float)(y:float)=ify>x||(not(sign_bity)&&sign_bitx)thenifis_nanythenyelsexelseifis_nanxthenxelseylet[@inline]max(x:float)(y:float)=ify>x||(not(sign_bity)&&sign_bitx)thenifis_nanxthenxelseyelseifis_nanythenyelsexlet[@inline]min_max(x:float)(y:float)=ifis_nanx||is_nanythen(nan,nan)elseify>x||(not(sign_bity)&&sign_bitx)then(x,y)else(y,x)let[@inline]min_num(x:float)(y:float)=ify>x||(not(sign_bity)&&sign_bitx)thenifis_nanxthenyelsexelseifis_nanythenxelseylet[@inline]max_num(x:float)(y:float)=ify>x||(not(sign_bity)&&sign_bitx)thenifis_nanythenxelseyelseifis_nanxthenyelsexlet[@inline]min_max_num(x:float)(y:float)=ifis_nanxthen(y,y)elseifis_nanythen(x,x)elseify>x||(not(sign_bity)&&sign_bitx)then(x,y)else(y,x)externalseeded_hash_param:int->int->int->'a->int="caml_hash"[@@noalloc]letseeded_hashseedx=seeded_hash_param10100seedxlethashx=seeded_hash_param101000xmoduleArray=structtypet=floatarrayexternallength:t->int="%floatarray_length"externalget:t->int->float="%floatarray_safe_get"externalset:t->int->float->unit="%floatarray_safe_set"externalcreate:int->t="caml_floatarray_create"externalunsafe_get:t->int->float="%floatarray_unsafe_get"externalunsafe_set:t->int->float->unit="%floatarray_unsafe_set"letunsafe_fillaofslenv=fori=ofstoofs+len-1dounsafe_setaivdoneexternalunsafe_blit:t->int->t->int->int->unit="caml_floatarray_blit"[@@noalloc]letcheckaofslenmsg=ifofs<0||len<0||ofs+len<0||ofs+len>lengthatheninvalid_argmsgletmakenv=letresult=createninunsafe_fillresult0nv;resultletinitlf=ifl<0theninvalid_arg"Float.Array.init"elseletres=createlinfori=0tol-1dounsafe_setresi(fi)done;resletappenda1a2=letl1=lengtha1inletl2=lengtha2inletresult=create(l1+l2)inunsafe_blita10result0l1;unsafe_blita20resultl1l2;result(* next 3 functions: modified copy of code from string.ml *)letensure_ge(x:int)y=ifx>=ythenxelseinvalid_arg"Float.Array.concat"letrecsum_lengthsacc=function|[]->acc|hd::tl->sum_lengths(ensure_ge(lengthhd+acc)acc)tlletconcatl=letlen=sum_lengths0linletresult=createleninletrecloopli=matchlwith|[]->assert(i=len)|hd::tl->lethlen=lengthhdinunsafe_blithd0resultihlen;looptl(i+hlen)inloopl0;resultletsubaofslen=checkaofslen"Float.Array.sub";letresult=createleninunsafe_blitaofsresult0len;resultletcopya=letl=lengthainletresult=createlinunsafe_blita0result0l;resultletfillaofslenv=checkaofslen"Float.Array.fill";unsafe_fillaofslenvletblitsrcsofsdstdofslen=checksrcsofslen"Float.array.blit";checkdstdofslen"Float.array.blit";unsafe_blitsrcsofsdstdofslenletto_lista=List.init(lengtha)(unsafe_geta)letof_listl=letresult=create(List.lengthl)inletrecfillil=matchlwith|[]->result|h::t->unsafe_setresultih;fill(i+1)tinfill0l(* duplicated from array.ml *)letiterfa=fori=0tolengtha-1dof(unsafe_getai)done(* duplicated from array.ml *)letiter2fab=iflengtha<>lengthbtheninvalid_arg"Float.Array.iter2: arrays must have the same length"elsefori=0tolengtha-1dof(unsafe_getai)(unsafe_getbi)doneletmapfa=letl=lengthainletr=createlinfori=0tol-1dounsafe_setri(f(unsafe_getai))done;r(* duplicated from array.ml *)letmap_inplacefa=fori=0tolengtha-1dounsafe_setai(f(unsafe_getai))doneletmap2fab=letla=lengthainletlb=lengthbinifla<>lbtheninvalid_arg"Float.Array.map2: arrays must have the same length"elsebeginletr=createlainfori=0tola-1dounsafe_setri(f(unsafe_getai)(unsafe_getbi))done;rend(* duplicated from array.ml *)letiterifa=fori=0tolengtha-1dofi(unsafe_getai)doneletmapifa=letl=lengthainletr=createlinfori=0tol-1dounsafe_setri(fi(unsafe_getai))done;r(* duplicated from array.ml *)letmapi_inplacefa=fori=0tolengtha-1dounsafe_setai(fi(unsafe_getai))done(* duplicated from array.ml *)letfold_leftfxa=letr=refxinfori=0tolengtha-1dor:=f!r(unsafe_getai)done;!r(* duplicated from array.ml *)letfold_rightfax=letr=refxinfori=lengtha-1downto0dor:=f(unsafe_getai)!rdone;!r(* duplicated from array.ml *)letexistspa=letn=lengthainletrecloopi=ifi=nthenfalseelseifp(unsafe_getai)thentrueelseloop(i+1)inloop0(* duplicated from array.ml *)letfor_allpa=letn=lengthainletrecloopi=ifi=nthentrueelseifp(unsafe_getai)thenloop(i+1)elsefalseinloop0(* duplicated from array.ml *)letmemxa=letn=lengthainletrecloopi=ifi=nthenfalseelseifcompare(unsafe_getai)x=0thentrueelseloop(i+1)inloop0(* mostly duplicated from array.ml, but slightly different *)letmem_ieeexa=letn=lengthainletrecloopi=ifi=nthenfalseelseifx=(unsafe_getai)thentrueelseloop(i+1)inloop0(* duplicated from array.ml *)letfind_optpa=letn=lengthainletrecloopi=ifi=nthenNoneelseletx=unsafe_getaiinifpxthenSomexelseloop(i+1)inloop0(* duplicated from array.ml *)letfind_indexpa=letn=lengthainletrecloopi=ifi=nthenNoneelseifp(unsafe_getai)thenSomeielseloop(i+1)inloop0(* duplicated from array.ml *)letfind_mapfa=letn=lengthainletrecloopi=ifi=nthenNoneelsematchf(unsafe_getai)with|None->loop(i+1)|Some_asr->rinloop0(* duplicated from array.ml *)letfind_mapifa=letn=lengthainletrecloopi=ifi=nthenNoneelsematchfi(unsafe_getai)with|None->loop(i+1)|Some_asr->rinloop0(* duplicated from array.ml *)exceptionBottomofintletsortcmpa=letmaxsonli=leti31=i+i+i+1inletx=refi31inifi31+2<lthenbeginifcmp(getai31)(geta(i31+1))<0thenx:=i31+1;ifcmp(geta!x)(geta(i31+2))<0thenx:=i31+2;!xendelseifi31+1<l&&cmp(getai31)(geta(i31+1))<0theni31+1elseifi31<ltheni31elseraise(Bottomi)inletrectrickledownlie=letj=maxsonliinifcmp(getaj)e>0thenbeginsetai(getaj);trickledownlje;endelsebeginsetaie;end;inlettricklelie=trytrickledownliewithBottomi->setaieinletrecbubbledownli=letj=maxsonliinsetai(getaj);bubbledownljinletbubbleli=trybubbledownliwithBottomi->iinletrectrickleupie=letfather=(i-1)/3inassert(i<>father);ifcmp(getafather)e<0thenbeginsetai(getafather);iffather>0thentrickleupfathereelseseta0e;endelsebeginsetaie;end;inletl=lengthainfori=(l+1)/3-1downto0dotrickleli(getai);done;fori=l-1downto2dolete=(getai)insetai(geta0);trickleup(bubblei0)e;done;ifl>1then(lete=(geta1)inseta1(geta0);seta0e)(* duplicated from array.ml, except for the call to [create] *)letcutoff=5letstable_sortcmpa=letmergesrc1ofssrc1lensrc2src2ofssrc2lendstdstofs=letsrc1r=src1ofs+src1lenandsrc2r=src2ofs+src2leninletrecloopi1s1i2s2d=ifcmps1s2<=0thenbeginsetdstds1;leti1=i1+1inifi1<src1rthenloopi1(getai1)i2s2(d+1)elseblitsrc2i2dst(d+1)(src2r-i2)endelsebeginsetdstds2;leti2=i2+1inifi2<src2rthenloopi1s1i2(getsrc2i2)(d+1)elseblitai1dst(d+1)(src1r-i1)endinloopsrc1ofs(getasrc1ofs)src2ofs(getsrc2src2ofs)dstofs;inletisorttosrcofsdstdstofslen=fori=0tolen-1dolete=(geta(srcofs+i))inletj=ref(dstofs+i-1)inwhile(!j>=dstofs&&cmp(getdst!j)e>0)dosetdst(!j+1)(getdst!j);decrj;done;setdst(!j+1)e;done;inletrecsorttosrcofsdstdstofslen=iflen<=cutoffthenisorttosrcofsdstdstofslenelsebeginletl1=len/2inletl2=len-l1insortto(srcofs+l1)dst(dstofs+l1)l2;sorttosrcofsa(srcofs+l2)l1;merge(srcofs+l2)l1dst(dstofs+l1)l2dstdstofs;end;inletl=lengthainifl<=cutoffthenisortto0a0lelsebeginletl1=l/2inletl2=l-l1inlett=createl2insorttol1t0l2;sortto0al2l1;mergel2l1t0l2a0;endletfast_sort=stable_sort(* duplicated from array.ml *)letto_seqa=letrecauxi()=ifi<lengthathenletx=unsafe_getaiinSeq.Cons(x,aux(i+1))elseSeq.Nilinaux0(* duplicated from array.ml *)letto_seqia=letrecauxi()=ifi<lengthathenletx=unsafe_getaiinSeq.Cons((i,x),aux(i+1))elseSeq.Nilinaux0(* mostly duplicated from array.ml *)letof_rev_listl=letlen=List.lengthlinleta=createleninletrecfilli=function[]->a|hd::tl->unsafe_setaihd;fill(i-1)tlinfill(len-1)l(* duplicated from array.ml *)letof_seqi=letl=Seq.fold_left(funaccx->x::acc)[]iinof_rev_listlletmap_to_arrayfa=letl=lengthainifl=0then[||]elsebeginletr=Array.makel(f(unsafe_geta0))infori=1tol-1doArray.unsafe_setri(f(unsafe_getai))done;rendletmap_from_arrayfa=letl=Array.lengthainletr=createlinfori=0tol-1dounsafe_setri(f(Array.unsafe_getai))done;rendmoduleArrayLabels=Array