123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533(*_ Create an alias to the built-in [array], whose parameter has layout [any]. We need
this alias to define the [Array] submodule below. [Base.Array.t] and [Stdlib.Array.t]
are unsuitable as they re-export [array] with a parameter of layout [value].
*)type('a:anymodseparable)builtin_array='aarrayopenBaseopenOcaml_intrinsics_kernel.ConditionalmoduleF=Float32moduleBoxed=Float32externalto_float32:float32#->(float32[@local_opt])@@portable="%box_float32"externalof_float32:(float32[@local_opt])->float32#@@portable="%unbox_float32"moduleStable=structmoduleV1=structopenstructmoduleF=F.Stable.V1endtypet=float32#letglobalize(local_t):t=tlet%template[@alloca=(heap,stack)][@inline]sexp_of_tt:Base.Sexp.t=(F.sexp_of_t[@alloca][@inlinedhint])(to_float32t)[@exclave_if_stacka];;let[@inline]t_of_sexpsexp:t=of_float32((F.t_of_sexp[@inlinedhint])sexp)letbin_shape_t=Bin_prot_unboxed_numbers.Float32_u.bin_shape_t[%%template[@@@mode.defaultm=(global,local)]let[@inlinealways]bin_size_tt=(Bin_prot_unboxed_numbers.Float32_u.bin_size_t[@modem][@inlined])t;;let[@inlinealways]bin_write_tbuf~post=(Bin_prot_unboxed_numbers.Float32_u.bin_write_t[@modem][@inlined])buf~post;;]let[@inlinealways]bin_read_tbuf~pos_ref=(Bin_prot_unboxed_numbers.Float32_u.bin_read_t[@inlined])buf~pos_ref;;let__bin_read_t__=Bin_prot_unboxed_numbers.Float32_u.__bin_read_t__letbin_writer_t=Bin_prot_unboxed_numbers.Float32_u.bin_writer_tletbin_reader_t=Bin_prot_unboxed_numbers.Float32_u.bin_reader_tletbin_t=Bin_prot_unboxed_numbers.Float32_u.bin_tlet[@inline]to_stringt:string=(F.to_string[@inlinedhint])(to_float32t)let[@inline]of_strings:t=of_float32((F.of_string[@inlinedhint])s)[%%template[@@@mode.defaultm=(global,local)]let[@inline][@zero_alloc]equalt1t2:bool=(F.equal[@modem])(to_float32t1)(to_float32t2);;let[@inline][@zero_alloc]comparet1t2:int=(F.compare[@modem])(to_float32t1)(to_float32t2);;]letstable_witness=Ppx_stable_witness_runtime.Stable_witness.assert_stableendendincludeStable.V1let[@inline]ascendingt1t2:int=(F.ascending[@inlinedhint])(to_float32t1)(to_float32t2);;let[@inline]descendingt1t2:int=(F.descending[@inlinedhint])(to_float32t1)(to_float32t2);;let[@inline]betweent~low~high:bool=(F.between[@inlinedhint])(to_float32t)~low:(to_float32low)~high:(to_float32high);;let[@inline]clamp_exnt~min~max:t=of_float32((F.clamp_exn[@inlinedhint])(to_float32t)~min:(to_float32min)~max:(to_float32max));;let[@inline]ppppft:unit=(F.pp[@inlinedhint])ppf(to_float32t)let[@inline]invariantt:unit=(F.invariant[@inlinedhint])(to_float32t)letnan:t=of_float32F.nanletinfinity:t=of_float32F.infinityletneg_infinity:t=of_float32F.neg_infinityletmax_value:t=of_float32F.max_valueletmin_value:t=of_float32F.min_valueletzero:t=of_float32F.zeroletone:t=of_float32F.oneletminus_one:t=of_float32F.minus_oneletpi:t=of_float32F.piletsqrt_pi:t=of_float32F.sqrt_piletsqrt_2pi:t=of_float32F.sqrt_2pileteuler_gamma_constant:t=of_float32F.euler_gamma_constantletepsilon_float:t=of_float32F.epsilon_floatletmax_finite_value:t=of_float32F.max_finite_valueletmin_positive_subnormal_value:t=of_float32F.min_positive_subnormal_valueletmin_positive_normal_value:t=of_float32F.min_positive_normal_valuelet[@inline]to_int32_preserve_ordert:int32option=(F.to_int32_preserve_order[@inlinedhint])(to_float32t);;let[@inline]to_int32_preserve_order_exnt:int32=(F.to_int32_preserve_order_exn[@inlinedhint])(to_float32t);;let[@inline]of_int32_preserve_orderi:t=of_float32((F.of_int32_preserve_order[@inlinedhint])i);;externalbox_int64:int64#->(int64[@local_opt])@@portable="%box_int64"externalunbox_int64:(int64[@local_opt])->int64#@@portable="%unbox_int64"let[@inline]one_ulpudt:t=of_float32((F.one_ulp[@inlinedhint])ud(to_float32t))let[@inline]of_inti:t=of_float32(F.of_inti)let[@inline]to_intt:int=(F.to_int[@inlinedhint])(to_float32t)let[@inline]of_int64i:t=of_float32((F.of_int64[@inlinedhint])i)let[@inline]to_int64t:int64=(F.to_int64[@inlinedhint])(to_float32t)let[@inline]of_int64_ux:t=of_float32((F.of_int64[@inlinedhint])(box_int64x))let[@inline]to_int64_ux:int64#=unbox_int64((F.to_int64[@inlinedhint])(to_float32x));;let[@inline]of_floati:t=of_float32(F.of_floati)let[@inline]to_floatt:float=F.to_float(to_float32t)externalunbox_f64:(float[@local_opt])->float#@@portable="%unbox_float"externalbox_f64:float#->(float[@local_opt])@@portable="%box_float"let[@inline][@zero_allocopt]to_float_ut:float#=unbox_f64((to_float[@inlinedhint])t);;let[@inline]of_float_uf:t=(of_float[@inlinedhint])(box_f64f)let[@inline]round?dirt:t=of_float32((F.round[@inlinedhint])?dir(to_float32t))let[@inline]iround?dirt:intoption=(F.iround[@inlinedhint])?dir(to_float32t)let[@inline]iround_exn?dirt:int=(F.iround_exn[@inlinedhint])?dir(to_float32t)let[@inline]round_towards_zerot:t=of_float32((F.round_towards_zero[@inlinedhint])(to_float32t));;let[@inline]round_downt:t=of_float32((F.round_down[@inlinedhint])(to_float32t))let[@inline]round_upt:t=of_float32((F.round_up[@inlinedhint])(to_float32t))(** Rounds half integers up. *)let[@inline]round_nearestt:t=of_float32((F.round_nearest[@inlinedhint])(to_float32t));;(** Rounds half integers to the even integer. *)let[@inline]round_nearest_half_to_event:t=of_float32((F.round_nearest_half_to_even[@inlinedhint])(to_float32t));;let[@inline]iround_towards_zerot:intoption=(F.iround_towards_zero[@inlinedhint])(to_float32t);;let[@inline]iround_downt:intoption=(F.iround_down[@inlinedhint])(to_float32t)let[@inline]iround_upt:intoption=(F.iround_up[@inlinedhint])(to_float32t)let[@inline]iround_nearestt:intoption=(F.iround_nearest[@inlinedhint])(to_float32t);;let[@inline]iround_towards_zero_exnt:int=(F.iround_towards_zero_exn[@inlinedhint])(to_float32t);;let[@inline]iround_down_exnt:int=(F.iround_down_exn[@inlinedhint])(to_float32t)let[@inline]iround_up_exnt:int=(F.iround_up_exn[@inlinedhint])(to_float32t)let[@inline]iround_nearest_exnt:int=(F.iround_nearest_exn[@inlinedhint])(to_float32t);;let[@inline]iround_nearest_half_to_event:int64=(F.iround_nearest_half_to_even[@inlinedhint])(to_float32t);;letiround_lbound=of_float32F.iround_lboundletiround_ubound=of_float32F.iround_uboundlet[@inline]is_nant:bool=(F.is_nan[@inlinedhint])(to_float32t)let[@inline]is_inft:bool=(F.is_inf[@inlinedhint])(to_float32t)let[@inline]is_finitet:bool=(F.is_finite[@inlinedhint])(to_float32t)let[@inline]is_integert:bool=(F.is_integer[@inlinedhint])(to_float32t)let[@inline]min_inant1t2:t=of_float32((F.min_inan[@inlinedhint])(to_float32t1)(to_float32t2));;let[@inline]max_inant1t2:t=of_float32((F.max_inan[@inlinedhint])(to_float32t1)(to_float32t2));;let[@inline]mod_floatt1t2:t=of_float32((F.mod_float[@inlinedhint])(to_float32t1)(to_float32t2));;let[@inline]addt1t2:t=of_float32(F.add(to_float32t1)(to_float32t2))let[@inline]subt1t2:t=of_float32(F.sub(to_float32t1)(to_float32t2))let[@inline]mult1t2:t=of_float32(F.mul(to_float32t1)(to_float32t2))let[@inline]divt1t2:t=of_float32(F.div(to_float32t1)(to_float32t2))moduleO=structexternalbox:float32#->(float32[@local_opt])@@portable="%box_float32"externalunbox:(float32[@local_opt])->float32#@@portable="%unbox_float32"let[@inline](+)t1t2:t=of_float32(F.O.(+)(to_float32t1)(to_float32t2))let[@inline](-)t1t2:t=of_float32(F.O.(-)(to_float32t1)(to_float32t2))let[@inline](*)t1t2:t=of_float32(F.O.(*)(to_float32t1)(to_float32t2))let[@inline](/)t1t2:t=of_float32(F.O.(/)(to_float32t1)(to_float32t2))let[@inline](%)t1t2:t=of_float32(F.O.(%)(to_float32t1)(to_float32t2))let[@inline](**)t1t2:t=of_float32(F.O.(**)(to_float32t1)(to_float32t2))let[@inline](~-)t:t=of_float32(F.O.(~-)(to_float32t))let[@inline](>=)t1t2:bool=F.O.(>=)(to_float32t1)(to_float32t2)let[@inline](<=)t1t2:bool=F.O.(<=)(to_float32t1)(to_float32t2)let[@inline](=)t1t2:bool=F.O.(=)(to_float32t1)(to_float32t2)let[@inline](>)t1t2:bool=F.O.(>)(to_float32t1)(to_float32t2)let[@inline](<)t1t2:bool=F.O.(<)(to_float32t1)(to_float32t2)let[@inline](<>)t1t2:bool=F.O.(<>)(to_float32t1)(to_float32t2)let[@inline]abst:t=of_float32(F.O.abs(to_float32t))let[@inline]negt:t=of_float32(F.O.neg(to_float32t))endincludeOmoduleO_dot=structlet[@inline](+.)t1t2:t=of_float32(F.O_dot.(+.)(to_float32t1)(to_float32t2));;let[@inline](-.)t1t2:t=of_float32(F.O_dot.(-.)(to_float32t1)(to_float32t2));;let[@inline](*.)t1t2:t=of_float32(F.O_dot.(*.)(to_float32t1)(to_float32t2));;let[@inline](/.)t1t2:t=of_float32(F.O_dot.(/.)(to_float32t1)(to_float32t2));;let[@inline](%.)t1t2:t=of_float32(F.O_dot.(%.)(to_float32t1)(to_float32t2));;let[@inline](**.)t1t2:t=of_float32(F.O_dot.(**.)(to_float32t1)(to_float32t2));;let[@inline](~-.)t:t=of_float32(F.O_dot.(~-.)(to_float32t))endlet[@inline]to_string_hum?delimiter?decimals?strip_zero?explicit_plust:string=(F.to_string_hum[@inlinedhint])?delimiter?decimals?strip_zero?explicit_plus(to_float32t);;let[@inline]to_padded_compact_stringt:string=(F.to_padded_compact_string[@inlinedhint])(to_float32t);;let[@inline]to_padded_compact_string_customt?prefix~kilo~mega~giga~tera?peta():string=(F.to_padded_compact_string_custom[@inlinedhint])(to_float32t)?prefix~kilo~mega~giga~tera?peta();;let[@inline]int_powti:t=of_float32((F.int_pow[@inlinedhint])(to_float32t)i)let[@inline]squaret:t=of_float32((F.square[@inlinedhint])(to_float32t))let[@inline]ldexpti:t=of_float32(F.ldexp(to_float32t)i)let[@inline]log10t:t=of_float32(F.log10(to_float32t))let[@inline]log2t:t=of_float32(F.log2(to_float32t))let[@inline]expm1t:t=of_float32(F.expm1(to_float32t))let[@inline]log1pt:t=of_float32(F.log1p(to_float32t))let[@inline]copysignt1t2:t=of_float32(F.copysign(to_float32t1)(to_float32t2))let[@inline]cost=of_float32(F.cos(to_float32t))let[@inline]sint:t=of_float32(F.sin(to_float32t))let[@inline]tant:t=of_float32(F.tan(to_float32t))let[@inline]acost:t=of_float32(F.acos(to_float32t))let[@inline]asint:t=of_float32(F.asin(to_float32t))let[@inline]atant:t=of_float32(F.atan(to_float32t))let[@inline]atan2t1t2:t=of_float32(F.atan2(to_float32t1)(to_float32t2))let[@inline]hypott1t2:t=of_float32(F.hypot(to_float32t1)(to_float32t2))let[@inline]cosht:t=of_float32(F.cosh(to_float32t))let[@inline]sinht:t=of_float32(F.sinh(to_float32t))let[@inline]tanht:t=of_float32(F.tanh(to_float32t))let[@inline]acosht:t=of_float32(F.acosh(to_float32t))let[@inline]asinht:t=of_float32(F.asinh(to_float32t))let[@inline]atanht:t=of_float32(F.atanh(to_float32t))let[@inline]sqrtt:t=of_float32(F.sqrt(to_float32t))let[@inline]cbrtt:t=of_float32(F.cbrt(to_float32t))let[@inline]expt:t=of_float32(F.exp(to_float32t))let[@inline]logt:t=of_float32(F.log(to_float32t))moduleClass=Base.Float.Classlet[@inline]classifyt:Class.t=(F.classify[@inlinedhint])(to_float32t)let[@inline]signt:Base.Sign.t=(F.sign[@inlinedhint])(to_float32t)[@alert"-deprecated"];;let[@inline]sign_exnt:Base.Sign.t=(F.sign_exn[@inlinedhint])(to_float32t)let[@inline]sign_or_nant:Base.Sign_or_nan.t=(F.sign_or_nan[@inlinedhint])(to_float32t);;let[@inline]create_ieee_exn~negative~exponent~mantissa:t=of_float32((F.create_ieee_exn[@inlinedhint])~negative~exponent~mantissa);;let[@inline]ieee_negativet:bool=(F.ieee_negative[@inlinedhint])(to_float32t)let[@inline]ieee_exponentt:int=(F.ieee_exponent[@inlinedhint])(to_float32t)let[@inline]ieee_mantissat:int=(F.ieee_mantissa[@inlinedhint])(to_float32t)externalbox_int32:int32#->(int32[@local_opt])@@portable="%box_int32"externalunbox_int32:(int32[@local_opt])->int32#@@portable="%unbox_int32"let[@inline]to_bitsx=F.to_bits(to_float32x)|>unbox_int32let[@inline]of_bitsx=F.of_bits(box_int32x)|>of_float32let[@inline]selectb(ifso:t)(ifnot:t):t=Unboxed.select_int32b(to_bitsifso)(to_bitsifnot)|>of_bits;;let[@inline]first_non_nan(x:t)(y:t):t=select(is_nanx)yx(* Both of these implementations are the same up to direction.
[if (x < y) then x else y] is the correct min, except that if either is nan we get y
(because comparisons with nan are false). If y is nan, that's correct. If x is nan, we
need to pick it, so explicitly test that.
Implement that branchlessly with [select]. The only weird thing here is that we want to
do two selects, but not pass back and forth to [int32] twice, so we write out the
selects in int32-space.
*)let[@inline]min(x:t)(y:t):t=letxb=to_bitsxinletyb=to_bitsyinletminb=Unboxed.select_int32(x<y)xbybinUnboxed.select_int32(is_nanx)xbminb|>of_bits;;let[@inline]max(x:t)(y:t):t=letxb=to_bitsxinletyb=to_bitsyinletmaxb=Unboxed.select_int32(x>y)xbybinUnboxed.select_int32(is_nanx)xbmaxb|>of_bits;;includestructopenBase_quickchecklet%templatequickcheck_generator=(Generator.Via_thunk.map[@modeportable])Generator.float~f:(funf()->of_float(f()));;let%templatequickcheck_observer=(Observer.Via_thunk.unmap[@modeportable])Observer.float~f:(funf()->to_float(f()));;letquickcheck_shrinker=Shrinker.atomicendmoduleRef=structtypenonrect={mutablecontents:t}let[@inline]gett=t.contentslet[@inline]settx=t.contents<-xlet[@inline]addtx=sett(gett+x)let[@inline]createcontents={contents}let[@inline]create_zero()=create#0.0smoduleO=structlet[@inline](!)t=gettlet[@inline](:=)tx=settxendendmoduleArray=structtype('a:float32)t='abuiltin_arrayexternallength:local_'at->int@@portable="%array_length"externalget:local_'at->int->'a@@portable="%array_safe_get"externalset:local_'at->int->'a->unit@@portable="%array_safe_set"externalunsafe_get:local_'at->int->'a@@portable="%array_unsafe_get"externalunsafe_set:local_'at->int->'a->unit@@portable="%array_unsafe_set"(* Unsafe because this function may be used to create values of type ['a], which may
have user-defined invariants beyond the float32 layout. *)externalunsafe_create_uninitialized:len:int->'at@@portable="caml_make_unboxed_float32_vect_bytecode""caml_make_unboxed_float32_vect"externalcreate_uninitialized:len:int->float32#t@@portable="caml_make_unboxed_float32_vect_bytecode""caml_make_unboxed_float32_vect"externalcreate_local_uninitialized:len:int->float32#t@local@@portable="caml_make_unboxed_float32_vect_bytecode""caml_make_local_unboxed_float32_vect"externalunsafe_blit:src:local_'at->src_pos:int->dst:local_'at->dst_pos:int->len:int->unit@@portable="caml_array_blit""caml_unboxed_float32_vect_blit"externalglobalize':local_'at->'at@@portable="%obj_dup"letglobalize_t=globalize't[%%template(* Copied from lib/base/src/ppx_compare_lib.ml *)let[@modelocal][@zero_alloc]comparecomparr1arr2=ifphys_equalarr1arr2then0else(letlen_a=lengtharr1inletlen_b=lengtharr2inletret=Int.comparelen_alen_binifInt.(ret<>0)thenretelse(let[@zero_alloc]recloopi=ifInt.(i=len_a)then0else(letl=unsafe_getarr1iandr=unsafe_getarr2iinletres=(comp[@zero_allocassume])lrinifInt.(res<>0)thenreselseloopInt.(i+1))inloop0[@nontail]));;let[@zero_alloc]compare=[%eta3compare[@modelocal]]](* The impl was copied from [lib/base/src/array.ml]. *)let[@zero_alloc]for_all2_local_exnt1t2~f=leti=refInt.O.(lengtht1-1)inletresult=reftrueinwhileInt.O.(!i>=0)&&!resultdoifnot((f[@zero_allocassume])(unsafe_gett1!i)(unsafe_gett2!i))thenresult:=falseelseInt.decridone;!result;;[%%templatelet[@modelocal][@zero_alloc]equalelement_equalt1t2=Int.O.(lengtht1=lengtht2)&&for_all2_local_exnt1t2~f:element_equal;;let[@zero_alloc]equal=[%eta3equal[@modelocal]]](* Copied with minor changes from [sexp_of_array] in [lib/sexplib0/src/sexp_conv.ml] *)letsexp_of_tsexp_of__aar=letlst_ref=ref[]infori=Int.O.(lengthar-1)downto0dolst_ref:=sexp_of__a(getari)::!lst_refdone;Sexp.List!lst_ref;;(* Custom implementation using unsafe uninitialized creation *)lett_of_sexpa__of_sexpsexp=match(sexp:Sexp.t)with|List[]->[||]|Listt->letlen=List.lengthtinletres=unsafe_create_uninitialized~leninList.iterit~f:(funiel->unsafe_setresi(a__of_sexpel));res|Atom_->raise_s[%sexp"array_of_sexp: list needed: {sexp#Sexp}"];;letinitlen~f=letr=unsafe_create_uninitialized~leninfori=0toBase.Int.O.(len-1)dounsafe_setri(fi)done;r;;letcopyt=init(lengtht)~f:(funi->unsafe_getti)[@nontail]endmoduleBigarray=Stdlib_stable.Float32_u.Bigarray