@@ -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*)
0 commit comments