# Buggy code
def get_laplacian_matrix(self):
    r"""Get the laplacian matrix of users and items.

    .. math::
        L = I - D^{-1} \times A

    Returns:
        Sparse tensor of the laplacian matrix.
    """
    # build adj matrix
    A = sp.dok_matrix(
        (self.n_users + self.n_items, self.n_users + self.n_items), dtype=np.float32
    )
    A = A.tolil()
    A[: self.n_users, self.n_users :] = self.interaction_matrix
    A[self.n_users :, : self.n_users] = self.interaction_matrix.transpose()
    A = A.todok()

    # norm adj matrix
    sumArr = (A > 0).sum(axis=1)
    diag = np.array(sumArr.flatten())[0] + 1e-7
    diag = np.power(diag, -1)
    D = sp.diags(diag)
    A_tilde = D * A

    # covert norm_adj matrix to tensor
    A_tilde = sp.coo_matrix(A_tilde)
    row = A_tilde.row
    col = A_tilde.col
    i = torch.LongTensor([row, col])
    data = torch.FloatTensor(A_tilde.data)
    A_tilde = torch.sparse.FloatTensor(i, data, torch.Size(A_tilde.shape))

    # generate laplace matrix
    L = self.get_eye_mat(self.n_items + self.n_users) - A_tilde
    return L


# Traceback (MemoryError)
20 Nov 23:58    INFO General Hyper Parameters:
gpu_id=0
use_gpu=True
seed=2020                                                                                                                                                                                                          [76/1356]
state=INFO
reproducibility=True
data_path=dataset/gowalla

Training Hyper Parameters:
checkpoint_dir=saved
epochs=300
train_batch_size=4
learner=adam
learning_rate=0.001
training_neg_sample_num=1
eval_step=1
stopping_step=10

Evaluation Hyper Parameters:
eval_setting=RO_RS,full
group_by_user=True
split_ratio=[0.8, 0.1, 0.1]
leave_one_num=2
real_time_process=True
metrics=Recall
topk=100
valid_metric=Recall@100
eval_batch_size=4

Dataset Hyper Parameters:
field_separator=
seq_separator=
USER_ID_FIELD=user_id
ITEM_ID_FIELD=item_id
RATING_FIELD=rating
LABEL_FIELD=label
threshold=None
NEG_PREFIX=neg_
load_col={'inter': ['user_id', 'item_id']}
unload_col=None
additional_feat_suffix=None
max_user_inter_num=None
min_user_inter_num=0
max_item_inter_num=None
min_item_inter_num=0
lowest_val=None
highest_val=None
equal_val=None
not_equal_val=None
drop_filter_field=True
fields_in_same_space=None
fill_nan=True
preload_weight=None
drop_preload_weight=True
normalize_field=None
normalize_all=True
ITEM_LIST_LENGTH_FIELD=item_length
LIST_SUFFIX=_list
MAX_ITEM_LIST_LENGTH=50
POSITION_FIELD=position_id
HEAD_ENTITY_ID_FIELD=head_id
TAIL_ENTITY_ID_FIELD=tail_id
RELATION_ID_FIELD=relation_id
ENTITY_ID_FIELD=entity_id


20 Nov 23:58    INFO gowalla
The number of users: 107093
Average actions of users: 37.17675456616741
The number of items: 1280970
Average actions of items: 3.1080635050496928
The number of inters: 3981333
The sparsity of the dataset: 99.99709779249932%
Remain Fields: ['user_id', 'item_id']
20 Nov 23:58    INFO Build [ModelType.GENERAL] DataLoader for [train] with format [InputType.PAIRWISE]
20 Nov 23:58    INFO Evaluation Setting:
Group by user_id
Ordering: {'strategy': 'shuffle'}
Splitting: {'strategy': 'by_ratio', 'ratios': [0.8, 0.1, 0.1]}
Negative Sampling: {'strategy': 'by', 'distribution': 'uniform', 'by': 1}
20 Nov 23:58    INFO batch_size = [[4]], shuffle = [True]

