let row m i =
  if i < Array.length m then Array.copy m.(i)
  else failwith (sprintf "invalid row index %d" i)