SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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/List.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 }
CSGObject * get_next_element()
Definition: List.h:185
int32_t index_t
Definition: common.h:62
static void qsort_index(T1 *output, T2 *index, uint32_t size)
Definition: Math.h:2202
bool check_blocks_list(CList *blocks)
#define SG_ERROR(...)
Definition: SGIO.h:129
CSGObject * get_first_element()
Definition: List.h:151
class IndexBlock used to represent contiguous indices of one group (e.g. block of related features) ...
Definition: IndexBlock.h:25
int32_t get_num_elements()
Definition: List.h:145
index_t get_min_index() const
Definition: IndexBlock.h:45
#define SG_UNREF(x)
Definition: SGObject.h:55
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
index_t get_max_index() const
Definition: IndexBlock.h:49
Class List implements a doubly connected list for low-level-objects.
Definition: List.h:84

SHOGUN Machine Learning Toolbox - Documentation