Skip to content

Commit d71d7bd

Browse files
bugfix in add_empty_columns, behavious still differs from arraymatrix
1 parent 8d1c548 commit d71d7bd

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

src/cdomains/affineEquality/arrayImplementation/arrayMatrix.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module ArrayMatrix: AbstractMatrix =
3939
let copy m = Timing.wrap "copy" (copy) m
4040

4141
let add_empty_columns m cols =
42-
let () = Printf.printf "Before add_empty_columns m:\n%s\n" (show m) in
42+
let () = Printf.printf "Before add_empty_columns m:\n%sindices: %s\n" (show m) (Array.fold_right (fun x s -> s ^ (Int.to_string x) ^ ",") cols "") in
4343
let nnc = Array.length cols in
4444
if is_empty m || nnc = 0 then m else
4545
let nr, nc = num_rows m, num_cols m in
@@ -82,7 +82,7 @@ module ArrayMatrix: AbstractMatrix =
8282
Array.blit m (n + 1) new_matrix n (num_rows new_matrix - n)); new_matrix
8383

8484
let get_col m n =
85-
let () = Printf.printf "get_col %i of m:\n%s\n%s\n" n (show m) (V.show (V.of_array @@ Array.init (Array.length m) (fun i -> m.(i).(n)))) in
85+
(*let () = Printf.printf "get_col %i of m:\n%s\n%s\n" n (show m) (V.show (V.of_array @@ Array.init (Array.length m) (fun i -> m.(i).(n)))) in*)
8686
V.of_array @@ Array.init (Array.length m) (fun i -> m.(i).(n))
8787

8888
let get_col m n = Timing.wrap "get_col" (get_col m) n
@@ -286,7 +286,7 @@ module ArrayMatrix: AbstractMatrix =
286286
match rref_vec_with m' v' with
287287
| Some res -> let () = Printf.printf "After rref_vec we have m:\n%s\n" (show res) in
288288
Some (remove_zero_rows res)
289-
| None -> None
289+
| None -> let () = Printf.printf "After rref_vec there is no normalization\n" in None
290290

291291
let rref_matrix_with m1 m2 =
292292
(*Similar to rref_vec_with but takes two matrices instead.*)

src/cdomains/affineEquality/arrayImplementation/arrayVector.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module ArrayVector: AbstractVector =
3636

3737
let remove_at_indices v idx = failwith "TODO"
3838

39-
let insert_zero_at_indices v idx = failwith "TODO"
39+
let insert_zero_at_indices v idx count = failwith "TODO"
4040

4141
let set_nth_with v n new_val =
4242
if n >= Array.length v then failwith "n outside of Array range" else

src/cdomains/affineEquality/sparseImplementation/listMatrix.ml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,21 @@ module ListMatrix: AbstractMatrix =
3939
Timing.wrap "copy" (copy) m
4040

4141
let add_empty_columns m cols =
42-
let () = Printf.printf "Before add_empty_columns m:\n%s\n" (show m) in
42+
let () = Printf.printf "Before add_empty_columns m:\n%sindices: %s\n" (show m) (Array.fold_right (fun x s -> s ^ (Int.to_string x) ^ ",") cols "") in
4343
let cols = Array.to_list cols in
4444
let sorted_cols = List.sort Stdlib.compare cols in
45-
let rec count_sorted_occ acc cols last count =
45+
let rec count_sorted_occ acc cols last count =
4646
match cols with
47-
| [] -> acc
48-
| (x :: xs) when x = last -> count_sorted_occ acc xs x (count + 1)
49-
| (x :: xs) -> count_sorted_occ ((last, count) :: acc) xs x 1
47+
| [] -> if count > 0 then (last, count) :: acc else acc
48+
| x :: xs when x = last -> count_sorted_occ acc xs x (count + 1)
49+
| x :: xs -> let acc = if count > 0 then (last, count) :: acc else acc in
50+
count_sorted_occ acc xs x 1
5051
in
51-
let occ_cols = count_sorted_occ [] sorted_cols (-1) 0 in
52-
let () = Printf.printf "After add_empty_columns m:\n%s\n" (show (List.map (fun row -> V.insert_zero_at_indices row occ_cols) m)) in
53-
List.map (fun row -> V.insert_zero_at_indices row occ_cols) m
52+
let occ_cols = List.rev @@ count_sorted_occ [] sorted_cols 0 0 in
53+
(*let () = Printf.printf "sorted cols is: %s\n" (List.fold_right (fun x s -> (Int.to_string x) ^ s) sorted_cols "") in
54+
let () = Printf.printf "sorted_occ is: %s\n" (List.fold_right (fun (i, count) s -> "(" ^ (Int.to_string i) ^ "," ^ (Int.to_string count) ^ ")" ^ s) occ_cols "") in*)
55+
let () = Printf.printf "After add_empty_columns m:\n%s\n" (show (List.map (fun row -> V.insert_zero_at_indices row occ_cols (List.length cols)) m)) in
56+
List.map (fun row -> V.insert_zero_at_indices row occ_cols (List.length cols)) m
5457

