Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file owl_sparse_dok_matrix.ml
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182# 1 "src/owl/sparse/owl_sparse_dok_matrix.ml"(*
* OWL - OCaml Scientific and Engineering Computing
* Copyright (c) 2016-2019 Liang Wang <liang.wang@cl.cam.ac.uk>
*)type('a,'b)kind=('a,'b)Bigarray.kindtype('a,'b)t={mutablem:int;(* number of rows *)mutablen:int;(* number of columns *)mutablek:('a,'b)kind;(* type of sparse matrices *)mutabled:(int*int,'a)Hashtbl.t;(* hashtbl for storing data *)}letzeros?(density=0.30)kmn={m=m;n=n;k=k;d=letc=int_of_float(float_of_int(m*n)*.density)inHashtbl.createc;}letrow_numx=x.mletcol_numx=x.nletshapex=(x.m,x.n)letnumelx=x.m*x.nletprunexr=Hashtbl.filter_map_inplace(fun_v->ifv=rthenNoneelseSomev)x.dletnnzx=let_=prunex(Owl_const.zerox.k)inHashtbl.((statsx.d).num_bindings)letdensityx=(float_of_int(nnzx))/.(float_of_int(numelx))letkindx=x.klet_check_boundaryijmn=ifi<0||i>=m||j<0||j>=nthenfailwith"error: index beyond the boundary"letsetxija=_check_boundaryijx.mx.n;let_a0=Owl_const.zerox.kinmatchHashtbl.memx.d(i,j)with|true->(ifa<>_a0thenHashtbl.replacex.d(i,j)aelseHashtbl.removex.d(i,j))|false->(ifa<>_a0thenHashtbl.addx.d(i,j)a)letgetxij=_check_boundaryijx.mx.n;matchHashtbl.memx.d(i,j)with|true->Hashtbl.findx.d(i,j)|false->Owl_const.zero(x.k)letresetx=Hashtbl.resetx.dletcopyx={m=x.m;n=x.n;k=x.k;d=Hashtbl.copyx.d;}letiteri_nzfx=Hashtbl.iter(fun(i,j)v->fijv)x.dletsavexf=Owl_io.marshal_to_filexfletload_kf=Owl_io.marshal_from_filef