let matrix_of_list ~l ~m ~n =
let nn = List.length l in
if (nn <> (m * n)) then (raise (Invalid_argument("matrix_of_list : dimensions mismatch |l| <> n*m")));
let res = Array.create_matrix m n (hd l) in
for j = 0 to (n-1) do
for i = 0 to (m-1) do
res.(i).(j) <- (List.nth l (i + j*m));
done;
done;
res