Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making Affine-equalities Sparse #1460

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading