Skip to content

Commit

Permalink
temporary changes to collect statistics on affine-equalities
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMichaelPetter committed May 10, 2024
1 parent 9c785b1 commit 4c6f214
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/analyses/apron/affineEqualityAnalysis.apron.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ let spec_module: (module MCPSpec) Lazy.t =
struct
include SpecFunctor (Priv) (AD) (RelationPrecCompareUtil.DummyUtil)
let name () = "affeq"
let finalize () =
let (size,n) = !AffineEqualityDomain.sparseity_stats in
let average = Q.div (Q.of_bigint (Z.mul (Z.of_int 100) (n))) (Q.of_bigint (size)) in
M.info_noloc ~category:Analyzer "Sparseity %f%% in total: %Ld" (Q.to_float average) (Z.to_int64 size)
end
in
(module Spec)
Expand Down
19 changes: 19 additions & 0 deletions src/cdomains/apron/affineEqualityDomain.apron.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module M = Messages
open GobApron
open VectorMatrix

let sparseity_stats = ref (Z.zero,Z.zero)

module Mpqf = SharedFunctions.Mpqf

module AffineEqualityMatrix (Vec: AbstractVector) (Mx: AbstractMatrix) =
Expand Down Expand Up @@ -344,9 +346,26 @@ struct

let join a b = timing_wrap "join" (join a) b

let density m =
let rownum= Matrix.num_rows m in
let size = Matrix.num_cols m * rownum in
let rows=List.of_enum (0--(rownum-1)) in
let countzero mat rowidx = List.fold (fun sum e -> if Mpqf.zero=e then sum+1 else sum) 0 (Vector.to_list @@ Matrix.get_row mat rowidx) in
let sumofentries=List.fold (fun sum rowindex -> (countzero m rowindex) + sum) 0 rows in
let percent = if size=0 then 0 else (sumofentries*100)/(size) in
(size,sumofentries,percent)

let join a b =
let res = join a b in
if M.tracing then M.tracel "join" "join a: %s b: %s -> %s " (show a) (show b) (show res) ;
(if !AnalysisState.postsolving && (Option.get !AnalysisState.verified) then
let (size,sum,percent) = density @@ Option.get res.d in
let (statcount,statportion) = !sparseity_stats in
sparseity_stats:= (Z.add statcount (Z.of_int size),Z.add statportion (Z.of_int sum));
let average = Q.div (Q.of_bigint (Z.mul (Z.of_int 100) (snd !sparseity_stats))) (Q.of_bigint (fst !sparseity_stats)) in
if M.tracing then M.trace "join-benchmark-in-detail" "join-benchmark: zeroes:%d total/weight: %d -> zero portion: %d%%" sum size percent;
if M.tracing then M.trace "join-benchmark" "join-benchmark: average zero portion of all encountered matrices: %f%%" (Q.to_float average)
);
res

let widen a b =
Expand Down

0 comments on commit 4c6f214

Please sign in to comment.