123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576(* File: vec_SD.ml
Copyright (C) 2001-
Markus Mottl
email: markus.mottl@gmail.com
WWW: http://www.ocaml.info
Christophe Troestler
email: Christophe.Troestler@umons.ac.be
WWW: http://math.umons.ac.be/anum/
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
*)openVec4_DopenUtilsopenFloat64letrandom?rnd_state?(from=-1.)?(range=2.)n=letvec=createninletstate=matchrnd_statewith|None->Random.get_state()|Somestate->stateinforrow=1tondovec.{row}<-Random.State.floatstaterange+.fromdone;ifrnd_state=NonethenRandom.set_statestate;vecletget_y_vec~loc~ofsy~incy~ny=get_veclocy_stryofsyincyncreateletget_z_vec~loc~ofsz~incz~nz=get_veclocz_strzofszinczncreate(* Unary vector operations *)letint_abs=absletunopdirectloc=letloc="Lacaml.D.Vec."^locinfun?n?ofsy?incy?y?ofsx?incxx->letofsx,incx=get_vec_geomlocx_strofsxincxinletofsy,incy=get_vec_geomlocy_strofsyincyinletn=get_dim_veclocx_strofsxincxxn_strninlety=get_y_vec~loc~ofsy~incy~nyindirect~n~ofsy~incy~y~ofsx~incx~x;yexternaldirect_abs:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dabs_stub_bc""lacaml_Dabs_stub"letabs=unopdirect_abs"abs"externaldirect_signum:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dsignum_stub_bc""lacaml_Dsignum_stub"letsignum=unopdirect_signum"signum"externaldirect_sqr:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dsqr_stub_bc""lacaml_Dsqr_stub"letsqr=unopdirect_sqr"sqr"externaldirect_sqrt:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dsqrt_stub_bc""lacaml_Dsqrt_stub"letsqrt=unopdirect_sqrt"sqrt"externaldirect_cbrt:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dcbrt_stub_bc""lacaml_Dcbrt_stub"letcbrt=unopdirect_cbrt"cbrt"externaldirect_exp:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dexp_stub_bc""lacaml_Dexp_stub"letexp=unopdirect_exp"exp"externaldirect_exp2:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dexp2_stub_bc""lacaml_Dexp2_stub"letexp2=unopdirect_exp2"exp2"externaldirect_expm1:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dexpm1_stub_bc""lacaml_Dexpm1_stub"letexpm1=unopdirect_expm1"expm1"externaldirect_log:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dlog_stub_bc""lacaml_Dlog_stub"letlog=unopdirect_log"log"externaldirect_log10:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dlog10_stub_bc""lacaml_Dlog10_stub"letlog10=unopdirect_log10"log10"externaldirect_log2:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dlog2_stub_bc""lacaml_Dlog2_stub"letlog2=unopdirect_log2"log2"externaldirect_log1p:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dlog1p_stub_bc""lacaml_Dlog1p_stub"letlog1p=unopdirect_log1p"log1p"externaldirect_sin:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dsin_stub_bc""lacaml_Dsin_stub"letsin=unopdirect_sin"sin"externaldirect_cos:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dcos_stub_bc""lacaml_Dcos_stub"letcos=unopdirect_cos"cos"externaldirect_tan:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dtan_stub_bc""lacaml_Dtan_stub"lettan=unopdirect_tan"tan"externaldirect_asin:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dasin_stub_bc""lacaml_Dasin_stub"letasin=unopdirect_asin"asin"externaldirect_acos:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dacos_stub_bc""lacaml_Dacos_stub"letacos=unopdirect_acos"acos"externaldirect_atan:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Datan_stub_bc""lacaml_Datan_stub"letatan=unopdirect_atan"atan"externaldirect_sinh:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dsinh_stub_bc""lacaml_Dsinh_stub"letsinh=unopdirect_sinh"sinh"externaldirect_cosh:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dcosh_stub_bc""lacaml_Dcosh_stub"letcosh=unopdirect_cosh"cosh"externaldirect_tanh:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dtanh_stub_bc""lacaml_Dtanh_stub"lettanh=unopdirect_tanh"tanh"externaldirect_asinh:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dasinh_stub_bc""lacaml_Dasinh_stub"letasinh=unopdirect_asinh"asinh"externaldirect_acosh:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dacosh_stub_bc""lacaml_Dacosh_stub"letacosh=unopdirect_acosh"acosh"externaldirect_atanh:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Datanh_stub_bc""lacaml_Datanh_stub"letatanh=unopdirect_atanh"atanh"externaldirect_floor:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dfloor_stub_bc""lacaml_Dfloor_stub"letfloor=unopdirect_floor"floor"externaldirect_ceil:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dceil_stub_bc""lacaml_Dceil_stub"letceil=unopdirect_ceil"ceil"externaldirect_round:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dround_stub_bc""lacaml_Dround_stub"letround=unopdirect_round"round"externaldirect_trunc:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dtrunc_stub_bc""lacaml_Dtrunc_stub"lettrunc=unopdirect_trunc"trunc"externaldirect_erf:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Derf_stub_bc""lacaml_Derf_stub"leterf=unopdirect_erf"erf"externaldirect_erfc:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Derfc_stub_bc""lacaml_Derfc_stub"leterfc=unopdirect_erfc"erfc"externaldirect_logistic:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dlogistic_stub_bc""lacaml_Dlogistic_stub"letlogistic=unopdirect_logistic"logistic"externaldirect_relu:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Drelu_stub_bc""lacaml_Drelu_stub"letrelu=unopdirect_relu"relu"externaldirect_softplus:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dsoftplus_stub_bc""lacaml_Dsoftplus_stub"letsoftplus=unopdirect_softplus"softplus"externaldirect_softsign:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Dsoftsign_stub_bc""lacaml_Dsoftsign_stub"letsoftsign=unopdirect_softsign"softsign"(* Binary vector operations *)letbinopdirectloc=letloc="Lacaml.D.Vec."^locinfun?n?ofsz?incz?z?ofsx?incxx?ofsy?incyy->letofsz,incz=get_vec_geomlocz_strofszinczinletofsx,incx=get_vec_geomlocx_strofsxincxinletofsy,incy=get_vec_geomlocy_strofsyincyinletn=get_dim_veclocx_strofsxincxxn_strnincheck_veclocy_stry(ofsy+(n-1)*int_absincy);letz=get_z_vec~loc~ofsz~incz~nzindirect~n~ofsz~incz~z~ofsx~incx~x~ofsy~incy~y;zexternaldirect_pow:n:(int[@untagged])->ofsz:(int[@untagged])->incz:(int[@untagged])->z:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->unit="lacaml_Dpow_stub_bc""lacaml_Dpow_stub"letpow=binopdirect_pow"pow"externaldirect_atan2:n:(int[@untagged])->ofsz:(int[@untagged])->incz:(int[@untagged])->z:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->unit="lacaml_Datan2_stub_bc""lacaml_Datan2_stub"letatan2=binopdirect_atan2"atan2"externaldirect_hypot:n:(int[@untagged])->ofsz:(int[@untagged])->incz:(int[@untagged])->z:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->unit="lacaml_Dhypot_stub_bc""lacaml_Dhypot_stub"lethypot=binopdirect_hypot"hypot"externaldirect_min2:n:(int[@untagged])->ofsz:(int[@untagged])->incz:(int[@untagged])->z:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->unit="lacaml_Dmin2_stub_bc""lacaml_Dmin2_stub"letmin2=binopdirect_min2"min2"externaldirect_max2:n:(int[@untagged])->ofsz:(int[@untagged])->incz:(int[@untagged])->z:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->unit="lacaml_Dmax2_stub_bc""lacaml_Dmax2_stub"letmax2=binopdirect_max2"max2"(* Misc functions *)externaldirect_log_sum_exp:n:(int[@untagged])->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->(float[@unboxed])="lacaml_Dlog_sum_exp_vec_stub_bc""lacaml_Dlog_sum_exp_vec_stub"letlog_sum_exp=letloc="Lacaml.D.Vec.log_sum_exp"infun?n?ofsx?incxx->letofsx,incx=get_vec_geomlocx_strofsxincxinletn=get_dim_veclocx_strofsxincxxn_strnindirect_log_sum_exp~n~ofsx~incx~x