Skip to content

Commit cb3010b

Browse files
address comments
1 parent dee4439 commit cb3010b

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

src/cdomains/affineEquality/sparseImplementation/listMatrix.ml

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,10 @@ module ListMatrix: SparseMatrixFunctor =
402402
in
403403

404404
let col_and_rc m colidx rowidx =
405-
let col = get_col_upper_triangular m colidx in col ,
406-
try V.nth col rowidx with (* V.nth could be integrated into get_col for the last few bits of performance... *)
407-
| Invalid_argument _ -> A.zero (* if col is empty, we return zero *)
405+
let col = get_col_upper_triangular m colidx in
406+
let rc = try V.nth col rowidx with (* V.nth could be integrated into get_col for the last few bits of performance... *)
407+
| Invalid_argument _ -> A.zero (* if col is empty, we return zero *) in
408+
col, rc
408409
in
409410

410411
let push_col m colidx col =
@@ -433,20 +434,15 @@ module ListMatrix: SparseMatrixFunctor =
433434
let rec sub_and_last_aux (acclist,acc) c1 c2 =
434435
match c1, c2 with
435436
| (i,_)::_,_ when i >= ridx -> (acclist,acc) (* we are done, no more entries in c1 that are relevant *)
436-
| (i1, v1) :: xs1, (i2, v2) :: xs2 ->
437-
if i1 = i2 then
438-
let res = A.sub v1 v2 in
439-
if A.equal res A.zero then
440-
sub_and_last_aux ((i1,res)::acclist,acc) xs1 xs2
441-
else
442-
sub_and_last_aux ((i1,res)::acclist,Some (i1,v1,v2)) xs1 xs2
443-
else if i1 < i2 then
444-
sub_and_last_aux ((i1,v1)::acclist,Some (i1,v1,A.zero)) xs1 ((i2, v2)::xs2)
445-
else (* i1 > i2 *)
446-
sub_and_last_aux ((i2,A.neg v2)::acclist,Some (i2,A.zero,v2)) ((i1, v1)::xs1) xs2
437+
| (i1, v1) :: xs1, (i2, v2) :: xs2 when i1 = i2 ->
438+
let res = A.sub v1 v2 in
439+
let acc = if A.equal res A.zero then acc else Some (i1, v1, v2) in
440+
sub_and_last_aux ((i1,res)::acclist,acc) xs1 xs2
441+
| (i1, v1) :: xs1, (i2, v2) :: xs2 when i1 < i2 -> sub_and_last_aux ((i1,v1)::acclist,Some (i1,v1,A.zero)) xs1 ((i2, v2)::xs2)
442+
| (i1, v1) :: xs1, (i2, v2) :: xs2 (* when i1 > i2 *)-> sub_and_last_aux ((i2,A.neg v2)::acclist,Some (i2,A.zero,v2)) ((i1, v1)::xs1) xs2
447443
| (i,v)::xs ,[] -> sub_and_last_aux ((i,v)::acclist,Some (i,v,A.zero)) xs []
448444
| [], (i,v)::xs -> sub_and_last_aux ((i,v)::acclist,Some (i,A.zero,v)) [] xs
449-
| _ -> (acclist,acc)
445+
| [], [] -> (acclist,acc)
450446
in
451447
let resl,rest = sub_and_last_aux ([],None) c1 c2 in
452448
if M.tracing then M.trace "linear_disjunct_cases" "sub_and_last: ridx: %d c1: %s, c2: %s, resultlist: %s, result_pivot: %s" ridx (V.show col1) (V.show col2) (String.concat "," (List.map (fun (i,v) -> Printf.sprintf "(%d,%s)" i (A.to_string v)) resl)) (match rest with None -> "None" | Some (i,v1,v2) -> Printf.sprintf "(%d,%s,%s)" i (A.to_string v1) (A.to_string v2));
@@ -456,8 +452,7 @@ module ListMatrix: SparseMatrixFunctor =
456452
match lastdiff with
457453
| None ->
458454
let sameinboth=get_col_upper_triangular m1 cidx in
459-
if M.tracing then M.trace "linear_disjunct_cases" "case_three: no difference found, cidx: %d, ridx: %d, coldiff: %s, sameinboth: %s"
460-
cidx ridx (V.show coldiff) (V.show sameinboth);
455+
if M.tracing then M.trace "linear_disjunct_cases" "case_three: no difference found, cidx: %d, ridx: %d, coldiff: %s, sameinboth: %s" cidx ridx (V.show coldiff) (V.show sameinboth);
461456
(del_col m1 cidx, del_col m2 cidx, push_col result cidx sameinboth, ridx) (* No difference found -> (del_col m1 cidx, del_col m2 cidx, push hd to result, ridx)*)
462457
| Some (idx,x,y) ->
463458
let r1 = safe_get_row m1 idx in
@@ -508,11 +503,9 @@ module ListMatrix: SparseMatrixFunctor =
508503
| a,b -> failwith ("matrix not in rref m1: " ^ (string_of_int a) ^ (string_of_int b)^(show m1) ^ " m2: " ^ (show m2))
509504
in
510505
(* create a totally empty intial result, with dimensions rows x cols *)
511-
let pseudoempty = List.init (max (num_rows m1) (num_rows m1)) (fun _ -> V.zero_vec (num_cols m1)) in
506+
let pseudoempty = BatList.make (max (num_rows m1) (num_rows m1)) (V.zero_vec (num_cols m1)) in
512507
let res = rev_matrix @@ lindisjunc_aux 0 0 m1 m2 pseudoempty in
513-
if M.tracing then (
514-
let pleinly = String.concat "\n" (List.map (fun line -> String.concat "," (List.map (fun (idx,valu) -> "("^string_of_int idx^","^A.to_string valu^")") (V.to_sparse_list line)) ) res) in
515-
M.tracel "linear_disjunct" "linear_disjunct between \n%s and \n%s =>\n%s \n(%s)" (show m1) (show m2) (show res) pleinly);
508+
if M.tracing then M.tracel "linear_disjunct" "linear_disjunct between \n%s and \n%s =>\n%s" (show m1) (show m2) (show res);
516509
res
517510

518511
end

0 commit comments

Comments
 (0)