I wonder if this is much slower in the 2d case? We should measure some time.