pyml icon indicating copy to clipboard operation
pyml copied to clipboard

Segmentation fault

Open richardalligier opened this issue 2 years ago • 0 comments

Hello,

With python 3.11, OCaml 4.14.0 and pyml 20231101. Some recursive calls seems to trigger a segfault. Here is a minimal reproducible example:

On the Python side I have net.py:

import numpy as np
def toto(n):
    return np.arange(n,dtype=np.float64).reshape(n,1)

and on OCaml side I have:

let print a =
  let n = Bigarray.Genarray.nth_dim a 0 in
  if Bigarray.Genarray.num_dims a > 1
  then
    begin
      for i=0 to n-1 do
        ignore(Bigarray.Genarray.slice_left a [|i|]);
      done;
    end

let ()=
  Py.initialize();
  let netpy = Py.import "net" in
  let n = 26000 in
  let x = Py.Module.get_function netpy "toto" [|Py.Int.of_int n|] in
  let y = (Numpy.to_bigarray Bigarray.float64 Bigarray.c_layout x) in
  print y;
  ()

I have a segfault when running the above code. The slice_left seems to be the culprit because if I replace it by Printf.printf "\n%d %f %!" i (Bigarray.Genarray.get a [|i;0|]); everything is fine. Best, Richard

richardalligier avatar Jan 22 '24 15:01 richardalligier