@@ -72,9 +72,10 @@ module ListMatrix: AbstractMatrix =
7272 let add_empty_columns m cols =
7373 Timing. wrap " add_empty_cols" (add_empty_columns m) cols
7474
75- let get_col m n =
76- (* 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*)
77- V. of_list @@ List. map (fun row -> V. nth row n) m (* builds full col including zeros, maybe use sparselist instead? *)
75+ let get_col m n = (* TODO: is this optimal? *)
76+ (* V.of_list @@ List.map (fun row -> V.nth row n) m (* builds full col including zeros, maybe use sparselist instead? *) *)
77+ V. of_sparse_list (num_rows m) @@ List. filteri_map (fun i row -> let value = V. nth row n in if value <> : A. zero then Some (i, value) else None ) m
78+
7879
7980 let get_col m n =
8081 Timing. wrap " get_col" (get_col m) n
@@ -83,6 +84,8 @@ module ListMatrix: AbstractMatrix =
8384 (* List.mapi (fun row_idx row -> V.set_nth row n (V.nth new_col row_idx)) m *)
8485 List. map2 (fun row value -> V. set_nth row n value) m (V. to_list new_col)
8586
87+ let set_col m new_col n = Timing. wrap " set_col" (set_col m) new_col n
88+
8689 let del_col m j =
8790 if num_cols m = 1 then empty ()
8891 else
@@ -101,6 +104,8 @@ module ListMatrix: AbstractMatrix =
101104 let vector_length = V. length v in
102105 List. mapi (fun index row -> if index < vector_length then f row (V. nth v index) else row ) m
103106
107+ let map2 f m v = Timing. wrap " Matrix.map2" (map2 f m) v
108+
104109 let map2i f m v = (* TODO: Optimize! We should probably do it like in map2 *)
105110 let rec map2i_min i acc m v =
106111 match m, v with
@@ -110,6 +115,8 @@ module ListMatrix: AbstractMatrix =
110115 in
111116 map2i_min 0 [] m (V. to_list v)
112117
118+ let map2i f m v = Timing. wrap " Matrix.map2i" (map2i f m) v
119+
113120 let find_opt = List. find_opt
114121
115122 let append_matrices m1 m2 = (* keeps dimensions of first matrix, what if dimensions differ?*)
0 commit comments