import torch


def idx2pos(idx, image_size):
	"""
	Given a flattened idx, return the position in the 3D image space.

	Args:

		idx (int): 					Index into flattened 3D volume
		image_size(list of 3 int): 	Size of 3D volume

	"""
	assert(len(image_size)==3)

	pos_x = idx / (image_size[1] * image_size[2]);
	idx_yz = idx % (image_size[1] * image_size[2]);
	pos_y = idx_yz / image_size[2];
	pos_z = idx_yz % image_size[2];
	return torch.LongTensor([pos_x, pos_y, pos_z]);