Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file owl_sparse_dok_matrix.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475# 1 "src/owl/sparse/owl_sparse_dok_matrix.ml"(*
* OWL - OCaml Scientific and Engineering Computing
* Copyright (c) 2016-2020 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;n;k;d=(letc=int_of_float(float_of_int(m*n)*.density)inHashtbl.createc)}letrow_numx=x.mletcol_numx=x.nletshapex=x.m,x.nletnumelx=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)aletgetxij=_check_boundaryijx.mx.n;matchHashtbl.memx.d(i,j)with|true->Hashtbl.findx.d(i,j)|false->Owl_const.zerox.kletresetx=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