1

I'm trying to avoid MainEvaluate in CompiledFunction. I've tried below but I couldn't get rid of it. I'd appreciate any help!!

Here f1 and f2 will be rank 1 list with real type.

decision[f1_, f2_] := And @@ Thread[LessEqual[f1, f2]] && Or @@ Thread[Less[f1, f2]];

dominates = Compile[{{f1, _Real, 1}, {f2, _Real, 1}}, 
decision[f1, f2], {{decision[_, _], True | False}}, 
CompilationOptions ->{"InlineCompiledFunctions" -> True}];
<< CompiledFunctionTools`
CompilePrint[dominates]
Sim
  • 13
  • 2

1 Answers1

1

Perhaps this?

dominates = Compile[{{f1, _Real, 1}, {f2, _Real, 1}}, 
  Length[Cases[UnitStep[f2 - f1], 0, 1]] == 0 && 
   Length[Cases[Unitize[f2 - f1], 1, 1]] > 0
  ]

For further discussion, see para. 2.3 of this answer: Performance tuning in Mathematica?

Michael E2
  • 235,386
  • 17
  • 334
  • 747