import torch


def enumerate_shifted_anchors(anchors, feat_stride, height, width):
	"""apply the anchors to each coordinate of a height * width feature map

	Args:
		anchors: (A, 4)
		feat_stride: (int)
		height: (int)
		width: (int)

	Returns:
		(height * width * A, 4)
	"""
	shift_y = torch.arange(0, height * feat_stride, feat_stride)
	shift_x = torch.arange(0, width * feat_stride, feat_stride)
	shift_y, shift_x = torch.meshgrid(shift_y, shift_x)
	shift = torch.stack([shift_x, shift_y], dim=2)
	shift = shift.reshape(-1, 2).repeat(1, 2)
	shifted_anchors = anchors + shift.unsqueeze(1)

	return shifted_anchors.reshape(-1, 4).float()