Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file vec4_C.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696(* File: vec_SDCZ.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.umh.ac.be/an/
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
*)openBigarrayopenComplex32openCommonopenUtils(* Creation of vectors and dimension accessor *)letcreate=vec_createletget_y_vec~loc~ofsy~incy~ny=get_veclocy_stryofsyincyncreateletget_z_vec~loc~ofsz~incz~nz=get_veclocz_strzofszinczncreateexternaldirect_fill:n:(int[@untagged])->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->a:num_type->unit="lacaml_Cfill_vec_stub_bc""lacaml_Cfill_vec_stub"letmakena=letx=createnindirect_fill~n~ofsx:1~incx:1~x~a;xletmake0n=makenzeroletinitnf=letv=createninfori=1tondov.{i}<-fidone;vletdim(vec:vec)=Array1.dimveclethas_zero_dim(vec:vec)=dimvec=0letof_arrayar=letn=Array.lengtharinletv=createninfori=1tondov.{i}<-ar.(i-1);done;vletto_array(v:vec)=letn=dimvinifn=0then[||]elseletar=Array.makenv.{1}infori=2tondoar.(i-1)<-v.{i}done;arletof_listl=letn=List.lengthlinletv=createninletcollixel=v.{ix}<-el;ix+1inignore(List.fold_leftcoll1l);vletto_list(v:vec)=letrecloopiacc=ifi=0thenaccelseloop(i-1)(v.{i}::acc)inloop(dimv)[]letappend(v1:vec)(v2:vec)=letn1=dimv1inletn2=dimv2inletn=n1+n2inletres=createninfori=1ton1dores.{i}<-v1.{i}done;fori=1ton2dores.{i+n1}<-v2.{i}done;resletreccoll_sizen=function|[]->n|v::vs->coll_size(dimv+n)vsexternaldirect_copy:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Ccopy_stub_bc""lacaml_Ccopy_stub"letconcatvs=lety=create(coll_size0vs)inletcollofsyx=letn=dimxindirect_copy~n~ofsy~incy:1~y~ofsx:1~incx:1~x;ofsy+ninignore(List.fold_leftcoll1vs);yletempty=create0externaldirect_linspace:y:vec->a:num_type->b:num_type->n:(int[@untagged])->unit="lacaml_Clinspace_stub_bc""lacaml_Clinspace_stub"letlinspace?yabn=lety=matchywith|Somey->check_vec"Vec.linspace"y_stryn;y|None->createnindirect_linspace~y~a~b~n;yexternaldirect_logspace:y:vec->a:num_type->b:num_type->base:(float[@unboxed])->n:(int[@untagged])->unit="lacaml_Clogspace_stub_bc""lacaml_Clogspace_stub"letlogspace?yab?(base=10.0)n=ifbase<=0.0theninvalid_arg"Vec.logspace: base <= 0.0";lety=matchywith|Somey->check_vec"Vec.logspace"y_stryn;y|None->createnindirect_logspace~y~a~b~base~n;y(* Iterators over vectors *)letvec_map_str="Vec.map"letmapf?n?ofsy?incy?y?ofsx?incx(x:vec)=letofsx,incx=get_vec_geomvec_map_strx_strofsxincxinletofsy,incy=get_vec_geomvec_map_stry_strofsyincyinletn=get_dim_vecvec_map_strx_strofsxincxxn_strninletmin_dim_y=ofsy+(n-1)*absincyinlety=matchywith|Somey->check_vecvec_map_stry_strymin_dim_y;y|None->createmin_dim_yinletstart,stop=get_vec_start_stop~incx~ofsx~ninleti_ref=refstartinletj_ref=ref(ifincy>0thenofsyelsemin_dim_y)inwhile!i_ref<>stopdoy.{!j_ref}<-fx.{!i_ref};i_ref:=!i_ref+incx;j_ref:=!j_ref+incy;done;yletvec_iter_str="Vec.iter"letiterf?n?ofsx?incx(x:vec)=letofsx,incx=get_vec_geomvec_iter_strx_strofsxincxinletn=get_dim_vecvec_iter_strx_strofsxincxxn_strninletstart,stop=get_vec_start_stop~incx~ofsx~ninleti_ref=refstartinwhile!i_ref<>stopdoleti=!i_refinfx.{i};i_ref:=i+incx;doneletvec_iteri_str="Vec.iteri"letiterif?n?ofsx?incx(x:vec)=letofsx,incx=get_vec_geomvec_iteri_strx_strofsxincxinletn=get_dim_vecvec_iteri_strx_strofsxincxxn_strninletstart,stop=get_vec_start_stop~incx~ofsx~ninleti_ref=refstartinwhile!i_ref<>stopdoleti=!i_refinfix.{i};i_ref:=i+incx;doneletvec_fold_str="Vec.fold"letfoldfacc?n?ofsx?incx(x:vec)=letofsx,incx=get_vec_geomvec_fold_strx_strofsxincxinletn=get_dim_vecvec_fold_strx_strofsxincxxn_strninletstart,stop=get_vec_start_stop~incx~ofsx~ninletrecloopacci=ifi=stopthenaccelseloop(faccx.{i})(i+incx)inloopaccstart(* Operations on one vector *)(* REV *)letrev(x:vec)=letn=dimxinletres=createninletn1=n+1infori=1tondores.{n1-i}<-x.{i}done;res(* FILL *)letvec_fill_str="Vec.fill"letfill?n?ofsx?incxxa=letofsx,incx=get_vec_geomvec_fill_strx_strofsxincxinletn=get_dim_vecvec_fill_strx_strofsxincxxn_strnindirect_fill~n~ofsx~incx~x~a(* MAX *)externaldirect_max:n:(int[@untagged])->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->num_type="lacaml_Cmax_stub_bc""lacaml_Cmax_stub"letvec_max_str="Vec.max"letmax?n?ofsx?incxx=letofsx,incx=get_vec_geomvec_max_strx_strofsxincxinletn=get_dim_vecvec_max_strx_strofsxincxxn_strnindirect_max~n~ofsx~incx~x(* MIN *)letvec_min_str="Vec.min"externaldirect_min:n:(int[@untagged])->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->num_type="lacaml_Cmin_stub_bc""lacaml_Cmin_stub"letmin?n?ofsx?incxx=letofsx,incx=get_vec_geomvec_min_strx_strofsxincxinletn=get_dim_vecvec_min_strx_strofsxincxxn_strnindirect_min~n~ofsx~incx~x(* SUM *)externaldirect_sum:n:(int[@untagged])->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->num_type="lacaml_Csum_vec_stub_bc""lacaml_Csum_vec_stub"letvec_sum_str="Vec.sum"letsum?n?ofsx?incxx=letofsx,incx=get_vec_geomvec_sum_strx_strofsxincxinletn=get_dim_vecvec_sum_strx_strofsxincxxn_strnindirect_sum~n~ofsx~incx~x(* PROD *)letvec_prod_str="Vec.prod"externaldirect_prod:n:(int[@untagged])->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->num_type="lacaml_Cprod_stub_bc""lacaml_Cprod_stub"letprod?n?ofsx?incxx=letofsx,incx=get_vec_geomvec_prod_strx_strofsxincxinletn=get_dim_vecvec_prod_strx_strofsxincxxn_strnindirect_prod~n~ofsx~incx~x(* ADD_CONST *)externaldirect_add_const:c:num_type->n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Cadd_const_vec_stub_bc""lacaml_Cadd_const_vec_stub"letvec_add_const_str="Vec.add_const"letadd_constc?n?ofsy?incy?y?ofsx?incxx=letofsx,incx=get_vec_geomvec_add_const_strx_strofsxincxinletofsy,incy=get_vec_geomvec_add_const_stry_strofsyincyinletn=get_dim_vecvec_add_const_strx_strofsxincxxn_strninlety=get_y_vec~loc:vec_add_const_str~ofsy~incy~nyindirect_add_const~c~n~ofsy~incy~y~ofsx~incx~x;y(* SQR_NRM2 *)externaldirect_sqr_nrm2:stable:bool->n:(int[@untagged])->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->(float[@unboxed])="lacaml_Csqr_nrm2_stub_bc""lacaml_Csqr_nrm2_stub"letsqr_nrm2?(stable=false)?n?ofsx?incxx=letloc="Vec.sqr_nrm2"inletofsx,incx=get_vec_geomlocx_strofsxincxinletn=get_dim_veclocx_strofsxincxxn_strnindirect_sqr_nrm2~stable~n~ofsx~incx~x(* SSQR *)externaldirect_ssqr:n:(int[@untagged])->c:num_type->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->num_type="lacaml_Cssqr_stub_bc""lacaml_Cssqr_stub"externaldirect_ssqr_zero:n:(int[@untagged])->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->num_type="lacaml_Cssqr_zero_stub_bc""lacaml_Cssqr_zero_stub"letvec_ssqr_str="Vec.ssqr"letssqr?n?c?ofsx?incxx=letofsx,incx=get_vec_geomvec_ssqr_strx_strofsxincxinletn=get_dim_vecvec_ssqr_strx_strofsxincxxn_strninmatchcwith|None->direct_ssqr_zero~n~ofsx~incx~x|Somec->ifc=zerothendirect_ssqr_zero~n~ofsx~incx~xelsedirect_ssqr~n~c~ofsx~incx~x(* SORT *)externaldirect_sort_incr:cmp:(num_type->num_type->int)->(* not used, ususal order *)n:(int[@untagged])->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Csort_incr_bc""lacaml_Csort_incr"externaldirect_sort_incr_perm:cmp:(num_type->num_type->int)->(* not used, ususal order *)n:(int[@untagged])->ofsp:(int[@untagged])->incp:(int[@untagged])->p:int_vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Csort_incr_perm_bc""lacaml_Csort_incr_perm"externaldirect_sort_decr:cmp:(num_type->num_type->int)->(* not used, usual decreasing order *)n:(int[@untagged])->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Csort_decr_bc""lacaml_Csort_decr"externaldirect_sort_decr_perm:cmp:(num_type->num_type->int)->(* not used, ususal order *)n:(int[@untagged])->ofsp:(int[@untagged])->incp:(int[@untagged])->p:int_vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Csort_decr_perm_bc""lacaml_Csort_decr_perm"externaldirect_sort:cmp:(num_type->num_type->int)->n:(int[@untagged])->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Csort_bc""lacaml_Csort"externaldirect_sort_perm:cmp:(num_type->num_type->int)->(* not used, ususal order *)n:(int[@untagged])->ofsp:(int[@untagged])->incp:(int[@untagged])->p:int_vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Csort_perm_bc""lacaml_Csort_perm"letvec_sort_str="Vec.sort"letp_str="p"letdummy_cmp__=0letsort?cmp?(decr=false)?n?ofsp?incp?p?ofsx?incxx=letofsx,incx=get_vec_geomvec_sort_strx_strofsxincxinletn=get_dim_vecvec_sort_strx_strofsxincxxn_strninmatchpwith|None->(matchcmpwith|None->ifdecrthendirect_sort_decr~cmp:dummy_cmp~n~ofsx~incx~xelsedirect_sort_incr~cmp:dummy_cmp~n~ofsx~incx~x|Somecmp->letcmp=ifdecrthen(funx1x2->cmpx2x1)elsecmpindirect_sort~cmp~n~ofsx~incx~x)|Somep->letofsp,incp=get_vec_geomvec_sort_strp_strofspincpincheck_vecvec_sort_strp_strpn;(matchcmpwith|None->ifdecrthendirect_sort_decr_perm~cmp:dummy_cmp~n~ofsp~incp~p~ofsx~incx~xelsedirect_sort_incr_perm~cmp:dummy_cmp~n~ofsp~incp~p~ofsx~incx~x|Somecmp->letcmp=ifdecrthen(funx1x2->cmpx2x1)elsecmpindirect_sort_perm~cmp~n~ofsp~incp~p~ofsx~incx~x)(* NEG *)externaldirect_neg:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Cneg_stub_bc""lacaml_Cneg_stub"letvec_neg_str="Vec.neg"letneg?n?ofsy?incy?y?ofsx?incxx=letofsx,incx=get_vec_geomvec_neg_strx_strofsxincxinletofsy,incy=get_vec_geomvec_neg_stry_strofsyincyinletn=get_dim_vecvec_neg_strx_strofsxincxxn_strninlety=get_y_vec~loc:vec_neg_str~ofsy~incy~nyindirect_neg~n~ofsy~incy~y~ofsx~incx~x;y(* RECI *)externaldirect_reci:n:(int[@untagged])->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->unit="lacaml_Creci_stub_bc""lacaml_Creci_stub"letvec_reci_loc="Vec.reci"letreci?n?ofsy?incy?y?ofsx?incxx=letofsx,incx=get_vec_geomvec_reci_locx_strofsxincxinletofsy,incy=get_vec_geomvec_reci_locy_strofsyincyinletn=get_dim_vecvec_reci_locx_strofsxincxxn_strninlety=get_y_vec~loc:vec_reci_loc~ofsy~incy~nyindirect_reci~n~ofsy~incy~y~ofsx~incx~x;y(* Operations on two vectors *)(* ADD *)externaldirect_add: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_Cadd_stub_bc""lacaml_Cadd_stub"letvec_add_str="Vec.add"letadd?n?ofsz?incz?z?ofsx?incxx?ofsy?incyy=letofsz,incz=get_vec_geomvec_add_strz_strofszinczandofsx,incx=get_vec_geomvec_add_strx_strofsxincxandofsy,incy=get_vec_geomvec_add_stry_strofsyincyinletn=get_dim_vecvec_add_strx_strofsxincxxn_strnincheck_vecvec_add_stry_stry(ofsy+(n-1)*absincy);letz=get_z_vec~loc:vec_add_str~ofsz~incz~nzindirect_add~n~ofsz~incz~z~ofsx~incx~x~ofsy~incy~y;z(* SUB *)externaldirect_sub: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_Csub_stub_bc""lacaml_Csub_stub"letvec_sub_str="Vec.sub"letsub?n?ofsz?incz?z?ofsx?incxx?ofsy?incyy=letofsz,incz=get_vec_geomvec_sub_strz_strofszinczandofsx,incx=get_vec_geomvec_sub_strx_strofsxincxandofsy,incy=get_vec_geomvec_sub_stry_strofsyincyinletn=get_dim_vecvec_sub_strx_strofsxincxxn_strnincheck_vecvec_sub_stry_stry(ofsy+(n-1)*absincy);letz=get_z_vec~loc:vec_sub_str~ofsz~incz~nzindirect_sub~n~ofsz~incz~z~ofsx~incx~x~ofsy~incy~y;z(* MUL *)externaldirect_mul: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_Cmul_stub_bc""lacaml_Cmul_stub"letvec_mul_str="Vec.mul"letmul?n?ofsz?incz?z?ofsx?incxx?ofsy?incyy=letofsz,incz=get_vec_geomvec_mul_strz_strofszinczandofsx,incx=get_vec_geomvec_mul_strx_strofsxincxandofsy,incy=get_vec_geomvec_mul_stry_strofsyincyinletn=get_dim_vecvec_mul_strx_strofsxincxxn_strnincheck_vecvec_mul_stry_stry(ofsy+(n-1)*absincy);letz=get_z_vec~loc:vec_mul_str~ofsz~incz~nzindirect_mul~n~ofsz~incz~z~ofsx~incx~x~ofsy~incy~y;z(* DIV *)externaldirect_div: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_Cdiv_stub_bc""lacaml_Cdiv_stub"letvec_div_str="Vec.div"letdiv?n?ofsz?incz?z?ofsx?incxx?ofsy?incyy=letofsz,incz=get_vec_geomvec_div_strz_strofszinczandofsx,incx=get_vec_geomvec_div_strx_strofsxincxandofsy,incy=get_vec_geomvec_div_stry_strofsyincyinletn=get_dim_vecvec_div_strx_strofsxincxxn_strnincheck_vecvec_div_stry_stry(ofsy+(n-1)*absincy);letz=get_z_vec~loc:vec_div_str~ofsz~incz~nzindirect_div~n~ofsz~incz~z~ofsx~incx~x~ofsy~incy~y;z(* ZPXY *)externaldirect_zpxy: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_Czpxy_stub_bc""lacaml_Czpxy_stub"letvec_zpxy_str="Vec.zpxy"letzpxy?n?ofsz?inczz?ofsx?incxx?ofsy?incyy=letofsz,incz=get_vec_geomvec_zpxy_strz_strofszinczandofsx,incx=get_vec_geomvec_zpxy_strx_strofsxincxandofsy,incy=get_vec_geomvec_zpxy_stry_strofsyincyinletn=get_dim_vecvec_zpxy_strx_strofsxincxxn_strnincheck_vecvec_zpxy_stry_stry(ofsy+(n-1)*absincy);check_vecvec_zpxy_strz_strz(ofsz+(n-1)*absincz);direct_zpxy~n~ofsz~incz~z~ofsx~incx~x~ofsy~incy~y(* ZMXY *)externaldirect_zmxy: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_Czmxy_stub_bc""lacaml_Czmxy_stub"letvec_zmxy_str="Vec.zmxy"letzmxy?n?ofsz?inczz?ofsx?incxx?ofsy?incyy=letofsz,incz=get_vec_geomvec_zmxy_strz_strofszinczandofsx,incx=get_vec_geomvec_zmxy_strx_strofsxincxandofsy,incy=get_vec_geomvec_zmxy_stry_strofsyincyinletn=get_dim_vecvec_zmxy_strx_strofsxincxxn_strnincheck_vecvec_zmxy_stry_stry(ofsy+(n-1)*absincy);check_vecvec_zpxy_strz_strz(ofsz+(n-1)*absincz);direct_zmxy~n~ofsz~incz~z~ofsx~incx~x~ofsy~incy~y(* SSQR_DIFF *)externaldirect_ssqr_diff:n:(int[@untagged])->ofsx:(int[@untagged])->incx:(int[@untagged])->x:vec->ofsy:(int[@untagged])->incy:(int[@untagged])->y:vec->num_type="lacaml_Cssqr_diff_stub_bc""lacaml_Cssqr_diff_stub"letvec_ssqr_diff_str="Vec.ssqr_diff"letssqr_diff?n?ofsx?incxx?ofsy?incyy=letofsx,incx=get_vec_geomvec_ssqr_diff_strx_strofsxincxandofsy,incy=get_vec_geomvec_ssqr_diff_stry_strofsyincyinletn=get_dim_vecvec_ssqr_diff_strx_strofsxincxxn_strnincheck_vecvec_ssqr_diff_stry_stry(ofsy+(n-1)*absincy);direct_ssqr_diff~n~ofsx~incx~x~ofsy~incy~y