def forward(self, size: Tuple[int, int]) -> paddle.Tensor:
        """Generate positional encoding for a grid of the specified size."""
        h, w = size
        device: Any = self.positional_encoding_gaussian_matrix.place
        grid = paddle.ones(shape=(h, w), dtype='float32')
        y_embed = grid.cumsum(axis=0) - 0.5
        x_embed = grid.cumsum(axis=1) - 0.5
        y_embed = y_embed / h
        x_embed = x_embed / w
        pe = self._pe_encoding(paddle.stack(x=[x_embed, y_embed], axis=-1))
        return pe.transpose(perm=[2, 0, 1])
Generate positional encoding for a grid of the specified size.
contrib/SegmentAnything/segment_anything/modeling/prompt_encoder.py