wrapped_ocaml.ml 736 B

12345678910111213141516171819202122232425262728293031
  1. let matrix_mul x y =
  2. let x0 = Array.length x
  3. and y0 = Array.length y in
  4. let y1 = if y0 = 0 then 0 else Array.length y.(0) in
  5. let z = Array.make_matrix x0 y1 0 in
  6. for i = 0 to x0-1 do
  7. for j = 0 to y1-1 do
  8. for k = 0 to y0-1 do
  9. z.(i).(j) <- z.(i).(j) + x.(i).(k) * y.(k).(j)
  10. done
  11. done
  12. done;
  13. z
  14. let new_matrix width height =
  15. Array.make_matrix width height 0
  16. let matrix_assign m x y item =
  17. m.(x).(y) <- item
  18. let matrix_retrieve m x y =
  19. m.(x).(y)
  20. let _ = Callback.register "ocaml_new_matrix" new_matrix
  21. let _ = Callback.register "ocaml_matrix_assign" matrix_assign
  22. let _ = Callback.register "ocaml_matrix_retrieve" matrix_retrieve
  23. let _ = Callback.register "ocaml_matrix_mul" matrix_mul