You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
inif validate_vec pivot_l then validate vs (i+1) else raise (Invalid_argument"Matrix not in rref: pivot column not empty!")
231
213
in validate m 0
232
214
233
-
(* Inserts the vector v with pivot at piv_idx at the correct position in m. m has to be in rref form. *)
215
+
(* This function return a tuple of row index and pivot position (column) in m *)
216
+
(* TODO: maybe we could use a Hashmap instead of a list? *)
217
+
letget_pivot_positions (m: t) : (int * int) list =
218
+
List.rev @@List.fold_lefti (
219
+
funaccirow -> matchV.find_first_non_zero row with
220
+
|None -> acc
221
+
|Some (pivot_col, _) -> (i, pivot_col) :: acc
222
+
) [] m
223
+
224
+
(* Sets the jth column to zero by subtracting multiples of v *)
225
+
letreduce_col_with_vecmjv=
226
+
let pivot_element =V.nth v j in
227
+
if pivot_element =A.zero then m
228
+
elseList.mapi (funidxrow ->
229
+
let row_value =V.nth row j in
230
+
if row_value =:A.zero then row
231
+
else (let s = row_value /: pivot_element in
232
+
V.map2_f_preserves_zero (funxy -> x -: (s *: y)) row v)
233
+
) m
234
+
235
+
(* Inserts the vector v with pivot at piv_idx at the correct position in m. m has to be in rref form and v is only <>: A.zero on piv_idx or idx not included in piv_positions *)
0 commit comments