SLIM  1.0
Sparse Linear Methods (SLIM) for top-n recommender systems
 All Data Structures Files Functions Variables Typedefs Macros Pages
check.c
Go to the documentation of this file.
1 /**********************************************************/
2 /*! \file
3  \brief This file constains routines for data pre-processing
4 */
5 /**********************************************************/
6 
7 
8 #include<slim.h>
9 
10 
11 /**********************************************************/
12 /*! \brief Check if test data are already in train data
13 
14  \param[in] ctrl A ctrl structure
15  \param[in] train The training data
16  \param[in] test The testing data
17  */
18 /**********************************************************/
19 void check_train_test(ctrl_t * ctrl, gk_csr_t * train, gk_csr_t * test){
20 
21  int error = 0;
22 
23  int nrows_test = test->nrows;
24 
25  for (int i = 0; i < nrows_test; i ++){
26 
27  int nc_test = test->rowptr[i+1] - test->rowptr[i];
28  int nc_train = train->rowptr[i+1] - train->rowptr[i];
29 
30  for (int j = 0; j < nc_test; j ++){
31 
32  int item_test = *(test->rowptr[i] + j + test->rowind);
33 
34  for (int k = 0; k < nc_train; k ++){
35 
36  int item_train = *(train->rowptr[i] + k + train->rowind);
37 
38  if (item_test == item_train){
39  printf("ERROR: user %6d has item %6d in both train and test\n", i, item_train);
40  error = 1;
41  break;
42  }
43 
44  }
45 
46  }
47 
48  }
49 
50  if (error)
51  errexit("ERROR: train and test not disjoint\n");
52 
53 }