implementing ivy algorithms for toroidal topology