I want a fast algorithm to get a list of elements to be kicked out of another list. But the kick out criterion is not the exact equivalence, however has a tolerance. Any two elements close enough are considered to be same.
The Complement
has SameTest
, for example set norm tolerance as 10^-6
e1 = RandomReal[1, {100, 2}];
e2 = e1 + 10^-9;
Complement[e1, e2, SameTest -> (Norm[#1 - #2] < 10^(-6) &) ]
For 100 point set, the timing is still OK, 0.25sec. For 1000, it is already slow, 8sec.
Any better solutions?
SameTest -> SameQ
and settingInternal``$SameQTolerance
to a higher value, gives a good speed-up, but it's not exactly the same as yourSameTest
as these are floating point numbers: if1.1
and1.0
are the same,0.1
and0.2
still may be different. $\endgroup$