1
$\begingroup$

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]
$\endgroup$
  • $\begingroup$ The expression in decision[] is not compilable. Try rewriting it using UnitStep[]. $\endgroup$ – Michael E2 Oct 12 '16 at 23:40
  • $\begingroup$ So you want all the elements of f1 less than or equal to the corresponding element of f2 and at least one the pairs unequal? $\endgroup$ – Michael E2 Oct 12 '16 at 23:42
1
$\begingroup$

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?

$\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.