SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IndexBlockRelation.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Copyright (C) 2012 Sergey Lisitsyn
8  */
9 
11 #include <shogun/lib/IndexBlock.h>
12 #include <shogun/lib/SGVector.h>
13 
14 using namespace shogun;
15 
17 {
18  int32_t n_sub_blocks = blocks->get_num_elements();
19  index_t* min_idxs = SG_MALLOC(index_t, n_sub_blocks);
20  index_t* max_idxs = SG_MALLOC(index_t, n_sub_blocks);
21  index_t* block_idxs_min = SG_MALLOC(index_t, n_sub_blocks);
22  index_t* block_idxs_max = SG_MALLOC(index_t, n_sub_blocks);
23  CIndexBlock* iter_block = (CIndexBlock*)(blocks->get_first_element());
24  for (int32_t i=0; i<n_sub_blocks; i++)
25  {
26  min_idxs[i] = iter_block->get_min_index();
27  max_idxs[i] = iter_block->get_max_index();
28  block_idxs_min[i] = i;
29  block_idxs_max[i] = i;
30  SG_UNREF(iter_block);
31  iter_block = (CIndexBlock*)(blocks->get_next_element());
32  }
33  CMath::qsort_index(min_idxs, block_idxs_min, n_sub_blocks);
34  CMath::qsort_index(max_idxs, block_idxs_max, n_sub_blocks);
35 
36  for (int32_t i=0; i<n_sub_blocks; i++)
37  {
38  if (block_idxs_min[i] != block_idxs_max[i])
39  SG_ERROR("Blocks do overlap and it is not supported\n");
40  }
41  if (min_idxs[0] != 0)
42  SG_ERROR("Block with smallest indices start from %d while 0 is required\n", min_idxs[0]);
43 
44  for (int32_t i=1; i<n_sub_blocks; i++)
45  {
46  if (min_idxs[i] > max_idxs[i-1])
47  SG_ERROR("There is an unsupported gap between %d and %d vectors\n", max_idxs[i-1], min_idxs[i]);
48  else if (min_idxs[i] < max_idxs[i-1])
49  SG_ERROR("Blocks do overlap and it is not supported\n");
50  }
51 
52  SG_FREE(min_idxs);
53  SG_FREE(max_idxs);
54  SG_FREE(block_idxs_min);
55  SG_FREE(block_idxs_max);
56  return true;
57 }

SHOGUN Machine Learning Toolbox - Documentation