5558
let add_empty_columns m cols =
5659
Timing.wrap "add_empty_cols" (add_empty_columns m) cols
@@ -68,7 +71,7 @@ module ListMatrix: AbstractMatrix =
6871
List.remove_at n m
6972

7073
let get_col m n =
71-
let () = Printf.printf "get_col %i of m:\n%s\n%s\n" n (show m) (V.show (V.of_list @@ List.map (fun row -> V.nth row n) m)) in
74+
(*let () = Printf.printf "get_col %i of m:\n%s\n%s\n" n (show m) (V.show (V.of_list @@ List.map (fun row -> V.nth row n) m)) in*)
7275
V.of_list @@ List.map (fun row -> V.nth row n) m (* builds full col including zeros, maybe use sparselist instead? *)
7376

7477
let get_col m n =
@@ -246,7 +249,7 @@ module ListMatrix: AbstractMatrix =
246249
match normalize @@ append_matrices m (init_with_vec v) with
247250
| Some res -> let () = Printf.printf "After rref_vec we have m:\n%s\n" (show res) in
248251
Some (remove_zero_rows res)
249-
| None -> None
252+
| None -> let () = Printf.printf "After rref_vec there is no normalization\n " in None
250253

251254
(*Similar to rref_vec_with but takes two matrices instead.*)
252255
(*ToDo Could become inefficient for large matrices since pivot_elements are always recalculated + many row additions*)

src/cdomains/affineEquality/sparseImplementation/sparseVector.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module SparseVector: AbstractVector =
8080
in
8181
{entries = remove_indices_helper v.entries idx 0; len = v.len - List.length idx}
8282

83-
let insert_zero_at_indices v idx =
83+
let insert_zero_at_indices v idx count =
8484
let rec add_indices_helper vec idx added_count =
8585
match vec, idx with
8686
| [], [] -> []
@@ -90,7 +90,7 @@ module SparseVector: AbstractVector =
9090
| ((col_idx, value) :: xs), ((i, count) :: ys) when i < col_idx -> (col_idx + added_count + count, value) :: add_indices_helper xs ys (added_count + count)
9191
| ((col_idx, value) :: xs), ((i, count) :: ys) -> (col_idx + added_count, value) :: add_indices_helper xs idx added_count
9292
in
93-
{entries = add_indices_helper v.entries idx 0; len = v.len + List.length idx}
93+
{entries = add_indices_helper v.entries idx 0; len = v.len + count}
9494

9595
let set_nth v n num = (* TODO: Optimize! *)
9696
if n >= v.len then failwith "Out of bounds"

src/cdomains/affineEquality/vector.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sig
1212

1313
val remove_at_indices: t -> int list -> t
1414

15-
val insert_zero_at_indices: t -> (int * int) list -> t
15+
val insert_zero_at_indices: t -> (int * int) list -> int -> t
1616

1717
val set_nth: t -> int -> num -> t
1818

0 commit comments

Comments
 (0)