Your non-mutating version is O(n * length(idx)) while my mutating version is O(n + length(idx)). I’m assuming the reason why you want to avoid mutation is because this may lead to issues with reverse mode differentiation?
Your non-mutating version is O(n * length(idx)) while my mutating version is O(n + length(idx)). I’m assuming the reason why you want to avoid mutation is because this may lead to issues with reverse mode differentiation?