10
$\begingroup$

Bug introduced in 12.0 and persisting through 12.0 or later


When I run the following code, the kernel hangs indefinitely:

$Version
(*  "12.0.0 for Mac OS X x86 (64-bit) (April 7, 2019)"  *)

cf = Compile[{{x, _Integer, 1}},
   Length@x,
   RuntimeAttributes -> {Listable}
   ];

cf[{}]   (* Works fine *)
(*  0  *)

cf[{{1}, {2, 3, 4}}]  (* Listability seems ok *)
(*  {1, 3}  *)

cf[{{}}] (* WARNING: Causes hang/crash *)

With Parallelization -> True, the kernel crashes after a couple of seconds. Without Parallelization, it hangs until I interrupt the kernel, which causes a crash.

Update: The following runs without crashing and produces the right result. I'm not sure how to tell if the program ran the uncompiled or compiled code. (I suppose it ran the compiled code, but I don't know how to verify that.)

cf[{{2, 3}, {}}]

CompiledFunction::cfta: Argument {{2,3},{}} at position 1 should be a rank 1 tensor of machine-size integers.

(*  {2, 0}  *)

I'm not very familiar with the compiler, so I'm wondering if there's some issue I'm ignorant of, such as some kind of type mismatch. Otherwise, I suppose it's a bug. It's rather inconvenient, as I was working with programmatically produced arrays that are sometimes empty.

If my program is correct and it is a bug, does anyone have a workaround (other than manually mapping/threading the compiled function over the list of arrays)?

$\endgroup$
  • $\begingroup$ I also stumbled upon this issue several times now. Usually, I try to circumvent it by assurring that the lists supplied to CompiledFunction are never empty, e.g., by appending dummy 0-entries... Sometimes, this come at almost no additiona price. The newest example is here. $\endgroup$ – Henrik Schumacher Jul 12 at 18:12
  • 1
    $\begingroup$ @HenrikSchumacher Thanks. Your comment led me to this: I never realized before that an empty array {} cannot be packed, not even with Most@Developer`ToPackedArray[{0}, Integer] (like Most[{0}] inside Compile[]). I'll see what WRI has to say this coming week, assuming I get an enlightening response. $\endgroup$ – Michael E2 Jul 13 at 16:05
2
$\begingroup$

This was passed on to developers at WRI as issue, [CASE:4280135]. No workaround was suggested.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.