prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  [🐛BUG] case_study.py 中， 输入的用户id只有一个时， full_sort_topk 报错
  代码
  ```python3
  import torch
  import pandas as pd
  
  from recbole.model.general_recommender.bpr import BPR
  from recbole.config import Config
  from recbole.data import create_dataset, data_preparation
  from recbole.utils.case_study import full_sort_topk
  
  param_dict = {
      'use_gpu': False
  }
  
  # 加载 BPR 模型
  bpr_model_path = "D:\\source\\recbole-0.2.0\\app\\ex\\saved\\BPR-Jan-18-2021_14-03-52.pth"
  bpr_config = Config(model='BPR',
                      dataset='ml-100k',
                      config_dict=param_dict)
  dataset = create_dataset(bpr_config)
  train_data, valid_data, test_data = data_preparation(bpr_config, dataset)
  
  bpr_model = BPR(bpr_config, train_data)
  checkpoint = torch.load(bpr_model_path)
  bpr_model.load_state_dict(checkpoint['state_dict'])
  bpr_model.eval()
  
  uid_series = dataset.token2id(dataset.uid_field, ['200'])  # 原始数据集中的用户id，变换为训练内部使用的索引id
  
  full_sort_topk(uid_series, bpr_model, test_data, 10)
  ```
  
  报错信息
  Traceback (most recent call last):
    File "D:/source/recbole-0.2.0/app/ex/bpr_predict_ml100k.py", line 33, in <module>
      full_sort_topk(uid_series, bpr_model, test_data, 10)
    File "D:\source\recbole-0.2.0\recbole\utils\case_study.py", line 87, in full_sort_topk
      scores = full_sort_scores(uid_series, model, test_data)
    File "D:\Anaconda3\envs\pytorch\lib\site-packages\torch\autograd\grad_mode.py", line 26, in decorate_context
      return func(*args, **kwargs)
    File "D:\source\recbole-0.2.0\recbole\utils\case_study.py", line 45, in full_sort_scores
      history_row = torch.cat([torch.full_like(hist_iid, i) for i, hist_iid in enumerate(history_item)])
  RuntimeError: zero-dimensional tensor (at position 0) cannot be concatenated
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `recbole/utils/case_study.py`
  Content:
  ```
  1 # @Time   : 2020/12/25
  2 # @Author : Yushuo Chen
  3 # @Email  : chenyushuo@ruc.edu.cn
  4 
  5 # UPDATE
  6 # @Time   : 2020/12/25
  7 # @Author : Yushuo Chen
  8 # @email  : chenyushuo@ruc.edu.cn
  9 
  10 """
  11 recbole.utils.case_study
  12 #####################################
  13 """
  14 
  15 import numpy as np
  16 import torch
  17 
  18 from recbole.data.dataloader.general_dataloader import GeneralFullDataLoader
  19 from recbole.data.dataloader.sequential_dataloader import SequentialFullDataLoader
  20 
  21 
  22 @torch.no_grad()
  23 def full_sort_scores(uid_series, model, test_data):
  24     """Calculate the scores of all items for each user in uid_series.
  25 
  26     Note:
  27         The score of [pad] and history items will be set into -inf.
  28 
  29     Args:
  30         uid_series (numpy.ndarray): User id series
  31         model (AbstractRecommender): Model to predict
  32         test_data (AbstractDataLoader): The test_data of model
  33 
  34     Returns:
  35         torch.Tensor: the scores of all items for each user in uid_series.
  36     """
  37     uid_field = test_data.dataset.uid_field
  38     dataset = test_data.dataset
  39     model.eval()
  40 
  41     if isinstance(test_data, GeneralFullDataLoader):
  42         index = np.isin(test_data.user_df[uid_field].numpy(), uid_series)
  43         input_interaction = test_data.user_df[index]
  44         history_item = test_data.uid2history_item[input_interaction[uid_field]]
  45         history_row = torch.cat([torch.full_like(hist_iid, i) for i, hist_iid in enumerate(history_item)])
  46         history_col = torch.cat(list(history_item))
  47         history_index = history_row, history_col
  48     elif isinstance(test_data, SequentialFullDataLoader):
  49         index = np.isin(test_data.uid_list, uid_series)
  50         input_interaction = test_data.augmentation(
  51             test_data.item_list_index[index], test_data.target_index[index], test_data.item_list_length[index]
  52         )
  53         history_index = None
  54     else:
  55         raise NotImplementedError
  56 
  57     # Get scores of all items
  58     try:
  59         scores = model.full_sort_predict(input_interaction)
  60     except NotImplementedError:
  61         input_interaction = input_interaction.repeat(dataset.item_num)
  62         input_interaction.update(test_data.get_item_feature().repeat(len(uid_series)))
  63         scores = model.predict(input_interaction)
  64 
  65     scores = scores.view(-1, dataset.item_num)
  66     scores[:, 0] = -np.inf  # set scores of [pad] to -inf
  67     if history_index is not None:
  68         scores[history_index] = -np.inf  # set scores of history items to -inf
  69 
  70     return scores
  71 
  72 
  73 def full_sort_topk(uid_series, model, test_data, k):
  74     """Calculate the top-k items' scores and ids for each user in uid_series.
  75 
  76     Args:
  77         uid_series (numpy.ndarray): User id series
  78         model (AbstractRecommender): Model to predict
  79         test_data (AbstractDataLoader): The test_data of model
  80         k (int): The top-k items.
  81 
  82     Returns:
  83         tuple:
  84             - topk_scores (torch.Tensor): The scores of topk items.
  85             - topk_index (torch.Tensor): The index of topk items, which is also the internal ids of items.
  86     """
  87     scores = full_sort_scores(uid_series, model, test_data)
  88     return torch.topk(scores, k)
  89
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/recbole/utils/case_study.py b/recbole/utils/case_study.py
  --- a/recbole/utils/case_study.py
  +++ b/recbole/utils/case_study.py
  @@ -41,7 +41,7 @@
       if isinstance(test_data, GeneralFullDataLoader):
           index = np.isin(test_data.user_df[uid_field].numpy(), uid_series)
           input_interaction = test_data.user_df[index]
  -        history_item = test_data.uid2history_item[input_interaction[uid_field]]
  +        history_item = test_data.uid2history_item[input_interaction[uid_field].numpy()]
           history_row = torch.cat([torch.full_like(hist_iid, i) for i, hist_iid in enumerate(history_item)])
           history_col = torch.cat(list(history_item))
           history_index = history_row, history_col
  
verification_info: {"golden_diff": "diff --git a/recbole/utils/case_study.py b/recbole/utils/case_study.py\n--- a/recbole/utils/case_study.py\n+++ b/recbole/utils/case_study.py\n@@ -41,7 +41,7 @@\n     if isinstance(test_data, GeneralFullDataLoader):\n         index = np.isin(test_data.user_df[uid_field].numpy(), uid_series)\n         input_interaction = test_data.user_df[index]\n-        history_item = test_data.uid2history_item[input_interaction[uid_field]]\n+        history_item = test_data.uid2history_item[input_interaction[uid_field].numpy()]\n         history_row = torch.cat([torch.full_like(hist_iid, i) for i, hist_iid in enumerate(history_item)])\n         history_col = torch.cat(list(history_item))\n         history_index = history_row, history_col\n", "issue": "[\ud83d\udc1bBUG] case_study.py \u4e2d\uff0c \u8f93\u5165\u7684\u7528\u6237id\u53ea\u6709\u4e00\u4e2a\u65f6\uff0c full_sort_topk \u62a5\u9519\n\u4ee3\u7801\r\n```python3\r\nimport torch\r\nimport pandas as pd\r\n\r\nfrom recbole.model.general_recommender.bpr import BPR\r\nfrom recbole.config import Config\r\nfrom recbole.data import create_dataset, data_preparation\r\nfrom recbole.utils.case_study import full_sort_topk\r\n\r\nparam_dict = {\r\n    'use_gpu': False\r\n}\r\n\r\n# \u52a0\u8f7d BPR \u6a21\u578b\r\nbpr_model_path = \"D:\\\\source\\\\recbole-0.2.0\\\\app\\\\ex\\\\saved\\\\BPR-Jan-18-2021_14-03-52.pth\"\r\nbpr_config = Config(model='BPR',\r\n                    dataset='ml-100k',\r\n                    config_dict=param_dict)\r\ndataset = create_dataset(bpr_config)\r\ntrain_data, valid_data, test_data = data_preparation(bpr_config, dataset)\r\n\r\nbpr_model = BPR(bpr_config, train_data)\r\ncheckpoint = torch.load(bpr_model_path)\r\nbpr_model.load_state_dict(checkpoint['state_dict'])\r\nbpr_model.eval()\r\n\r\nuid_series = dataset.token2id(dataset.uid_field, ['200'])  # \u539f\u59cb\u6570\u636e\u96c6\u4e2d\u7684\u7528\u6237id\uff0c\u53d8\u6362\u4e3a\u8bad\u7ec3\u5185\u90e8\u4f7f\u7528\u7684\u7d22\u5f15id\r\n\r\nfull_sort_topk(uid_series, bpr_model, test_data, 10)\r\n```\r\n\r\n\u62a5\u9519\u4fe1\u606f\r\nTraceback (most recent call last):\r\n  File \"D:/source/recbole-0.2.0/app/ex/bpr_predict_ml100k.py\", line 33, in <module>\r\n    full_sort_topk(uid_series, bpr_model, test_data, 10)\r\n  File \"D:\\source\\recbole-0.2.0\\recbole\\utils\\case_study.py\", line 87, in full_sort_topk\r\n    scores = full_sort_scores(uid_series, model, test_data)\r\n  File \"D:\\Anaconda3\\envs\\pytorch\\lib\\site-packages\\torch\\autograd\\grad_mode.py\", line 26, in decorate_context\r\n    return func(*args, **kwargs)\r\n  File \"D:\\source\\recbole-0.2.0\\recbole\\utils\\case_study.py\", line 45, in full_sort_scores\r\n    history_row = torch.cat([torch.full_like(hist_iid, i) for i, hist_iid in enumerate(history_item)])\r\nRuntimeError: zero-dimensional tensor (at position 0) cannot be concatenated\n", "before_files": [{"content": "# @Time   : 2020/12/25\n# @Author : Yushuo Chen\n# @Email  : chenyushuo@ruc.edu.cn\n\n# UPDATE\n# @Time   : 2020/12/25\n# @Author : Yushuo Chen\n# @email  : chenyushuo@ruc.edu.cn\n\n\"\"\"\nrecbole.utils.case_study\n#####################################\n\"\"\"\n\nimport numpy as np\nimport torch\n\nfrom recbole.data.dataloader.general_dataloader import GeneralFullDataLoader\nfrom recbole.data.dataloader.sequential_dataloader import SequentialFullDataLoader\n\n\n@torch.no_grad()\ndef full_sort_scores(uid_series, model, test_data):\n    \"\"\"Calculate the scores of all items for each user in uid_series.\n\n    Note:\n        The score of [pad] and history items will be set into -inf.\n\n    Args:\n        uid_series (numpy.ndarray): User id series\n        model (AbstractRecommender): Model to predict\n        test_data (AbstractDataLoader): The test_data of model\n\n    Returns:\n        torch.Tensor: the scores of all items for each user in uid_series.\n    \"\"\"\n    uid_field = test_data.dataset.uid_field\n    dataset = test_data.dataset\n    model.eval()\n\n    if isinstance(test_data, GeneralFullDataLoader):\n        index = np.isin(test_data.user_df[uid_field].numpy(), uid_series)\n        input_interaction = test_data.user_df[index]\n        history_item = test_data.uid2history_item[input_interaction[uid_field]]\n        history_row = torch.cat([torch.full_like(hist_iid, i) for i, hist_iid in enumerate(history_item)])\n        history_col = torch.cat(list(history_item))\n        history_index = history_row, history_col\n    elif isinstance(test_data, SequentialFullDataLoader):\n        index = np.isin(test_data.uid_list, uid_series)\n        input_interaction = test_data.augmentation(\n            test_data.item_list_index[index], test_data.target_index[index], test_data.item_list_length[index]\n        )\n        history_index = None\n    else:\n        raise NotImplementedError\n\n    # Get scores of all items\n    try:\n        scores = model.full_sort_predict(input_interaction)\n    except NotImplementedError:\n        input_interaction = input_interaction.repeat(dataset.item_num)\n        input_interaction.update(test_data.get_item_feature().repeat(len(uid_series)))\n        scores = model.predict(input_interaction)\n\n    scores = scores.view(-1, dataset.item_num)\n    scores[:, 0] = -np.inf  # set scores of [pad] to -inf\n    if history_index is not None:\n        scores[history_index] = -np.inf  # set scores of history items to -inf\n\n    return scores\n\n\ndef full_sort_topk(uid_series, model, test_data, k):\n    \"\"\"Calculate the top-k items' scores and ids for each user in uid_series.\n\n    Args:\n        uid_series (numpy.ndarray): User id series\n        model (AbstractRecommender): Model to predict\n        test_data (AbstractDataLoader): The test_data of model\n        k (int): The top-k items.\n\n    Returns:\n        tuple:\n            - topk_scores (torch.Tensor): The scores of topk items.\n            - topk_index (torch.Tensor): The index of topk items, which is also the internal ids of items.\n    \"\"\"\n    scores = full_sort_scores(uid_series, model, test_data)\n    return torch.topk(scores, k)\n", "path": "recbole/utils/case_study.py"}], "after_files": [{"content": "# @Time   : 2020/12/25\n# @Author : Yushuo Chen\n# @Email  : chenyushuo@ruc.edu.cn\n\n# UPDATE\n# @Time   : 2020/12/25\n# @Author : Yushuo Chen\n# @email  : chenyushuo@ruc.edu.cn\n\n\"\"\"\nrecbole.utils.case_study\n#####################################\n\"\"\"\n\nimport numpy as np\nimport torch\n\nfrom recbole.data.dataloader.general_dataloader import GeneralFullDataLoader\nfrom recbole.data.dataloader.sequential_dataloader import SequentialFullDataLoader\n\n\n@torch.no_grad()\ndef full_sort_scores(uid_series, model, test_data):\n    \"\"\"Calculate the scores of all items for each user in uid_series.\n\n    Note:\n        The score of [pad] and history items will be set into -inf.\n\n    Args:\n        uid_series (numpy.ndarray): User id series\n        model (AbstractRecommender): Model to predict\n        test_data (AbstractDataLoader): The test_data of model\n\n    Returns:\n        torch.Tensor: the scores of all items for each user in uid_series.\n    \"\"\"\n    uid_field = test_data.dataset.uid_field\n    dataset = test_data.dataset\n    model.eval()\n\n    if isinstance(test_data, GeneralFullDataLoader):\n        index = np.isin(test_data.user_df[uid_field].numpy(), uid_series)\n        input_interaction = test_data.user_df[index]\n        history_item = test_data.uid2history_item[input_interaction[uid_field].numpy()]\n        history_row = torch.cat([torch.full_like(hist_iid, i) for i, hist_iid in enumerate(history_item)])\n        history_col = torch.cat(list(history_item))\n        history_index = history_row, history_col\n    elif isinstance(test_data, SequentialFullDataLoader):\n        index = np.isin(test_data.uid_list, uid_series)\n        input_interaction = test_data.augmentation(\n            test_data.item_list_index[index], test_data.target_index[index], test_data.item_list_length[index]\n        )\n        history_index = None\n    else:\n        raise NotImplementedError\n\n    # Get scores of all items\n    try:\n        scores = model.full_sort_predict(input_interaction)\n    except NotImplementedError:\n        input_interaction = input_interaction.repeat(dataset.item_num)\n        input_interaction.update(test_data.get_item_feature().repeat(len(uid_series)))\n        scores = model.predict(input_interaction)\n\n    scores = scores.view(-1, dataset.item_num)\n    scores[:, 0] = -np.inf  # set scores of [pad] to -inf\n    if history_index is not None:\n        scores[history_index] = -np.inf  # set scores of history items to -inf\n\n    return scores\n\n\ndef full_sort_topk(uid_series, model, test_data, k):\n    \"\"\"Calculate the top-k items' scores and ids for each user in uid_series.\n\n    Args:\n        uid_series (numpy.ndarray): User id series\n        model (AbstractRecommender): Model to predict\n        test_data (AbstractDataLoader): The test_data of model\n        k (int): The top-k items.\n\n    Returns:\n        tuple:\n            - topk_scores (torch.Tensor): The scores of topk items.\n            - topk_index (torch.Tensor): The index of topk items, which is also the internal ids of items.\n    \"\"\"\n    scores = full_sort_scores(uid_series, model, test_data)\n    return torch.topk(scores, k)\n", "path": "recbole/utils/case_study.py"}]}