Simple question:
As a little step in a function I’m working on, I need to filter a unit range, say 1:5, just by taking one of its elements away, say 2. I understand that filter() is the way to go, combined with an anonymous function this way:
@time filter(x -> x .!=2, 1:5)
I’ve tried that several times with the time macro and each time it makes 88.81 K allocations, which is simply a lot, I would say. I also tried a similar filtration not using an anonymous function:
@time filter(isodd,1:5)
Just 14 allocations! I know I just tried 2 different cases, but I’m tempted to think that anonymous functions are very inefficient? I’m working on an MCMC algorithm, so if I’m repeating this step thousands of times, it’ll take days or my laptop is just going to crash.
Any suggestions on how to make this simple filtering efficiently are highly appreciated.
Cheers.
R.