Any faster approach than Outer for my computation

This should be equivalent:

l = RandomReal[{-2, 2}, 5000];
r = RandomReal[{-2, 2}, 5000];

Function[left, Abs[left - r]/Clip[r, {left, ∞}]] /@ 
   l; // AbsoluteTiming

0.32

(Note that this is much faster for packed arrays of machine precision numbers instead of integers and fractions)


You could try:

d[l1_, l2_] := With[{d = Outer[Plus, -l1, l2]}, Abs[d]/(Ramp[d] + l1)]

With your sample data:

r1 = d[list1, list2];
r2 = Outer[Abs[#1-#2]/Max[#1,#2]&, list1, list2];

r1===r2

True

For some large lists:

l1 = RandomReal[1, 5000];
l2 = RandomReal[1, 5001];

d[l1, l2]; //AbsoluteTiming
Outer[List, l1, l2]; //AbsoluteTiming

{0.483663, Null}

{0.141301, Null}

So, not too much slower than your reference Outer example.


This seems fairly snappy:

fn = With[{tup = Tuples[{#1, #2}]}, 
          Partition[Abs[Subtract @@ Transpose@tup]/(Max /@ tup), Length@#2]] &;

Use:

result= fn[list1, list2]