SHOGUN
v2.0.0
|
00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Copyright (C) 2012 Sergey Lisitsyn 00008 */ 00009 00010 #include <shogun/lib/IndexBlockRelation.h> 00011 #include <shogun/lib/IndexBlock.h> 00012 #include <shogun/lib/SGVector.h> 00013 00014 using namespace shogun; 00015 00016 bool CIndexBlockRelation::check_blocks_list(CList* blocks) 00017 { 00018 int32_t n_sub_blocks = blocks->get_num_elements(); 00019 index_t* min_idxs = SG_MALLOC(index_t, n_sub_blocks); 00020 index_t* max_idxs = SG_MALLOC(index_t, n_sub_blocks); 00021 index_t* block_idxs_min = SG_MALLOC(index_t, n_sub_blocks); 00022 index_t* block_idxs_max = SG_MALLOC(index_t, n_sub_blocks); 00023 CIndexBlock* iter_block = (CIndexBlock*)(blocks->get_first_element()); 00024 for (int32_t i=0; i<n_sub_blocks; i++) 00025 { 00026 min_idxs[i] = iter_block->get_min_index(); 00027 max_idxs[i] = iter_block->get_max_index(); 00028 block_idxs_min[i] = i; 00029 block_idxs_max[i] = i; 00030 SG_UNREF(iter_block); 00031 iter_block = (CIndexBlock*)(blocks->get_next_element()); 00032 } 00033 CMath::qsort_index(min_idxs, block_idxs_min, n_sub_blocks); 00034 CMath::qsort_index(max_idxs, block_idxs_max, n_sub_blocks); 00035 00036 for (int32_t i=0; i<n_sub_blocks; i++) 00037 { 00038 if (block_idxs_min[i] != block_idxs_max[i]) 00039 SG_ERROR("Blocks do overlap and it is not supported\n"); 00040 } 00041 if (min_idxs[0] != 0) 00042 SG_ERROR("Block with smallest indices start from %d while 0 is required\n", min_idxs[0]); 00043 00044 for (int32_t i=1; i<n_sub_blocks; i++) 00045 { 00046 if (min_idxs[i] > max_idxs[i-1]) 00047 SG_ERROR("There is an unsupported gap between %d and %d vectors\n", max_idxs[i-1], min_idxs[i]); 00048 else if (min_idxs[i] < max_idxs[i-1]) 00049 SG_ERROR("Blocks do overlap and it is not supported\n"); 00050 } 00051 00052 SG_FREE(min_idxs); 00053 SG_FREE(max_idxs); 00054 SG_FREE(block_idxs_min); 00055 SG_FREE(block_idxs_max); 00056 return true; 00057 }