20 Nov 23:58    INFO Build [ModelType.GENERAL] DataLoader for [evaluation] with format [InputType.POINTWISE]
20 Nov 23:58    INFO Evaluation Setting:
Group by user_id
Ordering: {'strategy': 'shuffle'}
Splitting: {'strategy': 'by_ratio', 'ratios': [0.8, 0.1, 0.1]}
Negative Sampling: {'strategy': 'full', 'distribution': 'uniform'}
20 Nov 23:58    INFO batch_size = [[4, 4]], shuffle = [False]

20 Nov 23:58    WARNING Batch size is changed to 1280970
20 Nov 23:58    WARNING Batch size is changed to 1280970
Traceback (most recent call last):
File "run_recbole.py", line 25, in <module>
run_recbole(model=args.model, dataset=args.dataset, config_file_list=config_file_list)
File "/home/szumowskit1/workspace/RecBole/recbole/quick_start/quick_start.py", line 45, in run_recbole
model = get_model(config['model'])(config, train_data).to(config['device'])
File "/home/szumowskit1/workspace/RecBole/recbole/model/general_recommender/lightgcn.py", line 69, in __init__
self.norm_adj_matrix = self.get_norm_adj_mat().to(self.device)
File "/home/szumowskit1/workspace/RecBole/recbole/model/general_recommender/lightgcn.py", line 90, in get_norm_adj_mat
A[:self.n_users, self.n_users:] = self.interaction_matrix
File "/home/szumowskit1/.venv/recbole/lib/python3.7/site-packages/scipy/sparse/lil.py", line 333, in __setitem__
IndexMixin.__setitem__(self, key, x)
File "/home/szumowskit1/.venv/recbole/lib/python3.7/site-packages/scipy/sparse/_index.py", line 116, in __setitem__
self._set_arrayXarray_sparse(i, j, x)
File "/home/szumowskit1/.venv/recbole/lib/python3.7/site-packages/scipy/sparse/lil.py", line 319, in _set_arrayXarray_sparse
x = np.asarray(x.toarray(), dtype=self.dtype)
File "/home/szumowskit1/.venv/recbole/lib/python3.7/site-packages/scipy/sparse/coo.py", line 321, in toarray
B = self._process_toarray_args(order, out)
File "/home/szumowskit1/.venv/recbole/lib/python3.7/site-packages/scipy/sparse/base.py", line 1185, in _process_toarray_args
return np.zeros(self.shape, dtype=self.dtype, order=order)
MemoryError: Unable to allocate 511. GiB for an array with shape (107093, 1280970) and data type float32

# Fixed code
def get_laplacian_matrix(self):
    r"""Get the laplacian matrix of users and items.

    .. math::
        L = I - D^{-1} \times A

    Returns:
        Sparse tensor of the laplacian matrix.
    """
    # build adj matrix
    A = sp.dok_matrix(
        (self.n_users + self.n_items, self.n_users + self.n_items), dtype=np.float32
    )
    inter_M = self.interaction_matrix
    inter_M_t = self.interaction_matrix.transpose()
    data_dict = dict(
        zip(zip(inter_M.row, inter_M.col + self.n_users), [1] * inter_M.nnz)
    )
    data_dict.update(
        dict(zip(zip(inter_M_t.row + self.n_users, inter_M_t.col), [1] * inter_M_t.nnz))
    )
    A._update(data_dict)

    # norm adj matrix
    sumArr = (A > 0).sum(axis=1)
    diag = np.array(sumArr.flatten())[0] + 1e-7
    diag = np.power(diag, -1)
    D = sp.diags(diag)
    A_tilde = D * A

    # covert norm_adj matrix to tensor
    A_tilde = sp.coo_matrix(A_tilde)
    row = A_tilde.row
    col = A_tilde.col
    i = torch.LongTensor([row, col])
    data = torch.FloatTensor(A_tilde.data)
    A_tilde = torch.sparse.FloatTensor(i, data, torch.Size(A_tilde.shape))

    # generate laplace matrix
    L = self.get_eye_mat(self.n_items + self.n_users) - A_tilde
    return L